X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fbrisk.phh;h=6ff2b8e116f4ca10c159c9c1c59aeee35a067f94;hb=8b9c2b3ec59baef7c9f64f9663347bc5b9cf69fe;hp=18a85e2b40e8b3d43d9fb519d0b757c7e9728112;hpb=1a1f50c83244ae2808cc9126296c8918bd0516a4;p=brisk.git diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index 18a85e2..6ff2b8e 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -28,7 +28,8 @@ 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_AUTH_N', 4); +define('TABLES_AUTH_N', 8); +define('TABLES_CERT_N', 4); define('PLAYERS_N', 3); define('MAX_POINTS', 5); define('MAX_PLAYERS', (20 + (PLAYERS_N * TABLES_N))); @@ -150,12 +151,12 @@ $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi', $G_lng = langtolng($G_lang); $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 ); -$G_brisk_version = "4.13.3"; +$G_brisk_version = "4.14.3"; /* MLANG: ALL THE INFO STRINGS IN brisk.phh */ -$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': nuovo sistema per calcolare le classifiche con bugfix, corretto bug nel comando cont', +$root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': nuovo sistema di registrazione degli utenti, aggiunto reinvio dell\' email di verifica, ban con classi di IP', 'Se vuoi iscriverti alla Mailing List, cliccala!' ), - 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: new placements calculation system with bugfix, cont command fixed.', + 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), NEWS: new users subscription system.', 'If you want to subscribe our Mailing List, click it!' ) ); $G_room_help = array( 'it' => ' @@ -302,6 +303,82 @@ Copyright 2006-2012 Matteo Nasta
version '.$G_brisk_version.'

Copyright 2006-2012
Matteo Nastasi (aka mop)

'); + +$G_PG_vow = array("a", "e", "i", "o", "u", "y"); +$G_PG_vow_n = 6; +$G_PG_cons = array( + "b", "bb", "bc", "bd", "bf", "bg", "bk", "bl", "bm", "bn", "bp", "br", "bs", "bt", "bv", "bw", "bz", + "c", "cb", "cc", "cd", "cf", "cg", "ck", "cl", "cm", "cn", "cp", "cq", "cr", "cs", "ct", "cv", "cw", "cx", "cz", + "d", "db", "dc", "dd", "df", "dg", "dk", "dl", "dm", "dn", "dp", "dr", "ds", "dt", "dv", "dw", "dx", "dz", + "f", "fb", "fc", "fd", "ff", "fg", "fk", "fl", "fm", "fn", "fp", "fr", "fs", "ft", "fv", "fw", "fx", "fz", + "g", "gb", "gc", "gd", "gf", "gg", "gk", "gl", "gm", "gn", "gp", "gr", "gs", "gt", "gv", "gw", "gx", "gz", + "j", "jb", "jc", "jd", "jf", "jg", "jk", "jl", "jm", "jn", "jp", "jq", "jr", "js", "jt", "jv", "jw", "jx", "jz", + "k", "kb", "kc", "kd", "kf", "kg", "kk", "kl", "km", "kn", "kp", "kr", "ks", "kt", "kv", "kw", "kx", "kz", + "l", "lb", "lc", "ld", "lf", "lg", "lk", "ll", "lm", "ln", "lp", "lr", "ls", "lt", "lv", "lw", "lx", "lz", + "m", "mb", "mc", "md", "mf", "mg", "mk", "ml", "mm", "mn", "mp", "mr", "ms", "mt", "mv", "mw", "mx", "mz", + "n", "nb", "nc", "nd", "nf", "ng", "nk", "nl", "nm", "nn", "np", "nr", "ns", "nt", "nv", "nw", "nx", "nz", + "p", "pb", "pc", "pd", "pf", "pg", "pk", "pl", "pm", "pn", "pp", "pr", "ps", "pt", "pv", "pw", "px", "pz", + "q", "qb", "qc", "qd", "qf", "qg", "qk", "ql", "qm", "qn", "qp", "qq", "qr", "qs", "qt", "qv", "qw", "qx", "qz", + "r", "rb", "rc", "rd", "rf", "rg", "rk", "rl", "rm", "rn", "rp", "rr", "rs", "rt", "rv", "rw", "rx", "rz", + "s", "sb", "sc", "sd", "sf", "sg", "sk", "sl", "sm", "sn", "sp", "sq", "sr", "ss", "st", "sv", "sw", "sx", "sz", + "t", "tb", "tc", "td", "tf", "tg", "tk", "tl", "tm", "tn", "tp", "tr", "ts", "tt", "tv", "tw", "tx", "tz", + "v", "vb", "vc", "vd", "vf", "vg", "vk", "vl", "vm", "vn", "vp", "vr", "vs", "vt", "vv", "vw", "vx", "vz", + "w", "wb", "wc", "wd", "wf", "wg", "wk", "wl", "wm", "wn", "wp", "wr", "ws", "wt", "wv", "ww", "wx", "wz", + "x", "xb", "xc", "xd", "xf", "xg", "xk", "xl", "xm", "xn", "xp", "xr", "xs", "xt", "xv", "xw", "xx", "xz", + "z", "zb", "zc", "zd", "zf", "zg", "zk", "zl", "zm", "zn", "zp", "zr", "zs", "zt", "zv", "zw", "zx", "zz", + ); +// $G_PG_cons_n = count($G_PG_cons); +// printf("N CONS: %d\n", $G_PG_cons_n); +$G_PG_cons_n = 345; + /* printf("%d %d\n", count($voc), count($cons)); */ + /* for ($i = 0 ; $i < 26 ; $i++) { */ + /* if (array_search(chr(ord('a') + $i), $voc) !== FALSE || $i == 7) */ + /* continue; */ + /* printf(' "%s", ', chr(ord('a') + $i)); */ + /* for ($e = 0 ; $e < 26 ; $e++) { */ + /* if (array_search(chr(ord('a') + $e), $voc) !== FALSE || $e == 7) */ + /* continue; */ + /* printf('"%s%s", ', chr(ord('a') + $i), chr(ord('a') + $e)); */ + /* } */ + /* printf("\n"); */ + /* } */ + +function passwd_gen($seed = NULL) +{ + GLOBAL $G_PG_vow, $G_PG_vow_n, $G_PG_cons, $G_PG_cons_n; + + $pw = ""; + + if ($seed != NULL) + mt_srand($seed); + else + mt_srand(); + + for ($sil = 0 ; $sil < 7 ; $sil++) { + if (($sil % 2) == 0) { + // vowels + for ($n = 0 ; $n < mt_rand(1,2) ; $n++) { + if ($n == 0) { + $old = mt_rand(0, $G_PG_vow_n-1); + $pw .= $G_PG_vow[$old]; + } + else { + $new = mt_rand(0, $G_PG_vow_n-1); + if ($new == $old) + $new = ($new + mt_rand(0, $G_PG_vow_n-2)) % $G_PG_vow_n; + $pw .= $G_PG_vow[$new]; + } + } + } + else { + // consonants + $pw .= $G_PG_cons[mt_rand(0, $G_PG_cons_n-1)]; + } + } + + return $pw; +} + function cmd_return($val, $desc) { return array('val' => $val, 'desc' => $desc); @@ -433,7 +510,7 @@ function escinput($s) function eschtml($s) { - return htmlentities($s); + return htmlentities($s, ENT_COMPAT, "UTF-8"); } function esclfhtml($s) @@ -501,6 +578,33 @@ function xcapemesg($s) } +class IPClass { + var $addr; + var $mask; + + function IPClass($ipset) + { + //split + $elem = split("/", $ipset, 2); + $addr = $elem[0]; + $mask = (int)$elem[1]; + + //convert mask + + $this->mask = ((1<<($mask))-1) << (32 - $mask); + $this->addr = ip2long($addr) & $this->mask; + + fprintf(STDERR, "New ipclass: %x (%x)\n", $this->addr, $this->mask); + } + + function match($ip) + { + fprintf(STDERR, "IP: %x, ADDR: %x, MASK: %x -> (%d)\n", + $ip, $this->addr, $this->mask, ((ip2long($ip) & $this->mask) == $this->addr)); + return (($ip & $this->mask) == $this->addr); + } +} + class Vect { function Vect($a) { @@ -518,12 +622,17 @@ class Vect { } } +define('TABLE_AUTH_TY_PUBL', 0); +define('TABLE_AUTH_TY_AUTH', 1); +define('TABLE_AUTH_TY_CERT', 2); + + class Table { var $idx; var $player; var $player_n; - var $auth_only; // se tavolo riservato o libero + var $auth_type; // required authorization to sit down var $wag_own; var $wag_com; @@ -546,7 +655,13 @@ class Table { $thiz->idx = $idx; $thiz->player = array(); $thiz->player_n = 0; - $thiz->auth_only = FALSE; + + if ($idx < TABLES_CERT_N) + $thiz->auth_type = TABLE_AUTH_TY_CERT; + else if ($idx < TABLES_AUTH_N) + $thiz->auth_type = TABLE_AUTH_TY_AUTH; + else + $thiz->auth_type = TABLE_AUTH_TY_PUBL; $thiz->wag_own = -1; $thiz->wag_com = ""; @@ -570,7 +685,7 @@ class Table { log_main("PLAYER_N - parent::copy.".$this->player_n); - $this->auth_only = $from->auth_only; + $this->auth_type = $from->auth_type; $this->wag_own = $from->wag_own; $this->wag_com = $from->wag_com; @@ -603,7 +718,7 @@ class Table { $thiz->player[$i] = $i; $thiz->player_n = $from->player_n; - $thiz->auth_only = $from->auth_only; + $thiz->auth_type = $from->auth_type; $thiz->wag_own = $from->wag_own; $thiz->wag_com = $from->wag_com; @@ -674,12 +789,7 @@ class Table { } } - - - // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table, - // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH)); - - // function act_content($isstanding, $sitted, $table, $cur_table, $allowed) + // Table->act_content - return 'id' of type of output required for table button function act_content($user) { $ret = ""; @@ -691,15 +801,23 @@ class Table { if ($isstanding) { if ($sitted < PLAYERS_N) { - if ($this->auth_only) { - if ($user->flags & USER_FLAG_AUTH) - $act = "sitreser"; - else - $act = 'reserved'; - } - else { - $act = 'sit'; - } + switch ($this->auth_type) { + case TABLE_AUTH_TY_CERT: + if ($user->is_cert()) + $act = "sitcert"; + else + $act = 'resercert'; + break; + case TABLE_AUTH_TY_AUTH: + if ($user->is_auth()) + $act = "sitreser"; + else + $act = 'reserved'; + break; + default: + $act = 'sit'; + break; + } } else { $act = 'none'; @@ -873,44 +991,171 @@ class Brisk var $step; // current step of the comm array var $garbage_timeout; var $shm_sz; - + + var $ban_list; // ban list (authized allowed) + var $black_list; // black list (anti-dos, noone allowed) + var $delay_mgr; public static $sess_cur; - function Brisk($crystal_filename) { - $this->crystal_filename = $crystal_filename; - $this->user = array(); - $this->table = array(); - $this->match = array(); - + function Brisk() + { + } + + // constructor + static function create($crystal_filename, $ban_list, $black_list) { + if (($brisk_ser = @file_get_contents($crystal_filename)) != FALSE) { + if (($brisk = unserialize($brisk_ser)) != FALSE) { + fprintf(STDERR, "ROOM FROM FILE\n"); + rename($crystal_filename, $crystal_filename.".old"); + + $brisk->reload($ban_list, $black_list); + + return($brisk); + } + } + + fprintf(STDERR, "NEW ROOM\n"); + $thiz = new Brisk(); + + $thiz->crystal_filename = $crystal_filename; + $thiz->user = array(); + $thiz->table = array(); + $thiz->match = array(); + + $thiz->ban_list = NULL; + $thiz->black_list = NULL; + + fprintf(STDERR, "PRE IPCLASS_UPDATE (%d, %d)\n", count($ban_list), count($black_list)); + $thiz->ipclass_update('ban_list', $ban_list); + $thiz->ipclass_update('black_list', $black_list); + fprintf(STDERR, "POST IPCLASS_UPDATE %d %d\n", count($thiz->ban_list), count($thiz->black_list)); + for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { - $this->user[$i] = User::create($this, $i, "", ""); + $thiz->user[$i] = User::create($thiz, $i, "", ""); } for ($i = 0 ; $i < TABLES_N ; $i++) { - $this->table[$i] = Table::create($i); - /* OLD METHOD - if ($i < 12) { - $row = ( (((int)($i / 4)) % 2) == 0 ); - $col = ($i % 2 == 0); - $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col)); - } - else { - $this->table[$i]->auth_only = FALSE; - } - */ - if ($i < TABLES_AUTH_N) - $this->table[$i]->auth_only = TRUE; - else - $this->table[$i]->auth_only = FALSE; + $thiz->table[$i] = Table::create($i); } - $this->garbage_timeout = 0; - $this->shm_sz = SHM_DIMS_MIN; + $thiz->garbage_timeout = 0; + $thiz->shm_sz = SHM_DIMS_MIN; - $this->delay_mgr = new Delay_Manager(1.5); + $thiz->delay_mgr = new Delay_Manager(1.5); static::$sess_cur = FALSE; + + return ($thiz); + } + + function ipclass_update($ip_out_s, $ip_in) + { + fprintf(STDERR, "N_IN: %d\n", count($ip_in)); + + $ip_out = &$this->$ip_out_s; + + // if already set clean the ban_list property + if ($ip_out) { + $ct = count($ip_out); + for ($i = 0 ; $i < $ct ; $i++) { + unset($ip_out[$i]); + } + unset($ip_out); + } + + $ip_out = array(); + for ($i = 0 ; $i < count($ip_in) ; $i++) { + $ip_out[$i] = new IPClass($ip_in[$i]); + } + } + + function reload($ban_list, $black_list) + { + fprintf(STDERR, "RELOAD STUFF (%d)(%d)\n", count($ban_list), count($black_list)); + + $this->ipclass_update("ban_list", $ban_list); + $this->ipclass_update("black_list", $black_list); + + $this->banned_kickoff(); + $this->garbage_manager(TRUE); + } + + function banned_kickoff() + { + $is_ban = FALSE; + + for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { + $table_cur = $this->table[$table_idx]; + // if the table is complete and exists we check users IP + + if ($table_cur->player_n == PLAYERS_N) { + if (isset($this->match[$table_idx]) && + $table_cur->table_token == $bin5->table_token) { + log_main("PLAYERS == N TABLE ".$table_idx); + + $bin5 = $this->match[$table_idx]; + + $is_ban |= $bin5->banned_kickoff(); + } + } + } + + for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { + $user_cur = $this->user[$i]; + + if ($user_cur->sess == "") + continue; + + // check if the IP is blacklisted + if ($this->black_check($user_cur->ip)) { + $user_cur->lacc = 0; + $is_ban = TRUE; + continue; + } + + // if authorized not check if banlisted + if ($user_cur->is_auth()) { + continue; + } + + if ($this->ban_check($user_cur->ip)) { + $user_cur->lacc = 0; + $is_ban = TRUE; + } + } + + return $is_ban; + } + + function ban_check($ip_str) + { + $ip = ip2long($ip_str); + fprintf(STDERR, "Brisk::ban_check %d\n", count($this->ban_list)); + for ($i = 0 ; $i < count($this->ban_list) ; $i++) { + fprintf(STDERR, "ban_list[%d] = %x (%x)\n", $i, + $this->ban_list[$i]->addr, $this->ban_list[$i]->mask); + if ($this->ban_list[$i]->match($ip)) { + fprintf(STDERR, "\n\nMATCHA!\n\n"); + return(TRUE); + } + } + return (FALSE); + } + + function black_check($ip_str) + { + $ip = ip2long($ip_str); + fprintf(STDERR, "Brisk::black_check %d\n", count($this->black_list)); + for ($i = 0 ; $i < count($this->black_list) ; $i++) { + fprintf(STDERR, "black_list[%d] = %x (%x)\n", $i, + $this->black_list[$i]->addr, $this->black_list[$i]->mask); + if ($this->black_list[$i]->match($ip)) { + fprintf(STDERR, "\n\nMATCHA!\n\n"); + return(TRUE); + } + } + return (FALSE); } function garbage_manager($force) @@ -1120,8 +1365,7 @@ class Brisk for ($i = 0 ; $i < TABLES_N ; $i++) { $ret .= $this->table_content($user, $i); - // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table, - // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH)); + $ret .= $this->table[$i]->act_content($user); if ($this->table[$i]->wag_own != -1) $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com); @@ -1209,15 +1453,11 @@ class Brisk // clean the action buttons in other tables for ($e = 0 ; $e < TABLES_N ; $e++) { if ($this->table[$e]->player_n < PLAYERS_N) { - // $ret .= table_act_content(TRUE, 0, $e, $user->table, - // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH)); $ret .= $this->table[$e]->act_content($user); } } } else { - // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table, - // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH)); $ret .= $table->act_content($user_cur); } } @@ -1292,8 +1532,6 @@ class Brisk $ret .= $this->table_content($user_cur, $table_idx); $ret .= $this->standup_content($user_cur); - // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table, - // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH)); $ret .= $table->act_content($user_cur); @@ -1321,8 +1559,7 @@ class Brisk log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n); log_main("JOIN_WAKEUP more"); - // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table, - // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH)); + $ret .= $table->act_content($user_cur); log_main("JOIN_WAKEUP end more"); @@ -1465,8 +1702,7 @@ class Brisk } else if ($table_idx > -1) { if ($table->player_n == PLAYERS_N) { - // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table, - /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH)); + $ret .= $table->act_content($user_cur); } } @@ -1604,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 { @@ -1646,11 +1882,11 @@ 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' || - ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE) + ($user->subst != 'standup' && $this->table[$user->table]->auth_type == TABLE_AUTH_TY_PUBL) ) ) { $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed @@ -1666,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." */ @@ -1819,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; + } } } /* @@ -1975,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; @@ -2044,7 +2280,6 @@ class Brisk $this->user[$idx]->ip = $ip; $this->user[$idx]->rec = $authenticate; - fprintf(STDERR, "MOP: [%s]\n", $authenticate->supp_comp); $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); @@ -2148,118 +2383,6 @@ class Brisk } } - // Static functions - static function create($crystal_filename) - { - if (($brisk_ser = @file_get_contents($crystal_filename)) == FALSE || - ($brisk = unserialize($brisk_ser)) == FALSE) { - fprintf(STDERR, "NEW ROOM\n"); - $brisk = new Brisk($crystal_filename); - } - else { - fprintf(STDERR, "ROOM FROM FILE\n"); - rename($crystal_filename, $crystal_filename.".old"); - } - - return $brisk; - } - - - function load_data() - { - GLOBAL $sess; - - do { - if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) { - log_main("ftok failed"); - break; - } - - if (($shm_sz = sharedmem_sz($tok)) == -1) { - log_main("shmop_open failed"); - } - - if ($shm_sz == -1) - $shm_sz = SHM_DIMS_MIN; - - if ($shm = shm_attach($tok, $shm_sz)) { - $brisk = @shm_get_var($shm, $tok); // CHECKED BELOW - - log_only("bri == ".($brisk == FALSE ? "FALSE" : "TRUE")." bri === ".($brisk === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($brisk) ? "TRUE" : "FALSE")); - if (isset($brisk)) - log_only("bri count ".count($brisk)); - - if ($brisk == FALSE) { - log_only("INIT MAIN DATA"); - shm_detach($shm); - - $brisk = Brisk::create(); - - log_shme("Brisk::create"); - - if (Brisk::save_data($brisk) == FALSE) - return FALSE; - - return $brisk; - } - $brisk->shm_sz = $shm_sz; - - shm_detach($shm); - - for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { - if (($brisk->user[$i] = User::load_data($i, FALSE)) == FALSE) { - log_crit("User::load_data failed"); - break; - } - } - if ($i < MAX_PLAYERS) { - break; - } - } - - // - // SHSPLIT: load users from the shared memory - // - return ($brisk); - } while (0); - - return (FALSE); - } - - - function save_data_orig($brisk) - { - GLOBAL $sess; - - $shm = FALSE; - - // var_dump($brisk); - - if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) - return (FALSE); - - while ($brisk->shm_sz < SHM_DIMS_MAX) { - if (($shm = shm_attach($tok, $brisk->shm_sz)) == FALSE) - break; - - // log_only("PUT_VAR DI ".strlen(serialize($brisk))); - if (@shm_put_var($shm, $tok, $brisk) != FALSE) { - shm_detach($shm); - return (TRUE); - } - if (shm_remove($shm) === FALSE) { - log_only("REMOVE FALLITA"); - break; - } - shm_detach($shm); - $brisk->shm_sz += SHM_DIMS_DLT; - } - - if ($shm) - shm_detach($shm); - - return (FALSE); - } function dump_data() { $brisk_ser = serialize($this); @@ -2271,77 +2394,6 @@ class Brisk return (FALSE); } - function save_data($brisk) - { - GLOBAL $sess; - - $ret = FALSE; - $shm = FALSE; - - if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) - return (FALSE); - - // SHSPLIT: before save the $brisk you must save users, - // detach from main struct and (then) reattach - $user_park = array(); - for ($i = 0 ; $i < MAX_PLAYERS ; $i++) { - $user_park[$i] = $brisk->user[$i]; - $brisk->user[$i] = FALSE; - } - - while ($brisk->shm_sz < SHM_DIMS_MAX) { - if (($shm = shm_attach($tok, $brisk->shm_sz)) == FALSE) - break; - - // log_only("PUT_VAR DI ".strlen(serialize($brisk))); - if (@shm_put_var($shm, $tok, $brisk) != FALSE) { - log_shme("Brisk::save_data"); - $ret = TRUE; - break; - } - if (shm_remove($shm) === FALSE) { - log_only("REMOVE FALLITA"); - break; - } - shm_detach($shm); - $brisk->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); - $brisk->user[$i] = $user_park[$i]; - } - log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE")); - - return ($ret); - } - - static function lock_data($is_exclusive) - { - if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) { - self::$delta_t = microtime(TRUE); - log_lock("LOCK room [".self::$delta_t."]"); - - return ($res); - } - - return (FALSE); - } - - static function unlock_data($res) - { - GLOBAL $sess; - - log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]"); - - file_unlock($res); - } - - function standup_content($user) { $ret = ""; @@ -2434,9 +2486,17 @@ class Brisk function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie) { - GLOBAL $G_black_list; + GLOBAL $G_ban_list, $G_black_list; printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path); + $remote_addr = addrtoipv4($addr); + + fprintf(STDERR, "\n\n\n PRE_BLACK_CHECK \n\n\n"); + if ($this->black_check($remote_addr)) { + // TODO: waiting async 5 sec before close + fprintf(STDERR, "\n\n\n BLACK_CHECK \n\n\n"); + return (FALSE); + } $enc = get_encoding($header); if (isset($header['User-Agent'])) { @@ -2965,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); }