Module server.types

General type definitions

Classes

class Address (host: str, port: int)
Expand source code
class Address(NamedTuple):
    """A peer IP address"""

    host: str
    port: int

    @classmethod
    def from_string(cls, address: str) -> "Address":
        host, port = address.rsplit(":", 1)
        return cls(host, int(port))

A peer IP address

Ancestors

  • builtins.tuple

Static methods

def from_string(address: str) ‑> Address

Instance variables

var host : str
Expand source code
class Address(NamedTuple):
    """A peer IP address"""

    host: str
    port: int

    @classmethod
    def from_string(cls, address: str) -> "Address":
        host, port = address.rsplit(":", 1)
        return cls(host, int(port))

Alias for field number 0

var port : int
Expand source code
class Address(NamedTuple):
    """A peer IP address"""

    host: str
    port: int

    @classmethod
    def from_string(cls, address: str) -> "Address":
        host, port = address.rsplit(":", 1)
        return cls(host, int(port))

Alias for field number 1

class GameLaunchOptions (mapname: str | None = None,
team: int | None = None,
faction: int | None = None,
expected_players: int | None = None,
map_position: int | None = None,
game_options: dict[str, typing.Any] | None = None)
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Additional options used to configure the FA lobby

Ancestors

  • builtins.tuple

Instance variables

var expected_players : int | None
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Alias for field number 3

var faction : int | None
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Alias for field number 2

var game_options : dict[str, typing.Any] | None
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Alias for field number 5

var map_position : int | None
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Alias for field number 4

var mapname : str | None
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Alias for field number 0

var team : int | None
Expand source code
class GameLaunchOptions(NamedTuple):
    """Additional options used to configure the FA lobby"""

    mapname: Optional[str] = None
    team: Optional[int] = None
    faction: Optional[int] = None
    expected_players: Optional[int] = None
    map_position: Optional[int] = None
    game_options: Optional[dict[str, Any]] = None

Alias for field number 1

class Map (id: int | None, folder_name: str, ranked: bool = False, weight: int = 1)
Expand source code
class Map(NamedTuple):
    id: Optional[int]
    folder_name: str
    ranked: bool = False
    # Map pool only
    weight: int = 1

    @property
    def file_path(self):
        """A representation of the map name as it looks in the database"""
        return f"maps/{self.folder_name}.zip"

    @property
    def scenario_file(self):
        return f"/maps/{self.folder_name}/{self.folder_name}_scenario.lua"

    def get_map(self) -> "Map":
        return self

Map(id, folder_name, ranked, weight)

Ancestors

  • builtins.tuple

Instance variables

prop file_path
Expand source code
@property
def file_path(self):
    """A representation of the map name as it looks in the database"""
    return f"maps/{self.folder_name}.zip"

A representation of the map name as it looks in the database

var folder_name : str
Expand source code
class Map(NamedTuple):
    id: Optional[int]
    folder_name: str
    ranked: bool = False
    # Map pool only
    weight: int = 1

    @property
    def file_path(self):
        """A representation of the map name as it looks in the database"""
        return f"maps/{self.folder_name}.zip"

    @property
    def scenario_file(self):
        return f"/maps/{self.folder_name}/{self.folder_name}_scenario.lua"

    def get_map(self) -> "Map":
        return self

Alias for field number 1

var id : int | None
Expand source code
class Map(NamedTuple):
    id: Optional[int]
    folder_name: str
    ranked: bool = False
    # Map pool only
    weight: int = 1

    @property
    def file_path(self):
        """A representation of the map name as it looks in the database"""
        return f"maps/{self.folder_name}.zip"

    @property
    def scenario_file(self):
        return f"/maps/{self.folder_name}/{self.folder_name}_scenario.lua"

    def get_map(self) -> "Map":
        return self

Alias for field number 0

var ranked : bool
Expand source code
class Map(NamedTuple):
    id: Optional[int]
    folder_name: str
    ranked: bool = False
    # Map pool only
    weight: int = 1

    @property
    def file_path(self):
        """A representation of the map name as it looks in the database"""
        return f"maps/{self.folder_name}.zip"

    @property
    def scenario_file(self):
        return f"/maps/{self.folder_name}/{self.folder_name}_scenario.lua"

    def get_map(self) -> "Map":
        return self

Alias for field number 2

prop scenario_file
Expand source code
@property
def scenario_file(self):
    return f"/maps/{self.folder_name}/{self.folder_name}_scenario.lua"
var weight : int
Expand source code
class Map(NamedTuple):
    id: Optional[int]
    folder_name: str
    ranked: bool = False
    # Map pool only
    weight: int = 1

    @property
    def file_path(self):
        """A representation of the map name as it looks in the database"""
        return f"maps/{self.folder_name}.zip"

    @property
    def scenario_file(self):
        return f"/maps/{self.folder_name}/{self.folder_name}_scenario.lua"

    def get_map(self) -> "Map":
        return self

