/* check if some variables are set in the config file, else set defaults */
if(!isset($EmailName))
$EmailName="[DoKo] ";
+if(isset($EMAIL_REPLY))
+ {
+ ini_set("sendmail_from",$EMAIL_REPLY);
+ }
+if(!isset($ADMIN_NAME))
+ {
+ output_header();
+ echo "<h1>Setup not completed</h1>";
+ echo "You need to set \$ADMIN_NAME in config.php.";
+ output_footer();
+ exit();
+ }
+if(!isset($ADMIN_EMAIL))
+ {
+ output_header();
+ echo "<h1>Setup not completed</h1>";
+ echo "You need to set \$ADMIN_EMAIL in config.php. ".
+ "If something goes wrong an email will send to this address.";
+ output_footer();
+ exit();
+ }
/* in case work has to be done on the database or other section we can
* shut down the server and tell people to come back later
if(DB_open()<0)
{
output_header();
- echo "Database error, can't connect...";
+ echo "Database error, can't connect... Please wait a while and try again. ".
+ "If the problem doesn't go away feel free to contact $ADMIN_NAME at $ADMIN_EMAIL.";
output_footer();
exit();
}
output_form_for_new_game($names);
}
/*check if everything is ready to set up a new game */
- else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen" ))
+ else if( myisset("PlayerA", "PlayerB","PlayerC","PlayerD","dullen","schweinchen","call" ))
{
$PlayerA = $_REQUEST["PlayerA"];
$PlayerB = $_REQUEST["PlayerB"];
$dullen = $_REQUEST["dullen"];
$schweinchen = $_REQUEST["schweinchen"];
-
+ $call = $_REQUEST["call"];
+
$EmailA = DB_get_email_by_name($PlayerA);
$EmailB = DB_get_email_by_name($PlayerB);
$EmailC = DB_get_email_by_name($PlayerC);
/* create random numbers */
$randomNR = create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD);
$randomNRstring = join(":",$randomNR);
-
- /* get ruleset information or create new one */
- $ruleset = DB_get_ruleset($dullen,$schweinchen);
- if($ruleset <0)
- {
- echo "Error defining ruleset: $ruleset";
- output_footer();
- DB_close();
- exit();
- };
-
+
/* create game */
$followup = NULL;
if(myisset("followup") )
$ruleset = DB_get_ruleset_by_gameid($followup); /* just copy ruleset from old game,
this way no manipulation is possible */
if($session)
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','1','pre',".
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
"'$ruleset','$session' ,NULL)");
else
{
$max = DB_get_max_session();
$max++;
mysql_query("UPDATE Game SET session='".$max."' WHERE id=".DB_quote_smart($followup));
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','1','pre',".
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre',".
"'$ruleset','$max' ,NULL)");
}
}
else
- mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1','1','pre', ".
+ {
+ /* get ruleset information or create new one */
+ $ruleset = DB_get_ruleset($dullen,$schweinchen,$call);
+ if($ruleset <0)
+ {
+ myerror("Error defining ruleset: $ruleset");
+ output_footer();
+ DB_close();
+ exit();
+ };
+
+ mysql_query("INSERT INTO Game VALUES (NULL, NULL, '$randomNRstring', 'normal', NULL,NULL,'1',NULL,'pre', ".
"'$ruleset',NULL ,NULL)");
+ }
$game_id = mysql_insert_id();
/* create hash */
/* all these variables have a pre-selected default,
* so we should never get here,
* unless a user tries to cheat ;) */
- echo "something went wrong...please contact the admin.";
+ echo "something went wrong during the setup...please contact the $ADMIN_NAME at $ADMIN_EMAIL.";
}
else
{
{
$userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
if($userstat!='poverty' && $userstat!='play')
- $ok = 0;
+ {
+ $ok = 0;
+ DB_set_player_by_gameid($gameid,$user);
+ }
};
if($ok)
- 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 $gameid, ".
- "please visit this link now to continue: \n".
- " ".$host."?me=".$userhash."\n\n" ;
- mymail($To,$EmailName." finished setup in game $gameid",$message);
- }
- };
+ {
+ /* 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 $gameid, ".
+ "please visit this link now to continue: \n".
+ " ".$host."?me=".$userhash."\n\n" ;
+ mymail($To,$EmailName." finished setup in game $gameid",$message);
+ }
+ };
+ };
};
break;
$r = mysql_fetch_array($result,MYSQL_NUM);
if(!$r)
{
- die("error in poverty");
+ myerror("error in poverty");
+ die();
};
if($r[0]==12)
{
" ".$host."?me=".$userhash."\n\n" ;
mymail($To,$EmailName." poverty (game $gameid)",$message);
}
-
}
/* this user is done */
else
echo "it's not your turn yet to decide if you want to take the trump or not.";
}
-
};
- }
- /* check if no one wanted to take trump, in that case the gamesickness would be set to 5 or 50 */
- $who = DB_get_sickness_by_gameid($gameid);
- if($who==5 || $who==50)
- {
- $message = "Hello, \n\n".
- "Game $gameid has been cancled since nobody wanted to take the trump.\n";
-
- $userids = DB_get_all_userid_by_gameid($gameid);
- foreach($userids as $user)
+ /* check if no one wanted to take trump, in that case the gamesickness would be set to 5 or 50 */
+ $who = DB_get_sickness_by_gameid($gameid);
+ if($who==5 || $who==50)
{
- $To = DB_get_email_by_userid($user);
- mymail($To,$EmailName."game $gameid cancled (poverty not resolved)",$message);
+ $message = "Hello, \n\n".
+ "Game $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);
+ }
+
+ /* delete everything from the dB */
+ DB_cancel_game($me);
+
+ echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
+ output_footer();
+ DB_close();
+ exit();
}
- /* delete everything from the dB */
- DB_cancel_game($me);
-
- echo "<p style=\"background-color:red\";>Game $gameid has been cancled.<br /><br /></p>";
- output_footer();
- DB_close();
- exit();
- }
-
- /* check if all players are ready to play */
- $ok = 1;
- foreach($userids as $user)
- if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
- $ok = 0;
-
- if($ok)
- {
- /* only set this after all poverty, etc. are handled*/
- DB_set_game_status_by_gameid($gameid,'play');
-
- /* email startplayer */
- $startplayer = DB_get_startplayer_by_gameid($gameid);
- $email = DB_get_email_by_pos_and_gameid($startplayer,$gameid);
- $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
- $who = DB_get_userid_by_email($email);
- DB_set_player_by_gameid($gameid,$who);
+ /* check if all players are ready to play */
+ $ok = 1;
+ foreach($userids as $user)
+ if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='play')
+ {
+ $ok = 0;
+ DB_set_player_by_gameid($gameid,$user);
+ }
- if($hash!=$me)
+ if($ok)
{
- /* email startplayer) */
- $message = "It's your turn now in game $gameid.\n".
- "Use this link to play a card: ".$host."?me=".$hash."\n\n" ;
- mymail($email,$EmailName."ready, set, go... (game $gameid) ",$message);
+ /* only set this after all poverty, etc. are handled*/
+ DB_set_game_status_by_gameid($gameid,'play');
+
+ /* email startplayer */
+ $startplayer = DB_get_startplayer_by_gameid($gameid);
+ $email = DB_get_email_by_pos_and_gameid($startplayer,$gameid);
+ $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
+ $who = DB_get_userid_by_email($email);
+ DB_set_player_by_gameid($gameid,$who);
+
+ if($hash!=$me)
+ {
+ /* email startplayer) */
+ $message = "It's your turn now in game $gameid.\n".
+ "Use this link to play a card: ".$host."?me=".$hash."\n\n" ;
+ mymail($email,$EmailName."ready, set, go... (game $gameid) ",$message);
+ }
+ else
+ echo " Please, <a href=\"$host?me=$me\">start</a> the game.<br />";
}
else
- echo " Please, <a href=\"$host?me=$me\">start</a> the game.<br />";
+ echo "\n <br />";
}
- else
- echo "\n <br />";
-
break;
case 'play':
case 'gameover':
if($winnerid>0)
mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
else
- echo "ERROR during scoring";
-
+ {
+ myerror("ERROR during scoring");
+ }
/* email all players */
/* individual score */
$result = mysql_query("SELECT fullname, IFNULL(SUM(score),0), Hand.party FROM Hand".
foreach($userids as $user)
$all[] = DB_get_email_by_userid($user);
- $TO = implode(",",$all);
+ $To = implode(",",$all);
$help = "\n\n (you can use reply all on this email to reach all the players.)\n";
mymail($To,$EmailName."game over (game $gameid) part 1(2)",$message.$help);
if($winnerid>0)
mysql_query("INSERT INTO Score VALUES (NULL, '$gameid', '$winnerid', '$points')");
else
- echo "ERROR during scoring";
-
+ {
+ myerror("ERROR during scoring");
+ };
if($debug)
echo "DEBUG: $winner got $points <br />";
}
break;
default:
- echo "error in testing the status";
+ myerror("error in testing the status");
}
output_footer();
DB_close();
if($ok)
{
- echo "Hmm, you forgot your passwort...nothing I can do at the moment:( ";
- echo " you need to email Arun for now... in the future it will be all automated and an ";
- echo "email with a new password will go to $email.";
+ /* check how many entries in recovery table */
+ $number = DB_get_number_of_passwords_recovery($uid);
+
+ /* if less than N recent ones, add a new one and send out email */
+ if( $number < 5 )
+ {
+ echo "Ok, I send you a new password. <br />";
+ if($number >1)
+ echo "N.B. You tried this already $number times during the last day and it will only work ".
+ " 5 times during a day.<br />";
+ echo "The new password will be valid for one day, make sure you reset it to something else.<br />";
+ echo "Back to the <a href=\"$host\">main page</a>.";
+
+ $TIME = (string) time(); /* to avoid collisions */
+ $hash = md5("Anewpassword".$email.$TIME);
+ $newpw = substr($hash,1,8);
+
+ $message = "Someone (hopefully you) requested a new password. \n".
+ "You can use this email and the following password: \n".
+ " $newpw \n".
+ "to log into the server. The new password is valid for 24h, so make\n".
+ "sure you reset your password to something new. Your old password will\n".
+ " also still be valid until you set a new one\n";
+ mymail($email,$EmailName."recovery ",$message);
+
+ DB_set_recovery_password($uid,md5($newpw));
+ }
+ else
+ {
+ echo "Sorry you already tried 5 times during the last 24h.<br />".
+ "You need to use one of those passwords or wait to get a new one.<br />";
+ echo "Back to the <a href=\"$host\">main page</a>.";
+ }
}
else
{
if($email=="")
- echo "you need to give me an email address!";
+ echo "You need to give me an email address! <br />".
+ "Please try <a href=\"$host\">again</a>.";
else
- echo "couldn't find a player with this email, please contact Arun, if you think this is a mistake";
+ echo "Couldn't find a player with this email! <br />".
+ "Please contact Arun, if you think this is a mistake <br />".
+ "or else try <a href=\"$host\">again</a>.";
}
}
else
$result = mysql_query("UPDATE User_Prefs SET value=".DB_quote_smart($setpref).
" WHERE user_id='$uid' AND pref_key='cardset'" );
else
- $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$uid','cardset',".DB_quote_smart($setpref).")");
+ $result = mysql_query("INSERT INTO User_Prefs VALUES(NULL,'$uid','cardset',".
+ DB_quote_smart($setpref).")");
echo "Ok, changed you preferences for the cards.\n";
break;
}
}
+ else if(myisset("passwd"))
+ {
+ if( $_REQUEST["passwd"]=="ask" )
+ {
+ /* reset password form*/
+ output_password_recovery($email,$password);
+ }
+ else if($_REQUEST["passwd"]=="set")
+ {
+ /* reset password */
+ $ok = 1;
+
+ /* check if old password matches */
+ if($password != md5($_REQUEST["password0"]))
+ $ok = -1;
+ /* check if new passwords are types the same twice */
+ if($_REQUEST["password1"] != $_REQUEST["password2"] )
+ $ok = -2;
+
+ switch($ok)
+ {
+ case '-2':
+ echo "The new passwords don't match. <br />";
+ break;
+ case '-1':
+ echo "The old password is not correct. <br />";
+ break;
+ case '1':
+ echo "Changed the password.<br />";
+ mysql_query("UPDATE User SET password='".md5($_REQUEST["password1"]).
+ "' WHERE id=".DB_quote_smart($uid));
+ break;
+ }
+ /* set password */
+ }
+ }
else /* output default user page */
{
$time = DB_get_user_timestamp($uid);
while( $r = mysql_fetch_array($result,MYSQL_NUM))
{
echo "<a href=\"".$host."?me=".$r[0]."\">game #".$r[1]." </a>";
- if($r[3])
+ if($r[3]==$uid || $r[3]==NULL)
+ echo "(it's <strong>your</strong> turn)\n";
+ else
{
- if($r[3]==$uid)
- echo "(it's <strong>your</strong> turn)\n";
- else
- {
- $name = DB_get_name_by_userid($r[3]);
- echo "(it's $name's turn)\n";
- };
- }
+ $name = DB_get_name_by_userid($r[3]);
+ echo "(it's $name's turn)\n";
+ };
+
if(time()-strtotime($r[2]) > 60*60*24*30)
echo " The game has been running for over a month.".
" Do you want to cancel it? <a href=\"$host?cancle=1&me=".$r[0]."\">yes</a>".