G_false reference and all explicit pass by references removed
[brisk.git] / web / briskin5 / Obj / briskin5.phh
index 205a122..0c36306 100644 (file)
@@ -2,7 +2,7 @@
 /*
  *  brisk - briskin5.phh
  *
- *  Copyright (C) 2006-2009 Matteo Nastasi
+ *  Copyright (C) 2006-2011 Matteo Nastasi
  *                          mailto: nastasi@alternativeoutput.it 
  *                                  matteo.nastasi@milug.org
  *                          web: http://www.alternativeoutput.it
@@ -20,8 +20,6 @@
  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
  * Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id$
- *
  */
 define(BRISKIN5_PLAYERS_N, 3);
 define(BRISKIN5_MAX_PLAYERS, BRISKIN5_PLAYERS_N);
@@ -172,12 +170,10 @@ class Table_briskin5 extends Table {
 
 
   /* CREATE() NOT USED
-  function &create($idx) 
+  function create($idx) 
   {
-    GLOBAL $G_false;
-
     if (($thiz =& new Table_briskin5()) == FALSE)
-      return ($G_false);
+      return (FALSE);
 
     $thiz->create($idx);
 
@@ -208,12 +204,10 @@ class Table_briskin5 extends Table {
   */
 
   /* CLONE() NOT USED
-  function &myclone(&$from)
+  function myclone(&$from)
   {
-    GLOBAL $G_false;
-    
     if (($thiz =& new Table_briskin5()) == FALSE)
-      return ($G_false);
+      return (FALSE);
     
     parent::copy($from);
 
@@ -252,18 +246,17 @@ class Table_briskin5 extends Table {
     parent::copy($from);
   }
 
-  function &spawn(&$from)
+  function spawn(&$from)
   {
-    GLOBAL $G_false;
-    
     if (($thiz =& new Table_briskin5()) == FALSE)
-      return ($G_false);
+      return (FALSE);
     
     $thiz->parentcopy($from);
 
     log_main("PLAYER_N - spawn.".$thiz->player_n);
 
-    $thiz->card = &$thiz->bunch_create();
+    $thiz->card = array();
+    $thiz->bunch_create();
     $thiz->mazzo    = rand(0,PLAYERS_N-1);
     $thiz->points_n = 0;
     $thiz->mult     = 1;
@@ -281,17 +274,26 @@ class Table_briskin5 extends Table {
   }
 
 
-  function &bunch_create()
+  //   function bunch_create_old() function AND 
+  //   {
+  //     $ret = array();
+  // 
+  //     for ($i = 0 ; $i < (BRISKIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
+  //       // for ($i = 0 ; $i < 40 ; $i++) {
+  //       $ret[$i] =& new Card($i, 'bunch', 'no_owner');
+  //     }
+  // 
+  //     $oret = &$ret;
+  //     return ($oret);
+  //   }
+
+  function bunch_create()
   {
-    $ret = array();
-
-    for ($i = 0 ; $i < (BRISKIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
-      // for ($i = 0 ; $i < 40 ; $i++) {
-      $ret[$i] =& new Card($i, 'bunch', 'no_owner');
-    }
-
-    $oret = &$ret;
-    return ($oret);
+      $ret = array();
+      
+      for ($i = 0 ; $i < (BRISKIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
+          $this->card[$i] = new Card($i, 'bunch', 'no_owner');
+      }
   }
 
   function bunch_make()
@@ -430,11 +432,9 @@ class User_briskin5 extends User {
   }
 
   /* CREATE NOT USED
-  function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
-    GLOBAL $G_false;
-
+  function create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
     if (($thiz =& new User()) == FALSE)
-      return ($G_false);
+      return (FALSE);
 
     $thiz->asta_card = -2;
     $thiz->asta_pnt  = -1;
@@ -463,12 +463,10 @@ class User_briskin5 extends User {
   }
 
   /* CLONE NOT USED
-  function &myclone(&$from)
+  function myclone(&$from)
   {
-    GLOBAL $G_false;
-    
     if (($thiz =& new User()) == FALSE)
-      return ($G_false);
+      return (FALSE);
 
     $thiz->copy($from);
 
@@ -476,12 +474,12 @@ class User_briskin5 extends User {
   } 
   */
   
-  function &spawn(&$from, $table, $table_pos)
+  function spawn(&$from, $table, $table_pos)
   {
-    GLOBAL $G_false, $CO_bin5_pref_ring_endauct;
+    GLOBAL $CO_bin5_pref_ring_endauct;
     
     if (($thiz =& new User_briskin5()) == FALSE)
-      return ($G_false);
+      return (FALSE);
     
     $thiz->parentcopy($from);
 
@@ -550,9 +548,9 @@ class Briskin5 {
   }
 
 
-  function &get_user($sess, &$idx)
+  function get_user($sess, &$idx)
   {
-    GLOBAL $PHP_SELF, $G_false;
+    GLOBAL $PHP_SELF;
 
     if (validate_sess($sess)) {
       for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) {
@@ -571,13 +569,14 @@ class Briskin5 {
       log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
     }
 
-    return ($G_false);
+    return (FALSE);
   }
 
 
   function garbage_manager($force)
   {
-    
+    GLOBAL $G_base;
+
     /* Garbage collector degli utenti in timeout */
     $ismod = FALSE;
     $curtime = time();
@@ -605,6 +604,15 @@ class Briskin5 {
            
             */
 
+            /* se gli altri utenti non erano d'accordo questo utente viene bannato */
+            $remcalc = $this->table[0]->exitlock_calc(&$this->user, $user_cur->table_pos);
+            if ($remcalc < 3) {
+                require_once("${G_base}Obj/hardban.phh");
+                Hardbans::add(($user_cur->flags & USER_FLAG_AUTH ? $user_cur->name : FALSE),
+                              $user_cur->ip, $user_cur->sess, $user_cur->laccwr + BAN_TIME);
+            }
+            //      $user->bantime = $user->laccwr + BAN_TIME;
+
            $this->table_wakeup(&$user_cur);
          }
        }
@@ -624,7 +632,7 @@ class Briskin5 {
   //
   //  static functions
   //
-  function &load_data($table_idx, $table_token = "") 
+  function load_data($table_idx, $table_token = "") 
   {
     GLOBAL $G_false, $sess;
     $doexit = FALSE;
@@ -670,7 +678,7 @@ class Briskin5 {
     if ($doexit)
       exit();
     
-    return ($G_false);
+    return (FALSE);
   }
   
 
@@ -1251,7 +1259,7 @@ function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
     else
       $ret .= "remark_off();";
     
-    /* WHO CALL AND WATH */
+    /* WHO CALL AND WHAT */
     $ret .= briscola_show($room, $table, $user);
     
   }
@@ -1456,6 +1464,7 @@ function briscola_show($room, $table, $user)
     $ret .= sprintf($prestr, 
                    xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd);
   }
+  $ret .= sprintf('set_iscalling(%d);', ($table->asta_win - $user->table_pos + BRISKIN5_PLAYERS_N) % BRISKIN5_PLAYERS_N);
 
   $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
                  $table->asta_win);
@@ -1488,4 +1497,17 @@ function game_result($asta_pnt, $pnt)
   }
 }
 
+function log_points($curtime, &$user, $where, $mesg) 
+{
+  GLOBAL $_SERVER;
+
+  if (($fp = @fopen(LEGAL_PATH."/points.log", 'a')) != FALSE) {
+    /* Unix time | session | nickname | IP | where was | mesg */
+    fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
+                        ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
+                        $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
+    fclose($fp);
+  }
+}
+
 ?>