Bombsquad-Ballistica-Modded.../dist/ba_data/python/bacommon/net.py

100 lines
2.7 KiB
Python
Raw Normal View History

2021-05-30 02:08:06 +05:30
# Released under the MIT License. See LICENSE for details.
#
"""Network related data and functionality."""
from __future__ import annotations
2022-07-16 17:59:14 +05:30
import datetime
2022-06-30 00:31:52 +05:30
from typing import TYPE_CHECKING, Any, Annotated
2021-10-26 23:32:18 +05:30
from dataclasses import dataclass, field
2021-05-30 02:08:06 +05:30
2021-10-26 23:32:18 +05:30
from efro.dataclassio import ioprepped, IOAttrs
2021-05-30 02:08:06 +05:30
if TYPE_CHECKING:
pass
2021-10-26 23:32:18 +05:30
@ioprepped
@dataclass
class ServerNodeEntry:
2021-05-30 02:08:06 +05:30
"""Information about a specific server."""
2022-06-09 01:26:46 +05:30
zone: Annotated[str, IOAttrs('r')]
2024-05-19 18:25:43 +05:30
# TODO: Remove soft_default after all master-servers upgraded.
latlong: Annotated[
tuple[float, float] | None, IOAttrs('ll', soft_default=None)
]
2021-10-26 23:32:18 +05:30
address: Annotated[str, IOAttrs('a')]
port: Annotated[int, IOAttrs('p')]
2021-05-30 02:08:06 +05:30
2021-10-26 23:32:18 +05:30
@ioprepped
@dataclass
class ServerNodeQueryResponse:
2021-05-30 02:08:06 +05:30
"""A response to a query about server-nodes."""
2022-07-16 17:59:14 +05:30
# The current utc time on the master server.
time: Annotated[datetime.datetime, IOAttrs('t')]
2024-05-19 18:25:43 +05:30
# Where the master server sees the query as coming from.
latlong: Annotated[tuple[float, float] | None, IOAttrs('ll')]
ping_per_dist: Annotated[float, IOAttrs('ppd')]
max_dist: Annotated[float, IOAttrs('md')]
debug_log_seconds: Annotated[
float | None, IOAttrs('d', store_default=False)
] = None
2021-05-30 02:08:06 +05:30
# If present, something went wrong, and this describes it.
2022-06-30 00:31:52 +05:30
error: Annotated[str | None, IOAttrs('e', store_default=False)] = None
2021-05-30 02:08:06 +05:30
# The set of servernodes.
servers: Annotated[
list[ServerNodeEntry], IOAttrs('s', store_default=False)
] = field(default_factory=list)
2021-05-30 02:08:06 +05:30
@ioprepped
@dataclass
class PrivateHostingState:
"""Combined state of whether we're hosting, whether we can, etc."""
2022-06-30 00:31:52 +05:30
unavailable_error: str | None = None
party_code: str | None = None
2021-05-30 02:08:06 +05:30
tickets_to_host_now: int = 0
2022-06-30 00:31:52 +05:30
minutes_until_free_host: float | None = None
free_host_minutes_remaining: float | None = None
2021-05-30 02:08:06 +05:30
@ioprepped
@dataclass
class PrivateHostingConfig:
"""Config provided when hosting a private party."""
2021-05-30 02:08:06 +05:30
session_type: str = 'ffa'
playlist_name: str = 'Unknown'
randomize: bool = False
tutorial: bool = False
2022-06-30 00:31:52 +05:30
custom_team_names: tuple[str, str] | None = None
2024-03-10 15:37:50 +05:30
custom_team_colors: (
tuple[tuple[float, float, float], tuple[float, float, float]] | None
) = None
2022-06-30 00:31:52 +05:30
playlist: list[dict[str, Any]] | None = None
2021-10-26 23:32:18 +05:30
exit_minutes: float = 120.0
exit_minutes_unclean: float = 180.0
exit_minutes_idle: float = 10.0
2021-05-30 02:08:06 +05:30
@ioprepped
@dataclass
class PrivatePartyConnectResult:
"""Info about a server we get back when connecting."""
2022-06-30 00:31:52 +05:30
error: str | None = None
2024-05-19 18:25:43 +05:30
address4: Annotated[str | None, IOAttrs('addr')] = None
address6: Annotated[str | None, IOAttrs('addr6')] = None
2022-06-30 00:31:52 +05:30
port: int | None = None
password: str | None = None