mirror of
https://github.com/kuitoi/kuitoi-Server.git
synced 2025-08-17 16:25:36 +00:00
Compare commits
4 Commits
4974d48411
...
a73b14f9b4
Author | SHA1 | Date | |
---|---|---|---|
a73b14f9b4 | |||
e3e5c6ecbb | |||
5953923368 | |||
580b836e39 |
19
README.md
19
README.md
@ -11,10 +11,6 @@ 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
|
||||||
@ -22,21 +18,30 @@ 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 state synchronizations _(Codes: We, Vi)_
|
- [ ] Car synchronizations:
|
||||||
|
- [x] Spawn cars
|
||||||
|
- [ ] Edit cars
|
||||||
|
- [ ] Delete cars
|
||||||
|
- [ ] Reset cars
|
||||||
- [ ] "ABG:" (compressed data)
|
- [ ] "ABG:" (compressed data)
|
||||||
- [x] Decompress data
|
- [x] Decompress data
|
||||||
- [ ] Vehicle data _(Code: Os)_
|
- [ ] Compress data
|
||||||
- [ ] 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] _~~(By design)~~_ Static text (bug)
|
- [x] History
|
||||||
|
- [x] Autocomplete
|
||||||
- [x] Events System
|
- [x] Events System
|
||||||
- [x] Call events
|
- [x] Call events
|
||||||
- [x] Create custom events
|
- [x] Create custom events
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -60,7 +61,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}")
|
||||||
@ -145,8 +146,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.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""
|
||||||
|
|
||||||
data = await self.__reader.read(100 * MB)
|
data = await self.__reader.read(100 * MB)
|
||||||
@ -258,11 +259,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 +278,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 +320,48 @@ 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:]
|
||||||
|
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
|
# TODO: HandleEvent
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -329,9 +369,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: ...
|
||||||
|
@ -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 += ","
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user