Skip to content

Commit

Permalink
0.2.1 (#11)
Browse files Browse the repository at this point in the history
- Исправлена ошибка с выбросом ошибки при резком разрыве соединения
- Добавлен лимит игроков
- Тепреь при разрыве соединения будет кидаться runtime
  • Loading branch information
themanyfaceddemon authored Sep 11, 2024
1 parent b78d55a commit 98d8abb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DMBotNetwork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .main.utils.cl_unit import ClUnit

__all__ = ["Client", "Server", "ClUnit"]
__version__ = "0.2.0"
__version__ = "0.2.1"
4 changes: 4 additions & 0 deletions DMBotNetwork/main/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ async def disconnect(cls) -> None:
cls._server_handler_task.cancel()
cls._server_handler_task = None

cls._writer = None
cls._reader = None

download_files = cls._content_path.glob("**/*.download")
for file in download_files:
file.unlink()
Expand Down Expand Up @@ -194,6 +197,7 @@ async def _server_handler(cls) -> None:
asyncio.CancelledError,
ConnectionAbortedError,
asyncio.exceptions.IncompleteReadError,
ConnectionResetError,
):
pass

Expand Down
14 changes: 14 additions & 0 deletions DMBotNetwork/main/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Server:
_server_name: str = "Dev_Server"
_allow_registration: bool = True
_timeout: float = 30.0
_max_players: int = -1

@classmethod
def register_methods_from_class(cls, external_class):
Expand Down Expand Up @@ -79,10 +80,12 @@ async def setup_server(
base_access: Dict[str, bool],
allow_registration: bool,
timeout: float,
max_player: int = -1, # inf
) -> None:
cls._server_name = server_name
cls._allow_registration = allow_registration
cls._timeout = timeout
cls._max_players = max_player

ServerDB.set_db_path(db_path)
ServerDB.set_owner_base_password(init_owner_password)
Expand Down Expand Up @@ -197,6 +200,14 @@ async def _cl_handler(
else:
await cl_unit.send_log_error("Unknown 'code' for net type.")

except (
asyncio.CancelledError,
ConnectionAbortedError,
asyncio.exceptions.IncompleteReadError,
ConnectionResetError,
):
pass

except Exception as err:
await cl_unit.send_log_error(f"An unexpected error occurred: {err}")

Expand All @@ -207,6 +218,9 @@ async def _cl_handler(

@classmethod
async def _auth(cls, cl_unit: ClUnit) -> None:
if cls._max_players != -1 and cls._max_players <= len(cls._cl_units):
raise ValueError("Server is full.")

await cl_unit.send_package(ResponseCode.AUTH_REQ)
receive_package = await asyncio.wait_for(
cl_unit.receive_package(), cls._timeout
Expand Down
1 change: 1 addition & 0 deletions server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def main():
base_access={},
allow_registration=False,
timeout=5.0,
max_player=0,
)

Server.register_methods_from_class(NetClassPong)
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.0",
version="0.2.1",
packages=find_packages(),
install_requires=["aiosqlite", "aiofiles", "bcrypt", "msgpack"],
author="Angels And Demons dev team",
Expand Down
Empty file removed test.py
Empty file.

0 comments on commit 98d8abb

Please sign in to comment.