Alias for field number 3

Methods

def get_map(self) ‑> Map
Expand source code
def get_map(self) -> "Map":
    return self
class MapPoolMap (*args, **kwargs)
Expand source code
class MapPoolMap(Protocol):
    id: int
    weight: int

    def get_map(self) -> "Map": ...

Base class for protocol classes.

Protocol classes are defined as::

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example::

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as::

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...

Ancestors

  • typing.Protocol
  • typing.Generic

Class variables

var id : int
var weight : int

Methods

def get_map(self) ‑> Map
Expand source code
def get_map(self) -> "Map": ...
class NeroxisGeneratedMap (id: int, version: str, spawns: int, map_size_pixels: int, weight: int = 1)
Expand source code
class NeroxisGeneratedMap(NamedTuple):
    id: int
    version: str
    spawns: int
    map_size_pixels: int
    weight: int = 1

    _NAME_PATTERN = re.compile(
        "neroxis_map_generator_([0-9.]+)_([a-z2-7]+)_([a-z2-7]+)"
    )

    @classmethod
    def is_neroxis_map(cls, folder_name: str) -> bool:
        """Check if mapname is map generator"""
        return cls._NAME_PATTERN.fullmatch(folder_name) is not None

    @classmethod
    def of(cls, params: dict, weight: int = 1):
        """Create a NeroxisGeneratedMap from params dict"""
        assert params["type"] == "neroxis"

        map_size_pixels = int(params["size"])

        if map_size_pixels <= 0:
            raise Exception("Map size is zero or negative")

        if map_size_pixels % 64 != 0:
            raise Exception("Map size is not a multiple of 64")

        spawns = int(params["spawns"])
        if spawns % 2 != 0:
            raise Exception("spawns is not a multiple of 2")

        version = params["version"]
        return cls(
            cls._get_id(version, spawns, map_size_pixels),
            version,
            spawns,
            map_size_pixels,
            weight,
        )

    @staticmethod
    def _get_id(version: str, spawns: int, map_size_pixels: int) -> int:
        return -int.from_bytes(
            bytes(
                f"{version}_{spawns}_{map_size_pixels}",
                encoding="ascii"
            ),
            "big"
        )

    def get_map(self) -> Map:
        """
        Generate a map name based on the version and parameters. If invalid
        parameters are specified hand back None
        """
        seed_bytes = random.getrandbits(64).to_bytes(8, "big")
        seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

        size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
        spawn_byte = self.spawns.to_bytes(1, "big")
        option_bytes = spawn_byte + size_byte
        option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

        folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

        return Map(
            id=self.id,
            folder_name=folder_name,
            ranked=True,
            weight=self.weight,
        )

NeroxisGeneratedMap(id, version, spawns, map_size_pixels, weight)

Ancestors

  • builtins.tuple

Static methods

def is_neroxis_map(folder_name: str) ‑> bool

Check if mapname is map generator

def of(params: dict, weight: int = 1)

Create a NeroxisGeneratedMap from params dict

Instance variables

var id : int
Expand source code
class NeroxisGeneratedMap(NamedTuple):
    id: int
    version: str
    spawns: int
    map_size_pixels: int
    weight: int = 1

    _NAME_PATTERN = re.compile(
        "neroxis_map_generator_([0-9.]+)_([a-z2-7]+)_([a-z2-7]+)"
    )

    @classmethod
    def is_neroxis_map(cls, folder_name: str) -> bool:
        """Check if mapname is map generator"""
        return cls._NAME_PATTERN.fullmatch(folder_name) is not None

    @classmethod
    def of(cls, params: dict, weight: int = 1):
        """Create a NeroxisGeneratedMap from params dict"""
        assert params["type"] == "neroxis"

        map_size_pixels = int(params["size"])

        if map_size_pixels <= 0:
            raise Exception("Map size is zero or negative")

        if map_size_pixels % 64 != 0:
            raise Exception("Map size is not a multiple of 64")

        spawns = int(params["spawns"])
        if spawns % 2 != 0:
            raise Exception("spawns is not a multiple of 2")

        version = params["version"]
        return cls(
            cls._get_id(version, spawns, map_size_pixels),
            version,
            spawns,
            map_size_pixels,
            weight,
        )

    @staticmethod
    def _get_id(version: str, spawns: int, map_size_pixels: int) -> int:
        return -int.from_bytes(
            bytes(
                f"{version}_{spawns}_{map_size_pixels}",
                encoding="ascii"
            ),
            "big"
        )

    def get_map(self) -> Map:
        """
        Generate a map name based on the version and parameters. If invalid
        parameters are specified hand back None
        """
        seed_bytes = random.getrandbits(64).to_bytes(8, "big")
        seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

        size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
        spawn_byte = self.spawns.to_bytes(1, "big")
        option_bytes = spawn_byte + size_byte
        option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

        folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

        return Map(
            id=self.id,
            folder_name=folder_name,
            ranked=True,
            weight=self.weight,
        )

