From 8b9c2b3ec59baef7c9f64f9663347bc5b9cf69fe Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Wed, 16 Jul 2014 08:06:38 +0200 Subject: [PATCH] user is_auth() is_cert() methods added --- web/Obj/brisk.phh | 36 +++++++++++++++++------------------ web/Obj/user.phh | 15 ++++++++++++++- web/briskin5/Obj/briskin5.phh | 6 +++--- web/briskin5/index_wr.php | 4 ++-- web/index.php | 4 ++-- web/index_wr.php | 25 ++++++++++++------------ 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index b1e7e46..6ff2b8e 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -803,13 +803,13 @@ class Table { if ($sitted < PLAYERS_N) { switch ($this->auth_type) { case TABLE_AUTH_TY_CERT: - if ($user->flags & USER_FLAG_AUTH && $user->flags & USER_FLAG_TY_CERT) + if ($user->is_cert()) $act = "sitcert"; else $act = 'resercert'; break; case TABLE_AUTH_TY_AUTH: - if ($user->flags & USER_FLAG_AUTH) + if ($user->is_auth()) $act = "sitreser"; else $act = 'reserved'; @@ -1115,7 +1115,7 @@ class Brisk } // if authorized not check if banlisted - if ($user_cur->flags & USER_FLAG_AUTH) { + if ($user_cur->is_auth()) { continue; } @@ -1840,16 +1840,16 @@ class Brisk } } else if (strcmp($msg, "/authreq") == 0) { - if ($user->flags & USER_FLAG_AUTH) { - $to_user = sprintf('authbox(300,200);'); - } - else { - /* MLANG: "Per autenticare qualcuno devi a tua volta essere autenticato.", "Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.", "Nickname %s già in uso." */ - $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]); - } + if ($user->is_cert()) { + $to_user = sprintf('authbox(300,200);'); + } + else { + /* MLANG: "Per autenticare qualcuno devi a tua volta essere autenticato.", "Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.", "Nickname %s già in uso." */ + $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]); + } } else if (strncmp($msg, "/mesgtoadm", 8) == 0) { - if ($user->flags & USER_FLAG_AUTH) { + if ($user->is_auth()) { $to_user = sprintf('mesgtoadmbox(500,300);'); } else { @@ -1882,7 +1882,7 @@ class Brisk } /* MLANG: "Non puoi cambiare nick a un tavolo per soli autenticati.", "Il nickname \'%s\' è già registrato, se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghostN." */ - if ($user->flags & USER_FLAG_AUTH) { + if ($user->is_auth()) { if (strcasecmp($user->name,$name_new) != 0) { if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) && ($user->subst == 'standup' || @@ -1902,7 +1902,7 @@ class Brisk } $user->name = $name_new; // OK - nick changed /* se nome gia' in uso, segnala cosa potrebbe capitare */ - if (($user->flags & USER_FLAG_AUTH) == 0) { + if ( ! $user->is_auth() ) { 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." */ @@ -2055,9 +2055,9 @@ class Brisk if ($is_normchat == TRUE) { // use MAP_AUTH to check if auth or isolation if ($user_cur->flags & USER_FLAG_MAP_AUTH) { - if (($user->flags & USER_FLAG_AUTH) == 0) { - continue; - } + if ( ! $user->is_auth() ) { + continue; + } } } /* @@ -2211,7 +2211,7 @@ class Brisk if (strcasecmp($this->user[$i]->name, $name_new) == 0) { if ($authenticate != FALSE) { $ghost = $i; - $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH); + $ghost_auth = $this->user[$i]->is_auth(); } else { $idx = $i; @@ -3025,7 +3025,7 @@ function log_legal($curtime, $addr, $user, $where, $mesg) if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) { /* Unix time | session | nickname | IP | where was | mesg */ fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess, - ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'), + ($user->is_auth() ? 'A' : 'N'), $user->name, $addr, $where , $mesg)); fclose($fp); } diff --git a/web/Obj/user.phh b/web/Obj/user.phh index e06c681..5ef9d9c 100644 --- a/web/Obj/user.phh +++ b/web/Obj/user.phh @@ -329,6 +329,16 @@ class User { return ($thiz); } + function is_auth() + { + return ($this->flags & USER_FLAG_AUTH); + } + + function is_cert() + { + return (($this->flags & USER_FLAG_AUTH) && ($this->flags & USER_FLAG_TY_CERT)); + } + function flags_set($flags, $mask) { $flags_old = $this->flags & (~$mask); @@ -549,7 +559,10 @@ class User { function myname_innerHTML() { - $class_id = ($this->flags & USER_FLAG_AUTH) + 1; + // 4 -> is certified + // 2 -> is authorized + // 1 -> is myself + $class_id = (($this->flags & USER_FLAG_TY_CERT) >> 16) | ($this->flags & USER_FLAG_AUTH) | 1; return (sprintf('$("myname").innerHTML = "%s";', $class_id, xcape($this->name,ENT_COMPAT,"UTF-8"))); diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index ee69b35..fc1b2a8 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -1243,7 +1243,7 @@ class Bin5 { } // if authorized not check if banlisted - if ($user_cur->flags & USER_FLAG_AUTH) { + if ($user_cur->is_auth()) { continue; } @@ -1292,7 +1292,7 @@ class Bin5 { $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->flags & USER_FLAG_AUTH ? $user_cur->name : FALSE), + Hardbans::add(($user_cur->is_auth() ? $user_cur->name : FALSE), $user_cur->ip, $user_cur->sess, $user_cur->laccwr + BAN_TIME); } // $user->bantime = $user->laccwr + BAN_TIME; @@ -2021,7 +2021,7 @@ function log_points($remote_addr, $curtime, $user, $where, $mesg) if (($fp = @fopen(LEGAL_PATH."/points.log", 'a')) != FALSE) { /* Unix time | session | nickname | IP | where was | mesg */ fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess, - ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'), + ($user->is_auth() ? 'A' : 'N'), $user->name, $remote_addr, $where , $mesg)); fclose($fp); } diff --git a/web/briskin5/index_wr.php b/web/briskin5/index_wr.php index 7a6e6ad..534fd28 100644 --- a/web/briskin5/index_wr.php +++ b/web/briskin5/index_wr.php @@ -72,7 +72,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie) return FALSE; } $bin5->brisk->sess_cur_set($user->sess); - if (!($user->flags & USER_FLAG_AUTH) && + if ( ( ! $user->is_auth() ) && $bin5->brisk->ban_check($user->ip)) { // TODO: waiting async 5 sec before close return (FALSE); @@ -150,7 +150,7 @@ function bin5_index_wr_main(&$bin5, $remote_addr_full, $get, $post, $cookie) } else { require_once("../Obj/hardban.phh"); - Hardbans::add(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE), + Hardbans::add(($user->is_auth() ? $user->name : FALSE), $user->ip, $user->sess, $user->laccwr + BAN_TIME); } // $user->bantime = $user->laccwr + BAN_TIME; diff --git a/web/index.php b/web/index.php index 11694ca..6e45cb0 100644 --- a/web/index.php +++ b/web/index.php @@ -381,7 +381,7 @@ function index_main(&$brisk, $transp_type, &$header_out, $remote_addr_full, $get $tables .= '
'; $tables .= ''; for ($ii = 0 ; $ii < TABLES_N ; $ii++) { - if ($user->flags & USER_FLAG_AUTH) + if ($user->is_auth()) $i = $ii; else $i = TABLES_N - $ii - 1; @@ -816,7 +816,7 @@ google_color_url = "000000"; // MLANG garantisci .$mlang_room['tit_splash'][$G_lang]. '
-'.($user->flags & USER_FLAG_AUTH ? ' +'.($user->is_auth() ? ' lacc = $curtime; - if (!($user->flags & USER_FLAG_AUTH) && + if ( ( ! $user->is_auth() ) && $brisk->ban_check($user->ip)) { // TODO: find a way to add a nonblocking sleep(5) here return (FALSE); @@ -300,8 +300,8 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) $mesg_to_user = ""; - log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); - if ($user->flags & USER_FLAG_AUTH) { + log_wr("INFO:SKIP:argz == warranty name: [".$cli_name."] AUTH: ".$user->is_auth()); + if ($user->is_auth()) { if (0 == 1) { if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) { if (($fp = @fopen(LEGAL_PATH."/warrant.txt", 'a')) != FALSE) { @@ -410,8 +410,8 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) $mesg_to_user = ""; - log_wr("INFO:SKIP:argz == mesgtoadm name: [".$user->name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); - if ($user->flags & USER_FLAG_AUTH) { + log_wr("INFO:SKIP:argz == mesgtoadm name: [".$user->name."] AUTH: ".$user->is_auth()); + if ($user->is_auth()) { if (($wa_lock = Warrant::lock_data(TRUE)) != FALSE) { if (($bdb = BriskDB::create()) != FALSE) { $bdb->users_load(); @@ -489,8 +489,8 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) $dobreak = FALSE; do { - log_wr("INFO:SKIP:argz == poll name: [".$cli_poll_name."] AUTH: ".($user->flags & USER_FLAG_AUTH)); - if (($user->flags & USER_FLAG_AUTH) != USER_FLAG_AUTH) { + log_wr("INFO:SKIP:argz == poll name: [".$cli_poll_name."] AUTH: ".$user->is_auth()); + if ( ! $user->is_auth() ) { // MLANG: Per partecipare al sondaggio devi essere autenticato. $mesg_to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['pollmust'][$G_lang]); log_wr("break1"); @@ -647,7 +647,7 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) } else if ($argz[0] == 'tosmgr') { // check IF is authnticated user, both terms of service versions matches - if ($user->flags & USER_FLAG_AUTH && count($argz) == 5) { + if ($user->is_auth() && count($argz) == 5) { $f_type = $argz[1]; $f_code = $argz[2]; $f_tos_curr = $argz[3]; $f_tos_vers = $argz[4]; @@ -702,12 +702,11 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) $dt, NICKSERV, $mlang_indwr['tabwait_a'][$G_lang], $table->wakeup_time - $curtime, $mlang_indwr['tabwait_b'][$G_lang]); } - else if ($table->auth_type == TABLE_AUTH_TY_CERT - && ( (($user->flags & USER_FLAG_AUTH) == 0) || (($user->flags & USER_FLAG_TY_CERT) == 0) ) ) { + else if ($table->auth_type == TABLE_AUTH_TY_CERT && ( ! $user->is_cert() ) ) { $not_allowed_msg = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['mustcert'][$G_lang]); } - else if ($table->auth_type == TABLE_AUTH_TY_AUTH && (($user->flags & USER_FLAG_AUTH) == 0)) { + else if ($table->auth_type == TABLE_AUTH_TY_AUTH && ( ! $user->is_auth() ) ) { $not_allowed_msg = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_indwr['mustauth'][$G_lang]); } @@ -725,11 +724,11 @@ function index_wr_main(&$brisk, $remote_addr_full, $get, $post, $cookie) // if ($user->bantime > $user->laccwr) { require_once("Obj/hardban.phh"); - if (($bantime = Hardbans::check(($user->flags & USER_FLAG_AUTH ? $user->name : FALSE), + if (($bantime = Hardbans::check(($user->is_auth() ? $user->name : FALSE), $user->ip, $user->sess)) != -1) { $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; /* MLANG: "
Ti sei alzato da un tavolo senza il consenso degli altri giocatori.

Dovrai aspettare ancora ".secstoword($user->bantime - $user->laccwr)." prima di poterti sedere nuovamente.", "resta in piedi.", "
Tu o qualcuno col tuo stesso indirizzo IP si è alzato da un tavolo senza il consenso degli altri giocatori.

Dovrai aspettare ancora ".secstoword($bantime - $user->laccwr)." prima di poterti sedere nuovamente.

Se non sei stato tu ad alzarti e possiedi un login con password, autenticandoti con quello, potrai accedere." */ - if ($user->flags & USER_FLAG_AUTH) { + if ($user->is_auth()) { $user->comm[$user->step % COMM_N] .= show_notify($mlang_indwr['badwake_a'][$G_lang].secstoword($user->bantime - $user->laccwr).$mlang_indwr['badwake_b'][$G_lang], 2000, $mlang_indwr['btn_stays'][$G_lang], 400, 100); } else { -- 2.17.1