Skip to content

Commit

Permalink
fix and add
Browse files Browse the repository at this point in the history
  • Loading branch information
themanyfaceddemon committed Sep 23, 2024
1 parent faff9d2 commit 0f44a5a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DMBotNetwork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .main.utils.server_db import ServerDB

__all__ = ["Client", "Server", "ClUnit", "require_access", "ServerDB"]
__version__ = "0.2.8"
__version__ = "0.2.9"
25 changes: 25 additions & 0 deletions DMBotNetwork/main/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,31 @@ async def setup_server(
cls._server = await asyncio.start_server(cls._cl_handler, host, port)
logger.info(f"Server setup. Host: {host}, port:{port}.")

@classmethod
def get_timeout(cls) -> float:
return cls._timeout

@classmethod
def set_timeout(cls, value: float) -> None:
cls._timeout = value

@classmethod
def get_allow_registration(cls) -> bool:
return cls._allow_registration

@classmethod
def set_allow_registration(cls, value: bool) -> None:
cls._allow_registration = value

@classmethod
def get_max_players(cls) -> int:
return cls._max_players

@classmethod
def set_max_players(cls, value: int) -> None:
if value < -1:
value = -1

cls._max_players = value

@classmethod
Expand Down Expand Up @@ -183,6 +198,16 @@ async def broadcast(cls, func_name: str, *args, **kwargs) -> None:
if tasks:
await asyncio.gather(*tasks)

@classmethod
async def remove_user(cls, login: str, remove_from_db: bool = False) -> None:
if remove_from_db:
await ServerDB.delete_user(login)

cl_unit = cls._cl_units.get(login, None)

if cl_unit is not None:
await cl_unit.disconnect("Remove from server")

@classmethod
async def _cl_handler(
cls, reader: asyncio.StreamReader, writer: asyncio.StreamWriter
Expand Down
2 changes: 1 addition & 1 deletion DMBotNetwork/main/utils/decorator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from functools import wraps
from typing import List

from .cl_unit import ClUnit
from .server_db import ServerDB
from functools import wraps


def require_access(req_access: List[str] | str):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="DMBotNetwork",
version="0.2.8",
version="0.2.9",
packages=find_packages(),
install_requires=["aiosqlite", "aiofiles", "bcrypt", "msgpack"],
author="Angels And Demons dev team",
Expand Down

0 comments on commit 0f44a5a

Please sign in to comment.