From 26bfbfbc268f01b0f4be171400aa4c53481a50c5 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 21 Jun 2024 10:54:02 +0800 Subject: [PATCH] Bump deps and fix crash --- go.mod | 7 ++++--- go.sum | 4 ++-- proxy.go | 28 +++++++++++++++------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 38cc4eb..7343630 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,7 @@ module github.com/teeworlds-go/proxy go 1.22.3 -require github.com/teeworlds-go/teeworlds v0.0.0-20240621015046-db550ce86fda - -require github.com/teeworlds-go/huffman v1.0.0 // indirect +require ( + github.com/teeworlds-go/huffman v1.0.0 // indirect + github.com/teeworlds-go/teeworlds v0.0.0-20240621024049-4f37d5de48ca // indirect +) diff --git a/go.sum b/go.sum index a5463e1..d2e42dd 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ github.com/teeworlds-go/huffman v1.0.0 h1:XSNMNAJZb+njNrPACsxcDrrLDXTGjZZt35FqLAuHi4I= github.com/teeworlds-go/huffman v1.0.0/go.mod h1:kjaXpL6C6xL7CM+tWPNYjdEgVZB2GumKhx7rCDdXArU= -github.com/teeworlds-go/teeworlds v0.0.0-20240621015046-db550ce86fda h1:Ho08Zo5Co+t5VfX4wVqiEDHxxDD3F+52AYne/Gs7oj0= -github.com/teeworlds-go/teeworlds v0.0.0-20240621015046-db550ce86fda/go.mod h1:aKhyLQAZ0cXv3e6ivNMiolKLbycQlDTIq9Yldn7klWM= +github.com/teeworlds-go/teeworlds v0.0.0-20240621024049-4f37d5de48ca h1:0u/k7xwegit84TXXBnS7iLJSxUxuE2AjOX/aJwlRIH0= +github.com/teeworlds-go/teeworlds v0.0.0-20240621024049-4f37d5de48ca/go.mod h1:aKhyLQAZ0cXv3e6ivNMiolKLbycQlDTIq9Yldn7klWM= diff --git a/proxy.go b/proxy.go index df307bb..bd39a8e 100644 --- a/proxy.go +++ b/proxy.go @@ -93,19 +93,21 @@ func RunConnection(conn *Connection, twconn *protocol7.Connection) { if err != nil { panic(err) } - // example of inspecting incoming trafic - for i, msg := range result.Packet.Messages { - if msg.MsgId() == network7.MsgGameSvChat { - var chat *messages7.SvChat - var ok bool - if chat, ok = result.Packet.Messages[i].(*messages7.SvChat); ok { - fmt.Printf("got chat msg: %s\n", chat.Message) - chat.Message = "capitalism." - - // modify chat if this was a proxy - result.Packet.Messages[i] = chat - - srvMsg = result.Packet.Pack(twconn) + // inspecting incoming trafic + if result != nil && result.Packet != nil { + for i, msg := range result.Packet.Messages { + if msg.MsgId() == network7.MsgGameSvChat { + var chat *messages7.SvChat + var ok bool + if chat, ok = result.Packet.Messages[i].(*messages7.SvChat); ok { + fmt.Printf("got chat msg: %s\n", chat.Message) + chat.Message = "capitalism." + + // modify chat if this was a proxy + result.Packet.Messages[i] = chat + + srvMsg = result.Packet.Pack(twconn) + } } } }