From: Matteo Nastasi (mop) Date: Thu, 16 Oct 2014 07:45:20 +0000 (+0200) Subject: GhostSess class added to manage logout reasons X-Git-Tag: v4.16.0~7 X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=1f1dc03f2bfda5d54dba9c25e8e3f9f45a4f1547;p=brisk.git GhostSess class added to manage logout reasons --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index db065d9..841ee0e 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -983,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 { @@ -999,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; @@ -1034,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, "", ""); @@ -1332,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); } @@ -2238,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 == "") { diff --git a/web/index.php b/web/index.php index 498f2fb..31d3711 100644 --- a/web/index.php +++ b/web/index.php @@ -38,8 +38,10 @@ $mlang_room = array( 'userpasserr' => array('it' => 'Utente e/o password errati 'en' => 'Standing players'), 'headline' => array('it' => 'briscola chiamata in salsa ajax', 'en' => 'declaration briscola in ajax sauce (Beta)'), - 'welcome' => array('it' => 'Digita il tuo nickname per accedere ai tavoli della briscola', - 'en' => 'Enter your nickname to access to the tables of briscola'), + 'welcome' => array('it' => 'Digita il tuo nickname per accedere ai tavoli della briscola.', + 'en' => 'Enter your nickname to access to the tables of briscola.'), + 'reas_anot' => array('it' => 'La tua sessione è stata assegnata ad un altro browser.', + 'en' => 'EN La tua sessione è stata assegnata ad un altro browser.'), 'btn_enter' => array('it' => 'entra', 'en' => 'enter'), 'passwarn' => array('it' => 'Se non hai ancora una password, lascia il campo in bianco ed entra.', @@ -336,7 +338,11 @@ function index_main(&$brisk, $transp_type, $header, &$header_out, $remote_addr_f $curtime = time(); /* Actions */ - + if (($ghost_sess = $brisk->ghost_sess->pop($sess)) != FALSE) { + if ($ghost_sess->reas == GHOST_SESS_REAS_ANOT) { + $last_msg = $mlang_room['reas_anot'][$G_lang]; + } + } if (validate_sess($sess)) { log_main("pre garbage_manager UNO"); $brisk->garbage_manager(TRUE);