aboutsummaryrefslogtreecommitdiff
path: root/distributor.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-24 20:11:23 +0000
committerFuwn <[email protected]>2021-07-24 20:11:23 +0000
commit688aec1791ca5ba357cef5afc4a4c6e11d8ff4c2 (patch)
tree73104855103207b7d04f385c255b8d891bf4715e /distributor.go
downloadterra-688aec1791ca5ba357cef5afc4a4c6e11d8ff4c2.tar.xz
terra-688aec1791ca5ba357cef5afc4a4c6e11d8ff4c2.zip
feat(global): push development state
Diffstat (limited to 'distributor.go')
-rw-r--r--distributor.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/distributor.go b/distributor.go
new file mode 100644
index 0000000..a8aa023
--- /dev/null
+++ b/distributor.go
@@ -0,0 +1,58 @@
+// Copyright (C) 2021-2021 The Whirlsplash Collective
+// SPDX-License-Identifier: GPL-3.0-only
+
+package terra
+
+import (
+ "encoding/binary"
+ "log"
+ "net"
+ "strconv"
+
+ utils "github.com/Whirlsplash/terra/net"
+)
+
+func doDistributor(ip string, serverPort string, username string, password string, avatar string) string {
+ tcpAddr, _ := net.ResolveTCPAddr(
+ "tcp",
+ ip+":"+serverPort,
+ )
+ conn, _ := net.DialTCP("tcp", nil, tcpAddr)
+
+ // PROPREQ
+ conn.Write([]byte("\x03\xff\x0a"))
+ reply := make([]byte, 1024)
+ conn.Read(reply)
+ log.Println("AutoServer: PROPREQ")
+
+ // SESSINIT
+ conn.Write(utils.EncodeSessionInitialization(
+ username,
+ password,
+ utils.AutoServer,
+ ))
+ reply = make([]byte, 1024)
+ conn.Read(reply)
+ log.Println("AutoServer: SESSINIT")
+
+ // PROPUPD
+ conn.Write(utils.EncodePropertyUpdate(avatar))
+ reply = make([]byte, 1024)
+ conn.Read(reply)
+ log.Println("AutoServer: PROPUPD")
+
+ // ROOMIDRQ
+ conn.Write([]byte(
+ "\x26\x01\x14\x22\x47\x72\x6f\x75\x6e\x64\x5a\x65\x72\x6f\x23\x73" +
+ "\x74\x61\x69\x72\x63\x61\x73\x65\x31\x3c\x64\x69\x6d\x65\x6e\x73" +
+ "\x69\x6f\x6e\x2d\x31\x3e",
+ ))
+ reply = make([]byte, 1024)
+ conn.Read(reply)
+ port := strconv.Itoa(int(binary.BigEndian.Uint16(reply[44:46])))
+ log.Println("AutoServer: ROOMIDRQ")
+
+ conn.Close()
+
+ return port
+}