aboutsummaryrefslogtreecommitdiff
path: root/pkg/server/distributor.go
blob: d9c6bcf592dad6d0e8b189fc9f550f7d91b392b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only

package server

import (
	"encoding/binary"
	"github.com/Whirlsplash/munch/pkg/server/utils"
	"github.com/spf13/viper"
	"log"
	"net"
	"strconv"
)

func doDistributor() string {
	tcpAddr, _ := net.ResolveTCPAddr(
		"tcp",
		viper.GetString("worlds.server.ip")+":"+viper.GetString("worlds.server.port"),
	)
	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(
		viper.GetString("worlds.account.username"),
		viper.GetString("worlds.account.password"),
		utils.AutoServer,
	))
	reply = make([]byte, 1024)
	conn.Read(reply)
	log.Println("AutoServer: SESSINIT")

	// PROPUPD
	conn.Write(utils.EncodePropertyUpdate(viper.GetString("worlds.account.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
}