Compare commits

..

No commits in common. "patch-3" and "master" have entirely different histories.

8 changed files with 103 additions and 149 deletions

View File

@ -4,4 +4,5 @@ def zingonify(d):
:param d: input dict :param d: input dict
:return: zingonified dict as str :return: zingonified dict as str
""" """
return "|".join(f"{k}:{v}" for k, v in d.items()) return "|".join(f"{k}:{v}" for k, v in d.items())

View File

@ -36,11 +36,7 @@ class handler(requestsManager.asyncRequestHandler):
username = self.get_argument("u") username = self.get_argument("u")
password = self.get_argument("h") password = self.get_argument("h")
replayID = self.get_argument("c") replayID = self.get_argument("c")
s = rxscore.score()
isRelaxing = False
if int(replayID) < 500000000:
isRelaxing = True
# Login check # Login check
userID = userUtils.getID(username) userID = userUtils.getID(username)
if userID == 0: if userID == 0:
@ -50,12 +46,19 @@ class handler(requestsManager.asyncRequestHandler):
if userUtils.check2FA(userID, ip): if userUtils.check2FA(userID, ip):
raise exceptions.need2FAException(MODULE_NAME, username, ip) raise exceptions.need2FAException(MODULE_NAME, username, ip)
replayData = glob.db.fetch("SELECT scores{relax}.*, users.username AS uname FROM scores{relax} LEFT JOIN users ON scores{relax}.userid = users.id WHERE scores{relax}.id = %s".format(relax="_relax" if isRelaxing else ""), [replayID]) # Get user ID
if bool(s.mods & 128): # Relax
# Increment 'replays watched by others' if needed replayData = glob.db.fetch("SELECT scores_relax.*, users.username AS uname FROM scores_relax LEFT JOIN users ON scores_relax.userid = users.id WHERE scores_relax.id = %s", [replayID])
if replayData is not None: # Increment 'replays watched by others' if needed
if username != replayData["uname"]: if replayData is not None:
userUtils.incrementReplaysWatched(replayData["userid"], replayData["play_mode"], replayData["mods"]) if username != replayData["uname"]:
userUtils.incrementReplaysWatched(replayData["userid"], replayData["play_mode"], s.mods)
else:
replayData = glob.db.fetch("SELECT scores.*, users.username AS uname FROM scores LEFT JOIN users ON scores.userid = users.id WHERE scores.id = %s", [replayID])
# Increment 'replays watched by others' if needed
if replayData is not None:
if username != replayData["uname"]:
userUtils.incrementReplaysWatched(replayData["userid"], replayData["play_mode"], s.mods)
log.info("Serving replay_{}.osr".format(replayID)) log.info("Serving replay_{}.osr".format(replayID))
fileName = ".data/replays/replay_{}.osr".format(replayID) fileName = ".data/replays/replay_{}.osr".format(replayID)

View File

@ -83,8 +83,11 @@ class handler(requestsManager.asyncRequestHandler):
friends = True friends = True
# Console output # Console output
fileNameShort = fileName[:48]+"..." if len(fileName) > 48 else fileName[:-4] fileNameShort = fileName[:32]+"..." if len(fileName) > 32 else fileName[:-4]
log.info("[{}] Requested beatmap {}".format("RELAX" if scoreboardType == 1 and int(self.get_argument("mods")) & 128 else "VANILLA", fileNameShort)) if scoreboardType == 1 and int(self.get_argument("mods")) & 128:
log.info("[RELAX] Requested beatmap {} ({})".format(fileNameShort, md5))
else:
log.info("[VANILLA] Requested beatmap {} ({})".format(fileNameShort, md5))
# Create beatmap object and set its data # Create beatmap object and set its data
bmap = beatmap.beatmap(md5, beatmapSetID, gameMode) bmap = beatmap.beatmap(md5, beatmapSetID, gameMode)

View File

