Added debug command, WIP sync joining and leaving

This commit is contained in:
Amazed 2019-03-11 21:18:30 +01:00
parent 1589188357
commit 892b7c8ad4
5 changed files with 117 additions and 11 deletions

View File

@ -138,7 +138,7 @@ class DN_MSG_INTERNAl_SEND_CONNECT_INFO(DFrame):
packet.putULong(self.dwReplySize)
packet.putULong(self.dwSize)
packet.putULong(self.dwFlags)
packet.putULong(self.dwMaxPlayers)
packet.putLong(self.dwMaxPlayers)
packet.putULong(self.dwCurrentPlayers)
packet.putULong(self.dwSessionNameOffset)
packet.putULong(self.dwSessionNameSize)

View File

@ -369,6 +369,7 @@ class Netserver(asyncio.DatagramProtocol):
player.phase = PlayerPhases.DN_SEND_CONNECT_INFO
elif payload[0] == 0xc3:
# CMESG_CONNECTED
player = self.get_temp_player(session)
if not player or not player.phase == PlayerPhases.DN_SEND_CONNECT_INFO:
return
@ -485,16 +486,22 @@ class Netserver(asyncio.DatagramProtocol):
await player.session.send_gamedata(b"\x10" + struct.pack("<B", player.team) + struct.pack("<L", player.id) + b"\x00\x00", acknow=False)
# spawn server as mecc
await player.session.send_gamedata(bytes.fromhex("05007300000200000000"), acknow=False)
await player.session.send_gamedata(bytes.fromhex("0a320000000073000001020000000000000000000000000000000000000000000000000000000000000000000000000000000a120000000073000003020000000000000000"), acknow=False)
#await player.session.send_gamedata(bytes.fromhex("05007300000200000000"), acknow=False)
#await player.session.send_gamedata(bytes.fromhex("0a320000000073000001020000000000000000000000000000000000000000000000000000000000000000000000000000000a120000000073000003020000000000000000"), acknow=False)
# spawn Bot 1 as kab
#await player.session.send_gamedata(bytes.fromhex("05017400000100000000"), acknow=False)
#await player.session.send_gamedata(bytes.fromhex("0a320000000174000001010000000000000000000000000000000000000000000000000000000000000000000000000000000a120000000174000003020000000000000000"), acknow=False)
# spawn Bot 2 as reap
await player.session.send_gamedata(bytes.fromhex("05027500000300000000"), acknow=False)
await player.session.send_gamedata(bytes.fromhex("0a320000000275000001030000000000000000000000000000000000000000000000000000000000000000000000000000000a120000000275000003020000000000000000"), acknow=False)
#await player.session.send_gamedata(bytes.fromhex("05027500000300000000"), acknow=False)
#await player.session.send_gamedata(bytes.fromhex("0a320000000275000001030000000000000000000000000000000000000000000000000000000000000000000000000000000a120000000275000003020000000000000000"), acknow=False)
# TODO: spawn all players except himself
await self.spawn_all_players_except(player)
# TODO: spawn player in other sessions
#await self.spawn_player_except(player)
# spawn Bot 3 as <id>
objid = "75"
@ -550,7 +557,7 @@ class Netserver(asyncio.DatagramProtocol):
#logger.info("%s is now at coords (%s,%s,%s)", player.name, player.x, player.y, player.z)
if player.opts["debug"]:
await player.send_message("%s is now at coords (%s,%s,%s, %s). Model: %s" % (player.name, player.x, player.y, player.z, player.o, model))
#await self.server.broadcast_message("(%s,%s,%s, %s,%s)" % (unknown4, unknown5, unknown6, unknown7, unknown9))
await self.server.broadcast_gamedata_except(player, payload)
elif payload[0] == 0x3a:
# CLIENT EXITED
@ -609,6 +616,77 @@ class Netserver(asyncio.DatagramProtocol):
mapdl.putByte(0x00) # ending
await player.session.send_gamedata(mapdl.getvalue(), acknow=False) # map chunk
data = fh.read(512)
elif payload[0] == 0x0a and payload[1] == 0x12:
player = self.get_player(session)
if not player:
logger.debug("Fuck that no player wtf man")
return
p = Packet(payload)
opcode = p.getByte()
length = p.getByte() # length?
unknown1 = p.getByte()
unknown2 = p.getByte()
unknown3 = p.getByte()
playerindex = p.getByte()
objid = p.getShort()
unknown5 = p.getByte()
unknown6 = p.getByte()
model = p.getULong()
direction = p.getShort()
orientation = p.getShort()
if not direction == 0:
if player.opts["debug"]:
await player.send_message("ObjID %s went: %s, o: %s" % (objid, direction, orientation))
await self.server.broadcast_gamedata_except(player, payload)
elif payload[0] == 0x0a and payload[1] == 0x12:
player = self.get_player(session)
if not player:
logger.debug("Fuck that no player wtf man")
return
p = Packet(payload)
opcode = p.getByte()
length = p.getByte() # length?
unknown1 = p.getByte()
unknown2 = p.getByte()
unknown3 = p.getByte()
playerindex = p.getByte()
objid = p.getShort()
unknown5 = p.getByte()
unknown6 = p.getByte()
model = p.getULong()
direction = p.getShort()
orientation = p.getShort()
if not direction == 0:
if player.opts["debug"]:
await player.send_message("ObjID %s went: %s, o: %s" % (objid, direction, orientation))
await self.server.broadcast_gamedata_except(player, payload)
elif payload[0] == 0x05: # SPAWN OBJECT
player = self.get_player(session)
if not player:
logger.debug("Fuck that no player wtf man")
return
p = Packet(payload)
opcode = p.getByte()
plix = p.getByte() # length?
oid = p.getShort()
unknown = p.getByte()
model = p.getULong()
player.oid = oid
await self.server.broadcast_gamedata_except(player, payload)
else:
player = self.get_player(session)
if not player:
logger.debug("Fuck that no player wtf man")
return
if player.opts["debug"]:
await player.send_message("Unknown: %s" % payload.hex())
await self.server.broadcast_gamedata_except(player, payload)
def build_players_dpid(self, exceptplayer=False):
@ -627,6 +705,32 @@ class Netserver(asyncio.DatagramProtocol):
p1 += b'\x00\x00'
return p1
async def spawn_player_except(self, player):
plix = self.server.get_player_index(player)
p = Packet()
p.putByte(0x05) # opcode
p.putByte(plix)
p.putShort(player.oid)
p.putByte(0x00)
p.putULong(2) # 2: mecc
p.putByte(0x00)
await self.server.broadcast_gamedata_except(player, p.getvalue())
async def spawn_all_players_except(self, player):
for pplayer in self.server.players:
if pplayer.name == "[Server]" or pplayer == player:
continue
plix = self.server.get_player_index(pplayer)
p = Packet()
p.putByte(0x05) # opcode
p.putByte(plix)
p.putShort(pplayer.oid)
p.putByte(0x00)
p.putULong(2) # 2: mecc
p.putByte(0x00)
await player.session.send_gamedata(p.getvalue())
def send_packet(self, addr, packet):
self.remotesocket.sendto(packet.getvalue(), addr)
#logger.debug("%s:%s < %s", addr[0], addr[1], packet.getvalue().hex())

