commit ea110681043bb548d1cc240817097753166f7d63
parent 2bef9a20b0d4be0082555ad601de11a5524df3dd
Author: Yoann Bonavero <yoann.b87@voila.fr>
Date: Mon, 7 Feb 2011 09:36:43 +0100
Correction de bugs sur le serveur.
Diffstat:
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/code/serveur/dump2sqlite.sh b/code/serveur/dump2sqlite.sh
@@ -18,8 +18,9 @@ create table type_relation(name, num, extended_name, info);
create table user(login primary key, mail, hash_passwd, score);
create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty);
create table game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash);
-create table played_game(pgid integer primary key autoincrement, gid, login);
+create table played_game(pgid integer primary key autoincrement, gid, login, played);
create table played_game_cloud(pgid, gid, type, num, relation, weight, score);
+insert into user(login, mail, hash_passwd, score) values('foo', 'foo@isp.com', '$(echo -n 'bar' | md5sum | cut -d ' ' -f 1)', 0);
EOF
# tr : pour virer le CRLF qui traîne
diff --git a/code/serveur/php/pticlic.php b/code/serveur/php/pticlic.php
@@ -154,12 +154,12 @@ function cg_build_cloud($cloudSize, $sources, $sumWeights) {
}
function cg_insert($centerEid, $cloud, $r1, $r2, $totalDifficulty) {
+ global $db, $user;
// Insère dans la base une partie avec le mot central $centerEid, le nuage $cloud et les relations $r1 et $r2
- global $db;
$db->exec("begin transaction;");
$db->exec("insert into game(gid, eid_central_word, relation_1, relation_2, difficulty) values (null, $centerEid, $r1, $r2, $totalDifficulty);");
$gid = $db->lastInsertRowID();
- $db->exec("insert into played_game(pgid, gid, login, played) values (null, $gid, null, true);");
+ $db->exec("insert into played_game(pgid, gid, login, played) values (null, $gid, null, 1);");
$pgid = $db->lastInsertRowID();
foreach ($cloud as $c) {
$db->exec("insert into game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash) values($gid, ".$c['pos'].", ".$c['d'].", ".$c['eid'].", 2, ".$c['probaR1'].", ".$c['probaR2'].", ".$c['probaR0'].", ".$c['probaTrash'].");");
@@ -185,13 +185,13 @@ function random_game() {
}
function game2json($game_id) {
- global $db;
- $db->exec("INSERT INTO played_game(pgid, gid, login, played) VALUES (null, $game_id, ".SQLite3::escapeString($user).", false);");
+ global $db, $user;
+ $db->exec("INSERT INTO played_game(pgid, gid, login, played) VALUES (null, $game_id, '".SQLite3::escapeString($user)."', 0);");
$pgid = $db->lastInsertRowID();
// TODO Yoann : faire des tests d'erreur pour ces select ?
$game = $db->query("select gid, (select name from node where eid = eid_central_word) as name_central_word, eid_central_word, relation_1, relation_2 from game where gid = ".$game_id.";");
$game = $game->fetchArray();
- echo "{gid:".$gid.",pgid:$pgid,cat1:".$game['relation_1'].",cat2:".$game['relation_2'].",cat3:0,cat4:-1,";
+ echo "{gid:".$game_id.",pgid:$pgid,cat1:".$game['relation_1'].",cat2:".$game['relation_2'].",cat3:0,cat4:-1,";
echo "center:{id:".$game['eid_central_word'].",name:".json_encode("".$game['name_central_word'])."},";
echo "cloudsize:10,cloud:["; // TODO ! compter dynamiquement.
@@ -199,12 +199,13 @@ function game2json($game_id) {
$notfirst = false;
while ($x = $res->fetchArray()) {
if ($notfirst) { echo ","; } else { $notfirst=true; }
- echo "{id:".$x['eid_word'].",name:".$x['name_word']."}";
+ echo "{id:".$x['eid_word'].",name:".json_encode("".$x['name_word'])."}";
}
echo "]}";
}
function main($action) {
+ global $db, $user;
// Sinon tout est bon on effectu l'opération correspondant à la commande passée.
// TODO : en production, utiliser : header("Content-Type: application/json; charset=utf-8");
header("Content-Type: text/plain; charset=utf-8");
@@ -231,18 +232,18 @@ function main($action) {
}
echo "]";
} else if($action == 1) { // "Set partie"
- if (!isset($_GET['pgid']))
+ if (!isset($_GET['pgid']) || !isset($_GET['gid']))
mDie(2,"La requête est incomplète");
$pgid = intval($_GET['pgid']);
$gid = intval($_GET['gid']);
- if ($user != $db->querySingle("SELECT login FROM played_game WHERE pgid = $pgid and $gid = $gid and played = false;"))
+ if ($user != $db->querySingle("SELECT login FROM played_game WHERE pgid = $pgid and $gid = $gid and played = 0;"))
mDie(4,"Cette partie n'est associée à votre nom d'utilisateur, ou bien vous l'avez déjà jouée.");
$userReputation = log($db->querySingle("SELECT score FROM user WHERE login='".SQLite3::escapeString($user)."';"));
$db->exec("begin transaction;");
- $db->exec("update played_game set played = true where pgid = $pgid;");
+ $db->exec("update played_game set played = 1 where pgid = $pgid;");
$r0 = 0;
$trash = -1;
@@ -252,7 +253,7 @@ function main($action) {
$res = $db->query("SELECT num, difficulty, totalWeight, probaR1, probaR2, probaR0, probaTrash FROM game_cloud WHERE gid = $gid;");
while ($row = $res->fetchArray()) {
$num = $row['num'];
- $relanswer = intval($_GET['$i']);
+ $relanswer = intval($_GET[$row['num']]);
switch ($relanswer) {
case $r1: $answer = 0; $probaRx = "probaR1"; break;
case $r2: $answer = 1; $probaRx = "probaR2"; break;