Compare commits

...
This repository has been archived on 2022-02-23. You can view files and clone it, but cannot push or open issues or pull requests.

27 Commits

Author SHA1 Message Date
solis
c170addf67
need this too 2019-02-21 22:54:10 +10:30
solis
8ba7196da3
fixed pp shit for you 2019-02-21 22:50:41 +10:30
Josh Smith
cfcc17df37 wtf am i doing rofl 2019-02-18 07:10:50 -05:00
Josh Smith
e4c6543963 dsfdswf 2019-02-18 07:06:17 -05:00
Josh Smith
0abb98f2db ?????????? 2019-02-18 07:04:03 -05:00
Josh Smith
cb9bd6cb5d it seems im having a brainlet moment or 2 here 2019-02-18 07:00:33 -05:00
Josh Smith
81b44e19fe b 2019-02-18 06:58:59 -05:00
Josh Smith
6df638449f Fix loved maps overwrite on both regular and relax; comment out log for completed statuses 2019-02-18 06:57:28 -05:00
cmyui
d26270ed73 48 2019-02-16 13:49:52 -05:00
cmyui
ed45506e64 1 liner 2019-02-16 13:31:16 -05:00
cmyui
3d0fa3ac43 good old threading ruining my day part 100 2019-02-16 13:23:12 -05:00
cmyui
e0c6feefde uhhhh 2019-02-16 13:17:52 -05:00
cmyui
26c274badb clean up relax-reg 2019-02-16 13:16:22 -05:00
cmyui
2e1ce5a3de log improvements 2019-02-15 18:29:10 -05:00
cmyui
703ce1c3de "anticheat" improvements.
big "" on the "anticheat" part; more like just improving autodetection for blatants.
2019-02-15 18:02:31 -05:00
Josh Smith
5dcfdc8577 a 2019-02-13 17:42:54 -05:00
Josh Smith
d66af9dfb1 Update submitModularHandler.pyx 2019-02-13 17:27:54 -05:00
Josh Smith
1090d34d38 Update submitModularHandler.pyx 2019-02-13 17:13:19 -05:00
Josh Smith
37730c1bb1 woops 2019-02-11 13:34:32 -05:00
Josh Smith
dba93f8bb3 Fix relax replay incrementing, do not send flag webhook if len not >1 2019-02-11 13:31:24 -05:00
Josh Smith
1c6aea6729
Merge pull request #10 from depreciate/master
added rating to beatmaps
2019-02-11 11:54:59 -05:00
Josh Smith
9b83b1367f Update scoreboards 2019-02-11 08:34:59 -05:00
Josh Smith
a83af9514a
moments in gaming 2019-02-11 07:01:43 -05:00
Josh Smith
3f69038285
Create generalHelper.py 2019-02-11 06:58:16 -05:00
Josh Smith
cd08451cd2
Merge pull request #8 from depreciate/master
ddd
2019-02-11 06:53:34 -05:00
Josh Smith
90a2b8f12c
Merge pull request #7 from depreciate/master
ddLOKL
2019-02-11 06:41:15 -05:00
Josh Smith
fc5a025bf0
Merge pull request #6 from depreciate/master
scoreboard shit
2019-02-11 06:36:31 -05:00
8 changed files with 148 additions and 102 deletions

View File

