diff --git a/opengsq/responses/source/environment.py b/opengsq/responses/source/environment.py index 78fc6c2..53bb20d 100644 --- a/opengsq/responses/source/environment.py +++ b/opengsq/responses/source/environment.py @@ -17,4 +17,18 @@ class Environment(IntEnum): @staticmethod def parse(byte: int): - return Environment(ord(chr(byte).lower())) + """ + Parses the given byte to an Environment value. If the byte does not correspond to a valid + Environment value, it defaults to Environment.Mac. + + Args: + byte (int): The byte to parse. + + Returns: + Environment: The corresponding Environment value, or Environment.Mac if the byte is not valid. + """ + try: + return Environment(ord(chr(byte).lower())) + except ValueError: + # 'm' or 'o' for Mac (the code changed after L4D1) + return Environment.Mac diff --git a/opengsq/responses/source/server_type.py b/opengsq/responses/source/server_type.py index 115a17b..249c69e 100644 --- a/opengsq/responses/source/server_type.py +++ b/opengsq/responses/source/server_type.py @@ -17,4 +17,14 @@ class ServerType(IntEnum): @staticmethod def parse(byte: int): + """ + Parses the given byte to a ServerType value. If the byte does not correspond to a valid + ServerType value, a ValueError is raised. + + Args: + byte (int): The byte to parse. + + Returns: + ServerType: The corresponding ServerType value. + """ return ServerType(ord(chr(byte).lower()))