def start_game_resp_response(message): game_object = None username = message['user']['username'].encode("utf8") game = sf.get_game(username) if game != None and message['response'] is True: sf.update_game_attribute(game['user1'], game['user2'], 'responded', True) sf.update_game_attribute(game['user1'], game['user2'], 'response', True) game_object = sf.get_game(username) sf.update_user_attribute(username, 'in_game', True) elif game != None: sf.update_game_attribute(game['user1'], game['user2'], 'responded', True) sf.update_game_attribute(game['user1'], game['user2'], 'response', False) game_object = sf.get_game(username) sf.remove_game(game_object['user1'], game_object['user2']) sf.update_user_attribute(game_object['user1'], 'in_game', False) sf.update_user_attribute(game_object['user2'], 'in_game', False) return_obj = { 'type': 'start_game_resp_resp', 'id' : message['id'], 'game' : game_object } return return_obj
def game_object_reqst_response(message): game_object = sf.get_game(message['user']['username']) if game_object != None and game_object['game_over'] is True: username1 = game_object['user1'] username2 = game_object['user2'] winner = game_object['winner'] if winner == username1: sf.update_user_attribute(username1, 'win_value', sf.get_user(username1)['win_value']+1) sf.update_user_attribute(username2, 'lose_value', sf.get_user(username2)['lose_value']+1) elif winner == username2: sf.update_user_attribute(username1, 'lose_value', sf.get_user(username1)['lose_value']+1) sf.update_user_attribute(username2, 'win_value', sf.get_user(username2)['win_value']+1) else: sf.update_user_attribute(username1, 'draw_value', sf.get_user(username1)['draw_value']+1) sf.update_user_attribute(username2, 'draw_value', sf.get_user(username2)['draw_value']+1) sf.update_user_attribute(username1, 'in_game', False) sf.update_user_attribute(username2, 'in_game', False) sf.remove_game(game_object['user1'], game_object['user2']) return_obj = { 'type': 'game_object_reqst_resp', 'id' : message['id'], 'game' : game_object } return return_obj