-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameclient.go
60 lines (50 loc) · 1.59 KB
/
gameclient.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
package ingamemodel
import (
"github.com/snakesneaks/snakesneaks-go-game-server-test/go-game-server/service/model"
)
const (
Ready ConnectionState = iota
Active
Disconnected
)
//ConnectionState is a connection state of game user
type ConnectionState int
//GameClientInfo user client data type in game
type GameClient struct {
Info GameClientInfo `json:"info"`
IngameInfo IngameInfo `json:"ingame_info"`
Conn GameClientConnection `json:"conn"`
}
//GameClientConnection
type GameClientConnection struct {
ConnState ConnectionState `json:"conn_state"`
//ConnLast time.Time `json:"conn_last,omitempty"`
}
//GameClientInfo
type GameClientInfo struct {
UserID uint32 `json:"user_id"`
Username string `json:"username"`
}
type IngameInfo struct {
Transform Transform `json:"transform"`
}
func NewIngameInfo() IngameInfo {
return IngameInfo{NewTransform(NewVector3(0, 0, 0), NewVector3(0, 0, 0))}
}
//NewGameClient creates game client already registered
func NewGameClient() GameClient {
clientInfo := GameClientInfo{UserID: 0, Username: ""}
clientConn := GameClientConnection{ConnState: Ready}
clientIngameInfo := NewIngameInfo()
return GameClient{Info: clientInfo, Conn: clientConn, IngameInfo: clientIngameInfo}
}
//ActivateClient Activate client
func ActivateClient(userID uint32) (GameClient, error) {
username, err := model.GetUsername(userID)
if err != nil {
return NewGameClient(), err
}
clientInfo := GameClientInfo{UserID: userID, Username: username}
clientConn := GameClientConnection{ConnState: Active}
return GameClient{Info: clientInfo, Conn: clientConn}, nil
}