From d8eac0035f97a64371557e7da8b9730fe28d8788 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sun, 29 Jul 2007 18:54:14 -0700 Subject: [PATCH] LAYOUT: address game by session.gamenr don't use gameid, but use session.gamenumber instead. needs this for tournaments later. new games will get a session number now by default. --- db.php | 13 +++++++++++++ index.php | 51 +++++++++++++++++++++++++++------------------------ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/db.php b/db.php index 41e4479..867be16 100644 --- a/db.php +++ b/db.php @@ -902,4 +902,17 @@ function DB_get_partner_hash_by_hash($hash) return NULL; } +function DB_format_gameid($gameid) +{ + $session = DB_get_session_by_gameid($gameid); + + /* get number of game */ + $result = mysql_query("SELECT COUNT(*),create_date FROM Game WHERE session='$session' ". + " GROUP by session". + " HAVING TIMEDIFF(create_date, (SELECT create_date FROM Game WHERE id='$gameid'))<=0"); + $r = mysql_fetch_array($result,MYSQL_NUM); + + return $session.".".$r[0]; +} + ?> \ No newline at end of file diff --git a/index.php b/index.php index c8c8804..71d4050 100644 --- a/index.php +++ b/index.php @@ -102,9 +102,12 @@ else if(myisset("new")) DB_close(); exit(); }; + /* get max session */ + $max = DB_get_max_session(); + $max++; mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ". - "'$ruleset',NULL ,NULL)"); + "'$ruleset','$max' ,NULL)"); } $game_id = mysql_insert_id(); @@ -187,19 +190,19 @@ else if(myisset("cancle","me")) if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */ { $message = "Hello, \n\n". - "Game $gameid has been cancled since nothing happend for a while and $myname requested it.\n"; + "Game ".DB_format_gameid($gameid)." has been cancled since nothing happend for a while and $myname requested it.\n"; $userids = DB_get_all_userid_by_gameid($gameid); foreach($userids as $user) { $To = DB_get_email_by_userid($user); - mymail($To,$EmailName."game $gameid cancled (timed out)",$message); + mymail($To,$EmailName."game ".DB_format_gameid($gameid)." cancled (timed out)",$message); } /* delete everything from the dB */ DB_cancel_game($me); - echo "

Game $gameid has been cancled.

"; + echo "

Game ".DB_format_gameid($gameid)." has been cancled.

"; } else echo "

You need to wait longer before you can cancle a game...

\n"; @@ -399,7 +402,7 @@ else if(myisset("me")) foreach($userids as $user) { $To = DB_get_email_by_userid($user); - mymail($To,$EmailName."game $gameid canceled",$message); + mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled",$message); } /* delete everything from the dB */ @@ -513,10 +516,10 @@ else if(myisset("me")) $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); if($userhash != $me) { - $message = "Everyone finish the questionary in game $gameid, ". + $message = "Everyone finish the questionary in game ".DB_format_gameid($gameid).", ". "please visit this link now to continue: \n". " ".$host."?me=".$userhash."\n\n" ; - mymail($To,$EmailName." finished setup in game $gameid",$message); + mymail($To,$EmailName." finished setup in game ".DB_format_gameid($gameid),$message); } }; }; @@ -610,7 +613,7 @@ else if(myisset("me")) foreach($userids as $user) { $To = DB_get_email_by_userid($user); - mymail($To,$EmailName."game $gameid canceled",$message); + mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled",$message); } /* delete everything from the dB */ @@ -786,7 +789,7 @@ else if(myisset("me")) $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:". " ".$host."?me=".$userhash."\n\n" ; - mymail($To,$EmailName." poverty (game $gameid)",$message); + mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } /* this user is done */ @@ -867,7 +870,7 @@ else if(myisset("me")) $message = "Someone has poverty, it's your turn to decide, ". "if you want to take the trump. Please visit:". " ".$host."?me=".$userhash."\n\n" ; - mymail($To,$EmailName." poverty (game $gameid)",$message); + mymail($To,$EmailName." poverty (game ".DB_format_gameid($gameid).")",$message); } } @@ -968,19 +971,19 @@ else if(myisset("me")) if($who==5 || $who==50) { $message = "Hello, \n\n". - "Game $gameid has been cancled since nobody wanted to take the trump.\n"; + "Game ".DB_format_gameid($gameid)." has been cancled since nobody wanted to take the trump.\n"; $userids = DB_get_all_userid_by_gameid($gameid); foreach($userids as $user) { $To = DB_get_email_by_userid($user); - mymail($To,$EmailName."game $gameid cancled (poverty not resolved)",$message); + mymail($To,$EmailName."game ".DB_format_gameid($gameid)." cancled (poverty not resolved)",$message); } /* delete everything from the dB */ DB_cancel_game($me); - echo "

Game $gameid has been cancled.

"; + echo "

Game ".DB_format_gameid($gameid)." has been cancled.

"; output_footer(); DB_close(); exit(); @@ -1010,9 +1013,9 @@ else if(myisset("me")) if($hash!=$me) { /* email startplayer) */ - $message = "It's your turn now in game $gameid.\n". + $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n". "Use this link to play a card: ".$host."?me=".$hash."\n\n" ; - mymail($email,$EmailName."ready, set, go... (game $gameid) ",$message); + mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message); } else echo " Please, start the game.
"; @@ -1099,7 +1102,7 @@ else if(myisset("me")) $firstcard = ""; /* first card in a trick */ echo "\n