mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-17 16:25:36 +00:00
Fix car spawning
This commit is contained in:
parent
e3e5c6ecbb
commit
a73b14f9b4
@ -5,6 +5,7 @@
|
|||||||
# Licence: FPA
|
# Licence: FPA
|
||||||
# (c) kuitoi.su 2023
|
# (c) kuitoi.su 2023
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
import math
|
import math
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ class Client:
|
|||||||
|
|
||||||
if int_header > 100 * MB:
|
if int_header > 100 * MB:
|
||||||
await self.kick("Header size limit exceeded")
|
await self.kick("Header size limit exceeded")
|
||||||
self.log.warn(f"Client {self.nick}:{self.cid} sent header of >100MB - "
|
self.log.warning(f"Client {self.nick}:{self.cid} sent header of >100MB - "
|
||||||
f"assuming malicious intent and disconnecting the client.")
|
f"assuming malicious intent and disconnecting the client.")
|
||||||
return b""
|
return b""
|
||||||
|
|
||||||
@ -324,18 +325,25 @@ class Client:
|
|||||||
continue
|
continue
|
||||||
sub_code = data[1]
|
sub_code = data[1]
|
||||||
data = data[3:]
|
data = data[3:]
|
||||||
|
vid = -1
|
||||||
|
pid = -1
|
||||||
match sub_code:
|
match sub_code:
|
||||||
case "s": # Spawn car
|
case "s": # Spawn car
|
||||||
if data[0] == "0":
|
if data[0] == "0":
|
||||||
car_id = len(self._cars)
|
car_id = len(self._cars)
|
||||||
self.log.debug(f"Created a car with ID {car_id}")
|
self.log.debug(f"Created a car with ID {car_id}")
|
||||||
# car_json = json.loads(data[5:])
|
car_data = data[2:]
|
||||||
car_json = data[5:]
|
car_json = {}
|
||||||
|
try:
|
||||||
|
car_json = json.loads(data[5:])
|
||||||
|
except Exception as e:
|
||||||
|
self.log.debug(f"Invalid car_json: Error: {e}; Data: {car_data}")
|
||||||
# TODO: Call event onVehicleSpawn
|
# TODO: Call event onVehicleSpawn
|
||||||
spawn = True
|
spawn = True
|
||||||
pkt = f"Os:{self.roles}:{self.nick}:{self.cid}-{car_id}:{car_json}"
|
pkt = f"Os:{self.roles}:{self.nick}:{self.cid}-{car_id}:{car_data}"
|
||||||
if spawn and car_id > config.Game['max_cars']:
|
if spawn and (config.Game['max_cars'] > car_id or car_json.get("jbm") == "unicycle"):
|
||||||
self._cars.append(car_json)
|
self.log.debug(f"Car spawn accepted.")
|
||||||
|
self._cars.append(car_data)
|
||||||
await self._send(pkt, to_all=True)
|
await self._send(pkt, to_all=True)
|
||||||
else:
|
else:
|
||||||
await self._send(pkt)
|
await self._send(pkt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user