[os-devel] SF.net SVN: ospace:[324] branches/ospace_0.5
Brought to you by:
qark
|
From: <qa...@us...> - 2011-12-28 19:02:56
|
Revision: 324
http://ospace.svn.sourceforge.net/ospace/?rev=324&view=rev
Author: qark
Date: 2011-12-28 19:02:47 +0000 (Wed, 28 Dec 2011)
Log Message:
-----------
- Initial version of support for multiple universes per game server. [Qark]
Modified Paths:
--------------
branches/ospace_0.5/ChangeLog.txt
branches/ospace_0.5/server/lib/ige/ClientMngr.py
branches/ospace_0.5/server/lib/ige/Config.py
branches/ospace_0.5/server/lib/ige/ospace/GameMngr.py
branches/ospace_0.5/server/lib/ige/ospace/IUniverse.py
branches/ospace_0.5/server/run.py
Added Paths:
-----------
branches/ospace_0.5/server/lib/ige/GameServer.py
branches/ospace_0.5/server/ospace-server.py
Removed Paths:
-------------
branches/ospace_0.5/server/ospace-server
Modified: branches/ospace_0.5/ChangeLog.txt
===================================================================
--- branches/ospace_0.5/ChangeLog.txt 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/ChangeLog.txt 2011-12-28 19:02:47 UTC (rev 324)
@@ -6,6 +6,9 @@
- $Author$
- $Revision$
+[2011-12-28]
+- Initial version of support for multiple universes per game server. [Qark]
+
[2011-12-05]
- Fixed galaxy restart issue. [Qark]
- Game information now exported to json. [Qark]
Modified: branches/ospace_0.5/server/lib/ige/ClientMngr.py
===================================================================
--- branches/ospace_0.5/server/lib/ige/ClientMngr.py 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/server/lib/ige/ClientMngr.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -1,5 +1,5 @@
#
-# Copyright 2001 - 2006 Ludek Smid [http://www.ospace.net/]
+# Copyright 2001 - 2012 Ludek Smid [http://www.ospace.net/]
#
# This file is part of IGE - Outer Space.
#
@@ -47,9 +47,9 @@
class ClientMngr:
- def __init__(self, database, config, configDir):
+ def __init__(self, database, authMethod, configDir):
self.configDir = configDir
- self.authMethod = config.server.authmethod
+ self.authMethod = authMethod
if not self.authMethod:
self.authMethod = Authentication.defaultMethod
self._filename = os.path.join(self.configDir, 'accounts')
Modified: branches/ospace_0.5/server/lib/ige/Config.py
===================================================================
--- branches/ospace_0.5/server/lib/ige/Config.py 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/server/lib/ige/Config.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -32,10 +32,13 @@
existing section an instance of Section class
is returned.
"""
- def __init__(self, file):
- self.__dict__["_config"] = ConfigParser()
+ def __init__(self, file, defaults = dict()):
+ self.__dict__["_config"] = ConfigParser(defaults)
self._config.read(file)
+ def __getitem__(self, name):
+ return self.__getattr__(name)
+
def __getattr__(self, name):
if not self._config.has_section(name):
self._config.add_section(name)
@@ -48,6 +51,9 @@
else:
raise AttributeError("Cannot assign value to config section")
+ def sections(self):
+ return self._config.sections()
+
def save(self, file):
fh = open(file, 'w')
self._config.write(fh)
Added: branches/ospace_0.5/server/lib/ige/GameServer.py
===================================================================
--- branches/ospace_0.5/server/lib/ige/GameServer.py (rev 0)
+++ branches/ospace_0.5/server/lib/ige/GameServer.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -0,0 +1,102 @@
+#
+# Copyright 2001 - 2012 Ludek Smid [http://www.ospace.net/]
+#
+# This file is part of Outer Space.
+#
+# Outer Space is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Outer Space is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with IGE - Outer Space; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+import os
+
+from ige import log
+from ige.ClientMngr import ClientMngr
+from ige.Config import Config
+from ige.Const import OID_UNIVERSE
+from ige.ospace.GameMngr import GameMngr
+from ige.IssueMngr import IssueMngr
+from ige.MsgMngr import MsgMngr
+from ige.SQLiteDatabase import Database, DatabaseString
+
+def rpc(f):
+ return f
+
+class GameServer(object):
+ """GameServer object manages one or more GameMngr object representing
+ individual games"""
+
+ def __init__(self, configuration):
+ self.loadConfigFile(configuration)
+ # inititalization
+ self.issueMngr = IssueMngr()
+ self.initializeClientMngr()
+ # initialize games
+ self.games = list()
+ for section in self.config.sections():
+ if not section.startswith("game"):
+ continue
+ config = self.config[section]
+ log.message("INITIALIZING GAME", config.gameid)
+ self.initializeGame(config)
+
+ def shutdown(self):
+ """Shutdown whole game server"""
+ for game in self.games:
+ game.shutdown()
+ del self.games
+ self.clientMngr.shutdown()
+ del self.clientMngr
+ self.issueMngr.shutdown()
+ del self.issueMngr
+
+ def loadConfigFile(self, configuration):
+ defaults = dict(
+ cwd = os.path.abspath(os.getcwd()),
+ )
+ self.config = Config(configuration, defaults)
+ # make sure we have required keys defined
+ assert self.config.server.datadir, "server.datadir MUST be defined"
+ assert self.config.server.dbdir, "server.dbdir MUST be defined"
+
+ def initializeClientMngr(self):
+ db = DatabaseString(self.config.server.dbdir, "accounts", cache = 100)
+ self.clientMngr = ClientMngr(db, self.config.server.authmethod, self.config.server.datadir)
+
+ def initializeGame(self, config):
+ """Initialize game according to configuration file fragment"""
+ gameID = config.gameid
+ # make sure we have required keys defined
+ assert config.galaxytype, "%s.galaxytype MUST be defined" % gameID
+ assert config.name, "%s.name MUST be defined" % gameID
+ # initialize database and objects
+ gameDB = Database(self.config.server.dbdir, "%s_game" % gameID, cache = 15000)
+ msgDB = DatabaseString(self.config.server.dbdir, "%s_msgs" % gameID, cache = 1000)
+ msgMngr = MsgMngr(msgDB)
+ gameMngr = GameMngr(gameID, config, self.clientMngr, msgMngr, gameDB, self.config.server.datadir)
+ # reset game if Universe does not exist
+ if not gameDB.has_key(OID_UNIVERSE):
+ log.message('Resetting game \'%s\'...' % gameID)
+ gameMngr.reset()
+ # normal operations
+ gameMngr.init()
+ if self.config.server.upgradegames:
+ gameMngr.upgrade()
+ msgMngr.upgrade()
+ gameMngr.start()
+ # keep reference to this game
+ self.games.append(gameMngr)
+
+ @rpc
+ def getConfiguration(self):
+ """Return configuration of the server"""
+ return
\ No newline at end of file
Property changes on: branches/ospace_0.5/server/lib/ige/GameServer.py
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/ospace_0.5/server/lib/ige/ospace/GameMngr.py
===================================================================
--- branches/ospace_0.5/server/lib/ige/ospace/GameMngr.py 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/server/lib/ige/ospace/GameMngr.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -96,21 +96,21 @@
return obj
def createUniverse(self):
- obj = self.db[OID_UNIVERSE]
- cmdObj = self.cmdPool[obj.type]
+ universe = self.db[OID_UNIVERSE]
tran = Transaction(self, OID_ADMIN)
- #! TODO this is temporary
- # create sector index (needed by loadFromXML)
- galaxy = self.db[cmdObj.createGalaxy(tran, obj)]
- #self.cmdPool[galaxy.type].loadFromXML(tran, galaxy, 'galaxy-Argo42P.xml', 'Circle42P', 100, 100, 'Argo')
- self.cmdPool[galaxy.type].loadFromXML(tran, galaxy, 'galaxy-Circle4P.xml', 'Circle4P', 100, 100, 'Galaxy Test')
- # setup environment
- self.cmdPool[galaxy.type].setupEnvironment(tran, galaxy)
- # start time
- self.cmdPool[galaxy.type].enableTime(tran, galaxy, force = 1)
- # create 'NATURE' player
- player = self.cmdPool[T_NATURE].new(T_NATURE)
- self.registerPlayer(player.login, player, OID_NATURE)
+ self.cmdPool[universe.type].createNewGalaxy(tran, universe, 0, 0, self.config.name)
+ ##! TODO this is temporary
+ ## create sector index (needed by loadFromXML)
+ #galaxy = self.db[cmdObj.createGalaxy(tran, obj)]
+ ##self.cmdPool[galaxy.type].loadFromXML(tran, galaxy, 'galaxy-Argo42P.xml', 'Circle42P', 100, 100, 'Argo')
+ #self.cmdPool[galaxy.type].loadFromXML(tran, galaxy, 'galaxy-Circle4P.xml', 'Circle4P', 100, 100, 'Galaxy Test')
+ ## setup environment
+ #self.cmdPool[galaxy.type].setupEnvironment(tran, galaxy)
+ ## start time
+ #self.cmdPool[galaxy.type].enableTime(tran, galaxy, force = 1)
+ ## create 'NATURE' player
+ #player = self.cmdPool[T_NATURE].new(T_NATURE)
+ #self.registerPlayer(player.login, player, OID_NATURE)
def getTurnData(self, sid):
IGEGameMngr.getTurnData(self, sid)
Modified: branches/ospace_0.5/server/lib/ige/ospace/IUniverse.py
===================================================================
--- branches/ospace_0.5/server/lib/ige/ospace/IUniverse.py 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/server/lib/ige/ospace/IUniverse.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -550,17 +550,24 @@
def createNewGalaxy(self, tran, obj, x, y, galaxyName):
- log.message("Adding new galaxy '%s' to (%d, %d)" % (galaxyName, x, y))
+ galaxyType = tran.gameMngr.config.galaxytype
+ if type(galaxyType) != str:
+ # old configuration file
+ log.debug("OLD configuration file detected, using server.newgalaxytype!")
+ galaxyType = tran.gameMngr.config.server.newgalaxytype
+ galaxyName = "Legacy Galaxy"
+ assert galaxyType, "galaxytype must be defined in configuration file"
+ print galaxyName
+ log.message("Adding new galaxy '%s' with type '%s' to (%d, %d)" % (galaxyName, galaxyType, x, y))
fh, galaxyFileName = tempfile.mkstemp(text = True)
log.debug("Generating new galaxy to temporary file", galaxyFileName)
- strGalaxyID = tran.gameMngr.config.server.newgalaxytype
- GenerateGalaxy(strGalaxyID, os.fdopen(fh, "w+b"))
+ GenerateGalaxy(galaxyType, os.fdopen(fh, "w+b"))
log.debug("Creating new galaxy")
newGalaxyID = self.createGalaxy(tran, obj)
log.debug("Created new galaxy", newGalaxyID)
newGalaxy = tran.db[newGalaxyID]
log.debug("Loading new ", newGalaxyID)
- self.cmd(newGalaxy).loadFromXML(tran, newGalaxy, galaxyFileName, strGalaxyID, x, y, galaxyName)
+ self.cmd(newGalaxy).loadFromXML(tran, newGalaxy, galaxyFileName, galaxyType, x, y, galaxyName)
log.debug("Setup Enviroment", newGalaxyID)
self.cmd(newGalaxy).setupEnvironment(tran, newGalaxy)
log.debug("Sending Announcement Message", newGalaxyID)
Deleted: branches/ospace_0.5/server/ospace-server
===================================================================
--- branches/ospace_0.5/server/ospace-server 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/server/ospace-server 2011-12-28 19:02:47 UTC (rev 324)
@@ -1,168 +0,0 @@
-#!/usr/bin/env python2.4
-#
-# Copyright 2001 - 2006 Ludek Smid [http://www.ospace.net/]
-#
-# This file is part of IGE - Outer Space.
-#
-# IGE - Outer Space is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# IGE - Outer Space is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with IGE - Outer Space; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-import sys
-
-# setup system path
-sys.path.insert(0,"lib")
-
-import os, atexit
-import getopt
-
-# logger
-from ige import log
-log.setMessageLog('var/logs/messages.log')
-log.setErrorLog('var/logs/errors.log')
-
-# options
-# parse arguments
-log.message('Parsing arguments...')
-options = ('reset', 'upgrade', 'devel', 'restore')
-
-opts, args = getopt.getopt(sys.argv[1:], '', options)
-
-optReset = 0
-optUpgrade = 0
-optDevel = 0
-optRestore = 0
-
-for opt, arg in opts:
- if opt == '--reset':
- optReset = 1
- elif opt == '--upgrade':
- optUpgrade = 1
- elif opt == '--devel':
- optDevel = 1
- elif opt == '--restore':
- optRestore = 1
-
-# record my pid
-
-# pid
-pidFd = os.open("var/server.pid", os.O_CREAT | os.O_EXCL | os.O_WRONLY)
-os.write(pidFd, str(os.getpid()))
-# TODO: check if server.pid points to the running process
-
-game = None
-msgMngr = None
-clientMngr = None
-issueMngr = None
-
-# define and register exit function
-def cleanup():
-# shut down game
- try:
- if game:
- log.message('Shutting down game...')
- game.shutdown()
-
- if msgMngr:
- log.message('Shutting down message manager...')
- msgMngr.shutdown()
-
- if clientMngr:
- log.message('Shutting down client manager...')
- clientMngr.shutdown()
-
- if issueMngr:
- log.message('Shutting down issue manager...')
- issueMngr.shutdown()
- except:
- log.exception("Shutdown of the server failed")
-
- log.message('Shutted down')
- log.message("Cleaning up...")
- # delete my pid
- os.close(pidFd)
- os.remove("var/server.pid")
-
-atexit.register(cleanup)
-
-# startup game
-log.debug('Importing IGE modules...')
-
-import ige.RPCServer as server
-import ige
-from ige.ClientMngr import ClientMngr
-from ige.MsgMngr import MsgMngr
-from ige.IssueMngr import IssueMngr
-from ige.ospace.GameMngr import GameMngr
-
-# set runtime mode
-ige.setRuntimeMode(not optDevel)
-
-gameName = 'Alpha'
-
-# open database
-from ige.MetakitDatabase import MetakitDatabase, MetakitDatabaseString
-
-log.debug("Creating databases...")
-gameDB = MetakitDatabase("var/db_data", "game_%s" % gameName, cache = 15000)
-clientDB = MetakitDatabaseString("var/db_data", "accounts", cache = 100)
-msgDB = MetakitDatabaseString("var/db_data", "messages", cache = 1000)
-
-if optRestore:
- gameDB.restore("var/backup-game_Alpha.osbackup")
- clientDB.restore("var/backup-accounts.osbackup")
- msgDB.restore("var/backup-messages.osbackup")
-
-# initialize game
-log.message('Initializing game \'%s\'...' % gameName)
-
-log.debug("Initializing issue manager")
-issueMngr = IssueMngr()
-log.debug("Initializing client manager")
-clientMngr = ClientMngr(clientDB)
-log.debug("Initializing message manager")
-msgMngr = MsgMngr(msgDB)
-
-log.debug("Initializing game manager")
-game = GameMngr(gameName, clientMngr, msgMngr, gameDB)
-
-if optReset:
- # reset game
- log.message('Resetting game \'%s\'...' % gameName)
- game.reset()
-else:
- # normal operations
- game.init()
-
- if optUpgrade:
- game.upgrade()
- msgMngr.upgrade()
-
- game.start()
-
- server.init(clientMngr)
- server.register(game)
-
- server.xmlrpcPublish('clientmngr', clientMngr)
- server.xmlrpcPublish('issuemngr', issueMngr)
-
- log.message('Initialized. Starting server...')
-
- try:
- import psyco
- psyco.full()
- log.message("Using psyco with full acceleration")
- except ImportError:
- log.message("NOT using psyco")
- server.start()
Copied: branches/ospace_0.5/server/ospace-server.py (from rev 322, branches/ospace_0.5/server/ospace-server)
===================================================================
--- branches/ospace_0.5/server/ospace-server.py (rev 0)
+++ branches/ospace_0.5/server/ospace-server.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -0,0 +1,127 @@
+#!/usr/bin/python
+#
+# Copyright 2001 - 2012 Ludek Smid [http://www.ospace.net/]
+#
+# This file is part of Outer Space.
+#
+# Outer Space is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Outer Space is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Outer Space; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+import os
+import sys
+
+# setup system path
+baseDir = os.path.abspath(os.path.dirname(__file__))
+
+sys.path.insert(0, os.path.join(baseDir, "lib"))
+sys.path.insert(0, os.path.join(baseDir, "..", "client-ai"))
+
+import atexit
+import optparse
+
+from ai_parser import AIList
+
+parser = optparse.OptionParser()
+parser.add_option("", "--configdir", dest="configDir",
+ metavar="DIRECTORY",
+ default="var",
+ help="Override default configuration directory",
+)
+parser.add_option("", "--configfile", dest="configFile",
+ metavar="DIRECTORY",
+ default="config.ini",
+ help="Override default name of configuration file",
+)
+parser.add_option("", "--restore", dest="restore",
+ metavar="STRING",
+ default=None,
+ help="Restore from backup files beginning with STRING",
+)
+parser.add_option("", "--reset", dest="reset",
+ action="store_true", default=False,
+ help="Sets server to reset itself"
+)
+parser.add_option("", "--upgrade", dest="upgrade",
+ action="store_true", default=False,
+ help="Server will undergo upgrade routine"
+)
+parser.add_option("", "--devel", dest="devel",
+ action="store_true", default=False,
+ help="Server will run in debug mode",
+)
+
+options, args = parser.parse_args()
+
+if args:
+ parser.error("No additional arguments are supported")
+
+# legacy logger
+from ige import log
+log.setMessageLog(os.path.join(options.configDir, 'logs/messages.log'))
+log.setErrorLog(os.path.join(options.configDir, 'logs/errors.log'))
+
+import ige.version
+log.message("Outer Space %s" % ige.version.versionStringFull)
+
+# record my pid
+pidFd = os.open(os.path.join(options.configDir, "server.pid"), os.O_CREAT | os.O_EXCL | os.O_WRONLY)
+os.write(pidFd, str(os.getpid()))
+# TODO: check if server.pid points to the running process
+
+gameServer = None
+
+# define and register exit function
+def cleanup():
+ """Shutdown game properly"""
+ try:
+ if gameServer:
+ log.message('Shutting down game...')
+ gameServer.shutdown()
+ except:
+ log.exception("Shutdown of the server failed")
+
+ # delete my pid
+ os.close(pidFd)
+ os.remove(os.path.join(options.configDir, "server.pid"))
+ log.message("GAME SHUT DOWN")
+
+atexit.register(cleanup)
+
+# startup game
+import ige
+import ige.RPCServer as server
+
+# set runtime mode
+ige.setRuntimeMode(not options.devel)
+
+# create game server
+from ige.GameServer import GameServer
+
+gameServer = GameServer(os.path.join(options.configDir, options.configFile))
+
+server.init(gameServer.clientMngr)
+for game in gameServer.games:
+ server.register(game)
+
+log.message('Initialized. Starting server...')
+
+try:
+ import psyco
+ psyco.full()
+ log.message("Using psyco with full acceleration")
+except ImportError:
+ log.message("NOT using psyco")
+
+server.start()
\ No newline at end of file
Property changes on: branches/ospace_0.5/server/ospace-server.py
___________________________________________________________________
Added: svn:executable
+ *
Modified: branches/ospace_0.5/server/run.py
===================================================================
--- branches/ospace_0.5/server/run.py 2011-12-05 21:53:41 UTC (rev 323)
+++ branches/ospace_0.5/server/run.py 2011-12-28 19:02:47 UTC (rev 324)
@@ -173,7 +173,7 @@
from ige.SQLiteDatabase import Database, DatabaseString
# set type of generated galaxies
if not config.server.newgalaxytype:
- config.server.newgalaxytype = 'Circle42P'
+ config.server.newgalaxytype = 'Circle9P'
log.debug("Creating databases...")
gameDB = Database(os.path.join(options.configDir,"db_data"), "game_%s" % gameName, cache = 15000)
@@ -204,7 +204,7 @@
log.debug("Initializing issue manager")
issueMngr = IssueMngr()
log.debug("Initializing client manager")
-clientMngr = ClientMngr(clientDB, config, options.configDir)
+clientMngr = ClientMngr(clientDB, config.server.authmethod, options.configDir)
log.debug("Initializing message manager")
msgMngr = MsgMngr(msgDB)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|