Change terminology game state -> game dump

This commit is contained in:
Eden Kirin
2023-03-30 11:32:16 +02:00
parent 48cb1a3798
commit 413e395a75
7 changed files with 40 additions and 35 deletions

View File

@ -5,7 +5,7 @@ import time
from threading import Thread
from typing import Optional
from hopper.interfaces import SendGameStateInterface
from hopper.interfaces import SendGameDumpInterface
from hopper.models.player import PlayerList
from settings import settings
@ -14,7 +14,7 @@ class InactivityWatchdog(Thread):
def __init__(
self,
players: PlayerList,
ws_server: Optional[SendGameStateInterface] = None,
ws_server: Optional[SendGameDumpInterface] = None,
*args,
**kwargs,
) -> None:
@ -38,7 +38,7 @@ class InactivityWatchdog(Thread):
seconds=settings.inacivity_watchdog.KICK_TIMEOUT
)
send_game_state = False
send_game_dump = False
for player in self.players:
if (
@ -48,7 +48,7 @@ class InactivityWatchdog(Thread):
):
player.active = False
logging.info(f"Player {player} set as inactive")
send_game_state = True
send_game_dump = True
# safe remove from list
n = 0
@ -57,18 +57,18 @@ class InactivityWatchdog(Thread):
if player.can_be_deactivated and player.last_seen < kick_threshold:
self.players.pop(n)
logging.info(f"Player {player} kicked out")
send_game_state = True
send_game_dump = True
else:
n += 1
if send_game_state:
self.send_game_state()
if send_game_dump:
self.send_game_dump()
def send_game_state(self):
def send_game_dump(self):
if not self.ws_server:
return
logging.info("Sending WS game state")
asyncio.run(self.ws_server.send_game_state())
logging.info("Sending WS game dump")
asyncio.run(self.ws_server.send_game_dump())
def stop(self) -> None:
self.stopped = True