Having fun spawning things

This commit is contained in:
Amazed 2019-03-05 03:58:01 +01:00
parent 88573a22b2
commit d946f792cd
5 changed files with 140 additions and 13 deletions

View File

@ -531,10 +531,16 @@ class Netserver(asyncio.DatagramProtocol):
logger.debug("Fuck that no player wtf man")
return
p = Packet(payload)
opcode = p.getShort()
unknown1 = p.getULong()
unknown2 = p.getULong()
unknown3 = p.getULong()
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()
playerx = p.getFloat()
playery = p.getFloat()
playerz = p.getFloat()
@ -542,16 +548,19 @@ class Netserver(asyncio.DatagramProtocol):
unknown5 = p.getULong()
unknown6 = p.getULong()
unknown7 = p.getULong()
unknown8 = p.getULong()
orientation = p.getULong() # orientation
unknown9 = p.getULong()
player.x = playerx
player.y = playery
player.z = playerz
player.oid = objid
player.o = orientation
#logger.info("%s is now at coords (%s,%s,%s)", player.name, player.x, player.y, player.z)
#await self.server.broadcast_message("%s is now at coords (%s,%s,%s)" % (player.name, player.x, player.y, player.z))
await player.session.send_gamedata(b"", acknow=False)
await self.server.broadcast_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))
elif payload[0] == 0x3a:
# CLIENT EXITED
player = self.get_player(session)

View File

@ -31,6 +31,8 @@ class Map:
return b"\xc7\x5f\x61\x1f"
if mappath == "test3.gck":
return b"\x59\xbb\xab\x52"
if mappath == "Testmap.gck":
return b"\x74\x07\x98\xaf"
# \x00\x00\x00\x00: [None]
# \x00\x00\x00\x01: <custom map>
# \x9c\x53\xf4\xdd: Three Way Island - Canyons

View File

@ -25,6 +25,7 @@ class Player(Entity):
self.id = random.getrandbits(16)
self.phase = PlayerPhases.NONE
self.ping = 1
self.oid = 0
async def change_team(self, newteam):
self.team = newteam

View File

@ -6,7 +6,6 @@ import struct
class Commands:
def __init__(self, server):
self.server = server
self._nextid = 118
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)
@ -60,8 +59,16 @@ class Commands:
await player.session.send_gamedata(bytes.fromhex("0b1a0000000002070000a5b0d4c35d9714c450abef354a68fb410914000000020700000402000000")+struct.pack("<L",diemethod)+bytes.fromhex("0000"))
if command[0] == "spawn" and len(command) > 1:
await self.server.broadcast_message("Spawning "+command[1]+"")
await self.server.spawn(self._nextid, "00", command[1])
await self.server.broadcast_message("Spawning " + command[1] + "")
await self.server.spawn(player, 0, 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]))
def setup(server):

114
server.py
View File

