bacommon.net

Network related data and functionality.

 1# Released under the MIT License. See LICENSE for details.
 2#
 3"""Network related data and functionality."""
 4
 5from __future__ import annotations
 6
 7import datetime
 8from typing import TYPE_CHECKING, Any, Annotated
 9from dataclasses import dataclass, field
10
11from efro.dataclassio import ioprepped, IOAttrs
12
13if TYPE_CHECKING:
14    pass
15
16
17@ioprepped
18@dataclass
19class ServerNodeEntry:
20    """Information about a specific server."""
21
22    zone: Annotated[str, IOAttrs('r')]
23    address: Annotated[str, IOAttrs('a')]
24    port: Annotated[int, IOAttrs('p')]
25
26
27@ioprepped
28@dataclass
29class ServerNodeQueryResponse:
30    """A response to a query about server-nodes."""
31
32    # The current utc time on the master server.
33    time: Annotated[datetime.datetime, IOAttrs('t')]
34
35    # If present, something went wrong, and this describes it.
36    error: Annotated[str | None, IOAttrs('e', store_default=False)] = None
37
38    # The set of servernodes.
39    servers: Annotated[
40        list[ServerNodeEntry], IOAttrs('s', store_default=False)
41    ] = field(default_factory=list)
42
43
44@ioprepped
45@dataclass
46class PrivateHostingState:
47    """Combined state of whether we're hosting, whether we can, etc."""
48
49    unavailable_error: str | None = None
50    party_code: str | None = None
51    tickets_to_host_now: int = 0
52    minutes_until_free_host: float | None = None
53    free_host_minutes_remaining: float | None = None
54
55
56@ioprepped
57@dataclass
58class PrivateHostingConfig:
59    """Config provided when hosting a private party."""
60
61    session_type: str = 'ffa'
62    playlist_name: str = 'Unknown'
63    randomize: bool = False
64    tutorial: bool = False
65    custom_team_names: tuple[str, str] | None = None
66    custom_team_colors: (
67        tuple[tuple[float, float, float], tuple[float, float, float]] | None
68    ) = None
69    playlist: list[dict[str, Any]] | None = None
70    exit_minutes: float = 120.0
71    exit_minutes_unclean: float = 180.0
72    exit_minutes_idle: float = 10.0
73
74
75@ioprepped
76@dataclass
77class PrivatePartyConnectResult:
78    """Info about a server we get back when connecting."""
79
80    error: str | None = None
81    addr: str | None = None
82    port: int | None = None
83    password: str | None = None
@ioprepped
@dataclass
class ServerNodeEntry:
18@ioprepped
19@dataclass
20class ServerNodeEntry:
21    """Information about a specific server."""
22
23    zone: Annotated[str, IOAttrs('r')]
24    address: Annotated[str, IOAttrs('a')]
25    port: Annotated[int, IOAttrs('p')]

Information about a specific server.

ServerNodeEntry( zone: Annotated[str, <efro.dataclassio._base.IOAttrs object>], address: Annotated[str, <efro.dataclassio._base.IOAttrs object>], port: Annotated[int, <efro.dataclassio._base.IOAttrs object>])
zone: Annotated[str, <efro.dataclassio._base.IOAttrs object at 0x1078ff3e0>]
address: Annotated[str, <efro.dataclassio._base.IOAttrs object at 0x108230890>]
port: Annotated[int, <efro.dataclassio._base.IOAttrs object at 0x108233170>]
@ioprepped
@dataclass
class ServerNodeQueryResponse:
28@ioprepped
29@dataclass
30class ServerNodeQueryResponse:
31    """A response to a query about server-nodes."""
32
33    # The current utc time on the master server.
34    time: Annotated[datetime.datetime, IOAttrs('t')]
35
36    # If present, something went wrong, and this describes it.
37    error: Annotated[str | None, IOAttrs('e', store_default=False)] = None
38
39    # The set of servernodes.
40    servers: Annotated[
41        list[ServerNodeEntry], IOAttrs('s', store_default=False)
42    ] = field(default_factory=list)

