forked from xiaonanln/goworld
/
DispatcherClient.go
46 lines (38 loc) · 1.24 KB
/
DispatcherClient.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
package dispatcherclient
import (
"net"
"github.com/xiaonanln/goworld/engine/consts"
"github.com/xiaonanln/goworld/engine/gwlog"
"github.com/xiaonanln/goworld/engine/netutil"
"github.com/xiaonanln/goworld/engine/proto"
)
type DispatcherClientType int
const (
GameDispatcherClientType DispatcherClientType = 1 + iota
GateDispatcherClientType
)
// DispatcherClient is a client connection to the dispatcher
type DispatcherClient struct {
*proto.GoWorldConnection
dctype DispatcherClientType
isReconnect bool
isRestoreGame bool
}
func newDispatcherClient(dctype DispatcherClientType, conn net.Conn, isReconnect bool, isRestoreGame bool) *DispatcherClient {
gwc := proto.NewGoWorldConnection(netutil.NewBufferedConnection(netutil.NetConnection{conn}), false, "")
if dctype != GameDispatcherClientType && dctype != GateDispatcherClientType {
gwlog.Fatalf("invalid dispatcher client type: %v", dctype)
}
dc := &DispatcherClient{
GoWorldConnection: gwc,
dctype: dctype,
isReconnect: isReconnect,
isRestoreGame: isRestoreGame,
}
dc.SetAutoFlush(consts.DISPATCHER_CLIENT_FLUSH_INTERVAL)
return dc
}
// Close the dispatcher client
func (dc *DispatcherClient) Close() error {
return dc.GoWorldConnection.Close()
}