@ -1,3 +1,4 @@
from dpnet.packet import Packet
from giants.map import Map
from giants.player import Player
from dpnet.netserver import Netserver
@ -56,6 +57,8 @@ class Server:
self.running = True
self.ticks = 60
self._nextid = 118
def update(self):
#logger.debug("Calling update")
pass
@ -144,10 +147,115 @@ class Server:
continue
await pplayer.send_message(text, color=color, type=type)
async def spawn(self, objid, plix, model):
await self.broadcast_gamedata(bytes.fromhex("05" + plix + struct.pack("<B", objid).hex() + "0000" + model + "00000000"), acknow=False)
await self.broadcast_gamedata(bytes.fromhex("0a32000000" + plix + struct.pack("<B", objid).hex() + "000001" + model + "000000ff00000000000000000000000000000000000000000000000000000000000000000000000a12000000" + plix + struct.pack("<B", objid).hex() + "0000" + model + "020000000000000000"), acknow=False)
async def spawn(self, player, plix, model):
p = Packet()
p.putByte(0x05) # opcode
p.putByte(plix)
p.putShort(self._nextid)
p.putByte(0x00)
p.putULong(model)
p.putByte(0x00)
await self.broadcast_gamedata(p.getvalue(), acknow=False)
#await self.broadcast_gamedata(bytes.fromhex("05" + plix + struct.pack("<H", self._nextid).hex() + "00" + model + "00000000"), acknow=False)
p = Packet()
p.putByte(0x0a) # opcode
p.putByte(0x12) # length
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(plix) # player index
p.putShort(self._nextid) # object id
p.putByte(0x00) # unknown
p.putByte(0x01) # unknown
p.putULong(model) # model
p.putFloat(player.x) # player x
p.putFloat(player.y) # player y
p.putFloat(player.z) # player z
p.putULong(0x00) # unknown
p.putULong(0x00) # unknown
p.putULong(0x00) # unknown
p.putULong(0x00) # unknown
p.putULong(0x00) # orientation
p.putULong(0x00) # unknown
await self.broadcast_gamedata(p.getvalue(), acknow=False)
self._nextid+=1
#await self.broadcast_gamedata(bytes.fromhex("0a12000000" + plix + struct.pack("<H", self._nextid).hex() + "0003" + model + "00000000"), acknow=False)
#await self.broadcast_gamedata(bytes.fromhex("0a32000000" + plix + struct.pack("<B", self._nextid).hex() + "000001" + model + "000000ff00000000000000000000000000000000000000000000000000000000000000000000000a12000000" + plix + struct.pack("<B", self._nextid).hex() + "0000" + model + "020000000000000000"), acknow=False)
async def change_model(self, player, model):
plid = self.get_player_index(player)
# p = Packet()
# p.putByte(0x0a) # opcode
# p.putByte(0x12) # length
# p.putByte(0x00) # unknown
# p.putByte(0x00) # unknown
# p.putByte(0x00) # unknown
# p.putByte(plid) # player index
# p.putShort(player.oid) # object id
# p.putByte(0x00) # unknown
# p.putByte(0x02) # 4 -> death, 3 -> little move
# p.putULong(model) # model
# p.putFloat(player.x) # x
# p.putFloat(player.y) # y
# p.putFloat(player.z) # z
# p.putULong(0x00) # unknown
# p.putULong(0x00) # unknown
# p.putULong(0x00) # unknown
# p.putULong(0x00) # unknown
# p.putULong(player.o + 30) # orientation
# p.putULong(0x00) # unknown
p = Packet()
p.putByte(0x0a) # opcode
p.putByte(0x32) # length
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(plid) # player index
p.putShort(player.oid) # object id
p.putByte(0x00) # unknown
p.putByte(0x01) # 1 -> stand still, 4 -> death, 3 -> little move
p.putULong(model) # model
p.putFloat(0x00) # x
p.putFloat(player.y) # y
p.putFloat(player.z) # z
p.putULong(0x00) # unknown
p.putULong(0x00) # unknown
p.putULong(0x00) # unknown
p.putULong(0x00) # unknown
p.putULong((player.o + 30) % 360) # orientation
p.putULong(0x00) # unknown
p.putByte(0x0a) # opcode
p.putByte(0x12) # length
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(plid) # player index
p.putShort(player.oid) # object id
p.putByte(0x00) # unknown
p.putByte(0x00) # 1 -> stand still, 4 -> death, 3 -> little move
p.putULong(model) # model
p.putULong(0x00)
p.putByte(0x00)
p.putByte(0x00)
await self.broadcast_gamedata(p.getvalue(), acknow=False)
#await self.broadcast_gamedata(bytes.fromhex("0a32000000" + plix + struct.pack("<B", objid).hex() + "000001" + model + "000000ff00000000000000000000000000000000000000000000000000000000000000000000000a12000000" + plix + struct.pack("<B", objid).hex() + "0000" + model + "020000000000000000"), acknow=False)
def get_player_index(self, player):
for iplayer in range(len(self.players)):
if self.players[iplayer] == player:
return iplayer
return False
def get_player_by_index(self, playerindex):
return self.players[playerindex]
if __name__ == '__main__':
server = Server(name="giantsd", maxplayers=20, register=False, teams=Teams.MvM) #, map=Map("Three Way Island - Canyons.gck"))