@ -36,7 +36,11 @@ 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:
@ -46,19 +50,12 @@ 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)
# Get user ID 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])
if bool(s.mods & 128): # Relax
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]) # Increment 'replays watched by others' if needed
# Increment 'replays watched by others' if needed if replayData is not None:
if replayData is not None: if username != replayData["uname"]:
if username != replayData["uname"]: userUtils.incrementReplaysWatched(replayData["userid"], replayData["play_mode"], replayData["mods"])
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,11 +83,8 @@ class handler(requestsManager.asyncRequestHandler):
friends = True friends = True
# Console output # Console output
fileNameShort = fileName[:32]+"..." if len(fileName) > 32 else fileName[:-4] fileNameShort = fileName[:48]+"..." if len(fileName) > 48 else fileName[:-4]
if scoreboardType == 1 and int(self.get_argument("mods")) & 128: log.info("[{}] Requested beatmap {}".format("RELAX" if scoreboardType == 1 and int(self.get_argument("mods")) & 128 else "VANILLA", fileNameShort))
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,13 +111,12 @@ 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)
@ -141,10 +140,13 @@ class handler(requestsManager.asyncRequestHandler):
# increment user playtime # increment user playtime
length = 0 length = 0
if s.passed: if s.passed:
length = userUtils.getBeatmapTime(beatmapInfo.beatmapID) try:
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
@ -159,51 +161,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] # Yea yea it's a bad way of doing it, kill yourself - cmyui osu gaming 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.
""" """
CTBLIST = [] CTBLIST = []
TAIKOLIST = [] TAIKOLIST = []
""" """
if (s.pp >= 1200 and s.gameMode == gameModes.STD and used_mods & 1024) and userID not in rxGods: if s.gameMode == gameModes.STD 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, "Restricted due to too high pp gain with FLASHLIGHT ({}pp)".format(s.pp)) userUtils.appendNotes(userID, "[osu!taiko] Restricted due to too high pp gain ({}pp).".format(s.pp))
log.warning("**{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**".format(username, userID, s.pp), "cm") log.warning("[osu!taiko] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm")
elif (s.pp >= 2000 and s.gameMode == gameModes.STD) and userID not in rxGods: elif (s.pp >= 1350) and s.gameMode == gameModes.CTB:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp)) userUtils.appendNotes(userID, "[osu!catch] 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") log.warning("[osu!catch] **{}** ({}) 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) and userID not in TAIKOLIST:
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) and userID not in CTBLIST:
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")
"""
else: # Vanilla else: # Vanilla
if (s.pp >= 500 and s.gameMode == gameModes.STD and used_mods & 1024): if s.gameMode == gameModes.STD:
userUtils.restrict(userID) if (s.pp >= 500) and used_mods & 1024:
userUtils.appendNotes(userID, "Restricted due to too high pp gain with FLASHLIGHT ({}pp)".format(s.pp)) userUtils.restrict(userID)
log.warning("**{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**".format(username, userID, s.pp), "cm") userUtils.appendNotes(userID, "[osu!] Restricted due to too high pp gain with FLASHLIGHT ({}pp).".format(s.pp))
elif (s.pp >= 700 and s.gameMode == gameModes.STD): log.warning("[osu!] **{}** ({}) has been restricted due to too high pp gain with FLASHLIGHT **({}pp)**.".format(username, userID, s.pp), "cm")
userUtils.restrict(userID) elif (s.pp >= 700):
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp)) userUtils.restrict(userID)
log.warning("**{}** ({}) has been restricted due to too high pp gain **({}pp)**".format(username, userID, s.pp), "cm") 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:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp)) userUtils.appendNotes(userID, "[osu!taiko] 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") log.warning("[osu!taiko] **{}** ({}) 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:
userUtils.restrict(userID) userUtils.restrict(userID)
userUtils.appendNotes(userID, "Restricted due to too high pp gain ({}pp)".format(s.pp)) userUtils.appendNotes(userID, "[osu!catch] 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") log.warning("[osu!catch] **{}** ({}) has been restricted due to too high pp gain **({}pp)**.".format(username, userID, s.pp), "cm")
""" """
# Check notepad hack # Check notepad hack
@ -230,7 +232,6 @@ class handler(requestsManager.asyncRequestHandler):
oldPersonalBestRank = 0 oldPersonalBestRank = 0
oldPersonalBest = None oldPersonalBest = None
# Save score in db # Save score in db
s.saveScoreInDB() s.saveScoreInDB()
@ -238,22 +239,23 @@ 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(haxFlags, used_mods, s.gameMode) flagsReadable = generalUtils.calculateFlags(int(haxFlags), used_mods, s.gameMode)
userUtils.appendNotes(userID, "-- has received clientside flags: {} [{}] (cheated score id: {})".format(haxFlags, flagsReadable, s.scoreID)) if len(flagsReadable) > 1:
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") userUtils.appendNotes(userID, "-- has received clientside flags: {} [{}] (cheated score id: {})".format(haxFlags, flagsReadable, s.scoreID))
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.passed: # just incase :)! if s.completed == 3: # just incase :)!
if (s.score - (s.c300 * 300 + s.c100 * 100 + s.c50 * 50)) < 0 and not isRelaxing: if (s.score - (s.c300 * 300 + s.c100 * 100 + s.c50 * 50)) < 0 and not isRelaxing and s.gameMode == 0:
#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("{} 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") 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")
if s.fullCombo and s.cMiss > 0: if s.fullCombo and s.cMiss > 0:
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") 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")
# 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:
@ -263,7 +265,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))
@ -327,6 +329,11 @@ 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)
@ -347,7 +354,6 @@ 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
@ -401,7 +407,6 @@ 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)
@ -497,6 +502,7 @@ 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

@ -4,5 +4,4 @@ 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

@ -55,7 +55,11 @@ 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
order = "ORDER BY pp DESC" if self.beatmap.rankedStatus == rankedStatuses.LOVED:
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
@ -109,7 +113,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 and self.mods & modsEnum.AUTOPLAY == 0: if self.mods > -1:
mods = "AND scores_relax.mods = %(mods)s" mods = "AND scores_relax.mods = %(mods)s"
else: else:
mods = "" mods = ""
@ -204,24 +208,28 @@ 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} >= (
overwrite = "pp" SELECT {PPorScore} FROM scores_relax WHERE beatmap_md5 = %(md5)s AND play_mode = %(mode)s AND completed = 3 AND userid = %(userid)s LIMIT 1
# We have a score, run the huge query ) 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")
# 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
query += " ORDER BY pp DESC LIMIT 1".format(overwrite) if self.beatmap.rankedStatus == rankedStatuses.LOVED:
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"]
@ -241,10 +249,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(pp=True) data += self.scores[0].getData()
# Output top 50 scores # Output top 50 scores
for i in self.scores[1:]: for i in self.scores[1:]:
data += i.getData(pp=True) data += i.getData(pp=self.beatmap.rankedStatus != rankedStatuses.LOVED)
return data return data

View File

@ -206,11 +206,16 @@ class score:
self.rank, self.rank,
self.date) self.date)
def setCompletedStatus(self): def setCompletedStatus(self, b = None):
""" """
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)
@ -232,17 +237,31 @@ 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 self.pp > personalBest["pp"]: if b.rankedStatus == rankedStatuses.RANKED:
# New best score
self.completed = 3 self.completed = 3
self.rankedScoreIncrease = self.score-personalBest["score"] self.calculatePP()
self.oldPersonalBest = personalBest["id"] if self.pp > personalBest["pp"]:
else: # New best score
self.completed = 2 self.completed = 3
self.rankedScoreIncrease = 0 self.rankedScoreIncrease = self.score-personalBest["score"]
self.oldPersonalBest = 0 self.oldPersonalBest = personalBest["id"]
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

@ -205,11 +205,16 @@ class score:
self.rank, self.rank,
self.date) self.date)
def setCompletedStatus(self): def setCompletedStatus(self, b = None):
""" """
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)
@ -231,17 +236,28 @@ 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 self.pp > personalBest["pp"]: if b.rankedStatus == rankedStatuses.RANKED:
# New best score if self.pp > personalBest["pp"]:
self.completed = 3 # New best score
self.rankedScoreIncrease = self.score-personalBest["score"] self.completed = 3
self.oldPersonalBest = personalBest["id"] self.rankedScoreIncrease = self.score-personalBest["score"]
else: self.oldPersonalBest = personalBest["id"]
self.completed = 2 else:
self.rankedScoreIncrease = 0 self.completed = 2
self.oldPersonalBest = 0 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
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 and self.mods & modsEnum.AUTOPLAY == 0: if self.mods > -1:
mods = "AND scores.mods = %(mods)s" mods = "AND scores.mods = %(mods)s"
else: else:
mods = "" mods = ""
@ -204,15 +204,19 @@ 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})
@ -238,6 +242,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 and self.mods & modsEnum.AUTOPLAY > 0) data += i.getData(pp=self.mods > -1)
return data return data