fix broken player count and empty open lobbies

This commit is contained in:
Alberto Xamin 2021-01-20 10:40:09 +01:00
parent 35e4f5fa0a
commit fabd7a3af0
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
3 changed files with 20 additions and 6 deletions

View File

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

View File

@ -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:

View File

@ -11,23 +11,23 @@
<input id="username" v-model="username" />
<input type="submit" :value="$t('submit')"/>
</form>
<p>{{$t("online_players")}}{{onlinePlayers}}</p>
<p v-if="onlinePlayers > 0">{{$t("online_players")}}{{onlinePlayers}}</p>
</div>
<div v-else>
<div v-if="!isInLobby" >
<p>{{$t("online_players")}}{{onlinePlayers}}</p>
<Card :card="getSelfCard" style="position:absolute; top:10pt; left: 10pt;"/>
<h2>{{$t("available_lobbies")}}</h2>
<div style="display: flex">
<Card v-for="lobby in openLobbies" v-bind:key="lobby.name" :card="getLobbyCard(lobby)" @click.native="joinLobby(lobby)"/>
<p v-if="noLobbyAvailable">{{$t("no_lobby_available")}}</p>
</div>
<form @submit="createLobby">
<h2>{{$t("create_lobby")}}</h2>
<p>{{$t("lobby_name")}}</p>
<input id="lobbyname" v-model="lobbyName"/>
<input type="submit" :value="$t('submit')"/>
</form>
<h2>{{$t("available_lobbies")}}</h2>
<div style="display: flex">
<Card v-for="lobby in openLobbies" v-bind:key="lobby.name" :card="getLobbyCard(lobby)" @click.native="joinLobby(lobby)"/>
<p v-if="noLobbyAvailable">{{$t("no_lobby_available")}}</p>
</div>
</div>
</div>
</div>
@ -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')
},
}
</script>