5 * Copyright (C) 2006-2012 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);
48 define('CHAT_ENABLED', TRUE);
50 define('SESS_LEN', 13);
51 define('STREAM_TIMEOUT', 60);
52 /* FIXME: move to sac-a-push .phh */
53 /* TIME_RD define the server-side timeout, after half of it a ping request
54 is sent to client, after this time the client is log out */
55 define('EXPIRE_TIME_RD', 180);
56 define('EXPIRE_TIME_SMAMMA', 360);
57 define('EXPIRE_TIME_WAG', 10);
58 define('WAKEUP_TIME', 12);
59 // BAN_TIME da allineare anche in commons.js
60 define('BAN_TIME', 3600);
61 define('GARBAGE_TIMEOUT', 5);
62 define('NICKSERV', "<i>BriskServ</i>");
64 define('LOCK_SHARE_MAX', 10000);
66 define('DBG_ONL2', 0x0001);
67 define('DBG_ONLY', 0x0002);
68 define('DBG_MAIN', 0x0004);
69 define('DBG_READ', 0x0008);
70 define('DBG_REA2', 0x0010);
71 define('DBG_SEND', 0x0020);
72 define('DBG_LOCK', 0x0040);
73 define('DBG_WRIT', 0x0080);
74 define('DBG_LOAD', 0x0100);
75 define('DBG_AUTH', 0x0200);
76 define('DBG_CRIT', 0x0400);
77 define('DBG_LMOP', 0x0800);
78 define('DBG_TRAC', 0x1000);
79 define('DBG_SHME', 0x2000);
80 define('DBG_ENGI', 0x4000);
81 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
82 define('BRISK_DEBUG', 0x0800);
84 define('BRISK_SINGLE_DEBUG',0);
85 define('BRISK_SINGLE_SESS', "");
86 define('DEBUGGING', "no-debugging");
88 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
90 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
91 'en' => 'back standing' ),
92 'btn_close' => array( 'it' => 'chiudi',
95 'tit_all' => array( 'it' => 'tutti',
98 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
99 'en' => '<br>You are being idle for ' ),
100 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
101 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
102 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
103 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
104 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
105 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
106 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
107 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
108 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
109 'en' => '<br>The entered password is not correct.<br><br>'),
110 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
111 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
112 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
113 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
114 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
115 'en' => '<b>To send a message you have to be authenticated.</b>'),
116 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
117 'en' => 'The nickname have to contain at least one letter or one number.'),
118 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
119 'en' => 'The nickname <b>%s</b> is already in use.'),
120 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
121 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
122 '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>',
123 '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 ???
124 'statunkn' => array( 'it' => 'Questo stato non esiste.',
125 'en' => 'This state don\'t exists.'),
126 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
127 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
128 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
129 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
131 'tit_onauth'=>array( 'it' => '(solo aut.)',
132 'en' => '(only aut.)'),
133 'tit_onisol'=>array( 'it' => '(isolam.to)',
134 'en' => '(isolation)'),
135 '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.',
136 'en' => 'Connection to the database failed<br>All authentications are suspended temporarly, you login as normal user.<br>We are about the limitation')
141 $G_lng = langtolng($G_lang);
143 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
144 $G_brisk_version = "4.10.1";
146 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
147 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: aggiunto il comando /cont per proseguire le partite.',
148 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
149 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: added /cont command to continue matches.',
150 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
152 $G_room_help = array( 'it' => '
153 <div style=\\"text-align: left; padding: 8px;\\">
154 <b>Descrizione</b><br>
155 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
156 <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>
157 <b>Configurazione del browser.</b><br>
158 Occorre abilitare i cookies.<br>
160 <b>Uso del sito</b><br>
161 Potete sedervi a un tavolo o rimanere in piedi.<br>
162 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
165 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>
166 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
167 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
168 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
169 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
170 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.
172 <dt><b>Comandi della chat</b>
173 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
174 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
175 <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\\"
176 <dd><b>/cont <i><id partita></i></b> - quando si è a un tavolo per garantiti, permette di proseguire una partita giocata in precedenza con gli stessi giocatori
177 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
178 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
179 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
185 <div style=\\"text-align: left; padding: 8px;\\">
186 <b>EN Descrizione</b><br>
187 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
188 <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>
189 <b>EN Configurazione del browser.</b><br>
190 Occorre abilitare i cookies.<br>
192 <b>Uso del sito</b><br>
193 Potete sedervi a un tavolo o rimanere in piedi.<br>
194 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
197 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>
198 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
199 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
200 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
201 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
202 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.
204 <dt><b>Comandi della chat</b>
205 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
206 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
207 <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\\"
208 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
209 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
210 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
216 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
217 <div style=\\"text-align: left; padding: 8px;\\">
218 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
220 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
221 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
223 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
224 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
225 <li>Smart card di InfoCamere
228 <b>Per auto-garantisi occorre possedere:</b><br><br>
230 <li>il codice PIN della propria carta
231 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
234 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
236 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
239 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
240 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
245 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
246 <div style=\\"text-align: left; padding: 8px;\\">
247 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
249 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
250 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
252 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
253 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
256 <b>Per auto-garantisi occorre possedere:</b><br><br>
258 <li>il codice PIN della propria carta
259 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
262 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
264 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
267 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
268 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
274 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
278 $G_room_about = array( 'it' => '<br>
279 <div id=\\"header\\" class=\\"header\\">
280 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
281 briscola chiamata in salsa ajax
283 <br><b>version '.$G_brisk_version.'</b><br><br>
284 Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
286 <div id=\\"header\\" class=\\"header\\">
287 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
288 declaration briscola in ajax sauce <b>(Beta)</b>
290 <br><b>version '.$G_brisk_version.'</b><br><br>
291 Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
297 function versions_cmp($v1, $v2)
299 // printf("V1: [%s]\nV2: [%s]\n", $v1, $v2);
303 $v1_ar = split('\.', $v1);
304 $v2_ar = split('\.', $v2);
306 $v2_ct = count($v2_ar);
308 for ($i = 0 ; $i < count($v1_ar) ; $i++) {
309 if (($v2_ct - 1) < $i) {
312 // printf("here [%s] [%s]\n", $v1_ar[$i], $v2_ar[$i]);
313 if ($v1_ar[$i] != $v2_ar[$i]) {
314 if (strval($v1_ar[$i]) < strval($v2_ar[$i]))
323 function addrtoipv4($addr)
325 $ipv4addr_arr = explode(':' , $addr);
326 if (isset($ipv4addr_arr[3])) {
327 $ipv4addr = $ipv4addr_arr[3];
337 for ($i = 0; $i < ob_get_level(); $i++)
339 ob_implicit_flush(1);
343 function force_no_cache(&$header_out)
345 $header_out['Pragma'] = 'no-cache, must-revalidate';
346 $header_out['Cache-Control'] = 'no-cache';
347 $header_out['Expires'] = '-1';
350 function file_lock($fname, $is_exclusive)
352 if (($res = @fopen($fname, "r+")) == FALSE) {
356 if (flock($res, ($is_exclusive ? LOCK_EX : LOCK_SH)) == FALSE) {
364 function file_unlock($res)
367 flock($res, LOCK_UN);
372 $escpush_from = array("\\", "\"");
373 $escpush_to = array("\\\\", "\\\"");
376 GLOBAL $escpush_from, $escpush_to;
378 return str_replace($escpush_from, $escpush_to, $s);
381 $escinp_from = array( "\"" );
382 $escinp_to = array( """ );
384 function escinput($s)
386 GLOBAL $escinp_from, $escinp_to;
388 return str_replace($escinp_from, $escinp_to, $s);
393 return htmlentities($s);
396 function esclfhtml($s)
398 return str_replace(" ", " ", str_replace("\n", "<br>", htmlspecialchars($s)));
401 function langtolng($lang)
405 return ($G_lang == 'en' ? '-en' : '');
408 function csplitter($in, $sep)
414 for ($i = 0 ; $i < strlen($in) ; $i++) {
415 $ini = substr($in, $i, 1);
419 else if ($ini == $sep) {
438 $from = array ( '\\', '@', '|' );
439 $to = array ( '\\\\', '@', '¦' );
441 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
446 $from = array ( '\\', '|', "\t", "\n");
447 $to = array ( '\\\\', '\\|', "\\t", "\\n");
449 return (str_replace($from, $to, $s));
452 function xcapemesg($s)
454 $from = array ( "\n");
455 $to = array ( "\\n");
457 return (str_replace($from, $to, $s));
467 function getbyid($idx)
469 return ($this->el[$idx]);
472 function setbyid($idx, $v)
474 $this->el[$idx] = $v;
483 var $auth_only; // se tavolo riservato o libero
490 var $table_start; // information field
498 function create($idx)
500 if (($thiz = new Table()) == FALSE)
504 $thiz->player = array();
506 $thiz->auth_only = FALSE;
512 $thiz->table_token = "";
513 $thiz->table_start = 0;
515 $thiz->wakeup_time = 0;
522 $this->idx = $from->idx;
523 $this->player = array();
524 for ($i = 0 ; $i < $from->player_n ; $i++)
525 $this->player[$i] = $from->player[$i];
526 $this->player_n = $from->player_n;
528 log_main("PLAYER_N - parent::copy.".$this->player_n);
530 $this->auth_only = $from->auth_only;
532 $this->wag_own = $from->wag_own;
533 $this->wag_com = $from->wag_com;
534 $this->wag_tout = $from->wag_tout;
536 $this->table_token = $from->table_token;
537 $this->table_start = $from->table_start;
539 $this->wakeup_time = $from->wakeup_time;
542 function myclone($from)
544 if (($thiz = new Table()) == FALSE)
552 function spawn($from)
554 if (($thiz = new Table()) == FALSE)
557 $thiz->idx = $from->idx;
558 $thiz->player = array();
559 for ($i = 0 ; $i < $from->player_n ; $i++)
560 $thiz->player[$i] = $i;
561 $thiz->player_n = $from->player_n;
563 $thiz->auth_only = $from->auth_only;
565 $thiz->wag_own = $from->wag_own;
566 $thiz->wag_com = $from->wag_com;
567 $thiz->wag_tout = $from->wag_tout;
569 $thiz->table_token = $from->table_token;
570 $thiz->table_start = $from->table_start;
572 $thiz->wakeup_time = $from->wakeup_time;
577 function wag_set($user_idx, $mesg)
581 $this->wag_own = $user_idx;
582 $this->wag_com = $mesg;
586 function wag_reset($timeout)
588 log_main("WAG_RESET");
590 unset($this->wag_own);
593 $this->wag_tout = $timeout;
596 function player_get($idx)
598 return ($this->player[$idx]);
601 function player_set($idx, $player)
603 $this->player[$idx] = $player;
606 function user_add($idx)
608 $this->player[$this->player_n] = $idx;
611 return ($this->player_n - 1);
614 function user_rem($room, $user)
616 $tabpos = $user->table_pos;
618 /* verifico la consistenza dei dati */
619 if ($room->user[$this->player[$tabpos]] == $user) {
621 /* aggiorna l'array dei giocatori al tavolo. */
622 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
623 $this->player[$i] = $this->player[$i+1];
624 $user_cur = $room->user[$this->player[$i]];
625 $user_cur->table_pos = $i;
630 log_main("INCONSISTENCY ON TABLE.");
636 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
637 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
639 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
640 function act_content($user)
643 $isstanding = ($user->subst == 'standup');
644 $sitted = $this->player_n;
646 $cur_table = $user->table;
650 if ($sitted < PLAYERS_N) {
651 if ($this->auth_only) {
652 if ($user->flags & USER_FLAG_AUTH)
666 if ($table == $cur_table)
673 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
686 function Delay_Manager($triglevel)
688 $this->triglevel = $triglevel;
689 $this->delta = array();
690 $this->lastcheck = 0;
693 function delta_get($curtime)
695 // clean too old delta items
696 for ($i = 0 ; $i < count($this->delta) ; $i++) {
697 if ($this->delta[$i][0] < $curtime) {
698 array_splice($this->delta, $i, 1);
703 // add new delta items if delay exceeded $this->triglevel sec
704 if ($curtime > $this->lastcheck + $this->triglevel && $curtime < $this->lastcheck + 1200.0) {
705 $delta = $curtime - $this->lastcheck - $this->triglevel;
706 array_push($this->delta, array($curtime + $delta , $delta));
707 // fprintf(STDERR, "DELTA: add new delta [%f] [%f] [%f]\n", $this->triglevel, $curtime + $delta, $delta);
710 // extract the maximum valid delta
712 for ($i = 0 ; $i < count($this->delta) ; $i++) {
713 $delta_cur = $this->delta[$i][1];
714 if ($delta_max < $delta_cur)
715 $delta_max = $delta_cur;
718 // fprintf(STDERR, "DELTA: status %d, delta_max: %f\n", count($this->delta), $delta_max);
723 function lastcheck_set($curtime)
725 $this->lastcheck = $curtime;
733 function Client_prefs()
737 static function from_user($user)
739 $thiz = new Client_prefs();
740 $thiz->user_load($user);
745 static function from_json($json)
747 $thiz = new Client_prefs();
748 if ($thiz->json_load($json) == FALSE) {
756 function user_load($user)
758 fprintf(STDERR, "QQ %s: %x\n", __FUNCTION__, $user->flags);
759 $this->listen = ($user->flags & USER_FLAG_MAP_AUTH) >> 2;
760 if ($user->rec != FALSE) {
761 $this->supp_comp = $user->rec->supp_comp_get();
764 $this->supp_comp = "000000000000";
767 fprintf(STDERR, "QQ %s: LISTEN: %d\n", __FUNCTION__, $this->listen);
770 function json_load($json_s)
775 if (gettype($json_s) == "string") {
776 if (($json = json_decode($json_s)) == FALSE)
782 if ($this->listen < 0 || $this->listen > 2)
784 $this->listen = $json->listen;
786 if (mb_strlen($json->supp_comp, "ASCII") != 12)
789 for ($i = 0, $idx = 0 ; $i < 12 ; $i++) {
790 if (($json->supp_comp[$i] >= '0' && $json->supp_comp[$i] <= '9') ||
791 ($json->supp_comp[$i] >= 'a' && $json->supp_comp[$i] <= 'f'))
797 $this->supp_comp = $json->supp_comp;
804 function store($user, $is_save)
807 fprintf(STDERR, "QQ %s::%s PRE: %x\n", __CLASS__, __FUNCTION__,
808 $user->flags & (~USER_FLAG_S_ALL & ~USER_FLAG_AUTH));
809 $user->flags_set(($this->listen << 2), USER_FLAG_MAP_AUTH);
810 fprintf(STDERR, "QQ %s::%s %x\n", __CLASS__, __FUNCTION__,
812 if ($user->is_supp_custom()) {
813 $user->rec->supp_comp_set($this->supp_comp);
816 $user->prefs_store();
825 var $crystal_filename;
829 var $comm; // commands for many people
830 var $step; // current step of the comm array
831 var $garbage_timeout;
836 function Room ($crystal_filename) {
837 $this->crystal_filename = $crystal_filename;
838 $this->user = array();
839 $this->table = array();
840 $this->match = array();
842 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
843 $this->user[$i] = User::create($this, $i, "", "");
846 for ($i = 0 ; $i < TABLES_N ; $i++) {
847 $this->table[$i] = Table::create($i);
850 $row = ( (((int)($i / 4)) % 2) == 0 );
851 $col = ($i % 2 == 0);
852 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
855 $this->table[$i]->auth_only = FALSE;
858 if ($i < TABLES_AUTH_N)
859 $this->table[$i]->auth_only = TRUE;
861 $this->table[$i]->auth_only = FALSE;
863 $this->garbage_timeout = 0;
864 $this->shm_sz = SHM_DIMS_MIN;
866 $this->delay_mgr = new Delay_Manager(1.5);
869 function garbage_manager($force)
871 GLOBAL $G_lang, $mlang_brisk, $G_base;
875 log_rd2("garbage_manager START");
877 /* Garbage collector degli utenti in timeout */
878 $curtime = microtime(TRUE);
880 $delta = $this->delay_mgr->delta_get($curtime);
882 if (!$force && !($this->garbage_timeout < $curtime)) {
883 $this->delay_mgr->lastcheck_set($curtime);
887 // Before all align times with table timeout
888 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
889 $table_cur = $this->table[$table_idx];
890 // if the table is complete and exists its shared mem we get the info about users lacc
892 if ($table_cur->player_n == PLAYERS_N) {
893 log_main("PLAYERS == N TABLE ".$table_idx);
896 $no_recovery = FALSE;
897 if (isset($this->match[$table_idx])) {
898 $bri = $this->match[$table_idx];
900 if ($table_cur->table_token != $bri->table_token) {
901 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
902 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
911 log_main("garbage_manager: bri loaded successfully.");
912 $bri->garbage_manager(TRUE);
914 $bri_table = $bri->table[0];
916 // is the end of the table
918 if ($bri->the_end == TRUE) {
920 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
922 log_main("garbage_manager: INSIDE THE END.");
924 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
925 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
926 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
929 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
930 // stat must be "table" by definition
931 $user_cur = $this->user[$table_cur->player[$i]];
932 $bri_user = $bri->user[$i];
934 $user_cur->subst = $bri_user->subst;
935 $user_cur->step = $bri_user->step;
936 $user_cur->lacc = $bri_user->lacc;
937 $user_cur->laccwr = $bri_user->lacc;
938 $user_cur->bantime = $bri_user->bantime;
941 log_legal($curtime, $user_cur->ip, $user_cur, "STAT:DESTROY_GAME", $plist);
943 $this->room_join_wakeup($user_cur, FALSE, 0);
944 $table_cur->table_token = "";
945 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
947 $this->match_del($table_idx);
950 log_main("gm:: save_data");
952 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
953 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
956 } // if ($bri == FALSE
957 else if ($no_recovery == FALSE) {
958 log_crit("ERROR: table ".$table_idx." unrecoverable join");
960 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
961 $user_cur = $this->user[$table_cur->player[$i]];
962 $user_cur->subst = "shutdowner";
963 $user_cur->step_inc();
965 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
966 $ret .= "gst.st = ".($user_cur->step+1)."; ";
967 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
968 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
969 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
970 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
971 $user_cur->step_inc();
974 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
975 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
976 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
978 log_legal($curtime, $user_cur->ip, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
980 $this->room_join_wakeup($user_cur, TRUE, -2);
981 $table_cur->table_token = "";
984 } // if ($table_cur->player_n == PLAYERS_N) {
985 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
987 log_rd2("out new loop.");
989 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
990 $user_cur = $this->user[$i];
992 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
994 if ($user_cur->sess == "")
997 if ($user_cur->lacc + EXPIRE_TIME_RD < ($curtime - $delta)) {
998 // Auto logout dell'utente
999 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime - delta ".($curtime - $delta));
1001 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1002 log_auth($user_cur->sess, "Autologout session.");
1006 log_rd2("AUTO LOGOUT.");
1007 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1008 $this->room_wakeup($user_cur);
1009 else if ($user_cur->subst == 'standup')
1010 $this->room_outstandup($user_cur);
1012 log_rd2("LOGOUT FROM WHAT ???");
1016 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < ($curtime - $delta)) { // lo rimettiamo in piedi
1017 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1018 $this->room_wakeup($user_cur);
1019 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1020 /* 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" */
1021 $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);
1022 $user_cur->step_inc();
1026 log_rd2("GARBAGE UPDATED!");
1028 $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
1031 $this->delay_mgr->lastcheck_set($curtime);
1035 function show_room($user_step, $user)
1037 GLOBAL $G_lang, $mlang_brisk;
1038 log_main("show_room: username: ".$user->name);
1040 $ret = sprintf('gst.st = %d; ', $user_step);
1042 $prefs = Client_prefs::from_user($user);
1043 $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs));
1046 if ($user->flags & USER_FLAG_ISOLAUTH) {
1047 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
1049 else if ($user->flags & USER_FLAG_LISTAUTH) {
1050 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1053 $ret .= 'list_set(\'all\', false, \'\' ); ';
1057 if ($user->subst == 'standup')
1058 $ret .= "tra.show(); ";
1060 $ret .= "tra.hide(); ";
1062 $ret .= sprintf('stat = "%s";', $user->stat);
1064 $ret .= root_welcome($user);
1065 if ($user->flags & USER_FLAG_DBFAILED) {
1066 $ret .= "gst.st = ".($user->step+1)."; ";
1067 $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
1070 $ret .= sprintf('subst = "%s";', $user->subst);
1071 $ret .= $user->myname_innerHTML();
1073 for ($i = 0 ; $i < TABLES_N ; $i++) {
1075 $ret .= $this->table_content($user, $i);
1076 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1077 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1078 $ret .= $this->table[$i]->act_content($user);
1079 if ($this->table[$i]->wag_own != -1)
1080 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
1082 $ret .= sprintf('tra.rem(%d); ', $i);
1084 $ret .= $this->standup_content($user);
1085 $ret .= "setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); ";
1091 function room_wakeup($user)
1093 $table_idx = $user->table;
1094 $table = $this->table[$table_idx];
1096 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1100 $from_table = ($user->stat == "table");
1102 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1104 for ($i = 0 ; $i < $table->player_n ; $i++) {
1105 $user_cur = $this->user[$table->player[$i]];
1106 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1108 if ($user->idx_get() != $table->player[$i]) {
1109 $user_cur->stat_set("room");
1110 $user_cur->subst = "sitdown";
1111 $user_cur->laccwr = $curtime;
1113 else if ($user->sess != "") {
1114 $user_cur->stat_set("room");
1115 $user_cur->subst = "standup";
1116 $user_cur->laccwr = $curtime;
1117 $user_cur->table = -1;
1122 $user->stat_set("room");
1123 $user->subst = "standup";
1124 $user->laccwr = $curtime;
1127 $remove_wagon = FALSE;
1128 if($table->wag_own == $user->idx_get()) {
1129 $table->wag_reset($curtime);
1130 $remove_wagon = TRUE;
1134 /* aggiorna l'array dei giocatori al tavolo. */
1135 $table->user_rem($this, $user);
1137 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1138 $user_cur = $this->user[$i];
1139 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1142 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1144 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1145 if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
1146 $ret .= 'gst.st_loc++; xstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1147 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1148 log_main("DOCUMENT.index.php: from table");
1150 else if ($user_cur->stat == "room") {
1151 log_main("DOCUMENT.index.php: from table");
1153 $ret .= $this->table_content($user_cur, $table_idx);
1154 $ret .= $this->standup_content($user_cur);
1156 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1157 $ret .= $table->act_content($user);
1159 if ($user->idx_get() == $i) {
1160 // set the new status
1161 $ret .= 'subst = "standup"; tra.show(); ';
1162 // clean the action buttons in other tables
1163 for ($e = 0 ; $e < TABLES_N ; $e++) {
1164 if ($this->table[$e]->player_n < PLAYERS_N) {
1165 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1166 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1167 $ret .= $this->table[$e]->act_content($user);
1172 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1173 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1174 $ret .= $table->act_content($user_cur);
1177 log_wr("ROOM_WAKEUP: ".$ret);
1178 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1179 $user_cur->step_inc();
1183 function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
1185 $table_idx = $user->table;
1186 $table = $this->table[$table_idx];
1188 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1191 $user_wup = array();
1193 $user_tab = array();
1195 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1197 for ($i = 0 ; $i < $table->player_n ; $i++) {
1198 $user_cur = $this->user[$table->player[$i]];
1199 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1200 if ($user_cur->sess != "") {
1201 if ($update_lacc == TRUE) {
1202 $user_cur->laccwr = $curtime;
1204 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1205 if ($user_cur->subst == "shutdowned") {
1206 $user_cur->stat_set("room");
1207 $user_cur->subst = "sitdown";
1209 else if ($user_cur->subst == "shutdowner") {
1210 $user_cur->stat_set("room");
1211 $user_cur->subst = "standup";
1212 $user_cur->table = -1;
1213 $user_wup[$user_wup_n++] = $user_cur;
1215 $remove_wagon = FALSE;
1216 if($table->wag_own == $table->player[$i]) {
1217 $remove_wagon = TRUE;
1218 $table->wag_reset($curtime);
1221 $user_tab[$user_tab_n++] = $table->player[$i];
1225 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1226 $table->user_rem($this, $user_wup[$wup_idx]);
1228 /* aggiorna l'array dei giocatori al tavolo. */
1230 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1231 log_main("START LOOP");
1232 $user_cur = $this->user[$i];
1233 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1234 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1239 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1241 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1242 if ($user_cur->stat == "room") {
1243 log_main("DOCUMENT.index.php from table");
1245 $ret .= $this->table_content($user_cur, $table_idx);
1246 $ret .= $this->standup_content($user_cur);
1248 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1249 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1250 $ret .= $table->act_content($user_cur);
1253 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1254 if ($user_tab[$tab_idx] == $i)
1257 // for users that wakeup the room will be reconstructed by index_rd.php
1258 if ($tab_idx < $user_tab_n) {
1259 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1261 // ARRAY_POP DISABLED
1262 // if ($trans_delta == 0)
1263 // while (array_pop($user_cur->comm) != NULL);
1265 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1266 $user_cur->comm[$user_cur->step % COMM_N] = "";
1267 $user_cur->step_inc();
1268 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
1269 $user_cur->step_inc();
1270 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1274 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1276 log_main("JOIN_WAKEUP more");
1277 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1278 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1279 $ret .= $table->act_content($user_cur);
1281 log_main("JOIN_WAKEUP end more");
1283 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1284 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1285 $user_cur->step_inc();
1289 function room_outstandup($user)
1291 $this->room_sitdown($user, -1);
1294 function table_update($user)
1296 log_main("table_update: pre - USER: ".$user->name);
1298 $table_idx = $user->table;
1300 if ($table_idx > -1)
1301 $table = $this->table[$table_idx];
1303 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1305 $user_cur = $this->user[$i];
1306 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1309 $ret = "gst.st = ".($user_cur->step+1)."; ";
1310 if ($table_idx > -1)
1311 $ret .= $this->table_content($user_cur, $table_idx);
1313 if ($user->idx_get() == $i) {
1314 $ret .= $user->myname_innerHTML();
1316 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1317 $user_cur->step_inc();
1320 log_main("table_update: post");
1323 function room_sitdown($user, $table_idx)
1325 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1329 if ($table_idx > -1 && $table_idx < TABLES_N) {
1330 $table = $this->table[$table_idx];
1333 if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
1334 for ($i = 0 ; $i < TABLES_N ; $i++) {
1335 if ($table->wag_own == $table->player[$i]) {
1336 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1337 $table->wag_reset(time());
1344 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1346 $user_cur = $this->user[$i];
1347 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1350 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1351 if ($table_idx > -1)
1352 $ret .= $this->table_content($user_cur, $table_idx);
1353 $ret .= $this->standup_content($user_cur);
1355 if ($user->idx_get() == $i) {
1356 $ret .= 'subst = "sitdown"; tra.hide(); ';
1357 // clean the action buttons in other tables
1358 for ($e = 0 ; $e < TABLES_N ; $e++) {
1359 $ret .= $this->table[$e]->act_content($user_cur);
1362 else if ($table_idx > -1) {
1363 if ($table->player_n == PLAYERS_N) {
1364 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1365 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1366 $ret .= $table->act_content($user_cur);
1369 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1370 $user_cur->step_inc();
1374 function chatt_send($user, $mesg)
1376 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1380 $msg = mb_substr($mesg, 6, 128, "UTF-8");
1382 $dt = date("H:i ", $curtime);
1393 $is_normchat = FALSE;
1394 /* for old isolation management $is_ticker = FALSE; */
1395 $update_room = FALSE;
1397 if (strcmp($msg, "/tav") == 0 ||
1398 strncmp($msg, "/tav ", 5) == 0) {
1400 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1401 /* 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>" */
1402 $msg = $mlang_brisk['tickmust'][$G_lang];
1403 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1408 $table = $this->table[$user->table];
1410 if ($table->wag_own != -1) {
1411 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1412 $msg = $mlang_brisk['tickjust'][$G_lang];
1413 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1418 $dtime = $curtime - $table->wag_tout;
1419 if ($dtime < EXPIRE_TIME_WAG) {
1420 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1421 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1422 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1423 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1428 $msg = substr($msg, 5);
1430 $table->wag_set($user->idx_get(), $msg);
1431 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1432 $to_room = $to_user;
1433 /* for old isolation management $is_ticker = TRUE; */
1435 } // /tav chat command
1437 else if (strncmp($msg, "/alarm ", 7) == 0) {
1438 if (strncmp($msg, "/alarm to ", 10) == 0) {
1439 $sp_pos = strpos($msg, " ", 10);
1440 $target = substr($msg, 10, $sp_pos - 10);
1441 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1445 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1448 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1449 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1450 $msg = $mlang_brisk['alarpass'][$G_lang];
1451 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1456 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1457 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1458 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1459 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1460 $dt, NICKSERV, $prestr);
1462 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1463 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1464 /* MLANG: "chiudi" */
1465 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1467 } // /alarm chat command
1468 else if (strncmp($msg, "/listen ", 8) == 0) {
1469 $arg = substr($msg, 8);
1471 if (strcasecmp($arg, "isolation") == 0) {
1473 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1474 $user->table >= TABLES_AUTH_N) {
1475 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1479 $user->flags &= ~USER_FLAG_MAP_AUTH;
1480 $user->flags |= USER_FLAG_ISOLAUTH;
1481 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1484 else if (strcasecmp($arg, "auth") == 0) {
1485 $flags_old = $user->flags;
1486 $user->flags &= ~USER_FLAG_MAP_AUTH;
1487 $user->flags |= USER_FLAG_LISTAUTH;
1488 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1491 $flags_old = $user->flags;
1492 $user->flags &= ~USER_FLAG_MAP_AUTH;
1493 $to_user = 'list_set(\'all\', true, \'\'); ';
1496 // if from isolation redraw standup area
1497 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1498 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1502 else if (strcmp($msg, "/authreq") == 0) {
1503 if ($user->flags & USER_FLAG_AUTH) {
1504 $to_user = sprintf('authbox(300,200);');
1507 /* 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." */
1508 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1511 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1512 if ($user->flags & USER_FLAG_AUTH) {
1513 $to_user = sprintf('mesgtoadmbox(500,300);');
1516 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1517 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1520 else if (strncmp($msg, "/nick ", 6) == 0) {
1521 log_main("chatt_send BEGIN");
1524 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1525 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1529 $msg = "COMMAND ".$msg;
1530 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1531 $user_cur = $this->user[$i];
1533 if ($user_cur->sess == '')
1535 if (strcasecmp($user_cur->name,$name_new) == 0)
1538 if ($i < MAX_PLAYERS) {
1539 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1540 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1544 /* 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>" */
1545 if ($user->flags & USER_FLAG_AUTH) {
1546 if (strcasecmp($user->name,$name_new) != 0) {
1547 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1548 ($user->subst == 'standup' ||
1549 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1552 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1553 for ($i = 0 ; $i < TABLES_N ; $i++) {
1554 $to_user .= $this->table[$i]->act_content($user);
1558 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1563 $user->name = $name_new; // OK - nick changed
1564 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1565 if (($user->flags & USER_FLAG_AUTH) == 0) {
1566 if (($bdb = BriskDB::create()) != FALSE) {
1568 /* 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>" */
1569 if ($bdb->login_exists($name_new)) {
1570 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1571 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1576 log_main("chatt_send start set");
1578 $update_room = TRUE;
1580 } // nick chat command
1582 else if (strncmp($msg, "/st ", 4) == 0) {
1583 log_main("chatt_send BEGIN");
1586 $st_str = substr($msg, 4);
1588 if (strcasecmp($st_str, "normale") == 0) {
1589 $st = USER_FLAG_S_NORM;
1591 else if (strcasecmp($st_str, "pausa") == 0) {
1592 $st = USER_FLAG_S_PAU;
1594 else if (strcasecmp($st_str, "fuori") == 0) {
1595 $st = USER_FLAG_S_OUT;
1597 else if (strcasecmp($st_str, "cane") == 0) {
1598 $st = USER_FLAG_S_DOG;
1600 else if (strcasecmp($st_str, "cibo") == 0) {
1601 $st = USER_FLAG_S_EAT;
1603 else if (strcasecmp($st_str, "lavoro") == 0) {
1604 $st = USER_FLAG_S_WRK;
1606 else if (strcasecmp($st_str, "sigaretta") == 0) {
1607 $st = USER_FLAG_S_SMK;
1609 else if (strcasecmp($st_str, "presente") == 0) {
1610 $st = USER_FLAG_S_EYE;
1612 else if (strcasecmp($st_str, "coniglio") == 0) {
1613 $st = USER_FLAG_S_RABB;
1615 else if (strcasecmp($st_str, "calcio") == 0) {
1616 $st = USER_FLAG_S_SOCC;
1618 else if (strcasecmp($st_str, "pupo") == 0) {
1619 $st = USER_FLAG_S_BABY;
1621 else if (strcasecmp($st_str, "pulizie") == 0) {
1622 $st = USER_FLAG_S_MOP;
1624 else if (strcasecmp($st_str, "babbo") == 0) {
1625 $st = USER_FLAG_S_BABBO;
1627 else if (strcasecmp($st_str, "renna") == 0) {
1628 $st = USER_FLAG_S_RENNA;
1630 else if (strcasecmp($st_str, "pupazzo") == 0) {
1631 $st = USER_FLAG_S_PUPAZ;
1633 else if (strcasecmp($st_str, "vischio") == 0) {
1634 $st = USER_FLAG_S_VISCH;
1637 /* MLANG: "Questo stato non esiste." */
1638 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1642 log_main("chatt_send start set");
1643 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1644 $update_room = TRUE;
1645 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1648 } // nick chat command
1650 else { // normal chat line
1651 $is_normchat = TRUE;
1652 if (CHAT_ENABLED && $curtime < ($user->chat_ban + $user->chat_dlt)) {
1654 $user->chat_dlt = $user->chat_dlt * 2;
1655 if ($user->chat_dlt > 120)
1656 $user->chat_dlt = 120;
1658 else if ($user->chat_lst == $msg)
1660 else if (CHAT_ENABLED && $curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1661 $user->chat_ban = $curtime;
1662 $user->chat_dlt = 5;
1666 $user->chat_ban = 0;
1667 $user->chat_dlt = 0;
1671 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1674 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1675 // temporary silentiation for troll (will became array check)
1676 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1677 $to_room = $to_user;
1680 log_legal($curtime, $user->ip, $user,
1681 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1683 $user->chat_lst = "$msg";
1684 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1694 // Output to clients
1697 if ($to_user != FALSE) {
1698 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1699 $user->comm[$user->step % COMM_N] .= $to_user;
1703 if ($to_room != FALSE) {
1704 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1705 $user_cur = $this->user[$i];
1706 if ($target != "" && $user_cur->name != $target)
1708 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user->idx_get() == $i)
1711 if ($is_normchat == TRUE) {
1712 // use MAP_AUTH to check if auth or isolation
1713 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1714 if (($user->flags & USER_FLAG_AUTH) == 0) {
1720 else if ($is_ticker) {
1721 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1722 if ($user->table >= TABLES_AUTH_N)
1727 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1728 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1729 $user_cur->step_inc();
1734 // FIXME BRISK4: include for each kind of table
1735 require_once("${G_base}briskin5/Obj/briskin5.phh");
1736 // Before all align times with table timeout
1737 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1738 if (isset($this->match[$table_idx])) {
1739 $bri = $this->match[$table_idx];
1741 $bri_table = $bri->table[0];
1742 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1743 // stat must be "table" by definition
1744 $bri_user = $bri->user[$i];
1746 if ($target != "" && $bri_user->name != $target)
1748 log_main("writa: ".$user_mesg);
1749 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1750 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1751 $bri_user->step_inc();
1753 } // if (isset($this->match
1754 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1755 } // if ($to_tabl == true ...
1758 if ($user->stat == 'room' && $user->subst == 'standup') {
1759 $this->standup_update($user);
1761 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1762 log_main("chatt_send pre table update");
1763 $this->table_update($user);
1764 log_main("chatt_send post table update");
1766 } // if ($update_room ...
1769 } // function chatt_send( ...
1771 function get_user($sess, &$idx)
1775 if (validate_sess($sess)) {
1776 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1777 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1780 $ret = $this->user[$i];
1784 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1785 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1786 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1789 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1796 * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1799 * if ($idx > -1 && ret == FALSE) => duplicated nick
1800 * if ($idx == -2 && ret == FALSE) => invalid name
1801 * if ($idx == -3 && ret == FALSE) => wrong password
1802 * if ($idx == -1 && ret == FALSE) => no space left
1803 * if ($idx == 0 && ret == user) => SUCCESS
1804 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
1807 function add_user(&$sess, &$idx, $name, $pass, $ip, $cookie)
1813 $authenticate = FALSE;
1815 $login_exists = FALSE;
1817 $ghost_auth = FALSE;
1822 if (($name_new = validate_name($name)) == FALSE) {
1827 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1828 if (validate_sess($sess) == FALSE)
1831 /* if pass != FALSE verify the login with pass */
1832 log_auth("XXX", "auth1");
1834 if (($bdb = BriskDB::create()) != FALSE) {
1836 if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
1837 log_auth("XXX", "auth2");
1838 $authenticate = $bdb->login_verify($name_new, $pass, $code);
1839 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
1841 if ($authenticate != FALSE) {
1842 $user_type = $authenticate->type_get();
1850 $login_exists = $bdb->login_exists($name_new);
1854 // if db is down, send a warning and verify only current users
1855 // no actions at this moment
1857 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1859 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1863 if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
1865 continue; // NOTE: CHECK IT !!
1867 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1868 if ($authenticate != FALSE) {
1870 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1881 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1883 /* there is another user logged with your account and you and him have authenticated => new user
1884 get the session of the old user */
1885 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
1888 $ghost_user = $this->user[$ghost];
1890 $ghost_user->comm[$ghost_user->step % COMM_N] = "";
1891 $ghost_user->step_inc();
1894 $ghost_user->sess = $sess;
1897 $ghost_user->sess = $sess;
1900 // If user at the table we need to update the table data too
1901 $table_idx = $ghost_user->table;
1902 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1903 require_once("${G_base}briskin5/Obj/briskin5.phh");
1904 if (isset($this->match[$table_idx])) {
1905 $bri = $this->match[$table_idx];
1907 if ($bri->the_end != TRUE) {
1908 $bri->user[$ghost_user->table_pos]->comm[$bri->user[$ghost_user->table_pos]->step % COMM_N] = "";
1909 $bri->user[$ghost_user->table_pos]->step_inc();
1910 $bri->user[$ghost_user->table_pos]->sess = $sess;
1916 return ($this->user[$ghost]);
1918 else if ($idx != -1 && $i == MAX_PLAYERS) {
1923 $this->user[$idx]->sess = $sess;
1926 $this->user[$idx]->sess = $sess;
1928 $this->user[$idx]->name = $name_new; // OK - add new user
1929 $this->user[$idx]->stat_set("room");
1930 $this->user[$idx]->step_set(0);
1931 while (array_pop($this->user[$idx]->comm) != NULL);
1932 $this->user[$idx]->subst = "standup";
1933 $this->user[$idx]->lacc = $curtime;
1934 $this->user[$idx]->laccwr = $curtime;
1935 $this->user[$idx]->bantime = 0;
1936 $this->user[$idx]->ip = $ip;
1938 $this->user[$idx]->rec = $authenticate;
1939 fprintf(STDERR, "MOP: [%s]\n", $authenticate->supp_comp);
1940 $this->user[$idx]->flags = $user_type;
1941 $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
1942 $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
1943 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
1945 if ($authenticate != FALSE) {
1946 $this->user[$idx]->code = $authenticate->code_get();
1948 // all this part is included in the db server
1949 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1951 if (isset($cookie['CO_list'])) {
1952 fprintf(STDERR, "QQ: %s CO_list: [%s]\n", __FUNCTION__, $cookie['CO_list']);
1953 if (strcmp($cookie['CO_list'], "auth") == 0) {
1954 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1955 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1957 if (strcmp($cookie['CO_list'], "isolation") == 0) {
1958 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1959 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
1962 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1967 fprintf(STDERR, "QQ: CO_list not set flags: %x\n", __FUNCTION__, $this->user[$idx]->flags);
1970 fprintf(STDERR, "QQ %s: flag %x\n", __FUNCTION__, $this->user[$idx]->flags);
1972 log_main("ghost: rename!");
1973 $ghost_user = $this->user[$ghost];
1975 if ($ghost_auth == FALSE) {
1976 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1977 $ghostname = 'ghost'.$sfx;
1978 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1979 if (strcmp("", $this->user[$i]->sess) == 0)
1982 if (strcasecmp($this->user[$i]->name, $ghostname) == 0) {
1987 if ($ghostname != '')
1991 $ghost_user->name = $ghostname;
1993 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1994 $this->standup_update($ghost_user);
1997 log_main("chatt_send pre table update");
1998 $this->table_update($ghost_user);
1999 log_main("chatt_send post table update");
2001 } // if ($ghost_auth == FALSE
2003 // FIXME: cacciare il vecchio utente room && table (if needed)
2004 $ghost_user->the_end = TRUE;
2005 $ghost_user->lacc = 0;
2006 $this->garbage_manager(TRUE);
2008 } // if ($ghost > -1) {
2013 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));
2015 $ret = $this->user[$real_idx];
2022 function standup_update($user)
2024 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2025 $user_cur = $this->user[$i];
2026 if ($user_cur->sess == '')
2029 log_main("STANDUP START: ".$user_cur->stat);
2031 if ($user_cur->stat == 'room') {
2032 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
2033 if ($user->idx_get() == $i) {
2034 $user_cur->comm[$user_cur->step % COMM_N] .= $user->myname_innerHTML();
2036 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
2038 $user_cur->step_inc();
2044 static function create($crystal_filename)
2046 if (($room_ser = @file_get_contents($crystal_filename)) == FALSE ||
2047 ($room = unserialize($room_ser)) == FALSE) {
2048 fprintf(STDERR, "NEW ROOM\n");
2049 $room = new Room($crystal_filename);
2052 fprintf(STDERR, "ROOM FROM FILE\n");
2053 rename($crystal_filename, $crystal_filename.".old");
2060 function load_data()
2065 if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) {
2066 log_main("ftok failed");
2070 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2071 log_main("shmop_open failed");
2075 $shm_sz = SHM_DIMS_MIN;
2077 if ($shm = shm_attach($tok, $shm_sz)) {
2078 $room = @shm_get_var($shm, $tok); // CHECKED BELOW
2080 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2082 log_only("bri count ".count($room));
2084 if ($room == FALSE) {
2085 log_only("INIT MAIN DATA");
2088 $room = Room::create();
2090 log_shme("Room::create");
2092 if (Room::save_data($room) == FALSE)
2097 $room->shm_sz = $shm_sz;
2101 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2102 if (($room->user[$i] = User::load_data($i, FALSE)) == FALSE) {
2103 log_crit("User::load_data failed");
2107 if ($i < MAX_PLAYERS) {
2113 // SHSPLIT: load users from the shared memory
2122 function save_data_orig($room)
2130 if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1)
2133 while ($room->shm_sz < SHM_DIMS_MAX) {
2134 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2137 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2138 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2142 if (shm_remove($shm) === FALSE) {
2143 log_only("REMOVE FALLITA");
2147 $room->shm_sz += SHM_DIMS_DLT;
2155 function dump_data()
2157 $room_ser = serialize($this);
2158 $room_ser_len = mb_strlen($room_ser, "ASCII");
2159 if (file_put_contents($this->crystal_filename, $room_ser) == $room_ser_len) {
2166 function save_data($room)
2173 if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1)
2176 // SHSPLIT: before save the $room you must save users,
2177 // detach from main struct and (then) reattach
2178 $user_park = array();
2179 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2180 $user_park[$i] = $room->user[$i];
2181 $room->user[$i] = FALSE;
2184 while ($room->shm_sz < SHM_DIMS_MAX) {
2185 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2188 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2189 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2190 log_shme("Room::save_data");
2194 if (shm_remove($shm) === FALSE) {
2195 log_only("REMOVE FALLITA");
2199 $room->shm_sz += SHM_DIMS_DLT;
2205 // SHSPLIT: reattach users to the room class
2206 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2207 User::save_data($user_park[$i], $i);
2208 $room->user[$i] = $user_park[$i];
2210 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
2215 static function lock_data($is_exclusive)
2217 if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) {
2218 self::$delta_t = microtime(TRUE);
2219 log_lock("LOCK room [".self::$delta_t."]");
2227 static function unlock_data($res)
2231 log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]");
2237 function standup_content($user)
2242 if ($user->stat != 'room')
2245 for ($i = 0 , $ct = 0 ; $ct < 4 && $i < MAX_PLAYERS ; $i++) {
2246 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2251 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2253 $content = ' j_stand_cont( [ ';
2255 $user_cur_id = $user->idx_get();
2256 for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
2257 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2260 $flags = $this->user[$i]->flags;
2262 // sql record exists AND last donate > 2013-01-01
2263 if ($this->user[$i]->is_supp_custom()) {
2264 $supp_comp_s = sprintf(', "%s"', $this->user[$i]->rec->supp_comp_get());
2270 if ($this->user[$i]->subst == "standup") {
2271 if ($user_cur_id == $i) {
2275 $content .= sprintf('%s[ %d, "%s"%s ]',($ct > 0 ? ', ' : ''), $flags,
2276 xcape($this->user[$i]->name), $supp_comp_s);
2285 function table_content($user, $table_idx)
2291 // Si possono usare i dati nella classe table
2294 $sess = $user->sess;
2295 $table = $this->table[$table_idx];
2297 if ($user->stat != 'room')
2300 $user_cur_id = $user->idx_get();
2302 for ($i = 0 ; $i < $table->player_n ; $i++) {
2303 $user_cur = $this->user[$table->player[$i]];
2305 $flags = $user_cur->flags;
2307 if ($user_cur_id == $table->player[$i])
2310 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2311 if ($user_cur->is_supp_custom())
2312 $supp_comp_s = sprintf(', "%s"', $user_cur->rec->supp_comp_get());
2316 $content .= sprintf('%s[ %d, "%s"%s ]',($i == 0 ? '' : ', '), $flags,
2317 xcape($user_cur->name), $supp_comp_s);
2322 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2327 function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
2329 GLOBAL $G_black_list;
2331 printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
2333 $enc = get_encoding($header);
2334 if (isset($header['User-Agent'])) {
2335 if (strstr($header['User-Agent'], "MSIE")) {
2336 $transp_type = "htmlfile";
2339 $transp_type = "xhr";
2343 $transp_type = "iframe";
2345 force_no_cache($header_out);
2351 index_main($this, $transp_type, $header_out, $addr, $get, $post, $cookie);
2352 $content = ob_get_contents();
2355 // fprintf(STDERR, "\n\nCONTENT [%s]\n\n", $content);
2356 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2360 case "index_wr.php":
2362 // Enhance required: in the POST case, after the header you must get content
2363 // from the socket, waiting if necessary
2366 fprintf(STDERR, "\n\nDENTRO QUI\n\n");
2368 index_wr_main($this, $addr, $get, $post, $cookie);
2369 $content = ob_get_contents();
2372 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2376 case "index_rd.php":
2377 if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE)
2379 if ($transp == 'websocket')
2383 if (!isset($cookie['sess'])
2384 || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)) {
2386 $content = User::stream_fini($transp, $s_a_p->rndstr, TRUE);
2388 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2393 // close a previous opened index_read_ifra socket, if exists
2394 if (($prev = $user->rd_socket_get()) != NULL) {
2395 $s_a_p->socks_unset($user->rd_socket_get());
2396 fclose($user->rd_socket_get());
2397 printf("CLOSE AND OPEN AGAIN ON IFRA2\n");
2398 $user->rd_socket_set(NULL);
2402 $user->stream_init($s_a_p->rndstr, $enc, $header, $header_out, $content, $get, $post, $cookie);
2403 $response = headers_render($header_out, -1).$user->chunked_content($content);
2404 $response_l = mb_strlen($response, "ASCII");
2406 $wret = @fwrite($new_socket, $response, $response_l);
2407 if ($wret < $response_l) {
2408 printf("TROUBLES WITH FWRITE: %d\n", $wret);
2409 $user->rd_cache_set(mb_substr($content, $wret, $response_l - $wret, "ASCII"));
2412 $user->rd_cache_set("");
2414 fflush($new_socket);
2417 $s_a_p->socks_set($new_socket, $user, NULL);
2418 $user->rd_socket_set($new_socket);
2419 printf(" - qui ci siamo - ");
2426 if (!(BRISK_DEBUG & DBG_ENGI))
2428 fprintf(STDERR, "TEST.PHP running\n");
2429 if (isset($post['data'])) {
2430 $content = $post['data'];
2433 $content = "NO DATA AVAILABLE";
2435 $header_out['Content-Type'] = 'text/plain';
2436 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2440 /* FAR TODO: move all into an array of registered sub-apps */
2441 $subs = "briskin5/";
2442 $subs_l = strlen($subs);
2443 if (!strncmp($path, $subs, $subs_l)) {
2444 $ret = Bin5::request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie);
2453 function match_add($idx, $match)
2455 $this->match[$idx] = $match;
2458 function match_del($idx)
2460 unset($this->match[$idx]);
2463 function match_get($idx, $token)
2465 if (isset($this->match[$idx])) {
2467 || $token == $this->match[$idx]->table_token) {
2468 return ($this->match[$idx]);
2476 function make_seed()
2478 list($usec, $sec) = explode(' ', microtime());
2479 return (float) $sec + ((float) $usec * 100000);
2482 function btrace_line($ar)
2484 GLOBAL $G_btrace_pref_sub;
2487 for ($i = 0 ; $i < count($ar) ; $i++) {
2488 $with_class = isset($ar[$i]['class']);
2489 $with_file = isset($ar[$i]['file']);
2490 $ret .= sprintf("%s%s%s (%s:%d)", ($i == 0 ? "" : ", "),
2491 ($with_class ? $ar[$i]['class'].$ar[$i]['type'] : ""),
2492 $ar[$i]['function'], ($with_file ? str_replace($G_btrace_pref_sub, "", $ar[$i]['file']) : ""),
2493 ($with_file ? $ar[$i]['line'] : ""));
2499 function trace_ftok($id, $add)
2501 // NOTE: without space to use sed to substitute "= @ftok(" with "= @ftok("
2502 $tok=@ftok($id, $add);
2504 log_shme($tok.": ".$id." + ".$add);
2509 function log_mop($step, $log)
2511 GLOBAL $sess, $PHP_SELF;
2513 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2516 if (isset($sess) == FALSE)
2521 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2524 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2525 $btrace = btrace_line(debug_backtrace());
2528 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2529 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $log, $btrace));
2535 function log_only2($log)
2537 GLOBAL $sess, $PHP_SELF;
2539 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2542 if (isset($sess) == FALSE)
2547 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2550 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2551 $btrace = btrace_line(debug_backtrace());
2554 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2555 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2560 function log_crit($log)
2562 GLOBAL $sess, $PHP_SELF;
2564 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2567 if (isset($sess) == FALSE)
2572 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2575 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2576 $btrace = btrace_line(debug_backtrace());
2579 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2580 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2585 function log_only($log)
2587 GLOBAL $sess, $PHP_SELF;
2589 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2592 if (isset($sess) == FALSE)
2597 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2600 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2601 $btrace = btrace_line(debug_backtrace());
2604 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2605 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2610 function log_main($log)
2612 GLOBAL $sess, $PHP_SELF;
2614 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2617 if (isset($sess) == FALSE)
2622 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2625 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2626 $btrace = btrace_line(debug_backtrace());
2629 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2630 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2635 function log_rd($log)
2637 GLOBAL $sess, $PHP_SELF;
2639 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2642 if (isset($sess) == FALSE)
2647 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2650 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2651 $btrace = btrace_line(debug_backtrace());
2654 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2655 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2660 function log_rd2($log)
2662 GLOBAL $sess, $PHP_SELF;
2664 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2667 if (isset($sess) == FALSE)
2672 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2675 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2676 $btrace = btrace_line(debug_backtrace());
2680 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2681 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2686 function log_send($log)
2688 GLOBAL $sess, $PHP_SELF;
2690 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2693 if (isset($sess) == FALSE)
2698 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2701 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2702 $btrace = btrace_line(debug_backtrace());
2705 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2706 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2711 function log_lock($log)
2713 GLOBAL $sess, $PHP_SELF;
2715 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2718 if (isset($sess) == FALSE)
2723 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2726 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2727 $btrace = btrace_line(debug_backtrace());
2730 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2731 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2736 function log_wr($log)
2738 GLOBAL $sess, $PHP_SELF;
2740 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2743 if (isset($sess) == FALSE)
2748 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2751 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2752 $btrace = btrace_line(debug_backtrace());
2755 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2756 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2761 function log_load($log)
2763 GLOBAL $sess, $PHP_SELF;
2765 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2768 if (isset($sess) == FALSE)
2773 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2776 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2777 $btrace = btrace_line(debug_backtrace());
2780 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2781 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2786 function log_auth($sess, $log)
2790 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2793 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2796 if ((BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2797 $btrace = btrace_line(debug_backtrace());
2800 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2801 fwrite($fp, sprintf("LOAD: [%s] [%d] [%s] [%s]\n", $sess, time(), $log, $btrace));
2806 function log_shme($log)
2808 GLOBAL $sess, $PHP_SELF;
2810 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SHME) == 0)
2813 if (isset($sess) == FALSE)
2818 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SHME) == 0)
2821 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2822 $btrace = btrace_line(debug_backtrace());
2825 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2826 fwrite($fp, sprintf("SHME: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2833 // function log_legal($curtime, $sess, $name, $where, $mesg)
2834 function log_legal($curtime, $addr, $user, $where, $mesg)
2837 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2838 /* Unix time | session | nickname | IP | where was | mesg */
2839 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2840 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2841 $user->name, $addr, $where , $mesg));
2846 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2851 if ($sitted < PLAYERS_N) {
2859 if ($table == $cur_table)
2866 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2871 function show_notify($text, $tout, $butt, $w, $h)
2873 log_main("SHOW_NOTIFY: ".$text);
2874 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2877 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
2879 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2880 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);
2883 function show_notify_document($text, $tout, $butt_arr, $confirm_func, $w, $h, $is_opaque, $block_time)
2885 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2888 for ($i = 0 ; $i < count($butt_arr) ; $i++) {
2889 $butts .= sprintf("%s'%s'", ($i == 0 ? "" : ","), $butt_arr[$i]);
2892 return sprintf('g_nd = new notify_document(gst, "%s", %d, [ %s ], %s, %d, %d, %s, %d);|',
2893 escpush($text), $tout, $butts, ($confirm_func == NULL ? "null" : $confirm_func), $w, $h, ($is_opaque ? "true" : "false"), $block_time);
2897 function root_welcome($user)
2899 GLOBAL $root_wellarr, $G_lang;
2903 $dt = date("H:i ", $curtime);
2905 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2906 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2913 function validate_sess($sess)
2915 if (strlen($sess) == SESS_LEN)
2921 function validate_name($name)
2923 $name_new = str_replace(' ', '_', mb_substr(trim($name),0,12, "UTF-8"));
2925 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2927 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2934 function playsound($filename)
2936 return (sprintf('playsound("flasou", "%s");', $filename));
2939 function secstoword($secs)
2945 $mins = floor($secs / 60);
2947 if ($G_lang == 'en') {
2949 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
2952 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
2956 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2959 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2964 function sharedmem_sz($tok)
2966 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2967 log_main("shmop_open failed");
2970 $shm_sz = shmop_size($shm_id);
2971 shmop_close($shm_id);
2973 // log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2980 static function lock_data($is_exclusive)
2982 if (($res = file_lock(FTOK_PATH."/warrant", $is_exclusive)) != FALSE) {
2983 self::$delta_t = microtime(TRUE);
2984 log_lock("LOCK warrant [".self::$delta_t."]");
2992 static function unlock_data($res)
2996 log_lock("UNLOCK warrant [".(microtime(TRUE) - (self::$delta_t))."]");
3005 static function lock_data($is_exclusive)
3007 if (($res = file_lock(FTOK_PATH."/poll", $is_exclusive)) != FALSE) {
3008 self::$delta_t = microtime(TRUE);
3009 log_lock("LOCK poll [".self::$delta_t."]");
3017 static function unlock_data($res)
3021 log_lock("UNLOCK poll [".(microtime(TRUE) - (self::$delta_t))."]");