Alias for field number 0

var map_size_pixels : int
Expand source code
class NeroxisGeneratedMap(NamedTuple):
    id: int
    version: str
    spawns: int
    map_size_pixels: int
    weight: int = 1

    _NAME_PATTERN = re.compile(
        "neroxis_map_generator_([0-9.]+)_([a-z2-7]+)_([a-z2-7]+)"
    )

    @classmethod
    def is_neroxis_map(cls, folder_name: str) -> bool:
        """Check if mapname is map generator"""
        return cls._NAME_PATTERN.fullmatch(folder_name) is not None

    @classmethod
    def of(cls, params: dict, weight: int = 1):
        """Create a NeroxisGeneratedMap from params dict"""
        assert params["type"] == "neroxis"

        map_size_pixels = int(params["size"])

        if map_size_pixels <= 0:
            raise Exception("Map size is zero or negative")

        if map_size_pixels % 64 != 0:
            raise Exception("Map size is not a multiple of 64")

        spawns = int(params["spawns"])
        if spawns % 2 != 0:
            raise Exception("spawns is not a multiple of 2")

        version = params["version"]
        return cls(
            cls._get_id(version, spawns, map_size_pixels),
            version,
            spawns,
            map_size_pixels,
            weight,
        )

    @staticmethod
    def _get_id(version: str, spawns: int, map_size_pixels: int) -> int:
        return -int.from_bytes(
            bytes(
                f"{version}_{spawns}_{map_size_pixels}",
                encoding="ascii"
            ),
            "big"
        )

    def get_map(self) -> Map:
        """
        Generate a map name based on the version and parameters. If invalid
        parameters are specified hand back None
        """
        seed_bytes = random.getrandbits(64).to_bytes(8, "big")
        seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

        size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
        spawn_byte = self.spawns.to_bytes(1, "big")
        option_bytes = spawn_byte + size_byte
        option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

        folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

        return Map(
            id=self.id,
            folder_name=folder_name,
            ranked=True,
            weight=self.weight,
        )

Alias for field number 3

var spawns : int
Expand source code
class NeroxisGeneratedMap(NamedTuple):
    id: int
    version: str
    spawns: int
    map_size_pixels: int
    weight: int = 1

    _NAME_PATTERN = re.compile(
        "neroxis_map_generator_([0-9.]+)_([a-z2-7]+)_([a-z2-7]+)"
    )

    @classmethod
    def is_neroxis_map(cls, folder_name: str) -> bool:
        """Check if mapname is map generator"""
        return cls._NAME_PATTERN.fullmatch(folder_name) is not None

    @classmethod
    def of(cls, params: dict, weight: int = 1):
        """Create a NeroxisGeneratedMap from params dict"""
        assert params["type"] == "neroxis"

        map_size_pixels = int(params["size"])

        if map_size_pixels <= 0:
            raise Exception("Map size is zero or negative")

        if map_size_pixels % 64 != 0:
            raise Exception("Map size is not a multiple of 64")

        spawns = int(params["spawns"])
        if spawns % 2 != 0:
            raise Exception("spawns is not a multiple of 2")

        version = params["version"]
        return cls(
            cls._get_id(version, spawns, map_size_pixels),
            version,
            spawns,
            map_size_pixels,
            weight,
        )

    @staticmethod
    def _get_id(version: str, spawns: int, map_size_pixels: int) -> int:
        return -int.from_bytes(
            bytes(
                f"{version}_{spawns}_{map_size_pixels}",
                encoding="ascii"
            ),
            "big"
        )

    def get_map(self) -> Map:
        """
        Generate a map name based on the version and parameters. If invalid
        parameters are specified hand back None
        """
        seed_bytes = random.getrandbits(64).to_bytes(8, "big")
        seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

        size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
        spawn_byte = self.spawns.to_bytes(1, "big")
        option_bytes = spawn_byte + size_byte
        option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

        folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

        return Map(
            id=self.id,
            folder_name=folder_name,
            ranked=True,
            weight=self.weight,
        )

Alias for field number 2

