Added session_max_players_override option for servers

This commit is contained in:
Era 2023-12-22 23:16:22 +03:30
parent 0dcad474d5
commit dbd19e58be
No known key found for this signature in database
GPG Key ID: B2DB3D0A54D17FD5
4 changed files with 29 additions and 5 deletions

View File

@ -427,6 +427,10 @@ class ServerController:
self._config.player_rejoin_cooldown self._config.player_rejoin_cooldown
) )
bascenev1.set_max_players_override(
self._config.session_max_players_override
)
# And here.. we.. go. # And here.. we.. go.
if self._config.stress_test_players is not None: if self._config.stress_test_players is not None:
# Special case: run a stress test. # Special case: run a stress test.

View File

@ -228,7 +228,9 @@ from bascenev1._settings import (
IntSetting, IntSetting,
Setting, Setting,
) )
from bascenev1._session import Session, set_player_rejoin_cooldown from bascenev1._session import (
Session, set_player_rejoin_cooldown, set_max_players_override
)
from bascenev1._stats import PlayerScoredMessage, PlayerRecord, Stats from bascenev1._stats import PlayerScoredMessage, PlayerRecord, Stats
from bascenev1._team import SessionTeam, Team, EmptyTeam from bascenev1._team import SessionTeam, Team, EmptyTeam
from bascenev1._teamgame import TeamGameActivity from bascenev1._teamgame import TeamGameActivity
@ -420,6 +422,7 @@ __all__ = [
'set_public_party_queue_enabled', 'set_public_party_queue_enabled',
'set_public_party_stats_url', 'set_public_party_stats_url',
'set_player_rejoin_cooldown', 'set_player_rejoin_cooldown',
'set_max_players_override',
'set_replay_speed_exponent', 'set_replay_speed_exponent',
'set_touchscreen_editing', 'set_touchscreen_editing',
'setmusic', 'setmusic',

View File

@ -23,6 +23,9 @@ if TYPE_CHECKING:
# such as skipping respawn waits. # such as skipping respawn waits.
_g_player_rejoin_cooldown: float = 0.0 _g_player_rejoin_cooldown: float = 0.0
# overrides the session's decision of max_players
_max_players_override: int | None = None
def set_player_rejoin_cooldown(cooldown: float) -> None: def set_player_rejoin_cooldown(cooldown: float) -> None:
"""Set the cooldown for individual players rejoining after leaving.""" """Set the cooldown for individual players rejoining after leaving."""
@ -30,6 +33,12 @@ def set_player_rejoin_cooldown(cooldown: float) -> None:
_g_player_rejoin_cooldown = max(0.0, cooldown) _g_player_rejoin_cooldown = max(0.0, cooldown)
def set_max_players_override(max_players: int | None) -> None:
"""Set the override for how many players can join a session"""
global _max_players_override # pylint: disable=global-statement
_max_players_override = max_players
class Session: class Session:
"""Defines a high level series of bascenev1.Activity-es. """Defines a high level series of bascenev1.Activity-es.
@ -161,7 +170,11 @@ class Session:
self.sessionteams = [] self.sessionteams = []
self.sessionplayers = [] self.sessionplayers = []
self.min_players = min_players self.min_players = min_players
self.max_players = max_players self.max_players = (
max_players
if _max_players_override is None
else _max_players_override
)
self.customdata = {} self.customdata = {}
self._in_set_activity = False self._in_set_activity = False
@ -255,7 +268,7 @@ class Session:
babase.app.classic is not None babase.app.classic is not None
and babase.app.classic.stress_test_reset_timer is None and babase.app.classic.stress_test_reset_timer is None
): ):
if len(self.sessionplayers) >= self.max_players: if len(self.sessionplayers) >= self.max_players >= 0:
# Print a rejection message *only* to the client trying to # Print a rejection message *only* to the client trying to
# join (prevents spamming everyone else in the game). # join (prevents spamming everyone else in the game).
_bascenev1.getsound('error').play() _bascenev1.getsound('error').play()

View File

@ -47,10 +47,14 @@ class ServerConfig:
# Max devices in the party. Note that this does *NOT* mean max players. # 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 # 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 # multiple controllers. Also, this number currently includes the server so
# generally make it 1 bigger than you need. Max-players is not currently # generally make it 1 bigger than you need.
# exposed but I'll try to add that soon.
max_party_size: int = 6 max_party_size: int = 6
# 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) # Options here are 'ffa' (free-for-all), 'teams' and 'coop' (cooperative)
# This value is ignored if you supply a playlist_code (see below). # This value is ignored if you supply a playlist_code (see below).
session_type: str = 'ffa' session_type: str = 'ffa'