From 2a0648bcd541866fb6a93a4584f4b533a9810d4d Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sun, 11 May 2025 01:35:14 +0200 Subject: [PATCH] server: send leave to client if they want to leave When we restart the signal server, the client might reconnect and still think it has state (i.e. is on a frequency). We should fix this in the client, but meanwhile we can just send out a leave to a client if they request to leave a frequency, even if they are not currently on a frequency. --- signalsrv/signalsrv.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/signalsrv/signalsrv.py b/signalsrv/signalsrv.py index adc83d7..6c9261b 100644 --- a/signalsrv/signalsrv.py +++ b/signalsrv/signalsrv.py @@ -145,19 +145,18 @@ class Client: type="morse-state", state=data["state"], from_player=self.id) async def _leave_room(self): - if not self.curr_freq: - self._send_error("You are not on a frequency") - return - - await self._send_to_group(self._others(self.curr_freq), - type="player-left", player=self.id) - try: - self.freqs[self.curr_freq].remove(self) - except ValueError: - LOG.warning("Player %s was not in freq %s", self.id, self.curr_freq) - if not self.freqs[self.curr_freq]: - del self.freqs[self.curr_freq] - self.curr_freq = None + if self.curr_freq: + await self._send_to_group(self._others(self.curr_freq), + type="player-left", player=self.id) + try: + self.freqs[self.curr_freq].remove(self) + except ValueError: + LOG.warning("Player %s was not in freq %s", self.id, self.curr_freq) + if not self.freqs[self.curr_freq]: + del self.freqs[self.curr_freq] + self.curr_freq = None + else: + LOG.warning("Client %s is not on a frequency, sending a 'leave' nontheless", self.client) try: await self._send(type="leave")