-added server files

This commit is contained in:
2022-11-15 19:06:00 +01:00
parent ab1757f7cd
commit 32bdc6dcb6
8 changed files with 149 additions and 2 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,2 @@
.vscode/*
*.php
*.exe
*.db

BIN
jscore

Binary file not shown.

27
server/getuserdata.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$user = "";
if (isset($_GET['user'])) $user = $_GET['user'];
$query = "SELECT data FROM userdata WHERE game LIKE '".$game."' AND user LIKE '".$user."'";
$resultado = $bd->query($query);
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
if ($fila) {
echo($fila['data']);
}
?>

27
server/getuserpoints.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$user = "";
if (isset($_GET['user'])) $user = $_GET['user'];
$query = "SELECT points FROM scores WHERE game LIKE '".$game."' AND user LIKE '".$user."'";
$resultado = $bd->query($query);
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
if ($fila) {
echo($fila['points']);
}
?>

BIN
server/jailgames.db Normal file

Binary file not shown.

29
server/score-list.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$query = "SELECT user, points FROM scores WHERE game LIKE '".$game."' ORDER BY points DESC LIMIT 10";
$resultado = $bd->query($query);
$res = "";
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
while ($fila) {
$res = $res.$fila['user'].",".$fila['points']."\n";
$fila = $resultado->fetchArray(SQLITE3_ASSOC);
}
echo($res);
?>

33
server/score-update.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$user = "";
if (isset($_GET['user'])) $user = $_GET['user'];
$points = "";
if (isset($_GET['points'])) $points = $_GET['points'];
$query = "SELECT count(*) as count FROM scores WHERE game LIKE '".$game."' AND user LIKE '".$user."'";
$resultado = $bd->query($query);
if ($resultado->fetchArray(SQLITE3_ASSOC)['count'] > 0) {
$query = "UPDATE scores SET points=".$points." WHERE game='".$game."' AND user='".$user."'";
$bd->exec($query);
} else {
$query = "INSERT INTO scores (game, user, points) VALUES ('".$game."', '".$user."', ".$points.")";
$bd->exec($query);
}
echo("OK");
?>

33
server/setuserdata.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class MiBD extends SQLite3
{
function __construct()
{
$this->open('../bd/jailgames.db');
}
}
$bd = new MiBD();
$game = "";
if (isset($_GET['game'])) $game = $_GET['game'];
$user = "";
if (isset($_GET['user'])) $user = $_GET['user'];
$data = "";
if (isset($_GET['data'])) $data = $_GET['data'];
$query = "SELECT count(*) as count FROM userdata WHERE game LIKE '".$game."' AND user LIKE '".$user."'";
$resultado = $bd->query($query);
if ($resultado->fetchArray(SQLITE3_ASSOC)['count'] > 0) {
$query = "UPDATE userdata SET data='".$data."' WHERE game='".$game."' AND user='".$user."'";
$bd->exec($query);
} else {
$query = "INSERT INTO userdata (game, user, data) VALUES ('".$game."', '".$user."', '".$data."')";
$bd->exec($query);
}
echo("OK");
?>