mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-17 16:25:36 +00:00
DO Sync cars;
DO Create cars;
This commit is contained in:
parent
580b836e39
commit
5953923368
@ -60,7 +60,7 @@ class Client:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def cars(self):
|
def cars(self):
|
||||||
return self.cars
|
return self._cars
|
||||||
|
|
||||||
def _update_logger(self):
|
def _update_logger(self):
|
||||||
self._log = utils.get_logger(f"{self.nick}:{self.cid}")
|
self._log = utils.get_logger(f"{self.nick}:{self.cid}")
|
||||||
@ -258,11 +258,13 @@ class Client:
|
|||||||
self.__alive = False
|
self.__alive = False
|
||||||
break
|
break
|
||||||
|
|
||||||
# V to Y
|
# Codes: V W X Y
|
||||||
if 89 >= data[0] >= 86:
|
if 89 >= data[0] >= 86:
|
||||||
await self._send(data, to_all=True, to_self=False)
|
await self._send(data, to_all=True, to_self=False)
|
||||||
|
|
||||||
code = chr(data[0])
|
data = data.decode('utf-8')
|
||||||
|
|
||||||
|
code = data[0]
|
||||||
self.log.debug(f"Received code: {code}, data: {data}")
|
self.log.debug(f"Received code: {code}, data: {data}")
|
||||||
match code:
|
match code:
|
||||||
case "H":
|
case "H":
|
||||||
@ -275,14 +277,14 @@ class Client:
|
|||||||
await self._send(f"JWelcome {self.nick}!", to_all=True) # Hello message
|
await self._send(f"JWelcome {self.nick}!", to_all=True) # Hello message
|
||||||
self._ready = True
|
self._ready = True
|
||||||
|
|
||||||
# TODO: Sync cars
|
for client in self.__Core.clients:
|
||||||
# for client in self.__Core.clients:
|
if not client:
|
||||||
# for car in client.cars:
|
continue
|
||||||
# await self._tcp_send(car)
|
for car in client.cars:
|
||||||
|
await self._send(car)
|
||||||
|
|
||||||
case "C":
|
case "C": # Chat handler
|
||||||
# Chat
|
msg = data[4 + len(self.nick):]
|
||||||
msg = data.decode()[4 + len(self.nick):]
|
|
||||||
if not msg:
|
if not msg:
|
||||||
self.log.debug("Tried to send an empty event, ignoring")
|
self.log.debug("Tried to send an empty event, ignoring")
|
||||||
continue
|
continue
|
||||||
@ -317,11 +319,41 @@ class Client:
|
|||||||
if need_send:
|
if need_send:
|
||||||
await self._send(data, to_all=True)
|
await self._send(data, to_all=True)
|
||||||
|
|
||||||
case "O":
|
case "O": # Vehicle info handler
|
||||||
# TODO: ParseVehicle
|
if len(data) < 6:
|
||||||
pass
|
continue
|
||||||
|
sub_code = data[1]
|
||||||
|
data = data[3:]
|
||||||
|
match sub_code:
|
||||||
|
case "s": # Spawn car
|
||||||
|
if data[0] == "0":
|
||||||
|
car_id = len(self._cars)
|
||||||
|
self.log.debug(f"Created a car with ID {car_id}")
|
||||||
|
# car_json = json.loads(data[5:])
|
||||||
|
car_json = data[5:]
|
||||||
|
# TODO: Call event onVehicleSpawn
|
||||||
|
spawn = True
|
||||||
|
pkt = f"Os:{self.roles}:{self.nick}:{self.cid}-{car_id}:{car_json}"
|
||||||
|
if spawn and car_id > config.Game['max_cars']:
|
||||||
|
self._cars.append(car_json)
|
||||||
|
await self._send(pkt, to_all=True)
|
||||||
|
else:
|
||||||
|
await self._send(pkt)
|
||||||
|
des = f"Od:{self.cid}-{car_id}"
|
||||||
|
await self._send(des)
|
||||||
|
case "c": # Edit car
|
||||||
|
# TODO: edit car
|
||||||
|
pass
|
||||||
|
case "d": # Delete car
|
||||||
|
# TODO: delete car
|
||||||
|
pass
|
||||||
|
case "r": # Reset car
|
||||||
|
# TODO: reset car
|
||||||
|
pass
|
||||||
|
case "t" | "m":
|
||||||
|
pass
|
||||||
|
|
||||||
case "E":
|
case "E": # Client events handler
|
||||||
# TODO: HandleEvent
|
# TODO: HandleEvent
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -329,9 +361,6 @@ class Client:
|
|||||||
# TODO: N
|
# TODO: N
|
||||||
pass
|
pass
|
||||||
|
|
||||||
case _:
|
|
||||||
pass
|
|
||||||
|
|
||||||
async def _remove_me(self):
|
async def _remove_me(self):
|
||||||
await asyncio.sleep(0.3)
|
await asyncio.sleep(0.3)
|
||||||
self.__alive = False
|
self.__alive = False
|
||||||
|
@ -29,6 +29,7 @@ class Client:
|
|||||||
self._guest = True
|
self._guest = True
|
||||||
self.__alive = True
|
self.__alive = True
|
||||||
self._ready = False
|
self._ready = False
|
||||||
|
self._cars = []
|
||||||
@property
|
@property
|
||||||
def _writer(self) -> StreamWriter: ...
|
def _writer(self) -> StreamWriter: ...
|
||||||
@property
|
@property
|
||||||
@ -43,6 +44,8 @@ class Client:
|
|||||||
def guest(self) -> bool: ...
|
def guest(self) -> bool: ...
|
||||||
@property
|
@property
|
||||||
def ready(self) -> bool: ...
|
def ready(self) -> bool: ...
|
||||||
|
@property
|
||||||
|
def cars(self) -> list: ...
|
||||||
def is_disconnected(self) -> bool: ...
|
def is_disconnected(self) -> bool: ...
|
||||||
async def kick(self, reason: str) -> None: ...
|
async def kick(self, reason: str) -> None: ...
|
||||||
async def _send(self, data: bytes | str, to_all: bool = False, to_self: bool = True, to_udp: bool = False, writer: StreamWriter = None) -> None: ...
|
async def _send(self, data: bytes | str, to_all: bool = False, to_self: bool = True, to_udp: bool = False, writer: StreamWriter = None) -> None: ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user