Added support for skipping player that takes too long
This commit is contained in:
@@ -47,7 +47,8 @@ function moveCard($user, $game, $swap1, $swap2) {
|
||||
}
|
||||
} while (dbRequest2("SELECT * FROM golfGamePlayers WHERE lastMode='eliminated' and orderID='$gameCurrentPlayer' and gameID='$game'"));
|
||||
$time = time();
|
||||
dbCommand("UPDATE golfGame SET deck='$deck', discard='$discard', currentPlayer='$gameCurrentPlayer', turnStartTime='$time' WHERE id=$game");
|
||||
$timeLeft = $gameData["skipTime"];
|
||||
dbCommand("UPDATE golfGame SET deck='$deck', discard='$discard', currentPlayer='$gameCurrentPlayer', turnStartTime='$time', timeLeft=$timeLeft WHERE id=$game");
|
||||
dbCommand("UPDATE golfGamePlayers SET upToDate=0 WHERE gameID='$game'");
|
||||
return array("code" => 200, "text" => "Switched card #$swap1 with $swap2");
|
||||
}
|
||||
@@ -163,9 +164,9 @@ function readyGame($game) {
|
||||
if ($USERNAME) {
|
||||
if (array_key_exists("game", $_GET)){ // Gets the game
|
||||
# Finds all games the player is still playing.
|
||||
$playing = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks FROM golfGame WHERE EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY turnStartTime DESC");
|
||||
$playing = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks, skipTime FROM golfGame WHERE EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY turnStartTime DESC");
|
||||
# Finds all open games.
|
||||
$data = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks FROM golfGame WHERE players != playersToStart and NOT EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY players DESC");
|
||||
$data = dbRequest2("SELECT name, password, players, playersToStart, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, ID, decks, skipTime FROM golfGame WHERE players != playersToStart and NOT EXISTS (SELECT * FROM golfGamePlayers WHERE golfGamePlayers.gameID = ID and user='$USERNAME') ORDER BY players DESC");
|
||||
foreach ($data as $id => $entry) { // Makes sure to not leak the password
|
||||
if ($entry["password"]) {
|
||||
$data[$id]["password"] = true;
|
||||
@@ -179,6 +180,20 @@ if ($USERNAME) {
|
||||
$game = dbRequest2("SELECT * FROM golfGame WHERE ID='$id'");
|
||||
if ($game) { // Will check if the game exists
|
||||
$game = $game[0];
|
||||
if ($game["currentPlayer"] != -1 and $game["skipTime"] != 0 and $game["players"] >= $game["playersToStart"]) { // Makes sure that this game requires the skip turn part.
|
||||
$time = time();
|
||||
if (dbRequest2("SELECT timeLeft FROM golfGame WHERE ID='$id'", "timeLeft")[0] <= 0) { // Checks if the time is up for the player not being active.
|
||||
$orderID = $game["currentPlayer"];
|
||||
$swap1 = rand(1, $game["cardNumber"]);
|
||||
$swap2 = (rand(0, 1)) ? "discard" : 'deck';
|
||||
moveCard(dbRequest2("SELECT user FROM golfGamePlayers WHERE orderID=$orderID", "user")[0], $id, $swap1, $swap2);
|
||||
$game = dbRequest2("SELECT * FROM golfGame WHERE ID='$id'")[0];
|
||||
} elseif (dbRequest2("SELECT turnStartTime FROM golfGame WHERE ID='$id'")[0] != $time) { // Checks if a new second has passed
|
||||
dbCommand("UPDATE golfGame SET turnStartTime=$time WHERE ID='$id'");
|
||||
$newTimeLeft = $game["timeLeft"] - 1;
|
||||
dbCommand("UPDATE golfGame SET timeLeft=$newTimeLeft WHERE ID='$id'");
|
||||
}
|
||||
}
|
||||
if (dbRequest2("SELECT upToDate FROM golfGamePlayers WHERE gameID='$id' and user='$USERNAME' and upToDate")) {
|
||||
echo "No change";
|
||||
header('alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400', true);
|
||||
@@ -330,7 +345,7 @@ if ($USERNAME) {
|
||||
http_response_code(404);
|
||||
echo "Game not found";
|
||||
}
|
||||
} elseif (array_key_exists("create", $_POST) and array_key_exists("cardNumber", $_POST) and array_key_exists("flipNumber", $_POST) and array_key_exists("playersToStart", $_POST) and array_key_exists("multiplierForFlip", $_POST) and array_key_exists("decks", $_POST)) { # Used to create a new room
|
||||
} elseif (array_key_exists("create", $_POST) and array_key_exists("cardNumber", $_POST) and array_key_exists("flipNumber", $_POST) and array_key_exists("playersToStart", $_POST) and array_key_exists("multiplierForFlip", $_POST) and array_key_exists("decks", $_POST) and array_key_exists("skipTime", $_POST)) { # Used to create a new room
|
||||
$password = "";
|
||||
$name = $_POST["create"];
|
||||
$cardNumber = intval($_POST["cardNumber"]);
|
||||
@@ -339,6 +354,7 @@ if ($USERNAME) {
|
||||
$playersToStart = $_POST["playersToStart"];
|
||||
$pointsToEnd = intval($_POST["pointsToEnd"]);
|
||||
$decks = intval($_POST["decks"]);
|
||||
$skipTime = intval($_POST["skipTime"]);
|
||||
$time = time();
|
||||
if (array_key_exists("password", $_POST)) {
|
||||
$password = $_POST["password"];
|
||||
@@ -364,8 +380,11 @@ if ($USERNAME) {
|
||||
} elseif ($decks > 50 or $decks < 1) {
|
||||
http_response_code(400);
|
||||
echo "You can only have 50 decks";
|
||||
} elseif ($skipTime < 0) {
|
||||
http_response_code(400);
|
||||
echo "Only positive times until skip are allowed";
|
||||
} else {
|
||||
dbCommand("INSERT INTO golfGame (deck, discard, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, name, password, players, playersToStart, currentPlayer, turnStartTime, decks) VALUES ('[]', '[]', $cardNumber, $flipNumber, $multiplierForFlip, $pointsToEnd, '$name', '$password', 0, $playersToStart, -1, $time, $decks)");
|
||||
dbCommand("INSERT INTO golfGame (deck, discard, cardNumber, flipNumber, multiplierForFlip, pointsToEnd, name, password, players, playersToStart, currentPlayer, turnStartTime, decks, skipTime, timeLeft) VALUES ('[]', '[]', $cardNumber, $flipNumber, $multiplierForFlip, $pointsToEnd, '$name', '$password', 0, $playersToStart, -1, $time, $decks, $skipTime, $skipTime)");
|
||||
echo "Created Game";
|
||||
writeLog(14, "$USERNAME created game for $playersToStart players, $cardNumber cards, $decks decks, and name $name with ip of $address");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function update(repeat=false) { // Will update the game.
|
||||
var text = "<tr><th>Name</th><Players</th><th>Current Players</th><th>Max Players</th><th>Multiplier for Flipping Last Card</th><th>Points to Out</th><th>Password</th><th>Cards</th><th>Cards to flip</th><th>Decks</th></tr>";
|
||||
var text = "<tr><th>Name</th><th>Players</th><th>Max Players</th><th>Skip Time</th><th>Multiplier for Flipping Last Card</th><th>Points to Out</th><th>Password</th><th>Cards</th><th>Cards to flip</th><th>Decks</th></tr>";
|
||||
const ajax = new XMLHttpRequest();
|
||||
ajax.onload = function() {
|
||||
if (ajax.status == 200) {
|
||||
@@ -8,7 +8,7 @@ function update(repeat=false) { // Will update the game.
|
||||
if (element.players == element.playersToStart) {
|
||||
joinText = "Continue";
|
||||
}
|
||||
text += `<tr><td>${element.name} <button onClick='joinGame(${element.ID})'>${joinText}</button></td><td>${element.players}</td><td>${element.playersToStart}</td><td>${element.multiplierForFlip}</td><td>${element.pointsToEnd}</td><td>${element.password ? `true` : "false"}</td><td>${element.cardNumber}</td><td>${element.flipNumber}</td><td>${element.decks}</td></tr>`;
|
||||
text += `<tr><td>${element.name} <button onClick='joinGame(${element.ID})'>${joinText}</button></td><td>${element.players}</td><td>${element.playersToStart}</td><td>${element.skipTime}</td><td>${element.multiplierForFlip}</td><td>${element.pointsToEnd}</td><td>${element.password ? `true` : "false"}</td><td>${element.cardNumber}</td><td>${element.flipNumber}</td><td>${element.decks}</td></tr>`;
|
||||
});
|
||||
$("#games").html(text);
|
||||
} else {
|
||||
@@ -40,7 +40,7 @@ function create() { // Will create a game
|
||||
if ($("#password").val()) {
|
||||
password = `&password=${$("#password").val()}`;
|
||||
}
|
||||
ajax.send(`create=${$("#name").val()}&cardNumber=${$("#cardNumber").val()}&flipNumber=${$("#flipNumber").val()}&playersToStart=${$("#playersToStart").val()}&multiplierForFlip=${$("#multiplierForFlip").val()}&pointsToEnd=${$("#pointsToEnd").val()}&decks=${$("#decks").val()}&key='${getCookie('user')}'${password}`);
|
||||
ajax.send(`create=${$("#name").val()}&cardNumber=${$("#cardNumber").val()}&flipNumber=${$("#flipNumber").val()}&playersToStart=${$("#playersToStart").val()}&multiplierForFlip=${$("#multiplierForFlip").val()}&pointsToEnd=${$("#pointsToEnd").val()}&decks=${$("#decks").val()}&skipTime=${$("#skipTime").val()}&key='${getCookie('user')}'${password}`);
|
||||
}
|
||||
function joinGame(id) {
|
||||
window.location = `game.php?game=${id}`;
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
<label for="playersToStart">Players: </label><input type='number' value='4' id="playersToStart"><br>
|
||||
<label for="multiplierForFlip">Multiplier for flipping last card: </label><input type='number' value='2' id="multiplierForFlip"><br>
|
||||
<label for="pointsToEnd">Points to get out: </label><input type='number' value='100' id="pointsToEnd"><br>
|
||||
<label for="decks">Number of decks to use </label><input type='number' value='1' id="decks"><br>
|
||||
<label for="decks">Number of decks to use: </label><input type='number' value='1' id="decks"><br>
|
||||
<label for="skipTime">Amount of time to wait before player is skipped(0 means that a player will never be skipped): </label><input type='number' value='0' id="skipTime"><br>
|
||||
<label for="password">Password(leave blank for none): </label><input type='password' value='' id="password"><br>
|
||||
<button id='create'>Create</button>
|
||||
</div>
|
||||
|
||||
@@ -167,7 +167,7 @@ def repair(): # Repairs all tables or updates them if needed
|
||||
"space3likes" : [["id", 1], ["account", 0]],
|
||||
"golfGamePlayers" : [["gameID", 1], ["multiplier", 1], ["user", 0], ["points", 1], ["orderID", 1], ["lastMode", 0], ["upToDate", 6]],
|
||||
"golfGameCards" : [["gameID", 1], ["user", 0], ["card", 1], ["cardPlacement", 1], ["faceUp", 6]],
|
||||
"golfGame" : [["ID", 5], ["deck", 4], ["discard", 4], ["cardNumber", 1], ["flipNumber", 1], ["multiplierForFlip", 1], ["pointsToEnd", 1], ["name", 0], ["password", 0], ["players", 1], ["playersToStart", 1], ["currentPlayer", 1], ["turnStartTime", 1], ["locked", 6], ["decks", 1]],
|
||||
"golfGame" : [["ID", 5], ["deck", 4], ["discard", 4], ["cardNumber", 1], ["flipNumber", 1], ["multiplierForFlip", 1], ["pointsToEnd", 1], ["name", 0], ["password", 0], ["players", 1], ["playersToStart", 1], ["currentPlayer", 1], ["turnStartTime", 1], ["locked", 6], ["decks", 1], ["skipTime", 1]],
|
||||
"docker" : [["link", 0], ["action", 0], ["image", 0], ["password", 0], ["owner", 0], ["port", 1], ["ID", 0]],
|
||||
"dockerImages" : [["realName", 0], ["shortName", 0]]
|
||||
}
|
||||
@@ -249,9 +249,16 @@ def repair(): # Repairs all tables or updates them if needed
|
||||
command("UPDATE golfGame SET decks='1'")
|
||||
version = "v2.1"
|
||||
updatedVersions.append("v2.1")
|
||||
if versionNumber == "v2.1": # Adds support for skip time
|
||||
command("ALTER table golfGame ADD skipTime int")
|
||||
command("ALTER table golfGame ADD timeLeft int")
|
||||
command("UPDATE golfGame SET skipTime='0'")
|
||||
command("UPDATE golfGame SET timeLeft='0'")
|
||||
version = "v2.2"
|
||||
updatedVersions.append("v2.2")
|
||||
# Fixes the version if it is invalid to the latest version
|
||||
if version != "v2.1":
|
||||
version = "v2.1"
|
||||
if version != "v2.2":
|
||||
version = "v2.2"
|
||||
except:
|
||||
1
|
||||
command("DELETE FROM information WHERE pointer='version'")
|
||||
|
||||
Reference in New Issue
Block a user