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

79 lines
2.2 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')]
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')]
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],
2021-10-26 23:32:18 +05:30
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."""
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
custom_team_colors: tuple[tuple[float, float, float],
tuple[float, float, float]] | None = None
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
addr: str | None = None
port: int | None = None
password: str | None = None