/
main.go
74 lines (66 loc) · 1.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package sgf
import (
"github.com/runningwild/sgf/core"
"github.com/runningwild/sgf/types"
)
type Engine interface {
RegisterGame(v interface{})
RegisterUpdate(v interface{})
RegisterRequest(v interface{})
RLock()
RUnlock()
Game() types.Game
}
type HostEngine interface {
Engine
Start(initialState types.Game)
MakeMajorUpdate(update types.Update)
}
type host struct {
*core.Host
}
func MakeHost(addr string, port int) (HostEngine, error) {
coreHost, err := core.MakeHost(addr, port)
if err != nil {
return nil, err
}
var h host
h.Host = coreHost
return &h, nil
}
func (h *host) RLock() {
h.Host.GameMutex.RLock()
}
func (h *host) RUnlock() {
h.Host.GameMutex.RUnlock()
}
func (h *host) Game() types.Game {
return h.Host.Game
}
type ClientEngine interface {
Engine
Start()
MakeMinorUpdate(update types.Update)
MakeRequest(request types.Request)
}
type Client struct {
*core.Client
}
func MakeClient(addr string, port int) (ClientEngine, error) {
coreClient, err := core.MakeClient(addr, port)
if err != nil {
return nil, err
}
var c Client
c.Client = coreClient
return &c, nil
}
func (c *Client) RLock() {
c.Client.GameMutex.RLock()
}
func (c *Client) RUnlock() {
c.Client.GameMutex.RUnlock()
}
func (c *Client) Game() types.Game {
return c.Client.Game
}