X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=functions.php;h=893f916c68271ba1d0151b83ee288969034094e1;hp=cfddbce169b54277a277b77d269c7a1ea61821cd;hb=65d3845752e76b9f1895cd9e2bf1a4fa6021f0af;hpb=9db97c855d40d089037410aad3595893f68f6d6a diff --git a/functions.php b/functions.php index cfddbce..893f916 100644 --- a/functions.php +++ b/functions.php @@ -1,16 +1,26 @@ ",$message); - echo "
To: $To
Subject: $Subject
$message
\n"; + $message = str_replace("\n","
\n",$message); + $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", + "\\0", $message); + //$message = ereg_replace("(http.*)[ <>]","\\1 ",$message); + + 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; } @@ -418,30 +428,29 @@ function create_array_of_random_numbers() global $debug; $r = array(); - $a = array(); - for($i=0;$i<48;$i++) - $a[$i]=$i+1; - - if(!$debug) - $r = array_rand($a,48); - else + if($debug) { - $a[ 0]=1; $a[12]=47; $a[24]=13; $a[36]=37; - $a[ 1]=2; $a[13]=48; $a[25]=14; $a[37]=38; - $a[ 2]=3; $a[14]=27; $a[26]=15; $a[38]=39; - $a[ 3]=4; $a[15]=16; $a[27]=28; $a[39]=40; - $a[ 4]=5; $a[16]=17; $a[28]=29; $a[40]=41; - $a[ 5]=6; $a[17]=18; $a[29]=30; $a[41]=42; - $a[ 6]=7; $a[18]=19; $a[30]=31; $a[42]=43; - $a[ 7]=8; $a[19]=20; $a[31]=32; $a[43]=44; - $a[ 8]=9; $a[20]=45; $a[32]=21; $a[44]=33; - $a[ 9]=10; $a[21]=46; $a[33]=22; $a[45]=34; - $a[10]=11; $a[22]=35; $a[34]=23; $a[46]=25; - $a[11]=12; $a[23]=36; $a[35]=24; $a[47]=26; + $r[ 0]=1; $r[12]=47; $r[24]=13; $r[36]=37; + $r[ 1]=2; $r[13]=48; $r[25]=14; $r[37]=38; + $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39; + $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40; + $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41; + $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42; + $r[ 6]=19; $r[18]=7; $r[30]=31; $r[42]=43; + $r[ 7]=20; $r[19]=8; $r[31]=32; $r[43]=44; + $r[ 8]=45; $r[20]=9; $r[32]=21; $r[44]=33; + $r[ 9]=46; $r[21]=10; $r[33]=22; $r[45]=34; + $r[10]=35; $r[22]=11; $r[34]=23; $r[46]=25; + $r[11]=36; $r[23]=12; $r[35]=24; $r[47]=26; } - - $r =$a; + else + { + for($i=0;$i<48;$i++) + $r[$i]=$i+1; + + shuffle($r); + }; return $r; } @@ -638,4 +647,50 @@ function sort_comp($a,$b) return pos_array($a,$ALL)-pos_array($b,$ALL); } -?> \ No newline at end of file +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); + + $NRcards = count(DB_get_hand($me)); + + $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; +} + +?>