X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=index.php;h=f6d0c681b09fadbdcf6bce66c5bc217205dad803;hp=0c288c71802e529ffdf88f9a7517ac74d6a2cd87;hb=0c5b3eeca3006f61dd326a86e8989c52694d581b;hpb=60ad6707c95493513f42bd8d99598d5b4c81bdc4
diff --git a/index.php b/index.php
index 0c288c7..f6d0c68 100644
--- a/index.php
+++ b/index.php
@@ -9,7 +9,7 @@ include_once("functions.php"); /* the rest */
/* make sure that user has set all variables in config.php */
config_check();
-/* open database */
+/* open the database */
if(DB_open()<0)
{
output_header();
@@ -29,12 +29,20 @@ session_start();
/* done major error checking, output header of HTML page */
output_header();
+/* The rest of the file consists of handling user input.
+ * The user sends information via html GET and POST variables,
+ * the script checks if these are set via "myisset"
+ * which can check a list of variables.
+ */
+
/* does the user want to log out? */
if(myisset("logout"))
{
+ /* distroy the session */
session_unset();
session_destroy();
$_SESSION = array();
+
echo "
\n";
foreach($userids as $user)
{
- $name = DB_get_name_by_userid($user);
+ $name = DB_get_name('userid',$user);
$usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
if($usersick=="poverty")
@@ -1098,7 +1104,7 @@ else if(myisset("me"))
$userids = DB_get_all_userid_by_gameid($gameid);
foreach($userids as $user)
{
- $To = DB_get_email_by_userid($user);
+ $To = DB_get_email('userid',$user);
mymail($To,$EmailName."game ".DB_format_gameid($gameid)." canceled (poverty not resolved)",$message);
}
@@ -1127,9 +1133,9 @@ else if(myisset("me"))
/* email startplayer */
$startplayer = DB_get_startplayer_by_gameid($gameid);
- $email = DB_get_email_by_pos_and_gameid($startplayer,$gameid);
+ $email = DB_get_email('position-gameid',$startplayer,$gameid);
$hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
- $who = DB_get_userid_by_email($email);
+ $who = DB_get_userid('email',$email);
DB_set_player_by_gameid($gameid,$who);
if($hash!=$me && DB_get_email_pref_by_hash($hash)!="emailaddict")
@@ -1178,7 +1184,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 */
}
@@ -1343,7 +1349,7 @@ else if(myisset("me"))
if(myisset("card") && $myturn)
{
$card = $_REQUEST["card"];
- $handid = DB_get_handid_by_hash($me);
+ $handid = DB_get_handid('hash',$me);
/* check if we have card and that we haven't played it yet*/
/* set played in hand_card to true where hand_id and card_id*/
@@ -1358,15 +1364,15 @@ else if(myisset("me"))
DB_update_game_timestamp($gameid);
/* check if a call was made, must do this before we set the card status to played */
- if(myisset("call120") && $_REQUEST["call120"] == "yes" && can_call(120,$me))
+ if(myisset("call") && $_REQUEST["call"] == "120" && can_call(120,$me))
$result = mysql_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
- if(myisset("call90") && $_REQUEST["call90"] == "yes" && can_call(90,$me))
+ if(myisset("call") && $_REQUEST["call"] == "90" && can_call(90,$me))
$result = mysql_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
- if(myisset("call60") && $_REQUEST["call60"] == "yes" && can_call(60,$me))
+ if(myisset("call") && $_REQUEST["call"] == "60" && can_call(60,$me))
$result = mysql_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
- if(myisset("call30") && $_REQUEST["call30"] == "yes" && can_call(30,$me))
+ if(myisset("call") && $_REQUEST["call"] == "30" && can_call(30,$me))
$result = mysql_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
- if(myisset("call0") && $_REQUEST["call0"] == "yes" && can_call(0,$me))
+ if(myisset("call") && $_REQUEST["call"] == "0" && can_call(0,$me))
$result = mysql_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
/* mark card as played */
@@ -1381,8 +1387,12 @@ else if(myisset("me"))
$playid = DB_play_card($trickid,$handcardid,$sequence);
- /* check for schweinchen */
- if($GAME["schweinchen"] && ($card == 19 || $card == 20) )
+ /* check special output for schweinchen in case:
+ * schweinchen is in the rules, a fox has been played and the gametype is correct
+ */
+ if( $GAME["schweinchen"] &&
+ ($card == 19 || $card == 20) &&
+ ($gametype == "normal" || $gametype == "silent"|| $gametype=="trump"))
{
$GAME["schweinchen"]++; // count how many have been played including this one
if($GAME["schweinchen"]==3 && $RULES["schweinchen"]=="second" )
@@ -1411,7 +1421,7 @@ else if(myisset("me"))
/* who won the trick */
$play = DB_get_cards_by_trick($trickid);
$winner = get_winner($play,$gametype); /* returns the position */
- $winnerid = DB_get_userid_by_gameid_and_position($gameid,$winner);
+ $winnerid = DB_get_userid('gameid-position',$gameid,$winner);
/* is tricknr <=3 */
if($tricknr <=3 && $winnerid!=$whosick)
{
@@ -1436,15 +1446,28 @@ 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 )
if ($played['pos']!= $winner )
{
/* possible caught a fox, check party */
- $uid1 = DB_get_userid_by_gameid_and_position($gameid,$winner);
- $uid2 = DB_get_userid_by_gameid_and_position($gameid,$played['pos']);
+ $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
+ $uid2 = DB_get_userid('gameid-position',$gameid,$played['pos']);
$party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
$party2 = DB_get_party_by_gameid_and_userid($gameid,$uid2);
@@ -1454,14 +1477,27 @@ 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 )
{
/* possible caught a fox, check party */
- $uid1 = DB_get_userid_by_gameid_and_position($gameid,$winner);
+ $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
$party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
mysql_query("INSERT INTO Score".
@@ -1475,7 +1511,7 @@ else if(myisset("me"))
}
if($points > 39)
{
- $uid1 = DB_get_userid_by_gameid_and_position($gameid,$winner);
+ $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
$party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
mysql_query("INSERT INTO Score".
@@ -1557,8 +1593,8 @@ else if(myisset("me"))
if(DB_get_game_status_by_gameid($gameid)=='play')
{
$next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
- $email = DB_get_email_by_hash($next_hash);
- $who = DB_get_userid_by_email($email);
+ $email = DB_get_email('hash',$next_hash);
+ $who = DB_get_userid('email',$email);
DB_set_player_by_gameid($gameid,$who);
$message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
@@ -1817,7 +1853,7 @@ else if(myisset("me"))
$all = array();
foreach($userids as $user)
- $all[] = DB_get_email_by_userid($user);
+ $all[] = DB_get_email('userid',$user);
$To = implode(",",$all);
$help = "\n\n (you can use reply all on this email to reach all the players.)\n";
@@ -1825,7 +1861,7 @@ else if(myisset("me"))
foreach($userids as $user)
{
- $To = DB_get_email_by_userid($user);
+ $To = DB_get_email('userid',$user);
$hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
$link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".
@@ -1927,7 +1963,7 @@ else if(myisset("me"))
{
echo "
";
- $name = DB_get_name_by_userid($user);
+ $name = DB_get_name('userid',$user);
$oldcards = DB_get_all_hand($userhash);
$oldcards = mysort($oldcards,$gametype);
echo "$name's cards were:
\n";
@@ -2076,7 +2112,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
else
{
$name = $_SESSION["name"];
- $email = DB_get_email_by_name($name);
+ $email = DB_get_email('name',$name);
$password = DB_get_passwd_by_name($name);
};
@@ -2086,7 +2122,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
/* check if player is in the database */
$ok = 1;
- $myid = DB_get_userid_by_email($email);
+ $myid = DB_get_userid('email',$email);
if(!$myid)
$ok = 0;
@@ -2150,14 +2186,14 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
$password = md5($password);
$ok = 1;
- $myid = DB_get_userid_by_email_and_password($email,$password);
+ $myid = DB_get_userid('email-password',$email,$password);
if(!$myid)
$ok = 0;
if($ok)
{
/* user information is ok */
- $myname = DB_get_name_by_email($email);
+ $myname = DB_get_name('email',$email);
$_SESSION["name"] = $myname;
output_status();
@@ -2288,7 +2324,7 @@ else if( myisset("email","password") || isset($_SESSION["name"]) )
echo "(it's
your turn)\n";
else
{
- $name = DB_get_name_by_userid($r[3]);
+ $name = DB_get_name('userid',$r[3]);
$gameid = $r[1];
if(DB_get_reminder($r[3],$gameid)==0)
if(time()-strtotime($r[2]) > 60*60*24*7)