Reading the chat kinda works
This commit is contained in:
parent
cf6efb1e3f
commit
ef2c7e8a34
22
teeworlds.go
22
teeworlds.go
|
@ -28,8 +28,9 @@ const (
|
||||||
msgSysConReady = 5
|
msgSysConReady = 5
|
||||||
msgSysSnapSingle = 8
|
msgSysSnapSingle = 8
|
||||||
|
|
||||||
msgGameReadyToEnter = 8
|
|
||||||
msgGameMotd = 1
|
msgGameMotd = 1
|
||||||
|
msgGameSvChat = 3
|
||||||
|
msgGameReadyToEnter = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
func ctrlToken(myToken []byte) []byte {
|
func ctrlToken(myToken []byte) []byte {
|
||||||
|
@ -195,25 +196,35 @@ func (client *TeeworldsClient) onSystemMsg(msg int, chunk chunk.Chunk, u *packer
|
||||||
fmt.Println("got ready")
|
fmt.Println("got ready")
|
||||||
client.sendStartInfo()
|
client.sendStartInfo()
|
||||||
} else if msg == msgSysSnapSingle {
|
} else if msg == msgSysSnapSingle {
|
||||||
tick := u.GetInt()
|
// tick := u.GetInt()
|
||||||
fmt.Printf("got snap single tick=%d\n", tick)
|
// fmt.Printf("got snap single tick=%d\n", tick)
|
||||||
client.sendKeepAlive()
|
client.sendKeepAlive()
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("unknown system message id=%d data=%x\n", msg, chunk.Data)
|
fmt.Printf("unknown system message id=%d data=%x\n", msg, chunk.Data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onChatMessage(mode int, clientId int, targetId int, message string) {
|
||||||
|
fmt.Printf("[chat] %d: %s\n", clientId, message)
|
||||||
|
}
|
||||||
|
|
||||||
func (client *TeeworldsClient) onGameMsg(msg int, chunk chunk.Chunk, u *packer.Unpacker) {
|
func (client *TeeworldsClient) onGameMsg(msg int, chunk chunk.Chunk, u *packer.Unpacker) {
|
||||||
if msg == msgGameReadyToEnter {
|
if msg == msgGameReadyToEnter {
|
||||||
fmt.Println("got ready to enter")
|
fmt.Println("got ready to enter")
|
||||||
client.sendEnterGame()
|
client.sendEnterGame()
|
||||||
|
} else if msg == msgGameSvChat {
|
||||||
|
mode := u.GetInt()
|
||||||
|
clientId := u.GetInt()
|
||||||
|
targetId := u.GetInt()
|
||||||
|
message := u.GetString()
|
||||||
|
onChatMessage(mode, clientId, targetId, message)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("unknown game message id=%d data=%x\n", msg, chunk.Data)
|
fmt.Printf("unknown game message id=%d data=%x\n", msg, chunk.Data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *TeeworldsClient) onMessage(chunk chunk.Chunk) {
|
func (client *TeeworldsClient) onMessage(chunk chunk.Chunk) {
|
||||||
fmt.Printf("got chunk size=%d data=%v\n", chunk.Header.Size, chunk.Data)
|
// fmt.Printf("got chunk size=%d data=%v\n", chunk.Header.Size, chunk.Data)
|
||||||
|
|
||||||
if chunk.Header.Flags.Vital {
|
if chunk.Header.Flags.Vital {
|
||||||
client.Ack++
|
client.Ack++
|
||||||
|
@ -235,7 +246,6 @@ func (client *TeeworldsClient) onMessage(chunk chunk.Chunk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *TeeworldsClient) onPacketPayload(header []byte, data []byte) {
|
func (client *TeeworldsClient) onPacketPayload(header []byte, data []byte) {
|
||||||
fmt.Printf("got payload: %x %x\n", header, data)
|
|
||||||
chunks := chunk.UnpackChunks(data)
|
chunks := chunk.UnpackChunks(data)
|
||||||
|
|
||||||
for _, c := range chunks {
|
for _, c := range chunks {
|
||||||
|
@ -274,7 +284,6 @@ func (client *TeeworldsClient) onPacket(data []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if header.Flags.Compression {
|
if header.Flags.Compression {
|
||||||
fmt.Printf("got compressed data: %x\n", payload)
|
|
||||||
huff := huffman.Huffman{}
|
huff := huffman.Huffman{}
|
||||||
var err error
|
var err error
|
||||||
payload, err = huff.Decompress(payload)
|
payload, err = huff.Decompress(payload)
|
||||||
|
@ -282,7 +291,6 @@ func (client *TeeworldsClient) onPacket(data []byte) {
|
||||||
fmt.Printf("huffman error: %v\n", err)
|
fmt.Printf("huffman error: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("got decompressed: %x\n", payload)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.onPacketPayload(headerRaw, payload)
|
client.onPacketPayload(headerRaw, payload)
|
||||||
|
|
Loading…
Reference in a new issue