diff --git a/.gitignore b/.gitignore index 5059a6a..d11470e 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,6 @@ ENV/ # Logs logs/ + +# vscode +.vscode/ \ No newline at end of file diff --git a/sampy/client/__init__.py b/sampy/client/__init__.py index bf7648a..f0bf061 100644 --- a/sampy/client/__init__.py +++ b/sampy/client/__init__.py @@ -5,12 +5,15 @@ from . import base from . import query from . import player +from ..struct.server import Server + STATE_UNKNOWN = (0, base.BaseClient) STATE_QUERY = (1, query.QueryClient) STATE_PLAYER = (2, player.PlayerClient) class Client: - def __init__(self, socket: socket.socket, ip: str, port: int): + def __init__(self, config: Server, socket: socket.socket, ip: str, port: int): + self.config = config self.socket = socket self.ip = ip self.port = port @@ -19,7 +22,7 @@ class Client: def set_state(self, state: tuple): self.state = state - self.client = self.state[1](self.socket, self.ip, self.port) + self.client = self.state[1](self.config, self.socket, self.ip, self.port) async def on_packet(self, packet: bytes): if self.state == STATE_UNKNOWN: diff --git a/sampy/client/base.py b/sampy/client/base.py index b2493c7..287c8dd 100644 --- a/sampy/client/base.py +++ b/sampy/client/base.py @@ -1,11 +1,14 @@ import socket import struct +from ..struct.server import Server + import logging logger = logging.getLogger(__name__) class BaseClient: - def __init__(self, socket: socket.socket, ip: str, port: int): + def __init__(self, config: Server, socket: socket.socket, ip: str, port: int): + self.config = config self.socket = socket self.ip = ip self.port = port diff --git a/sampy/client/player.py b/sampy/client/player.py index c9b10b2..31b7280 100644 --- a/sampy/client/player.py +++ b/sampy/client/player.py @@ -1,13 +1,15 @@ import socket from . import base +from ..struct.server import Server import logging logger = logging.getLogger(__name__) class PlayerClient(base.BaseClient): - def __init__(self, socket: socket.socket, ip: str, port: int): - super().__init__(socket, ip, port) + def __init__(self, config: Server, socket: socket.socket, ip: str, port: int): + super().__init__(config, socket, ip, port) + logger.debug("Client resolved to PlayerClient") async def on_packet(self, packet: bytes): logger.debug("on_packet(%s)" % packet) \ No newline at end of file diff --git a/sampy/client/query.py b/sampy/client/query.py index 71d279c..43c7eb5 100644 --- a/sampy/client/query.py +++ b/sampy/client/query.py @@ -1,13 +1,19 @@ import socket from . import base +from ..struct.server import Server +from ..shared import glob import logging logger = logging.getLogger(__name__) class QueryClient(base.BaseClient): - def __init__(self, socket: socket.socket, ip: str, port: int): - super().__init__(socket, ip, port) + def __init__(self, config: Server, socket: socket.socket, ip: str, port: int): + super().__init__(config, socket, ip, port) + logger.debug("Client resolved to QueryClient") async def on_packet(self, packet: bytes): - logger.debug("on_packet(%s)" % packet) \ No newline at end of file + logger.debug("on_packet(%s)" % packet) + + async def query_i(): + pass \ No newline at end of file diff --git a/sampy/env.py b/sampy/env.py index 6c609c0..f767dca 100644 --- a/sampy/env.py +++ b/sampy/env.py @@ -18,4 +18,3 @@ class Environment(Thread): def run(self): self.event_loop.run_until_complete(self.server.main()) - print("Ended?") \ No newline at end of file diff --git a/sampy/server.py b/sampy/server.py index 61c3194..287ded5 100644 --- a/sampy/server.py +++ b/sampy/server.py @@ -34,7 +34,7 @@ class Server: if addr not in self.clients: ip, port = addr - self.clients[addr] = Client(self.socket, ip, port) + self.clients[addr] = Client(self.config, self.socket, ip, port) await self.clients[addr].on_packet(data) await asyncio.sleep(0) \ No newline at end of file diff --git a/sampy/shared/glob.py b/sampy/shared/glob.py index 53dccd3..f2ffad7 100644 --- a/sampy/shared/glob.py +++ b/sampy/shared/glob.py @@ -10,8 +10,11 @@ if not os.path.isfile("config.json"): with open("config.json", "r") as f: config = json.load(f) +# aliases +conf = config["sampy"] +conf_log = conf["logging"] + # Setup logger -conf_log = config["sampy"]["logging"] # alias ## fix for logging level default_logging_fallback = False if type(conf_log["level"]) is not int: