Exemple #1
0
 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")))
Exemple #2
0
 def fromBinary(self, uuid, version=None):
     if len(uuid) != 16:
         raise Exception("Must have exactly 16 bytes")
     return UUID(Binary.readInt(Utils.substr(uuid, 0, 4)),
                 Binary.readInt(Utils.substr(uuid, 4, 4)),
                 Binary.readInt(Utils.substr(uuid, 8, 4)),
                 Binary.readInt(Utils.substr(uuid, 12, 4)), version)
Exemple #3
0
 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")))
Exemple #4
0
 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)
Exemple #5
0
    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)
Exemple #6
0
 def __init__(self):
     if Utils.getOS() == 'windows':
         from ctypes import windll
         kernel = windll.kernel32
         kernel.SetConsoleMode(kernel.GetStdHandle(-11), 7)
     self.BOLD = '\x1b[1m'
     self.OBFUSCATED = ''
     self.ITALIC = '\x1b[3m'
     self.UNDERLINE = '\x1b[4m'
     self.STRIKETHROUGH = '\x1b[9m'
     self.RESET = '\x1b[m'
     self.BLACK = '\x1b[38;5;16m'
     self.DARKBLUE = '\x1b[38;5;19m'
     self.DARKGREEN = '\x1b[38;5;34m'
     self.DARKAQUA = '\x1b[38;5;37m'
     self.DARKRED = '\x1b[38;5;124m'
     self.PURPLE = '\x1b[38;5;127m'
     self.GOLD = '\x1b[38;5;214m'
     self.GRAY = '\x1b[38;5;145m'
     self.DARKGRAY = '\x1b[38;5;59m'
     self.BLUE = '\x1b[38;5;63m'
     self.GREEN = '\x1b[38;5;83m'
     self.AQUA = '\x1b[38;5;87m'
     self.RED = '\x1b[38;5;203m'
     self.LIGHTPURPLE = '\x1b[38;5;207m'
     self.YELLOW = '\x1b[38;5;227m'
     self.WHITE = '\x1b[38;5;231m'
Exemple #7
0
 def toString(self):
     hex = Utils.bin2hex(self.toBinary())
     if self.version != None:
         return hex[0:8] + "-" + hex[8:8 + 4] + "-" + int(
             self.version,
             16) + hex[13:13 + 3] + "-8" + hex[17:17 +
                                               3] + "-" + hex[20:20 + 12]
     return hex[0:8] + "-" + hex[8:8 + 4] + "-" + hex[
         12:12 + 4] + "-" + hex[16:16 + 4] + "-" + hex[20:20 + 12]
Exemple #8
0
 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)
Exemple #9
0
 def decodePayload(self):
     self.protocol = self.getInt()
     stream = NetworkStream(self.getBytesString())
     chainData = json.loads(stream.get(stream.getLInt()).decode())
     for chain in chainData["chain"]:
         decodedChain = Utils.decodeJwt(chain)
         if "extraData" in decodedChain:
             extraData = decodedChain["extraData"]
             self.xuid = extraData["XUID"]
             self.identity = extraData["identity"]
             self.displayName = extraData["displayName"]
         self.identityPublicKey = decodedChain["identityPublicKey"]
     decodedJwt = Utils.decodeJwt(stream.get(stream.getLInt()).decode())
     self.deviceId = decodedJwt["DeviceId"]
     self.deviceOs = decodedJwt["DeviceOS"]
     self.deviceModel = decodedJwt["DeviceModel"]
     self.clientRandomId = decodedJwt["ClientRandomId"]
     self.serverAddress = decodedJwt["ServerAddress"]
     self.languageCode = decodedJwt["LanguageCode"]
     self.skin = self.skinFromDecodedJwt(decodedJwt)
Exemple #10
0
 def decodePayload(self):
     self.protocol = self.getInt()
     try:
         buffer = DataPacket.BinaryStream(self.getString())
         self.chainData = json.loads(buffer.get(buffer.getLInt()))
         hasExtraData = False
         for chain in self.chainData["chain"]:
             webtoken = Utils.decodeJWT(chain)
             if webtoken["extraData"] in locals(
             ) or webtoken["extraData"] in globals():
                 if hasExtraData:
                     raise Exception(
                         "Found 'extraData' multiple times in key chain")
                 hasExtraData = True
                 if webtoken["extraData"]["displayName"] in locals(
                 ) or webtoken["extraData"]["displayName"] in globals():
                     self.username = webtoken["extraData"]["displayName"]
                 if webtoken["extraData"]["identity"] in locals(
                 ) or webtoken["extraData"]["identity"] in globals():
                     self.clientUUID = webtoken["extraData"]["identity"]
                 if webtoken["extraData"]["XUID"] in locals(
                 ) or webtoken["extraData"]["XUID"] in globals():
                     self.xuid = webtoken["extraData"]["XUID"]
             if webtoken["identityPublicKey"] in locals(
             ) or webtoken["identityPublicKey"] in globals():
                 self.identityPublicKey = webtoken["identityPublicKey"]
         self.clientDataJwt = buffer.get(buffer.getLInt())
         self.clientData = Utils.decodeJWT(self.clientDataJwt)
         self.clientId = self.clientData[
             "ClientRandomId"] if self.clientData[
                 "ClientRandomId"] != None else None
         self.serverAddress = self.clientData[
             "ServerAddress"] if self.clientData[
                 "ServerAddress"] != None else None
         self.locale = self.clientData["LanguageCode"] if self.clientData[
             "LanguageCode"] != None else None
     except:
         if self.protocol == ProtocolInfo.MCBE_PROTOCOL_VERSION:
             raise Exception("Error")
