X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fbrisk.phh;h=7bea78cf09f3de58800e362e70abe3cfa49f2af1;hb=9ab060c9b70ac285727871e3f79a4ba144620b2b;hp=bd1edb893cd2116dfa43837c0b3c95dac5b09caa;hpb=3269331d0e5f2dbad822ca34c33761104edb7dea;p=brisk.git diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index bd1edb8..7bea78c 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -77,6 +77,7 @@ define('DBG_CRIT', 0x0400); define('DBG_LMOP', 0x0800); define('DBG_TRAC', 0x1000); define('DBG_SHME', 0x2000); +define('DBG_ENGI', 0x4000); // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols define('BRISK_DEBUG', 0x0800); @@ -140,12 +141,12 @@ $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.6.0"; +$G_brisk_version = "4.9.2"; /* MLANG: ALL THE INFO STRINGS IN brisk.phh */ -$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': aggiunti script di avvio automatico, gestione dei segnali e logging dell\' ultima connessione.', +$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': aggiunto WebSocket come sistema preferenziale di comunicazione e corretto qualche bug.', 'Se vuoi iscriverti alla Mailing List, cliccala!' ), - 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: usage of reader/writer locking instead of generic exclusive locking.', + 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: added WebSocket as preferential communication system and fixed some bug.', 'If you want to subscribe our Mailing List, click it!' ) ); $G_room_help = array( 'it' => ' @@ -697,10 +698,92 @@ class Delay_Manager class Client_prefs { var $listen; + var $supp_comp; - function Client_prefs($listen) + function Client_prefs() { - $this->listen = $listen; + } + + static function from_user($user) + { + $thiz = new Client_prefs(); + $thiz->user_load($user); + + return ($thiz); + } + + static function from_json($json) + { + $thiz = new Client_prefs(); + if ($thiz->json_load($json) == FALSE) { + unset($thiz); + return (FALSE); + } + + return ($thiz); + } + + function user_load($user) + { + fprintf(STDERR, "QQ %s: %x\n", __FUNCTION__, $user->flags); + $this->listen = ($user->flags & USER_FLAG_MAP_AUTH) >> 2; + if ($user->rec != FALSE) { + $this->supp_comp = $user->rec->supp_comp; + } + else { + $this->supp_comp = "000000000000"; + } + + fprintf(STDERR, "QQ %s: LISTEN: %d\n", __FUNCTION__, $this->listen); + } + + function json_load($json_s) + { + $ret = FALSE; + + do { + if (gettype($json_s) == "string") { + if (($json = json_decode($json_s)) == FALSE) + break; + } + else { + $json = $json_s; + } + if ($this->listen < 0 || $this->listen > 2) + break; + $this->listen = $json->listen; + + if (mb_strlen($json->supp_comp, "ASCII") != 12) + break; + + for ($i = 0, $idx = 0 ; $i < 12 ; $i++) { + if (($json->supp_comp[$i] >= '0' && $json->supp_comp[$i] <= '9') || + ($json->supp_comp[$i] >= 'a' && $json->supp_comp[$i] <= 'f')) + continue; + break; + } + if ($i < 12) + break; + $this->supp_comp = $json->supp_comp; + $ret = TRUE; + } while (FALSE); + + return ($ret); + } + + function store($user, $is_save) + { + // save into DB + fprintf(STDERR, "QQ %s::%s PRE: %x\n", __CLASS__, __FUNCTION__, + $user->flags & (~USER_FLAG_S_ALL & ~USER_FLAG_AUTH)); + $user->flags_set(($this->listen << 2), USER_FLAG_MAP_AUTH); + fprintf(STDERR, "QQ %s::%s %x\n", __CLASS__, __FUNCTION__, + $user->flags); + if ($user->is_supp_custom()) { + $user->rec->supp_comp = $this->supp_comp; + } + if ($is_save) + $user->store_set(); } } @@ -926,9 +1009,8 @@ class Room $ret = sprintf('gst.st = %d; ', $user_step); - // for test: $prefs = new Client_prefs(USER_FLAG_LISTAUTH >> 2); - $prefs = new Client_prefs(($user->flags & USER_FLAG_MAP_AUTH) >> 2); - $ret .= sprintf('prefs_load(\'%s\');', json_encode($prefs)); + $prefs = Client_prefs::from_user($user); + $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs)); if(false) { if ($user->flags & USER_FLAG_ISOLAUTH) { @@ -1210,54 +1292,53 @@ class Room function room_sitdown($user, $table_idx) { - log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name)); - - $train_app = ""; - - if ($table_idx > -1 && $table_idx < TABLES_N) { - $table = $this->table[$table_idx]; - - // wagon shutdown - if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) { - for ($i = 0 ; $i < TABLES_N ; $i++) { - if ($table->wag_own == $table->player[$i]) { - $train_app = sprintf("tra.rem(%d); ", $table_idx); - $table->wag_reset(time()); - break; - } - } - } - } - - for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { - $ret = ""; - $user_cur = $this->user[$i]; - if ($user_cur->sess == '' || $user_cur->stat != 'room') - continue; + log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name)); - $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app; - if ($table_idx > -1) - $ret .= $this->table_content($user_cur, $table_idx); - $ret .= $this->standup_content($user_cur); + $train_app = ""; - if ($user->idx_get() == $i) { - $ret .= 'subst = "sitdown"; tra.hide(); '; - // clean the action buttons in other tables - for ($e = 0 ; $e < TABLES_N ; $e++) { - // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE); - $ret .= $this->table[$e]->act_content($user_cur); - } + if ($table_idx > -1 && $table_idx < TABLES_N) { + $table = $this->table[$table_idx]; + + // wagon shutdown + if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) { + for ($i = 0 ; $i < TABLES_N ; $i++) { + if ($table->wag_own == $table->player[$i]) { + $train_app = sprintf("tra.rem(%d); ", $table_idx); + $table->wag_reset(time()); + break; + } + } + } } - else if ($table_idx > -1) { - if ($table->player_n == PLAYERS_N) { - // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table, - /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH)); - $ret .= $table->act_content($user_cur); - } + + for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + $ret = ""; + $user_cur = $this->user[$i]; + if ($user_cur->sess == '' || $user_cur->stat != 'room') + continue; + + $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app; + if ($table_idx > -1) + $ret .= $this->table_content($user_cur, $table_idx); + $ret .= $this->standup_content($user_cur); + + if ($user->idx_get() == $i) { + $ret .= 'subst = "sitdown"; tra.hide(); '; + // clean the action buttons in other tables + for ($e = 0 ; $e < TABLES_N ; $e++) { + $ret .= $this->table[$e]->act_content($user_cur); + } + } + else if ($table_idx > -1) { + if ($table->player_n == PLAYERS_N) { + // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table, + /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH)); + $ret .= $table->act_content($user_cur); + } + } + $user_cur->comm[$user_cur->step % COMM_N] = $ret; + $user_cur->step_inc(); } - $user_cur->comm[$user_cur->step % COMM_N] = $ret; - $user_cur->step_inc(); - } } function chatt_send($user, $mesg) @@ -1824,31 +1905,39 @@ class Room $this->user[$idx]->bantime = 0; $this->user[$idx]->ip = $ip; + $this->user[$idx]->rec = $authenticate; + fprintf(STDERR, "MOP: [%s]\n", $authenticate->supp_comp); $this->user[$idx]->flags = $user_type; $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00); $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00); log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags)); - if ($authenticate != FALSE) { - $this->user[$idx]->code = $authenticate->code_get(); - $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; - - if (isset($cookie['CO_list'])) { - if (strcmp($cookie['CO_list'], "auth") == 0) { - $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; - $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; - } - if (strcmp($cookie['CO_list'], "isolation") == 0) { - $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; - $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH; + $this->user[$idx]->code = $authenticate->code_get(); + if (0 == 1) { + // all this part is included in the db server + $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; + + if (isset($cookie['CO_list'])) { + fprintf(STDERR, "QQ: %s CO_list: [%s]\n", __FUNCTION__, $cookie['CO_list']); + if (strcmp($cookie['CO_list'], "auth") == 0) { + $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; + } + if (strcmp($cookie['CO_list'], "isolation") == 0) { + $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH; + } + else { + $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + } + } } else { - $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + fprintf(STDERR, "QQ: CO_list not set flags: %x\n", __FUNCTION__, $this->user[$idx]->flags); } - } } - + fprintf(STDERR, "QQ %s: flag %x\n", __FUNCTION__, $this->user[$idx]->flags); if ($ghost > -1) { log_main("ghost: rename!"); $ghost_user = $this->user[$ghost]; @@ -2133,18 +2222,28 @@ class Room $content = ' j_stand_cont( [ '; + $user_cur_id = $user->idx_get(); for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) { if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "") continue; $flags = $this->user[$i]->flags; - + + // sql record exists AND last donate > 2013-01-01 + if ($this->user[$i]->is_supp_custom()) { + $supp_comp_s = sprintf(', "%s"', $this->user[$i]->rec->supp_comp); + } + else { + $supp_comp_s = ''; + } + if ($this->user[$i]->subst == "standup") { - if ($user->idx_get() == $i) { + if ($user_cur_id == $i) { $flags |= 1; } - $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name)); + $content .= sprintf('%s[ %d, "%s"%s ]',($ct > 0 ? ', ' : ''), $flags, + xcape($this->user[$i]->name), $supp_comp_s); $ct++; } } @@ -2168,18 +2267,24 @@ class Room if ($user->stat != 'room') return; + $user_cur_id = $user->idx_get(); $content = "[ "; for ($i = 0 ; $i < $table->player_n ; $i++) { $user_cur = $this->user[$table->player[$i]]; $flags = $user_cur->flags; - if ($user->idx_get() == $table->player[$i]) + if ($user_cur_id == $table->player[$i]) $flags |= 1; log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx)); - - $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name)); + if ($user_cur->is_supp_custom()) + $supp_comp_s = sprintf(', "%s"', $user_cur->rec->supp_comp); + else + $supp_comp_s = ''; + + $content .= sprintf('%s[ %d, "%s"%s ]',($i == 0 ? '' : ', '), $flags, + xcape($user_cur->name), $supp_comp_s); } $content .= ' ]'; @@ -2191,7 +2296,9 @@ class Room function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie) { - printf("NEW_SOCKET (root): %d\n", intval($new_socket)); + GLOBAL $G_black_list; + + printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path); $enc = get_encoding($header); if (isset($header['User-Agent'])) { @@ -2215,30 +2322,40 @@ class Room $content = ob_get_contents(); ob_end_clean(); - $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content); + // fprintf(STDERR, "\n\nCONTENT [%s]\n\n", $content); + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; break; case "index_wr.php": + // + // Enhance required: in the POST case, after the header you must get content + // from the socket, waiting if necessary + // + + fprintf(STDERR, "\n\nDENTRO QUI\n\n"); ob_start(); index_wr_main($this, $addr, $get, $post, $cookie); $content = ob_get_contents(); ob_end_clean(); - $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content); + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; break; case "index_rd_ifra.php": + if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE) + $transp = "iframe"; + if ($transp == 'websocket') + $enc = 'plain'; + do { if (!isset($cookie['sess']) || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)) { - if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE) - $transp = "iframe"; $content = User::stream_fini($transp, $s_a_p->rndstr, TRUE); - $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content); + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; break; @@ -2252,9 +2369,8 @@ class Room } $content = ""; - $user->stream_init($s_a_p->rndstr, $enc, $header_out, $content, $get, $post, $cookie); - - $response = headers_render($header_out, -1).chunked_content($user->rd_zls_get(), $content); + $user->stream_init($s_a_p->rndstr, $enc, $header, $header_out, $content, $get, $post, $cookie); + $response = headers_render($header_out, -1).$user->chunked_content($content); $response_l = mb_strlen($response, "ASCII"); $wret = @fwrite($new_socket, $response, $response_l); @@ -2268,7 +2384,7 @@ class Room fflush($new_socket); - $s_a_p->socks_set($new_socket, $user); + $s_a_p->socks_set($new_socket, $user, NULL); $user->rd_socket_set($new_socket); printf(" - qui ci siamo - "); return TRUE; @@ -2276,7 +2392,20 @@ class Room return FALSE; break; - + case 'test.php': + if (!(BRISK_DEBUG & DBG_ENGI)) + return (FALSE); + fprintf(STDERR, "TEST.PHP running\n"); + if (isset($post['data'])) { + $content = $post['data']; + } + else { + $content = "NO DATA AVAILABLE"; + } + $header_out['Content-Type'] = 'text/plain'; + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); + return TRUE; + break; default: /* FAR TODO: move all into an array of registered sub-apps */ $subs = "briskin5/";