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
:return: zingonified dict as str
"""
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")
password = self.get_argument("h")
replayID = self.get_argument("c")
isRelaxing = False
if int(replayID) < 500000000:
isRelaxing = True
s = rxscore.score()
# Login check
userID = userUtils.getID(username)
if userID == 0:
@ -50,12 +46,19 @@ class handler(requestsManager.asyncRequestHandler):
if userUtils.check2FA(userID, 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
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
if replayData is not None:
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))
fileName = ".data/replays/replay_{}.osr".format(replayID)

View File

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

View File

@ -117,6 +117,7 @@ class handler(requestsManager.asyncRequestHandler):
isRelaxing = used_mods & 128
# 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.setDataFromScoreData(scoreData)
@ -140,10 +141,7 @@ class handler(requestsManager.asyncRequestHandler):
# increment user playtime
length = 0
if s.passed:
try:
length = userUtils.getBeatmapTime(beatmapInfo.beatmapID)
except Exception:
log.error("Error while contacting mirror server.")
else:
length = math.ceil(int(self.get_argument("ft")) / 1000)
@ -165,47 +163,47 @@ class handler(requestsManager.asyncRequestHandler):
# Restrict obvious cheaters™
if restricted == False:
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 = []
TAIKOLIST = []
"""
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.
if (s.pp >= 1200 and s.gameMode == gameModes.STD and used_mods & 1024) and userID not in rxGods:
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.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 >= 2000 and s.gameMode == gameModes.STD) and userID not in rxGods:
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.appendNotes(userID, "[osu!taiko] 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")
elif (s.pp >= 1350) and s.gameMode == gameModes.CTB:
userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!catch] 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")
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")
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:
elif (s.pp >= 10000 and s.gameMode == gameModes.TAIKO) and userID not in TAIKOLIST:
userUtils.restrict(userID)
userUtils.appendNotes(userID, "[osu!taiko] 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")
elif s.pp >= 10000) and (s.gameMode == gameModes.CTB:
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, "[osu!catch] 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")
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
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
@ -232,6 +230,7 @@ class handler(requestsManager.asyncRequestHandler):
oldPersonalBestRank = 0
oldPersonalBest = None
# Save score in db
s.saveScoreInDB()
@ -239,23 +238,22 @@ class handler(requestsManager.asyncRequestHandler):
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:
flagsReadable = generalUtils.calculateFlags(int(haxFlags), used_mods, s.gameMode)
if len(flagsReadable) > 1:
flagsReadable = generalUtils.calculateFlags(haxFlags, used_mods, s.gameMode)
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")
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")
if s.score < 0 or s.score > (2 ** 63) - 1:
userUtils.ban(userID)
userUtils.appendNotes(userID, "Banned due to negative score.")
if s.completed == 3: # just incase :)!
if (s.score - (s.c300 * 300 + s.c100 * 100 + s.c50 * 50)) < 0 and not isRelaxing and s.gameMode == 0:
if s.passed: # just incase :)!
if (s.score - (s.c300 * 300 + s.c100 * 100 + s.c50 * 50)) < 0 and not isRelaxing:
#userUtils.ban(userID)
#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:
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
if s.gameMode == gameModes.MANIA and s.score > 1000000:
@ -329,11 +327,6 @@ class handler(requestsManager.asyncRequestHandler):
# Update beatmap playcount (and passcount)
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
if 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)
oldRank = userUtils.getGameRank(userID, s.gameMode)
# Always update users stats (total/ranked score, playcount, level, acc and pp)
# even if not passed
@ -407,6 +401,7 @@ class handler(requestsManager.asyncRequestHandler):
if beatmapInfo is not None and beatmapInfo != False and s.passed:
log.debug("Started building ranking panel.")
if isRelaxing: # Relax
# Trigger bancho stats cache update
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})
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)
# 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)"
# Sort and limit at the end
if self.beatmap.rankedStatus == rankedStatuses.LOVED:
order = "ORDER BY score DESC"
else:
order = "ORDER BY pp DESC"
limit = "LIMIT 1"
# Build query, get params and run query
@ -113,7 +109,7 @@ class scoreboard:
country = ""
# 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"
else:
mods = ""
@ -208,28 +204,24 @@ class scoreboard:
# 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.{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
) 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")
overwrite = "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
if self.country:
query += " AND users_stats.country = (SELECT country FROM users_stats WHERE id = %(userid)s LIMIT 1)"
# Mods
if self.mods > -1:
query += " AND scores_relax.mods = %(mods)s"
# 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)"
# Sort and limit at the end
if self.beatmap.rankedStatus == rankedStatuses.LOVED:
query += " ORDER BY score DESC LIMIT 1"
else:
query += " ORDER BY pp DESC LIMIT 1"
query += " ORDER BY pp DESC LIMIT 1".format(overwrite)
result = glob.db.fetch(query, {"md5": self.beatmap.fileMD5, "userid": self.userID, "mode": self.gameMode, "mods": self.mods})
if result is not None:
self.personalBestRank = result["rank"]
@ -249,10 +241,10 @@ class scoreboard:
# Set personal best score rank
self.setPersonalBestRank() # sets self.personalBestRank with the huge query
self.scores[0].rank = self.personalBestRank
data += self.scores[0].getData()
data += self.scores[0].getData(pp=True)
# Output top 50 scores
for i in self.scores[1:]:
data += i.getData(pp=self.beatmap.rankedStatus != rankedStatuses.LOVED)
data += i.getData(pp=True)
return data

View File

@ -206,16 +206,11 @@ class score:
self.rank,
self.date)
def setCompletedStatus(self, b = None):
def setCompletedStatus(self):
"""
Set this score completed status and rankedScoreIncrease
"""
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):
# Get userID
userID = userUtils.getID(self.playerName)
@ -237,7 +232,6 @@ class score:
self.oldPersonalBest = 0
else:
# Compare personal best's score with current score
if b.rankedStatus == rankedStatuses.RANKED:
if self.pp > personalBest["pp"]:
# New best score
self.completed = 3
@ -247,18 +241,8 @@ class score:
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
#log.info("Completed status: {}".format(self.completed))
log.info("Completed status: {}".format(self.completed))
def saveScoreInDB(self):
"""

View File

@ -205,16 +205,11 @@ class score:
self.rank,
self.date)
def setCompletedStatus(self, b = None):
def setCompletedStatus(self):
"""
Set this score completed status and rankedScoreIncrease
"""
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):
# Get userID
userID = userUtils.getID(self.playerName)
@ -236,9 +231,6 @@ class score:
self.oldPersonalBest = 0
else:
# Compare personal best's score with current score
if b.rankedStatus == rankedStatuses.RANKED:
self.completed = 3
self.calculatePP()
if self.pp > personalBest["pp"]:
# New best score
self.completed = 3
@ -248,19 +240,8 @@ class score:
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):
"""

View File

@ -109,7 +109,7 @@ class scoreboard:
country = ""
# 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"
else:
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 >= (
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"""
# Country
if self.country:
query += " AND users_stats.country = (SELECT country FROM users_stats WHERE id = %(userid)s LIMIT 1)"
# Mods
if self.mods > -1:
query += " AND scores.mods = %(mods)s"
# Friends
if self.friends:
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
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})
@ -242,6 +238,6 @@ class scoreboard:
# Output top 50 scores
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