From bd3aa68b123e6af44c44f3b155d280b40bbd7bd6 Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Sat, 25 Oct 2014 11:31:40 +0200 Subject: [PATCH] first step for better steps management --- web/Obj/brisk.phh | 60 +++++++++++++++++++++++++++++++----------- web/Obj/sac-a-push.phh | 2 ++ web/Obj/user.phh | 6 ++++- web/commons.js | 2 +- web/index_wr.php | 9 ++++++- 5 files changed, 60 insertions(+), 19 deletions(-) diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 41653d1..ea90ddd 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -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); @@ -2720,6 +2721,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) { diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index e4e020d..5f9818a 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -156,6 +156,8 @@ function spu_process_info($stream_info, &$method, &$header, &$get, &$post, &$coo printf("A COUNT: [%s] %d\n", $a[0], count($a)); for ($i = 0 ; $i < count($a) ; $i++) { $b = explode('=', $a[$i]); + if ($b[0] == "") + continue; $get[$b[0]] = urldecode($b[1]); } } diff --git a/web/Obj/user.phh b/web/Obj/user.phh index 6cdb1fe..fcabab7 100644 --- a/web/Obj/user.phh +++ b/web/Obj/user.phh @@ -119,6 +119,7 @@ class User { var $subst; // substatus for each status var $step; // step of the current status var $trans_step; // step to enable transition between pages (disable == -1) + var $cl_step; // current step returned by client var $rd_socket; // socket handle of push stream var $rd_endtime; // end time for push stream @@ -180,6 +181,7 @@ class User { $thiz->subst = $subst; $thiz->step = 1; $thiz->trans_step = -1; + $thiz->cl_step = -1; $thiz->comm = array(); $thiz->rd_socket = NULL; @@ -233,6 +235,7 @@ class User { $this->subst = $from->subst; $this->step = $from->step; $this->trans_step = $from->trans_step; + $this->cl_step = $from->cl_step; $this->comm = array(); $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N)); @@ -296,6 +299,7 @@ class User { $thiz->subst = $from->subst; $thiz->step = $from->step; $thiz->trans_step = $from->trans_step; + $thiz->cl_step = $from->cl_step; $thiz->comm = array(); /* @@ -615,7 +619,7 @@ class User { $ret = FALSE; $curtime = time(); - + /* Nothing changed, return. */ if ($this->rd_step == $this->step) return (FALSE); diff --git a/web/commons.js b/web/commons.js index 36eb7c4..851749f 100644 --- a/web/commons.js +++ b/web/commons.js @@ -270,7 +270,7 @@ function send_mesg(mesg) var is_conn = (sess == "not_connected" ? false : true); // alert("xhr_wr: "+xhr_wr+" is_conn: "+is_conn); - xhr_wr.open('GET', 'index_wr.php?'+(is_conn ? 'sess='+sess+'&' : '')+'mesg='+mesg, (is_conn ? true : false)); + xhr_wr.open('GET', 'index_wr.php?&'+(is_conn ? 'sess='+sess : '')+'&stp='+gst.st+'&mesg='+mesg, (is_conn ? true : false)); xhr_wr.setRequestHeader("If-Modified-Since", new Date().toUTCString()); xhr_wr.onreadystatechange = function() { return; }; if (typeof(g_debug) == 'number' && g_debug > 0 diff --git a/web/index_wr.php b/web/index_wr.php index 28b476e..bec14b7 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -129,9 +129,12 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) log_load("index_wr.php"); $remote_addr = addrtoipv4($remote_addr_full); - if (($mesg = gpcs_var('mesg', $get, $post, $cookie)) === FALSE) + if (($mesg = gpcs_var('mesg', $get, $post, $cookie)) === FALSE) unset($mesg); + if (($cl_step = gpcs_var('stp', $get, NULL, NULL)) === FALSE) + $cl_step = -2; + if (($sess = gpcs_var('sess', $get, $post, $cookie)) === FALSE) $sess = ""; @@ -234,6 +237,10 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) // LACC UPDATED $user->lacc = $curtime; + if ($user->cl_step < $cl_step) { + log_step(sprintf("%s|%s|%d|%d|%d|%d", $user->sess, $user->name, $user->step, $user->cl_step, $cl_step, $user->step - $user->cl_step)); + $user->cl_step = $cl_step; + } if ( ( ! $user->is_auth() ) && $brisk->ban_check($user->ip)) { -- 2.17.1