commit 21b319f92251730020f347e7e20c466f14df6b6f
parent 8cd539e6d18b5a676505f8592122615c67ccd7fe
Author: Yoann <yoann.b87@voila.fr>
Date: Wed, 18 May 2011 17:36:09 +0200
Petit nettoyage du code suppression d'élément plus utilisés.
Diffstat:
2 files changed, 33 insertions(+), 44 deletions(-)
diff --git a/code/serveur/php/ressources/backend.inc b/code/serveur/php/ressources/backend.inc
@@ -1,8 +1,9 @@
<?php
-
require_once("ressources/relations.inc");
require_once("ressources/db.inc");
+
+
/* Les prototypes des fonctions :
* ===============================>
* checkLogin($user, $passwd);
@@ -26,10 +27,19 @@ require_once("ressources/db.inc");
* get_game_relations();
* getGameRelationsJSON();
* setGameGetScore($user, $pgid, $gid, $answers);
-* insertNode($node);
* getNodeEid($node);
+* wordExist($node);
+* setUserInfo($user, $key, $value);
+* userPrefsDefaults();
+* userPrefs($user);
+* setUserPref($user, $key, $value);
*/
+
+
+/* Les définitions
+====================*/
+
function longStrVal($str) {
return preg_match('/^-?[0-9]+$/', ''.$str) ? ''.$str : '0';
}
@@ -535,6 +545,7 @@ function normalizeProbas($row) {
function setGame($user, $pgid, $gid, $answers)
{
$db = getDB();
+
if ('ok' !== $db->querySingle("SELECT 'ok' FROM played_game WHERE pgid = ".longStrVal($pgid)." and gid = ".intval($gid)." and login = '".SQLite3::escapeString($user)."' and timestamp = -1;")) {
return getGameScores($user, $pgid, $gid);
}
@@ -615,23 +626,9 @@ function getGameScores($user, $pgid, $gid) {
}
/** Fourni l'ensembles des relations pouvant apparaître dans le jeu.
-* @return array : un tableau de realtions.
+* @return JSON type et nom des relations.
*/
-function get_game_relations()
-{
- $reqlations = array();
-
- $relations[] = 5;
- $relations[] = 7;
- $relations[] = 9;
- $relations[] = 10;
- $relations[] = 13;
- $relations[] = 22;
-
- return $relations;
-}
-
-function getGameRelationsJSON() {
+function getGameRelations() {
$json = "{";
global $stringRelations;
@@ -655,20 +652,6 @@ function setGameGetScore($user, $pgid, $gid, $answers) {
echo json_encode($scores);
}
-/** Insère dans la base de données le noeud si il n'existe pas encore.
-* @param node : le noeud à ajouter.
-*/
-function insertNode($node) {
- $db = getDB();
-
- if($db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."'") == null) {
- $db->exec("INSERT INTO node(name,type,weight) VALUES('".SQLite3::escapeString($node)."',1,50);");
- return true;
- }
-
- return false;
-}
-
/** retourne l'eid d'un mot.
* @param node : le mot dont on veut obtenir l'eid.
@@ -679,6 +662,10 @@ function getNodeEid($node) {
return $db->querySingle("SELECT eid FROM node WHERE name='".SQLite3::escapeString($node)."';");
}
+/* Permet de déterminer si le mot existe dans la base de données ou non.
+ * @param node : Le mot dont on veut connaître l'existance.
+ * @return char : "0" ou "1".
+*/
function wordExist($node) {
$db = getDB();
@@ -716,4 +703,4 @@ function setUserPref($user, $key, $value) {
}
}
-?>
-\ No newline at end of file
+?>
diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php
@@ -1,6 +1,5 @@
<?php
session_start();
-
require_once("ressources/backend.inc");
require_once("ressources/db.inc");
@@ -17,6 +16,7 @@ function logError($errNum, $msg, $other="")
$dumpParameters = str_replace("(\n","",print_r($_GET,true));
$dumpParameters = str_replace(")\n","",$dumpParameters);
+ // Ecriture dans le fichier.
fwrite($file,"\nErreur n° ".$errNum);
fwrite($file," : ".$msg);
if(!empty($other))
@@ -52,9 +52,9 @@ function main()
$action = $_GET['action'];
- if ($action != 3 && (!$loginIsOk)) {
+ if ($action != 3 && (!$loginIsOk))
throw new Exception("Vous n'êtes pas connecté.", 10);
- }
+
if ($action == 3) {
echo json_encode(
Array(
@@ -67,9 +67,9 @@ function main()
if ($action == 2) { // "Create partie"
// Requête POST : http://serveur/server.php?action=2&nb=2&mode=normal&user=foo&passwd=bar
- if (!isset($_GET['nb']) || !isset($_GET['mode'])) {
+ if (!isset($_GET['nb']) || !isset($_GET['mode']))
throw new Exception("La requête est incomplète", 2);
- }
+
createGame(intval($_GET['nb']), $_GET['mode']);
echo '{"success":1}';
}
@@ -79,9 +79,9 @@ function main()
}
else if($action == 1) { // "Set partie"
// Requête POST : http://serveur/server.php?action=1&mode=normal&user=foo&passwd=bar&gid=1234&pgid=12357&0=0&1=-1&2=22&3=13&9=-1
- if (!isset($_GET['pgid']) || !isset($_GET['gid']) || !isset($_GET['answers'])) {
+ if (!isset($_GET['pgid']) || !isset($_GET['gid']) || !isset($_GET['answers']))
throw new Exception("La requête est incomplète", 2);
- }
+
setGameGetScore($user, $_GET['pgid'], $_GET['gid'], $_GET['answers']);
} else if($action == 4) { // CheckWord
if (!isset($_GET['word']))
@@ -93,7 +93,7 @@ function main()
echo "false";
}
else if($action == 5) { // Get relations (JSON)
- echo getGameRelationsJSON();
+ echo getGameRelations();
}
else if($action == 6) {
if (!isset($_GET['game']))
@@ -105,6 +105,7 @@ function main()
} elseif ($action == 8) { // Set user pref
if (!isset($_GET['key']) || !isset($_GET['value']))
throw new Exception("La requête est incomplète", 2);
+
setUserPref($user, $_GET['key'], $_GET['value']);
userPrefs($user);
} else {
@@ -119,7 +120,9 @@ function server() {
} else {
header("Content-Type: application/json; charset=utf-8");
}
+
ob_start();
+
try {
main();
ob_end_flush();
@@ -132,6 +135,7 @@ function server() {
"isError" => true
)
);
+
logError($e->getCode(), $e->getMessage(), date("c"));
closeDB();
}
@@ -141,4 +145,4 @@ function server() {
server();
-?>
-\ No newline at end of file
+?>