Ejemplo n.º 1
0
    def render_POST(self, request):
        def started(result):
            request.finish()

        def stopped(result):
            request.finish()

        data = json.loads(request.content.getvalue())
        action = data.get("action", None)

        s = supervisor.get()

        if action is None:
            return resource.ErrorPage(http.BAD_REQUEST,
                                      http.RESPONSES[http.BAD_REQUEST],
                                      "action required")

        elif action.lower() == "start":
            d = s.startMinecraft(jar=settings.config["minecraft"]["jar"],
                                 path=settings.config["minecraft"]["home"])
            d.addCallback(started)

        elif action.lower() == "stop":
            d = s.stopMinecraft()
            d.addCallback(stopped)

        return server.NOT_DONE_YET
Ejemplo n.º 2
0
    def render_POST(self, request):

        def started(result):
            request.finish()

        def stopped(result):
            request.finish()

        data = json.loads(request.content.getvalue())
        action = data.get("action", None)

        s = supervisor.get()

        if action is None:
             return resource.ErrorPage(http.BAD_REQUEST,
                                       http.RESPONSES[http.BAD_REQUEST],
                                       "action required")

        elif action.lower() == "start":
            d = s.startMinecraft(jar=settings.config["minecraft"]["jar"],
                                 path=settings.config["minecraft"]["home"])
            d.addCallback(started)

        elif action.lower() == "stop":
            d = s.stopMinecraft()
            d.addCallback(stopped)

        return server.NOT_DONE_YET
Ejemplo n.º 3
0
    def render_GET(self, request):
        def backup():
            def done(_):
                request.finish()

            path = os.path.join(settings.config["minecraft"]["path"],
                                self.world)

            # Punt on sending the right encoding
            request.setHeader("content-type",
                              "application/octet-stream")
            request.setHeader("content-disposition",
                              "attachemnt;filename=%s" % self.file)
            backup = backup.backup(path, type, done)
            request.registerProducer(backup, True)

        def saveAll(result):
            if not result["success"]:
                requst.finish()

            backup()

        def saveOff(result):
            if not result["success"]:
                request.finish()

            d = supervisor.get().getMinecraftProto().saveAll()
            d.addCallback(saveAll)

        if not backup.isKnownType(self.type):
            return ''

        if supervisor.get().minecraftRunning():
            d = supervisor.get().getMinecraftProto().saveOff()
            d.addCallback(saveOff)
        else:
            backup()

        return server.NOT_DONE_YET
Ejemplo n.º 4
0
    def render_GET(self, request):
        def backup():
            def done(_):
                request.finish()

            path = os.path.join(settings.config["minecraft"]["path"],
                                self.world)

            # Punt on sending the right encoding
            request.setHeader("content-type", "application/octet-stream")
            request.setHeader("content-disposition",
                              "attachemnt;filename=%s" % self.file)
            backup = backup.backup(path, type, done)
            request.registerProducer(backup, True)

        def saveAll(result):
            if not result["success"]:
                requst.finish()

            backup()

        def saveOff(result):
            if not result["success"]:
                request.finish()

            d = supervisor.get().getMinecraftProto().saveAll()
            d.addCallback(saveAll)

        if not backup.isKnownType(self.type):
            return ''

        if supervisor.get().minecraftRunning():
            d = supervisor.get().getMinecraftProto().saveOff()
            d.addCallback(saveOff)
        else:
            backup()

        return server.NOT_DONE_YET
Ejemplo n.º 5
0
    def makeService(self, options):
        settings.loadConfig(options["file"])

        svc = service.MultiService()

        checker = PublicKeyCredentialsChecker(pubAuthKeys)

        from shaft import supervisor 
        s = supervisor.get()

        # We don't start by default since this will be triggered by web
        #s.startMinecraft(jar=settings.config["minecraft"]["jar"],
        #                 path=settings.config["minecraft"]["home"])

        s.setServiceParent(svc)

        namespace = {"s": s,
                     "log": log,
                     "p": s.protocols}

        sshRealm = TerminalRealm()
        sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace)

        sshPortal = portal.Portal(sshRealm, [checker])
        sshFactory = ConchFactory(sshPortal)
        sshService = strports.service(str(settings.config["ssh"]["port"]),
                                      sshFactory)
        sshService.setServiceParent(svc)

        site = server.Site(web.getRoot(),
                           logPath=settings.config["web"]["log"])

        if int(settings.config["web"]["port"]) != 0:
            siteService = strports.service(settings.config["web"]["port"],
                                           site)
            siteService.setServiceParent(svc)

        return svc
Ejemplo n.º 6
0
    def makeService(self, options):
        settings.loadConfig(options["file"])

        svc = service.MultiService()

        checker = PublicKeyCredentialsChecker(pubAuthKeys)

        from shaft import supervisor
        s = supervisor.get()

        # We don't start by default since this will be triggered by web
        #s.startMinecraft(jar=settings.config["minecraft"]["jar"],
        #                 path=settings.config["minecraft"]["home"])

        s.setServiceParent(svc)

        namespace = {"s": s, "log": log, "p": s.protocols}

        sshRealm = TerminalRealm()
        sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace)

        sshPortal = portal.Portal(sshRealm, [checker])
        sshFactory = ConchFactory(sshPortal)
        sshService = strports.service(str(settings.config["ssh"]["port"]),
                                      sshFactory)
        sshService.setServiceParent(svc)

        site = server.Site(web.getRoot(),
                           logPath=settings.config["web"]["log"])

        if int(settings.config["web"]["port"]) != 0:
            siteService = strports.service(settings.config["web"]["port"],
                                           site)
            siteService.setServiceParent(svc)

        return svc
Ejemplo n.º 7
0
        def saveOff(result):
            if not result["success"]:
                request.finish()

            d = supervisor.get().getMinecraftProto().saveAll()
            d.addCallback(saveAll)
Ejemplo n.º 8
0
        def saveOff(result):
            if not result["success"]:
                request.finish()

            d = supervisor.get().getMinecraftProto().saveAll()
            d.addCallback(saveAll)