Compare commits

..

4 Commits

Author SHA1 Message Date
a73b14f9b4 Fix car spawning 2023-07-16 10:42:34 +03:00
e3e5c6ecbb Update TODOs 2023-07-16 09:50:02 +03:00
5953923368 DO Sync cars;
DO Create cars;
2023-07-16 09:48:53 +03:00
580b836e39 Minor fixes 2023-07-16 09:37:38 +03:00
5 changed files with 74 additions and 29 deletions

View File

@ -11,10 +11,6 @@ BeamingDrive Multiplayer (BeamMP) server compatible with BeamMP clients.
- [x] Private access (Without key, Direct connect)
- [x] Public access (With key, listing in Launcher)
- [X] Player authentication
- [ ] KuiToi System
- [ ] Servers counter
- [ ] Players counter
- [ ] Etc.
- [ ] TCP Server part:
- [x] Handle code
- [x] Understanding BeamMP header
@ -22,21 +18,30 @@ BeamingDrive Multiplayer (BeamMP) server compatible with BeamMP clients.
- [x] Connecting to the world
- [x] Chat
- [x] Players online counter
- [ ] Car state synchronizations _(Codes: We, Vi)_
- [ ] Car synchronizations:
- [x] Spawn cars
- [ ] Edit cars
- [ ] Delete cars
- [ ] Reset cars
- [ ] "ABG:" (compressed data)
- [x] Decompress data
- [ ] Vehicle data _(Code: Os)_
- [ ] Compress data
- [ ] UDP Server part:
- [ ] Players synchronizations _(Code: Zp)_
- [ ] Ping _(Code: p)_
- [x] Additional:
- [ ] KuiToi System
- [ ] Servers counter
- [ ] Players counter
- [ ] Etc.
- [x] Logger
- [x] Just logging
- [x] Log in file
- [x] Log history (.1.log, .2.log, ...)
- [x] Console:
- [x] Tabulation
- [x] _~~(By design)~~_ Static text (bug)
- [x] History
- [x] Autocomplete
- [x] Events System
- [x] Call events
- [x] Create custom events

View File

@ -5,6 +5,7 @@
# Licence: FPA
# (c) kuitoi.su 2023
import asyncio
import json
import math
import zlib
@ -60,7 +61,7 @@ class Client:
@property
def cars(self):
return self.cars
return self._cars
def _update_logger(self):
self._log = utils.get_logger(f"{self.nick}:{self.cid}")
@ -145,8 +146,8 @@ class Client:
if int_header > 100 * MB:
await self.kick("Header size limit exceeded")
self.log.warn(f"Client {self.nick}:{self.cid} sent header of >100MB - "
f"assuming malicious intent and disconnecting the client.")
self.log.warning(f"Client {self.nick}:{self.cid} sent header of >100MB - "
f"assuming malicious intent and disconnecting the client.")
return b""
data = await self.__reader.read(100 * MB)
@ -258,11 +259,13 @@ class Client:
self.__alive = False
break
# V to Y
# Codes: V W X Y
if 89 >= data[0] >= 86:
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}")
match code:
case "H":
@ -275,14 +278,14 @@ class Client:
await self._send(f"JWelcome {self.nick}!", to_all=True) # Hello message
self._ready = True
# TODO: Sync cars
# for client in self.__Core.clients:
# for car in client.cars:
# await self._tcp_send(car)
for client in self.__Core.clients:
if not client:
continue
for car in client.cars:
await self._send(car)
case "C":
# Chat
msg = data.decode()[4 + len(self.nick):]
case "C": # Chat handler
msg = data[4 + len(self.nick):]
if not msg:
self.log.debug("Tried to send an empty event, ignoring")
continue
@ -317,11 +320,48 @@ class Client:
if need_send:
await self._send(data, to_all=True)
case "O":
# TODO: ParseVehicle
pass
case "O": # Vehicle info handler
if len(data) < 6:
continue
sub_code = data[1]
data = data[3:]
vid = -1
pid = -1
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_data = data[2:]
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
spawn = True
pkt = f"Os:{self.roles}:{self.nick}:{self.cid}-{car_id}:{car_data}"
if spawn and (config.Game['max_cars'] > car_id or car_json.get("jbm") == "unicycle"):
self.log.debug(f"Car spawn accepted.")
self._cars.append(car_data)
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
pass
@ -329,9 +369,6 @@ class Client:
# TODO: N
pass
case _:
pass
async def _remove_me(self):
await asyncio.sleep(0.3)
self.__alive = False

View File

@ -29,6 +29,7 @@ class Client:
self._guest = True
self.__alive = True
self._ready = False
self._cars = []
@property
def _writer(self) -> StreamWriter: ...
@property
@ -43,6 +44,8 @@ class Client:
def guest(self) -> bool: ...
@property
def ready(self) -> bool: ...
@property
def cars(self) -> list: ...
def is_disconnected(self) -> bool: ...
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: ...

View File

@ -85,7 +85,7 @@ class Core:
for client in self.clients:
if not client:
continue
out += f"{client._nick}"
out += f"{client.nick}"
if need_cid:
out += f":{client.cid}"
out += ","

View File

@ -52,8 +52,8 @@ class TCPServer:
# TODO: i18n
await client.kick('Invalid key! Please restart your game.')
return False, client
client._nick = res["username"]
client._roles = res["roles"]
client.nick = res["username"]
client.roles = res["roles"]
client._guest = res["guest"]
# noinspection PyProtectedMember
client._update_logger()