Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added project layout, defined amp commands for server/client #24

Merged
merged 10 commits into from
Nov 16, 2023
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ authors = [

requires-python = ">=3.8"
dependencies = [
# list dependencies here
"twisted==23.10.0",
]

[project.optional-dependencies]
Expand Down
4 changes: 0 additions & 4 deletions teamprojekt_competition_server/__init__.py

This file was deleted.

Empty file.
14 changes: 0 additions & 14 deletions teamprojekt_competition_server/example.py

This file was deleted.

1 change: 1 addition & 0 deletions teamprojekt_competition_server/server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file.
90 changes: 90 additions & 0 deletions teamprojekt_competition_server/shared/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
This module defines the commands used for the server client communication.
"""

from twisted.protocols.amp import Integer, String, Boolean, Command


class ServerCommand(Command):
"""Interface for commands send from the server"""

pass


class ClientCommand(Command):
"""Interface for commands send from the client"""

pass


class AuthFailed(Exception):
"""Exception raised when authentication fails.

This exception is raised in cases where the authentication process encounters
an issue, such as an invalid token.

Attributes:
None
"""

pass


class InvalidVersion(Exception):
"""Exception raised for an invalid version during authentication.

This exception is raised when the version provided during the authentication
process is not compatible with the current version of the server.

Attributes:
None
"""

pass


class AuthClient(ClientCommand):
"""Command for authenticating the client with the server.

Arguments:
token (String): Token of the client
version (Integer): Version number of the running client framework

Response:
uuid (Integer): UUID assigned by the server to the client
"""

arguments = [(b"token", String()), (b"version", Integer())]
response = [(b"uuid", Integer())]
fatalErrors = {
AuthFailed: b"INVALID_TOKEN",
InvalidVersion: b"INCOMPATIBLE_VERSION",
}


class StartGame(ServerCommand):
"""Command to notify the client that the game starts"""

arguments = [(b"game_id", Integer())]
response = [(b"ready", Boolean())]


class EndGame(ServerCommand):
"""Command to notify the client that the game has ended"""

arguments = [
(b"result", Boolean()),
(b"stats", Integer()),
] # Integer acts as a dummy type, we might want to create a custom data-type here!
response = [(b"ready", Boolean())]


class Step(ServerCommand):
"""Command for requesting the next step from the agent"""

arguments = [
(b"env", Integer())
] # Integer acts as a dummy type, we might want to create a custom data-type here!
response = [
(b"action", Integer())
] # Integer acts as a dummy type, we might want to create a custom data-type here!
5 changes: 5 additions & 0 deletions tests/default_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Default Test"""


def test_default():
assert ("this is a default " + "test") == "this is a default test"
10 changes: 0 additions & 10 deletions tests/test_example.py

This file was deleted.

Loading