|
| 1 | +// Copyright (C) 2021-2021 The Whirlsplash Collective |
| 2 | +// SPDX-License-Identifier: GPL-3.0-only |
| 3 | + |
| 4 | +package server |
| 5 | + |
| 6 | +import ( |
| 7 | + "github.com/Whirlsplash/munch/pkg/server/utils" |
| 8 | + "github.com/spf13/viper" |
| 9 | + "log" |
| 10 | + "net" |
| 11 | +) |
| 12 | + |
| 13 | +func doHub(port string) { |
| 14 | + tcpAddr, _ := net.ResolveTCPAddr( |
| 15 | + "tcp", |
| 16 | + (viper.GetString("worlds.server.ip") + ":" + port), |
| 17 | + ) |
| 18 | + conn, _ := net.DialTCP("tcp", nil, tcpAddr) |
| 19 | + |
| 20 | + // PROPREQ |
| 21 | + conn.Write([]byte("\x03\xff\x0a")) |
| 22 | + reply := make([]byte, 1024) |
| 23 | + conn.Read(reply) |
| 24 | + log.Println("RoomServer: PROPREQ") |
| 25 | + |
| 26 | + // SESSINIT |
| 27 | + conn.Write(utils.EncodeSessionInitialization( |
| 28 | + viper.GetString("worlds.account.username"), |
| 29 | + viper.GetString("worlds.account.password"), |
| 30 | + utils.RoomServer, |
| 31 | + )) |
| 32 | + reply = make([]byte, 1024) |
| 33 | + conn.Read(reply) |
| 34 | + log.Println("RoomServer: SESSINIT") |
| 35 | + |
| 36 | + // SUB-DIST |
| 37 | + conn.Write([]byte( |
| 38 | + "\x0d\x01\x16\x00\x02\x00\x00\x00\xfa\x00\x00\x0a\xf8" + |
| 39 | + "\x0d\x01\x16\x00\x01\x00\x00\x02\xee\x00\x00\x0c\xf9" + |
| 40 | + "\x0d\x01\x16\x00\x07\x00\x00\x36\xaf\x00\x00\x09\xbd" + |
| 41 | + "\x0d\x01\x16\x00\x06\xf1\x77\x00\x00\x01\x90\x0d\xcf\x0d\x01\x16" + |
| 42 | + "\x98\xee\x00\x00\x00\xc8\x00\x28\x0e\x67\x0d\x01\x16\x00\x04\x00" + |
| 43 | + "\x00\x00\xfa\x00\x00\x0c\xb7\x0d\x01\x16\x00\x03\x00\x00\x02\xee" + |
| 44 | + "\x00\x00\x0c\x30\x0d\x01\x16\x00\x09\x01\xf4\x03\xe8\x01\xf4\x09" + |
| 45 | + "\xd5\x0d\x01\x16\x00\x08\x00\x00\x00\x00\x00\x00\xff\x9c\x0f\x01" + |
| 46 | + "\x12\x00\x08\x00\x01\x04\xcc\x09\xa1\x00\x00\x01\x25\x07\x01\x18" + |
| 47 | + "\x00\x01\x0c\xf9\x07\x01\x18\x00\x03\x0c\x30\x07\x01\x18\x00\x09" + |
| 48 | + "\x09\xd5\x07\x01\x18\x00\x07\x09\xbd\x07\x01\x18\x00\x06\x0d\xcf" + |
| 49 | + "\x07\x01\x18\x98\xee\x0e\x67\x07\x01\x18\x00\x04\x0c\xb7\x07\x01" + |
| 50 | + "\x18\x00\x02\x0a\xf8", |
| 51 | + )) |
| 52 | + reply = make([]byte, 1024) |
| 53 | + conn.Read(reply) |
| 54 | + log.Println("RoomServer: SUBSCRIB") |
| 55 | + |
| 56 | + // Listen for whispers |
| 57 | + for { |
| 58 | + reply = make([]byte, 1024) |
| 59 | + conn.Read(reply) |
| 60 | + if reply[2] == 17 { |
| 61 | + decodedText := utils.DecodeText(reply) |
| 62 | + log.Printf( |
| 63 | + "RoomServer: WHISPER: %s: %s\n", |
| 64 | + decodedText.Author, decodedText.Message, |
| 65 | + ) |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + conn.Close() |
| 70 | +} |
0 commit comments