From 227bde246211ad6ed4e8a21706ce5d021722e7a4 Mon Sep 17 00:00:00 2001 From: Ritabrata Das Date: Sun, 2 Feb 2025 20:19:52 +0530 Subject: Intial Commit --- config.py | 2 +- lib/YSplayer.py | 5 ++++- proxy.py | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index ab3b14c..05e7a53 100644 --- a/config.py +++ b/config.py @@ -3,7 +3,7 @@ from logging import DEBUG, WARN, INFO, CRITICAL # Configuration # Logging Level : Most of the times having INFO level is enough # But while submitting issues, please consider sending the logs with DEBUG level -LOGGING_LEVEL = INFO +LOGGING_LEVEL = DEBUG # Server Configuration # Replace with the YSFlight server address diff --git a/lib/YSplayer.py b/lib/YSplayer.py index 53c9092..ca6cb1c 100644 --- a/lib/YSplayer.py +++ b/lib/YSplayer.py @@ -1,7 +1,9 @@ +from lib.loginHandler import Login + class Player: def __init__(self,username, playerId, x, y, z, throttle, aam, agm, gunAmmo, rktAmmo, fuel, ipAddr, life, vx, vy, vz, gValue, - streamWriterObject=None, warningSent=False, smokedAdded=False): + streamWriterObject=None, warningSent=False, smokedAdded=False, loginHandle=Login()): self.username = username self.ip = ipAddr self.playerId = playerId @@ -22,6 +24,7 @@ class Player: self.streamWriterObject = streamWriterObject self.warningSent = warningSent self.smokeAdded = smokedAdded + self.loginHandle = loginHandle def __str__(self): return f"Username: {self.username}, IP: {self.ip}, " \ diff --git a/proxy.py b/proxy.py index 5852d67..bd65c12 100644 --- a/proxy.py +++ b/proxy.py @@ -6,10 +6,11 @@ Lisenced under GPLv3 import asyncio from struct import unpack, pack from lib.parseFlightData import parseFlightData -from lib import YSchat, YSplayer, YSendFlight, YSundead, YSviaversion +from lib import YSchat, YSplayer, YSendFlight, YSundead, YSviaversion, loginHandler, expressLogin import logging from logging import critical, warning, info, debug from config import * +from time import sleep # Configuration SERVER_HOST = SERVER_HOST @@ -37,9 +38,19 @@ async def handle_client(client_reader, client_writer): async def forward(reader, writer, direction, player=player): while True: try: - data = await reader.read(4096) - if not data: + header = await reader.readexactly(4) # Ensures we always get 4 bytes + if not header: + break # Connection closed + + length = unpack("I", header)[0] + + remainder = await reader.read(length) + + if not remainder: break + + data = header + remainder + if direction == "client_to_server": try: length, packet_type = unpack("