@ -111,12 +111,13 @@ class handler(requestsManager.asyncRequestHandler):
# Get restricted # Get restricted
restricted = userUtils.isRestricted(userID) restricted = userUtils.isRestricted(userID)
# Get variables for relax # Get variables for relax
used_mods = int(scoreData[13]) used_mods = int(scoreData[13])
isRelaxing = used_mods & 128 isRelaxing = used_mods & 128
# Create score object and set its data # Create score object and set its data
log.info("[{}] {} has submitted a score on {}...".format("RELAX" if isRelaxing else "VANILLA", username, scoreData[0]))
s = rxscore.score() if isRelaxing else score.score() s = rxscore.score() if isRelaxing else score.score()
s.setDataFromScoreData(scoreData) s.setDataFromScoreData(scoreData)
@ -140,13 +141,10 @@ class handler(requestsManager.asyncRequestHandler):
# increment user playtime # increment user playtime
length = 0 length = 0
if s.passed: if s.passed:
try: length = userUtils.getBeatmapTime(beatmapInfo.beatmapID)
length = userUtils.getBeatmapTime(beatmapInfo.beatmapID)
except Exception:
log.error("Error while contacting mirror server.")
else: else:
length = math.ceil(int(self.get_argument("ft")) / 1000) length = math.ceil(int(self.get_argument("ft")) / 1000)
userUtils.incrementPlaytime(userID, s.gameMode, length) userUtils.incrementPlaytime(userID, s.gameMode, length)
# Calculate PP # Calculate PP
midPPCalcException = None midPPCalcException = None
@ -161,51 +159,51 @@ class handler(requestsManager.asyncRequestHandler):
log.error("Caught an exception in pp calculation, re-raising after saving score in db") log.error("Caught an exception in pp calculation, re-raising after saving score in db")
s.pp = 0 s.pp = 0
midPPCalcException = e midPPCalcException = e
# Restrict obvious cheaters™ # Restrict obvious cheaters™
if restricted == False: if restricted == False:
if isRelaxing: # Relax if isRelaxing: # Relax
rxGods = [7340, 2137, 6868, 1215, 15066, 14522, 1325, 5798, 21610, 1254, 15070, 3445, 17157, 14791, 14728, 1366, 2961, 5524, 1188, 1401, 26754, 3388, 5692, 2173, 4299] # Yea yea it's a bad way of doing it; will fix. rxGods = [7340, 2137, 6868, 1215, 15066, 14522, 1325, 5798, 21610, 1254, 15070, 3445, 17157, 14791, 14728] # Yea yea it's a bad way of doing it, kill yourself - cmyui osu gaming
""" """
CTBLIST = [] CTBLIST = []
TAIKOLIST = [] TAIKOLIST = []
""" """
if s.gameMode == gameModes.STD and userID not in rxGods: if (s.pp >= 1200 and s.gameMode == gameModes.STD and used_mods & 1024) and userID not in rxGods:
if (s.pp >= 1100) and used_mods & 1024 and userID != 17547: # MBMasher plays too much FL; make him an exception just incase.
userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!] Restricted due to too high pp gain with FLASHLIGHT ({}pp).".format(s.pp))
log.warning("[osu!] **{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**.".format(username, userID, s.pp), "cm")
elif (s.pp >= 1600):
userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!] Restricted due to too high pp gain ({}pp).".format(s.pp))
log.warning("[osu!] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm")
elif (s.pp >= 1000) and s.gameMode == gameModes.TAIKO:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!taiko] Restricted due to too high pp gain ({}pp).".format(s.pp)) userUtils.appendNotes(userID, "Restricted due to too high pp gain with FLASHLIGHT ({}pp)".format(s.pp))
log.warning("[osu!taiko] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm") log.warning("**{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**".format(username, userID, s.pp), "cm")
elif (s.pp >= 1350) and s.gameMode == gameModes.CTB: elif (s.pp >= 2000 and s.gameMode == gameModes.STD) and userID not in rxGods:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!catch] Restricted due to too high pp gain ({}pp).".format(s.pp)) userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp))
log.warning("[osu!catch] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm") log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm")
else: # Vanilla
if s.gameMode == gameModes.STD:
if (s.pp >= 500) and used_mods & 1024:
userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!] Restricted due to too high pp gain with FLASHLIGHT ({}pp).".format(s.pp))
log.warning("[osu!] **{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**.".format(username, userID, s.pp), "cm")
elif (s.pp >= 700):
userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!] Restricted due to too high pp gain ({}pp).".format(s.pp))
log.warning("[osu!] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm")
""" """
elif (s.pp >= 10000) and s.gameMode == gameModes.TAIKO: elif (s.pp >= 10000 and s.gameMode == gameModes.TAIKO) and userID not in TAIKOLIST:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!taiko] Restricted due to too high pp gain ({}pp).".format(s.pp)) userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp))
log.warning("[osu!taiko] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm") log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm")
elif s.pp >= 10000) and (s.gameMode == gameModes.CTB: elif s.pp >= 10000 and (s.gameMode == gameModes.CTB) and userID not in CTBLIST:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!catch] Restricted due to too high pp gain ({}pp).".format(s.pp)) userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp))
log.warning("[osu!catch] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm") log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm")
"""
else: # Vanilla
if (s.pp >= 500 and s.gameMode == gameModes.STD and used_mods & 1024):
userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain with FLASHLIGHT ({}pp)".format(s.pp))
log.warning("**{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**".format(username, userID, s.pp), "cm")
elif (s.pp >= 700 and s.gameMode == gameModes.STD):
userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp))
log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm")
"""
elif (s.pp >= 10000 and s.gameMode == gameModes.TAIKO):
userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp))
log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm")
elif s.pp >= 10000 and (s.gameMode == gameModes.CTB):
userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp))
log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm")
""" """
# Check notepad hack # Check notepad hack
@ -232,6 +230,7 @@ class handler(requestsManager.asyncRequestHandler):
oldPersonalBestRank = 0 oldPersonalBestRank = 0
oldPersonalBest = None oldPersonalBest = None
# Save score in db # Save score in db
s.saveScoreInDB() s.saveScoreInDB()
@ -239,23 +238,22 @@ class handler(requestsManager.asyncRequestHandler):
haxFlags = scoreData[17].count(' ') # 4 is normal, 0 is irregular but inconsistent. haxFlags = scoreData[17].count(' ') # 4 is normal, 0 is irregular but inconsistent.
if haxFlags != 4 and haxFlags != 0 and s.completed > 1 and restricted == False: if haxFlags != 4 and haxFlags != 0 and s.completed > 1 and restricted == False:
flagsReadable = generalUtils.calculateFlags(int(haxFlags), used_mods, s.gameMode) flagsReadable = generalUtils.calculateFlags(haxFlags, used_mods, s.gameMode)
if len(flagsReadable) > 1: userUtils.appendNotes(userID, "-- has received clientside flags: {} [{}] (cheated score id: {})".format(haxFlags, flagsReadable, s.scoreID))
userUtils.appendNotes(userID, "-- has received clientside flags: {} [{}] (cheated score id: {})".format(haxFlags, flagsReadable, s.scoreID)) log.warning("**{}** ({}) has received clientside anti cheat flags.\n\nFlags: {}.\n[{}]\n\nScore ID: {scoreID}\nReplay: https://akatsuki.pw/web/replays/{scoreID}".format(username, userID, haxFlags, flagsReadable, scoreID=s.scoreID), "cm")
log.warning("**{}** (https://akatsuki.pw/{relax}u/{}) has received clientside anti cheat flags.\n\nFlags: {}.\n[{}]\n\nScore ID: {scoreID}\nReplay: https://akatsuki.pw/web/replays/{scoreID}".format(username, userID, haxFlags, flagsReadable, scoreID=s.scoreID, relax="rx/" if isRelaxing else ""), "cm")
if s.score < 0 or s.score > (2 ** 63) - 1: if s.score < 0 or s.score > (2 ** 63) - 1:
userUtils.ban(userID) userUtils.ban(userID)
userUtils.appendNotes(userID, "Banned due to negative score.") userUtils.appendNotes(userID, "Banned due to negative score.")
if s.completed == 3: # just incase :)! if s.passed: # just incase :)!
if (s.score - (s.c300 * 300 + s.c100 * 100 + s.c50 * 50)) < 0 and not isRelaxing and s.gameMode == 0: if (s.score - (s.c300 * 300 + s.c100 * 100 + s.c50 * 50)) < 0 and not isRelaxing:
#userUtils.ban(userID) #userUtils.ban(userID)
#userUtils.appendNotes(userID, "Banned due to score being less than no-combo value.") #userUtils.appendNotes(userID, "Banned due to score being less than no-combo value.")
log.cmyui("{} (https://akatsuki.pw/{relax}u/{}) has submitted a score where score is less than no-combo value. (scoreID: {}, score: {}, pp:{})".format(username, userID, s.scoreID, s.score, s.pp, relax="rx/" if isRelaxing else ""), discord="cm") log.cmyui("{} has submitted a score where score is less than no-combo value. (scoreID: {}, score: {}, pp:{})".format(username, s.scoreID, s.score, s.pp), discord="cm")
if s.fullCombo and s.cMiss > 0: if s.fullCombo and s.cMiss > 0:
log.cmyui("{} (https://akatsuki.pw/{relax}u/{}) has submitted a score with 'fullCombo' flag, but has > 0 misses. (scoreID: {}, score: {}, pp:{})".format(username, userID, s.scoreID, s.score, s.pp, relax="rx/" if isRelaxing else ""), discord="cm") log.cmyui("{} has submitted a score with 'fullCombo' flag, but has > 0 misses. (scoreID: {}, score: {}, pp:{})".format(username, s.scoreID, s.score, s.pp), discord="cm")
# Make sure the score is not memed # Make sure the score is not memed
if s.gameMode == gameModes.MANIA and s.score > 1000000: if s.gameMode == gameModes.MANIA and s.score > 1000000:
@ -265,7 +263,7 @@ class handler(requestsManager.asyncRequestHandler):
# Ci metto la faccia, ci metto la testa e ci metto il mio cuore # Ci metto la faccia, ci metto la testa e ci metto il mio cuore
if ((s.mods & mods.DOUBLETIME) > 0 and (s.mods & mods.HALFTIME) > 0) \ if ((s.mods & mods.DOUBLETIME) > 0 and (s.mods & mods.HALFTIME) > 0) \
or ((s.mods & mods.HARDROCK) > 0 and (s.mods & mods.EASY) > 0) \ or ((s.mods & mods.HARDROCK) > 0 and (s.mods & mods.EASY) > 0) \
or ((s.mods & mods.SUDDENDEATH) > 0 and (s.mods & mods.NOFAIL) > 0) \ or ((s.mods & mods.SUDDENDEATH) > 0 and (s.mods & mods.NOFAIL) > 0)\
or ((s.mods & mods.RELAX) > 0 and (s.mods & mods.RELAX2) > 0): or ((s.mods & mods.RELAX) > 0 and (s.mods & mods.RELAX2) > 0):
userUtils.ban(userID) userUtils.ban(userID)
userUtils.appendNotes(userID, "Impossible mod combination ({}).".format(s.mods)) userUtils.appendNotes(userID, "Impossible mod combination ({}).".format(s.mods))
@ -329,11 +327,6 @@ class handler(requestsManager.asyncRequestHandler):
# Update beatmap playcount (and passcount) # Update beatmap playcount (and passcount)
beatmap.incrementPlaycount(s.fileMd5, s.passed) beatmap.incrementPlaycount(s.fileMd5, s.passed)
# Print out score submission
songNameFull = beatmapInfo.songName.encode().decode("ASCII", "ignore")
songNameShort = songNameFull[:48]+"..." if len(songNameFull) > 48 else songNameFull[:-4]
log.info("[{}] {} has submitted a score on {}...".format("RELAX" if isRelaxing else "VANILLA", username, songNameShort))
# Let the api know of this score # Let the api know of this score
if s.scoreID: if s.scoreID:
glob.redis.publish("api:score_submission", s.scoreID) glob.redis.publish("api:score_submission", s.scoreID)
@ -354,6 +347,7 @@ class handler(requestsManager.asyncRequestHandler):
oldUserData = glob.userStatsCache.get(userID, s.gameMode) oldUserData = glob.userStatsCache.get(userID, s.gameMode)
oldRank = userUtils.getGameRank(userID, s.gameMode) oldRank = userUtils.getGameRank(userID, s.gameMode)
# Always update users stats (total/ranked score, playcount, level, acc and pp) # Always update users stats (total/ranked score, playcount, level, acc and pp)
# even if not passed # even if not passed
@ -407,6 +401,7 @@ class handler(requestsManager.asyncRequestHandler):
if beatmapInfo is not None and beatmapInfo != False and s.passed: if beatmapInfo is not None and beatmapInfo != False and s.passed:
log.debug("Started building ranking panel.") log.debug("Started building ranking panel.")
if isRelaxing: # Relax if isRelaxing: # Relax
# Trigger bancho stats cache update # Trigger bancho stats cache update
glob.redis.publish("peppy:update_rxcached_stats", userID) glob.redis.publish("peppy:update_rxcached_stats", userID)
@ -502,7 +497,6 @@ class handler(requestsManager.asyncRequestHandler):
params = urlencode({"k": glob.conf.config["server"]["apikey"], "to": "#announce", "msg": annmsg}) params = urlencode({"k": glob.conf.config["server"]["apikey"], "to": "#announce", "msg": annmsg})
requests.get("{}/api/v1/fokabotMessage?{}".format(glob.conf.config["server"]["banchourl"], params)) requests.get("{}/api/v1/fokabotMessage?{}".format(glob.conf.config["server"]["banchourl"], params))
# Add the #1 to the database. Yes this is spaghetti.
scoreUtils.newFirst(s.scoreID, userID, s.fileMd5, s.gameMode, isRelaxing) scoreUtils.newFirst(s.scoreID, userID, s.fileMd5, s.gameMode, isRelaxing)
# Write message to client # Write message to client

