Exemple #1
0
def login_player(db_con, player_id, player_password):
    if not player_id:
        return False
    if not player_password:
        return False
    try:
        if not db_con:
            db_con = get_connection()
        db_cur = db_con.cursor()
        pw_hash_bin = common.sha224sum_bin(player_password, 'dJ7wz3FXu7YNS4')
        db_cur.execute("SELECT ingame_name, rank, last_ip, last_online, online_seconds FROM players WHERE id=? AND password_hash=?", [player_id, sql_db.Binary(pw_hash_bin)])
        return db_cur.fetchone()
    except sql_db.Error, e:
        print '[DATABASE ERROR] Could not log in player with ID %s: %s' % (player_id, e.args[0])
Exemple #2
0
def register_player(db_con, player_name, player_ip, player_password):
    if not player_name:
        return None
    if not player_password:
        return None
    try:
        if not db_con:
            db_con = get_connection()
        db_cur = db_con.cursor()
        pw_hash_bin = common.sha224sum_bin(player_password, 'dJ7wz3FXu7YNS4')
        db_cur.execute("INSERT INTO players (ingame_name, password_hash, last_ip, last_online, online_seconds, rank) VALUES (?, ?, ?, ?, 0, 'default')", [player_name.lower(), sql_db.Binary(pw_hash_bin), player_ip, reactor.seconds()])
        db_con.commit()
        if db_cur.rowcount == 1:
            return db_cur.lastrowid
    except sql_db.Error, e:
        print '[DATABASE ERROR] Error while registering player "%s": %s' % (player_name, e.args[0])