-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.go
118 lines (102 loc) · 2.79 KB
/
game.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package lobby
import "context"
const (
// DefaultGamePort is a default UDP port for Nox games.
DefaultGamePort = 18590
)
// GameMode is a Nox game mode.
type GameMode string
const (
ModeKOTR = GameMode("kotr")
ModeCTF = GameMode("ctf")
ModeFlagBall = GameMode("flagball")
ModeChat = GameMode("chat")
ModeArena = GameMode("arena")
ModeElimination = GameMode("elimination")
ModeQuest = GameMode("quest")
ModeCoop = GameMode("coop")
ModeCustom = GameMode("custom")
)
// GameAccess specifies access for the game (open, password-protected, etc).
type GameAccess string
const (
AccessOpen = GameAccess("open")
AccessPassword = GameAccess("pass")
AccessClosed = GameAccess("closed")
)
// Resolution is a max resolution used for the game.
// Historically Nox used a limited resolution. For HD-aware servers, HighRes should be set.
type Resolution struct {
HighRes bool `json:"high_res,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
}
func (v *Resolution) Clone() *Resolution {
if v == nil {
return nil
}
v2 := *v
return &v2
}
// GameHost is an interface for the game server.
type GameHost interface {
// GameInfo returns current information about the active game.
GameInfo(ctx context.Context) (*Game, error)
}
// Game is an information about the Nox game, as provided by the server hosting it.
// See GameInfo for an information returned by the lobby server.
type Game struct {
Name string `json:"name"`
Address string `json:"addr,omitempty"`
Port int `json:"port,omitempty"`
Map string `json:"map"`
Mode GameMode `json:"mode"`
Access GameAccess `json:"access,omitempty"`
Vers string `json:"vers,omitempty"`
Res Resolution `json:"res,omitempty"`
Players PlayersInfo `json:"players"`
Quest *QuestInfo `json:"quest,omitempty"`
}
func (g *Game) Clone() *Game {
if g == nil {
return nil
}
g2 := *g
g2.Players = *g.Players.Clone()
g2.Res = *g.Res.Clone()
g2.Quest = g.Quest.Clone()
return &g2
}
// PlayerInfo is an information about a specific player.
type PlayerInfo struct {
Name string `json:"name"`
Class string `json:"class,omitempty"`
}
// PlayersInfo is an information about players in a specific game.
type PlayersInfo struct {
Cur int `json:"cur"`
Max int `json:"max"`
List []PlayerInfo `json:"list,omitempty"`
}
func (v *PlayersInfo) Clone() *PlayersInfo {
if v == nil {
return nil
}
v2 := *v
if len(v.List) != 0 {
v2.List = make([]PlayerInfo, len(v.List))
copy(v2.List, v.List)
}
return &v2
}
// QuestInfo is additional information for Nox Quest game mode.
type QuestInfo struct {
Stage int `json:"stage"`
}
func (v *QuestInfo) Clone() *QuestInfo {
if v == nil {
return nil
}
v2 := *v
return &v2
}