View File

@ -55,11 +55,7 @@ class scoreboard:
friends = "AND (scores_relax.userid IN (SELECT user2 FROM users_relationships WHERE user1 = %(userid)s) OR scores_relax.userid = %(userid)s)" friends = "AND (scores_relax.userid IN (SELECT user2 FROM users_relationships WHERE user1 = %(userid)s) OR scores_relax.userid = %(userid)s)"
# Sort and limit at the end # Sort and limit at the end
if self.beatmap.rankedStatus == rankedStatuses.LOVED: order = "ORDER BY pp DESC"
order = "ORDER BY score DESC"
else:
order = "ORDER BY pp DESC"
limit = "LIMIT 1" limit = "LIMIT 1"
# Build query, get params and run query # Build query, get params and run query
@ -113,7 +109,7 @@ class scoreboard:
country = "" country = ""
# Mods ranking (ignore auto, since we use it for pp sorting) # Mods ranking (ignore auto, since we use it for pp sorting)
if self.mods > -1: if self.mods > -1 and self.mods & modsEnum.AUTOPLAY == 0:
mods = "AND scores_relax.mods = %(mods)s" mods = "AND scores_relax.mods = %(mods)s"
else: else:
mods = "" mods = ""
@ -208,28 +204,24 @@ class scoreboard:
# We have a score, run the huge query # We have a score, run the huge query
# Base query # Base query
query = """SELECT COUNT(*) AS rank FROM scores_relax STRAIGHT_JOIN users ON scores_relax.userid = users.id STRAIGHT_JOIN users_stats ON users.id = users_stats.id WHERE scores_relax.{PPorScore} >= (
SELECT {PPorScore} FROM scores_relax WHERE beatmap_md5 = %(md5)s AND play_mode = %(mode)s AND completed = 3 AND userid = %(userid)s LIMIT 1 overwrite = "pp"
) AND scores_relax.beatmap_md5 = %(md5)s AND scores_relax.play_mode = %(mode)s AND scores_relax.completed = 3 AND users.privileges & 1 > 0""".format(PPorScore="score" if self.beatmap.rankedStatus == rankedStatuses.LOVED else "pp") # We have a score, run the huge query
# Base query
query = """SELECT COUNT(*) AS rank FROM scores_relax STRAIGHT_JOIN users ON scores_relax.userid = users.id STRAIGHT_JOIN users_stats ON users.id = users_stats.id WHERE scores_relax.{0} >= (
SELECT {0} FROM scores_relax WHERE beatmap_md5 = %(md5)s AND play_mode = %(mode)s AND completed = 3 AND userid = %(userid)s LIMIT 1
) AND scores_relax.beatmap_md5 = %(md5)s AND scores_relax.play_mode = %(mode)s AND scores_relax.completed = 3 AND users.privileges & 1 > 0""".format(overwrite)
# Country # Country
if self.country: if self.country:
query += " AND users_stats.country = (SELECT country FROM users_stats WHERE id = %(userid)s LIMIT 1)" query += " AND users_stats.country = (SELECT country FROM users_stats WHERE id = %(userid)s LIMIT 1)"
# Mods # Mods
if self.mods > -1: if self.mods > -1:
query += " AND scores_relax.mods = %(mods)s" query += " AND scores_relax.mods = %(mods)s"
# Friends # Friends
if self.friends: if self.friends:
query += " AND (scores_relax.userid IN (SELECT user2 FROM users_relationships WHERE user1 = %(userid)s) OR scores_relax.userid = %(userid)s)" query += " AND (scores_relax.userid IN (SELECT user2 FROM users_relationships WHERE user1 = %(userid)s) OR scores_relax.userid = %(userid)s)"
# Sort and limit at the end # Sort and limit at the end
if self.beatmap.rankedStatus == rankedStatuses.LOVED: query += " ORDER BY pp DESC LIMIT 1".format(overwrite)
query += " ORDER BY score DESC LIMIT 1"
else:
query += " ORDER BY pp DESC LIMIT 1"
result = glob.db.fetch(query, {"md5": self.beatmap.fileMD5, "userid": self.userID, "mode": self.gameMode, "mods": self.mods}) result = glob.db.fetch(query, {"md5": self.beatmap.fileMD5, "userid": self.userID, "mode": self.gameMode, "mods": self.mods})
if result is not None: if result is not None:
self.personalBestRank = result["rank"] self.personalBestRank = result["rank"]
@ -249,10 +241,10 @@ class scoreboard:
# Set personal best score rank # Set personal best score rank
self.setPersonalBestRank() # sets self.personalBestRank with the huge query self.setPersonalBestRank() # sets self.personalBestRank with the huge query
self.scores[0].rank = self.personalBestRank self.scores[0].rank = self.personalBestRank
data += self.scores[0].getData() data += self.scores[0].getData(pp=True)
# Output top 50 scores # Output top 50 scores
for i in self.scores[1:]: for i in self.scores[1:]:
data += i.getData(pp=self.beatmap.rankedStatus != rankedStatuses.LOVED) data += i.getData(pp=True)
return data return data