A response to a query about server-nodes.

ServerNodeQueryResponse( time: Annotated[datetime.datetime, <efro.dataclassio._base.IOAttrs object>], error: Annotated[str | None, <efro.dataclassio._base.IOAttrs object>] = None, servers: Annotated[list[ServerNodeEntry], <efro.dataclassio._base.IOAttrs object>] = <factory>)
time: Annotated[datetime.datetime, <efro.dataclassio._base.IOAttrs object at 0x108233710>]
error: Annotated[str | None, <efro.dataclassio._base.IOAttrs object at 0x108233980>] = None
servers: Annotated[list[ServerNodeEntry], <efro.dataclassio._base.IOAttrs object at 0x108233b60>]
@ioprepped
@dataclass
class PrivateHostingState:
45@ioprepped
46@dataclass
47class PrivateHostingState:
48    """Combined state of whether we're hosting, whether we can, etc."""
49
50    unavailable_error: str | None = None
51    party_code: str | None = None
52    tickets_to_host_now: int = 0
53    minutes_until_free_host: float | None = None
54    free_host_minutes_remaining: float | None = None

Combined state of whether we're hosting, whether we can, etc.

PrivateHostingState( unavailable_error: str | None = None, party_code: str | None = None, tickets_to_host_now: int = 0, minutes_until_free_host: float | None = None, free_host_minutes_remaining: float | None = None)
unavailable_error: str | None = None
party_code: str | None = None
tickets_to_host_now: int = 0
minutes_until_free_host: float | None = None
free_host_minutes_remaining: float | None = None
@ioprepped
@dataclass
class PrivateHostingConfig:
57@ioprepped
58@dataclass
59class PrivateHostingConfig:
60    """Config provided when hosting a private party."""
61
62    session_type: str = 'ffa'
63    playlist_name: str = 'Unknown'
64    randomize: bool = False
65    tutorial: bool = False
66    custom_team_names: tuple[str, str] | None = None
67    custom_team_colors: (
68        tuple[tuple[float, float, float], tuple[float, float, float]] | None
69    ) = None
70    playlist: list[dict[str, Any]] | None = None
71    exit_minutes: float = 120.0
72    exit_minutes_unclean: float = 180.0
73    exit_minutes_idle: float = 10.0

Config provided when hosting a private party.

PrivateHostingConfig( session_type: str = 'ffa', playlist_name: str = 'Unknown', randomize: bool = False, tutorial: bool = False, custom_team_names: tuple[str, str] | None = None, custom_team_colors: tuple[tuple[float, float, float], tuple[float, float, float]] | None = None, playlist: list[dict[str, typing.Any]] | None = None, exit_minutes: float = 120.0, exit_minutes_unclean: float = 180.0, exit_minutes_idle: float = 10.0)
session_type: str = 'ffa'
playlist_name: str = 'Unknown'
randomize: bool = False
tutorial: bool = False
custom_team_names: tuple[str, str] | None = None
custom_team_colors: tuple[tuple[float, float, float], tuple[float, float, float]] | None = None
playlist: list[dict[str, typing.Any]] | None = None
exit_minutes: float = 120.0
exit_minutes_unclean: float = 180.0
exit_minutes_idle: float = 10.0
@ioprepped
@dataclass
class PrivatePartyConnectResult:
76@ioprepped
77@dataclass
78class PrivatePartyConnectResult:
79    """Info about a server we get back when connecting."""
80
81    error: str | None = None
82    addr: str | None = None
83    port: int | None = None
84    password: str | None = None

Info about a server we get back when connecting.

PrivatePartyConnectResult( error: str | None = None, addr: str | None = None, port: int | None = None, password: str | None = None)
error: str | None = None
addr: str | None = None
port: int | None = None
password: str | None = None