Compare commits

..

No commits in common. "a73b14f9b4e712df34617131422481afd0d29d2a" and "4974d48411c0fe7f9c85b96fd65e7083ae181c71" have entirely different histories.

5 changed files with 29 additions and 74 deletions

View File

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

View File

@ -5,7 +5,6 @@
# 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
@ -61,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}")
@ -146,8 +145,8 @@ 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.warning(f"Client {self.nick}:{self.cid} sent header of >100MB - " self.log.warn(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""
data = await self.__reader.read(100 * MB) data = await self.__reader.read(100 * MB)
@ -259,13 +258,11 @@ class Client:
self.__alive = False self.__alive = False
break break
# Codes: V W X Y # V to 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)
data = data.decode('utf-8') code = chr(data[0])
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":
@ -278,14 +275,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
for client in self.__Core.clients: # TODO: Sync cars
if not client: # for client in self.__Core.clients:
continue # for car in client.cars:
for car in client.cars: # await self._tcp_send(car)
await self._send(car)
case "C": # Chat handler case "C":
msg = data[4 + len(self.nick):] # Chat
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
@ -320,48 +317,11 @@ class Client:
if need_send: if need_send:
await self._send(data, to_all=True) await self._send(data, to_all=True)
case "O": # Vehicle info handler case "O":
if len(data) < 6: # TODO: ParseVehicle
continue pass
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": # Client events handler case "E":
# TODO: HandleEvent # TODO: HandleEvent
pass pass
@ -369,6 +329,9 @@ 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

View File

@ -29,7 +29,6 @@ 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
@ -44,8 +43,6 @@ 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: ...

View File

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

View File

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