-
Notifications
You must be signed in to change notification settings - Fork 1
/
summary.go
189 lines (168 loc) · 5.58 KB
/
summary.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package distance
import (
"math"
"net/url"
"time"
)
// Summary is the structure of a summary response from /summary.
type Summary struct {
Server Server
Level Level
ChatLog []ChatMessage
Players []Player
AutoServer AutoServer
VoteCommands VoteCommands
}
// FindPlayer finds the player by the given Unity Player GUID string. Nil is
// returned if no players are found.
func (s Summary) FindPlayer(guid string) *Player {
for i, player := range s.Players {
if player.UnityPlayerGUID == guid {
return &s.Players[i]
}
}
return nil
}
// Server describes the server in Summary.
type Server struct {
CurrentLevelID int64 `json:"CurrentLevelId"`
MaxPlayers int64
Port int64
ReportToMasterServer bool
MasterServerGameModeOverride string
DistanceVersion int64
IsInLobby bool
HasModeStarted bool
ModeStartTime float64
}
// AutoServer is part of Summary.
type AutoServer struct {
IdleTimeout int64
LevelTimeout int64
AdvanceWhenStartingPlayersFinish bool
WelcomeMessage string
LevelEndTime float64
StartingPlayerGuids []string
}
// ChatMessage is part of Summary. It describes a message in the ChatLog.
type ChatMessage struct {
Sender string
GUID string `json:"Guid"`
Timestamp float64
Chat string
Type ChatMessageType
Description string
}
// Time returns the timestamp in time.Time.
func (msg ChatMessage) Time() time.Time {
sec, f := math.Modf(msg.Timestamp)
return time.Unix(int64(sec), int64(float64(time.Second)*f))
}
// ChatMessageType is the enumerated type for a message's type.
type ChatMessageType string
const (
PlayerCustomMessage ChatMessageType = "PlayerCustom"
ServerCustomMessage ChatMessageType = "ServerCustom"
ServerVanillaMessage ChatMessageType = "ServerVanilla"
PlayerActionMessage ChatMessageType = "PlayerAction"
PlayerChatMessage ChatMessageType = "PlayerChatMessage"
)
// Level describes a level in Summary.
type Level struct {
Index int
Name string
RelativeLevelPath string
WorkshopFileID string `json:"WorkshopFileId"`
GameMode string
Difficulty string
}
// WorkshopURL returns the workshop URL to this level.
func (lvl Level) WorkshopURL() string {
return "https://steamcommunity.com/sharedfiles/filedetails/?id=" + lvl.WorkshopFileID
}
// Player describes a player in Summary.
type Player struct {
UnityPlayerGUID string `json:"UnityPlayerGuid"`
State PlayerState
Stuck bool
LevelID int `json:"LevelId"`
ReceivedInfo bool
Index int
Name string
JoinedAt float64
ValidatedAt float64
Ready bool
Car Car
LevelCompatibilityInfo LevelCompatibilityInfo
LevelCompatibility string
Valid bool
IPAddress string `json:"IpAddress"`
Port int
}
// PlayerState describes the current state of a Player in Summary.
type PlayerState string
const (
PlayerInitializing PlayerState = "Initializing"
PlayerInitialized PlayerState = "Initialized"
PlayerLoadingLobbyScene PlayerState = "LoadingLobbyScene"
PlayerLoadedLobbyScene PlayerState = "LoadedLobbyScene"
PlayerSubmittedLobbyInfo PlayerState = "SubmittedLobbyInfo"
PlayerWaitingForCompatibilityStatus PlayerState = "WaitingForCompatibilityStatus"
PlayerLoadingGameModeScene PlayerState = "LoadingGameModeScene"
PlayerLoadedGameModeScene PlayerState = "LoadedGameModeScene"
PlayerSubmittedGameModeInfo PlayerState = "SubmittedGameModeInfo"
PlayerStartedMode PlayerState = "StartedMode"
PlayerCantLoadLevelSoInLobby PlayerState = "CantLoadLevelSoInLobby"
)
// LevelCompatibilityInfo describes the level compatibility information from
// Summary.
type LevelCompatibilityInfo struct {
LevelCompatibilityID int `json:"LevelCompatibilityId"`
HasLevel bool
LevelVersion string
}
// Car describes a Player's car in Summary.
type Car struct {
Colors [][4]float32 `json:"CarColors"`
Name string `json:"CarName"`
Points int
Finished bool
FinishType FinishType
FinishData int
Spectator bool
Alive bool
WingsOpen bool
Position []float32
Rotation []float32
Velocity []float32
AngularVelocity []float32
}
// IsFinished returns true if the car finished normally.
func (c Car) IsFinished() bool { return c.Finished && c.FinishType == NormalFinish }
type FinishType string
const (
NoneFinish FinishType = "None"
NormalFinish FinishType = "Normal"
DNFFinish FinishType = "DNF"
SpectateFinish FinishType = "Spectate"
JoinedLateFinish FinishType = "JoinedLate"
ViewingReplayFinish FinishType = "ViewingReplay"
LeavingLevelFinish FinishType = "LeavingLevel"
)
// VoteCommands describes the vote commands in Summary.
type VoteCommands struct {
SkipThreshold float64
HasSkipped bool
ExtendThreshold float64
ExtendTime float64
LeftAt map[string]float64
PlayerVotes map[string]Level
AgainstVotes map[string]int
SkipVotes []string
ExtendVotes []string
}
// Summary gets the server summary.
func (c *Client) Summary() (*Summary, error) {
var s *Summary
return s, c.getJSON(url.URL{Path: "/summary"}, &s)
}