Esempio n. 1
0
def acct_mysql_update_2():
    sql = "ALTER TABLE accounts ADD chatname varchar(255) default '' AFTER slots;"
    database.execute(sql)

    sql = "ALTER TABLE accounts ADD ignorelist longtext AFTER chatname;"
    database.execute(sql)

    return True
Esempio n. 2
0
def acct_sqlite_update_2():
    sql = "ALTER TABLE accounts ADD chatname varchar(255) default '';"
    database.execute(sql)

    sql = "ALTER TABLE accounts ADD ignorelist longtext;"
    database.execute(sql)

    return True
Esempio n. 3
0
def mysql_update_10():
    # Create new guild tables

    sql = "CREATE TABLE `guilds_enemies` ( `guild` int(10) unsigned NOT NULL default '0', `enemy` int(10) unsigned NOT NULL default '0', PRIMARY KEY(`guild`,`enemy`)) TYPE=MYISAM CHARACTER SET utf8;"
    database.execute(sql)

    sql = "CREATE TABLE `guilds_allies` ( `guild` int(10) unsigned NOT NULL default '0', `ally` int(10) unsigned NOT NULL default '0', PRIMARY KEY(`guild`,`ally`)) TYPE=MYISAM CHARACTER SET utf8;"
    database.execute(sql)

    return True
Esempio n. 4
0
def updateacctversion(version, driver):
    try:
        if driver == 'mysql':
            database.execute(
                "REPLACE INTO `settings` VALUES('db_version', '%u');" %
                version)
        else:
            database.execute(
                "REPLACE INTO settings VALUES('db_version', '%u');" % version)
    except Exception, e:
        console.log(
            LOG_WARNING,
            "Unable to update account database version to %u:\n%s\n" %
            (i + 1, str(e)))
Esempio n. 5
0
def backup_db():
    if enabled and backup_path:
        accountsdir = "%s/%s_accounts" % (backup_path, datetime.date.today())
        worlddir = "%s/%s_world" % (backup_path, datetime.date.today())
        if accountsdriver == 'mysql' or worlddriver == 'mysql':
            try:
                # What are we optimizing
                if accountsdriver == 'mysql' and worlddriver == 'mysql':
                    log(
                        LOG_MESSAGE,
                        "Doing a backup for the accounts and world databases..."
                    )
                    if not os.path.isdir(accountsdir):
                        os.mkdir(accountsdir)
                    if not os.path.isdir(worlddir):
                        os.mkdir(worlddir)
                elif accountsdriver == 'mysql' or worlddriver == 'mysql':
                    if accountsdriver == 'mysql':
                        if not os.path.isdir(accountsdir):
                            os.mkdir(accountsdir)
                        log(LOG_MESSAGE,
                            "Doing a backup for the accounts database...")
                    elif worlddriver == 'mysql':
                        if not os.path.isdir(worlddir):
                            os.mkdir(worlddir)
                        log(LOG_MESSAGE,
                            "Doing a backup for the world database...")
                # Time to backup
                if accountsdriver == 'mysql':
                    database.open(database.ACCOUNTS)
                    database.execute("BACKUP TABLE %s TO '%s'" %
                                     (database.MYSQL_ACCOUNTS, accountsdir))
                    database.close()
                    log(LOG_MESSAGE,
                        "Accounts database saved to: %s" % (accountsdir))
                if worlddriver == 'mysql':
                    database.open(database.WORLD)
                    database.execute("BACKUP TABLE %s TO '%s'" %
                                     (database.MYSQL_WORLD, worlddir))
                    database.close()
                    #else:
                    #	log( LOG_MESSAGE, "Warning: Failed to open the world database!" )
                    log(LOG_MESSAGE,
                        "World database saved to: %s" % (worlddir))
            except:
                log(LOG_MESSAGE,
                    " Backup of the accounts/world database failed.")
        return True
    else:
        return False
Esempio n. 6
0
def onUpdateDatabase(current, version):
    # Find the update table for the database driver in use
    driver = database.driver(WORLD)
    if driver == 'mysql':
        updates = MYSQL_UPDATES
    elif driver == 'sqlite':
        updates = SQLITE_UPDATES
    else:
        console.log(LOG_ERROR, "Unknown database driver: %s.\n" % driver)
        return False

    for i in range(version, current):
        # No update for this version available
        if not i in updates:
            console.log(LOG_ERROR,
                        "No update available for database version %u.\n" % i)
            return False

        console.log(LOG_MESSAGE,
                    "Updating database from version %u to %u.\n" % (i, i + 1))

        try:
            if not updates[i]():
                return False
        except Exception, e:
            console.log(LOG_ERROR, str(e) + "\n")
            return False

        wolfpack.setoption('db_version', str(i + 1))
        try:
            if driver == 'mysql':
                database.execute(
                    "REPLACE INTO `settings` VALUES('db_version', '%u');" %
                    (i + 1))
            else:
                database.execute(
                    "REPLACE INTO settings VALUES('db_version', '%u');" %
                    (i + 1))
        except Exception, e:
            console.log(
                LOG_WARNING, "Unable to update database version to %u:\n%s\n" %
                (i + 1, str(e)))
