X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=7ca77d6947428efa631e6c73ca23cb7a60529a5c;hp=c8c88041558c6b2e14903b5cd599ffb4b7155a83;hb=a7ab5e63c5558a72d5ca56f96b406dc41108cce9;hpb=d7c42361bda4c64a0594a8640156a504fc334f11 diff --git a/index.php b/index.php index c8c8804..7ca77d6 100644 --- a/index.php +++ b/index.php @@ -33,8 +33,15 @@ if(myisset("logout")) } else if(myisset("new")) { - $names = DB_get_all_names(); - output_form_for_new_game($names); + if( isset($_SESSION["name"]) ) + { + $names = DB_get_all_names(); + output_form_for_new_game($names); + } + else + { + echo "Please log in."; + } } /*check if everything is ready to set up a new game */ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","call" )) @@ -78,6 +85,23 @@ else if(myisset("new")) $session = DB_get_session_by_gameid($followup); $ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game, this way no manipulation is possible */ + + /* check if there is a game in pre or play mode, in that case do nothing */ + if( DB_is_session_active($session) > 0 ) + { + echo "

There is already a game going on in session $session, you can't start a new one

"; + output_footer(); + DB_close(); + exit(); + } + else if ( DB_is_session_active($session) < 0 ) + { + echo "

ERROR: status of session $session couldn't be determined.

"; + output_footer(); + DB_close(); + exit(); + } + if($session) mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',". "'$ruleset','$session' ,NULL)"); @@ -102,9 +126,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,23 +214,75 @@ 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"; } +/* send out a reminder */ +else if(myisset("remind","me")) + { + $me = $_REQUEST["me"]; + + /* test for valid ID */ + $myid = DB_get_userid_by_hash($me); + if(!$myid) + { + echo "Can't find you in the database, please check the url.
\n"; + echo "perhaps the game has been cancled, check by login in here."; + output_footer(); + DB_close(); + exit(); + } + + DB_update_user_timestamp($myid); + + /* get some information from the DB */ + $gameid = DB_get_gameid_by_hash($me); + $myname = DB_get_name_by_hash($me); + + /* check if game really is old enough */ + $result = mysql_query("SELECT mod_date,player,status from Game WHERE id='$gameid' " ); + $r = mysql_fetch_array($result,MYSQL_NUM); + if( (time()-strtotime($r[0]) > 60*60*24*7) && ($r[2]!='gameover') ) /* = 1 week */ + { + $name = DB_get_name_by_userid($r[1]); + $To = DB_get_email_by_userid($r[1]); + $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]); + + $message = "Hello $name, \n\n". + "It's your turn in game ".DB_format_gameid($gameid)." \n". + "Actually everyone else is waiting for you for more than a week now ;)\n\n". + "Please visit this link now to continue: \n". + " ".$host."?me=".$userhash."\n\n" ; + + if(DB_get_reminder($r[1],$gameid)>0) + { + echo "

An email has already been sent out.

\n"; + } + else + { + DB_set_reminder($r[1],$gameid); + mymail($To,$EmailName."Reminder: game ".DB_format_gameid($gameid)." it's your turn",$message); + + echo "

Game ".DB_format_gameid($gameid).": an email has been sent out.

"; + } + } + else + echo "

You need to wait longer before you can send out a reminder...

\n"; + } /* handle request from one specific player for one game, * (the hash is set on a per game base) */ else if(myisset("me")) @@ -275,63 +354,6 @@ else if(myisset("me")) /* put everyting in a form */ echo "
\n"; - /* output left menu */ - - display_user_menu(); - - /* output right menu */ - - /* display rule set for this game */ - echo "
\n"; - - if($gamestatus != 'pre') - echo " Gametype: $GT
\n"; - - echo "Rules:
\n"; - echo "10ofhearts : ".$RULES["dullen"] ."
\n"; - echo "schweinchen: ".$RULES["schweinchen"] ."
\n"; - echo "call: ".$RULES["call"] ."
\n"; - - echo "
\n"; - if($mystatus == 'play' ) - { - output_form_calls($me); - - echo "
\nA short comment:\n"; - echo "
"; - } - - echo "\n"; - - - if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' ) - { - echo "
\n"; - - $session = DB_get_session_by_gameid($gameid); - $result = mysql_query("SELECT id,create_date FROM Game". - " WHERE session=$session". - " ORDER BY create_date DESC". - " LIMIT 1"); - $r = -1; - if($result) - $r = mysql_fetch_array($result,MYSQL_NUM); - - if(!$session || $gameid==$r[0]) - { - /* suggest a new game with the same people in it, just rotated once (unless last game was solo) */ - $names = DB_get_all_names_by_gameid($gameid); - $type = DB_get_gametype_by_gameid($gameid); - - if($type=="solo") - output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid); - else - output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid); - } - } - - echo "
\n"; - /* output game */ /* output extra division in case this game is part of a session */ @@ -344,9 +366,9 @@ else if(myisset("me")) foreach($hashes as $hash) { if($hash == $me) - echo "$i "; + echo "$i \n"; else - echo "$i "; + echo "$i \n"; $i++; } echo "\n"; @@ -384,7 +406,7 @@ else if(myisset("me")) */ if( !myisset("in") ) { - echo "

