Final commit before archive

This commit is contained in:
Emily 2020-03-29 18:45:38 +02:00
parent 2166a30aa9
commit 0e2bc4f886
31 changed files with 74 additions and 54 deletions

View File

View File

@ -5,13 +5,14 @@
"password": "",
"hostname": "Python > C",
"max_players": 50,
"mode": "yay",
"language": "spoop"
"mode": "debug",
"language": "English"
},
"logging": {
"filename": "",
"level": "DEBUG",
"format": "%(name)s - %(levelname)s - %(message)s",
"format": "[%(name)s:L%(lineno)02d %(levelname)s] %(message)s",
"datefmt": "%d-%b-%y %H:%M:%S"
}
},
"debug": true
}

14
main.py
View File

@ -1,14 +1,11 @@
from importlib import reload
import sys
import socket
import json
import logging
from objects import glob
from objects.server import Server
from objects import client
from sampy import glob
from sampy import client
from sampy.server import Server
logger = logging.getLogger(__name__)
@ -21,11 +18,12 @@ if __name__ == "__main__":
while True:
try:
cmd = input()
if cmd == "quit" or cmd == "exit" or cmd == "stop":
if cmd in ["quit","exit","stop"]:
exit(0)
else:
logger.info("> Restarting...")
client.restart()
glob.server.restart()
#client.restart()
"""for module in sys.modules.values():
reload(module)
glob.server = Server(glob.config["host"], glob.config["port"])

View File

@ -1,3 +0,0 @@
from . import enums
from . import compression

View File

@ -1,3 +0,0 @@
from . import glob
from . import client
from . import server

7
sampy/__init__.py Normal file
View File

@ -0,0 +1,7 @@
from . import handlers
from . import helpers
from . import network
from . import raknet
from . import glob
from . import client
from . import server

View File

@ -1,14 +1,15 @@
from importlib import reload
import socket
import logging
import struct
from network.compression import uncompress
from .network.compression import uncompress
from .handlers import serverQueryHandler, mainHandler
from .helpers.byteFormater import readable_bytes
from .server import Server
from handlers import serverQueryHandler, mainHandler
from helpers.byteFormater import readable_bytes
from . import glob
if glob.config["debug"]:
from importlib import reload
logger = logging.getLogger(__name__)
@ -18,13 +19,14 @@ class Client:
b"SAMP": serverQueryHandler.handle
}
def __init__(self, server: "Server", addr: "Address"):
def __init__(self, server, addr: "Address"):
self.server = server
self.ip_uint = struct.unpack(b"<I", bytes(int(x) for x in addr[0].split(".")))[0]
self.addr = addr
self.state = 0
self.__writebuffer = bytearray()
def handle_data(self, data: bytes):
@ -33,7 +35,7 @@ class Client:
if data.startswith(pattern):
queue = handle(self, data)
if queue:
self.write_to_buffer(queue)
self.write(queue)
found = True
if not found:
@ -46,27 +48,27 @@ class Client:
logger.error(err)
finally:
if queue:
self.write_to_buffer(queue)
self.write(queue)
def write_to_buffer(self, data: bytes):
def write(self, data: bytes):
if type(data) == int:
self.__writebuffer.append(data)
elif type(data) == list:
for item in data:
self.write_to_buffer(item)
self.write(item)
else:
self.__writebuffer += data
def get_buffer_size(self) -> int:
return len(self.__writebuffer)
def flush(self):
if not self.get_buffer_size():
return
def write_socket(self):
if self.get_buffer_size() > 0:
#write_chunk = self.__writebuffer.pop(0)
#logger.debug("[%s] <- %s" % (self.addr, write_chunk))
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(self.__writebuffer)))
self.server.socket.sendto(self.__writebuffer, self.addr)
self.__writebuffer.clear()
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(self.__writebuffer)))
self.server.socket.sendto(self.__writebuffer, self.addr)
self.__writebuffer.clear()
def send_immediate(self, data: bytes):
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(data)))

View File

@ -1,10 +1,9 @@
import sys
import json
import logging
from random import randint
from network.enums import types as TYPE
from .network.enums import types as TYPE
# ---------------------------------------------------------------------------
# public

View File

@ -1,5 +1,5 @@
from . import mainHandler
from . import serverQueryHandler
from . import handshakeHandler
from . import unknownHandler
from . import unknownHandler
from . import queueHandler

View File

@ -1,14 +1,14 @@
import logging
import struct
from network.enums import types as TYPE
from objects import glob
from ..network.enums import types as TYPE
from .. import glob
logger = logging.getLogger(__name__)
def handle(client: "Client", data: bytes) -> bytes:
challenge = (client.ip_uint ^ glob.challenge_short) & TYPE.MAX_USHORT
challenge_solution = challenge ^ 0x6969
challenge_solution = challenge ^ 0x6969 # 0x6969 being client_version?
challenge_answer = struct.unpack_from(b">H", data, 1)[0]

View File

@ -6,14 +6,16 @@ import struct
from . import handshakeHandler
from . import unknownHandler
from . import queueHandler
from helpers.byteFormater import readable_bytes
from ..helpers.byteFormater import readable_bytes
logger = logging.getLogger(__name__)
HANDLERS = {
0x18: handshakeHandler.handle,
0x00: unknownHandler.handle
0x00: unknownHandler.handle,
0xe3: queueHandler.handle
}
def handle(client: "Client", data: bytes) -> bytes:

View File

@ -0,0 +1,11 @@
import logging
import struct
from ..network.enums import types as TYPE
from .. import glob
logger = logging.getLogger(__name__)
def handle(client: "Client", data: bytes) -> bytes:
return b""

View File

@ -1,8 +1,8 @@
import struct
import logging
from objects import glob
from helpers import dataHelper
from .. import glob
from ..helpers import dataHelper
logger = logging.getLogger(__name__)
logger.propagate = False # Disable console logging

View File

@ -1,8 +1,8 @@
import struct
from random import randint
from helpers.checksumHelper import CheckSum
from network.enums import types as TYPE
from ..helpers.checksumHelper import CheckSum
from ..network.enums import types as TYPE
TEA_ROUNDS = 32
TEA_XOR_MASK = 0x5E94A3CF

View File

@ -1,4 +1,4 @@
from network.enums import types as TYPE
from ..network.enums import types as TYPE
# TODO: Single function if Object's state is not needed
class CheckSum:

View File

@ -0,0 +1,3 @@
from . import consts
from . import enums
from . import compression

View File

@ -1,6 +1,6 @@
import logging
from objects import glob
from .. import glob
# Found @ addr 0x004C88E0
LOOKUP_TABLE = b"\xb4b\x07\xe5\x9d\xafc\xdd\xe3\xd0\xcc\xfe\xdc\xdbk.j@\xabG\xc9\xd1S\xd5 \x91\xa5\x0eJ\xdf\x18\x89\xfdo%\x12\xb7\x13w\x00e6mI\xecW*\xa9\x11_\xfax\x95\xa4\xbd\x1e\xd9yD\xcd\xde\x81\xeb\t>\xf6\xee\xda\x7f\xa3\x1a\xa7-\xa6\xad\xc1F\x93\xd2\x1b\x9c\xaa\xd7NKML\xf3\xb84\xc0\xca\x88\xf4\x94\xcb\x0490\x82\xd6s\xb0\xbf\"\x01AnH,\xa8u\xb1\n\xae\x9f\'\x80\x10\xce\xf0)(\x85\r\x05\xf75\xbb\xbc\x15\x06\xf5`q\x03\x1f\xeaZ3\x92\x8d\xe7\x90[\xe9\xcf\x9e\xd3]\xed1\x1c\x0bR\x16Q\x0f\x86\xc5h\x9b!\x0c\x8bB\x87\xffO\xbe\xc8\xe8\xc7\xd4z\xe0U/\x8a\x8e\xba\x987\xe4\xb28\xa1\xb62\x83:{\x84<a\xfb\x8c\x14=C;\x1d\xc3\xa2\x96\xb3\xf8\xc4\xf2&+\xd8|\xfc#$f\xefidPTY\xf1\xa0t\xac\xc6}\xb5\xe6\xe2\xc2~g\x17^\xe1\xb9?lp\x08\x99EVv\xf9\x9a\x97\x19r\\\x02\x8fX"

1
sampy/raknet/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import bitStream

View File

@ -1,5 +1,5 @@
class BitStream:
def __init__(self, data: array = []):
def __init__(self, data: list = []):
self.bits_used = 0
self.read_offset = 0
self.data = data

View File

@ -1,7 +1,6 @@
import socket
import select
import logging
from threading import Thread
from .client import Client
@ -57,4 +56,7 @@ class Server(Thread):
client.write_socket()
"""for c in self.clients.values():
print(c.__writebuffer)"""
print(c.__writebuffer)"""
def restart(self):
[c.restart() for c in self.clients]