aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.py2
-rw-r--r--lib/YSplayer.py5
-rw-r--r--proxy.py41
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("<I I", data[:8])
@@ -111,11 +122,15 @@ async def handle_client(client_reader, client_writer):
# username = (b''.join(unpack("II16cI", data)[2:16])).decode('ascii').strip('\x00')
username = b''.join(extracted[2:16]).decode('ascii').strip('\x00')
version = extracted[-1]
- info(f"Connection request by {player.username} : {ipAddr}; YSFVERSION = {version}")
+ info(f"Connection request by {username} : {ipAddr}; YSFVERSION = {version}")
player.username = username
player.ip = ipAddr
debug("Player object fixed!")
debug(player)
+ # targetWriter = player.streamWriterObject
+ # targetWriter.write(b'\x04\x00\x00\x00\x10\x00\x00\x00')
+ print("16 packet sent!")
+ # await targetWriter.drain()
if version != YSF_VERSION and VIA_VERSION:
info(f"ViaVersion enabled : Porting {username} from {YSF_VERSION} to {version}")
targetWriter = player.streamWriterObject
@@ -134,6 +149,10 @@ async def handle_client(client_reader, client_writer):
# here we patch the packet to have smoke forcefully
# This part also is for regen, so we disable cheat detection for health
player.life = -1
+ elif packet_type == 44:
+ # We drop the packets from YSFlight and use it for ourselves
+ debug("Packet verification unimplemented!")
+ continue
"""
if player.life < 5:
targetPlayer = player
@@ -158,6 +177,20 @@ async def handle_client(client_reader, client_writer):
if packet_type == 36:
# print("S2C ", str(data))
pass
+ elif packet_type == 44: # Aircraft List
+ # We modify the ysf's packet for express login
+ if not player.loginHandle.loggedIn:
+ targetWriter = player.streamWriterObject
+ data = expressLogin.combinedPacket
+ await targetWriter.write(expressLogin.combinedPacket)
+ await sleep(2)
+ await targetWriter.write(b'\x04\x00\x00\x00\x10\x00\x00\x00')
+ print("Forcefully sent packet!")
+ print(type(expressLogin.combinedPacket))
+ await targetWriter.drain()
+ player.loginHandle.loggedIn = True
+ continue
+
"""
targetWriter = player.streamWriterObject
id = player.playerId