You need to answer the question.

"; + echo "

You need to answer the question.

"; DB_set_hand_status_by_hash($me,'start'); } else @@ -399,7 +421,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 */ @@ -434,94 +456,109 @@ else if(myisset("me")) * unless a user tries to cheat ;) * can also happen if user reloads the page! */ - echo "

You need to answer the questions.

"; + echo "

You need to answer the questions.

"; DB_set_hand_status_by_hash($me,'init'); } else { - echo "Processing what you selected in the last step...
"; - - /* check if this sickness needs to be handled first */ - $gametype = DB_get_gametype_by_gameid($gameid); - $startplayer = DB_get_startplayer_by_gameid($gameid); - - if( $_REQUEST["solo"]!="No") + /* check if someone selected more than one vorbehalt */ + $Nvorbehalt = 0; + if($_REQUEST["solo"]!="No") $Nvorbehalt++; + if($_REQUEST["wedding"] == "yes") $Nvorbehalt++; + if($_REQUEST["poverty"] == "yes") $Nvorbehalt++; + if($_REQUEST["nines"] == "yes") $Nvorbehalt++; + + if($Nvorbehalt>1) + { + echo "

You selected more than one vorbehalt, please go back ". + "and answer the question again.

"; + DB_set_hand_status_by_hash($me,'init'); + } + else { - /* user wants to play a solo */ + echo "

Processing what you selected in the last step..."; - /* store the info in the user's hand info */ - DB_set_solo_by_hash($me,$_REQUEST["solo"]); - DB_set_sickness_by_hash($me,"solo"); + /* check if this sickness needs to be handled first */ + $gametype = DB_get_gametype_by_gameid($gameid); + $startplayer = DB_get_startplayer_by_gameid($gameid); - echo "
Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.
\n"; - - if($gametype == "solo" && $startplayer<$mypos) - {}/* do nothing, since someone else already is playing solo */ - else + if( $_REQUEST["solo"]!="No") { - /* this solo comes first - * store info in game table - */ - DB_set_gametype_by_gameid($gameid,"solo"); - DB_set_startplayer_by_gameid($gameid,$mypos); - DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]); - }; - } - else if($_REQUEST["wedding"] == "yes") - { - /* TODO: add silent solo somewhere*/ - echo "Ok, you don't want to play a silent solo...wedding was chosen.
\n"; - DB_set_sickness_by_hash($me,"wedding"); - } - else if($_REQUEST["poverty"] == "yes") - { - echo "Don't think you can win with just a few trump...? ok, poverty chosen
\n"; - DB_set_sickness_by_hash($me,"poverty"); - } - else if($_REQUEST["nines"] == "yes") - { - echo "What? You just don't want to play a game because you have a few nines? Well, if no one". - " is playing solo, this game will be canceled.
\n"; - DB_set_sickness_by_hash($me,"nines"); - } - - echo " Ok, done with checking, please go to the next step of the setup.
"; - - /* move on to the next stage*/ - DB_set_hand_status_by_hash($me,'poverty'); - - /* check if everyone has reached this stage, send out email */ - $userids = DB_get_all_userid_by_gameid($gameid); - $ok = 1; - foreach($userids as $user) - { - $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid); - if($userstat!='poverty' && $userstat!='play') + /* user wants to play a solo */ + + /* store the info in the user's hand info */ + DB_set_solo_by_hash($me,$_REQUEST["solo"]); + DB_set_sickness_by_hash($me,"solo"); + + echo "
Seems like you want to play a ".$_REQUEST["solo"]." solo. Got it.
\n"; + + if($gametype == "solo" && $startplayer<$mypos) + {}/* do nothing, since someone else already is playing solo */ + else + { + /* this solo comes first + * store info in game table + */ + DB_set_gametype_by_gameid($gameid,"solo"); + DB_set_startplayer_by_gameid($gameid,$mypos); + DB_set_solo_by_gameid($gameid,$_REQUEST["solo"]); + }; + } + else if($_REQUEST["wedding"] == "yes") { - $ok = 0; - DB_set_player_by_gameid($gameid,$user); + /* TODO: add silent solo somewhere*/ + echo "Ok, you don't want to play a silent solo...wedding was chosen.
\n"; + DB_set_sickness_by_hash($me,"wedding"); } - }; - if($ok) - { - /* reset player = everyone has to do something now */ - DB_set_player_by_gameid($gameid,NULL); - + else if($_REQUEST["poverty"] == "yes") + { + echo "Don't think you can win with just a few trump...? ok, poverty chosen
\n"; + DB_set_sickness_by_hash($me,"poverty"); + } + else if($_REQUEST["nines"] == "yes") + { + echo "What? You just don't want to play a game because you have a few nines? Well, if no one". + " is playing solo, this game will be canceled.
\n"; + DB_set_sickness_by_hash($me,"nines"); + } + + echo " Ok, done with checking, please go to the next step of the setup.

"; + + /* move on to the next stage*/ + DB_set_hand_status_by_hash($me,'poverty'); + + /* check if everyone has reached this stage, send out email */ + $userids = DB_get_all_userid_by_gameid($gameid); + $ok = 1; foreach($userids as $user) { - $To = DB_get_email_by_userid($user); - $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); - if($userhash != $me) + $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid); + if($userstat!='poverty' && $userstat!='play') { - $message = "Everyone finish the questionary in game $gameid, ". - "please visit this link now to continue: \n". - " ".$host."?me=".$userhash."\n\n" ; - mymail($To,$EmailName." finished setup in game $gameid",$message); + $ok = 0; + DB_set_player_by_gameid($gameid,$user); } }; + if($ok) + { + /* reset player = everyone has to do something now */ + DB_set_player_by_gameid($gameid,NULL); + + foreach($userids as $user) + { + $To = DB_get_email_by_userid($user); + $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); + if($userhash != $me) + { + $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 ".DB_format_gameid($gameid),$message); + } + }; + }; }; }; - break; case 'poverty': @@ -530,7 +567,8 @@ else if(myisset("me")) * set that one in the Game table * tell people about it. */ - echo "
Checking if someone else selected solo, nines, wedding or poverty.
"; + echo "
\n"; + echo "

Checking if someone else selected solo, nines, wedding or poverty.

"; /* check if everyone has reached this stage */ $userids = DB_get_all_userid_by_gameid($gameid); @@ -610,7 +648,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 +824,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 */ @@ -804,11 +842,11 @@ else if(myisset("me")) $result = mysql_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" ); /* add hidden button with trump in it to get to the next point */ - echo "
\n"; + echo "
\n"; echo " \n"; echo " \n"; echo " \n"; - echo "
\n"; + echo "
\n"; } else if(myisset("trump","exchange") && $_REQUEST["trump"]>0 && ($who==$mypos || $who==$mypos*10)) { @@ -867,7 +905,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); } } @@ -909,7 +947,7 @@ else if(myisset("me")) else { /* else show all trump, have lowest card pre-selected, have hidden setting for */ - echo "
you need to get rid of a few cards
\n"; + echo "
you need to get rid of a few cards
\n"; set_gametype($gametype); /* this sets the $CARDS variable */ $mycards = DB_get_hand($me); @@ -921,12 +959,12 @@ else if(myisset("me")) display_link_card($card,$PREF["cardset"],$type); echo " \n"; echo " \n"; - echo "\n"; + echo "
\n"; } } else if($who == $mypos || $who == $mypos*10) { - echo "
\n"; + echo "
\n"; foreach($userids as $user) { $name = DB_get_name_by_userid($user); @@ -944,7 +982,7 @@ else if(myisset("me")) } } echo "No,way I take those trump...
\n"; - echo "
\n"; + echo "
\n"; echo "Your cards are:
\n"; $mycards = DB_get_hand($me); @@ -968,19 +1006,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 +1048,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.
"; @@ -1020,6 +1058,7 @@ else if(myisset("me")) else echo "\n
"; } + echo "
\n"; break; case 'play': case 'gameover': @@ -1051,8 +1090,8 @@ else if(myisset("me")) /* has the game started? No, then just wait here...*/ if($gamestatus == 'pre') { - echo "You finished the setup, but not everyone else finished it... ". - "so you need to wait for the others. Just wait for the an email...
"; + echo "

You finished the setup, but not everyone else finished it... ". + "so you need to wait for the others. Just wait for the an email...

"; break; /* not sure this works... the idea is that you can * only play a card after everyone is ready to play */ } @@ -1099,7 +1138,7 @@ else if(myisset("me")) $firstcard = ""; /* first card in a trick */ echo "\n