mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 23:59:18 +08:00
Merge pull request #628 from EraOSBeta/master
Added the reject_recently_left_players plugin into the base game
This commit is contained in:
commit
5cd779fa51
@ -43,6 +43,10 @@
|
|||||||
### Era0S
|
### Era0S
|
||||||
- Bug Fixer
|
- Bug Fixer
|
||||||
- Modder
|
- Modder
|
||||||
|
- Added a feature
|
||||||
|
|
||||||
### VinniTR
|
### VinniTR
|
||||||
- Fixes
|
- Fixes
|
||||||
|
|
||||||
|
### Rikko
|
||||||
|
- Created the original "reject_recently_left_players" plugin
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
"""Defines base session class."""
|
"""Defines base session class."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import math
|
||||||
import weakref
|
import weakref
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
@ -17,6 +18,8 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
import bascenev1
|
import bascenev1
|
||||||
|
|
||||||
|
TIMEOUT = 10
|
||||||
|
|
||||||
|
|
||||||
class Session:
|
class Session:
|
||||||
"""Defines a high level series of bascenev1.Activity-es.
|
"""Defines a high level series of bascenev1.Activity-es.
|
||||||
@ -203,6 +206,10 @@ class Session:
|
|||||||
# Instantiate our session globals node which will apply its settings.
|
# Instantiate our session globals node which will apply its settings.
|
||||||
self._sessionglobalsnode = _bascenev1.newnode('sessionglobals')
|
self._sessionglobalsnode = _bascenev1.newnode('sessionglobals')
|
||||||
|
|
||||||
|
self._players_on_wait: dict = {}
|
||||||
|
self._player_requested_identifiers: dict = {}
|
||||||
|
self._waitlist_timers: dict = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def context(self) -> bascenev1.ContextRef:
|
def context(self) -> bascenev1.ContextRef:
|
||||||
"""A context-ref pointing at this activity."""
|
"""A context-ref pointing at this activity."""
|
||||||
@ -253,6 +260,26 @@ class Session:
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
identifier = player.get_v1_account_id()
|
||||||
|
if identifier:
|
||||||
|
leave_time = self._players_on_wait.get(identifier)
|
||||||
|
if leave_time:
|
||||||
|
diff = str(math.ceil(TIMEOUT - babase.apptime() + leave_time))
|
||||||
|
_bascenev1.broadcastmessage(
|
||||||
|
babase.Lstr(
|
||||||
|
translate=(
|
||||||
|
'serverResponses',
|
||||||
|
'You can join in ${COUNT} seconds.',
|
||||||
|
),
|
||||||
|
subs=[('${COUNT}', diff)],
|
||||||
|
),
|
||||||
|
color=(1, 1, 0),
|
||||||
|
clients=[player.inputdevice.client_id],
|
||||||
|
transient=True,
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
self._player_requested_identifiers[player.id] = identifier
|
||||||
|
|
||||||
_bascenev1.getsound('dripity').play()
|
_bascenev1.getsound('dripity').play()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -270,6 +297,15 @@ class Session:
|
|||||||
|
|
||||||
activity = self._activity_weak()
|
activity = self._activity_weak()
|
||||||
|
|
||||||
|
identifier = self._player_requested_identifiers.get(sessionplayer.id)
|
||||||
|
if identifier:
|
||||||
|
self._players_on_wait[identifier] = babase.apptime()
|
||||||
|
with babase.ContextRef.empty():
|
||||||
|
self._waitlist_timers[identifier] = babase.AppTimer(
|
||||||
|
TIMEOUT,
|
||||||
|
babase.Call(self._remove_player_from_waitlist, identifier),
|
||||||
|
)
|
||||||
|
|
||||||
if not sessionplayer.in_game:
|
if not sessionplayer.in_game:
|
||||||
# Ok, the player is still in the lobby; simply remove them.
|
# Ok, the player is still in the lobby; simply remove them.
|
||||||
with self.context:
|
with self.context:
|
||||||
@ -770,3 +806,9 @@ class Session:
|
|||||||
if pass_to_activity:
|
if pass_to_activity:
|
||||||
activity.add_player(sessionplayer)
|
activity.add_player(sessionplayer)
|
||||||
return sessionplayer
|
return sessionplayer
|
||||||
|
|
||||||
|
def _remove_player_from_waitlist(self, identifier: str) -> None:
|
||||||
|
try:
|
||||||
|
self._players_on_wait.pop(identifier)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user