def on_close(self): G.PENDING_NOTIFICATIONS += ('Average FPS: %f' % (self.total_fps / self.iterations), ) if G.SERVER: G.PENDING_NOTIFICATIONS += ("Saving...", ) save_world(G.SERVER, "world") G.update_notifications() G.STOP = True super(Window, self).on_close()
def main(options): G.GAME_MODE = options.game_mode G.SAVE_FILENAME = options.save G.DISABLE_SAVE = options.disable_save for name, val in options._get_kwargs(): setattr(G.LAUNCH_OPTIONS, name, val) if options.fast: G.TIME_RATE //= 20 if G.LANGUAGE != 'default': reload(sys) sys.setdefaultencoding('utf8') gettext.install(True, localedir=None, str=1) gettext.find(G.APP_NAME.lower(), 'locale') gettext.textdomain(G.APP_NAME.lower()) gettext.bind_textdomain_codeset(G.APP_NAME.lower(), 'utf8') language = gettext.translation(G.APP_NAME.lower(), 'locale', languages=[G.LANGUAGE], fallback=True) G._ = lambda s: language.ugettext(s) load_modules() # try: # window_config = Config(sample_buffers=1, samples=4) #, depth_size=8) #, double_buffer=True) #TODO Break anti-aliasing/multisampling into an explicit menu option # window = Window(resizable=True, config=window_config) # except pyglet.window.NoSuchConfigException: window = Window(resizable=True, vsync=False) pyglet.app.run() if G.CLIENT: G.CLIENT.stop() if G.SERVER: print('Saving...') save_world(G.SERVER, "world") print('Shutting down internal server...') G.main_timer.stop() G.SERVER._stop.set() G.SERVER.shutdown()
print "Listening on",ip,port helptext = "Available commands: " + ", ".join(["say", "stop", "save"]) while 1: args = raw_input().replace(chr(13), "").split(" ") # On some systems CR is appended, gotta remove that cmd = args.pop(0) if cmd == "say": msg = "Server: %s" % " ".join(args) print msg for player in server.players.itervalues(): player.sendchat(msg, color=(180,180,180,255)) elif cmd == "help": print helptext elif cmd == "save": print "Saving..." save_world(server, "world") print "Done saving" elif cmd == "stop": server._stop.set() print "Disconnecting clients..." for address in server.players: server.players[address].request.shutdown(SHUT_RDWR) server.players[address].request.close() print "Shutting down socket..." server.shutdown() print "Saving..." save_world(server, "world") print "Goodbye" break else: print "Unknown command '%s'." % cmd, helptext
print "Listening on",ip,port helptext = "Available commands: " + ", ".join(["say", "stop", "save"]) while 1: args = raw_input().replace(chr(13), "").split(" ") # On some systems CR is appended, gotta remove that cmd = args.pop(0) if cmd == "say": msg = "Server: %s" % " ".join(args) print msg for player in server.players.itervalues(): player.sendchat(msg, color=(180,180,180,255)) elif cmd == "help": print helptext elif cmd == "save": print "Saving..." save_world(server, "world") print "Done saving" elif cmd == "stop": server._stop.set() G.main_timer.stop() print "Disconnecting clients..." for address in server.players: try: server.players[address].request.shutdown(SHUT_RDWR) server.players[address].request.close() except socket.error: pass print "Shutting down socket..." server.shutdown() print "Saving..." save_world(server, "world")
def execute(self): save_world(G.SERVER, "world")
def save_to_file(self): if G.DISABLE_SAVE: save_world(self, G.game_dir, G.SAVE_FILENAME)