View File

@ -206,16 +206,11 @@ class score:
self.rank, self.rank,
self.date) self.date)
def setCompletedStatus(self, b = None): def setCompletedStatus(self):
""" """
Set this score completed status and rankedScoreIncrease Set this score completed status and rankedScoreIncrease
""" """
self.completed = 0 self.completed = 0
# Create beatmap object
if b is None:
b = beatmap.beatmap(self.fileMd5, 0)
if self.passed == True and scoreUtils.isRankable(self.mods): if self.passed == True and scoreUtils.isRankable(self.mods):
# Get userID # Get userID
userID = userUtils.getID(self.playerName) userID = userUtils.getID(self.playerName)
@ -237,28 +232,17 @@ class score:
self.oldPersonalBest = 0 self.oldPersonalBest = 0
else: else:
# Compare personal best's score with current score # Compare personal best's score with current score
if b.rankedStatus == rankedStatuses.RANKED: if self.pp > personalBest["pp"]:
if self.pp > personalBest["pp"]: # New best score
# New best score self.completed = 3
self.completed = 3 self.rankedScoreIncrease = self.score-personalBest["score"]
self.rankedScoreIncrease = self.score-personalBest["score"] self.oldPersonalBest = personalBest["id"]
self.oldPersonalBest = personalBest["id"] else:
else: self.completed = 2
self.completed = 2 self.rankedScoreIncrease = 0
self.rankedScoreIncrease = 0 self.oldPersonalBest = 0
self.oldPersonalBest = 0
elif b.rankedStatus == rankedStatuses.LOVED:
if self.score > personalBest["score"]:
# New best score
self.completed = 3
self.rankedScoreIncrease = self.score-personalBest["score"]
self.oldPersonalBest = personalBest["id"]
else:
self.completed = 2
self.rankedScoreIncrease = 0
self.oldPersonalBest = 0
#log.info("Completed status: {}".format(self.completed)) log.info("Completed status: {}".format(self.completed))
def saveScoreInDB(self): def saveScoreInDB(self):
""" """

