web_only="FALSE"
brisk_conf="brisk.conf.pho"
-if [ "$1" = "--ck" ]; then
- find -name '*.pho' -o -name '*.phh' -o -name '*.php' -exec php5 -l {} \;
+if [ "$1" = "chk" ]; then
+ set -e
+ oldifs="$IFS"
+ IFS='
+'
+ for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
+ php5 -l $i
+ done
exit 0
fi
+# before all check errors on the sources
+$0 chk || exit 3
+
+if [ "$1" = "pkg" ]; then
+ if [ "$2" != "" ]; then
+ tag="$2"
+ else
+ tag="$(git describe)"
+ fi
+ nam1="brisk_${tag}.tgz"
+ nam2="brisk-img_${tag}.tgz"
+ echo "Build packages ${nam1} and ${nam2}."
+ read -p "Proceed [y/n]: " a
+ if [ "$a" != "y" -a "$a" != "Y" ]; then
+ exit 1
+ fi
+ git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
+ cd ../brisk-img
+ git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
+ cd -
+ exit 0
+fi
+
if [ -f $HOME/.brisk_install ]; then
. $HOME/.brisk_install
fi
+
if [ "x$cookie_path" = "x" ]; then
cookie_path=$web_path
fi
+
function usage () {
echo
echo "$1 -h"
- echo "$1 --ck - run lintian on all ph* files."
+ echo "$1 chk - run lintian on all ph* files."
+ echo "$1 pkg - build brisk packages."
echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-a <auth_file_name>] [-f conffile] [-p outconf] [-d TRUE|FALSE] [-w web_dir] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-c <cookie_path>]"
echo " -h this help"
echo " -f use this config file"
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
DONE - produrle
DONE - mostrarle
+ STEP 1.1
+ DONE - points archiver
+
+ STEP 1.2
+ - partial usability if database go down.
+
STEP 1.5
- - sistema di inserimento nuovi utenti (riversatore da form di inserimento)
+ - sistema di inserimento nuovi utenti (riversatore da form di inserimento)
STEP 2
- aggiornare le funz di gestione db in modo che prevedano anche il flag SUSPEND
+== how to move match ==
+select m.code, m.ttok, min(g.tstamp) from bsk_bin5_matches as m, bsk_bin5_games as g where g.mcode = m.code GROUP BY m.code, m.ttok;
+
== rende la view dei punteggi ==
select m.ttok, m.tidx, g.code, g.tstamp, p.pts, u.login from bsk_bin5_points as p, bsk_bin5_games as g, bsk_bin5_matches as m, bsk_users as u where p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND g.tstamp > '2010-10-01 00:00:00' ORDER BY g.tstamp;
#
# all this part is from mopshop and we will use it to construct the brisk database
#
-DBHOST=127.0.0.1
-DBUSER=brisk
-DBBASE=brisk
-DBPASS=briskpass
-PFX="bsk_"
+
+if [ -f $HOME/.db.conf ]; then
+ source $HOME/.db.conf
+else
+ DBHOST=127.0.0.1
+ DBUSER=brisk
+ DBBASE=brisk
+ DBPASS=briskpass
+ PFX="bsk_"
+fi
if [ -f $HOME/.brisk_install ]; then
- . $HOME/.brisk_install
+ source $HOME/.brisk_install
fi
+
sqlexe () {
local sht
sht=$1
# MAIN
#
sht=0
-if [ -f $HOME/.db.conf ]; then
- source $HOME/.db.conf
-fi
if [ "$1" = "-s" ]; then
shift
( echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) | sqlexe $sht
elif [ "$1" = "rebuild" ]; then
( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; \
- echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
+ echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
| sqlexe $sht
elif [ "$1" = "psql" ]; then
psql -h $DBHOST -U $DBUSER $DBBASE $@
elif [ "$1" = "piped" ]; then
psql -h $DBHOST -U $DBUSER $DBBASE -t -q -A -F '|' $@
elif [ "$1" = "dump" ]; then
- if [ $# -eq 1 ]; then
- pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
- else
- pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
- fi
+ if [ $# -eq 1 ]; then
+ pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
+ else
+ pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
+ fi
elif [ "$1" = "dumpall" ]; then
- if [ $# -eq 1 ]; then
- pg_dump -h $DBHOST -U $DBUSER $DBBASE
- else
- pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
- fi
+ if [ $# -eq 1 ]; then
+ pg_dump -h $DBHOST -U $DBUSER $DBBASE
+ else
+ pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
+ fi
elif [ "$1" = "add" ]; then
- cat "$2" | psql -h $DBHOST -U $DBUSER $DBBASE
+ cat "$2" | psql -h $DBHOST -U $DBUSER $DBBASE
else
echo " USAGE"
echo " ./builder create"
pass text,
email text UNIQUE,
type integer,
- tsusp timestamp DEFAULT to_timestamp(0) -- disable timeout
- mtime timestamp DEFAULT to_timestamp(0) -- last access
+ tsusp timestamp DEFAULT to_timestamp(0), -- disable timeout
+ mtime timestamp DEFAULT to_timestamp(0) -- last access
);
DROP TABLE #PFX#groups;
log_auth("xxx", sprintf("Challenges::add [%s]\n", $login));
// FIXME Checks here
if ($login == '') {
- return ($G_false);
+ return (FALSE);
}
// log_auth("xxx", "LOOPI tstamp: ".$this->item[$i]->tstamp." curtime: ".$curtime);
- if (($chal = new Challenge($login, $token, $ip, $tstamp)) == null) {
- return ($G_false);
+ if (($chal = new Challenge($login, $token, $ip, $tstamp)) == FALSE) {
+ return (FALSE);
}
$this->item[$this->item_n] = $chal;
}
// Static functions
- function &init_data()
+ static function create()
{
$chal =& new Challenges();
return $chal;
}
- function &load_data()
+ function load_data()
{
- GLOBAL $G_false, $sess;
+ GLOBAL $sess;
$doexit = FALSE;
do {
if (($tok = @ftok(FTOK_PATH."/challenges", "B")) == -1) {
if ($chals == FALSE) {
log_only("INIT CHALLENGES DATA");
- $chals =& Challenges::init_data();
+ $chals =& Challenges::create();
if (@shm_put_var($shm, $tok, $chals) == FALSE) {
log_only("PUT_VAR FALLITA ".strlen(serialize($chals)));
log_only(serialize($chals));
$chals->garbage_manager();
- $ret = &$chals;
- return ($ret);
+ return ($chals);
} while (0);
if ($doexit)
exit();
- return ($G_false);
+ return (FALSE);
}
- function save_data(&$chals)
+ function save_data($chals)
{
$shm = FALSE;
$oldmod = $chals->mod;
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);
'tit_onauth'=>array( 'it' => '(solo aut.)',
'en' => '(only aut.)'),
'tit_onisol'=>array( 'it' => '(isolam.to)',
- 'en' => '(isolation)')
+ 'en' => '(isolation)'),
+ 'db_failed' =>array('it' => '<br>Il collegamento al database è fallito.<br>Temporaneamente tutte le autenticazioni verranno sospese, accederai a Brisk come un utente normale.<br><br>Ci scusiamo per il disagio.',
+ 'en' => 'Connection to the database failed<br>All authentications are suspended temporarly, you login as normal user.<br>We are about the limitation')
);
-$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 = "2.5.0";
+$G_brisk_version = "3.2.0";
/* MLANG: ALL THE INFO STRINGS IN brisk.phh */
$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: informazioni al tavolo sul chiamante, nuovo stato di supporter del sito.',
{
}
- 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();
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++)
$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();
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;
}
define(USER_FLAG_AUTH, 0x02);
define(USER_FLAG_MAP_AUTH, 0x0c);
-
define(USER_FLAG_LISTAUTH, 0x04);
define(USER_FLAG_ISOLAUTH, 0x08);
+define(USER_FLAG_DBFAILED, 0x10);
+
// user status
define(USER_FLAG_S_NORM, 0x000); // done
define(USER_FLAG_S_PAU, 0x100); // 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
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;
$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;
$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;
$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 $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) {
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)
$ret .= sprintf('stat = "%s";', $user->stat);
$ret .= root_wellcome($user);
+ if ($user->flags & USER_FLAG_DBFAILED) {
+ $ret .= "gst.st = ".($user->step+1)."; ";
+ $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
+ }
+
$ret .= sprintf('subst = "%s";', $user->subst);
$itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
$itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
$msg = substr($mesg, 6, 128);
$curtime = time();
$dt = date("H:i ", $curtime);
+ $target = "";
//
// Compute actions
$user->name = $name_new; // OK - nick changed
/* se nome gia' in uso, segnala cosa potrebbe capitare */
if (($user->flags & USER_FLAG_AUTH) == 0) {
- $bdb = new BriskDB();
- $bdb->users_load();
- /* MLANG: "Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>" */
- if ($bdb->login_exists($name_new)) {
- $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
- $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
- }
+ if (($bdb = BriskDB::create()) != FALSE) {
+ $bdb->users_load();
+ /* MLANG: "Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>" */
+ if ($bdb->login_exists($name_new)) {
+ $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
+ $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
+ }
+ }
}
log_main("chatt_send start set");
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++) {
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
* if ($idx == -3 && ret == FALSE) => wrong password
* if ($idx == -1 && ret == FALSE) => no space left
* if ($idx == 0 && ret == user) => SUCCESS
- * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
+ * 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;
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)));
/* if pass != FALSE verify the login with pass */
log_auth("XXX", "auth1");
- $bdb = new BriskDB();
- $bdb->users_load();
- if ($pass != FALSE) {
- log_auth("XXX", "auth2");
- $authenticate = $bdb->login_verify($name_new, $pass, $code);
- log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
-
- if ($authenticate != FALSE) {
- $user_type = $authenticate->type_get();
- }
- else {
- $idx = -3;
- return ($G_false);
- }
+
+ if (($bdb = BriskDB::create()) != FALSE) {
+ $bdb->users_load();
+ if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
+ log_auth("XXX", "auth2");
+ $authenticate = $bdb->login_verify($name_new, $pass, $code);
+ 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 (FALSE);
+ }
+ }
+ else {
+ $login_exists = $bdb->login_exists($name_new);
+ }
}
else {
- $login_exists = $bdb->login_exists($name_new);
+ // if db is down, send a warning and verify only current users
+ // no actions at this moment
}
for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
/* free user ? */
if ($idx == -1)
$idx = $i;
}
- if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
+ if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
$idfree = $i;
continue; // NOTE: CHECK IT !!
}
log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
+ /* there is another user logged with your account and you and him have authenticated => che new user
+ get the session of the old user */
if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
/* swap session */
$this->user[$idx]->bantime = 0;
$this->user[$idx]->ip = $ip;
- $this->user[$idx]->flags = ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00) | $user_type;
-
+ $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));
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];
}
// 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");
$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;
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;
$this->type = $type;
}
- static function &LoginDBItemFromRecord($rec)
+ static function LoginDBItemFromRecord($rec)
{
- $ret = & new LoginDBItem($rec->code, $rec->login, $rec->pass,
+ $ret = new LoginDBItem($rec->code, $rec->login, $rec->pass,
$rec->email, $rec->type);
return ($ret);
log_main("BriskDB create:end");
}
+ static function create()
+ {
+ $ret = new BriskDB();
+
+ return ($ret);
+ }
+
function users_load()
{
GLOBAL $DOCUMENT_ROOT;
return ($this->item[$idx]->login);
}
- function &getitem_bylogin($login, &$id)
+ function getitem_bylogin($login, &$id)
{
- GLOBAL $G_false;
-
log_main("login_exists: ".$login);
/* check the existence of the nick in the BriskDB */
}
}
$id = -1;
- return ($G_false);
+ return (FALSE);
}
function getmail($login)
return (FALSE);
}
- function &login_verify($login, $pass)
+ function login_verify($login, $pass)
{
- GLOBAL $G_false;
-
- $ret = &$G_false;
+ $ret = FALSE;
log_main("login_verify: ".$login);
var $db = FALSE;
function DBConn()
+ {
+ $this->db = DBConn::$dbcnnx;
+ }
+
+ static function create()
{
GLOBAL $G_dbauth;
if (DBConn::$dbcnnx == FALSE) {
if (!(DBConn::$dbcnnx = @pg_connect ($G_dbauth))) {
- echo "DB connection failed.";
- exit;
+ return (FALSE);
}
}
- $this->db = DBConn::$dbcnnx;
- return;
+ $out = new DBConn();
+
+ return $out;
}
function db()
{
var $item;
var $item_n;
- function BriskDB()
+ function BriskDB($dbconn)
{
- GLOBAL $DOCUMENT_ROOT, $G_dbpfx, $G_false;
+ $this->dbconn = $dbconn;
+ }
+
+ static function create()
+ {
+ GLOBAL $DOCUMENT_ROOT, $G_dbpfx;
+
+ $ret = FALSE;
+
log_main("BriskDB create:start");
- $this->dbconn = new DBConn();
+ do {
+ if (($dbconn = DBConn::create()) == FALSE)
+ break;
+
+ $ret = new BriskDB($dbconn);
+ } while (0);
- log_main("BriskDB create:end");
+ return ($ret);
}
function users_load()
return FALSE;
}
- function &getrecord_bylogin($login) {
- GLOBAL $G_false, $G_dbpfx;
+ function getrecord_bylogin($login) {
+ GLOBAL $G_dbpfx;
$user_sql = sprintf("SELECT * FROM %susers WHERE login = lower('%s') AND (type & CAST (X'%08x' as integer)) = 0;", $G_dbpfx, escsql($login), USER_FLAG_TY_DISABLE);
if (($user_pg = pg_query($this->dbconn->db(), $user_sql)) == FALSE)
- return $ret;
+ return FALSE;
if (pg_numrows($user_pg) != 1)
- return $ret;
+ return FALSE;
$user_obj = pg_fetch_object($user_pg, 0);
- function &login_verify($login, $pass)
+ function login_verify($login, $pass)
{
- GLOBAL $G_dbpfx, $G_false;
+ GLOBAL $G_dbpfx;
- $ret = &$G_false;
+ $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 FALSE;
+ }
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()) {
return ($ret);
}
- function &getitem_bylogin($login, &$id) {
- GLOBAL $G_false;
-
- $ret = &$G_false;
+ function getitem_bylogin($login, &$id) {
+ $ret = FALSE;
$id = -1;
log_main("getitem_bylogin: ".$login);
return TRUE;
}
- function &getdbconn()
+ function getdbconn()
{
- $ret = $this->dbconn;
- return ($ret);
+ return ($this->dbconn);
}
// ttok text UNIQUE,
log_auth("xxx", sprintf("Hardbans::add [%s]\n", $login));
- if (($chal = new Hardban($login, $ip, $session, $timeout)) == null) {
- return ($G_false);
+ if (($chal = new Hardban($login, $ip, $session, $timeout)) == FALSE) {
+ return (FALSE);
}
$this->item[$this->item_n] = $chal;
}
// Static functions
- function &init_data()
+ static function create()
{
$chal =& new Hardbans();
return $chal;
}
- function &load_data()
+ function load_data()
{
- GLOBAL $G_false, $sess;
+ GLOBAL $sess;
$doexit = FALSE;
do {
if (($tok = @ftok(FTOK_PATH."/hardbans", "B")) == -1) {
if ($hban == FALSE) {
log_only("INIT HARDBAN DATA");
- $hban =& Hardbans::init_data();
+ $hban =& Hardbans::create();
if (@shm_put_var($shm, $tok, $hban) == FALSE) {
log_only("PUT_VAR FALLITA ".strlen(serialize($hban)));
log_only(serialize($hban));
$hban->garbage_manager(TRUE);
- $ret = &$hban;
- return ($ret);
+ return ($hban);
} while (0);
if ($doexit)
exit();
- return ($G_false);
+ return (FALSE);
}
- function save_data(&$hban)
+ function save_data($hban)
{
$shm = FALSE;
$oldmod = $hban->mod;
$cont .= sprintf("Loading failed.<br>\n");
break;
}
- $newdb = new BriskDB();
+
+ if (($newdb = BriskDB::create()) == FALSE) {
+ $cont .= sprintf("Database connection failed.<br>\n");
+ break;
+ }
$newdb->users_load();
if ($newdb->addusers_from_olddb($olddb, $cont) == FALSE) {
$cont .= sprintf("Insert failed.<br>\n");
break;
}
- $newdb = new BriskDB();
+ if (($newdb = BriskDB::create()) == FALSE) {
+ $cont .= sprintf("Database connection failed.<br>\n");
+ break;
+ }
+
$newdb->users_load();
$dbconn = $newdb->getdbconn();
for ($pts_n = 0 ; !feof($fp) ; $pts_n++) {
/* CREATE() NOT USED
- function &create($idx)
+ function create($idx)
{
- GLOBAL $G_false;
-
if (($thiz =& new Table_briskin5()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->create($idx);
*/
/* CLONE() NOT USED
- function &myclone(&$from)
+ function myclone(&$from)
{
- GLOBAL $G_false;
-
if (($thiz =& new Table_briskin5()) == FALSE)
- return ($G_false);
+ return (FALSE);
parent::copy($from);
parent::copy($from);
}
- function &spawn(&$from)
+ function spawn(&$from)
{
- GLOBAL $G_false;
-
if (($thiz =& new Table_briskin5()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->parentcopy($from);
log_main("PLAYER_N - spawn.".$thiz->player_n);
- $thiz->card = &$thiz->bunch_create();
+ $thiz->card = array();
+ $thiz->bunch_create();
$thiz->mazzo = rand(0,PLAYERS_N-1);
$thiz->points_n = 0;
$thiz->mult = 1;
}
- function &bunch_create()
- {
- $ret = array();
-
- for ($i = 0 ; $i < (BRISKIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
- // for ($i = 0 ; $i < 40 ; $i++) {
- $ret[$i] =& new Card($i, 'bunch', 'no_owner');
- }
+ // function bunch_create_old() function AND
+ // {
+ // $ret = array();
+ //
+ // for ($i = 0 ; $i < (BRISKIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
+ // // for ($i = 0 ; $i < 40 ; $i++) {
+ // $ret[$i] =& new Card($i, 'bunch', 'no_owner');
+ // }
+ //
+ // $oret = &$ret;
+ // return ($oret);
+ // }
- $oret = &$ret;
- return ($oret);
+ function bunch_create()
+ {
+ $ret = array();
+
+ for ($i = 0 ; $i < (BRISKIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
+ $this->card[$i] = new Card($i, 'bunch', 'no_owner');
+ }
}
function bunch_make()
}
/* CREATE NOT USED
- function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
- GLOBAL $G_false;
-
+ function create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
if (($thiz =& new User()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->asta_card = -2;
$thiz->asta_pnt = -1;
}
/* CLONE NOT USED
- function &myclone(&$from)
+ function myclone(&$from)
{
- GLOBAL $G_false;
-
if (($thiz =& new User()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->copy($from);
}
*/
- function &spawn(&$from, $table, $table_pos)
+ function spawn(&$from, $table, $table_pos)
{
- GLOBAL $G_false, $CO_bin5_pref_ring_endauct;
+ GLOBAL $CO_bin5_pref_ring_endauct;
if (($thiz =& new User_briskin5()) == FALSE)
- return ($G_false);
+ return (FALSE);
$thiz->parentcopy($from);
}
- 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 < BRISKIN5_MAX_PLAYERS ; $i++) {
log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
}
- return ($G_false);
+ return (FALSE);
}
//
// static functions
//
- function &load_data($table_idx, $table_token = "")
+ function load_data($table_idx, $table_token = "")
{
GLOBAL $G_false, $sess;
$doexit = FALSE;
if ($doexit)
exit();
- return ($G_false);
+ return (FALSE);
}
$this->gam = $gam;
}
- function &myclone()
+ function myclone()
{
$ret = new Ptsgam($this->username, $this->pts, $this->gam);
function placing_time_pgsql()
{
GLOBAL $G_dbpfx;
- $bdb = new BriskDB();
+
+ if (($bdb = BriskDB::create()) == FALSE) {
+ log_crit("placing: database connection failed");
+ return (FALSE);
+ }
$mti_sql = sprintf("SELECT CAST(EXTRACT(EPOCH FROM mtime) AS INTEGER) as mtime
FROM %sbin5_places_mtime WHERE code = 0;", $G_dbpfx);
}
-function placing_show_file(&$user, $ty, $subty)
+function placing_show_file($user, $ty, $subty)
{
$tail = FALSE;
function placing_show_pgsql(&$user, $ty, $subty)
{
GLOBAL $G_dbpfx;
-
- $bdb = new BriskDB();
+
+ if (($bdb = BriskDB::create()) == FALSE) {
+ log_crit("placing: database connection failed");
+ return ("");
+ }
if ($user != FALSE) {
$pla_sql = sprintf("SELECT * from %sbin5_places where type = %d AND (rank <= %d OR ucode = '%s');",
if (($proxy_step = step_get($sess)) != FALSE) {
// log_rd2("Postget".$proxy_step."zizi");
- if ($cur_step == $proxy_step) {
+ if ($cur_step == $proxy_step['s']) {
log_lock("P");
return (FALSE);
}
if ($user->table_orig < TABLES_AUTH_N) {
require_once("../Obj/dbase_".$G_dbasetype.".phh");
+ if (($bdb = BriskDB::create()) != FALSE) {
+ $bdb->bin5_points_save($curtime, $table->table_token, $user->table_orig, $ucodes, $pt_cur);
+ unset($bdb);
+ }
+ else {
+ log_points($curtime, $user, "STAT:BRISKIN5:FINISH_GAME", "DATABASE CONNECTION FAILED");
+ }
log_points($curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist);
- $bdb = new BriskDB();
- $bdb->bin5_points_save($curtime, $table->table_token, $user->table_orig, $ucodes, $pt_cur);
- unset($bdb);
}
$table->game_next();
/*
line example:
1246428948|492e4e9e856b0|N|tre|172.22.1.90|STAT:BRISKIN5:FINISH_GAME|4a4afd4983039|6|3|tre|1|due|2|uno|-1|
-
-TODO:
- - update the STAT file with differential
- - recalculate points
-
*/
function main_file($curtime)
{
+ GLOBAL $G_alarm_passwd;
$tri = array();
$mon = array();
$wee = array();
fclose($fp_start);
}
- $bdb = new BriskDB();
+ if (($bdb = BriskDB::create()) == FALSE) {
+ echo "database connection failed";
+ exit;
+ }
+
$bdb->users_load();
for ($i = 0 ; $i < $bdb->count() ; $i++) {
{
GLOBAL $G_dbpfx;
- $bdb = new BriskDB();
+ if (($bdb = BriskDB::create()) == FALSE) {
+ echo "database connection failed";
+ exit;
+ }
$limi = array( TRI_LIMIT, MON_LIMIT, WEE_LIMIT );
$ming = array( TRI_MIN_GAMES, MON_MIN_GAMES, WEE_MIN_GAMES );
log_crit("statadm: begin failed");
break;
}
+
+ $mtc_sql = sprintf("CREATE TEMPORARY TABLE %sbin5_temp_matches ON COMMIT DROP AS SELECT m.code, max(g.tstamp) AS tstamp
+ FROM %sbin5_matches as m, %sbin5_games as g
+ WHERE g.mcode = m.code GROUP BY m.code, m.ttok",
+ $G_dbpfx, $G_dbpfx, $G_dbpfx);
+ // error_log($mtc_sql, 0);
+ if (pg_query($bdb->dbconn->db(), $mtc_sql) == FALSE) {
+ log_crit("statadm: temporary matches table creation [$mtc_sql] failed");
+ break;
+ }
+
+ $tmt_sql = sprintf("SELECT * FROM %sbin5_temp_matches WHERE tstamp < to_timestamp(%d)",
+ $G_dbpfx, $curtime - TRI_LIMIT);
+ // error_log($tmt_sql, 0);
+
+ // if deletable old matches exists then ...
+ if (($tmt_pg = pg_query($bdb->dbconn->db(), $tmt_sql)) != FALSE) {
+ //
+ // store matches before clean them
+ //
+ $fname = sprintf("%s/pts_archive%s.log", LEGAL_PATH, date("Ymd", $curtime));
+ if (($fp = @fopen($fname, 'a')) == FALSE) {
+ log_crit("statadm: log file [$fname] open failed");
+ break;
+ }
+
+ $tmt_n = pg_numrows($tmt_pg);
+ // get matches
+ for ($m = 0 ; $m < $tmt_n ; $m++) {
+ $tmt_obj = pg_fetch_object($tmt_pg, $m);
+
+ $mtc_sql = sprintf("SELECT * from %sbin5_matches WHERE code = %d",
+ $G_dbpfx, $tmt_obj->code);
+
+ error_log($mtc_sql, 0);
+ if (($mtc_pg = pg_query($bdb->dbconn->db(), $mtc_sql)) == FALSE || pg_numrows($mtc_pg) != 1) {
+ log_crit("statadm: matches row select failed");
+ break;
+ }
+ $mtc_obj = pg_fetch_object($mtc_pg, 0);
+
+ if (fwrite($fp, sprintf("M|%d|%s|%d|\n", $mtc_obj->code, xcapelt($mtc_obj->ttok), $mtc_obj->tidx)) == FALSE) {
+ log_crit("statadm: log file [$fname] write match failed");
+ break;
+ }
+
+ // get games associated to each match
+ $gam_sql = sprintf("SELECT code, mcode, EXTRACT(epoch FROM tstamp) AS tstamp FROM %sbin5_games
+ WHERE mcode = %d ORDER BY tstamp",
+ $G_dbpfx, $mtc_obj->code);
+ if (($gam_pg = pg_query($bdb->dbconn->db(), $gam_sql)) == FALSE) {
+ log_crit("statadm: games row select failed");
+ break;
+ }
+
+ $gam_n = pg_numrows($gam_pg);
+ for ($g = 0 ; $g < $gam_n ; $g++) {
+ $gam_obj = pg_fetch_object($gam_pg, $g);
+
+ if (fwrite($fp, sprintf("G|%d|%d|%d|\n", $gam_obj->mcode, $gam_obj->code, $gam_obj->tstamp)) == FALSE) {
+ log_crit("statadm: log file [$fname] write game failed");
+ break;
+ }
+ $pts_sql = sprintf("SELECT * FROM %sbin5_points WHERE gcode = %d", $G_dbpfx, $gam_obj->code);
+ if (($pts_pg = pg_query($bdb->dbconn->db(), $pts_sql)) == FALSE) {
+ log_crit("statadm: points row select [$pts_sql] failed");
+ break;
+ }
+ $pts_n = pg_numrows($pts_pg);
+ for ($p = 0 ; $p < $pts_n ; $p++) {
+ $pts_obj = pg_fetch_object($pts_pg, $p);
+
+ if (fwrite($fp, sprintf("P|%d|%d|%d|\n", $pts_obj->gcode, $pts_obj->ucode, $pts_obj->pts)) == FALSE) {
+ log_crit("statadm: log file [$fname] write pts failed");
+ break;
+ }
+ }
+ if ($p < $pts_n)
+ break;
+ }
+ if ($g < $gam_n)
+ break;
+
+ // delete match and all it's childs (games and points)
+ $del_sql = sprintf("DELETE FROM %sbin5_matches WHERE code = %d",
+ $G_dbpfx, $tmt_obj->code);
+ if (($del_pg = pg_query($bdb->dbconn->db(),$del_sql)) == FALSE || pg_affected_rows($del_pg) != 1) {
+ log_crit("statadm: matches row deletion failed");
+ break;
+ }
+
+ }
+ if ($m < $tmt_n)
+ break;
+ } // if (($tmt_pg = pg_query($bdb->dbco...
- // Truncate table (postgresql extension, in other SQL you must user unqualified DELETE
+ // GEN: Truncate table (postgresql extension, in other SQL you must user unqualified DELETE
$tru_sql = sprintf("TRUNCATE %sbin5_places;", $G_dbpfx);
if (pg_query($bdb->dbconn->db(), $tru_sql) == FALSE) {
log_crit("statadm: truncate failed");
break;
}
-
+
for ($dtime = 0 ; $dtime < count($limi) ; $dtime++) {
$old_score = array( 1000000000, 1000000000);
$old_gam = array( -1, -1);
$pla_sql = sprintf("SELECT (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) as score, sum(p.pts) as points, count(p.pts) as games, u.code as ucode, u.login as login
FROM %sbin5_points as p, %sbin5_games as g, %sbin5_matches as m, %susers as u
WHERE p.ucode = u.code AND p.gcode = g.code AND g.mcode = m.code AND
- g.tstamp > to_timestamp(%d)
+ g.tstamp > to_timestamp(%d) AND g.tstamp <= to_timestamp(%d)
GROUP BY u.code, u.login
ORDER BY (float4(sum(p.pts)) * 100.0 ) / float4(count(p.pts)) DESC,
count(p.pts) DESC",
- $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $curtime - $limi[$dtime], $ming[$dtime]);
+ $G_dbpfx, $G_dbpfx, $G_dbpfx, $G_dbpfx, $curtime - $limi[$dtime], $curtime);
// log_crit("statadm: INFO: [$pla_sql]");
- if (($pla_pg = pg_query($bdb->dbconn->db(), $pla_sql)) == FALSE || pg_numrows($pla_pg) == 0) {
+ if (($pla_pg = pg_query($bdb->dbconn->db(), $pla_sql)) == FALSE) {
// no point found, abort
log_crit("statadm: main placement select failed [$pla_sql]");
break;
$fun_name = "main_${G_dbasetype}";
- $curtime = time();
+ $ctime = time();
+
+ $curtime = ((int)($ctime / (24 * 3600))) * 24 * 3600 - (((int)substr(date("O", $ctime), 0, -2)) * 3600);
if ($ret = $fun_name($curtime))
echo "Success.<br>\n";
else
if (($proxy_step = step_get($sess)) != FALSE) {
// log_rd2("Postget".$proxy_step."zizi");
- if ($cur_step == $proxy_step) {
+ if ($cur_step == $proxy_step['s']) {
log_lock("P");
return (FALSE);
}
'en' => 'close' ),
'commerr' => array( 'it' => '<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>',
'en' => '<b>An error was occurred during the saving, try again or contact the administrator.</b>'),
+ 'coerrdb' => array( 'it' => '<b>Il database è temporaneamente irraggiungibile, riprova più tardi o contatta l\'amministratore.</b>',
+ 'en' => '<b>The database is temporarly unavailable, retry to later or conctact the administrator.</b>'),
'warrmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
'en' => 'To authenticate somebody you have to be authenticated in your turn'),
'mesgrepl' => array( 'it' => '<br><br>Il messaggio è stato inoltrato all\'amministratore.',
log_mop(0, 'index_wr.php: COMM: '.xcapemesg($mesg));
log_wr('COMM: '.xcapemesg($mesg));
+$curtime = time();
+$dt = date("H:i ", $curtime);
+
$sem = Room::lock_data();
if (($room = &Room::load_data()) == FALSE) {
echo "Load data error";
log_main("chal lock data success");
if (($chals = &Challenges::load_data()) != FALSE) {
- $curtime = time();
$token = uniqid("");
// echo '2|'.$argz[1].'|'.$token.'|'.$_SERVER['REMOTE_ADDR'].'|'.$curtime.'|';
echo show_notify(str_replace("\n", " ", $G_room_roadmap[$G_lang]), 0, $mlang_indwr['btn_close'][$G_lang], 400, 200);
}
else if ($argz[0] == 'placing') {
- GLOBAL $G_false;
-
require_once("briskin5/Obj/briskin5.phh");
require_once("briskin5/Obj/placing.phh");
- echo show_notify(str_replace("\n", " ", placings_show($G_false)), 0, $mlang_indwr['btn_close'][$G_lang], 800, 600);
+ echo show_notify(str_replace("\n", " ", placings_show(FALSE)), 0, $mlang_indwr['btn_close'][$G_lang], 800, 600);
}
else if ($argz[0] == 'whysupport') {
echo show_notify(str_replace("\n", " ", $G_room_whysupport[$G_lang]), 0, $mlang_indwr['btn_close'][$G_lng], 400, 200);
else if ($argz[0] == 'warranty') {
GLOBAL $cli_name, $cli_email;
- $curtime = time();
$mesg_to_user = "";
log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
if ($mesg_to_user != "") {
$user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
- $dt = date("H:i ", $curtime);
$user->comm[$user->step % COMM_N] .= $mesg_to_user;
$user->step_inc();
}
}
else if ($argz[0] == 'mesgtoadm') {
- GLOBAL $cli_subj, $cli_mesg;
-
- $curtime = time();
- $mesg_to_user = "";
-
- log_wr("INFO:SKIP:argz == mesgtoadm name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
- if ($user->flags & USER_FLAG_AUTH) {
- if (($wa_lock = Warrant::lock_data()) != FALSE) {
- $bdb = new BriskDB();
- $bdb->users_load();
-
- if (($ema = $bdb->getmail($user->name)) != FALSE) {
- // mail("nastasi",
- mail("brisk@alternativeoutput.it", urldecode($cli_subj), urldecode($cli_mesg), sprintf("From: %s <%s>", $user->name, $ema));
- }
-
- if (($fp = @fopen(LEGAL_PATH."/messages.txt", 'a')) != FALSE) {
- /* Unix time | session | nickname | IP | where was | mesg */
- fwrite($fp, sprintf("%ld|%s|%s|%s\n", $curtime, $user->name,
- xcapelt(urldecode($cli_subj)), xcapelt(urldecode($cli_mesg))));
- fclose($fp);
- }
- Warrant::unlock_data($wa_lock);
- $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
- /* MLANG: "" */
- $user->comm[$user->step % COMM_N] .= show_notify($mlang_indwr['mesgrepl'][$G_lang], 0, $mlang_indwr['btn_close'][$G_lang], 400, 110);
- $user->step_inc();
- echo "1";
+ GLOBAL $cli_subj, $cli_mesg;
+
+ $mesg_to_user = "";
+
+ log_wr("INFO:SKIP:argz == mesgtoadm name: [".$user->name."] AUTH: ".($user->flags & USER_FLAG_AUTH));
+ if ($user->flags & USER_FLAG_AUTH) {
+ if (($wa_lock = Warrant::lock_data()) != FALSE) {
+ if (($bdb = BriskDB::create()) != FALSE) {
+ $bdb->users_load();
+
+ if (($ema = $bdb->getmail($user->name)) != FALSE) {
+ // mail("nastasi",
+ mail("brisk@alternativeoutput.it", urldecode($cli_subj), urldecode($cli_mesg), sprintf("From: %s <%s>", $user->name, $ema));
+ }
+
+ if (($fp = @fopen(LEGAL_PATH."/messages.txt", 'a')) != FALSE) {
+ /* Unix time | session | nickname | IP | where was | mesg */
+ fwrite($fp, sprintf("%ld|%s|%s|%s\n", $curtime, $user->name,
+ xcapelt(urldecode($cli_subj)), xcapelt(urldecode($cli_mesg))));
+ fclose($fp);
+ }
+ Warrant::unlock_data($wa_lock);
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ /* MLANG: "" */
+ $user->comm[$user->step % COMM_N] .= show_notify($mlang_indwr['mesgrepl'][$G_lang], 0, $mlang_indwr['btn_close'][$G_lang], 400, 110);
+ $user->step_inc();
+ echo "1";
+ }
+ else {
+ /* MLANG: "<b>Il database è temporaneamente irraggiungibile, riprova più tardi o contatta l\'amministratore.</b>" */
+ $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['coerrdb'][$G_lang]);
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ }
+ }
+ else {
+ /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
+ $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['commerr'][$G_lang]);
+ }
+
}
else {
- /* MLANG: "<b>E\' occorso un errore durante il salvataggio, riprova o contatta l\'amministratore.</b>" */
- $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['commerr'][$G_lang]);
+ /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" */
+ $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['mesgmust'][$G_lang]);
}
- }
- else {
- /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>" */
- $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['mesgmust'][$G_lang]);
- }
-
- if ($mesg_to_user != "") {
- $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
-
- $dt = date("H:i ", $curtime);
- $user->comm[$user->step % COMM_N] .= $mesg_to_user;
- $user->step_inc();
- }
+ if ($mesg_to_user != "") {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+
+ $user->comm[$user->step % COMM_N] .= $mesg_to_user;
+ $user->step_inc();
+ }
}
GLOBAL $G_with_poll, $G_poll_name, $cli_choose, $cli_poll_name;
$poll_lock = FALSE;
- $curtime = time();
$mesg_to_user = "";
$fp = FALSE;
if ($mesg_to_user != "") {
$user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
- $dt = date("H:i ", $curtime);
$user->comm[$user->step % COMM_N] .= $mesg_to_user;
$user->step_inc();
}
$table_idx = $argz[1];
$table = &$room->table[$table_idx];
- $curtime = time();
-
if ($G_shutdown || $table->wakeup_time > $curtime ||
($table->auth_only && (($user->flags & USER_FLAG_AUTH) == 0)) ) {
$user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
- $dt = date("H:i ", $curtime);
/* MLANG: "<b>Il server sta per essere riavviato, non possono avere inizio nuove partite.</b>", "<b>Il tavolo a cui volevi sederti richiede autentifica.</b>", "<b>Il tavolo si è appena liberato, ci si potrà sedere tra %d secondi.</b>" */
if ($G_shutdown) {
$user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['shutmsg'][$G_lang]);
// START THE SPAWN HERE!!!!
//
- $curtime = time();
-
// Create new spawned table
$bri_sem = Briskin5::lock_data($table_idx);
$table_token = uniqid("");