Module server.types

General type definitions

Classes

class Address (host: str, port: int)

A peer IP address

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))

Ancestors

  • builtins.tuple

Static methods

def from_string(address: str) ‑> Address

Instance variables

var host : str

Alias for field number 0

var port : int

Alias for field number 1

class GameLaunchOptions (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, typing.Any]] = None)

Additional options used to configure the FA lobby

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

Ancestors

  • builtins.tuple

Instance variables

var expected_players : Optional[int]

Alias for field number 3

var faction : Optional[int]

Alias for field number 2

var game_options : Optional[dict[str, typing.Any]]

Alias for field number 5

var map_position : Optional[int]

Alias for field number 4

var mapname : Optional[str]

Alias for field number 0

var team : Optional[int]

Alias for field number 1

class Map (id: Optional[int], folder_name: str, ranked: bool = False, weight: int = 1)

Map(id, folder_name, ranked, weight)

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

Ancestors

  • builtins.tuple

Instance variables

prop file_path

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

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"
var folder_name : str

Alias for field number 1

var id : Optional[int]

Alias for field number 0

var ranked : bool

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

Alias for field number 3

Methods

def get_map(self) ‑> Map
class MapPoolMap (*args, **kwargs)

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:
        ...
Expand source code
class MapPoolMap(Protocol):
    id: int
    weight: int

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

Ancestors

  • typing.Protocol
  • typing.Generic

Class variables

var id : int
var weight : int

Methods

def get_map(self) ‑> Map
class NeroxisGeneratedMap (id: int, version: str, spawns: int, map_size_pixels: int, weight: int = 1)

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

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,
        )

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

Alias for field number 0

var map_size_pixels : int

Alias for field number 3

var spawns : int

Alias for field number 2

var version : str

Alias for field number 1

var weight : int

Alias for field number 4

Methods

def get_map(self) ‑> Map

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