-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver_data.go
53 lines (46 loc) · 1.37 KB
/
server_data.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
package goproxy
import (
"strings"
"strconv"
)
// this struct holds the Server Data
type ServerData struct {
// raw Server Data as mixed slice
RawData []interface{}
// Server name as string
serverName string
// Server protocol version as int
protocolVersion int
// Server game version as int
gameVersion int
// Server online player count as int
onlinePlayerCount int //ignore
// Server nax player count as int
maxPlayerCount int //ignore
}
func NewServerData() ServerData {
return ServerData{}
}
// This parses Data sent from the Server
// the Data is send in this format:
// MCPE;Server name;protocol version;MCPE version;online player count;max player count
func (svData *ServerData) ParseFromString(data string){
split := strings.Split(data, ";")[1:]
svData.serverName = split[0]
svData.protocolVersion, _ = strconv.Atoi(split[1])
svData.gameVersion, _ = strconv.Atoi(split[2])
svData.onlinePlayerCount, _ = strconv.Atoi(split[3])
svData.maxPlayerCount, _ = strconv.Atoi(split[4])
}
// returns the Server name sent from the Server
func (svData *ServerData) GetServerName() string {
return svData.serverName
}
// returns the protocol version sent from the Server
func (svData *ServerData) GetProtocolVersion() int {
return svData.protocolVersion
}
// returns the game version sent from the Server
func (svData *ServerData) GetGameVersion() int {
return svData.gameVersion
}