View File

@ -205,16 +205,11 @@ class score:
self.rank, self.rank,
self.date) self.date)
def setCompletedStatus(self, b = None): def setCompletedStatus(self):
""" """
Set this score completed status and rankedScoreIncrease Set this score completed status and rankedScoreIncrease
""" """
self.completed = 0 self.completed = 0
# Create beatmap object
if b is None:
b = beatmap.beatmap(self.fileMd5, 0)
if self.passed == True and scoreUtils.isRankable(self.mods): if self.passed == True and scoreUtils.isRankable(self.mods):
# Get userID # Get userID
userID = userUtils.getID(self.playerName) userID = userUtils.getID(self.playerName)
@ -236,31 +231,17 @@ class score:
self.oldPersonalBest = 0 self.oldPersonalBest = 0
else: else:
# Compare personal best's score with current score # Compare personal best's score with current score
if b.rankedStatus == rankedStatuses.RANKED: if self.pp > personalBest["pp"]:
# New best score
self.completed = 3 self.completed = 3
self.calculatePP() self.rankedScoreIncrease = self.score-personalBest["score"]
if self.pp > personalBest["pp"]: self.oldPersonalBest = personalBest["id"]
# New best score else:
self.completed = 3 self.completed = 2
self.rankedScoreIncrease = self.score-personalBest["score"] self.rankedScoreIncrease = 0
self.oldPersonalBest = personalBest["id"] self.oldPersonalBest = 0
else:
self.completed = 2
self.rankedScoreIncrease = 0
self.oldPersonalBest = 0
elif b.rankedStatus == rankedStatuses.LOVED:
if self.score > personalBest["score"]:
# New best score
self.completed = 3
self.rankedScoreIncrease = self.score-personalBest["score"]
self.oldPersonalBest = personalBest["id"]
else:
self.completed = 2
self.rankedScoreIncrease = 0
self.oldPersonalBest = 0
self.completed = 3
#log.info("Completed status: {}".format(self.completed)) log.info("Completed status: {}".format(self.completed))
def saveScoreInDB(self): def saveScoreInDB(self):
""" """

