def main(): tornado.options.parse_command_line() # Port port = options.port # Instance Type instancetype = options.instancetype # Zone name zonename = options.zonename # Owner owner = options.owner zoneid = '-'.join((instancetype, zonename, owner)) print "ZoneID: %s" % zoneid # Make sure mongodb is up while True: try: me.connect(zoneid) break except(me.connection.ConnectionError): # Mongo's not up yet. Give it time. time.sleep(.1) print "sleeping" print "Loading %s's data." % zonename from importlib import import_module # Import the zone's init script zonemodule = import_module('games.zones.'+zonename) # Initialize the zone zonescript = zonemodule.Zone() handlers = [] handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y))) handlers.append((r"/objects", ObjectsHandler)) handlers.append((r"/setstatus", CharStatusHandler)) handlers.append((r"/movement", MovementHandler)) handlers.append((r"/admin", AdminHandler)) handlers.append((r"/messages", MessageHandler)) handlers.append((r"/activate/(.*)", ScriptedObjectHandler)) server = BaseServer(handlers) server.listen(port) print "Starting up Zoneserver..." server.start()
def main(): import tornado from tornado.options import options, define # Port port = options.port # Instance Type instancetype = options.instancetype # Zone name zonename = options.zonename # Owner owner = options.owner handlers = [] # handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y))) handlers.append((r"/objects", ObjectsHandler)) handlers.append((r"/setstatus", CharStatusHandler)) handlers.append((r"/movement", MovementHandler)) handlers.append((r"/admin", AdminHandler)) handlers.append((r"/messages", MessageHandler)) handlers.append((r"/activate/(.*)", ScriptedObjectHandler)) server = BaseServer(handlers) zoneid = '-'.join((instancetype, zonename, owner)) print "ZoneID: %s" % zoneid print "Loading %s's data." % zonename # Import the zone's init script zonemodule = import_object('games.zones.'+zonename) # Initialize the zone zonescript = zonemodule.Zone(logger=logging.getLogger('simplemmo-zoneserver-'+zoneid)) server.listen(port) logging.info("Starting up Zoneserver...") try: server.start() except KeyboardInterrupt: logging.info("Exiting %s." % zoneid)
def main(): import tornado from tornado.options import options, define # Port port = options.port # Instance Type instancetype = options.instancetype # Zone name zonename = options.zonename # Owner owner = options.owner handlers = [] # handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y))) handlers.append((r"/objects", ObjectsHandler)) handlers.append((r"/setstatus", CharStatusHandler)) handlers.append((r"/movement", MovementHandler)) handlers.append((r"/admin", AdminHandler)) handlers.append((r"/messages", MessageHandler)) handlers.append((r"/activate/(.*)", ScriptedObjectHandler)) server = BaseServer(handlers) zoneid = '-'.join((instancetype, zonename, owner)) print "ZoneID: %s" % zoneid print "Loading %s's data." % zonename # Import the zone's init script zonemodule = import_object('games.zones.' + zonename) # Initialize the zone zonescript = zonemodule.Zone( logger=logging.getLogger('simplemmo-zoneserver-' + zoneid)) server.listen(port) logging.info("Starting up Zoneserver...") try: server.start() except KeyboardInterrupt: logging.info("Exiting %s." % zoneid)
def get_characters(self, username): '''Queries the database for all characters owned by a particular user.''' user = User.get(username=username) logging.info(user.characters) return [c.name for c in user.characters] if __name__ == "__main__": handlers = [] handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y))) handlers.append((r"/register", RegistrationHandler)) handlers.append((r"/login", AuthHandler)) handlers.append((r"/logout", LogoutHandler)) handlers.append((r"/characters", CharacterHandler)) server = BaseServer(handlers) server.listen(settings.AUTHSERVERPORT) try: user = User.get(username=settings.DEFAULT_USERNAME) except User.DoesNotExist: password = UserController.hash_password(settings.DEFAULT_PASSWORD) user = User(username=settings.DEFAULT_USERNAME, password=password) user.save() print "Starting up Authserver..." try: server.start() except KeyboardInterrupt: print "Exiting Authserver."
def cleanup(self): # Every 5 minutes... global NEXTCLEANUP if NEXTCLEANUP < time.time(): NEXTCLEANUP = time.time() + (5 * 60) # If pid not in database # Kill the process by pid if __name__ == "__main__": handlers = [] handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y))) handlers.append((r"/(.*)", ZoneHandler)) server = BaseServer(handlers) # On startup, iterate through entries in zones table. See if they are up, if not, delete them. for port in [z.port for z in Zone.select()]: serverurl = "%s://%s:%d" % (PROTOCOL, HOSTNAME, port) try: requests.get(serverurl) except (requests.ConnectionError): # Server is down, remove it from the zones table. Zone.get(port=port).delete_instance() server.listen(MASTERZONESERVERPORT) print "Starting up Master Zoneserver..." try: server.start()
def create(self, character_name): logging.info("Creating a character named %s" % character_name) try: user = User.get(username=self.get_current_user()) except User.DoesNotExist: return if Character.select().where(Character.name==character_name).exists(): return False character = Character(user=user, name=character_name) character.save() logging.info("Created a character %s" % character) return character.name if __name__ == "__main__": handlers = [] handlers.append((r"/", lambda x, y: SimpleHandler(__doc__, x, y))) handlers.append((r"/new", CharacterCreationHandler)) handlers.append((r"/(.*)/zone", CharacterZoneHandler)) server = BaseServer(handlers) server.listen(CHARSERVERPORT) print "Starting up Charserver..." try: server.start() except KeyboardInterrupt: logging.info("Exiting Charserver.")
tornado.options.parse_command_line() dburi = options.dburi # Connect to the elixir db from elixir_models import setup setup(db_uri=dburi) # On startup, iterate through entries in zones table. See if they are up, if not, delete them. for port in [z[0] for z in session.query(Zone.port).all()]: serverurl = "%s://%s:%d" % (PROTOCOL, HOSTNAME, port) try: requests.get(serverurl) except(requests.ConnectionError): # Server is down, remove it from the zones table. Zone.query.filter_by(port=port).delete(), Zone session.commit() server = BaseServer(handlers) server.listen(MASTERZONESERVERPORT) print "Starting up Master Zoneserver..." try: server.start() except KeyboardInterrupt: # Catch ctrl+c and continue with the script. pass for job in JOBS: job.terminate()