X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=functions.php;h=7ee180e946b9d2f8c248b9062e428b1d866ac61d;hp=75f1fedc28622bc962d5c56c9ab750f39a2278c2;hb=0bf8233e0ef1db60e09269db5a2372fdd67f290d;hpb=12cfb198f8d644e370d646a7c42b37291a466089 diff --git a/functions.php b/functions.php index 75f1fed..7ee180e 100644 --- a/functions.php +++ b/functions.php @@ -1,6 +1,6 @@ \n",$message); $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "\\0", $message); - //$message = ereg_replace("(http.*)[ <>]","\\1 ",$message); - echo "
To: $To
Subject: $Subject
$message
\n"; + echo "
To: $To
"; + if($header != "") + echo $header."
"; + echo "Subject: $Subject
$message
\n"; } else - mail($To,$Subject,$message); + if($header != "") + mail($To,$Subject,$message,$header); + else + mail($To,$Subject,$message); return; } @@ -23,7 +28,7 @@ function myisset() /* returns 1 if all names passed as args are defined by a GET or POST statement, * else return 0 */ - + $ok = 1; $args = func_get_args(); @@ -36,10 +41,17 @@ function myisset() return $ok; } +function myerror($message) +{ + echo "".htmlspecialchars($message)."\n"; + mymail($ADMIN_EMAIL,$EmailName." Error in Code",$message); + return; +} + function pos_array($c,$arr) { $ret = 0; - + $i = 0; foreach($arr as $a) { @@ -271,87 +283,6 @@ function count_trump($cards) return $trump; } -function card_to_name($card) -{ - switch($card) - { - case 1: - case 2: - return "ten of hearts"; - case 3: - case 4: - return "queen of clubs"; - case 5: - case 6: - return "queen of spades"; - case 7: - case 8: - return "queen of hearts"; - case 9: - case 10: - return "queen of diamonds"; - case 11: - case 12: - return "jack of clubs"; - case 13: - case 14: - return "jack of spades"; - case 15: - case 16: - return "jack of hearts"; - case 17: - case 18: - return "jack of diamonds"; - case 19: - case 20: - return "ace of diamonds"; - case 21: - case 22: - return "ten of diamonds"; - case 23: - case 24: - return "king of diamonds"; - case 25: - case 26: - return "nine of diamonds";; - case 27: - case 28: - return "ace of clubs"; - case 29: - case 30: - return "ten of clubs"; - case 31: - case 32: - return "king of clubs"; - case 33: - case 34: - return "nine of clubs"; - case 35: - case 36: - return "ace of spades"; - case 37: - case 38: - return "ten of spades"; - case 39: - case 40: - return "king of spades"; - case 41: - case 42: - return "nine of spades"; - case 43: - case 44: - return "ace of hearts"; - case 45: - case 46: - return "king of hearts"; - case 47: - case 48: - return "nine of hearts"; - default: - return "something went wrong, please contact the admin. Error: code1. $card
"; - } -} - function card_value($card) { switch($card) @@ -411,13 +342,14 @@ function card_value($card) case 48: return 0; default: - echo "something went wrong, please contact the admin. ErrorCode: 2 - $card
"; + myerror("something went wrong, please contact $ADMIN_NAME at $ADMIN_EMAIL. ErrorCode: 2 - $card
"); + echo "something went wrong, please contact $ADMIN_NAME at $ADMIN_EMAIL. ErrorCode: 2 - $card
"; return 0; } } -function create_array_of_random_numbers() +function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD) { global $debug; @@ -440,10 +372,21 @@ function create_array_of_random_numbers() } else { + /* check if we can find a game were non of the player was involved and return + * cards insted + */ + $userstr = implode(",",array($useridA,$useridB,$useridC,$useridD)); + $randomnumbers = DB_get_unused_randomnumbers($userstr); + $randomnumbers = explode(":",$randomnumbers); + + if(sizeof($randomnumbers)==48) + return $randomnumbers; + + /* need to create new numbers */ for($i=0;$i<48;$i++) $r[$i]=$i+1; - shuffle($r); + shuffle($r); }; return $r; @@ -643,7 +586,48 @@ function sort_comp($a,$b) function can_call($what,$hash) { - return 1; + 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); + + $NRcards = count(DB_get_hand($hash)); + + $NRallcards = 0; + for ($i=1;$i<5;$i++) + { + $user = DB_get_hash_from_game_and_pos($gameid,$i); + $NRallcards += count(DB_get_hand($user)); + }; + + /* in case of a wedding, everything will be delayed by an offset */ + $offset = 0; + if($gametype=="wedding") + { + $offset = DB_get_sickness_by_gameid($gameid); + if ($offset <0) /* not resolved */ + return 0; + }; + + switch ($RULES["call"]) + { + case "1st-own-card": + if( 4-($what/30) >= 12 - ($NRcards + $offset)) + return 1; + break; + case "5th-card": + if( 27+4*($what/30) <= $NRallcards + $offset*4) + return 1; + break; + case "9-cards": + if( ($what/10) <= $NRcards + $offset) + return 1; + break; + } + + return 0; } -?> \ No newline at end of file +?>