View File

@ -109,7 +109,7 @@ class scoreboard:
country = "" country = ""
# Mods ranking (ignore auto, since we use it for pp sorting) # Mods ranking (ignore auto, since we use it for pp sorting)
if self.mods > -1: if self.mods > -1 and self.mods & modsEnum.AUTOPLAY == 0:
mods = "AND scores.mods = %(mods)s" mods = "AND scores.mods = %(mods)s"
else: else:
mods = "" mods = ""
@ -204,19 +204,15 @@ class scoreboard:
query = """SELECT COUNT(*) AS rank FROM scores STRAIGHT_JOIN users ON scores.userid = users.id STRAIGHT_JOIN users_stats ON users.id = users_stats.id WHERE scores.score >= ( query = """SELECT COUNT(*) AS rank FROM scores STRAIGHT_JOIN users ON scores.userid = users.id STRAIGHT_JOIN users_stats ON users.id = users_stats.id WHERE scores.score >= (
SELECT score FROM scores WHERE beatmap_md5 = %(md5)s AND play_mode = %(mode)s AND completed = 3 AND userid = %(userid)s LIMIT 1 SELECT score FROM scores WHERE beatmap_md5 = %(md5)s AND play_mode = %(mode)s AND completed = 3 AND userid = %(userid)s LIMIT 1
) AND scores.beatmap_md5 = %(md5)s AND scores.play_mode = %(mode)s AND scores.completed = 3 AND users.privileges & 1 > 0""" ) AND scores.beatmap_md5 = %(md5)s AND scores.play_mode = %(mode)s AND scores.completed = 3 AND users.privileges & 1 > 0"""
# Country # Country
if self.country: if self.country:
query += " AND users_stats.country = (SELECT country FROM users_stats WHERE id = %(userid)s LIMIT 1)" query += " AND users_stats.country = (SELECT country FROM users_stats WHERE id = %(userid)s LIMIT 1)"
# Mods # Mods
if self.mods > -1: if self.mods > -1:
query += " AND scores.mods = %(mods)s" query += " AND scores.mods = %(mods)s"
# Friends # Friends
if self.friends: if self.friends:
query += " AND (scores.userid IN (SELECT user2 FROM users_relationships WHERE user1 = %(userid)s) OR scores.userid = %(userid)s)" query += " AND (scores.userid IN (SELECT user2 FROM users_relationships WHERE user1 = %(userid)s) OR scores.userid = %(userid)s)"
# Sort and limit at the end # Sort and limit at the end
query += " ORDER BY score DESC LIMIT 1" query += " ORDER BY score DESC LIMIT 1"
result = glob.db.fetch(query, {"md5": self.beatmap.fileMD5, "userid": self.userID, "mode": self.gameMode, "mods": self.mods}) result = glob.db.fetch(query, {"md5": self.beatmap.fileMD5, "userid": self.userID, "mode": self.gameMode, "mods": self.mods})
@ -242,6 +238,6 @@ class scoreboard:
# Output top 50 scores # Output top 50 scores
for i in self.scores[1:]: for i in self.scores[1:]:
data += i.getData(pp=self.mods > -1) data += i.getData(pp=self.mods > -1 and self.mods & modsEnum.AUTOPLAY > 0)
return data return data