Compare commits

..

3 Commits

Author SHA1 Message Date
a057004cd2 Decompress data 2023-07-08 18:57:18 +03:00
f7defaed0c Minor fixes 2023-07-08 18:46:05 +03:00
abd4fb60c1 Minor fixes 2023-07-08 13:10:37 +03:00
3 changed files with 12 additions and 10 deletions

View File

@ -15,10 +15,13 @@ BeamingDrive Multiplayer (BeamMP) server compatible with BeamMP clients.
- [x] Connecting to the world - [x] Connecting to the world
- [x] Chat - [x] Chat
- [ ] ABG: (compressed data) - [ ] ABG: (compressed data)
- [ ] Decompress data - [x] Decompress data
- [ ] Vehicle data - [ ] Vehicle data
- [ ] Players synchronizations
- [ ] UDP Server part: - [ ] UDP Server part:
- [ ] Players synchronizations - [ ] Players synchronizations
- [ ] Ping
- [ ] Player counter
- [x] Additional: - [x] Additional:
- [x] Events System - [x] Events System
- [x] Plugins support - [x] Plugins support

View File

@ -5,6 +5,7 @@
# Licence: FPA # Licence: FPA
# (c) kuitoi.su 2023 # (c) kuitoi.su 2023
import asyncio import asyncio
import zlib
from core import utils from core import utils
from .tcp_server import TCPServer from .tcp_server import TCPServer
@ -70,7 +71,6 @@ class Client:
# if not self.is_disconnected(): # if not self.is_disconnected():
# self.log.debug(f"Client with {self.nick}({self.cid}) disconnected") # self.log.debug(f"Client with {self.nick}({self.cid}) disconnected")
# return b"" # return b""
header = await self.reader.read(4) # header: 4 bytes header = await self.reader.read(4) # header: 4 bytes
int_header = 0 int_header = 0
@ -88,17 +88,16 @@ class Client:
return b"" return b""
data = await self.reader.read(101 * MB) data = await self.reader.read(101 * MB)
self.log.debug(f"header: `{header}`; int_header: `{int_header}`; data: `{data}`;")
if len(data) != int_header: if len(data) != int_header:
self.log.debug(f"WARN Expected to read {int_header} bytes, instead got {len(data)}") self.log.debug(f"WARN Expected to read {int_header} bytes, instead got {len(data)}")
# TODO: ABG: DeComp(Data)
abg = b"ABG:" abg = b"ABG:"
if len(data) > len(abg) and data.startswith(abg): if len(data) > len(abg) and data.startswith(abg):
data = data[len(abg):] data = zlib.decompress(data[len(abg):])
return b"" self.log.debug(f"ABG: {data}")
# return DeComp(Data); return data
self.log.debug(f"header: `{header}`; int_header: `{int_header}`; data: `{data}`;")
return data return data
async def sync_resources(self): async def sync_resources(self):

View File

@ -27,10 +27,10 @@ class TCPServer:
self.log.debug(f"recv1 data: {data}") self.log.debug(f"recv1 data: {data}")
if len(data) > 50: if len(data) > 50:
await client.kick("Too long data") await client.kick("Too long data")
return return False, None
if "VC2.0" not in data.decode("utf-8"): if "VC2.0" not in data.decode("utf-8"):
await client.kick("Outdated Version.") await client.kick("Outdated Version.")
return return False, None
else: else:
await client.tcp_send(b"A") # Accepted client version await client.tcp_send(b"A") # Accepted client version
@ -38,7 +38,7 @@ class TCPServer:
self.log.debug(f"recv2 data: {data}") self.log.debug(f"recv2 data: {data}")
if len(data) > 50: if len(data) > 50:
await client.kick("Invalid Key (too long)!") await client.kick("Invalid Key (too long)!")
return return False, None
client.key = data.decode("utf-8") client.key = data.decode("utf-8")
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
url = 'https://auth.beammp.com/pkToUser' url = 'https://auth.beammp.com/pkToUser'