2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
8 function config_check()
10 global $EmailName,$EMAIL_REPLY,$ADMIN_NAME,$ADMIN_EMAIL,$DB_work;
12 /* check if some variables are set in the config file, else set defaults */
13 if(!isset($EmailName))
15 if(isset($EMAIL_REPLY))
17 ini_set("sendmail_from",$EMAIL_REPLY);
19 if(!isset($ADMIN_NAME))
22 echo "<h1>Setup not completed</h1>";
23 echo "You need to set \$ADMIN_NAME in config.php.";
27 if(!isset($ADMIN_EMAIL))
30 echo "<h1>Setup not completed</h1>";
31 echo "You need to set \$ADMIN_EMAIL in config.php. ".
32 "If something goes wrong an email will be send to this address.";
39 echo "<h1>Setup not completed</h1>";
40 echo "You need to set \$DB_work in config.php. ".
41 "If this is set to 1, the game will be suspended and one can work safely on the database.".
42 "The default should be 0 for the game to work.";
49 echo "Working on the database...please check back later.";
57 function mymail($To,$Subject,$message,$header="")
59 global $debug,$EMAIL_REPLY;
61 if(isset($EMAIL_REPLY))
62 $header .= "From: e-DoKo daemon <$EMAIL_REPLY>\r\n";
66 /* display email on screen,
69 $message = str_replace("\n","<br />\n",$message);
70 $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
71 "<a href=\"\\0\">\\0</a>", $message);
73 echo "<br />To: $To<br />";
75 echo $header."<br />";
76 echo "Subject: $Subject <br />$message<br />\n";
80 mail($To,$Subject,$message,$header);
82 mail($To,$Subject,$message);
88 /* returns 1 if all names passed as args are defined by a GET or POST statement,
93 $args = func_get_args();
95 foreach($args as $arg)
97 $ok = $ok * isset($_REQUEST[$arg]);
98 /*echo "$arg: ok = $ok <br />";
104 function myerror($message)
106 echo "<span class=\"error\">".htmlspecialchars($message)."</span>\n";
107 mymail($ADMIN_EMAIL,$EmailName." Error in Code",$message);
111 function pos_array($c,$arr)
128 function is_trump($c)
132 if(in_array($c,$CARDS["trump"]))
138 function is_same_suite($c1,$c2)
142 if(in_array($c1,$CARDS["trump"] ) && in_array($c2,$CARDS["trump"] ) ) return 1;
143 if(in_array($c1,$CARDS["clubs"] ) && in_array($c2,$CARDS["clubs"] ) ) return 1;
144 if(in_array($c1,$CARDS["hearts"] ) && in_array($c2,$CARDS["hearts"] ) ) return 1;
145 if(in_array($c1,$CARDS["spades"] ) && in_array($c2,$CARDS["spades"] ) ) return 1;
146 if(in_array($c1,$CARDS["diamonds"]) && in_array($c2,$CARDS["diamonds"]) ) return 1;
151 function compare_cards($a,$b,$game)
153 /* if "a" is higher than "b" return 1, else 0, "a" being the card first played */
159 /* first map all cards to the odd number,
160 * this insure that the first card wins the trick
161 * if they are the same card
163 if( $a/2 - (int)($a/2) != 0.5)
165 if( $b/2 - (int)($b/2) != 0.5)
168 /* check for schweinchen and ten of hearts*/
174 if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
176 if($a == 19 || $a == 20 )
178 if($b == 19 || $b == 20 )
181 if($RULES["schweinchen"]=="second" && $GAME["schweinchen"]==3)
183 if($a == 19 || $a == 20 )
185 if($b == 19 || $b == 20 )
191 /* check for ten of hearts rule */
192 if($RULES["dullen"]=="secondwins")
193 if($a==1 && $b==1) /* both 10 of hearts */
194 return 0; /* second one wins.*/
198 /* no special cases here */
202 if(is_trump($a) && is_trump($b) && $a<=$b)
204 else if(is_trump($a) && is_trump($b) )
207 { /*$a is not a trump */
211 { /* both no trump */
214 $posA = pos_array($a,$CARDS["clubs"]);
215 $posB = pos_array($b,$CARDS["clubs"]);
223 $posA = pos_array($a,$CARDS["spades"]);
224 $posB = pos_array($b,$CARDS["spades"]);
232 $posA = pos_array($a,$CARDS["hearts"]);
233 $posB = pos_array($b,$CARDS["hearts"]);
241 $posA = pos_array($a,$CARDS["diamonds"]);
242 $posB = pos_array($b,$CARDS["diamonds"]);
249 /* not the same suit and no trump: a wins */
255 function get_winner($p,$mode)
257 /* get all 4 cards played in a trick, in the order they are played */
260 $c1pos = $tmp["pos"];
264 $c2pos = $tmp["pos"];
268 $c3pos = $tmp["pos"];
272 $c4pos = $tmp["pos"];
274 /* first card is better than all the rest */
275 if( compare_cards($c1,$c2,$mode) && compare_cards($c1,$c3,$mode) && compare_cards($c1,$c4,$mode) )
278 /* second card is better than first and better than the rest */
279 if( !compare_cards($c1,$c2,$mode) && compare_cards($c2,$c3,$mode) && compare_cards($c2,$c4,$mode) )
282 /* third card is better than first card and better than last */
283 if( !compare_cards($c1,$c3,$mode) && compare_cards($c3,$c4,$mode) )
284 /* if second card is better than first, third card needs to be even better */
285 if( !compare_cards($c1,$c2,$mode) && !compare_cards($c2,$c3,$mode) )
287 /* second is worse than first, e.g. not following suite */
288 else if (compare_cards($c1,$c2,$mode) )
291 /* non of the above */
295 function count_nines($cards)
299 foreach($cards as $c)
301 if($c == "25" || $c == "26") $nines++;
302 else if($c == "33" || $c == "34") $nines++;
303 else if($c == "41" || $c == "42") $nines++;
304 else if($c == "47" || $c == "48") $nines++;
310 function check_wedding($cards)
313 if( in_array("3",$cards) && in_array("4",$cards) )
319 function count_trump($cards)
325 /* count each trump, including the foxes */
326 foreach($cards as $c)
330 /* normally foxes don't count as trump, so we substract them here
331 * in case someone has schweinchen, one or two of them should count as trump
332 * though, so we need to add one trump for those cases */
335 if( in_array("19",$cards))
337 if( in_array("20",$cards) )
340 /* handle case where player has schweinchen */
341 if( in_array("19",$cards) && in_array("20",$cards) )
342 switch($RULES["schweinchen"])
345 /* add two, in case the player has both foxes (schweinchen) */
350 case "secondaftercall":
351 /* add one, in case the player has both foxes (schweinchen) */
361 function create_array_of_random_numbers($useridA,$useridB,$useridC,$useridD)
369 $r[ 0]=1; $r[12]=47; $r[24]=13; $r[36]=37;
370 $r[ 1]=2; $r[13]=23; $r[25]=14; $r[37]=38;
371 $r[ 2]=3; $r[14]=27; $r[26]=15; $r[38]=39;
372 $r[ 3]=4; $r[15]=16; $r[27]=28; $r[39]=40;
373 $r[ 4]=5; $r[16]=17; $r[28]=29; $r[40]=41;
374 $r[ 5]=18; $r[17]=6; $r[29]=30; $r[41]=42;
375 $r[ 6]=21; $r[18]=7; $r[30]=31; $r[42]=43;
376 $r[ 7]=22; $r[19]=8; $r[31]=32; $r[43]=44;
377 $r[ 8]=45; $r[20]=9; $r[32]=19; $r[44]=33;
378 $r[ 9]=46; $r[21]=10; $r[33]=20; $r[45]=24;
379 $r[10]=35; $r[22]=11; $r[34]=48; $r[46]=25;
380 $r[11]=36; $r[23]=12; $r[35]=34; $r[47]=26;
384 /* check if we can find a game were non of the player was involved and return
387 $userstr = "'".implode("','",array($useridA,$useridB,$useridC,$useridD))."'";
388 $randomnumbers = DB_get_unused_randomnumbers($userstr);
389 $randomnumbers = explode(":",$randomnumbers);
391 if(sizeof($randomnumbers)==48)
392 return $randomnumbers;
394 /* need to create new numbers */
398 /* shuffle using a better random generator than the standard one */
399 for ($i = 0; $i <48; $i++)
401 $j = @mt_rand(0, $i);
411 function display_cards($me,$myturn)
416 function have_suit($cards,$c)
421 if(in_array($c,$CARDS["trump"]))
422 $suite = $CARDS["trump"];
423 else if(in_array($c,$CARDS["clubs"]))
424 $suite = $CARDS["clubs"];
425 else if(in_array($c,$CARDS["spades"]))
426 $suite = $CARDS["spades"];
427 else if(in_array($c,$CARDS["hearts"]))
428 $suite = $CARDS["hearts"];
429 else if(in_array($c,$CARDS["diamonds"]))
430 $suite = $CARDS["diamonds"];
432 foreach($cards as $card)
434 if(in_array($card,$suite))
441 function same_type($card,$c)
446 /* figure out what kind of card c is */
447 if(in_array($c,$CARDS["trump"]))
448 $suite = $CARDS["trump"];
449 else if(in_array($c,$CARDS["clubs"]))
450 $suite = $CARDS["clubs"];
451 else if(in_array($c,$CARDS["spades"]))
452 $suite = $CARDS["spades"];
453 else if(in_array($c,$CARDS["hearts"]))
454 $suite = $CARDS["hearts"];
455 else if(in_array($c,$CARDS["diamonds"]))
456 $suite = $CARDS["diamonds"];
458 /* card is the same suid return 1 */
459 if(in_array($card,$suite))
465 function set_gametype($gametype)
478 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
479 '17','18','19','20','21','22','23','24','25','26');
480 $CARDS["diamonds"] = array();
481 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
482 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
483 $CARDS["hearts"] = array('43','44','45','46','47','48');
484 $CARDS["foxes"] = array('19','20');
485 if($RULES["dullen"]=='none')
487 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
488 '17','18','19','20','21','22','23','24','25','26');
489 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
493 $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
494 $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
495 $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
496 $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
497 $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
498 $CARDS["foxes"] = array();
501 $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
502 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
503 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
504 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
505 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
506 $CARDS["foxes"] = array();
509 $CARDS["trump"] = array();
510 $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
511 $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
512 $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
513 $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
514 $CARDS["foxes"] = array();
517 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
518 '17','18','27','28','29','30','31','32','33','34');
519 $CARDS["clubs"] = array();
520 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
521 $CARDS["hearts"] = array('43','44','45','46','47','48');
522 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
523 $CARDS["foxes"] = array();
524 if($RULES["dullen"]=='none')
526 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
527 '17','18','27','28','29','30','31','32','33','34');
528 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
532 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
533 '17','18','35','36','37','38','39','40','41','42');
534 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
535 $CARDS["spades"] = array();
536 $CARDS["hearts"] = array('43','44','45','46','47','48');
537 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
538 $CARDS["foxes"] = array();
539 if($RULES["dullen"]=='none')
541 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
542 '17','18','35','36','37','38','39','40','41','42');
543 $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
547 $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
548 '17','18','43','44','45','46','47','48');
549 $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
550 $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
551 $CARDS["hearts"] = array();
552 $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
553 $CARDS["foxes"] = array();
554 if($RULES["dullen"]=='none')
556 $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
557 '17','18','43','44','1','2','45','46','47','48');
563 function mysort($cards,$gametype)
565 usort ( $cards, "sort_comp" );
569 function sort_comp($a,$b)
574 $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
575 $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
577 return pos_array($a,$ALL)-pos_array($b,$ALL);
580 function can_call($what,$hash)
584 $gameid = DB_get_gameid_by_hash($hash);
585 $gametype = DB_get_gametype_by_gameid($gameid);
586 $oldcall = DB_get_call_by_hash($hash);
587 $pcall = DB_get_partner_call_by_hash($hash);
589 if( ($pcall!=NULL && $what >= $pcall) ||
590 ($oldcall!=NULL && $what >=$oldcall) )
595 $NRcards = count(DB_get_hand($hash));
600 $user = DB_get_hash_from_game_and_pos($gameid,$i);
601 $NRallcards += count(DB_get_hand($user));
604 /* in case of a wedding, everything will be delayed by an offset */
606 if($gametype=="wedding")
608 $offset = DB_get_sickness_by_gameid($gameid);
609 if ($offset <0) /* not resolved */
613 switch ($RULES["call"])
616 if( 4-($what/30) >= 12 - ($NRcards + $offset))
620 if( 27+4*($what/30) <= $NRallcards + $offset*4)
625 if($oldcall!=NULL && $pcall!=NULL)
626 $mincall = ($oldcall>$pcall) ? $pcall : $oldcall;
627 else if($oldcall!=NULL)
629 else if ($pcall!=NULL)
634 if( 12 <= ($NRcards + $offset))
638 else if ( 9 <= ($NRcards + $offset))
640 if( ($mincall>=0 && $mincall==120) )
643 else if ( 6 <= ($NRcards + $offset))
645 if( ($mincall>=0 && $mincall<=90 && $what<=60 ) )
648 else if ( 3 <= ($NRcards + $offset))
650 if( ($mincall>=0 && $mincall<=60 && $what<=30 ) )
653 else if ( 0 <= ($NRcards + $offset))
655 if( ($mincall>=0 && $mincall<=30 && $what==0 ) )
664 function display_table ()
666 global $gameid, $GT, $debug,$INDEX,$defaulttimezone;
668 $result = DB_query("SELECT User.fullname as name,".
669 " Hand.position as position, ".
671 " Hand.party as party, ".
672 " Hand.sickness as sickness, ".
673 " Hand.point_call, ".
674 " User.last_login, ".
678 "LEFT JOIN User ON User.id=Hand.user_id ".
679 "WHERE Hand.game_id='".$gameid."' ".
680 "ORDER BY position ASC");
682 echo "<div class=\"table\">\n".
683 " <img class=\"table\" src=\"pics/table.png\" alt=\"table\" />\n";
684 while($r = DB_fetch_array($result))
694 date_default_timezone_set($defaulttimezone);
695 $lastlogin = strtotime($r[6]);
696 date_default_timezone_set($timezone);
697 $timenow = strtotime(date("Y-m-d H:i:s"));
699 echo " <div class=\"table".($pos-1)."\">\n";
703 echo " <a href=\"".$INDEX."?action=game&me=".$hash."\">$name</a>\n";
705 /* add hints for poverty, wedding, solo, etc */
706 if( $gametype != "solo")
707 if($GAME["schweinchen"] && $RULES["schweinchen"]=="both" && $GAME["schweinchen-who"]==$hash)
708 echo " Schweinchen. <br />";
710 if($GT=="poverty" && $party=="re")
711 if($sickness=="poverty")
713 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
714 $cards = DB_get_all_hand($userhash);
715 $trumpNR = count_trump($cards);
717 echo " <img src=\"pics/button/poverty_trump_button.png\" class=\"button\" alt=\"poverty < trump back\" />";
719 echo " <img src=\"pics/button/poverty_notrump_button.png\" class=\"button\" alt=\"poverty <\" />";
722 echo " <img src=\"pics/button/poverty_partner_button.png\" class=\"button\" alt=\"poverty >\" />";
726 if($sickness=="poverty")
728 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
729 $cards = DB_get_all_hand($userhash);
730 $trumpNR = count_trump($cards);
732 echo " <img src=\"pics/button/poverty_trump_button.png\" class=\"button\" alt=\"poverty < trump back\" />";
734 echo " <img src=\"pics/button/poverty_notrump_button.png\" class=\"button\" alt=\"poverty <\" />";
737 echo " <img src=\"pics/button/poverty_partner_button.png\" class=\"button\" alt=\"poverty >\" />";
739 if($sickness=="poverty")
741 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
742 $cards = DB_get_all_hand($userhash);
743 $trumpNR = count_trump($cards);
745 echo " <img src=\"pics/button/poverty2_trump_button.png\" class=\"button\" alt=\"poverty2 < trump back\" />";
747 echo " <img src=\"pics/button/poverty2_notrump_button.png\" class=\"button\" alt=\"poverty2 <\" />";
750 echo " <img src=\"pics/button/poverty2_partner_button.png\" class=\"button\" alt=\"poverty2 >\" />";
752 if($GT=="wedding" && $party=="re")
753 if($sickness=="wedding")
754 echo " <img src=\"pics/button/wedding_button.png\" class=\"button\" alt=\"wedding\" />";
756 echo " <img src=\"pics/button/wedding_partner_button.png\" class=\"button\" alt=\"wedding partner\" />";
758 if(ereg("solo",$GT) && $party=="re")
760 if(ereg("queen",$GT))
761 echo " <img src=\"pics/button/queensolo_button.png\" class=\"button\" alt=\"$GT\" />";
762 else if(ereg("jack",$GT))
763 echo " <img src=\"pics/button/jacksolo_button.png\" class=\"button\" alt=\"$GT\" />";
764 else if(ereg("club",$GT))
765 echo " <img src=\"pics/button/clubsolo_button.png\" class=\"button\" alt=\"$GT\" />";
766 else if(ereg("spade",$GT))
767 echo " <img src=\"pics/button/spadesolo_button.png\" class=\"button\" alt=\"$GT\" />";
768 else if(ereg("heart",$GT))
769 echo " <img src=\"pics/button/heartsolo_button.png\" class=\"button\" alt=\"$GT\" />";
770 else if(ereg("trumpless",$GT))
771 echo " <img src=\"pics/button/notrumpsolo_button.png\" class=\"button\" alt=\"$GT\" />";
772 else if(ereg("trump",$GT))
773 echo " <img src=\"pics/button/trumpsolo_button.png\" class=\"button\" alt=\"$GT\" />";
776 /* add point calls */
780 echo " <img src=\"pics/button/re_button.png\" class=\"button\" alt=\"re\" />";
782 echo " <img src=\"pics/button/contra_button.png\" class=\"button\" alt=\"contra\" />";
786 echo " <img src=\"pics/button/0_button.png\" class=\"button\" alt=\"0\" />";
789 echo " <img src=\"pics/button/30_button.png\" class=\"button\" alt=\"30\" />";
792 echo " <img src=\"pics/button/60_button.png\" class=\"button\" alt=\"60\" />";
795 echo " <img src=\"pics/button/90_button.png\" class=\"button\" alt=\"90\" />";
801 echo " <span title=\"".date("Y-m-d H:i:s",$timenow). "\">local time</span>\n";
802 echo " <span title=\"".date("Y-m-d H:i:s",$lastlogin)."\">last login</span>\n";
806 echo "</div>\n"; /* end output table */
813 function display_user_menu()
815 global $WIKI,$myid,$INDEX;
816 echo "<div class=\"usermenu\">\n".
817 "<a href=\"".$INDEX."\"> Go to my user page </a>";
819 $result = DB_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand".
820 " LEFT JOIN Game On Hand.game_id=Game.id".
821 " WHERE Hand.user_id='$myid'".
822 " AND Game.player='$myid'".
823 " AND Game.status<>'gameover'".
824 " ORDER BY Game.session" );
825 if(DB_num_rows($result))
826 echo "<hr />It's your turn in these games:<br />\n";
828 while( $r = DB_fetch_array($result))
830 echo "<a href=\"".$INDEX."?action=game&me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n";
833 echo "<hr /> <a href=\"".$INDEX."?action=new\">Start a new game</a>\n";
835 echo "<hr /> <a href=\"".$INDEX."?action=prefs\">Change settings</a>\n";
837 echo "<hr /> <a href=\"".$INDEX."?action=stats\">Statistics</a>\n";
840 "<hr />Report bugs in the <a href=\"".$WIKI."\">wiki</a>\n";
845 function generate_score_table($session)
848 $gameids = DB_get_gameids_of_finished_games_by_session($session);
853 $output = "<div class=\"scoretable\">\n<table class=\"score\">\n <tr>\n";
856 /* get player id, names... from the first game */
858 $result = DB_query("SELECT User.id, User.fullname from Hand".
859 " LEFT JOIN User On Hand.user_id=User.id".
860 " WHERE Hand.game_id=".$gameids[0]);
861 while( $r = DB_fetch_array($result))
863 $player[] = array( 'id' => $r[0], 'points' => 0 );
864 $output.= " <td> ".substr($r[1],0,2)." </td>\n";
866 $output.=" <td>P</td>\n </tr>\n";
868 /* get points and generate table */
869 foreach($gameids as $gameid)
873 $re_score = DB_get_score_by_gameid($gameid);
874 foreach($player as $key=>$pl)
876 $party = DB_get_party_by_gameid_and_userid($gameid,$pl['id']);
878 if(DB_get_gametype_by_gameid($gameid)=="solo")
879 $player[$key]['points'] += 3*$re_score;
881 $player[$key]['points'] += $re_score;
882 else if ($party == "contra")
883 $player[$key]['points'] -= $re_score;
885 $output.=" <td>".$player[$key]['points']."</td>\n";
887 $output.=" <td>".abs($re_score);
890 if(DB_get_gametype_by_gameid($gameid)=="solo")
892 $output.="</td>\n </tr>\n";
895 $output.="</table></div>\n";
900 function generate_global_score_table()
903 $gameids = DB_get_gameids_of_finished_games_by_session(0);
908 /* get player id, names... from the User table */
910 $result = DB_query("SELECT User.id, User.fullname FROM User");
912 while( $r = DB_fetch_array($result))
913 $player[] = array( 'id' => $r[0], 'name'=> $r[1], 'points' => 0 ,'nr' => 0);
915 /* get points and generate table */
916 foreach($gameids as $gameid)
918 $re_score = DB_get_score_by_gameid($gameid);
919 /* TODO: this shouldn't loop over all players, just the 4 players that are in the game */
920 foreach($player as $key=>$pl)
922 $party = DB_get_party_by_gameid_and_userid($gameid,$pl['id']);
924 if(DB_get_gametype_by_gameid($gameid)=="solo")
925 $player[$key]['points'] += 3*$re_score;
927 $player[$key]['points'] += $re_score;
928 else if ($party == "contra")
929 $player[$key]['points'] -= $re_score;
931 $player[$key]['nr']+=1;
935 echo "<table>\n <tr>\n";
938 if($a['nr']==0 ) return 1;
939 if($b['nr']==0) return 1;
941 $a=$a['points']/$a['nr'];
942 $b=$b['points']/$b['nr'];
946 return ($a > $b) ? -1 : 1;
948 usort($player,"cmp");
949 foreach($player as $pl)
952 echo " <tr><td>",$pl['name'],"</td><td>",round($pl['points']/$pl['nr'],3),"</td></tr>\n";