def updateRanks(userID=0, score=None): if score is None and userID == 0: raise ValueError("Either score or userID must be provieded") if score is not None: userID = score.playerUserID rank = generalUtils.getRank(int(score.gameMode), int(score.mods), int(score.accuracy) * 100, int(score.c300), int(score.c100), int(score.c50), int(score.cMiss)) if score.passed and rank == 'XH': glob.db.execute( "UPDATE users_stats SET XH = XH + 1 WHERE id = {} LIMIT 1".format( userID)) if score.passed and rank == 'X': glob.db.execute( "UPDATE users_stats SET X = X + 1 WHERE id = {} LIMIT 1".format( userID)) if score.passed and rank == 'SH': glob.db.execute( "UPDATE users_stats SET SH = SH + 1 WHERE id = {} LIMIT 1".format( userID)) if score.passed and rank == 'S': glob.db.execute( "UPDATE users_stats SET S = S + 1 WHERE id = {} LIMIT 1".format( userID)) if score.passed and rank == 'A': glob.db.execute( "UPDATE users_stats SET A = A + 1 WHERE id = {} LIMIT 1".format( userID))
def buildFullReplay(scoreID=None, scoreData=None, rawReplay=None): if all(v is None for v in (scoreID, scoreData)) or all( v is not None for v in (scoreID, scoreData)): raise AttributeError( "Either scoreID or scoreData must be provided, not neither or both" ) if scoreData is None: scoreData = glob.db.fetch( "SELECT scores.*, users.username FROM scores LEFT JOIN users ON scores.userid = users.id " "WHERE scores.id = %s", [scoreID]) else: scoreID = scoreData["id"] if scoreData is None or scoreID is None: raise exceptions.scoreNotFoundError() if rawReplay is None: # Make sure raw replay exists fileName = getFirstReplayFileName(scoreID) if fileName is None: raise FileNotFoundError() # 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], [toDotTicks(int(scoreData["time"])), dataTypes.uInt64], [rawReplay, dataTypes.rawReplay], [0, dataTypes.uInt32], [0, dataTypes.uInt32], ]) # Return full replay return fullReplay
def tillerinoLast(fro, chan, message): try: # Run the command in PM only if chan.startswith("#"): return False data = glob.db.fetch( """SELECT beatmaps.song_name as sn, scores.*, beatmaps.beatmap_id as bid, beatmaps.difficulty_std, beatmaps.difficulty_taiko, beatmaps.difficulty_ctb, beatmaps.difficulty_mania, beatmaps.max_combo as fc FROM scores LEFT JOIN beatmaps ON beatmaps.beatmap_md5=scores.beatmap_md5 LEFT JOIN users ON users.id = scores.userid WHERE users.username = %s ORDER BY scores.time DESC LIMIT 1""", [fro]) if data is None: return False diffString = "difficulty_{}".format( gameModes.getGameModeForDB(data["play_mode"])) rank = generalUtils.getRank(data["play_mode"], data["mods"], data["accuracy"], data["300_count"], data["100_count"], data["50_count"], data["misses_count"]) ifPlayer = "{0} | ".format(fro) if chan != "FokaBot" else "" ifFc = " (FC)" if data["max_combo"] == data[ "fc"] else " {0}x/{1}x".format(data["max_combo"], data["fc"]) beatmapLink = "[http://osu.ppy.sh/b/{1} {0}]".format( data["sn"], data["bid"]) hasPP = data["play_mode"] == gameModes.STD or data[ "play_mode"] == gameModes.MANIA msg = ifPlayer msg += beatmapLink if data["play_mode"] != gameModes.STD: msg += " <{0}>".format( gameModes.getGameModeForPrinting(data["play_mode"])) if data["mods"]: msg += ' +' + generalUtils.readableMods(data["mods"]) if not hasPP: msg += " | {0:,}".format(data["score"]) msg += ifFc msg += " | {0:.2f}%, {1}".format(data["accuracy"], rank.upper()) msg += " {{ {0} / {1} / {2} / {3} }}".format( data["300_count"], data["100_count"], data["50_count"], data["misses_count"]) msg += " | {0:.2f} stars".format(data[diffString]) return msg msg += " ({0:.2f}%, {1})".format(data["accuracy"], rank.upper()) msg += ifFc msg += " | {0:.2f}pp".format(data["pp"]) stars = data[diffString] if data["mods"]: token = glob.tokens.getTokenFromUsername(fro) if token is None: return False userID = token.userID token.tillerino[0] = data["bid"] token.tillerino[1] = data["mods"] token.tillerino[2] = data["accuracy"] oppaiData = getPPMessage(userID, just_data=True) if "stars" in oppaiData: stars = oppaiData["stars"] msg += " | {0:.2f} stars".format(stars) return msg except Exception as a: log.error(a) return False
def buildFullReplay(scoreID=None, scoreData=None, rawReplay=None, relax=0): if all(v is None for v in (scoreID, scoreData)) or all( v is not None for v in (scoreID, scoreData)): raise AttributeError( "Either scoreID or scoreData must be provided, not neither or both" ) if scoreData is None: if features.MASTER_SCORE_TABLE: scoreData = glob.db.fetch( "SELECT s.*, users.username FROM scores_master as s LEFT JOIN users ON s.userid = users.id " "WHERE s.id = %s AND special_mode = %s", [scoreID, int(relax)]) else: scoreData = glob.db.fetch( f"SELECT s.*, users.username FROM {modeSwitches.score[relax]} as s LEFT JOIN users ON s.userid = users.id " "WHERE s.id = %s", [scoreID]) else: scoreID = scoreData["id"] if scoreData is None or scoreID is None: raise exceptions.scoreNotFoundError() if rawReplay is None: # Make sure raw replay exists fileName = "{}{}/replay_{}.osr".format( glob.conf.config["server"]["replayspath"], modeSwitches.rp_folder[relax], scoreID) if not os.path.isfile(fileName): log.error('[SM{}] Trying to open {}...'.format(relax, fileName)) raise FileNotFoundError() # 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], [generalHelper.toDotTicks(int(scoreData["time"])), dataTypes.uInt64], [rawReplay, dataTypes.rawReplay], [0, dataTypes.uInt32], [scoreData['id'], dataTypes.uInt64], ]) # Return full replay return fullReplay
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")
def buildFullReplay(scoreID=None, scoreData=None, rawReplay=None): if all(v is None for v in (scoreID, scoreData)) or all( v is not None for v in (scoreID, scoreData)): raise AttributeError( "Either scoreID or scoreData must be provided, not neither or both" ) mode = 0 # TODO: Implement better way to handle this if scoreData is None: scoreData = glob.db.fetch( "SELECT osu_scores_high.*, phpbb_users.username FROM osu_scores_high LEFT JOIN phpbb_users ON osu_scores_high.user_id = phpbb_users.user_id " "WHERE osu_scores_high.score_id = %s", [scoreID]) if scoreData is None: mode = 1 scoreData = glob.db.fetch( "SELECT osu_scores_taiko_high.*, phpbb_users.username FROM osu_scores_taiko_high LEFT JOIN phpbb_users ON osu_scores_taiko_high.user_id = phpbb_users.user_id " "WHERE osu_scores_taiko_high.score_id = %s", [scoreID]) if scoreData is None: mode = 2 scoreData = glob.db.fetch( "SELECT osu_scores_fruits_high.*, phpbb_users.username FROM osu_scores_fruits_high LEFT JOIN phpbb_users ON osu_scores_fruits_high.user_id = phpbb_users.user_id " "WHERE osu_scores_fruits_high.score_id = %s", [scoreID]) if scoreData is None: mode = 3 scoreData = glob.db.fetch( "SELECT osu_scores_mania_high.*, phpbb_users.username FROM osu_scores_mania_high LEFT JOIN phpbb_users ON osu_scores_mania_high.user_id = phpbb_users.user_id " "WHERE osu_scores_mania_high.score_id = %s", [scoreID]) else: scoreID = scoreData["id"] if scoreData is None or scoreID is None: raise exceptions.scoreNotFoundError() scoreID = int(scoreID) if rawReplay is None: rawReplay = getRawReplayS3(scoreID) # Calculate missing replay data rank = generalUtils.getRank(int(mode), int(scoreData["mods"]), int(scoreData["accuracy"]), int(scoreData["count300"]), int(scoreData["count100"]), int(scoreData["count50"]), int(scoreData["countmiss"])) checksum = glob.db.fetch( "SELECT checksum FROM osu_beatmaps WHERE beatmap_id = %s LIMIT 1", (scoreData["beatmap_id"])) magicHash = generalUtils.stringMd5( "{}p{}o{}o{}t{}a{}r{}e{}y{}o{}u{}{}{}".format( int(scoreData["count100"]) + int(scoreData["count300"]), scoreData["count50"], scoreData["countgeki"], scoreData["countkatu"], scoreData["countmiss"], checksum, scoreData["maxcombo"], "True" if int(scoreData["perfect"]) == 1 else "False", # TODO: check whether full combo or not (or "perfect" means "full combo"?) scoreData["username"], scoreData["score"], rank, scoreData["enabled_mods"], "True")) # Add headers (convert to full replay) fullReplay = binaryHelper.binaryWrite([ [mode, dataTypes.byte], [20150414, dataTypes.uInt32], [scoreData["checksum"], dataTypes.string], [scoreData["username"], dataTypes.string], [magicHash, dataTypes.string], [scoreData["count300"], dataTypes.uInt16], [scoreData["count100"], dataTypes.uInt16], [scoreData["count50"], dataTypes.uInt16], [scoreData["countgeki"], dataTypes.uInt16], [scoreData["countkatu"], dataTypes.uInt16], [scoreData["countmiss"], dataTypes.uInt16], [scoreData["score"], dataTypes.uInt32], [scoreData["maxcombo"], dataTypes.uInt16], [scoreData["perfect"], dataTypes.byte], [scoreData["enabled_mods"], dataTypes.uInt32], [0, dataTypes.byte], [toDotTicks(int(scoreData["date"])), dataTypes.uInt64], [rawReplay, dataTypes.rawReplay], [0, dataTypes.uInt32], [0, dataTypes.uInt32], ]) # Return full replay return fullReplay
if rawReplay is None: # Make sure raw replay exists fileName = "{}{}/replay_{}.osr".format( glob.conf.config["server"]["replayspath"], table_suffix, scoreID) if not os.path.isfile(fileName): raise FileNotFoundError() # 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],