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>");
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);
69 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
70 define(BRISK_DEBUG, 0xffffffbf);
72 define(BRISK_SINGLE_DEBUG,0);
73 define(BRISK_SINGLE_SESS, "");
74 // define(DEBUGGING, "local");
76 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
78 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
79 'en' => 'back standing' ),
80 'btn_close' => array( 'it' => 'chiudi',
83 'tit_all' => array( 'it' => 'tutti',
86 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
87 'en' => '<br>You are being idle for ' ),
88 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
89 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
90 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
91 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
92 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
93 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
94 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
95 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
96 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
97 'en' => '<br>The entered password is not correct.<br><br>'),
98 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
99 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
100 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
101 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
102 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
103 'en' => '<b>To send a message you have to be authenticated.</b>'),
104 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
105 'en' => 'The nickname have to contain at least one letter or one number.'),
106 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
107 'en' => 'The nickname <b>%s</b> is already in use.'),
108 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
109 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
110 '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>',
111 '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 ???
112 'statunkn' => array( 'it' => 'Questo stato non esiste.',
113 'en' => 'This state don\'t exists.'),
114 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
115 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
116 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
117 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
119 'tit_onauth'=>array( 'it' => '(solo aut.)',
120 'en' => '(only aut.)'),
121 'tit_onisol'=>array( 'it' => '(isolam.to)',
122 'en' => '(isolation)')
128 $G_lng = langtolng($G_lang);
130 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
131 $G_brisk_version = "2.4.2 - trusty";
133 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
134 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: nuovo calcolo dei punteggi (doppio oltre i 70, triplo oltre gli 80 etc...), più informazioni al tavolo.',
135 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
136 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: new method to calculate points (double after 70, triple after 80 and so on ...), more info at the table.',
137 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
139 $G_room_help = array( 'it' => '
140 <div style=\\"text-align: left; padding: 8px;\\">
141 <b>Descrizione</b><br>
142 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
143 <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>
144 <b>Configurazione del browser.</b><br>
145 Occorre abilitare i cookies.<br>
147 <b>Uso del sito</b><br>
148 Potete sedervi a un tavolo o rimanere in piedi.<br>
149 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
152 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>
153 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
154 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
155 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
156 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
157 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.
159 <dt><b>Comandi della chat</b>
160 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
161 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
162 <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\\"
163 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
164 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
165 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
171 <div style=\\"text-align: left; padding: 8px;\\">
172 <b>EN Descrizione</b><br>
173 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
174 <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>
175 <b>EN Configurazione del browser.</b><br>
176 Occorre abilitare i cookies.<br>
178 <b>Uso del sito</b><br>
179 Potete sedervi a un tavolo o rimanere in piedi.<br>
180 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
183 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>
184 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
185 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
186 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
187 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
188 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.
190 <dt><b>Comandi della chat</b>
191 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
192 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
193 <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\\"
194 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
195 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
196 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
202 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
203 <div style=\\"text-align: left; padding: 8px;\\">
204 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
206 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
207 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
209 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
210 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
211 <li>Smart card di InfoCamere
214 <b>Per auto-garantisi occorre possedere:</b><br><br>
216 <li>il codice PIN della propria carta
217 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
220 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
222 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
225 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
226 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
231 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
232 <div style=\\"text-align: left; padding: 8px;\\">
233 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
235 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
236 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
238 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
239 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
242 <b>Per auto-garantisi occorre possedere:</b><br><br>
244 <li>il codice PIN della propria carta
245 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
248 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
250 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
253 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
254 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
260 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
264 $G_room_about = array( 'it' => '<br>
265 <div id=\\"header\\" class=\\"header\\">
266 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
267 briscola chiamata in salsa ajax
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>',
272 <div id=\\"header\\" class=\\"header\\">
273 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
274 declaration briscola in ajax sauce <b>(Beta)</b>
276 <br><b>version '.$G_brisk_version.'</b><br><br>
277 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
280 function langtolng($lang)
284 return ($G_lang == 'en' ? '-en' : '');
287 function csplitter($in, $sep)
293 for ($i = 0 ; $i < strlen($in) ; $i++) {
294 $ini = substr($in, $i, 1);
298 else if ($ini == $sep) {
317 $from = array ( '\\', '@', '|' );
318 $to = array ( '\\\\', '@', '¦' );
320 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
325 $from = array ( '\\', '|', "\t", "\n");
326 $to = array ( '\\\\', '\\|', "\\t", "\\n");
328 return (str_replace($from, $to, $s));
331 function xcapemesg($s)
333 $from = array ( "\n");
334 $to = array ( "\\n");
336 return (str_replace($from, $to, $s));
345 var $auth_only; // se tavolo riservato o libero
352 var $table_start; // information field
360 function &create($idx)
364 if (($thiz =& new Table()) == FALSE)
368 $thiz->player = array();
370 $thiz->auth_only = FALSE;
372 $thiz->wag_own = NULL;
376 $thiz->table_token = "";
377 $thiz->table_start = 0;
379 $thiz->wakeup_time = 0;
384 function copy(&$from)
388 $this->idx = $from->idx;
389 $this->player = array();
390 for ($i = 0 ; $i < $from->player_n ; $i++)
391 $this->player[$i] = $from->player[$i];
392 $this->player_n = $from->player_n;
394 log_main("PLAYER_N - parent::copy.".$this->player_n);
396 $this->auth_only = $from->auth_only;
398 $this->wag_own = $from->wag_own;
399 $this->wag_com = $from->wag_com;
400 $this->wag_tout = $from->wag_tout;
402 $this->table_token = $from->table_token;
403 $this->table_start = $from->table_start;
405 $this->wakeup_time = $from->wakeup_time;
408 function &myclone(&$from)
412 if (($thiz =& new Table()) == FALSE)
420 function &spawn(&$from)
424 if (($thiz =& new Table()) == FALSE)
427 $thiz->idx = $from->idx;
428 $thiz->player = array();
429 for ($i = 0 ; $i < $from->player_n ; $i++)
430 $thiz->player[$i] = $i;
431 $thiz->player_n = $from->player_n;
433 $thiz->auth_only = $from->auth_only;
435 $thiz->wag_own = $from->wag_own;
436 $thiz->wag_com = $from->wag_com;
437 $thiz->wag_tout = $from->wag_tout;
439 $thiz->table_token = $from->table_token;
440 $thiz->table_start = $from->table_start;
442 $thiz->wakeup_time = $from->wakeup_time;
447 function wag_set(&$user, $mesg)
451 $this->wag_own = &$user;
452 $this->wag_com = $mesg;
456 function wag_reset($timeout)
458 log_main("WAG_RESET");
460 unset($this->wag_own);
461 $this->wag_own = NULL;
463 $this->wag_tout = $timeout;
466 function getPlayer($idx)
468 return ($this->player[$idx]);
471 function setPlayer($idx, $player)
473 $this->player[$idx] = $player;
476 function user_add($idx)
478 $this->player[$this->player_n] = $idx;
481 return ($this->player_n - 1);
484 function user_rem(&$room, &$user)
486 $tabpos = $user->table_pos;
488 /* verifico la consistenza dei dati */
489 if ($room->user[$this->player[$tabpos]] == $user) {
491 /* aggiorna l'array dei giocatori al tavolo. */
492 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
493 $this->player[$i] = $this->player[$i+1];
494 $user_cur = &$room->user[$this->player[$i]];
495 $user_cur->table_pos = $i;
500 log_main("INCONSISTENCY ON TABLE.");
506 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
507 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
509 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
510 function act_content(&$user)
513 $isstanding = ($user->subst == 'standup');
514 $sitted = $this->player_n;
516 $cur_table = $user->table;
520 if ($sitted < PLAYERS_N) {
521 if ($this->auth_only) {
522 if ($user->flags & USER_FLAG_AUTH)
536 if ($table == $cur_table)
543 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
551 define(USER_FLAG_AUTH, 0x02);
553 define(USER_FLAG_MAP_AUTH, 0x0c);
555 define(USER_FLAG_LISTAUTH, 0x04);
556 define(USER_FLAG_ISOLAUTH, 0x08);
559 define(USER_FLAG_S_NORM, 0x000); // done
560 define(USER_FLAG_S_PAU, 0x100); // done
561 define(USER_FLAG_S_OUT, 0x200); // done
562 define(USER_FLAG_S_DOG, 0x300); // done
563 define(USER_FLAG_S_EAT, 0x400); // done
564 define(USER_FLAG_S_WRK, 0x500); // done
565 define(USER_FLAG_S_SMK, 0x600); // done
566 define(USER_FLAG_S_EYE, 0x700); // done
567 define(USER_FLAG_S_RABB, 0x800); // done
569 define(USER_FLAG_S_ALL, 0xf00); // done
572 var $name; // name of the user
573 var $sess; // session of the user
574 var $ip; // ip of the user
575 var $lacc; // last access (for the cleanup)
576 var $laccwr; // last access (for the cleanup)
577 var $bantime; // timeout to temporary ban
578 var $stat; // status (outdoor, room, table, game, ...)
579 var $subst; // substatus for each status
580 var $step; // step of the current status
581 var $trans_step; // step to enable transition between pages (disable == -1)
582 var $comm; // commands array
583 // var $asta_card; //
585 // var $handpt; // Total card points at the beginning of the current hand.
586 // var $exitislock; // Player can exit from the table ?
588 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
589 // it is allways ZERO
590 var $table_orig; // id of the current table (if in table state)
591 var $table; // id of the current table (if in table state)
592 var $table_pos; // idx on the table
593 var $table_token;// token that identify a game on a table
594 var $flags; // Bitfield with: AUTHENTICATE: 0x02
595 var $the_end; // Flag to change the end of the session
597 var $chat_lst; // Last chat line
598 var $chattime; // Array of chat times
599 var $chat_cur; // Current chat line number
600 var $chat_ban; // Time for ban chat
601 var $chat_dlt; // Delta t for ban
605 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
608 if (($thiz =& new User()) == FALSE)
614 $thiz->lacc = time();
615 $thiz->laccwr = time();
618 $thiz->subst = $subst;
620 $thiz->trans_step = -1;
621 $thiz->comm = array();
622 $thiz->asta_card = -2;
623 $thiz->asta_pnt = -1;
625 $thiz->exitislock = TRUE;
629 $thiz->chattime = array_fill(0, CHAT_N, 0);
631 $thiz->chat_lst = "";
635 $thiz->table_orig = $table;
636 $thiz->table = $table;
637 $thiz->table_pos = -1;
638 $thiz->table_token = "";
643 function copy(&$from)
647 $this->name = $from->name;
648 $this->sess = $from->sess;
649 $this->ip = $from->ip;
650 $this->lacc = $from->lacc;
651 $this->laccwr = $from->laccwr;
652 $this->bantime = $from->bantime;
653 $this->stat = $from->stat;
654 $this->subst = $from->subst;
655 $this->step = $from->step;
656 $this->trans_step = $from->trans_step;
657 $this->comm = array();
659 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
660 for ($i = $i_start ; $i < $from->step ; $i++) {
662 $this->comm[$ii] = $from->comm[$ii];
664 $this->asta_card = $from->asta_card;
665 $this->asta_pnt = $from->asta_pnt;
666 $this->handpt = $from->handpt;
667 $this->exitislock = $from->exitislock;
669 $this->flags = $from->flags;
671 $this->chattime = array();
672 for ($i = 0 ; $i < CHAT_N ; $i++)
673 $this->chattime[$i] = $from->chattime[$i];
674 $this->chat_cur = $from->chat_cur;
675 $this->chat_lst = $from->chat_lst;
676 $this->chat_ban = $from->chat_ban;
677 $this->chat_dlt = $from->chat_dlt;
679 $this->table_orig = $from->table_orig;
680 $this->table = $from->table;
681 $this->table_pos = $from->table_pos;
682 $this->table_token = $from->table_token;
683 $this->the_end = $from->the_end;
689 function &myclone(&$from)
693 if (($thiz =& new User()) == FALSE)
701 function &spawn(&$from, $table, $table_pos)
705 if (($thiz =& new User()) == FALSE)
708 $thiz->name = $from->name;
709 $thiz->sess = $from->sess;
710 $thiz->ip = $from->ip;
711 $thiz->lacc = $from->lacc;
712 $thiz->laccwr = $from->laccwr;
713 $thiz->bantime = $from->bantime;
714 $thiz->stat = $from->stat;
715 $thiz->subst = $from->subst;
716 $thiz->step = $from->step;
717 $thiz->trans_step = $from->trans_step;
718 $thiz->comm = array();
721 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
722 for ($i = $i_start ; $i < $from->step ; $i++) {
723 log_wr("TRY PUSH:".$i);
725 $thiz->comm[$ii] = $from->comm[$ii];
728 $thiz->asta_card = $from->asta_card;
729 $thiz->asta_pnt = $from->asta_pnt;
730 $thiz->handpt = $from->handpt;
731 $thiz->exitislock = $from->exitislock;
732 $thiz->the_end = $from->the_end;
734 $thiz->flags = $from->flags;
736 $thiz->chattime = array_fill(0, CHAT_N, 0);
738 $thiz->chat_lst = "";
743 $thiz->table_orig = $table;
745 $thiz->table_pos = $table_pos;
746 $thiz->table_token = $from->table_token;
751 function stat_set($stat) {
752 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
753 $this->stat = "$stat";
756 if (validate_sess($this->sess)) {
757 if (file_exists(PROXY_PATH) == FALSE)
759 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
760 fwrite($fp, sprintf("%s\n",$this->stat));
766 function step_set($step) {
770 if (validate_sess($this->sess) == FALSE)
772 if (file_exists(PROXY_PATH) == FALSE)
774 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
776 fwrite($fp, pack("l",$this->step), 4);
785 function step_inc($delta = 1) {
786 $this->step += $delta;
788 if (validate_sess($this->sess)) {
789 if (file_exists(PROXY_PATH) == FALSE)
791 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
792 fwrite($fp, pack("l",$this->step), 4);
803 log_legal($curtime, $this, "STAT:LOGOUT", '');
805 $tmp_sess = $this->sess;
807 step_unproxy($tmp_sess);
808 $this->name = ""; // OK here
809 while (array_pop($this->comm) != NULL);
811 $this->chattime = array_fill(0, CHAT_N, 0);
813 $this->chat_lst = "";
816 $this->the_end = FALSE;
826 function step_get($sess) {
829 if (validate_sess($sess) == FALSE)
832 if (file_exists(PROXY_PATH) == FALSE)
834 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
836 if (($s = fread($fp, 4)) == FALSE)
840 $arr = unpack('l', $s);
843 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
850 log_rd2("STEP_GET: return false ");
855 function step_unproxy($sess) {
856 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
857 if (file_exists(PROXY_PATH) == FALSE)
859 @unlink(PROXY_PATH."/".$sess.".step");
866 var $comm; // commands for many people
867 var $step; // current step of the comm array
868 var $garbage_timeout;
872 $this->user = array();
873 $this->table = array();
875 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
876 $this->user[$i] =& User::create("", "");
879 for ($i = 0 ; $i < TABLES_N ; $i++) {
880 $this->table[$i] =& Table::create($i);
883 $row = ( (((int)($i / 4)) % 2) == 0 );
884 $col = ($i % 2 == 0);
885 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
888 $this->table[$i]->auth_only = FALSE;
891 if ($i < TABLES_AUTH_N)
892 $this->table[$i]->auth_only = TRUE;
894 $this->table[$i]->auth_only = FALSE;
896 $this->garbage_timeout = 0;
899 function garbage_manager($force)
901 GLOBAL $G_lang, $mlang_brisk;
905 log_rd2("garbage_manager START");
907 /* Garbage collector degli utenti in timeout */
909 if ($force || $this->garbage_timeout < $curtime) {
911 // FIXME BRISK4: include for each kind of table
912 require_once("briskin5/Obj/briskin5.phh");
914 // Before all align times with table timeout
915 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
916 $table_cur =& $this->table[$table_idx];
917 // if the table is complete and exists its shared mem we get the info about users lacc
919 if ($table_cur->player_n == PLAYERS_N) {
920 log_main("PLAYERS == N TABLE ".$table_idx);
922 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
923 log_main("bin5 lock data success");
925 $no_recovery = FALSE;
926 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
927 if ($table_cur->table_token != $bri->table_token) {
928 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
929 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
939 log_main("garbage_manager: bri loaded successfully.");
940 $bri->garbage_manager(TRUE);
942 $bri_table = &$bri->table[0];
944 // is the end of the table
945 if ($bri->the_end == TRUE) {
947 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
949 log_main("garbage_manager: INSIDE THE END.");
951 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
952 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
953 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
956 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
957 // stat must be "table" by definition
958 $user_cur =& $this->user[$table_cur->player[$i]];
959 $bri_user =& $bri->user[$i];
961 $user_cur->subst = $bri_user->subst;
962 $user_cur->step = $bri_user->step;
963 $user_cur->lacc = $bri_user->lacc;
964 $user_cur->laccwr = $bri_user->lacc;
965 $user_cur->bantime = $bri_user->bantime;
968 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
970 $this->room_join_wakeup(&$user_cur, FALSE, 0);
971 $table_cur->table_token = "";
972 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
973 Briskin5::destroy_data($table_idx);
976 log_main("gm:: save_data");
978 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
979 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
982 Briskin5::save_data(&$bri);
984 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
985 else if ($no_recovery == FALSE) {
986 log_crit("ERROR: table ".$table_idx." unrecoverable join");
988 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
989 $user_cur = &$this->user[$table_cur->player[$i]];
990 $user_cur->subst = "shutdowner";
991 $user_cur->step_inc();
993 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
994 $ret .= "gst.st = ".($user_cur->step+1)."; ";
995 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
996 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
997 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
998 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
999 $user_cur->step_inc();
1002 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
1003 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1004 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1006 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
1008 $this->room_join_wakeup(&$user_cur, TRUE, -2);
1009 $table_cur->table_token = "";
1012 Briskin5::unlock_data($sem);
1014 } // if ($table_cur->player_n == PLAYERS_N) {
1015 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1017 log_rd2("out new loop.");
1019 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1020 $user_cur = &$this->user[$i];
1022 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1024 if ($user_cur->sess == "")
1027 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1028 // Auto logout dell'utente
1029 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1031 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1032 log_auth($user_cur->sess, "Autologout session.");
1036 log_rd2("AUTO LOGOUT.");
1037 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1038 $this->room_wakeup(&$user_cur);
1039 else if ($user_cur->subst == 'standup')
1040 $this->room_outstandup(&$user_cur);
1042 log_rd2("LOGOUT FROM WHAT ???");
1046 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1047 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1048 $this->room_wakeup(&$user_cur);
1049 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1050 /* 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" */
1051 $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);
1052 $user_cur->step_inc();
1056 log_rd2("GARBAGE UPDATED!");
1058 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1065 function show_room($user_step, &$user)
1067 GLOBAL $G_lang, $mlang_brisk;
1068 log_main("show_room: username: ".$user->name);
1070 $ret = sprintf('gst.st = %d; ', $user_step);
1072 if ($user->flags & USER_FLAG_ISOLAUTH) {
1073 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
1075 else if ($user->flags & USER_FLAG_LISTAUTH) {
1076 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1079 $ret .= 'list_set(\'all\', false, \'\' ); ';
1082 if ($user->subst == 'standup')
1083 $ret .= "tra.show(); ";
1085 $ret .= "tra.hide(); ";
1087 $ret .= sprintf('stat = "%s";', $user->stat);
1089 $ret .= root_wellcome($user);
1090 $ret .= sprintf('subst = "%s";', $user->subst);
1091 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1092 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1093 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1094 for ($i = 0 ; $i < TABLES_N ; $i++) {
1096 $ret .= $this->table_content($user, $i);
1097 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1098 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1099 $ret .= $this->table[$i]->act_content($user);
1100 if ($this->table[$i]->wag_own != NULL)
1101 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
1103 $ret .= sprintf('tra.rem(%d); ', $i);
1105 $ret .= $this->standup_content($user);
1111 function room_wakeup(&$user)
1113 $table_idx = $user->table;
1114 $table = &$this->table[$table_idx];
1116 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1120 $from_table = ($user->stat == "table");
1122 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1124 for ($i = 0 ; $i < $table->player_n ; $i++) {
1125 $user_cur = &$this->user[$table->player[$i]];
1126 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1128 if ($user_cur != $user) {
1129 $user_cur->stat_set("room");
1130 $user_cur->subst = "sitdown";
1131 $user_cur->laccwr = $curtime;
1133 else if ($user->sess != "") {
1134 $user_cur->stat_set("room");
1135 $user_cur->subst = "standup";
1136 $user_cur->laccwr = $curtime;
1137 $user_cur->table = -1;
1142 $user->stat_set("room");
1143 $user->subst = "standup";
1144 $user->laccwr = $curtime;
1147 $remove_wagon = false;
1148 if($table->wag_own == $user) {
1149 $remove_wagon = true;
1150 $table->wag_reset($curtime);
1155 /* aggiorna l'array dei giocatori al tavolo. */
1156 $table->user_rem(&$this, &$user);
1158 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1159 $user_cur = &$this->user[$i];
1160 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1163 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1165 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1166 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
1167 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1168 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1169 log_main("DOCUMENT.index.php: from table");
1171 else if ($user_cur->stat == "room") {
1172 log_main("DOCUMENT.index.php: from table");
1174 $ret .= $this->table_content($user_cur, $table_idx);
1175 $ret .= $this->standup_content($user_cur);
1177 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1178 $ret .= $table->act_content($user);
1180 if ($user_cur == $user) {
1181 // set the new status
1182 $ret .= 'subst = "standup"; tra.show(); ';
1183 // clean the action buttons in other tables
1184 for ($e = 0 ; $e < TABLES_N ; $e++) {
1185 if ($this->table[$e]->player_n < PLAYERS_N) {
1186 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1187 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1188 $ret .= $this->table[$e]->act_content($user);
1193 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1194 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1195 $ret .= $table->act_content($user_cur);
1198 log_wr("ROOM_WAKEUP: ".$ret);
1199 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1200 $user_cur->step_inc();
1204 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1206 $table_idx = $user->table;
1207 $table = &$this->table[$table_idx];
1209 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1212 $user_wup = array();
1214 $user_tab = array();
1216 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1218 for ($i = 0 ; $i < $table->player_n ; $i++) {
1219 $user_cur = &$this->user[$table->player[$i]];
1220 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1221 if ($user_cur->sess != "") {
1222 if ($update_lacc == TRUE) {
1223 $user_cur->laccwr = $curtime;
1225 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1226 if ($user_cur->subst == "shutdowned") {
1227 $user_cur->stat_set("room");
1228 $user_cur->subst = "sitdown";
1230 else if ($user_cur->subst == "shutdowner") {
1231 $user_cur->stat_set("room");
1232 $user_cur->subst = "standup";
1233 $user_cur->table = -1;
1234 $user_wup[$user_wup_n++] = &$user_cur;
1236 $remove_wagon = false;
1237 if($table->wag_own == $user_cur) {
1238 $remove_wagon = true;
1239 $table->wag_reset($curtime);
1242 $user_tab[$user_tab_n++] = &$user_cur;
1246 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1247 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1249 /* aggiorna l'array dei giocatori al tavolo. */
1251 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1252 log_main("START LOOP");
1253 $user_cur = &$this->user[$i];
1254 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1255 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1260 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1262 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1263 if ($user_cur->stat == "room") {
1264 log_main("DOCUMENT.index.php from table");
1266 $ret .= $this->table_content($user_cur, $table_idx);
1267 $ret .= $this->standup_content($user_cur);
1269 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1270 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1271 $ret .= $table->act_content($user_cur);
1274 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1275 if ($user_cur == $user_tab[$tab_idx])
1278 // for users that wakeup the room will be reconstructed by index_rd.php
1279 if ($tab_idx < $user_tab_n) {
1280 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1282 // ARRAY_POP DISABLED
1283 // if ($trans_delta == 0)
1284 // while (array_pop($user_cur->comm) != NULL);
1286 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1287 $user_cur->comm[$user_cur->step % COMM_N] = "";
1288 $user_cur->step_inc();
1289 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1290 $user_cur->step_inc();
1291 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1295 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1297 log_main("JOIN_WAKEUP more");
1298 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1299 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1300 $ret .= $table->act_content($user_cur);
1302 log_main("JOIN_WAKEUP end more");
1304 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1305 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1306 $user_cur->step_inc();
1310 function room_outstandup(&$user)
1312 $this->room_sitdown(&$user, -1);
1315 function table_update(&$user)
1317 log_main("table_update: pre - USER: ".$user->name);
1319 $table_idx = $user->table;
1321 if ($table_idx > -1)
1322 $table = &$this->table[$table_idx];
1324 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1326 $user_cur = &$this->user[$i];
1327 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1330 $ret = "gst.st = ".($user_cur->step+1)."; ";
1331 if ($table_idx > -1)
1332 $ret .= $this->table_content($user_cur, $table_idx);
1334 if ($user_cur == $user) {
1335 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1336 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1337 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1339 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1340 $user_cur->step_inc();
1343 log_main("table_update: post");
1346 function room_sitdown(&$user, $table_idx)
1348 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1352 if ($table_idx > -1 && $table_idx < TABLES_N) {
1353 $table = &$this->table[$table_idx];
1356 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1357 for ($i = 0 ; $i < TABLES_N ; $i++) {
1358 $user_cur =& $this->user[$table->player[$i]];
1359 if ($user_cur == $table->wag_own) {
1360 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1361 $table->wag_reset(time());
1368 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1370 $user_cur = &$this->user[$i];
1371 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1374 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1375 if ($table_idx > -1)
1376 $ret .= $this->table_content($user_cur, $table_idx);
1377 $ret .= $this->standup_content($user_cur);
1379 if ($user_cur == $user) {
1380 $ret .= 'subst = "sitdown"; tra.hide(); ';
1381 // clean the action buttons in other tables
1382 for ($e = 0 ; $e < TABLES_N ; $e++) {
1383 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1384 $ret .= $this->table[$e]->act_content($user_cur);
1387 else if ($table_idx > -1) {
1388 if ($table->player_n == PLAYERS_N) {
1389 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1390 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1391 $ret .= $table->act_content($user_cur);
1394 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1395 $user_cur->step_inc();
1399 function chatt_send(&$user, $mesg)
1401 GLOBAL $G_alarm_passwd, $mlang_brisk, $G_lang;
1405 $msg = substr($mesg, 6, 128);
1407 $dt = date("H:i ", $curtime);
1417 $is_normchat = FALSE;
1418 /* for old isolation management $is_ticker = FALSE; */
1419 $update_room = FALSE;
1421 if (strcmp($msg, "/tav") == 0 ||
1422 strncmp($msg, "/tav ", 5) == 0) {
1424 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1425 /* 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>" */
1426 $msg = $mlang_brisk['tickmust'][$G_lang];
1427 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1432 $table = &$this->table[$user->table];
1434 if ($table->wag_own != NULL) {
1435 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1436 $msg = $mlang_brisk['tickjust'][$G_lang];
1437 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1442 $dtime = $curtime - $table->wag_tout;
1443 if ($dtime < EXPIRE_TIME_WAG) {
1444 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1445 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1446 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1447 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1452 $msg = substr($msg, 5);
1454 $table->wag_set($user, $msg);
1455 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1456 $to_room = $to_user;
1457 /* for old isolation management $is_ticker = TRUE; */
1459 } // /tav chat command
1461 else if (strncmp($msg, "/alarm ", 7) == 0) {
1462 if (strncmp($msg, "/alarm to ", 10) == 0) {
1463 $sp_pos = strpos($msg, " ", 10);
1464 $target = substr($msg, 10, $sp_pos - 10);
1465 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1469 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1472 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1473 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1474 $msg = $mlang_brisk['alarpass'][$G_lang];
1475 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1480 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1481 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1482 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1483 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1484 $dt, NICKSERV, $prestr);
1486 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1487 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1488 /* MLANG: "chiudi" */
1489 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1491 } // /alarm chat command
1492 else if (strncmp($msg, "/listen ", 8) == 0) {
1493 $arg = substr($msg, 8);
1495 if (strcasecmp($arg, "isolation") == 0) {
1497 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1498 $user->table >= TABLES_AUTH_N) {
1499 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1503 $user->flags &= ~USER_FLAG_MAP_AUTH;
1504 $user->flags |= USER_FLAG_ISOLAUTH;
1505 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1508 else if (strcasecmp($arg, "auth") == 0) {
1509 $flags_old = $user->flags;
1510 $user->flags &= ~USER_FLAG_MAP_AUTH;
1511 $user->flags |= USER_FLAG_LISTAUTH;
1512 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1515 $flags_old = $user->flags;
1516 $user->flags &= ~USER_FLAG_MAP_AUTH;
1517 $to_user = 'list_set(\'all\', true, \'\'); ';
1520 // if from isolation redraw standup area
1521 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1522 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1526 else if (strcmp($msg, "/authreq") == 0) {
1527 if ($user->flags & USER_FLAG_AUTH) {
1528 $to_user = sprintf('authbox(300,200);');
1531 /* 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." */
1532 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1535 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1536 if ($user->flags & USER_FLAG_AUTH) {
1537 $to_user = sprintf('mesgtoadmbox(500,300);');
1540 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1541 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1544 else if (strncmp($msg, "/nick ", 6) == 0) {
1545 log_main("chatt_send BEGIN");
1548 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1549 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1553 $msg = "COMMAND ".$msg;
1554 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1555 $user_cur = &$this->user[$i];
1557 if ($user_cur->sess == '')
1559 if ($user_cur->name == $name_new)
1562 if ($i < MAX_PLAYERS) {
1563 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1564 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1568 /* 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>" */
1569 if ($user->flags & USER_FLAG_AUTH) {
1570 if (strcasecmp($user->name,$name_new) != 0) {
1571 if (($user->flags & USER_FLAG_MAP_AUTH != USER_FLAG_ISOLAUTH) &&
1572 ($user->subst == 'standup' ||
1573 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1576 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1577 for ($i = 0 ; $i < TABLES_N ; $i++) {
1578 $to_user .= $this->table[$i]->act_content($user);
1582 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1587 $user->name = $name_new; // OK - nick changed
1588 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1589 if (($user->flags & USER_FLAG_AUTH) == 0) {
1590 $userdb = new LoginDB();
1591 /* 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>" */
1592 if ($userdb->login_exists($name_new)) {
1593 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1594 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1598 log_main("chatt_send start set");
1600 $update_room = TRUE;
1602 } // nick chat command
1604 else if (strncmp($msg, "/st ", 4) == 0) {
1605 log_main("chatt_send BEGIN");
1608 $st_str = substr($msg, 4);
1610 if (strcasecmp($st_str, "normale") == 0) {
1611 $st = USER_FLAG_S_NORM;
1613 else if (strcasecmp($st_str, "pausa") == 0) {
1614 $st = USER_FLAG_S_PAU;
1616 else if (strcasecmp($st_str, "fuori") == 0) {
1617 $st = USER_FLAG_S_OUT;
1619 else if (strcasecmp($st_str, "cane") == 0) {
1620 $st = USER_FLAG_S_DOG;
1622 else if (strcasecmp($st_str, "cibo") == 0) {
1623 $st = USER_FLAG_S_EAT;
1625 else if (strcasecmp($st_str, "lavoro") == 0) {
1626 $st = USER_FLAG_S_WRK;
1628 else if (strcasecmp($st_str, "sigaretta") == 0) {
1629 $st = USER_FLAG_S_SMK;
1631 else if (strcasecmp($st_str, "presente") == 0) {
1632 $st = USER_FLAG_S_EYE;
1634 else if (strcasecmp($st_str, "coniglio") == 0) {
1635 $st = USER_FLAG_S_RABB;
1638 /* MLANG: "Questo stato non esiste." */
1639 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1643 log_main("chatt_send start set");
1644 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1645 $update_room = TRUE;
1646 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1649 } // nick chat command
1651 else { // normal chat line
1652 $is_normchat = TRUE;
1653 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1655 $user->chat_dlt = $user->chat_dlt * 2;
1656 if ($user->chat_dlt > 120)
1657 $user->chat_dlt = 120;
1659 else if ($user->chat_lst == $msg)
1661 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1662 $user->chat_ban = $curtime;
1663 $user->chat_dlt = 5;
1667 $user->chat_ban = 0;
1668 $user->chat_dlt = 0;
1672 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1675 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1676 // temporary silentiation for troll (will became array check)
1677 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1678 $to_room = $to_user;
1681 log_legal($curtime, $user,
1682 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1684 $user->chat_lst = "$msg";
1685 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1695 // Output to clients
1698 if ($to_user != FALSE) {
1699 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1700 $user->comm[$user->step % COMM_N] .= $to_user;
1704 if ($to_room != FALSE) {
1705 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1706 $user_cur = &$this->user[$i];
1707 if ($target != "" && $user_cur->name != $target)
1709 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1710 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1713 if ($is_normchat == TRUE) {
1714 // use MAP_AUTH to check if auth or isolation
1715 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1716 if (($user->flags & USER_FLAG_AUTH) == 0) {
1722 else if ($is_ticker) {
1723 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1724 if ($user->table >= TABLES_AUTH_N)
1729 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1730 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1731 $user_cur->step_inc();
1736 // FIXME BRISK4: include for each kind of table
1737 require_once("briskin5/Obj/briskin5.phh");
1738 // Before all align times with table timeout
1739 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1740 $table_cur =& $this->table[$table_idx];
1741 // if the table is complete and exists its shared mem we get the info about users lacc
1743 if ($table_cur->player_n == PLAYERS_N) {
1744 log_main("PLAYERS == N TABLE ".$table_idx);
1746 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1747 log_main("bin5 lock data success");
1749 $no_recovery = FALSE;
1750 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1751 if ($table_cur->table_token != $bri->table_token) {
1752 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1757 if ($bri != FALSE) {
1758 $bri_table = &$bri->table[0];
1759 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1760 // stat must be "table" by definition
1761 $bri_user =& $bri->user[$i];
1763 if ($target != "" && $bri_user->name != $target)
1765 log_main("writa: ".$user_mesg);
1766 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1767 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1768 $bri_user->step_inc();
1770 Briskin5::save_data(&$bri);
1772 Briskin5::unlock_data($sem);
1774 } // if ($table_cur->player_n == PLAYERS_N) {
1775 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1776 } // if ($to_tabl == true ...
1779 if ($user->stat == 'room' && $user->subst == 'standup') {
1780 $this->standup_update(&$user);
1782 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1783 log_main("chatt_send pre table update");
1784 $this->table_update(&$user);
1785 log_main("chatt_send post table update");
1787 } // if ($update_room ...
1790 } // function chatt_send( ...
1792 function &get_user($sess, &$idx)
1794 GLOBAL $PHP_SELF, $G_false;
1796 if (validate_sess($sess)) {
1797 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1798 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1801 $ret = &$this->user[$i];
1805 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1806 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1807 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1810 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1819 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1822 * if ($idx > -1 && ret == FALSE) => duplicated nick
1823 * if ($idx == -2 && ret == FALSE) => invalid name
1824 * if ($idx == -3 && ret == FALSE) => wrong password
1825 * if ($idx == -1 && ret == FALSE) => no space left
1826 * if ($idx == 0 && ret == user) => SUCCESS
1827 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1832 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1834 GLOBAL $G_false, $CO_list;
1838 $authenticate = FALSE;
1839 $login_exists = FALSE;
1841 $ghost_auth = FALSE;
1845 if (($name_new = validate_name($name)) == FALSE) {
1850 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1851 if (validate_sess($sess) == FALSE)
1854 /* if pass != FALSE verify the login with pass */
1855 log_auth("XXX", "auth1");
1856 $userdb = new LoginDB();
1857 if ($pass != FALSE) {
1858 log_auth("XXX", "auth2");
1859 $authenticate = $userdb->login_verify($name_new, $pass);
1860 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1862 if ($authenticate == FALSE) {
1868 $login_exists = $userdb->login_exists($name_new);
1870 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1872 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1876 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1878 continue; // NOTE: CHECK IT !!
1880 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1881 if ($authenticate == FALSE) {
1887 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1894 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1896 if ($ghost > -1 && $ghost_auth && $authenticate) {
1899 $ghost_user =& $this->user[$ghost];
1901 $ghost_user->step_inc();
1904 $ghost_user->sess = $sess;
1907 $ghost_user->sess = $sess;
1910 // If user at the table we need to update the table data too
1911 $table_idx = $ghost_user->table;
1912 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1913 // FIXME BRISK4: include for each kind of table
1914 require_once("briskin5/Obj/briskin5.phh");
1915 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1916 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1917 if ($bri->the_end != TRUE) {
1918 $bri->user[$ghost_user->table_pos]->step_inc();
1919 $bri->user[$ghost_user->table_pos]->sess = $sess;
1920 Briskin5::save_data(&$bri);
1923 Briskin5::unlock_data($brisem);
1928 return ($this->user[$ghost]);
1930 else if ($idx != -1 && $i == MAX_PLAYERS) {
1935 $this->user[$idx]->sess = $sess;
1938 $this->user[$idx]->sess = $sess;
1940 $this->user[$idx]->name = $name_new; // OK - add new user
1941 $this->user[$idx]->stat_set("room");
1942 $this->user[$idx]->step_set(0);
1943 while (array_pop($this->user[$idx]->comm) != NULL);
1944 $this->user[$idx]->subst = "standup";
1945 $this->user[$idx]->lacc = $curtime;
1946 $this->user[$idx]->laccwr = $curtime;
1947 $this->user[$idx]->bantime = 0;
1948 $this->user[$idx]->ip = $ip;
1950 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1952 if ($authenticate) {
1953 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1955 if (isset($CO_list)) {
1956 if (strcmp($CO_list, "auth") == 0) {
1957 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1958 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1960 if (strcmp($CO_list, "isolation") == 0) {
1961 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1962 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
1965 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
1971 log_main("ghost: rename!");
1972 $ghost_user =& $this->user[$ghost];
1974 if ($ghost_auth == FALSE) {
1975 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1976 $ghostname = 'ghost'.$sfx;
1977 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1978 if (strcmp("", $this->user[$i]->sess) == 0)
1981 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1986 if ($ghostname != '')
1990 $ghost_user->name = $ghostname;
1992 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1993 $this->standup_update(&$ghost_user);
1996 log_main("chatt_send pre table update");
1997 $this->table_update(&$ghost_user);
1998 log_main("chatt_send post table update");
2000 } // if ($ghost_auth == FALSE
2002 // FIXME: cacciare il vecchio utente room && table (if needed)
2003 $ghost_user->the_end = TRUE;
2004 $ghost_user->lacc = 0;
2005 $this->garbage_manager(TRUE);
2007 } // if ($ghost > -1) {
2009 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
2013 return ($this->user[$real_idx]);
2019 function standup_update(&$user)
2021 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2022 $user_cur = &$this->user[$i];
2023 if ($user_cur->sess == '')
2026 log_main("STANDUP START: ".$user_cur->stat);
2028 if ($user_cur->stat == 'room') {
2029 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
2030 if ($user_cur == $user) {
2031 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
2032 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
2034 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
2035 $itin, xcape($user->name), $itou);
2037 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
2039 $user_cur->step_inc();
2045 function &init_data()
2047 $room =& new Room();
2053 function &load_data()
2055 GLOBAL $G_false, $sess;
2058 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2059 log_main("ftok failed");
2064 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2065 log_main("shmop_open failed");
2069 $shm_sz = SHM_DIMS_MIN;
2071 if ($shm = shm_attach($tok, $shm_sz)) {
2072 $room = @shm_get_var($shm, $tok);
2074 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2076 log_only("bri count ".count($room));
2078 if ($room == FALSE) {
2079 log_only("INIT MAIN DATA");
2081 $room =& Room::init_data();
2082 if (@shm_put_var($shm, $tok, $room) == FALSE) {
2083 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
2084 log_only(serialize($room));
2087 $room->shm_sz = $shm_sz;
2102 function save_data(&$room)
2110 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2113 while ($room->shm_sz < SHM_DIMS_MAX) {
2114 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2117 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2118 if (shm_put_var($shm, $tok, $room) != FALSE) {
2122 if (shm_remove($shm) === FALSE) {
2123 log_only("REMOVE FALLITA");
2127 $room->shm_sz += SHM_DIMS_DLT;
2136 function lock_data()
2140 // echo "LOCK: ".FTOK_PATH."/main";
2142 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2145 // echo "FTOK ".$tok."<br>";
2146 if (($res = sem_get($tok)) == FALSE) {
2149 if (sem_acquire($res)) {
2150 log_lock("LOCK room");
2157 function unlock_data($res)
2161 log_lock("UNLOCK room");
2163 return (sem_release($res));
2167 function standup_content($user)
2172 if ($user->stat != 'room')
2175 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
2176 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2181 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2183 $content = ' j_stand_cont( [ ';
2185 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
2186 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2189 $flags = $this->user[$e]->flags;
2191 if ($this->user[$e]->subst == "standup") {
2192 if ($this->user[$e] == $user)
2197 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
2206 function table_content($user, $table_idx)
2212 // Si possono usare i dati nella classe table
2215 $sess = $user->sess;
2216 $table = &$this->table[$table_idx];
2218 if ($user->stat != 'room')
2222 for ($i = 0 ; $i < $table->player_n ; $i++) {
2223 $user_cur = &$this->user[$table->player[$i]];
2225 $flags = $user_cur->flags;
2227 if ($user_cur == $user)
2230 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2232 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2237 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2244 function make_seed()
2246 list($usec, $sec) = explode(' ', microtime());
2247 return (float) $sec + ((float) $usec * 100000);
2251 function log_only2($log) {
2254 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2257 if (isset($sess) == FALSE)
2262 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2265 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2266 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2271 function log_crit($log) {
2274 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2277 if (isset($sess) == FALSE)
2282 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2285 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2286 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2291 function log_only($log) {
2294 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2297 if (isset($sess) == FALSE)
2302 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2305 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2306 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2311 function log_main($log) {
2314 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2317 if (isset($sess) == FALSE)
2322 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2325 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2326 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2331 function log_rd($log) {
2334 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2337 if (isset($sess) == FALSE)
2342 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2345 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2346 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2351 function log_rd2($log) {
2354 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2357 if (isset($sess) == FALSE)
2362 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2365 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2366 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2371 function log_send($log) {
2374 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2377 if (isset($sess) == FALSE)
2382 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2385 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2386 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2391 function log_lock($log) {
2394 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2397 if (isset($sess) == FALSE)
2402 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2405 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2406 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2411 function log_wr($log) {
2414 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2417 if (isset($sess) == FALSE)
2422 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2425 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2426 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2431 function log_load($log) {
2434 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2437 if (isset($sess) == FALSE)
2442 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2445 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2446 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2451 function log_auth($sess, $log) {
2452 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2455 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2458 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2459 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2465 // function log_legal($curtime, $sess, $name, $where, $mesg)
2466 function log_legal($curtime, &$user, $where, $mesg)
2470 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2471 /* Unix time | session | nickname | IP | where was | mesg */
2472 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2473 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2474 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2479 function log_points($curtime, &$user, $where, $mesg)
2483 if (($fp = @fopen(LEGAL_PATH."/points.log", 'a')) != FALSE) {
2484 /* Unix time | session | nickname | IP | where was | mesg */
2485 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2486 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2487 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2495 function lock_banlist()
2497 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2501 if (($res = sem_get($tok)) == FALSE) {
2502 echo "SEM_GET FAILED";
2505 if (sem_acquire($res))
2511 function unlock_banlist($res)
2513 return (sem_release($res));
2516 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2521 if ($sitted < PLAYERS_N) {
2529 if ($table == $cur_table)
2536 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2541 function show_notify($text, $tout, $butt, $w, $h)
2543 log_main("SHOW_NOTIFY: ".$text);
2544 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2547 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
2549 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2550 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);
2554 function root_wellcome($user)
2556 GLOBAL $root_wellarr, $G_lang;
2560 $dt = date("H:i ", $curtime);
2562 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2563 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2570 function validate_sess($sess)
2572 if (strlen($sess) == SESS_LEN)
2578 function validate_name($name)
2580 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2582 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2584 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2591 function playsound($filename)
2593 return (sprintf('playsound("flasou", "%s");', $filename));
2596 function secstoword($secs)
2600 $mins = floor($secs / 60);
2602 if ($G_lang == 'en') {
2604 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
2607 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
2611 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2614 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2619 function sharedmem_sz($tok)
2621 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2622 log_main("shmop_open failed");
2625 $shm_sz = shmop_size($shm_id);
2626 shmop_close($shm_id);
2628 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2633 function lock_data()
2637 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2640 // echo "FTOK ".$tok."<br>";
2641 if (($res = sem_get($tok)) == FALSE) {
2644 if (sem_acquire($res)) {
2645 log_lock("LOCK warrant");
2652 function unlock_data($res)
2656 log_lock("UNLOCK warrant");
2658 return (sem_release($res));
2663 function lock_data()
2667 if (($tok = @ftok(FTOK_PATH."/poll", "B")) == -1) {
2670 // echo "FTOK ".$tok."<br>";
2671 if (($res = sem_get($tok)) == FALSE) {
2674 if (sem_acquire($res)) {
2675 log_lock("LOCK poll");
2682 function unlock_data($res)
2686 log_lock("UNLOCK poll");
2688 return (sem_release($res));