X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=71d40506c27d5cd52d2000b8dad41714ecd8fda7;hp=1d6dffff64d99a928f23f33ecb975eea503e26fe;hb=d8eac0035f97a64371557e7da8b9730fe28d8788;hpb=b5f096688faaebf7846b3e725e1bd2dd9251b203
diff --git a/index.php b/index.php
index 1d6dfff..71d4050 100644
--- a/index.php
+++ b/index.php
@@ -6,41 +6,7 @@ include_once("output.php"); /* html output only */
include_once("db.php"); /* database only */
include_once("functions.php"); /* the rest */
-/* 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 "
Setup not completed
";
- echo "You need to set \$ADMIN_NAME in config.php.";
- output_footer();
- exit();
- }
-if(!isset($ADMIN_EMAIL))
- {
- output_header();
- echo "Setup not completed
";
- 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(0)
- {
- output_header();
- echo "Working on the database...please check back in a few mintues";
- output_footer();
- exit();
- }
+config_check();
if(DB_open()<0)
{
@@ -136,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();
@@ -221,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";
@@ -273,7 +242,6 @@ else if(myisset("me"))
DB_get_PREF($myid);
/* end set pref */
-
/* get rule set for this game */
$result = mysql_query("SELECT * FROM Rulesets".
" LEFT JOIN Game ON Game.ruleset=Rulesets.id ".
@@ -284,7 +252,6 @@ else if(myisset("me"))
$RULES["schweinchen"] = $r[3];
$RULES["call"] = $r[4];
-
/* get some infos about the game */
$gametype = DB_get_gametype_by_gameid($gameid);
$gamestatus = DB_get_game_status_by_gameid($gameid);
@@ -294,9 +261,31 @@ else if(myisset("me"))
$gametype = DB_get_solo_by_gameid($gameid);
$GT = $gametype." ".$GT;
}
+
+ /* does anyone have both foxes */
+ $GAME["schweinchen"]=0;
+ for($i=1;$i<5;$i++)
+ {
+ $hash = DB_get_hash_from_game_and_pos($gameid,$i);
+ $cards = DB_get_all_hand($hash);
+ if( in_array("19",$cards) && in_array("20",$cards) )
+ {
+ $GAME["schweinchen"]=1;
+ $GAME["schweinchen-who"]=$hash;
+ }
+ };
+
+ /* put everyting in a form */
+ echo "\n";
}
else if($mystatus=='play' )
{
echo "Your cards are:
\n";
foreach($mycards as $card)
display_card($card,$PREF["cardset"]);
-
- echo "\n";
-
}
else if($mystatus=='gameover')
{
@@ -1609,11 +1481,9 @@ else if(myisset("me"))
if( $gameend < 60*60*24*7 )
{
- echo "\n";
}
$oldcards = DB_get_all_hand($me);
@@ -1654,23 +1524,6 @@ else if(myisset("me"))
}
else
{
- echo "the game is over now...
\n";
-
- $result = mysql_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand".
- " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
- " LEFT JOIN User ON User.id=Hand.user_id".
- " LEFT JOIN Play ON Trick.id=Play.trick_id".
- " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
- " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
- " WHERE Hand.game_id='$gameid'".
- " GROUP BY User.fullname" );
- echo "Final Score:
\n".
- " \n";;
- while( $r = mysql_fetch_array($result,MYSQL_NUM))
- echo " ".$r[0]." | (".$r[2].") | ".$r[1]." |
";
- echo "
\n";
-
-
$result = mysql_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
" LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
" LEFT JOIN User ON User.id=Hand.user_id".
@@ -1679,37 +1532,17 @@ else if(myisset("me"))
" LEFT JOIN Card ON Card.id=Hand_Card.card_id".
" WHERE Hand.game_id='$gameid'".
" GROUP BY Hand.party" );
- echo "Totals:
\n".
- " \n";
+ echo " Totals:
\n";
while( $r = mysql_fetch_array($result,MYSQL_NUM))
- echo "
".$r[0]." | ".$r[1]." |
\n";
- 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);
+ echo " ".$r[0]." ".$r[1]."
\n";
+ echo "\n";
- 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);
- }
}
break;
default:
myerror("error in testing the status");
}
+ echo "\n";
output_footer();
DB_close();
exit();
@@ -1832,7 +1665,8 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
$ok = 1;
/* check if old password matches */
- if($password != md5($_REQUEST["password0"]))
+ $oldpasswd = md5($_REQUEST["password0"]);
+ if(!( ($password == $oldpasswd) || DB_check_recovery_passwords($oldpasswd,$email) ))
$ok = -1;
/* check if new passwords are types the same twice */
if($_REQUEST["password1"] != $_REQUEST["password2"] )
@@ -1883,7 +1717,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
" WHERE Hand.user_id='$uid' AND Game.status='pre'" );
while( $r = mysql_fetch_array($result,MYSQL_NUM))
{
- echo "game #".$r[1]." ";
+ echo "game".DB_format_gameid($r[1])." ";
if($r[3]==$uid || $r[3]==NULL)
echo "(it's your turn)\n";
else
@@ -1906,7 +1740,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
" WHERE Hand.user_id='$uid' AND Game.status='play'" );
while( $r = mysql_fetch_array($result,MYSQL_NUM))
{
- echo "game #".$r[1]." ";
+ echo "game ".DB_format_gameid($r[1])." ";
if($r[3])
{
if($r[3]==$uid)
@@ -1930,7 +1764,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
$output = array();
$result = mysql_query("SELECT hash,game_id from Hand WHERE user_id='$uid' AND status='gameover'" );
while( $r = mysql_fetch_array($result,MYSQL_NUM))
- $output[] = "#".$r[1]." ";
+ $output[] = "".DB_format_gameid($r[1])." ";
echo implode(", ",$output)."\n";
$names = DB_get_all_names();
@@ -1950,38 +1784,6 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
DB_close();
exit();
}
-/* page for registration */
- else if(myisset("register") )
- {
- output_register();
- }
-/* new user wants to register */
- else if(myisset("Rfullname","Remail","Rpassword","Rtimezone") )
- {
- $ok=1;
- if(DB_get_userid_by_name($_REQUEST["Rfullname"]))
- {
- echo "please chose another name
";
- $ok=0;
- }
- if(DB_get_userid_by_email($_REQUEST["Remail"]))
- {
- echo "this email address is already used ?!
";
- $ok=0;
- }
- if($ok)
- {
- $r=mysql_query("INSERT INTO User VALUES(NULL,".DB_quote_smart($_REQUEST["Rfullname"]).
- ",".DB_quote_smart($_REQUEST["Remail"]).
- ",".DB_quote_smart(md5($_REQUEST["Rpassword"])).
- ",".DB_quote_smart($_REQUEST["Rtimezone"]).",NULL)");
-
- if($r)
- echo " added you to the database";
- else
- echo " something went wrong, couldn't add you to the database, please contact $ADMIN_NAME at $ADMIN_EMAIL.";
- }
- }
/* default login page */
else
{