giants-stupid-server/dpnet/gamepackets.py

190 lines
5.1 KiB
Python
Raw Normal View History

2019-03-13 01:37:49 +01:00
from dpnet.packet import Packet
class MSG_CHANGE_TEAM():
def __init__(self, player, teamid: int, respawn: bool = True):
self.player = player
self.teamid = teamid
self.respawn = respawn
if self.teamid > 255:
raise ValueError("Team ID must be < 256")
def to_packet(self):
p = Packet()
p.putByte(0x10) # opcode
p.putByte(self.teamid)
p.putULong(self.player.id)
p.putByte(self.respawn)
p.putByte(0x00) # end
return p.getvalue()
class MSG_MOVE_PLAYER():
def __init__(self, player, direction, orientation):
self.player = player
self.direction = direction
self.orientation = orientation
def to_packet(self):
p = Packet()
p.putByte(0x0f) # opcode
p.putByte(0x12) # opcode2?
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putByte(self.player) # player index
p.putShort(self.player.oid)
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putULong(self.player.model())
p.putShort(self.direction)
p.putShort(self.orientation)
p.putByte(0x00) # end
return p.getvalue()
class MSG_PLAYER_PING():
def __init__(self, player, ping):
self.player = player
self.ping = ping
def to_packet(self):
p = Packet()
p.putByte(0x2f) # opcode
p.putByte(self.player.get_index())
p.putByte(0x00) # unknown
p.putByte(0x00) # unknown
p.putShort(self.ping) # ping
p.putByte(0x00) # end
return p.getvalue()
class MSG_SWITCH_WEAPON():
def __init__(self, player, newweapon):
self.player = player
self.newweapon = newweapon
def to_packet(self):
p = Packet()
p.putByte(0x09) # opcode
p.putByte(0x0f) # opcode2?
p.putByte(0x00)
p.putShort(0x0000)
p.putByte(self.player.get_index())
p.putShort(self.player.oid)
p.putByte(0x00)
p.putByte(0x0a)
p.putULong(0x02)
p.putByte(self.newweapon)
p.putByte(0x00) # end
return p.getvalue()
class MSG_DROP_WEAPON():
def __init__(self, player, oid, weapon, ammo):
self.player = player
self.weapon = weapon
self.ammo = ammo
self.oid = oid
def to_packet(self):
p = Packet()
p.putByte(0x20) # opcode
# TODO: fixit
p.putShort(0x012e) # can also be 1303 ... oid? my oid was 7 at the time
#p.putShort(self.oid) # can also be 1303 ... oid? my oid was 7 at the time
p.putShort(0x0000)
p.putByte(self.player.get_index())
p.putByte(0x38)
p.putShort(0x0000)
p.putFloat(self.player.x)
p.putFloat(self.player.y)
p.putFloat(self.player.z)
p.putFloat(self.player.o)
p.putFloat(0xc79e28c1) # ??
p.putShort(0x0000)
p.putULong(0x70410000)
p.putByte(self.weapon)
p.putByte(0x00)
p.putULong(self.ammo)
p.putShort(0x0000)
p.putShort(0x0000)
p.putByte(0x00)
return p.getvalue()
class MSG_BULLET_EXPLOSION():
def __init__(self, player, projectile, x, y, z):
self.player = player
self.projectile = projectile
self.x = x
self.y = y
self.z = z
def to_packet(self):
p = Packet()
p.putByte(0x09) # opcode
p.putULong(0x1a)
p.putByte(self.player.get_index())
p.putShort(0x0631)
p.putByte(0x00)
p.putByte(0x03)
p.putULong(0x4d)
p.putFloat(self.x)
p.putFloat(self.y)
p.putFloat(self.z)
p.putByte(0x00)
return p.getvalue()
class MSG_PLAYER_DIE():
def __init__(self, player, deathtype):
self.player = player
self.deathtype = deathtype
def to_packet(self):
p = Packet()
p.putByte(0x0b) # opcode
p.putULong(0x1a)
p.putByte(0x00)
p.putByte(self.player.get_index())
p.putByte(0x07)
p.putShort(0x0000)
p.putFloat(self.player.x)
p.putFloat(self.player.y)
p.putFloat(self.player.z)
p.putFloat(self.player.o)
p.putShort(0x1409) # oid?
p.putByte(0x00)
p.putShort(0x0000)
p.putByte(self.player.get_index())
p.putByte(0x07)
p.putShort(0x0000)
p.putByte(0x04)
p.putByte(0x02)
p.putShort(0x0000)
p.putByte(0x00)
p.putULong(self.deathtype)
p.putByte(0x00)
p.putByte(0x00) # end
return p.getvalue()
class MSG_PLAYER_TELEPORT():
def __init__(self, player, newx, newy, newz, newo):
self.player = player
self.newx = newx
self.newy = newy
self.newz = newz
self.newo = newo
def to_packet(self):
p = Packet()
p.putByte(0x13) # opcode
p.putByte(self.player.get_index())
p.putShort(self.player.oid)
p.putByte(0x00)
p.putFloat(0x00000000)
p.putFloat(self.newx)
p.putFloat(self.newy)
p.putFloat(self.newz)
p.putByte(0x00)
return p.getvalue()