mirror of
https://github.com/Wesley-DeMontigny/WLUS.git
synced 2026-05-02 14:29:18 -05:00
Added Character Deletion
Character Deletion works fine, need to add chracter_stats and character info tables into the character creation process. The queries are there, but commented out. There seems to be some problem with the database that I'll have to fix later
This commit is contained in:
@@ -13,6 +13,10 @@ class Plugin:
|
||||
packet_enum.PacketHeader.CLIENT_USER_SESSION_INFO.value)
|
||||
parent.register_handler(Plugin.handle_minifigure_creation,
|
||||
packet_enum.PacketHeader.CLIENT_MINIFIGURE_CREATE_REQUEST.value)
|
||||
parent.register_handler(Plugin.handle_load_world,
|
||||
packet_enum.PacketHeader.CLIENT_ENTER_WORLD.value)
|
||||
parent.register_handler(Plugin.handle_minifigure_delete,
|
||||
packet_enum.PacketHeader.CLIENT_DELETE_MINIFIGURE_REQUEST.value)
|
||||
|
||||
@classmethod
|
||||
def handle_handshake(cls, data: bytes, address, server):
|
||||
@@ -31,6 +35,35 @@ class Plugin:
|
||||
packet.write(server_handshake)
|
||||
server.send(packet, address)
|
||||
|
||||
@classmethod
|
||||
def handle_load_world(cls, data: bytes, address, server):
|
||||
"""
|
||||
Handles when the user hits the play button.
|
||||
"""
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def handle_minifigure_delete(cls, data: bytes, address, server):
|
||||
"""
|
||||
Handles when the user deletes a minifigure.
|
||||
"""
|
||||
stream = ReadStream(data)
|
||||
character_id = stream.read(client_to_world.CharacterDeleteRequestPacket).object_id
|
||||
c = server.db_connection.cursor()
|
||||
session = server.lookup_session_by_ip(address[0])
|
||||
c.execute("SELECT account_id FROM wlus.account WHERE username = %s", (session["username"],))
|
||||
account_id = c.fetchone()[0]
|
||||
c.execute("SELECT * FROM wlus.character WHERE account_id = %s AND character_id = %s",
|
||||
(account_id, int(character_id)))
|
||||
data = c.fetchone()
|
||||
if data:
|
||||
c.execute("DELETE FROM wlus.character WHERE account_id = %s AND character_id = %s",
|
||||
(account_id, int(character_id)))
|
||||
c.execute("DELETE FROM wlus.inventory WHERE player_id = %s", (int(character_id),))
|
||||
c.execute("DELETE FROM wlus.character_stats WHERE player_id = %s", (int(character_id),))
|
||||
c.execute("DELETE FROM wlus.character_info WHERE player_id = %s", (int(character_id),))
|
||||
server.db_connection.commit()
|
||||
|
||||
@classmethod
|
||||
def handle_minifigure_creation(cls, data: bytes, address, server):
|
||||
c = server.db_connection.cursor()
|
||||
|
||||
@@ -18,6 +18,91 @@ class CString(bitstream.Serializable):
|
||||
return stream.read(bytes, allocated_length=self.allocated_length, length_type=self.length_type).decode('latin1')
|
||||
|
||||
|
||||
class Vector3(bitstream.Serializable):
|
||||
def __init__(self):
|
||||
self.x: float = 0.0
|
||||
self.y: float = 0.0
|
||||
self.z: float = 0.0
|
||||
|
||||
def __add__(self, other):
|
||||
result = Vector3()
|
||||
result.x = self.x + other.x
|
||||
result.y = self.y + other.y
|
||||
result.z = self.z + other.z
|
||||
return result
|
||||
|
||||
def __sub__(self, other):
|
||||
result = Vector3()
|
||||
result.x = self.x - other.x
|
||||
result.y = self.y - other.y
|
||||
result.z = self.z - other.z
|
||||
return result
|
||||
|
||||
def __eq__(self, other):
|
||||
if self.x == other.x and self.y == other.y and self.z == other.z:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def deserialize(cls, stream: bitstream.ReadStream) -> bitstream.Serializable:
|
||||
result = Vector3()
|
||||
result.x = stream.read(bitstream.c_float)
|
||||
result.y = stream.read(bitstream.c_float)
|
||||
result.z = stream.read(bitstream.c_float)
|
||||
return result
|
||||
|
||||
def serialize(self, stream: bitstream.WriteStream) -> None:
|
||||
stream.write(bitstream.c_float(self.x))
|
||||
stream.write(bitstream.c_float(self.y))
|
||||
stream.write(bitstream.c_float(self.z))
|
||||
|
||||
|
||||
class Vector4(bitstream.Serializable):
|
||||
def __init__(self):
|
||||
self.x: float = 0.0
|
||||
self.y: float = 0.0
|
||||
self.z: float = 0.0
|
||||
self.w: float = 0.0
|
||||
|
||||
def __add__(self, other):
|
||||
result = Vector3()
|
||||
result.x = self.x + other.x
|
||||
result.y = self.y + other.y
|
||||
result.z = self.z + other.z
|
||||
result.w = self.w + other.w
|
||||
return result
|
||||
|
||||
def __sub__(self, other):
|
||||
result = Vector3()
|
||||
result.x = self.x - other.x
|
||||
result.y = self.y - other.y
|
||||
result.z = self.z - other.z
|
||||
result.w = self.w - other.w
|
||||
return result
|
||||
|
||||
def __eq__(self, other):
|
||||
if self.x == other.x and self.y == other.y and self.z == other.z and self.w == other.w:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def deserialize(cls, stream: bitstream.ReadStream) -> bitstream.Serializable:
|
||||
result = Vector3()
|
||||
result.x = stream.read(bitstream.c_float)
|
||||
result.y = stream.read(bitstream.c_float)
|
||||
result.z = stream.read(bitstream.c_float)
|
||||
result.w = stream.read(bitstream.c_float)
|
||||
return result
|
||||
|
||||
def serialize(self, stream: bitstream.WriteStream) -> None:
|
||||
stream.write(bitstream.c_float(self.x))
|
||||
stream.write(bitstream.c_float(self.y))
|
||||
stream.write(bitstream.c_float(self.z))
|
||||
stream.write(bitstream.c_float(self.w))
|
||||
|
||||
|
||||
class LwoObjID:
|
||||
"""
|
||||
This is the data type that object ids are made out of.
|
||||
@@ -189,4 +274,17 @@ class LoginCharacter(bitstream.Serializable):
|
||||
item_id = LwoObjID.gen_lwoobjid()
|
||||
c.execute("INSERT INTO wlus.inventory (object_id, lot, slot, equipped, linked, quantity, player_id)"
|
||||
"VALUES (%s, %s, %s, 1, 1, 1, %s)", (item_id, self.equipped_items[i], i, self.object_id))
|
||||
"""
|
||||
c.execute('INSERT INTO `wlus`.`character_info` (`player_id`,`position`,`rotation`,`health`,`max_health`,'
|
||||
'`armor`,`max_armor`,`imagination`,`max_imagination`,`backpack_space`,`currency`,`universe_score`'
|
||||
',`level`) VALUES (%s,"0,0,0","0,0,0,0",4,4,0,0,0,0,20,0,0,0);', (self.object_id,))
|
||||
c.execute('INSERT INTO `wlus`.`character_stats`(`currency_collected`,`bricks_collected`,'
|
||||
'`smashables_smashed`,`quick_builds_done`,`enemies_smashed`,`rockets_used`,`pets_tamed`,'
|
||||
'`imagination_collected`,`health_collected`,`armor_collected`,`distance_traveled`,`times_died`,'
|
||||
'`damage_taken`,`damage_healed`,`armor_repaired`,`imagination_restored`,`imagination_used`,'
|
||||
'`distance_driven`,`time_airborne_in_car`,`racing_imagination_collected`,'
|
||||
'`racing_imagination_crates_smashed`,`race_car_boosts`,`car_wrecks`,`racing_smashables_smashed`,'
|
||||
'`races_finished`,`races_won`,`player_id`) VALUES '
|
||||
'(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,%s);', (self.object_id,))
|
||||
"""
|
||||
connection.commit()
|
||||
|
||||
@@ -19,7 +19,7 @@ class PacketHeader(Enum):
|
||||
MINIFIGURE_CREATION_RESPONSE = b"S\x05\x00\x08\x00\x00\x00\x00"
|
||||
CLIENT_DELETE_MINIFIGURE_REQUEST = b'S\x04\x00\x06\x00\x00\x00\x00'
|
||||
WORLD_INFO = b'S\x05\x00\x02\x00\x00\x00\x00'
|
||||
CLINET_ENTER_WORLD = b'S\x04\x00\x04\x00\x00\x00\x00'
|
||||
CLIENT_ENTER_WORLD = b'S\x04\x00\x04\x00\x00\x00\x00'
|
||||
CLIENT_LOAD_COMPLETE = b'S\x04\x00\x13\x00\x00\x00\x00'
|
||||
DETAILED_USER_INFO = b'S\x05\x00\x04\x00\x00\x00\x00'
|
||||
ROUTED_PACKET = b'S\x04\x00\x15\x00\x00\x00\x00'
|
||||
|
||||
Reference in New Issue
Block a user