public static function RankBeatmapNew() {
global $URL;
global $ScoresConfig;
try {
if (!isset($_POST["beatmaps"])) {
throw new Exception("Invalid form data");
}
$bsid = -1;
$result = "";
$updateCache = false;
// Do stuff for each beatmap
foreach ($_POST["beatmaps"] as $beatmapID => $status) {
$logToRap = true;
// Get beatmap set id if not set yet
if ($bsid == -1) {
$bsid = $GLOBALS["db"]->fetch("SELECT beatmapset_id FROM beatmaps WHERE beatmap_id = ? LIMIT 1", [$beatmapID]);
if (!$bsid) {
throw new Exception("Beatmap set not found! Please load one diff from this set ingame and try again.");
}
$bsid = current($bsid);
}
// Change beatmap status
switch ($status) {
// Rank beatmap
case "rank":
$GLOBALS["db"]->execute("UPDATE beatmaps SET ranked = 2, ranked_status_freezed = 1 WHERE beatmap_id = ? LIMIT 1", [$beatmapID]);
// Restore old scores
$GLOBALS["db"]->execute("UPDATE scores s JOIN (SELECT userid, MAX(score) maxscore FROM scores JOIN beatmaps ON scores.beatmap_md5 = beatmaps.beatmap_md5 WHERE beatmaps.beatmap_md5 = (SELECT beatmap_md5 FROM beatmaps WHERE beatmap_id = ? LIMIT 1) GROUP BY userid) s2 ON s.score = s2.maxscore AND s.userid = s2.userid SET completed = 3", [$beatmapID]);
$result .= "$beatmapID has been ranked and its scores have been restored. | ";
$rap .= "ranked";
break;
// Love beatmap (INCASE THE BEATMAP IS TOO MUCH PP)
case "love":
$GLOBALS["db"]->execute("UPDATE beatmaps SET ranked = 5, ranked_status_freezed = 1 WHERE beatmap_id = ? LIMIT 1", [$beatmapID]);
// Restore old scores
$GLOBALS["db"]->execute("UPDATE scores s JOIN (SELECT userid, MAX(score) maxscore FROM scores JOIN beatmaps ON scores.beatmap_md5 = beatmaps.beatmap_md5 WHERE beatmaps.beatmap_md5 = (SELECT beatmap_md5 FROM beatmaps WHERE beatmap_id = ? LIMIT 1) GROUP BY userid) s2 ON s.score = s2.maxscore AND s.userid = s2.userid SET completed = 3", [$beatmapID]);
$result .= "$beatmapID has been loved and its scores have been restored. | ";
$rap .= "loved";
break;
// Unrank beatmap (INCASE ITS TOO BAD TO PLAY)
case "unrank":
$GLOBALS["db"]->execute("UPDATE beatmaps SET ranked = 0, ranked_status_freezed = 1 WHERE beatmap_id = ? LIMIT 1", [$beatmapID]);
// Restore old scores
$GLOBALS["db"]->execute("UPDATE scores s JOIN (SELECT userid, MAX(score) maxscore FROM scores JOIN beatmaps ON scores.beatmap_md5 = beatmaps.beatmap_md5 WHERE beatmaps.beatmap_md5 = (SELECT beatmap_md5 FROM beatmaps WHERE beatmap_id = ? LIMIT 1) GROUP BY userid) s2 ON s.score = s2.maxscore AND s.userid = s2.userid SET completed = 2", [$beatmapID]);
$result .= "$beatmapID has been ranked and its scores have been mark as old scores. | ";
$rap .= "unranked";
break;
// Force osu!api update (unfreeze)
case "update":
$updateCache = true;
$GLOBALS["db"]->execute("UPDATE beatmaps SET ranked = 0, ranked_status_freezed = 0 WHERE beatmap_id = ? LIMIT 1", [$beatmapID]);
$result .= "$beatmapID's ranked status is the same from official osu!. | ";
$rap .= "updated status from bancho for";
break;
// No changes
case "no":
$logToRap = false;
$result .= "$beatmapID's ranked status has not been edited!. | ";
$rap .= "nothing to do with";
break;
// EH! VOLEVI!
default:
throw new Exception("Unknown ranked status value.");
break;
}
// RAP Log
if ($logToRap)
rapLog(sprintf("has %s beatmap set %s", $rap, $bsid), $_SESSION["userid"]);
}
// Update beatmap set from osu!api if
// at least one diff has been unfrozen
global $URL;
if ($updateCache) {
post_content_http($URL["scores"]."/api/v1/cacheBeatmap", [
"sid" => $bsid,
"refresh" => 1
], 30);
}
// Send a message to #announce
if ($status == "rank") {
$bm = $GLOBALS["db"]->fetch("SELECT beatmapset_id, song_name FROM beatmaps WHERE beatmapset_id = ? LIMIT 1", [$bsid]);
$msg = "" . $bm["song_name"] . " is now ranked!";
$msgtoannounce = "[https://osu.ppy.sh/s/" . $bsid . " " . $bm["song_name"] . "] is now ranked!";
$statuscrot = "ranked";
$requestanjing = "https://c.datenshi.xyz/api/v1/fokabotMessage?k=" . urlencode($ScoresConfig["api_key"]) . "&to=%23announce&msg=" . $msgtoannounce . "";
} else if ($status == "love") {
$bm = $GLOBALS["db"]->fetch("SELECT beatmapset_id, song_name FROM beatmaps WHERE beatmapset_id = ? LIMIT 1", [$bsid]);
$msg = "" . $bm["song_name"] . " is now loved!";
$msgtoannounce = "[https://osu.ppy.sh/s/" . $bsid . " " . $bm["song_name"] . "] is now Loved!";
$statuscrot = "loved";
$requestanjing = "https://c.datenshi.xyz/api/v1/fokabotMessage?k=" . urlencode($ScoresConfig["api_key"]) . "&to=%23announce&msg=" . $msgtoannounce . "";
} else if ($status == "unrank") {
$bm = $GLOBALS["db"]->fetch("SELECT beatmapset_id, song_name FROM beatmaps WHERE beatmapset_id = ? LIMIT 1", [$bsid]);
$msg = "" . $bm["song_name"] . " just got unranked!";
$msgtoannounce = "[https://osu.ppy.sh/s/" . $bsid . " " . $bm["song_name"] . "] just got unranked!";
$statuscrot = "unranked";
$requestanjing = "https://c.datenshi.xyz/api/v1/fokabotMessage?k=" . urlencode($ScoresConfig["api_key"]) . "&to=%23announce&msg=" . $msgtoannounce . "";
}
$curlanjing = curl_init();
curl_setopt_array($curlanjing, [
CURLOPT_URL => $requestanjing,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
]);
curl_exec($curlanjing);
curl_close($curlanjing);
// Done
redirect("index.php?p=117&s=".$result);
} catch (Exception $e) {
redirect('index.php?p=117&e='.$e->getMessage());
}
}
Last active
August 27, 2020 02:24
-
-
Save troke12/abe16726d5aee05c44a12cfb61c212ad to your computer and use it in GitHub Desktop.
br
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FILE TEST.php
result di middleware TEST.php