async def handle_pkt(self, pkt): if pkt[0] == 0x03: # player self.pid = bytes([pkt[1]]) await self.writepkt(b"\x04" + self.pid + b"\x00\x00" + prepstr("SERVER") + b"\x00\x00\x00\x00" + b"\x00\x00\x00" * 7 + b"\x00") await self.writepkt(b"\x44" + prepstr(str(uuid.uuid4()))) await self.writepkt(b"\x10" + self.pid + b"\x99\x99") await self.writepkt(b"\x2a" + self.pid + b"\x99\x99") await self.writepkt(b"\x32" + self.pid + b"\x35\xbe" + b"\x00" * 20) for x in range(0, 0xdb + 1): await self.writepkt(b"\x05" + self.pid + bytes(x) + b"\x00\x00\x00\x00\x00") await self.writepkt(b"\x06") elif pkt[0] == 0x07: # world info await self.writepkt(b"\x08\xff\xff\xff\xff\xff\xff\xff\xff") elif pkt[0] == 0x31: await self.writepkt(b"\x0c" + self.pid + b"\xff\xff\xff\xff") self.ready = True
async def quit(cl: TClientConnection, srv: TRelayServer, args): await cl.writepkt(b"\x02" + prepstr(" ".join(args))) return True
async def sendchat(self, msg: str): await self.writepkt(b"\x52\x01" + self.pid + b"\x03\x53\x61\x79" + prepstr(msg))
async def connect(self, dest): self.reader, self.writer = await asyncio.open_connection( dest[0], dest[1]) asyncio.get_event_loop().create_task(self.listen()) await self.writepkt(b"\x01" + prepstr("Terraria194"))
async def PartyCommand(srv,cl,msg:str): await cl.prcon.writepkt(b"\x52\x01\x00"+prepstr("Party")+prepstr(msg)) # hacks!
# this file re-creates the chat netmodule's commands, so that i dont have to pass them through to the server to get them. async def EmoteCommand(srv,cl,msg:str): await srv.broadcastChat(cl,message="*"+cl.name+" "+msg,color=b"\x94\x4a\x00") async def PlayingCommand(srv,cl,msg:str): msg = "Currently on the network: "+",".join([x.name for x in srv.conns]) msg += "\nOn the same server as you: "+",".join([x.name for x in srv.conns if cl.cur_server == x.cur_server]) await cl.sendchat(msg) async def RollCommand(srv,cl,msg:str): from random import randint await srv.broadcastChat(cl,message=cl.name+" has rolled a "+str(randint(0,100))+".",sendall=False) async def SayCommand(srv,cl,msg:str) print(msg) if msg[0] != "/": await srv.broadcastChat(cl,author=cl,message=msg) else: await cl.prcon.writepkt(b"\x52\x01\x00"+prepstr("Say")+prepstr(msg)) # hacks! async def PartyCommand(srv,cl,msg:str): await cl.prcon.writepkt(b"\x52\x01\x00"+prepstr("Party")+prepstr(msg)) # hacks! chatcommands = { "Emote": EmoteCommand, "Roll": RollCommand, "Say": SayCommand, "Party": PartyCommand, "Playing": PlayingCommand }