Compare commits

...

2 Commits

Author SHA1 Message Date
Amazed 5b6820b8b3 Merge remote-tracking branch 'origin/master' 2019-03-13 01:40:02 +01:00
Amazed 6cb80fd276 New opcodes, new logic, WIP instagib 2019-03-13 01:39:49 +01:00
4 changed files with 260 additions and 0 deletions

190
dpnet/gamepackets.py Normal file
View File

@ -0,0 +1,190 @@
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()

5
giants/gameobject.py Normal file
View File

@ -0,0 +1,5 @@
from giants.entity import Entity
class GameObject(Entity):
pass

6
giants/projectile.py Normal file
View File

@ -0,0 +1,6 @@
from giants.entity import Entity
class Projectile(Entity):
def __init__(self):
super().__init__()

59
plugins/instagib.py Normal file
View File

@ -0,0 +1,59 @@
from dpnet.packet import Packet
from dpnet.gamepackets import *
from random import randint
class Instagib:
def __init__(self, server):
self.server = server
async def on_player_spawn(self, player):
await self.server.broadcast_message("%s has spawned" % player.name)
# random teleport
await self.random_teleport(player)
# give stuff
await self.give_stuff(player)
async def on_player_respawn(self, player):
await self.server.broadcast_message("%s has respawned" % player.name)
# random teleport
await self.random_teleport(player)
# give stuff
await self.give_stuff(player)
async def on_player_shoot(self, player):
await self.spawn_sniper(player)
async def on_player_hit(self, player, shooter, damage, weapon):
# make player die
await self.server.broadcast_gamedata(MSG_PLAYER_DIE(player, 1))
async def give_stuff(self, player):
# remove current weapon
await self.remove_current_weapon(player)
# add sniper
await self.spawn_sniper(player)
async def spawn_sniper(self, player):
await self.server.broadcast_gamedata(MSG_DROP_WEAPON(player, self.server._nextid, 6, 255).to_packet())
self.server._nextid += 1
async def remove_current_weapon(self, player):
await self.server.broadcast_gamedata(MSG_SWITCH_WEAPON(player, 0xff).to_packet())
async def random_teleport(self, player):
# random teleport
maxdist = 300
x = randint(-(maxdist/2), maxdist/2)
y = randint(-(maxdist/2), maxdist/2)
z = randint(-(maxdist/2), maxdist/2)
await self.server.broadcast_gamedata(MSG_PLAYER_TELEPORT(player, x, y, z).to_packet())
def setup(server):
plugin = Instagib(server)
server.add_plugin(plugin)