43 lines
892 B
Go
43 lines
892 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"bytes"
|
||
|
"encoding/binary"
|
||
|
"encoding/hex"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
logger Logger
|
||
|
)
|
||
|
|
||
|
func handleMtaConnection(clientConnection *bufio.ReadWriter) {
|
||
|
buf := make([]byte, 4096)
|
||
|
for {
|
||
|
bytesRead, err := clientConnection.Read(buf)
|
||
|
if err != nil {
|
||
|
logger.Errorln("Error reading from clientConnection:", err.Error())
|
||
|
break
|
||
|
} else {
|
||
|
logger.Infof("Read %d bytes from connection\n", bytesRead)
|
||
|
logger.Debugf("%s", hex.Dump(buf[0:bytesRead]))
|
||
|
|
||
|
// First 4 Bytes will be some integer thing "length"
|
||
|
// Let's parse that
|
||
|
var packetLength uint32
|
||
|
bytesReader := bytes.NewReader(buf[0:4])
|
||
|
err := binary.Read(bytesReader, binary.BigEndian, &packetLength)
|
||
|
if err != nil {
|
||
|
logger.Errorln(err.Error())
|
||
|
}
|
||
|
logger.Debugf("Parsed length: %d\n", packetLength)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
logger = NewLogger(os.Stdout, os.Stderr, DEBUG)
|
||
|
runServer()
|
||
|
}
|