2 /* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 /* make sure that we are not called from outside the scripts,
22 * use a variable defined in config.php to check this
27 /* calling game.php only makes sense when we give it a hash for a game */
30 echo "Hmm, you really shouldn't mess with the urls.<br />\n";
33 $me = $_REQUEST['me'];
35 /* Ok, got a hash, but is it valid? */
36 $myid = DB_get_userid('hash',$me);
39 echo "Can't find you in the database, please check the url.<br />\n";
40 echo "perhaps the game has been canceled, check by login in <a href=\"$INDEX\">here</a>.";
44 global $GAME,$RULES,$CARDS;
46 /* get some information from the DB */
47 $gameid = DB_get_gameid_by_hash($me);
48 $myname = DB_get_name('hash',$me);
49 $mystatus = DB_get_status_by_hash($me);
50 $origmystatus = DB_get_status_by_hash($me); /* to show "it's your turn" menu when game has just finished */
51 $mypos = DB_get_pos_by_hash($me);
52 $myhand = DB_get_handid('hash',$me);
53 $myparty = DB_get_party_by_hash($me);
54 $session = DB_get_session_by_gameid($gameid);
56 /* get prefs and save them in a variable*/
57 $PREF = DB_get_PREF(isset($_SESSION['id'])?$_SESSION['id']:$myid);
59 /* get rule set for this game */
60 $RULES = DB_get_RULES($gameid);
62 /* get some infos about the game */
63 $gametype = DB_get_gametype_by_gameid($gameid);
64 $gamestatus = DB_get_game_status_by_gameid($gameid);
68 $gametype = DB_get_solo_by_gameid($gameid);
69 $GT = $gametype.' '.$GT;
72 /* do we need to worry about Schweinchen?
73 * check gametype and rules
74 * if yes, figure out if someone actually has Schweinchen
75 * save information in $GAME
78 if( $gamestatus == 'pre' )
80 /* always need to use Schweinchen to figure out for example who has poverty */
85 /* in a game Schweinchen is not valid in all types of games */
86 if( in_array($gametype,array('normal','wedding','trump','silent') ))
87 if( in_array($RULES['schweinchen'],array('both','second','secondaftercall')) )
91 /* these are the defaults */
92 $GAME['schweinchen-who'] = NULL;
93 $GAME['schweinchen-first'] = NULL;
94 $GAME['schweinchen-second'] = NULL;
98 /* need to check for Schweinchen */
101 $hash = DB_get_hash_from_game_and_pos($gameid,$i);
102 $cards = DB_get_all_hand($hash);
103 if( in_array('19',$cards) && in_array('20',$cards) )
104 $GAME['schweinchen-who']=$hash;
106 $GAME['schweinchen-first'] = 0; /* to keep track if they have been played already */
107 $GAME['schweinchen-second'] = 0;
109 /* end check for Schweinchen */
111 /* set the $CARDS variable, needed for sorting the cards
112 * we set it to normal so that the pre-game phase is handled ok
113 * and later set it to the correct game type that is played
115 set_gametype('normal');
117 /* put everyting in a form */
118 echo "<form action=\"index.php?action=game&me=$me\" method=\"post\">\n";
120 /* handle user notes (only possible while game is running)*/
121 if( $mystatus!='gameover' )
124 $note = $_REQUEST['note'];
127 DB_insert_note($note,$gameid,$myid);
130 /* make sure that we don't show the notes to the wrong person
131 * (e.g. other people looking at an old game)
133 if( $mystatus != 'gameover' ||
134 ( $mystatus == 'gameover' &&
135 isset($_SESSION['id']) &&
136 $myid == $_SESSION['id']))
137 output_user_notes($myid,$gameid,$mystatus);
139 /* handle calls, output a comment to show when the call was made */
140 /* initialize comments */
143 /* check for calls, set comment */
144 if(myisset('call') && $_REQUEST['call'] == '120' && can_call(120,$me))
146 $result = DB_query("UPDATE Hand SET point_call='120' WHERE hash='$me' ");
149 else if($myparty=='contra')
150 $comment .= "Contra";
152 if(myisset('call') && $_REQUEST['call'] == '90' && can_call(90,$me))
154 $result = DB_query("UPDATE Hand SET point_call='90' WHERE hash='$me' ");
157 if(myisset('call') && $_REQUEST['call'] == '60' && can_call(60,$me))
159 $result = DB_query("UPDATE Hand SET point_call='60' WHERE hash='$me' ");
162 if(myisset('call') && $_REQUEST['call'] == '30' && can_call(30,$me))
164 $result = DB_query("UPDATE Hand SET point_call='30' WHERE hash='$me' ");
167 if(myisset('call') && $_REQUEST['call'] == '0' && can_call(0,$me))
169 $result = DB_query("UPDATE Hand SET point_call='0' WHERE hash='$me' ");
173 /* get information needed to submit comment */
174 $playid = DB_get_current_playid($gameid);
178 DB_insert_comment($comment,$playid,$myid);
181 /* end check for calls */
184 /* output extra division in case this game is part of a session */
187 echo "<div class=\"session\">\n";
188 echo ' <div class="sessionrules">'._('Rules').': ';
189 switch($RULES['dullen'])
192 echo " <img class=\"rulesicon\" alt=\""._('no ten of hearts')."\" src=\"pics/button/no-ten-of-hearts.png\"/>\n"; break;
194 echo " <img class=\"rulesicon\" alt=\""._('ten of hearts')."\" src=\"pics/button/ten-of-hearts.png\"/>\n"; break;
196 echo " <img class=\"rulesicon\" alt=\""._('second ten of hearts')."\" src=\"pics/button/second-ten-of-hearts.png\"/>\n"; break;
198 switch($RULES['schweinchen'])
201 echo " <img class=\"rulesicon\" alt=\""._('no schweinchen')."\" ".
202 "src=\"pics/button/no-schweinchen.png\"/>\n"; break;
204 echo " <img class=\"rulesicon\" alt=\""._('two schweinchen')."\" ".
205 "src=\"pics/button/two-schweinchen.png\"/>\n"; break;
207 echo " <img class=\"rulesicon\" alt=\"".('second schweinchen')."\" ".
208 "src=\"pics/button/second-schweinchen.png\"/>\n"; break;
209 case 'secondaftercall':
210 echo " <img class=\"rulesicon\" alt=\""._('second schweinchen after call')."\" ".
211 "src=\"pics/button/second-schweinchen-after-call.png\"/>\n"; break;
213 switch($RULES['call'])
216 echo " <img class=\"rulesicon\" alt=\""._('1st-own-card')."\" src=\"pics/button/1st-own-card.png\"/>\n"; break;
218 echo " <img class=\"rulesicon\" alt=\""._('5th-card')."\" src=\"pics/button/5th-card.png\"/>\n"; break;
220 echo " <img class=\"rulesicon\" alt=\""._('9-cards')."\" src=\"pics/button/9-cards.png\"/>\n"; break;
223 echo ' '._('10ofhearts').": {$RULES['dullen']} <br />\n";
224 echo ' '._('schweinchen').": {$RULES['schweinchen']} <br />\n";
225 echo ' '._('call').": {$RULES['call']} <br />\n";
226 echo ' '._('lowtrump').": {$RULES['lowtrump']} <br />\n";
227 echo " </div>\n </div>\n";
231 echo " <div class=\"sessionscore\">";
233 $score = generate_score_table($session);
235 /* get the last entry to show on the main page */
237 $finalscore = array_pop($tmpscore);
238 $finalscore = $finalscore['players'];
242 echo _('Score').": \n";
243 foreach($finalscore as $user=>$value)
245 $name = DB_get_name('userid',$user);
246 echo " ".substr($name,0,2).": $value ";
251 /* first game, no score yet */
255 /* output all games for the score table */
256 echo format_score_table_html($score,$myid);
259 /* figure out which game in a session we are in and link to the
260 * previous and next game if possible
262 $hashes = DB_get_hashes_by_session($session,$myid);
265 foreach($hashes as $hash)
275 $previous = $hashes[$j-2];
283 if(isset($_SESSION['id']) && $_SESSION['id']==$myid)
286 echo "<a href=\"{$INDEX}?action=game&me=$previous\">"._('previous game')."</a> \n";
287 echo "This is game number $j of <a href=\"{$INDEX}?action=game&me=$lasthash\">$i</a> in session $session.\n";
289 echo " <a href=\"{$INDEX}?action=game&me=$next\">"._('next game')."</a> \n";
292 echo "This is game number $j of $i in session $session.";
296 /* display the table and the names */
299 /* mystatus gets the player through the different stages of a game.
300 * start: does the player want to play?
301 * init: check for sickness
302 * check: check for return values from init
303 * poverty: handle poverty, wait here until all player have reached this state
304 * display sickness and move on to game
305 * play: game in progress
306 * gameover: are we revisiting a game
309 /* the user has done something, update the timestamp. Use $myid in
310 * active games and check for session-id in old games (myid might be wrong in that case)
312 if($mystatus!='gameover')
313 DB_update_user_timestamp($myid);
315 if(isset($_SESSION['id']))
316 DB_update_user_timestamp($_SESSION['id']);
321 /* don't ask if user has autosetup set to yest */
323 if($PREF['autosetup']=='yes') $skip = 1;
325 if( !myisset('in') && !$skip)
327 /* asks the player, if he wants to join the game */
328 output_check_want_to_play($me);
329 echo '<div class="mycards"></div>';
334 /* check the result, if player wants to join, got next stage, else cancel game */
335 if(!$skip && $_REQUEST['in'] == 'no' )
337 /* cancel the game */
338 $message = "Hello, \n\n".
339 "the game has been canceled due to the request of one of the players.\n\n";
341 $userids = DB_get_all_userid_by_gameid($gameid);
342 foreach($userids as $user)
344 $subject = 'Game '.DB_format_gameid($gameid).' canceled';
345 mymail($user,$subject,$message);
348 /* update game status */
349 cancel_game('noplay',$gameid);
354 /* user wants to join the game */
356 /* move on to the next stage,
357 * no break statement to immediately go to the next stage
360 DB_set_hand_status_by_hash($me,'init');
362 /* check if everyone has reached this stage, send out email */
363 $userids = DB_get_all_userid_by_gameid($gameid);
365 foreach($userids as $user)
367 $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
368 if($userstat!='init')
370 /* whos turn is it? */
371 DB_set_player_by_gameid($gameid,$user);
378 /* all done, send out email unless this player is the startplayer */
379 $startplayer = DB_get_startplayer_by_gameid($gameid);
380 if($mypos == $startplayer)
382 /* do nothing, go to next stage */
386 /* email startplayer */
388 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
389 $who = DB_get_userid('hash',$hash);
390 DB_set_player_by_gameid($gameid,$who);
392 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
393 "Use this link to go the game: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
394 mymail($who,"Ready, set, go... (game ".DB_format_gameid($gameid).") ",$message);
401 /* here we ask the player if he is sick */
402 $mycards = DB_get_hand($me);
403 $mycards = mysort($mycards,$gametype);
405 if(!myisset('solo','wedding','poverty','nines','lowtrump') )
407 /* output sickness of other playes, in case the already selected and are sitting in front of the current player */
408 echo "\n<ul class=\"tricks\">\n";
409 echo " <li class=\"nohighlight\"> Game ".DB_format_gameid($gameid).": </li>\n";
410 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
411 " <div class=\"trick\" id=\"trick0\">\n";
413 for($pos=1;$pos<5;$pos++)
415 $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
416 $userid = DB_get_userid('gameid-position',$gameid,$pos);
417 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
419 if($userstatus=='start' || $userstatus=='init')
420 echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br/ > to decide </div>\n"; /* show this to everyone */
422 if($usersick!=NULL && $pos<=$mypos ) /* only show this for people sitting before the player */
423 echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
424 else if($usersick==NULL && $pos<=$mypos)
425 echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
427 echo " </div>\n </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
428 /* end displaying sickness */
430 output_check_for_sickness($me,$mycards);
432 echo '<div class="mycards">'._('Your cards are').": <br />\n";
433 foreach($mycards as $card)
434 display_card($card,$PREF['cardset']);
441 /* check if someone selected more than one sickness */
443 if($_REQUEST['solo']!='No') $Nsickness++;
444 if($_REQUEST['wedding'] == 'yes') $Nsickness++;
445 if($_REQUEST['poverty'] == 'yes') $Nsickness++;
446 if($_REQUEST['nines'] == 'yes') $Nsickness++;
447 if($_REQUEST['lowtrump'] == 'yes') $Nsickness++;
451 echo "<p class=\"message\"> You selected more than one sickness, please go back ".
452 "and answer the <a href=\"$INDEX?action=game&me=$me&in=yes\">question</a> again.</p>";
454 echo '<div class="mycards">'._('Your cards are').": <br />\n";
455 foreach($mycards as $card)
456 display_card($card,$PREF['cardset']);
463 /* everything is ok, save what user said and proceed */
464 echo "<p class=\"message\">Processing what you selected in the last step...";
466 /* check if this sickness needs to be handled first */
467 $gametype = DB_get_gametype_by_gameid($gameid);
468 $startplayer = DB_get_startplayer_by_gameid($gameid); /* need this to check which solo goes first */
470 if( $_REQUEST['solo']!='No' )
472 /* user wants to play a solo */
474 /* store the info in the user's hand info */
475 DB_set_solo_by_hash($me,$_REQUEST['solo']);
476 DB_set_sickness_by_hash($me,'solo');
478 echo "<br />Seems like you want to play a {$_REQUEST['solo']} solo. Got it.<br />\n";
480 if($gametype == 'solo' && $startplayer<$mypos)
481 {}/* do nothing, since someone else already is playing solo */
484 /* this solo comes first
485 * store info in game table
487 DB_set_gametype_by_gameid($gameid,'solo');
488 DB_set_startplayer_by_gameid($gameid,$mypos);
489 DB_set_solo_by_gameid($gameid,$_REQUEST['solo']);
492 else if($_REQUEST['wedding'] == 'yes')
494 /* silent solo is set further down */
495 echo _("Ok, you don't want to play a silent solo...wedding was chosen.")."<br />\n";
496 DB_set_sickness_by_hash($me,'wedding');
498 else if($_REQUEST['poverty'] == 'yes')
500 echo _("Don't think you can win with just a few trump...? Ok, poverty chosen.")." <br />\n";
501 DB_set_sickness_by_hash($me,'poverty');
503 else if($_REQUEST['nines'] == 'yes')
505 echo _("What? You just don't want to play a game because you have a few nines? Well, if no one".
506 " is playing solo, this game will be canceled.")."<br />\n";
507 DB_set_sickness_by_hash($me,'nines');
509 else if($_REQUEST['lowtrump'] == 'yes')
511 if($RULES['lowtrump']=='cancel')
512 echo _("What? You just don't want to play a game because you have low trump? Well, if no one".
513 " is playing solo, this game will be canceled.")."<br />\n";
515 echo _("Don't think you can win with low trumps...? Ok, poverty chosen.")." <br />.<br />\n";
517 DB_set_sickness_by_hash($me,'lowtrump');
522 /* move on to the next stage*/
523 DB_set_hand_status_by_hash($me,'check');
529 /* here we check what all players said and figure out what game we are playing
530 * this can therefore only be handled once all players finished the last stage
533 $mycards = DB_get_hand($me);
534 $mycards = mysort($mycards,$gametype);
536 /* output sickness of other playes, in case they already selected and are sitting in front of the current player */
537 echo "\n<ul class=\"tricks\">\n";
538 echo " <li class=\"nohighlight\"> Game ".DB_format_gameid($gameid).": </li>\n";
539 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
540 " <div class=\"trick\" id=\"trick0\">\n";
542 for($pos=1;$pos<5;$pos++)
544 $usersick = DB_get_sickness_by_pos_and_gameid($pos,$gameid);
545 $userid = DB_get_userid('gameid-position',$gameid,$pos);
546 $userstatus = DB_get_hand_status_by_userid_and_gameid($userid,$gameid);
548 if($userstatus=='start' || $userstatus=='init')
549 echo " <div class=\"vorbehalt".($pos-1)."\"> still needs <br />to decide </div>\n"; /* show this to everyone */
551 if($usersick!=NULL) /* in the init-phase we only showed players with $pos<$mypos, now we can show all */
552 echo " <div class=\"vorbehalt".($pos-1)."\"> sick </div>\n";
554 echo " <div class=\"vorbehalt".($pos-1)."\"> healthy </div>\n";
556 echo " </div>\n </li>\n</ul>\n"; /* end div trick, end li trick , end tricks*/
557 /* end displaying sickness */
559 echo "<div class=\"message\">\n";
560 echo '<p> '._('Checking if someone else selected solo, nines, wedding or poverty.').'</p>';
562 /* check if everyone has reached this stage */
563 $userids = DB_get_all_userid_by_gameid($gameid);
565 foreach($userids as $user)
567 $userstat = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
568 if($userstat!='check')
571 DB_set_player_by_gameid($gameid,$user);
578 echo '<p>'._('This step can only be handled after everyone finished the last step. '.
579 'Seems like this is not the case, so you need to wait a bit... '.
580 'you will get an email once that is the case, please use the link in '.
581 'that email to continue the game.').'</p></div>';
583 /* display cards, if player was just at the init-phase he will still see the cards from there
584 * we can put this one here, since the last player to finish the init state won't get here and
585 * will still see his card anyway from the init-phase
587 if($mystatus=='check')
590 echo '<div class="mycards">'._('Your cards are').": <br />\n";
591 foreach($mycards as $card)
592 display_card($card,$PREF['cardset']);
599 /* Ok, everyone finished the init-phase, time to figure out what game we
600 * are playing, in case there are any solos this already
601 * will have the correct information in it */
603 echo '<p>'._('Ok, everyone is done... figuring out what kind of game we are playing.').'</p>';
605 $gametype = DB_get_gametype_by_gameid($gameid);
606 $startplayer = DB_get_startplayer_by_gameid($gameid);
608 /* check for sickness */
613 foreach($userids as $user)
615 $name = DB_get_name('userid',$user);
616 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
617 if($usersick == 'nines' || ($RULES['lowtrump']=='cancel' && $usersick=='lowtrump') )
620 $cancelsick = $usersick;
621 break; /* no need to check for other poverties, since only solo can win and that is already set */
623 else if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
625 else if($usersick == 'wedding')
627 else if($usersick == 'solo')
631 /* now check which sickness comes first and set the gametype to it */
632 if($gametype == 'solo')
639 if($cancelsick == 'nines')
641 $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
642 " has five or more nines and nobody is playing solo.\n\n".
643 "To redeal either start a new game or, in case the game was part of a tournament,\n".
644 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
646 /* update game status */
647 cancel_game('nines',$gameid);
649 echo "<p>The game has been canceled because ".DB_get_name('userid',$cancel).
650 " has five or more nines and nobody is playing solo.</p>\n";
652 else if ($cancelsick == 'lowtrump')
654 $message = "The game has been canceled because ".DB_get_name('userid',$cancel).
655 " has low trump and nobody is playing solo.\n\n".
656 "To redeal either start a new game or, in case the game was part of a tournament,\n".
657 "go to the last game and use the link at the bottom of the page to redeal.\n\n";
659 /* update game status */
660 cancel_game('lowtrump',$gameid);
662 echo "<p>The game has been canceled because ".DB_get_name('userid',$cancel).
663 " has low trump and nobody is playing solo.</p>\n";
666 $userids = DB_get_all_userid_by_gameid($gameid);
667 foreach($userids as $user)
669 $subject = 'Game '.DB_format_gameid($gameid).' canceled';
670 mymail($user,$subject,$message);
673 echo "</div>\n"; /* end div message */
676 else if($poverty==1) /* one person has poverty */
678 DB_set_gametype_by_gameid($gameid,'poverty');
679 $gametype = 'poverty';
680 $who = DB_get_sickness_by_gameid($gameid);
683 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
684 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
685 DB_set_sickness_by_gameid($gameid,2); /* who needs to be asked first */
687 DB_set_sickness_by_gameid($gameid,1); /* who needs to be asked first */
690 else if($poverty==2) /* two people have poverty */
692 DB_set_gametype_by_gameid($gameid,'dpoverty');
693 $gametype = 'dpoverty';
694 $who = DB_get_sickness_by_gameid($gameid);
697 $firstsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
698 if($firstsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
700 $secondsick = DB_get_sickness_by_pos_and_gameid(1,$gameid);
701 if($secondsick == 'poverty' || ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
702 DB_set_sickness_by_gameid($gameid,30); /* who needs to be asked first */
704 DB_set_sickness_by_gameid($gameid,20); /* who needs to be asked first */
707 DB_set_sickness_by_gameid($gameid,10); /* who needs to be asked first */
712 DB_set_gametype_by_gameid($gameid,'wedding');
713 DB_set_sickness_by_gameid($gameid,'-1'); /* wedding not resolved yet */
714 $gametype = 'wedding';
716 /* now the gametype is set correctly in the database */
717 echo '<p>'._('Got it').' :)</p>';
719 /* loop over all players, set re/contra if possible and start the game if possible */
720 $userids = DB_get_all_userid_by_gameid($gameid);
721 foreach($userids as $userid)
723 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
728 /* are we the solo player? set us to re, else set us to contra */
729 $pos = DB_get_pos_by_hash($userhash);
730 if($pos == $startplayer)
731 DB_set_party_by_hash($userhash,'re');
733 DB_set_party_by_hash($userhash,'contra');
734 DB_set_hand_status_by_hash($userhash,'play');
738 /* set person with the wedding to re, do the rest during the game */
739 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
740 if($usersick == 'wedding')
741 DB_set_party_by_hash($userhash,'re');
743 DB_set_party_by_hash($userhash,'contra');
745 DB_set_hand_status_by_hash($userhash,'play');
749 $hand = DB_get_all_hand($userhash);
751 if(in_array('3',$hand)||in_array('4',$hand))
752 DB_set_party_by_hash($userhash,'re');
754 DB_set_party_by_hash($userhash,'contra');
755 DB_set_hand_status_by_hash($userhash,'play');
759 /* set person with poverty to play status */
760 $usersick = DB_get_sickness_by_userid_and_gameid($userid,$gameid);
761 if($usersick == 'poverty' || ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump'))
762 DB_set_hand_status_by_hash($userhash,'play');
764 /* set status of first player to be asked to poverty */
765 $who = DB_get_sickness_by_gameid($gameid);
766 if($who > 6) $who= $who/10; /* in case we have dpoverty */
767 $whoid = DB_get_userid('gameid-position',$gameid,$who);
769 DB_set_hand_status_by_hash($userhash,'poverty');
772 /* check for silent solo, set game type to solo in this case */
773 $gametype = DB_get_gametype_by_gameid($gameid);
774 $userids = DB_get_all_userid_by_gameid($gameid);
775 foreach($userids as $userid)
777 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$userid);
779 if($gametype=='normal')
781 $userhand = DB_get_all_hand($userhash);
782 if(check_wedding($userhand))
784 /* normal game type and player has both queens -> silent solo */
785 /* keep startplayer, just set gametype to silent solo */
786 DB_set_gametype_by_gameid($gameid,'solo');
787 DB_set_solo_by_gameid($gameid,'silent');
792 /* send out email to first player or poverty person*/
793 if($gametype!='poverty' && $gametype!='dpoverty')
795 $startplayer = DB_get_startplayer_by_gameid($gameid);
796 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
797 $who = DB_get_userid('hash',$hash);
798 DB_set_player_by_gameid($gameid,$who);
802 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
804 /* email startplayer */
805 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
806 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
807 $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).')';
808 mymail($who,$subject,$message);
812 echo "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br />\n";
816 /* set status of first player to be asked to poverty */
817 $who = DB_get_sickness_by_gameid($gameid);
818 if($who > 6) $who= $who/10; /* in case we have dpoverty */
820 $whoid = DB_get_userid('gameid-position',$gameid,$who);
822 echo "Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.<br /\n";
825 $whohash = DB_get_hash_from_game_and_pos($gameid,$who);
826 DB_set_player_by_gameid($gameid,$whoid);
828 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
830 /* email player for poverty */
831 $message = "Poverty: It's your turn now in game ".DB_format_gameid($gameid).".\n".
832 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$whohash."\n\n" ;
833 $subject = 'Poverty (game '.DB_format_gameid($gameid).') ';
834 mymail($whoid,$subject,$message);
840 echo '<div class="mycards">'._('Your cards are').": <br />\n";
841 foreach($mycards as $card)
842 display_card($card,$PREF['cardset']);
849 /* user only gets here in a poverty game, several things have to be handled here:
850 * A) ask, if user wants to take trump
852 * poverty: set re/contra
853 * dpoverty: first time: set re, send email to second player
854 * second time: set contra
855 * poverty: set status of other players to 'play'
856 * set status to play in case 0 trump
857 * no -> set status to play,
858 * ask next player or cancle the game if no more players
859 * B) user took trump and has too many cards (e.g. count(cards)>12 and re/contra set)
860 * ask to give cards back, set status to play, once player has 12 cards
862 * it is easier to check B) first
865 set_gametype($gametype); /* this sets the $CARDS variable */
866 $myparty = DB_get_party_by_hash($me);
868 /* the following is part B) of whats needs to be done)
869 /* check if user wants to give cards back */
870 if(myisset('exchange'))
872 $exchange = $_REQUEST['exchange'];
873 $partnerhash = DB_get_partner_hash_by_hash($me);
874 $partnerid = DB_get_userid('hash',$partnerhash);
875 $partnerhand = DB_get_handid('gameid-userid',$gameid,$partnerid);
877 /* if exchange is set to a value>0, exchange that card back to the partner */
880 $result = DB_query("UPDATE Hand_Card SET hand_id='$partnerhand'".
881 " WHERE hand_id='$myhand' AND card_id=".DB_quote_smart($exchange));
882 DB_add_exchanged_card(DB_quote_smart($exchange),$myhand,$partnerhand);
887 $mycards = DB_get_hand($me);
888 $mycards = mysort($mycards,$gametype);
890 /* output pre-game trick in case user reloads,
891 * only needs to be done when a team has been formed */
892 if($myparty=='re' || $myparty=='contra')
894 echo "\n<ul class=\"tricks\">\n";
895 echo " <li class=\"nohighlight\"> Game ".DB_format_gameid($gameid).": </li>\n";
897 $mygametype = DB_get_gametype_by_gameid($gameid);
899 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
900 " <div class=\"trick\" id=\"trick0\">\n";
902 /* get information so show the cards that have been handed over in a poverty game */
903 output_exchanged_cards();
905 echo " </div>\n </li>\n</ul>\n\n"; /* end div trick, end li trick , end ul tricks */
907 /* end output pre-game trick */
909 /* check if user need to give more cards back */
910 if( ($myparty=='re' || $myparty=='contra') && count($mycards)>12)
912 echo '<div class="poverty"> '._('You need to get rid of a few cards')."</div>\n";
915 echo '<div class="mycards">'._('Your cards are').": <br />\n";
916 foreach($mycards as $card)
917 display_link_card($card,$PREF['cardset'],$type);
918 echo " <input type=\"submit\" class=\"submitbutton\" value=\"select card to give back\" />\n";
921 else if( ($myparty=='re' || $myparty=='contra') && count($mycards)==12)
923 /* user is done, ready to play */
924 DB_set_hand_status_by_hash($me,'play');
926 /* email start player */
927 $startplayer = DB_get_startplayer_by_gameid($gameid);
928 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
929 $who = DB_get_userid('hash',$hash);
930 DB_set_player_by_gameid($gameid,$who);
934 if(DB_get_email_pref_by_hash($hash)!='emailaddict')
936 /* email startplayer */
937 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
938 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
939 $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).') ';
940 mymail($who,$subject,$message);
944 echo "<div class=\"message\">Please, <a href=\"$INDEX?action=game&me=$me\">start</a> the game.</div>\n";
947 /* the following is part A) of what needs to be done */
948 if(!myisset('trump'))
952 echo "<div class=\"poverty\">\n";
953 $userids = DB_get_all_userid_by_gameid($gameid);
954 foreach($userids as $user)
956 $name = DB_get_name('userid',$user);
957 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
958 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
959 $userparty = DB_get_party_by_hash($userhash);
961 if(($usersick=='poverty'|| ($RULES['lowtrump']=='poverty' && $usersick=='lowtrump')) && !$userparty)
963 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
964 $cards = DB_get_hand($hash);
967 foreach($cards as $card)
968 if($card<27) $nrtrump++;
970 if($usersick=='lowtrump')
972 echo "Player $name has $nrtrump $low trump. Do you want to take them?".
973 "<a href=\"index.php?action=game&me=$me&trump=$user\">Yes</a> <br />\n";
976 echo "<a href=\"index.php?action=game&me=$me&trump=no\">No way</a> <br />\n";
977 echo "</div><div>\n";
979 echo '<div class="mycards">'._('Your cards are').": <br />\n";
980 foreach($mycards as $card)
981 display_card($card,$PREF['cardset']);
982 echo "</div></div>\n";
988 $trump = $_REQUEST['trump'];
992 /* user doesn't want to take trump */
993 DB_set_hand_status_by_hash($me,'play');
995 /* set next player who needs to be asked and email him*/
996 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
997 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
999 /* don't ask people who have poverty */
1001 if($firstsick=='poverty' || ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1003 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1008 if($gametype=='dpoverty')
1010 $next=999; /* need to cancel for sure, since both would need to take the trump */
1013 /* no more people to ask, need to cancel the game */
1016 $message = "Hello, \n\n".
1017 "Game ".DB_format_gameid($gameid)." has been canceled since nobody wanted to take the trump.\n\n";
1019 $userids = DB_get_all_userid_by_gameid($gameid);
1020 foreach($userids as $user)
1022 $subject = 'Game '.DB_format_gameid($gameid).' canceled (poverty not resolved)';
1023 mymail($user,$subject,$message);
1026 /* update game status */
1027 cancel_game('trump',$gameid);
1029 echo "<p class=\"message\";>Game ".DB_format_gameid($gameid)." has been canceled.<br /><br /></p>";
1034 /* email next player, set his status to poverty */
1035 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1036 $userid = DB_get_userid('hash',$userhash);
1038 DB_set_player_by_gameid($gameid,$userid);
1039 DB_set_hand_status_by_hash($userhash,'poverty');
1041 $message = "Someone has poverty, it's your turn to decide, if you want to take the trump. Please visit:".
1042 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1043 $subject = 'Poverty (game '.DB_format_gameid($gameid).')';
1044 mymail($userid,$subject,$message);
1049 /* player wants to take trump, change cards */
1051 /* user wants to take trump */
1052 $trump = $_REQUEST['trump'];
1053 $userhand = DB_get_handid('gameid-userid',$gameid,$trump);
1054 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$trump);
1056 /* remember which cards were handed over*/
1057 $partnerhand = DB_get_all_hand($userhash);
1058 foreach ($partnerhand as $card)
1060 DB_add_exchanged_card($card,$userhand,$myhand);
1062 /* copy trump from player A to B */
1063 $result = DB_query("UPDATE Hand_Card SET hand_id='$myhand' WHERE hand_id='$userhand' AND card_id<'27'" );
1066 $mycards = DB_get_hand($me);
1069 if($gametype=='poverty')
1071 $userids = DB_get_all_userid_by_gameid($gameid);
1072 foreach($userids as $user)
1074 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1075 if($hash==$userhash||$hash==$me)
1077 DB_set_party_by_hash($hash,'re');
1081 DB_set_party_by_hash($hash,'contra');
1082 DB_set_hand_status_by_hash($hash,'play'); /* the contra party is ready to play */
1085 /* check if we are done (in case of no trump handed over), if so, go to 'play' phase right away*/
1086 if(count($mycards)==12)
1088 DB_set_hand_status_by_hash($me,'play');
1093 /* has the re party already been set?*/
1095 $userids = DB_get_all_userid_by_gameid($gameid);
1096 foreach($userids as $user)
1098 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1099 $party = DB_get_party_by_hash($hash);
1105 DB_set_party_by_hash($me,'contra');
1106 DB_set_party_by_hash($userhash,'contra');
1110 DB_set_party_by_hash($me,'re');
1111 DB_set_party_by_hash($userhash,'re');
1113 /* send out email to second non-poverty player */
1114 $firstsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+1,$gameid);
1115 $secondsick = (string) DB_get_sickness_by_pos_and_gameid($mypos+2,$gameid);
1118 if($firstsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $firstsick=='lowtrump'))
1119 if($secondsick=='poverty'|| ($RULES['lowtrump']=='poverty' && $secondsick=='lowtrump'))
1125 echo "<div class=\"message\">Error in poverty, please contact the Admin</div>\n";
1127 $userhash = DB_get_hash_from_game_and_pos($gameid,$mypos+$next);
1128 $userid = DB_get_userid('hash',$userhash);
1130 DB_set_player_by_gameid($gameid,$userid);
1131 DB_set_hand_status_by_hash($userhash,'poverty');
1133 $message = "Two people have poverty, it's your turn to decide, if you want to take the trump. Please visit:".
1134 " ".$HOST.$INDEX."?action=game&me=".$userhash."\n\n" ;
1135 $subject = 'Double poverty (game '.DB_format_gameid($gameid).')';
1136 mymail($userid,$subject,$message);
1139 echo "<div class=\"message\">Please, <a href=\"$INDEX?action=game&me=$me\">continue</a> here.</div>\n";
1147 /* both entries here, so that the tricks are visible for both.
1148 * in case of 'play' there is a break later that skips the last part
1151 /* first check if the game has been canceled and display */
1154 case 'cancel-noplay':
1155 echo "<div class=\"message\"><p>The game has been canceled due to the request of one player.</p><p>If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted.</p></div>";
1157 case 'cancel-timedout':
1158 echo "<div class=\"message\"><p>The game has been canceled because one player wasn't responding.</p><p>If this was a mistake all 4 players need to send an Email to $ADMIN_NAME at $ADMIN_EMAIL requesting that the game should be restarted.</p></div>";
1160 case 'cancel-nines':
1161 echo "<div class=\"message\"><p>The game has been canceled because one player had too many nines.</p></div>";
1163 case 'cancel-lowtrump':
1164 echo "<div class=\"message\"><p>The game has been canceled because one player had low trump.</p></div>";
1166 case 'cancel-trump':
1167 echo "<div class=\"message\"><p>The game has been canceled because nobody wanted to take the trump.</p></div>";
1170 /* for these two types, we shouldn't show the cards, since we might want to restart the game */
1171 if (in_array($gamestatus,array('cancel-noplay','cancel-timedout')))
1174 /* check if all players are ready to play,
1175 * if so, send out email to the startplayer
1176 * only need to do this if the game hasn't started yet
1178 $gamestatus = DB_get_game_status_by_gameid($gameid);
1179 if($gamestatus == 'pre')
1182 $userids = DB_get_all_userid_by_gameid($gameid);
1183 foreach($userids as $user)
1185 $userstatus = DB_get_hand_status_by_userid_and_gameid($user,$gameid);
1186 if($userstatus !='play' && $userstatus!='gameover')
1189 DB_set_player_by_gameid($gameid,$user);
1195 /* only set this after all poverty, etc. are handled*/
1196 DB_set_game_status_by_gameid($gameid,'play');
1198 /* email startplayer */
1199 $startplayer = DB_get_startplayer_by_gameid($gameid);
1200 $hash = DB_get_hash_from_game_and_pos($gameid,$startplayer);
1201 $who = DB_get_userid('hash',$hash);
1202 DB_set_player_by_gameid($gameid,$who);
1204 if($hash!=$me && DB_get_email_pref_by_hash($hash)!='emailaddict')
1206 /* email startplayer) */
1207 $message = "It's your turn now in game ".DB_format_gameid($gameid).".\n".
1208 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$hash."\n\n" ;
1209 $subject = 'Ready, set, go... (game '.DB_format_gameid($gameid).')';
1210 mymail($who,$subject,$message);
1214 /* figure out what kind of game we are playing,
1215 * set the global variables $CARDS['trump'],$CARDS['diamonds'],$CARDS['hearts'],
1216 * $CARDS['clubs'],$CARDS['spades'],$CARDS['foxes']
1220 $gametype = DB_get_gametype_by_gameid($gameid);
1222 if($gametype=='solo')
1224 $gametype = DB_get_solo_by_gameid($gameid);
1225 if($gametype=='silent')
1228 $GT = $gametype.' '.$GT;
1231 $gametype = 'normal';
1233 set_gametype($gametype); /* this sets the $CARDS variable */
1235 /* get some infos about the game, need to reset this, since it might have changed */
1236 $gamestatus = DB_get_game_status_by_gameid($gameid);
1238 /* has the game started? No, then just wait here...*/
1239 if($gamestatus == 'pre')
1241 echo '<p class="message"> '._('You finished the setup, but not everyone else finished it... '.
1242 'You need to wait for the others. Just wait for an email.').' </p>';
1244 $mycards = DB_get_hand($me);
1245 $mycards = mysort($mycards,$gametype);
1247 echo '<div class="mycards">'._('Your cards are').": <br />\n";
1248 foreach($mycards as $card)
1249 display_card($card,$PREF['cardset']);
1252 break; /* not sure this works... the idea is that you can
1253 * only play a card after everyone is ready to play */
1257 /* get time from the last action of the game */
1258 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
1259 $gameend = time() - strtotime($r[0]);
1261 /* handle comments in case player didn't play a card, allow comments a week after the end of the game */
1262 if( (!myisset('card') && $mystatus=='play') || ($mystatus=='gameover' && ($gameend < 60*60*24*7)) )
1263 if(myisset('comment'))
1265 $comment = $_REQUEST['comment'];
1266 $playid = DB_get_current_playid($gameid);
1269 DB_insert_comment($comment,$playid,$myid);
1272 /* get everything relevant to display the tricks */
1273 $result = DB_query("SELECT Hand_Card.card_id as card,".
1274 " Hand.position as position,".
1275 " Play.sequence as sequence, ".
1277 " GROUP_CONCAT(CONCAT('<span>',User.fullname,': ',Comment.comment,'</span>')".
1278 " SEPARATOR '\n' ), ".
1279 " Play.create_date, ".
1282 "LEFT JOIN Play ON Trick.id=Play.trick_id ".
1283 "LEFT JOIN Hand_Card ON Play.hand_card_id=Hand_Card.id ".
1284 "LEFT JOIN Hand ON Hand_Card.hand_id=Hand.id ".
1285 "LEFT JOIN Comment ON Play.id=Comment.play_id ".
1286 "LEFT JOIN User On User.id=Comment.user_id ".
1287 "WHERE Trick.game_id='".$gameid."' ".
1288 "GROUP BY Trick.id, sequence ".
1289 "ORDER BY Trick.id, sequence ASC");
1291 $lasttrick = DB_get_max_trickid($gameid);
1293 $play = array(); /* needed to calculate winner later */
1295 $pos = DB_get_startplayer_by_gameid($gameid)-1;
1296 $firstcard = ''; /* first card in a trick */
1298 echo "\n<ul class=\"tricks\">\n";
1299 echo ' <li class="nohighlight"> '._('Game').' '.DB_format_gameid($gameid).": </li>\n";
1301 /* output vorbehalte */
1302 $mygametype = DB_get_gametype_by_gameid($gameid);
1303 $mygamesolo = DB_get_solo_by_gameid($gameid);
1304 if($mygametype != 'normal') /* only show when needed */
1305 if(!( $mygametype == 'solo' && $mygamesolo == 'silent') )
1307 echo " <li onclick=\"hl('0');\" class=\"current\"><a href=\"#\">Pre</a>\n".
1308 " <div class=\"trick\" id=\"trick0\">\n";
1310 /* get information so show the cards that have been handed over in a poverty game */
1311 output_exchanged_cards();
1313 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1317 while($r = DB_fetch_array($result))
1325 /* count number of tricks */
1329 /* check if first schweinchen has been played */
1330 if( $GAME['schweinchen-who'] && ($r[0] == 19 || $r[0] == 20) )
1331 if(!$GAME['schweinchen-first'])
1332 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1334 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1336 /* save card to be able to find the winner of the trick later */
1337 $play[$seq] = array('card'=>$r[0],'pos'=>$pos);
1341 /* first card in a trick, output some html */
1342 if($trick!=$lasttrick)
1344 /* start of an old trick? */
1345 echo " <li onclick=\"hl('$trickNR');\" class=\"old\"><a href=\"#\">"._('Trick')." $trickNR</a>\n".
1346 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1347 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1349 else if($trick==$lasttrick)
1351 /* start of a last trick? */
1352 echo " <li onclick=\"hl('$trickNR');\" class=\"current\"><a href=\"#\">"._('Trick')." $trickNR</a>\n".
1353 " <div class=\"trick\" id=\"trick".$trickNR."\">\n".
1354 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1357 /* remember first card, so that we are able to check, what cards can be played */
1362 echo " <div class=\"card".($pos-1)."\">\n";
1364 /* display comments */
1366 echo " <span class=\"comment\">".$comment."</span>\n";
1369 display_card($r[0],$PREF['cardset']);
1371 echo " </div>\n"; /* end div card */
1376 $winner = get_winner($play,$gametype); /* returns the position */
1377 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1381 /* whos turn is it? */
1384 $winner = get_winner($play,$gametype); /* returns the position */
1386 $firstcard = ''; /* new trick, no first card */
1391 if($next==5) $next = 1;
1394 /* my turn?, display cards as links, ask for comments*/
1395 if(DB_get_pos_by_hash($me) == $next)
1400 /* do we want to play a card? */
1401 if(myisset('card') && $myturn)
1403 $card = $_REQUEST['card'];
1404 $handid = DB_get_handid('hash',$me);
1405 $commentSchweinchen =''; /* used to add a comment when Schweinchen is being played */
1407 /* check if we have card and that we haven't played it yet*/
1408 /* set played in hand_card to true where hand_id and card_id*/
1409 $r = DB_query_array("SELECT id FROM Hand_Card WHERE played='false' and ".
1410 "hand_id='$handid' AND card_id=".DB_quote_smart($card));
1411 $handcardid = $r[0];
1413 if($handcardid) /* everything ok, play card */
1415 /* update Game timestamp */
1416 DB_update_game_timestamp($gameid);
1418 /* mark card as played */
1419 DB_query("UPDATE Hand_Card SET played='true' WHERE hand_id='$handid' AND card_id=".
1420 DB_quote_smart($card));
1422 /* get trick id or start new trick */
1423 $a = DB_get_current_trickid($gameid);
1428 $playid = DB_play_card($trickid,$handcardid,$sequence);
1430 /* check special output for schweinchen in case in case a fox is being played
1431 * check for correct rules, etc. has already been done
1433 if( $GAME['schweinchen-who'] && ($card == 19 || $card == 20) )
1435 if(!$GAME['schweinchen-first'])
1436 $GAME['schweinchen-first'] = 1; /* playing the first fox */
1438 $GAME['schweinchen-second'] = 1; /* this must be the second fox */
1440 if( $RULES['schweinchen']=='both' ||
1441 ($RULES['schweinchen']=='second' && $GAME['schweinchen-second']==1 )||
1442 ($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-second']==1 &&
1443 (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
1446 DB_insert_comment('Schweinchen! ',$playid,$myid);
1447 $commentSchweinchen = 'Schweinchen! ';
1450 echo 'schweinchen = '.$GAME['schweinchen-who'].' ---<br />';
1453 /* if sequence == 4 check who one in case of wedding */
1454 if($sequence == 4 && $GT == 'wedding')
1456 /* is wedding resolve */
1457 $resolved = DB_get_sickness_by_gameid($gameid);
1460 /* who has wedding */
1461 $userids = DB_get_all_userid_by_gameid($gameid);
1462 foreach($userids as $user)
1464 $usersick = DB_get_sickness_by_userid_and_gameid($user,$gameid);
1465 if($usersick == 'wedding')
1468 /* who won the trick */
1469 $play = DB_get_cards_by_trick($trickid);
1470 $winner = get_winner($play,$gametype); /* returns the position */
1471 $winnerid = DB_get_userid('gameid-position',$gameid,$winner);
1472 /* is tricknr <=3 */
1473 if($tricknr <=3 && $winnerid!=$whosick)
1475 /* set resolved at tricknr*/
1476 $resolved = DB_set_sickness_by_gameid($gameid,$tricknr);
1478 $whash = DB_get_hash_from_gameid_and_userid($gameid,$winnerid);
1479 DB_set_party_by_hash($whash,'re');
1481 if($tricknr == 3 && $winnerid==$whosick)
1483 /* set resolved at tricknr*/
1484 $resolved = DB_set_sickness_by_gameid($gameid,'3');
1489 /* if sequence == 4, set winner of the trick, count points and set the next player */
1492 $play = DB_get_cards_by_trick($trickid);
1493 $winner = get_winner($play,$gametype); /* returns the position */
1496 * check if someone caught a fox
1497 *******************************/
1499 /* first check if we should account for solos at all,
1500 * since it doesn't make sense in some games
1502 $ok = 0; /* fox shouldn't be counted */
1503 if(DB_get_gametype_by_gameid($gameid)=='solo')
1505 $solo = DB_get_solo_by_gameid($gameid);
1506 if($solo == 'trump' || $solo == 'silent')
1507 $ok = 1; /* for trump solos and silent solos, foxes are ok */
1510 $ok = 1; /* for all other games (not solos) foxes are ok too */
1513 foreach($play as $played)
1515 if ( $played['card']==19 || $played['card']==20 )
1516 if ($played['pos']!= $winner )
1518 /* possible caught a fox, check party */
1519 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1520 $uid2 = DB_get_userid('gameid-position',$gameid,$played['pos']);
1522 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1523 $party2 = DB_get_party_by_gameid_and_userid($gameid,$uid2);
1525 if($party1 != $party2)
1526 DB_query("INSERT INTO Score".
1527 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,$uid2,'fox')");
1532 * check for karlchen (jack of clubs in the last trick)
1533 ******************************************************/
1535 /* same as for foxes, karlchen doesn't always make sense
1536 * check what kind of game it is and set karlchen accordingly */
1538 if($tricknr == 12 ) /* Karlchen works only in the last trick */
1540 /* check for solo */
1542 if(DB_get_gametype_by_gameid($gameid)=='solo' )
1543 $solo = DB_get_solo_by_gameid($gameid);
1545 /* no Karlchen in these solos */
1546 if($solo != 'trumpless' && $solo != 'jack' && $solo != 'queen' )
1548 foreach($play as $played)
1549 if ( $played['card']==11 || $played['card']==12 )
1550 if ($played['pos'] == $winner )
1553 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1554 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1556 DB_query("INSERT INTO Score".
1557 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
1560 }; /* end scoring Karlchen */
1563 * check for doppelopf (>40 points)
1564 ***********************************/
1567 foreach($play as $played)
1569 $points += DB_get_card_value_by_cardid($played['card']);
1573 $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
1574 $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
1576 DB_query("INSERT INTO Score".
1577 " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
1581 * set winner (for this trick)
1585 DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
1587 echo "ERROR during scoring";
1590 echo "DEBUG: position $winner won the trick <br />";
1592 /* who is the next player? */
1597 $next = DB_get_pos_by_hash($me)+1;
1599 if($next==5) $next=1;
1601 /* check for coment */
1602 if(myisset('comment'))
1604 $comment = $_REQUEST['comment'];
1606 DB_insert_comment($comment,$playid,$myid);
1607 if($commentSchweinchen)
1608 $comment = $commentSchweinchen . $comment;
1611 /* display played card */
1612 $pos = DB_get_pos_by_hash($me);
1615 echo " <li onclick=\"hl('".($tricknr)."');\" class=\"current\"><a href=\"#\">"._('Trick').' '.($tricknr)."</a>\n".
1616 " <div class=\"trick\" id=\"trick".($tricknr)."\">\n".
1617 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";
1620 echo " <div class=\"card".($pos-1)."\">\n ";
1622 /* display comments */
1623 display_card($card,$PREF['cardset']);
1625 echo "\n <span class=\"comment\"> ".$comment."</span>\n";
1628 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1630 /*check if we still have cards left, else set status to gameover */
1631 if(sizeof(DB_get_hand($me))==0)
1633 DB_set_hand_status_by_hash($me,'gameover');
1634 $mystatus = 'gameover';
1637 /* if all players are done, set game status to game over,
1638 * get the points of the last trick and send out an email
1641 $userids = DB_get_all_userid_by_gameid($gameid);
1644 foreach($userids as $user)
1645 if(DB_get_hand_status_by_userid_and_gameid($user,$gameid)!='gameover')
1649 DB_set_game_status_by_gameid($gameid,'gameover');
1651 /* email next player, if game is still running */
1652 if(DB_get_game_status_by_gameid($gameid)=='play')
1654 $next_hash = DB_get_hash_from_game_and_pos($gameid,$next);
1655 $who = DB_get_userid('hash',$next_hash);
1656 DB_set_player_by_gameid($gameid,$who);
1658 $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
1659 "It's your turn now.\n".
1660 "Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
1661 if( DB_get_email_pref_by_uid($who)!='emailaddict' )
1663 $subject = 'A card has been played in game '.DB_format_gameid($gameid);
1664 mymail($who,$subject,$message);
1667 else /* send out final email */
1669 /* individual score */
1670 $result = DB_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party FROM Hand".
1671 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1672 " LEFT JOIN User ON User.id=Hand.user_id".
1673 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1674 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1675 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1676 " WHERE Hand.game_id='$gameid'".
1677 " GROUP BY User.fullname" );
1678 $message = "The game is over. Thanks for playing :)\n";
1679 $message .= "Final score:\n";
1680 while( $r = DB_fetch_array($result) )
1681 $message .= " ".$r[0]."(".$r[2].") ".$r[1]."\n";
1683 $result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
1684 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1685 " LEFT JOIN User ON User.id=Hand.user_id".
1686 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1687 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1688 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1689 " WHERE Hand.game_id='$gameid'".
1690 " GROUP BY Hand.party" );
1691 $message .= "\nTotals:\n";
1694 while( $r = DB_fetch_array($result) )
1696 $message .= " ".$r[0]." ".$r[1]."\n";
1699 else if($r[0] == 'contra')
1704 * save score in database
1708 /* get calls from re/contra */
1710 $call_contra = NULL;
1711 foreach($userids as $user)
1713 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1714 $call = DB_get_call_by_hash($hash);
1715 $party = DB_get_party_by_hash($hash);
1719 $call = (int) $call;
1725 else if( $call < $call_re)
1728 else if($party=='contra')
1730 if($call_contra==NULL)
1731 $call_contra = $call;
1732 else if( $call < $call_contra)
1733 $call_contra = $call;
1738 /* figure out who one */
1739 $winning_party = NULL;
1741 if($call_re == NULL && $call_contra==NULL)
1743 /* nobody made a call, so it's easy to figure out who won */
1745 $winning_party='re';
1747 $winning_party='contra';
1751 /* if one party makes a call, they only win, iff they make enough points
1752 * if only one party made a call, the other one wins,
1753 * if the first one didn't make it
1757 $offset = 120 - $call_re;
1759 $offset--; /* since we use a > in the next equation */
1761 if($re > 120+$offset)
1762 $winning_party='re';
1763 else if ($call_contra == NULL )
1764 $winning_party='contra';
1769 $offset = 120 - $call_contra;
1770 if($call_contra == 0)
1771 $offset--; /* since we use a > in the next equation */
1773 if($contra > 120+$offset)
1774 $winning_party='contra';
1775 else if ($call_re == NULL )
1776 $winning_party='re';
1780 /* one point for each call of the other party in case the other party didn't win
1781 * and one point each in case the party made more than points than one of the calls
1783 if($winning_party!='contra' && $call_contra!=NULL)
1785 for( $p=$call_contra;$p<=120; $p+=30 )
1787 DB_query("INSERT INTO Score".
1788 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'against$p')");
1791 for( $p=$call_contra; $p<120; $p+=30)
1794 DB_query("INSERT INTO Score".
1795 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')");
1798 if($winning_party!='re' and $call_re!=NULL)
1800 for( $p=$call_re;$p<=120; $p+=30 )
1802 DB_query("INSERT INTO Score".
1803 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'against$p')");
1806 for( $p=$call_re; $p<120; $p+=30)
1809 DB_query("INSERT INTO Score".
1810 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'made$p')");
1814 /* point in case contra won */
1815 if($winning_party=='contra')
1817 DB_query("INSERT INTO Score".
1818 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
1821 /* one point each for winning and each 30 points + calls */
1822 if($winning_party=='re')
1824 foreach(array(120,150,180,210,240) as $p)
1827 if($p==240 || $call_contra!=NULL)
1831 DB_query("INSERT INTO Score".
1832 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
1834 /* re called something and won */
1835 foreach(array(0,30,60,90,120) as $p)
1837 if($call_re!=NULL && $call_re<$p+1)
1838 DB_query("INSERT INTO Score".
1839 " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
1842 else if( $winning_party=='contra')
1844 foreach(array(120,150,180,210,240) as $p)
1847 if($p==240 || $call_re!=NULL)
1850 if($contra>$p-$offset)
1851 DB_query("INSERT INTO Score".
1852 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
1854 /* re called something and won */
1855 foreach(array(0,30,60,90,120) as $p)
1857 if($call_contra!=NULL && $call_contra<$p+1)
1858 DB_query("INSERT INTO Score".
1859 " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
1864 /* add score points to email */
1867 $message .= " Points Re: \n";
1868 $queryresult = DB_query("SELECT score FROM Score ".
1869 " WHERE game_id=$gameid AND party='re'".
1871 while($r = DB_fetch_array($queryresult) )
1873 $message .= " ".$r[0]."\n";
1876 $message .= " Points Contra: \n";
1877 $queryresult = DB_query("SELECT score FROM Score ".
1878 " WHERE game_id=$gameid AND party='contra'".
1880 while($r = DB_fetch_array($queryresult) )
1882 $message .= " ".$r[0]."\n";
1885 $message .= " Total Points (from the Re point of view): $Tpoint\n";
1888 $session = DB_get_session_by_gameid($gameid);
1889 $score = generate_score_table($session);
1891 $message .= "Score Table:\n";
1892 $message .= format_score_table_ascii($score);
1893 $message .= "\nUse these links to have a look at game ".DB_format_gameid($gameid).": \n";
1895 /* send out final email */
1896 foreach($userids as $user)
1898 /* add links for all players */
1899 $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
1900 $name = DB_get_name('userid',$user);
1902 $link = "$name: ".$HOST.$INDEX."?action=game&me=".$hash."\n" ;
1905 $message .= "\n\n (you can use reply all on this email to reach all the players.)\n\n";
1906 $subject = ' Game over (game '.DB_format_gameid($gameid).') ';
1907 mymail($userids,$subject,$message);
1912 echo "can't find that card?! <br />\n";
1915 else if(myisset('card') && !$myturn )
1917 echo _("please wait until it's your turn!")."<br />\n";
1920 if($seq!=4 && $trickNR>=1 && !(myisset('card') && $myturn) )
1921 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1923 /* display points in case game is over */
1924 if($mystatus=='gameover' && DB_get_game_status_by_gameid($gameid)=='gameover' )
1926 echo " <li onclick=\"hl('13');\" class=\"current\"><a href=\"#\">"._('Score')."</a>\n".
1927 " <div class=\"trick\" id=\"trick13\">\n";
1928 /* add pic for re/contra
1929 " <img class=\"arrow\" src=\"pics/arrow".($pos-1).".png\" alt=\"table\" />\n";*/
1931 $result = DB_query("SELECT User.fullname, IFNULL(SUM(Card.points),0), Hand.party,Hand.position FROM Hand".
1932 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1933 " LEFT JOIN User ON User.id=Hand.user_id".
1934 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1935 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1936 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1937 " WHERE Hand.game_id='$gameid'".
1938 " GROUP BY User.fullname" );
1939 while( $r = DB_fetch_array($result))
1940 echo " <div class=\"card".($r[3]-1)."\">\n".
1941 " <div class=\"score\">".$r[2]."<br /> ".$r[1]."</div>\n".
1944 /* display totals */
1945 $result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
1946 " LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
1947 " LEFT JOIN User ON User.id=Hand.user_id".
1948 " LEFT JOIN Play ON Trick.id=Play.trick_id".
1949 " LEFT JOIN Hand_Card ON Hand_Card.id=Play.hand_card_id".
1950 " LEFT JOIN Card ON Card.id=Hand_Card.card_id".
1951 " WHERE Hand.game_id='$gameid'".
1952 " GROUP BY Hand.party" );
1953 echo "<div class=\"total\">\n Totals:<br />\n";
1954 while( $r = DB_fetch_array($result))
1955 echo " ".$r[0]." ".$r[1]."<br />\n";
1957 $queryresult = DB_query("SELECT timediff(mod_date,create_date) ".
1958 " FROM Game WHERE id='$gameid'");
1959 $r = DB_fetch_array($queryresult);
1960 echo " <p>This game took ".$r[0]." hours.</p>\n";
1962 echo " <div class=\"re\">\n Points Re: <br />\n";
1963 $queryresult = DB_query("SELECT score FROM Score ".
1964 " WHERE game_id=$gameid AND party='re'".
1966 while($r = DB_fetch_array($queryresult) )
1967 echo " ".$r[0]."<br />\n";
1970 echo " <div class=\"contra\">\n Points Contra: <br />\n";
1971 $queryresult = DB_query("SELECT score FROM Score ".
1972 " WHERE game_id=$gameid AND party='contra'".
1974 while($r = DB_fetch_array($queryresult) )
1975 echo " ".$r[0]."<br />\n";
1980 echo " </div>\n </li>\n"; /* end div trick, end li trick */
1983 echo " <li onclick=\"hl_prev();\" class=\"old\"><a href=\"#\">"._('prev')."</a></li>\n";
1984 echo " <li onclick=\"hl_next();\" class=\"old\"><a href=\"#\">"._('next')."</a></li>\n";
1985 echo "</ul>\n"; /* end ul tricks*/
1987 $mycards = DB_get_hand($me);
1988 $mycards = mysort($mycards,$gametype);
1989 echo "<div class=\"mycards\">\n";
1991 if($myturn && !myisset('card') && $mystatus=='play' )
1993 echo "Hello ".$myname.", it's your turn! <br />\n";
1994 echo _('Your cards are').": <br />\n";
1996 /* do we have to follow suite? */
1998 if(have_suit($mycards,$firstcard))
2001 /* count how many cards we can play, so that we can pre-select it if there is only one */
2003 foreach($mycards as $card)
2008 /* display only cards that the player is allowed to play as links, the rest just display normal
2009 * also check if we have both schweinchen, in that case only display on of them as playable
2011 if( ($followsuit && !same_type($card,$firstcard)) ||
2012 ( (int)($card)==19 &&
2013 !$GAME['schweinchen-first'] &&
2014 ( $RULES['schweinchen']=='second' ||
2015 ( $RULES['schweinchen']=='secondaftercall' &&
2016 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2017 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2020 $GAME['schweinchen-who']==$me &&
2021 in_array($gametype,array('normal','wedding','trump','silent'))
2029 if($howmanycards==1)
2034 foreach($mycards as $card)
2036 /* display only cards that the player is allowed to play as links, the rest just display normal
2037 * also check if we have both schweinchen, in that case only display on of them as playable
2039 if( ($followsuit && !same_type($card,$firstcard)) ||
2040 ( (int)($card)==19 &&
2041 !$GAME['schweinchen-first'] &&
2042 ( $RULES['schweinchen']=='second' ||
2043 ( $RULES['schweinchen']=='secondaftercall' &&
2044 (DB_get_call_by_hash($GAME['schweinchen-who']) ||
2045 DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
2048 $GAME['schweinchen-who']==$me &&
2049 in_array($gametype,array('normal','wedding','trump','silent'))
2052 display_card($card,$PREF['cardset']);
2054 display_link_card($card,$PREF['cardset'],$type='card',$selected=$howmanycards);
2057 else if($mystatus=='play' )
2059 echo _('Your cards are').": <br />\n";
2060 foreach($mycards as $card)
2061 display_card($card,$PREF['cardset']);
2063 else if($mystatus=='gameover')
2065 $oldcards = DB_get_all_hand($me);
2066 $oldcards = mysort($oldcards,$gametype);
2068 if(isset($_SESSION['id']) && $myid==$_SESSION['id'])
2069 echo _('Your cards were').": <br />\n";
2072 $name = DB_get_name('userid',$myid);
2073 echo "$name's were: <br />\n";
2076 foreach($oldcards as $card)
2077 display_card($card,$PREF['cardset']);
2079 $userids = DB_get_all_userid_by_gameid($gameid);
2080 foreach($userids as $user)
2082 $userhash = DB_get_hash_from_gameid_and_userid($gameid,$user);
2088 $name = DB_get_name('userid',$user);
2089 $oldcards = DB_get_all_hand($userhash);
2090 $oldcards = mysort($oldcards,$gametype);
2091 echo "$name's cards were: <br />\n";
2092 foreach($oldcards as $card)
2093 display_card($card,$PREF['cardset']);
2099 /* if the game is over do some extra stuff, therefore exit the swtich statement if we are still playing*/
2100 if($mystatus=='play')
2103 /* the following happens only when the gamestatus is 'gameover' */
2104 /* check if game is over, display results */
2105 if(DB_get_game_status_by_gameid($gameid)=='play')
2107 echo _('The game is over for you... other people still need to play though');
2111 myerror("error in testing the status");
2114 /* output other games where it is the users turn
2115 * make sure that the people looking at old games don't see the wrong games here
2117 if( $gamestatus != 'gameover' )
2119 /* game isn't over, only valid user can get here, so show menu */
2120 display_user_menu($myid);
2122 else if( $origmystatus != 'gameover' )
2124 /* user just played the very last card, game is now over, it's still ok to show the menu though */
2125 display_user_menu($myid);
2127 else if( $mystatus == 'gameover' &&
2128 isset($_SESSION['id']) )
2130 /* user is looking at someone else's game, show the menu for the correct user */
2131 display_user_menu($_SESSION['id']);
2135 echo "<div class=\"usermenu\">\n";
2136 echo "It's your turn in these games:<br />\n";
2137 echo "Please log in to see this information.\n";
2142 * display gameinfo: re/contra, comment-box, play-card button, games played by others
2145 echo "<div class=\"gameinfo\">\n";
2147 /* get time from the last action of the game */
2148 $r = DB_query_array("SELECT mod_date from Game WHERE id='$gameid' " );
2149 $gameend = time() - strtotime($r[0]);
2152 if($gamestatus == 'play' || $gameend < 60*60*24*7)
2154 echo ' '._('A short comment').":<input name=\"comment\" type=\"text\" size=\"20\" maxlength=\"100\" />\n";
2158 if($gamestatus == 'play' )
2160 $myparty = DB_get_party_by_hash($me);
2161 output_form_calls($me,$myparty);
2164 /* play-card button */
2165 if($gamestatus == 'play' || $gameend < 60*60*24*7)
2167 echo " <input type=\"submit\" value=\""._('submit')."\" />\n";
2170 /* has this hand been played by others? */
2171 $other_game_ids = DB_played_by_others($gameid);
2172 if(sizeof($other_game_ids)>0 && $mystatus=='gameover')
2174 $mypos = DB_get_pos_by_hash($me);
2175 echo " <p>See how other played the same hand: \n";
2176 foreach($other_game_ids as $id)
2178 $otherhash = DB_get_hash_from_game_and_pos($id,$mypos);
2179 $othername = DB_get_name('hash',$otherhash);
2180 echo " <a href=\"$INDEX?action=game&me=$otherhash\">$othername</a> ";
2185 echo "</div>\n"; /* end gameinfo */
2189 $gamestatus = DB_get_game_status_by_gameid($gameid);
2190 if($mystatus=='gameover' &&
2191 ($gamestatus =='gameover' || $gamestatus =='cancel-nines' || $gamestatus =='cancel-trump') &&
2192 isset($_SESSION['id']) && $_SESSION['id']==$myid)
2194 $session = DB_get_session_by_gameid($gameid);
2195 $result = DB_query("SELECT id,create_date FROM Game".
2196 " WHERE session=$session".
2197 " ORDER BY create_date DESC".
2201 $r = DB_fetch_array($result);
2203 if(!$session || $gameid==$r[0])
2205 /* suggest a new game with the same people in it, just rotated once (unless last game was solo) */
2206 $names = DB_get_all_names_by_gameid($gameid);
2207 $type = DB_get_gametype_by_gameid($gameid);
2211 $solo = DB_get_solo_by_gameid($gameid);
2213 if($solo!='silent') /* repeat game with same first player */
2214 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2215 else /* rotate normally */
2216 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);
2218 else if($gamestatus == 'cancel-nines' || $gamestatus == 'cancel-trump')
2219 output_ask_for_new_game($names[0],$names[1],$names[2],$names[3],$gameid);
2220 else /* rotate normally */
2221 output_ask_for_new_game($names[1],$names[2],$names[3],$names[0],$gameid);