def save(player_obj): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("update player set " "playername = :playername, " "password = :password, " "currentLoadout = :currentLoadout, " "inMatch = :inMatch, " "mmr = :mmr, " "token = :token, " "playerLevel = :playerLevel " "where id = :playerId", { "playerId": player_obj.id, "playername": player_obj.name, "password": player_obj.password, "currentLoadout": player_obj.loadout_id, "inMatch": player_obj.in_match, "mmr": player_obj.mmr, "playerLevel": player_obj.player_level, "token": player_obj.token }) cursor.close() conn.commit()
def update(troop_obj): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from troop m " "where m.id = :troop_id", {"troop_id": troop_obj.id}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: troop_id, class_id, loadout_id, skin_id = temp_data else: return if troop_obj.class_id != class_id: troop_obj.class_id = class_id if troop_obj.troop_class is not None: troop_obj.troop_class = db_troop_class.get_by_id(class_id) if troop_obj.skin_id != skin_id: troop_obj.skin_id = skin_id if troop_obj.skin is not None: troop_obj.skin = db_skin.get_by_id(skin_id) if troop_obj.loadout_id != loadout_id: troop_obj.loadout_id = loadout_id if troop_obj.loadout is not None: troop_obj.loadout = db_loadout.get_by_id(loadout_id)
def save(troop_obj, skip_refresh=False): conn = db_ops.get_connection() cursor = conn.cursor() print "loadout id in troop is", troop_obj.loadout_id logging.debug("pre update troop sql") cursor.execute("update Troop set " "classId = :classId, " "loadoutId = :loadoutId, " "skinId = :skinId " "where id = :troopId", { "troopId": troop_obj.id, "classId": troop_obj.class_id, "loadoutId": troop_obj.loadout_id, "skinId": troop_obj.skin_id }) cursor.close() if troop_obj.modifiers is not None: db_troop_modifier.save(troop_obj, skip_refresh=True) conn.commit() if not skip_refresh: db_ops.refresh_troop_stats()
def get_players(match_history_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "select m.player1ID " "from MatchHistory m " "where m.matchHistoryId = match_history_id", {"match_history_id": match_history_id}) temp_data = cursor.fetchone() if temp_data is not None: first_player, = temp_data else: first_player = None cursor.execute( "select m.player2ID " "from MatchHistory m " "where m.matchHistoryId = match_history_id", {"match_history_id": match_history_id}) temp_data = cursor.fetchone() if temp_data is not None: second_player, = temp_data else: second_player = None cursor.close() return [first_player, second_player]
def get_response(): post_form = krait.request.get_post_form() username = post_form.get("username") password = post_form.get("password") if username is None or password is None: return krait.Response( "HTTP/1.1", 400, {}, "<html><body><h1>400 Bad Request</h1></body></html>") redirect_url = "/login_fail" fail = False try: db_conn = db_ops.get_connection() cursor = db_conn.cursor() result = cursor.callfunc("user_ops.checkSaltedPassword", cursor.var(cx_Oracle.NUMBER), [username, password]) db_conn.commit() except cx_Oracle.DatabaseError, exception: error_messages = [ "Error checking DB for username {}: {}".format( username, exception.args[0]) ] redirect_url += "?errors=" + urllib.quote_plus( json.dumps(error_messages)) fail = True result = 0
def update(troop_stats_obj): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from TroopStatsCalculator where id = :troop_id", {"troop_id": troop_stats_obj.troop_id}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: troop_id, class_id, loadout_id, skin_id, max_hp, dmg, atk_range, move_range = temp_data else: return if troop_stats_obj.troop is not None and \ (troop_stats_obj.class_id, troop_stats_obj.loadout_id, troop_stats_obj.skin_id) !=\ (class_id, loadout_id, skin_id): db_troop.update(troop_stats_obj.troop) troop_stats_obj.troop_class = troop_stats_obj.troop.troop_class troop_stats_obj.loadout = troop_stats_obj.troop.loadout troop_stats_obj.skin = troop_stats_obj.troop.skin troop_stats_obj.class_id = class_id troop_stats_obj.loadout_id = loadout_id troop_stats_obj.skin_id = skin_id troop_stats_obj.max_hp = max_hp troop_stats_obj.dmg = dmg troop_stats_obj.atk_range = atk_range troop_stats_obj.move_range = move_range
def save(troop_obj, skip_refresh=False): if troop_obj.modifiers is None: return troop_id = troop_obj.id conn = db_ops.get_connection() cursor = conn.cursor() logging.debug("pre delete tm sql") cursor.execute("delete from troopModifier " "where troopId = :troop_id", {"troop_id": troop_id}) logging.debug("pre insert loadout sql") cursor.executemany("insert into troopModifier " "values(:troopId, :modId)", [ {"troopId": troop_id, "modId": mod.id} for mod in troop_obj.modifiers ]) cursor.close() conn.commit() if not skip_refresh: db_ops.refresh_troop_stats()
def get_by_id(match_id, skip_update=False): if match_id in match_cache: if not skip_update: update(match_cache[match_id]) return match_cache[match_id] conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from Match m " "where m.id = :match_id", {"match_id": match_id}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: match_id, player1, player2, turn, turn_start_time, score1, score2, map_id, time_started = \ temp_data else: return None result = match.Match(match_id, player1, player2, turn, turn_start_time, score1, score2, map_id, time_started) match_cache[match_id] = result return result
def create(player1, player2): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select matchidseq.nextval from dual") match_id, = cursor.fetchone() try: cursor.execute( "insert into match values(:match_id,:id1,:id2,1,NULL,0,0,NULL," "(select systimestamp from dual))", { "match_id": match_id, "id1": player1.player_id, "id2": player2.player_id }) except ValueError as ex: logging.debug(ex.message) try: cursor.execute("insert into flag values (:match_id, 1, 3, 14, null)", {"match_id": match_id}) cursor.execute("insert into flag values (:match_id, 2, 60, 14, null)", {"match_id": match_id}) except ValueError as ex: logging.debug(ex.message) conn.commit() cursor.close()
def get_score(match_history_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "select m.score1 " "from MatchHistory m " "where m.matchHistoryId = match_history_id", {"match_history_id": match_history_id}) temp_data = cursor.fetchone() if temp_data is not None: first_score, = temp_data else: first_score = None cursor.execute( "select m.score2 " "from MatchHistory m " "where m.matchHistoryId = match_history_id", {"match_history_id": match_history_id}) temp_data = cursor.fetchone() if temp_data is not None: second_score, = temp_data else: second_score = None cursor.close() return [first_score, second_score]
def get_by_loadout_id(loadout_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select id from troop where loadoutId = :loadout_id", {"loadout_id": loadout_id}) ids = cursor.fetchall() return [get_by_id(i) for i, in ids]
def is_deleted(queue_obj): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select 'a' from queue where playerId = :player_id", {"player_id": queue_obj.player_id}) exists = cursor.fetchone() is not None cursor.close() return not exists
def get_by_match(match_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select id from MatchTroop where matchId = :match_id", {"match_id": match_id}) temp_data = cursor.fetchall() cursor.close() return [get_by_id(m_id) for m_id, in temp_data]
def get_all(): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from skin") return [ skin.Skin(skin_id, class_id, filename) for skin_id, class_id, filename in cursor ]
def get_by_troop_id(troop_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from troopModifier m " "where m.troopId = :troop_id", {"troop_id": troop_id}) items = cursor.fetchall() return [troop_modifier.TroopModifier(troop_id, modifier_id) for troop_id, modifier_id in items]
def delete_long_waits(): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "delete from queue " "where current_timestamp - timeStarted > interval '60' second " "and matchReady = 0") cursor.close() conn.commit()
def get_all(): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from Modifier m ") return [ modifier.Modifier(modifier_id, name, max_hp, dmg, atk_range, move_range, min_level) for modifier_id, name, max_hp, dmg, atk_range, move_range, min_level in cursor ]
def __init__(self): # List of strings, each is an error. Add with self.error_messages.append(error_message) self.error_messages = [] db_conn = None try: db_conn = db_ops.get_connection() except cx_Oracle.DatabaseError, exception: del self.error_messages[:] self.error_messages.append("Sorry, but we could't connect to the WEGAS Database\n") self.error_messages.append(exception)
def is_deleted(match_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from Match m " "where m.id = :match_id", {"match_id": match_id}) temp_data = cursor.fetchone() cursor.close() return (temp_data is None)
def get_all(): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from troopClass") return [ troop_class.TroopClass(troop_class_id, name, description, max_hp, dmg, atk_range, move_range, min_level) for troop_class_id, name, description, max_hp, dmg, atk_range, move_range, min_level in cursor ]
def delete_by_id(match_id): conn = db_ops.get_connection() cursor = conn.cursor() try: cursor.execute("delete from match where id = :match_id", {"match_id": match_id}) except ValueError: logging.debug(ValueError.message) cursor.close() conn.commit() cursor.close() conn.commit()
def get_by_match(match_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from flag where matchId = :match_id", {"match_id": match_id}) results = [] for match_id, flag_idx, x_axis, y_axis, carrying_troop_id in cursor: results.append( flag.Flag(match_id, flag_idx, x_axis, y_axis, carrying_troop_id)) cursor.close() return results
def get_players(number_of_players): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "select playerid from (select playerid from queue where matchready = 0 order by priority) where rownum < :number_of_players + 1 ", {"number_of_players": number_of_players}) player_ids = cursor.fetchall() player_queue = [] for i, in player_ids: player_queue.append(get_by_id(i)) cursor.close() return player_queue
def get_sourcefile(map_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select m.sourceFile " "from Map m " "where m.id = :map_id", {"map_id": map_id}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: map_sourcefile, = temp_data else: return None return map_sourcefile
def get_by_filename(filename): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select id from skin s " "where s.filename = :filename", {"filename": filename}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: skin_id, = temp_data return get_by_id(skin_id) else: return None
def get_by_loadout_id(loadout_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "select id from TroopStatsCalculator where loadoutId = :loadout_id", {"loadout_id": loadout_id}) ids = cursor.fetchall() cursor.close() print "nr of troops in loadout:", len(ids) print ids print loadout_id return [get_by_id(i) for i, in ids]
def get_by_name(class_name): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select id from troopclass t " "where t.name = :class_name", {"class_name": class_name}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: class_id, = temp_data else: return None return get_by_id(class_id)
def get_by_id(player_id): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute("select * from queue " "where playerId = :player_id", {"player_id": player_id}) temp_data = cursor.fetchone() cursor.close() if temp_data is not None: player_id, time_started, priority, join_response, match_ready = temp_data else: return None return queue.Queue(player_id, time_started, priority, join_response, match_ready)
def get_by_player(player): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "select id from Match m " "where m.player1 = :player_id or m.player2 = :player_id", {"player_id": player.id}) result_tuple = cursor.fetchone() if result_tuple is None: return None else: match_id, = result_tuple return get_by_id(match_id)
def insert(player_id, priority): conn = db_ops.get_connection() cursor = conn.cursor() cursor.execute( "Insert into queue " "values(:player_id, (SELECT SYSTIMESTAMP FROM DUAL), :priority, 0, 0)", { "player_id": player_id, "priority": priority }) conn.commit() cursor.close() return get_by_id(player_id)