From 2e45b48173b69b17e06df8f2e0dd338e8ff8ef64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Georges=20Dup=C3=A9ron?=
Date: Sat, 7 May 2011 22:48:20 +0200
Subject: [PATCH 1/2] =?UTF-8?q?Une=20partie=20du=20travail=20n=C3=A9cessai?=
=?UTF-8?q?re=20=C3=A0=20l'=C3=A9cran=20pr=C3=A9f=C3=A9rences.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
code/serveur/dump2sqlite.sh | 1 +
code/serveur/php/jeu.html | 27 +++++--------------
code/serveur/php/ressources/backend.inc | 31 +++++++++++++++++++++
code/serveur/php/ressources/black.css | 36 +++++++++++++++++++++++++
code/serveur/php/ressources/green.css | 36 +++++++++++++++++++++++++
code/serveur/php/ressources/pticlic.js | 19 ++++++++-----
code/serveur/php/server.php | 7 ++++-
7 files changed, 129 insertions(+), 28 deletions(-)
create mode 100644 code/serveur/php/ressources/black.css
create mode 100644 code/serveur/php/ressources/green.css
diff --git a/code/serveur/dump2sqlite.sh b/code/serveur/dump2sqlite.sh
index 584874e..6da7ed6 100755
--- a/code/serveur/dump2sqlite.sh
+++ b/code/serveur/dump2sqlite.sh
@@ -34,6 +34,7 @@ create table played_game_cloud(pgid, gid, type, num, relation, weight, score);
create table colon_nodes(eid);
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);
EOF
diff --git a/code/serveur/php/jeu.html b/code/serveur/php/jeu.html
index 0b8d6db..e74a46f 100644
--- a/code/serveur/php/jeu.html
+++ b/code/serveur/php/jeu.html
@@ -5,41 +5,27 @@
+
diff --git a/code/serveur/php/ressources/backend.inc b/code/serveur/php/ressources/backend.inc
index 123093e..c96fd57 100644
--- a/code/serveur/php/ressources/backend.inc
+++ b/code/serveur/php/ressources/backend.inc
@@ -766,4 +766,35 @@ function wordExist($node) {
return getNodeEid($node) === null ? "0" : "1";
}
+
+function getUserInfo($user, $key) {
+ return getdb()->querySingle("SELECT value FROM user_info WHERE user = '".sqlite3::escapestring($user)."' AND key = '".SQLite3::escapeString($key)."';");
+}
+
+function setUserInfo($user, $key, $value) {
+ getDB()->exec("UPDATE user_info SET value = '".SQLite3::escapeString($value)
+ ."' WHERE user = '".SQLite3::escapeString($user)
+ ."' AND key = '".SQLite3::escapeString($key)."';");
+}
+
+function userPrefsDefaults() {
+ $prefs = Array(
+ "theme" => "green"
+ );
+}
+
+function userPrefs($user) {
+ $res = userPrefsDefaults();
+ foreach ($res as $k => &$v) {
+ $x = getUserInfo($user, $k);
+ if ($x !== null) $v = $x;
+ }
+ echo json_encode($res);
+}
+
+function setUserPref($user, $key, $value) {
+ if (array_key_exists($key, userPrefsDefaults()))
+ setUserInfo($user, $key, $value);
+}
+
?>
\ No newline at end of file
diff --git a/code/serveur/php/ressources/black.css b/code/serveur/php/ressources/black.css
new file mode 100644
index 0000000..b433c1b
--- /dev/null
+++ b/code/serveur/php/ressources/black.css
@@ -0,0 +1,36 @@
+/* Colors */
+
+html, body {
+ background-color: black;
+ color: white;
+}
+
+.screen {
+ background-color: black;
+}
+
+#splash.screen {
+ background-color: black;
+}
+
+#mc-caption {
+ color: white;
+}
+
+#mn-caption {
+ color: white;
+}
+
+#mn-caption-block {
+ border-color: #aaaaaa;
+ background-color: #222222;
+}
+
+.relationBox {
+ border-color: #cccccc;
+ background-color: #222222;
+}
+
+.relations .hot {
+ background-color: #cccccc;
+}
diff --git a/code/serveur/php/ressources/green.css b/code/serveur/php/ressources/green.css
new file mode 100644
index 0000000..3d0f68e
--- /dev/null
+++ b/code/serveur/php/ressources/green.css
@@ -0,0 +1,36 @@
+/* Colors */
+
+html, body {
+ background-color: black;
+ color: black;
+}
+
+.screen {
+ background-color: #FFFFE0;
+}
+
+#splash.screen {
+ background-color: black;
+}
+
+#mc-caption {
+ color: #8b4;
+}
+
+#mn-caption {
+ color: #4a4;
+}
+
+#mn-caption-block {
+ border-color: #44AA44;
+ background-color: #F0F8D0;
+}
+
+.relationBox {
+ border-color: #44AA44;
+ background-color: #F0F8D0;
+}
+
+.relations .hot {
+ background-color: yellow;
+}
diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
index 6fe32f9..e0fb3e2 100644
--- a/code/serveur/php/ressources/pticlic.js
+++ b/code/serveur/php/ressources/pticlic.js
@@ -1,4 +1,6 @@
// ==== URL persistante
+var nullFunction = function(){};
+
function State(init) {
try {
$.extend(this, init || {});
@@ -109,6 +111,7 @@ function UI () {
window.console && console.log(msg);
} catch(e) {alert("Error UI.log");alert(e);}
},
+ info: function(title, msg) { alert(msg); },
setScreen: function() {}
};
}
@@ -173,7 +176,7 @@ ajaj.bigError = function(x) {
ajaj.error = function(msg) {
try {
UI().dismiss();
- alert(msg);
+ UI().info("Erreur !", msg);
UI().exit();
} catch(e) {alert("Error ajaj.error");alert(e);}
}
@@ -277,6 +280,7 @@ frontpage.jss = function(w, h, iconSize) {
frontpage.enter = function () {
try {
if (location.hash != '') state.commit();
+ console.log("fubar");
$("#frontpage .frontpage-button.game").clickOnce(frontpage.click.goGame);
$("#frontpage .frontpage-button.connection").clickOnce(frontpage.click.goConnection);
$("#frontpage .frontpage-button.info").clickOnce(frontpage.click.goInfo);
@@ -288,6 +292,7 @@ frontpage.enter = function () {
frontpage.click = {};
frontpage.click.goGame = function(){
try {
+ console.log("goGame");
state.set('screen', 'game').validate();
} catch(e) {alert("Error frontpage.click.goGame");alert(e);}
};
@@ -364,7 +369,7 @@ game.jss = function(w, h, iconSize) {
game.enter = function () {
try {
if (!state.game) {
- var notAlreadyFetching = !runstate.gameFetched;
+ var notAlreadyFetching = !runstate.gameFetched || runstate.gameFetched == nullFunction;
runstate.gameFetched = function(data) {
try {
state.game = data;
@@ -396,7 +401,7 @@ game.leave = function () {
try {
$("#game .relations").empty();
$('#game #mn-caption').stop().clearQueue();
- if (runstate.gameFetched) runstate.gameFetched = function() {};
+ if (runstate.gameFetched) runstate.gameFetched = nullFunction;
} catch(e) {alert("Error game.leave");alert(e);}
};
@@ -496,7 +501,7 @@ score.jss = function(w, h, iconSize) {
score.enter = function () {
try {
if (!state.hasScore) {
- var notAlreadyFetching = !runstate.scoreFetched;
+ var notAlreadyFetching = !runstate.scoreFetched || runstate.scoreFetched == nullFunction;
runstate.scoreFetched = function(data) {
try {
for (var i = 0; i < data.scores.length; ++i) {
@@ -534,7 +539,7 @@ score.enter = function () {
score.leave = function () {
try {
- if (runstate.scoreFetched) runstate.scoreFetched = function() {};
+ if (runstate.scoreFetched) runstate.scoreFetched = nullFunction;
$("#score .scores").empty();
$("#templates .scoreTotal").empty();
} catch(e) {alert("Error score.leave");alert(e);}
@@ -625,9 +630,9 @@ connection.connect = function() {
connection.connectFetched = function(data) {
try {
if (data && data.loginOk) {
- alert("Vous êtes connecté !");
+ UI().info("Connexion", "Vous êtes connecté !");
} else if (data && data.isError && data.error == 3) {
- alert(data.msg);
+ UI().info("Connexion", data.msg);
} else {
ajaj.smallError(data);
}
diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php
index 0c836cf..55632e6 100644
--- a/code/serveur/php/server.php
+++ b/code/serveur/php/server.php
@@ -104,10 +104,15 @@ function main()
throw new Exception("La requête est incomplète", 2);
decodeAndInsertGame($user,$_GET['game']);
+ } elseif ($action == 7) { // Get user prefs
+ userPrefs($user);
+ } 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']);
} else {
throw new Exception("Commande inconnue", 2);
}
- // Attention, il y a une $action == 7, mais plus haut.
}
function server() {
From fdc1a3315b4fb9c2486d004d3cad0098e92eab3b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Georges=20Dup=C3=A9ron?=
Date: Sat, 7 May 2011 23:28:29 +0200
Subject: [PATCH 2/2] =?UTF-8?q?Suite=20de=20l'=C3=A9cran=20des=20pr=C3=A9f?=
=?UTF-8?q?=C3=A9rences.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
code/serveur/php/jeu.html | 11 ++++
code/serveur/php/ressources/pticlic.js | 78 +++++++++++++++++++++-----
2 files changed, 75 insertions(+), 14 deletions(-)
diff --git a/code/serveur/php/jeu.html b/code/serveur/php/jeu.html
index e74a46f..f5a0038 100644
--- a/code/serveur/php/jeu.html
+++ b/code/serveur/php/jeu.html
@@ -124,6 +124,17 @@ html, body {
+
+
+

diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
index e0fb3e2..86415b7 100644
--- a/code/serveur/php/ressources/pticlic.js
+++ b/code/serveur/php/ressources/pticlic.js
@@ -280,10 +280,10 @@ frontpage.jss = function(w, h, iconSize) {
frontpage.enter = function () {
try {
if (location.hash != '') state.commit();
- console.log("fubar");
$("#frontpage .frontpage-button.game").clickOnce(frontpage.click.goGame);
$("#frontpage .frontpage-button.connection").clickOnce(frontpage.click.goConnection);
$("#frontpage .frontpage-button.info").clickOnce(frontpage.click.goInfo);
+ $("#frontpage .frontpage-button.prefs").clickOnce(frontpage.click.goPrefs);
jss();
UI().dismiss();
} catch(e) {alert("Error frontpage.enter");alert(e);}
@@ -292,7 +292,6 @@ frontpage.enter = function () {
frontpage.click = {};
frontpage.click.goGame = function(){
try {
- console.log("goGame");
state.set('screen', 'game').validate();
} catch(e) {alert("Error frontpage.click.goGame");alert(e);}
};
@@ -311,6 +310,12 @@ frontpage.click.goInfo = function() {
} catch(e) {alert("Error frontpage.click.goInfo");alert(e);}
};
+frontpage.click.goPrefs = function() {
+ try {
+ UI().show("PtiClic", "Chargement…");
+ state.set('screen', 'prefs').commit().validate();
+ } catch(e) {alert("Error frontpage.click.goPrefs");alert(e);}
+};
// ==== Code métier pour le jeu
game = {};
@@ -590,12 +595,8 @@ connection.jss = function(w, h, iconSize) {
} catch(e) {alert("Error anonymous 1 in connection.jss");alert(e);}
};
- (c)
- .css('text-align', 'center');
-
- $c("label")
- .css("white-space", "nowrap");
$c("input, label")
+ .css("white-space", "nowrap")
.css('position', 'absolute')
.fitFont(w*0.3, h*0.25);
$c("#user-label").east({left:w/2,top:h*0.25});
@@ -608,8 +609,8 @@ connection.jss = function(w, h, iconSize) {
connection.enter = function() {
try {
- jss();
$("#connect-form").unbind("submit", connection.connect).submit(connection.connect);
+ jss();
UI().dismiss();
} catch(e) {alert("Error connection.enter");alert(e);}
};
@@ -623,7 +624,7 @@ connection.connect = function() {
user: $("#user").val(),
passwd: $("#passwd").val(),
}, connection.connectFetched, connection.connectFetched);
- return false
+ return false;
} catch(e) {alert("Error connection.connect");alert(e);}
}
@@ -653,12 +654,61 @@ info.jss = function(w,h,iconSize) {
info.enter = function() {
try {
+ $("#info-back").clickOnce(info.click.goBack);
jss();
- $("#info-back").clickOnce(function(){
- try {
- state.set('screen', 'frontpage').validate();
- } catch(e) {alert("Error anonymous in info.enter");alert(e);}
- });
UI().dismiss();
} catch(e) {alert("Error info.enter");alert(e);}
};
+
+info.click = {};
+info.click.goBack = function(){
+ try {
+ state.set('screen', 'frontpage').validate();
+ } catch(e) {alert("Error anonymous in info.enter");alert(e);}
+};
+
+// ==== Code métier pour la page de configuration
+prefs = {};
+
+prefs.jss = function(w,h,iconSize) {
+ try {
+ var p = $("#prefs.screen");
+ var $p = function() {
+ try {
+ return p.find.apply(p,arguments);
+ } catch(e) {alert("Error anonymous 1 in prefs.jss");alert(e);}
+ };
+
+ $("input, label, select")
+ .css("white-space", "nowrap")
+ .css('position', 'absolute')
+ .fitFont(w*0.4, h*0.1);
+ $p("#theme-label").east({left:w/2,top:h*0.25});
+ $p("#theme").west({left:w/2,top:h*0.25});
+ $p("#prefs-cancel").east({left:w*0.45,top:h*0.5});
+ $p("#prefs-apply").west({left:w*0.55,top:h*0.5});
+ } catch(e) {alert("Error prefs.jss");alert(e);}
+}
+
+prefs.enter = function() {
+ try {
+ $("#prefs-form").unbind('submit', prefs.apply).submit(prefs.apply);
+ $("#prefs-cancel").clickOnce(prefs.cancel);
+ jss();
+ UI().dismiss();
+ } catch(e) {alert("Error prefs.enter");alert(e);}
+};
+
+prefs.apply = function(){
+ try {
+ alert($("#theme").val());
+ state.set('screen', 'frontpage').validate();
+ return false;
+ } catch(e) {alert("Error anonymous in prefs.click.apply");alert(e);}
+};
+
+prefs.cancel = function(){
+ try {
+ state.set('screen', 'frontpage').validate();
+ } catch(e) {alert("Error anonymous in prefs.click.cancel");alert(e);}
+};