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.
This commit is contained in:
Sebastian Lohff 2025-05-11 01:35:14 +02:00
parent 024160c169
commit 2a0648bcd5
1 changed files with 12 additions and 13 deletions

View File

@ -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")