Final commit before archive
This commit is contained in:
parent
2166a30aa9
commit
0e2bc4f886
|
@ -5,13 +5,14 @@
|
||||||
"password": "",
|
"password": "",
|
||||||
"hostname": "Python > C",
|
"hostname": "Python > C",
|
||||||
"max_players": 50,
|
"max_players": 50,
|
||||||
"mode": "yay",
|
"mode": "debug",
|
||||||
"language": "spoop"
|
"language": "English"
|
||||||
},
|
},
|
||||||
"logging": {
|
"logging": {
|
||||||
"filename": "",
|
"filename": "",
|
||||||
"level": "DEBUG",
|
"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"
|
"datefmt": "%d-%b-%y %H:%M:%S"
|
||||||
}
|
},
|
||||||
|
"debug": true
|
||||||
}
|
}
|
14
main.py
14
main.py
|
@ -1,14 +1,11 @@
|
||||||
from importlib import reload
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from objects import glob
|
from sampy import glob
|
||||||
from objects.server import Server
|
from sampy import client
|
||||||
|
from sampy.server import Server
|
||||||
from objects import client
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -21,11 +18,12 @@ if __name__ == "__main__":
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
cmd = input()
|
cmd = input()
|
||||||
if cmd == "quit" or cmd == "exit" or cmd == "stop":
|
if cmd in ["quit","exit","stop"]:
|
||||||
exit(0)
|
exit(0)
|
||||||
else:
|
else:
|
||||||
logger.info("> Restarting...")
|
logger.info("> Restarting...")
|
||||||
client.restart()
|
glob.server.restart()
|
||||||
|
#client.restart()
|
||||||
"""for module in sys.modules.values():
|
"""for module in sys.modules.values():
|
||||||
reload(module)
|
reload(module)
|
||||||
glob.server = Server(glob.config["host"], glob.config["port"])
|
glob.server = Server(glob.config["host"], glob.config["port"])
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
from . import enums
|
|
||||||
|
|
||||||
from . import compression
|
|
|
@ -1,3 +0,0 @@
|
||||||
from . import glob
|
|
||||||
from . import client
|
|
||||||
from . import server
|
|
7
sampy/__init__.py
Normal file
7
sampy/__init__.py
Normal 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
|
|
@ -1,14 +1,15 @@
|
||||||
from importlib import reload
|
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import struct
|
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 . import glob
|
||||||
|
if glob.config["debug"]:
|
||||||
from helpers.byteFormater import readable_bytes
|
from importlib import reload
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -18,13 +19,14 @@ class Client:
|
||||||
b"SAMP": serverQueryHandler.handle
|
b"SAMP": serverQueryHandler.handle
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, server: "Server", addr: "Address"):
|
def __init__(self, server, addr: "Address"):
|
||||||
self.server = server
|
self.server = server
|
||||||
|
|
||||||
self.ip_uint = struct.unpack(b"<I", bytes(int(x) for x in addr[0].split(".")))[0]
|
self.ip_uint = struct.unpack(b"<I", bytes(int(x) for x in addr[0].split(".")))[0]
|
||||||
|
|
||||||
self.addr = addr
|
self.addr = addr
|
||||||
self.state = 0
|
self.state = 0
|
||||||
|
|
||||||
self.__writebuffer = bytearray()
|
self.__writebuffer = bytearray()
|
||||||
|
|
||||||
def handle_data(self, data: bytes):
|
def handle_data(self, data: bytes):
|
||||||
|
@ -33,7 +35,7 @@ class Client:
|
||||||
if data.startswith(pattern):
|
if data.startswith(pattern):
|
||||||
queue = handle(self, data)
|
queue = handle(self, data)
|
||||||
if queue:
|
if queue:
|
||||||
self.write_to_buffer(queue)
|
self.write(queue)
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
|
@ -46,27 +48,27 @@ class Client:
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
finally:
|
finally:
|
||||||
if queue:
|
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:
|
if type(data) == int:
|
||||||
self.__writebuffer.append(data)
|
self.__writebuffer.append(data)
|
||||||
elif type(data) == list:
|
elif type(data) == list:
|
||||||
for item in data:
|
for item in data:
|
||||||
self.write_to_buffer(item)
|
self.write(item)
|
||||||
else:
|
else:
|
||||||
self.__writebuffer += data
|
self.__writebuffer += data
|
||||||
|
|
||||||
def get_buffer_size(self) -> int:
|
def get_buffer_size(self) -> int:
|
||||||
return len(self.__writebuffer)
|
return len(self.__writebuffer)
|
||||||
|
|
||||||
def write_socket(self):
|
def flush(self):
|
||||||
if self.get_buffer_size() > 0:
|
if not self.get_buffer_size():
|
||||||
#write_chunk = self.__writebuffer.pop(0)
|
return
|
||||||
#logger.debug("[%s] <- %s" % (self.addr, write_chunk))
|
|
||||||
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(self.__writebuffer)))
|
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(self.__writebuffer)))
|
||||||
self.server.socket.sendto(self.__writebuffer, self.addr)
|
self.server.socket.sendto(self.__writebuffer, self.addr)
|
||||||
self.__writebuffer.clear()
|
self.__writebuffer.clear()
|
||||||
|
|
||||||
def send_immediate(self, data: bytes):
|
def send_immediate(self, data: bytes):
|
||||||
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(data)))
|
logger.debug("[%s] <- %s" % (self.addr, readable_bytes(data)))
|
|
@ -1,10 +1,9 @@
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
from network.enums import types as TYPE
|
from .network.enums import types as TYPE
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# public
|
# public
|
|
@ -1,5 +1,5 @@
|
||||||
from . import mainHandler
|
from . import mainHandler
|
||||||
from . import serverQueryHandler
|
from . import serverQueryHandler
|
||||||
|
|
||||||
from . import handshakeHandler
|
from . import handshakeHandler
|
||||||
from . import unknownHandler
|
from . import unknownHandler
|
||||||
|
from . import queueHandler
|
|
@ -1,14 +1,14 @@
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from network.enums import types as TYPE
|
from ..network.enums import types as TYPE
|
||||||
from objects import glob
|
from .. import glob
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def handle(client: "Client", data: bytes) -> bytes:
|
def handle(client: "Client", data: bytes) -> bytes:
|
||||||
challenge = (client.ip_uint ^ glob.challenge_short) & TYPE.MAX_USHORT
|
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]
|
challenge_answer = struct.unpack_from(b">H", data, 1)[0]
|
||||||
|
|
|
@ -6,14 +6,16 @@ import struct
|
||||||
|
|
||||||
from . import handshakeHandler
|
from . import handshakeHandler
|
||||||
from . import unknownHandler
|
from . import unknownHandler
|
||||||
|
from . import queueHandler
|
||||||
|
|
||||||
from helpers.byteFormater import readable_bytes
|
from ..helpers.byteFormater import readable_bytes
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
HANDLERS = {
|
HANDLERS = {
|
||||||
0x18: handshakeHandler.handle,
|
0x18: handshakeHandler.handle,
|
||||||
0x00: unknownHandler.handle
|
0x00: unknownHandler.handle,
|
||||||
|
0xe3: queueHandler.handle
|
||||||
}
|
}
|
||||||
|
|
||||||
def handle(client: "Client", data: bytes) -> bytes:
|
def handle(client: "Client", data: bytes) -> bytes:
|
11
sampy/handlers/queueHandler.py
Normal file
11
sampy/handlers/queueHandler.py
Normal 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""
|
|
@ -1,8 +1,8 @@
|
||||||
import struct
|
import struct
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from objects import glob
|
from .. import glob
|
||||||
from helpers import dataHelper
|
from ..helpers import dataHelper
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.propagate = False # Disable console logging
|
logger.propagate = False # Disable console logging
|
|
@ -1,8 +1,8 @@
|
||||||
import struct
|
import struct
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
from helpers.checksumHelper import CheckSum
|
from ..helpers.checksumHelper import CheckSum
|
||||||
from network.enums import types as TYPE
|
from ..network.enums import types as TYPE
|
||||||
|
|
||||||
TEA_ROUNDS = 32
|
TEA_ROUNDS = 32
|
||||||
TEA_XOR_MASK = 0x5E94A3CF
|
TEA_XOR_MASK = 0x5E94A3CF
|
|
@ -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
|
# TODO: Single function if Object's state is not needed
|
||||||
|
|
||||||
class CheckSum:
|
class CheckSum:
|
3
sampy/network/__init__.py
Normal file
3
sampy/network/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from . import consts
|
||||||
|
from . import enums
|
||||||
|
from . import compression
|
|
@ -1,6 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from objects import glob
|
from .. import glob
|
||||||
|
|
||||||
# Found @ addr 0x004C88E0
|
# 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"
|
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
1
sampy/raknet/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
from . import bitStream
|
|
@ -1,5 +1,5 @@
|
||||||
class BitStream:
|
class BitStream:
|
||||||
def __init__(self, data: array = []):
|
def __init__(self, data: list = []):
|
||||||
self.bits_used = 0
|
self.bits_used = 0
|
||||||
self.read_offset = 0
|
self.read_offset = 0
|
||||||
self.data = data
|
self.data = data
|
|
@ -1,7 +1,6 @@
|
||||||
import socket
|
import socket
|
||||||
import select
|
import select
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from .client import Client
|
from .client import Client
|
||||||
|
@ -58,3 +57,6 @@ class Server(Thread):
|
||||||
|
|
||||||
"""for c in self.clients.values():
|
"""for c in self.clients.values():
|
||||||
print(c.__writebuffer)"""
|
print(c.__writebuffer)"""
|
||||||
|
|
||||||
|
def restart(self):
|
||||||
|
[c.restart() for c in self.clients]
|
Reference in New Issue
Block a user