Пример #1
0
def ConfigureServer(DBNAME):
    import sys,os
    
    options={"database":""}
    
    database = ""
    
    # String options
    for option in ['database']:
        for x in xrange(len(sys.argv)):
            if sys.argv[x].find(option) == 0:
                pos = sys.argv[x].find('=') + 1
                if pos > 0 and options.has_key(option):
                    options[option]=sys.argv[x][pos:]
                    sys.argv[x] = ''
    
    DATABASE=options['database']
    
    from mud.common.dbconfig import SetDBConnection
    
    if not os.path.exists(DATABASE):
        os.makedirs(DATABASE)
        
    from mud.utils import getSQLiteURL
    SetDBConnection(getSQLiteURL('/%s/%s'%(DATABASE,DBNAME)),True)
Пример #2
0
def ShutdownEmbeddedWorld():
    global WORLDSERVER, MANHOLE
    if not WORLDSERVER:
        return

    world = World.byName("TheWorld")
    world.shutdown()
    WORLDSERVER.shutdown()
    WORLDSERVER = None

    if MANHOLE:
        MANHOLE.stopListening()

    MANHOLE = None
    SetDBConnection(None)
Пример #3
0
    if CoreSettings.PGSERVER:
        print "Copying fresh baseline"
        d = "./%s/data/worlds/multiplayer/%s/cluster%i"%(GAMEROOT,WORLDNAME,CLUSTER)
        try:
            rmtree(d)
        except:
            pass
        os.makedirs(d)
        DATABASE = d+"/world.db"
        copyfile("./%s/data/worlds/multiplayer.baseline/world.db"%GAMEROOT,DATABASE)
    else:
        DATABASE = "./%s/data/worlds/multiplayer/%s/world.db"%(GAMEROOT,WORLDNAME)

    from mud.utils import getSQLiteURL
    SetDBConnection(getSQLiteURL(DATABASE),True)


    #--- Avatars
    from mud.world.theworld import World
    THEWORLD = World.byName("TheWorld")
    THEWORLD.multiName = WORLDNAME
    if CLUSTER!=-1:
        ZONESTARTPORT+=CLUSTER*100
    THEWORLD.zoneStartPort = ZONESTARTPORT
    THEWORLD.pwNewPlayer = PLAYERPASSWORD
    THEWORLD.staticZoneNames = STATICZONES

    if not CoreSettings.PGSERVER:
        THEWORLD.allowConnections = False
        THEWORLD.dbFile = "%s/%s/data/worlds/multiplayer/%s/world.db"%(os.getcwd(),GAMEROOT,WORLDNAME)
Пример #4
0
def WorldUpdate(worldPath, baselinePath, fromgame=False, force=False):
    global FROMGAME
    global FORCE
    # Save arguments in global variables to be used
    #  on various data copiers.
    FROMGAME = fromgame
    FORCE = force

    # Check if the world needs updating.
    # 0 = no update needed, 1 = updated needed, -1 = error.
    try:
        result = CheckWorld(worldPath, baselinePath)
    except:
        traceback.print_exc()
        return -1
    if result != 1:
        return result

    # If we get here, we need to update the world.
    try:
        # If the world update has been called from in-game,
        #  which means single-player, tell the user what we're doing.
        if FROMGAME:
            TGECall("MessagePopup", "Updating World...", "Please wait...")
            TGEEval("Canvas.repaint();")

        # Get the database connection of the world to be updated.
        WCONN = sqlite.connect(worldPath)

        # Get information on database structure of world-specific data.
        # We need information about users, players, characters and
        #  related content. Not needed is invariable stuff such as
        #  item protos, spell protos, mob spawns and the like.
        QuerySchema(WCONN)

        # Save player data.
        players = []
        for r in WCONN.execute("select id from Player;").fetchall():
            pc = PlayerCopier(WCONN, r[0])
            players.append(pc)

        # Save user data.
        users = []
        for r in WCONN.execute("select id from user;").fetchall():
            u = UserCopier(WCONN, r[0])
            users.append(u)

        # Close the database connection.
        WCONN.close()

        # Backup the world database.
        shutil.copyfile(worldPath, "%s.bak" % worldPath)

        # Create a new copy of the static world database
        #  which doesn't contain any variable data.
        shutil.copyfile(baselinePath, "%s.new" % worldPath)

        # Get a database connection to the new copy
        #  of the static world database.
        DATABASE = "sqlite:///%s.new" % worldPath
        SetDBConnection(DATABASE)

        # Start inserting saved user and player data
        #  into new world database.
        conn = Player._connection.getConnection()
        cursor = conn.cursor()
        cursor.execute("BEGIN;")

        for u in users:
            u.install()

        for p in players:
            p.install()

        # Finish transaction and close database connection.
        cursor.execute("END;")
        cursor.close()
        SetDBConnection(None)

        # Finally copy the updated database to the
        #  standard path, overwriting previous database.
        shutil.copyfile(worldPath + ".new", worldPath)
    # An error occured, luckily we didn't directly write
    #  to the database to be updated.
    except:
        traceback.print_exc()
        return -1

    # If the database updated was done from in-game
    #  (single-player), tell the user that we're finished
    #  with updating and will now load the world.
    if FROMGAME:
        TGECall("MessagePopup", "Loading World...", "Please wait...")
        TGEEval("Canvas.repaint();")

    # Return successful.
    return 0
