WS send game state

This commit is contained in:
Eden Kirin
2023-03-25 15:54:23 +01:00
parent 0f0fe68890
commit 4b511c0cb8
5 changed files with 41 additions and 18 deletions

View File

@ -1,9 +1,11 @@
import asyncio
import datetime
import logging
import time
from threading import Thread
from hopper.models.player import PlayerList
from hopper.ws_client import ws_send_game_state
from settings import settings
@ -28,6 +30,8 @@ class InactivityWatchdog(Thread):
seconds=settings.inacivity_watchdog.KICK_TIMEOUT
)
send_game_state = False
for player in self.players:
if (
player.can_be_deactivated
@ -36,6 +40,7 @@ class InactivityWatchdog(Thread):
):
player.active = False
logging.info(f"Player {player} set as inactive")
send_game_state = True
# safe remove from list
n = 0
@ -44,8 +49,16 @@ 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
else:
n += 1
if send_game_state:
self.send_game_state()
def send_game_state(self):
logging.info("Sending WS game state")
asyncio.run(ws_send_game_state())
def stop(self) -> None:
self.stopped = True