X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;ds=inline;f=web%2FObj%2Fbrisk.phh;h=82a95ce3ac650631139b6b6b0cab623119087564;hb=1e3ae80924342e436b2100e5631e6fd58d4af79d;hp=07c6168dd0591cc9cb539cd5f69e94b68e94cd0d;hpb=d9f1de409fac8d9bff593813fec3db1f0c08cdc7;p=brisk.git
diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh
index 07c6168..82a95ce 100644
--- a/web/Obj/brisk.phh
+++ b/web/Obj/brisk.phh
@@ -35,7 +35,11 @@ define(MAX_PLAYERS, (20 + (PLAYERS_N * TABLES_N)));
define(SHM_DIMS_MIN, (50000 + 10000 * TABLES_N + 15000 * MAX_PLAYERS));
define(SHM_DIMS_MAX, SHM_DIMS_MIN + 1048576);
define(SHM_DIMS_DLT, 65536);
-
+
+define(SHM_DIMS_U_MIN, 4096);
+define(SHM_DIMS_U_MAX, 65536);
+define(SHM_DIMS_U_DLT, 4096);
+
define(COMM_N, 18);
define(COMM_GEN_N, 50);
@@ -127,16 +131,15 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
);
-$G_false = FALSE;
$G_lng = langtolng($G_lang);
$G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
-$G_brisk_version = "3.2.0";
+$G_brisk_version = "3.4.2";
/* MLANG: ALL THE INFO STRINGS IN brisk.phh */
-$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': informazioni al tavolo sul chiamante, nuovo stato di supporter del sito.',
+$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': versione di test per la nuova gestione dei dati volatili.',
'Se vuoi iscriverti alla Mailing List, cliccala!' ),
- 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: caller information on the table, new supporter status.',
+ 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: test version for the new volatile data management.',
'If you want to subscribe our Mailing List, click it!' ) );
$G_room_help = array( 'it' => '
@@ -380,12 +383,10 @@ class Table {
{
}
- function &create($idx)
+ function create($idx)
{
- GLOBAL $G_false;
-
if (($thiz =& new Table()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->idx = $idx;
$thiz->player = array();
@@ -404,10 +405,8 @@ class Table {
return ($thiz);
}
- function copy(&$from)
+ function copy($from)
{
- GLOBAL $G_false;
-
$this->idx = $from->idx;
$this->player = array();
for ($i = 0 ; $i < $from->player_n ; $i++)
@@ -428,24 +427,20 @@ class Table {
$this->wakeup_time = $from->wakeup_time;
}
- function &myclone(&$from)
+ function myclone($from)
{
- GLOBAL $G_false;
-
if (($thiz =& new Table()) == FALSE)
- return ($G_false);
+ return (FALSE);
$this->copy($from);
return ($thiz);
}
- function &spawn(&$from)
+ function spawn($from)
{
- GLOBAL $G_false;
-
if (($thiz =& new Table()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->idx = $from->idx;
$thiz->player = array();
@@ -467,11 +462,11 @@ class Table {
return ($thiz);
}
- function wag_set(&$user, $mesg)
+ function wag_set($user, $mesg)
{
log_main("WAG_SET");
- $this->wag_own = &$user;
+ $this->wag_own = $user;
$this->wag_com = $mesg;
$this->wag_tout = 0;
}
@@ -486,12 +481,12 @@ class Table {
$this->wag_tout = $timeout;
}
- function getPlayer($idx)
+ function player_get($idx)
{
return ($this->player[$idx]);
}
- function setPlayer($idx, $player)
+ function player_set($idx, $player)
{
$this->player[$idx] = $player;
}
@@ -604,6 +599,7 @@ define(USER_FLAG_TY_SUSPEND, 0x400000); // done
define(USER_FLAG_TY_DISABLE, 0x800000); // done
class User {
+ var $idx; // index in the users array
var $code; // authentication code
var $name; // name of the user
var $sess; // session of the user
@@ -635,15 +631,18 @@ class User {
var $chat_cur; // Current chat line number
var $chat_ban; // Time for ban chat
var $chat_dlt; // Delta t for ban
+ var $shm_sz;
+
function User() {
}
- function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
- GLOBAL $G_false;
+ function create($idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
+ // error_log("User::create BEGIN", 0);
if (($thiz =& new User()) == FALSE)
- return ($G_false);
+ return (FALSE);
+ $thiz->idx = $idx;
$thiz->code = -1;
$thiz->name = $name;
$thiz->sess = $sess;
@@ -673,14 +672,13 @@ class User {
$thiz->table = $table;
$thiz->table_pos = -1;
$thiz->table_token = "";
-
+ $thiz->shm_sz = SHM_DIMS_U_MIN;
return ($thiz);
}
- function copy(&$from)
+ function copy($from)
{
- GLOBAL $G_false;
-
+ $this->idx = $from->idx;
$this->code = $from->code;
$this->name = $from->name;
$this->sess = $from->sess;
@@ -719,30 +717,27 @@ class User {
$this->table_pos = $from->table_pos;
$this->table_token = $from->table_token;
$this->the_end = $from->the_end;
-
+ $this->shm_sz = $from->shm_sz;
return (TRUE);
}
- function &myclone(&$from)
+ function myclone($from)
{
- GLOBAL $G_false;
-
if (($thiz =& new User()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->copy($from);
return ($thiz);
}
- function &spawn(&$from, $table, $table_pos)
+ function spawn($from, $table, $table_pos)
{
- GLOBAL $G_false;
-
if (($thiz =& new User()) == FALSE)
- return ($G_false);
+ return (FALSE);
+ $thiz->idx = $from->idx;
$thiz->code = $from->code;
$thiz->name = $from->name;
$thiz->sess = $from->sess;
@@ -783,10 +778,15 @@ class User {
$thiz->table = 0;
$thiz->table_pos = $table_pos;
$thiz->table_token = $from->table_token;
+ $thiz->shm_sz = $from->shm_sz;
return ($thiz);
}
+ function idx_get() {
+ return ($this->idx);
+ }
+
function code_get() {
return ($this->code);
}
@@ -816,7 +816,7 @@ class User {
mkdir(PROXY_PATH);
if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
break;
- fwrite($fp, pack("l",$this->step), 4);
+ fwrite($fp, pack("LL",$this->step, $this->idx));
fclose($fp);
return (TRUE);
@@ -832,7 +832,7 @@ class User {
if (file_exists(PROXY_PATH) == FALSE)
mkdir(PROXY_PATH);
$fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
- fwrite($fp, pack("l",$this->step), 4);
+ fwrite($fp, pack("LL", $this->step, $this->idx));
fclose($fp);
return (TRUE);
@@ -858,12 +858,105 @@ class User {
$this->chat_dlt = 0;
$this->the_end = FALSE;
}
-} // end class User
+ // SHSPLIT save and load function for the User class.
+ function load_data($id)
+ {
+ GLOBAL $sess;
+
+ // error_log("User::load_data BEGIN", 0);
+
+ $doexit = FALSE;
+ do {
+ if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
+ log_main("ftok failed");
+ $doexit = TRUE;
+ 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)) {
+ $user = @shm_get_var($shm, $tok);
+
+ log_only("bri == ".($user == FALSE ? "FALSE" : "TRUE")." bri === ".($user === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($user) ? "TRUE" : "FALSE"));
+ if (isset($user))
+ log_only("bri count ".count($user));
+
+ 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_only("PUT_VAR FALLITA ".strlen(serialize($user)));
+ log_only(serialize($user));
+ }
+ }
+
+ $user->shm_sz = $shm_sz;
+
+ shm_detach($shm);
+ }
+
+ //
+ // SHSPLIT: load users from the shared memory
+ //
+ return ($user);
+ } while (0);
+
+ if ($doexit)
+ exit();
+
+ return (FALSE);
+ }
+
+
+ function save_data(&$user, $id)
+ {
+ GLOBAL $sess;
+
+ $shm = FALSE;
+
+ // var_dump($user);
+ // error_log("User::save_data BEGIN", 0);
+
+ if (($tok = @ftok(FTOK_PATH."/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);
+ 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);
+ }
+
+} // end class User
function step_get($sess) {
@@ -876,15 +969,15 @@ function step_get($sess) {
mkdir(PROXY_PATH);
if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
break;
- if (($s = fread($fp, 4)) == FALSE)
+ if (($s = fread($fp, 8)) == FALSE)
break;
- if (strlen($s) != 4)
+ if (strlen($s) != 8)
break;
- $arr = unpack('l', $s);
+ $arr = unpack('Ls/Li', $s);
fclose($fp);
// log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
- return ($arr[1]);
+ return ($arr);
} while (0);
if ($fp != FALSE)
@@ -916,7 +1009,7 @@ class Room {
$this->table = array();
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
- $this->user[$i] =& User::create("", "");
+ $this->user[$i] =& User::create($i, "", "");
}
for ($i = 0 ; $i < TABLES_N ; $i++) {
@@ -937,6 +1030,7 @@ class Room {
$this->table[$i]->auth_only = FALSE;
}
$this->garbage_timeout = 0;
+ $this->shm_sz = SHM_DIMS_MIN;
}
function garbage_manager($force)
@@ -1453,6 +1547,7 @@ class Room {
$msg = substr($mesg, 6, 128);
$curtime = time();
$dt = date("H:i ", $curtime);
+ $target = "";
//
// Compute actions
@@ -1848,9 +1943,9 @@ class Room {
return;
} // function chatt_send( ...
- function &get_user($sess, &$idx)
+ function get_user($sess, &$idx)
{
- GLOBAL $PHP_SELF, $G_false;
+ GLOBAL $PHP_SELF;
if (validate_sess($sess)) {
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
@@ -1869,11 +1964,11 @@ class Room {
log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
}
- return ($G_false);
+ return (FALSE);
}
/*
- * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
+ * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
*
* RETURN VALUE:
* if ($idx > -1 && ret == FALSE) => duplicated nick
@@ -1884,9 +1979,9 @@ class Room {
* if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
*/
- function &add_user(&$sess, &$idx, $name, $pass, $ip)
+ function add_user(&$sess, &$idx, $name, $pass, $ip)
{
- GLOBAL $G_base, $G_false, $CO_list;
+ GLOBAL $G_base, $CO_list;
$idx = 0;
@@ -1901,7 +1996,7 @@ class Room {
if (($name_new = validate_name($name)) == FALSE) {
$idx = -2;
- return ($G_false);
+ return (FALSE);
}
log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
@@ -1919,11 +2014,12 @@ class Room {
log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
if ($authenticate != FALSE) {
+ // error_log(print_r(&$authenticate, TRUE),0);
$user_type = $authenticate->type_get();
}
else {
$idx = -3;
- return ($G_false);
+ return (FALSE);
}
}
else {
@@ -2089,10 +2185,10 @@ class Room {
return ($ret);
}
- return ($G_false);
+ return (FALSE);
}
- function standup_update(&$user)
+ function standup_update($user)
{
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
$user_cur = &$this->user[$i];
@@ -2118,18 +2214,21 @@ class Room {
}
// Static functions
- function &init_data()
+ static function create()
{
- $room =& new Room();
+ $room = new Room();
return $room;
}
-
- function &load_data()
+
+ function load_data()
{
- GLOBAL $G_false, $sess;
+ GLOBAL $sess;
$doexit = FALSE;
+
+ // error_log("Room::load_data BEGIN", 0);
+
do {
if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
log_main("ftok failed");
@@ -2145,37 +2244,48 @@ class Room {
$shm_sz = SHM_DIMS_MIN;
if ($shm = shm_attach($tok, $shm_sz)) {
- $room = @shm_get_var($shm, $tok);
-
- log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
- if (isset($room))
- log_only("bri count ".count($room));
-
- if ($room == FALSE) {
- log_only("INIT MAIN DATA");
-
- $room =& Room::init_data();
- if (@shm_put_var($shm, $tok, $room) == FALSE) {
- log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
- log_only(serialize($room));
- }
- }
- $room->shm_sz = $shm_sz;
-
- shm_detach($shm);
+ $room = @shm_get_var($shm, $tok);
+
+ log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
+ if (isset($room))
+ log_only("bri count ".count($room));
+
+ if ($room == FALSE) {
+ log_only("INIT MAIN DATA");
+ shm_detach($shm);
+
+ // error_log("DE CHE", 0);
+
+ $room = Room::create();
+
+ if (Room::save_data($room) == FALSE)
+ return FALSE;
+
+ return $room;
+ }
+ $room->shm_sz = $shm_sz;
+
+ shm_detach($shm);
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $room->user[$i] = User::load_data($i);
+ }
}
- $ret = &$room;
- return ($ret);
+
+ //
+ // SHSPLIT: load users from the shared memory
+ //
+ return ($room);
} while (0);
if ($doexit)
exit();
- return ($G_false);
+ return (FALSE);
}
- function save_data(&$room)
+ function save_data_orig(&$room)
{
GLOBAL $sess;
@@ -2209,6 +2319,57 @@ class Room {
return (FALSE);
}
+
+ function save_data(&$room)
+ {
+ GLOBAL $sess;
+
+ $ret = FALSE;
+ $shm = FALSE;
+
+ // var_dump($room);
+ // error_log("Room::save_data BEGIN", 0);
+
+ if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
+ return (FALSE);
+
+ // SHSPLIT: before save the $room you must save users,
+ // detach from main struct and (then) reattach
+ $user_park = array();
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_park[$i] = $room->user[$i];
+ $room->user[$i] = FALSE;
+ }
+
+ while ($room->shm_sz < SHM_DIMS_MAX) {
+ if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
+ break;
+
+ // log_only("PUT_VAR DI ".strlen(serialize($room)));
+ if (shm_put_var($shm, $tok, $room) != FALSE) {
+ $ret = TRUE;
+ break;
+ }
+ if (shm_remove($shm) === FALSE) {
+ log_only("REMOVE FALLITA");
+ break;
+ }
+ shm_detach($shm);
+ $room->shm_sz += SHM_DIMS_DLT;
+ }
+
+ if ($shm)
+ shm_detach($shm);
+
+ // SHSPLIT: reattach users to the room class
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ User::save_data($user_park[$i], $i);
+ $room->user[$i] = $user_park[$i];
+ }
+
+ return ($ret);
+ }
+
function lock_data()
{
GLOBAL $sess;