commit a3bdaf90c0771e287950deaf9925778b4840fc82
parent b831fe6a7472e4cdf90484328570d6e32257fbbe
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date: Wed, 25 May 2011 22:41:08 +0200
Merge branch 'unstable' of https://github.com/jsmaniac/2011-m1s2-ter into unstable
Diffstat:
9 files changed, 157 insertions(+), 73 deletions(-)
diff --git a/code/serveur/dump2sqlite.sh b/code/serveur/dump2sqlite.sh
@@ -26,7 +26,7 @@ create table node(eid integer primary key autoincrement, name, type, weight);
create table relation(rid integer primary key autoincrement, start, end, type, weight);
create table type_node(name, num);
create table type_relation(name, num, extended_name, info);
-create table user(login primary key, mail, hash_passwd, score, ugroup);
+create table user(login primary key, mail, hash_passwd, score, ugroup, cgCount);
create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty, author, nb_like, nb_dislike);
create table game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash);
create table played_game(pgid, gid, login, timestamp, like, primary key(login, pgid));
@@ -37,8 +37,9 @@ create table random_cloud_node(eid,nbneighbors);
create table random_center_node(eid);
create table user_info(user, key, value, primary key (user, key));
-insert into user(login, mail, hash_passwd, score, ugroup) values('$(echo "$user" | sed -e "s/'/''/g")', 'foo@isp.com', '$(echo "$passwd" | dd bs=1 count="${#passwd}" | (if which md5sum >/dev/null 2>&1; then md5sum; else md5; fi) | cut -d ' ' -f 1)', 0, 1);
-insert into user(login, mail, hash_passwd, score, ugroup) values('bot', 'no mail', 'no password', 0, 1);
+insert into user(login, mail, hash_passwd, score, ugroup, cgCount) values('$(echo "$user" | sed -e "s/'/''/g")', 'foo@isp.com', '$(echo "$passwd" |
+dd bs=1 count="${#passwd}" | (if which md5sum >/dev/null 2>&1; then md5sum; else md5; fi) | cut -d ' ' -f 1)', 0, 1, 0);
+insert into user(login, mail, hash_passwd, score, ugroup, cgCount) values('bot', 'no mail', 'no password', 0, 1, 0);
EOF
# tr : pour virer le CRLF qui traîne
diff --git a/code/serveur/php/createGame.php b/code/serveur/php/createGame.php
@@ -102,7 +102,7 @@ if(!isset($_SESSION['userId']))
</head>
<body>
<?php include("ressources/menu.inc"); ?>
- <div class="content creategame">
+ <form class="content creategame">
<h2>Création de parties</h2>
<p>Cette page vous permet de créer des parties personalisées en indiquant les mots qui seront affiché pour un mot central.<br /><br />
<div id="errorDiv" class="message warning" style="display:none;"></div>
@@ -159,9 +159,7 @@ if(!isset($_SESSION['userId']))
</table>
</div>
<div id="button"></div>
- </div>
- <div id="templates" style="display:none">
- </div>
+ </form>
<?php include("ressources/footer.inc"); ?>
</body>
</html>
diff --git a/code/serveur/php/jeu.html b/code/serveur/php/jeu.html
@@ -128,8 +128,12 @@
</div>
<div id="score" class="screen">
<h1 class="fitFont" style="width:100%; height:8%; top: 6%; position:absolute; margin:0; text-align:center;">Score total : <span class="scoreTotal"></span></h1>
- <div class="scores fitFont" style="width:100%; height:62%; top:20%; position:absolute;"></div>
- <p class="fitFont" style="text-align: center; width:90%; height:12%; top:86%; left:5%; position:absolute; margin:0; padding:0;">
+ <div class="scores fitFont" style="width:100%; height:50%; top:20%; position:absolute;"></div>
+ <p class="fitFont" style="text-align: center; width:90%; height:12%; top:74%; left:5%; position:absolute; margin:0; padding:0;">
+ <a id="jaime" class="button" href="#frontpage" style="width40%; right:55%; position:absolute;">J'♥ cette partie</a>
+ <a id="jaimepas" class="button" href="#frontpage" style="width40%; left:55%; position:absolute;">J'♥ pas cette partie</a>
+ </p>
+ <p class="fitFont" style="clear:both; text-align: center; width:90%; height:12%; top:86%; left:5%; position:absolute; margin:0; padding:0;">
<a class="button" href="#frontpage">J'ai vu !</a>
</p>
</div>
diff --git a/code/serveur/php/ressources/backend.inc b/code/serveur/php/ressources/backend.inc
@@ -5,37 +5,39 @@ require_once("ressources/db.inc");
/* Les prototypes des fonctions :
-* ===============================>
-* checkLogin($user, $passwd);
-* randomCenterNode();
-* randomCloudNode();
-* cgBuildResultSets($cloudSize, $centerEid, $r1, $r2);
-* cgChooseRelations();
-* cgBuildCloud($centerEid, $cloudSize, $sources, $sumWeights);
-* insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty, $userName);
-* randomGameCore();
-* randomGame();
-* formatWord($word);
-* game2array($user, $pgid);
-* createGame($nbParties, $mode);
-* createGameCore($cloudSize);
-* computeScore($probas, $difficulty, $answer, $userReputation);
-* computeUserReputation($score);
-* normalizeProbas($row);
-* setGame($user, $pgid, $gid, $answers);
-* get_game_relations();
-* getGameRelationsJSON();
-* setGameGetScore($user, $pgid, $gid, $answers);
-* getNodeEid($node);
-* wordExist($node);
-* setUserInfo($user, $key, $value);
+*===============================>
+* checkLogin($user, $passwd);
+* randomCenterNode();
+* randomCloudNode();
+* cgBuildResultSets($cloudSize, $centerEid, $r1, $r2);
+* cgChooseRelations();
+* cgBuildCloud($centerEid, $cloudSize, $sources, $sumWeights);
+* insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty, $userName);
+* randomGameCore();
+* randomGame();
+* formatWord($word);
+* game2array($user, $pgid);
+* createGame($nbParties, $mode);
+* createGameCore($cloudSize);
+* computeScore($probas, $difficulty, $answer, $userReputation);
+* computeUserReputation($score);
+* normalizeProbas($row);
+* setGame($user, $pgid, $gid, $answers);
+* getGameRelations();
+* setGameGetScore($user, $pgid, $gid, $answers);
+* getNodeEid($node);
+* wordExist($node);
+* setUserInfo($user, $key, $value);
* userPrefsDefaults();
* userPrefs($user);
-* setUserPref($user, $key, $value);
+* setUserPref($user, $key, $value);
+* getJAimePgid($user, $pgid);
+* setJAimePgid($user, $pgid, $value);
+* addGameCreationBonus($user, $nb);
+* getNbGameCreationRemained($user);
*/
-
/* Les définitions
====================*/
@@ -354,7 +356,32 @@ function insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty, $user
*/
function randomGameCore() {
$db = getDB();
- return $db->querySingle("select gid from game where gid = (abs(random()) % (select max(gid) from game))+1 or gid = (select max(gid) from game where gid > 0) order by gid limit 1;");
+
+ $game = $db->query('SELECT gid,(nb_like - nb_dislike + 5 * (author != "bot")) AS coef FROM game');
+ $game = $game->fetchArray();
+
+ foreach($game as $g) {
+ if($g['coef'] < -5)
+ $g['coef'] = 0;
+ else
+ $g['coef'] += 5;
+
+ $sum += $g['coef'];
+ }
+
+ $game = rand(0,$sum);
+
+ foreach($game as $g) {
+ $count += $g['coef'];
+
+ if($count >= $randomValue)
+ return $g['gid'];
+ }
+
+ return 0;
+
+ // Ancienne requêtes de sélection.
+ //return $db->querySingle("select gid from game where gid = (abs(random()) % (select max(gid) from game))+1 or gid = (select max(gid) from game where gid > 0) order by gid limit 1;");
}
/** Sélection aléatoire d'une partie de la base de données parmis les parties à jouer.
@@ -711,4 +738,29 @@ function setUserPref($user, $key, $value) {
}
}
+function getJAimePgid($user, $pgid) {
+ getDB()->querySingle("SELECT like FROM played_game WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
+}
+
+function setJAimePgid($user, $pgid, $value) {
+ $value = intval($value) / abs(intval($value) || 1); // Calcule le signe de $value : -1 ou 0 ou 1
+ $original = getJAimePgid($user, $pgid);
+ getDB()->querySingle("UPDATE played_game SET like = ".$value." WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
+ getDB()->querySingle("UPDATE game SET nb_like = nb_like".($original == 1 ? " - 1" : "").($value == 1 ? " + 1" : "")." WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
+ getDB()->querySingle("UPDATE game SET nb_dislike = nb_dislike".($original == -1 ? " - 1" : "").($value == -1 ? " + 1" : "")." WHERE login = '".SQLite3::escapeString($user)."' and pgid = ".longStrVal($pgid).";");
+}
+
+function addGameCreationBonus($user, $nb) {
+ if($nb > 0) {
+ getDB()->exec('UPDATE user SET cgCount = cgCount + '.$ng.' WHERE user='.$user);
+ return true;
+ }
+
+ return false;
+}
+
+function getNbGameCreationRemained() {
+ return getDB()->querySingle('SELECT cgCount FROM user WHERE user='.$user);
+}
+
?>
diff --git a/code/serveur/php/ressources/createGame.js b/code/serveur/php/ressources/createGame.js
@@ -42,14 +42,14 @@ $(function() {
var updateRelationLabels = function() {
$('#relations option').each(function(i,e) {
- $(e).text(applyFormat($(e).data("format"), $('#centralWord').val() || 'mot central', '…'));
+ $(e).text(applyFormat($(e).data("format"), $('#centralWord').val().trim() || 'mot central', '…'));
});
$('.relationLabel').each(function(i,e) {
$(e).text(applyFormat(
$(e).data("format"),
- $('#centralWord').val() || 'mot central',
- $(e).closest('.wordLine').find('.word').val() || '…'));
+ $('#centralWord').val().trim() || 'mot central',
+ $(e).closest('.wordLine').find('.word').val().trim() || '…'));
});
}
@@ -92,26 +92,22 @@ $(function() {
$("#button").html('<input type="button" id="addLine" name="addLine" value="Ajouter" />');
$("#addLine").click(function(){ displayNWordLines(1); });
- $("#button").append('<input type="button" id="validate" name="validate" value="Valider" />');
- $("#validate").click(function(){ formOK(); });
+ $("#button").append('<input type="submit" id="validate" name="validate" value="Valider" />');
+ $("form").submit(formOK);
};
var checkWord = function () {
updateRelationLabels();
var input = $(this);
- var word = input.val();
+ var word = input.val().trim();
input.closest(".wordLine, #center").removeClass("valid invalid");
if (word != "") {
- $.ajax({
- type: "GET",
- url: "server.php?",
- data: "action=4&word="+word, //+"&user="+user+"&passwd="+passwd,
- success: function(msg){
- input.closest(".wordLine, #center").addClass(msg == false ? "invalid" : "valid");
- wordsOK[input.attr("id")] = !(msg == false);
- }});
+ $.getJSON("server.php",{action:4,word:word}, function(msg){
+ input.closest(".wordLine, #center").addClass(msg ? "valid" : "invalid");
+ wordsOK[input.attr("id")] = !(msg == false);
+ });
}
};
@@ -120,7 +116,7 @@ $(function() {
if ($("#relation1").val() == $("#relation2").val())
displayError("Les deux relation doivent être différents");
- else if ($("#centralWord").val() == "")
+ else if ($("#centralWord").val().trim() == "")
displayError("Le mot central doit être renseigné.");
else if (badWord())
displayError("Il existe des mots incorrects");
@@ -146,7 +142,7 @@ $(function() {
var badWord = function() {
for (word in wordsOK)
- if ($("#"+word).val() != "" && wordsOK[word] == false)
+ if ($("#"+word).val().trim() != "" && wordsOK[word] == false)
return true;
return false;
@@ -167,13 +163,13 @@ $(function() {
var exit;
var cloud = "";
- exit = {center:$("#centralWord").val(),
+ exit = {center:$("#centralWord").val().trim(),
relations:[$("#relation1").val(),$("#relation2").val(),0,-1],
cloud:[]};
for(i=1;i<numWord;i++) {
exit.cloud.push({
- name:$("#word-"+i).val(),
+ name:$("#word-"+i).val().trim(),
relations:[
$("#r1-"+i).is(":checked") ? "1":"0",
$("#r2-"+i).is(":checked") ? "1":"0",
@@ -183,9 +179,9 @@ $(function() {
});
}
- $.get("server.php",{action:"6",game:exit},function (data) {
+ $.getJSON("server.php",{action:6,game:exit},function (data) {
//$(".word").closest(".wordLine, #center").removeClass("valid invalid");
- if(data == true) {
+ if(data === true) {
displaySuccess("La partie à bien été enregistrée");
$('#newCreationLink').show();
$('#center').hide();
@@ -193,22 +189,25 @@ $(function() {
$('#wordLines').hide();
$('#button').hide();
}
- else if (data == false) {
+ else if (data === false) {
$('input').removeAttr('disabled');
displayError("Le nuage doit contenir au moins "+nbWordMin+" mots valides.");
}
- else if (data != true) {
+ else if (data.length) {
$('input').removeAttr('disabled');
- var that = $(this);
-
-
- $.each(data,function(i,e) {
+
+ $.each(data,function(i,bad) {
$('.word')
- .filter(function() { return that.val() == e; })
+ .removeClass("invalid")
+ .addClass("valid")
+ .filter(function(i,w) { return $(w).val().trim() == bad; })
.closest(".wordLine, #center")
- .removeClass("valid invalid")
+ .removeClass("valid")
.addClass("invalid");
});
+ } else {
+ $('input').removeAttr('disabled');
+ displayError("Une erreur inconnue est survenue. 42.");
}
});
diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
@@ -4,6 +4,7 @@ function init(fn) {
}
$.ajaj = function(url, data, dfd, retryCheck, callback) {
+ dfd = dfd || $.Deferred();
var user = '' + UI().getPreference("user");
var passwd = '' + UI().getPreference("passwd");
user = runstate.user || user;
@@ -312,6 +313,7 @@ init(function() {
if (updating) return false;
updating = true;
if (!runstate.game || state.pgid != runstate.game.pgid) {
+ updating = false;
$('#game').trigger('goto');
return;
}
@@ -363,6 +365,14 @@ runstate.scoreCache = new Cache(function getScore(k, dfd, arg) {
}, dfd, function() { return state.pgid == k; });
});
+function jAime(aime) {
+ $.ajaj('server.php?callback=?', {
+ pgid: state.pgid,
+ action: 10,
+ value: (aime ? 1 : -1)
+ });
+}
+
init(function() {
var score = $.screen('score');
score.bind('pre-enter', function() {
@@ -386,6 +396,8 @@ init(function() {
.appendTo("#score .scores");
});
});
+ $('#jaime').click(function() { jAime(true); });
+ $('#jaimepas').click(function() { jAime(false); });
});
// ==== Écran Préférences
diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php
@@ -111,10 +111,25 @@ function main()
setUserPref($user, $_GET['key'], $_GET['value']);
userPrefs($user);
- } elseif ($action == 9) {
+ }
+ elseif ($action == 9) {
session_destroy();
echo '{"disconnected":true}';
- } else {
+ }
+ elseif ($action == 10) { // Set J'aime / J'aime pas
+ if (!isset($_GET['value']) || !isset($_GET['pgid']))
+ throw new Exception("La requête est incomplète", 2);
+
+ setJAimePgid($user, $_GET['pgid'], intval($_GET['value']));
+ echo '{"JAimePas":true}';
+ }
+ elseif ($action == 11) { // bonus création de parties
+ if (!isset($_GET['value']))
+ throw new Exception("La requête est incomplète", 2);
+
+ addGameCreationBonus($user, $_GET['value']);
+ }
+ else {
throw new Exception("Commande inconnue", 2);
}
}
diff --git a/code/serveur/php/signup.php b/code/serveur/php/signup.php
@@ -79,10 +79,10 @@ if(isset($_POST['signuppswd2'])){
if(count($msg) == 0 && $newpage == false)
{
- $ok = ($db->query("INSERT INTO user(mail, login, hash_passwd, score, ugroup) VALUES ('" . SQLite3::escapeString($signupemail)
+ $ok = ($db->query("INSERT INTO user(mail, login, hash_passwd, score, ugroup, sgCount) VALUES ('" . SQLite3::escapeString($signupemail)
. "', '" . SQLite3::escapeString($signupid)
. "', '" . SQLite3::escapeString(md5($signuppswd1))
- . "', 0, 1);"));
+ . "', 0, 1, 0);"));
if($ok == true) {
$_SESSION['userId'] = $signupid;
diff --git a/presentation/presentation.tex b/presentation/presentation.tex
@@ -473,6 +473,7 @@ Inconvénient~: on n'introduit pas de nouvelles relations sémantiques spécifiq
\end{frame}
\begin{frame}
+ \frametitle{Création manuelle de parties}
\large Quel intérêt pour les joueurs ?
\begin{itemize}
@@ -483,12 +484,14 @@ Inconvénient~: on n'introduit pas de nouvelles relations sémantiques spécifiq
\end{itemize}
\end{frame}
+\section{Site Internet}
\begin{frame}
- \large Un site internet, pourquoi faire ?
-\newline \\
- \large Que peut-on y trouver ?
-\newline \\
- \large Jouez directement sur le site !
+ \frametitle{Le site Internet}
+ \large Un site internet, pourquoi faire ?
+ \newline \\
+ \large Que peut-on y trouver ?
+ \newline \\
+ \large Jouez directement sur le site !
\end{frame}
\section{Demonstration}