These examples need a better place
This commit is contained in:
parent
72bf459d79
commit
9ea7a3735c
31
teeworlds.go
31
teeworlds.go
|
@ -93,28 +93,27 @@ func main() {
|
||||||
}
|
}
|
||||||
response := client.OnPacket(packet)
|
response := client.OnPacket(packet)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
|
|
||||||
// example of inspecting incoming trafic
|
// example of inspecting incoming trafic
|
||||||
for i, _ := range packet.Messages {
|
for _, msg := range packet.Messages {
|
||||||
var chat *messages7.SvChat
|
switch msg := msg.(type) {
|
||||||
var ok bool
|
case *messages7.SvChat:
|
||||||
if chat, ok = packet.Messages[i].(*messages7.SvChat); ok {
|
// inspect incoming traffic
|
||||||
fmt.Printf("got chat msg: %s\n", chat.Message)
|
fmt.Printf("got incoming chat msg: %s\n", msg.Message)
|
||||||
|
default:
|
||||||
// modify chat if this was a proxy
|
|
||||||
packet.Messages[i] = chat
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// example of modifying outgoing traffic
|
// example of modifying outgoing traffic
|
||||||
for i, msg := range response.Messages {
|
for i, msg := range response.Messages {
|
||||||
if msg.MsgId() == network7.MsgCtrlConnect {
|
switch msg := msg.(type) {
|
||||||
var connect *messages7.CtrlConnect
|
case *messages7.SvChat:
|
||||||
var ok bool
|
// inspect outgoing traffic
|
||||||
if connect, ok = response.Messages[i].(*messages7.CtrlConnect); ok {
|
fmt.Printf("got outgoing chat msg: %s\n", msg.Message)
|
||||||
connect.Token = [4]byte{0xaa, 0xaa, 0xaa, 0xaa}
|
|
||||||
response.Messages[i] = connect
|
// change outgoing traffic
|
||||||
}
|
msg.Message += " (edited by go)"
|
||||||
|
packet.Messages[i] = msg
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue