Rename imports
This commit is contained in:
parent
ee08f6a3b1
commit
0c0a8d327c
4
main.py
4
main.py
|
@ -1,12 +1,12 @@
|
||||||
from sampy.env import Environment
|
from sampy.env import Environment
|
||||||
from sampy.struct.server import Server
|
from sampy.struct.server import ServerConfig
|
||||||
|
|
||||||
from sampy.shared.glob import config
|
from sampy.shared.glob import config
|
||||||
|
|
||||||
environments = []
|
environments = []
|
||||||
|
|
||||||
for server in config["demo"]["servers"]:
|
for server in config["demo"]["servers"]:
|
||||||
server_config = Server(**server) # Initialize a new Server struct every time even if you are just changing the port (required due to reference and automation values)
|
server_config = ServerConfig(**server) # Initialize a new Server struct every time even if you are just changing the port (required due to reference and automation values)
|
||||||
env = Environment(server_config)
|
env = Environment(server_config)
|
||||||
environments.append(env)
|
environments.append(env)
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@ from . import base
|
||||||
from . import query
|
from . import query
|
||||||
from . import player
|
from . import player
|
||||||
|
|
||||||
from ..struct.server import Server
|
from ..struct.server import ServerConfig
|
||||||
|
|
||||||
STATE_UNKNOWN = (0, base.BaseClient)
|
STATE_UNKNOWN = (0, base.BaseClient)
|
||||||
STATE_QUERY = (1, query.QueryClient)
|
STATE_QUERY = (1, query.QueryClient)
|
||||||
STATE_PLAYER = (2, player.PlayerClient)
|
STATE_PLAYER = (2, player.PlayerClient)
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, config: Server, socket: socket.socket, ip: str, port: int):
|
def __init__(self, config: ServerConfig, socket: socket.socket, ip: str, port: int):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.socket = socket
|
self.socket = socket
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from ..struct.server import Server
|
from ..struct.server import ServerConfig
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class BaseClient:
|
class BaseClient:
|
||||||
def __init__(self, config: Server, socket: socket.socket, ip: str, port: int):
|
def __init__(self, config: ServerConfig, socket: socket.socket, ip: str, port: int):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.socket = socket
|
self.socket = socket
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from . import base
|
from .base import BaseClient
|
||||||
from ..struct.server import Server
|
from ..struct.server import ServerConfig
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class PlayerClient(base.BaseClient):
|
class PlayerClient(BaseClient):
|
||||||
def __init__(self, config: Server, socket: socket.socket, ip: str, port: int):
|
def __init__(self, config: ServerConfig, socket: socket.socket, ip: str, port: int):
|
||||||
super().__init__(config, socket, ip, port)
|
super().__init__(config, socket, ip, port)
|
||||||
logger.debug("Client resolved to PlayerClient")
|
logger.debug("Client resolved to PlayerClient")
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
import socket
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
from . import base
|
from .base import BaseClient
|
||||||
from ..struct.server import Server
|
from ..struct.server import ServerConfig
|
||||||
from ..shared import glob
|
from ..shared import glob
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class QueryClient(base.BaseClient):
|
class QueryClient(BaseClient):
|
||||||
def __init__(self, config: Server, socket: socket.socket, ip: str, port: int):
|
def __init__(self, config: ServerConfig, socket: socket.socket, ip: str, port: int):
|
||||||
super().__init__(config, socket, ip, port)
|
super().__init__(config, socket, ip, port)
|
||||||
logger.debug("Client resolved to QueryClient")
|
logger.debug("Client resolved to QueryClient")
|
||||||
|
|
||||||
async def on_packet(self, packet: bytes):
|
async def on_packet(self, packet: bytes):
|
||||||
logger.debug("on_packet(%s)" % packet)
|
logger.debug("on_packet(%s)" % packet)
|
||||||
|
|
||||||
async def query_i():
|
async def query_i(self):
|
||||||
pass
|
len_hostname = len(self.config.hostname)
|
||||||
|
len_mode = len(self.config.mode)
|
||||||
|
len_language = len(self.config.language)
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from .struct.server import Server as struct
|
from .struct.server import ServerConfig
|
||||||
from . import server
|
from .server import Server
|
||||||
|
|
||||||
class Environment(Thread):
|
class Environment(Thread):
|
||||||
def __init__(self, config: struct):
|
def __init__(self, config: ServerConfig):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.event_loop = asyncio.get_event_loop()
|
self.event_loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
self.server = server.Server(self.config)
|
self.server = Server(self.config)
|
||||||
|
|
||||||
def command(self, cmd: str):
|
def command(self, cmd: str):
|
||||||
self.event_loop.create_task(self.server.on_command(cmd))
|
self.event_loop.create_task(self.server.on_command(cmd))
|
||||||
|
|
|
@ -2,14 +2,14 @@ import socket
|
||||||
import asyncio
|
import asyncio
|
||||||
from select import select # This is straight up magic
|
from select import select # This is straight up magic
|
||||||
|
|
||||||
from .struct.server import Server as struct
|
from .struct.server import ServerConfig
|
||||||
from .client import Client
|
from .client import Client
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Server:
|
class Server:
|
||||||
def __init__(self, config: struct):
|
def __init__(self, config: ServerConfig):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.clients = {}
|
self.clients = {}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from random import randint
|
from random import randint
|
||||||
|
|
||||||
class Server:
|
class ServerConfig:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
host: str, port: int,
|
host: str, port: int,
|
||||||
hostname: str, password: str,
|
hostname: str, password: str,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user