Added map download

This commit is contained in:
Amazed 2019-03-05 01:49:13 +01:00
parent 877d79f4d1
commit 88573a22b2
2 changed files with 45 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import os
from .packet import Packet
from .EnumQuery import EnumQuery
from .EnumResponse import EnumResponse
@ -559,6 +561,48 @@ class Netserver(asyncio.DatagramProtocol):
await self.server.broadcast_event("on_player_left", player)
await self.server.remove_player(player)
elif payload[0] == 0x4d:
# CLIENT DOWNLOAD MAP
player = self.get_player(session)
if not player:
logger.debug("Fuck that no player wtf man")
return
payload = Packet()
payload.putByte(0x4e) # packet opcode
#payload.putByte(0x9d) # packet opcode?
mapsize = os.stat("maps/"+self.server.currentmap.mappath).st_size
payload.putULong(mapsize) # map size
payload.putBytes((self.server.currentmap.mapname+"\x00"*(128-len(self.server.currentmap.mapname))).encode("ascii"))
await player.session.send_gamedata(payload.getvalue())
with open("maps/"+self.server.currentmap.mappath, "rb") as fh:
data = fh.read(512)
while data != b"":
if len(data) == 512:
# full packet
mapdl = Packet()
mapdl.putByte(0x4f) # opcode
mapdl.putByte(0x00) # unknown
mapdl.putByte(0x02) # unknown
mapdl.putByte(0x00) # unknown
mapdl.putByte(0x00) # unknown
mapdl.putBytes(data)
mapdl.putByte(0x00) # ending
await player.session.send_gamedata(mapdl.getvalue(), acknow=False) # map chunk
else:
# last packet
mapdl = Packet()
mapdl.putByte(0x4f) # opcode
mapdl.putULong(len(data)) # map end length
mapdl.putBytes(data)
# fill with crap at the end
mapdl.putBytes(b"\x00"*(512-len(data)))
mapdl.putByte(0x00) # ending
await player.session.send_gamedata(mapdl.getvalue(), acknow=False) # map chunk
data = fh.read(512)
def send_packet(self, addr, packet):

View File

@ -22,7 +22,7 @@ class Server:
self.register_with_ms = kwargs.get("register", False)
self.teams = kwargs.get("teams", Teams.MvM)
self.game_type = kwargs.get("gametype", GameTypes.TeamDeathmatchWithFullBase)
self.currentmap = kwargs.get("map", Map("test3.gck"))
self.currentmap = kwargs.get("map", Map("Testmap.gck"))
self.maxplayers = kwargs.get("maxplayers", 20)
self.name = kwargs.get("name", "Default Server Name")