Rename imports

This commit is contained in:
Emily 2020-03-29 19:12:31 +02:00
parent ee08f6a3b1
commit 0c0a8d327c
8 changed files with 27 additions and 23 deletions

View File

@ -1,12 +1,12 @@
from sampy.env import Environment
from sampy.struct.server import Server
from sampy.struct.server import ServerConfig
from sampy.shared.glob import config
environments = []
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)
environments.append(env)

View File

@ -5,14 +5,14 @@ from . import base
from . import query
from . import player
from ..struct.server import Server
from ..struct.server import ServerConfig
STATE_UNKNOWN = (0, base.BaseClient)
STATE_QUERY = (1, query.QueryClient)
STATE_PLAYER = (2, player.PlayerClient)
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.socket = socket
self.ip = ip

View File

@ -1,13 +1,13 @@
import socket
import struct
from ..struct.server import Server
from ..struct.server import ServerConfig
import logging
logger = logging.getLogger(__name__)
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.socket = socket
self.ip = ip

View File

@ -1,13 +1,13 @@
import socket
from . import base
from ..struct.server import Server
from .base import BaseClient
from ..struct.server import ServerConfig
import logging
logger = logging.getLogger(__name__)
class PlayerClient(base.BaseClient):
def __init__(self, config: Server, socket: socket.socket, ip: str, port: int):
class PlayerClient(BaseClient):
def __init__(self, config: ServerConfig, socket: socket.socket, ip: str, port: int):
super().__init__(config, socket, ip, port)
logger.debug("Client resolved to PlayerClient")

View File

@ -1,19 +1,23 @@
import socket
import struct
from . import base
from ..struct.server import Server
from .base import BaseClient
from ..struct.server import ServerConfig
from ..shared import glob
import logging
logger = logging.getLogger(__name__)
class QueryClient(base.BaseClient):
def __init__(self, config: Server, socket: socket.socket, ip: str, port: int):
class QueryClient(BaseClient):
def __init__(self, config: ServerConfig, 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)
async def query_i():
pass
async def query_i(self):
len_hostname = len(self.config.hostname)
len_mode = len(self.config.mode)
len_language = len(self.config.language)

View File

@ -1,17 +1,17 @@
import asyncio
from threading import Thread
from .struct.server import Server as struct
from . import server
from .struct.server import ServerConfig
from .server import Server
class Environment(Thread):
def __init__(self, config: struct):
def __init__(self, config: ServerConfig):
super().__init__()
self.daemon = True
self.event_loop = asyncio.get_event_loop()
self.config = config
self.server = server.Server(self.config)
self.server = Server(self.config)
def command(self, cmd: str):
self.event_loop.create_task(self.server.on_command(cmd))

View File

@ -2,14 +2,14 @@ import socket
import asyncio
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
import logging
logger = logging.getLogger(__name__)
class Server:
def __init__(self, config: struct):
def __init__(self, config: ServerConfig):
self.config = config
self.clients = {}

View File

@ -1,6 +1,6 @@
from random import randint
class Server:
class ServerConfig:
def __init__(self,
host: str, port: int,
hostname: str, password: str,