def asyncGet(self, screenshotID=None):
        try:
            # Make sure the screenshot exists
            if screenshotID is None or not os.path.isfile("{}/{}".format(
                    glob.conf.config["server"]["screenshotspath"],
                    screenshotID)):
                raise exceptions.fileNotFoundException(MODULE_NAME,
                                                       screenshotID)

            # Read screenshot
            with open(
                    "{}/{}".format(
                        glob.conf.config["server"]["screenshotspath"],
                        screenshotID), "rb") as f:
                data = f.read()

            # Output
            log.info("Served screenshot {}".format(screenshotID))

            # Display screenshot
            self.write(data)
            self.set_header("Content-type", "image/jpg")
            self.set_header("Content-length", len(data))
        except exceptions.fileNotFoundException:
            self.set_status(404)
    def asyncGet(self, replayID):
        try:
            #try to found vanilla replay

            try:
                fullReplay = replayHelper.buildFullReplay(scoreID=replayID)
            except (exceptions.fileNotFoundException,
                    exceptions.scoreNotFoundError):
                #try found relax replay (yes, try, try, try)
                try:
                    fullReplay = replayHelperRelax.buildFullReplay(
                        scoreID=replayID)
                except (exceptions.fileNotFoundException,
                        exceptions.scoreNotFoundError):
                    try:
                        fullReplay = replayHelperAuto.buildFullReplay(
                            scoreID=replayID)
                    except (exceptions.fileNotFoundException,
                            exceptions.scoreNotFoundError):
                        raise exceptions.fileNotFoundException(
                            MODULE_NAME, None)
            self.write(fullReplay)
            self.add_header("Content-type", "application/octet-stream")
            self.set_header("Content-length", len(fullReplay))
            self.set_header("Content-Description", "File Transfer")
            self.set_header("Content-Disposition",
                            "attachment; filename=\"{}.osr\"".format(replayID))
        except (exceptions.fileNotFoundException,
                exceptions.scoreNotFoundError):
            self.write("Replay not found")
Exemple #3
0
    def asyncGet(self, errorID):
        try:
            # Find the file
            fileName = ".data/clienterrors/{}.json".format(errorID)
            if not os.path.isfile(fileName):
                raise exceptions.fileNotFoundException(MODULE_NAME, fileName)

            # Read and json loads error file
            with open(fileName, "rb") as f:
                data = json.loads(f.read())

            # Write to page
            self.write(json.dumps(data, indent=2, sort_keys=True))
            self.add_header("Content-type", "application/json")
        except exceptions.fileNotFoundException:
            self.write("Errorlog not found")
    def asyncGet(self, replayID):
        try:
            # Make sure the score exists
            scoreData = glob.db.fetch(
                "SELECT scores.*, users.username FROM scores LEFT JOIN users ON scores.userid = users.id WHERE scores.id = %s",
                [replayID])
            if scoreData is None:
                raise exceptions.fileNotFoundException(MODULE_NAME, replayID)

            # Make sure raw replay exists
            fileName = ".data/replays/replay_{}.osr".format(replayID)
            if not os.path.isfile(fileName):
                raise exceptions.fileNotFoundException(MODULE_NAME, fileName)

            # Read raw replay
            with open(fileName, "rb") as f:
                rawReplay = f.read()

            # Calculate missing replay data
            rank = generalUtils.getRank(int(scoreData["play_mode"]),
                                        int(scoreData["mods"]),
                                        int(scoreData["accuracy"]),
                                        int(scoreData["300_count"]),
                                        int(scoreData["100_count"]),
                                        int(scoreData["50_count"]),
                                        int(scoreData["misses_count"]))
            magicHash = generalUtils.stringMd5(
                "{}p{}o{}o{}t{}a{}r{}e{}y{}o{}u{}{}{}".format(
                    int(scoreData["100_count"]) + int(scoreData["300_count"]),
                    scoreData["50_count"], scoreData["gekis_count"],
                    scoreData["katus_count"], scoreData["misses_count"],
                    scoreData["beatmap_md5"], scoreData["max_combo"],
                    "True" if int(scoreData["full_combo"]) == 1 else "False",
                    scoreData["username"], scoreData["score"], rank,
                    scoreData["mods"], "True"))
            # Add headers (convert to full replay)
            fullReplay = binaryHelper.binaryWrite([
                [scoreData["play_mode"], dataTypes.byte],
                [20150414, dataTypes.uInt32],
                [scoreData["beatmap_md5"], dataTypes.string],
                [scoreData["username"], dataTypes.string],
                [magicHash, dataTypes.string],
                [scoreData["300_count"], dataTypes.uInt16],
                [scoreData["100_count"], dataTypes.uInt16],
                [scoreData["50_count"], dataTypes.uInt16],
                [scoreData["gekis_count"], dataTypes.uInt16],
                [scoreData["katus_count"], dataTypes.uInt16],
                [scoreData["misses_count"], dataTypes.uInt16],
                [scoreData["score"], dataTypes.uInt32],
                [scoreData["max_combo"], dataTypes.uInt16],
                [scoreData["full_combo"], dataTypes.byte],
                [scoreData["mods"], dataTypes.uInt32],
                [0, dataTypes.byte],
                [
                    int((scoreData["time"] * 10000000) + 621355968000000000),
                    dataTypes.uInt64
                ],
                [rawReplay, dataTypes.rawReplay],
                [0, dataTypes.uInt32],
                [0, dataTypes.uInt32],
            ])

            # Serve full replay
            self.write(fullReplay)
            self.add_header("Content-type", "application/octet-stream")
            self.set_header("Content-length", len(fullReplay))
            self.set_header("Content-Description", "File Transfer")
            self.set_header(
                "Content-Disposition",
                "attachment; filename=\"{}.osr\"".format(scoreData["id"]))
        except exceptions.fileNotFoundException:
            self.write("Replay not found")