-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4545b72
commit 3916c33
Showing
13 changed files
with
206 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .authentication_exception import AuthenticationException | ||
from .invalid_packet_exception import InvalidPacketException | ||
from .server_not_found_exception import ServerNotFoundException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class AuthenticationException(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class InvalidPacketException(Exception): | ||
"""Represents errors that occur during application execution when a packet is invalid.""" | ||
|
||
def __init__(self, message: str): | ||
""" | ||
Initializes a new instance of the InvalidPacketException class with a specified error message. | ||
Args: | ||
message (str): The message that describes the error. | ||
""" | ||
super().__init__(message) | ||
|
||
@staticmethod | ||
def throw_if_not_equal(received, expected): | ||
""" | ||
Checks if the received value is equal to the expected value. | ||
Args: | ||
received: The received value. | ||
expected: The expected value. | ||
Raises: | ||
InvalidPacketException: Thrown when the received value does not match the expected value. | ||
""" | ||
if isinstance(received, bytes) and isinstance(expected, bytes): | ||
if received != expected: | ||
raise InvalidPacketException( | ||
InvalidPacketException.get_message(received, expected) | ||
) | ||
elif received != expected: | ||
raise InvalidPacketException( | ||
InvalidPacketException.get_message(received, expected) | ||
) | ||
|
||
@staticmethod | ||
def get_message(received, expected): | ||
""" | ||
Returns a formatted error message. | ||
Args: | ||
received: The received value. | ||
expected: The expected value. | ||
Returns: | ||
str: The formatted error message. | ||
""" | ||
if isinstance(received, bytes) and isinstance(expected, bytes): | ||
received_str = " ".join(format(x, "02x") for x in received) | ||
expected_str = " ".join(format(x, "02x") for x in expected) | ||
else: | ||
received_str = str(received) | ||
expected_str = str(expected) | ||
|
||
return f"Packet header mismatch. Received: {received_str}. Expected: {expected_str}." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ServerNotFoundException(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .player import Player | ||
from .status import Status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dataclasses import asdict, dataclass | ||
|
||
|
||
@dataclass | ||
class Player: | ||
""" | ||
Represents a player in the game. | ||
Attributes: | ||
name (str): The name of the player. | ||
team (str): The team of the player. | ||
skin (str): The skin of the player. | ||
score (int): The score of the player. | ||
ping (int): The ping of the player. | ||
time (int): The time of the player. | ||
""" | ||
|
||
name: str | ||
team: str | ||
skin: str | ||
score: int | ||
ping: int | ||
time: int | ||
|
||
@property | ||
def __dict__(self): | ||
return asdict(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from dataclasses import asdict, dataclass, field | ||
|
||
from opengsq.responses.ase.player import Player | ||
|
||
|
||
@dataclass | ||
class Status: | ||
""" | ||
Represents the status of a game server. | ||
Attributes: | ||
gamename (str): The name of the game. | ||
gameport (int): The port number of the game server. | ||
hostname (str): The hostname of the game server. | ||
gametype (str): The type of the game. | ||
map (str): The current map of the game. | ||
version (str): The version of the game. | ||
password (bool): Whether a password is required to join the game. | ||
numplayers (int): The number of players currently in the game. | ||
maxplayers (int): The maximum number of players allowed in the game. | ||
rules (dict[str, str]): The rules of the game. Defaults to an empty dictionary. | ||
players (list[Player]): The players currently in the game. Defaults to an empty list. | ||
""" | ||
|
||
gamename: str | ||
gameport: int | ||
hostname: str | ||
gametype: str | ||
map: str | ||
version: str | ||
password: bool | ||
numplayers: int | ||
maxplayers: int | ||
rules: dict[str, str] = field(default_factory=dict) | ||
players: list[Player] = field(default_factory=list) | ||
|
||
@property | ||
def __dict__(self): | ||
return asdict(self) |