Пример #5
0
from mud.common.dbconfig import SetDBConnection

#setup the db connection
DATABASEPATH = "%s/data/worlds/multiplayer.baseline" % GAMEROOT
DATABASE = DATABASEPATH + "/world.db"

try:
    shutil.rmtree(DATABASEPATH)
except:
    pass

if not os.path.exists(DATABASEPATH):
    os.makedirs(DATABASEPATH)

SetDBConnection('sqlite:/%s' % DATABASE, True)

from sqlobject import *
from mud.common.persistent import Persistent
conn = Persistent._connection

#conn.getConnection().autoCommit = False
conn.autoCommit = False
Persistent._connection = transaction = conn.transaction()

from genesis.dbdict import DBDict  #must be imported after db connection set

#table import
from mud.world.theworld import World
from mud.world.player import Player, PlayerXPCredit, PlayerMonsterSpawn
from mud.world.character import Character, CharacterSpell, StartingGear, CharacterSkill, CharacterAdvancement, CharacterDialogChoice, CharacterVaultItem, CharacterFaction
Пример #6
0
def SetupEmbeddedWorld(worldname):
    global WORLDSERVER
    global MANHOLE

    DATABASE = "sqlite:///%s/%s/data/worlds/singleplayer/%s/world.db" % (
        os.getcwd(), GAMEROOT, worldname)
    SetDBConnection(DATABASE, True)

    #destroy the new player user, and recreate
    try:
        user = User.byName("NewPlayer")
        user.destroySelf()
    except:
        pass

    CreatePlayer()
    IDESetup()

    #--- Application

    from twisted.spread import pb
    from twisted.internet import reactor
    from twisted.cred.credentials import UsernamePassword

    from mud.server.app import Server

    WORLDSERVER = server = Server(3013)
    server.startServices()

    #kickstart the heart
    world = World.byName("TheWorld")

    #TODO, single player backups
    #world.dbFile = os.getcwd()+"/minions.of.mirth/data/worlds/singleplayer/"+worldname+"/world.db"

    try:
        v = int(TGEGetGlobal("$pref::gameplay::difficulty"))
    except:
        v = 0
        TGESetGlobal("$pref::gameplay::difficulty", 0)
    try:
        respawn = float(TGEGetGlobal("$pref::gameplay::monsterrespawn"))
    except:
        TGESetGlobal("$pref::gameplay::monsterrespawn", 0.0)
        respawn = 0.0
    try:
        SPpopulators = int(TGEGetGlobal("$pref::gameplay::SPpopulators"))
    except:
        SPpopulators = 0
        TGESetGlobal("$pref::gameplay::SPpopulators", 0)

    if v == 1:
        CoreSettings.DIFFICULTY = 0
    elif v == 2:
        CoreSettings.DIFFICULTY = 2
    else:
        CoreSettings.DIFFICULTY = 1

    CoreSettings.RESPAWNTIME = respawn
    CoreSettings.SPPOPULATORS = SPpopulators

    CoreSettings.SINGLEPLAYER = True
    world.launchTime = currentTime()
    world.singlePlayer = True

    world.startup()
    world.transactionTick()

    world.tick()