X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fbrisk.phh;h=4fefa542199bd56c1e3ef1e6e9648cc75db906cd;hb=d6e78ab1c534675fdaf838c17375850f414d4c3e;hp=cf6b8246c734ac817648ded54c07880298265241;hpb=9facf6a8c63b14f22736b12855900fe89456f379;p=brisk.git diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index cf6b824..4fefa54 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -2,7 +2,7 @@ /* * brisk - brisk.phh * - * Copyright (C) 2006-2008 Matteo Nastasi + * Copyright (C) 2006-2009 Matteo Nastasi * mailto: nastasi@alternativeoutput.it * matteo.nastasi@milug.org * web: http://www.alternativeoutput.it @@ -27,7 +27,7 @@ define(BRISK_CONF, "brisk.conf.pho"); define(FTOK_PATH, "/var/lib/brisk"); define(LEGAL_PATH, "/tmp/legal_brisk"); define(PROXY_PATH, "/var/lib/brisk_proxy"); -define(TABLES_N, 32); +define(TABLES_N, 36); define(PLAYERS_N, 3); define(MAX_POINTS, 5); define(MAX_PLAYERS, (20 + (PLAYERS_N * TABLES_N))); @@ -65,7 +65,7 @@ define(DBG_AUTH, 0x0200); define(DBG_CRIT, 0x0400); // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols -define(BRISK_DEBUG, 0xffffffff); +define(BRISK_DEBUG, 0xffffffbf); define(BRISK_SINGLE_DEBUG,0); define(BRISK_SINGLE_SESS, ""); @@ -80,10 +80,10 @@ $G_lng = ""; // $G_lng = "_en"; $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 ); -$G_brisk_version = "2.1.5 - trusty"; +$G_brisk_version = "2.1.7 - trusty"; /* MLANG: ALL THE INFO STRINGS IN brisk.phh */ -$root_wellarr = Array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': il rendering degli utenti in piedi è stato riscritto.', +$root_wellarr = Array ( 'Brisk (Ver. '.$G_brisk_version.'), NOVITA\': menu comandi, filtro opzionale sui non autenticati e "return bug" corretto.', 'Se vuoi iscriverti alla Mailing List, cliccala!' ); $G_room_help= ' @@ -111,6 +111,8 @@ Dopo che è iniziata una partita per uscirne dovete chiedere agli altri gi
/tav <frase di invito> - invito per gli altri giocatori al tavolo dove si è seduti
/st <stato> - cambia l\'icona associata al tuo user; stato può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
/garante - se si è autenticati permette di garantire per un utente fidato +
/mesgtoadm - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito +
/listen <all or auth> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all) '; @@ -136,88 +138,34 @@ function xcape($s) function xcapelt($s) { - $from = array ( '\\', '|' ); - $to = array ( '\\\\', '\\|' ); + $from = array ( '\\', '|', "\t", "\n"); + $to = array ( '\\\\', '\\|', "\\t", "\\n"); return (str_replace($from, $to, $s)); } -class Card { - var $value; /* 0 - 39 card value */ - var $stat; /* 'bunch', 'hand', 'table', 'take' */ - var $owner; /* (table position 0-4) */ - // var $pos; /* Pos in hand. */ - var $x; /* When played the X position on the table of the owner. */ - var $y; /* When played the Y position on the table of the owner. */ - - function Card($value, $stat, $owner) - { - $this->value = $value; - $this->stat = $stat; // Card stat - $this->owner = $owner; - } - - function assign($stat,$owner) - { - $this->stat = $stat; // Card stat - $this->owner = $owner; - } - - function setpos($pos) - { - $this->pos = $pos; - } +function xcapemesg($s) +{ + $from = array ( "\n"); + $to = array ( "\\n"); - function play($x,$y) - { - $this->stat = 'table'; // Card stat - $this->x = $x; - $this->y = $y; - } + return (str_replace($from, $to, $s)); +} - function take($newown) - { - $this->stat = 'take'; // Card stat - $this->owner = $newown; - } -} // end class Card class Table { var $idx; var $player; var $player_n; - var $card; - var $mazzo; - var $gstart; - var $turn; - var $auth_only; + + var $auth_only; // se tavolo riservato o libero var $wag_own; var $wag_com; var $wag_tout; - var $asta_pla; - var $asta_pla_n; - var $asta_card; - var $asta_pnt; - - var $mult; - var $points; // points array - var $points_n; // number of row of points - var $total; - - var $asta_win; - var $briscola; - var $friend; - - var $old_reason; - var $old_asta_pnt; - var $old_pnt; - var $old_win; - var $old_friend; - var $table_token; - var $table_start; + var $table_start; // information field var $wakeup_time; @@ -235,33 +183,12 @@ class Table { $thiz->idx = $idx; $thiz->player = array(); $thiz->player_n = 0; - $thiz->card = FALSE; - $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction - $thiz->asta_pla_n= -1; - $thiz->asta_card = -1; - $thiz->asta_pnt = -1; - $thiz->mult = 1; - $thiz->auth_only = FALSE; - $thiz->points = array( ); - $thiz->points_n = 0; - $thiz->total = array( 0, 0, 0, 0, 0); - $thiz->asta_win = -1; - $thiz->briscola = -1; - $thiz->friend = -1; - $thiz->turn = 0; - $thiz->wag_own = NULL; $thiz->wag_com = ""; $thiz->wag_tout = 0; - $thiz->old_reason = ""; - $thiz->old_asta_pnt = -1; - $thiz->old_pnt = -1; - $thiz->old_win = -1; - $thiz->old_friend = -1; - $thiz->table_token = ""; $thiz->table_start = 0; @@ -270,53 +197,38 @@ class Table { return ($thiz); } - function &clone(&$from) + function copy(&$from) { GLOBAL $G_false; - if (($thiz =& new Table()) == FALSE) - return ($G_false); - - $thiz->idx = $from->idx; - $thiz->player = array(); + $this->idx = $from->idx; + $this->player = array(); for ($i = 0 ; $i < $from->player_n ; $i++) - $thiz->player[$i] = $from->player[$i]; - $thiz->player_n = $from->player_n; - $thiz->card = $from->card; - $thiz->mazzo = $from->mazzo; // REVIEW - $thiz->gstart = $from->gstart; - $thiz->turn = $from->turn; + $this->player[$i] = $from->player[$i]; + $this->player_n = $from->player_n; - $thiz->auth_only = $from->auth_only; + log_main("PLAYER_N - parent::copy.".$this->player_n); + + $this->auth_only = $from->auth_only; - $thiz->wag_own = $from->wag_own; - $thiz->wag_com = $from->wag_com; - $thiz->wag_tout = $from->wag_taut; + $this->wag_own = $from->wag_own; + $this->wag_com = $from->wag_com; + $this->wag_tout = $from->wag_tout; - $thiz->asta_pla = $from->asta_pla; - $thiz->asta_pla_n = $from->asta_pla_n; - $thiz->asta_card = $from->asta_card; - $thiz->asta_pnt = $from->asta_pnt; - - $thiz->mult = $from->mult; - $thiz->points = $from->points; - $thiz->points_n = $from->points_n; - $thiz->total = $from->total; - - $thiz->asta_win = $from->asta_win; - $thiz->briscola = $from->briscola; - $thiz->friend = $from->friend; - - $thiz->old_reason = $from->old_reason; - $thiz->old_asta_pnt = $from->old_asta_pnt; - $thiz->old_pnt = $from->old_pnt; - $thiz->old_win = $from->old_win; - $thiz->old_friend = $from->old_friend; + $this->table_token = $from->table_token; + $this->table_start = $from->table_start; - $thiz->table_token = $from->table_token; - $thiz->table_start = $from->table_start; + $this->wakeup_time = $from->wakeup_time; + } - $thiz->wakeup_time = $from->wakeup_time; + function &clone(&$from) + { + GLOBAL $G_false; + + if (($thiz =& new Table()) == FALSE) + return ($G_false); + + $this->copy($from); return ($thiz); } @@ -329,42 +241,16 @@ class Table { return ($G_false); $thiz->idx = $from->idx; + $thiz->player = array(); + for ($i = 0 ; $i < $from->player_n ; $i++) + $thiz->player[$i] = $i; $thiz->player_n = $from->player_n; - $thiz->card = &$thiz->bunch_create(); - $thiz->mazzo = $from->mazzo; - $thiz->gstart = $from->gstart; - $thiz->turn = $from->turn; $thiz->auth_only = $from->auth_only; $thiz->wag_own = $from->wag_own; $thiz->wag_com = $from->wag_com; - $thiz->wag_tout = $from->wag_taut; - - $thiz->asta_pla = $from->asta_pla; - $thiz->asta_pla_n = $from->asta_pla_n; - $thiz->asta_card = $from->asta_card; - $thiz->asta_pnt = $from->asta_pnt; - - $thiz->mult = $from->mult; - $thiz->points = $from->points; - $thiz->points_n = $from->points_n; - $thiz->total = $from->total; - - $thiz->asta_win = $from->asta_win; - $thiz->briscola = $from->briscola; - $thiz->friend = $from->friend; - - $thiz->old_reason = $from->old_reason; - $thiz->old_asta_pnt = $from->old_asta_pnt; - $thiz->old_pnt = $from->old_pnt; - $thiz->old_win = $from->old_win; - $thiz->old_friend = $from->old_friend; - - // players are rearranged in an dedicated array - $thiz->player = array(); - for ($i = 0 ; $i < $from->player_n ; $i++) - $thiz->player[$i] = $i; + $thiz->wag_tout = $from->wag_tout; $thiz->table_token = $from->table_token; $thiz->table_start = $from->table_start; @@ -373,18 +259,6 @@ class Table { return ($thiz); } - - function &bunch_create() - { - $ret = array(); - - for ($i = 0 ; $i < 40 ; $i++) { - $ret[$i] =& new Card($i, 'bunch', 'no_owner'); - } - - $oret = &$ret; - return ($oret); - } function wag_set(&$user, $mesg) { @@ -405,79 +279,6 @@ class Table { $this->wag_tout = $timeout; } - function bunch_make() - { - $ct = array(0,0,0,0,0); - - mt_srand(make_seed()); - - for ($i = 39 ; $i >= 0 ; $i--) - $rest[$i] = $i; - - for ($i = 39 ; $i >= 0 ; $i--) { - $rn = rand(0, $i); - - if ($rn == 0) - log_main("RND ZERO"); - - $id = $rest[$rn]; - - $owner = $i % 5; - $this->card[$id]->assign('hand', $owner); - - $rest[$rn] = $rest[$i]; - // $pubbpos[$rn2] = $pubbpos[$i]; - } - } - - function init(&$userarr) - { - $this->mazzo = rand(0,PLAYERS_N-1); - $this->points_n = 0; - $this->mult = 1; - $this->old_win =-1; - $this->old_reason = ""; - for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $this->total[$i] = 0; - $user_cur = &$userarr[$this->player[$i]]; - $user_cur->exitislock = TRUE; - } - - log_main("table::init: ci siamo"); - } - - function game_init(&$userarr) - { - log_rd2("GSTART 4"); - - $this->gstart = ($this->mazzo+1) % PLAYERS_N; - $this->bunch_make(); - - - $this->asta_pla_n = PLAYERS_N; - $this->asta_card = -1; - $this->asta_pnt = 60; - $this->asta_win = -1; - $this->briscola = -1; - $this->friend = -1; - $this->turn = 0; - - for ($i = 0 ; $i < PLAYERS_N ; $i++) { - $this->asta_pla[$i] = TRUE; - $user_cur = &$userarr[$this->player[$i]]; - $user_cur->subst = 'asta'; - $user_cur->asta_card = -2; - $user_cur->asta_pnt = -1; - $user_cur->handpt = $this->hand_points($i); - // SEE function calculate_points(&$table) - } - } - - function game_next() - { - $this->mazzo = ($this->mazzo + 1) % PLAYERS_N; - } - function getPlayer($idx) { return ($this->player[$idx]); @@ -516,45 +317,6 @@ class Table { } } - function hand_points($idx) - { - GLOBAL $G_all_points; - - $tot = 0; - - for ($i = 0 ; $i < 40 ; $i++) { - if ($this->card[$i]->owner != $idx) - continue; - - $ctt = $this->card[$i]->value % 10; - $tot += $G_all_points[$ctt]; - } - - return ($tot); - } - - function exitlock_show(&$userarr, $table_pos) - { - $ct = $this->exitlock_calc(&$userarr, $table_pos); - - $ret = sprintf('exitlock_show(%d, %s);', $ct, - ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false')); - return ($ret); - } - - function exitlock_calc(&$userarr, $table_pos) - { - $ct = 0; - - for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) { - if ($userarr[$this->player[$i]]->exitislock == FALSE) - $ct++; - } - - return ($ct); - } - - // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table, @@ -598,13 +360,12 @@ class Table { return ($ret); } - - } // end class Table - + // User flags -define(USER_FLAG_AUTH, 0x02); +define(USER_FLAG_AUTH, 0x02); +define(USER_FLAG_LISTAUTH, 0x04); // user status define(USER_FLAG_S_NORM, 0x000); // done @@ -630,10 +391,14 @@ class User { var $step; // step of the current status var $trans_step; // step to enable transition between pages (disable == -1) var $comm; // commands array - var $asta_card; // - var $asta_pnt; // - var $handpt; // Total card points at the beginning of the current hand. - var $exitislock; // Player can exit from the table ? + // var $asta_card; // + // var $asta_pnt; // + // var $handpt; // Total card points at the beginning of the current hand. + // var $exitislock; // Player can exit from the table ? + + // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table + // it is allways ZERO + var $table_orig; // id of the current table (if in table state) var $table; // id of the current table (if in table state) var $table_pos; // idx on the table var $table_token;// token that identify a game on a table @@ -678,56 +443,68 @@ class User { $thiz->chat_ban = 0; $thiz->chat_dlt = 0; - $thiz->table = $table; + $thiz->table_orig = $table; + $thiz->table = $table; $thiz->table_pos = -1; $thiz->table_token = ""; return ($thiz); } - function &clone(&$from) + function copy(&$from) { GLOBAL $G_false; - if (($thiz =& new User()) == FALSE) - return ($G_false); - - $thiz->name = $from->name; - $thiz->sess = $from->sess; - $thiz->ip = $from->ip; - $thiz->lacc = $from->lacc; - $thiz->laccwr = $from->laccwr; - $thiz->bantime = $from->bantime; - $thiz->stat = $from->stat; - $thiz->subst = $from->subst; - $thiz->step = $from->step; - $thiz->trans_step = $from->trans_step; - $thiz->comm = array(); + $this->name = $from->name; + $this->sess = $from->sess; + $this->ip = $from->ip; + $this->lacc = $from->lacc; + $this->laccwr = $from->laccwr; + $this->bantime = $from->bantime; + $this->stat = $from->stat; + $this->subst = $from->subst; + $this->step = $from->step; + $this->trans_step = $from->trans_step; + $this->comm = array(); $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N)); for ($i = $i_start ; $i < $from->step ; $i++) { $ii = $i % COMM_N; - $thiz->comm[$ii] = $from->comm[$ii]; + $this->comm[$ii] = $from->comm[$ii]; } - $thiz->asta_card = $from->asta_card; - $thiz->asta_pnt = $from->asta_pnt; - $thiz->handpt = $from->handpt; - $thiz->exitislock = $from->exitislock; + $this->asta_card = $from->asta_card; + $this->asta_pnt = $from->asta_pnt; + $this->handpt = $from->handpt; + $this->exitislock = $from->exitislock; - $thiz->flags = $from->flags; + $this->flags = $from->flags; - $thiz->chattime = array(); + $this->chattime = array(); for ($i = 0 ; $i < CHAT_N ; $i++) - $thiz->chattime[$i] = $from->chattime[$i]; - $thiz->chat_cur = $from->chat_cur; - $thiz->chat_lst = $from->chat_lst; - $thiz->chat_ban = $from->chat_ban; - $thiz->chat_dlt = $from->chat_dlt; - - $thiz->table = $from->table; - $thiz->table_pos = $from->table_pos; - $thiz->table_token = $from->table_token; - $thiz->the_end = $from->the_end; + $this->chattime[$i] = $from->chattime[$i]; + $this->chat_cur = $from->chat_cur; + $this->chat_lst = $from->chat_lst; + $this->chat_ban = $from->chat_ban; + $this->chat_dlt = $from->chat_dlt; + + $this->table_orig = $from->table_orig; + $this->table = $from->table; + $this->table_pos = $from->table_pos; + $this->table_token = $from->table_token; + $this->the_end = $from->the_end; + + return (TRUE); + } + + + function &clone(&$from) + { + GLOBAL $G_false; + + if (($thiz =& new User()) == FALSE) + return ($G_false); + + $thiz->copy($from); return ($thiz); } @@ -774,7 +551,8 @@ class User { $thiz->chat_dlt = 0; - $thiz->table = $table; + $thiz->table_orig = $table; + $thiz->table = 0; $thiz->table_pos = $table_pos; $thiz->table_token = $from->table_token; @@ -851,6 +629,11 @@ class User { } // end class User + + + + + function step_get($sess) { $fp = FALSE; do { @@ -906,6 +689,7 @@ class Room { 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); @@ -914,6 +698,11 @@ class Room { else { $this->table[$i]->auth_only = FALSE; } + */ + if ($i < 12) + $this->table[$i]->auth_only = TRUE; + else + $this->table[$i]->auth_only = FALSE; } $this->garbage_timeout = 0; } @@ -928,6 +717,9 @@ class Room { $curtime = time(); if ($force || $this->garbage_timeout < $curtime) { + // FIXME BRISK4: include for each kind of table + require_once("briskin5/Obj/briskin5.phh"); + // Before all align times with table timeout for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { $table_cur =& $this->table[$table_idx]; @@ -965,7 +757,7 @@ class Room { */ log_main("garbage_manager: INSIDE THE END."); - $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n"; + $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n"; for ($i = 0 ; $i < $table_cur->player_n ; $i++) { $plist .= '|'.$this->user[$table_cur->player[$i]]->sess; } @@ -1081,8 +873,15 @@ class Room { { log_main("show_room: username: ".$user->name); - $ret = sprintf('gst.st = %d; ', $user_step); + + if ($user->flags & USER_FLAG_LISTAUTH) { + $ret .= 'list_set(\'auth\', false, \'(solo aut.)\' ); '; + } + else { + $ret .= 'list_set(\'all\', false, \'\' ); '; + } + if ($user->subst == 'standup') $ret .= "tra.show(); "; else @@ -1417,6 +1216,7 @@ class Room { $to_all = FALSE; $to_room = FALSE; $to_tabl = FALSE; + $is_normchat = FALSE; $update_room = FALSE; if (strcmp($msg, "/tav") == 0 || @@ -1487,6 +1287,18 @@ class Room { $to_all = show_notify($msg, 0, "chiudi", 400, 120); } while (0); } // /alarm chat command + else if (strncmp($msg, "/listen ", 8) == 0) { + $arg = substr($msg, 8); + + if (strcasecmp($arg, "auth") == 0) { + $user->flags |= USER_FLAG_LISTAUTH; + $to_user = 'list_set(\'auth\', true, \'(solo aut.)\'); '; + } + else { + $user->flags &= ~USER_FLAG_LISTAUTH; + $to_user = 'list_set(\'all\', true, \'\'); '; + } + } else if (strncmp($msg, "/garante", 8) == 0) { if ($user->flags & USER_FLAG_AUTH) { $to_user = sprintf('authbox(300,200);'); @@ -1496,6 +1308,15 @@ class Room { $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Per autenticare qualcuno devi a tua volta essere autenticato.");', $dt, NICKSERV); } } + else if (strncmp($msg, "/mesgtoadm", 8) == 0) { + if ($user->flags & USER_FLAG_AUTH) { + $to_user = sprintf('mesgtoadmbox(500,300);'); + } + else { + /* MLANG: "Per inviare un messaggio devi essere autenticato." */ + $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Per inviare un messaggio devi essere autenticato.");', $dt, NICKSERV); + } + } else if (strncmp($msg, "/nick ", 6) == 0) { log_main("chatt_send BEGIN"); @@ -1595,6 +1416,7 @@ class Room { } // nick chat command else { // normal chat line + $is_normchat = TRUE; if ($curtime < ($user->chat_ban + $user->chat_dlt)) { $only_you = TRUE; $user->chat_dlt = $user->chat_dlt * 2; @@ -1655,6 +1477,14 @@ class Room { if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user) continue; + if ($is_normchat == TRUE) { + if ($user_cur->flags & USER_FLAG_LISTAUTH) { + if (($user->flags & USER_FLAG_AUTH) == 0) { + continue; + } + } + } + $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; "; $user_cur->comm[$user_cur->step % COMM_N] .= $to_room; $user_cur->step_inc(); @@ -1662,6 +1492,8 @@ class Room { } if ($to_tabl) { + // FIXME BRISK4: include for each kind of table + require_once("briskin5/Obj/briskin5.phh"); // Before all align times with table timeout for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) { $table_cur =& $this->table[$table_idx]; @@ -1758,7 +1590,7 @@ class Room { function &add_user(&$sess, &$idx, $name, $pass, $ip) { - GLOBAL $G_false; + GLOBAL $G_false, $CO_list; $idx = 0; @@ -1837,6 +1669,8 @@ class Room { // If user at the table we need to update the table data too $table_idx = $ghost_user->table; if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) { + // FIXME BRISK4: include for each kind of table + require_once("briskin5/Obj/briskin5.phh"); if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) { if (($bri = &Briskin5::load_data($table_idx)) != FALSE) { if ($bri->the_end != TRUE) { @@ -1873,7 +1707,15 @@ class Room { $this->user[$idx]->ip = $ip; $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00); + + if ($authenticate) { + $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; + if (isset($CO_list) && strcmp($CO_list, "all") == 0) { + $this->user[$idx]->flags &= ~USER_FLAG_LISTAUTH; + } + } + if ($ghost > -1) { log_main("ghost: rename!"); $ghost_user =& $this->user[$ghost];