X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fbriskin5%2FObj%2Fbriskin5.phh;h=10edf1b272ec0348f4c53a25557da7efa579f3b8;hb=f8ae81cef2871be97c5466319efbafb23599baac;hp=815c8b4b5ebf2a5e61f3897693e6cceef1e2d261;hpb=f48d5700d29e4dec071f9f49940870266c92d38c;p=brisk.git diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index 815c8b4..10edf1b 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -183,7 +183,7 @@ class Bin5_table extends Table { $thiz->asta_pla_n= -1; $thiz->asta_card = -1; $thiz->asta_pnt = -1; - $thiz->mult = 1; + $thiz->mult = 0; $thiz->points = array( ); $thiz->points_n = 0; @@ -260,7 +260,7 @@ class Bin5_table extends Table { $thiz->bunch_create(); $thiz->mazzo = rand(0,PLAYERS_N-1); $thiz->points_n = 0; - $thiz->mult = 1; + $thiz->mult = 0; $thiz->old_win = -1; $thiz->old_reason = ""; @@ -274,6 +274,32 @@ class Bin5_table extends Table { return ($thiz); } + function asta2mult($asta_pnt) + { + if ($asta_pnt > 110) + return (6); + else if ($asta_pnt > 100) + return (5); + else if ($asta_pnt > 90) + return (4); + else if ($asta_pnt > 80) + return (3); + else if ($asta_pnt > 70) + return (2); + else + return (1); + } + + function multer($is_new) + { + if ($is_new) { + return (pow(2, $this->mult) * $this->asta2mult($this->asta_pnt)); + } + else { + return (pow(2, $this->old_mult) * $this->asta2mult($this->old_asta_pnt)); + } + } + // function bunch_create_old() function AND // { @@ -329,7 +355,7 @@ class Bin5_table extends Table { /* MOVED INTO SPAWN $this->mazzo = rand(0,PLAYERS_N-1); $this->points_n = 0; - $this->mult = 1; + $this->mult = 0; $this->old_win = -1; $this->old_reason = ""; */ @@ -477,7 +503,7 @@ class Bin5_user extends User { } */ - function spawn($from, &$bri, $table, $table_pos, $get, $post, $cookie) + static function spawn($from, &$bri, $table, $table_pos, $get, $post, $cookie) { if (($thiz = new Bin5_user()) == FALSE) return (FALSE); @@ -499,7 +525,7 @@ class Bin5_user extends User { log_wr("Bin5 constructor"); - $this->privflags = ($CO_bin5_pref_ring_endauct == "true" ? BIN5_USER_FLAG_RING_ENDAUCT : 0) | 0; + $thiz->privflags = ($CO_bin5_pref_ring_endauct == "true" ? BIN5_USER_FLAG_RING_ENDAUCT : 0) | 0; $thiz->table_orig = $table; $thiz->table = 0; @@ -584,112 +610,6 @@ class Bin5_user extends User { @unlink(BIN5_PROXY_PATH."/table".$tab_id."/".$sess.".step"); } - static function load_data($tab_id, $id, $sess) - { - log_load("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] "); - - do { - if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) { - log_main("ftok failed"); - break; - } - - if (($shm_sz = sharedmem_sz($tok)) == -1) { - log_main("shmop_open failed"); - } - - if ($shm_sz == -1) - $shm_sz = SHM_DIMS_U_MIN; - - if ($shm = shm_attach($tok, $shm_sz)) { - if (($user = @shm_get_var($shm, $tok)) == FALSE) { - break; - } - - if ($sess != FALSE && $user->sess != $sess) { - break; - } - log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE")); - - if ($user == FALSE) { - log_only("INIT MAIN DATA"); - - // SHSPLIT FIXME: init_data for User class ?? - $user = User::create($id, "", ""); - if (@shm_put_var($shm, $tok, $user) == FALSE) { - log_shme("Bin5_user::save_data2"); - - log_only("PUT_VAR FALLITA ".strlen(serialize($user))); - log_only(serialize($user)); - } - } - else { - if ($sess != FALSE) { - // This part isn't strictly required but is good to verify - // the coerence of cached and User class saved value of step field. - $old_step = $user->step; - $arr = Bin5_user::load_step($tab_id, $sess); - $user->step = $arr['s']; - if ($old_step != $user->step) { - log_crit("Bin5:: steps are diffetents User->step ".$user->step." Old_step: ".$old_step); - } - - } - } - - $user->shm_sz = $shm_sz; - - shm_detach($shm); - } - - // - // SHSPLIT: load users from the shared memory - // - return ($user); - } while (0); - - log_crit("Bin5_user::load_data:ret FALSE"); - - return (FALSE); - } - - static function save_data($user, $tab_id, $id) - { - GLOBAL $sess; - - $shm = FALSE; - - if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) { - return (FALSE); - } - while ($user->shm_sz < SHM_DIMS_U_MAX) { - if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE) - break; - - // log_only("PUT_VAR DI ".strlen(serialize($user))); - if (@shm_put_var($shm, $tok, $user) != FALSE) { - shm_detach($shm); - $user->save_step(); - log_main("User[".$id."] saved."); - - log_shme("Bin5_user::save_data"); - - return (TRUE); - } - if (shm_remove($shm) === FALSE) { - log_only("REMOVE FALLITA"); - break; - } - shm_detach($shm); - $user->shm_sz += SHM_DIMS_U_DLT; - } - - if ($shm) - shm_detach($shm); - - return (FALSE); - } - function destroy_data($tab_id) { do { @@ -720,48 +640,14 @@ class Bin5_user extends User { return ($ret); } - public static function stream_fini($init_string, $is_unrecoverable) -{ - printf("xXx user::stream_fini\n"); - - // IF IFRAME THEN: - $body = ""; - $body .= sprintf(" - - - - - -"); - $body .= sprintf("\n", $init_string); - $body .= sprintf("", 0, escpush(self::blocking_error($is_unrecoverable)) ); - // ELSE IF XHR THEN: - // return (self::blocking_error($is_unrecoverable)); - return ($body); -} - - - protected function blocking_error($is_unrecoverable) + static function blocking_error($is_unrecoverable) { - GLOBAL $is_page_streaming; - - $is_page_streaming = TRUE; log_crit("BLOCKING_ERROR UNREC: ".($is_unrecoverable ? "TRUE" : "FALSE")); return (sprintf(($is_unrecoverable ? 'xstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");')); } protected function page_sync($sess, $page) { - GLOBAL $is_page_streaming; - - $is_page_streaming = TRUE; log_rd2("PAGE_SYNC"); printf("xXx BIN5_USER::PAGE_SYNC\n"); return (sprintf('xstm.stop(); window.onbeforeunload = null; window.onunload = null; document.location.assign("%s");', $page)); @@ -769,7 +655,7 @@ push(\"%s\"); protected function maincheck($cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate, $table_idx, $table_token) { - GLOBAL $G_lang, $mlang_indrd, $is_page_streaming; + GLOBAL $G_lang, $mlang_indrd; GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx; GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout; $CO_splashdate = "CO_splashdate".$G_splash_idx; @@ -795,10 +681,9 @@ push(\"%s\"); $S_load_stat['wR_minusone']++; - if ($this->the_end == TRUE) { - log_rd2("main_check: the end".var_export(debug_backtrace())); - $is_page_streaming = TRUE; - } + // if ($this->the_end == TRUE) { + // log_rd2("main_check: the end".var_export(debug_backtrace())); + // } if ($this->trans_step != -1) { log_rd2("TRANS USATO ".$this->trans_step); @@ -916,28 +801,7 @@ class Bin5 { var $the_end; var $tok; - static function page_manager($room, $header_out, $path, $method, $addr, $get, $post, $cookie) - { - switch ($path) { - case "": - case "index.php": - ob_start(); - bin5_index_main($room, $header_out, $addr, $get, $post, $cookie); - $content = ob_get_contents(); - ob_end_clean(); - - force_no_cache($header_out); - - $pgflush = new PageFlush($new_socket, $curtime, 20, $header_out, $content); - - if ($pgflush->try_flush($curtime) == FALSE) { - // Add $pgflush to the pgflush array - array_push($pages_flush, $pgflush); - } - break; - } - return TRUE; - } + var $delay_mgr; function Bin5 ($room, $table_idx, $table_token, $get, $post, $cookie) { $this->user = array(); @@ -967,6 +831,8 @@ class Bin5 { $this->table_token = $table_token; $this->garbage_timeout = 0; + $this->delay_mgr = new Delay_Manager((GARBAGE_TIMEOUT *3.0) / 2.0); + log_wr("Bin5 constructor end"); } @@ -1003,6 +869,9 @@ class Bin5 { /* Garbage collector degli utenti in timeout */ $ismod = FALSE; $curtime = time(); + + $delta = $this->delay_mgr->delta_get($curtime); + if ($force || $this->garbage_timeout < $curtime) { for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) { $user_cur = $this->user[$i]; @@ -1010,7 +879,7 @@ class Bin5 { ($user_cur->stat == 'table' && ($user_cur->subst == 'shutdowned' || $user_cur->subst == 'shutdowner'))) continue; - if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente + if ($user_cur->lacc + EXPIRE_TIME_RD < ($curtime - $delta)) { // Auto logout dell'utente log_rd2($user_cur->sess." bin5 AUTO LOGOUT."); if ($user_cur->stat == 'table') { @@ -1046,115 +915,10 @@ class Bin5 { $ismod = TRUE; } + $this->delay_mgr->lastcheck_set($curtime); return ($ismod); } - // Bin5::load_data - static function load_data($table_idx, $table_token = "") - { - $shm = FALSE; - - log_wr("TABLE_FTOK ".FTOK_PATH."/bin5/table".$table_idx."/table"); - - do { - if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) { - log_main("ftok failed"); - break; - } - - if (($shm_sz = sharedmem_sz($tok)) == -1) { - log_main("shmop_open failed"); - break; - } - - if (($shm = shm_attach($tok, $shm_sz)) == FALSE) - break; - - if (($bri = @shm_get_var($shm, $tok)) == FALSE) - break; - - if ($table_token != "" && $bri->table_token != $table_token) { - log_wr("bri->table_token: ".$bri->table_token."table_token: ".$table_token); - break; - } - $bri->tok = $tok; - - shm_detach($shm); - - for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) { - if (($bri->user[$i] = Bin5_user::load_data($table_idx, $i, FALSE)) == FALSE) { - log_crit("Bin5_user::load_data failed"); - break; - } - } - if ($i < BIN5_MAX_PLAYERS) { - break; - } - - return ($bri); - } while (FALSE); - - if ($shm != FALSE) - shm_detach($shm); - - log_wr("briskin5 load_data failed"); - - return (FALSE); - } - - - - function save_data($bri) - { - GLOBAL $sess; - - $ret = FALSE; - $shm = FALSE; - - log_main("SAVE BRISKIN5 DATA"); - - if (!isset($bri->tok)) - return (FALSE); - - $user_park = array(); - for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) { - $user_park[$i] = $bri->user[$i]; - $bri->user[$i] = FALSE; - } - - while ($bri->shm_sz < BIN5_SHM_MAX) { - if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE) - break; - - if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) { - - log_shme("Bin5::save_data"); - - $ret = TRUE; - break; - } - if (shm_remove($shm) === FALSE) { - log_only("REMOVE FALLITA"); - break; - } - shm_detach($shm); - $bri->shm_sz += BIN5_SHM_DLT; - } - - if ($shm) - shm_detach($shm); - - // SHSPLIT: reattach users to the room class - for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) { - Bin5_user::save_data($user_park[$i], $bri->table_idx, $i); - $bri->user[$i] = $user_park[$i]; - } - log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE")); - - return ($ret); - } - - function destroy_data() { @@ -1330,7 +1094,7 @@ class Bin5 { $dt, $user->flags, xcape($user->name), xcape($user_mesg)); $user_cur->step_inc(); } - log_legal($curtime, 'xxx', $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg); + log_legal($curtime, $user->ip, $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg); } } @@ -1387,27 +1151,42 @@ class Bin5 { return ($is_ab); } - static function request_mgr(&$s_a_p, $enc, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie) + static function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie) { + GLOBAL $G_black_list; + printf("NEW_SOCKET (root): %d\n", intval($new_socket)); + $enc = get_encoding($header); + if (isset($header['User-Agent'])) { + if (strstr($header['User-Agent'], "MSIE")) { + $transp_type = "htmlfile"; + } + else { + $transp_type = "xhr"; + } + } + else { + $transp_type = "iframe"; + } + force_no_cache($header_out); + if (($table_idx = gpcs_var('table_idx', $get, $post, $cookie)) === FALSE) unset($table_idx); if (($table_token = gpcs_var('table_token', $get, $post, $cookie)) === FALSE) unset($table_token); - force_no_cache($header_out); switch ($path) { case "": case "index.php": ob_start(); - bin5_index_main($header_out, $addr, $get, $post, $cookie); + bin5_index_main($transp_type, $header_out, $addr, $get, $post, $cookie); $content = ob_get_contents(); ob_end_clean(); - $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content); + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; break; @@ -1420,8 +1199,14 @@ class Bin5 { $content = ob_get_contents(); ob_end_clean(); } + else { + $content = "Bin5 Load data error"; + } + } + else { + $content = "Bin5 Load data error"; } - $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content); + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; break; @@ -1433,8 +1218,8 @@ class Bin5 { || ($bri = $s_a_p->app->match_get($table_idx, $table_token)) == NULL || (($user = $bri->get_user($cookie['sess'], $idx)) == FALSE)) { - $content = Bin5_user::stream_fini($s_a_p->rndstr, TRUE); - $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content); + $content = Bin5_user::stream_fini($transp_type, $s_a_p->rndstr, TRUE); + $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; break; @@ -1463,7 +1248,7 @@ class Bin5 { 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; @@ -1502,21 +1287,6 @@ function locshm_exists($tok) } -function asta2mult($asta_pnt) -{ - if ($asta_pnt > 110) - return (5); - else if ($asta_pnt > 100) - return (4); - else if ($asta_pnt > 90) - return (3); - else if ($asta_pnt > 80) - return (2); - else if ($asta_pnt > 70) - return (1); - else - return (0); -} // rendiamo qui l'elenco dei punti come return della func function calculate_points(&$table) @@ -1535,6 +1305,7 @@ function calculate_points(&$table) $table->old_asta_pnt = $table->asta_pnt; $table->old_mult = $table->mult; + // count points for the temporary 2 teams for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) { // for ($i = 0 ; $i < 40 ; $i++) { $ctt = $table->card[$i]->value % 10; @@ -1545,8 +1316,8 @@ function calculate_points(&$table) log_wr(sprintf("PRO: [%d]", $pro)); - - if ($table->asta_pnt == 61 && $pro == 60) { // PATTA ! + // PATTA case ! + if ($table->asta_pnt == 61 && $pro == 60) { $table->points[$table->points_n % MAX_POINTS] = array(); for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { $table->points[$table->points_n % MAX_POINTS][$i] = 0; @@ -1564,8 +1335,6 @@ function calculate_points(&$table) else $sig = -1; - $gamult = asta2mult($table->asta_pnt); - $table->points[$table->points_n % MAX_POINTS] = array(); for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { if ($i == $table->asta_win) @@ -1579,9 +1348,9 @@ function calculate_points(&$table) log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt)); - $pt = $pt * $sig * ($gamult + $table->mult) * ($pro == 120 ? 2 : 1); + $pt = $pt * $sig * $table->multer(TRUE) * ($pro == 120 ? 2 : 1); - log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1))); + log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->multer(TRUE), ($pro == 120 ? 2 : 1))); $table->points[$table->points_n % MAX_POINTS][$i] = $pt; $table->total[$i] += $pt; @@ -1589,7 +1358,7 @@ function calculate_points(&$table) } $table->points_n++; $table->old_pnt = $pro; - $table->mult = 1; + $table->mult = 0; return($ret); } @@ -1646,7 +1415,7 @@ function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again) $ret .= "setTimeout(preload_images, 500, g_preload_img_arr, g_imgct);"; } if (!$is_again) - $ret .= table_wellcome($user); + $ret .= table_welcome($user); if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca $ret .= playsound("cow.mp3"); @@ -1906,8 +1675,9 @@ function show_table_info(&$bri, &$table, $table_pos) ($wol == 1 ? $mlang_bin5_bin5['info_win'][$G_lang] : ($wol == 0 ? $mlang_bin5_bin5['info_peer'][$G_lang] : $mlang_bin5_bin5['info_lost'][$G_lang]))); } } - if (($table->old_mult + asta2mult($table->old_asta_pnt)) > 1) { - $noty .= sprintf($mlang_bin5_bin5['info_omul'][$G_lang], multoval($table->old_mult + asta2mult($table->old_asta_pnt))); + $old_multer = $table->multer(FALSE); + if ($old_multer > 1) { + $noty .= sprintf($mlang_bin5_bin5['info_omul'][$G_lang], multoval($old_multer)); } $noty .= "

"; } @@ -1938,8 +1708,9 @@ function show_table_info(&$bri, &$table, $table_pos) $noty .= sprintf($mlang_bin5_bin5['info_turn'][$G_lang], $unam); } - if (($table->mult + asta2mult($table->asta_pnt)) > 1) { - $noty .= sprintf($mlang_bin5_bin5['info_mult'][$G_lang], multoval($table->mult + asta2mult($table->asta_pnt))); + $multer = $table->multer(TRUE); + if ($multer > 1) { + $noty .= sprintf($mlang_bin5_bin5['info_mult'][$G_lang], multoval($multer) ); } $noty .= "

"; $ret .= show_notify($noty, 3000, $mlang_bin5_bin5['btn_bkgame'][$G_lang], 500, 400); @@ -1953,7 +1724,7 @@ function show_table_info(&$bri, &$table, $table_pos) return ($ret); } -function table_wellcome($user) +function table_welcome($user) { GLOBAL $table_wellarr, $G_lang; $ret = "";