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:
parent
024160c169
commit
2a0648bcd5
|
@ -145,19 +145,18 @@ class Client:
|
||||||
type="morse-state", state=data["state"], from_player=self.id)
|
type="morse-state", state=data["state"], from_player=self.id)
|
||||||
|
|
||||||
async def _leave_room(self):
|
async def _leave_room(self):
|
||||||
if not self.curr_freq:
|
if self.curr_freq:
|
||||||
self._send_error("You are not on a frequency")
|
await self._send_to_group(self._others(self.curr_freq),
|
||||||
return
|
type="player-left", player=self.id)
|
||||||
|
try:
|
||||||
await self._send_to_group(self._others(self.curr_freq),
|
self.freqs[self.curr_freq].remove(self)
|
||||||
type="player-left", player=self.id)
|
except ValueError:
|
||||||
try:
|
LOG.warning("Player %s was not in freq %s", self.id, self.curr_freq)
|
||||||
self.freqs[self.curr_freq].remove(self)
|
if not self.freqs[self.curr_freq]:
|
||||||
except ValueError:
|
del self.freqs[self.curr_freq]
|
||||||
LOG.warning("Player %s was not in freq %s", self.id, self.curr_freq)
|
self.curr_freq = None
|
||||||
if not self.freqs[self.curr_freq]:
|
else:
|
||||||
del self.freqs[self.curr_freq]
|
LOG.warning("Client %s is not on a frequency, sending a 'leave' nontheless", self.client)
|
||||||
self.curr_freq = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self._send(type="leave")
|
await self._send(type="leave")
|
||||||
|
|
Loading…
Reference in New Issue