增加server status和mega type
This commit is contained in:
@ -13,6 +13,16 @@ enum ServerPacketType {
|
|||||||
LEAVE = 6;
|
LEAVE = 6;
|
||||||
LIST = 7;
|
LIST = 7;
|
||||||
TOTAL = 8;
|
TOTAL = 8;
|
||||||
|
STATUS = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ServerStatus {
|
||||||
|
FREE = 0;
|
||||||
|
WAITING = 1;
|
||||||
|
STARTING = 2;
|
||||||
|
PLAYING = 3;
|
||||||
|
ENDING = 4;
|
||||||
|
FULL = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ServerPacket {
|
message ServerPacket {
|
||||||
@ -50,3 +60,7 @@ message ServerListPacket {
|
|||||||
message ServerTotalPacket {
|
message ServerTotalPacket {
|
||||||
int32 total = 1;
|
int32 total = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ServerStatusPacket {
|
||||||
|
ServerStatus status = 1;
|
||||||
|
}
|
@ -22,6 +22,7 @@ const (
|
|||||||
ServerTypeRoom ServerType = "ROOM"
|
ServerTypeRoom ServerType = "ROOM"
|
||||||
ServerTypeLimbo ServerType = "LIMBO"
|
ServerTypeLimbo ServerType = "LIMBO"
|
||||||
ServerTypeSystem ServerType = "SYSTEM"
|
ServerTypeSystem ServerType = "SYSTEM"
|
||||||
|
ServerTypeMega ServerType = "MAGA" // make america great again
|
||||||
)
|
)
|
||||||
|
|
||||||
func (typ ServerType) Prefix() string {
|
func (typ ServerType) Prefix() string {
|
||||||
@ -34,6 +35,8 @@ func (typ ServerType) Prefix() string {
|
|||||||
return ""
|
return ""
|
||||||
case ServerTypeSystem:
|
case ServerTypeSystem:
|
||||||
return "S"
|
return "S"
|
||||||
|
case ServerTypeMega:
|
||||||
|
return "mega"
|
||||||
case ServerTypeUnknown:
|
case ServerTypeUnknown:
|
||||||
default:
|
default:
|
||||||
return "U"
|
return "U"
|
||||||
@ -41,6 +44,17 @@ func (typ ServerType) Prefix() string {
|
|||||||
return "U"
|
return "U"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Status string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ServerStatusFree Status = "FREE"
|
||||||
|
ServerStatusWaiting Status = "WAITING"
|
||||||
|
ServerStatusStarting Status = "STARTING"
|
||||||
|
ServerStatusFull Status = "FULL"
|
||||||
|
ServerStatusPlaying Status = "PLAYING"
|
||||||
|
ServerStatusEnding Status = "ENDING"
|
||||||
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -50,6 +64,7 @@ type Server struct {
|
|||||||
Type ServerType `json:"type"`
|
Type ServerType `json:"type"`
|
||||||
Motd string `json:"motd"`
|
Motd string `json:"motd"`
|
||||||
Players []string `json:"players"`
|
Players []string `json:"players"`
|
||||||
|
Status Status `json:"status"`
|
||||||
LastHB time.Time
|
LastHB time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +168,10 @@ func ServerRegister(c *gin.Context) {
|
|||||||
Id: generateServerId(data.Type.Prefix()),
|
Id: generateServerId(data.Type.Prefix()),
|
||||||
Host: data.Host,
|
Host: data.Host,
|
||||||
Port: data.Port,
|
Port: data.Port,
|
||||||
|
Motd: data.Motd,
|
||||||
Type: data.Type,
|
Type: data.Type,
|
||||||
Group: data.Group,
|
Group: data.Group,
|
||||||
|
Players: make([]string, 0),
|
||||||
LastHB: time.Now(),
|
LastHB: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +353,32 @@ func serverReadLoop(conn *ws.Conn, serverId string) {
|
|||||||
conn.WriteChan <- ws.Binary(buf)
|
conn.WriteChan <- ws.Binary(buf)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case ServerPacketType_STATUS:
|
||||||
|
var payload ServerStatusPacket
|
||||||
|
err := proto.Unmarshal(pkt.GetPayload(), &payload)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
switch payload.Status {
|
||||||
|
case ServerStatus_FREE:
|
||||||
|
server.Status = ServerStatusFull
|
||||||
|
break
|
||||||
|
case ServerStatus_WAITING:
|
||||||
|
server.Status = ServerStatusWaiting
|
||||||
|
break
|
||||||
|
case ServerStatus_STARTING:
|
||||||
|
server.Status = ServerStatusStarting
|
||||||
|
break
|
||||||
|
case ServerStatus_PLAYING:
|
||||||
|
server.Status = ServerStatusPlaying
|
||||||
|
break
|
||||||
|
case ServerStatus_ENDING:
|
||||||
|
server.Status = ServerStatusEnding
|
||||||
|
break
|
||||||
|
case ServerStatus_FULL:
|
||||||
|
server.Status = ServerStatusFull
|
||||||
|
break
|
||||||
|
}
|
||||||
case ServerPacketType_TOTAL:
|
case ServerPacketType_TOTAL:
|
||||||
total := 0
|
total := 0
|
||||||
servers.Range(func(_, value any) bool {
|
servers.Range(func(_, value any) bool {
|
||||||
@ -358,13 +401,11 @@ func serverReadLoop(conn *ws.Conn, serverId string) {
|
|||||||
}
|
}
|
||||||
conn.WriteChan <- ws.Binary(buf)
|
conn.WriteChan <- ws.Binary(buf)
|
||||||
}
|
}
|
||||||
default:
|
case <-conn.Context.Done():
|
||||||
if conn.IsClosed() {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func serverProxyReadLoop(conn *ws.Conn) {
|
func serverProxyReadLoop(conn *ws.Conn) {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
Reference in New Issue
Block a user