69 lines
1.4 KiB
Go
69 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"encoding/binary"
|
|
"net"
|
|
)
|
|
|
|
func main() {
|
|
conn, err := net.Dial("tcp", "poop.siteop.biz:3977")
|
|
failError(err, "net.Dial")
|
|
logInfoDebug("Connected to poop.siteop.biz:3977")
|
|
|
|
//send auth
|
|
p := PacketAdminJoin{
|
|
Packet: Packet{PType: AdminPacketAdminJoin},
|
|
Password: "plop",
|
|
AppName: "gottdad",
|
|
AppVersion: "alpha",
|
|
}
|
|
_, err = conn.Write(p.Bytes())
|
|
failError(err, "conn.Write")
|
|
logInfoDebug("Authentication sent (%v)", p.Bytes())
|
|
r := bufio.NewReader(conn)
|
|
b := make([]byte, 0xFFFF)
|
|
read := 0
|
|
n := 0
|
|
|
|
for {
|
|
p := Packet{}
|
|
|
|
for {
|
|
n, err = r.Read(b[read:])
|
|
logErrorDebug(err, "r.Read")
|
|
read += n
|
|
logInfoDebug("Waiting for packet, read %d bytes.", read)
|
|
if read >= 3 {
|
|
logInfoDebug("Packet read")
|
|
break
|
|
}
|
|
}
|
|
p.PLength = binary.LittleEndian.Uint16(b[0:])
|
|
p.PType = b[2]
|
|
if p.PLength <= 3 {
|
|
logInfoAlert("Wrong packet length")
|
|
break
|
|
}
|
|
|
|
logInfoDebug("Waiting for full packet : len : %d / type : %d", p.PLength, p.PType)
|
|
|
|
for {
|
|
n, err = r.Read(b[read:])
|
|
logErrorDebug(err, "r.Read")
|
|
read += n
|
|
logInfoDebug("Waiting for data, read %d/%d bytes.", read, p.PLength)
|
|
if read >= int(p.PLength) {
|
|
break
|
|
}
|
|
}
|
|
|
|
logInfoDebug("Packet read : len : %d / type : %d", p.PLength, p.PType)
|
|
c := make([]byte, 0xFFFF)
|
|
copy(c, b[p.PLength:])
|
|
b = c
|
|
read -= int(p.PLength)
|
|
}
|
|
|
|
}
|