+ $offset = 0;
+
+ if($call_re!=NULL)
+ $offset = 120 - $call_re;
+ else if($call_contra!=NULL)
+ $offset = -1*(120 - $call_contra)-1;
+
+ if($call_re==0)
+ $offset -= 1;
+
+ if($call_contra==0)
+ $offset += 1;
+
+ if($re > 120 + $offset)
+ {
+ /* re won */
+
+ /* normal win */
+ foreach(array(120,150,180,210,240) as $p)
+ {
+ $offset = 0;
+ if($p==240)
+ $offset = 1;
+
+ if($re>$p-$offset)
+ mysql_query("INSERT INTO Score".
+ " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'".(240-$p)."')");
+ }
+
+ /* re called something and won */
+ if($call_re!=NULL)
+ foreach(array(0,30,60,90,120) as $p)
+ {
+ if($call_re<$p+1)
+ mysql_query("INSERT INTO Score".
+ " VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
+ }
+ }
+ else
+ {
+ /* contra won */
+ mysql_query("INSERT INTO Score".
+ " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'againstqueens')");
+
+ /* normal win */
+ foreach(array(120,150,180,210,240) as $p)
+ {
+ $offset = 0;
+ if($p==240)
+ $offset = 1;
+
+ if($re>$p-$offset)
+ mysql_query("INSERT INTO Score".
+ " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'".(240-$p)."')");
+ }
+
+ /* contra called something and won */
+ if($call_contra!=NULL)
+ foreach(array(0,30,60,90,120) as $p)
+ {
+ if($call_contra<$p+1)
+ mysql_query("INSERT INTO Score".
+ " VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
+ }
+ }
+ }
+ /* send out final email */
+ $all = array();
+
+ foreach($userids as $user)
+ $all[] = DB_get_email_by_userid($user);
+ $To = implode(",",$all);
+
+ $help = "\n\n (you can use reply all on this email to reach all the players.)\n";
+ mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 1(2)",$message.$help);
+
+ foreach($userids as $user)
+ {
+ $To = DB_get_email_by_userid($user);
+ $hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
+
+ $link = "Use this link to have a look at game ".DB_format_gameid($gameid).": ".$host."?me=".$hash."\n\n" ;
+ if( DB_get_email_pref_by_uid($user) != "emailaddict" )
+ mymail($To,$EmailName."game over (game ".DB_format_gameid($gameid).") part 2(2)",$link);