def lobby_response(message): lobby_object = {'users': sf.get_lobby()} return_obj = { 'type': 'lobby_resp', 'id' : message['id'], 'lobby' : lobby_object } return return_obj
def start_game_req_response(message): game_object = None username = message['user']['username'].encode("utf8") opponent_name = message['opponent'].encode("utf8") lobby = sf.get_lobby() user_in_lobby = False opponent_in_lobby = False for user in lobby: if user['username'] == username: user_in_lobby = True if user['username'] == opponent_name: opponent_in_lobby = True if user_in_lobby and opponent_in_lobby: sf.update_user_attribute(username, 'in_game', True) game_object = sf.add_game(username, opponent_name) else: print 'Error: could not start game, a user was not in the lobby' return_obj = { 'type': 'start_game_req_resp', 'id' : message['id'], 'game' : game_object } return return_obj