var version : str
Expand source code
class NeroxisGeneratedMap(NamedTuple):
    id: int
    version: str
    spawns: int
    map_size_pixels: int
    weight: int = 1

    _NAME_PATTERN = re.compile(
        "neroxis_map_generator_([0-9.]+)_([a-z2-7]+)_([a-z2-7]+)"
    )

    @classmethod
    def is_neroxis_map(cls, folder_name: str) -> bool:
        """Check if mapname is map generator"""
        return cls._NAME_PATTERN.fullmatch(folder_name) is not None

    @classmethod
    def of(cls, params: dict, weight: int = 1):
        """Create a NeroxisGeneratedMap from params dict"""
        assert params["type"] == "neroxis"

        map_size_pixels = int(params["size"])

        if map_size_pixels <= 0:
            raise Exception("Map size is zero or negative")

        if map_size_pixels % 64 != 0:
            raise Exception("Map size is not a multiple of 64")

        spawns = int(params["spawns"])
        if spawns % 2 != 0:
            raise Exception("spawns is not a multiple of 2")

        version = params["version"]
        return cls(
            cls._get_id(version, spawns, map_size_pixels),
            version,
            spawns,
            map_size_pixels,
            weight,
        )

    @staticmethod
    def _get_id(version: str, spawns: int, map_size_pixels: int) -> int:
        return -int.from_bytes(
            bytes(
                f"{version}_{spawns}_{map_size_pixels}",
                encoding="ascii"
            ),
            "big"
        )

    def get_map(self) -> Map:
        """
        Generate a map name based on the version and parameters. If invalid
        parameters are specified hand back None
        """
        seed_bytes = random.getrandbits(64).to_bytes(8, "big")
        seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

        size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
        spawn_byte = self.spawns.to_bytes(1, "big")
        option_bytes = spawn_byte + size_byte
        option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

        folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

        return Map(
            id=self.id,
            folder_name=folder_name,
            ranked=True,
            weight=self.weight,
        )

Alias for field number 1

var weight : int
Expand source code
class NeroxisGeneratedMap(NamedTuple):
    id: int
    version: str
    spawns: int
    map_size_pixels: int
    weight: int = 1

    _NAME_PATTERN = re.compile(
        "neroxis_map_generator_([0-9.]+)_([a-z2-7]+)_([a-z2-7]+)"
    )

    @classmethod
    def is_neroxis_map(cls, folder_name: str) -> bool:
        """Check if mapname is map generator"""
        return cls._NAME_PATTERN.fullmatch(folder_name) is not None

    @classmethod
    def of(cls, params: dict, weight: int = 1):
        """Create a NeroxisGeneratedMap from params dict"""
        assert params["type"] == "neroxis"

        map_size_pixels = int(params["size"])

        if map_size_pixels <= 0:
            raise Exception("Map size is zero or negative")

        if map_size_pixels % 64 != 0:
            raise Exception("Map size is not a multiple of 64")

        spawns = int(params["spawns"])
        if spawns % 2 != 0:
            raise Exception("spawns is not a multiple of 2")

        version = params["version"]
        return cls(
            cls._get_id(version, spawns, map_size_pixels),
            version,
            spawns,
            map_size_pixels,
            weight,
        )

    @staticmethod
    def _get_id(version: str, spawns: int, map_size_pixels: int) -> int:
        return -int.from_bytes(
            bytes(
                f"{version}_{spawns}_{map_size_pixels}",
                encoding="ascii"
            ),
            "big"
        )

    def get_map(self) -> Map:
        """
        Generate a map name based on the version and parameters. If invalid
        parameters are specified hand back None
        """
        seed_bytes = random.getrandbits(64).to_bytes(8, "big")
        seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

        size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
        spawn_byte = self.spawns.to_bytes(1, "big")
        option_bytes = spawn_byte + size_byte
        option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

        folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

        return Map(
            id=self.id,
            folder_name=folder_name,
            ranked=True,
            weight=self.weight,
        )

Alias for field number 4

Methods

def get_map(self) ‑> Map
Expand source code
def get_map(self) -> Map:
    """
    Generate a map name based on the version and parameters. If invalid
    parameters are specified hand back None
    """
    seed_bytes = random.getrandbits(64).to_bytes(8, "big")
    seed_str = base64.b32encode(seed_bytes).decode("ascii").replace("=", "").lower()

    size_byte = (self.map_size_pixels // 64).to_bytes(1, "big")
    spawn_byte = self.spawns.to_bytes(1, "big")
    option_bytes = spawn_byte + size_byte
    option_str = base64.b32encode(option_bytes).decode("ascii").replace("=", "").lower()

    folder_name = f"neroxis_map_generator_{self.version}_{seed_str}_{option_str}"

    return Map(
        id=self.id,
        folder_name=folder_name,
        ranked=True,
        weight=self.weight,
    )

Generate a map name based on the version and parameters. If invalid parameters are specified hand back None