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 define('EXPIRE_TIME_RD', 180);
52 define('EXPIRE_TIME_SMAMMA', 360);
53 define('EXPIRE_TIME_WAG', 10);
54 define('WAKEUP_TIME', 12);
55 // BAN_TIME da allineare anche in commons.js
56 define('BAN_TIME', 3600);
57 define('GARBAGE_TIMEOUT', 10);
58 define('NICKSERV', "<i>BriskServ</i>");
60 define('LOCK_SHARE_MAX', 10000);
62 define('DBG_ONL2', 0x0001);
63 define('DBG_ONLY', 0x0002);
64 define('DBG_MAIN', 0x0004);
65 define('DBG_READ', 0x0008);
66 define('DBG_REA2', 0x0010);
67 define('DBG_SEND', 0x0020);
68 define('DBG_LOCK', 0x0040);
69 define('DBG_WRIT', 0x0080);
70 define('DBG_LOAD', 0x0100);
71 define('DBG_AUTH', 0x0200);
72 define('DBG_CRIT', 0x0400);
73 define('DBG_LMOP', 0x0800);
74 define('DBG_TRAC', 0x1000);
75 define('DBG_SHME', 0x2000);
76 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
77 define('BRISK_DEBUG', 0x0800);
79 define('BRISK_SINGLE_DEBUG',0);
80 define('BRISK_SINGLE_SESS', "");
81 define('DEBUGGING', "no-debugging");
83 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
85 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
86 'en' => 'back standing' ),
87 'btn_close' => array( 'it' => 'chiudi',
90 'tit_all' => array( 'it' => 'tutti',
93 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
94 'en' => '<br>You are being idle for ' ),
95 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
96 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
97 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
98 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
99 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
100 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
101 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
102 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
103 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
104 'en' => '<br>The entered password is not correct.<br><br>'),
105 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
106 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
107 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
108 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
109 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
110 'en' => '<b>To send a message you have to be authenticated.</b>'),
111 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
112 'en' => 'The nickname have to contain at least one letter or one number.'),
113 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
114 'en' => 'The nickname <b>%s</b> is already in use.'),
115 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
116 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
117 '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>',
118 '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 ???
119 'statunkn' => array( 'it' => 'Questo stato non esiste.',
120 'en' => 'This state don\'t exists.'),
121 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
122 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
123 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
124 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
126 'tit_onauth'=>array( 'it' => '(solo aut.)',
127 'en' => '(only aut.)'),
128 'tit_onisol'=>array( 'it' => '(isolam.to)',
129 'en' => '(isolation)'),
130 '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.',
131 'en' => 'Connection to the database failed<br>All authentications are suspended temporarly, you login as normal user.<br>We are about the limitation')
136 $G_lng = langtolng($G_lang);
138 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
139 $G_brisk_version = "3.6.3";
141 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
142 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo sistema di evidenziazione degli utenti registrati.',
143 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
144 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: usage of reader/writer locking instead of generic exclusive locking.',
145 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
147 $G_room_help = array( 'it' => '
148 <div style=\\"text-align: left; padding: 8px;\\">
149 <b>Descrizione</b><br>
150 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
151 <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>
152 <b>Configurazione del browser.</b><br>
153 Occorre abilitare i cookies.<br>
155 <b>Uso del sito</b><br>
156 Potete sedervi a un tavolo o rimanere in piedi.<br>
157 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
160 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>
161 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
162 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
163 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
164 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
165 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.
167 <dt><b>Comandi della chat</b>
168 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
169 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
170 <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\\"
171 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
172 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
173 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
179 <div style=\\"text-align: left; padding: 8px;\\">
180 <b>EN Descrizione</b><br>
181 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
182 <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>
183 <b>EN Configurazione del browser.</b><br>
184 Occorre abilitare i cookies.<br>
186 <b>Uso del sito</b><br>
187 Potete sedervi a un tavolo o rimanere in piedi.<br>
188 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
191 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>
192 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
193 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
194 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
195 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
196 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.
198 <dt><b>Comandi della chat</b>
199 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
200 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
201 <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\\"
202 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
203 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
204 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
210 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
211 <div style=\\"text-align: left; padding: 8px;\\">
212 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
214 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
215 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
217 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
218 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
219 <li>Smart card di InfoCamere
222 <b>Per auto-garantisi occorre possedere:</b><br><br>
224 <li>il codice PIN della propria carta
225 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
228 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
230 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
233 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
234 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
239 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
240 <div style=\\"text-align: left; padding: 8px;\\">
241 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
243 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
244 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
246 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
247 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
250 <b>Per auto-garantisi occorre possedere:</b><br><br>
252 <li>il codice PIN della propria carta
253 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
256 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
258 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
261 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
262 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
268 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
272 $G_room_about = array( 'it' => '<br>
273 <div id=\\"header\\" class=\\"header\\">
274 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
275 briscola chiamata in salsa ajax
277 <br><b>version '.$G_brisk_version.'</b><br><br>
278 Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
280 <div id=\\"header\\" class=\\"header\\">
281 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
282 declaration briscola in ajax sauce <b>(Beta)</b>
284 <br><b>version '.$G_brisk_version.'</b><br><br>
285 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
293 function file_lock($fname, $is_exclusive)
295 if (($res = @fopen($fname, "r+")) == FALSE) {
299 if (flock($res, ($is_exclusive ? LOCK_EX : LOCK_SH)) == FALSE) {
307 function file_unlock($res)
310 flock($res, LOCK_UN);
315 function webservers_exceeded()
317 return(file_exists(PROXY_PATH."/webservers_exceded.flag"));
320 function webservers_check()
322 GLOBAL $G_webserver_max;
324 /* FIXME: check all procs expirations */
329 $dh = opendir('/proc');
330 while (($file = readdir($dh)) !== false) {
331 if (preg_match('/[0-9]+/', $file)) {
332 $cmdline = explode("\0", file_get_contents('/proc/'.$file.'/cmdline'));
333 // echo "xxx".$cmdline[0].$n;
334 if (strstr('/usr/sbin/apache2', $cmdline[0]) != FALSE) {
335 // echo "yyy".$cmdline[0].$n;
342 if ($ct >= $G_webserver_max) {
343 touch(PROXY_PATH."/webservers_exceded.flag");
346 unlink(PROXY_PATH."/webservers_exceded.flag");
351 $escpush_from = array("\\", "\"");
352 $escpush_to = array("\\\\", "\\\"");
355 GLOBAL $escpush_from, $escpush_to;
357 return str_replace($escpush_from, $escpush_to, $s);
360 $escinp_from = array( "\"" );
361 $escinp_to = array( """ );
363 function escinput($s)
365 GLOBAL $escinp_from, $escinp_to;
367 return str_replace($escinp_from, $escinp_to, $s);
372 return htmlentities($s);
375 function esclfhtml($s)
377 return str_replace("\n", "<br>\n", htmlentities($s));
381 function langtolng($lang)
385 return ($G_lang == 'en' ? '-en' : '');
388 function csplitter($in, $sep)
394 for ($i = 0 ; $i < strlen($in) ; $i++) {
395 $ini = substr($in, $i, 1);
399 else if ($ini == $sep) {
418 $from = array ( '\\', '@', '|' );
419 $to = array ( '\\\\', '@', '¦' );
421 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
426 $from = array ( '\\', '|', "\t", "\n");
427 $to = array ( '\\\\', '\\|', "\\t", "\\n");
429 return (str_replace($from, $to, $s));
432 function xcapemesg($s)
434 $from = array ( "\n");
435 $to = array ( "\\n");
437 return (str_replace($from, $to, $s));
447 function getbyid($idx)
449 return ($this->el[$idx]);
452 function setbyid($idx, $v)
454 $this->el[$idx] = $v;
463 var $auth_only; // se tavolo riservato o libero
470 var $table_start; // information field
478 function create($idx)
480 if (($thiz = new Table()) == FALSE)
484 $thiz->player = array();
486 $thiz->auth_only = FALSE;
492 $thiz->table_token = "";
493 $thiz->table_start = 0;
495 $thiz->wakeup_time = 0;
502 $this->idx = $from->idx;
503 $this->player = array();
504 for ($i = 0 ; $i < $from->player_n ; $i++)
505 $this->player[$i] = $from->player[$i];
506 $this->player_n = $from->player_n;
508 log_main("PLAYER_N - parent::copy.".$this->player_n);
510 $this->auth_only = $from->auth_only;
512 $this->wag_own = $from->wag_own;
513 $this->wag_com = $from->wag_com;
514 $this->wag_tout = $from->wag_tout;
516 $this->table_token = $from->table_token;
517 $this->table_start = $from->table_start;
519 $this->wakeup_time = $from->wakeup_time;
522 function myclone($from)
524 if (($thiz = new Table()) == FALSE)
532 function spawn($from)
534 if (($thiz = new Table()) == FALSE)
537 $thiz->idx = $from->idx;
538 $thiz->player = array();
539 for ($i = 0 ; $i < $from->player_n ; $i++)
540 $thiz->player[$i] = $i;
541 $thiz->player_n = $from->player_n;
543 $thiz->auth_only = $from->auth_only;
545 $thiz->wag_own = $from->wag_own;
546 $thiz->wag_com = $from->wag_com;
547 $thiz->wag_tout = $from->wag_tout;
549 $thiz->table_token = $from->table_token;
550 $thiz->table_start = $from->table_start;
552 $thiz->wakeup_time = $from->wakeup_time;
557 function wag_set($user_idx, $mesg)
561 $this->wag_own = $user_idx;
562 $this->wag_com = $mesg;
566 function wag_reset($timeout)
568 log_main("WAG_RESET");
570 unset($this->wag_own);
573 $this->wag_tout = $timeout;
576 function player_get($idx)
578 return ($this->player[$idx]);
581 function player_set($idx, $player)
583 $this->player[$idx] = $player;
586 function user_add($idx)
588 $this->player[$this->player_n] = $idx;
591 return ($this->player_n - 1);
594 function user_rem($room, $user)
596 $tabpos = $user->table_pos;
598 /* verifico la consistenza dei dati */
599 if ($room->user[$this->player[$tabpos]] == $user) {
601 /* aggiorna l'array dei giocatori al tavolo. */
602 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
603 $this->player[$i] = $this->player[$i+1];
604 $user_cur = $room->user[$this->player[$i]];
605 $user_cur->table_pos = $i;
610 log_main("INCONSISTENCY ON TABLE.");
616 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
617 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
619 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
620 function act_content($user)
623 $isstanding = ($user->subst == 'standup');
624 $sitted = $this->player_n;
626 $cur_table = $user->table;
630 if ($sitted < PLAYERS_N) {
631 if ($this->auth_only) {
632 if ($user->flags & USER_FLAG_AUTH)
646 if ($table == $cur_table)
653 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
661 define('USER_FLAG_AUTH', 0x02);
663 define('USER_FLAG_MAP_AUTH', 0x0c);
664 define('USER_FLAG_LISTAUTH', 0x04);
665 define('USER_FLAG_ISOLAUTH', 0x08);
667 define('USER_FLAG_DBFAILED', 0x10);
670 define('USER_FLAG_S_NORM', 0x000); // done
671 define('USER_FLAG_S_PAU', 0x100); // done
672 define('USER_FLAG_S_OUT', 0x200); // done
673 define('USER_FLAG_S_DOG', 0x300); // done
674 define('USER_FLAG_S_EAT', 0x400); // done
675 define('USER_FLAG_S_WRK', 0x500); // done
676 define('USER_FLAG_S_SMK', 0x600); // done
677 define('USER_FLAG_S_EYE', 0x700); // done
678 define('USER_FLAG_S_RABB', 0x800); // done
679 define('USER_FLAG_S_SOCC', 0x900); // done
680 define('USER_FLAG_S_BABY', 0xa00); // done
681 define('USER_FLAG_S_MOP', 0xb00); // done
683 define('USER_FLAG_S_ALL', 0xf00); // done
685 /* type of user normal, supporter etc ... */
686 define('USER_FLAG_TY_ALL', 0xff0000); // done
687 define('USER_FLAG_TY_NORM', 0x010000); // done
688 define('USER_FLAG_TY_SUPER', 0x020000); // done
689 // ... other usefull status ...
690 define('USER_FLAG_TY_SUSPEND', 0x400000); // done
691 define('USER_FLAG_TY_DISABLE', 0x800000); // done
693 define('RD_STREAM_TIMEOUT', 4);
696 var $idx; // index in the users array when you are in game
697 var $idx_orig; // index in the users array when you aren't in game
698 var $code; // authentication code
699 var $name; // name of the user
700 var $sess; // session of the user
701 var $ip; // ip of the user
702 var $lacc; // last access (for the cleanup)
703 var $laccwr; // last access (for the cleanup)
704 var $bantime; // timeout to temporary ban
705 var $stat; // status (outdoor, room, table, game, ...)
706 var $subst; // substatus for each status
707 var $step; // step of the current status
708 var $trans_step; // step to enable transition between pages (disable == -1)
710 var $rd_socket; // socket handle of push stream
711 var $rd_endtime; // end time for push stream
712 var $rd_stat; // actual status of push stream
713 var $rd_subst; // actual substatus of push stream
714 var $rd_step; // actual step of push stream
715 var $rd_from; // referer
716 var $rd_scristp; // current script step (for each session)
717 var $rd_tout; // if no message are sent after RD_STREAM_TIMEOUT secs we send a keepalive from server
719 var $comm; // commands array
720 // var $asta_card; //
722 // var $handpt; // Total card points at the beginning of the current hand.
723 // var $exitislock; // Player can exit from the table ?
725 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
726 // it is allways ZERO
727 var $table; // id of the current table when you are in game
728 var $table_orig; // id of the current table when you aren't in game
729 var $table_pos; // idx on the table
730 var $table_token;// token that identify a game on a table
731 var $flags; // Bitfield with: AUTHENTICATE: 0x02
732 var $the_end; // Flag to change the end of the session
734 var $chat_lst; // Last chat line
735 var $chattime; // Array of chat times
736 var $chat_cur; // Current chat line number
737 var $chat_ban; // Time for ban chat
738 var $chat_dlt; // Delta t for ban
744 function create($idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
745 if (($thiz = new User()) == FALSE)
749 $thiz->idx_orig = $idx;
754 $thiz->lacc = time();
755 $thiz->laccwr = time();
758 $thiz->subst = $subst;
760 $thiz->trans_step = -1;
761 $thiz->comm = array();
763 $thiz->rd_socket = NULL;
764 $thiz->rd_endtime = -1;
766 $thiz->rd_subst = "";
769 $thiz->rd_scristp = -1;
772 $thiz->asta_card = -2;
773 $thiz->asta_pnt = -1;
775 $thiz->exitislock = TRUE;
779 $thiz->chattime = array_fill(0, CHAT_N, 0);
781 $thiz->chat_lst = "";
785 $thiz->table_orig = $table;
786 $thiz->table = $table;
787 $thiz->table_pos = -1;
788 $thiz->table_token= "";
789 $thiz->shm_sz = SHM_DIMS_U_MIN;
795 $this->idx = $from->idx;
796 $this->idx_orig = $from->idx;
797 $this->code = $from->code;
798 $this->name = $from->name;
799 $this->sess = $from->sess;
800 $this->ip = $from->ip;
801 $this->lacc = $from->lacc;
802 $this->laccwr = $from->laccwr;
803 $this->bantime = $from->bantime;
804 $this->stat = $from->stat;
805 $this->subst = $from->subst;
806 $this->step = $from->step;
807 $this->trans_step = $from->trans_step;
808 $this->comm = array();
810 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
811 for ($i = $i_start ; $i < $from->step ; $i++) {
813 if (isset($from->comm[$ii])) {
814 $this->comm[$ii] = $from->comm[$ii];
817 $this->asta_card = $from->asta_card;
818 $this->asta_pnt = $from->asta_pnt;
819 $this->handpt = $from->handpt;
820 $this->exitislock = $from->exitislock;
822 $this->flags = $from->flags;
824 $this->chattime = array();
825 for ($i = 0 ; $i < CHAT_N ; $i++)
826 $this->chattime[$i] = $from->chattime[$i];
827 $this->chat_cur = $from->chat_cur;
828 $this->chat_lst = $from->chat_lst;
829 $this->chat_ban = $from->chat_ban;
830 $this->chat_dlt = $from->chat_dlt;
832 $this->table_orig = $from->table_orig;
833 $this->table = $from->table;
834 $this->table_pos = $from->table_pos;
835 $this->table_token = $from->table_token;
836 $this->the_end = $from->the_end;
837 $this->shm_sz = $from->shm_sz;
842 function myclone($from)
844 if (($thiz = new User()) == FALSE)
852 function spawn($from, $table, $table_pos)
854 if (($thiz = new User()) == FALSE)
857 $thiz->idx = $from->idx;
858 $thiz->idx_orig = $from->idx;
859 $thiz->code = $from->code;
860 $thiz->name = $from->name;
861 $thiz->sess = $from->sess;
862 $thiz->ip = $from->ip;
863 $thiz->lacc = $from->lacc;
864 $thiz->laccwr = $from->laccwr;
865 $thiz->bantime = $from->bantime;
866 $thiz->stat = $from->stat;
867 $thiz->subst = $from->subst;
868 $thiz->step = $from->step;
869 $thiz->trans_step = $from->trans_step;
870 $thiz->comm = array();
873 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
874 for ($i = $i_start ; $i < $from->step ; $i++) {
875 log_wr("TRY PUSH:".$i);
877 $thiz->comm[$ii] = $from->comm[$ii];
880 $thiz->asta_card = $from->asta_card;
881 $thiz->asta_pnt = $from->asta_pnt;
882 $thiz->handpt = $from->handpt;
883 $thiz->exitislock = $from->exitislock;
884 $thiz->the_end = $from->the_end;
886 $thiz->flags = $from->flags;
888 $thiz->chattime = array_fill(0, CHAT_N, 0);
890 $thiz->chat_lst = "";
895 $thiz->table_orig = $table;
897 $thiz->table_pos = $table_pos;
898 $thiz->table_token = $from->table_token;
899 $thiz->shm_sz = $from->shm_sz;
904 function rd_data_set($curtime, $stat, $subst, $step, $from)
906 $this->rd_endtime = $curtime + STREAM_TIMEOUT;
907 $this->rd_stat = $stat;
908 $this->rd_subst = $subst;
909 $this->rd_step = $step;
910 $this->rd_from = $from;
911 $this->rd_scristp = 0;
912 $this->rd_tout = $curtime + RD_STREAM_TIMEOUT;
915 function rd_socket_get() {
916 return ($this->rd_socket);
919 function rd_socket_set($sock) {
920 $this->rd_socket = $sock;
923 function rd_tout_get()
925 return ($this->rd_tout);
928 function rd_tout_set($tm)
930 $this->rd_tout = $tm;
933 function rd_tout_is_expired($tm)
935 // printf("rd_tout %d tm %d\n", $this->rd_tout, $tm);
936 return ($this->rd_tout < $tm);
939 function rd_endtime_is_expired($tm)
941 // printf("rd_endtime %d tm %d\n", $this->rd_tout, $tm);
942 return ($this->rd_endtime < $tm);
945 function rd_tout_reset($tm)
947 $this->rd_tout = $tm + RD_STREAM_TIMEOUT;
954 function code_get() {
955 return ($this->code);
958 function stat_set($stat) {
959 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
960 $this->stat = "$stat";
963 if (validate_sess($this->sess)) {
964 if (file_exists(PROXY_PATH) == FALSE)
965 mkdir(PROXY_PATH, 0775, TRUE);
966 $fp = @fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
967 fwrite($fp, sprintf("%s\n",$this->stat));
973 function step_set($step)
975 $this->step = $step & 0x7fffffff;
980 function step_inc($delta = 1) {
981 $this->step += $delta;
982 /* modularization because unpack() not manage unsigned 32bit int correctly */
983 $this->step &= 0x7fffffff;
992 if (validate_sess($this->sess) == FALSE)
994 if (file_exists(PROXY_PATH) == FALSE)
995 mkdir(PROXY_PATH, 0775, TRUE);
996 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
998 fwrite($fp, pack("LL",$this->step, $this->idx));
1001 log_main("step_set [".$this->sess. "] [".$this->step."]");
1009 static function load_step($sess)
1013 if (validate_sess($sess) == FALSE)
1016 if (file_exists(PROXY_PATH) == FALSE)
1017 mkdir(PROXY_PATH, 0775, TRUE);
1018 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
1020 if (($s = fread($fp, 8)) == FALSE)
1022 if (mb_strlen($s, "ASCII") != 8)
1024 $arr = unpack('Ls/Li', $s);
1027 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
1034 log_rd2("STEP_GET [".$sess."]: return false ");
1039 static function unproxy_step($sess) {
1040 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
1041 if (file_exists(PROXY_PATH) == FALSE)
1043 @unlink(PROXY_PATH."/".$sess.".step");
1048 log_legal($curtime, $this, "STAT:LOGOUT", '');
1050 $tmp_sess = $this->sess;
1052 self::unproxy_step($tmp_sess);
1053 $this->name = ""; // OK here
1054 while (array_pop($this->comm) != NULL);
1056 $this->chattime = array_fill(0, CHAT_N, 0);
1057 $this->chat_cur = 0;
1058 $this->chat_lst = "";
1059 $this->chat_ban = 0;
1060 $this->chat_dlt = 0;
1061 $this->the_end = FALSE;
1064 static function load_data($id, $sess)
1066 log_main("load_data: id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
1069 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
1070 log_main("ftok failed");
1074 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1075 log_main("shmop_open failed");
1079 $shm_sz = SHM_DIMS_U_MIN;
1081 if ($shm = shm_attach($tok, $shm_sz)) {
1082 if (($user = @shm_get_var($shm, $tok)) == FALSE) {
1085 if ($sess != FALSE && $user->sess != $sess) {
1088 log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
1090 if ($user == FALSE) {
1091 log_only("INIT MAIN DATA");
1093 // SHSPLIT FIXME: init_data for User class ??
1094 $user = User::create($id, "", "");
1095 if (@shm_put_var($shm, $tok, $user) == FALSE) {
1096 log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
1097 log_only(serialize($user));
1099 log_shme("User::save_data2");
1102 if ($sess != FALSE) {
1104 * NOTE: this part is for check only, theoretically
1105 * user->step anch proxy_step are set allways at the same value
1107 $old_step = $user->step;
1108 $arr = User::load_step($sess);
1109 $user->step = $arr['s'];
1110 if ($old_step != $user->step) {
1111 log_crit("steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
1115 $user->shm_sz = $shm_sz;
1121 // SHSPLIT: load users from the shared memory
1130 static function save_data($user, $id)
1136 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
1139 while ($user->shm_sz < SHM_DIMS_U_MAX) {
1140 if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
1143 // log_only("PUT_VAR DI ".strlen(serialize($user)));
1144 if (@shm_put_var($shm, $tok, $user) != FALSE) {
1146 if ($user->sess != "")
1149 log_shme("User::save_data");
1151 log_main("User[".$id."] saved.");
1154 if (shm_remove($shm) === FALSE) {
1155 log_only("REMOVE FALLITA");
1159 $user->shm_sz += SHM_DIMS_U_DLT;
1168 function myname_innerHTML()
1170 $class_id = ($this->flags & USER_FLAG_AUTH) + 1;
1172 return (sprintf('$("myname").innerHTML = "<span class=\"au%d\">%s</span>";', $class_id,
1173 xcape($this->name,ENT_COMPAT,"UTF-8")));
1185 var $comm; // commands for many people
1186 var $step; // current step of the comm array
1187 // externalized var $garbage_timeout;
1191 $this->user = array();
1192 $this->table = array();
1194 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1195 $this->user[$i] = User::create($i, "", "");
1198 for ($i = 0 ; $i < TABLES_N ; $i++) {
1199 $this->table[$i] = Table::create($i);
1202 $row = ( (((int)($i / 4)) % 2) == 0 );
1203 $col = ($i % 2 == 0);
1204 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
1207 $this->table[$i]->auth_only = FALSE;
1210 if ($i < TABLES_AUTH_N)
1211 $this->table[$i]->auth_only = TRUE;
1213 $this->table[$i]->auth_only = FALSE;
1215 // externalized $this->garbage_timeout = 0;
1216 Room::garbage_time_expire_set(0);
1217 $this->shm_sz = SHM_DIMS_MIN;
1220 function garbage_manager($force)
1222 GLOBAL $G_lang, $mlang_brisk, $G_base;
1226 log_rd2("garbage_manager START");
1228 /* Garbage collector degli utenti in timeout */
1231 // externalized if ($force || $this->garbage_timeout < $curtime) {
1232 if (!$force && !Room::garbage_time_is_expired($curtime)) {
1237 // FIXME BRISK4: include for each kind of table
1238 require_once("${G_base}briskin5/Obj/briskin5.phh");
1240 // Before all align times with table timeout
1241 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1242 $table_cur = $this->table[$table_idx];
1243 // if the table is complete and exists its shared mem we get the info about users lacc
1245 if ($table_cur->player_n == PLAYERS_N) {
1246 log_main("PLAYERS == N TABLE ".$table_idx);
1248 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1249 log_main("bin5 lock data success");
1251 $no_recovery = FALSE;
1252 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1253 if ($table_cur->table_token != $bri->table_token) {
1254 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1255 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
1256 $no_recovery = TRUE;
1261 if ($bri != FALSE) {
1265 log_main("garbage_manager: bri loaded successfully.");
1266 $bri->garbage_manager(TRUE);
1268 $bri_table = $bri->table[0];
1270 // is the end of the table
1271 if ($bri->the_end == TRUE) {
1273 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
1275 log_main("garbage_manager: INSIDE THE END.");
1277 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
1278 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1279 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1282 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1283 // stat must be "table" by definition
1284 $user_cur = $this->user[$table_cur->player[$i]];
1285 $bri_user = $bri->user[$i];
1287 $user_cur->subst = $bri_user->subst;
1288 $user_cur->step = $bri_user->step;
1289 $user_cur->lacc = $bri_user->lacc;
1290 $user_cur->laccwr = $bri_user->lacc;
1291 $user_cur->bantime = $bri_user->bantime;
1294 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
1296 $this->room_join_wakeup($user_cur, FALSE, 0);
1297 $table_cur->table_token = "";
1298 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
1300 $bri->destroy_data($table_idx);
1303 log_main("gm:: save_data");
1305 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1306 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
1309 Bin5::save_data($bri);
1311 } // else if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1312 else if ($no_recovery == FALSE) {
1313 log_crit("ERROR: table ".$table_idx." unrecoverable join");
1315 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1316 $user_cur = $this->user[$table_cur->player[$i]];
1317 $user_cur->subst = "shutdowner";
1318 $user_cur->step_inc();
1320 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
1321 $ret .= "gst.st = ".($user_cur->step+1)."; ";
1322 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
1323 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
1324 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
1325 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1326 $user_cur->step_inc();
1329 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
1330 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1331 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1333 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
1335 $this->room_join_wakeup($user_cur, TRUE, -2);
1336 $table_cur->table_token = "";
1339 Bin5::unlock_data($sem);
1341 } // if ($table_cur->player_n == PLAYERS_N) {
1342 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1344 log_rd2("out new loop.");
1346 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1347 $user_cur = $this->user[$i];
1349 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1351 if ($user_cur->sess == "")
1354 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1355 // Auto logout dell'utente
1356 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1358 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1359 log_auth($user_cur->sess, "Autologout session.");
1363 log_rd2("AUTO LOGOUT.");
1364 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1365 $this->room_wakeup($user_cur);
1366 else if ($user_cur->subst == 'standup')
1367 $this->room_outstandup($user_cur);
1369 log_rd2("LOGOUT FROM WHAT ???");
1373 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1374 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1375 $this->room_wakeup($user_cur);
1376 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1377 /* 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" */
1378 $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);
1379 $user_cur->step_inc();
1383 log_rd2("GARBAGE UPDATED!");
1385 // externalized $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1386 Room::garbage_time_expire_set($curtime + GARBAGE_TIMEOUT);
1392 function show_room($user_step, $user)
1394 GLOBAL $G_lang, $mlang_brisk;
1395 log_main("show_room: username: ".$user->name);
1397 $ret = sprintf('gst.st = %d; ', $user_step);
1399 if ($user->flags & USER_FLAG_ISOLAUTH) {
1400 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
1402 else if ($user->flags & USER_FLAG_LISTAUTH) {
1403 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1406 $ret .= 'list_set(\'all\', false, \'\' ); ';
1409 if ($user->subst == 'standup')
1410 $ret .= "tra.show(); ";
1412 $ret .= "tra.hide(); ";
1414 $ret .= sprintf('stat = "%s";', $user->stat);
1416 $ret .= root_wellcome($user);
1417 if ($user->flags & USER_FLAG_DBFAILED) {
1418 $ret .= "gst.st = ".($user->step+1)."; ";
1419 $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
1422 $ret .= sprintf('subst = "%s";', $user->subst);
1423 $ret .= $user->myname_innerHTML();
1425 for ($i = 0 ; $i < TABLES_N ; $i++) {
1427 $ret .= $this->table_content($user, $i);
1428 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1429 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1430 $ret .= $this->table[$i]->act_content($user);
1431 if ($this->table[$i]->wag_own != -1)
1432 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
1434 $ret .= sprintf('tra.rem(%d); ', $i);
1436 $ret .= $this->standup_content($user);
1442 function room_wakeup($user)
1444 $table_idx = $user->table;
1445 $table = $this->table[$table_idx];
1447 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1451 $from_table = ($user->stat == "table");
1453 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1455 for ($i = 0 ; $i < $table->player_n ; $i++) {
1456 $user_cur = $this->user[$table->player[$i]];
1457 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1459 if ($user->idx_get() != $table->player[$i]) {
1460 $user_cur->stat_set("room");
1461 $user_cur->subst = "sitdown";
1462 $user_cur->laccwr = $curtime;
1464 else if ($user->sess != "") {
1465 $user_cur->stat_set("room");
1466 $user_cur->subst = "standup";
1467 $user_cur->laccwr = $curtime;
1468 $user_cur->table = -1;
1473 $user->stat_set("room");
1474 $user->subst = "standup";
1475 $user->laccwr = $curtime;
1478 $remove_wagon = FALSE;
1479 if($table->wag_own == $user->idx_get()) {
1480 $table->wag_reset($curtime);
1481 $remove_wagon = TRUE;
1485 /* aggiorna l'array dei giocatori al tavolo. */
1486 $table->user_rem($this, $user);
1488 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1489 $user_cur = $this->user[$i];
1490 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1493 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1495 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1496 if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
1497 $ret .= 'gst.st_loc++; hstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1498 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1499 log_main("DOCUMENT.index.php: from table");
1501 else if ($user_cur->stat == "room") {
1502 log_main("DOCUMENT.index.php: from table");
1504 $ret .= $this->table_content($user_cur, $table_idx);
1505 $ret .= $this->standup_content($user_cur);
1507 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1508 $ret .= $table->act_content($user);
1510 if ($user->idx_get() == $i) {
1511 // set the new status
1512 $ret .= 'subst = "standup"; tra.show(); ';
1513 // clean the action buttons in other tables
1514 for ($e = 0 ; $e < TABLES_N ; $e++) {
1515 if ($this->table[$e]->player_n < PLAYERS_N) {
1516 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1517 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1518 $ret .= $this->table[$e]->act_content($user);
1523 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1524 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1525 $ret .= $table->act_content($user_cur);
1528 log_wr("ROOM_WAKEUP: ".$ret);
1529 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1530 $user_cur->step_inc();
1534 function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
1536 $table_idx = $user->table;
1537 $table = $this->table[$table_idx];
1539 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1542 $user_wup = array();
1544 $user_tab = array();
1546 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1548 for ($i = 0 ; $i < $table->player_n ; $i++) {
1549 $user_cur = $this->user[$table->player[$i]];
1550 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1551 if ($user_cur->sess != "") {
1552 if ($update_lacc == TRUE) {
1553 $user_cur->laccwr = $curtime;
1555 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1556 if ($user_cur->subst == "shutdowned") {
1557 $user_cur->stat_set("room");
1558 $user_cur->subst = "sitdown";
1560 else if ($user_cur->subst == "shutdowner") {
1561 $user_cur->stat_set("room");
1562 $user_cur->subst = "standup";
1563 $user_cur->table = -1;
1564 $user_wup[$user_wup_n++] = $user_cur;
1566 $remove_wagon = FALSE;
1567 if($table->wag_own == $table->player[$i]) {
1568 $remove_wagon = TRUE;
1569 $table->wag_reset($curtime);
1572 $user_tab[$user_tab_n++] = $table->player[$i];
1576 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1577 $table->user_rem($this, $user_wup[$wup_idx]);
1579 /* aggiorna l'array dei giocatori al tavolo. */
1581 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1582 log_main("START LOOP");
1583 $user_cur = $this->user[$i];
1584 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1585 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1590 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1592 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1593 if ($user_cur->stat == "room") {
1594 log_main("DOCUMENT.index.php from table");
1596 $ret .= $this->table_content($user_cur, $table_idx);
1597 $ret .= $this->standup_content($user_cur);
1599 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1600 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1601 $ret .= $table->act_content($user_cur);
1604 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1605 if ($user_tab[$tab_idx] == $i)
1608 // for users that wakeup the room will be reconstructed by index_rd.php
1609 if ($tab_idx < $user_tab_n) {
1610 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1612 // ARRAY_POP DISABLED
1613 // if ($trans_delta == 0)
1614 // while (array_pop($user_cur->comm) != NULL);
1616 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1617 $user_cur->comm[$user_cur->step % COMM_N] = "";
1618 $user_cur->step_inc();
1619 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
1620 $user_cur->step_inc();
1621 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1625 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1627 log_main("JOIN_WAKEUP more");
1628 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1629 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1630 $ret .= $table->act_content($user_cur);
1632 log_main("JOIN_WAKEUP end more");
1634 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1635 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1636 $user_cur->step_inc();
1640 function room_outstandup($user)
1642 $this->room_sitdown($user, -1);
1645 function table_update($user)
1647 log_main("table_update: pre - USER: ".$user->name);
1649 $table_idx = $user->table;
1651 if ($table_idx > -1)
1652 $table = $this->table[$table_idx];
1654 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1656 $user_cur = $this->user[$i];
1657 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1660 $ret = "gst.st = ".($user_cur->step+1)."; ";
1661 if ($table_idx > -1)
1662 $ret .= $this->table_content($user_cur, $table_idx);
1664 if ($user->idx_get() == $i) {
1665 $ret .= $user->myname_innerHTML();
1667 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1668 $user_cur->step_inc();
1671 log_main("table_update: post");
1674 function room_sitdown($user, $table_idx)
1676 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1680 if ($table_idx > -1 && $table_idx < TABLES_N) {
1681 $table = $this->table[$table_idx];
1684 if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
1685 for ($i = 0 ; $i < TABLES_N ; $i++) {
1686 if ($table->wag_own == $table->player[$i]) {
1687 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1688 $table->wag_reset(time());
1695 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1697 $user_cur = $this->user[$i];
1698 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1701 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1702 if ($table_idx > -1)
1703 $ret .= $this->table_content($user_cur, $table_idx);
1704 $ret .= $this->standup_content($user_cur);
1706 if ($user->idx_get() == $i) {
1707 $ret .= 'subst = "sitdown"; tra.hide(); ';
1708 // clean the action buttons in other tables
1709 for ($e = 0 ; $e < TABLES_N ; $e++) {
1710 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1711 $ret .= $this->table[$e]->act_content($user_cur);
1714 else if ($table_idx > -1) {
1715 if ($table->player_n == PLAYERS_N) {
1716 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1717 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1718 $ret .= $table->act_content($user_cur);
1721 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1722 $user_cur->step_inc();
1726 function chatt_send($user, $mesg)
1728 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1732 $msg = substr($mesg, 6, 128);
1734 $dt = date("H:i ", $curtime);
1745 $is_normchat = FALSE;
1746 /* for old isolation management $is_ticker = FALSE; */
1747 $update_room = FALSE;
1749 if (strcmp($msg, "/tav") == 0 ||
1750 strncmp($msg, "/tav ", 5) == 0) {
1752 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1753 /* 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>" */
1754 $msg = $mlang_brisk['tickmust'][$G_lang];
1755 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1760 $table = $this->table[$user->table];
1762 if ($table->wag_own != -1) {
1763 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1764 $msg = $mlang_brisk['tickjust'][$G_lang];
1765 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1770 $dtime = $curtime - $table->wag_tout;
1771 if ($dtime < EXPIRE_TIME_WAG) {
1772 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1773 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1774 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1775 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1780 $msg = substr($msg, 5);
1782 $table->wag_set($user->idx_get(), $msg);
1783 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1784 $to_room = $to_user;
1785 /* for old isolation management $is_ticker = TRUE; */
1787 } // /tav chat command
1789 else if (strncmp($msg, "/alarm ", 7) == 0) {
1790 if (strncmp($msg, "/alarm to ", 10) == 0) {
1791 $sp_pos = strpos($msg, " ", 10);
1792 $target = substr($msg, 10, $sp_pos - 10);
1793 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1797 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1800 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1801 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1802 $msg = $mlang_brisk['alarpass'][$G_lang];
1803 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1808 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1809 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1810 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1811 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1812 $dt, NICKSERV, $prestr);
1814 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1815 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1816 /* MLANG: "chiudi" */
1817 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1819 } // /alarm chat command
1820 else if (strncmp($msg, "/listen ", 8) == 0) {
1821 $arg = substr($msg, 8);
1823 if (strcasecmp($arg, "isolation") == 0) {
1825 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1826 $user->table >= TABLES_AUTH_N) {
1827 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1831 $user->flags &= ~USER_FLAG_MAP_AUTH;
1832 $user->flags |= USER_FLAG_ISOLAUTH;
1833 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1836 else if (strcasecmp($arg, "auth") == 0) {
1837 $flags_old = $user->flags;
1838 $user->flags &= ~USER_FLAG_MAP_AUTH;
1839 $user->flags |= USER_FLAG_LISTAUTH;
1840 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1843 $flags_old = $user->flags;
1844 $user->flags &= ~USER_FLAG_MAP_AUTH;
1845 $to_user = 'list_set(\'all\', true, \'\'); ';
1848 // if from isolation redraw standup area
1849 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1850 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1854 else if (strcmp($msg, "/authreq") == 0) {
1855 if ($user->flags & USER_FLAG_AUTH) {
1856 $to_user = sprintf('authbox(300,200);');
1859 /* 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." */
1860 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1863 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1864 if ($user->flags & USER_FLAG_AUTH) {
1865 $to_user = sprintf('mesgtoadmbox(500,300);');
1868 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1869 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1872 else if (strncmp($msg, "/nick ", 6) == 0) {
1873 log_main("chatt_send BEGIN");
1876 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1877 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1881 $msg = "COMMAND ".$msg;
1882 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1883 $user_cur = $this->user[$i];
1885 if ($user_cur->sess == '')
1887 if (strcasecmp($user_cur->name,$name_new) == 0)
1890 if ($i < MAX_PLAYERS) {
1891 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1892 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1896 /* 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>" */
1897 if ($user->flags & USER_FLAG_AUTH) {
1898 if (strcasecmp($user->name,$name_new) != 0) {
1899 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1900 ($user->subst == 'standup' ||
1901 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1904 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1905 for ($i = 0 ; $i < TABLES_N ; $i++) {
1906 $to_user .= $this->table[$i]->act_content($user);
1910 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1915 $user->name = $name_new; // OK - nick changed
1916 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1917 if (($user->flags & USER_FLAG_AUTH) == 0) {
1918 if (($bdb = BriskDB::create()) != FALSE) {
1920 /* 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>" */
1921 if ($bdb->login_exists($name_new)) {
1922 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1923 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1928 log_main("chatt_send start set");
1930 $update_room = TRUE;
1932 } // nick chat command
1934 else if (strncmp($msg, "/st ", 4) == 0) {
1935 log_main("chatt_send BEGIN");
1938 $st_str = substr($msg, 4);
1940 if (strcasecmp($st_str, "normale") == 0) {
1941 $st = USER_FLAG_S_NORM;
1943 else if (strcasecmp($st_str, "pausa") == 0) {
1944 $st = USER_FLAG_S_PAU;
1946 else if (strcasecmp($st_str, "fuori") == 0) {
1947 $st = USER_FLAG_S_OUT;
1949 else if (strcasecmp($st_str, "cane") == 0) {
1950 $st = USER_FLAG_S_DOG;
1952 else if (strcasecmp($st_str, "cibo") == 0) {
1953 $st = USER_FLAG_S_EAT;
1955 else if (strcasecmp($st_str, "lavoro") == 0) {
1956 $st = USER_FLAG_S_WRK;
1958 else if (strcasecmp($st_str, "sigaretta") == 0) {
1959 $st = USER_FLAG_S_SMK;
1961 else if (strcasecmp($st_str, "presente") == 0) {
1962 $st = USER_FLAG_S_EYE;
1964 else if (strcasecmp($st_str, "coniglio") == 0) {
1965 $st = USER_FLAG_S_RABB;
1967 else if (strcasecmp($st_str, "calcio") == 0) {
1968 $st = USER_FLAG_S_SOCC;
1970 else if (strcasecmp($st_str, "pupo") == 0) {
1971 $st = USER_FLAG_S_BABY;
1973 else if (strcasecmp($st_str, "pulizie") == 0) {
1974 $st = USER_FLAG_S_MOP;
1977 /* MLANG: "Questo stato non esiste." */
1978 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1982 log_main("chatt_send start set");
1983 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1984 $update_room = TRUE;
1985 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1988 } // nick chat command
1990 else { // normal chat line
1991 $is_normchat = TRUE;
1992 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1994 $user->chat_dlt = $user->chat_dlt * 2;
1995 if ($user->chat_dlt > 120)
1996 $user->chat_dlt = 120;
1998 else if ($user->chat_lst == $msg)
2000 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
2001 $user->chat_ban = $curtime;
2002 $user->chat_dlt = 5;
2006 $user->chat_ban = 0;
2007 $user->chat_dlt = 0;
2011 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
2014 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
2015 // temporary silentiation for troll (will became array check)
2016 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
2017 $to_room = $to_user;
2020 log_legal($curtime, $user,
2021 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
2023 $user->chat_lst = "$msg";
2024 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
2034 // Output to clients
2037 if ($to_user != FALSE) {
2038 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
2039 $user->comm[$user->step % COMM_N] .= $to_user;
2043 if ($to_room != FALSE) {
2044 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2045 $user_cur = $this->user[$i];
2046 if ($target != "" && $user_cur->name != $target)
2048 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user->idx_get() == $i)
2051 if ($is_normchat == TRUE) {
2052 // use MAP_AUTH to check if auth or isolation
2053 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
2054 if (($user->flags & USER_FLAG_AUTH) == 0) {
2060 else if ($is_ticker) {
2061 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
2062 if ($user->table >= TABLES_AUTH_N)
2067 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
2068 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
2069 $user_cur->step_inc();
2074 // FIXME BRISK4: include for each kind of table
2075 require_once("${G_base}briskin5/Obj/briskin5.phh");
2076 // Before all align times with table timeout
2077 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
2078 $table_cur = $this->table[$table_idx];
2079 // if the table is complete and exists its shared mem we get the info about users lacc
2081 if ($table_cur->player_n == PLAYERS_N) {
2082 log_main("PLAYERS == N TABLE ".$table_idx);
2084 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
2085 log_main("bin5 lock data success");
2087 $no_recovery = FALSE;
2088 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
2089 if ($table_cur->table_token != $bri->table_token) {
2090 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
2095 if ($bri != FALSE) {
2096 $bri_table = $bri->table[0];
2097 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
2098 // stat must be "table" by definition
2099 $bri_user = $bri->user[$i];
2101 if ($target != "" && $bri_user->name != $target)
2103 log_main("writa: ".$user_mesg);
2104 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
2105 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
2106 $bri_user->step_inc();
2108 Bin5::save_data($bri);
2110 Bin5::unlock_data($sem);
2112 } // if ($table_cur->player_n == PLAYERS_N) {
2113 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
2114 } // if ($to_tabl == true ...
2117 if ($user->stat == 'room' && $user->subst == 'standup') {
2118 $this->standup_update($user);
2120 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
2121 log_main("chatt_send pre table update");
2122 $this->table_update($user);
2123 log_main("chatt_send post table update");
2125 } // if ($update_room ...
2128 } // function chatt_send( ...
2130 function get_user($sess, &$idx)
2134 if (validate_sess($sess)) {
2135 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2136 if (strcmp($sess, $this->user[$i]->sess) == 0) {
2139 $ret = $this->user[$i];
2143 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
2144 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
2145 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
2148 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
2155 * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
2158 * if ($idx > -1 && ret == FALSE) => duplicated nick
2159 * if ($idx == -2 && ret == FALSE) => invalid name
2160 * if ($idx == -3 && ret == FALSE) => wrong password
2161 * if ($idx == -1 && ret == FALSE) => no space left
2162 * if ($idx == 0 && ret == user) => SUCCESS
2163 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
2166 function add_user(&$sess, &$idx, $name, $pass, $ip)
2168 GLOBAL $G_base, $CO_list;
2172 $authenticate = FALSE;
2174 $login_exists = FALSE;
2176 $ghost_auth = FALSE;
2181 if (($name_new = validate_name($name)) == FALSE) {
2186 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
2187 if (validate_sess($sess) == FALSE)
2190 /* if pass != FALSE verify the login with pass */
2191 log_auth("XXX", "auth1");
2193 if (($bdb = BriskDB::create()) != FALSE) {
2195 if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
2196 log_auth("XXX", "auth2");
2197 $authenticate = $bdb->login_verify($name_new, $pass, $code);
2198 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
2200 if ($authenticate != FALSE) {
2201 $user_type = $authenticate->type_get();
2209 $login_exists = $bdb->login_exists($name_new);
2213 // if db is down, send a warning and verify only current users
2214 // no actions at this moment
2216 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2218 if (strcmp($sess, $this->user[$i]->sess) == 0) {
2222 if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
2224 continue; // NOTE: CHECK IT !!
2226 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
2227 if ($authenticate != FALSE) {
2229 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
2240 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
2242 /* there is another user logged with your account and you and him have authenticated => new user
2243 get the session of the old user */
2244 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
2247 $ghost_user = $this->user[$ghost];
2249 $ghost_user->step_inc();
2252 $ghost_user->sess = $sess;
2255 $ghost_user->sess = $sess;
2258 // If user at the table we need to update the table data too
2259 $table_idx = $ghost_user->table;
2260 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
2261 // FIXME BRISK4: include for each kind of table
2262 require_once("${G_base}briskin5/Obj/briskin5.phh");
2263 if (($brisem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
2264 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
2265 if ($bri->the_end != TRUE) {
2266 $bri->user[$ghost_user->table_pos]->step_inc();
2267 $bri->user[$ghost_user->table_pos]->sess = $sess;
2268 Bin5::save_data($bri);
2271 Bin5::unlock_data($brisem);
2276 return ($this->user[$ghost]);
2278 else if ($idx != -1 && $i == MAX_PLAYERS) {
2283 $this->user[$idx]->sess = $sess;
2286 $this->user[$idx]->sess = $sess;
2288 $this->user[$idx]->name = $name_new; // OK - add new user
2289 $this->user[$idx]->stat_set("room");
2290 $this->user[$idx]->step_set(0);
2291 while (array_pop($this->user[$idx]->comm) != NULL);
2292 $this->user[$idx]->subst = "standup";
2293 $this->user[$idx]->lacc = $curtime;
2294 $this->user[$idx]->laccwr = $curtime;
2295 $this->user[$idx]->bantime = 0;
2296 $this->user[$idx]->ip = $ip;
2298 $this->user[$idx]->flags = $user_type;
2299 $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
2300 $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
2301 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
2304 if ($authenticate != FALSE) {
2305 $this->user[$idx]->code = $authenticate->code_get();
2306 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2308 if (isset($CO_list)) {
2309 if (strcmp($CO_list, "auth") == 0) {
2310 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2311 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2313 if (strcmp($CO_list, "isolation") == 0) {
2314 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2315 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
2318 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2324 log_main("ghost: rename!");
2325 $ghost_user = $this->user[$ghost];
2327 if ($ghost_auth == FALSE) {
2328 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
2329 $ghostname = 'ghost'.$sfx;
2330 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2331 if (strcmp("", $this->user[$i]->sess) == 0)
2334 if (strcasecmp($this->user[$i]->name, $ghostname) == 0) {
2339 if ($ghostname != '')
2343 $ghost_user->name = $ghostname;
2345 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
2346 $this->standup_update($ghost_user);
2349 log_main("chatt_send pre table update");
2350 $this->table_update($ghost_user);
2351 log_main("chatt_send post table update");
2353 } // if ($ghost_auth == FALSE
2355 // FIXME: cacciare il vecchio utente room && table (if needed)
2356 $ghost_user->the_end = TRUE;
2357 $ghost_user->lacc = 0;
2358 $this->garbage_manager(TRUE);
2360 } // if ($ghost > -1) {
2365 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));
2367 $ret = $this->user[$real_idx];
2374 function standup_update($user)
2376 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2377 $user_cur = $this->user[$i];
2378 if ($user_cur->sess == '')
2381 log_main("STANDUP START: ".$user_cur->stat);
2383 if ($user_cur->stat == 'room') {
2384 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
2385 if ($user->idx_get() == $i) {
2386 $user_cur->comm[$user_cur->step % COMM_N] .= $user->myname_innerHTML();
2388 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
2390 $user_cur->step_inc();
2396 static function create()
2404 function load_data()
2409 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2410 log_main("ftok failed");
2414 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2415 log_main("shmop_open failed");
2419 $shm_sz = SHM_DIMS_MIN;
2421 if ($shm = shm_attach($tok, $shm_sz)) {
2422 $room = @shm_get_var($shm, $tok); // CHECKED BELOW
2424 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2426 log_only("bri count ".count($room));
2428 if ($room == FALSE) {
2429 log_only("INIT MAIN DATA");
2432 $room = Room::create();
2434 log_shme("Room::create");
2436 if (Room::save_data($room) == FALSE)
2441 $room->shm_sz = $shm_sz;
2445 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2446 if (($room->user[$i] = User::load_data($i, FALSE)) == FALSE) {
2447 log_crit("User::load_data failed");
2451 if ($i < MAX_PLAYERS) {
2457 // SHSPLIT: load users from the shared memory
2466 function save_data_orig($room)
2474 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2477 while ($room->shm_sz < SHM_DIMS_MAX) {
2478 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2481 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2482 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2486 if (shm_remove($shm) === FALSE) {
2487 log_only("REMOVE FALLITA");
2491 $room->shm_sz += SHM_DIMS_DLT;
2501 function save_data($room)
2508 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2511 // SHSPLIT: before save the $room you must save users,
2512 // detach from main struct and (then) reattach
2513 $user_park = array();
2514 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2515 $user_park[$i] = $room->user[$i];
2516 $room->user[$i] = FALSE;
2519 while ($room->shm_sz < SHM_DIMS_MAX) {
2520 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2523 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2524 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2525 log_shme("Room::save_data");
2529 if (shm_remove($shm) === FALSE) {
2530 log_only("REMOVE FALLITA");
2534 $room->shm_sz += SHM_DIMS_DLT;
2540 // SHSPLIT: reattach users to the room class
2541 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2542 User::save_data($user_park[$i], $i);
2543 $room->user[$i] = $user_park[$i];
2545 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
2550 static function lock_data($is_exclusive)
2552 if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) {
2553 self::$delta_t = microtime(TRUE);
2554 log_lock("LOCK room [".self::$delta_t."]");
2562 static function unlock_data($res)
2566 log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]");
2572 function standup_content($user)
2577 if ($user->stat != 'room')
2580 for ($i = 0 , $ct = 0 ; $ct < 4 && $i < MAX_PLAYERS ; $i++) {
2581 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2586 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2588 $content = ' j_stand_cont( [ ';
2590 for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
2591 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2594 $flags = $this->user[$i]->flags;
2596 if ($this->user[$i]->subst == "standup") {
2597 if ($user->idx_get() == $i) {
2601 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name));
2610 function table_content($user, $table_idx)
2616 // Si possono usare i dati nella classe table
2619 $sess = $user->sess;
2620 $table = $this->table[$table_idx];
2622 if ($user->stat != 'room')
2626 for ($i = 0 ; $i < $table->player_n ; $i++) {
2627 $user_cur = $this->user[$table->player[$i]];
2629 $flags = $user_cur->flags;
2631 if ($user->idx_get() == $table->player[$i])
2634 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2636 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2641 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2646 static function garbage_time_is_expired($tm)
2651 if (file_exists(PROXY_PATH) == FALSE)
2652 mkdir(PROXY_PATH, 0775, TRUE);
2653 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE)
2655 if (($s = fread($fp, 4)) == FALSE)
2657 if (mb_strlen($s, "ASCII") != 4)
2659 $arr = unpack('Le', $s);
2660 if ($arr['e'] > $tm)
2667 log_rd2("END: return ".($ret ? "TRUE" : "FALSE"));
2672 static function garbage_time_expire_set($tm)
2675 if (file_exists(PROXY_PATH) == FALSE)
2676 mkdir(PROXY_PATH, 0775, TRUE);
2677 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE)
2679 fwrite($fp, pack("L",$tm));
2691 function make_seed()
2693 list($usec, $sec) = explode(' ', microtime());
2694 return (float) $sec + ((float) $usec * 100000);
2697 function btrace_line($ar)
2699 GLOBAL $G_btrace_pref_sub;
2702 for ($i = 0 ; $i < count($ar) ; $i++) {
2703 $with_class = isset($ar[$i]['class']);
2704 $with_file = isset($ar[$i]['file']);
2705 $ret .= sprintf("%s%s%s (%s:%d)", ($i == 0 ? "" : ", "),
2706 ($with_class ? $ar[$i]['class'].$ar[$i]['type'] : ""),
2707 $ar[$i]['function'], ($with_file ? str_replace($G_btrace_pref_sub, "", $ar[$i]['file']) : ""),
2708 ($with_file ? $ar[$i]['line'] : ""));
2714 function trace_ftok($id, $add)
2716 // NOTE: without space to use sed to substitute "= @ftok(" with "= @ftok("
2717 $tok=@ftok($id, $add);
2719 log_shme($tok.": ".$id." + ".$add);
2724 function log_mop($step, $log)
2726 GLOBAL $sess, $PHP_SELF;
2728 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2731 if (isset($sess) == FALSE)
2736 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2739 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2740 $btrace = btrace_line(debug_backtrace());
2743 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2744 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $log, $btrace));
2750 function log_only2($log)
2752 GLOBAL $sess, $PHP_SELF;
2754 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2757 if (isset($sess) == FALSE)
2762 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2765 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2766 $btrace = btrace_line(debug_backtrace());
2769 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2770 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2775 function log_crit($log)
2777 GLOBAL $sess, $PHP_SELF;
2779 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2782 if (isset($sess) == FALSE)
2787 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2790 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2791 $btrace = btrace_line(debug_backtrace());
2794 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2795 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2800 function log_only($log)
2802 GLOBAL $sess, $PHP_SELF;
2804 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2807 if (isset($sess) == FALSE)
2812 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2815 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2816 $btrace = btrace_line(debug_backtrace());
2819 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2820 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2825 function log_main($log)
2827 GLOBAL $sess, $PHP_SELF;
2829 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2832 if (isset($sess) == FALSE)
2837 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2840 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2841 $btrace = btrace_line(debug_backtrace());
2844 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2845 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2850 function log_rd($log)
2852 GLOBAL $sess, $PHP_SELF;
2854 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2857 if (isset($sess) == FALSE)
2862 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2865 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2866 $btrace = btrace_line(debug_backtrace());
2869 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2870 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2875 function log_rd2($log)
2877 GLOBAL $sess, $PHP_SELF;
2879 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2882 if (isset($sess) == FALSE)
2887 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2890 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2891 $btrace = btrace_line(debug_backtrace());
2895 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2896 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2901 function log_send($log)
2903 GLOBAL $sess, $PHP_SELF;
2905 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2908 if (isset($sess) == FALSE)
2913 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2916 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2917 $btrace = btrace_line(debug_backtrace());
2920 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2921 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2926 function log_lock($log)
2928 GLOBAL $sess, $PHP_SELF;
2930 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2933 if (isset($sess) == FALSE)
2938 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2941 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2942 $btrace = btrace_line(debug_backtrace());
2945 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2946 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2951 function log_wr($log)
2953 GLOBAL $sess, $PHP_SELF;
2955 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2958 if (isset($sess) == FALSE)
2963 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2966 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2967 $btrace = btrace_line(debug_backtrace());
2970 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2971 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2976 function log_load($log)
2978 GLOBAL $sess, $PHP_SELF;
2980 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2983 if (isset($sess) == FALSE)
2988 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2991 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2992 $btrace = btrace_line(debug_backtrace());
2995 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2996 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
3001 function log_auth($sess, $log)
3005 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
3008 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
3011 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
3012 $btrace = btrace_line(debug_backtrace());
3015 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
3016 fwrite($fp, sprintf("LOAD: [%s] [%d] [%s] [%s]\n", $sess, time(), $log, $btrace));
3021 function log_shme($log)
3023 GLOBAL $sess, $PHP_SELF;
3025 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SHME) == 0)
3028 if (isset($sess) == FALSE)
3033 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SHME) == 0)
3036 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
3037 $btrace = btrace_line(debug_backtrace());
3040 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
3041 fwrite($fp, sprintf("SHME: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
3048 // function log_legal($curtime, $sess, $name, $where, $mesg)
3049 function log_legal($curtime, $user, $where, $mesg)
3053 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
3054 /* Unix time | session | nickname | IP | where was | mesg */
3055 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
3056 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
3057 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
3062 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
3067 if ($sitted < PLAYERS_N) {
3075 if ($table == $cur_table)
3082 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
3087 function show_notify($text, $tout, $butt, $w, $h)
3089 log_main("SHOW_NOTIFY: ".$text);
3090 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
3093 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
3095 log_main("SHOW_NOTIFY OPAQUE: ".$text);
3096 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);
3100 function root_wellcome($user)
3102 GLOBAL $root_wellarr, $G_lang;
3106 $dt = date("H:i ", $curtime);
3108 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
3109 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
3116 function validate_sess($sess)
3118 if (strlen($sess) == SESS_LEN)
3124 function validate_name($name)
3126 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
3128 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
3130 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
3137 function playsound($filename)
3139 return (sprintf('playsound("flasou", "%s");', $filename));
3142 function secstoword($secs)
3148 $mins = floor($secs / 60);
3150 if ($G_lang == 'en') {
3152 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
3155 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
3159 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
3162 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
3167 function sharedmem_sz($tok)
3169 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
3170 log_main("shmop_open failed");
3173 $shm_sz = shmop_size($shm_id);
3174 shmop_close($shm_id);
3176 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
3183 static function lock_data($is_exclusive)
3185 if (($res = file_lock(FTOK_PATH."/warrant", $is_exclusive)) != FALSE) {
3186 self::$delta_t = microtime(TRUE);
3187 log_lock("LOCK warrant [".self::$delta_t."]");
3195 static function unlock_data($res)
3199 log_lock("UNLOCK warrant [".(microtime(TRUE) - (self::$delta_t))."]");
3208 static function lock_data($is_exclusive)
3210 if (($res = file_lock(FTOK_PATH."/poll", $is_exclusive)) != FALSE) {
3211 self::$delta_t = microtime(TRUE);
3212 log_lock("LOCK poll [".self::$delta_t."]");
3220 static function unlock_data($res)
3224 log_lock("UNLOCK poll [".(microtime(TRUE) - (self::$delta_t))."]");