Compare commits

..

6 Commits

Author SHA1 Message Date
foin137
d1c4b59a43 Better display settings 2023-11-05 16:23:51 +01:00
foin137
9ee2148d9a Merge pull request #34 from foin137/phpversionupdate
Ready for php 8.1, fix bug [#31]

Handle mysql errors [#33]
Include option to disable new game creation
Include license in every file
2023-11-05 16:14:17 +01:00
foin137
a45bd3c642 Update version 2023-11-05 16:08:17 +01:00
foin137
30fea14c07 Include license statement 2023-11-05 16:07:41 +01:00
foin137
2bf710e215 Possibility to disable new games
Include possibility to disable new games by changing a constant in constants.php
2023-11-05 16:02:36 +01:00
foin137
93b38cfc47 Handle mysqli errors
- Handle mysql errors that are no longer silenced per default for new php versions
- Handled error when log file cannot be created
2023-11-05 15:44:24 +01:00
7 changed files with 377 additions and 174 deletions

View File

@@ -1,3 +1,26 @@
<?php
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
?>
<!DOCTYPE html>
<HTML>
<head>
@@ -143,8 +166,14 @@ p#liste {
else
{
//Schauen, ob es auch einen Eintrag zu diesem Spiel in der Datenbank gibt...
$spiel_existiert = True;
try{
$alleres = $mysqli->Query("SELECT * FROM $spielID"."_spieler");
if(isset($alleres->num_rows))
}
catch (Exception $e) {
$spiel_existiert = False;
}
if($spiel_existiert && isset($alleres->num_rows))
{
//Schauen, ob es auch mich als Spieler gibt und meine verifizierungsnr stimmt
$spielerResult = $mysqli->Query("SELECT * FROM $spielID"."_spieler WHERE id = $eigeneID AND verifizierungsnr = ".(int)$_COOKIE['verifizierungsnr']);
@@ -1457,9 +1486,17 @@ p#liste {
if (isset($_POST['neuesSpiel']))
{
//Starten wir ein neues Spiel
if (_NOGAMECREATIONERRORMESSAGE == "")
{
$mysqli->Query("UPDATE $spielID"."_game SET spielphase = ".PHASESETUP);
$mysqli->Query("UPDATE $spielID"."_spieler SET reload = 1");
}
else
{
//Spiel darf nicht erstellt werden, da _NOGAMECREATIONERRORMESSAGE existiert
echo "<p class='error' >Spiel darf nicht erstellt werden: ". _NOGAMECREATIONERRORMESSAGE ."</p>";
}
}
echo "<form action='Werwolf.php' method='post'>
<input type='hidden' name='neuesSpiel' value=1 />
<p class='normal' ><input type='submit' value='Neues Spiel'/></p>
@@ -1503,6 +1540,9 @@ p#liste {
if (rand(1,100)==50)
loescheAlteSpiele($mysqli);
//Wir erstellen ein neues Spiel
if (_NOGAMECREATIONERRORMESSAGE == "") //Wir dürfen nur ein neues Spiel erstellen, falls diese message auf "" steht
{
//Eine Schleife, die solange rennt, bis eine neue Zahl gefunden wurde
for ($i = 1; $i <= 100000; $i++)
{
@@ -1513,8 +1553,14 @@ p#liste {
}
$spielID = rand(10000,99999);
//nachschauen, ob ein Spiel mit dieser Nummer bereits existiert
$existiert = False;
try {
$res = $mysqli->Query("SELECT * FROM $spielID"."_spieler");
if(isset($res->num_rows)){
}
catch (mysqli_sql_exception $e){
$existiert = True;
}
if(!$existiert && isset($res->num_rows)){
//Tabelle existiert
}else{
@@ -1622,6 +1668,12 @@ p#liste {
$pageReload = true;
}
else
{
//Spiel darf nicht erstellt werden, da _NOGAMECREATIONERRORMESSAGE existiert
echo "<p class='error' >Spiel darf nicht erstellt werden: ". _NOGAMECREATIONERRORMESSAGE ."</p>";
}
}
else
{
//kein Name eingegeben! erneut
echo "<p class='error' >Sie müssen einen gültigen Namen eingeben</p>";
@@ -1635,8 +1687,14 @@ p#liste {
if ($_POST['ihrName'] != "" && strpos($_POST['ihrName'],"$")===false && strpos($_POST['ihrName'],";")===false && strpos($_POST['ihrName'],'"')===false && strpos($_POST['ihrName'],"'")===false && strpos($_POST['ihrName'],"=")===false)
{
//Name wurde eingegeben. Existiert auch ein Spiel dieser Nummer?
$existiert = False;
try{
$res = $mysqli->Query("SELECT * FROM $spielID"."_spieler");
if(isset($res->num_rows))
}
catch(mysqli_sql_exception $e){
$existiert = True;
}
if(!$existiert && isset($res->num_rows))
{
//Ein Spiel dieser Nummer existiert!
$verboteneNamen = array("niemanden","niemand","keinen","keiner","dorfbewohner","werwolf","seher","seherin","hexe","hexer","jäger","amor","beschützer","paranormaler ermittler","lykantroph","lykantrophin","spion","spionin","mordlustiger","mordlustige","pazifist","pazifistin","alter mann","alter","alte","alte frau","die alten","alten");
@@ -1645,6 +1703,7 @@ p#liste {
$stmt->bind_param('s',$_POST['ihrName']);
$stmt->execute();
$nameRes = $stmt->get_result();
$stmt->close();
if ($nameRes->num_rows <= 0 && !in_array(strtolower($_POST['ihrName']),$verboteneNamen))
{
//Name gültig
@@ -1696,7 +1755,6 @@ p#liste {
{
echo "<p class='error' >Der angegebene Name ist bereits vorhanden oder ungültig</p>";
}
$stmt->close();
}
else
{

View File

@@ -1,5 +1,25 @@
<?php
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include "includes/includes.php";
header("Content-Type: text/html; charset=utf-8");
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');

View File

@@ -1,9 +1,37 @@
<?php
//Constants
define("_VERSION","v1.2.7");
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//Settings:
define ("_NOGAMECREATIONERRORMESSAGE", ""); //Falls nicht "": Kein Spiel kann erstellt werden, stattdessen wird der string angezeigt.
//define ("_NOGAMECREATIONERRORMESSAGE", "Wartungsarbeiten bis ..."); //Falls nicht "": Kein Spiel kann erstellt werden, stattdessen wird der string angezeigt.
define("_LISTMAXRELOADTIME",3000);
define("_MAXPLAYERS",50);
///////////////////////////////////
// Constants, do not change!
///////////////////////////////////
define("_VERSION","v1.2.9");
//Phasen
define ("PHASESETUP",0);
define ("PHASESPIELSETUP",1);

View File

@@ -1,4 +1,25 @@
<?php
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
function start()
{
//Diese Funktion zeigt das Startformular an, bei dem der Nutzer aufgefordert wird, ein Spiel zu erstellen, oder eine ID einzugeben
@@ -30,8 +51,14 @@ function loescheAlteSpiele($mysqli)
for ($i = 10000; $i<= 99999; $i++)
{
$existiert = True;
try{
$alleres = $mysqli ->Query("SELECT * FROM $i"."_game");
if(isset($alleres->num_rows))
}
catch (mysqli_sql_exception $e){
$existiert = False;
}
if($existiert && isset($alleres->num_rows))
{
$temp = $alleres->fetch_assoc();
if ($temp['letzterAufruf'] < $zeitpunkt)
@@ -251,25 +278,25 @@ function spielRegeln($mysqli)
auswahl.werwoelfe.disabled = false;auswahl.werwolfbutton1.disabled=false; auswahl.werwolfbutton2.disabled=false;}'><label for='zufaelligauswaehlenID'> Die Charaktere verdeckt und zufällig auswählen </label></span>
<p class='normal' >Geben Sie dazu eine maximale Anzahl von Charakteren ein, die vorkommen sollen, bei Werwölfen müssen sie nichts eingeben<br>
Zusätzlich können Sie noch einen Wert eingeben, der die Verteilung bestimmt. Ein positiver Wert erleichtert das Spiel für die Dorfbewohner, ein negativer für die Werwölfe (nur bei der zufälligen Charakterverteilung)</p>";
echo "<span class='normal' ><label for='zufaelligeAuswahlBonusID'> Verteilung der zufälligen Charaktere </label><INPUT TYPE='number' NAME='zufaelligeAuswahlBonus' id='zufaelligeAuswahlBonusID' Size='2' value=$zufaelligeAuswahlBonus MIN=-15 MAX=15></span>";
echo "<span class='normal' ><label for='zufaelligeAuswahlBonusID'> Verteilung der zufälligen Charaktere </label><INPUT TYPE='number' NAME='zufaelligeAuswahlBonus' id='zufaelligeAuswahlBonusID' Size='4' value=$zufaelligeAuswahlBonus MIN=-15 MAX=15></span>";
echo "</div>";
echo "<div><h3 >Countdown-Einstellungen</h3>";
echo "<span class='normal' ><INPUT TYPE='button' VALUE='Countdowns zurücksetzen' OnClick='auswahl.werwolftimer1.value=60; auswahl.werwolfzusatz1.value=4; auswahl.werwolftimer2.value=50; auswahl.werwolfzusatz2.value=3; auswahl.dorftimer.value=550; auswahl.dorfzusatz.value=10; auswahl.dorfstichwahltimer.value=200; auswahl.dorfstichwahlzusatz.value=5'></span>";
echo "<span class='normal' ><label for='werwolftimer1ID'>Sekunden, bis die Werwölfe nicht mehr einstimmig wählen müssen: </label>
<INPUT TYPE='number' NAME='werwolftimer1' id='werwolftimer1ID' SIZE='2' VALUE=$werwolftimer1 MIN='20' MAX='500'><br>
<label for='werwolfzusatz1ID'>Zusätzliche Zeit pro Werwolf: </label><INPUT TYPE='number' NAME='werwolfzusatz1' id='werwolfzusatz1ID' SIZE='2' VALUE=$werwolfzusatz1 MIN='0' MAX='60'></span>";
<INPUT TYPE='number' NAME='werwolftimer1' id='werwolftimer1ID' SIZE='4' VALUE=$werwolftimer1 MIN='20' MAX='500'><br>
<label for='werwolfzusatz1ID'>Zusätzliche Zeit pro Werwolf: </label><INPUT TYPE='number' NAME='werwolfzusatz1' id='werwolfzusatz1ID' SIZE='4' VALUE=$werwolfzusatz1 MIN='0' MAX='60'></span>";
echo "<span class='normal' ><label for='werwolftimer2ID'>Sekunden, bis nach Ablaufen der Einstimmigkeit die Wahl der Werwölfe erfolglos ist: </label>
<INPUT TYPE='number' NAME='werwolftimer2' id='werwolftimer2ID' SIZE='2' VALUE=$werwolftimer2 MIN='10' MAX='500'><br>
<label for='werwolfzusatz2ID'>Zusätzliche Zeit pro Werwolf: </label><INPUT TYPE='number' NAME='werwolfzusatz2' id='werwolfzusatz2ID' SIZE='2' VALUE=$werwolfzusatz2 MIN='0' MAX='60'></span>";
<INPUT TYPE='number' NAME='werwolftimer2' id='werwolftimer2ID' SIZE='4' VALUE=$werwolftimer2 MIN='10' MAX='500'><br>
<label for='werwolfzusatz2ID'>Zusätzliche Zeit pro Werwolf: </label><INPUT TYPE='number' NAME='werwolfzusatz2' id='werwolfzusatz2ID' SIZE='4' VALUE=$werwolfzusatz2 MIN='0' MAX='60'></span>";
echo "<span class='normal' ><label for='dorftimerID'>Sekunden, bis die normale Abstimmung des Dorfes am Tag erfolglos ist: </label>
<INPUT TYPE='number' NAME='dorftimer' id='dorftimerID' SIZE='2' VALUE=$dorftimer MIN='60' MAX='7200'><br>
<label for='dorfzusatzID'>Zusätzliche Zeit pro Dorfbewohner: </label><INPUT TYPE='number' NAME='dorfzusatz' id='dorfzusatzID' SIZE='2' VALUE=$dorfzusatz MIN='0' MAX='300'></span>";
<INPUT TYPE='number' NAME='dorftimer' id='dorftimerID' SIZE='4' VALUE=$dorftimer MIN='60' MAX='7200'><br>
<label for='dorfzusatzID'>Zusätzliche Zeit pro Dorfbewohner: </label><INPUT TYPE='number' NAME='dorfzusatz' id='dorfzusatzID' SIZE='4' VALUE=$dorfzusatz MIN='0' MAX='300'></span>";
echo "<span class='normal' ><label for='dorfstichwahltimerID'>Sekunden, bis die Stichwahl am Tag erfolglos ist: </label>
<INPUT TYPE='number' NAME='dorfstichwahltimer' id='dorfstichwahltimerID' SIZE='2' VALUE=$dorfstichwahltimer MIN='30' MAX='3600'><br>
<label for='dorfstichwahlzusatzID'>Zusätzliche Zeit pro Dorfbewohner: </label><INPUT TYPE='number' NAME='dorfstichwahlzusatz' id='dorfstichwahlzusatzID' SIZE='2' VALUE=$dorfstichwahlzusatz MIN='0' MAX='300'></span>";
<INPUT TYPE='number' NAME='dorfstichwahltimer' id='dorfstichwahltimerID' SIZE='4' VALUE=$dorfstichwahltimer MIN='30' MAX='3600'><br>
<label for='dorfstichwahlzusatzID'>Zusätzliche Zeit pro Dorfbewohner: </label><INPUT TYPE='number' NAME='dorfstichwahlzusatz' id='dorfstichwahlzusatzID' SIZE='4' VALUE=$dorfstichwahlzusatz MIN='0' MAX='300'></span>";
echo "<span class='normal' ><label for='inaktivzeitID'>Sekunden, nach denen angezeigt wird, auf wen noch gewartet wird: </label>
<INPUT TYPE='number' NAME='inaktivzeit' id='inaktivzeitID' SIZE='2' VALUE=$inaktivzeit MIN='20' MAX='3600'><br>
<label for='inaktivzeitzusatzID'>Zusätzliche Zeit pro Spieler: </label><INPUT TYPE='number' NAME='inaktivzeitzusatz' id='inaktivzeitzusatzID' SIZE='2' VALUE=$inaktivzeitzusatz MIN='0' MAX='300'></span>";
<INPUT TYPE='number' NAME='inaktivzeit' id='inaktivzeitID' SIZE='4' VALUE=$inaktivzeit MIN='20' MAX='3600'><br>
<label for='inaktivzeitzusatzID'>Zusätzliche Zeit pro Spieler: </label><INPUT TYPE='number' NAME='inaktivzeitzusatz' id='inaktivzeitzusatzID' SIZE='4' VALUE=$inaktivzeitzusatz MIN='0' MAX='300'></span>";
echo "</div><span align = 'center'><input type='submit' value = 'Speichern'/></span>";
echo "</form>";
}
@@ -1658,6 +1685,7 @@ function writeGameToLog($mysqli)
$spielID = $_COOKIE['SpielID'];
$fileName = "log/Werwolf_log_".date("Y_m").".log";
$myfile = fopen($fileName, "a");
if ($myfile){
fwrite($myfile,"\n--- SPIEL BEENDET --- \n");
fwrite($myfile,"SpielID: $spielID \n");
fwrite($myfile,"SpielEnde: ".date("d.m.Y, H:i:s")."\n");
@@ -1682,17 +1710,20 @@ function writeGameToLog($mysqli)
}
fwrite($myfile,"--- ENDE DES SPIELLOGS ---\n");
fclose($myfile);
}
}
function writeGameToLogSpielErstellen($mysqli, $spielID, $name)
{
$fileName = "log/Werwolf_log_".date("Y_m").".log";
$myfile = fopen($fileName, "a");
if ($myfile){
fwrite($myfile,"\n--- NEUES SPIEL ERSTELLT --- \n");
fwrite($myfile,"SpielID: $spielID \n");
fwrite($myfile,"Zeit: ".date("d.m.Y, H:i:s")."\n");
fwrite($myfile,"Name des Erstellers: $name \n");
fclose($myfile);
}
}
function checkeSiegbedingungen($mysqli)
@@ -1813,11 +1844,13 @@ function setBereit($mysqli,$spielerID,$bereit)
function gameAssoc($mysqli)
{
$spielID = $_COOKIE['SpielID'];
try{
if ($gameRes = $mysqli->Query("SELECT * FROM $spielID"."_game"))
{
$gameA = $gameRes->fetch_assoc();
return $gameA;
}
}catch(mysqli_sql_exception $e) {}
return false;
}
@@ -1835,11 +1868,13 @@ function getName($mysqli, $spielerID)
//Gibt den Namen des Spielers mit der $spielerID zurück
$spielID = $_COOKIE['SpielID'];
$spielerID = (int)$spielerID;
try{
if ($res = $mysqli->Query("SELECT * FROM $spielID"."_spieler WHERE id = $spielerID"))
{
$temp = $res->fetch_assoc();
return $temp['name'];
}
} catch(mysqli_sql_exception $e) {}
return "Unknown";
}

View File

@@ -1,5 +1,26 @@
<?php
$id = "id"; // Ihre ID zum MySQL Server
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
$id = "id"; // Ihre ID (username) zum MySQL Server
$pw = "pw"; // Passwort zum MySQL Server
$host = "localhost"; // Host ("localhost" oder "IP-Adresse")
$db = "werwolf"; // Name Ihrer Datenbank

View File

@@ -1,5 +1,25 @@
<?php
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include "includes/includes.php";
include "includes/constants.php";
header("Content-Type: text/html; charset=utf-8");

View File

@@ -1,4 +1,25 @@
<?php
/*
werwolfonline, a php web game
Copyright (C) 2023
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
header("Content-Type: text/html; charset=utf-8");
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past