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.6.0";
146 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
147 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: aggiunti script di avvio automatico, gestione dei segnali e logging dell\' ultima connessione.',
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>: usage of reader/writer locking instead of generic exclusive locking.',
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>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
177 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
178 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
184 <div style=\\"text-align: left; padding: 8px;\\">
185 <b>EN Descrizione</b><br>
186 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
187 <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>
188 <b>EN Configurazione del browser.</b><br>
189 Occorre abilitare i cookies.<br>
191 <b>Uso del sito</b><br>
192 Potete sedervi a un tavolo o rimanere in piedi.<br>
193 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
196 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>
197 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
198 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
199 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
200 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
201 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.
203 <dt><b>Comandi della chat</b>
204 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
205 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
206 <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\\"
207 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
208 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
209 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
215 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
216 <div style=\\"text-align: left; padding: 8px;\\">
217 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
219 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
220 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
222 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
223 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
224 <li>Smart card di InfoCamere
227 <b>Per auto-garantisi occorre possedere:</b><br><br>
229 <li>il codice PIN della propria carta
230 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
233 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
235 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
238 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
239 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
244 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
245 <div style=\\"text-align: left; padding: 8px;\\">
246 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
248 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
249 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
251 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
252 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
255 <b>Per auto-garantisi occorre possedere:</b><br><br>
257 <li>il codice PIN della propria carta
258 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
261 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
263 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
266 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
267 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
273 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
277 $G_room_about = array( 'it' => '<br>
278 <div id=\\"header\\" class=\\"header\\">
279 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
280 briscola chiamata in salsa ajax
282 <br><b>version '.$G_brisk_version.'</b><br><br>
283 Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
285 <div id=\\"header\\" class=\\"header\\">
286 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
287 declaration briscola in ajax sauce <b>(Beta)</b>
289 <br><b>version '.$G_brisk_version.'</b><br><br>
290 Copyright 2006-2012 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
292 function addrtoipv4($addr)
294 $ipv4addr_arr = explode(':' , $addr);
295 if (isset($ipv4addr_arr[3])) {
296 $ipv4addr = $ipv4addr_arr[3];
306 for ($i = 0; $i < ob_get_level(); $i++)
308 ob_implicit_flush(1);
312 function force_no_cache(&$header_out)
314 $header_out['Pragma'] = 'no-cache, must-revalidate';
315 $header_out['Cache-Control'] = 'no-cache';
316 $header_out['Expires'] = '-1';
319 function file_lock($fname, $is_exclusive)
321 if (($res = @fopen($fname, "r+")) == FALSE) {
325 if (flock($res, ($is_exclusive ? LOCK_EX : LOCK_SH)) == FALSE) {
333 function file_unlock($res)
336 flock($res, LOCK_UN);
341 $escpush_from = array("\\", "\"");
342 $escpush_to = array("\\\\", "\\\"");
345 GLOBAL $escpush_from, $escpush_to;
347 return str_replace($escpush_from, $escpush_to, $s);
350 $escinp_from = array( "\"" );
351 $escinp_to = array( """ );
353 function escinput($s)
355 GLOBAL $escinp_from, $escinp_to;
357 return str_replace($escinp_from, $escinp_to, $s);
362 return htmlentities($s);
365 function esclfhtml($s)
367 return str_replace("\n", "<br>\n", htmlentities($s));
371 function langtolng($lang)
375 return ($G_lang == 'en' ? '-en' : '');
378 function csplitter($in, $sep)
384 for ($i = 0 ; $i < strlen($in) ; $i++) {
385 $ini = substr($in, $i, 1);
389 else if ($ini == $sep) {
408 $from = array ( '\\', '@', '|' );
409 $to = array ( '\\\\', '@', '¦' );
411 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
416 $from = array ( '\\', '|', "\t", "\n");
417 $to = array ( '\\\\', '\\|', "\\t", "\\n");
419 return (str_replace($from, $to, $s));
422 function xcapemesg($s)
424 $from = array ( "\n");
425 $to = array ( "\\n");
427 return (str_replace($from, $to, $s));
437 function getbyid($idx)
439 return ($this->el[$idx]);
442 function setbyid($idx, $v)
444 $this->el[$idx] = $v;
453 var $auth_only; // se tavolo riservato o libero
460 var $table_start; // information field
468 function create($idx)
470 if (($thiz = new Table()) == FALSE)
474 $thiz->player = array();
476 $thiz->auth_only = FALSE;
482 $thiz->table_token = "";
483 $thiz->table_start = 0;
485 $thiz->wakeup_time = 0;
492 $this->idx = $from->idx;
493 $this->player = array();
494 for ($i = 0 ; $i < $from->player_n ; $i++)
495 $this->player[$i] = $from->player[$i];
496 $this->player_n = $from->player_n;
498 log_main("PLAYER_N - parent::copy.".$this->player_n);
500 $this->auth_only = $from->auth_only;
502 $this->wag_own = $from->wag_own;
503 $this->wag_com = $from->wag_com;
504 $this->wag_tout = $from->wag_tout;
506 $this->table_token = $from->table_token;
507 $this->table_start = $from->table_start;
509 $this->wakeup_time = $from->wakeup_time;
512 function myclone($from)
514 if (($thiz = new Table()) == FALSE)
522 function spawn($from)
524 if (($thiz = new Table()) == FALSE)
527 $thiz->idx = $from->idx;
528 $thiz->player = array();
529 for ($i = 0 ; $i < $from->player_n ; $i++)
530 $thiz->player[$i] = $i;
531 $thiz->player_n = $from->player_n;
533 $thiz->auth_only = $from->auth_only;
535 $thiz->wag_own = $from->wag_own;
536 $thiz->wag_com = $from->wag_com;
537 $thiz->wag_tout = $from->wag_tout;
539 $thiz->table_token = $from->table_token;
540 $thiz->table_start = $from->table_start;
542 $thiz->wakeup_time = $from->wakeup_time;
547 function wag_set($user_idx, $mesg)
551 $this->wag_own = $user_idx;
552 $this->wag_com = $mesg;
556 function wag_reset($timeout)
558 log_main("WAG_RESET");
560 unset($this->wag_own);
563 $this->wag_tout = $timeout;
566 function player_get($idx)
568 return ($this->player[$idx]);
571 function player_set($idx, $player)
573 $this->player[$idx] = $player;
576 function user_add($idx)
578 $this->player[$this->player_n] = $idx;
581 return ($this->player_n - 1);
584 function user_rem($room, $user)
586 $tabpos = $user->table_pos;
588 /* verifico la consistenza dei dati */
589 if ($room->user[$this->player[$tabpos]] == $user) {
591 /* aggiorna l'array dei giocatori al tavolo. */
592 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
593 $this->player[$i] = $this->player[$i+1];
594 $user_cur = $room->user[$this->player[$i]];
595 $user_cur->table_pos = $i;
600 log_main("INCONSISTENCY ON TABLE.");
606 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
607 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
609 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
610 function act_content($user)
613 $isstanding = ($user->subst == 'standup');
614 $sitted = $this->player_n;
616 $cur_table = $user->table;
620 if ($sitted < PLAYERS_N) {
621 if ($this->auth_only) {
622 if ($user->flags & USER_FLAG_AUTH)
636 if ($table == $cur_table)
643 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
656 function Delay_Manager($triglevel)
658 $this->triglevel = $triglevel;
659 $this->delta = array();
660 $this->lastcheck = 0;
663 function delta_get($curtime)
665 // clean too old delta items
666 for ($i = 0 ; $i < count($this->delta) ; $i++) {
667 if ($this->delta[$i][0] < $curtime) {
668 array_splice($this->delta, $i, 1);
673 // add new delta items if delay exceeded $this->triglevel sec
674 if ($curtime > $this->lastcheck + $this->triglevel && $curtime < $this->lastcheck + 1200.0) {
675 $delta = $curtime - $this->lastcheck - $this->triglevel;
676 array_push($this->delta, array($curtime + $delta , $delta));
677 // fprintf(STDERR, "DELTA: add new delta [%f] [%f] [%f]\n", $this->triglevel, $curtime + $delta, $delta);
680 // extract the maximum valid delta
682 for ($i = 0 ; $i < count($this->delta) ; $i++) {
683 $delta_cur = $this->delta[$i][1];
684 if ($delta_max < $delta_cur)
685 $delta_max = $delta_cur;
688 // fprintf(STDERR, "DELTA: status %d, delta_max: %f\n", count($this->delta), $delta_max);
693 function lastcheck_set($curtime)
695 $this->lastcheck = $curtime;
702 function Client_prefs()
706 static function from_user($user)
708 $thiz = new Client_prefs();
709 $thiz->user_load($user);
714 static function from_json($json)
716 $thiz = new Client_prefs();
717 if ($thiz->json_load($json) == FALSE) {
724 function user_load($user)
726 fprintf(STDERR, "QQ %s: %x\n", __FUNCTION__, $user->flags);
727 $this->listen = ($user->flags & USER_FLAG_MAP_AUTH) >> 2;
729 fprintf(STDERR, "QQ %s: LISTEN: %d\n", __FUNCTION__, $this->listen);
732 function json_load($json_s)
734 if (gettype($json_s) == "string") {
735 if (($json = json_decode($json_s)) == FALSE)
741 $this->listen = $json->listen;
746 function store($user, $is_save)
749 fprintf(STDERR, "QQ %s::%s PRE: %x\n", __CLASS__, __FUNCTION__,
750 $user->flags & (~USER_FLAG_S_ALL & ~USER_FLAG_AUTH));
751 $user->flags_set(($this->listen << 2), USER_FLAG_MAP_AUTH);
752 fprintf(STDERR, "QQ %s::%s %x\n", __CLASS__, __FUNCTION__,
764 var $crystal_filename;
768 var $comm; // commands for many people
769 var $step; // current step of the comm array
770 var $garbage_timeout;
775 function Room ($crystal_filename) {
776 $this->crystal_filename = $crystal_filename;
777 $this->user = array();
778 $this->table = array();
779 $this->match = array();
781 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
782 $this->user[$i] = User::create($this, $i, "", "");
785 for ($i = 0 ; $i < TABLES_N ; $i++) {
786 $this->table[$i] = Table::create($i);
789 $row = ( (((int)($i / 4)) % 2) == 0 );
790 $col = ($i % 2 == 0);
791 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
794 $this->table[$i]->auth_only = FALSE;
797 if ($i < TABLES_AUTH_N)
798 $this->table[$i]->auth_only = TRUE;
800 $this->table[$i]->auth_only = FALSE;
802 $this->garbage_timeout = 0;
803 $this->shm_sz = SHM_DIMS_MIN;
805 $this->delay_mgr = new Delay_Manager(1.5);
808 function garbage_manager($force)
810 GLOBAL $G_lang, $mlang_brisk, $G_base;
814 log_rd2("garbage_manager START");
816 /* Garbage collector degli utenti in timeout */
817 $curtime = microtime(TRUE);
819 $delta = $this->delay_mgr->delta_get($curtime);
821 if (!$force && !($this->garbage_timeout < $curtime)) {
822 $this->delay_mgr->lastcheck_set($curtime);
826 // Before all align times with table timeout
827 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
828 $table_cur = $this->table[$table_idx];
829 // if the table is complete and exists its shared mem we get the info about users lacc
831 if ($table_cur->player_n == PLAYERS_N) {
832 log_main("PLAYERS == N TABLE ".$table_idx);
835 $no_recovery = FALSE;
836 if (isset($this->match[$table_idx])) {
837 $bri = $this->match[$table_idx];
839 if ($table_cur->table_token != $bri->table_token) {
840 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
841 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
850 log_main("garbage_manager: bri loaded successfully.");
851 $bri->garbage_manager(TRUE);
853 $bri_table = $bri->table[0];
855 // is the end of the table
857 if ($bri->the_end == TRUE) {
859 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
861 log_main("garbage_manager: INSIDE THE END.");
863 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
864 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
865 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
868 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
869 // stat must be "table" by definition
870 $user_cur = $this->user[$table_cur->player[$i]];
871 $bri_user = $bri->user[$i];
873 $user_cur->subst = $bri_user->subst;
874 $user_cur->step = $bri_user->step;
875 $user_cur->lacc = $bri_user->lacc;
876 $user_cur->laccwr = $bri_user->lacc;
877 $user_cur->bantime = $bri_user->bantime;
880 log_legal($curtime, $user_cur->ip, $user_cur, "STAT:DESTROY_GAME", $plist);
882 $this->room_join_wakeup($user_cur, FALSE, 0);
883 $table_cur->table_token = "";
884 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
886 $this->match_del($table_idx);
889 log_main("gm:: save_data");
891 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
892 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
895 } // if ($bri == FALSE
896 else if ($no_recovery == FALSE) {
897 log_crit("ERROR: table ".$table_idx." unrecoverable join");
899 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
900 $user_cur = $this->user[$table_cur->player[$i]];
901 $user_cur->subst = "shutdowner";
902 $user_cur->step_inc();
904 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
905 $ret .= "gst.st = ".($user_cur->step+1)."; ";
906 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
907 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
908 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
909 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
910 $user_cur->step_inc();
913 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
914 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
915 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
917 log_legal($curtime, $user_cur->ip, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
919 $this->room_join_wakeup($user_cur, TRUE, -2);
920 $table_cur->table_token = "";
923 } // if ($table_cur->player_n == PLAYERS_N) {
924 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
926 log_rd2("out new loop.");
928 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
929 $user_cur = $this->user[$i];
931 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
933 if ($user_cur->sess == "")
936 if ($user_cur->lacc + EXPIRE_TIME_RD < ($curtime - $delta)) {
937 // Auto logout dell'utente
938 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime - delta ".($curtime - $delta));
940 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
941 log_auth($user_cur->sess, "Autologout session.");
945 log_rd2("AUTO LOGOUT.");
946 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
947 $this->room_wakeup($user_cur);
948 else if ($user_cur->subst == 'standup')
949 $this->room_outstandup($user_cur);
951 log_rd2("LOGOUT FROM WHAT ???");
955 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < ($curtime - $delta)) { // lo rimettiamo in piedi
956 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
957 $this->room_wakeup($user_cur);
958 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
959 /* 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" */
960 $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);
961 $user_cur->step_inc();
965 log_rd2("GARBAGE UPDATED!");
967 $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
970 $this->delay_mgr->lastcheck_set($curtime);
974 function show_room($user_step, $user)
976 GLOBAL $G_lang, $mlang_brisk;
977 log_main("show_room: username: ".$user->name);
979 $ret = sprintf('gst.st = %d; ', $user_step);
981 $prefs = Client_prefs::from_user($user);
982 $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs));
985 if ($user->flags & USER_FLAG_ISOLAUTH) {
986 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
988 else if ($user->flags & USER_FLAG_LISTAUTH) {
989 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
992 $ret .= 'list_set(\'all\', false, \'\' ); ';
996 if ($user->subst == 'standup')
997 $ret .= "tra.show(); ";
999 $ret .= "tra.hide(); ";
1001 $ret .= sprintf('stat = "%s";', $user->stat);
1003 $ret .= root_welcome($user);
1004 if ($user->flags & USER_FLAG_DBFAILED) {
1005 $ret .= "gst.st = ".($user->step+1)."; ";
1006 $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
1009 $ret .= sprintf('subst = "%s";', $user->subst);
1010 $ret .= $user->myname_innerHTML();
1012 for ($i = 0 ; $i < TABLES_N ; $i++) {
1014 $ret .= $this->table_content($user, $i);
1015 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1016 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1017 $ret .= $this->table[$i]->act_content($user);
1018 if ($this->table[$i]->wag_own != -1)
1019 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
1021 $ret .= sprintf('tra.rem(%d); ', $i);
1023 $ret .= $this->standup_content($user);
1024 $ret .= "setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); ";
1030 function room_wakeup($user)
1032 $table_idx = $user->table;
1033 $table = $this->table[$table_idx];
1035 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1039 $from_table = ($user->stat == "table");
1041 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1043 for ($i = 0 ; $i < $table->player_n ; $i++) {
1044 $user_cur = $this->user[$table->player[$i]];
1045 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1047 if ($user->idx_get() != $table->player[$i]) {
1048 $user_cur->stat_set("room");
1049 $user_cur->subst = "sitdown";
1050 $user_cur->laccwr = $curtime;
1052 else if ($user->sess != "") {
1053 $user_cur->stat_set("room");
1054 $user_cur->subst = "standup";
1055 $user_cur->laccwr = $curtime;
1056 $user_cur->table = -1;
1061 $user->stat_set("room");
1062 $user->subst = "standup";
1063 $user->laccwr = $curtime;
1066 $remove_wagon = FALSE;
1067 if($table->wag_own == $user->idx_get()) {
1068 $table->wag_reset($curtime);
1069 $remove_wagon = TRUE;
1073 /* aggiorna l'array dei giocatori al tavolo. */
1074 $table->user_rem($this, $user);
1076 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1077 $user_cur = $this->user[$i];
1078 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1081 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1083 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1084 if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
1085 $ret .= 'gst.st_loc++; xstm.stop(); window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1086 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1087 log_main("DOCUMENT.index.php: from table");
1089 else if ($user_cur->stat == "room") {
1090 log_main("DOCUMENT.index.php: from table");
1092 $ret .= $this->table_content($user_cur, $table_idx);
1093 $ret .= $this->standup_content($user_cur);
1095 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1096 $ret .= $table->act_content($user);
1098 if ($user->idx_get() == $i) {
1099 // set the new status
1100 $ret .= 'subst = "standup"; tra.show(); ';
1101 // clean the action buttons in other tables
1102 for ($e = 0 ; $e < TABLES_N ; $e++) {
1103 if ($this->table[$e]->player_n < PLAYERS_N) {
1104 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1105 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1106 $ret .= $this->table[$e]->act_content($user);
1111 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1112 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1113 $ret .= $table->act_content($user_cur);
1116 log_wr("ROOM_WAKEUP: ".$ret);
1117 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1118 $user_cur->step_inc();
1122 function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
1124 $table_idx = $user->table;
1125 $table = $this->table[$table_idx];
1127 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1130 $user_wup = array();
1132 $user_tab = array();
1134 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1136 for ($i = 0 ; $i < $table->player_n ; $i++) {
1137 $user_cur = $this->user[$table->player[$i]];
1138 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1139 if ($user_cur->sess != "") {
1140 if ($update_lacc == TRUE) {
1141 $user_cur->laccwr = $curtime;
1143 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1144 if ($user_cur->subst == "shutdowned") {
1145 $user_cur->stat_set("room");
1146 $user_cur->subst = "sitdown";
1148 else if ($user_cur->subst == "shutdowner") {
1149 $user_cur->stat_set("room");
1150 $user_cur->subst = "standup";
1151 $user_cur->table = -1;
1152 $user_wup[$user_wup_n++] = $user_cur;
1154 $remove_wagon = FALSE;
1155 if($table->wag_own == $table->player[$i]) {
1156 $remove_wagon = TRUE;
1157 $table->wag_reset($curtime);
1160 $user_tab[$user_tab_n++] = $table->player[$i];
1164 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1165 $table->user_rem($this, $user_wup[$wup_idx]);
1167 /* aggiorna l'array dei giocatori al tavolo. */
1169 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1170 log_main("START LOOP");
1171 $user_cur = $this->user[$i];
1172 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1173 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1178 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1180 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1181 if ($user_cur->stat == "room") {
1182 log_main("DOCUMENT.index.php from table");
1184 $ret .= $this->table_content($user_cur, $table_idx);
1185 $ret .= $this->standup_content($user_cur);
1187 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1188 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1189 $ret .= $table->act_content($user_cur);
1192 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1193 if ($user_tab[$tab_idx] == $i)
1196 // for users that wakeup the room will be reconstructed by index_rd.php
1197 if ($tab_idx < $user_tab_n) {
1198 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1200 // ARRAY_POP DISABLED
1201 // if ($trans_delta == 0)
1202 // while (array_pop($user_cur->comm) != NULL);
1204 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1205 $user_cur->comm[$user_cur->step % COMM_N] = "";
1206 $user_cur->step_inc();
1207 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
1208 $user_cur->step_inc();
1209 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1213 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1215 log_main("JOIN_WAKEUP more");
1216 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1217 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1218 $ret .= $table->act_content($user_cur);
1220 log_main("JOIN_WAKEUP end more");
1222 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1223 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1224 $user_cur->step_inc();
1228 function room_outstandup($user)
1230 $this->room_sitdown($user, -1);
1233 function table_update($user)
1235 log_main("table_update: pre - USER: ".$user->name);
1237 $table_idx = $user->table;
1239 if ($table_idx > -1)
1240 $table = $this->table[$table_idx];
1242 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1244 $user_cur = $this->user[$i];
1245 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1248 $ret = "gst.st = ".($user_cur->step+1)."; ";
1249 if ($table_idx > -1)
1250 $ret .= $this->table_content($user_cur, $table_idx);
1252 if ($user->idx_get() == $i) {
1253 $ret .= $user->myname_innerHTML();
1255 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1256 $user_cur->step_inc();
1259 log_main("table_update: post");
1262 function room_sitdown($user, $table_idx)
1264 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1268 if ($table_idx > -1 && $table_idx < TABLES_N) {
1269 $table = $this->table[$table_idx];
1272 if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
1273 for ($i = 0 ; $i < TABLES_N ; $i++) {
1274 if ($table->wag_own == $table->player[$i]) {
1275 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1276 $table->wag_reset(time());
1283 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1285 $user_cur = $this->user[$i];
1286 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1289 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1290 if ($table_idx > -1)
1291 $ret .= $this->table_content($user_cur, $table_idx);
1292 $ret .= $this->standup_content($user_cur);
1294 if ($user->idx_get() == $i) {
1295 $ret .= 'subst = "sitdown"; tra.hide(); ';
1296 // clean the action buttons in other tables
1297 for ($e = 0 ; $e < TABLES_N ; $e++) {
1298 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1299 $ret .= $this->table[$e]->act_content($user_cur);
1302 else if ($table_idx > -1) {
1303 if ($table->player_n == PLAYERS_N) {
1304 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1305 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1306 $ret .= $table->act_content($user_cur);
1309 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1310 $user_cur->step_inc();
1314 function chatt_send($user, $mesg)
1316 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1320 $msg = mb_substr($mesg, 6, 128, "UTF-8");
1322 $dt = date("H:i ", $curtime);
1333 $is_normchat = FALSE;
1334 /* for old isolation management $is_ticker = FALSE; */
1335 $update_room = FALSE;
1337 if (strcmp($msg, "/tav") == 0 ||
1338 strncmp($msg, "/tav ", 5) == 0) {
1340 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1341 /* 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>" */
1342 $msg = $mlang_brisk['tickmust'][$G_lang];
1343 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1348 $table = $this->table[$user->table];
1350 if ($table->wag_own != -1) {
1351 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1352 $msg = $mlang_brisk['tickjust'][$G_lang];
1353 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1358 $dtime = $curtime - $table->wag_tout;
1359 if ($dtime < EXPIRE_TIME_WAG) {
1360 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1361 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1362 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1363 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1368 $msg = substr($msg, 5);
1370 $table->wag_set($user->idx_get(), $msg);
1371 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1372 $to_room = $to_user;
1373 /* for old isolation management $is_ticker = TRUE; */
1375 } // /tav chat command
1377 else if (strncmp($msg, "/alarm ", 7) == 0) {
1378 if (strncmp($msg, "/alarm to ", 10) == 0) {
1379 $sp_pos = strpos($msg, " ", 10);
1380 $target = substr($msg, 10, $sp_pos - 10);
1381 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1385 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1388 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1389 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1390 $msg = $mlang_brisk['alarpass'][$G_lang];
1391 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1396 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1397 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1398 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1399 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1400 $dt, NICKSERV, $prestr);
1402 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1403 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1404 /* MLANG: "chiudi" */
1405 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1407 } // /alarm chat command
1408 else if (strncmp($msg, "/listen ", 8) == 0) {
1409 $arg = substr($msg, 8);
1411 if (strcasecmp($arg, "isolation") == 0) {
1413 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1414 $user->table >= TABLES_AUTH_N) {
1415 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1419 $user->flags &= ~USER_FLAG_MAP_AUTH;
1420 $user->flags |= USER_FLAG_ISOLAUTH;
1421 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1424 else if (strcasecmp($arg, "auth") == 0) {
1425 $flags_old = $user->flags;
1426 $user->flags &= ~USER_FLAG_MAP_AUTH;
1427 $user->flags |= USER_FLAG_LISTAUTH;
1428 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1431 $flags_old = $user->flags;
1432 $user->flags &= ~USER_FLAG_MAP_AUTH;
1433 $to_user = 'list_set(\'all\', true, \'\'); ';
1436 // if from isolation redraw standup area
1437 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1438 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1442 else if (strcmp($msg, "/authreq") == 0) {
1443 if ($user->flags & USER_FLAG_AUTH) {
1444 $to_user = sprintf('authbox(300,200);');
1447 /* 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." */
1448 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1451 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1452 if ($user->flags & USER_FLAG_AUTH) {
1453 $to_user = sprintf('mesgtoadmbox(500,300);');
1456 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1457 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1460 else if (strncmp($msg, "/nick ", 6) == 0) {
1461 log_main("chatt_send BEGIN");
1464 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1465 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1469 $msg = "COMMAND ".$msg;
1470 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1471 $user_cur = $this->user[$i];
1473 if ($user_cur->sess == '')
1475 if (strcasecmp($user_cur->name,$name_new) == 0)
1478 if ($i < MAX_PLAYERS) {
1479 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1480 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1484 /* 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>" */
1485 if ($user->flags & USER_FLAG_AUTH) {
1486 if (strcasecmp($user->name,$name_new) != 0) {
1487 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1488 ($user->subst == 'standup' ||
1489 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1492 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1493 for ($i = 0 ; $i < TABLES_N ; $i++) {
1494 $to_user .= $this->table[$i]->act_content($user);
1498 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1503 $user->name = $name_new; // OK - nick changed
1504 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1505 if (($user->flags & USER_FLAG_AUTH) == 0) {
1506 if (($bdb = BriskDB::create()) != FALSE) {
1508 /* 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>" */
1509 if ($bdb->login_exists($name_new)) {
1510 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1511 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1516 log_main("chatt_send start set");
1518 $update_room = TRUE;
1520 } // nick chat command
1522 else if (strncmp($msg, "/st ", 4) == 0) {
1523 log_main("chatt_send BEGIN");
1526 $st_str = substr($msg, 4);
1528 if (strcasecmp($st_str, "normale") == 0) {
1529 $st = USER_FLAG_S_NORM;
1531 else if (strcasecmp($st_str, "pausa") == 0) {
1532 $st = USER_FLAG_S_PAU;
1534 else if (strcasecmp($st_str, "fuori") == 0) {
1535 $st = USER_FLAG_S_OUT;
1537 else if (strcasecmp($st_str, "cane") == 0) {
1538 $st = USER_FLAG_S_DOG;
1540 else if (strcasecmp($st_str, "cibo") == 0) {
1541 $st = USER_FLAG_S_EAT;
1543 else if (strcasecmp($st_str, "lavoro") == 0) {
1544 $st = USER_FLAG_S_WRK;
1546 else if (strcasecmp($st_str, "sigaretta") == 0) {
1547 $st = USER_FLAG_S_SMK;
1549 else if (strcasecmp($st_str, "presente") == 0) {
1550 $st = USER_FLAG_S_EYE;
1552 else if (strcasecmp($st_str, "coniglio") == 0) {
1553 $st = USER_FLAG_S_RABB;
1555 else if (strcasecmp($st_str, "calcio") == 0) {
1556 $st = USER_FLAG_S_SOCC;
1558 else if (strcasecmp($st_str, "pupo") == 0) {
1559 $st = USER_FLAG_S_BABY;
1561 else if (strcasecmp($st_str, "pulizie") == 0) {
1562 $st = USER_FLAG_S_MOP;
1564 else if (strcasecmp($st_str, "babbo") == 0) {
1565 $st = USER_FLAG_S_BABBO;
1567 else if (strcasecmp($st_str, "renna") == 0) {
1568 $st = USER_FLAG_S_RENNA;
1570 else if (strcasecmp($st_str, "pupazzo") == 0) {
1571 $st = USER_FLAG_S_PUPAZ;
1573 else if (strcasecmp($st_str, "vischio") == 0) {
1574 $st = USER_FLAG_S_VISCH;
1577 /* MLANG: "Questo stato non esiste." */
1578 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1582 log_main("chatt_send start set");
1583 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1584 $update_room = TRUE;
1585 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1588 } // nick chat command
1590 else { // normal chat line
1591 $is_normchat = TRUE;
1592 if (CHAT_ENABLED && $curtime < ($user->chat_ban + $user->chat_dlt)) {
1594 $user->chat_dlt = $user->chat_dlt * 2;
1595 if ($user->chat_dlt > 120)
1596 $user->chat_dlt = 120;
1598 else if ($user->chat_lst == $msg)
1600 else if (CHAT_ENABLED && $curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1601 $user->chat_ban = $curtime;
1602 $user->chat_dlt = 5;
1606 $user->chat_ban = 0;
1607 $user->chat_dlt = 0;
1611 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1614 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1615 // temporary silentiation for troll (will became array check)
1616 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1617 $to_room = $to_user;
1620 log_legal($curtime, $user->ip, $user,
1621 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1623 $user->chat_lst = "$msg";
1624 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1634 // Output to clients
1637 if ($to_user != FALSE) {
1638 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1639 $user->comm[$user->step % COMM_N] .= $to_user;
1643 if ($to_room != FALSE) {
1644 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1645 $user_cur = $this->user[$i];
1646 if ($target != "" && $user_cur->name != $target)
1648 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user->idx_get() == $i)
1651 if ($is_normchat == TRUE) {
1652 // use MAP_AUTH to check if auth or isolation
1653 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1654 if (($user->flags & USER_FLAG_AUTH) == 0) {
1660 else if ($is_ticker) {
1661 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1662 if ($user->table >= TABLES_AUTH_N)
1667 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1668 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1669 $user_cur->step_inc();
1674 // FIXME BRISK4: include for each kind of table
1675 require_once("${G_base}briskin5/Obj/briskin5.phh");
1676 // Before all align times with table timeout
1677 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1678 if (isset($this->match[$table_idx])) {
1679 $bri = $this->match[$table_idx];
1681 $bri_table = $bri->table[0];
1682 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1683 // stat must be "table" by definition
1684 $bri_user = $bri->user[$i];
1686 if ($target != "" && $bri_user->name != $target)
1688 log_main("writa: ".$user_mesg);
1689 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1690 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1691 $bri_user->step_inc();
1693 } // if (isset($this->match
1694 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1695 } // if ($to_tabl == true ...
1698 if ($user->stat == 'room' && $user->subst == 'standup') {
1699 $this->standup_update($user);
1701 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1702 log_main("chatt_send pre table update");
1703 $this->table_update($user);
1704 log_main("chatt_send post table update");
1706 } // if ($update_room ...
1709 } // function chatt_send( ...
1711 function get_user($sess, &$idx)
1715 if (validate_sess($sess)) {
1716 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1717 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1720 $ret = $this->user[$i];
1724 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1725 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1726 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1729 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1736 * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1739 * if ($idx > -1 && ret == FALSE) => duplicated nick
1740 * if ($idx == -2 && ret == FALSE) => invalid name
1741 * if ($idx == -3 && ret == FALSE) => wrong password
1742 * if ($idx == -1 && ret == FALSE) => no space left
1743 * if ($idx == 0 && ret == user) => SUCCESS
1744 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
1747 function add_user(&$sess, &$idx, $name, $pass, $ip, $cookie)
1753 $authenticate = FALSE;
1755 $login_exists = FALSE;
1757 $ghost_auth = FALSE;
1762 if (($name_new = validate_name($name)) == FALSE) {
1767 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1768 if (validate_sess($sess) == FALSE)
1771 /* if pass != FALSE verify the login with pass */
1772 log_auth("XXX", "auth1");
1774 if (($bdb = BriskDB::create()) != FALSE) {
1776 if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
1777 log_auth("XXX", "auth2");
1778 $authenticate = $bdb->login_verify($name_new, $pass, $code);
1779 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
1781 if ($authenticate != FALSE) {
1782 $user_type = $authenticate->type_get();
1790 $login_exists = $bdb->login_exists($name_new);
1794 // if db is down, send a warning and verify only current users
1795 // no actions at this moment
1797 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1799 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1803 if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
1805 continue; // NOTE: CHECK IT !!
1807 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1808 if ($authenticate != FALSE) {
1810 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1821 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1823 /* there is another user logged with your account and you and him have authenticated => new user
1824 get the session of the old user */
1825 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
1828 $ghost_user = $this->user[$ghost];
1830 $ghost_user->comm[$ghost_user->step % COMM_N] = "";
1831 $ghost_user->step_inc();
1834 $ghost_user->sess = $sess;
1837 $ghost_user->sess = $sess;
1840 // If user at the table we need to update the table data too
1841 $table_idx = $ghost_user->table;
1842 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1843 require_once("${G_base}briskin5/Obj/briskin5.phh");
1844 if (isset($this->match[$table_idx])) {
1845 $bri = $this->match[$table_idx];
1847 if ($bri->the_end != TRUE) {
1848 $bri->user[$ghost_user->table_pos]->comm[$bri->user[$ghost_user->table_pos]->step % COMM_N] = "";
1849 $bri->user[$ghost_user->table_pos]->step_inc();
1850 $bri->user[$ghost_user->table_pos]->sess = $sess;
1856 return ($this->user[$ghost]);
1858 else if ($idx != -1 && $i == MAX_PLAYERS) {
1863 $this->user[$idx]->sess = $sess;
1866 $this->user[$idx]->sess = $sess;
1868 $this->user[$idx]->name = $name_new; // OK - add new user
1869 $this->user[$idx]->stat_set("room");
1870 $this->user[$idx]->step_set(0);
1871 while (array_pop($this->user[$idx]->comm) != NULL);
1872 $this->user[$idx]->subst = "standup";
1873 $this->user[$idx]->lacc = $curtime;
1874 $this->user[$idx]->laccwr = $curtime;
1875 $this->user[$idx]->bantime = 0;
1876 $this->user[$idx]->ip = $ip;
1878 $this->user[$idx]->flags = $user_type;
1879 $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
1880 $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
1881 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
1883 if ($authenticate != FALSE) {
1884 $this->user[$idx]->code = $authenticate->code_get();
1886 // all this part is included in the db server
1887 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1889 if (isset($cookie['CO_list'])) {
1890 fprintf(STDERR, "QQ: %s CO_list: [%s]\n", __FUNCTION__, $cookie['CO_list']);
1891 if (strcmp($cookie['CO_list'], "auth") == 0) {
1892 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1893 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1895 if (strcmp($cookie['CO_list'], "isolation") == 0) {
1896 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1897 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
1900 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1905 fprintf(STDERR, "QQ: CO_list not set flags: %x\n", __FUNCTION__, $this->user[$idx]->flags);
1908 fprintf(STDERR, "QQ %s: flag %x\n", __FUNCTION__, $this->user[$idx]->flags);
1910 log_main("ghost: rename!");
1911 $ghost_user = $this->user[$ghost];
1913 if ($ghost_auth == FALSE) {
1914 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1915 $ghostname = 'ghost'.$sfx;
1916 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1917 if (strcmp("", $this->user[$i]->sess) == 0)
1920 if (strcasecmp($this->user[$i]->name, $ghostname) == 0) {
1925 if ($ghostname != '')
1929 $ghost_user->name = $ghostname;
1931 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1932 $this->standup_update($ghost_user);
1935 log_main("chatt_send pre table update");
1936 $this->table_update($ghost_user);
1937 log_main("chatt_send post table update");
1939 } // if ($ghost_auth == FALSE
1941 // FIXME: cacciare il vecchio utente room && table (if needed)
1942 $ghost_user->the_end = TRUE;
1943 $ghost_user->lacc = 0;
1944 $this->garbage_manager(TRUE);
1946 } // if ($ghost > -1) {
1951 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));
1953 $ret = $this->user[$real_idx];
1960 function standup_update($user)
1962 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1963 $user_cur = $this->user[$i];
1964 if ($user_cur->sess == '')
1967 log_main("STANDUP START: ".$user_cur->stat);
1969 if ($user_cur->stat == 'room') {
1970 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1971 if ($user->idx_get() == $i) {
1972 $user_cur->comm[$user_cur->step % COMM_N] .= $user->myname_innerHTML();
1974 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1976 $user_cur->step_inc();
1982 static function create($crystal_filename)
1984 if (($room_ser = @file_get_contents($crystal_filename)) == FALSE ||
1985 ($room = unserialize($room_ser)) == FALSE) {
1986 fprintf(STDERR, "NEW ROOM\n");
1987 $room = new Room($crystal_filename);
1990 fprintf(STDERR, "ROOM FROM FILE\n");
1991 rename($crystal_filename, $crystal_filename.".old");
1998 function load_data()
2003 if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1) {
2004 log_main("ftok failed");
2008 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2009 log_main("shmop_open failed");
2013 $shm_sz = SHM_DIMS_MIN;
2015 if ($shm = shm_attach($tok, $shm_sz)) {
2016 $room = @shm_get_var($shm, $tok); // CHECKED BELOW
2018 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2020 log_only("bri count ".count($room));
2022 if ($room == FALSE) {
2023 log_only("INIT MAIN DATA");
2026 $room = Room::create();
2028 log_shme("Room::create");
2030 if (Room::save_data($room) == FALSE)
2035 $room->shm_sz = $shm_sz;
2039 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2040 if (($room->user[$i] = User::load_data($i, FALSE)) == FALSE) {
2041 log_crit("User::load_data failed");
2045 if ($i < MAX_PLAYERS) {
2051 // SHSPLIT: load users from the shared memory
2060 function save_data_orig($room)
2068 if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1)
2071 while ($room->shm_sz < SHM_DIMS_MAX) {
2072 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2075 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2076 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2080 if (shm_remove($shm) === FALSE) {
2081 log_only("REMOVE FALLITA");
2085 $room->shm_sz += SHM_DIMS_DLT;
2093 function dump_data()
2095 $room_ser = serialize($this);
2096 $room_ser_len = mb_strlen($room_ser, "ASCII");
2097 if (file_put_contents($this->crystal_filename, $room_ser) == $room_ser_len) {
2104 function save_data($room)
2111 if (($tok = @ftok(FTOK_PATH."/main", "C")) == -1)
2114 // SHSPLIT: before save the $room you must save users,
2115 // detach from main struct and (then) reattach
2116 $user_park = array();
2117 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2118 $user_park[$i] = $room->user[$i];
2119 $room->user[$i] = FALSE;
2122 while ($room->shm_sz < SHM_DIMS_MAX) {
2123 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2126 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2127 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2128 log_shme("Room::save_data");
2132 if (shm_remove($shm) === FALSE) {
2133 log_only("REMOVE FALLITA");
2137 $room->shm_sz += SHM_DIMS_DLT;
2143 // SHSPLIT: reattach users to the room class
2144 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2145 User::save_data($user_park[$i], $i);
2146 $room->user[$i] = $user_park[$i];
2148 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
2153 static function lock_data($is_exclusive)
2155 if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) {
2156 self::$delta_t = microtime(TRUE);
2157 log_lock("LOCK room [".self::$delta_t."]");
2165 static function unlock_data($res)
2169 log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]");
2175 function standup_content($user)
2180 if ($user->stat != 'room')
2183 for ($i = 0 , $ct = 0 ; $ct < 4 && $i < MAX_PLAYERS ; $i++) {
2184 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2189 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2191 $content = ' j_stand_cont( [ ';
2193 for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
2194 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2197 $flags = $this->user[$i]->flags;
2199 if ($this->user[$i]->subst == "standup") {
2200 if ($user->idx_get() == $i) {
2204 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name));
2213 function table_content($user, $table_idx)
2219 // Si possono usare i dati nella classe table
2222 $sess = $user->sess;
2223 $table = $this->table[$table_idx];
2225 if ($user->stat != 'room')
2229 for ($i = 0 ; $i < $table->player_n ; $i++) {
2230 $user_cur = $this->user[$table->player[$i]];
2232 $flags = $user_cur->flags;
2234 if ($user->idx_get() == $table->player[$i])
2237 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2239 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2244 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2249 function request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, $path, $addr, $get, $post, $cookie)
2251 printf("NEW_SOCKET (root): %d PATH [%s]\n", intval($new_socket), $path);
2253 $enc = get_encoding($header);
2254 if (isset($header['User-Agent'])) {
2255 if (strstr($header['User-Agent'], "MSIE")) {
2256 $transp_type = "htmlfile";
2259 $transp_type = "xhr";
2263 $transp_type = "iframe";
2265 force_no_cache($header_out);
2271 index_main($this, $transp_type, $header_out, $addr, $get, $post, $cookie);
2272 $content = ob_get_contents();
2275 // fprintf(STDERR, "\n\nCONTENT [%s]\n\n", $content);
2276 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2280 case "index_wr.php":
2282 // Enhance required: in the POST case, after the header you must get content
2283 // from the socket, waiting if necessary
2286 fprintf(STDERR, "\n\nDENTRO QUI\n\n");
2288 index_wr_main($this, $addr, $get, $post, $cookie);
2289 $content = ob_get_contents();
2292 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2296 case "index_rd_ifra.php":
2298 if (!isset($cookie['sess'])
2299 || (($user = $this->get_user($cookie['sess'], $idx)) == FALSE)) {
2300 if (($transp = gpcs_var('transp', $get, $post, $cookie)) === FALSE)
2303 $content = User::stream_fini($transp, $s_a_p->rndstr, TRUE);
2305 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2310 // close a previous opened index_read_ifra socket, if exists
2311 if (($prev = $user->rd_socket_get()) != NULL) {
2312 $s_a_p->socks_unset($user->rd_socket_get());
2313 fclose($user->rd_socket_get());
2314 printf("CLOSE AND OPEN AGAIN ON IFRA2\n");
2315 $user->rd_socket_set(NULL);
2319 $user->stream_init($s_a_p->rndstr, $enc, $header_out, $content, $get, $post, $cookie);
2321 $response = headers_render($header_out, -1).chunked_content($user->rd_zls_get(), $content);
2322 $response_l = mb_strlen($response, "ASCII");
2324 $wret = @fwrite($new_socket, $response, $response_l);
2325 if ($wret < $response_l) {
2326 printf("TROUBLES WITH FWRITE: %d\n", $wret);
2327 $user->rd_cache_set(mb_substr($content, $wret, $response_l - $wret, "ASCII"));
2330 $user->rd_cache_set("");
2332 fflush($new_socket);
2335 $s_a_p->socks_set($new_socket, $user, NULL);
2336 $user->rd_socket_set($new_socket);
2337 printf(" - qui ci siamo - ");
2344 if (!(BRISK_DEBUG & DBG_ENGI))
2346 fprintf(STDERR, "TEST.PHP running\n");
2347 if (isset($post['data'])) {
2348 $content = $post['data'];
2351 $content = "NO DATA AVAILABLE";
2353 $header_out['Content-Type'] = 'text/plain';
2354 $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content);
2358 /* FAR TODO: move all into an array of registered sub-apps */
2359 $subs = "briskin5/";
2360 $subs_l = strlen($subs);
2361 if (!strncmp($path, $subs, $subs_l)) {
2362 $ret = Bin5::request_mgr(&$s_a_p, $header, &$header_out, &$new_socket, substr($path, $subs_l) , $addr, $get, $post, $cookie);
2371 function match_add($idx, $match)
2373 $this->match[$idx] = $match;
2376 function match_del($idx)
2378 unset($this->match[$idx]);
2381 function match_get($idx, $token)
2383 if (isset($this->match[$idx])) {
2385 || $token == $this->match[$idx]->table_token) {
2386 return ($this->match[$idx]);
2394 function make_seed()
2396 list($usec, $sec) = explode(' ', microtime());
2397 return (float) $sec + ((float) $usec * 100000);
2400 function btrace_line($ar)
2402 GLOBAL $G_btrace_pref_sub;
2405 for ($i = 0 ; $i < count($ar) ; $i++) {
2406 $with_class = isset($ar[$i]['class']);
2407 $with_file = isset($ar[$i]['file']);
2408 $ret .= sprintf("%s%s%s (%s:%d)", ($i == 0 ? "" : ", "),
2409 ($with_class ? $ar[$i]['class'].$ar[$i]['type'] : ""),
2410 $ar[$i]['function'], ($with_file ? str_replace($G_btrace_pref_sub, "", $ar[$i]['file']) : ""),
2411 ($with_file ? $ar[$i]['line'] : ""));
2417 function trace_ftok($id, $add)
2419 // NOTE: without space to use sed to substitute "= @ftok(" with "= @ftok("
2420 $tok=@ftok($id, $add);
2422 log_shme($tok.": ".$id." + ".$add);
2427 function log_mop($step, $log)
2429 GLOBAL $sess, $PHP_SELF;
2431 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2434 if (isset($sess) == FALSE)
2439 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2442 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2443 $btrace = btrace_line(debug_backtrace());
2446 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2447 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $log, $btrace));
2453 function log_only2($log)
2455 GLOBAL $sess, $PHP_SELF;
2457 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2460 if (isset($sess) == FALSE)
2465 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2468 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2469 $btrace = btrace_line(debug_backtrace());
2472 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2473 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2478 function log_crit($log)
2480 GLOBAL $sess, $PHP_SELF;
2482 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2485 if (isset($sess) == FALSE)
2490 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2493 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2494 $btrace = btrace_line(debug_backtrace());
2497 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2498 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2503 function log_only($log)
2505 GLOBAL $sess, $PHP_SELF;
2507 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2510 if (isset($sess) == FALSE)
2515 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2518 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2519 $btrace = btrace_line(debug_backtrace());
2522 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2523 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2528 function log_main($log)
2530 GLOBAL $sess, $PHP_SELF;
2532 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2535 if (isset($sess) == FALSE)
2540 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2543 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2544 $btrace = btrace_line(debug_backtrace());
2547 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2548 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2553 function log_rd($log)
2555 GLOBAL $sess, $PHP_SELF;
2557 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2560 if (isset($sess) == FALSE)
2565 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2568 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2569 $btrace = btrace_line(debug_backtrace());
2572 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2573 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2578 function log_rd2($log)
2580 GLOBAL $sess, $PHP_SELF;
2582 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2585 if (isset($sess) == FALSE)
2590 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2593 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2594 $btrace = btrace_line(debug_backtrace());
2598 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2599 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2604 function log_send($log)
2606 GLOBAL $sess, $PHP_SELF;
2608 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2611 if (isset($sess) == FALSE)
2616 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2619 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2620 $btrace = btrace_line(debug_backtrace());
2623 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2624 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2629 function log_lock($log)
2631 GLOBAL $sess, $PHP_SELF;
2633 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2636 if (isset($sess) == FALSE)
2641 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2644 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2645 $btrace = btrace_line(debug_backtrace());
2648 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2649 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2654 function log_wr($log)
2656 GLOBAL $sess, $PHP_SELF;
2658 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2661 if (isset($sess) == FALSE)
2666 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2669 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2670 $btrace = btrace_line(debug_backtrace());
2673 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2674 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2679 function log_load($log)
2681 GLOBAL $sess, $PHP_SELF;
2683 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2686 if (isset($sess) == FALSE)
2691 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2694 if ((BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2695 $btrace = btrace_line(debug_backtrace());
2698 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2699 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2704 function log_auth($sess, $log)
2708 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2711 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2714 if ((BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_TRAC)
2715 $btrace = btrace_line(debug_backtrace());
2718 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2719 fwrite($fp, sprintf("LOAD: [%s] [%d] [%s] [%s]\n", $sess, time(), $log, $btrace));
2724 function log_shme($log)
2726 GLOBAL $sess, $PHP_SELF;
2728 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SHME) == 0)
2731 if (isset($sess) == FALSE)
2736 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SHME) == 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("SHME: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2751 // function log_legal($curtime, $sess, $name, $where, $mesg)
2752 function log_legal($curtime, $addr, $user, $where, $mesg)
2755 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2756 /* Unix time | session | nickname | IP | where was | mesg */
2757 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2758 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2759 $user->name, $addr, $where , $mesg));
2764 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2769 if ($sitted < PLAYERS_N) {
2777 if ($table == $cur_table)
2784 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2789 function show_notify($text, $tout, $butt, $w, $h)
2791 log_main("SHOW_NOTIFY: ".$text);
2792 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2795 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
2797 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2798 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);
2802 function root_welcome($user)
2804 GLOBAL $root_wellarr, $G_lang;
2808 $dt = date("H:i ", $curtime);
2810 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2811 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2818 function validate_sess($sess)
2820 if (strlen($sess) == SESS_LEN)
2826 function validate_name($name)
2828 $name_new = str_replace(' ', '_', mb_substr(trim($name),0,12, "UTF-8"));
2830 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2832 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2839 function playsound($filename)
2841 return (sprintf('playsound("flasou", "%s");', $filename));
2844 function secstoword($secs)
2850 $mins = floor($secs / 60);
2852 if ($G_lang == 'en') {
2854 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
2857 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
2861 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2864 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2869 function sharedmem_sz($tok)
2871 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2872 log_main("shmop_open failed");
2875 $shm_sz = shmop_size($shm_id);
2876 shmop_close($shm_id);
2878 // log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2885 static function lock_data($is_exclusive)
2887 if (($res = file_lock(FTOK_PATH."/warrant", $is_exclusive)) != FALSE) {
2888 self::$delta_t = microtime(TRUE);
2889 log_lock("LOCK warrant [".self::$delta_t."]");
2897 static function unlock_data($res)
2901 log_lock("UNLOCK warrant [".(microtime(TRUE) - (self::$delta_t))."]");
2910 static function lock_data($is_exclusive)
2912 if (($res = file_lock(FTOK_PATH."/poll", $is_exclusive)) != FALSE) {
2913 self::$delta_t = microtime(TRUE);
2914 log_lock("LOCK poll [".self::$delta_t."]");
2922 static function unlock_data($res)
2926 log_lock("UNLOCK poll [".(microtime(TRUE) - (self::$delta_t))."]");