5 * Copyright (C) 2006-2011 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
26 define(BRISK_CONF, "brisk.conf.pho");
27 define(FTOK_PATH, "/var/lib/brisk");
28 define(LEGAL_PATH, "/tmp/legal_brisk");
29 define(PROXY_PATH, "/var/lib/brisk_proxy");
31 define(TABLES_AUTH_N, 4);
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);
50 define(STREAM_TIMEOUT, 20);
51 define(EXPIRE_TIME_RD, 180);
52 define(EXPIRE_TIME_SMAMMA, 360);
53 define(EXPIRE_TIME_WAG, 10);
54 define(WAKEUP_TIME, 12);
55 // BAN_TIME da allineare anche in commons.js
56 define(BAN_TIME, 3600);
57 define(GARBAGE_TIMEOUT, 10);
58 define(NICKSERV, "<i>BriskServ</i>");
60 define(LOCK_SHARE_MAX, 10000);
62 define(DBG_ONL2, 0x0001);
63 define(DBG_ONLY, 0x0002);
64 define(DBG_MAIN, 0x0004);
65 define(DBG_READ, 0x0008);
66 define(DBG_REA2, 0x0010);
67 define(DBG_SEND, 0x0020);
68 define(DBG_LOCK, 0x0040);
69 define(DBG_WRIT, 0x0080);
70 define(DBG_LOAD, 0x0100);
71 define(DBG_AUTH, 0x0200);
72 define(DBG_CRIT, 0x0400);
73 define(DBG_LMOP, 0x0800);
74 define(DBG_TRAC, 0x1000);
75 define(DBG_SHME, 0x2000);
76 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
77 define(BRISK_DEBUG, 0xffffffbf);
79 define(BRISK_SINGLE_DEBUG,0);
80 define(BRISK_SINGLE_SESS, "");
81 // define(DEBUGGING, "local");
83 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
85 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
86 'en' => 'back standing' ),
87 'btn_close' => array( 'it' => 'chiudi',
90 'tit_all' => array( 'it' => 'tutti',
93 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
94 'en' => '<br>You are being idle for ' ),
95 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
96 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
97 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
98 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
99 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
100 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
101 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
102 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
103 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
104 'en' => '<br>The entered password is not correct.<br><br>'),
105 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
106 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
107 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
108 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
109 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
110 'en' => '<b>To send a message you have to be authenticated.</b>'),
111 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
112 'en' => 'The nickname have to contain at least one letter or one number.'),
113 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
114 'en' => 'The nickname <b>%s</b> is already in use.'),
115 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
116 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
117 'nickjust' => array( 'it' => 'Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>',
118 'en' => 'The nickname <b>\'%s\'</b> is already registered, <b>if its proprietary will authenticate you will named again officially ghost<i>N</i>.</b>'), // FIXME: him ???
119 'statunkn' => array( 'it' => 'Questo stato non esiste.',
120 'en' => 'This state don\'t exists.'),
121 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
122 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
123 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
124 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
126 'tit_onauth'=>array( 'it' => '(solo aut.)',
127 'en' => '(only aut.)'),
128 'tit_onisol'=>array( 'it' => '(isolam.to)',
129 'en' => '(isolation)'),
130 'db_failed' =>array('it' => '<br>Il collegamento al database è fallito.<br>Temporaneamente tutte le autenticazioni verranno sospese, accederai a Brisk come un utente normale.<br><br>Ci scusiamo per il disagio.',
131 'en' => 'Connection to the database failed<br>All authentications are suspended temporarly, you login as normal user.<br>We are about the limitation')
136 $G_lng = langtolng($G_lang);
138 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
139 $G_brisk_version = "3.5.5";
141 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
142 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: quinta versione di test per la nuova gestione dei dati volatili, rivista gestione del ticker.',
143 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
144 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: third test version for the new volatile data management, ticker management refactored.',
145 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
147 $G_room_help = array( 'it' => '
148 <div style=\\"text-align: left; padding: 8px;\\">
149 <b>Descrizione</b><br>
150 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
151 <a target=\\"_blank\\" href=\\"http://it.wikipedia.org/wiki/Briscola#Gioco_a_5\\">Wikipedia</a>; in breve è la variante con l\'asta prima sulla carta e poi sui punti.<br><br>
152 <b>Configurazione del browser.</b><br>
153 Occorre abilitare i cookies.<br>
155 <b>Uso del sito</b><br>
156 Potete sedervi a un tavolo o rimanere in piedi.<br>
157 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
160 All\'inizio vengono distribuite le carte e parte l\'asta; per partecipare all\'asta, quando sarà il vostro turno, potrete scegliere se andare avanti o passare cliccando sulle icone corrispondenti. Se si arriva ai punti, scrivete nella textbox il vostro rilancio e cliccate PUNTI.<br><br>
161 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
162 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
163 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
164 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
165 Dopo che è iniziata una partita per uscirne dovete chiedere agli altri giocatori di sbloccarla cliccando sul lucchetto. Se non si segue questa prassi, una volta usciti, non vi potrete sedere a nessun tavolo per '.floor(BAN_TIME/60).' minuti.
167 <dt><b>Comandi della chat</b>
168 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
169 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
170 <dd><b>/st <i><stato></i></b> - cambia l\'icona associata al tuo user; <i>stato</i> può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
171 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
172 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
173 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
179 <div style=\\"text-align: left; padding: 8px;\\">
180 <b>EN Descrizione</b><br>
181 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
182 <a target=\\"_blank\\" href=\\"http://it.wikipedia.org/wiki/Briscola#Gioco_a_5\\">Wikipedia</a>; in breve è la variante con l\'asta prima sulla carta e poi sui punti.<br><br>
183 <b>EN Configurazione del browser.</b><br>
184 Occorre abilitare i cookies.<br>
186 <b>Uso del sito</b><br>
187 Potete sedervi a un tavolo o rimanere in piedi.<br>
188 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
191 All\'inizio vengono distribuite le carte e parte l\'asta; per partecipare all\'asta, quando sarà il vostro turno, potrete scegliere se andare avanti o passare cliccando sulle icone corrispondenti. Se si arriva ai punti, scrivete nella textbox il vostro rilancio e cliccate PUNTI.<br><br>
192 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
193 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
194 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
195 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
196 Dopo che è iniziata una partita per uscirne dovete chiedere agli altri giocatori di sbloccarla cliccando sul lucchetto. Se non si segue questa prassi, una volta usciti, non vi potrete sedere a nessun tavolo per '.floor(BAN_TIME/60).' minuti.
198 <dt><b>Comandi della chat</b>
199 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
200 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
201 <dd><b>/st <i><stato></i></b> - cambia l\'icona associata al tuo user; <i>stato</i> può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
202 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
203 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
204 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
210 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
211 <div style=\\"text-align: left; padding: 8px;\\">
212 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
214 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
215 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
217 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
218 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
219 <li>Smart card di InfoCamere
222 <b>Per auto-garantisi occorre possedere:</b><br><br>
224 <li>il codice PIN della propria carta
225 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
228 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
230 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
233 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
234 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
239 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
240 <div style=\\"text-align: left; padding: 8px;\\">
241 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
243 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
244 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
246 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
247 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
250 <b>Per auto-garantisi occorre possedere:</b><br><br>
252 <li>il codice PIN della propria carta
253 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
256 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
258 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
261 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
262 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
268 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
272 $G_room_about = array( 'it' => '<br>
273 <div id=\\"header\\" class=\\"header\\">
274 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
275 briscola chiamata in salsa ajax
277 <br><b>version '.$G_brisk_version.'</b><br><br>
278 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
280 <div id=\\"header\\" class=\\"header\\">
281 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
282 declaration briscola in ajax sauce <b>(Beta)</b>
284 <br><b>version '.$G_brisk_version.'</b><br><br>
285 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
287 function file_lock($fname, $is_exclusive)
289 if (($res = fopen($fname, "r+")) == FALSE) {
293 if (flock($res, ($is_exclusive ? LOCK_EX : LOCK_SH)) == FALSE) {
301 function file_unlock($res)
304 flock($res, LOCK_UN);
309 function webservers_exceeded()
311 return(file_exists(PROXY_PATH."/webservers_exceded.flag"));
314 function webservers_check()
316 GLOBAL $G_webserver_max;
320 $dh = opendir('/proc');
321 while (($file = readdir($dh)) !== false) {
322 if (preg_match('/[0-9]+/', $file)) {
323 $cmdline = explode("\0", file_get_contents('/proc/'.$file.'/cmdline'));
324 // echo "xxx".$cmdline[0].$n;
325 if (strstr('/usr/sbin/apache2', $cmdline[0]) != FALSE) {
326 // echo "yyy".$cmdline[0].$n;
333 if ($ct >= $G_webserver_max) {
334 touch(PROXY_PATH."/webservers_exceded.flag");
337 unlink(PROXY_PATH."/webservers_exceded.flag");
342 $escinp_from = array( "\"" );
343 $escinp_to = array( """ );
345 function escinput($s)
347 GLOBAL $escinp_from, $escinp_to;
349 return str_replace($escinp_from, $escinp_to, $s);
354 return htmlentities($s);
357 function esclfhtml($s)
359 return str_replace("\n", "<br>\n", htmlentities($s));
363 function langtolng($lang)
367 return ($G_lang == 'en' ? '-en' : '');
370 function csplitter($in, $sep)
376 for ($i = 0 ; $i < strlen($in) ; $i++) {
377 $ini = substr($in, $i, 1);
381 else if ($ini == $sep) {
400 $from = array ( '\\', '@', '|' );
401 $to = array ( '\\\\', '@', '¦' );
403 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
408 $from = array ( '\\', '|', "\t", "\n");
409 $to = array ( '\\\\', '\\|', "\\t", "\\n");
411 return (str_replace($from, $to, $s));
414 function xcapemesg($s)
416 $from = array ( "\n");
417 $to = array ( "\\n");
419 return (str_replace($from, $to, $s));
429 function getbyid($idx)
431 return ($this->el[$idx]);
434 function setbyid($idx, $v)
436 $this->el[$idx] = $v;
445 var $auth_only; // se tavolo riservato o libero
452 var $table_start; // information field
460 function create($idx)
462 if (($thiz = new Table()) == FALSE)
466 $thiz->player = array();
468 $thiz->auth_only = FALSE;
474 $thiz->table_token = "";
475 $thiz->table_start = 0;
477 $thiz->wakeup_time = 0;
484 $this->idx = $from->idx;
485 $this->player = array();
486 for ($i = 0 ; $i < $from->player_n ; $i++)
487 $this->player[$i] = $from->player[$i];
488 $this->player_n = $from->player_n;
490 log_main("PLAYER_N - parent::copy.".$this->player_n);
492 $this->auth_only = $from->auth_only;
494 $this->wag_own = $from->wag_own;
495 $this->wag_com = $from->wag_com;
496 $this->wag_tout = $from->wag_tout;
498 $this->table_token = $from->table_token;
499 $this->table_start = $from->table_start;
501 $this->wakeup_time = $from->wakeup_time;
504 function myclone($from)
506 if (($thiz = new Table()) == FALSE)
514 function spawn($from)
516 if (($thiz = new Table()) == FALSE)
519 $thiz->idx = $from->idx;
520 $thiz->player = array();
521 for ($i = 0 ; $i < $from->player_n ; $i++)
522 $thiz->player[$i] = $i;
523 $thiz->player_n = $from->player_n;
525 $thiz->auth_only = $from->auth_only;
527 $thiz->wag_own = $from->wag_own;
528 $thiz->wag_com = $from->wag_com;
529 $thiz->wag_tout = $from->wag_tout;
531 $thiz->table_token = $from->table_token;
532 $thiz->table_start = $from->table_start;
534 $thiz->wakeup_time = $from->wakeup_time;
539 function wag_set($user_idx, $mesg)
543 $this->wag_own = $user_idx;
544 $this->wag_com = $mesg;
548 function wag_reset($timeout)
550 log_main("WAG_RESET");
552 unset($this->wag_own);
555 $this->wag_tout = $timeout;
558 function player_get($idx)
560 return ($this->player[$idx]);
563 function player_set($idx, $player)
565 $this->player[$idx] = $player;
568 function user_add($idx)
570 $this->player[$this->player_n] = $idx;
573 return ($this->player_n - 1);
576 function user_rem($room, $user)
578 $tabpos = $user->table_pos;
580 /* verifico la consistenza dei dati */
581 if ($room->user[$this->player[$tabpos]] == $user) {
583 /* aggiorna l'array dei giocatori al tavolo. */
584 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
585 $this->player[$i] = $this->player[$i+1];
586 $user_cur = $room->user[$this->player[$i]];
587 $user_cur->table_pos = $i;
592 log_main("INCONSISTENCY ON TABLE.");
598 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
599 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
601 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
602 function act_content($user)
605 $isstanding = ($user->subst == 'standup');
606 $sitted = $this->player_n;
608 $cur_table = $user->table;
612 if ($sitted < PLAYERS_N) {
613 if ($this->auth_only) {
614 if ($user->flags & USER_FLAG_AUTH)
628 if ($table == $cur_table)
635 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
643 define(USER_FLAG_AUTH, 0x02);
645 define(USER_FLAG_MAP_AUTH, 0x0c);
646 define(USER_FLAG_LISTAUTH, 0x04);
647 define(USER_FLAG_ISOLAUTH, 0x08);
649 define(USER_FLAG_DBFAILED, 0x10);
652 define(USER_FLAG_S_NORM, 0x000); // done
653 define(USER_FLAG_S_PAU, 0x100); // done
654 define(USER_FLAG_S_OUT, 0x200); // done
655 define(USER_FLAG_S_DOG, 0x300); // done
656 define(USER_FLAG_S_EAT, 0x400); // done
657 define(USER_FLAG_S_WRK, 0x500); // done
658 define(USER_FLAG_S_SMK, 0x600); // done
659 define(USER_FLAG_S_EYE, 0x700); // done
660 define(USER_FLAG_S_RABB, 0x800); // done
661 define(USER_FLAG_S_SOCC, 0x900); // done
662 define(USER_FLAG_S_BABY, 0xa00); // done
663 define(USER_FLAG_S_MOP, 0xb00); // done
665 define(USER_FLAG_S_ALL, 0xf00); // done
667 /* type of user normal, supporter etc ... */
668 define(USER_FLAG_TY_ALL, 0xff0000); // done
669 define(USER_FLAG_TY_NORM, 0x010000); // done
670 define(USER_FLAG_TY_SUPER, 0x020000); // done
671 // ... other usefull status ...
672 define(USER_FLAG_TY_SUSPEND, 0x400000); // done
673 define(USER_FLAG_TY_DISABLE, 0x800000); // done
676 var $idx; // index in the users array when you are in game
677 var $idx_orig; // index in the users array when you aren't in game
678 var $code; // authentication code
679 var $name; // name of the user
680 var $sess; // session of the user
681 var $ip; // ip of the user
682 var $lacc; // last access (for the cleanup)
683 var $laccwr; // last access (for the cleanup)
684 var $bantime; // timeout to temporary ban
685 var $stat; // status (outdoor, room, table, game, ...)
686 var $subst; // substatus for each status
687 var $step; // step of the current status
688 var $trans_step; // step to enable transition between pages (disable == -1)
689 var $comm; // commands array
690 // var $asta_card; //
692 // var $handpt; // Total card points at the beginning of the current hand.
693 // var $exitislock; // Player can exit from the table ?
695 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
696 // it is allways ZERO
697 var $table; // id of the current table when you are in game
698 var $table_orig; // id of the current table when you aren't in game
699 var $table_pos; // idx on the table
700 var $table_token;// token that identify a game on a table
701 var $flags; // Bitfield with: AUTHENTICATE: 0x02
702 var $the_end; // Flag to change the end of the session
704 var $chat_lst; // Last chat line
705 var $chattime; // Array of chat times
706 var $chat_cur; // Current chat line number
707 var $chat_ban; // Time for ban chat
708 var $chat_dlt; // Delta t for ban
714 function create($idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
715 if (($thiz = new User()) == FALSE)
719 $thiz->idx_orig = $idx;
724 $thiz->lacc = time();
725 $thiz->laccwr = time();
728 $thiz->subst = $subst;
730 $thiz->trans_step = -1;
731 $thiz->comm = array();
732 $thiz->asta_card = -2;
733 $thiz->asta_pnt = -1;
735 $thiz->exitislock = TRUE;
739 $thiz->chattime = array_fill(0, CHAT_N, 0);
741 $thiz->chat_lst = "";
745 $thiz->table_orig = $table;
746 $thiz->table = $table;
747 $thiz->table_pos = -1;
748 $thiz->table_token= "";
749 $thiz->shm_sz = SHM_DIMS_U_MIN;
755 $this->idx = $from->idx;
756 $this->idx_orig = $from->idx;
757 $this->code = $from->code;
758 $this->name = $from->name;
759 $this->sess = $from->sess;
760 $this->ip = $from->ip;
761 $this->lacc = $from->lacc;
762 $this->laccwr = $from->laccwr;
763 $this->bantime = $from->bantime;
764 $this->stat = $from->stat;
765 $this->subst = $from->subst;
766 $this->step = $from->step;
767 $this->trans_step = $from->trans_step;
768 $this->comm = array();
770 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
771 for ($i = $i_start ; $i < $from->step ; $i++) {
773 if (isset($from->comm[$ii])) {
774 $this->comm[$ii] = $from->comm[$ii];
777 $this->asta_card = $from->asta_card;
778 $this->asta_pnt = $from->asta_pnt;
779 $this->handpt = $from->handpt;
780 $this->exitislock = $from->exitislock;
782 $this->flags = $from->flags;
784 $this->chattime = array();
785 for ($i = 0 ; $i < CHAT_N ; $i++)
786 $this->chattime[$i] = $from->chattime[$i];
787 $this->chat_cur = $from->chat_cur;
788 $this->chat_lst = $from->chat_lst;
789 $this->chat_ban = $from->chat_ban;
790 $this->chat_dlt = $from->chat_dlt;
792 $this->table_orig = $from->table_orig;
793 $this->table = $from->table;
794 $this->table_pos = $from->table_pos;
795 $this->table_token = $from->table_token;
796 $this->the_end = $from->the_end;
797 $this->shm_sz = $from->shm_sz;
802 function myclone($from)
804 if (($thiz = new User()) == FALSE)
812 function spawn($from, $table, $table_pos)
814 if (($thiz = new User()) == FALSE)
817 $thiz->idx = $from->idx;
818 $thiz->idx_orig = $from->idx;
819 $thiz->code = $from->code;
820 $thiz->name = $from->name;
821 $thiz->sess = $from->sess;
822 $thiz->ip = $from->ip;
823 $thiz->lacc = $from->lacc;
824 $thiz->laccwr = $from->laccwr;
825 $thiz->bantime = $from->bantime;
826 $thiz->stat = $from->stat;
827 $thiz->subst = $from->subst;
828 $thiz->step = $from->step;
829 $thiz->trans_step = $from->trans_step;
830 $thiz->comm = array();
833 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
834 for ($i = $i_start ; $i < $from->step ; $i++) {
835 log_wr("TRY PUSH:".$i);
837 $thiz->comm[$ii] = $from->comm[$ii];
840 $thiz->asta_card = $from->asta_card;
841 $thiz->asta_pnt = $from->asta_pnt;
842 $thiz->handpt = $from->handpt;
843 $thiz->exitislock = $from->exitislock;
844 $thiz->the_end = $from->the_end;
846 $thiz->flags = $from->flags;
848 $thiz->chattime = array_fill(0, CHAT_N, 0);
850 $thiz->chat_lst = "";
855 $thiz->table_orig = $table;
857 $thiz->table_pos = $table_pos;
858 $thiz->table_token = $from->table_token;
859 $thiz->shm_sz = $from->shm_sz;
868 function code_get() {
869 return ($this->code);
872 function stat_set($stat) {
873 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
874 $this->stat = "$stat";
877 if (validate_sess($this->sess)) {
878 if (file_exists(PROXY_PATH) == FALSE)
879 mkdir(PROXY_PATH, 0775, TRUE);
880 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
881 fwrite($fp, sprintf("%s\n",$this->stat));
887 function step_set($step)
889 $this->step = $step & 0x7fffffff;
894 function step_inc($delta = 1) {
895 $this->step += $delta;
896 /* modularization because unpack() not manage unsigned 32bit int correctly */
897 $this->step &= 0x7fffffff;
905 if (validate_sess($this->sess) == FALSE)
907 if (file_exists(PROXY_PATH) == FALSE)
908 mkdir(PROXY_PATH, 0775, TRUE);
909 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
911 fwrite($fp, pack("LL",$this->step, $this->idx));
914 log_main("step_set [".$this->sess. "] [".$this->step."]");
922 static function load_step($sess)
926 if (validate_sess($sess) == FALSE)
929 if (file_exists(PROXY_PATH) == FALSE)
930 mkdir(PROXY_PATH, 0775, TRUE);
931 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
933 if (($s = fread($fp, 8)) == FALSE)
935 if (mb_strlen($s, "ASCII") != 8)
937 $arr = unpack('Ls/Li', $s);
940 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
947 log_rd2("STEP_GET [".$sess."]: return false ");
952 static function unproxy_step($sess) {
953 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
954 if (file_exists(PROXY_PATH) == FALSE)
956 @unlink(PROXY_PATH."/".$sess.".step");
961 log_legal($curtime, $this, "STAT:LOGOUT", '');
963 $tmp_sess = $this->sess;
965 self::unproxy_step($tmp_sess);
966 $this->name = ""; // OK here
967 while (array_pop($this->comm) != NULL);
969 $this->chattime = array_fill(0, CHAT_N, 0);
971 $this->chat_lst = "";
974 $this->the_end = FALSE;
977 static function load_data($id, $sess)
979 log_main("load_data: id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
982 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
983 log_main("ftok failed");
987 if (($shm_sz = sharedmem_sz($tok)) == -1) {
988 log_main("shmop_open failed");
992 $shm_sz = SHM_DIMS_U_MIN;
994 if ($shm = shm_attach($tok, $shm_sz)) {
995 if (($user = @shm_get_var($shm, $tok)) == FALSE) {
998 if ($sess != FALSE && $user->sess != $sess) {
1001 log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
1003 if ($user == FALSE) {
1004 log_only("INIT MAIN DATA");
1006 // SHSPLIT FIXME: init_data for User class ??
1007 $user = User::create($id, "", "");
1008 if (@shm_put_var($shm, $tok, $user) == FALSE) {
1009 log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
1010 log_only(serialize($user));
1012 log_shme("User::save_data2");
1015 if ($sess != FALSE) {
1017 * NOTE: this part is for check only, theoretically
1018 * user->step anch proxy_step are set allways at the same value
1020 $old_step = $user->step;
1021 $arr = User::load_step($sess);
1022 $user->step = $arr['s'];
1023 if ($old_step != $user->step) {
1024 log_crit("steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
1028 $user->shm_sz = $shm_sz;
1034 // SHSPLIT: load users from the shared memory
1043 static function save_data($user, $id)
1049 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
1052 while ($user->shm_sz < SHM_DIMS_U_MAX) {
1053 if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
1056 // log_only("PUT_VAR DI ".strlen(serialize($user)));
1057 if (@shm_put_var($shm, $tok, $user) != FALSE) {
1059 if ($user->sess != "")
1062 log_shme("User::save_data");
1064 log_main("User[".$id."] saved.");
1067 if (shm_remove($shm) === FALSE) {
1068 log_only("REMOVE FALLITA");
1072 $user->shm_sz += SHM_DIMS_U_DLT;
1091 var $comm; // commands for many people
1092 var $step; // current step of the comm array
1093 // externalized var $garbage_timeout;
1097 $this->user = array();
1098 $this->table = array();
1100 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1101 $this->user[$i] = User::create($i, "", "");
1104 for ($i = 0 ; $i < TABLES_N ; $i++) {
1105 $this->table[$i] = Table::create($i);
1108 $row = ( (((int)($i / 4)) % 2) == 0 );
1109 $col = ($i % 2 == 0);
1110 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
1113 $this->table[$i]->auth_only = FALSE;
1116 if ($i < TABLES_AUTH_N)
1117 $this->table[$i]->auth_only = TRUE;
1119 $this->table[$i]->auth_only = FALSE;
1121 // externalized $this->garbage_timeout = 0;
1122 Room::garbage_time_expire_set(0);
1123 $this->shm_sz = SHM_DIMS_MIN;
1126 function garbage_manager($force)
1128 GLOBAL $G_lang, $mlang_brisk, $G_base;
1132 log_rd2("garbage_manager START");
1134 /* Garbage collector degli utenti in timeout */
1137 // externalized if ($force || $this->garbage_timeout < $curtime) {
1138 if (!$force && !Room::garbage_time_is_expired($curtime)) {
1143 // FIXME BRISK4: include for each kind of table
1144 require_once("${G_base}briskin5/Obj/briskin5.phh");
1146 // Before all align times with table timeout
1147 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1148 $table_cur = $this->table[$table_idx];
1149 // if the table is complete and exists its shared mem we get the info about users lacc
1151 if ($table_cur->player_n == PLAYERS_N) {
1152 log_main("PLAYERS == N TABLE ".$table_idx);
1154 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1155 log_main("bin5 lock data success");
1157 $no_recovery = FALSE;
1158 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1159 if ($table_cur->table_token != $bri->table_token) {
1160 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1161 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
1162 $no_recovery = TRUE;
1167 if ($bri != FALSE) {
1171 log_main("garbage_manager: bri loaded successfully.");
1172 $bri->garbage_manager(TRUE);
1174 $bri_table = $bri->table[0];
1176 // is the end of the table
1177 if ($bri->the_end == TRUE) {
1179 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
1181 log_main("garbage_manager: INSIDE THE END.");
1183 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
1184 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1185 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1188 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1189 // stat must be "table" by definition
1190 $user_cur = $this->user[$table_cur->player[$i]];
1191 $bri_user = $bri->user[$i];
1193 $user_cur->subst = $bri_user->subst;
1194 $user_cur->step = $bri_user->step;
1195 $user_cur->lacc = $bri_user->lacc;
1196 $user_cur->laccwr = $bri_user->lacc;
1197 $user_cur->bantime = $bri_user->bantime;
1200 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
1202 $this->room_join_wakeup($user_cur, FALSE, 0);
1203 $table_cur->table_token = "";
1204 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
1206 $bri->destroy_data($table_idx);
1209 log_main("gm:: save_data");
1211 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1212 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
1215 Bin5::save_data($bri);
1217 } // else if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1218 else if ($no_recovery == FALSE) {
1219 log_crit("ERROR: table ".$table_idx." unrecoverable join");
1221 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1222 $user_cur = $this->user[$table_cur->player[$i]];
1223 $user_cur->subst = "shutdowner";
1224 $user_cur->step_inc();
1226 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
1227 $ret .= "gst.st = ".($user_cur->step+1)."; ";
1228 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
1229 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
1230 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
1231 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1232 $user_cur->step_inc();
1235 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
1236 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1237 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1239 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
1241 $this->room_join_wakeup($user_cur, TRUE, -2);
1242 $table_cur->table_token = "";
1245 Bin5::unlock_data($sem);
1247 } // if ($table_cur->player_n == PLAYERS_N) {
1248 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1250 log_rd2("out new loop.");
1252 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1253 $user_cur = $this->user[$i];
1255 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1257 if ($user_cur->sess == "")
1260 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1261 // Auto logout dell'utente
1262 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1264 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1265 log_auth($user_cur->sess, "Autologout session.");
1269 log_rd2("AUTO LOGOUT.");
1270 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1271 $this->room_wakeup($user_cur);
1272 else if ($user_cur->subst == 'standup')
1273 $this->room_outstandup($user_cur);
1275 log_rd2("LOGOUT FROM WHAT ???");
1279 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1280 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1281 $this->room_wakeup($user_cur);
1282 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1283 /* 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" */
1284 $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);
1285 $user_cur->step_inc();
1289 log_rd2("GARBAGE UPDATED!");
1291 // externalized $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1292 Room::garbage_time_expire_set($curtime + GARBAGE_TIMEOUT);
1298 function show_room($user_step, $user)
1300 GLOBAL $G_lang, $mlang_brisk;
1301 log_main("show_room: username: ".$user->name);
1303 $ret = sprintf('gst.st = %d; ', $user_step);
1305 if ($user->flags & USER_FLAG_ISOLAUTH) {
1306 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
1308 else if ($user->flags & USER_FLAG_LISTAUTH) {
1309 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1312 $ret .= 'list_set(\'all\', false, \'\' ); ';
1315 if ($user->subst == 'standup')
1316 $ret .= "tra.show(); ";
1318 $ret .= "tra.hide(); ";
1320 $ret .= sprintf('stat = "%s";', $user->stat);
1322 $ret .= root_wellcome($user);
1323 if ($user->flags & USER_FLAG_DBFAILED) {
1324 $ret .= "gst.st = ".($user->step+1)."; ";
1325 $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
1328 $ret .= sprintf('subst = "%s";', $user->subst);
1329 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1330 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1331 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1332 for ($i = 0 ; $i < TABLES_N ; $i++) {
1334 $ret .= $this->table_content($user, $i);
1335 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1336 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1337 $ret .= $this->table[$i]->act_content($user);
1338 if ($this->table[$i]->wag_own != -1)
1339 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
1341 $ret .= sprintf('tra.rem(%d); ', $i);
1343 $ret .= $this->standup_content($user);
1349 function room_wakeup($user)
1351 $table_idx = $user->table;
1352 $table = $this->table[$table_idx];
1354 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1358 $from_table = ($user->stat == "table");
1360 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1362 for ($i = 0 ; $i < $table->player_n ; $i++) {
1363 $user_cur = $this->user[$table->player[$i]];
1364 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1366 if ($user->idx_get() != $table->player[$i]) {
1367 $user_cur->stat_set("room");
1368 $user_cur->subst = "sitdown";
1369 $user_cur->laccwr = $curtime;
1371 else if ($user->sess != "") {
1372 $user_cur->stat_set("room");
1373 $user_cur->subst = "standup";
1374 $user_cur->laccwr = $curtime;
1375 $user_cur->table = -1;
1380 $user->stat_set("room");
1381 $user->subst = "standup";
1382 $user->laccwr = $curtime;
1385 $remove_wagon = FALSE;
1386 if($table->wag_own == $user->idx_get()) {
1387 $table->wag_reset($curtime);
1388 $remove_wagon = TRUE;
1392 /* aggiorna l'array dei giocatori al tavolo. */
1393 $table->user_rem($this, $user);
1395 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1396 $user_cur = $this->user[$i];
1397 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1400 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1402 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1403 if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
1404 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1405 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1406 log_main("DOCUMENT.index.php: from table");
1408 else if ($user_cur->stat == "room") {
1409 log_main("DOCUMENT.index.php: from table");
1411 $ret .= $this->table_content($user_cur, $table_idx);
1412 $ret .= $this->standup_content($user_cur);
1414 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1415 $ret .= $table->act_content($user);
1417 if ($user->idx_get() == $i) {
1418 // set the new status
1419 $ret .= 'subst = "standup"; tra.show(); ';
1420 // clean the action buttons in other tables
1421 for ($e = 0 ; $e < TABLES_N ; $e++) {
1422 if ($this->table[$e]->player_n < PLAYERS_N) {
1423 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1424 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1425 $ret .= $this->table[$e]->act_content($user);
1430 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1431 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1432 $ret .= $table->act_content($user_cur);
1435 log_wr("ROOM_WAKEUP: ".$ret);
1436 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1437 $user_cur->step_inc();
1441 function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
1443 $table_idx = $user->table;
1444 $table = $this->table[$table_idx];
1446 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1449 $user_wup = array();
1451 $user_tab = array();
1453 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1455 for ($i = 0 ; $i < $table->player_n ; $i++) {
1456 $user_cur = $this->user[$table->player[$i]];
1457 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1458 if ($user_cur->sess != "") {
1459 if ($update_lacc == TRUE) {
1460 $user_cur->laccwr = $curtime;
1462 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1463 if ($user_cur->subst == "shutdowned") {
1464 $user_cur->stat_set("room");
1465 $user_cur->subst = "sitdown";
1467 else if ($user_cur->subst == "shutdowner") {
1468 $user_cur->stat_set("room");
1469 $user_cur->subst = "standup";
1470 $user_cur->table = -1;
1471 $user_wup[$user_wup_n++] = $user_cur;
1473 $remove_wagon = FALSE;
1474 if($table->wag_own == $table->player[$i]) {
1475 $remove_wagon = TRUE;
1476 $table->wag_reset($curtime);
1479 $user_tab[$user_tab_n++] = $table->player[$i];
1483 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1484 $table->user_rem($this, $user_wup[$wup_idx]);
1486 /* aggiorna l'array dei giocatori al tavolo. */
1488 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1489 log_main("START LOOP");
1490 $user_cur = $this->user[$i];
1491 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1492 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1497 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1499 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1500 if ($user_cur->stat == "room") {
1501 log_main("DOCUMENT.index.php from table");
1503 $ret .= $this->table_content($user_cur, $table_idx);
1504 $ret .= $this->standup_content($user_cur);
1506 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1507 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1508 $ret .= $table->act_content($user_cur);
1511 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1512 if ($user_tab[$tab_idx] == $i)
1515 // for users that wakeup the room will be reconstructed by index_rd.php
1516 if ($tab_idx < $user_tab_n) {
1517 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1519 // ARRAY_POP DISABLED
1520 // if ($trans_delta == 0)
1521 // while (array_pop($user_cur->comm) != NULL);
1523 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1524 $user_cur->comm[$user_cur->step % COMM_N] = "";
1525 $user_cur->step_inc();
1526 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
1527 $user_cur->step_inc();
1528 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1532 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1534 log_main("JOIN_WAKEUP more");
1535 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1536 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1537 $ret .= $table->act_content($user_cur);
1539 log_main("JOIN_WAKEUP end more");
1541 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1542 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1543 $user_cur->step_inc();
1547 function room_outstandup($user)
1549 $this->room_sitdown($user, -1);
1552 function table_update($user)
1554 log_main("table_update: pre - USER: ".$user->name);
1556 $table_idx = $user->table;
1558 if ($table_idx > -1)
1559 $table = $this->table[$table_idx];
1561 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1563 $user_cur = $this->user[$i];
1564 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1567 $ret = "gst.st = ".($user_cur->step+1)."; ";
1568 if ($table_idx > -1)
1569 $ret .= $this->table_content($user_cur, $table_idx);
1571 if ($user->idx_get() == $i) {
1572 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1573 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1574 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1576 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1577 $user_cur->step_inc();
1580 log_main("table_update: post");
1583 function room_sitdown($user, $table_idx)
1585 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1589 if ($table_idx > -1 && $table_idx < TABLES_N) {
1590 $table = $this->table[$table_idx];
1593 if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
1594 for ($i = 0 ; $i < TABLES_N ; $i++) {
1595 if ($table->wag_own == $table->player[$i]) {
1596 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1597 $table->wag_reset(time());
1604 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1606 $user_cur = $this->user[$i];
1607 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1610 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1611 if ($table_idx > -1)
1612 $ret .= $this->table_content($user_cur, $table_idx);
1613 $ret .= $this->standup_content($user_cur);
1615 if ($user->idx_get() == $i) {
1616 $ret .= 'subst = "sitdown"; tra.hide(); ';
1617 // clean the action buttons in other tables
1618 for ($e = 0 ; $e < TABLES_N ; $e++) {
1619 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1620 $ret .= $this->table[$e]->act_content($user_cur);
1623 else if ($table_idx > -1) {
1624 if ($table->player_n == PLAYERS_N) {
1625 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1626 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1627 $ret .= $table->act_content($user_cur);
1630 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1631 $user_cur->step_inc();
1635 function chatt_send($user, $mesg)
1637 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1641 $msg = substr($mesg, 6, 128);
1643 $dt = date("H:i ", $curtime);
1654 $is_normchat = FALSE;
1655 /* for old isolation management $is_ticker = FALSE; */
1656 $update_room = FALSE;
1658 if (strcmp($msg, "/tav") == 0 ||
1659 strncmp($msg, "/tav ", 5) == 0) {
1661 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1662 /* 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>" */
1663 $msg = $mlang_brisk['tickmust'][$G_lang];
1664 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1669 $table = $this->table[$user->table];
1671 if ($table->wag_own != -1) {
1672 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1673 $msg = $mlang_brisk['tickjust'][$G_lang];
1674 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1679 $dtime = $curtime - $table->wag_tout;
1680 if ($dtime < EXPIRE_TIME_WAG) {
1681 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1682 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1683 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1684 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1689 $msg = substr($msg, 5);
1691 $table->wag_set($user->idx_get(), $msg);
1692 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1693 $to_room = $to_user;
1694 /* for old isolation management $is_ticker = TRUE; */
1696 } // /tav chat command
1698 else if (strncmp($msg, "/alarm ", 7) == 0) {
1699 if (strncmp($msg, "/alarm to ", 10) == 0) {
1700 $sp_pos = strpos($msg, " ", 10);
1701 $target = substr($msg, 10, $sp_pos - 10);
1702 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1706 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1709 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1710 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1711 $msg = $mlang_brisk['alarpass'][$G_lang];
1712 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1717 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1718 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1719 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1720 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1721 $dt, NICKSERV, $prestr);
1723 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1724 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1725 /* MLANG: "chiudi" */
1726 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1728 } // /alarm chat command
1729 else if (strncmp($msg, "/listen ", 8) == 0) {
1730 $arg = substr($msg, 8);
1732 if (strcasecmp($arg, "isolation") == 0) {
1734 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1735 $user->table >= TABLES_AUTH_N) {
1736 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1740 $user->flags &= ~USER_FLAG_MAP_AUTH;
1741 $user->flags |= USER_FLAG_ISOLAUTH;
1742 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1745 else if (strcasecmp($arg, "auth") == 0) {
1746 $flags_old = $user->flags;
1747 $user->flags &= ~USER_FLAG_MAP_AUTH;
1748 $user->flags |= USER_FLAG_LISTAUTH;
1749 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1752 $flags_old = $user->flags;
1753 $user->flags &= ~USER_FLAG_MAP_AUTH;
1754 $to_user = 'list_set(\'all\', true, \'\'); ';
1757 // if from isolation redraw standup area
1758 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1759 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1763 else if (strcmp($msg, "/authreq") == 0) {
1764 if ($user->flags & USER_FLAG_AUTH) {
1765 $to_user = sprintf('authbox(300,200);');
1768 /* 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." */
1769 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1772 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1773 if ($user->flags & USER_FLAG_AUTH) {
1774 $to_user = sprintf('mesgtoadmbox(500,300);');
1777 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1778 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1781 else if (strncmp($msg, "/nick ", 6) == 0) {
1782 log_main("chatt_send BEGIN");
1785 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1786 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1790 $msg = "COMMAND ".$msg;
1791 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1792 $user_cur = $this->user[$i];
1794 if ($user_cur->sess == '')
1796 if ($user_cur->name == $name_new)
1799 if ($i < MAX_PLAYERS) {
1800 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1801 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1805 /* 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>" */
1806 if ($user->flags & USER_FLAG_AUTH) {
1807 if (strcasecmp($user->name,$name_new) != 0) {
1808 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1809 ($user->subst == 'standup' ||
1810 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1813 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1814 for ($i = 0 ; $i < TABLES_N ; $i++) {
1815 $to_user .= $this->table[$i]->act_content($user);
1819 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1824 $user->name = $name_new; // OK - nick changed
1825 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1826 if (($user->flags & USER_FLAG_AUTH) == 0) {
1827 if (($bdb = BriskDB::create()) != FALSE) {
1829 /* 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>" */
1830 if ($bdb->login_exists($name_new)) {
1831 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1832 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1837 log_main("chatt_send start set");
1839 $update_room = TRUE;
1841 } // nick chat command
1843 else if (strncmp($msg, "/st ", 4) == 0) {
1844 log_main("chatt_send BEGIN");
1847 $st_str = substr($msg, 4);
1849 if (strcasecmp($st_str, "normale") == 0) {
1850 $st = USER_FLAG_S_NORM;
1852 else if (strcasecmp($st_str, "pausa") == 0) {
1853 $st = USER_FLAG_S_PAU;
1855 else if (strcasecmp($st_str, "fuori") == 0) {
1856 $st = USER_FLAG_S_OUT;
1858 else if (strcasecmp($st_str, "cane") == 0) {
1859 $st = USER_FLAG_S_DOG;
1861 else if (strcasecmp($st_str, "cibo") == 0) {
1862 $st = USER_FLAG_S_EAT;
1864 else if (strcasecmp($st_str, "lavoro") == 0) {
1865 $st = USER_FLAG_S_WRK;
1867 else if (strcasecmp($st_str, "sigaretta") == 0) {
1868 $st = USER_FLAG_S_SMK;
1870 else if (strcasecmp($st_str, "presente") == 0) {
1871 $st = USER_FLAG_S_EYE;
1873 else if (strcasecmp($st_str, "coniglio") == 0) {
1874 $st = USER_FLAG_S_RABB;
1876 else if (strcasecmp($st_str, "calcio") == 0) {
1877 $st = USER_FLAG_S_SOCC;
1879 else if (strcasecmp($st_str, "pupo") == 0) {
1880 $st = USER_FLAG_S_BABY;
1882 else if (strcasecmp($st_str, "pulizie") == 0) {
1883 $st = USER_FLAG_S_MOP;
1886 /* MLANG: "Questo stato non esiste." */
1887 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1891 log_main("chatt_send start set");
1892 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1893 $update_room = TRUE;
1894 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1897 } // nick chat command
1899 else { // normal chat line
1900 $is_normchat = TRUE;
1901 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1903 $user->chat_dlt = $user->chat_dlt * 2;
1904 if ($user->chat_dlt > 120)
1905 $user->chat_dlt = 120;
1907 else if ($user->chat_lst == $msg)
1909 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1910 $user->chat_ban = $curtime;
1911 $user->chat_dlt = 5;
1915 $user->chat_ban = 0;
1916 $user->chat_dlt = 0;
1920 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1923 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1924 // temporary silentiation for troll (will became array check)
1925 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1926 $to_room = $to_user;
1929 log_legal($curtime, $user,
1930 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1932 $user->chat_lst = "$msg";
1933 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1943 // Output to clients
1946 if ($to_user != FALSE) {
1947 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1948 $user->comm[$user->step % COMM_N] .= $to_user;
1952 if ($to_room != FALSE) {
1953 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1954 $user_cur = $this->user[$i];
1955 if ($target != "" && $user_cur->name != $target)
1957 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user->idx_get() == $i)
1960 if ($is_normchat == TRUE) {
1961 // use MAP_AUTH to check if auth or isolation
1962 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1963 if (($user->flags & USER_FLAG_AUTH) == 0) {
1969 else if ($is_ticker) {
1970 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1971 if ($user->table >= TABLES_AUTH_N)
1976 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1977 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1978 $user_cur->step_inc();
1983 // FIXME BRISK4: include for each kind of table
1984 require_once("${G_base}briskin5/Obj/briskin5.phh");
1985 // Before all align times with table timeout
1986 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1987 $table_cur = $this->table[$table_idx];
1988 // if the table is complete and exists its shared mem we get the info about users lacc
1990 if ($table_cur->player_n == PLAYERS_N) {
1991 log_main("PLAYERS == N TABLE ".$table_idx);
1993 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1994 log_main("bin5 lock data success");
1996 $no_recovery = FALSE;
1997 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1998 if ($table_cur->table_token != $bri->table_token) {
1999 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
2004 if ($bri != FALSE) {
2005 $bri_table = $bri->table[0];
2006 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
2007 // stat must be "table" by definition
2008 $bri_user = $bri->user[$i];
2010 if ($target != "" && $bri_user->name != $target)
2012 log_main("writa: ".$user_mesg);
2013 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
2014 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
2015 $bri_user->step_inc();
2017 Bin5::save_data($bri);
2019 Bin5::unlock_data($sem);
2021 } // if ($table_cur->player_n == PLAYERS_N) {
2022 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
2023 } // if ($to_tabl == true ...
2026 if ($user->stat == 'room' && $user->subst == 'standup') {
2027 $this->standup_update($user);
2029 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
2030 log_main("chatt_send pre table update");
2031 $this->table_update($user);
2032 log_main("chatt_send post table update");
2034 } // if ($update_room ...
2037 } // function chatt_send( ...
2039 function get_user($sess, &$idx)
2043 if (validate_sess($sess)) {
2044 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2045 if (strcmp($sess, $this->user[$i]->sess) == 0) {
2048 $ret = $this->user[$i];
2052 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
2053 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
2054 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
2057 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
2064 * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
2067 * if ($idx > -1 && ret == FALSE) => duplicated nick
2068 * if ($idx == -2 && ret == FALSE) => invalid name
2069 * if ($idx == -3 && ret == FALSE) => wrong password
2070 * if ($idx == -1 && ret == FALSE) => no space left
2071 * if ($idx == 0 && ret == user) => SUCCESS
2072 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
2075 function add_user(&$sess, &$idx, $name, $pass, $ip)
2077 GLOBAL $G_base, $CO_list;
2081 $authenticate = FALSE;
2083 $login_exists = FALSE;
2085 $ghost_auth = FALSE;
2090 if (($name_new = validate_name($name)) == FALSE) {
2095 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
2096 if (validate_sess($sess) == FALSE)
2099 /* if pass != FALSE verify the login with pass */
2100 log_auth("XXX", "auth1");
2102 if (($bdb = BriskDB::create()) != FALSE) {
2104 if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
2105 log_auth("XXX", "auth2");
2106 $authenticate = $bdb->login_verify($name_new, $pass, $code);
2107 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
2109 if ($authenticate != FALSE) {
2110 $user_type = $authenticate->type_get();
2118 $login_exists = $bdb->login_exists($name_new);
2122 // if db is down, send a warning and verify only current users
2123 // no actions at this moment
2125 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2127 if (strcmp($sess, $this->user[$i]->sess) == 0) {
2131 if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
2133 continue; // NOTE: CHECK IT !!
2135 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
2136 if ($authenticate != FALSE) {
2138 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
2149 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
2151 /* there is another user logged with your account and you and him have authenticated => che new user
2152 get the session of the old user */
2153 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
2156 $ghost_user = $this->user[$ghost];
2158 $ghost_user->step_inc();
2161 $ghost_user->sess = $sess;
2164 $ghost_user->sess = $sess;
2167 // If user at the table we need to update the table data too
2168 $table_idx = $ghost_user->table;
2169 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
2170 // FIXME BRISK4: include for each kind of table
2171 require_once("${G_base}briskin5/Obj/briskin5.phh");
2172 if (($brisem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
2173 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
2174 if ($bri->the_end != TRUE) {
2175 $bri->user[$ghost_user->table_pos]->step_inc();
2176 $bri->user[$ghost_user->table_pos]->sess = $sess;
2177 Bin5::save_data($bri);
2180 Bin5::unlock_data($brisem);
2185 return ($this->user[$ghost]);
2187 else if ($idx != -1 && $i == MAX_PLAYERS) {
2192 $this->user[$idx]->sess = $sess;
2195 $this->user[$idx]->sess = $sess;
2197 $this->user[$idx]->name = $name_new; // OK - add new user
2198 $this->user[$idx]->stat_set("room");
2199 $this->user[$idx]->step_set(0);
2200 while (array_pop($this->user[$idx]->comm) != NULL);
2201 $this->user[$idx]->subst = "standup";
2202 $this->user[$idx]->lacc = $curtime;
2203 $this->user[$idx]->laccwr = $curtime;
2204 $this->user[$idx]->bantime = 0;
2205 $this->user[$idx]->ip = $ip;
2207 $this->user[$idx]->flags = $user_type;
2208 $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
2209 $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
2210 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
2213 if ($authenticate != FALSE) {
2214 $this->user[$idx]->code = $authenticate->code_get();
2215 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2217 if (isset($CO_list)) {
2218 if (strcmp($CO_list, "auth") == 0) {
2219 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2220 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2222 if (strcmp($CO_list, "isolation") == 0) {
2223 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2224 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
2227 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2233 log_main("ghost: rename!");
2234 $ghost_user = $this->user[$ghost];
2236 if ($ghost_auth == FALSE) {
2237 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
2238 $ghostname = 'ghost'.$sfx;
2239 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2240 if (strcmp("", $this->user[$i]->sess) == 0)
2243 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
2248 if ($ghostname != '')
2252 $ghost_user->name = $ghostname;
2254 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
2255 $this->standup_update($ghost_user);
2258 log_main("chatt_send pre table update");
2259 $this->table_update($ghost_user);
2260 log_main("chatt_send post table update");
2262 } // if ($ghost_auth == FALSE
2264 // FIXME: cacciare il vecchio utente room && table (if needed)
2265 $ghost_user->the_end = TRUE;
2266 $ghost_user->lacc = 0;
2267 $this->garbage_manager(TRUE);
2269 } // if ($ghost > -1) {
2274 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));
2276 $ret = $this->user[$real_idx];
2283 function standup_update($user)
2285 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2286 $user_cur = $this->user[$i];
2287 if ($user_cur->sess == '')
2290 log_main("STANDUP START: ".$user_cur->stat);
2292 if ($user_cur->stat == 'room') {
2293 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
2294 if ($user->idx_get() == $i) {
2295 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
2296 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
2298 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
2299 $itin, xcape($user->name), $itou);
2301 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
2303 $user_cur->step_inc();
2309 static function create()
2317 function load_data()
2322 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2323 log_main("ftok failed");
2327 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2328 log_main("shmop_open failed");
2332 $shm_sz = SHM_DIMS_MIN;
2334 if ($shm = shm_attach($tok, $shm_sz)) {
2335 $room = @shm_get_var($shm, $tok); // CHECKED BELOW
2337 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2339 log_only("bri count ".count($room));
2341 if ($room == FALSE) {
2342 log_only("INIT MAIN DATA");
2345 $room = Room::create();
2347 log_shme("Room::create");
2349 if (Room::save_data($room) == FALSE)
2354 $room->shm_sz = $shm_sz;
2358 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2359 if (($room->user[$i] = User::load_data($i, FALSE)) == FALSE) {
2360 log_crit("Bin5_user::load_data failed");
2364 if ($i < MAX_PLAYERS) {
2370 // SHSPLIT: load users from the shared memory
2379 function save_data_orig($room)
2387 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2390 while ($room->shm_sz < SHM_DIMS_MAX) {
2391 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2394 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2395 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2399 if (shm_remove($shm) === FALSE) {
2400 log_only("REMOVE FALLITA");
2404 $room->shm_sz += SHM_DIMS_DLT;
2414 function save_data($room)
2421 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2424 // SHSPLIT: before save the $room you must save users,
2425 // detach from main struct and (then) reattach
2426 $user_park = array();
2427 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2428 $user_park[$i] = $room->user[$i];
2429 $room->user[$i] = FALSE;
2432 while ($room->shm_sz < SHM_DIMS_MAX) {
2433 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2436 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2437 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2438 log_shme("Room::save_data");
2442 if (shm_remove($shm) === FALSE) {
2443 log_only("REMOVE FALLITA");
2447 $room->shm_sz += SHM_DIMS_DLT;
2453 // SHSPLIT: reattach users to the room class
2454 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2455 User::save_data($user_park[$i], $i);
2456 $room->user[$i] = $user_park[$i];
2458 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
2463 static function lock_data($is_exclusive)
2465 if (($res = file_lock(FTOK_PATH."/main", $is_exclusive)) != FALSE) {
2466 self::$delta_t = microtime(TRUE);
2467 log_lock("LOCK room [".self::$delta_t."]");
2475 static function unlock_data($res)
2479 log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]");
2485 function standup_content($user)
2490 if ($user->stat != 'room')
2493 for ($i = 0 , $ct = 0 ; $ct < 4 && $i < MAX_PLAYERS ; $i++) {
2494 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2499 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2501 $content = ' j_stand_cont( [ ';
2503 for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
2504 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2507 $flags = $this->user[$i]->flags;
2509 if ($this->user[$i]->subst == "standup") {
2510 if ($user->idx_get() == $i) {
2514 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name));
2523 function table_content($user, $table_idx)
2529 // Si possono usare i dati nella classe table
2532 $sess = $user->sess;
2533 $table = $this->table[$table_idx];
2535 if ($user->stat != 'room')
2539 for ($i = 0 ; $i < $table->player_n ; $i++) {
2540 $user_cur = $this->user[$table->player[$i]];
2542 $flags = $user_cur->flags;
2544 if ($user->idx_get() == $table->player[$i])
2547 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2549 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2554 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2559 static function garbage_time_is_expired($tm)
2564 if (file_exists(PROXY_PATH) == FALSE)
2565 mkdir(PROXY_PATH, 0775, TRUE);
2566 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE)
2568 if (($s = fread($fp, 4)) == FALSE)
2570 if (mb_strlen($s, "ASCII") != 4)
2572 $arr = unpack('Le', $s);
2573 if ($arr['e'] > $tm)
2580 log_rd2("END: return ".($ret ? "TRUE" : "FALSE"));
2585 static function garbage_time_expire_set($tm)
2588 if (file_exists(PROXY_PATH) == FALSE)
2589 mkdir(PROXY_PATH, 0775, TRUE);
2590 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE)
2592 fwrite($fp, pack("L",$tm));
2604 function make_seed()
2606 list($usec, $sec) = explode(' ', microtime());
2607 return (float) $sec + ((float) $usec * 100000);
2610 function btrace_line($ar)
2612 GLOBAL $G_btrace_pref_sub;
2615 for ($i = 0 ; $i < count($ar) ; $i++) {
2616 $with_class = isset($ar[$i]['class']);
2617 $with_file = isset($ar[$i]['file']);
2618 $ret .= sprintf("%s%s%s (%s:%d)", ($i == 0 ? "" : ", "),
2619 ($with_class ? $ar[$i]['class'].$ar[$i]['type'] : ""),
2620 $ar[$i]['function'], ($with_file ? str_replace($G_btrace_pref_sub, "", $ar[$i]['file']) : ""),
2621 ($with_file ? $ar[$i]['line'] : ""));
2627 function trace_ftok($id, $add)
2629 // NOTE: without space to use sed to substitute "= @ftok(" with "= @ftok("
2630 $tok=@ftok($id, $add);
2632 log_shme($tok.": ".$id." + ".$add);
2637 function log_mop($step, $log)
2639 GLOBAL $sess, $PHP_SELF;
2641 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2644 if (isset($sess) == FALSE)
2649 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2652 if (BRISK_DEBUG & DBG_TRAC)
2653 $btrace = btrace_line(debug_backtrace());
2656 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2657 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $log, $btrace));
2663 function log_only2($log)
2665 GLOBAL $sess, $PHP_SELF;
2667 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2670 if (isset($sess) == FALSE)
2675 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2678 if (BRISK_DEBUG & DBG_TRAC)
2679 $btrace = btrace_line(debug_backtrace());
2682 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2683 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2688 function log_crit($log)
2690 GLOBAL $sess, $PHP_SELF;
2692 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2695 if (isset($sess) == FALSE)
2700 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2703 if (BRISK_DEBUG & DBG_TRAC)
2704 $btrace = btrace_line(debug_backtrace());
2707 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2708 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2713 function log_only($log)
2715 GLOBAL $sess, $PHP_SELF;
2717 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2720 if (isset($sess) == FALSE)
2725 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2728 if (BRISK_DEBUG & DBG_TRAC)
2729 $btrace = btrace_line(debug_backtrace());
2732 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2733 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2738 function log_main($log)
2740 GLOBAL $sess, $PHP_SELF;
2742 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2745 if (isset($sess) == FALSE)
2750 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2753 if (BRISK_DEBUG & DBG_TRAC)
2754 $btrace = btrace_line(debug_backtrace());
2757 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2758 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2763 function log_rd($log)
2765 GLOBAL $sess, $PHP_SELF;
2767 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2770 if (isset($sess) == FALSE)
2775 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2778 if (BRISK_DEBUG & DBG_TRAC)
2779 $btrace = btrace_line(debug_backtrace());
2782 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2783 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2788 function log_rd2($log)
2790 GLOBAL $sess, $PHP_SELF;
2792 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2795 if (isset($sess) == FALSE)
2800 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2803 if (BRISK_DEBUG & DBG_TRAC)
2804 $btrace = btrace_line(debug_backtrace());
2808 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2809 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2814 function log_send($log)
2816 GLOBAL $sess, $PHP_SELF;
2818 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2821 if (isset($sess) == FALSE)
2826 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2829 if (BRISK_DEBUG & DBG_TRAC)
2830 $btrace = btrace_line(debug_backtrace());
2833 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2834 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2839 function log_lock($log)
2841 GLOBAL $sess, $PHP_SELF;
2843 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2846 if (isset($sess) == FALSE)
2851 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2854 if (BRISK_DEBUG & DBG_TRAC)
2855 $btrace = btrace_line(debug_backtrace());
2858 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2859 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2864 function log_wr($log)
2866 GLOBAL $sess, $PHP_SELF;
2868 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2871 if (isset($sess) == FALSE)
2876 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2879 if (BRISK_DEBUG & DBG_TRAC)
2880 $btrace = btrace_line(debug_backtrace());
2883 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2884 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2889 function log_load($log)
2891 GLOBAL $sess, $PHP_SELF;
2893 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2896 if (isset($sess) == FALSE)
2901 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2904 if (BRISK_DEBUG & DBG_TRAC)
2905 $btrace = btrace_line(debug_backtrace());
2908 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2909 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2914 function log_auth($sess, $log)
2918 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2921 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2924 if (BRISK_DEBUG & DBG_TRAC)
2925 $btrace = btrace_line(debug_backtrace());
2928 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2929 fwrite($fp, sprintf("LOAD: [%s] [%d] [%s] [%s]\n", $sess, time(), $log, $btrace));
2934 function log_shme($log)
2936 GLOBAL $sess, $PHP_SELF;
2938 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SHME) == 0)
2941 if (isset($sess) == FALSE)
2946 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SHME) == 0)
2949 if (BRISK_DEBUG & DBG_TRAC)
2950 $btrace = btrace_line(debug_backtrace());
2953 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2954 fwrite($fp, sprintf("SHME: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2961 // function log_legal($curtime, $sess, $name, $where, $mesg)
2962 function log_legal($curtime, $user, $where, $mesg)
2966 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2967 /* Unix time | session | nickname | IP | where was | mesg */
2968 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2969 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2970 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2975 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2980 if ($sitted < PLAYERS_N) {
2988 if ($table == $cur_table)
2995 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
3000 function show_notify($text, $tout, $butt, $w, $h)
3002 log_main("SHOW_NOTIFY: ".$text);
3003 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
3006 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
3008 log_main("SHOW_NOTIFY OPAQUE: ".$text);
3009 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);
3013 function root_wellcome($user)
3015 GLOBAL $root_wellarr, $G_lang;
3019 $dt = date("H:i ", $curtime);
3021 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
3022 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
3029 function validate_sess($sess)
3031 if (strlen($sess) == SESS_LEN)
3037 function validate_name($name)
3039 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
3041 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
3043 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
3050 function playsound($filename)
3052 return (sprintf('playsound("flasou", "%s");', $filename));
3055 function secstoword($secs)
3061 $mins = floor($secs / 60);
3063 if ($G_lang == 'en') {
3065 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
3068 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
3072 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
3075 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
3080 function sharedmem_sz($tok)
3082 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
3083 log_main("shmop_open failed");
3086 $shm_sz = shmop_size($shm_id);
3087 shmop_close($shm_id);
3089 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
3096 static function lock_data($is_exclusive)
3098 if (($res = file_lock(FTOK_PATH."/warrant", $is_exclusive)) != FALSE) {
3099 self::$delta_t = microtime(TRUE);
3100 log_lock("LOCK warrant [".self::$delta_t."]");
3108 static function unlock_data($res)
3112 log_lock("UNLOCK warrant [".(microtime(TRUE) - (self::$delta_t))."]");
3121 static function lock_data($is_exclusive)
3123 if (($res = file_lock(FTOK_PATH."/poll", $is_exclusive)) != FALSE) {
3124 self::$delta_t = microtime(TRUE);
3125 log_lock("LOCK poll [".self::$delta_t."]");
3133 static function unlock_data($res)
3137 log_lock("UNLOCK poll [".(microtime(TRUE) - (self::$delta_t))."]");