From 9ea7a3735c833ac287101d9a26cfa79d6aef379c Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 22 Jun 2024 12:38:17 +0800 Subject: [PATCH] These examples need a better place --- teeworlds.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/teeworlds.go b/teeworlds.go index ab704fc..bf3fa20 100644 --- a/teeworlds.go +++ b/teeworlds.go @@ -93,28 +93,27 @@ func main() { } response := client.OnPacket(packet) if response != nil { - // example of inspecting incoming trafic - for i, _ := range packet.Messages { - var chat *messages7.SvChat - var ok bool - if chat, ok = packet.Messages[i].(*messages7.SvChat); ok { - fmt.Printf("got chat msg: %s\n", chat.Message) - - // modify chat if this was a proxy - packet.Messages[i] = chat + for _, msg := range packet.Messages { + switch msg := msg.(type) { + case *messages7.SvChat: + // inspect incoming traffic + fmt.Printf("got incoming chat msg: %s\n", msg.Message) + default: } } // example of modifying outgoing traffic for i, msg := range response.Messages { - if msg.MsgId() == network7.MsgCtrlConnect { - var connect *messages7.CtrlConnect - var ok bool - if connect, ok = response.Messages[i].(*messages7.CtrlConnect); ok { - connect.Token = [4]byte{0xaa, 0xaa, 0xaa, 0xaa} - response.Messages[i] = connect - } + switch msg := msg.(type) { + case *messages7.SvChat: + // inspect outgoing traffic + fmt.Printf("got outgoing chat msg: %s\n", msg.Message) + + // change outgoing traffic + msg.Message += " (edited by go)" + packet.Messages[i] = msg + default: } }