from giants import ChatColor import asyncio import struct from dpnet.packet import Packet from dpnet.gamepackets import * from random import randint class Commands: def __init__(self, server): self.server = server self.recorded = b'' self.recording = False self.recordingplayer = None self.nextweapon = 1 async def on_player_gamedata(self, player, gamedatabytes): if self.recording: self.recorded = gamedatabytes self.recording = False await self.recordingplayer.send_message("Packet recorded: %s" % (self.recorded.hex(),), color=ChatColor.Cyan) async def on_player_chat(self, player, type, team, message): await self.server.broadcast_message_except(player, "%s: %s" % (player.name, message), color=ChatColor.Yellow) print(message) command = message.split(" ") if len(command) > 1 and command[0] == "team": newteam = command[1] respawn = True if len(command) > 2: respawn = False if command[2] == "off" or command[2] == "no" or command[2] == "false" else True print("Changing team of %s to %s" % (player.name, newteam)) await self.server.broadcast_message("%s switched to team %s using command" % (player.name, newteam)) await player.change_team(int(newteam), respawn=respawn) if len(command) > 1 and command[0] == "ping": newping = command[1] print("Changing ping of %s to %s" % (player.name, newping)) await self.server.broadcast_message("%s set his ping to %s" % (player.name, newping)) await player.send_ping(int(newping)) if command[0] == "ping": print("ping function") await self.server.broadcast_message("pong") if command[0] == "colors": # color codes seem to go from 01 to 0F, loop and show each value: for i in range(1, 0xf + 1): print("Trying value %s" % i) await player.send_message("Color %s" % i, color=i) await asyncio.sleep(2) # sleep between each value to see what value makes the client crash if command[0] == "chattypes": # type codes seem to go from 00 to 0F, loop and show each value: CRASH for i in range(0, 0xf+1): print("Trying value %s" % i) await self.server.broadcast_message("Type %s" % i, type=i) await asyncio.sleep(2) # sleep between each value to see what value makes the client crash if command[0] == "doomchat": # tries every value of first byte and second byte for i in range(3,0xff+1): for j in range(0, 0x81): if i == 0 and j == 2: break # ;) message = "(%s, %s)" % (i, j) print(message) await player.session.send_gamedata(b"\x35" + struct.pack(" 1: diemethod = int(command[1]) await player.send_message("Death by id: %s" % diemethod) await self.server.broadcast_gamedata(MSG_PLAYER_DIE(player, diemethod).to_packet()) #await player.session.send_gamedata(bytes.fromhex("0b1a0000000002070000a5b0d4c35d9714c450abef354a68fb410914000000020700000402000000")+struct.pack(" 1: await self.server.broadcast_message("Spawning " + command[1] + "") await self.server.spawn(player, int(command[1])) if command[0] == "changeme" and len(command) > 1: await self.server.broadcast_message("Changing your model to " + command[1] + "") await self.server.change_model(player, int(command[1])) if command[0] == "change" and len(command) > 2: await self.server.broadcast_message("Changing model of "+command[1]+" to "+command[2]+"") await self.server.change_model(self.server.get_player_by_index(int(command[1])), int(command[2])) if command[0] == "debug": if player.opts["debug"]: player.opts["debug"] = False await player.send_message("Debug disabled") else: player.opts["debug"] = True await player.send_message("Debug enabled") if command[0] == "record": self.recording = True self.recordingplayer = player await player.send_message("Recording next packet...", color=ChatColor.Cyan) if command[0] == "replayshow": await player.send_message("Packet: %s" % (self.recorded.hex(),), color=ChatColor.Cyan) if command[0] == "replay" or command[0] == "r" and len(command) == 1: await player.session.send_gamedata(self.recorded) await player.send_message("Sent packet %s to you" % (self.recorded.hex(),), color=ChatColor.Cyan) if command[0] == "switch" and len(command) > 1: newweap = int(command[1]) await player.send_message("Got you weapon %s" % newweap, color=ChatColor.Cyan) await self.server.broadcast_gamedata(MSG_SWITCH_WEAPON(player, newweap).to_packet()) if command[0] == "s": await player.send_message("Got you weapon %s" % (self.nextweapon,), color=ChatColor.Cyan) await self.server.broadcast_gamedata(MSG_SWITCH_WEAPON(player, self.nextweapon).to_packet()) self.nextweapon += 1 if command[0] == "emptyweapons": for _ in range(4): await self.server.broadcast_gamedata(MSG_SWITCH_WEAPON(player, 0xff).to_packet()) await player.send_message("Emptied your weapons", color=ChatColor.Cyan) if command[0] == "sniper": p = Packet() p.putByte(0x20) p.putShort(self.server._nextid) # oid? self.server._nextid += 1 p.putShort(0x0000) p.putShort(0x0440) p.putShort(0x0100) p.putFloat(0) # x p.putFloat(0) # y p.putFloat(0) # z p.putFloat(0) # o p.putFloat(0x621c68c1) # wtf? p.putShort(0x0000) p.putShort(0x7041) # oid? p.putShort(0x0000) p.putShort(0x0300) p.putLong(0x1e0000) p.putLong(0x0) p.putByte(0x00) # end await self.server.broadcast_gamedata(p.getvalue()) if len(command) > 1 and command[0] == "drop": weap = int(command[1]) await player.send_message("Dropped weapon %s" % weap, color=ChatColor.Cyan) await self.server.broadcast_gamedata(MSG_DROP_WEAPON(player, self.server.new_oid(), weap, 255).to_packet()) if command[0] == "coords": await player.send_message("You are at (%s,%s,%s)" % (player.x, player.y, player.z), color=ChatColor.Cyan) if command[0] == "tp": x = randint(-200,200) y = randint(-200,200) z = randint(-200,200) o = 0 await player.send_message("Teleporting you to (%s,%s,%s)" % (x, y, z), color=ChatColor.Cyan) await self.server.broadcast_gamedata(MSG_PLAYER_TELEPORT(player, x, y, z, o).to_packet()) if len(command) > 1 and command[0] == "fire": weap = int(command[1]) if len(command) > 2: i = int(command[2]) else: i = 1 for _ in range(i): x = randint(-200, 200) y = randint(-200, 200) z = randint(-200, 200) o = 0 await player.send_message("Firing to (%s,%s,%s)" % (x, y, z), color=ChatColor.Cyan) await self.server.broadcast_gamedata(MSG_NEW_PROJECTILE(player, self.server.new_oid(), weap, x, y, z, o).to_packet()) if command[0] == "popup": await player.send_message("Spawned popup", color=ChatColor.Cyan) await self.server.broadcast_gamedata(bytes.fromhex("09160000000438000002250000000a000000040700000913000000040700001102000000041d00000a090e00000004380000032500000000")) def setup(server): plugin = Commands(server) server.add_plugin(plugin)