X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fbrisk.phh;h=0f6f1b06a4c6fe2af4ba8d0e51cad5a7e6a58a7e;hb=5d70dcb6a7c803a6ddacf872bacdf4906babcd80;hp=a94412e8d03e2748b86d9e4b0bb346947fa00a81;hpb=0b1e5521bd8d1c7b6f349038fe4daa819da11d0e;p=brisk.git diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index a94412e..0f6f1b0 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -140,10 +140,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.0.0"; +$G_brisk_version = "4.4.1"; /* MLANG: ALL THE INFO STRINGS IN brisk.phh */ -$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': adottato sac-a-push come motore per l\'invio dei dati in tempo reale.', +$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': nuovo stream dati xhr, prima versione completa.', '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.', 'If you want to subscribe our Mailing List, click it!' ) ); @@ -672,46 +672,49 @@ class Table { -class Room { +class Room +{ static $delta_t; - - var $user; - var $table; - var $match; - var $comm; // commands for many people - var $step; // current step of the comm array - var $garbage_timeout; - var $shm_sz; - - function Room () { - $this->user = array(); - $this->table = array(); - $this->match = array(); - - for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { - $this->user[$i] = User::create($this, $i, "", ""); - } - - for ($i = 0 ; $i < TABLES_N ; $i++) { - $this->table[$i] = Table::create($i); - /* OLD METHOD - if ($i < 12) { - $row = ( (((int)($i / 4)) % 2) == 0 ); - $col = ($i % 2 == 0); - $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col)); - } - else { - $this->table[$i]->auth_only = FALSE; - } - */ - if ($i < TABLES_AUTH_N) - $this->table[$i]->auth_only = TRUE; - else - $this->table[$i]->auth_only = FALSE; + + var $crystal_filename; + var $user; + var $table; + var $match; + var $comm; // commands for many people + var $step; // current step of the comm array + var $garbage_timeout; + var $shm_sz; + + function Room ($crystal_filename) { + $this->crystal_filename = $crystal_filename; + $this->user = array(); + $this->table = array(); + $this->match = array(); + + for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + $this->user[$i] = User::create($this, $i, "", ""); + } + + for ($i = 0 ; $i < TABLES_N ; $i++) { + $this->table[$i] = Table::create($i); + /* OLD METHOD + if ($i < 12) { + $row = ( (((int)($i / 4)) % 2) == 0 ); + $col = ($i % 2 == 0); + $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col)); + } + else { + $this->table[$i]->auth_only = FALSE; + } + */ + if ($i < TABLES_AUTH_N) + $this->table[$i]->auth_only = TRUE; + else + $this->table[$i]->auth_only = FALSE; + } + $this->garbage_timeout = 0; + $this->shm_sz = SHM_DIMS_MIN; } - $this->garbage_timeout = 0; - $this->shm_sz = SHM_DIMS_MIN; - } function garbage_manager($force) { @@ -1561,46 +1564,27 @@ class Room { } if ($to_tabl) { - // FIXME BRISK4: include for each kind of table - require_once("${G_base}briskin5/Obj/briskin5.phh"); - // Before all align times with table timeout - for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { - $table_cur = $this->table[$table_idx]; - // if the table is complete and exists its shared mem we get the info about users lacc - - if ($table_cur->player_n == PLAYERS_N) { - log_main("PLAYERS == N TABLE ".$table_idx); - - if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) { - log_main("bin5 lock data success"); - - $no_recovery = FALSE; - if (($bri = Bin5::load_data($table_idx)) != FALSE) { - if ($table_cur->table_token != $bri->table_token) { - log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token); - $bri = FALSE; - } - } - - if ($bri != FALSE) { - $bri_table = $bri->table[0]; - for ($i = 0 ; $i < $bri_table->player_n ; $i++) { - // stat must be "table" by definition - $bri_user = $bri->user[$i]; + // FIXME BRISK4: include for each kind of table + require_once("${G_base}briskin5/Obj/briskin5.phh"); + // Before all align times with table timeout + for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { + if (isset($this->match[$table_idx])) { + $bri = $this->match[$table_idx]; + + $bri_table = $bri->table[0]; + for ($i = 0 ; $i < $bri_table->player_n ; $i++) { + // stat must be "table" by definition + $bri_user = $bri->user[$i]; - if ($target != "" && $bri_user->name != $target) - continue; - log_main("writa: ".$user_mesg); - $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; "; - $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl; - $bri_user->step_inc(); - } - Bin5::save_data($bri); - } - Bin5::unlock_data($sem); - } // bri::lock_data - } // if ($table_cur->player_n == PLAYERS_N) { - } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { + if ($target != "" && $bri_user->name != $target) + continue; + log_main("writa: ".$user_mesg); + $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; "; + $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl; + $bri_user->step_inc(); + } + } // if (isset($this->match + } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { } // if ($to_tabl == true ... if ($update_room) { @@ -1736,6 +1720,7 @@ class Room { $ghost_user = $this->user[$ghost]; $curtime = time(); + $ghost_user->comm[$ghost_user->step % COMM_N] = ""; $ghost_user->step_inc(); if ($sess == "") { $sess = uniqid(""); @@ -1748,18 +1733,16 @@ class Room { // If user at the table we need to update the table data too $table_idx = $ghost_user->table; if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) { - // FIXME BRISK4: include for each kind of table - require_once("${G_base}briskin5/Obj/briskin5.phh"); - if (($brisem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) { - if (($bri = Bin5::load_data($table_idx)) != FALSE) { - if ($bri->the_end != TRUE) { - $bri->user[$ghost_user->table_pos]->step_inc(); - $bri->user[$ghost_user->table_pos]->sess = $sess; - Bin5::save_data($bri); - } + require_once("${G_base}briskin5/Obj/briskin5.phh"); + if (isset($this->match[$table_idx])) { + $bri = $this->match[$table_idx]; + + if ($bri->the_end != TRUE) { + $bri->user[$ghost_user->table_pos]->comm[$bri->user[$ghost_user->table_pos]->step % COMM_N] = ""; + $bri->user[$ghost_user->table_pos]->step_inc(); + $bri->user[$ghost_user->table_pos]->sess = $sess; + } } - Bin5::unlock_data($brisem); - } } $idx = $ghost; @@ -1883,10 +1866,17 @@ class Room { } // Static functions - static function create() + static function create($crystal_filename) { - $room = new Room(); - + if (($room_ser = @file_get_contents($crystal_filename)) == FALSE || + ($room = unserialize($room_ser)) == FALSE) { + fprintf(STDERR, "NEW ROOM\n"); + $room = new Room($crystal_filename); + } + else { + fprintf(STDERR, "ROOM FROM FILE\n"); + } + return $room; } @@ -1986,7 +1976,16 @@ class Room { return (FALSE); } - + function dump_data() + { + $room_ser = serialize($this); + $room_ser_len = mb_strlen($room_ser, "ASCII"); + if (file_put_contents($this->crystal_filename, $room_ser) == $room_ser_len) { + return (TRUE); + } + + return (FALSE); + } function save_data($room) { @@ -2133,17 +2132,29 @@ class Room { return ($ret); } - function request_mgr(&$s_a_p, $enc, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie) + 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)); + $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); switch ($path) { case "": case "index.php": ob_start(); - index_main($this, $header_out, $addr, $get, $post, $cookie); + index_main($this, $transp_type, $header_out, $addr, $get, $post, $cookie); $content = ob_get_contents(); ob_end_clean(); @@ -2211,7 +2222,7 @@ class Room { $subs = "briskin5/"; $subs_l = strlen($subs); if (!strncmp($path, $subs, $subs_l)) { - $ret = Bin5::request_mgr(&$s_a_p, $enc, &$header_out, &$new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie); + $ret = Bin5::request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie); return ($ret); } break;