forked from ECSC2022/ctf-gameserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
474 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module github.com/fausecteam/ctf-gameserver/go/checkerlib | ||
|
||
require ( | ||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 | ||
golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM= | ||
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= | ||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20200610111108-226ff32320da h1:bGb80FudwxpeucJUjPYJXuJ8Hk91vNtfvrymzwiei38= | ||
golang.org/x/sys v0.0.0-20200610111108-226ff32320da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Communication with checkermaster | ||
|
||
package checkerlib | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"encoding/json" | ||
"io" | ||
"sync" | ||
) | ||
|
||
type ipcData struct { | ||
sync.Mutex | ||
|
||
in *bufio.Scanner | ||
out io.Writer | ||
} | ||
|
||
func (i *ipcData) Send(action string, param interface{}) { | ||
ipc.Lock() | ||
defer ipc.Unlock() | ||
|
||
i.send(action, param) | ||
} | ||
func (i *ipcData) SendRecv(action string, param interface{}) interface{} { | ||
ipc.Lock() | ||
defer ipc.Unlock() | ||
|
||
i.send(action, param) | ||
return i.recv() | ||
} | ||
|
||
func (i *ipcData) send(action string, param interface{}) { | ||
data := struct { | ||
Action string `json:"action"` | ||
Param interface{} `json:"param"` | ||
}{ | ||
action, | ||
param, | ||
} | ||
|
||
x, err := json.Marshal(data) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// Make sure that our JSON consists of just a single line as required | ||
// by IPC protocol | ||
x = append(bytes.Replace(x, []byte{'\n'}, nil, -1), '\n') | ||
|
||
_, err = i.out.Write(x) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func (i *ipcData) recv() interface{} { | ||
if !i.in.Scan() { | ||
panic(i.in.Err()) | ||
} | ||
var x struct { | ||
Response interface{} `json:"response"` | ||
} | ||
err := json.Unmarshal(i.in.Bytes(), &x) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return x.Response | ||
} |
Oops, something went wrong.