5 * Copyright (C) 2006-2009 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>");
56 define(DBG_ONL2, 0x0001);
57 define(DBG_ONLY, 0x0002);
58 define(DBG_MAIN, 0x0004);
59 define(DBG_READ, 0x0008);
60 define(DBG_REA2, 0x0010);
61 define(DBG_SEND, 0x0020);
62 define(DBG_LOCK, 0x0040);
63 define(DBG_WRIT, 0x0080);
64 define(DBG_LOAD, 0x0100);
65 define(DBG_AUTH, 0x0200);
66 define(DBG_CRIT, 0x0400);
68 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
69 define(BRISK_DEBUG, 0xffffffbf);
71 define(BRISK_SINGLE_DEBUG,0);
72 define(BRISK_SINGLE_SESS, "");
73 // define(DEBUGGING, "local");
75 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
77 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
78 'en' => 'back standing' ),
79 'btn_close' => array( 'it' => 'chiudi',
82 'tit_all' => array( 'it' => 'tutti',
85 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
86 'en' => '<br>You are being idle for ' ),
87 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
88 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
89 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
90 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
91 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
92 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
93 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
94 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
95 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
96 'en' => '<br>The entered password is not correct.<br><br>'),
97 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
98 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
99 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
100 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
101 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
102 'en' => '<b>To send a message you have to be authenticated.</b>'),
103 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
104 'en' => 'The nickname have to contain at least one letter or one number.'),
105 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
106 'en' => 'The nickname <b>%s</b> is already in use.'),
107 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>',
108 'en' => '<b>You can\'t change your nickname into a table for only authenticated.</b>'),
109 '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>',
110 '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 ???
111 'statunkn' => array( 'it' => 'Questo stato non esiste.',
112 'en' => 'This state don\'t exists.'),
113 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
114 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
115 'tit_onauth'=>array( 'it' => '(solo aut.)',
116 'en' => '(only aut.)'),
122 $G_lng = langtolng($G_lang);
124 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
125 $G_brisk_version = "2.2.0 - trusty";
127 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
128 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: bug della carta coperta risolto, assenso all\'apertura del tavolo non revocabile, multi-lingua quasi ultimato.',
129 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' ),
130 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: Multi-language support',
131 'If you want to subscribe our <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, click it!' ) );
133 $G_room_help = array( 'it' => '
134 <div style=\\"text-align: left; padding: 8px;\\">
135 <b>Descrizione</b><br>
136 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
137 <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>
138 <b>Configurazione del browser.</b><br>
139 Occorre abilitare i cookies.<br>
141 <b>Uso del sito</b><br>
142 Potete sedervi a un tavolo o rimanere in piedi.<br>
143 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
146 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>
147 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
148 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
149 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
150 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
151 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.
153 <dt><b>Comandi della chat</b>
154 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
155 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
156 <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\\"
157 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
158 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
159 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
165 <div style=\\"text-align: left; padding: 8px;\\">
166 <b>EN Descrizione</b><br>
167 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
168 <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>
169 <b>EN Configurazione del browser.</b><br>
170 Occorre abilitare i cookies.<br>
172 <b>Uso del sito</b><br>
173 Potete sedervi a un tavolo o rimanere in piedi.<br>
174 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
177 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>
178 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
179 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
180 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
181 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
182 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.
184 <dt><b>Comandi della chat</b>
185 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
186 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
187 <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\\"
188 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
189 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
190 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
196 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
197 <div style=\\"text-align: left; padding: 8px;\\">
198 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
200 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
201 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
203 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
204 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
207 <b>Per auto-garantisi occorre possedere:</b><br><br>
209 <li>il codice PIN della propria carta
210 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
213 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
215 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
218 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
219 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
224 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
225 <div style=\\"text-align: left; padding: 8px;\\">
226 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
228 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
229 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
231 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
232 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
235 <b>Per auto-garantisi occorre possedere:</b><br><br>
237 <li>il codice PIN della propria carta
238 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
241 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
243 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
246 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
247 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
253 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
257 $G_room_about = array( 'it' => '<br>
258 <div id=\\"header\\" class=\\"header\\">
259 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
260 briscola chiamata in salsa ajax
262 <br><b>version '.$G_brisk_version.'</b><br><br>
263 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
265 <div id=\\"header\\" class=\\"header\\">
266 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
267 declaration briscola in ajax sauce <b>(Beta)</b>
269 <br><b>version '.$G_brisk_version.'</b><br><br>
270 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
273 function langtolng($lang)
277 return ($G_lang == 'en' ? '-en' : '');
280 function csplitter($in, $sep)
286 for ($i = 0 ; $i < strlen($in) ; $i++) {
290 else if ($in{$i} == $sep) {
294 $out[$id] .= $in{$i};
298 $out[$id] .= $in{$i};
309 $from = array ( '\\', '@', '|' );
310 $to = array ( '\\\\', '@', '¦' );
312 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
317 $from = array ( '\\', '|', "\t", "\n");
318 $to = array ( '\\\\', '\\|', "\\t", "\\n");
320 return (str_replace($from, $to, $s));
323 function xcapemesg($s)
325 $from = array ( "\n");
326 $to = array ( "\\n");
328 return (str_replace($from, $to, $s));
337 var $auth_only; // se tavolo riservato o libero
344 var $table_start; // information field
352 function &create($idx)
356 if (($thiz =& new Table()) == FALSE)
360 $thiz->player = array();
362 $thiz->auth_only = FALSE;
364 $thiz->wag_own = NULL;
368 $thiz->table_token = "";
369 $thiz->table_start = 0;
371 $thiz->wakeup_time = 0;
376 function copy(&$from)
380 $this->idx = $from->idx;
381 $this->player = array();
382 for ($i = 0 ; $i < $from->player_n ; $i++)
383 $this->player[$i] = $from->player[$i];
384 $this->player_n = $from->player_n;
386 log_main("PLAYER_N - parent::copy.".$this->player_n);
388 $this->auth_only = $from->auth_only;
390 $this->wag_own = $from->wag_own;
391 $this->wag_com = $from->wag_com;
392 $this->wag_tout = $from->wag_tout;
394 $this->table_token = $from->table_token;
395 $this->table_start = $from->table_start;
397 $this->wakeup_time = $from->wakeup_time;
400 function &clone(&$from)
404 if (($thiz =& new Table()) == FALSE)
412 function &spawn(&$from)
416 if (($thiz =& new Table()) == FALSE)
419 $thiz->idx = $from->idx;
420 $thiz->player = array();
421 for ($i = 0 ; $i < $from->player_n ; $i++)
422 $thiz->player[$i] = $i;
423 $thiz->player_n = $from->player_n;
425 $thiz->auth_only = $from->auth_only;
427 $thiz->wag_own = $from->wag_own;
428 $thiz->wag_com = $from->wag_com;
429 $thiz->wag_tout = $from->wag_tout;
431 $thiz->table_token = $from->table_token;
432 $thiz->table_start = $from->table_start;
434 $thiz->wakeup_time = $from->wakeup_time;
439 function wag_set(&$user, $mesg)
443 $this->wag_own = &$user;
444 $this->wag_com = $mesg;
448 function wag_reset($timeout)
450 log_main("WAG_RESET");
452 unset($this->wag_own);
453 $this->wag_own = NULL;
455 $this->wag_tout = $timeout;
458 function getPlayer($idx)
460 return ($this->player[$idx]);
463 function setPlayer($idx, $player)
465 $this->player[$idx] = $player;
468 function user_add($idx)
470 $this->player[$this->player_n] = $idx;
473 return ($this->player_n - 1);
476 function user_rem(&$room, &$user)
478 $tabpos = $user->table_pos;
480 /* verifico la consistenza dei dati */
481 if ($room->user[$this->player[$tabpos]] == $user) {
483 /* aggiorna l'array dei giocatori al tavolo. */
484 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
485 $this->player[$i] = $this->player[$i+1];
486 $user_cur = &$room->user[$this->player[$i]];
487 $user_cur->table_pos = $i;
492 log_main("INCONSISTENCY ON TABLE.");
498 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
499 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
501 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
502 function act_content(&$user)
505 $isstanding = ($user->subst == 'standup');
506 $sitted = $this->player_n;
508 $cur_table = $user->table;
512 if ($sitted < PLAYERS_N) {
513 if ($this->auth_only) {
514 if ($user->flags & USER_FLAG_AUTH)
528 if ($table == $cur_table)
535 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
543 define(USER_FLAG_AUTH, 0x02);
544 define(USER_FLAG_LISTAUTH, 0x04);
547 define(USER_FLAG_S_NORM, 0x000); // done
548 define(USER_FLAG_S_PAU, 0x100); // done
549 define(USER_FLAG_S_OUT, 0x200); // done
550 define(USER_FLAG_S_DOG, 0x300); // done
551 define(USER_FLAG_S_EAT, 0x400); // done
552 define(USER_FLAG_S_WRK, 0x500); // done
553 define(USER_FLAG_S_SMK, 0x600); // done
554 define(USER_FLAG_S_EYE, 0x700); // done
556 define(USER_FLAG_S_ALL, 0xf00); // done
559 var $name; // name of the user
560 var $sess; // session of the user
561 var $ip; // ip of the user
562 var $lacc; // last access (for the cleanup)
563 var $laccwr; // last access (for the cleanup)
564 var $bantime; // timeout to temporary ban
565 var $stat; // status (outdoor, room, table, game, ...)
566 var $subst; // substatus for each status
567 var $step; // step of the current status
568 var $trans_step; // step to enable transition between pages (disable == -1)
569 var $comm; // commands array
570 // var $asta_card; //
572 // var $handpt; // Total card points at the beginning of the current hand.
573 // var $exitislock; // Player can exit from the table ?
575 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
576 // it is allways ZERO
577 var $table_orig; // id of the current table (if in table state)
578 var $table; // id of the current table (if in table state)
579 var $table_pos; // idx on the table
580 var $table_token;// token that identify a game on a table
581 var $flags; // Bitfield with: AUTHENTICATE: 0x02
582 var $the_end; // Flag to change the end of the session
584 var $chat_lst; // Last chat line
585 var $chattime; // Array of chat times
586 var $chat_cur; // Current chat line number
587 var $chat_ban; // Time for ban chat
588 var $chat_dlt; // Delta t for ban
592 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
595 if (($thiz =& new User()) == FALSE)
601 $thiz->lacc = time();
602 $thiz->laccwr = time();
605 $thiz->subst = $subst;
607 $thiz->trans_step = -1;
608 $thiz->comm = array();
609 $thiz->asta_card = -2;
610 $thiz->asta_pnt = -1;
612 $thiz->exitislock = TRUE;
616 $thiz->chattime = array_fill(0, CHAT_N, 0);
618 $thiz->chat_lst = "";
622 $thiz->table_orig = $table;
623 $thiz->table = $table;
624 $thiz->table_pos = -1;
625 $thiz->table_token = "";
630 function copy(&$from)
634 $this->name = $from->name;
635 $this->sess = $from->sess;
636 $this->ip = $from->ip;
637 $this->lacc = $from->lacc;
638 $this->laccwr = $from->laccwr;
639 $this->bantime = $from->bantime;
640 $this->stat = $from->stat;
641 $this->subst = $from->subst;
642 $this->step = $from->step;
643 $this->trans_step = $from->trans_step;
644 $this->comm = array();
646 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
647 for ($i = $i_start ; $i < $from->step ; $i++) {
649 $this->comm[$ii] = $from->comm[$ii];
651 $this->asta_card = $from->asta_card;
652 $this->asta_pnt = $from->asta_pnt;
653 $this->handpt = $from->handpt;
654 $this->exitislock = $from->exitislock;
656 $this->flags = $from->flags;
658 $this->chattime = array();
659 for ($i = 0 ; $i < CHAT_N ; $i++)
660 $this->chattime[$i] = $from->chattime[$i];
661 $this->chat_cur = $from->chat_cur;
662 $this->chat_lst = $from->chat_lst;
663 $this->chat_ban = $from->chat_ban;
664 $this->chat_dlt = $from->chat_dlt;
666 $this->table_orig = $from->table_orig;
667 $this->table = $from->table;
668 $this->table_pos = $from->table_pos;
669 $this->table_token = $from->table_token;
670 $this->the_end = $from->the_end;
676 function &clone(&$from)
680 if (($thiz =& new User()) == FALSE)
688 function &spawn(&$from, $table, $table_pos)
692 if (($thiz =& new User()) == FALSE)
695 $thiz->name = $from->name;
696 $thiz->sess = $from->sess;
697 $thiz->ip = $from->ip;
698 $thiz->lacc = $from->lacc;
699 $thiz->laccwr = $from->laccwr;
700 $thiz->bantime = $from->bantime;
701 $thiz->stat = $from->stat;
702 $thiz->subst = $from->subst;
703 $thiz->step = $from->step;
704 $thiz->trans_step = $from->trans_step;
705 $thiz->comm = array();
708 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
709 for ($i = $i_start ; $i < $from->step ; $i++) {
710 log_wr("TRY PUSH:".$i);
712 $thiz->comm[$ii] = $from->comm[$ii];
715 $thiz->asta_card = $from->asta_card;
716 $thiz->asta_pnt = $from->asta_pnt;
717 $thiz->handpt = $from->handpt;
718 $thiz->exitislock = $from->exitislock;
719 $thiz->the_end = $from->the_end;
721 $thiz->flags = $from->flags;
723 $thiz->chattime = array_fill(0, CHAT_N, 0);
725 $thiz->chat_lst = "";
730 $thiz->table_orig = $table;
732 $thiz->table_pos = $table_pos;
733 $thiz->table_token = $from->table_token;
738 function stat_set($stat) {
739 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
740 $this->stat = "$stat";
743 if (validate_sess($this->sess)) {
744 if (file_exists(PROXY_PATH) == FALSE)
746 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
747 fwrite($fp, sprintf("%s\n",$this->stat));
753 function step_set($step) {
757 if (validate_sess($this->sess) == FALSE)
759 if (file_exists(PROXY_PATH) == FALSE)
761 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
763 fwrite($fp, pack("l",$this->step), 4);
772 function step_inc($delta = 1) {
773 $this->step += $delta;
775 if (validate_sess($this->sess)) {
776 if (file_exists(PROXY_PATH) == FALSE)
778 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
779 fwrite($fp, pack("l",$this->step), 4);
790 log_legal($curtime, $this, "STAT:LOGOUT", '');
792 $tmp_sess = $this->sess;
794 step_unproxy($tmp_sess);
795 $this->name = ""; // OK here
796 while (array_pop($this->comm) != NULL);
798 $this->chattime = array_fill(0, CHAT_N, 0);
800 $this->chat_lst = "";
803 $this->the_end = FALSE;
813 function step_get($sess) {
816 if (validate_sess($sess) == FALSE)
819 if (file_exists(PROXY_PATH) == FALSE)
821 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
823 if (($s = fread($fp, 4)) == FALSE)
827 $arr = unpack('l', $s);
830 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
837 log_rd2("STEP_GET: return false ");
842 function step_unproxy($sess) {
843 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
844 if (file_exists(PROXY_PATH) == FALSE)
846 @unlink(PROXY_PATH."/".$sess.".step");
853 var $comm; // commands for many people
854 var $step; // current step of the comm array
855 var $garbage_timeout;
859 $this->user = array();
860 $this->table = array();
862 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
863 $this->user[$i] =& User::create("", "");
866 for ($i = 0 ; $i < TABLES_N ; $i++) {
867 $this->table[$i] =& Table::create($i);
870 $row = ( (((int)($i / 4)) % 2) == 0 );
871 $col = ($i % 2 == 0);
872 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
875 $this->table[$i]->auth_only = FALSE;
878 if ($i < TABLES_AUTH_N)
879 $this->table[$i]->auth_only = TRUE;
881 $this->table[$i]->auth_only = FALSE;
883 $this->garbage_timeout = 0;
886 function garbage_manager($force)
888 GLOBAL $G_lang, $mlang_brisk;
892 log_rd2("garbage_manager START");
894 /* Garbage collector degli utenti in timeout */
896 if ($force || $this->garbage_timeout < $curtime) {
898 // FIXME BRISK4: include for each kind of table
899 require_once("briskin5/Obj/briskin5.phh");
901 // Before all align times with table timeout
902 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
903 $table_cur =& $this->table[$table_idx];
904 // if the table is complete and exists its shared mem we get the info about users lacc
906 if ($table_cur->player_n == PLAYERS_N) {
907 log_main("PLAYERS == N TABLE ".$table_idx);
909 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
910 log_main("bin5 lock data success");
912 $no_recovery = FALSE;
913 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
914 if ($table_cur->table_token != $bri->table_token) {
915 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
916 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
926 log_main("garbage_manager: bri loaded successfully.");
927 $bri->garbage_manager(TRUE);
929 $bri_table = &$bri->table[0];
931 // is the end of the table
932 if ($bri->the_end == TRUE) {
934 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
936 log_main("garbage_manager: INSIDE THE END.");
938 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
939 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
940 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
943 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
944 // stat must be "table" by definition
945 $user_cur =& $this->user[$table_cur->player[$i]];
946 $bri_user =& $bri->user[$i];
948 $user_cur->subst = $bri_user->subst;
949 $user_cur->step = $bri_user->step;
950 $user_cur->lacc = $bri_user->lacc;
951 $user_cur->laccwr = $bri_user->lacc;
952 $user_cur->bantime = $bri_user->bantime;
955 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
957 $this->room_join_wakeup(&$user_cur, FALSE, 0);
958 $table_cur->table_token = "";
959 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
960 Briskin5::destroy_data($table_idx);
963 log_main("gm:: save_data");
965 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
966 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
969 Briskin5::save_data(&$bri);
971 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
972 else if ($no_recovery == FALSE) {
973 log_crit("ERROR: table ".$table_idx." unrecoverable join");
975 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
976 $user_cur = &$this->user[$table_cur->player[$i]];
977 $user_cur->subst = "shutdowner";
978 $user_cur->step_inc();
980 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
981 $ret .= "gst.st = ".($user_cur->step+1)."; ";
982 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
983 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
984 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
985 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
986 $user_cur->step_inc();
989 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
990 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
991 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
993 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
995 $this->room_join_wakeup(&$user_cur, TRUE, -2);
996 $table_cur->table_token = "";
999 Briskin5::unlock_data($sem);
1001 } // if ($table_cur->player_n == PLAYERS_N) {
1002 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1004 log_rd2("out new loop.");
1006 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1007 $user_cur = &$this->user[$i];
1009 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1011 if ($user_cur->sess == "")
1014 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1015 // Auto logout dell'utente
1016 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1018 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1019 log_auth($user_cur->sess, "Autologout session.");
1023 log_rd2("AUTO LOGOUT.");
1024 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1025 $this->room_wakeup(&$user_cur);
1026 else if ($user_cur->subst == 'standup')
1027 $this->room_outstandup(&$user_cur);
1029 log_rd2("LOGOUT FROM WHAT ???");
1033 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1034 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1035 $this->room_wakeup(&$user_cur);
1036 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1037 /* 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" */
1038 $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);
1039 $user_cur->step_inc();
1043 log_rd2("GARBAGE UPDATED!");
1045 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1052 function show_room($user_step, &$user)
1054 GLOBAL $G_lang, $mlang_brisk;
1055 log_main("show_room: username: ".$user->name);
1057 $ret = sprintf('gst.st = %d; ', $user_step);
1059 if ($user->flags & USER_FLAG_LISTAUTH) {
1060 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1063 $ret .= 'list_set(\'all\', false, \'\' ); ';
1066 if ($user->subst == 'standup')
1067 $ret .= "tra.show(); ";
1069 $ret .= "tra.hide(); ";
1071 $ret .= sprintf('stat = "%s";', $user->stat);
1073 $ret .= root_wellcome($user);
1074 $ret .= sprintf('subst = "%s";', $user->subst);
1075 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1076 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1077 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1078 for ($i = 0 ; $i < TABLES_N ; $i++) {
1079 $ret .= $this->table_content($user, $i);
1080 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1081 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1082 $ret .= $this->table[$i]->act_content($user);
1083 if ($this->table[$i]->wag_own != NULL)
1084 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
1086 $ret .= sprintf('tra.rem(%d); ', $i);
1088 $ret .= $this->standup_content($user);
1094 function room_wakeup(&$user)
1096 $table_idx = $user->table;
1097 $table = &$this->table[$table_idx];
1099 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1103 $from_table = ($user->stat == "table");
1105 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1107 for ($i = 0 ; $i < $table->player_n ; $i++) {
1108 $user_cur = &$this->user[$table->player[$i]];
1109 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1111 if ($user_cur != $user) {
1112 $user_cur->stat_set("room");
1113 $user_cur->subst = "sitdown";
1114 $user_cur->laccwr = $curtime;
1116 else if ($user->sess != "") {
1117 $user_cur->stat_set("room");
1118 $user_cur->subst = "standup";
1119 $user_cur->laccwr = $curtime;
1120 $user_cur->table = -1;
1125 $user->stat_set("room");
1126 $user->subst = "standup";
1127 $user->laccwr = $curtime;
1130 $remove_wagon = false;
1131 if($table->wag_own == $user) {
1132 $remove_wagon = true;
1133 $table->wag_reset($curtime);
1138 /* aggiorna l'array dei giocatori al tavolo. */
1139 $table->user_rem(&$this, &$user);
1141 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1142 $user_cur = &$this->user[$i];
1143 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1146 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1148 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1149 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
1150 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1151 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1152 log_main("DOCUMENT.index.php: from table");
1154 else if ($user_cur->stat == "room") {
1155 log_main("DOCUMENT.index.php: from table");
1157 $ret .= $this->table_content($user_cur, $table_idx);
1158 $ret .= $this->standup_content($user_cur);
1160 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1161 $ret .= $table->act_content($user);
1163 if ($user_cur == $user) {
1164 // set the new status
1165 $ret .= 'subst = "standup"; tra.show(); ';
1166 // clean the action buttons in other tables
1167 for ($e = 0 ; $e < TABLES_N ; $e++) {
1168 if ($this->table[$e]->player_n < PLAYERS_N) {
1169 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1170 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1171 $ret .= $this->table[$e]->act_content($user);
1176 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1177 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1178 $ret .= $table->act_content($user_cur);
1181 log_wr("ROOM_WAKEUP: ".$ret);
1182 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1183 $user_cur->step_inc();
1187 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1189 $table_idx = $user->table;
1190 $table = &$this->table[$table_idx];
1192 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1195 $user_wup = array();
1197 $user_tab = array();
1199 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1201 for ($i = 0 ; $i < $table->player_n ; $i++) {
1202 $user_cur = &$this->user[$table->player[$i]];
1203 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1204 if ($user_cur->sess != "") {
1205 if ($update_lacc == TRUE) {
1206 $user_cur->laccwr = $curtime;
1208 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1209 if ($user_cur->subst == "shutdowned") {
1210 $user_cur->stat_set("room");
1211 $user_cur->subst = "sitdown";
1213 else if ($user_cur->subst == "shutdowner") {
1214 $user_cur->stat_set("room");
1215 $user_cur->subst = "standup";
1216 $user_cur->table = -1;
1217 $user_wup[$user_wup_n++] = &$user_cur;
1219 $remove_wagon = false;
1220 if($table->wag_own == $user_cur) {
1221 $remove_wagon = true;
1222 $table->wag_reset($curtime);
1225 $user_tab[$user_tab_n++] = &$user_cur;
1229 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1230 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1232 /* aggiorna l'array dei giocatori al tavolo. */
1234 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1235 log_main("START LOOP");
1236 $user_cur = &$this->user[$i];
1237 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1238 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1243 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1245 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1246 if ($user_cur->stat == "room") {
1247 log_main("DOCUMENT.index.php from table");
1249 $ret .= $this->table_content($user_cur, $table_idx);
1250 $ret .= $this->standup_content($user_cur);
1252 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1253 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1254 $ret .= $table->act_content($user_cur);
1257 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1258 if ($user_cur == $user_tab[$tab_idx])
1261 // for users that wakeup the room will be reconstructed by index_rd.php
1262 if ($tab_idx < $user_tab_n) {
1263 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1265 // ARRAY_POP DISABLED
1266 // if ($trans_delta == 0)
1267 // while (array_pop($user_cur->comm) != NULL);
1269 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1270 $user_cur->comm[$user_cur->step % COMM_N] = "";
1271 $user_cur->step_inc();
1272 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1273 $user_cur->step_inc();
1274 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1278 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1280 log_main("JOIN_WAKEUP more");
1281 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1282 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1283 $ret .= $table->act_content($user_cur);
1285 log_main("JOIN_WAKEUP end more");
1287 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1288 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1289 $user_cur->step_inc();
1293 function room_outstandup(&$user)
1295 $this->room_sitdown(&$user, -1);
1298 function table_update(&$user)
1300 log_main("table_update: pre - USER: ".$user->name);
1302 $table_idx = $user->table;
1304 if ($table_idx > -1)
1305 $table = &$this->table[$table_idx];
1307 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1309 $user_cur = &$this->user[$i];
1310 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1313 $ret = "gst.st = ".($user_cur->step+1)."; ";
1314 if ($table_idx > -1)
1315 $ret .= $this->table_content($user_cur, $table_idx);
1317 if ($user_cur == $user) {
1318 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1319 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1320 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1322 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1323 $user_cur->step_inc();
1326 log_main("table_update: post");
1329 function room_sitdown(&$user, $table_idx)
1331 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1335 if ($table_idx > -1 && $table_idx < TABLES_N) {
1336 $table = &$this->table[$table_idx];
1339 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1340 for ($i = 0 ; $i < TABLES_N ; $i++) {
1341 $user_cur =& $this->user[$table->player[$i]];
1342 if ($user_cur == $table->wag_own) {
1343 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1344 $table->wag_reset(time());
1351 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1353 $user_cur = &$this->user[$i];
1354 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1357 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1358 if ($table_idx > -1)
1359 $ret .= $this->table_content($user_cur, $table_idx);
1360 $ret .= $this->standup_content($user_cur);
1362 if ($user_cur == $user) {
1363 $ret .= 'subst = "sitdown"; tra.hide(); ';
1364 // clean the action buttons in other tables
1365 for ($e = 0 ; $e < TABLES_N ; $e++) {
1366 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1367 $ret .= $this->table[$e]->act_content($user_cur);
1370 else if ($table_idx > -1) {
1371 if ($table->player_n == PLAYERS_N) {
1372 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1373 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1374 $ret .= $table->act_content($user_cur);
1377 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1378 $user_cur->step_inc();
1382 function chatt_send(&$user, $mesg)
1384 GLOBAL $G_alarm_passwd, $mlang_brisk, $G_lang;
1388 $msg = substr($mesg, 6, 128);
1390 $dt = date("H:i ", $curtime);
1400 $is_normchat = FALSE;
1401 $update_room = FALSE;
1403 if (strcmp($msg, "/tav") == 0 ||
1404 strncmp($msg, "/tav ", 5) == 0) {
1406 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1407 /* 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>" */
1408 $msg = $mlang_brisk['tickmust'][$G_lang];
1409 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1414 $table = &$this->table[$user->table];
1416 if ($table->wag_own != NULL) {
1417 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1418 $msg = $mlang_brisk['tickjust'][$G_lang];
1419 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1424 $dtime = $curtime - $table->wag_tout;
1425 if ($dtime < EXPIRE_TIME_WAG) {
1426 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1427 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1428 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1429 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1434 $msg = substr($msg, 5);
1436 $table->wag_set($user, $msg);
1437 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1438 $to_room = $to_user;
1441 } // /tav chat command
1443 else if (strncmp($msg, "/alarm ", 7) == 0) {
1444 if (strncmp($msg, "/alarm to ", 10) == 0) {
1445 $sp_pos = strpos($msg, " ", 10);
1446 $target = substr($msg, 10, $sp_pos - 10);
1447 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1451 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1454 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1455 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1456 $msg = $mlang_brisk['alarpass'][$G_lang];
1457 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1462 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1463 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1464 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1465 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1466 $dt, NICKSERV, $prestr);
1468 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1469 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1470 /* MLANG: "chiudi" */
1471 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1473 } // /alarm chat command
1474 else if (strncmp($msg, "/listen ", 8) == 0) {
1475 $arg = substr($msg, 8);
1477 if (strcasecmp($arg, "auth") == 0) {
1478 $user->flags |= USER_FLAG_LISTAUTH;
1479 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1482 $user->flags &= ~USER_FLAG_LISTAUTH;
1483 $to_user = 'list_set(\'all\', true, \'\'); ';
1486 else if (strcmp($msg, "/authreq") == 0) {
1487 if ($user->flags & USER_FLAG_AUTH) {
1488 $to_user = sprintf('authbox(300,200);');
1491 /* 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." */
1492 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1495 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1496 if ($user->flags & USER_FLAG_AUTH) {
1497 $to_user = sprintf('mesgtoadmbox(500,300);');
1500 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1501 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1504 else if (strncmp($msg, "/nick ", 6) == 0) {
1505 log_main("chatt_send BEGIN");
1508 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1509 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1513 $msg = "COMMAND ".$msg;
1514 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1515 $user_cur = &$this->user[$i];
1517 if ($user_cur->sess == '')
1519 if ($user_cur->name == $name_new)
1522 if ($i < MAX_PLAYERS) {
1523 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1524 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1528 /* 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>" */
1529 if ($user->flags & USER_FLAG_AUTH) {
1530 if (strcasecmp($user->name,$name_new) != 0) {
1531 if ($user->subst == 'standup' || ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)) {
1532 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1533 for ($i = 0 ; $i < TABLES_N ; $i++) {
1534 $to_user .= $this->table[$i]->act_content($user);
1538 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1543 $user->name = $name_new; // OK - nick changed
1544 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1545 if (($user->flags & USER_FLAG_AUTH) == 0) {
1546 $userdb = new LoginDB();
1547 /* 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>" */
1548 if ($userdb->login_exists($name_new)) {
1549 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1550 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1554 log_main("chatt_send start set");
1556 $update_room = TRUE;
1558 } // nick chat command
1560 else if (strncmp($msg, "/st ", 4) == 0) {
1561 log_main("chatt_send BEGIN");
1564 $st_str = substr($msg, 4);
1566 if (strcasecmp($st_str, "normale") == 0) {
1567 $st = USER_FLAG_S_NORM;
1569 else if (strcasecmp($st_str, "pausa") == 0) {
1570 $st = USER_FLAG_S_PAU;
1572 else if (strcasecmp($st_str, "fuori") == 0) {
1573 $st = USER_FLAG_S_OUT;
1575 else if (strcasecmp($st_str, "cane") == 0) {
1576 $st = USER_FLAG_S_DOG;
1578 else if (strcasecmp($st_str, "cibo") == 0) {
1579 $st = USER_FLAG_S_EAT;
1581 else if (strcasecmp($st_str, "lavoro") == 0) {
1582 $st = USER_FLAG_S_WRK;
1584 else if (strcasecmp($st_str, "sigaretta") == 0) {
1585 $st = USER_FLAG_S_SMK;
1587 else if (strcasecmp($st_str, "presente") == 0) {
1588 $st = USER_FLAG_S_EYE;
1591 /* MLANG: "Questo stato non esiste." */
1592 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1596 log_main("chatt_send start set");
1597 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1598 $update_room = TRUE;
1599 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1602 } // nick chat command
1604 else { // normal chat line
1605 $is_normchat = TRUE;
1606 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1608 $user->chat_dlt = $user->chat_dlt * 2;
1609 if ($user->chat_dlt > 120)
1610 $user->chat_dlt = 120;
1612 else if ($user->chat_lst == $msg)
1614 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1615 $user->chat_ban = $curtime;
1616 $user->chat_dlt = 5;
1620 $user->chat_ban = 0;
1621 $user->chat_dlt = 0;
1625 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1628 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1629 // temporary silentiation for troll (will became array check)
1630 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1631 $to_room = $to_user;
1634 log_legal($curtime, $user,
1635 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1637 $user->chat_lst = "$msg";
1638 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1648 // Output to clients
1651 if ($to_user != FALSE) {
1652 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1653 $user->comm[$user->step % COMM_N] .= $to_user;
1657 if ($to_room != FALSE) {
1658 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1659 $user_cur = &$this->user[$i];
1660 if ($target != "" && $user_cur->name != $target)
1662 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1663 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1666 if ($is_normchat == TRUE) {
1667 if ($user_cur->flags & USER_FLAG_LISTAUTH) {
1668 if (($user->flags & USER_FLAG_AUTH) == 0) {
1674 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1675 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1676 $user_cur->step_inc();
1681 // FIXME BRISK4: include for each kind of table
1682 require_once("briskin5/Obj/briskin5.phh");
1683 // Before all align times with table timeout
1684 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1685 $table_cur =& $this->table[$table_idx];
1686 // if the table is complete and exists its shared mem we get the info about users lacc
1688 if ($table_cur->player_n == PLAYERS_N) {
1689 log_main("PLAYERS == N TABLE ".$table_idx);
1691 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1692 log_main("bin5 lock data success");
1694 $no_recovery = FALSE;
1695 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1696 if ($table_cur->table_token != $bri->table_token) {
1697 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1702 if ($bri != FALSE) {
1703 $bri_table = &$bri->table[0];
1704 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1705 // stat must be "table" by definition
1706 $bri_user =& $bri->user[$i];
1708 if ($target != "" && $bri_user->name != $target)
1710 log_main("writa: ".$user_mesg);
1711 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1712 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1713 $bri_user->step_inc();
1715 Briskin5::save_data(&$bri);
1717 Briskin5::unlock_data($sem);
1719 } // if ($table_cur->player_n == PLAYERS_N) {
1720 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1721 } // if ($to_tabl == true ...
1724 if ($user->stat == 'room' && $user->subst == 'standup') {
1725 $this->standup_update(&$user);
1727 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1728 log_main("chatt_send pre table update");
1729 $this->table_update(&$user);
1730 log_main("chatt_send post table update");
1732 } // if ($update_room ...
1735 } // function chatt_send( ...
1737 function &get_user($sess, &$idx)
1739 GLOBAL $PHP_SELF, $G_false;
1741 if (validate_sess($sess)) {
1742 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1743 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1746 $ret = &$this->user[$i];
1750 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1751 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1752 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1755 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1764 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1767 * if ($idx > -1 && ret == FALSE) => duplicated nick
1768 * if ($idx == -2 && ret == FALSE) => invalid name
1769 * if ($idx == -3 && ret == FALSE) => wrong password
1770 * if ($idx == -1 && ret == FALSE) => no space left
1771 * if ($idx == 0 && ret == user) => SUCCESS
1772 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1777 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1779 GLOBAL $G_false, $CO_list;
1783 $authenticate = FALSE;
1784 $login_exists = FALSE;
1786 $ghost_auth = FALSE;
1790 if (($name_new = validate_name($name)) == FALSE) {
1795 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1796 if (validate_sess($sess) == FALSE)
1799 /* if pass != FALSE verify the login with pass */
1800 log_auth("XXX", "auth1");
1801 $userdb = new LoginDB();
1802 if ($pass != FALSE) {
1803 log_auth("XXX", "auth2");
1804 $authenticate = $userdb->login_verify($name_new, $pass);
1805 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1807 if ($authenticate == FALSE) {
1813 $login_exists = $userdb->login_exists($name_new);
1815 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1817 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1821 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1823 continue; // NOTE: CHECK IT !!
1825 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1826 if ($authenticate == FALSE) {
1832 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1839 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1841 if ($ghost > -1 && $ghost_auth && $authenticate) {
1844 $ghost_user =& $this->user[$ghost];
1846 $ghost_user->step_inc();
1849 $ghost_user->sess = $sess;
1852 $ghost_user->sess = $sess;
1855 // If user at the table we need to update the table data too
1856 $table_idx = $ghost_user->table;
1857 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1858 // FIXME BRISK4: include for each kind of table
1859 require_once("briskin5/Obj/briskin5.phh");
1860 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1861 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1862 if ($bri->the_end != TRUE) {
1863 $bri->user[$ghost_user->table_pos]->step_inc();
1864 $bri->user[$ghost_user->table_pos]->sess = $sess;
1865 Briskin5::save_data(&$bri);
1868 Briskin5::unlock_data($brisem);
1873 return ($this->user[$ghost]);
1875 else if ($idx != -1 && $i == MAX_PLAYERS) {
1880 $this->user[$idx]->sess = $sess;
1883 $this->user[$idx]->sess = $sess;
1885 $this->user[$idx]->name = $name_new; // OK - add new user
1886 $this->user[$idx]->stat_set("room");
1887 $this->user[$idx]->step_set(0);
1888 while (array_pop($this->user[$idx]->comm) != NULL);
1889 $this->user[$idx]->subst = "standup";
1890 $this->user[$idx]->lacc = $curtime;
1891 $this->user[$idx]->laccwr = $curtime;
1892 $this->user[$idx]->bantime = 0;
1893 $this->user[$idx]->ip = $ip;
1895 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1897 if ($authenticate) {
1898 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1900 if (isset($CO_list) && strcmp($CO_list, "all") == 0) {
1901 $this->user[$idx]->flags &= ~USER_FLAG_LISTAUTH;
1906 log_main("ghost: rename!");
1907 $ghost_user =& $this->user[$ghost];
1909 if ($ghost_auth == FALSE) {
1910 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1911 $ghostname = 'ghost'.$sfx;
1912 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1913 if (strcmp("", $this->user[$i]->sess) == 0)
1916 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1921 if ($ghostname != '')
1925 $ghost_user->name = $ghostname;
1927 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1928 $this->standup_update(&$ghost_user);
1931 log_main("chatt_send pre table update");
1932 $this->table_update(&$ghost_user);
1933 log_main("chatt_send post table update");
1935 } // if ($ghost_auth == FALSE
1937 // FIXME: cacciare il vecchio utente room && table (if needed)
1938 $ghost_user->the_end = TRUE;
1939 $ghost_user->lacc = 0;
1940 $this->garbage_manager(TRUE);
1942 } // if ($ghost > -1) {
1944 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1948 return ($this->user[$real_idx]);
1954 function standup_update(&$user)
1956 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1957 $user_cur = &$this->user[$i];
1958 if ($user_cur->sess == '')
1961 log_main("STANDUP START: ".$user_cur->stat);
1963 if ($user_cur->stat == 'room') {
1964 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1965 if ($user_cur == $user) {
1966 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1967 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1969 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
1970 $itin, xcape($user->name), $itou);
1972 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1974 $user_cur->step_inc();
1980 function &init_data()
1982 $room =& new Room();
1988 function &load_data()
1990 GLOBAL $G_false, $sess;
1993 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1994 log_main("ftok failed");
1999 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2000 log_main("shmop_open failed");
2004 $shm_sz = SHM_DIMS_MIN;
2006 if ($shm = shm_attach($tok, $shm_sz)) {
2007 $room = @shm_get_var($shm, $tok);
2009 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2011 log_only("bri count ".count($room));
2013 if ($room == FALSE) {
2014 log_only("INIT MAIN DATA");
2016 $room =& Room::init_data();
2017 if (@shm_put_var($shm, $tok, $room) == FALSE) {
2018 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
2019 log_only(serialize($room));
2022 $room->shm_sz = $shm_sz;
2037 function save_data(&$room)
2045 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2048 while ($room->shm_sz < SHM_DIMS_MAX) {
2049 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2052 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2053 if (shm_put_var($shm, $tok, $room) != FALSE) {
2057 if (shm_remove($shm) === FALSE) {
2058 log_only("REMOVE FALLITA");
2062 $room->shm_sz += SHM_DIMS_DLT;
2071 function lock_data()
2075 // echo "LOCK: ".FTOK_PATH."/main";
2077 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2080 // echo "FTOK ".$tok."<br>";
2081 if (($res = sem_get($tok)) == FALSE) {
2084 if (sem_acquire($res)) {
2085 log_lock("LOCK room");
2092 function unlock_data($res)
2096 log_lock("UNLOCK room");
2098 return (sem_release($res));
2102 function standup_content($user)
2107 if ($user->stat != 'room')
2110 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
2111 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2116 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2118 $content = ' j_stand_cont( [ ';
2120 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
2121 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2124 $flags = $this->user[$e]->flags;
2126 if ($this->user[$e]->subst == "standup") {
2127 if ($this->user[$e] == $user)
2132 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
2141 function table_content($user, $table_idx)
2147 // Si possono usare i dati nella classe table
2150 $sess = $user->sess;
2151 $table = &$this->table[$table_idx];
2153 if ($user->stat != 'room')
2157 for ($i = 0 ; $i < $table->player_n ; $i++) {
2158 $user_cur = &$this->user[$table->player[$i]];
2160 $flags = $user_cur->flags;
2162 if ($user_cur == $user)
2165 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2167 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2172 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2179 function make_seed()
2181 list($usec, $sec) = explode(' ', microtime());
2182 return (float) $sec + ((float) $usec * 100000);
2186 function log_only2($log) {
2189 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2192 if (isset($sess) == FALSE)
2197 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2200 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2201 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2206 function log_crit($log) {
2209 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2212 if (isset($sess) == FALSE)
2217 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2220 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2221 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2226 function log_only($log) {
2229 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2232 if (isset($sess) == FALSE)
2237 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2240 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2241 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2246 function log_main($log) {
2249 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2252 if (isset($sess) == FALSE)
2257 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2260 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2261 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2266 function log_rd($log) {
2269 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2272 if (isset($sess) == FALSE)
2277 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2280 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2281 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2286 function log_rd2($log) {
2289 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2292 if (isset($sess) == FALSE)
2297 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2300 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2301 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2306 function log_send($log) {
2309 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2312 if (isset($sess) == FALSE)
2317 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2320 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2321 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2326 function log_lock($log) {
2329 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2332 if (isset($sess) == FALSE)
2337 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2340 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2341 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2346 function log_wr($log) {
2349 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2352 if (isset($sess) == FALSE)
2357 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2360 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2361 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2366 function log_load($log) {
2369 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2372 if (isset($sess) == FALSE)
2377 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2380 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2381 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2386 function log_auth($sess, $log) {
2387 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2390 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2393 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2394 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2400 // function log_legal($curtime, $sess, $name, $where, $mesg)
2401 function log_legal($curtime, &$user, $where, $mesg)
2405 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2406 /* Unix time | session | nickname | IP | where was | mesg */
2407 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2408 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2409 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2417 function lock_banlist()
2419 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2423 if (($res = sem_get($tok)) == FALSE) {
2424 echo "SEM_GET FAILED";
2427 if (sem_acquire($res))
2433 function unlock_banlist($res)
2435 return (sem_release($res));
2438 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2443 if ($sitted < PLAYERS_N) {
2451 if ($table == $cur_table)
2458 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2463 function show_notify($text, $tout, $butt, $w, $h)
2465 log_main("SHOW_NOTIFY: ".$text);
2466 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2470 function root_wellcome($user)
2472 GLOBAL $root_wellarr, $G_lang;
2476 $dt = date("H:i ", $curtime);
2478 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2479 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2486 function validate_sess($sess)
2488 if (strlen($sess) == SESS_LEN)
2494 function validate_name($name)
2496 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2498 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2500 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2507 function playsound($filename)
2509 return (sprintf('playsound("flasou", "%s");', $filename));
2512 function secstoword($secs)
2516 $mins = floor($secs / 60);
2518 if ($G_lang == 'en') {
2520 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
2523 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
2527 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2530 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2535 function sharedmem_sz($tok)
2537 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2538 log_main("shmop_open failed");
2541 $shm_sz = shmop_size($shm_id);
2542 shmop_close($shm_id);
2544 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2549 function lock_data()
2553 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2556 // echo "FTOK ".$tok."<br>";
2557 if (($res = sem_get($tok)) == FALSE) {
2560 if (sem_acquire($res)) {
2561 log_lock("LOCK warrant");
2568 function unlock_data($res)
2572 log_lock("UNLOCK warrant");
2574 return (sem_release($res));
2579 function lock_data()
2583 if (($tok = @ftok(FTOK_PATH."/poll", "B")) == -1) {
2586 // echo "FTOK ".$tok."<br>";
2587 if (($res = sem_get($tok)) == FALSE) {
2590 if (sem_acquire($res)) {
2591 log_lock("LOCK poll");
2598 function unlock_data($res)
2602 log_lock("UNLOCK poll");
2604 return (sem_release($res));