X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=functions.php;h=3726cf115f00888f37fbdc6aafe98d72a368c066;hp=2d2277b4da4feeebc143ac06695d6ba6a26e7dfc;hb=a7ab5e63c5558a72d5ca56f96b406dc41108cce9;hpb=1332ef44c9587295fe054c73415d405247fb297d diff --git a/functions.php b/functions.php index 2d2277b..3726cf1 100644 --- a/functions.php +++ b/functions.php @@ -1,8 +1,60 @@ 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 be send to this address."; + output_footer(); + exit(); + } + if(!isset($DB_work)) + { + output_header(); + echo "

Setup not completed

"; + echo "You need to set \$DB_work in config.php. ". + "If this is set to 1, the game will be suspended and one can work safely on the database.". + "The default should be 0 for the game to work."; + output_footer(); + exit(); + } + if($DB_work) + { + output_header(); + echo "Working on the database...please check back later."; + output_footer(); + exit(); + } + + return; +} + function mymail($To,$Subject,$message,$header="") { - global $debug; + global $debug,$EMAIL_REPLY; + + if(isset($EMAIL_REPLY)) + $header .= "From: e-DoKo daemon <$EMAIL_REPLY>\r\n"; if($debug) { @@ -333,9 +385,6 @@ function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD) return $r; } - - - function display_cards($me,$myturn) { return; @@ -529,10 +578,16 @@ function can_call($what,$hash) { global $RULES; - /*TODO: check if this already has been call by teammate */ - $gameid = DB_get_gameid_by_hash($hash); $gametype = DB_get_gametype_by_gameid($gameid); + $oldcall = DB_get_call_by_hash($hash); + $pcall = DB_get_partner_call_by_hash($hash); + + if( ($pcall!=NULL && $what >= $pcall) || + ($oldcall!=NULL && $what >=$oldcall) ) + { + return 0; + } $NRcards = count(DB_get_hand($hash)); @@ -563,12 +618,216 @@ function can_call($what,$hash) return 1; break; case "9-cards": - if( ($what/10) <= $NRcards + $offset) - return 1; + + if($oldcall!=NULL && $pcall!=NULL) + $mincall = ($oldcall>$pcall) ? $pcall : $oldcall; + else if($oldcall!=NULL) + $mincall = $oldcall; + else if ($pcall!=NULL) + $mincall = $pcall; + else + $mincall = -1; + + if( 12 <= ($NRcards + $offset)) + { + return 1; + } + else if ( 9 <= ($NRcards + $offset)) + { + if( ($mincall>=0 && $mincall==120) ) + return 1; + } + else if ( 6 <= ($NRcards + $offset)) + { + if( ($mincall>=0 && $mincall<=90 && $what<=60 ) ) + return 1; + } + else if ( 3 <= ($NRcards + $offset)) + { + if( ($mincall>=0 && $mincall<=60 && $what<=30 ) ) + return 1; + } + else if ( 0 <= ($NRcards + $offset)) + { + if( ($mincall>=0 && $mincall<=30 && $what==0 ) ) + return 1; + }; break; } return 0; } +function display_table () +{ + global $gameid, $GT, $debug,$host; + + $result = mysql_query("SELECT User.fullname as name,". + " Hand.position as position, ". + " User.id, ". + " Hand.party as party, ". + " Hand.sickness as sickness, ". + " Hand.point_call, ". + " User.last_login, ". + " Hand.hash ". + "FROM Hand ". + "LEFT JOIN User ON User.id=Hand.user_id ". + "WHERE Hand.game_id='".$gameid."' ". + "ORDER BY position ASC"); + + echo "
\n". + " \"table\"\n"; + while($r = mysql_fetch_array($result,MYSQL_NUM)) + { + $name = $r[0]; + $pos = $r[1]; + $user = $r[2]; + $party = $r[3]; + $sickness = $r[4]; + $call = $r[5]; + $lastlogin = strtotime($r[6]); + $hash = $r[7]; + + $offset = DB_get_user_timezone($user); + $zone = return_timezone($offset); + date_default_timezone_set($zone); + + echo "
\n"; + if(!$debug) + echo " $name \n"; + else + echo " $name\n"; + + /* add hints for poverty, wedding, solo, etc */ + if($GT=="poverty" && $party=="re") + if($sickness=="poverty") + { + $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); + $cards = DB_get_all_hand($userhash); + $trumpNR = count_trump($cards); + if($trumpNR) + echo " \"poverty"; + else + echo " \"poverty"; + } + else + echo " \"poverty\" />"; + + if($GT=="dpoverty") + if($party=="re") + if($sickness=="poverty") + { + $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); + $cards = DB_get_all_hand($userhash); + $trumpNR = count_trump($cards); + if($trumpNR) + echo " \"poverty"; + else + echo " \"poverty"; + } + else + echo " \"poverty\" />"; + else + if($sickness=="poverty") + { + $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user); + $cards = DB_get_all_hand($userhash); + $trumpNR = count_trump($cards); + if($trumpNR) + echo " \"poverty2"; + else + echo " \"poverty2"; + } + else + echo " \"poverty2\" />"; + + if($GT=="wedding" && $party=="re") + if($sickness=="wedding") + echo " \"wedding\""; + else + echo " \"wedding"; + + if(ereg("solo",$GT) && $party=="re") + { + if(ereg("queen",$GT)) + echo " \"$GT\""; + else if(ereg("jack",$GT)) + echo " \"$GT\""; + else if(ereg("club",$GT)) + echo " \"$GT\""; + else if(ereg("spade",$GT)) + echo " \"$GT\""; + else if(ereg("heart",$GT)) + echo " \"$GT\""; + else if(ereg("trumpless",$GT)) + echo " \"$GT\""; + else if(ereg("trump",$GT)) + echo " \"$GT\""; + } + + /* add point calls */ + if($call!=NULL) + { + if($party=="re") + echo " \"re\""; + else + echo " \"contra\""; + switch($call) + { + case "0": + echo " \"0\""; + break; + case "30": + echo " \"30\""; + break; + case "60": + echo " \"60\""; + break; + case "90": + echo " \"90\""; + break; + } + } + + echo "
\n"; + echo " local time\n"; + echo " last login\n"; + echo "
\n"; + + } + echo "
\n"; /* end output table */ + + + return; +} + + +function display_user_menu() +{ + global $wiki,$myid,$host; + echo "
\n". + " go to my user page "; + + $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand". + " LEFT JOIN Game On Hand.game_id=Game.id". + " WHERE Hand.user_id='$myid'". + " AND Game.player='$myid'". + " AND Game.status<>'gameover'" ); + if(mysql_num_rows($result)) + echo "
It's your turn in these games:
\n"; + + while( $r = mysql_fetch_array($result,MYSQL_NUM)) + { + echo "game ".DB_format_gameid($r[1])."
\n"; + } + + echo "
start a new game\n"; + + + echo + "
Report bugs in the wiki\n"; + echo "
\n"; + return; +} + ?>