Hackily get the client to a channel server

This commit is contained in:
Andrew Gutekanst
2019-12-24 00:20:35 +09:00
parent 7aef17f7d9
commit e5066d4f8b
13 changed files with 1275 additions and 27 deletions

46
channel_server.go Normal file
View 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)
}
}