mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-16 08:55:31 +01:00
Hackily get the client to a channel server
This commit is contained in:
46
channel_server.go
Normal file
46
channel_server.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/Andoryuuta/Erupe/network"
|
||||
"github.com/Andoryuuta/byteframe"
|
||||
)
|
||||
|
||||
func handleChannelServerConnection(conn net.Conn) {
|
||||
fmt.Println("Channel server got connection!")
|
||||
// Unlike the sign and entrance server,
|
||||
// the client DOES NOT initalize the channel connection with 8 NULL bytes.
|
||||
|
||||
cc := network.NewCryptConn(conn)
|
||||
for {
|
||||
pkt, err := cc.ReadPacket()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
bf := byteframe.NewByteFrameFromBytes(pkt)
|
||||
opcode := network.PacketID(bf.ReadUint16())
|
||||
fmt.Printf("Opcode: %s\n", opcode)
|
||||
fmt.Printf("Data:\n%s\n", hex.Dump(pkt))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func doChannelServer(listenAddr string) {
|
||||
l, err := net.Listen("tcp", listenAddr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go handleChannelServerConnection(conn)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user