View File

@ -60,7 +60,7 @@ class Commands:
if command[0] == "spawn" and len(command) > 1:
await self.server.broadcast_message("Spawning " + command[1] + "")
await self.server.spawn(player, 0, int(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] + "")

View File

@ -3,10 +3,11 @@ import random
class Greetings:
def __init__(self, server):
self.server = server
self.messages = ["Welcome %s!", "Beware! %s has arrived!", "A wild %s appears", "%s has come and is ready to pwn."]
self.join_messages = ["Welcome %s!", "Beware! %s has arrived!", "A wild %s appears.", "%s has come and is ready to pwn."]
self.left_messages = ["%s has left.", "%s has stopped Giants and started playing Apex. Shame!", "A wild %s disappeared.", "%s was happy with the score and left the game."]
async def on_player_join(self, player):
await self.server.broadcast_message(random.choice(self.messages) % player.name)
await self.server.broadcast_message(random.choice(self.join_messages) % player.name)
async def on_map_change(self, newmap):
await self.server.broadcast_message("You are now playing on "+newmap.mapname)
@ -15,7 +16,7 @@ class Greetings:
await self.server.broadcast_message("%s switched to team %s" % (player.name, newteam))
async def on_player_left(self, player):
await self.server.broadcast_message("%s has left the game" % player.name)
await self.server.broadcast_message(random.choice(self.left_messages) % player.name)
def setup(server):

View File

@ -152,7 +152,8 @@ class Server:
continue
await pplayer.send_message(text, color=color, type=type)
async def spawn(self, player, plix, model):
async def spawn(self, player, model):
plix = self.get_player_index(player)
p = Packet()
p.putByte(0x05) # opcode
p.putByte(plix)