def joinRoom(roomInfo): if len(roomInfo) == 0: return if request.sid in rooms: #Checks if the user is already in a room if rooms[request.sid] == roomInfo: return leave_room(rooms[request.sid]) send("<b> " + names[request.sid] + " has left the room<b>", room=rooms[request.sid]) winner = Game.removeUser(games[rooms[request.sid]], request.sid) if len(games[rooms[request.sid]] ['users']) == 0: #Deletes game room if no-one is in it games.pop(rooms[request.sid]) elif winner != None: send("<b>" + names[games[rooms[request.sid]][winner]] + " has won the game!</b>", room=rooms[request.sid]) join_room(roomInfo) #Places user in a room if roomInfo not in games: #Create new game games[roomInfo] = Game.newGame() Game.addUser(games[roomInfo], request.sid) rooms[request. sid] = roomInfo #Sets room of user in a dictionary for later use emit('joinRoom', roomInfo) emit('gameUpdate', games[roomInfo]['board']) send("<b> " + names[request.sid] + " joined " + roomInfo + "<b>", room=roomInfo)
def joinRoom(roomID): if len(roomID) == 0: return if request.sid in rooms: #Checks if the user is already in a room if rooms[request.sid] == roomID: return leave_room(rooms[request.sid]) if len(games[rooms[request.sid]] ['players']) == 0: #Deletes game room if no-one is in it games.pop(rooms[request.sid]) if roomID not in games: #Create new game if roomID in savedgameinfo: games[roomID] = Game.newGame( request.sid, maxTime=savedgameinfo[roomID]['maxTime'], maxRounds=savedgameinfo[roomID]['maxRounds']) savedgameinfo.pop(roomID) else: games[roomID] = Game.newGame(request.sid) emit('yourturn', games[roomID]['offeredWords']) else: Game.addUser(games[roomID], request.sid) #dbu.agame(session['username'],games[roomID]) join_room(roomID) #Places user in a room rooms[ request.sid] = roomID #Sets room of user in a dictionary for later use emit('joinRoom', roomID) emit('newPlayer', names[request.sid], broadcast=True, include_self=False, room=roomID) scoresToSend = {} for i in games[roomID]['points'].keys( ): #Maps request.sids to the corresponding name before sending scoresToSend[names[i]] = games[roomID]['points'][i] emit('updateScores', scoresToSend) emit('highlightDrawer', names[games[roomID]['order'][games[roomID]['currDrawer']]]) send('<b>' + names[request.sid] + ' has joined the room</b>', broadcast=True, room=roomID)