go-teeworlds-protocol/teeworlds7/game.go

54 lines
1.7 KiB
Go
Raw Normal View History

2024-06-23 05:05:57 +00:00
package teeworlds7
import (
"fmt"
"github.com/teeworlds-go/go-teeworlds-protocol/messages7"
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
"github.com/teeworlds-go/go-teeworlds-protocol/protocol7"
)
func (client *Client) processGame(netMsg messages7.NetMessage, response *protocol7.Packet) bool {
switch msg := netMsg.(type) {
case *messages7.SvMotd:
userMsgCallback(client.Callbacks.GameSvMotd, msg, func() {
2024-06-23 05:05:57 +00:00
if msg.Message != "" {
fmt.Printf("[motd] %s\n", msg.Message)
}
})
2024-06-23 05:05:57 +00:00
case *messages7.SvBroadcast:
userMsgCallback(client.Callbacks.GameSvBroadcast, msg, func() {
2024-06-23 05:05:57 +00:00
fmt.Printf("[broadcast] %s\n", msg.Message)
})
2024-06-23 05:05:57 +00:00
case *messages7.SvChat:
userMsgCallback(client.Callbacks.GameSvChat, msg, func() {
2024-06-23 05:05:57 +00:00
if msg.ClientId < 0 || msg.ClientId > network7.MaxClients {
fmt.Printf("[chat] *** %s\n", msg.Message)
return
}
name := client.Game.Players[msg.ClientId].Info.Name
fmt.Printf("[chat] <%s> %s\n", name, msg.Message)
})
2024-06-23 05:05:57 +00:00
case *messages7.SvClientInfo:
userMsgCallback(client.Callbacks.GameSvClientInfo, msg, func() {
2024-06-23 05:05:57 +00:00
client.Game.Players[msg.ClientId].Info = *msg
fmt.Printf("got client info id=%d name=%s\n", msg.ClientId, msg.Name)
})
2024-06-24 06:56:04 +00:00
case *messages7.SvReadyToEnter:
userMsgCallback(client.Callbacks.GameSvReadyToEnter, msg, func() {
2024-06-23 05:05:57 +00:00
fmt.Println("got ready to enter")
response.Messages = append(response.Messages, &messages7.EnterGame{})
})
2024-06-23 05:05:57 +00:00
case *messages7.Unknown:
userMsgCallback(client.Callbacks.MsgUnknown, msg, func() {
2024-06-23 05:05:57 +00:00
// TODO: msg id of unknown messages should not be -1
fmt.Println("TODO: why is the msg id -1???")
printUnknownMessage(msg, "unknown game")
})
2024-06-23 05:05:57 +00:00
default:
printUnknownMessage(netMsg, "unprocessed game")
return false
}
return true
}