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 "
You are now logged out!
\n". "(This will take you back to the home-page)
"; } +/* 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 "
Please log in.
"; @@ -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 "
You need to be one of the players to start a new game.
"; @@ -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 "
You started a new game. The emails have been sent out!
\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 finished the setup, but not everyone else finished it... ". - "so you need to wait for the others. Just wait for the an email...

"; + "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("
\n\n \n","",$score); + $score = str_replace("
\n","",$score); + $score = str_replace("\n","",$score); + $score = str_replace(array("","","",""),array("","\n","","|"),$score); + $score = explode("\n",$score); + + $header = array_slice($score,0,1); + $header = explode("|",$header[0]); + for($i=0;$i5) $header.= " ... \n"; + + if(sizeof($score)>5) $score = array_slice($score,-5,5); + for($i=0;$i\n"; /* end ul tricks*/ + echo "
Personal notes:
\n"; + $notes = DB_get_notes_by_userid_and_gameid($myid,$gameid); + foreach($notes as $note) + echo "$note
\n"; + echo "Insert note:\n"; + echo "
\n"; + $mycards = DB_get_hand($me); $mycards = mysort($mycards,$gametype); echo "
\n"; @@ -1982,7 +2085,6 @@ else if(myisset("me")) echo "
\n"; - echo "\n"; output_footer(); DB_close(); @@ -2004,8 +2106,10 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) $password = DB_get_passwd_by_name($name); }; + /* user has forgotten his password */ if(myisset("forgot")) { + /* check if player is in the database */ $ok = 1; $myid = DB_get_userid_by_email($email); @@ -2027,6 +2131,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) echo "The new password will be valid for one day, make sure you reset it to something else.
"; echo "Back to the main page."; + /* create temporary password, use the fist 8 letters of a md5 hash */ $TIME = (string) time(); /* to avoid collisions */ $hash = md5("Anewpassword".$email.$TIME); $newpw = substr($hash,1,8); @@ -2039,28 +2144,33 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) " also still be valid until you set a new one\n"; mymail($email,$EmailName."recovery ",$message); + /* we save these in the database */ DB_set_recovery_password($myid,md5($newpw)); } else { + /* make it so that people (or a robot) can request thousands of passwords within a short time + * and spam a user this way */ echo "Sorry you already tried 5 times during the last 24h.
". "You need to use one of those passwords or wait to get a new one.
"; echo "Back to the main page."; } } else - { + {/* can't find user id in the database */ + + /* no email given? */ if($email=="") echo "You need to give me an email address!
". "Please try again."; - else + else /* default error message */ echo "Couldn't find a player with this email!
". "Please contact Arun, if you think this is a mistake
". "or else try again."; } } - else - { + else + { /* normal user page */ /* verify password and email */ if(strlen($password)!=32) $password = md5($password); @@ -2072,12 +2182,14 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) if($ok) { + /* user information is ok */ $myname = DB_get_name_by_email($email); $_SESSION["name"] = $myname; output_status(); DB_get_PREF($myid); + /* does the user want to change some preferences? */ if(myisset("setpref")) { $setpref=$_REQUEST["setpref"]; @@ -2109,6 +2221,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) break; } } + /* user wants to change his password or request a temporary one */ else if(myisset("passwd")) { if( $_REQUEST["passwd"]=="ask" ) @@ -2155,6 +2268,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) display_user_menu(); + /* display all games the user has played */ echo "
"; echo "

These are all your games:

\n"; echo "

Session:
\n"; @@ -2196,21 +2310,18 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) if($r[4] != 'gameover') { echo "\n "; - if($r[3]) + if($r[3]==$myid || !$r[3]) + echo "(it's your turn)\n"; + else { - if($r[3]==$myid) - echo "(it's your turn)\n"; - else - { - $name = DB_get_name_by_userid($r[3]); - $gameid = $r[1]; - if(DB_get_reminder($r[3],$gameid)==0) - if(time()-strtotime($r[2]) > 60*60*24*7) - echo "". - "Send a reminder."; - echo "(it's $name's turn)\n"; - }; - } + $name = DB_get_name_by_userid($r[3]); + $gameid = $r[1]; + if(DB_get_reminder($r[3],$gameid)==0) + if(time()-strtotime($r[2]) > 60*60*24*7) + echo "". + "Send a reminder."; + echo "(it's $name's turn)\n"; + }; if(time()-strtotime($r[2]) > 60*60*24*30) echo "". "Cancel?". @@ -2219,10 +2330,20 @@ else if( myisset("email","password") || isset($_SESSION["name"]) ) } } echo "\n\n"; - $names = DB_get_all_names(); - echo "

Registered players:

\n

\n"; - echo implode(", ",$names)."\n"; - echo "

\n
"; + + /* display last 5 users that have signed up to e-DoKo */ + $names = DB_get_names_of_new_logins(5); + echo "

New Players:

\n

\n"; + echo implode(", ",$names).",...\n"; + echo "

\n"; + + /* display last 5 users that logged on */ + $names = DB_get_names_of_last_logins(5); + echo "

Players last logged in:

\n

\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) {