From: Matteo Nastasi Date: Thu, 12 Jan 2017 06:23:23 +0000 (+0000) Subject: Merge remote-tracking branch 'origin/master' into nginx X-Git-Tag: v5.6.0~34 X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=commitdiff_plain;h=302c97f7ac81dfcc6fc8d8d44359f4f432e4618a;hp=-c;p=brisk.git Merge remote-tracking branch 'origin/master' into nginx Conflicts: web/briskin5/index_wr.php web/index_wr.php --- 302c97f7ac81dfcc6fc8d8d44359f4f432e4618a diff --combined INSTALL.sh index a4b076c,36e2f70..219c73e --- a/INSTALL.sh +++ b/INSTALL.sh @@@ -9,7 -9,8 +9,8 @@@ apache_conf="/etc/apache2/sites-availab card_hand=3 players_n=3 tables_n=44 - tables_auth_n=12 + tables_appr_n=12 + tables_auth_n=8 tables_cert_n=4 brisk_auth_conf="brisk_spu_auth.conf.pho" brisk_debug="0x0400" @@@ -31,7 -32,7 +32,7 @@@ function usage () echo "$1 -h" echo "$1 chk - run lintian on all ph* files." echo "$1 pkg - build brisk packages." - echo "$1 [-W] [-n 3|5] [-c 2|8] [-t <(n>=4)>] [-T ] [-G ] [-A ] [-a ] [-f ] [-p ] [-U ] [-u ] [-d ] [-w ] [-k ] [-l ] [-y ] [-P ] [-x]" + echo "$1 [-W] [-n 3|5] [-c 2|8] [-t <(n>=4)>] [-T ] [-r ] [-G ] [-A ] [-a ] [-f ] [-p ] [-U ] [-u ] [-d ] [-w ] [-k ] [-l ] [-y ] [-P ] [-x]" echo " -h this help" echo " -f use this config file" echo " -p save preferences in the file" @@@ -40,6 -41,7 +41,7 @@@ echo " -c number cards in hand - def. $card_hand" echo " -n number of players - def. $players_n" echo " -t number of tables - def. $tables_n" + echo " -r number of appr-only tables - def. $tables_appr_n" echo " -T number of auth-only tables - def. $tables_auth_n" echo " -G number of cert-only tables - def. $tables_cert_n" echo " -a authorization file name - def. \"$brisk_auth_conf\"" @@@ -170,6 -172,7 +172,7 @@@ while [ $# -gt 0 ]; d -c*) card_hand="$(get_param "-c" "$1" "$2")"; sh=$?;; -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;; -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;; + -r*) tables_appr_n="$(get_param "-r" "$1" "$2")"; sh=$?;; -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;; -G*) tables_cert_n="$(get_param "-G" "$1" "$2")"; sh=$?;; -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;; @@@ -207,6 -210,7 +210,7 @@@ echo " apache_conf:\"$apache_conf\" echo " card_hand: $card_hand" echo " players_n: $players_n" echo " tables_n: $tables_n" + echo " tables_appr_n: $tables_appr_n" echo " tables_auth_n: $tables_auth_n" echo " tables_cert_n: $tables_cert_n" echo " brisk_auth_conf: \"$brisk_auth_conf\"" @@@ -231,6 -235,7 +235,7 @@@ if [ ! -z "$outconf" ]; the echo "card_hand=$card_hand" echo "players_n=$players_n" echo "tables_n=$tables_n" + echo "tables_appr_n=$tables_appr_n" echo "tables_auth_n=$tables_auth_n" echo "tables_cert_n=$tables_cert_n" echo "brisk_auth_conf=\"$brisk_auth_conf\"" @@@ -359,8 -364,6 +364,8 @@@ if [ "$web_only" = "FALSE" ]; the done chmod -R 777 ${proxy_path}/bin5 + mkdir -p "${legal_path}" + chmod 777 "${legal_path}" fi install -d ${web_path}__ for i in $(find web -type d | grep '/' | sed 's/^....//g'); do @@@ -370,10 -373,6 +375,10 @@@ don for i in $(find web -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^....//g'); do install -m 644 "web/$i" "${web_path}__/$i" done + +# hardlink for nginx managed websocket files. +ln "${web_path}__/xynt_test01.php" "${web_path}__/xynt_test01_wss.php" + if [ "$test_add" = "TRUE" ]; then for i in $(find webtest -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^........//g'); do install -m 644 "webtest/$i" "${web_path}__/$i" @@@ -411,6 -410,7 +416,7 @@@ s@define *( *'SITE_PREFIX_LEN',[^)]*)@d sed -i "s@define *( *'USOCK_PATH',[^)]*)@define('USOCK_PATH', \"$usock_path\")@g" ${web_path}__/spush/brisk-spush.phh sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g; + s@define *( *'TABLES_APPR_N',[^)]*)@define('TABLES_APPR_N', $tables_appr_n)@g; s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g; s@define *( *'TABLES_CERT_N',[^)]*)@define('TABLES_CERT_N', $tables_cert_n)@g; s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g; diff --combined web/Obj/brisk.phh index 45e5fd1,f971277..0c33591 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@@ -28,6 -28,7 +28,7 @@@ define('FTOK_PATH', "/var/lib/brisk") define('LEGAL_PATH', "/tmp/legal_brisk"); define('PROXY_PATH', "/var/lib/brisk_proxy"); define('TABLES_N', 36); + define('TABLES_APPR_N', 12); define('TABLES_AUTH_N', 8); define('TABLES_CERT_N', 4); define('PLAYERS_N', 3); @@@ -152,13 -153,14 +153,14 @@@ $mlang_brisk = array( 'btn_backstand'= $G_lng = langtolng($G_lang); $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 ); - $G_brisk_version = "5.1.3"; + $G_brisk_version = "5.2.1"; /* MLANG: ALL THE INFO STRINGS IN brisk.phh */ - $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': comando /info e doppio click sugli utenti registrati, nuovi utenti apprendisti, info su numero di mani e di partite.', + $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': puoi creare la tua rete di amicizie con /info, vedere cosa pensano i tuoi amici degli altri utenti e ci sono i nuovi tavoli riservati per registrati e apprendisti, corretti alcuni errori.', 'Se vuoi iscriverti alla Mailing List, cliccala!' ), - 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: ENcomando /info e doppio click sugli utenti registrati, nuovi utenti apprendisti.', - 'If you want to subscribe our Mailing List, click it!' ) ); + 'en' => array ( 'EN Brisk (Ver. '.$G_brisk_version.'), NOVITA\': puoi creare la tua rete di amicizie con /info,', + 'vedere cosa pensano i tuoi amici degli altri utenti e tavoli riservati per registrati e apprendisti.', + 'Se vuoi iscriverti alla Mailing List, cliccala!' ) ); $G_room_help = array( 'it' => '
@@@ -634,8 -636,9 +636,9 @@@ class Vect } define('TABLE_AUTH_TY_PUBL', 0); - define('TABLE_AUTH_TY_AUTH', 1); - define('TABLE_AUTH_TY_CERT', 2); + define('TABLE_AUTH_TY_APPR', 1); + define('TABLE_AUTH_TY_AUTH', 2); + define('TABLE_AUTH_TY_CERT', 3); class Table { @@@ -671,6 -674,8 +674,8 @@@ $thiz->auth_type = TABLE_AUTH_TY_CERT; else if ($idx < TABLES_AUTH_N) $thiz->auth_type = TABLE_AUTH_TY_AUTH; + else if ($idx < TABLES_APPR_N) + $thiz->auth_type = TABLE_AUTH_TY_APPR; else $thiz->auth_type = TABLE_AUTH_TY_PUBL; @@@ -825,6 -830,12 +830,12 @@@ else $act = 'reserved'; break; + case TABLE_AUTH_TY_APPR: + if ($user->is_auth()) + $act = "sitappr"; + else + $act = 'reserved'; + break; default: $act = 'sit'; break; @@@ -1643,7 -1654,13 +1654,13 @@@ class Bris } } - function info_show($user, $user_login, $dt) + /* + function info_show($user, $target, $dt) + + if success return assoc. array with "ret" => 0 and other fields + else return an assoc. array with "ret: != 0 and "mesg" with an error description + */ + function info_show($user, $target, $dt) { GLOBAL $G_lang, $mlang_brisk, $G_base; @@@ -1652,7 -1669,7 +1669,7 @@@ $ret = 0; do { - if ($user_login == "") { + if ($target == "") { $ret = 1; break; } @@@ -1660,13 -1677,13 +1677,13 @@@ $ret = 2; break; } - if (($user_item = $bdb->getitem_bylogin($user_login, $user_code)) == FALSE) { + if ($target == $user->name) { $ret = 3; + $mesg = sprintf($mlang_brisk['inf_self'][$G_lang]); break; } - if ($user_login == $user->name) { + if (($user_item = $bdb->getitem_bylogin($target, $user_code)) == FALSE) { $ret = 4; - $mesg = sprintf($mlang_brisk['inf_self'][$G_lang]); break; } if (($guar_item = $bdb->getitem_bycode($user_item->guar_code_get())) != FALSE) { @@@ -1677,11 -1694,24 +1694,24 @@@ } $user_tos_vers = $user_item->tos_vers_get(); + $partyskill = $bdb->usersnet_partyskill($user->code, $user_item->code); + + $widefriend = $bdb->usersnet_widefriend($user->code, $user_item->code); + $widefriend['skill'] = $bdb->usersnet_wideskill($user->code, $user_item->code); + $narrowfriend = $bdb->usersnet_narrowfriend($user->code, $user_item->code); + $narrowfriend['skill'] = $bdb->usersnet_narrowskill($user->code, $user_item->code); + + if (($usersnet_item = $bdb->usersnet_bycode($user->code, $user_item->code, + $widefriend, $narrowfriend)) == FALSE) { + $usersnet_item = $bdb->usersnet_default($user->code, $user_item->code, + $widefriend, $narrowfriend); + } + if (versions_cmp($user_tos_vers, "1.2") < 0) { - $mesg = sprintf($mlang_brisk['tos_old'][$G_lang], xcape($user_login)); + $mesg = sprintf($mlang_brisk['tos_old'][$G_lang], xcape($target)); } else if ($guar_login == "") { - $mesg = sprintf($mlang_brisk['inf_nfd'][$G_lang], xcape($user_login)); + $mesg = sprintf($mlang_brisk['inf_nfd'][$G_lang], xcape($target)); } } while (0); @@@ -1695,7 -1725,7 +1725,7 @@@ else { $jret = json_encode(array("ret" => 0, "mesg" => "", - "login" => $user_login, + "login" => $target, // FIXME: state internationalization "state" => ($user_item->type & USER_FLAG_TY_APPR ? "Apprendista" : @@@ -1704,14 -1734,49 +1734,49 @@@ "Normale" : "Stato sconosciuto"))), "guar" => ($user_item->type & USER_FLAG_TY_APPR ? "" : $guar_login), + "party" => $partyskill, "match" => (versions_cmp($user_tos_vers, "1.4") < 0 ? "non autorizzato" : $user_item->match_cnt) , "game" => (versions_cmp($user_tos_vers, "1.4") < 0 ? "non autorizzato" : $user_item->game_cnt), - "friend" => "unknown")); + "friend" => usersnet_friend_getlabel($usersnet_item->friend), + "skill" => $usersnet_item->skill, + "trust" => $usersnet_item->trust, + "widefriend" => $usersnet_item->widefriend, + "narrowfriend" => $usersnet_item->narrowfriend + )); } return $jret; } + function info_save($user, $json_s) + { + GLOBAL $G_lang, $mlang_brisk, $G_base; + + $mesg = ""; + $user_code = -1; + $ret = 0; + $subret = 0; + + do { + if (($json = json_decode($json_s)) == FALSE) { + $ret = 1; + break; + } + + if (($bdb = BriskDB::create()) == FALSE) { + $ret = 2; + break; + } + + if (($subret = $bdb->usersnet_save($user->code, $json)) != 0) { + $ret = 4000 + $subret; + break; + } + } while(0); + + return ($ret); + } + function room_outstandup($user) { $this->room_sitdown($user, -1); @@@ -1858,7 -1923,7 +1923,7 @@@ return ($this->kickuser($user_out, $out_reas)); } - function chatt_send($user, $mesg) + function chatt_send($user, $mesg, $mlang_indwr = NULL) { GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang; $only_you = FALSE; @@@ -2059,7 -2124,7 +2124,7 @@@ if (($bdb = BriskDB::create()) != FALSE) { $bdb->users_load(); /* MLANG: "Il nickname \'%s\' è già registrato, se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghostN." */ - if ($bdb->login_exists($name_new)) { + if ($bdb->login_exists(strtolower($name_new))) { $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new)); $to_user .= nickserv_msg($dt, $prestr); } @@@ -2072,10 -2137,20 +2137,20 @@@ } while (0); } // nick chat command else if (strncmp($msg, "/info ", 6) == 0) { - $guar_user = substr($msg, 6); + do { + if (! $user->is_auth()) { + if ($mlang_indwr) { + $to_user = nickserv_msg($dt, $mlang_indwr['info_auth'][$G_lang]); + } + else { + $to_user = nickserv_msg($dt, "error"); + } + break; + } + $info_user = substr($msg, 6); - error_log("here [" . $guar_user."]"); - echo $this->info_show($user, $guar_user, $dt); + echo $this->info_show($user, urldecode($info_user), $dt); + } while(0); } else if (strncmp($msg, "/st ", 4) == 0) { log_main("chatt_send BEGIN"); @@@ -2370,7 -2445,7 +2445,7 @@@ } } else { - $login_exists = $bdb->login_exists($name_new); + $login_exists = $bdb->login_exists(strtolower($name_new)); } } else { @@@ -2728,10 -2803,9 +2803,10 @@@ break; case "index_rd.php": + case "index_rd_wss.php": if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE) $transp = "iframe"; - if ($transp == 'websocket') + if ($transp == 'websocket' || $transp == 'websocketsec') $enc = 'plain'; do { @@@ -2797,7 -2871,7 +2872,7 @@@ $subs = "briskin5/"; $subs_l = strlen($subs); if (!strncmp($path, $subs, $subs_l)) { - $ret = Bin5::request_mgr(&$s_a_p, $header, &$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; @@@ -3466,5 -3540,31 +3541,31 @@@ function carousel_top( } } + function login_consistency($name) + { + $old_c = ''; + if (($len = mb_strlen($name)) > 12) { + return FALSE; + } + for ($i = 0 ; $i < mb_strlen($name) ; $i++) { + $c = mb_substr($name, $i, 1); + if (mb_ereg_match ("[a-zA-Z0-9]", $c)) { + if ($old_c != $c) { + $old_c = $c; + $old_ct = 1; + } + else { + $old_ct++; + if ($old_ct > 2) { + return (FALSE); + } + } + } + else { + return (FALSE); + } + } + return (TRUE); + } ?> diff --combined web/Obj/dbase_pgsql.phh index f8b7538,1baefa3..cdcec51 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@@ -25,7 -25,7 +25,7 @@@ require_once("${G_base}Obj/dbase_base.phh"); $escsql_from = array( "\\", "'" ); - $escsql_to = array( "\\\\", "\\'" ); + $escsql_to = array( "\\\\", "''" ); function escsql($s) { @@@ -62,8 -62,9 +62,9 @@@ class DBCon static function destroy() { if (DBConn::$dbcnnx != FALSE) { + $ret = pg_close(DBConn::$dbcnnx); DBConn::$dbcnnx = FALSE; - return (pg_close(DBConn::$dbcnnx)); + return ($ret); } return TRUE; } @@@ -112,11 -113,17 +113,17 @@@ class BriskD function query($sql) { - if (($res = pg_query($this->dbconn->db(), $sql)) == FALSE) { + if (!$this->dbconn) + if (($this->dbconn = DBConn::recover()) == FALSE) + return FALSE; + + if (($res = @pg_query($this->dbconn->db(), $sql)) == FALSE) { + error_log('pg_result_status: ' . pg_result_status($res)); + error_log('pg_connection_status: ' . pg_connection_status($this->dbconn->db())); // try to recover the connection if (($this->dbconn = DBConn::recover()) == FALSE) return FALSE; - return (pg_query($this->dbconn->db(), $sql)); + return (@pg_query($this->dbconn->db(), $sql)); } return ($res); @@@ -138,7 -145,7 +145,7 @@@ /* check the existence of the nick in the BriskDB */ log_main("login_exists: ".$login); - $user_sql = sprintf("SELECT * FROM %susers WHERE login = lower('%s')", + $user_sql = sprintf("SELECT * FROM %susers WHERE login = '%s'", $G_dbpfx, escsql($login)); if (($user_pg = $this->query($user_sql)) != FALSE) if (pg_numrows($user_pg) == 1) @@@ -203,10 -210,6 +210,6 @@@ return (FALSE); } - if (($sere_pg = $this->query($sere_sql)) == FALSE) { - return (FALSE); - } - $sere_sql = sprintf("SELECT * FROM %sselfreg_chk WHERE (ip & %d) = %d;", $G_dbpfx, int2four($G_selfreg_mask), int2four($laddr & $G_selfreg_mask)); if (($sere_pg = $this->query($sere_sql)) == FALSE) { @@@ -352,11 -355,9 +355,9 @@@ $user_sql = sprintf("UPDATE %susers SET (type, supp_comp) = (%d, '%s') WHERE code = %d;", $G_dbpfx, $flags, escsql($supp_comp), $code); - fprintf(STDERR, "REQUEST [%s]\n", $user_sql); if ( ! (($user_pg = $this->query($user_sql)) != FALSE && pg_affected_rows($user_pg) == 1) ) { return FALSE; } - fprintf(STDERR, "REQUEST GOOD [%s]\n", $user_sql); return TRUE; } @@@ -367,11 -368,9 +368,9 @@@ $user_sql = sprintf("UPDATE %susers SET (type, disa_reas) = (%d, %d) WHERE code = %d;", $G_dbpfx, $flags, $disa_reas, $code); - fprintf(STDERR, "REQUEST [%s]\n", $user_sql); if ( ! (($user_pg = $this->query($user_sql)) != FALSE && pg_affected_rows($user_pg) == 1) ) { return FALSE; } - fprintf(STDERR, "REQUEST GOOD [%s]\n", $user_sql); return TRUE; } @@@ -382,11 -381,9 +381,9 @@@ $user_sql = sprintf("UPDATE %susers SET (tos_vers) = ('%s') WHERE code = %d;", $G_dbpfx, escsql($tos_vers), $code); - fprintf(STDERR, "REQUEST [%s]\n", $user_sql); if ( ! (($user_pg = $this->query($user_sql)) != FALSE && pg_affected_rows($user_pg) == 1) ) { return FALSE; } - fprintf(STDERR, "REQUEST GOOD [%s]\n", $user_sql); return TRUE; } @@@ -433,7 -430,7 +430,7 @@@ } if ($chals->ismod()) { - Challenges::save_data(&$chals); + Challenges::save_data($chals); } Challenges::unlock_data($a_sem); @@@ -855,7 -852,222 +852,222 @@@ INSERT INTO %smails (code, ucode, type return (TRUE); } + function friendship_default() + { + return (array(usersnet_friend_getlabel(1) => "0", + usersnet_friend_getlabel(2) => "0", + usersnet_friend_getlabel(3) => "0", + usersnet_friend_getlabel(4) => "0", + usersnet_friend_getlabel(5) => "0")); + } + + function usersnet_widefriend($owner, $target) + { + GLOBAL $G_dbpfx; + + $widefriend = $this->friendship_default(); + + $wfri_sql = sprintf("SELECT * FROM %susersnet_widefriend WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($wfri_pg = $this->query($wfri_sql)) == FALSE) { + return ($widefriend); + } + + for ($i = 0 ; $i < pg_numrows($wfri_pg) ; $i++) { + $wfri_obj = pg_fetch_object($wfri_pg, $i); + $widefriend[usersnet_friend_getlabel(intval($wfri_obj->friend))] = $wfri_obj->count; + } + + return ($widefriend); + } + + function usersnet_wideskill($owner, $target) + { + GLOBAL $G_dbpfx; + + $wideskill = "//"; + $wskl_sql = sprintf("SELECT * FROM %susersnet_wideskill WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($wskl_pg = $this->query($wskl_sql)) == FALSE) { + return ($wideskill); + } + + if (pg_numrows($wskl_pg) > 0) { + $wskl_obj = pg_fetch_object($wskl_pg, 0); + // TODO: UNCOMMENT IF THE NETWORK WORKS VERY WELL + // if ($wskl_obj->count >= 3) + $wideskill = sprintf("%3.2f", $wskl_obj->skill); + } + return ($wideskill); + } + + function usersnet_narrowfriend($owner, $target) + { + GLOBAL $G_dbpfx; + + $narrowfriend = $this->friendship_default(); + + $nfri_sql = sprintf("SELECT * FROM %susersnet_narrowfriend WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($nfri_pg = $this->query($nfri_sql)) == FALSE) { + return $narrowfriend; + } + + for ($i = 0 ; $i < pg_numrows($nfri_pg) ; $i++) { + $nfri_obj = pg_fetch_object($nfri_pg, $i); + $narrowfriend[usersnet_friend_getlabel(intval($nfri_obj->friend))] = $nfri_obj->count; + } + return ($narrowfriend); + } + + function usersnet_narrowskill($owner, $target) + { + GLOBAL $G_dbpfx; + + $narrowskill = "//"; + + $nskl_sql = sprintf("SELECT * FROM %susersnet_narrowskill WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($nskl_pg = $this->query($nskl_sql)) == FALSE) { + return ($narrowskill); + } + + if (pg_numrows($nskl_pg) > 0) { + $nskl_obj = pg_fetch_object($nskl_pg, 0); + // TODO: UNCOMMENT IF THE NETWORK WORKS VERY WELL + // if ($nskl_obj->count >= 3) + $narrowskill = sprintf("%3.2f", $nskl_obj->skill); + } + return ($narrowskill); + } + + function usersnet_partyskill($owner, $target) + { + GLOBAL $G_dbpfx; + + $partyskill = "non disponibile"; + + $pskl_sql = sprintf("SELECT * FROM %susersnet_party WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($pskl_pg = $this->query($pskl_sql)) == FALSE) { + return ($partyskill); + } + + if (pg_numrows($pskl_pg) > 0) { + $pskl_obj = pg_fetch_object($pskl_pg, 0); + // TODO: UNCOMMENT IF THE NETWORK WORKS VERY WELL + // if ($wskl_obj->count >= 3) + $partyskill = sprintf("%3.2f", $pskl_obj->skill); + } + return ($partyskill); + } + + function usersnet_bycode($owner, $target, $widefriend, $narrowfriend) + { + GLOBAL $G_dbpfx; + $ret = FALSE; + + $net_sql = sprintf("SELECT * FROM %susersnet WHERE owner = %d AND target = %d;", + $G_dbpfx, $owner, $target); + if (($net_pg = $this->query($net_sql)) == FALSE) + return FALSE; + + if (pg_numrows($net_pg) != 1) + return FALSE; + + $net_obj = pg_fetch_object($net_pg, 0); + + return (UsersNetItem::UsersNetItemFromRecord($net_obj, $widefriend, $narrowfriend)); + } + + function usersnet_default($owner, $target, $widefriend, $narrowfriend) + { + return (UsersNetItem::UsersNetItemDefaults($owner, $target, $widefriend, $narrowfriend)); + } + + function usersnet_save($owner_id, $json) + { + GLOBAL $G_dbpfx; + $ret = 99999; + $trans = FALSE; + + do { + $friend = usersnet_friend_getid($json->friend); + + $json->skill = intval($json->skill); + $json->trust = intval($json->trust); + + if ($json->skill < 1 || $json->skill > 5 || + $json->trust < 1 || $json->trust > 5 || + $friend == FALSE) { + $ret = 1; + break; + } + $this->transaction('BEGIN'); + $trans = TRUE; + + if ($friend == USERSNET_FRIEND_UNKNOWN) { + // try to update + $net_sql = sprintf(" + DELETE FROM %susersnet + USING %susers as us + WHERE owner = %d AND us.login = '%s' AND target = us.code;", + $G_dbpfx, $G_dbpfx, + $owner_id, escsql(strtolower($json->login))); + + if (($net_pg = $this->query($net_sql)) == FALSE) { + $ret = 5; + break; + } + } + else { // if ($friend == USERSNET_FRIEND_UNKNOWN + // try to update + $net_sql = sprintf(" + UPDATE %susersnet SET (friend, skill, trust, mtime) = + (%d, %d, %d, now()) + FROM %susers as us + WHERE owner = %d AND us.login = '%s' AND target = us.code RETURNING *;", + $G_dbpfx, + $friend, $json->skill, $json->trust, + $G_dbpfx, + $owner_id, escsql(strtolower($json->login))); + if (($net_pg = $this->query($net_sql)) == FALSE || pg_numrows($net_pg) == 0) { + $net_sql = sprintf(" + INSERT INTO %susersnet SELECT %d AS owner, us.code as target, + %d as friend, %d as skill, %d as trust + FROM %susers as us WHERE us.login = '%s' RETURNING *;", + $G_dbpfx, $owner_id, + $friend, $json->skill, $json->trust, + $G_dbpfx, escsql(strtolower($json->login))); + if (($net_pg = $this->query($net_sql)) == FALSE) { + log_wr('insert query failed'); + $ret = 2; + break; + } + if (pg_numrows($net_pg) != 1) { + log_wr(sprintf('insert numrow failed [%s] [%d]', $net_sql, pg_numrows($net_pg))); + $ret = 3; + break; + } + } + else { + if (pg_numrows($net_pg) != 1) { + log_wr('update numrow failed'); + $ret = 4; + break; + } + } + } + $this->transaction('COMMIT'); + return (0); + } while (0); + + if ($trans) + $this->transaction('ROLLBACK'); + + return ($ret); + } } // End class BriskDB class LoginDBOld diff --combined web/Obj/sac-a-push.phh index ca9c0cb,a3fe932..46227fc --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@@ -30,6 -30,22 +30,22 @@@ define('DIRECT_ST_WRITE', 2) declare(ticks = 1); + /* this list is created with bin/get_globals.sh */ + $_globals_list = array( + 'G_admin_mail', 'G_alarm_passwd', 'G_all_points', 'G_ban_list', 'G_base', + 'G_black_list', 'G_brisk_version', 'G_btrace_pref_sub', 'G_cloud_smasher', + 'G_crypt_key', 'G_dbasetype', 'G_dbauth', 'G_dbpfx', 'G_doc_path', + 'G_domain', 'G_donors_all', 'G_donors_cur', 'G_is_local', 'G_lang', 'G_lng', + 'G_mail_seed', 'G_notguar_code', 'G_PG_cons', 'G_PG_cons_n', 'G_PG_vow', + 'G_PG_vow_n', 'G_poll_entries', 'G_poll_name', 'G_poll_title', + 'G_provider_proxy', 'G_proxy_white_list', 'G_room_about', 'G_room_help', + 'G_room_passwdhowto', 'G_room_roadmap', + 'G_selfreg_mask', 'G_selfreg_tout', 'G_shutdown', 'G_sidebanner', + 'G_sidebanner_idx', 'G_splash_content', 'G_splash_contents', + 'G_splash_cont_idx', 'G_splash_h', 'G_splash_idx', 'G_splash_interval', + 'G_splash_timeout', 'G_splash_w', 'G_topbanner', 'G_tos_dthard', + 'G_tos_dtsoft', 'G_tos_fname', 'G_tos_idx', 'G_tos_vers', 'G_webbase'); + function global_dump() { GLOBAL $G_alarm_passwd, $G_ban_list, $G_black_list, $G_btrace_pref_sub, $G_dbauth; @@@ -40,7 -56,7 +56,7 @@@ GLOBAL $G_splash_h, $G_splash_idx, $G_splash_interval, $G_splash_timeout; GLOBAL $G_splash_w, $G_topbanner, $G_with_donors, $G_with_poll; GLOBAL $G_with_splash, $G_sidebanner, $G_sidebanner_idx; - GLOBAL $G_with_topbanner, $G_selfreg_tout; + GLOBAL $G_with_topbanner, $G_selfreg_tout, $G_selfreg_mask; fprintf(STDERR, "G_alarm_passwd = [%s]\n", print_r($G_alarm_passwd, TRUE)); fprintf(STDERR, "G_ban_list = [%s]\n", print_r($G_ban_list, TRUE)); @@@ -555,7 -571,7 +571,7 @@@ class Sac_a_push function pendpage_try_addcont(&$new_socket, $tout, $method, $header, $get, $post, $cookie, $path, $addr, $rest, $cont) { - $pendpage = PendingPage::pendingpage_continue(&$new_socket, $this->curtime, $tout, $method, + $pendpage = PendingPage::pendingpage_continue( $new_socket, $this->curtime, $tout, $method, $header, $get, $post, $cookie, $path, $addr, $rest, $cont); @@@ -629,6 -645,18 +645,18 @@@ $this->app->users_cleanup(); } + function check_globals() + { + GLOBAL $_globals_list; + foreach ($_globals_list as $g) { + if (!array_search($g, $GLOBALS) || !isset($GLOBALS[$g])) { + error_log(sprintf("Global [%s] not declared", $g)); + return FALSE; + } + } + return TRUE; + } + function run() { GLOBAL $DOCUMENT_ROOT, $HTTP_HOST; @@@ -645,6 -673,11 +673,11 @@@ GLOBAL $G_with_topbanner; GLOBAL $G_tos_vers, $G_tos_fname, $G_tos_dtsoft, $G_tos_dthard, $G_tos_idx, $G_doc_path; + if (!$this->check_globals()) { + fprintf(STDERR, "Take a look to the phplog file, GLOBALS missing!\n"); + sleep(10); + } + if ($this->main_loop) { return (FALSE); } @@@ -816,6 -849,10 +849,10 @@@ $this->reload(FALSE, $G_provider_proxy); $this->app->reload(FALSE, $G_ban_list, $G_black_list, $G_cloud_smasher); + if (!$this->check_globals()) { + fprintf(STDERR, "Take a look to the phplog file, GLOBALS missing!\n"); + sleep(10); + } global_dump(); } else if ($line == "shutdown" || $line == "sd") { @@@ -996,7 -1033,7 +1033,7 @@@ return cmd_return(401, 'malformed cmd'); } $idx = -1; - if (($user = $this->app->get_user($cmd['sess'], &$idx)) == FALSE) + if (($user = $this->app->get_user($cmd['sess'], $idx)) == FALSE) return cmd_return(402, 'user not found'); if (($user->flags & USER_FLAG_TY_ADMIN) == 0x00) diff --combined web/Obj/user.phh index ad42e7f,d8230b4..c972404 --- a/web/Obj/user.phh +++ b/web/Obj/user.phh @@@ -830,7 -830,7 +830,7 @@@ function stream_init($init_string, $enc $this->rd_data_set($curtime, $transp, $enc, $stat, $subst, $step, $from); - $ret = $this->rd_transp->init($enc, $header, &$header_out, $init_string, self::base_get(), $this->rd_scristp); + $ret = $this->rd_transp->init($enc, $header, $header_out, $init_string, self::base_get(), $this->rd_scristp); if ($ret === FALSE) { return FALSE; @@@ -923,5 -923,39 +923,39 @@@ function chunked_fini( } // end class User + define('USERSNET_FRIEND_BLACK', 1); + define('USERSNET_FRIEND_UNKNOWN', 2); + define('USERSNET_FRIEND_TEST', 3); + define('USERSNET_FRIEND_FRIEND', 4); + define('USERSNET_FRIEND_BFF', 5); + + if (!isset($__usersnet_friend_map)) { + $__usersnet_friend_map = array("black", "unknown", "test", "friend", "bff"); + } + + function usersnet_friend_getlabel($id) + { + GLOBAL $__usersnet_friend_map; + + $id_i = intval($id); + + if ($id_i < 1 || $id_i > count($__usersnet_friend_map)) { + return FALSE; + } + return ($__usersnet_friend_map[$id_i - 1]); + } + + /* return index + 1 of friend label */ + function usersnet_friend_getid($label_in) + { + GLOBAL $__usersnet_friend_map; + foreach ($__usersnet_friend_map as $id => $label) { + if ($label == $label_in) { + return ($id + 1); + } + } + + return FALSE; + } ?> diff --combined web/briskin5/Obj/briskin5.phh index 0b61781,f5db998..67b584c --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@@ -525,7 -525,7 +525,7 @@@ class Bin5_table extends Table $game_delta = 1; // $this->game_next(1); - $this->game_init(&$bri->user); + $this->game_init($bri->user); } else if ($action == BIN5_RULES_ABANDON) { // return TRUE if all correct if (!($user->handpt <= 2)) { @@@ -544,7 -544,7 +544,7 @@@ // Non si cambia mazzo se si abbandona la partita $game_delta = 0; // $this->game_next(0); - $this->game_init(&$bri->user); + $this->game_init($bri->user); } else if ($action == BIN5_RULES_FINISH) { // return TRUE if all correct $this->old_act = $action; @@@ -661,7 -661,7 +661,7 @@@ log_points($user->ip, $curtime, $user, "STAT:BRISKIN5:FINISH_GAME", $plist); } - $this->game_init(&$bri->user); + $this->game_init($bri->user); return (TRUE); } @@@ -763,7 -763,7 +763,7 @@@ $this->mazzo = $match_data['mazzo_next']; $this->mult = $match_data['mult_next']; $this->match_id = $match_id; - $this->game_init(&$bri->user); + $this->game_init($bri->user); /* reload of the page with the new layout */ for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) { @@@ -779,7 -779,7 +779,7 @@@ $user_cur->comm[$user_cur->step % COMM_N] = ""; $user_cur->step_inc(); - $user_cur->comm[$user_cur->step % COMM_N] = show_table(&$bri, &$user_cur, $user_cur->step+1, TRUE, FALSE); + $user_cur->comm[$user_cur->step % COMM_N] = show_table($bri, $user_cur, $user_cur->step+1, TRUE, FALSE); $user_cur->step_inc(); } return (TRUE); @@@ -1069,7 -1069,7 +1069,7 @@@ class Bin5_user extends User log_load("RESYNC"); /* NOTE: $this->room is associated with the current $bri object */ printf("xXx CLASS NAME [%s]\n", get_class($this->room)); - $ret = show_table(&$this->room, $this, $this->step, FALSE, FALSE); + $ret = show_table($this->room, $this, $this->step, FALSE, FALSE); } log_rd2("NEWSTAT: ".$this->stat); @@@ -1172,7 -1172,7 +1172,7 @@@ class Bin5 $user[$table->player[$i]]->table_token = $table_token; $this->user[$i] = Bin5_user::spawn($user[$table->player[$i]], $this, $table_idx, $i, $get, $post, $cookie); } - $this->table[0] = Bin5_table::spawn(&$table); + $this->table[0] = Bin5_table::spawn($table); log_main("TABLE_OLD_WIN - Bin5:".$this->table[0]->old_asta_win); @@@ -1265,7 -1265,7 +1265,7 @@@ $user_cur->the_end = TRUE; /* se gli altri utenti non erano d'accordo questo utente viene bannato */ - $remcalc = $this->table[0]->exitlock_calc(&$this->user, $user_cur->table_pos); + $remcalc = $this->table[0]->exitlock_calc($this->user, $user_cur->table_pos); if ($remcalc < 3) { require_once("${G_base}Obj/hardban.phh"); Hardbans::add(($user_cur->is_auth() ? $user_cur->name : FALSE), @@@ -1353,7 -1353,7 +1353,7 @@@ } - function chatt_send($user, $mesg) + function chatt_send($user, $mesg, $mlang_indwr = NULL) { GLOBAL $mlang_brisk, $G_lang; @@@ -1479,7 -1479,7 +1479,7 @@@ case "": case "index.php": ob_start(); - bin5_index_main($transp_type, $header_out, $addr, $get, $post, $cookie); + bin5_index_main($transp_type, $header, $header_out, $addr, $get, $post, $cookie); $content = ob_get_contents(); ob_end_clean(); @@@ -1507,10 -1507,9 +1507,10 @@@ break; case "index_rd.php": + case "index_rd_wss.php": if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE) $transp = "iframe"; - if ($transp == 'websocket') + if ($transp == 'websocket' || $transp == 'websocketsec') $enc = 'plain'; do { @@@ -1610,7 -1609,7 +1610,7 @@@ function show_table(&$bri, &$user, $sen $table_pos = $user->table_pos; $ret = "table_init();"; - $ret .= $table->exitlock_show(&$bri->user, $table_pos); + $ret .= $table->exitlock_show($bri->user, $table_pos); if (!$is_again) { /* GENERAL STATUS */ $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;', @@@ -1641,7 -1640,7 +1641,7 @@@ } /* NOTIFY FOR THE CARD MAKER */ if ($is_transition) { // && $user->subst == "asta" superfluo - $ret .= show_table_info(&$bri, &$table, $table_pos); + $ret .= show_table_info($bri, $table, $table_pos); $ret .= "setTimeout(preload_images, 500, g_preload_img_arr, g_imgct);"; } else { diff --combined web/commons.js index d1d2318,cefb6c0..29f6056 --- a/web/commons.js +++ b/web/commons.js @@@ -430,11 -430,6 +430,6 @@@ function act_roadmap( send_mesg("roadmap"); } - function act_whysupport() - { - send_mesg("whysupport"); - } - function act_lascio() { send_mesg("lascio"); @@@ -1038,7 -1033,7 +1033,7 @@@ function user_decorator(user, is_real for (i = 0 ; i < 4 ; i++) { if (flags & (1 << i)) { - cl += sp + "au" + i; + cl += sp + "au" + i + (is_real ? "" : "_off"); sp = " "; } } @@@ -1393,7 -1388,7 +1388,7 @@@ function url_complete(parent, url } // alert("host: ["+host+"] path: ["+path+"]"); - if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/') { + if (url.substring(0,6) == 'http:/' || url.substring(0,7) == 'https:/' || url.substring(0,4) == 'ws:/' || url.substring(0,5) == 'wss:/') { return (url); } else if (url.substring(0,1) == '/') { diff --combined web/index.php index c841325,73ebd17..155935a --- a/web/index.php +++ b/web/index.php @@@ -228,18 -228,34 +228,34 @@@ $mlang_room = array( 'userpassuse' => 'en' => 'Send a message to the administrator:'), 'mesgtoadm_sub'=> array('it' => 'soggetto:', 'en' => 'subject:'), - 'info_login' => array('it' => 'Utente:', - 'en' => 'User:'), - 'info_state' => array('it' => 'Stato:', - 'en' => 'State:'), - 'info_guar' => array('it' => 'Garante:', - 'en' => 'Guarantee:'), - 'info_match' => array('it' => 'Partite:', - 'en' => 'Matches:'), - 'info_game' => array('it' => 'Mani:', - 'en' => 'Hands:'), + 'info_login' => array('it' => 'Utente', + 'en' => 'User'), + 'info_status' => array('it' => 'Stato', + 'en' => 'Status'), + 'info_status_tit' => array('it' => 'Stato dell\' utente.', + 'en' => 'User status.'), + 'info_guar' => array('it' => 'Garante', + 'en' => 'Guarantee'), + 'info_match' => array('it' => 'Partite', + 'en' => 'Matches'), + 'info_match_tit' => array('it' => 'Partite giocate ai tavoli riservati.', + 'en' => 'Matches played at reserved tables.'), + 'info_party' => array('it' => 'Party', + 'en' => 'Party'), + 'info_party_tit' => array('it' => 'Bravura calcolata in base ad amici, agli amici fidati e agli amici degli amici fidati in base alla credibilità degli amici fidati.', + 'en' => 'Skill calculated with party rules.'), + 'info_game' => array('it' => 'Mani', + 'en' => 'Hands'), + 'info_game_tit' => array('it' => 'Mani giocate ai tavoli riservati.', + 'en' => 'Hands played at reserved tables.'), 'info_frie' => array('it' => 'Conoscenza:', 'en' => 'Friendship:'), + 'info_repfrie' => array('it' => 'Cosa ne pensano gli amici', + 'en' => 'Friends reputation'), + 'info_repbff' => array('it' => 'Cosa ne pensano gli amici fidati', + 'en' => 'Best friends reputation'), + 'info_skill' => array('it' => 'Bravura', + 'en' => 'Skill') ); require_once("briskin5/Obj/briskin5.phh"); @@@ -344,9 -360,6 +360,9 @@@ function index_main(&$brisk, $transp_ty GLOBAL $G_lang, $G_lng, $mlang_room; GLOBAL $BRISK_SHOWHTML, $BRISK_DEBUG, $_SERVER, $_COOKIE; + $transp_port = ((array_key_exists("X-Forwarded-Proto", $header) && + $header["X-Forwarded-Proto"] == "https") ? 443 : 80); + if (($sess = gpcs_var('sess', $get, $post, $cookie)) === FALSE) $sess = ""; if (($name = gpcs_var('name', $get, $post, $cookie)) === FALSE) @@@ -418,7 -431,7 +434,7 @@@ log_main("pre garbage_manager UNO"); $brisk->garbage_manager(TRUE); log_main("post garbage_manager"); - if (($user = &$brisk->get_user($sess, &$idx)) != FALSE) { + if (($user = $brisk->get_user($sess, $idx)) != FALSE) { if ($user->the_end == FALSE) { $brisk->sess_cur_set($user->sess); log_main("user stat: ".$user->stat); @@@ -451,7 -464,7 +467,7 @@@ /* try login */ if ($banned == FALSE && - ($user = $brisk->add_user(&$sess, &$idx, $name, $pass_private, + ($user = $brisk->add_user($sess, $idx, $name, $pass_private, $remote_addr, $header, $cookie)) != FALSE) { $brisk->sess_cur_set($user->sess); $ACTION = "room"; @@@ -636,7 -649,7 +652,7 @@@ google_color_text = "404040" google_color_url = "000000"; //--> -'; +'; $banner_top_right = carousel_top(); } else { @@@ -655,7 -668,7 +671,7 @@@ google_color_text = "404040" google_color_url = "000000"; //--> -'; +'; } } else { // !$G_is_local @@@ -669,7 -682,7 +685,7 @@@
'.$banner_top_left.'
'.(($G_with_topbanner || $G_with_donors) ? '
' : '').'
- + '.$mlang_room['headline'][$G_lang].'
'.( ($G_with_topbanner || $G_with_donors) ? sprintf('
%s
', ($G_with_topbanner ? $G_topbanner : @@@ -737,11 -750,6 +753,6 @@@ alt="'.$mlang_room['tit_cook'][$G_lang].'">'.$mlang_room['itm_cook'][$G_lang].'

- '.$mlang_room['itm_cla'][$G_lang].'
@@@ -764,7 -772,7 +775,7 @@@ Parma 11/09
+ title="1° Torneo-Meeting di Parma del 22/11/2009">Parma 11/09
'.$altout_support_big.' - + ' . ( /* NOTE: here facebook or fake facebook */ (!$G_is_local && $_cookie_law_3party == 'true') ? '
@@@ -1006,6 -1014,7 +1017,7 @@@ + @@@ -1026,6 -1035,7 +1038,7 @@@ var g_debug = 0 var g_lang = ""; var g_lng = ""; var g_tables_n = ; + var g_tables_appr_n = ; var g_tables_auth_n = ; var g_tables_cert_n = ; var g_prefs, g_prefs_new = null; @@@ -1174,6 -1184,7 +1187,7 @@@ cookie_law(null) + @@@ -1194,6 -1205,7 +1208,7 @@@ var g_lang = ""; var g_lng = ""; var g_tables_n = ; + var g_tables_appr_n = ; var g_tables_auth_n = ; var g_tables_cert_n = ; var g_prefs, g_prefs_new = null; @@@ -1237,7 -1249,7 +1252,7 @@@ sidebanners_init($G_sidebanner_idx); ?> sess = ""; -xstm = new xynt_streaming(window, "", 80, 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', function(com){eval(com);}); +xstm = new xynt_streaming(window, , 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', function(com){eval(com);}); xstm.hbit_set(heartbit); tra = new train($('room_tit')); window.onunload = onunload_cb; @@@ -1377,22 -1389,64 +1392,64 @@@ type="submit" class="button" onclick="t
-