gottdad/main.go

53 lines
1.1 KiB
Go
Raw Normal View History

2020-06-14 16:27:57 +02:00
package main
import (
2020-06-14 16:32:21 +02:00
"bufio"
2020-06-14 16:27:57 +02:00
"net"
)
func main() {
2020-06-14 16:32:21 +02:00
conn, err := net.Dial("tcp", "poop.siteop.biz:3977")
2020-06-14 16:27:57 +02:00
failError(err, "net.Dial")
logInfoDebug("Connected to poop.siteop.biz:3977")
2020-06-14 16:44:40 +02:00
//send auth
p := PacketAdminJoin{
2020-06-14 16:48:00 +02:00
Packet: Packet{PType: AdminPacketAdminJoin},
2020-06-14 17:13:25 +02:00
Password: "plop",
AppName: "gottdad",
AppVersion: "alpha",
2020-06-14 16:44:40 +02:00
}
_, err = conn.Write(p.Bytes())
failError(err, "conn.Write")
2020-06-14 17:38:25 +02:00
logInfoDebug("Authentication sent (%v)", p.Bytes())
2020-06-14 22:16:39 +02:00
r := bufio.NewReader(conn)
2020-06-14 16:44:40 +02:00
2020-06-14 22:05:45 +02:00
for {
p := Packet{}
2020-06-14 22:16:39 +02:00
b, err := r.ReadByte()
2020-06-14 22:05:45 +02:00
logErrorDebug(err, "conn.ReadByte")
2020-06-14 22:17:17 +02:00
p.PLength = uint16(b) << 8
2020-06-14 22:16:39 +02:00
b, err = r.ReadByte()
2020-06-14 22:05:45 +02:00
logErrorDebug(err, "conn.ReadByte")
2020-06-14 22:17:17 +02:00
p.PLength += uint16(b)
2020-06-14 22:16:39 +02:00
b, err = r.ReadByte()
2020-06-14 22:05:45 +02:00
logErrorDebug(err, "conn.ReadByte")
p.PType = uint8(b)
2020-06-14 22:07:45 +02:00
if p.PLength <= 3 {
logInfoAlert("Wrong packet length")
break
}
2020-06-14 22:05:45 +02:00
d := make([]byte, p.PLength-3)
for {
2020-06-14 22:16:39 +02:00
_, err := r.Read(d[len(d):])
2020-06-14 22:05:45 +02:00
logErrorDebug(err, "conn.Read")
2020-06-14 22:07:45 +02:00
if len(d) == int(p.PLength-3) {
2020-06-14 22:05:45 +02:00
break
}
}
logInfoDebug("Packet read : len : %d / type : %d", p.PLength, p.PType)
2020-06-14 22:07:45 +02:00
2020-06-14 22:05:45 +02:00
}
2020-06-14 16:27:57 +02:00
}