Exemple #11
0
 def putPacket(self,
               player: Player,
               packet: DataPacket,
               needACK: bool = False,
               immediate: bool = True):
     if Utils.searchList(self.identifers, player) == True:
         identifier = self.identifiers[Utils.getKeyInListFromItem(
             self.identifers, player)]
         if not packet.isEncoded:
             packet.encode()
         if isinstance(packet, BatchPacket):
             if needACK:
                 pk = EncapsulatedPacket()
                 pk.identifierACK = self.identifiersACK[identifier]
                 self.identifiersACK[identifier] += 1
                 pk.buffer = packet.buffer
                 pk.reliability = 3
                 pk.orderChannel = 0
             else:
                 try:
                     packet._encapsulatedPacket
                 except:
                     packet._encapsulatedPacket = CachedEncapsulatedPacket()
                     packet._encapsulatedPacket.identifierACK = None
                     packet._encapsulatedPacket.buffer = packet.buffer
                     packet._encapsulatedPacket.reliability = 3
                     packet._encapsulatedPacket.orderChannel = 0
                 pk = packet._encapsulatedPacket
             self.interface.sendEncapsulated(
                 identifier, pk, (PyRakLib.FLAG_NEED_ACK if needACK else 0)
                 | (PyRakLib.PRIORITY_IMMEDIATE
                    if immediate else PyRakLib.PRIORITY_NORMAL))
             return pk.identifierACK
         else:
             #self.server.batchPackets([player], [packet], True, immediate)
             return None
     return None
Exemple #12
0
 def start():
     config = Utils.getDefaultConfig()
     step = 0
     while True:
         if step == 0:
             Base.printLanguages()
             userInput = input("> Please, select a language: ")
             if userInput in Base.languages:
                 config.config["language"] = userInput
                 print("- " + Base.getTranslation("langSelectedAsBase"))
                 step += 1
             else:
                 print("[!] That language does not exists. Please, choose one from the list.")
         elif step == 1:
             print(Wizard.podrumLicense)
             userInput = input("> " + Base.getTranslation("acceptLicense") + ": ")
             if Wizard.checkYesNo(userInput):
                 step += 1
             elif not Wizard.checkYesNo(userInput):
                 print(Base.getTranslation("mustAcceptLicense"))
             elif Wizard.checkYesNo(userInput) is None:
                 print(Base.getTranslation("writeYesOrNo"))
         elif step == 2:
             userInput = input("> " + Base.getTranslation("wizardSetup") + ": ")
             if Wizard.checkYesNo(userInput):
                 step += 1
             elif not Wizard.checkYesNo(userInput):
                 print("> " + Base.getTranslation("wizardSkipped"))
                 Wizard.isInWizard = False
                 config.save()
                 break
         elif step == 3:
             print(Wizard.podrumLogo)
             print(">- Podrum - Wizard -<\n\n")
             step += 1
         elif step == 4:
             userInput = input("[>] " + Base.getTranslation("writeServerPort") + " ")
             if userInput == "":
                 config.config["server-port"] = 19132
                 step += 1
             elif userInput.isdigit():
                 config.config["server-port"] = int(userInput)
                 step += 1
         elif step == 5:
             userInput = input("[>] " + Base.getTranslation("writeMOTD") + " ")
             if(userInput != ""):
                 config.config["motd"] = userInput
                 step += 1
         elif step == 6:
             userInput = input("[>] " + Base.getTranslation("writeGamemode") + " ")
             if userInput.isdigit():
                 if int(userInput) >= 0 and int(userInput) <= 3:
                     config.config["gamemode"] = int(userInput)
                     step += 1
         elif step == 7:
             userInput = input("[>] " + Base.getTranslation("writeMaxPlayers") + " ")
             if userInput.isdigit():
                 config.config["max-players"] = int(userInput)
                 step += 1
         elif step == 8:
             print(Base.getTranslation("wizardFinished"))
             Wizard.isInWizard = False
             config.save()
             break
Exemple #13
0
 def fromString(self, uuid, version=None):
     return self.fromBinary(Utils.hex2bin(uuid.strip().replace("-", "")),
                            version)
Exemple #14
0
 def toString(self):
     hex = Utils.bin2hex(self.toBinary())
     if self.version != None:
         return Utils.substr(hex, 0, 8) + "-" + Utils.substr(
             hex, 8, 4) + "-" + int(self.version, 16) + Utils.substr(
                 hex, 13, 3) + "-8" + Utils.substr(
                     hex, 17, 3) + "-" + Utils.substr(hex, 20, 12)
     return Utils.substr(hex, 0, 8) + "-" + Utils.substr(
         hex, 8, 4) + "-" + Utils.substr(hex, 12, 4) + "-" + Utils.substr(
             hex, 16, 4) + "-" + Utils.substr(hex, 20, 12)
 def execute(self, sender, args):
     sender.sendMessage("Stopping server...")
     Plugin.unloadAll()
     sender.sendMessage("Server stopped.")
     Utils.killServer()
Exemple #16
0
 def getTranslation(content):
     config = Utils.getDefaultConfig()
     langId = config.config["language"]
     return Base.translate(langId, content)