def checkTravisBuild(path): if not ServerFS.checkForFile(path, "server.json"): Logger.log("error", "Couldn't find server.json file.") os._exit(1) if os.path.getsize(f'{path}/server.json') == 0: Logger.log("error", "The server.json file is empty.") os._exit(1) print("Build success.") os._exit(0)
def run(self): while True: line = input() if line != "": args = line.split() command = args[0] if CommandManager.isCommand(command): CommandManager.commands[command].execute(self.server, args) else: Logger.error(Base.getTranslation("invalidCommand"))
def unload(plugin): PluginLoader.setValues(plugin) if PluginLoader.main.rsplit('.', 1)[0] in sys.modules: PluginLoader.pluginModule = importlib.import_module( PluginLoader.main.rsplit('.', 1)[0]) pluginClass = getattr(PluginLoader.pluginModule, PluginLoader.main.rsplit('.', 1)[1]) Logger.log('info', f'Unloading {PluginLoader.name}...') pluginClass.onStop() Logger.log('success', f'Successfully unloaded {PluginLoader.name}!') pluginClass.onStopped() del sys.modules[PluginLoader.main.rsplit('.', 1)[0]] del PluginLoader.loadedPluginFiles[plugin] del PluginLoader.loadedPluginNames[PluginLoader.name] PluginLoader.loadedPluginsList = list( PluginLoader.loadedPluginNames.keys()) PluginLoader.loadedPluginsCount = len( PluginLoader.loadedPluginNames)
def save(self): try: if self.format == self.formats["json"]: self.file = open(self.file.name , "+w") json.dump(self.config, self.file, indent = 4) elif self.format == self.formats["yaml"]: self.file = open(self.file.name , "+w") yaml.dump(self.config, self.file) elif self.format == self.formats["properties"]: self.file = open(self.file.name , "+w") Properties.dump(self.config, self.file) elif self.format == self.formats["toml"]: self.file = open(self.file.name , "+w") toml.dump(self.config, self.file) elif self.format == self.formats["ini"]: self.file = open(self.file.name , "+w") toml.dump(self.config, self.file) except Exception as e: Logger.error(f"Could not save the config: {self.file.name}") Logger.error(e)
def __init__(self, withWizard): super().__init__() self.startTime = time() if Utils.getOS() == "windows": Utils.enableWindowsFormating() if Utils.isPacked(): print(Utils.getPodrumDir()) Base.addFromZipDir(Utils.getPodrumDir(), "podrum/lang/languages") else: Base.addFromDir(Utils.getPodrumDir() + "/" + "podrum/lang/languages") if not Utils.checkAllFiles() and withWizard: Wizard.start() while Wizard.isInWizard: pass self.config = Utils.getDefaultConfig() self.ip = self.config.config["server-ip"] self.port = int(self.config.config["server-port"]) print(str(self.podrumLogo)) Logger.info(str(Base.getTranslation("startingServer")).replace("{ip}", str(self.ip)).replace("{port}", str(self.port))) Logger.info(str(Base.getTranslation("license"))) RegisterVanilla() Plugin.pluginsDir = os.getcwd() + "/plugins" Plugin.server = self Plugin.loadAll() self.endTime = time() self.timeDiff = "%.3f" % (self.endTime - self.startTime) Logger.info(f'Done in {str(self.timeDiff)}s. Type "help" to view all available commands.') CommandReader(self) Interface(self.ip, self.port) while self.isTicking: sleep(self.tickrate)
def __init__(self, path, withWizard, isTravisBuild=False): super().__init__() startTime = Utils.microtime(True) self.path = path self.withWizard = withWizard if (withWizard): ServerFS.checkAllFiles(path) else: Wizard.skipWizard(path, True) port = self.port print(str(self.podrumLogo)) Wizard.isInWizard = False Logger.log( 'info', str(Base.get("startingServer")).replace( "{ip}", str(Utils.getPrivateIpAddress())).replace("{port}", str(port))) Logger.log( 'info', str(Base.get("extIpMsg")).replace("{ipPublic}", str(Utils.getPublicIpAddress()))) Logger.log('info', str(Base.get("license"))) server = PyRakLibServer(port=19132) handler = ServerHandler(server, None) handler.sendOption( "name", "MCPE;Podrum powered server;407;1.16.0;0;0;0;PodrumPoweredServer;0" ) repeter = 0 while repeater >= 1: pass # Here is going to be the place for the packet handling doneTime = Utils.microtime(True) finishStartupSeconds = "%.3f" % (doneTime - startTime) Logger.log( 'info', f'Done in {str(finishStartupSeconds)}s. Type "help" to view all available commands.' ) if (isTravisBuild): Server.checkTravisBuild(path) else: while Wizard.isInWizard == False: cmd = input('> ') Server.command(cmd, True) cmd = None ticking = True while ticking: time.sleep(0.002)
def command(string, fromConsole): if string.lower() == 'stop': Logger.log('info', 'Stopping server...') Utils.killServer() elif string.lower() == '': return elif string.lower() == 'help': Logger.log('info', '/stop: Stops the server') else: Logger.log('error', str(Base.get("invalidCommand")))
def __init__(self, path, withWizard, isTravisBuild=False): super().__init__() startTime = Utils.microtime(True) self.path = path self.withWizard = withWizard self.tickrate = 20 / 1000 if (withWizard): ServerFS.checkAllFiles(path) else: Wizard.skipWizard(path, True) print(str(self.podrumLogo)) Wizard.isInWizard = False Logger.log( 'info', str(Base.get("startingServer")).replace( "{ip}", str(Utils.getPrivateIpAddress())).replace( "{port}", str(self.port))) Logger.log( 'info', str(Base.get("extIpMsg")).replace("{ipPublic}", str(Utils.getPublicIpAddress()))) Logger.log('info', str(Base.get("license"))) PluginLoader.loadAll() doneTime = Utils.microtime(True) self.queryHandler = QueryHandler(self) self.mainInterface = NetworkInterface(self) self.mainInterface.process() finishStartupSeconds = "%.3f" % (doneTime - startTime) Logger.log( 'info', f'Done in {str(finishStartupSeconds)}s. Type "help" to view all available commands.' ) if (isTravisBuild): Server.checkTravisBuild(path) else: while Wizard.isInWizard == False: cmd = input('> ') Server.command(cmd, True) cmd = None ticking = True while ticking: time.sleep(self.tickrate)
def load(plugin): if Plugin.getName(plugin) in PluginLoader.loadedPluginNames: Logger.log('alert', f'Disabling duplicate plugin {Plugin.getName(plugin)}') return PluginLoader.setValues(plugin) sys.path.insert(0, plugin) PluginLoader.pluginModule = importlib.import_module( PluginLoader.main.rsplit('.', 1)[0]) pluginClass = getattr(PluginLoader.pluginModule, PluginLoader.main.rsplit('.', 1)[1]) Logger.log('info', f'Loading {PluginLoader.name}...') pluginClass.onStart() Logger.log('success', f'Successfully loaded {PluginLoader.name}!') pluginClass.onStarted() PluginLoader.loadedPluginFiles.update({plugin: plugin}) PluginLoader.loadedPluginNames.update( {PluginLoader.name: PluginLoader.name}) PluginLoader.loadedPluginsList = list( PluginLoader.loadedPluginNames.keys()) PluginLoader.loadedPluginsCount = len(PluginLoader.loadedPluginNames)
def sendMessage(self, message): Logger.info(message)
def onCloseConnection(self, address, reason): Logger.info(f"{address.address} disconnected due to {reason}")
def getLogger(self): return Logger()
def command(string, fromConsole): if string.lower() == 'stop': Logger.log('info', 'Stopping server...') PluginLoader.unloadAll() Logger.log('info', 'Server stopped.') Utils.killServer() elif string.lower() == '': return elif string.lower() == 'help': Logger.log('info', '/stop: Stops the server') elif string.lower() == 'reload': PluginLoader.reloadAll() Logger.log('info', 'Reload successful!') elif string.lower() == 'plugins' or string.lower() == 'pl': pluginsString = "" for pluginName in PluginLoader.loadedPluginsList: pluginsString = pluginsString + pluginName if pluginName != PluginLoader.loadedPluginsList[ PluginLoader.loadedPluginsCount - 1]: pluginsString += ", " Logger.log( 'info', f'Plugins({PluginLoader.loadedPluginsCount}): {pluginsString}') else: Logger.log('error', str(Base.get("invalidCommand")))