Esempio n. 7
0
def acct_sqlite_update_1():
    sql = "ALTER TABLE accounts ADD creationdate varchar(19) default NULL;"
    database.execute(sql)

    sql = "ALTER TABLE accounts ADD totalgametime int NOT NULL default '0';"
    database.execute(sql)

    sql = "ALTER TABLE accounts ADD slots smallint(5) NOT NULL default '1';"
    database.execute(sql)

    return True
Esempio n. 8
0
def acct_mysql_update_1():
    sql = "ALTER TABLE accounts ADD creationdate varchar(19) default NULL AFTER email;"
    database.execute(sql)

    sql = "ALTER TABLE accounts ADD totalgametime int NOT NULL default '0' AFTER creationdate;"
    database.execute(sql)

    sql = "ALTER TABLE accounts ADD slots smallint(5) NOT NULL default '1' AFTER totalgametime;"
    database.execute(sql)

    return True
Esempio n. 9
0
def sqlite_update_12():
    sql = "CREATE TABLE tmp_items12 (serial unsigned int(10) NOT NULL default '0',id unsigned smallint(5) NOT NULL default '0',color unsigned smallint(5) NOT NULL default '0',cont unsigned int(10) NOT NULL default '0',layer unsigned tinyint(3) NOT NULL default '0',amount smallint(5)  NOT NULL default '0',hp smallint(6) NOT NULL default '0',maxhp smallint(6) NOT NULL default '0',movable tinyint(3)  NOT NULL default '0',owner unsigned int(10) NOT NULL default '0',visible tinyint(3)  NOT NULL default '0',priv tinyint(3)  NOT NULL default '0',baseid varchar(64) NOT NULL default '',PRIMARY KEY (serial));"
    database.execute(sql)
    sql = "insert into tmp_items12 select * from items;"
    database.execute(sql)
    sql = "drop table items;"
    database.execute(sql)

    sql = "CREATE TABLE items (serial unsigned int(10) NOT NULL default '0',id unsigned smallint(5) NOT NULL default '0',color unsigned smallint(5) NOT NULL default '0',cont unsigned int(10) NOT NULL default '0',layer unsigned tinyint(3) NOT NULL default '0',amount smallint(5)  NOT NULL default '0',hp smallint(6) NOT NULL default '0',maxhp smallint(6) NOT NULL default '0',movable tinyint(3)  NOT NULL default '0',owner unsigned int(10) NOT NULL default '0',visible tinyint(3)  NOT NULL default '0',priv unsigned tinyint(3)  NOT NULL default '0',baseid varchar(64) NOT NULL default '',PRIMARY KEY (serial));"
    database.execute(sql)

    sql = "insert into items select * from tmp_items12"
    database.execute(sql)
    sql = "drop table tmp_items12;"
    database.execute(sql)

    # optimize
    sql = "VACUUM"
    database.execute(sql)

    return True
Esempio n. 10
0
def sqlite_update_8():

    sql = "CREATE TABLE tmp_players7 ( serial bigint, account varchar(16), additionalflags bigint, visualrange tinyint(3), profile longtext, fixedlight tinyint(3), strlock smallint, dexlock smallint, intlock smallint);"
    database.execute(sql)
    sql = "insert into tmp_players7 select * from players;"
    database.execute(sql)
    sql = "drop table players;"
    database.execute(sql)

    sql = "CREATE TABLE players ( serial bigint NOT NULL default '0', account varchar(16) default NULL, additionalflags bigint NOT NULL default '0', visualrange tinyint(3) NOT NULL default '0', profile longtext, fixedlight tinyint(3) NOT NULL default '0',	strlock smallint NOT NULL default '0', dexlock smallint NOT NULL default '0', intlock smallint NOT NULL default '0', maxcontrolslots tinyint(4) NOT NULL default '5', PRIMARY KEY  (serial) );"
    database.execute(sql)

    sql = "insert into players select *, 5 from tmp_players7"
    database.execute(sql)
    sql = "drop table tmp_players7;"
    database.execute(sql)

    # optimize
    sql = "VACUUM"
    database.execute(sql)

    return True
Esempio n. 11
0
def mysql_update_12():
    # change 'priv' from signed to unsigned
    sql = "ALTER TABLE `items` MODIFY `priv` tinyint(3) unsigned NOT NULL default '0';"
    database.execute(sql)

    return True
Esempio n. 12
0
def mysql_update_7():
    sql = "ALTER TABLE players ADD `maxcontrolslots` tinyint(4) NOT NULL default '5' AFTER intlock;"
    database.execute(sql)

    return True