5 * Copyright (C) 2006-2011 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
26 define('BRISK_CONF', "brisk.conf.pho");
27 define('FTOK_PATH', "/var/lib/brisk");
28 define('LEGAL_PATH', "/tmp/legal_brisk");
29 define('PROXY_PATH', "/var/lib/brisk_proxy");
30 define('TABLES_N', 36);
31 define('TABLES_AUTH_N', 4);
32 define('PLAYERS_N', 3);
33 define('MAX_POINTS', 5);
34 define('MAX_PLAYERS', (20 + (PLAYERS_N * TABLES_N)));
35 define('SHM_DIMS_MIN', (50000 + 10000 * TABLES_N + 15000 * MAX_PLAYERS));
36 define('SHM_DIMS_MAX', SHM_DIMS_MIN + 1048576);
37 define('SHM_DIMS_DLT', 65536);
39 define('SHM_DIMS_U_MIN', 4096);
40 define('SHM_DIMS_U_MAX', 65536);
41 define('SHM_DIMS_U_DLT', 4096);
44 define('COMM_GEN_N', 50);
47 define('CHAT_ILL_TIME', 6);
49 define('SESS_LEN', 13);
50 define('STREAM_TIMEOUT', 60);
51 /* FIXME: move to sac-a-push .phh */
52 define('EXPIRE_TIME_RD', 180);
53 define('EXPIRE_TIME_SMAMMA', 360);
54 define('EXPIRE_TIME_WAG', 10);
55 define('WAKEUP_TIME', 12);
56 // BAN_TIME da allineare anche in commons.js
57 define('BAN_TIME', 3600);
58 define('GARBAGE_TIMEOUT', 10);
59 define('NICKSERV', "<i>BriskServ</i>");
61 define('LOCK_SHARE_MAX', 10000);
63 define('DBG_ONL2', 0x0001);
64 define('DBG_ONLY', 0x0002);
65 define('DBG_MAIN', 0x0004);
66 define('DBG_READ', 0x0008);
67 define('DBG_REA2', 0x0010);
68 define('DBG_SEND', 0x0020);
69 define('DBG_LOCK', 0x0040);
70 define('DBG_WRIT', 0x0080);
71 define('DBG_LOAD', 0x0100);
72 define('DBG_AUTH', 0x0200);
73 define('DBG_CRIT', 0x0400);
74 define('DBG_LMOP', 0x0800);
75 define('DBG_TRAC', 0x1000);
76 define('DBG_SHME', 0x2000);
77 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
78 define('BRISK_DEBUG', 0x0800);
80 define('BRISK_SINGLE_DEBUG',0);
81 define('BRISK_SINGLE_SESS', "");
82 define('DEBUGGING', "no-debugging");
84 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
86 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
87 'en' => 'back standing' ),
88 'btn_close' => array( 'it' => 'chiudi',
91 'tit_all' => array( 'it' => 'tutti',
94 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
95 'en' => '<br>You are being idle for ' ),
96 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
97 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
98 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
99 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
100 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
101 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
102 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
103 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
104 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
105 'en' => '<br>The entered password is not correct.<br><br>'),
106 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
107 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
108 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
109 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
110 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
111 'en' => '<b>To send a message you have to be authenticated.</b>'),
112 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
113 'en' => 'The nickname have to contain at least one letter or one number.'),
114 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
115 'en' => 'The nickname <b>%s</b> is already in use.'),
116 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
117 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
118 'nickjust' => array( 'it' => 'Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>',
119 'en' => 'The nickname <b>\'%s\'</b> is already registered, <b>if its proprietary will authenticate you will named again officially ghost<i>N</i>.</b>'), // FIXME: him ???
120 'statunkn' => array( 'it' => 'Questo stato non esiste.',
121 'en' => 'This state don\'t exists.'),
122 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
123 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
124 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
125 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
127 'tit_onauth'=>array( 'it' => '(solo aut.)',
128 'en' => '(only aut.)'),
129 'tit_onisol'=>array( 'it' => '(isolam.to)',
130 'en' => '(isolation)'),
131 '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.',
132 'en' => 'Connection to the database failed<br>All authentications are suspended temporarly, you login as normal user.<br>We are about the limitation')
137 $G_lng = langtolng($G_lang);
139 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
140 $G_brisk_version = "3.6.3";
142 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
143 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo sistema di evidenziazione degli utenti registrati.',
144 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
145 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: usage of reader/writer locking instead of generic exclusive locking.',
146 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
148 $G_room_help = array( 'it' => '
149 <div style=\\"text-align: left; padding: 8px;\\">
150 <b>Descrizione</b><br>
151 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
152 <a target=\\"_blank\\" href=\\"http://it.wikipedia.org/wiki/Briscola#Gioco_a_5\\">Wikipedia</a>; in breve è la variante con l\'asta prima sulla carta e poi sui punti.<br><br>
153 <b>Configurazione del browser.</b><br>
154 Occorre abilitare i cookies.<br>
156 <b>Uso del sito</b><br>
157 Potete sedervi a un tavolo o rimanere in piedi.<br>
158 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
161 All\'inizio vengono distribuite le carte e parte l\'asta; per partecipare all\'asta, quando sarà il vostro turno, potrete scegliere se andare avanti o passare cliccando sulle icone corrispondenti. Se si arriva ai punti, scrivete nella textbox il vostro rilancio e cliccate PUNTI.<br><br>
162 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
163 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
164 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
165 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
166 Dopo che è iniziata una partita per uscirne dovete chiedere agli altri giocatori di sbloccarla cliccando sul lucchetto. Se non si segue questa prassi, una volta usciti, non vi potrete sedere a nessun tavolo per '.floor(BAN_TIME/60).' minuti.
168 <dt><b>Comandi della chat</b>
169 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
170 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
171 <dd><b>/st <i><stato></i></b> - cambia l\'icona associata al tuo user; <i>stato</i> può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
172 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
173 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
174 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
180 <div style=\\"text-align: left; padding: 8px;\\">
181 <b>EN Descrizione</b><br>
182 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
183 <a target=\\"_blank\\" href=\\"http://it.wikipedia.org/wiki/Briscola#Gioco_a_5\\">Wikipedia</a>; in breve è la variante con l\'asta prima sulla carta e poi sui punti.<br><br>
184 <b>EN Configurazione del browser.</b><br>
185 Occorre abilitare i cookies.<br>
187 <b>Uso del sito</b><br>
188 Potete sedervi a un tavolo o rimanere in piedi.<br>
189 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
192 All\'inizio vengono distribuite le carte e parte l\'asta; per partecipare all\'asta, quando sarà il vostro turno, potrete scegliere se andare avanti o passare cliccando sulle icone corrispondenti. Se si arriva ai punti, scrivete nella textbox il vostro rilancio e cliccate PUNTI.<br><br>
193 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
194 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
195 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
196 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
197 Dopo che è iniziata una partita per uscirne dovete chiedere agli altri giocatori di sbloccarla cliccando sul lucchetto. Se non si segue questa prassi, una volta usciti, non vi potrete sedere a nessun tavolo per '.floor(BAN_TIME/60).' minuti.
199 <dt><b>Comandi della chat</b>
200 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
201 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
202 <dd><b>/st <i><stato></i></b> - cambia l\'icona associata al tuo user; <i>stato</i> può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
203 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
204 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
205 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
211 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
212 <div style=\\"text-align: left; padding: 8px;\\">
213 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
215 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
216 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
218 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
219 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
220 <li>Smart card di InfoCamere
223 <b>Per auto-garantisi occorre possedere:</b><br><br>
225 <li>il codice PIN della propria carta
226 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
229 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
231 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
234 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
235 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
240 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
241 <div style=\\"text-align: left; padding: 8px;\\">
242 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
244 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
245 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
247 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
248 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
251 <b>Per auto-garantisi occorre possedere:</b><br><br>
253 <li>il codice PIN della propria carta
254 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
257 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
259 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
262 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
263 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
269 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
273 $G_room_about = array( 'it' => '<br>
274 <div id=\\"header\\" class=\\"header\\">
275 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
276 briscola chiamata in salsa ajax
278 <br><b>version '.$G_brisk_version.'</b><br><br>
279 Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
281 <div id=\\"header\\" class=\\"header\\">
282 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
283 declaration briscola in ajax sauce <b>(Beta)</b>
285 <br><b>version '.$G_brisk_version.'</b><br><br>
286 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
290 for ($i = 0; $i < ob_get_level(); $i++)
292 ob_implicit_flush(1);
296 function file_lock($fname, $is_exclusive)
298 if (($res = @fopen($fname, "r+")) == FALSE) {
302 if (flock($res, ($is_exclusive ? LOCK_EX : LOCK_SH)) == FALSE) {
310 function file_unlock($res)
313 flock($res, LOCK_UN);
318 function webservers_exceeded()
320 return(file_exists(PROXY_PATH."/webservers_exceded.flag"));
323 function webservers_check()
325 GLOBAL $G_webserver_max;
327 /* FIXME: check all procs expirations */
332 $dh = opendir('/proc');
333 while (($file = readdir($dh)) !== false) {
334 if (preg_match('/[0-9]+/', $file)) {
335 $cmdline = explode("\0", file_get_contents('/proc/'.$file.'/cmdline'));
336 // echo "xxx".$cmdline[0].$n;
337 if (strstr('/usr/sbin/apache2', $cmdline[0]) != FALSE) {
338 // echo "yyy".$cmdline[0].$n;
345 if ($ct >= $G_webserver_max) {
346 touch(PROXY_PATH."/webservers_exceded.flag");
349 unlink(PROXY_PATH."/webservers_exceded.flag");
354 $escpush_from = array("\\", "\"");
355 $escpush_to = array("\\\\", "\\\"");
358 GLOBAL $escpush_from, $escpush_to;
360 return str_replace($escpush_from, $escpush_to, $s);
363 $escinp_from = array( "\"" );
364 $escinp_to = array( """ );
366 function escinput($s)
368 GLOBAL $escinp_from, $escinp_to;
370 return str_replace($escinp_from, $escinp_to, $s);
375 return htmlentities($s);
378 function esclfhtml($s)
380 return str_replace("\n", "<br>\n", htmlentities($s));
384 function langtolng($lang)
388 return ($G_lang == 'en' ? '-en' : '');
391 function csplitter($in, $sep)
397 for ($i = 0 ; $i < strlen($in) ; $i++) {
398 $ini = substr($in, $i, 1);
402 else if ($ini == $sep) {
421 $from = array ( '\\', '@', '|' );
422 $to = array ( '\\\\', '@', '¦' );
424 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
429 $from = array ( '\\', '|', "\t", "\n");
430 $to = array ( '\\\\', '\\|', "\\t", "\\n");
432 return (str_replace($from, $to, $s));
435 function xcapemesg($s)
437 $from = array ( "\n");
438 $to = array ( "\\n");
440 return (str_replace($from, $to, $s));
450 function getbyid($idx)
452 return ($this->el[$idx]);
455 function setbyid($idx, $v)
457 $this->el[$idx] = $v;
466 var $auth_only; // se tavolo riservato o libero
473 var $table_start; // information field
481 function create($idx)
483 if (($thiz = new Table()) == FALSE)
487 $thiz->player = array();
489 $thiz->auth_only = FALSE;
495 $thiz->table_token = "";
496 $thiz->table_start = 0;
498 $thiz->wakeup_time = 0;
505 $this->idx = $from->idx;
506 $this->player = array();
507 for ($i = 0 ; $i < $from->player_n ; $i++)
508 $this->player[$i] = $from->player[$i];
509 $this->player_n = $from->player_n;
511 log_main("PLAYER_N - parent::copy.".$this->player_n);
513 $this->auth_only = $from->auth_only;
515 $this->wag_own = $from->wag_own;
516 $this->wag_com = $from->wag_com;
517 $this->wag_tout = $from->wag_tout;
519 $this->table_token = $from->table_token;
520 $this->table_start = $from->table_start;
522 $this->wakeup_time = $from->wakeup_time;
525 function myclone($from)
527 if (($thiz = new Table()) == FALSE)
535 function spawn($from)
537 if (($thiz = new Table()) == FALSE)
540 $thiz->idx = $from->idx;
541 $thiz->player = array();
542 for ($i = 0 ; $i < $from->player_n ; $i++)
543 $thiz->player[$i] = $i;
544 $thiz->player_n = $from->player_n;
546 $thiz->auth_only = $from->auth_only;
548 $thiz->wag_own = $from->wag_own;
549 $thiz->wag_com = $from->wag_com;
550 $thiz->wag_tout = $from->wag_tout;
552 $thiz->table_token = $from->table_token;
553 $thiz->table_start = $from->table_start;
555 $thiz->wakeup_time = $from->wakeup_time;
560 function wag_set($user_idx, $mesg)
564 $this->wag_own = $user_idx;
565 $this->wag_com = $mesg;
569 function wag_reset($timeout)
571 log_main("WAG_RESET");
573 unset($this->wag_own);
576 $this->wag_tout = $timeout;
579 function player_get($idx)
581 return ($this->player[$idx]);
584 function player_set($idx, $player)
586 $this->player[$idx] = $player;
589 function user_add($idx)
591 $this->player[$this->player_n] = $idx;
594 return ($this->player_n - 1);
597 function user_rem($room, $user)
599 $tabpos = $user->table_pos;
601 /* verifico la consistenza dei dati */
602 if ($room->user[$this->player[$tabpos]] == $user) {
604 /* aggiorna l'array dei giocatori al tavolo. */
605 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
606 $this->player[$i] = $this->player[$i+1];
607 $user_cur = $room->user[$this->player[$i]];
608 $user_cur->table_pos = $i;
613 log_main("INCONSISTENCY ON TABLE.");
619 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
620 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
622 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
623 function act_content($user)
626 $isstanding = ($user->subst == 'standup');
627 $sitted = $this->player_n;
629 $cur_table = $user->table;
633 if ($sitted < PLAYERS_N) {
634 if ($this->auth_only) {
635 if ($user->flags & USER_FLAG_AUTH)
649 if ($table == $cur_table)
656 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
671 var $comm; // commands for many people
672 var $step; // current step of the comm array
673 // externalized var $garbage_timeout;
677 $this->user = array();
678 $this->table = array();
679 $this->match = array();
681 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
682 $this->user[$i] = User::create($this, $i, "", "");
685 for ($i = 0 ; $i < TABLES_N ; $i++) {
686 $this->table[$i] = Table::create($i);
689 $row = ( (((int)($i / 4)) % 2) == 0 );
690 $col = ($i % 2 == 0);
691 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
694 $this->table[$i]->auth_only = FALSE;
697 if ($i < TABLES_AUTH_N)
698 $this->table[$i]->auth_only = TRUE;
700 $this->table[$i]->auth_only = FALSE;
702 // externalized $this->garbage_timeout = 0;
703 Room::garbage_time_expire_set(0);
704 $this->shm_sz = SHM_DIMS_MIN;
707 function garbage_manager($force)
709 GLOBAL $G_lang, $mlang_brisk, $G_base;
713 log_rd2("garbage_manager START");
715 /* Garbage collector degli utenti in timeout */
718 // externalized if ($force || $this->garbage_timeout < $curtime) {
719 if (!$force && !Room::garbage_time_is_expired($curtime)) {
725 // Before all align times with table timeout
726 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
727 $table_cur = $this->table[$table_idx];
728 // if the table is complete and exists its shared mem we get the info about users lacc
730 if ($table_cur->player_n == PLAYERS_N) {
731 log_main("PLAYERS == N TABLE ".$table_idx);
734 $no_recovery = FALSE;
735 if (isset($this->match[$table_idx])) {
736 $bri = $this->match[$table_idx];
738 if ($table_cur->table_token != $bri->table_token) {
739 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
740 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
750 log_main("garbage_manager: bri loaded successfully.");
751 $bri->garbage_manager(TRUE);
753 $bri_table = $bri->table[0];
755 // is the end of the table
757 if ($bri->the_end == TRUE) {
759 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
761 log_main("garbage_manager: INSIDE THE END.");
763 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
764 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
765 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
768 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
769 // stat must be "table" by definition
770 $user_cur = $this->user[$table_cur->player[$i]];
771 $bri_user = $bri->user[$i];
773 $user_cur->subst = $bri_user->subst;
774 $user_cur->step = $bri_user->step;
775 $user_cur->lacc = $bri_user->lacc;
776 $user_cur->laccwr = $bri_user->lacc;
777 $user_cur->bantime = $bri_user->bantime;
780 log_legal($curtime, 'xxx', $user_cur, "STAT:DESTROY_GAME", $plist);
782 $this->room_join_wakeup($user_cur, FALSE, 0);
783 $table_cur->table_token = "";
784 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
786 $this->match_del($table_idx);
789 log_main("gm:: save_data");
791 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
792 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
795 } // if ($bri == FALSE
796 else if ($no_recovery == FALSE) {
797 log_crit("ERROR: table ".$table_idx." unrecoverable join");
799 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
800 $user_cur = $this->user[$table_cur->player[$i]];
801 $user_cur->subst = "shutdowner";
802 $user_cur->step_inc();
804 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
805 $ret .= "gst.st = ".($user_cur->step+1)."; ";
806 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
807 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
808 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
809 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
810 $user_cur->step_inc();
813 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
814 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
815 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
817 log_legal($curtime, 'xxx', $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
819 $this->room_join_wakeup($user_cur, TRUE, -2);
820 $table_cur->table_token = "";
823 } // if ($table_cur->player_n == PLAYERS_N) {
824 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
826 log_rd2("out new loop.");
828 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
829 $user_cur = $this->user[$i];
831 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
833 if ($user_cur->sess == "")
836 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
837 // Auto logout dell'utente
838 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
840 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
841 log_auth($user_cur->sess, "Autologout session.");
845 log_rd2("AUTO LOGOUT.");
846 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
847 $this->room_wakeup($user_cur);
848 else if ($user_cur->subst == 'standup')
849 $this->room_outstandup($user_cur);
851 log_rd2("LOGOUT FROM WHAT ???");
855 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
856 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
857 $this->room_wakeup($user_cur);
858 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
859 /* MLANG: <br>Sei stato inattivo per ".(EXPIRE_TIME_SMAMMA/60.0)." minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.", "torna ai tavoli" */
860 $user_cur->comm[$user_cur->step % COMM_N] .= show_notify($mlang_brisk['tabtout_a'][$G_lang].(EXPIRE_TIME_SMAMMA/60.0).$mlang_brisk['tabtout_b'][$G_lang], 0, $mlang_brisk['btn_backstand'][$G_lang], 400, 100);
861 $user_cur->step_inc();
865 log_rd2("GARBAGE UPDATED!");
867 // externalized $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
868 Room::garbage_time_expire_set($curtime + GARBAGE_TIMEOUT);
874 function show_room($user_step, $user)
876 GLOBAL $G_lang, $mlang_brisk;
877 log_main("show_room: username: ".$user->name);
879 $ret = sprintf('gst.st = %d; ', $user_step);
881 if ($user->flags & USER_FLAG_ISOLAUTH) {
882 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
884 else if ($user->flags & USER_FLAG_LISTAUTH) {
885 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
888 $ret .= 'list_set(\'all\', false, \'\' ); ';
891 if ($user->subst == 'standup')
892 $ret .= "tra.show(); ";
894 $ret .= "tra.hide(); ";
896 $ret .= sprintf('stat = "%s";', $user->stat);
898 $ret .= root_wellcome($user);
899 if ($user->flags & USER_FLAG_DBFAILED) {
900 $ret .= "gst.st = ".($user->step+1)."; ";
901 $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
904 $ret .= sprintf('subst = "%s";', $user->subst);
905 $ret .= $user->myname_innerHTML();
907 for ($i = 0 ; $i < TABLES_N ; $i++) {
909 $ret .= $this->table_content($user, $i);
910 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
911 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
912 $ret .= $this->table[$i]->act_content($user);
913 if ($this->table[$i]->wag_own != -1)
914 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
916 $ret .= sprintf('tra.rem(%d); ', $i);
918 $ret .= $this->standup_content($user);
924 function room_wakeup($user)
926 $table_idx = $user->table;
927 $table = $this->table[$table_idx];
929 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
933 $from_table = ($user->stat == "table");
935 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
937 for ($i = 0 ; $i < $table->player_n ; $i++) {
938 $user_cur = $this->user[$table->player[$i]];
939 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
941 if ($user->idx_get() != $table->player[$i]) {
942 $user_cur->stat_set("room");
943 $user_cur->subst = "sitdown";
944 $user_cur->laccwr = $curtime;
946 else if ($user->sess != "") {
947 $user_cur->stat_set("room");
948 $user_cur->subst = "standup";
949 $user_cur->laccwr = $curtime;
950 $user_cur->table = -1;
955 $user->stat_set("room");
956 $user->subst = "standup";
957 $user->laccwr = $curtime;
960 $remove_wagon = FALSE;
961 if($table->wag_own == $user->idx_get()) {
962 $table->wag_reset($curtime);
963 $remove_wagon = TRUE;
967 /* aggiorna l'array dei giocatori al tavolo. */
968 $table->user_rem($this, $user);
970 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
971 $user_cur = $this->user[$i];
972 if ($user_cur->sess == '' || $user_cur->stat != 'room')
975 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
977 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
978 if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
979 $ret .= 'gst.st_loc++; hstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
980 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
981 log_main("DOCUMENT.index.php: from table");
983 else if ($user_cur->stat == "room") {
984 log_main("DOCUMENT.index.php: from table");
986 $ret .= $this->table_content($user_cur, $table_idx);
987 $ret .= $this->standup_content($user_cur);
989 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
990 $ret .= $table->act_content($user);
992 if ($user->idx_get() == $i) {
993 // set the new status
994 $ret .= 'subst = "standup"; tra.show(); ';
995 // clean the action buttons in other tables
996 for ($e = 0 ; $e < TABLES_N ; $e++) {
997 if ($this->table[$e]->player_n < PLAYERS_N) {
998 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
999 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1000 $ret .= $this->table[$e]->act_content($user);
1005 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1006 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1007 $ret .= $table->act_content($user_cur);
1010 log_wr("ROOM_WAKEUP: ".$ret);
1011 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1012 $user_cur->step_inc();
1016 function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
1018 $table_idx = $user->table;
1019 $table = $this->table[$table_idx];
1021 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1024 $user_wup = array();
1026 $user_tab = array();
1028 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1030 for ($i = 0 ; $i < $table->player_n ; $i++) {
1031 $user_cur = $this->user[$table->player[$i]];
1032 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1033 if ($user_cur->sess != "") {
1034 if ($update_lacc == TRUE) {
1035 $user_cur->laccwr = $curtime;
1037 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1038 if ($user_cur->subst == "shutdowned") {
1039 $user_cur->stat_set("room");
1040 $user_cur->subst = "sitdown";
1042 else if ($user_cur->subst == "shutdowner") {
1043 $user_cur->stat_set("room");
1044 $user_cur->subst = "standup";
1045 $user_cur->table = -1;
1046 $user_wup[$user_wup_n++] = $user_cur;
1048 $remove_wagon = FALSE;
1049 if($table->wag_own == $table->player[$i]) {
1050 $remove_wagon = TRUE;
1051 $table->wag_reset($curtime);
1054 $user_tab[$user_tab_n++] = $table->player[$i];
1058 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1059 $table->user_rem($this, $user_wup[$wup_idx]);
1061 /* aggiorna l'array dei giocatori al tavolo. */
1063 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1064 log_main("START LOOP");
1065 $user_cur = $this->user[$i];
1066 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1067 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1072 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1074 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1075 if ($user_cur->stat == "room") {
1076 log_main("DOCUMENT.index.php from table");
1078 $ret .= $this->table_content($user_cur, $table_idx);
1079 $ret .= $this->standup_content($user_cur);
1081 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1082 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1083 $ret .= $table->act_content($user_cur);
1086 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1087 if ($user_tab[$tab_idx] == $i)
1090 // for users that wakeup the room will be reconstructed by index_rd.php
1091 if ($tab_idx < $user_tab_n) {
1092 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1094 // ARRAY_POP DISABLED
1095 // if ($trans_delta == 0)
1096 // while (array_pop($user_cur->comm) != NULL);
1098 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1099 $user_cur->comm[$user_cur->step % COMM_N] = "";
1100 $user_cur->step_inc();
1101 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
1102 $user_cur->step_inc();
1103 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1107 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1109 log_main("JOIN_WAKEUP more");
1110 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1111 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1112 $ret .= $table->act_content($user_cur);
1114 log_main("JOIN_WAKEUP end more");
1116 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1117 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1118 $user_cur->step_inc();
1122 function room_outstandup($user)
1124 $this->room_sitdown($user, -1);
1127 function table_update($user)
1129 log_main("table_update: pre - USER: ".$user->name);
1131 $table_idx = $user->table;
1133 if ($table_idx > -1)
1134 $table = $this->table[$table_idx];
1136 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1138 $user_cur = $this->user[$i];
1139 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1142 $ret = "gst.st = ".($user_cur->step+1)."; ";
1143 if ($table_idx > -1)
1144 $ret .= $this->table_content($user_cur, $table_idx);
1146 if ($user->idx_get() == $i) {
1147 $ret .= $user->myname_innerHTML();
1149 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1150 $user_cur->step_inc();
1153 log_main("table_update: post");
1156 function room_sitdown($user, $table_idx)
1158 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1162 if ($table_idx > -1 && $table_idx < TABLES_N) {
1163 $table = $this->table[$table_idx];
1166 if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
1167 for ($i = 0 ; $i < TABLES_N ; $i++) {
1168 if ($table->wag_own == $table->player[$i]) {
1169 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1170 $table->wag_reset(time());
1177 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1179 $user_cur = $this->user[$i];
1180 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1183 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1184 if ($table_idx > -1)
1185 $ret .= $this->table_content($user_cur, $table_idx);
1186 $ret .= $this->standup_content($user_cur);
1188 if ($user->idx_get() == $i) {
1189 $ret .= 'subst = "sitdown"; tra.hide(); ';
1190 // clean the action buttons in other tables
1191 for ($e = 0 ; $e < TABLES_N ; $e++) {
1192 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1193 $ret .= $this->table[$e]->act_content($user_cur);
1196 else if ($table_idx > -1) {
1197 if ($table->player_n == PLAYERS_N) {
1198 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1199 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1200 $ret .= $table->act_content($user_cur);
1203 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1204 $user_cur->step_inc();
1208 function chatt_send($user, $mesg)
1210 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1214 $msg = substr($mesg, 6, 128);
1216 $dt = date("H:i ", $curtime);
1227 $is_normchat = FALSE;
1228 /* for old isolation management $is_ticker = FALSE; */
1229 $update_room = FALSE;
1231 if (strcmp($msg, "/tav") == 0 ||
1232 strncmp($msg, "/tav ", 5) == 0) {
1234 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1235 /* MLANG: "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>", "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>", "<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>" */
1236 $msg = $mlang_brisk['tickmust'][$G_lang];
1237 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1242 $table = $this->table[$user->table];
1244 if ($table->wag_own != -1) {
1245 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1246 $msg = $mlang_brisk['tickjust'][$G_lang];
1247 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1252 $dtime = $curtime - $table->wag_tout;
1253 if ($dtime < EXPIRE_TIME_WAG) {
1254 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1255 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1256 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1257 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1262 $msg = substr($msg, 5);
1264 $table->wag_set($user->idx_get(), $msg);
1265 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1266 $to_room = $to_user;
1267 /* for old isolation management $is_ticker = TRUE; */
1269 } // /tav chat command
1271 else if (strncmp($msg, "/alarm ", 7) == 0) {
1272 if (strncmp($msg, "/alarm to ", 10) == 0) {
1273 $sp_pos = strpos($msg, " ", 10);
1274 $target = substr($msg, 10, $sp_pos - 10);
1275 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1279 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1282 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1283 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1284 $msg = $mlang_brisk['alarpass'][$G_lang];
1285 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1290 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1291 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1292 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1293 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1294 $dt, NICKSERV, $prestr);
1296 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1297 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1298 /* MLANG: "chiudi" */
1299 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1301 } // /alarm chat command
1302 else if (strncmp($msg, "/listen ", 8) == 0) {
1303 $arg = substr($msg, 8);
1305 if (strcasecmp($arg, "isolation") == 0) {
1307 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1308 $user->table >= TABLES_AUTH_N) {
1309 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1313 $user->flags &= ~USER_FLAG_MAP_AUTH;
1314 $user->flags |= USER_FLAG_ISOLAUTH;
1315 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1318 else if (strcasecmp($arg, "auth") == 0) {
1319 $flags_old = $user->flags;
1320 $user->flags &= ~USER_FLAG_MAP_AUTH;
1321 $user->flags |= USER_FLAG_LISTAUTH;
1322 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1325 $flags_old = $user->flags;
1326 $user->flags &= ~USER_FLAG_MAP_AUTH;
1327 $to_user = 'list_set(\'all\', true, \'\'); ';
1330 // if from isolation redraw standup area
1331 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1332 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1336 else if (strcmp($msg, "/authreq") == 0) {
1337 if ($user->flags & USER_FLAG_AUTH) {
1338 $to_user = sprintf('authbox(300,200);');
1341 /* MLANG: "<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>", "Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.", "Nickname <b>%s</b> già in uso." */
1342 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1345 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1346 if ($user->flags & USER_FLAG_AUTH) {
1347 $to_user = sprintf('mesgtoadmbox(500,300);');
1350 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1351 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1354 else if (strncmp($msg, "/nick ", 6) == 0) {
1355 log_main("chatt_send BEGIN");
1358 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1359 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1363 $msg = "COMMAND ".$msg;
1364 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1365 $user_cur = $this->user[$i];
1367 if ($user_cur->sess == '')
1369 if (strcasecmp($user_cur->name,$name_new) == 0)
1372 if ($i < MAX_PLAYERS) {
1373 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1374 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1378 /* MLANG: "<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>", "Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>" */
1379 if ($user->flags & USER_FLAG_AUTH) {
1380 if (strcasecmp($user->name,$name_new) != 0) {
1381 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1382 ($user->subst == 'standup' ||
1383 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1386 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1387 for ($i = 0 ; $i < TABLES_N ; $i++) {
1388 $to_user .= $this->table[$i]->act_content($user);
1392 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1397 $user->name = $name_new; // OK - nick changed
1398 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1399 if (($user->flags & USER_FLAG_AUTH) == 0) {
1400 if (($bdb = BriskDB::create()) != FALSE) {
1402 /* 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>" */
1403 if ($bdb->login_exists($name_new)) {
1404 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1405 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1410 log_main("chatt_send start set");
1412 $update_room = TRUE;
1414 } // nick chat command
1416 else if (strncmp($msg, "/st ", 4) == 0) {
1417 log_main("chatt_send BEGIN");
1420 $st_str = substr($msg, 4);
1422 if (strcasecmp($st_str, "normale") == 0) {
1423 $st = USER_FLAG_S_NORM;
1425 else if (strcasecmp($st_str, "pausa") == 0) {
1426 $st = USER_FLAG_S_PAU;
1428 else if (strcasecmp($st_str, "fuori") == 0) {
1429 $st = USER_FLAG_S_OUT;
1431 else if (strcasecmp($st_str, "cane") == 0) {
1432 $st = USER_FLAG_S_DOG;
1434 else if (strcasecmp($st_str, "cibo") == 0) {
1435 $st = USER_FLAG_S_EAT;
1437 else if (strcasecmp($st_str, "lavoro") == 0) {
1438 $st = USER_FLAG_S_WRK;
1440 else if (strcasecmp($st_str, "sigaretta") == 0) {
1441 $st = USER_FLAG_S_SMK;
1443 else if (strcasecmp($st_str, "presente") == 0) {
1444 $st = USER_FLAG_S_EYE;
1446 else if (strcasecmp($st_str, "coniglio") == 0) {
1447 $st = USER_FLAG_S_RABB;
1449 else if (strcasecmp($st_str, "calcio") == 0) {
1450 $st = USER_FLAG_S_SOCC;
1452 else if (strcasecmp($st_str, "pupo") == 0) {
1453 $st = USER_FLAG_S_BABY;
1455 else if (strcasecmp($st_str, "pulizie") == 0) {
1456 $st = USER_FLAG_S_MOP;
1459 /* MLANG: "Questo stato non esiste." */
1460 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1464 log_main("chatt_send start set");
1465 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1466 $update_room = TRUE;
1467 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1470 } // nick chat command
1472 else { // normal chat line
1473 $is_normchat = TRUE;
1474 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1476 $user->chat_dlt = $user->chat_dlt * 2;
1477 if ($user->chat_dlt > 120)
1478 $user->chat_dlt = 120;
1480 else if ($user->chat_lst == $msg)
1482 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1483 $user->chat_ban = $curtime;
1484 $user->chat_dlt = 5;
1488 $user->chat_ban = 0;
1489 $user->chat_dlt = 0;
1493 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1496 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1497 // temporary silentiation for troll (will became array check)
1498 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1499 $to_room = $to_user;
1502 log_legal($curtime, 'xxx', $user,
1503 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1505 $user->chat_lst = "$msg";
1506 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1516 // Output to clients
1519 if ($to_user != FALSE) {
1520 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1521 $user->comm[$user->step % COMM_N] .= $to_user;
1525 if ($to_room != FALSE) {
1526 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1527 $user_cur = $this->user[$i];
1528 if ($target != "" && $user_cur->name != $target)
1530 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user->idx_get() == $i)
1533 if ($is_normchat == TRUE) {
1534 // use MAP_AUTH to check if auth or isolation
1535 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1536 if (($user->flags & USER_FLAG_AUTH) == 0) {
1542 else if ($is_ticker) {
1543 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1544 if ($user->table >= TABLES_AUTH_N)
1549 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1550 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1551 $user_cur->step_inc();
1556 // FIXME BRISK4: include for each kind of table
1557 require_once("${G_base}briskin5/Obj/briskin5.phh");
1558 // Before all align times with table timeout
1559 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1560 $table_cur = $this->table[$table_idx];
1561 // if the table is complete and exists its shared mem we get the info about users lacc
1563 if ($table_cur->player_n == PLAYERS_N) {
1564 log_main("PLAYERS == N TABLE ".$table_idx);
1566 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1567 log_main("bin5 lock data success");
1569 $no_recovery = FALSE;
1570 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1571 if ($table_cur->table_token != $bri->table_token) {
1572 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1577 if ($bri != FALSE) {
1578 $bri_table = $bri->table[0];
1579 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1580 // stat must be "table" by definition
1581 $bri_user = $bri->user[$i];
1583 if ($target != "" && $bri_user->name != $target)
1585 log_main("writa: ".$user_mesg);
1586 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1587 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1588 $bri_user->step_inc();
1590 Bin5::save_data($bri);
1592 Bin5::unlock_data($sem);
1594 } // if ($table_cur->player_n == PLAYERS_N) {
1595 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1596 } // if ($to_tabl == true ...
1599 if ($user->stat == 'room' && $user->subst == 'standup') {
1600 $this->standup_update($user);
1602 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1603 log_main("chatt_send pre table update");
1604 $this->table_update($user);
1605 log_main("chatt_send post table update");
1607 } // if ($update_room ...
1610 } // function chatt_send( ...
1612 function get_user($sess, &$idx)
1616 if (validate_sess($sess)) {
1617 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1618 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1621 $ret = $this->user[$i];
1625 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1626 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1627 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1630 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1637 * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1640 * if ($idx > -1 && ret == FALSE) => duplicated nick
1641 * if ($idx == -2 && ret == FALSE) => invalid name
1642 * if ($idx == -3 && ret == FALSE) => wrong password
1643 * if ($idx == -1 && ret == FALSE) => no space left
1644 * if ($idx == 0 && ret == user) => SUCCESS
1645 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
1648 function add_user(&$sess, &$idx, $name, $pass, $ip)
1650 GLOBAL $G_base, $CO_list;
1654 $authenticate = FALSE;
1656 $login_exists = FALSE;
1658 $ghost_auth = FALSE;
1663 if (($name_new = validate_name($name)) == FALSE) {
1668 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1669 if (validate_sess($sess) == FALSE)
1672 /* if pass != FALSE verify the login with pass */
1673 log_auth("XXX", "auth1");
1675 if (($bdb = BriskDB::create()) != FALSE) {
1677 if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
1678 log_auth("XXX", "auth2");
1679 $authenticate = $bdb->login_verify($name_new, $pass, $code);
1680 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
1682 if ($authenticate != FALSE) {
1683 $user_type = $authenticate->type_get();
1691 $login_exists = $bdb->login_exists($name_new);
1695 // if db is down, send a warning and verify only current users
1696 // no actions at this moment
1698 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1700 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1704 if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
1706 continue; // NOTE: CHECK IT !!
1708 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1709 if ($authenticate != FALSE) {
1711 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1722 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1724 /* there is another user logged with your account and you and him have authenticated => new user
1725 get the session of the old user */
1726 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
1729 $ghost_user = $this->user[$ghost];
1731 $ghost_user->step_inc();
1734 $ghost_user->sess = $sess;
1737 $ghost_user->sess = $sess;
1740 // If user at the table we need to update the table data too
1741 $table_idx = $ghost_user->table;
1742 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1743 // FIXME BRISK4: include for each kind of table
1744 require_once("${G_base}briskin5/Obj/briskin5.phh");
1745 if (($brisem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1746 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1747 if ($bri->the_end != TRUE) {
1748 $bri->user[$ghost_user->table_pos]->step_inc();
1749 $bri->user[$ghost_user->table_pos]->sess = $sess;
1750 Bin5::save_data($bri);
1753 Bin5::unlock_data($brisem);
1758 return ($this->user[$ghost]);
1760 else if ($idx != -1 && $i == MAX_PLAYERS) {
1765 $this->user[$idx]->sess = $sess;
1768 $this->user[$idx]->sess = $sess;
1770 $this->user[$idx]->name = $name_new; // OK - add new user
1771 $this->user[$idx]->stat_set("room");
1772 $this->user[$idx]->step_set(0);
1773 while (array_pop($this->user[$idx]->comm) != NULL);
1774 $this->user[$idx]->subst = "standup";
1775 $this->user[$idx]->lacc = $curtime;
1776 $this->user[$idx]->laccwr = $curtime;
1777 $this->user[$idx]->bantime = 0;
1778 $this->user[$idx]->ip = $ip;
1780 $this->user[$idx]->flags = $user_type;
1781 $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
1782 $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
1783 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
1786 if ($authenticate != FALSE) {
1787 $this->user[$idx]->code = $authenticate->code_get();
1788 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1790 if (isset($CO_list)) {
1791 if (strcmp($CO_list, "auth") == 0) {
1792 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1793 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1795 if (strcmp($CO_list, "isolation") == 0) {
1796 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1797 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
1800 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1806 log_main("ghost: rename!");
1807 $ghost_user = $this->user[$ghost];
1809 if ($ghost_auth == FALSE) {
1810 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1811 $ghostname = 'ghost'.$sfx;
1812 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1813 if (strcmp("", $this->user[$i]->sess) == 0)
1816 if (strcasecmp($this->user[$i]->name, $ghostname) == 0) {
1821 if ($ghostname != '')
1825 $ghost_user->name = $ghostname;
1827 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1828 $this->standup_update($ghost_user);
1831 log_main("chatt_send pre table update");
1832 $this->table_update($ghost_user);
1833 log_main("chatt_send post table update");
1835 } // if ($ghost_auth == FALSE
1837 // FIXME: cacciare il vecchio utente room && table (if needed)
1838 $ghost_user->the_end = TRUE;
1839 $ghost_user->lacc = 0;
1840 $this->garbage_manager(TRUE);
1842 } // if ($ghost > -1) {
1847 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s] count [%d] name [%s] code [%s]", $idx, $sess, $name_new, count($this->user),$this->user[$real_idx]->name, $this->user[$real_idx]->code));
1849 $ret = $this->user[$real_idx];
1856 function standup_update($user)
1858 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1859 $user_cur = $this->user[$i];
1860 if ($user_cur->sess == '')
1863 log_main("STANDUP START: ".$user_cur->stat);
1865 if ($user_cur->stat == 'room') {
1866 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1867 if ($user->idx_get() == $i) {
1868 $user_cur->comm[$user_cur->step % COMM_N] .= $user->myname_innerHTML();
1870 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1872 $user_cur->step_inc();
1878 static function create()
1886 function load_data()
1891 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1892 log_main("ftok failed");
1896 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1897 log_main("shmop_open failed");
1901 $shm_sz = SHM_DIMS_MIN;
1903 if ($shm = shm_attach($tok, $shm_sz)) {
1904 $room = @shm_get_var($shm, $tok); // CHECKED BELOW
1906 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1908 log_only("bri count ".count($room));
1910 if ($room == FALSE) {
1911 log_only("INIT MAIN DATA");
1914 $room = Room::create();
1916 log_shme("Room::create");
1918 if (Room::save_data($room) == FALSE)
1923 $room->shm_sz = $shm_sz;
1927 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1928 if (($room->user[$i] = User::load_data($i, FALSE)) == FALSE) {
1929 log_crit("User::load_data failed");
1933 if ($i < MAX_PLAYERS) {
1939 // SHSPLIT: load users from the shared memory
1948 function save_data_orig($room)
1956 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1959 while ($room->shm_sz < SHM_DIMS_MAX) {
1960 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1963 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1964 if (@shm_put_var($shm, $tok, $room) != FALSE) {
1968 if (shm_remove($shm) === FALSE) {
1969 log_only("REMOVE FALLITA");
1973 $room->shm_sz += SHM_DIMS_DLT;
1983 function save_data($room)
1990 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1993 // SHSPLIT: before save the $room you must save users,
1994 // detach from main struct and (then) reattach
1995 $user_park = array();
1996 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1997 $user_park[$i] = $room->user[$i];
1998 $room->user[$i] = FALSE;
2001 while ($room->shm_sz < SHM_DIMS_MAX) {
2002 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2005 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2006 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2007 log_shme("Room::save_data");
2011 if (shm_remove($shm) === FALSE) {
2012 log_only("REMOVE FALLITA");
2016 $room->shm_sz += SHM_DIMS_DLT;
2022 // SHSPLIT: reattach users to the room class
2023 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2024 User::save_data($user_park[$i], $i);
2025 $room->user[$i] = $user_park[$i];
2027 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
2032 static function lock_data($is_exclusive)
2034 if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) {
2035 self::$delta_t = microtime(TRUE);
2036 log_lock("LOCK room [".self::$delta_t."]");
2044 static function unlock_data($res)
2048 log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]");
2054 function standup_content($user)
2059 if ($user->stat != 'room')
2062 for ($i = 0 , $ct = 0 ; $ct < 4 && $i < MAX_PLAYERS ; $i++) {
2063 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2068 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2070 $content = ' j_stand_cont( [ ';
2072 for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
2073 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2076 $flags = $this->user[$i]->flags;
2078 if ($this->user[$i]->subst == "standup") {
2079 if ($user->idx_get() == $i) {
2083 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name));
2092 function table_content($user, $table_idx)
2098 // Si possono usare i dati nella classe table
2101 $sess = $user->sess;
2102 $table = $this->table[$table_idx];
2104 if ($user->stat != 'room')
2108 for ($i = 0 ; $i < $table->player_n ; $i++) {
2109 $user_cur = $this->user[$table->player[$i]];
2111 $flags = $user_cur->flags;
2113 if ($user->idx_get() == $table->player[$i])
2116 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2118 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2123 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2128 static function garbage_time_is_expired($tm)
2133 if (file_exists(PROXY_PATH) == FALSE)
2134 mkdir(PROXY_PATH, 0775, TRUE);
2135 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE)
2137 if (($s = fread($fp, 4)) == FALSE)
2139 if (mb_strlen($s, "ASCII") != 4)
2141 $arr = unpack('Le', $s);
2142 if ($arr['e'] > $tm)
2149 log_rd2("END: return ".($ret ? "TRUE" : "FALSE"));
2154 static function garbage_time_expire_set($tm)
2157 if (file_exists(PROXY_PATH) == FALSE)
2158 mkdir(PROXY_PATH, 0775, TRUE);
2159 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE)
2161 fwrite($fp, pack("L",$tm));
2170 function request_mgr(&$s_a_p, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
2172 printf("NEW_SOCKET (root): %d\n", intval($new_socket));
2178 index_main($this, $header_out, $addr, $get, $post, $cookie);
2179 $content = ob_get_contents();
2182 $s_a_p->pgflush_try_add($new_socket, 20, $header_out, $content);
2186 case "index_wr.php":
2188 index_wr_main($this, $addr, $get, $post, $cookie);
2189 $content = ob_get_contents();
2192 $s_a_p->pgflush_try_add($new_socket, 20, $header_out, $content);
2196 case "index_rd_ifra.php":
2198 if (!isset($cookie['sess'])
2199 || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)) {
2200 $content = User::stream_fini(TRUE);
2202 $s_a_p->pgflush_try_add($new_socket, 20, $header_out, $content);
2207 // close a previous opened index_read_ifra socket, if exists
2208 if (($prev = $user->rd_socket_get()) != NULL) {
2209 $s_a_p->socks_unset($user->rd_socket_get());
2210 fclose($user->rd_socket_get());
2211 printf("CLOSE AND OPEN AGAIN ON IFRA2\n");
2212 $user->rd_socket_set(NULL);
2216 $user->stream_init($header_out, $content, $get, $post, $cookie);
2218 $response = headers_render($header_out, -1).chunked_content($content);
2219 $response_l = mb_strlen($response, "ASCII");
2221 $wret = @fwrite($new_socket, $response, $response_l);
2222 if ($wret < $response_l) {
2223 printf("TROUBLES WITH FWRITE: %d\n", $wret);
2224 $user->rd_cache_set(mb_substr($content, $wret, $response_l - $wret, "ASCII"));
2227 $user->rd_cache_set("");
2229 fflush($new_socket);
2232 $s_a_p->socks_set($new_socket, $user);
2233 $user->rd_socket_set($new_socket);
2234 printf(" - qui ci siamo - ");
2242 /* FAR TODO: move all into an array of registered sub-apps */
2243 $subs = "briskin5/";
2244 $subs_l = strlen($subs);
2245 if (!strncmp($path, $subs, $subs_l)) {
2246 $ret = Bin5::request_mgr(&$s_a_p, &$header_out, &$new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie);
2255 function match_add($idx, $match)
2257 $this->match[$idx] = $match;
2260 function match_del($idx)
2262 unset($this->match[$idx]);
2265 function match_get($idx, $token)
2267 if (isset($this->match[$idx])) {
2269 || $token == $this->match[$idx]->table_token) {
2270 return ($this->match[$idx]);
2278 function make_seed()
2280 list($usec, $sec) = explode(' ', microtime());
2281 return (float) $sec + ((float) $usec * 100000);
2284 function btrace_line($ar)
2286 GLOBAL $G_btrace_pref_sub;
2289 for ($i = 0 ; $i < count($ar) ; $i++) {
2290 $with_class = isset($ar[$i]['class']);
2291 $with_file = isset($ar[$i]['file']);
2292 $ret .= sprintf("%s%s%s (%s:%d)", ($i == 0 ? "" : ", "),
2293 ($with_class ? $ar[$i]['class'].$ar[$i]['type'] : ""),
2294 $ar[$i]['function'], ($with_file ? str_replace($G_btrace_pref_sub, "", $ar[$i]['file']) : ""),
2295 ($with_file ? $ar[$i]['line'] : ""));
2301 function trace_ftok($id, $add)
2303 // NOTE: without space to use sed to substitute "= @ftok(" with "= @ftok("
2304 $tok=@ftok($id, $add);
2306 log_shme($tok.": ".$id." + ".$add);
2311 function log_mop($step, $log)
2313 GLOBAL $sess, $PHP_SELF;
2315 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2318 if (isset($sess) == FALSE)
2323 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2326 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2327 $btrace = btrace_line(debug_backtrace());
2330 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2331 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $log, $btrace));
2337 function log_only2($log)
2339 GLOBAL $sess, $PHP_SELF;
2341 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2344 if (isset($sess) == FALSE)
2349 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2352 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2353 $btrace = btrace_line(debug_backtrace());
2356 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2357 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2362 function log_crit($log)
2364 GLOBAL $sess, $PHP_SELF;
2366 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2369 if (isset($sess) == FALSE)
2374 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2377 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2378 $btrace = btrace_line(debug_backtrace());
2381 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2382 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2387 function log_only($log)
2389 GLOBAL $sess, $PHP_SELF;
2391 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2394 if (isset($sess) == FALSE)
2399 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2402 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2403 $btrace = btrace_line(debug_backtrace());
2406 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2407 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2412 function log_main($log)
2414 GLOBAL $sess, $PHP_SELF;
2416 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2419 if (isset($sess) == FALSE)
2424 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2427 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2428 $btrace = btrace_line(debug_backtrace());
2431 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2432 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2437 function log_rd($log)
2439 GLOBAL $sess, $PHP_SELF;
2441 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2444 if (isset($sess) == FALSE)
2449 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2452 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2453 $btrace = btrace_line(debug_backtrace());
2456 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2457 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2462 function log_rd2($log)
2464 GLOBAL $sess, $PHP_SELF;
2466 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2469 if (isset($sess) == FALSE)
2474 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2477 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2478 $btrace = btrace_line(debug_backtrace());
2482 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2483 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2488 function log_send($log)
2490 GLOBAL $sess, $PHP_SELF;
2492 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2495 if (isset($sess) == FALSE)
2500 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2503 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2504 $btrace = btrace_line(debug_backtrace());
2507 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2508 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2513 function log_lock($log)
2515 GLOBAL $sess, $PHP_SELF;
2517 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2520 if (isset($sess) == FALSE)
2525 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2528 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2529 $btrace = btrace_line(debug_backtrace());
2532 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2533 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2538 function log_wr($log)
2540 GLOBAL $sess, $PHP_SELF;
2542 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2545 if (isset($sess) == FALSE)
2550 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2553 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2554 $btrace = btrace_line(debug_backtrace());
2557 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2558 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2563 function log_load($log)
2565 GLOBAL $sess, $PHP_SELF;
2567 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2570 if (isset($sess) == FALSE)
2575 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2578 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2579 $btrace = btrace_line(debug_backtrace());
2582 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2583 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2588 function log_auth($sess, $log)
2592 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2595 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2598 if ((BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2599 $btrace = btrace_line(debug_backtrace());
2602 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2603 fwrite($fp, sprintf("LOAD: [%s] [%d] [%s] [%s]\n", $sess, time(), $log, $btrace));
2608 function log_shme($log)
2610 GLOBAL $sess, $PHP_SELF;
2612 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SHME) == 0)
2615 if (isset($sess) == FALSE)
2620 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SHME) == 0)
2623 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2624 $btrace = btrace_line(debug_backtrace());
2627 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2628 fwrite($fp, sprintf("SHME: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2635 // function log_legal($curtime, $sess, $name, $where, $mesg)
2636 function log_legal($curtime, $addr, $user, $where, $mesg)
2639 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2640 /* Unix time | session | nickname | IP | where was | mesg */
2641 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2642 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2643 $user->name, $addr, $where , $mesg));
2648 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2653 if ($sitted < PLAYERS_N) {
2661 if ($table == $cur_table)
2668 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2673 function show_notify($text, $tout, $butt, $w, $h)
2675 log_main("SHOW_NOTIFY: ".$text);
2676 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2679 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
2681 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2682 return sprintf('var noti = new notify_ex(gst,"%s",%d,"%s",%d,%d, %s, %d);', $text, $tout, $butt, $w, $h, ($is_opaque ? "true" : "false"), $block_time);
2686 function root_wellcome($user)
2688 GLOBAL $root_wellarr, $G_lang;
2692 $dt = date("H:i ", $curtime);
2694 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2695 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2702 function validate_sess($sess)
2704 if (strlen($sess) == SESS_LEN)
2710 function validate_name($name)
2712 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2714 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2716 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2723 function playsound($filename)
2725 return (sprintf('playsound("flasou", "%s");', $filename));
2728 function secstoword($secs)
2734 $mins = floor($secs / 60);
2736 if ($G_lang == 'en') {
2738 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
2741 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
2745 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2748 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2753 function sharedmem_sz($tok)
2755 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2756 log_main("shmop_open failed");
2759 $shm_sz = shmop_size($shm_id);
2760 shmop_close($shm_id);
2762 // log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2769 static function lock_data($is_exclusive)
2771 if (($res = file_lock(FTOK_PATH."/warrant", $is_exclusive)) != FALSE) {
2772 self::$delta_t = microtime(TRUE);
2773 log_lock("LOCK warrant [".self::$delta_t."]");
2781 static function unlock_data($res)
2785 log_lock("UNLOCK warrant [".(microtime(TRUE) - (self::$delta_t))."]");
2794 static function lock_data($is_exclusive)
2796 if (($res = file_lock(FTOK_PATH."/poll", $is_exclusive)) != FALSE) {
2797 self::$delta_t = microtime(TRUE);
2798 log_lock("LOCK poll [".self::$delta_t."]");
2806 static function unlock_data($res)
2810 log_lock("UNLOCK poll [".(microtime(TRUE) - (self::$delta_t))."]");