echo "$pp/$dname"
return 0
fi
- pp="`dirname "$pp"`"
+ pp="$(dirname "$pp")"
done
return 1
# echo aa $1 xx $2 bb
conffile=""
case $1 in
- -f*) conffile="`get_param "-f" "$1" "$2"`"; sh=$?;;
- -p*) outconf="`get_param "-p" "$1" "$2"`"; sh=$?;;
- -n*) players_n="`get_param "-n" "$1" "$2"`"; sh=$?;;
- -t*) tables_n="`get_param "-t" "$1" "$2"`"; sh=$?;;
- -T*) tables_auth_n="`get_param "-T" "$1" "$2"`"; sh=$?;;
- -a*) brisk_auth_conf="`get_param "-a" "$1" "$2"`"; sh=$?;;
- -d*) brisk_debug="`get_param "-d" "$1" "$2"`"; sh=$?;;
- -w*) web_path="`get_param "-w" "$1" "$2"`"; sh=$?;;
- -k*) ftok_path="`get_param "-k" "$1" "$2"`"; sh=$?;;
- -y*) proxy_path="`get_param "-y" "$1" "$2"`"; sh=$?;;
- -c*) cookie_path="`get_param "-c" "$1" "$2"`"; sh=$?;;
- -C*) brisk_conf="`get_param "-C" "$1" "$2"`"; sh=$?;;
- -l*) legal_path="`get_param "-l" "$1" "$2"`"; sh=$?;;
+ -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
+ -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
+ -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
+ -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
+ -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
+ -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
+ -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
+ -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
+ -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
+ -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
+ -c*) cookie_path="$(get_param "-c" "$1" "$2")"; sh=$?;;
+ -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
+ -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
-W) web_only="TRUE";;
-h) usage $0; exit 0;;
*) usage $0; exit 1;;
# Pre-check
#
# check for etc path existence
-dsta="`dirname "$web_path"`"
-etc_path="`searchetc "$dsta" Etc`"
+dsta="$(dirname "$web_path")"
+etc_path="$(searchetc "$dsta" Etc)"
if [ $? -ne 0 ]; then
echo "Etc directory not found"
exit 1
chmod 666 ${ftokk_path}/warrant
touch ${ftokk_path}/poll
chmod 666 ${ftokk_path}/poll
- for i in `seq 0 99`; do
+ for i in $(seq 0 99); do
touch ${ftokk_path}/table$i
chmod 666 ${ftokk_path}/table$i
done
+ for i in $(seq 0 299); do
+ touch ${ftokk_path}/user$i
+ chmod 666 ${ftokk_path}/user$i
+ done
fi
install -d ${web_path}__
-for i in `find web -type d | grep -v /CVS | sed 's/^....//g'`; do
+for i in $(find web -type d | grep -v /CVS | sed 's/^....//g'); do
install -d ${web_path}__/$i
done
-for i in `find web -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' | grep -v /CVS | sed 's/^....//g'`; do
+for i in $(find web -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' | grep -v /CVS | sed 's/^....//g'); do
install -m 644 web/$i ${web_path}__/$i
done
fi
# .js substitutions
-sed -i "s/PLAYERS_N *= *[0-9]\+/PLAYERS_N = $players_n/g" `find ${web_path}__ -type f -name '*.js' -exec grep -l 'PLAYERS_N *= *[0-9]\+' {} \;`
+sed -i "s/PLAYERS_N *= *[0-9]\+/PLAYERS_N = $players_n/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l 'PLAYERS_N *= *[0-9]\+' {} \;)
-sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" `find ${web_path}__ -type f -name '*.js' -exec grep -l '^var G_send_time *= *[0-9]\+' {} \;`
+sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l '^var G_send_time *= *[0-9]\+' {} \;)
# .ph[pho] substitutions
-sed -i "s/define *( *PLAYERS_N, *[0-9]\+ *)/define(PLAYERS_N, $players_n)/g" `find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *PLAYERS_N, *[0-9]\+ *)' {} \;`
+sed -i "s/define *( *PLAYERS_N, *[0-9]\+ *)/define(PLAYERS_N, $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *PLAYERS_N, *[0-9]\+ *)' {} \;)
-sed -i "s/define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)/define(BRISKIN5_PLAYERS_N, $players_n)/g" `find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)' {} \;`
+sed -i "s/define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)/define(BRISKIN5_PLAYERS_N, $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)' {} \;)
-sed -i "s@define *( *FTOK_PATH,[^)]*)@define(FTOK_PATH, \"$ftok_path\")@g" `find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *FTOK_PATH,[^)]*)' {} \;`
+sed -i "s@define *( *FTOK_PATH,[^)]*)@define(FTOK_PATH, \"$ftok_path\")@g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *FTOK_PATH,[^)]*)' {} \;)
sed -i "s@define *( *TABLES_N,[^)]*)@define(TABLES_N, $tables_n)@g" ${web_path}__/Obj/brisk.phh
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);
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
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") {
+ function &create($idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
GLOBAL $G_false;
+ // error_log("User::create BEGIN", 0);
+
if (($thiz =& new User()) == FALSE)
return ($G_false);
+ $thiz->idx = $idx;
$thiz->code = -1;
$thiz->name = $name;
$thiz->sess = $sess;
$thiz->table = $table;
$thiz->table_pos = -1;
$thiz->table_token = "";
-
+ $thiz->shm_sz = SHM_DIMS_U_MIN;
return ($thiz);
}
{
GLOBAL $G_false;
+ $this->idx = $from->idx;
$this->code = $from->code;
$this->name = $from->name;
$this->sess = $from->sess;
$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);
}
if (($thiz =& new User()) == FALSE)
return ($G_false);
+ $thiz->idx = $from->idx;
$thiz->code = $from->code;
$thiz->name = $from->name;
$thiz->sess = $from->sess;
$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);
}
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);
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);
$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 $G_false, $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
+ //
+ $ret = &$user;
+ return ($ret);
+ } while (0);
+
+ if ($doexit)
+ exit();
+
+ return ($G_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) {
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)
$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++) {
$this->table[$i]->auth_only = FALSE;
}
$this->garbage_timeout = 0;
+ $this->shm_sz = SHM_DIMS_MIN;
}
function garbage_manager($force)
$msg = substr($mesg, 6, 128);
$curtime = time();
$dt = date("H:i ", $curtime);
+ $target = "";
//
// Compute actions
$idx = 0;
+ error_log("add_user: G_false: [".$G_false."]", 0);
+
$authenticate = FALSE;
$user_type = 0;
$login_exists = FALSE;
log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
if ($authenticate != FALSE) {
+ error_log(print_r(&$authenticate, TRUE),0);
$user_type = $authenticate->type_get();
}
else {
}
// Static functions
- function &init_data()
+ static function &create()
{
$room =& new Room();
return $room;
}
-
+
function &load_data()
{
GLOBAL $G_false, $sess;
$doexit = FALSE;
+
+ // error_log("Room::load_data BEGIN", 0);
+
do {
if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
log_main("ftok failed");
$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 $G_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);
+ }
}
+
+ //
+ // SHSPLIT: load users from the shared memory
+ //
$ret = &$room;
return ($ret);
} while (0);
}
- function save_data(&$room)
+ function save_data_orig(&$room)
{
GLOBAL $sess;
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;
}
}
- $ret = new DBConn();
+ $out = new DBConn();
- return $ret;
+ return $out;
}
function db()
{
{
GLOBAL $DOCUMENT_ROOT, $G_dbpfx, $G_false;
- $dbconn = $G_false;
- $ret = $G_false;
+ $ret = FALSE;
log_main("BriskDB create:start");
do {
- if (($dbconn = DBConn::create()) == FALSE)
+ if (($dbconn = DBConn::create()) == FALSE)
break;
$ret = new BriskDB($dbconn);
} while (0);
- log_main("BriskDB create:end");
- return ($ret);
+ if ($ret)
+ return ($ret);
+ else
+ return ($G_false);
}
function users_load()
{
GLOBAL $G_dbpfx, $G_false;
- $ret = &$G_false;
+ error_log("dbase_pgsql G_false: [".$G_false."]", 0);
+
+ $ret = FALSE;
log_main("login_verify: ".$login);
//O for ($i = 0 ; $i < $this->item_n ; $i++) {
//O log_main("login_verify: BEGIN");
- if (($user_obj = $this->getrecord_bylogin($login)) == FALSE)
- return $ret;
+ if (($user_obj = $this->getrecord_bylogin($login)) == FALSE) {
+ return $G_false;
+ }
+
+ error_log("G_false: [".$G_false."] user_obj: ".print_r($user_obj, TRUE), 0);
log_main("login[".$user_obj->code."]: ".$user_obj->login);
/* if it exists check for a valid challenge */
if (($a_sem = Challenges::lock_data()) != FALSE) {
+ error_log("loop-2", 0);
if (($chals = &Challenges::load_data()) != FALSE) {
+ error_log("loop-1", 0);
for ($e = 0 ; $e < $chals->item_n ; $e++) {
-
+ error_log("loop", 0);
log_main("challenge[".$e."]: ".$chals->item[$e]->login);
if (strcmp($login, $chals->item[$e]->login) == 0) {
+ error_log("loop2", 0);
log_main("login_verify [".$pass."] with [".md5($chals->item[$e]->token.$user_obj->pass)."]");
if (strcmp($pass, md5($chals->item[$e]->token.$user_obj->pass)) == 0) {
+ error_log("loop3", 0);
log_main("login_verify SUCCESS for ".$login);
$chals->rem($login);
$ret = LoginDBItem::LoginDBItemFromRecord($user_obj);
+ error_log("dbitem: ".print_r($ret, TRUE));
break;
}
}
} // end for ($e = 0 ...
+ error_log("end loop-1", 0);
}
if ($chals->ismod()) {
// O } // if (strcasecmp($this->item[$i]->login, ...
//O }
- return ($ret);
+ error_log("return: ".($G_false == FALSE ? "FALSE" : "not FALSE"), 0);
+
+ if ($ret)
+ return ($ret);
+ else
+ return ($G_false);
}
function &getitem_bylogin($login, &$id) {