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

247 lines
8.8 KiB
Python
Raw Normal View History

2021-03-29 03:24:13 +05:30
# Released under the MIT License. See LICENSE for details.
#
"""Functionality related to the server manager script."""
from __future__ import annotations
from enum import Enum
2021-05-30 02:08:06 +05:30
from dataclasses import field, dataclass
2022-06-30 00:31:52 +05:30
from typing import TYPE_CHECKING, Any
2021-05-30 02:08:06 +05:30
from efro.dataclassio import ioprepped
2021-03-29 03:24:13 +05:30
if TYPE_CHECKING:
2021-05-30 02:08:06 +05:30
pass
2021-03-29 03:24:13 +05:30
2021-05-30 02:08:06 +05:30
@ioprepped
2021-03-29 03:24:13 +05:30
@dataclass
class ServerConfig:
"""Configuration for the server manager app (<appname>_server)."""
# Name of our server in the public parties list.
party_name: str = 'FFA'
# If True, your party will show up in the global public party list
2024-05-19 18:25:43 +05:30
# Otherwise it will still be joinable via LAN or connecting by IP
# address.
2021-03-29 03:24:13 +05:30
party_is_public: bool = True
2024-05-19 18:25:43 +05:30
# If True, all connecting clients will be authenticated through the
# master server to screen for fake account info. Generally this
# should always be enabled unless you are hosting on a LAN with no
# internet connection.
2021-03-29 03:24:13 +05:30
authenticate_clients: bool = True
2024-05-19 18:25:43 +05:30
# IDs of server admins. Server admins are not kickable through the
# default kick vote system and they are able to kick players without
# a vote. To get your account id, enter 'getaccountid' in
# settings->advanced->enter-code.
admins: list[str] = field(default_factory=list)
2021-03-29 03:24:13 +05:30
# Whether the default kick-voting system is enabled.
enable_default_kick_voting: bool = True
2024-05-19 18:25:43 +05:30
# To be included in the public server list, your server MUST be
# accessible via an ipv4 address. By default, the master server will
# try to use the address your server contacts it from, but this may
# be an ipv6 address these days so you may need to provide an ipv4
# address explicitly.
public_ipv4_address: str | None = None
# You can optionally provide an ipv6 address for your server for the
# public server list. Unlike ipv4, a server is not required to have
# an ipv6 address to appear in the list, but is still good to
# provide when available since more and more devices are using ipv6
# these days. Your server's ipv6 address will be autodetected if
# your server uses ipv6 when communicating with the master server. You
# can pass an empty string here to explicitly disable the ipv6
# address.
public_ipv6_address: str | None = None
# UDP port to host on. Change this to work around firewalls or run
# multiple servers on one machine.
#
# 43210 is the default and the only port that will show up in the
# LAN browser tab.
2021-03-29 03:24:13 +05:30
port: int = 43210
2024-05-19 18:25:43 +05:30
# Max devices in the party. Note that this does *NOT* mean max
# players. Any device in the party can have more than one player on
# it if they have multiple controllers. Also, this number currently
# includes the server so generally make it 1 bigger than you need.
2021-03-29 03:24:13 +05:30
max_party_size: int = 6
2024-05-19 18:25:43 +05:30
# Max players that can join a session. If present this will override
# the session's preferred max_players. if a value below 0 is given
# player limit will be removed.
session_max_players_override: int | None = None
# Options here are 'ffa' (free-for-all), 'teams' and 'coop'
# (cooperative) This value is ignored if you supply a playlist_code
# (see below).
2021-03-29 03:24:13 +05:30
session_type: str = 'ffa'
2024-05-19 18:25:43 +05:30
# Playlist-code for teams or free-for-all mode sessions. To host
# your own custom playlists, use the 'share' functionality in the
# playlist editor in the regular version of the game. This will give
# you a numeric code you can enter here to host that playlist.
2022-06-30 00:31:52 +05:30
playlist_code: int | None = None
2021-03-29 03:24:13 +05:30
2024-05-19 18:25:43 +05:30
# Alternately, you can embed playlist data here instead of using
# codes. Make sure to set session_type to the correct type for the
# data here.
2022-06-30 00:31:52 +05:30
playlist_inline: list[dict[str, Any]] | None = None
2021-05-30 02:08:06 +05:30
2024-05-19 18:25:43 +05:30
# Whether to shuffle the playlist or play its games in designated
# order.
2021-03-29 03:24:13 +05:30
playlist_shuffle: bool = True
2024-05-19 18:25:43 +05:30
# If True, keeps team sizes equal by disallowing joining the largest
# team (teams mode only).
2021-03-29 03:24:13 +05:30
auto_balance_teams: bool = True
2024-05-19 18:25:43 +05:30
# The campaign used when in co-op session mode. Do
# print(ba.app.campaigns) to see available campaign names.
2021-10-26 23:32:18 +05:30
coop_campaign: str = 'Easy'
2024-05-19 18:25:43 +05:30
# The level name within the campaign used in co-op session mode. For
# campaign name FOO, do print(ba.app.campaigns['FOO'].levels) to see
2021-10-26 23:32:18 +05:30
# available level names.
coop_level: str = 'Onslaught Training'
2021-03-29 03:24:13 +05:30
# Whether to enable telnet access.
2024-05-19 18:25:43 +05:30
#
# IMPORTANT: This option is no longer available, as it was being
# used for exploits. Live access to the running server is still
# possible through the mgr.cmd() function in the server script. Run
# your server through tools such as 'screen' or 'tmux' and you can
# reconnect to it remotely over a secure ssh connection.
2021-03-29 03:24:13 +05:30
enable_telnet: bool = False
# Series length in teams mode (7 == 'best-of-7' series; a team must
# get 4 wins)
teams_series_length: int = 7
2024-05-19 18:25:43 +05:30
# Points to win in free-for-all mode (Points are awarded per game
# based on performance)
2021-03-29 03:24:13 +05:30
ffa_series_length: int = 24
2024-05-19 18:25:43 +05:30
# If you have a custom stats webpage for your server, you can use
# this to provide a convenient in-game link to it in the
# server-browser alongside the server name.
#
2021-03-29 03:24:13 +05:30
# if ${ACCOUNT} is present in the string, it will be replaced by the
# currently-signed-in account's id. To fetch info about an account,
2021-05-30 02:08:06 +05:30
# your back-end server can use the following url:
2022-03-13 17:33:09 +05:30
# https://legacy.ballistica.net/accountquery?id=ACCOUNT_ID_HERE
2022-06-30 00:31:52 +05:30
stats_url: str | None = None
2021-03-29 03:24:13 +05:30
2024-05-19 18:25:43 +05:30
# If present, the server subprocess will attempt to gracefully exit
# after this amount of time. A graceful exit can occur at the end of
# a series or other opportune time. Server-managers set to
# auto-restart (the default) will then spin up a fresh subprocess.
# This mechanism can be useful to clear out any memory leaks or
# other accumulated bad state in the server subprocess.
2022-06-30 00:31:52 +05:30
clean_exit_minutes: float | None = None
2021-03-29 03:24:13 +05:30
2024-05-19 18:25:43 +05:30
# If present, the server subprocess will shut down immediately after
# this amount of time. This can be useful as a fallback for
# clean_exit_time. The server manager will then spin up a fresh
# server subprocess if auto-restart is enabled (the default).
2022-06-30 00:31:52 +05:30
unclean_exit_minutes: float | None = None
2021-03-29 03:24:13 +05:30
2024-05-19 18:25:43 +05:30
# If present, the server subprocess will shut down immediately if
# this amount of time passes with no activity from any players. The
# server manager will then spin up a fresh server subprocess if
# auto-restart is enabled (the default).
2022-06-30 00:31:52 +05:30
idle_exit_minutes: float | None = None
2021-03-29 03:24:13 +05:30
2021-05-30 02:08:06 +05:30
# Should the tutorial be shown at the beginning of games?
show_tutorial: bool = False
# Team names (teams mode only).
2022-06-30 00:31:52 +05:30
team_names: tuple[str, str] | None = None
2021-05-30 02:08:06 +05:30
# Team colors (teams mode only).
2024-03-10 15:37:50 +05:30
team_colors: (
tuple[tuple[float, float, float], tuple[float, float, float]] | None
) = None
2021-05-30 02:08:06 +05:30
2024-05-19 18:25:43 +05:30
# Whether to enable the queue where players can line up before
# entering your server. Disabling this can be used as a workaround
# to deal with queue spamming attacks.
2022-12-25 00:39:49 +05:30
enable_queue: bool = True
2023-12-21 15:55:50 +05:30
# Protocol version we host with. Currently the default is 33 which
# still allows older 1.4 game clients to connect. Explicitly setting
# to 35 no longer allows those clients but adds/fixes a few things
# such as making camera shake properly work in net games.
protocol_version: int | None = None
2021-03-29 03:24:13 +05:30
# (internal) stress-testing mode.
2022-06-30 00:31:52 +05:30
stress_test_players: int | None = None
2021-03-29 03:24:13 +05:30
2023-12-21 15:55:50 +05:30
# How many seconds individual players from a given account must wait
# before rejoining the game. This can help suppress exploits
# involving leaving and rejoining or switching teams rapidly.
player_rejoin_cooldown: float = 10.0
2021-03-29 03:24:13 +05:30
2024-05-19 18:25:43 +05:30
# NOTE: as much as possible, communication from the server-manager to
# the child-process should go through these and not ad-hoc Python string
# commands since this way is type safe.
2021-03-29 03:24:13 +05:30
class ServerCommand:
"""Base class for commands that can be sent to the server."""
@dataclass
class StartServerModeCommand(ServerCommand):
"""Tells the app to switch into 'server' mode."""
2021-03-29 03:24:13 +05:30
config: ServerConfig
class ShutdownReason(Enum):
"""Reason a server is shutting down."""
2021-03-29 03:24:13 +05:30
NONE = 'none'
RESTARTING = 'restarting'
@dataclass
class ShutdownCommand(ServerCommand):
"""Tells the server to shut down."""
2021-03-29 03:24:13 +05:30
reason: ShutdownReason
immediate: bool
@dataclass
class ChatMessageCommand(ServerCommand):
"""Chat message from the server."""
2021-03-29 03:24:13 +05:30
message: str
2022-06-30 00:31:52 +05:30
clients: list[int] | None
2021-03-29 03:24:13 +05:30
@dataclass
class ScreenMessageCommand(ServerCommand):
"""Screen-message from the server."""
2021-03-29 03:24:13 +05:30
message: str
2022-06-30 00:31:52 +05:30
color: tuple[float, float, float] | None
clients: list[int] | None
2021-03-29 03:24:13 +05:30
@dataclass
class ClientListCommand(ServerCommand):
"""Print a list of clients."""
@dataclass
class KickCommand(ServerCommand):
"""Kick a client."""
2021-03-29 03:24:13 +05:30
client_id: int
2022-06-30 00:31:52 +05:30
ban_time: int | None