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);
40 define(COMM_GEN_N, 50);
43 define(CHAT_ILL_TIME, 6);
46 define(STREAM_TIMEOUT, 20);
47 define(EXPIRE_TIME_RD, 180);
48 define(EXPIRE_TIME_SMAMMA, 360);
49 define(EXPIRE_TIME_WAG, 10);
50 define(WAKEUP_TIME, 12);
51 // BAN_TIME da allineare anche in commons.js
52 define(BAN_TIME, 3600);
53 define(GARBAGE_TIMEOUT, 10);
54 define(NICKSERV, "<i>BriskServ</i>");
57 define(DBG_ONL2, 0x0001);
58 define(DBG_ONLY, 0x0002);
59 define(DBG_MAIN, 0x0004);
60 define(DBG_READ, 0x0008);
61 define(DBG_REA2, 0x0010);
62 define(DBG_SEND, 0x0020);
63 define(DBG_LOCK, 0x0040);
64 define(DBG_WRIT, 0x0080);
65 define(DBG_LOAD, 0x0100);
66 define(DBG_AUTH, 0x0200);
67 define(DBG_CRIT, 0x0400);
68 define(DBG_LMOP, 0x0800);
70 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
71 define(BRISK_DEBUG, 0xffffffbf);
73 define(BRISK_SINGLE_DEBUG,0);
74 define(BRISK_SINGLE_SESS, "");
75 // define(DEBUGGING, "local");
77 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
79 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
80 'en' => 'back standing' ),
81 'btn_close' => array( 'it' => 'chiudi',
84 'tit_all' => array( 'it' => 'tutti',
87 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
88 'en' => '<br>You are being idle for ' ),
89 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
90 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
91 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
92 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
93 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
94 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
95 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
96 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
97 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
98 'en' => '<br>The entered password is not correct.<br><br>'),
99 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
100 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
101 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
102 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
103 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
104 'en' => '<b>To send a message you have to be authenticated.</b>'),
105 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
106 'en' => 'The nickname have to contain at least one letter or one number.'),
107 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
108 'en' => 'The nickname <b>%s</b> is already in use.'),
109 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
110 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
111 '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>',
112 '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 ???
113 'statunkn' => array( 'it' => 'Questo stato non esiste.',
114 'en' => 'This state don\'t exists.'),
115 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
116 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
117 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
118 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
120 'tit_onauth'=>array( 'it' => '(solo aut.)',
121 'en' => '(only aut.)'),
122 'tit_onisol'=>array( 'it' => '(isolam.to)',
123 'en' => '(isolation)')
129 $G_lng = langtolng($G_lang);
131 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
132 $G_brisk_version = "2.5.0";
134 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
135 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: informazioni al tavolo sul chiamante, nuovo stato di supporter del sito.',
136 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
137 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: caller information on the table, new supporter status.',
138 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
140 $G_room_help = array( 'it' => '
141 <div style=\\"text-align: left; padding: 8px;\\">
142 <b>Descrizione</b><br>
143 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
144 <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>
145 <b>Configurazione del browser.</b><br>
146 Occorre abilitare i cookies.<br>
148 <b>Uso del sito</b><br>
149 Potete sedervi a un tavolo o rimanere in piedi.<br>
150 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
153 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>
154 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
155 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
156 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
157 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
158 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.
160 <dt><b>Comandi della chat</b>
161 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
162 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
163 <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\\"
164 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
165 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
166 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
172 <div style=\\"text-align: left; padding: 8px;\\">
173 <b>EN Descrizione</b><br>
174 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
175 <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>
176 <b>EN Configurazione del browser.</b><br>
177 Occorre abilitare i cookies.<br>
179 <b>Uso del sito</b><br>
180 Potete sedervi a un tavolo o rimanere in piedi.<br>
181 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
184 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>
185 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
186 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
187 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
188 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
189 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.
191 <dt><b>Comandi della chat</b>
192 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
193 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
194 <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\\"
195 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
196 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
197 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
203 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
204 <div style=\\"text-align: left; padding: 8px;\\">
205 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
207 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
208 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
210 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
211 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
212 <li>Smart card di InfoCamere
215 <b>Per auto-garantisi occorre possedere:</b><br><br>
217 <li>il codice PIN della propria carta
218 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
221 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
223 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
226 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
227 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
232 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
233 <div style=\\"text-align: left; padding: 8px;\\">
234 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
236 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
237 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
239 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
240 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
243 <b>Per auto-garantisi occorre possedere:</b><br><br>
245 <li>il codice PIN della propria carta
246 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
249 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
251 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
254 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
255 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
261 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
265 $G_room_about = array( 'it' => '<br>
266 <div id=\\"header\\" class=\\"header\\">
267 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
268 briscola chiamata in salsa ajax
270 <br><b>version '.$G_brisk_version.'</b><br><br>
271 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
273 <div id=\\"header\\" class=\\"header\\">
274 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
275 declaration briscola in ajax sauce <b>(Beta)</b>
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 $escinp_from = array( "\"" );
281 $escinp_to = array( """ );
283 function escinput($s)
285 GLOBAL $escinp_from, $escinp_to;
287 return str_replace($escinp_from, $escinp_to, $s);
292 return htmlentities($s);
295 function esclfhtml($s)
297 return str_replace("\n", "<br>\n", htmlentities($s));
301 function langtolng($lang)
305 return ($G_lang == 'en' ? '-en' : '');
308 function csplitter($in, $sep)
314 for ($i = 0 ; $i < strlen($in) ; $i++) {
315 $ini = substr($in, $i, 1);
319 else if ($ini == $sep) {
338 $from = array ( '\\', '@', '|' );
339 $to = array ( '\\\\', '@', '¦' );
341 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
346 $from = array ( '\\', '|', "\t", "\n");
347 $to = array ( '\\\\', '\\|', "\\t", "\\n");
349 return (str_replace($from, $to, $s));
352 function xcapemesg($s)
354 $from = array ( "\n");
355 $to = array ( "\\n");
357 return (str_replace($from, $to, $s));
366 var $auth_only; // se tavolo riservato o libero
373 var $table_start; // information field
381 function &create($idx)
385 if (($thiz =& new Table()) == FALSE)
389 $thiz->player = array();
391 $thiz->auth_only = FALSE;
393 $thiz->wag_own = NULL;
397 $thiz->table_token = "";
398 $thiz->table_start = 0;
400 $thiz->wakeup_time = 0;
405 function copy(&$from)
409 $this->idx = $from->idx;
410 $this->player = array();
411 for ($i = 0 ; $i < $from->player_n ; $i++)
412 $this->player[$i] = $from->player[$i];
413 $this->player_n = $from->player_n;
415 log_main("PLAYER_N - parent::copy.".$this->player_n);
417 $this->auth_only = $from->auth_only;
419 $this->wag_own = $from->wag_own;
420 $this->wag_com = $from->wag_com;
421 $this->wag_tout = $from->wag_tout;
423 $this->table_token = $from->table_token;
424 $this->table_start = $from->table_start;
426 $this->wakeup_time = $from->wakeup_time;
429 function &myclone(&$from)
433 if (($thiz =& new Table()) == FALSE)
441 function &spawn(&$from)
445 if (($thiz =& new Table()) == FALSE)
448 $thiz->idx = $from->idx;
449 $thiz->player = array();
450 for ($i = 0 ; $i < $from->player_n ; $i++)
451 $thiz->player[$i] = $i;
452 $thiz->player_n = $from->player_n;
454 $thiz->auth_only = $from->auth_only;
456 $thiz->wag_own = $from->wag_own;
457 $thiz->wag_com = $from->wag_com;
458 $thiz->wag_tout = $from->wag_tout;
460 $thiz->table_token = $from->table_token;
461 $thiz->table_start = $from->table_start;
463 $thiz->wakeup_time = $from->wakeup_time;
468 function wag_set(&$user, $mesg)
472 $this->wag_own = &$user;
473 $this->wag_com = $mesg;
477 function wag_reset($timeout)
479 log_main("WAG_RESET");
481 unset($this->wag_own);
482 $this->wag_own = NULL;
484 $this->wag_tout = $timeout;
487 function getPlayer($idx)
489 return ($this->player[$idx]);
492 function setPlayer($idx, $player)
494 $this->player[$idx] = $player;
497 function user_add($idx)
499 $this->player[$this->player_n] = $idx;
502 return ($this->player_n - 1);
505 function user_rem(&$room, &$user)
507 $tabpos = $user->table_pos;
509 /* verifico la consistenza dei dati */
510 if ($room->user[$this->player[$tabpos]] == $user) {
512 /* aggiorna l'array dei giocatori al tavolo. */
513 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
514 $this->player[$i] = $this->player[$i+1];
515 $user_cur = &$room->user[$this->player[$i]];
516 $user_cur->table_pos = $i;
521 log_main("INCONSISTENCY ON TABLE.");
527 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
528 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
530 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
531 function act_content(&$user)
534 $isstanding = ($user->subst == 'standup');
535 $sitted = $this->player_n;
537 $cur_table = $user->table;
541 if ($sitted < PLAYERS_N) {
542 if ($this->auth_only) {
543 if ($user->flags & USER_FLAG_AUTH)
557 if ($table == $cur_table)
564 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
572 define(USER_FLAG_AUTH, 0x02);
574 define(USER_FLAG_MAP_AUTH, 0x0c);
576 define(USER_FLAG_LISTAUTH, 0x04);
577 define(USER_FLAG_ISOLAUTH, 0x08);
580 define(USER_FLAG_S_NORM, 0x000); // done
581 define(USER_FLAG_S_PAU, 0x100); // done
582 define(USER_FLAG_S_OUT, 0x200); // done
583 define(USER_FLAG_S_DOG, 0x300); // done
584 define(USER_FLAG_S_EAT, 0x400); // done
585 define(USER_FLAG_S_WRK, 0x500); // done
586 define(USER_FLAG_S_SMK, 0x600); // done
587 define(USER_FLAG_S_EYE, 0x700); // done
588 define(USER_FLAG_S_RABB, 0x800); // done
589 define(USER_FLAG_S_SOCC, 0x900); // done
590 define(USER_FLAG_S_BABY, 0xa00); // done
591 define(USER_FLAG_S_MOP, 0xb00); // done
593 define(USER_FLAG_S_ALL, 0xf00); // done
595 /* type of user normal, supporter etc ... */
596 define(USER_FLAG_TY_ALL, 0xff0000); // done
597 define(USER_FLAG_TY_NORM, 0x010000); // done
598 define(USER_FLAG_TY_SUPER, 0x020000); // done
599 // ... other usefull status ...
600 define(USER_FLAG_TY_SUSPEND, 0x400000); // done
601 define(USER_FLAG_TY_DISABLE, 0x800000); // done
604 var $code; // authentication code
605 var $name; // name of the user
606 var $sess; // session of the user
607 var $ip; // ip of the user
608 var $lacc; // last access (for the cleanup)
609 var $laccwr; // last access (for the cleanup)
610 var $bantime; // timeout to temporary ban
611 var $stat; // status (outdoor, room, table, game, ...)
612 var $subst; // substatus for each status
613 var $step; // step of the current status
614 var $trans_step; // step to enable transition between pages (disable == -1)
615 var $comm; // commands array
616 // var $asta_card; //
618 // var $handpt; // Total card points at the beginning of the current hand.
619 // var $exitislock; // Player can exit from the table ?
621 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
622 // it is allways ZERO
623 var $table_orig; // id of the current table (if in table state)
624 var $table; // id of the current table (if in table state)
625 var $table_pos; // idx on the table
626 var $table_token;// token that identify a game on a table
627 var $flags; // Bitfield with: AUTHENTICATE: 0x02
628 var $the_end; // Flag to change the end of the session
630 var $chat_lst; // Last chat line
631 var $chattime; // Array of chat times
632 var $chat_cur; // Current chat line number
633 var $chat_ban; // Time for ban chat
634 var $chat_dlt; // Delta t for ban
638 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
641 if (($thiz =& new User()) == FALSE)
648 $thiz->lacc = time();
649 $thiz->laccwr = time();
652 $thiz->subst = $subst;
654 $thiz->trans_step = -1;
655 $thiz->comm = array();
656 $thiz->asta_card = -2;
657 $thiz->asta_pnt = -1;
659 $thiz->exitislock = TRUE;
663 $thiz->chattime = array_fill(0, CHAT_N, 0);
665 $thiz->chat_lst = "";
669 $thiz->table_orig = $table;
670 $thiz->table = $table;
671 $thiz->table_pos = -1;
672 $thiz->table_token = "";
677 function copy(&$from)
681 $this->code = $from->code;
682 $this->name = $from->name;
683 $this->sess = $from->sess;
684 $this->ip = $from->ip;
685 $this->lacc = $from->lacc;
686 $this->laccwr = $from->laccwr;
687 $this->bantime = $from->bantime;
688 $this->stat = $from->stat;
689 $this->subst = $from->subst;
690 $this->step = $from->step;
691 $this->trans_step = $from->trans_step;
692 $this->comm = array();
694 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
695 for ($i = $i_start ; $i < $from->step ; $i++) {
697 $this->comm[$ii] = $from->comm[$ii];
699 $this->asta_card = $from->asta_card;
700 $this->asta_pnt = $from->asta_pnt;
701 $this->handpt = $from->handpt;
702 $this->exitislock = $from->exitislock;
704 $this->flags = $from->flags;
706 $this->chattime = array();
707 for ($i = 0 ; $i < CHAT_N ; $i++)
708 $this->chattime[$i] = $from->chattime[$i];
709 $this->chat_cur = $from->chat_cur;
710 $this->chat_lst = $from->chat_lst;
711 $this->chat_ban = $from->chat_ban;
712 $this->chat_dlt = $from->chat_dlt;
714 $this->table_orig = $from->table_orig;
715 $this->table = $from->table;
716 $this->table_pos = $from->table_pos;
717 $this->table_token = $from->table_token;
718 $this->the_end = $from->the_end;
724 function &myclone(&$from)
728 if (($thiz =& new User()) == FALSE)
736 function &spawn(&$from, $table, $table_pos)
740 if (($thiz =& new User()) == FALSE)
743 $thiz->code = $from->code;
744 $thiz->name = $from->name;
745 $thiz->sess = $from->sess;
746 $thiz->ip = $from->ip;
747 $thiz->lacc = $from->lacc;
748 $thiz->laccwr = $from->laccwr;
749 $thiz->bantime = $from->bantime;
750 $thiz->stat = $from->stat;
751 $thiz->subst = $from->subst;
752 $thiz->step = $from->step;
753 $thiz->trans_step = $from->trans_step;
754 $thiz->comm = array();
757 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
758 for ($i = $i_start ; $i < $from->step ; $i++) {
759 log_wr("TRY PUSH:".$i);
761 $thiz->comm[$ii] = $from->comm[$ii];
764 $thiz->asta_card = $from->asta_card;
765 $thiz->asta_pnt = $from->asta_pnt;
766 $thiz->handpt = $from->handpt;
767 $thiz->exitislock = $from->exitislock;
768 $thiz->the_end = $from->the_end;
770 $thiz->flags = $from->flags;
772 $thiz->chattime = array_fill(0, CHAT_N, 0);
774 $thiz->chat_lst = "";
779 $thiz->table_orig = $table;
781 $thiz->table_pos = $table_pos;
782 $thiz->table_token = $from->table_token;
787 function code_get() {
788 return ($this->code);
791 function stat_set($stat) {
792 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
793 $this->stat = "$stat";
796 if (validate_sess($this->sess)) {
797 if (file_exists(PROXY_PATH) == FALSE)
799 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
800 fwrite($fp, sprintf("%s\n",$this->stat));
806 function step_set($step) {
810 if (validate_sess($this->sess) == FALSE)
812 if (file_exists(PROXY_PATH) == FALSE)
814 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
816 fwrite($fp, pack("l",$this->step), 4);
825 function step_inc($delta = 1) {
826 $this->step += $delta;
828 if (validate_sess($this->sess)) {
829 if (file_exists(PROXY_PATH) == FALSE)
831 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
832 fwrite($fp, pack("l",$this->step), 4);
843 log_legal($curtime, $this, "STAT:LOGOUT", '');
845 $tmp_sess = $this->sess;
847 step_unproxy($tmp_sess);
848 $this->name = ""; // OK here
849 while (array_pop($this->comm) != NULL);
851 $this->chattime = array_fill(0, CHAT_N, 0);
853 $this->chat_lst = "";
856 $this->the_end = FALSE;
866 function step_get($sess) {
869 if (validate_sess($sess) == FALSE)
872 if (file_exists(PROXY_PATH) == FALSE)
874 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
876 if (($s = fread($fp, 4)) == FALSE)
880 $arr = unpack('l', $s);
883 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
890 log_rd2("STEP_GET: return false ");
895 function step_unproxy($sess) {
896 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
897 if (file_exists(PROXY_PATH) == FALSE)
899 @unlink(PROXY_PATH."/".$sess.".step");
906 var $comm; // commands for many people
907 var $step; // current step of the comm array
908 var $garbage_timeout;
912 $this->user = array();
913 $this->table = array();
915 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
916 $this->user[$i] =& User::create("", "");
919 for ($i = 0 ; $i < TABLES_N ; $i++) {
920 $this->table[$i] =& Table::create($i);
923 $row = ( (((int)($i / 4)) % 2) == 0 );
924 $col = ($i % 2 == 0);
925 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
928 $this->table[$i]->auth_only = FALSE;
931 if ($i < TABLES_AUTH_N)
932 $this->table[$i]->auth_only = TRUE;
934 $this->table[$i]->auth_only = FALSE;
936 $this->garbage_timeout = 0;
939 function garbage_manager($force)
941 GLOBAL $G_lang, $mlang_brisk, $G_base;
945 log_rd2("garbage_manager START");
947 /* Garbage collector degli utenti in timeout */
949 if ($force || $this->garbage_timeout < $curtime) {
951 // FIXME BRISK4: include for each kind of table
952 require_once("${G_base}briskin5/Obj/briskin5.phh");
954 // Before all align times with table timeout
955 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
956 $table_cur =& $this->table[$table_idx];
957 // if the table is complete and exists its shared mem we get the info about users lacc
959 if ($table_cur->player_n == PLAYERS_N) {
960 log_main("PLAYERS == N TABLE ".$table_idx);
962 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
963 log_main("bin5 lock data success");
965 $no_recovery = FALSE;
966 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
967 if ($table_cur->table_token != $bri->table_token) {
968 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
969 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
979 log_main("garbage_manager: bri loaded successfully.");
980 $bri->garbage_manager(TRUE);
982 $bri_table = &$bri->table[0];
984 // is the end of the table
985 if ($bri->the_end == TRUE) {
987 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
989 log_main("garbage_manager: INSIDE THE END.");
991 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
992 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
993 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
996 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
997 // stat must be "table" by definition
998 $user_cur =& $this->user[$table_cur->player[$i]];
999 $bri_user =& $bri->user[$i];
1001 $user_cur->subst = $bri_user->subst;
1002 $user_cur->step = $bri_user->step;
1003 $user_cur->lacc = $bri_user->lacc;
1004 $user_cur->laccwr = $bri_user->lacc;
1005 $user_cur->bantime = $bri_user->bantime;
1008 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
1010 $this->room_join_wakeup(&$user_cur, FALSE, 0);
1011 $table_cur->table_token = "";
1012 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
1013 Briskin5::destroy_data($table_idx);
1016 log_main("gm:: save_data");
1018 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1019 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
1022 Briskin5::save_data(&$bri);
1024 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1025 else if ($no_recovery == FALSE) {
1026 log_crit("ERROR: table ".$table_idx." unrecoverable join");
1028 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1029 $user_cur = &$this->user[$table_cur->player[$i]];
1030 $user_cur->subst = "shutdowner";
1031 $user_cur->step_inc();
1033 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
1034 $ret .= "gst.st = ".($user_cur->step+1)."; ";
1035 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
1036 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
1037 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
1038 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1039 $user_cur->step_inc();
1042 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
1043 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1044 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1046 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
1048 $this->room_join_wakeup(&$user_cur, TRUE, -2);
1049 $table_cur->table_token = "";
1052 Briskin5::unlock_data($sem);
1054 } // if ($table_cur->player_n == PLAYERS_N) {
1055 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1057 log_rd2("out new loop.");
1059 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1060 $user_cur = &$this->user[$i];
1062 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1064 if ($user_cur->sess == "")
1067 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1068 // Auto logout dell'utente
1069 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1071 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1072 log_auth($user_cur->sess, "Autologout session.");
1076 log_rd2("AUTO LOGOUT.");
1077 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1078 $this->room_wakeup(&$user_cur);
1079 else if ($user_cur->subst == 'standup')
1080 $this->room_outstandup(&$user_cur);
1082 log_rd2("LOGOUT FROM WHAT ???");
1086 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1087 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1088 $this->room_wakeup(&$user_cur);
1089 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1090 /* 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" */
1091 $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);
1092 $user_cur->step_inc();
1096 log_rd2("GARBAGE UPDATED!");
1098 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1105 function show_room($user_step, &$user)
1107 GLOBAL $G_lang, $mlang_brisk;
1108 log_main("show_room: username: ".$user->name);
1110 $ret = sprintf('gst.st = %d; ', $user_step);
1112 if ($user->flags & USER_FLAG_ISOLAUTH) {
1113 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
1115 else if ($user->flags & USER_FLAG_LISTAUTH) {
1116 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1119 $ret .= 'list_set(\'all\', false, \'\' ); ';
1122 if ($user->subst == 'standup')
1123 $ret .= "tra.show(); ";
1125 $ret .= "tra.hide(); ";
1127 $ret .= sprintf('stat = "%s";', $user->stat);
1129 $ret .= root_wellcome($user);
1130 $ret .= sprintf('subst = "%s";', $user->subst);
1131 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1132 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1133 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1134 for ($i = 0 ; $i < TABLES_N ; $i++) {
1136 $ret .= $this->table_content($user, $i);
1137 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1138 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1139 $ret .= $this->table[$i]->act_content($user);
1140 if ($this->table[$i]->wag_own != NULL)
1141 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
1143 $ret .= sprintf('tra.rem(%d); ', $i);
1145 $ret .= $this->standup_content($user);
1151 function room_wakeup(&$user)
1153 $table_idx = $user->table;
1154 $table = &$this->table[$table_idx];
1156 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1160 $from_table = ($user->stat == "table");
1162 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1164 for ($i = 0 ; $i < $table->player_n ; $i++) {
1165 $user_cur = &$this->user[$table->player[$i]];
1166 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1168 if ($user_cur != $user) {
1169 $user_cur->stat_set("room");
1170 $user_cur->subst = "sitdown";
1171 $user_cur->laccwr = $curtime;
1173 else if ($user->sess != "") {
1174 $user_cur->stat_set("room");
1175 $user_cur->subst = "standup";
1176 $user_cur->laccwr = $curtime;
1177 $user_cur->table = -1;
1182 $user->stat_set("room");
1183 $user->subst = "standup";
1184 $user->laccwr = $curtime;
1187 $remove_wagon = false;
1188 if($table->wag_own == $user) {
1189 $remove_wagon = true;
1190 $table->wag_reset($curtime);
1195 /* aggiorna l'array dei giocatori al tavolo. */
1196 $table->user_rem(&$this, &$user);
1198 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1199 $user_cur = &$this->user[$i];
1200 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1203 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1205 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1206 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
1207 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1208 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1209 log_main("DOCUMENT.index.php: from table");
1211 else if ($user_cur->stat == "room") {
1212 log_main("DOCUMENT.index.php: from table");
1214 $ret .= $this->table_content($user_cur, $table_idx);
1215 $ret .= $this->standup_content($user_cur);
1217 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1218 $ret .= $table->act_content($user);
1220 if ($user_cur == $user) {
1221 // set the new status
1222 $ret .= 'subst = "standup"; tra.show(); ';
1223 // clean the action buttons in other tables
1224 for ($e = 0 ; $e < TABLES_N ; $e++) {
1225 if ($this->table[$e]->player_n < PLAYERS_N) {
1226 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1227 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1228 $ret .= $this->table[$e]->act_content($user);
1233 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1234 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1235 $ret .= $table->act_content($user_cur);
1238 log_wr("ROOM_WAKEUP: ".$ret);
1239 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1240 $user_cur->step_inc();
1244 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1246 $table_idx = $user->table;
1247 $table = &$this->table[$table_idx];
1249 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1252 $user_wup = array();
1254 $user_tab = array();
1256 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1258 for ($i = 0 ; $i < $table->player_n ; $i++) {
1259 $user_cur = &$this->user[$table->player[$i]];
1260 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1261 if ($user_cur->sess != "") {
1262 if ($update_lacc == TRUE) {
1263 $user_cur->laccwr = $curtime;
1265 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1266 if ($user_cur->subst == "shutdowned") {
1267 $user_cur->stat_set("room");
1268 $user_cur->subst = "sitdown";
1270 else if ($user_cur->subst == "shutdowner") {
1271 $user_cur->stat_set("room");
1272 $user_cur->subst = "standup";
1273 $user_cur->table = -1;
1274 $user_wup[$user_wup_n++] = &$user_cur;
1276 $remove_wagon = false;
1277 if($table->wag_own == $user_cur) {
1278 $remove_wagon = true;
1279 $table->wag_reset($curtime);
1282 $user_tab[$user_tab_n++] = &$user_cur;
1286 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1287 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1289 /* aggiorna l'array dei giocatori al tavolo. */
1291 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1292 log_main("START LOOP");
1293 $user_cur = &$this->user[$i];
1294 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1295 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1300 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1302 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1303 if ($user_cur->stat == "room") {
1304 log_main("DOCUMENT.index.php from table");
1306 $ret .= $this->table_content($user_cur, $table_idx);
1307 $ret .= $this->standup_content($user_cur);
1309 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1310 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1311 $ret .= $table->act_content($user_cur);
1314 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1315 if ($user_cur == $user_tab[$tab_idx])
1318 // for users that wakeup the room will be reconstructed by index_rd.php
1319 if ($tab_idx < $user_tab_n) {
1320 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1322 // ARRAY_POP DISABLED
1323 // if ($trans_delta == 0)
1324 // while (array_pop($user_cur->comm) != NULL);
1326 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1327 $user_cur->comm[$user_cur->step % COMM_N] = "";
1328 $user_cur->step_inc();
1329 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1330 $user_cur->step_inc();
1331 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1335 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1337 log_main("JOIN_WAKEUP more");
1338 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1339 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1340 $ret .= $table->act_content($user_cur);
1342 log_main("JOIN_WAKEUP end more");
1344 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1345 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1346 $user_cur->step_inc();
1350 function room_outstandup(&$user)
1352 $this->room_sitdown(&$user, -1);
1355 function table_update(&$user)
1357 log_main("table_update: pre - USER: ".$user->name);
1359 $table_idx = $user->table;
1361 if ($table_idx > -1)
1362 $table = &$this->table[$table_idx];
1364 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1366 $user_cur = &$this->user[$i];
1367 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1370 $ret = "gst.st = ".($user_cur->step+1)."; ";
1371 if ($table_idx > -1)
1372 $ret .= $this->table_content($user_cur, $table_idx);
1374 if ($user_cur == $user) {
1375 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1376 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1377 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1379 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1380 $user_cur->step_inc();
1383 log_main("table_update: post");
1386 function room_sitdown(&$user, $table_idx)
1388 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1392 if ($table_idx > -1 && $table_idx < TABLES_N) {
1393 $table = &$this->table[$table_idx];
1396 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1397 for ($i = 0 ; $i < TABLES_N ; $i++) {
1398 $user_cur =& $this->user[$table->player[$i]];
1399 if ($user_cur == $table->wag_own) {
1400 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1401 $table->wag_reset(time());
1408 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1410 $user_cur = &$this->user[$i];
1411 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1414 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1415 if ($table_idx > -1)
1416 $ret .= $this->table_content($user_cur, $table_idx);
1417 $ret .= $this->standup_content($user_cur);
1419 if ($user_cur == $user) {
1420 $ret .= 'subst = "sitdown"; tra.hide(); ';
1421 // clean the action buttons in other tables
1422 for ($e = 0 ; $e < TABLES_N ; $e++) {
1423 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1424 $ret .= $this->table[$e]->act_content($user_cur);
1427 else if ($table_idx > -1) {
1428 if ($table->player_n == PLAYERS_N) {
1429 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1430 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1431 $ret .= $table->act_content($user_cur);
1434 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1435 $user_cur->step_inc();
1439 function chatt_send(&$user, $mesg)
1441 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1445 $msg = substr($mesg, 6, 128);
1447 $dt = date("H:i ", $curtime);
1457 $is_normchat = FALSE;
1458 /* for old isolation management $is_ticker = FALSE; */
1459 $update_room = FALSE;
1461 if (strcmp($msg, "/tav") == 0 ||
1462 strncmp($msg, "/tav ", 5) == 0) {
1464 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1465 /* 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>" */
1466 $msg = $mlang_brisk['tickmust'][$G_lang];
1467 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1472 $table = &$this->table[$user->table];
1474 if ($table->wag_own != NULL) {
1475 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1476 $msg = $mlang_brisk['tickjust'][$G_lang];
1477 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1482 $dtime = $curtime - $table->wag_tout;
1483 if ($dtime < EXPIRE_TIME_WAG) {
1484 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1485 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1486 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1487 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1492 $msg = substr($msg, 5);
1494 $table->wag_set($user, $msg);
1495 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1496 $to_room = $to_user;
1497 /* for old isolation management $is_ticker = TRUE; */
1499 } // /tav chat command
1501 else if (strncmp($msg, "/alarm ", 7) == 0) {
1502 if (strncmp($msg, "/alarm to ", 10) == 0) {
1503 $sp_pos = strpos($msg, " ", 10);
1504 $target = substr($msg, 10, $sp_pos - 10);
1505 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1509 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1512 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1513 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1514 $msg = $mlang_brisk['alarpass'][$G_lang];
1515 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1520 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1521 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1522 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1523 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1524 $dt, NICKSERV, $prestr);
1526 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1527 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1528 /* MLANG: "chiudi" */
1529 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1531 } // /alarm chat command
1532 else if (strncmp($msg, "/listen ", 8) == 0) {
1533 $arg = substr($msg, 8);
1535 if (strcasecmp($arg, "isolation") == 0) {
1537 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1538 $user->table >= TABLES_AUTH_N) {
1539 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1543 $user->flags &= ~USER_FLAG_MAP_AUTH;
1544 $user->flags |= USER_FLAG_ISOLAUTH;
1545 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1548 else if (strcasecmp($arg, "auth") == 0) {
1549 $flags_old = $user->flags;
1550 $user->flags &= ~USER_FLAG_MAP_AUTH;
1551 $user->flags |= USER_FLAG_LISTAUTH;
1552 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1555 $flags_old = $user->flags;
1556 $user->flags &= ~USER_FLAG_MAP_AUTH;
1557 $to_user = 'list_set(\'all\', true, \'\'); ';
1560 // if from isolation redraw standup area
1561 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1562 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1566 else if (strcmp($msg, "/authreq") == 0) {
1567 if ($user->flags & USER_FLAG_AUTH) {
1568 $to_user = sprintf('authbox(300,200);');
1571 /* 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." */
1572 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1575 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1576 if ($user->flags & USER_FLAG_AUTH) {
1577 $to_user = sprintf('mesgtoadmbox(500,300);');
1580 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1581 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1584 else if (strncmp($msg, "/nick ", 6) == 0) {
1585 log_main("chatt_send BEGIN");
1588 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1589 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1593 $msg = "COMMAND ".$msg;
1594 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1595 $user_cur = &$this->user[$i];
1597 if ($user_cur->sess == '')
1599 if ($user_cur->name == $name_new)
1602 if ($i < MAX_PLAYERS) {
1603 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1604 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1608 /* 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>" */
1609 if ($user->flags & USER_FLAG_AUTH) {
1610 if (strcasecmp($user->name,$name_new) != 0) {
1611 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1612 ($user->subst == 'standup' ||
1613 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1616 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1617 for ($i = 0 ; $i < TABLES_N ; $i++) {
1618 $to_user .= $this->table[$i]->act_content($user);
1622 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1627 $user->name = $name_new; // OK - nick changed
1628 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1629 if (($user->flags & USER_FLAG_AUTH) == 0) {
1630 $bdb = new BriskDB();
1632 /* 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>" */
1633 if ($bdb->login_exists($name_new)) {
1634 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1635 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1639 log_main("chatt_send start set");
1641 $update_room = TRUE;
1643 } // nick chat command
1645 else if (strncmp($msg, "/st ", 4) == 0) {
1646 log_main("chatt_send BEGIN");
1649 $st_str = substr($msg, 4);
1651 if (strcasecmp($st_str, "normale") == 0) {
1652 $st = USER_FLAG_S_NORM;
1654 else if (strcasecmp($st_str, "pausa") == 0) {
1655 $st = USER_FLAG_S_PAU;
1657 else if (strcasecmp($st_str, "fuori") == 0) {
1658 $st = USER_FLAG_S_OUT;
1660 else if (strcasecmp($st_str, "cane") == 0) {
1661 $st = USER_FLAG_S_DOG;
1663 else if (strcasecmp($st_str, "cibo") == 0) {
1664 $st = USER_FLAG_S_EAT;
1666 else if (strcasecmp($st_str, "lavoro") == 0) {
1667 $st = USER_FLAG_S_WRK;
1669 else if (strcasecmp($st_str, "sigaretta") == 0) {
1670 $st = USER_FLAG_S_SMK;
1672 else if (strcasecmp($st_str, "presente") == 0) {
1673 $st = USER_FLAG_S_EYE;
1675 else if (strcasecmp($st_str, "coniglio") == 0) {
1676 $st = USER_FLAG_S_RABB;
1678 else if (strcasecmp($st_str, "calcio") == 0) {
1679 $st = USER_FLAG_S_SOCC;
1681 else if (strcasecmp($st_str, "pupo") == 0) {
1682 $st = USER_FLAG_S_BABY;
1684 else if (strcasecmp($st_str, "pulizie") == 0) {
1685 $st = USER_FLAG_S_MOP;
1688 /* MLANG: "Questo stato non esiste." */
1689 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1693 log_main("chatt_send start set");
1694 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1695 $update_room = TRUE;
1696 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1699 } // nick chat command
1701 else { // normal chat line
1702 $is_normchat = TRUE;
1703 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1705 $user->chat_dlt = $user->chat_dlt * 2;
1706 if ($user->chat_dlt > 120)
1707 $user->chat_dlt = 120;
1709 else if ($user->chat_lst == $msg)
1711 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1712 $user->chat_ban = $curtime;
1713 $user->chat_dlt = 5;
1717 $user->chat_ban = 0;
1718 $user->chat_dlt = 0;
1722 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1725 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1726 // temporary silentiation for troll (will became array check)
1727 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1728 $to_room = $to_user;
1731 log_legal($curtime, $user,
1732 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1734 $user->chat_lst = "$msg";
1735 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1745 // Output to clients
1748 if ($to_user != FALSE) {
1749 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1750 $user->comm[$user->step % COMM_N] .= $to_user;
1754 if ($to_room != FALSE) {
1755 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1756 $user_cur = &$this->user[$i];
1757 if ($target != "" && $user_cur->name != $target)
1759 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1760 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1763 if ($is_normchat == TRUE) {
1764 // use MAP_AUTH to check if auth or isolation
1765 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1766 if (($user->flags & USER_FLAG_AUTH) == 0) {
1772 else if ($is_ticker) {
1773 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1774 if ($user->table >= TABLES_AUTH_N)
1779 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1780 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1781 $user_cur->step_inc();
1786 // FIXME BRISK4: include for each kind of table
1787 require_once("${G_base}briskin5/Obj/briskin5.phh");
1788 // Before all align times with table timeout
1789 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1790 $table_cur =& $this->table[$table_idx];
1791 // if the table is complete and exists its shared mem we get the info about users lacc
1793 if ($table_cur->player_n == PLAYERS_N) {
1794 log_main("PLAYERS == N TABLE ".$table_idx);
1796 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1797 log_main("bin5 lock data success");
1799 $no_recovery = FALSE;
1800 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1801 if ($table_cur->table_token != $bri->table_token) {
1802 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1807 if ($bri != FALSE) {
1808 $bri_table = &$bri->table[0];
1809 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1810 // stat must be "table" by definition
1811 $bri_user =& $bri->user[$i];
1813 if ($target != "" && $bri_user->name != $target)
1815 log_main("writa: ".$user_mesg);
1816 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1817 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1818 $bri_user->step_inc();
1820 Briskin5::save_data(&$bri);
1822 Briskin5::unlock_data($sem);
1824 } // if ($table_cur->player_n == PLAYERS_N) {
1825 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1826 } // if ($to_tabl == true ...
1829 if ($user->stat == 'room' && $user->subst == 'standup') {
1830 $this->standup_update(&$user);
1832 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1833 log_main("chatt_send pre table update");
1834 $this->table_update(&$user);
1835 log_main("chatt_send post table update");
1837 } // if ($update_room ...
1840 } // function chatt_send( ...
1842 function &get_user($sess, &$idx)
1844 GLOBAL $PHP_SELF, $G_false;
1846 if (validate_sess($sess)) {
1847 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1848 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1851 $ret = &$this->user[$i];
1855 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1856 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1857 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1860 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1869 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1872 * if ($idx > -1 && ret == FALSE) => duplicated nick
1873 * if ($idx == -2 && ret == FALSE) => invalid name
1874 * if ($idx == -3 && ret == FALSE) => wrong password
1875 * if ($idx == -1 && ret == FALSE) => no space left
1876 * if ($idx == 0 && ret == user) => SUCCESS
1877 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1882 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1884 GLOBAL $G_base, $G_false, $CO_list;
1888 $authenticate = FALSE;
1890 $login_exists = FALSE;
1892 $ghost_auth = FALSE;
1897 if (($name_new = validate_name($name)) == FALSE) {
1902 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1903 if (validate_sess($sess) == FALSE)
1906 /* if pass != FALSE verify the login with pass */
1907 log_auth("XXX", "auth1");
1908 $bdb = new BriskDB();
1910 if ($pass != FALSE) {
1911 log_auth("XXX", "auth2");
1912 $authenticate = $bdb->login_verify($name_new, $pass, $code);
1913 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
1915 if ($authenticate != FALSE) {
1916 $user_type = $authenticate->type_get();
1924 $login_exists = $bdb->login_exists($name_new);
1926 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1928 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1932 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1934 continue; // NOTE: CHECK IT !!
1936 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1937 if ($authenticate != FALSE) {
1939 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1950 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1952 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
1955 $ghost_user =& $this->user[$ghost];
1957 $ghost_user->step_inc();
1960 $ghost_user->sess = $sess;
1963 $ghost_user->sess = $sess;
1966 // If user at the table we need to update the table data too
1967 $table_idx = $ghost_user->table;
1968 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1969 // FIXME BRISK4: include for each kind of table
1970 require_once("${G_base}briskin5/Obj/briskin5.phh");
1971 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1972 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1973 if ($bri->the_end != TRUE) {
1974 $bri->user[$ghost_user->table_pos]->step_inc();
1975 $bri->user[$ghost_user->table_pos]->sess = $sess;
1976 Briskin5::save_data(&$bri);
1979 Briskin5::unlock_data($brisem);
1984 return ($this->user[$ghost]);
1986 else if ($idx != -1 && $i == MAX_PLAYERS) {
1991 $this->user[$idx]->sess = $sess;
1994 $this->user[$idx]->sess = $sess;
1996 $this->user[$idx]->name = $name_new; // OK - add new user
1997 $this->user[$idx]->stat_set("room");
1998 $this->user[$idx]->step_set(0);
1999 while (array_pop($this->user[$idx]->comm) != NULL);
2000 $this->user[$idx]->subst = "standup";
2001 $this->user[$idx]->lacc = $curtime;
2002 $this->user[$idx]->laccwr = $curtime;
2003 $this->user[$idx]->bantime = 0;
2004 $this->user[$idx]->ip = $ip;
2006 $this->user[$idx]->flags = ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00) | $user_type;
2008 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
2011 if ($authenticate != FALSE) {
2012 $this->user[$idx]->code = $authenticate->code_get();
2013 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2015 if (isset($CO_list)) {
2016 if (strcmp($CO_list, "auth") == 0) {
2017 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2018 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2020 if (strcmp($CO_list, "isolation") == 0) {
2021 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2022 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
2025 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2031 log_main("ghost: rename!");
2032 $ghost_user =& $this->user[$ghost];
2034 if ($ghost_auth == FALSE) {
2035 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
2036 $ghostname = 'ghost'.$sfx;
2037 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2038 if (strcmp("", $this->user[$i]->sess) == 0)
2041 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
2046 if ($ghostname != '')
2050 $ghost_user->name = $ghostname;
2052 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
2053 $this->standup_update(&$ghost_user);
2056 log_main("chatt_send pre table update");
2057 $this->table_update(&$ghost_user);
2058 log_main("chatt_send post table update");
2060 } // if ($ghost_auth == FALSE
2062 // FIXME: cacciare il vecchio utente room && table (if needed)
2063 $ghost_user->the_end = TRUE;
2064 $ghost_user->lacc = 0;
2065 $this->garbage_manager(TRUE);
2067 } // if ($ghost > -1) {
2072 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));
2074 $ret = $this->user[$real_idx];
2081 function standup_update(&$user)
2083 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2084 $user_cur = &$this->user[$i];
2085 if ($user_cur->sess == '')
2088 log_main("STANDUP START: ".$user_cur->stat);
2090 if ($user_cur->stat == 'room') {
2091 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
2092 if ($user_cur == $user) {
2093 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
2094 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
2096 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
2097 $itin, xcape($user->name), $itou);
2099 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
2101 $user_cur->step_inc();
2107 function &init_data()
2109 $room =& new Room();
2115 function &load_data()
2117 GLOBAL $G_false, $sess;
2120 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2121 log_main("ftok failed");
2126 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2127 log_main("shmop_open failed");
2131 $shm_sz = SHM_DIMS_MIN;
2133 if ($shm = shm_attach($tok, $shm_sz)) {
2134 $room = @shm_get_var($shm, $tok);
2136 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2138 log_only("bri count ".count($room));
2140 if ($room == FALSE) {
2141 log_only("INIT MAIN DATA");
2143 $room =& Room::init_data();
2144 if (@shm_put_var($shm, $tok, $room) == FALSE) {
2145 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
2146 log_only(serialize($room));
2149 $room->shm_sz = $shm_sz;
2164 function save_data(&$room)
2172 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2175 while ($room->shm_sz < SHM_DIMS_MAX) {
2176 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2179 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2180 if (shm_put_var($shm, $tok, $room) != FALSE) {
2184 if (shm_remove($shm) === FALSE) {
2185 log_only("REMOVE FALLITA");
2189 $room->shm_sz += SHM_DIMS_DLT;
2198 function lock_data()
2202 // echo "LOCK: ".FTOK_PATH."/main";
2204 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2207 // echo "FTOK ".$tok."<br>";
2208 if (($res = sem_get($tok)) == FALSE) {
2211 if (sem_acquire($res)) {
2212 log_lock("LOCK room");
2219 function unlock_data($res)
2223 log_lock("UNLOCK room");
2225 return (sem_release($res));
2229 function standup_content($user)
2234 if ($user->stat != 'room')
2237 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
2238 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2243 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2245 $content = ' j_stand_cont( [ ';
2247 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
2248 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2251 $flags = $this->user[$e]->flags;
2253 if ($this->user[$e]->subst == "standup") {
2254 if ($this->user[$e] == $user)
2259 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
2268 function table_content($user, $table_idx)
2274 // Si possono usare i dati nella classe table
2277 $sess = $user->sess;
2278 $table = &$this->table[$table_idx];
2280 if ($user->stat != 'room')
2284 for ($i = 0 ; $i < $table->player_n ; $i++) {
2285 $user_cur = &$this->user[$table->player[$i]];
2287 $flags = $user_cur->flags;
2289 if ($user_cur == $user)
2292 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2294 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2299 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2306 function make_seed()
2308 list($usec, $sec) = explode(' ', microtime());
2309 return (float) $sec + ((float) $usec * 100000);
2313 function log_mop($step, $log) {
2314 GLOBAL $sess, $PHP_SELF;
2316 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2319 if (isset($sess) == FALSE)
2324 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2327 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2328 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $PHP_SELF, $log));
2334 function log_only2($log) {
2335 GLOBAL $sess, $PHP_SELF;
2337 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2340 if (isset($sess) == FALSE)
2345 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2348 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2349 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2354 function log_crit($log) {
2355 GLOBAL $sess, $PHP_SELF;
2357 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2360 if (isset($sess) == FALSE)
2365 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2368 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2369 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2374 function log_only($log) {
2375 GLOBAL $sess, $PHP_SELF;
2377 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2380 if (isset($sess) == FALSE)
2385 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2388 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2389 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2394 function log_main($log) {
2395 GLOBAL $sess, $PHP_SELF;
2397 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2400 if (isset($sess) == FALSE)
2405 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2408 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2409 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2414 function log_rd($log) {
2415 GLOBAL $sess, $PHP_SELF;
2417 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2420 if (isset($sess) == FALSE)
2425 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2428 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2429 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2434 function log_rd2($log) {
2435 GLOBAL $sess, $PHP_SELF;
2437 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2440 if (isset($sess) == FALSE)
2445 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2448 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2449 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2454 function log_send($log) {
2455 GLOBAL $sess, $PHP_SELF;
2457 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2460 if (isset($sess) == FALSE)
2465 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2468 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2469 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2474 function log_lock($log) {
2475 GLOBAL $sess, $PHP_SELF;
2477 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2480 if (isset($sess) == FALSE)
2485 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2488 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2489 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2494 function log_wr($log) {
2495 GLOBAL $sess, $PHP_SELF;
2497 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2500 if (isset($sess) == FALSE)
2505 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2508 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2509 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2514 function log_load($log) {
2515 GLOBAL $sess, $PHP_SELF;
2517 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2520 if (isset($sess) == FALSE)
2525 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2528 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2529 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $PHP_SELF, $log));
2534 function log_auth($sess, $log) {
2536 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2539 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2542 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2543 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s] [%s]\n", $sess, time(), $PHP_SELF, $log));
2549 // function log_legal($curtime, $sess, $name, $where, $mesg)
2550 function log_legal($curtime, &$user, $where, $mesg)
2554 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2555 /* Unix time | session | nickname | IP | where was | mesg */
2556 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2557 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2558 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2564 function lock_banlist()
2566 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2570 if (($res = sem_get($tok)) == FALSE) {
2571 echo "SEM_GET FAILED";
2574 if (sem_acquire($res))
2580 function unlock_banlist($res)
2582 return (sem_release($res));
2585 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2590 if ($sitted < PLAYERS_N) {
2598 if ($table == $cur_table)
2605 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2610 function show_notify($text, $tout, $butt, $w, $h)
2612 log_main("SHOW_NOTIFY: ".$text);
2613 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2616 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
2618 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2619 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);
2623 function root_wellcome($user)
2625 GLOBAL $root_wellarr, $G_lang;
2629 $dt = date("H:i ", $curtime);
2631 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2632 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2639 function validate_sess($sess)
2641 if (strlen($sess) == SESS_LEN)
2647 function validate_name($name)
2649 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2651 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2653 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2660 function playsound($filename)
2662 return (sprintf('playsound("flasou", "%s");', $filename));
2665 function secstoword($secs)
2669 $mins = floor($secs / 60);
2671 if ($G_lang == 'en') {
2673 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
2676 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
2680 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2683 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2688 function sharedmem_sz($tok)
2690 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2691 log_main("shmop_open failed");
2694 $shm_sz = shmop_size($shm_id);
2695 shmop_close($shm_id);
2697 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2702 function lock_data()
2706 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2709 // echo "FTOK ".$tok."<br>";
2710 if (($res = sem_get($tok)) == FALSE) {
2713 if (sem_acquire($res)) {
2714 log_lock("LOCK warrant");
2721 function unlock_data($res)
2725 log_lock("UNLOCK warrant");
2727 return (sem_release($res));
2732 function lock_data()
2736 if (($tok = @ftok(FTOK_PATH."/poll", "B")) == -1) {
2739 // echo "FTOK ".$tok."<br>";
2740 if (($res = sem_get($tok)) == FALSE) {
2743 if (sem_acquire($res)) {
2744 log_lock("LOCK poll");
2751 function unlock_data($res)
2755 log_lock("UNLOCK poll");
2757 return (sem_release($res));