GhostSess class added to manage logout reasons
[brisk.git] / web / Obj / brisk.phh
index 41653d1..841ee0e 100644 (file)
@@ -64,22 +64,23 @@ define('NICKSERV', "BriskServ");
 
 define('LOCK_SHARE_MAX', 10000);
 
-define('DBG_ONL2', 0x0001);
-define('DBG_ONLY', 0x0002);
-define('DBG_MAIN', 0x0004);
-define('DBG_READ', 0x0008);
-define('DBG_REA2', 0x0010);
-define('DBG_SEND', 0x0020);
-define('DBG_LOCK', 0x0040);
-define('DBG_WRIT', 0x0080);
-define('DBG_LOAD', 0x0100);
-define('DBG_AUTH', 0x0200);
-define('DBG_CRIT', 0x0400);
-define('DBG_LMOP', 0x0800);
-define('DBG_TRAC', 0x1000);
-define('DBG_SHME', 0x2000);
-define('DBG_ENGI', 0x4000);
-define('DBG_CDS',  0x8000);
+define('DBG_ONL2', 0x000001);
+define('DBG_ONLY', 0x000002);
+define('DBG_MAIN', 0x000004);
+define('DBG_READ', 0x000008);
+define('DBG_REA2', 0x000010);
+define('DBG_SEND', 0x000020);
+define('DBG_LOCK', 0x000040);
+define('DBG_WRIT', 0x000080);
+define('DBG_LOAD', 0x000100);
+define('DBG_AUTH', 0x000200);
+define('DBG_CRIT', 0x000400);
+define('DBG_LMOP', 0x000800);
+define('DBG_TRAC', 0x001000);
+define('DBG_SHME', 0x002000);
+define('DBG_ENGI', 0x004000);
+define('DBG_CDS',  0x008000);
+define('DBG_STEP', 0x010000);
 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
 define('BRISK_DEBUG', 0x0800);
 
@@ -152,10 +153,10 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
 $G_lng = langtolng($G_lang);
 
 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
-$G_brisk_version = "4.14.5";
+$G_brisk_version = "4.15.0";
 
 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
-$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo sistema di registrazione degli utenti, aggiunto reinvio dell\' email di verifica, ban con classi di IP, nuovi colori, nuovo sistema bi banner laterali per gli eventi',
+$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: primo passo per rendere piĆ¹ robusto il sistema di notifica.',
                                        'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
                        'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: new users subscription system, refactored sidebanner system.',
                                        'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
@@ -982,6 +983,67 @@ class Client_prefs {
     }
 }
 
+define('GHOST_SESS_TOUT', 300);
+define('GHOST_SESS_REAS_ANOT', 1);
+class GhostSessEl
+{
+    var $time;
+    var $sess;
+    var $reas;
+
+    function GhostSessEl($time, $sess, $reas)
+    {
+        $this->time = $time + GHOST_SESS_TOUT;
+        $this->sess = $sess;
+        $this->reas = $reas;
+    }
+}
+
+class GhostSess
+{
+    var $gs;
+
+    function GhostSess()
+    {
+        $this->gs = array();
+    }
+
+    // push or update for this session
+    function push($time, $sess, $reas)
+    {
+        foreach($this->gs as $el) {
+            if ($el->sess == "$sess") {
+                $el->reas = $reas;
+                $el->time = $time + GHOST_SESS_TOUT;
+                return TRUE;
+            }
+        }
+
+        $this->gs[] = new GhostSessEl($time, $sess, $reas);
+        return TRUE;
+    }
+
+    function pop($sess)
+    {
+        foreach($this->gs as $key => $el) {
+            if ($el->sess == "$sess") {
+                $ret = $this->gs[$key];
+                unset($this->gs[$key]);
+                return ($ret);
+            }
+        }
+        return FALSE;
+    }
+
+    function garbage_manager($curtime)
+    {
+        foreach($this->gs as $key => $el) {
+            if ($el->time < $curtime) {
+                unset($this->gs[$key]);
+            }
+        }
+    }
+}
 
 class Brisk
 {
@@ -998,7 +1060,7 @@ class Brisk
 
     var $ban_list;  // ban list (authized allowed)
     var $black_list;  // black list (anti-dos, noone allowed)
-
+    var $ghost_sess;
     var $delay_mgr;
 
     var $cds;
@@ -1033,6 +1095,7 @@ class Brisk
 
         $thiz->ban_list = NULL;
         $thiz->black_list = NULL;
+        $thiz->ghost_sess = new GhostSess();
 
         for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
             $thiz->user[$i] = User::create($thiz, $i, "", "");
@@ -1331,6 +1394,8 @@ class Brisk
     $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
     $ismod = TRUE;
 
+    $this->ghost_sess->garbage_manager($curtime);
+
     $this->delay_mgr->lastcheck_set($curtime);
     return ($ismod);
   }
@@ -2237,6 +2302,7 @@ class Brisk
 
       $ghost_user = $this->user[$ghost];
       $curtime = time();
+      $this->ghost_sess->push($curtime, $ghost_user->sess, GHOST_SESS_REAS_ANOT);
       $ghost_user->comm[$ghost_user->step % COMM_N] = "";
       $ghost_user->step_inc();
       if ($sess == "") {
@@ -2720,6 +2786,33 @@ function log_mop($step, $log)
     }
 }
 
+function log_step($log)
+{
+    GLOBAL $PHP_SELF;
+
+    if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_STEP) == 0)
+        return;
+
+    $sess = Brisk::sess_cur_get();
+    if (isset($sess) == FALSE)
+        $ssess = "XXXX";
+    else
+        $ssess = $sess;
+
+    if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_STEP) == 0)
+        return;
+
+    if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
+        $btrace = btrace_line(debug_backtrace());
+    else
+        $btrace = "";
+    if (($fp = @fopen(LEGAL_PATH."/step.log", 'a')) != FALSE) {
+        fwrite($fp, sprintf("STEP: [%f] [%s] [%s]\n", gettimeofday(TRUE), $log, $btrace));
+        fclose($fp);
+    }
+}
+
+
 
 function log_cds($log)
 {