Skip to content

Commit

Permalink
Update protocol library
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Jun 22, 2024
1 parent deff86f commit 80c8d98
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.22.3

require (
github.com/teeworlds-go/huffman v1.0.0 // indirect
github.com/teeworlds-go/teeworlds v0.0.0-20240621051401-94b6c7787cee // indirect
github.com/teeworlds-go/teeworlds v0.0.0-20240622051525-1cf0184d605b // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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-20240621051401-94b6c7787cee h1:kHlXfFQ22RcvVPltdS0JaP60P3symbvobL0tQWD3vvA=
github.com/teeworlds-go/teeworlds v0.0.0-20240621051401-94b6c7787cee/go.mod h1:aKhyLQAZ0cXv3e6ivNMiolKLbycQlDTIq9Yldn7klWM=
github.com/teeworlds-go/teeworlds v0.0.0-20240622051525-1cf0184d605b h1:L2O3FCBy3ShdNMIzGV0IEVJ6bvMGuzWoR7XLwhSWFTY=
github.com/teeworlds-go/teeworlds v0.0.0-20240622051525-1cf0184d605b/go.mod h1:aKhyLQAZ0cXv3e6ivNMiolKLbycQlDTIq9Yldn7klWM=
86 changes: 43 additions & 43 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,52 +92,52 @@ func RunConnection(conn *Connection, twconn *protocol7.Connection) {
}

srvMsg := buffer[0:n]
result, err := twconn.OnPacket(srvMsg)

packet := &protocol7.Packet{}
err = packet.Unpack(srvMsg)
if err != nil {
panic(err)
}
// 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

repack := result.Packet.Pack(twconn)
srvMsg = repack
fmt.Printf("repack %x\n", repack)
}
} else if msg.MsgId() == network7.MsgCtrlToken {
fmt.Printf("got token=%x registering sigint handler ...\n", twconn.ServerToken)

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGINT)
go func() {
<-c
Vlogf(0, "Got ctrl+c sending disconnect token=%x ack=%d ...\n", twconn.ServerToken, twconn.Ack)

packet := protocol7.Packet{}
packet.Messages = append(packet.Messages, &messages7.CtrlClose{})
packet.Header.Token = twconn.ServerToken
packet.Header.Ack = twconn.Ack
disconnectPacked := packet.Pack(twconn)
_, err = conn.ServerConn.Write(disconnectPacked)

time.Sleep(10_000_000)

Vlogf(0, "disconnected. token=%x ack=%d\n", twconn.ServerToken, twconn.Ack)
Vlogf(0, "disconnect: %x\n", disconnectPacked)

os.Exit(0)
}()

}

// count sequence numbers so we can spoof the client
// and send a disconnect message on behalf of the client
twconn.OnPacket(packet)

for i, msg := range packet.Messages {
switch msg := msg.(type) {
case *messages7.SvChat:
// inspect outgoing traffic
fmt.Printf("%s -> capitalism.\n", msg.Message)

// change outgoing traffic
msg.Message = "capitalism."
packet.Messages[i] = msg
srvMsg = packet.Pack(twconn)
case *messages7.CtrlToken:
fmt.Printf("got token=%x registering sigint handler ...\n", msg.Token)

c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGINT)
go func() {
<-c
Vlogf(0, "Got ctrl+c sending disconnect token=%x ack=%d ...\n", msg.Token, twconn.Ack)

packet := protocol7.Packet{}
packet.Messages = append(packet.Messages, &messages7.CtrlClose{})
packet.Header.Token = msg.Token
packet.Header.Ack = twconn.Ack
disconnectPacked := packet.Pack(twconn)
_, err = conn.ServerConn.Write(disconnectPacked)

time.Sleep(10_000_000)

Vlogf(0, "disconnected. token=%x ack=%d\n", msg.Token, twconn.Ack)
Vlogf(0, "disconnect: %x\n", disconnectPacked)

os.Exit(0)
}()

default:
}
}

Expand Down

0 comments on commit 80c8d98

Please sign in to comment.