diff --git a/backend/__init__.py b/backend/__init__.py index 4d7e706..f21a5af 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -40,6 +40,11 @@ def connect(sid, environ): sio.enter_room(sid, 'lobby') sio.emit('players', room='lobby', data=online_players) +@sio.event +def get_online_players(sid): + global online_players + sio.emit('players', room='lobby', data=online_players) + @sio.event def set_username(sid, username): ses = sio.get_session(sid) diff --git a/backend/bang/game.py b/backend/bang/game.py index c724150..5a2ca92 100644 --- a/backend/bang/game.py +++ b/backend/bang/game.py @@ -373,6 +373,13 @@ class Game: player.game = None if self.disconnect_bot and self.started: player.is_bot = True + if len([p for p in self.players if not p.is_bot]) == 0: + print(f'no players left in game {self.name}, shutting down') + self.shutting_down = True + self.players = [] + self.spectators = [] + self.deck = None + return True eventlet.sleep(15) # he may reconnect if player.is_bot: if len(player.available_characters) > 0: diff --git a/frontend/src/components/Menu.vue b/frontend/src/components/Menu.vue index 2c8a215..58e59e7 100644 --- a/frontend/src/components/Menu.vue +++ b/frontend/src/components/Menu.vue @@ -11,23 +11,23 @@ -

{{$t("online_players")}}{{onlinePlayers}}

+

{{$t("online_players")}}{{onlinePlayers}}

{{$t("online_players")}}{{onlinePlayers}}

-

{{$t("available_lobbies")}}

-
- -

{{$t("no_lobby_available")}}

-

{{$t("create_lobby")}}

{{$t("lobby_name")}}

+

{{$t("available_lobbies")}}

+
+ +

{{$t("no_lobby_available")}}

+
@@ -79,6 +79,7 @@ export default { }, players(num) { this.onlinePlayers = num; + console.log('PLAYERS:' + num) } }, methods: { @@ -115,6 +116,7 @@ export default { mounted() { if (localStorage.getItem('username')) this.username = localStorage.getItem('username') + this.$socket.emit('get_online_players') }, }