makes the checks for submitting klumpy result much stricter

This commit is contained in:
2023-06-03 22:51:50 -04:00
parent 238baed47b
commit b8c58dd50f
7 changed files with 81 additions and 13 deletions

View File

@@ -1,14 +1,45 @@
<?php
// Makes sure that this was a valid game
function valid_moves($board, $history)
{
if (count($board) != 4 && count($history) != 16) {
return false;
}
foreach ($board as $row) {
if (count($row) != 4) {
return false;
}
}
$rounds = pow(2, 16) - 1;
foreach ($history as $round) {
if (count($round["hand"]) != 3) {
return false;
}
if (count($round["board"]) != 2) {
return false;
}
$rounds -= pow(2, $round["board"][0] + $round["board"][1] * 4);
if ($rounds < 0) {
return false;
}
$board_card = $board[$round["board"][0]][$round["board"][1]];
$hand_card1_match = $round["hand"][0]["number"] == $board_card["number"] && $round["hand"][0]["color"] == $board_card["color"];
$hand_card2_match = $round["hand"][1]["number"] == $board_card["number"] && $round["hand"][1]["color"] == $board_card["color"];
$hand_card3_match = $round["hand"][2]["number"] == $board_card["number"] && $round["hand"][2]["color"] == $board_card["color"];
if (!$hand_card1_match && !$hand_card2_match && !$hand_card3_match) {
return false;
}
}
return $rounds == 0;
}
require_once "api.php";
// Used to create an entry in the leaderboard
if (array_key_exists("board", $_POST) && array_key_exists("history", $_POST) && array_key_exists("points", $_POST) && array_key_exists("type", $_POST)) {
exec("node ../klumpy/score.js " . escapeshellarg($OGPOST["board"]), $points);
$points = array_sum(json_decode(join("", $points)));
if ($points > 0 && $points == intval($_POST["points"]) && $_POST["type"] == "main") {
if ($points > 0 && $points == intval($_POST["points"]) && $_POST["type"] == "main" && valid_moves(json_decode($OGPOST["board"], true), json_decode($OGPOST["history"], true))) {
if ($USERNAME) {
$ID = random_int(0, 2147483600);
dbCommand("DELETE FROM klumpy WHERE gameID = ?", [$ID]);
dbCommand("INSERT INTO klumpy (gameID, `type`, username, score, board, history) VALUES (?, ?, ?, ?, ?, ?)", [$ID, $_POST["type"], $USERNAME, $points, $OGPOST["board"], $OGPOST["history"]]);
dbCommand("INSERT INTO klumpy `type`, username, score, board, history) VALUES (?, ?, ?, ?, ?, ?)", [$_POST["type"], $USERNAME, $points, $OGPOST["board"], $OGPOST["history"]]);
}
http_response_code(200);
// Gets the leaderboard position
@@ -23,7 +54,8 @@ if (array_key_exists("board", $_POST) && array_key_exists("history", $_POST) &&
"message" => "You are not logged in",
]);
} else {
writeLog("klumpy", "$USERNAME scored $points on leaderboard for position $position");
$ID = dbRequest2("SELECT gameID FROM klumpy WHERE username=? AND board=? AND history=?", "gameID", [$USERNAME, $OGPOST["board"], $OGPOST["history"]])[0];
writeLog(31, "$USERNAME scored $points on leaderboard for position $position");
echo json_encode([
"position" => $position,
"points" => $points,

View File

@@ -9,7 +9,7 @@ include 'functions.php';
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
<link rel="manifest" href="/favicon/site.webmanifest">
<link rel="stylesheet" type="text/css" href="/css/website.css?v=1.0.3" />
<link rel="stylesheet" type="text/css" href="/css/website.css?v=1.0.4" />
<script type="text/javascript" src="/javascript/jquery.js"></script>
<script defer="true" type="text/javascript" src="/javascript/jquery-ui.min.js"></script>
<link defer="true" rel="stylesheet" href="/css/jquery-ui.min.css">

View File

@@ -3,7 +3,7 @@
<html dir="ltr" lang="en">
<?php
if (!file_exists("config.json")) {
echo '<link rel="stylesheet" type="text/css" href="/css/website.css?v=1.0.3" />';
echo '<link rel="stylesheet" type="text/css" href="/css/website.css?v=1.0.4" />';
echo "<h2>Missing configuration please input configuration</h2>";
}
?>

0
html/klumpy/leaderboard.js Normal file → Executable file
View File

0
html/klumpy/leaderboard.php Normal file → Executable file
View File

0
html/klumpy/render.js Normal file → Executable file
View File

View File

@@ -237,7 +237,14 @@ def repair(): # Repairs all tables or updates them if needed
["bots", 1],
],
"random_stuff": [["type", 0], ["word", 0], ["definition", 4]],
"klumpy": [["gameID", 1], ["type", 0], ["username", 0], ["score", 1], ["board", 4], ["history", 4]],
"klumpy": [
["gameID", 5],
["type", 0],
["username", 0],
["score", 1],
["board", 4],
["history", 4],
],
}
changedTables = []
for x in databaseDict:
@@ -302,7 +309,7 @@ def repair(): # Repairs all tables or updates them if needed
name == "information"
): # Used to check the information table to see if the database can be updated in a better way.
version = trueSearch("SELECT data FROM information WHERE pointer='version'")
latest_version = "v2.7"
latest_version = "v2.8"
if version: # Checks if the version tag still exists.
try: # In here you can update the version to a new version
version = version[0][0]
@@ -377,14 +384,43 @@ def repair(): # Repairs all tables or updates them if needed
version = "v2.6"
updatedVersions.append("v2.6")
if version == "v2.6":
createTable("klumpy", [["gameID", 1], ["type", 6], ["username", 0], ["score", 1], ["board", 4], ["history", 4]])
createTable(
"klumpy",
[
["gameID", 1],
["type", 6],
["username", 0],
["score", 1],
["board", 4],
["history", 4],
],
)
version = "v2.7"
updatedVersions.append("v2.7")
# Fixes the version if it is invalid to the latest version
if version != latest_version:
version = latest_version
if version == "v2.7":
command("RENAME TABLE klumpy TO klumpy2")
createTable(
"klumpy",
[
["gameID", 5],
["type", 6],
["username", 0],
["score", 1],
["board", 4],
["history", 4],
],
)
command(
"INSERT INTO klumpy (type, username, score, board, history) SELECT type, username, score, board, history FROM klumpy2"
)
command("DROP TABLE klumpy2")
version = "v2.8"
updatedVersions.append("v2.8")
except:
1
# Fixes the version if it is invalid to the latest version
if version != latest_version:
version = latest_version
command("DELETE FROM information WHERE pointer='version'")
command(f"INSERT INTO information VALUES('version', '{version}')")
else: