X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=f212cf307096cd44c0c8d306de85c00ad5268958;hp=6807fa612c70560448d280a1807ca719be3d1a9f;hb=d1e0b371bfc49d0e6a73631621d7881e305f37e3;hpb=a96688595ffc3663a70754a3a194fc3eeefb5405 diff --git a/index.php b/index.php index 6807fa6..f212cf3 100644 --- a/index.php +++ b/index.php @@ -6,8 +6,10 @@ include_once("output.php"); /* html output only */ include_once("db.php"); /* database only */ include_once("functions.php"); /* the rest */ +/* make sure that user has set all variables in config.php */ config_check(); +/* open database */ if(DB_open()<0) { output_header(); @@ -17,13 +19,17 @@ if(DB_open()<0) exit(); } -/* start a session, if it is not already running */ +/* start a session, if it is not already running. + * This way people don't have to log in all the times. + * The session variables can also be read out from different + * php scripts, so that the code can be easily split up across several files + */ session_start(); /* done major error checking, output header of HTML page */ output_header(); -/* check if we want to start a new game */ +/* does the user want to log out? */ if(myisset("logout")) { session_unset(); @@ -32,9 +38,11 @@ if(myisset("logout")) echo "
"; } +/* check if we want to start a new game */ else if(myisset("new")) { output_status(); + /* user need to be logged in to do this */ if( isset($_SESSION["name"]) ) { $names = DB_get_all_names(); @@ -52,6 +60,7 @@ else if(myisset("new")) else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","call" )) { output_status(); + /* user needs to be logged in */ if( !isset($_SESSION["name"]) ) { echo " "; @@ -61,12 +70,13 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" /* get my name */ $name = $_SESSION["name"]; + /* the names of the four players */ $PlayerA = $_REQUEST["PlayerA"]; $PlayerB = $_REQUEST["PlayerB"]; $PlayerC = $_REQUEST["PlayerC"]; $PlayerD = $_REQUEST["PlayerD"]; - /* check if user is in the game */ + /* the person who sets up the game has to be one of the players */ if(!in_array($name,array($PlayerA,$PlayerB,$PlayerC,$PlayerD))) { echo " "; @@ -74,16 +84,19 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" DB_close(); exit(); } - + + /* what rules were selected */ $dullen = $_REQUEST["dullen"]; $schweinchen = $_REQUEST["schweinchen"]; $call = $_REQUEST["call"]; + /* get the emails addresses of the players */ $EmailA = DB_get_email_by_name($PlayerA); $EmailB = DB_get_email_by_name($PlayerB); $EmailC = DB_get_email_by_name($PlayerC); $EmailD = DB_get_email_by_name($PlayerD); + /* this is used to check if the player names are all ok */ if($EmailA=="" || $EmailB=="" || $EmailC=="" || $EmailD=="") { echo "couldn't find one of the names, please start a new game"; @@ -92,6 +105,7 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" exit(); } + /* get user ids */ $useridA = DB_get_userid_by_name($PlayerA); $useridB = DB_get_userid_by_name($PlayerB); $useridC = DB_get_userid_by_name($PlayerC); @@ -103,6 +117,7 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" /* create game */ $followup = NULL; + /* is this game a follow up in an already started session? */ if(myisset("followup") ) { $followup= $_REQUEST["followup"]; @@ -131,7 +146,7 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" "'$ruleset','$session' ,NULL)"); else { - /* get max session */ + /* get max session and start a new one */ $max = DB_get_max_session(); $max++; mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup)); @@ -139,7 +154,7 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" "'$ruleset','$max' ,NULL)"); } } - else + else /* no follow up, start a new session */ { /* get ruleset information or create new one */ $ruleset = DB_get_ruleset($dullen,$schweinchen,$call); @@ -210,7 +225,8 @@ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" echo " \n"; } - } /* end set up a new game */ + /* end set up a new game */ + } /* cancel a game, if nothing has happend in the last N minutes */ else if(myisset("cancel","me")) { @@ -235,7 +251,7 @@ else if(myisset("cancel","me")) $gameid = DB_get_gameid_by_hash($me); $myname = DB_get_name_by_hash($me); - /* check if game really is old enough */ + /* check if game really is old enough to be canceled */ $result = mysql_query("SELECT mod_date from Game WHERE id='$gameid' " ); $r = mysql_fetch_array($result,MYSQL_NUM); if(time()-strtotime($r[0]) > 60*60*24*30) /* = 1 month */ @@ -284,13 +300,13 @@ else if(myisset("remind","me")) $gameid = DB_get_gameid_by_hash($me); $myname = DB_get_name_by_hash($me); - /* check if game really is old enough */ + /* check if player hasn't done anything in a while */ $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]); + $To = DB_get_email_by_userid($r[1]); $userhash = DB_get_hash_from_gameid_and_userid($gameid,$r[1]); $message = "Hello $name, \n\n". @@ -299,6 +315,7 @@ else if(myisset("remind","me")) "Please visit this link now to continue: \n". " ".$HOST.$INDEX."?me=".$userhash."\n\n" ; + /* make sure we don't send too many reminders to one person */ if(DB_get_reminder($r[1],$gameid)>0) { echo "An email has already been sent out.
\n"; @@ -331,7 +348,8 @@ else if(myisset("me")) DB_close(); exit(); } - + + /* user might get here by clicking on the link in an email, so session might not be set */ if(isset($_SESSION["name"])) output_status($_SESSION["name"]); @@ -424,11 +442,13 @@ else if(myisset("me")) case 'start': if( !myisset("in") ) { + /* asks the player, if he wants to join the game */ output_check_want_to_play($me); break; } else { + /* check the result, if player wants to join, got next stage, else cancel game */ if($_REQUEST["in"] == "no") { /* cancel the game */ @@ -487,7 +507,7 @@ else if(myisset("me")) DB_set_player_by_gameid($gameid,$who); $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n". - "Use this link to play a card: ".$HOST.$INDEX."?me=".$hash."\n\n" ; + "Use this link to go the game: ".$HOST.$INDEX."?me=".$hash."\n\n" ; mymail($email,$EmailName."ready, set, go... (game ".DB_format_gameid($gameid).") ",$message); */ } @@ -1158,7 +1178,7 @@ else if(myisset("me")) if($gamestatus == 'pre') { echo " "; + "You need to wait for the others. Just wait for an email. "; break; /* not sure this works... the idea is that you can * only play a card after everyone is ready to play */ } @@ -1179,6 +1199,16 @@ else if(myisset("me")) DB_insert_comment($comment,$playid,$myid); }; + /* handle notes in case player didn't play a card, allow notes only during a game */ + if( (!myisset("card") && $mystatus=='play') ) + if(myisset("note")) + { + $note = $_REQUEST["note"]; + + if($note != "") + DB_insert_note($note,$gameid,$myid); + }; + /* get everything relevant to display the tricks */ $result = mysql_query("SELECT Hand_Card.card_id as card,". " Hand.position as position,". @@ -1406,7 +1436,20 @@ else if(myisset("me")) $winner = get_winner($play,$gametype); /* returns the position */ /* check if someone caught a fox */ - if(DB_get_gametype_by_gameid($gameid)!="solo") + /* first check if we should account for solos at all, + * since it doesn't make sense in some games + */ + $ok = 0; /* fox shouldn't be counted */ + if(DB_get_gametype_by_gameid($gameid)=="solo") + { + $solo = DB_get_solo_by_gameid($gameid); + if($solo == "trump" || $solo == "silent") + $ok = 1; /* for trump solos and silent solos, foxes are ok */ + } + else + $ok = 1; /* for all other games (not solos) foxes are ok too */ + + if($ok==1) foreach($play as $played) { if ( $played['card']==19 || $played['card']==20 ) @@ -1424,8 +1467,21 @@ else if(myisset("me")) " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')"); } } + /* check for karlchen (jack of clubs in the last trick)*/ - if(DB_get_gametype_by_gameid($gameid)!="solo" && $tricknr == 12) + /* same as for foxes, karlchen doesn't always make sense + * check what kind of game it is and set karlchen accordingly */ + $ok = 1; /* default: karlchen should be accounted for */ + if($tricknr != 12 ) + $ok = 0; /* Karlchen works only in the last trick */ + if($ok && DB_get_gametype_by_gameid($gameid)=="solo" ) + { + $solo = DB_get_solo_by_gameid($gameid); + if($solo == "trumpless" || $solo == "jack" || $solo == "queen" ) + $ok = 0; /* no Karlchen in these solos */ + } + + if($ok) foreach($play as $played) if ( $played['card']==11 || $played['card']==12 ) if ($played['pos'] == $winner ) @@ -1477,6 +1533,14 @@ else if(myisset("me")) DB_insert_comment($comment,$playid,$myid); }; + /* check for note */ + if(myisset("note")) + { + $note = $_REQUEST["note"]; + if($note != "") + DB_insert_note($note,$gameid,$myid); + }; + /* display played card */ $pos = DB_get_pos_by_hash($me); if($sequence==1) @@ -1743,6 +1807,38 @@ else if(myisset("me")) $message .= " Total Points (from the Re point of view): $Tpoint\n"; $message .= "\n"; + $session = DB_get_session_by_gameid($gameid); + $score = generate_score_table($session); + /* convert html to ascii */ + $score = str_replace("Session:
\n";
@@ -2196,21 +2310,18 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
if($r[4] != 'gameover')
{
echo "
\n"; - echo implode(", ",$names)."\n"; - echo "
\n\n"; + echo implode(", ",$names).",...\n"; + echo "
\n"; + + /* display last 5 users that logged on */ + $names = DB_get_names_of_last_logins(5); + echo "\n"; + echo implode(", ",$names).",...\n"; + echo "
\n"; + + echo "\n"; } } else @@ -2237,6 +2358,8 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) /* default login page */ else { + /* this outputs the default home page with some extra statistics on it */ + $pre[0]=0;$game[0]=0;$done[0]=0; $r=mysql_query("SELECT COUNT(id) FROM Game GROUP BY status"); if($r) {