5 * Copyright (C) 2006-2011 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
26 define(BRISK_CONF, "brisk.conf.pho");
27 define(FTOK_PATH, "/var/lib/brisk");
28 define(LEGAL_PATH, "/tmp/legal_brisk");
29 define(PROXY_PATH, "/var/lib/brisk_proxy");
31 define(TABLES_AUTH_N, 4);
33 define(MAX_POINTS, 5);
34 define(MAX_PLAYERS, (20 + (PLAYERS_N * TABLES_N)));
35 define(SHM_DIMS_MIN, (50000 + 10000 * TABLES_N + 15000 * MAX_PLAYERS));
36 define(SHM_DIMS_MAX, SHM_DIMS_MIN + 1048576);
37 define(SHM_DIMS_DLT, 65536);
39 define(SHM_DIMS_U_MIN, 4096);
40 define(SHM_DIMS_U_MAX, 65536);
41 define(SHM_DIMS_U_DLT, 4096);
44 define(COMM_GEN_N, 50);
47 define(CHAT_ILL_TIME, 6);
50 define(STREAM_TIMEOUT, 20);
51 define(EXPIRE_TIME_RD, 180);
52 define(EXPIRE_TIME_SMAMMA, 360);
53 define(EXPIRE_TIME_WAG, 10);
54 define(WAKEUP_TIME, 12);
55 // BAN_TIME da allineare anche in commons.js
56 define(BAN_TIME, 3600);
57 define(GARBAGE_TIMEOUT, 10);
58 define(NICKSERV, "<i>BriskServ</i>");
60 define(LOCK_SHARE_MAX, 10000);
62 define(DBG_ONL2, 0x0001);
63 define(DBG_ONLY, 0x0002);
64 define(DBG_MAIN, 0x0004);
65 define(DBG_READ, 0x0008);
66 define(DBG_REA2, 0x0010);
67 define(DBG_SEND, 0x0020);
68 define(DBG_LOCK, 0x0040);
69 define(DBG_WRIT, 0x0080);
70 define(DBG_LOAD, 0x0100);
71 define(DBG_AUTH, 0x0200);
72 define(DBG_CRIT, 0x0400);
73 define(DBG_LMOP, 0x0800);
74 define(DBG_TRAC, 0x1000);
75 define(DBG_SHME, 0x2000);
76 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
77 define(BRISK_DEBUG, 0xffffffbf);
79 define(BRISK_SINGLE_DEBUG,0);
80 define(BRISK_SINGLE_SESS, "");
81 // define(DEBUGGING, "local");
83 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
85 $mlang_brisk = array( 'btn_backstand'=> array( 'it' => 'torna in piedi',
86 'en' => 'back standing' ),
87 'btn_close' => array( 'it' => 'chiudi',
90 'tit_all' => array( 'it' => 'tutti',
93 'tabtout_a'=> array( 'it' => '<br>Sei stato inattivo per ',
94 'en' => '<br>You are being idle for ' ),
95 'tabtout_b'=> array( 'it' => ' minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.',
96 'en' => ' minutes. <br><br>Then you return with the <b>standing players</b>.'),
97 'tickmust' => array( 'it' => '<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>',
98 'en' => '<br>To activate the signalling message of the table it\'s necessary to be sitting<br><br>'),
99 'tickjust' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> ',
100 'en' => 'EN<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br> '),
101 'tickwait' => array( 'it' => '<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>',
102 'en' => 'EN<br>The signalling message of the table<br>will be deactivated for %d second%s.<br><br>'),
103 'alarpass' => array( 'it' => '<br>La password digitata non è corretta.<br><br>',
104 'en' => '<br>The entered password is not correct.<br><br>'),
105 'alarret' => array( 'it' => '"Alarm \\"<b>%s</b>\\" inviato a <b>%s</b>."',
106 'en' => '"Alarm \\"<b>%s</b>\\" sent to <b>%s</b>."'),
107 'authmust' => array( 'it' => '<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>',
108 'en' => '<b>To authenticate someone you have to be authenticated.</b>'), // on your turn
109 'mesgmust' => array( 'it' => '<b>Per inviare un messaggio devi essere autenticato.</b>',
110 'en' => '<b>To send a message you have to be authenticated.</b>'),
111 'nickmust' => array( 'it' => 'Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.',
112 'en' => 'The nickname have to contain at least one letter or one number.'),
113 'nickdupl' => array( 'it' => 'Nickname <b>%s</b> già in uso.',
114 'en' => 'The nickname <b>%s</b> is already in use.'),
115 'authchan' => array( 'it' => '<b>Non puoi cambiare nick a un tavolo per soli autenticati o se sei in modalità isolata.</b>',
116 'en' => '<b>You can\'t change your nickname into a table for only authenticated or if you are in isolation mode.</b>'),
117 'nickjust' => array( 'it' => 'Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>',
118 'en' => 'The nickname <b>\'%s\'</b> is already registered, <b>if its proprietary will authenticate you will named again officially ghost<i>N</i>.</b>'), // FIXME: him ???
119 'statunkn' => array( 'it' => 'Questo stato non esiste.',
120 'en' => 'This state don\'t exists.'),
121 'tabincon' => array( 'it' => '<br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>',
122 'en' => 'EN <br>I dati del tavolo n° %d sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>'),
123 'listmust' => array( 'it' => '<b>Per andare in isolamento non bisogna essere seduti a tavoli non riservati.</b>',
124 'en' => '<b>To go to isolation you must don\'t stay on not reserved tables</b>'),
126 'tit_onauth'=>array( 'it' => '(solo aut.)',
127 'en' => '(only aut.)'),
128 'tit_onisol'=>array( 'it' => '(isolam.to)',
129 'en' => '(isolation)'),
130 'db_failed' =>array('it' => '<br>Il collegamento al database è fallito.<br>Temporaneamente tutte le autenticazioni verranno sospese, accederai a Brisk come un utente normale.<br><br>Ci scusiamo per il disagio.',
131 'en' => 'Connection to the database failed<br>All authentications are suspended temporarly, you login as normal user.<br>We are about the limitation')
136 $G_lng = langtolng($G_lang);
138 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
139 $G_brisk_version = "3.5.5";
141 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
142 $root_wellarr = array( 'it' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: quinta versione di test per la nuova gestione dei dati volatili, rivista gestione del ticker.',
143 'Se vuoi iscriverti alla <a target="_blank" href="mailto:ml-briscola+subscribe@milug.org">Mailing List</a>, cliccala!' ),
144 'en' => array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NEWS</b>: third test version for the new volatile data management, ticker management refactored.',
145 'If you want to subscribe our <a target="_blank" href="ml-briscola+subscribe@milug.org">Mailing List</a>, click it!' ) );
147 $G_room_help = array( 'it' => '
148 <div style=\\"text-align: left; padding: 8px;\\">
149 <b>Descrizione</b><br>
150 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
151 <a target=\\"_blank\\" href=\\"http://it.wikipedia.org/wiki/Briscola#Gioco_a_5\\">Wikipedia</a>; in breve è la variante con l\'asta prima sulla carta e poi sui punti.<br><br>
152 <b>Configurazione del browser.</b><br>
153 Occorre abilitare i cookies.<br>
155 <b>Uso del sito</b><br>
156 Potete sedervi a un tavolo o rimanere in piedi.<br>
157 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
160 All\'inizio vengono distribuite le carte e parte l\'asta; per partecipare all\'asta, quando sarà il vostro turno, potrete scegliere se andare avanti o passare cliccando sulle icone corrispondenti. Se si arriva ai punti, scrivete nella textbox il vostro rilancio e cliccate PUNTI.<br><br>
161 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
162 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
163 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
164 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
165 Dopo che è iniziata una partita per uscirne dovete chiedere agli altri giocatori di sbloccarla cliccando sul lucchetto. Se non si segue questa prassi, una volta usciti, non vi potrete sedere a nessun tavolo per '.floor(BAN_TIME/60).' minuti.
167 <dt><b>Comandi della chat</b>
168 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
169 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
170 <dd><b>/st <i><stato></i></b> - cambia l\'icona associata al tuo user; <i>stato</i> può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
171 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
172 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
173 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
179 <div style=\\"text-align: left; padding: 8px;\\">
180 <b>EN Descrizione</b><br>
181 EN Questa è un\'implementazione della briscola in cinque, così come è spiegata su
182 <a target=\\"_blank\\" href=\\"http://it.wikipedia.org/wiki/Briscola#Gioco_a_5\\">Wikipedia</a>; in breve è la variante con l\'asta prima sulla carta e poi sui punti.<br><br>
183 <b>EN Configurazione del browser.</b><br>
184 Occorre abilitare i cookies.<br>
186 <b>Uso del sito</b><br>
187 Potete sedervi a un tavolo o rimanere in piedi.<br>
188 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
191 All\'inizio vengono distribuite le carte e parte l\'asta; per partecipare all\'asta, quando sarà il vostro turno, potrete scegliere se andare avanti o passare cliccando sulle icone corrispondenti. Se si arriva ai punti, scrivete nella textbox il vostro rilancio e cliccate PUNTI.<br><br>
192 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
193 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
194 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
195 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
196 Dopo che è iniziata una partita per uscirne dovete chiedere agli altri giocatori di sbloccarla cliccando sul lucchetto. Se non si segue questa prassi, una volta usciti, non vi potrete sedere a nessun tavolo per '.floor(BAN_TIME/60).' minuti.
198 <dt><b>Comandi della chat</b>
199 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
200 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
201 <dd><b>/st <i><stato></i></b> - cambia l\'icona associata al tuo user; <i>stato</i> può valere: \\"normale\\", \\"fuori\\", \\"pausa\\", \\"cibo\\", \\"cane\\", \\"lavoro\\", \\"presente\\" oppure \\"sigaretta\\"
202 <dd><b>/authreq</b> - se si è autenticati permette di garantire per un utente fidato
203 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
204 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
210 $G_room_passwdhowto = array( 'it' => '<br><h2>Come registrarsi su Brisk</h2>
211 <div style=\\"text-align: left; padding: 8px;\\">
212 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
214 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
215 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
217 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
218 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
219 <li>Smart card di InfoCamere
222 <b>Per auto-garantisi occorre possedere:</b><br><br>
224 <li>il codice PIN della propria carta
225 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
228 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
230 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
233 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
234 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
239 'en' => '<br><h2>EN Come registrarsi su Brisk</h2>
240 <div style=\\"text-align: left; padding: 8px;\\">
241 EN Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
243 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
244 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
246 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
247 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
250 <b>Per auto-garantisi occorre possedere:</b><br><br>
252 <li>il codice PIN della propria carta
253 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
256 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
258 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
261 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
262 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
268 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
272 $G_room_about = array( 'it' => '<br>
273 <div id=\\"header\\" class=\\"header\\">
274 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
275 briscola chiamata in salsa ajax
277 <br><b>version '.$G_brisk_version.'</b><br><br>
278 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>',
280 <div id=\\"header\\" class=\\"header\\">
281 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
282 declaration briscola in ajax sauce <b>(Beta)</b>
284 <br><b>version '.$G_brisk_version.'</b><br><br>
285 Copyright 2006-2009 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>');
287 $escinp_from = array( "\"" );
288 $escinp_to = array( """ );
290 function escinput($s)
292 GLOBAL $escinp_from, $escinp_to;
294 return str_replace($escinp_from, $escinp_to, $s);
299 return htmlentities($s);
302 function esclfhtml($s)
304 return str_replace("\n", "<br>\n", htmlentities($s));
308 function langtolng($lang)
312 return ($G_lang == 'en' ? '-en' : '');
315 function csplitter($in, $sep)
321 for ($i = 0 ; $i < strlen($in) ; $i++) {
322 $ini = substr($in, $i, 1);
326 else if ($ini == $sep) {
345 $from = array ( '\\', '@', '|' );
346 $to = array ( '\\\\', '@', '¦' );
348 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
353 $from = array ( '\\', '|', "\t", "\n");
354 $to = array ( '\\\\', '\\|', "\\t", "\\n");
356 return (str_replace($from, $to, $s));
359 function xcapemesg($s)
361 $from = array ( "\n");
362 $to = array ( "\\n");
364 return (str_replace($from, $to, $s));
374 function getbyid($idx)
376 return ($this->el[$idx]);
379 function setbyid($idx, $v)
381 $this->el[$idx] = $v;
390 var $auth_only; // se tavolo riservato o libero
397 var $table_start; // information field
405 function create($idx)
407 if (($thiz = new Table()) == FALSE)
411 $thiz->player = array();
413 $thiz->auth_only = FALSE;
419 $thiz->table_token = "";
420 $thiz->table_start = 0;
422 $thiz->wakeup_time = 0;
429 $this->idx = $from->idx;
430 $this->player = array();
431 for ($i = 0 ; $i < $from->player_n ; $i++)
432 $this->player[$i] = $from->player[$i];
433 $this->player_n = $from->player_n;
435 log_main("PLAYER_N - parent::copy.".$this->player_n);
437 $this->auth_only = $from->auth_only;
439 $this->wag_own = $from->wag_own;
440 $this->wag_com = $from->wag_com;
441 $this->wag_tout = $from->wag_tout;
443 $this->table_token = $from->table_token;
444 $this->table_start = $from->table_start;
446 $this->wakeup_time = $from->wakeup_time;
449 function myclone($from)
451 if (($thiz = new Table()) == FALSE)
459 function spawn($from)
461 if (($thiz = new Table()) == FALSE)
464 $thiz->idx = $from->idx;
465 $thiz->player = array();
466 for ($i = 0 ; $i < $from->player_n ; $i++)
467 $thiz->player[$i] = $i;
468 $thiz->player_n = $from->player_n;
470 $thiz->auth_only = $from->auth_only;
472 $thiz->wag_own = $from->wag_own;
473 $thiz->wag_com = $from->wag_com;
474 $thiz->wag_tout = $from->wag_tout;
476 $thiz->table_token = $from->table_token;
477 $thiz->table_start = $from->table_start;
479 $thiz->wakeup_time = $from->wakeup_time;
484 function wag_set($user_idx, $mesg)
488 $this->wag_own = $user_idx;
489 $this->wag_com = $mesg;
493 function wag_reset($timeout)
495 log_main("WAG_RESET");
497 unset($this->wag_own);
500 $this->wag_tout = $timeout;
503 function player_get($idx)
505 return ($this->player[$idx]);
508 function player_set($idx, $player)
510 $this->player[$idx] = $player;
513 function user_add($idx)
515 $this->player[$this->player_n] = $idx;
518 return ($this->player_n - 1);
521 function user_rem($room, $user)
523 $tabpos = $user->table_pos;
525 /* verifico la consistenza dei dati */
526 if ($room->user[$this->player[$tabpos]] == $user) {
528 /* aggiorna l'array dei giocatori al tavolo. */
529 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
530 $this->player[$i] = $this->player[$i+1];
531 $user_cur = $room->user[$this->player[$i]];
532 $user_cur->table_pos = $i;
537 log_main("INCONSISTENCY ON TABLE.");
543 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
544 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
546 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
547 function act_content($user)
550 $isstanding = ($user->subst == 'standup');
551 $sitted = $this->player_n;
553 $cur_table = $user->table;
557 if ($sitted < PLAYERS_N) {
558 if ($this->auth_only) {
559 if ($user->flags & USER_FLAG_AUTH)
573 if ($table == $cur_table)
580 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
588 define(USER_FLAG_AUTH, 0x02);
590 define(USER_FLAG_MAP_AUTH, 0x0c);
591 define(USER_FLAG_LISTAUTH, 0x04);
592 define(USER_FLAG_ISOLAUTH, 0x08);
594 define(USER_FLAG_DBFAILED, 0x10);
597 define(USER_FLAG_S_NORM, 0x000); // done
598 define(USER_FLAG_S_PAU, 0x100); // done
599 define(USER_FLAG_S_OUT, 0x200); // done
600 define(USER_FLAG_S_DOG, 0x300); // done
601 define(USER_FLAG_S_EAT, 0x400); // done
602 define(USER_FLAG_S_WRK, 0x500); // done
603 define(USER_FLAG_S_SMK, 0x600); // done
604 define(USER_FLAG_S_EYE, 0x700); // done
605 define(USER_FLAG_S_RABB, 0x800); // done
606 define(USER_FLAG_S_SOCC, 0x900); // done
607 define(USER_FLAG_S_BABY, 0xa00); // done
608 define(USER_FLAG_S_MOP, 0xb00); // done
610 define(USER_FLAG_S_ALL, 0xf00); // done
612 /* type of user normal, supporter etc ... */
613 define(USER_FLAG_TY_ALL, 0xff0000); // done
614 define(USER_FLAG_TY_NORM, 0x010000); // done
615 define(USER_FLAG_TY_SUPER, 0x020000); // done
616 // ... other usefull status ...
617 define(USER_FLAG_TY_SUSPEND, 0x400000); // done
618 define(USER_FLAG_TY_DISABLE, 0x800000); // done
621 var $idx; // index in the users array when you are in game
622 var $idx_orig; // index in the users array when you aren't in game
623 var $code; // authentication code
624 var $name; // name of the user
625 var $sess; // session of the user
626 var $ip; // ip of the user
627 var $lacc; // last access (for the cleanup)
628 var $laccwr; // last access (for the cleanup)
629 var $bantime; // timeout to temporary ban
630 var $stat; // status (outdoor, room, table, game, ...)
631 var $subst; // substatus for each status
632 var $step; // step of the current status
633 var $trans_step; // step to enable transition between pages (disable == -1)
634 var $comm; // commands array
635 // var $asta_card; //
637 // var $handpt; // Total card points at the beginning of the current hand.
638 // var $exitislock; // Player can exit from the table ?
640 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
641 // it is allways ZERO
642 var $table; // id of the current table when you are in game
643 var $table_orig; // id of the current table when you aren't in game
644 var $table_pos; // idx on the table
645 var $table_token;// token that identify a game on a table
646 var $flags; // Bitfield with: AUTHENTICATE: 0x02
647 var $the_end; // Flag to change the end of the session
649 var $chat_lst; // Last chat line
650 var $chattime; // Array of chat times
651 var $chat_cur; // Current chat line number
652 var $chat_ban; // Time for ban chat
653 var $chat_dlt; // Delta t for ban
659 function create($idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
660 if (($thiz = new User()) == FALSE)
664 $thiz->idx_orig = $idx;
669 $thiz->lacc = time();
670 $thiz->laccwr = time();
673 $thiz->subst = $subst;
675 $thiz->trans_step = -1;
676 $thiz->comm = array();
677 $thiz->asta_card = -2;
678 $thiz->asta_pnt = -1;
680 $thiz->exitislock = TRUE;
684 $thiz->chattime = array_fill(0, CHAT_N, 0);
686 $thiz->chat_lst = "";
690 $thiz->table_orig = $table;
691 $thiz->table = $table;
692 $thiz->table_pos = -1;
693 $thiz->table_token= "";
694 $thiz->shm_sz = SHM_DIMS_U_MIN;
700 $this->idx = $from->idx;
701 $this->idx_orig = $from->idx;
702 $this->code = $from->code;
703 $this->name = $from->name;
704 $this->sess = $from->sess;
705 $this->ip = $from->ip;
706 $this->lacc = $from->lacc;
707 $this->laccwr = $from->laccwr;
708 $this->bantime = $from->bantime;
709 $this->stat = $from->stat;
710 $this->subst = $from->subst;
711 $this->step = $from->step;
712 $this->trans_step = $from->trans_step;
713 $this->comm = array();
715 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
716 for ($i = $i_start ; $i < $from->step ; $i++) {
718 if (isset($from->comm[$ii])) {
719 $this->comm[$ii] = $from->comm[$ii];
722 $this->asta_card = $from->asta_card;
723 $this->asta_pnt = $from->asta_pnt;
724 $this->handpt = $from->handpt;
725 $this->exitislock = $from->exitislock;
727 $this->flags = $from->flags;
729 $this->chattime = array();
730 for ($i = 0 ; $i < CHAT_N ; $i++)
731 $this->chattime[$i] = $from->chattime[$i];
732 $this->chat_cur = $from->chat_cur;
733 $this->chat_lst = $from->chat_lst;
734 $this->chat_ban = $from->chat_ban;
735 $this->chat_dlt = $from->chat_dlt;
737 $this->table_orig = $from->table_orig;
738 $this->table = $from->table;
739 $this->table_pos = $from->table_pos;
740 $this->table_token = $from->table_token;
741 $this->the_end = $from->the_end;
742 $this->shm_sz = $from->shm_sz;
747 function myclone($from)
749 if (($thiz = new User()) == FALSE)
757 function spawn($from, $table, $table_pos)
759 if (($thiz = new User()) == FALSE)
762 $thiz->idx = $from->idx;
763 $thiz->idx_orig = $from->idx;
764 $thiz->code = $from->code;
765 $thiz->name = $from->name;
766 $thiz->sess = $from->sess;
767 $thiz->ip = $from->ip;
768 $thiz->lacc = $from->lacc;
769 $thiz->laccwr = $from->laccwr;
770 $thiz->bantime = $from->bantime;
771 $thiz->stat = $from->stat;
772 $thiz->subst = $from->subst;
773 $thiz->step = $from->step;
774 $thiz->trans_step = $from->trans_step;
775 $thiz->comm = array();
778 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
779 for ($i = $i_start ; $i < $from->step ; $i++) {
780 log_wr("TRY PUSH:".$i);
782 $thiz->comm[$ii] = $from->comm[$ii];
785 $thiz->asta_card = $from->asta_card;
786 $thiz->asta_pnt = $from->asta_pnt;
787 $thiz->handpt = $from->handpt;
788 $thiz->exitislock = $from->exitislock;
789 $thiz->the_end = $from->the_end;
791 $thiz->flags = $from->flags;
793 $thiz->chattime = array_fill(0, CHAT_N, 0);
795 $thiz->chat_lst = "";
800 $thiz->table_orig = $table;
802 $thiz->table_pos = $table_pos;
803 $thiz->table_token = $from->table_token;
804 $thiz->shm_sz = $from->shm_sz;
813 function code_get() {
814 return ($this->code);
817 function stat_set($stat) {
818 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
819 $this->stat = "$stat";
822 if (validate_sess($this->sess)) {
823 if (file_exists(PROXY_PATH) == FALSE)
824 mkdir(PROXY_PATH, 0775, TRUE);
825 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
826 fwrite($fp, sprintf("%s\n",$this->stat));
832 function step_set($step)
834 $this->step = $step & 0x7fffffff;
839 function step_inc($delta = 1) {
840 $this->step += $delta;
841 /* modularization because unpack() not manage unsigned 32bit int correctly */
842 $this->step &= 0x7fffffff;
850 if (validate_sess($this->sess) == FALSE)
852 if (file_exists(PROXY_PATH) == FALSE)
853 mkdir(PROXY_PATH, 0775, TRUE);
854 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
856 fwrite($fp, pack("LL",$this->step, $this->idx));
859 log_main("step_set [".$this->sess. "] [".$this->step."]");
867 static function load_step($sess)
871 if (validate_sess($sess) == FALSE)
874 if (file_exists(PROXY_PATH) == FALSE)
875 mkdir(PROXY_PATH, 0775, TRUE);
876 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
878 if (($s = fread($fp, 8)) == FALSE)
880 if (mb_strlen($s, "ASCII") != 8)
882 $arr = unpack('Ls/Li', $s);
885 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
892 log_rd2("STEP_GET [".$sess."]: return false ");
897 static function unproxy_step($sess) {
898 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
899 if (file_exists(PROXY_PATH) == FALSE)
901 @unlink(PROXY_PATH."/".$sess.".step");
906 log_legal($curtime, $this, "STAT:LOGOUT", '');
908 $tmp_sess = $this->sess;
910 self::unproxy_step($tmp_sess);
911 $this->name = ""; // OK here
912 while (array_pop($this->comm) != NULL);
914 $this->chattime = array_fill(0, CHAT_N, 0);
916 $this->chat_lst = "";
919 $this->the_end = FALSE;
922 static function load_data($id, $sess)
924 log_main("load_data: id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
927 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
928 log_main("ftok failed");
932 if (($shm_sz = sharedmem_sz($tok)) == -1) {
933 log_main("shmop_open failed");
937 $shm_sz = SHM_DIMS_U_MIN;
939 if ($shm = shm_attach($tok, $shm_sz)) {
940 if (($user = @shm_get_var($shm, $tok)) == FALSE) {
943 if ($sess != FALSE && $user->sess != $sess) {
946 log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
948 if ($user == FALSE) {
949 log_only("INIT MAIN DATA");
951 // SHSPLIT FIXME: init_data for User class ??
952 $user = User::create($id, "", "");
953 if (@shm_put_var($shm, $tok, $user) == FALSE) {
954 log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
955 log_only(serialize($user));
957 log_shme("User::save_data2");
960 if ($sess != FALSE) {
962 * NOTE: this part is for check only, theoretically
963 * user->step anch proxy_step are set allways at the same value
965 $old_step = $user->step;
966 $arr = User::load_step($sess);
967 $user->step = $arr['s'];
968 if ($old_step != $user->step) {
969 log_crit("steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
973 $user->shm_sz = $shm_sz;
979 // SHSPLIT: load users from the shared memory
988 static function save_data($user, $id)
994 if (($tok = @ftok(FTOK_PATH."/user".$id, "B")) == -1) {
997 while ($user->shm_sz < SHM_DIMS_U_MAX) {
998 if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
1001 // log_only("PUT_VAR DI ".strlen(serialize($user)));
1002 if (@shm_put_var($shm, $tok, $user) != FALSE) {
1004 if ($user->sess != "")
1007 log_shme("User::save_data");
1009 log_main("User[".$id."] saved.");
1012 if (shm_remove($shm) === FALSE) {
1013 log_only("REMOVE FALLITA");
1017 $user->shm_sz += SHM_DIMS_U_DLT;
1036 var $comm; // commands for many people
1037 var $step; // current step of the comm array
1038 // externalized var $garbage_timeout;
1042 $this->user = array();
1043 $this->table = array();
1045 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1046 $this->user[$i] = User::create($i, "", "");
1049 for ($i = 0 ; $i < TABLES_N ; $i++) {
1050 $this->table[$i] = Table::create($i);
1053 $row = ( (((int)($i / 4)) % 2) == 0 );
1054 $col = ($i % 2 == 0);
1055 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
1058 $this->table[$i]->auth_only = FALSE;
1061 if ($i < TABLES_AUTH_N)
1062 $this->table[$i]->auth_only = TRUE;
1064 $this->table[$i]->auth_only = FALSE;
1066 // externalized $this->garbage_timeout = 0;
1067 Room::garbage_time_expire_set(0);
1068 $this->shm_sz = SHM_DIMS_MIN;
1071 function garbage_manager($force)
1073 GLOBAL $G_lang, $mlang_brisk, $G_base;
1077 log_rd2("garbage_manager START");
1079 /* Garbage collector degli utenti in timeout */
1082 // externalized if ($force || $this->garbage_timeout < $curtime) {
1083 if (!$force && !Room::garbage_time_is_expired($curtime)) {
1087 // FIXME BRISK4: include for each kind of table
1088 require_once("${G_base}briskin5/Obj/briskin5.phh");
1090 // Before all align times with table timeout
1091 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1092 $table_cur = $this->table[$table_idx];
1093 // if the table is complete and exists its shared mem we get the info about users lacc
1095 if ($table_cur->player_n == PLAYERS_N) {
1096 log_main("PLAYERS == N TABLE ".$table_idx);
1098 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1099 log_main("bin5 lock data success");
1101 $no_recovery = FALSE;
1102 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1103 if ($table_cur->table_token != $bri->table_token) {
1104 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1105 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
1106 $no_recovery = TRUE;
1111 if ($bri != FALSE) {
1115 log_main("garbage_manager: bri loaded successfully.");
1116 $bri->garbage_manager(TRUE);
1118 $bri_table = $bri->table[0];
1120 // is the end of the table
1121 if ($bri->the_end == TRUE) {
1123 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
1125 log_main("garbage_manager: INSIDE THE END.");
1127 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
1128 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1129 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1132 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1133 // stat must be "table" by definition
1134 $user_cur = $this->user[$table_cur->player[$i]];
1135 $bri_user = $bri->user[$i];
1137 $user_cur->subst = $bri_user->subst;
1138 $user_cur->step = $bri_user->step;
1139 $user_cur->lacc = $bri_user->lacc;
1140 $user_cur->laccwr = $bri_user->lacc;
1141 $user_cur->bantime = $bri_user->bantime;
1144 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
1146 $this->room_join_wakeup($user_cur, FALSE, 0);
1147 $table_cur->table_token = "";
1148 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
1150 $bri->destroy_data($table_idx);
1153 log_main("gm:: save_data");
1155 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1156 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
1159 Bin5::save_data($bri);
1161 } // else if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1162 else if ($no_recovery == FALSE) {
1163 log_crit("ERROR: table ".$table_idx." unrecoverable join");
1165 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1166 $user_cur = $this->user[$table_cur->player[$i]];
1167 $user_cur->subst = "shutdowner";
1168 $user_cur->step_inc();
1170 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
1171 $ret .= "gst.st = ".($user_cur->step+1)."; ";
1172 // MLANG <br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>
1173 $prestr = sprintf($mlang_brisk['tabincon'][$G_lang], $user_cur->table);
1174 $ret .= show_notify($prestr, 2000, $mlang_brisk['btn_close'][$G_lang], 400, 110);
1175 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1176 $user_cur->step_inc();
1179 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
1180 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1181 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1183 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
1185 $this->room_join_wakeup($user_cur, TRUE, -2);
1186 $table_cur->table_token = "";
1189 Bin5::unlock_data($sem);
1191 } // if ($table_cur->player_n == PLAYERS_N) {
1192 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1194 log_rd2("out new loop.");
1196 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1197 $user_cur = $this->user[$i];
1199 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1201 if ($user_cur->sess == "")
1204 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1205 // Auto logout dell'utente
1206 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1208 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1209 log_auth($user_cur->sess, "Autologout session.");
1213 log_rd2("AUTO LOGOUT.");
1214 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1215 $this->room_wakeup($user_cur);
1216 else if ($user_cur->subst == 'standup')
1217 $this->room_outstandup($user_cur);
1219 log_rd2("LOGOUT FROM WHAT ???");
1223 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1224 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1225 $this->room_wakeup($user_cur);
1226 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1227 /* 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" */
1228 $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);
1229 $user_cur->step_inc();
1233 log_rd2("GARBAGE UPDATED!");
1235 // externalized $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1236 Room::garbage_time_expire_set($curtime + GARBAGE_TIMEOUT);
1242 function show_room($user_step, $user)
1244 GLOBAL $G_lang, $mlang_brisk;
1245 log_main("show_room: username: ".$user->name);
1247 $ret = sprintf('gst.st = %d; ', $user_step);
1249 if ($user->flags & USER_FLAG_ISOLAUTH) {
1250 $ret .= 'list_set(\'isolation\', false, \''.$mlang_brisk['tit_onisol'][$G_lang].'\' ); ';
1252 else if ($user->flags & USER_FLAG_LISTAUTH) {
1253 $ret .= 'list_set(\'auth\', false, \''.$mlang_brisk['tit_onauth'][$G_lang].'\' ); ';
1256 $ret .= 'list_set(\'all\', false, \'\' ); ';
1259 if ($user->subst == 'standup')
1260 $ret .= "tra.show(); ";
1262 $ret .= "tra.hide(); ";
1264 $ret .= sprintf('stat = "%s";', $user->stat);
1266 $ret .= root_wellcome($user);
1267 if ($user->flags & USER_FLAG_DBFAILED) {
1268 $ret .= "gst.st = ".($user->step+1)."; ";
1269 $ret .= show_notify($mlang_brisk['db_failed'][$G_lang], 0, $mlang_brisk['btn_close'][$G_lang], 400, 140);
1272 $ret .= sprintf('subst = "%s";', $user->subst);
1273 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1274 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1275 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1276 for ($i = 0 ; $i < TABLES_N ; $i++) {
1278 $ret .= $this->table_content($user, $i);
1279 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1280 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1281 $ret .= $this->table[$i]->act_content($user);
1282 if ($this->table[$i]->wag_own != -1)
1283 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->user[$this->table[$i]->wag_own]->name, $this->table[$i]->wag_com);
1285 $ret .= sprintf('tra.rem(%d); ', $i);
1287 $ret .= $this->standup_content($user);
1293 function room_wakeup($user)
1295 $table_idx = $user->table;
1296 $table = $this->table[$table_idx];
1298 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1302 $from_table = ($user->stat == "table");
1304 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1306 for ($i = 0 ; $i < $table->player_n ; $i++) {
1307 $user_cur = $this->user[$table->player[$i]];
1308 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1310 if ($user->idx_get() != $table->player[$i]) {
1311 $user_cur->stat_set("room");
1312 $user_cur->subst = "sitdown";
1313 $user_cur->laccwr = $curtime;
1315 else if ($user->sess != "") {
1316 $user_cur->stat_set("room");
1317 $user_cur->subst = "standup";
1318 $user_cur->laccwr = $curtime;
1319 $user_cur->table = -1;
1324 $user->stat_set("room");
1325 $user->subst = "standup";
1326 $user->laccwr = $curtime;
1329 $remove_wagon = FALSE;
1330 if($table->wag_own == $user->idx_get()) {
1331 $table->wag_reset($curtime);
1332 $remove_wagon = TRUE;
1336 /* aggiorna l'array dei giocatori al tavolo. */
1337 $table->user_rem($this, $user);
1339 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1340 $user_cur = $this->user[$i];
1341 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1344 // log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1346 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1347 if ($from_table && ($user_cur->table == $table_idx || $user->idx_get() == $i)) {
1348 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1349 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1350 log_main("DOCUMENT.index.php: from table");
1352 else if ($user_cur->stat == "room") {
1353 log_main("DOCUMENT.index.php: from table");
1355 $ret .= $this->table_content($user_cur, $table_idx);
1356 $ret .= $this->standup_content($user_cur);
1358 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1359 $ret .= $table->act_content($user);
1361 if ($user->idx_get() == $i) {
1362 // set the new status
1363 $ret .= 'subst = "standup"; tra.show(); ';
1364 // clean the action buttons in other tables
1365 for ($e = 0 ; $e < TABLES_N ; $e++) {
1366 if ($this->table[$e]->player_n < PLAYERS_N) {
1367 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1368 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1369 $ret .= $this->table[$e]->act_content($user);
1374 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1375 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1376 $ret .= $table->act_content($user_cur);
1379 log_wr("ROOM_WAKEUP: ".$ret);
1380 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1381 $user_cur->step_inc();
1385 function room_join_wakeup($user, $update_lacc = FALSE, $trans_delta)
1387 $table_idx = $user->table;
1388 $table = $this->table[$table_idx];
1390 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1393 $user_wup = array();
1395 $user_tab = array();
1397 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1399 for ($i = 0 ; $i < $table->player_n ; $i++) {
1400 $user_cur = $this->user[$table->player[$i]];
1401 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1402 if ($user_cur->sess != "") {
1403 if ($update_lacc == TRUE) {
1404 $user_cur->laccwr = $curtime;
1406 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1407 if ($user_cur->subst == "shutdowned") {
1408 $user_cur->stat_set("room");
1409 $user_cur->subst = "sitdown";
1411 else if ($user_cur->subst == "shutdowner") {
1412 $user_cur->stat_set("room");
1413 $user_cur->subst = "standup";
1414 $user_cur->table = -1;
1415 $user_wup[$user_wup_n++] = $user_cur;
1417 $remove_wagon = FALSE;
1418 if($table->wag_own == $table->player[$i]) {
1419 $remove_wagon = TRUE;
1420 $table->wag_reset($curtime);
1423 $user_tab[$user_tab_n++] = $table->player[$i];
1427 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1428 $table->user_rem($this, $user_wup[$wup_idx]);
1430 /* aggiorna l'array dei giocatori al tavolo. */
1432 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1433 log_main("START LOOP");
1434 $user_cur = $this->user[$i];
1435 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1436 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1441 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx);
1443 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1444 if ($user_cur->stat == "room") {
1445 log_main("DOCUMENT.index.php from table");
1447 $ret .= $this->table_content($user_cur, $table_idx);
1448 $ret .= $this->standup_content($user_cur);
1450 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1451 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1452 $ret .= $table->act_content($user_cur);
1455 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1456 if ($user_tab[$tab_idx] == $i)
1459 // for users that wakeup the room will be reconstructed by index_rd.php
1460 if ($tab_idx < $user_tab_n) {
1461 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1463 // ARRAY_POP DISABLED
1464 // if ($trans_delta == 0)
1465 // while (array_pop($user_cur->comm) != NULL);
1467 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1468 $user_cur->comm[$user_cur->step % COMM_N] = "";
1469 $user_cur->step_inc();
1470 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), $user_cur);
1471 $user_cur->step_inc();
1472 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1476 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1478 log_main("JOIN_WAKEUP more");
1479 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1480 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1481 $ret .= $table->act_content($user_cur);
1483 log_main("JOIN_WAKEUP end more");
1485 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1486 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1487 $user_cur->step_inc();
1491 function room_outstandup($user)
1493 $this->room_sitdown($user, -1);
1496 function table_update($user)
1498 log_main("table_update: pre - USER: ".$user->name);
1500 $table_idx = $user->table;
1502 if ($table_idx > -1)
1503 $table = $this->table[$table_idx];
1505 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1507 $user_cur = $this->user[$i];
1508 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1511 $ret = "gst.st = ".($user_cur->step+1)."; ";
1512 if ($table_idx > -1)
1513 $ret .= $this->table_content($user_cur, $table_idx);
1515 if ($user->idx_get() == $i) {
1516 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1517 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1518 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1520 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1521 $user_cur->step_inc();
1524 log_main("table_update: post");
1527 function room_sitdown($user, $table_idx)
1529 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1533 if ($table_idx > -1 && $table_idx < TABLES_N) {
1534 $table = $this->table[$table_idx];
1537 if ($table->wag_own != -1 && $table->player_n == PLAYERS_N) {
1538 for ($i = 0 ; $i < TABLES_N ; $i++) {
1539 if ($table->wag_own == $table->player[$i]) {
1540 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1541 $table->wag_reset(time());
1548 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1550 $user_cur = $this->user[$i];
1551 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1554 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1555 if ($table_idx > -1)
1556 $ret .= $this->table_content($user_cur, $table_idx);
1557 $ret .= $this->standup_content($user_cur);
1559 if ($user->idx_get() == $i) {
1560 $ret .= 'subst = "sitdown"; tra.hide(); ';
1561 // clean the action buttons in other tables
1562 for ($e = 0 ; $e < TABLES_N ; $e++) {
1563 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1564 $ret .= $this->table[$e]->act_content($user_cur);
1567 else if ($table_idx > -1) {
1568 if ($table->player_n == PLAYERS_N) {
1569 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1570 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1571 $ret .= $table->act_content($user_cur);
1574 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1575 $user_cur->step_inc();
1579 function chatt_send($user, $mesg)
1581 GLOBAL $G_base, $G_alarm_passwd, $mlang_brisk, $G_lang;
1585 $msg = substr($mesg, 6, 128);
1587 $dt = date("H:i ", $curtime);
1598 $is_normchat = FALSE;
1599 /* for old isolation management $is_ticker = FALSE; */
1600 $update_room = FALSE;
1602 if (strcmp($msg, "/tav") == 0 ||
1603 strncmp($msg, "/tav ", 5) == 0) {
1605 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1606 /* 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>" */
1607 $msg = $mlang_brisk['tickmust'][$G_lang];
1608 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1613 $table = $this->table[$user->table];
1615 if ($table->wag_own != -1) {
1616 // MLANG <br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>
1617 $msg = $mlang_brisk['tickjust'][$G_lang];
1618 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1623 $dtime = $curtime - $table->wag_tout;
1624 if ($dtime < EXPIRE_TIME_WAG) {
1625 // MLANG - <br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>
1626 $msg = sprintf($mlang_brisk['tickwait'][$G_lang],
1627 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? ($G_lang == 'en' ? "" : "o") : ($G_lang == 'en' ? "s" : "i")));
1628 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang] , 400, 100);
1633 $msg = substr($msg, 5);
1635 $table->wag_set($user->idx_get(), $msg);
1636 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1637 $to_room = $to_user;
1638 /* for old isolation management $is_ticker = TRUE; */
1640 } // /tav chat command
1642 else if (strncmp($msg, "/alarm ", 7) == 0) {
1643 if (strncmp($msg, "/alarm to ", 10) == 0) {
1644 $sp_pos = strpos($msg, " ", 10);
1645 $target = substr($msg, 10, $sp_pos - 10);
1646 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1650 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1653 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1654 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1655 $msg = $mlang_brisk['alarpass'][$G_lang];
1656 $to_user = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 100);
1661 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1662 $prestr = sprintf($mlang_brisk['alarret'][$G_lang], xcape(substr($msg, strlen($alarm_check))),
1663 ($target == "" ? $mlang_brisk['tit_all'][$G_lang] : xcape($target)) );
1664 $to_user = sprintf('chatt_sub("%s", [2, "%s"],%s);',
1665 $dt, NICKSERV, $prestr);
1667 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1668 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1669 /* MLANG: "chiudi" */
1670 $to_all = show_notify($msg, 0, $mlang_brisk['btn_close'][$G_lang], 400, 120);
1672 } // /alarm chat command
1673 else if (strncmp($msg, "/listen ", 8) == 0) {
1674 $arg = substr($msg, 8);
1676 if (strcasecmp($arg, "isolation") == 0) {
1678 if ($user->stat == 'room' && $user->subst == 'sitdown' &&
1679 $user->table >= TABLES_AUTH_N) {
1680 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['listmust'][$G_lang]);
1684 $user->flags &= ~USER_FLAG_MAP_AUTH;
1685 $user->flags |= USER_FLAG_ISOLAUTH;
1686 $to_user = 'list_set(\'isolation\', true, \''.$mlang_brisk['tit_onisol'][$G_lang].'\'); ';
1689 else if (strcasecmp($arg, "auth") == 0) {
1690 $flags_old = $user->flags;
1691 $user->flags &= ~USER_FLAG_MAP_AUTH;
1692 $user->flags |= USER_FLAG_LISTAUTH;
1693 $to_user = 'list_set(\'auth\', true, \''.$mlang_brisk['tit_onauth'][$G_lang].'\'); ';
1696 $flags_old = $user->flags;
1697 $user->flags &= ~USER_FLAG_MAP_AUTH;
1698 $to_user = 'list_set(\'all\', true, \'\'); ';
1701 // if from isolation redraw standup area
1702 if (($flags_old ^ $user->flags) & USER_FLAG_ISOLAUTH) {
1703 $to_user .= 'standup_data_old = null; '.$this->standup_content($user);
1707 else if (strcmp($msg, "/authreq") == 0) {
1708 if ($user->flags & USER_FLAG_AUTH) {
1709 $to_user = sprintf('authbox(300,200);');
1712 /* 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." */
1713 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authmust'][$G_lang]);
1716 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1717 if ($user->flags & USER_FLAG_AUTH) {
1718 $to_user = sprintf('mesgtoadmbox(500,300);');
1721 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1722 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['mesgmust'][$G_lang]);
1725 else if (strncmp($msg, "/nick ", 6) == 0) {
1726 log_main("chatt_send BEGIN");
1729 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1730 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1734 $msg = "COMMAND ".$msg;
1735 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1736 $user_cur = $this->user[$i];
1738 if ($user_cur->sess == '')
1740 if ($user_cur->name == $name_new)
1743 if ($i < MAX_PLAYERS) {
1744 $prestr = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1745 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1749 /* 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>" */
1750 if ($user->flags & USER_FLAG_AUTH) {
1751 if (strcasecmp($user->name,$name_new) != 0) {
1752 if (( ($user->flags & USER_FLAG_MAP_AUTH) != USER_FLAG_ISOLAUTH) &&
1753 ($user->subst == 'standup' ||
1754 ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)
1757 $user->flags &= ~(USER_FLAG_AUTH | USER_FLAG_TY_ALL); // Remove auth if name changed
1758 for ($i = 0 ; $i < TABLES_N ; $i++) {
1759 $to_user .= $this->table[$i]->act_content($user);
1763 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1768 $user->name = $name_new; // OK - nick changed
1769 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1770 if (($user->flags & USER_FLAG_AUTH) == 0) {
1771 if (($bdb = BriskDB::create()) != FALSE) {
1773 /* 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>" */
1774 if ($bdb->login_exists($name_new)) {
1775 $prestr = sprintf($mlang_brisk['nickjust'][$G_lang], xcape($name_new));
1776 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $prestr);
1781 log_main("chatt_send start set");
1783 $update_room = TRUE;
1785 } // nick chat command
1787 else if (strncmp($msg, "/st ", 4) == 0) {
1788 log_main("chatt_send BEGIN");
1791 $st_str = substr($msg, 4);
1793 if (strcasecmp($st_str, "normale") == 0) {
1794 $st = USER_FLAG_S_NORM;
1796 else if (strcasecmp($st_str, "pausa") == 0) {
1797 $st = USER_FLAG_S_PAU;
1799 else if (strcasecmp($st_str, "fuori") == 0) {
1800 $st = USER_FLAG_S_OUT;
1802 else if (strcasecmp($st_str, "cane") == 0) {
1803 $st = USER_FLAG_S_DOG;
1805 else if (strcasecmp($st_str, "cibo") == 0) {
1806 $st = USER_FLAG_S_EAT;
1808 else if (strcasecmp($st_str, "lavoro") == 0) {
1809 $st = USER_FLAG_S_WRK;
1811 else if (strcasecmp($st_str, "sigaretta") == 0) {
1812 $st = USER_FLAG_S_SMK;
1814 else if (strcasecmp($st_str, "presente") == 0) {
1815 $st = USER_FLAG_S_EYE;
1817 else if (strcasecmp($st_str, "coniglio") == 0) {
1818 $st = USER_FLAG_S_RABB;
1820 else if (strcasecmp($st_str, "calcio") == 0) {
1821 $st = USER_FLAG_S_SOCC;
1823 else if (strcasecmp($st_str, "pupo") == 0) {
1824 $st = USER_FLAG_S_BABY;
1826 else if (strcasecmp($st_str, "pulizie") == 0) {
1827 $st = USER_FLAG_S_MOP;
1830 /* MLANG: "Questo stato non esiste." */
1831 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"%s");', $dt, NICKSERV, $mlang_brisk['statunkn'][$G_lang]);
1835 log_main("chatt_send start set");
1836 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1837 $update_room = TRUE;
1838 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1841 } // nick chat command
1843 else { // normal chat line
1844 $is_normchat = TRUE;
1845 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1847 $user->chat_dlt = $user->chat_dlt * 2;
1848 if ($user->chat_dlt > 120)
1849 $user->chat_dlt = 120;
1851 else if ($user->chat_lst == $msg)
1853 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1854 $user->chat_ban = $curtime;
1855 $user->chat_dlt = 5;
1859 $user->chat_ban = 0;
1860 $user->chat_dlt = 0;
1864 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1867 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1868 // temporary silentiation for troll (will became array check)
1869 // if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1870 $to_room = $to_user;
1873 log_legal($curtime, $user,
1874 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1876 $user->chat_lst = "$msg";
1877 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1887 // Output to clients
1890 if ($to_user != FALSE) {
1891 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1892 $user->comm[$user->step % COMM_N] .= $to_user;
1896 if ($to_room != FALSE) {
1897 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1898 $user_cur = $this->user[$i];
1899 if ($target != "" && $user_cur->name != $target)
1901 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user->idx_get() == $i)
1904 if ($is_normchat == TRUE) {
1905 // use MAP_AUTH to check if auth or isolation
1906 if ($user_cur->flags & USER_FLAG_MAP_AUTH) {
1907 if (($user->flags & USER_FLAG_AUTH) == 0) {
1913 else if ($is_ticker) {
1914 if (($user_cur->flags & USER_FLAG_MAP_AUTH) == USER_FLAG_ISOLAUTH) {
1915 if ($user->table >= TABLES_AUTH_N)
1920 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1921 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1922 $user_cur->step_inc();
1927 // FIXME BRISK4: include for each kind of table
1928 require_once("${G_base}briskin5/Obj/briskin5.phh");
1929 // Before all align times with table timeout
1930 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1931 $table_cur = $this->table[$table_idx];
1932 // if the table is complete and exists its shared mem we get the info about users lacc
1934 if ($table_cur->player_n == PLAYERS_N) {
1935 log_main("PLAYERS == N TABLE ".$table_idx);
1937 if (($sem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
1938 log_main("bin5 lock data success");
1940 $no_recovery = FALSE;
1941 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
1942 if ($table_cur->table_token != $bri->table_token) {
1943 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1948 if ($bri != FALSE) {
1949 $bri_table = $bri->table[0];
1950 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1951 // stat must be "table" by definition
1952 $bri_user = $bri->user[$i];
1954 if ($target != "" && $bri_user->name != $target)
1956 log_main("writa: ".$user_mesg);
1957 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1958 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1959 $bri_user->step_inc();
1961 Bin5::save_data($bri);
1963 Bin5::unlock_data($sem);
1965 } // if ($table_cur->player_n == PLAYERS_N) {
1966 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1967 } // if ($to_tabl == true ...
1970 if ($user->stat == 'room' && $user->subst == 'standup') {
1971 $this->standup_update($user);
1973 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1974 log_main("chatt_send pre table update");
1975 $this->table_update($user);
1976 log_main("chatt_send post table update");
1978 } // if ($update_room ...
1981 } // function chatt_send( ...
1983 function get_user($sess, &$idx)
1987 if (validate_sess($sess)) {
1988 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1989 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1992 $ret = $this->user[$i];
1996 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1997 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1998 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
2001 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
2008 * function add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
2011 * if ($idx > -1 && ret == FALSE) => duplicated nick
2012 * if ($idx == -2 && ret == FALSE) => invalid name
2013 * if ($idx == -3 && ret == FALSE) => wrong password
2014 * if ($idx == -1 && ret == FALSE) => no space left
2015 * if ($idx == 0 && ret == user) => SUCCESS
2016 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db)
2019 function add_user(&$sess, &$idx, $name, $pass, $ip)
2021 GLOBAL $G_base, $CO_list;
2025 $authenticate = FALSE;
2027 $login_exists = FALSE;
2029 $ghost_auth = FALSE;
2034 if (($name_new = validate_name($name)) == FALSE) {
2039 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
2040 if (validate_sess($sess) == FALSE)
2043 /* if pass != FALSE verify the login with pass */
2044 log_auth("XXX", "auth1");
2046 if (($bdb = BriskDB::create()) != FALSE) {
2048 if ($pass != FALSE) { // TODO: here add a method to $bdb to check if the db is available.
2049 log_auth("XXX", "auth2");
2050 $authenticate = $bdb->login_verify($name_new, $pass, $code);
2051 log_auth("XXX", "authenticate: ".($authenticate != FALSE ? "TRUE" : "FALSE"));
2053 if ($authenticate != FALSE) {
2054 $user_type = $authenticate->type_get();
2062 $login_exists = $bdb->login_exists($name_new);
2066 // if db is down, send a warning and verify only current users
2067 // no actions at this moment
2069 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2071 if (strcmp($sess, $this->user[$i]->sess) == 0) {
2075 if ($idfree == -1 && strcmp($this->user[$i]->sess, "") == 0) {
2077 continue; // NOTE: CHECK IT !!
2079 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
2080 if ($authenticate != FALSE) {
2082 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
2093 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
2095 /* there is another user logged with your account and you and him have authenticated => che new user
2096 get the session of the old user */
2097 if ($ghost > -1 && $ghost_auth && ($authenticate != FALSE)) {
2100 $ghost_user = $this->user[$ghost];
2102 $ghost_user->step_inc();
2105 $ghost_user->sess = $sess;
2108 $ghost_user->sess = $sess;
2111 // If user at the table we need to update the table data too
2112 $table_idx = $ghost_user->table;
2113 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
2114 // FIXME BRISK4: include for each kind of table
2115 require_once("${G_base}briskin5/Obj/briskin5.phh");
2116 if (($brisem = Bin5::lock_data(TRUE, $table_idx)) != FALSE) {
2117 if (($bri = Bin5::load_data($table_idx)) != FALSE) {
2118 if ($bri->the_end != TRUE) {
2119 $bri->user[$ghost_user->table_pos]->step_inc();
2120 $bri->user[$ghost_user->table_pos]->sess = $sess;
2121 Bin5::save_data($bri);
2124 Bin5::unlock_data($brisem);
2129 return ($this->user[$ghost]);
2131 else if ($idx != -1 && $i == MAX_PLAYERS) {
2136 $this->user[$idx]->sess = $sess;
2139 $this->user[$idx]->sess = $sess;
2141 $this->user[$idx]->name = $name_new; // OK - add new user
2142 $this->user[$idx]->stat_set("room");
2143 $this->user[$idx]->step_set(0);
2144 while (array_pop($this->user[$idx]->comm) != NULL);
2145 $this->user[$idx]->subst = "standup";
2146 $this->user[$idx]->lacc = $curtime;
2147 $this->user[$idx]->laccwr = $curtime;
2148 $this->user[$idx]->bantime = 0;
2149 $this->user[$idx]->ip = $ip;
2151 $this->user[$idx]->flags = $user_type;
2152 $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00);
2153 $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00);
2154 log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags));
2157 if ($authenticate != FALSE) {
2158 $this->user[$idx]->code = $authenticate->code_get();
2159 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2161 if (isset($CO_list)) {
2162 if (strcmp($CO_list, "auth") == 0) {
2163 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2164 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
2166 if (strcmp($CO_list, "isolation") == 0) {
2167 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2168 $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH;
2171 $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH;
2177 log_main("ghost: rename!");
2178 $ghost_user = $this->user[$ghost];
2180 if ($ghost_auth == FALSE) {
2181 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
2182 $ghostname = 'ghost'.$sfx;
2183 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2184 if (strcmp("", $this->user[$i]->sess) == 0)
2187 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
2192 if ($ghostname != '')
2196 $ghost_user->name = $ghostname;
2198 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
2199 $this->standup_update($ghost_user);
2202 log_main("chatt_send pre table update");
2203 $this->table_update($ghost_user);
2204 log_main("chatt_send post table update");
2206 } // if ($ghost_auth == FALSE
2208 // FIXME: cacciare il vecchio utente room && table (if needed)
2209 $ghost_user->the_end = TRUE;
2210 $ghost_user->lacc = 0;
2211 $this->garbage_manager(TRUE);
2213 } // if ($ghost > -1) {
2218 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s] count [%d] name [%s] code [%s]", $idx, $sess, $name_new, count($this->user),$this->user[$real_idx]->name, $this->user[$real_idx]->code));
2220 $ret = $this->user[$real_idx];
2227 function standup_update($user)
2229 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2230 $user_cur = $this->user[$i];
2231 if ($user_cur->sess == '')
2234 log_main("STANDUP START: ".$user_cur->stat);
2236 if ($user_cur->stat == 'room') {
2237 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
2238 if ($user->idx_get() == $i) {
2239 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
2240 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
2242 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
2243 $itin, xcape($user->name), $itou);
2245 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
2247 $user_cur->step_inc();
2253 static function create()
2261 function load_data()
2266 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2267 log_main("ftok failed");
2271 if (($shm_sz = sharedmem_sz($tok)) == -1) {
2272 log_main("shmop_open failed");
2276 $shm_sz = SHM_DIMS_MIN;
2278 if ($shm = shm_attach($tok, $shm_sz)) {
2279 $room = @shm_get_var($shm, $tok); // CHECKED BELOW
2281 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
2283 log_only("bri count ".count($room));
2285 if ($room == FALSE) {
2286 log_only("INIT MAIN DATA");
2289 $room = Room::create();
2291 log_shme("Room::create");
2293 if (Room::save_data($room) == FALSE)
2298 $room->shm_sz = $shm_sz;
2302 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2303 if (($room->user[$i] = User::load_data($i, FALSE)) == FALSE) {
2304 log_crit("Bin5_user::load_data failed");
2308 if ($i < MAX_PLAYERS) {
2314 // SHSPLIT: load users from the shared memory
2323 function save_data_orig($room)
2331 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2334 while ($room->shm_sz < SHM_DIMS_MAX) {
2335 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2338 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2339 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2343 if (shm_remove($shm) === FALSE) {
2344 log_only("REMOVE FALLITA");
2348 $room->shm_sz += SHM_DIMS_DLT;
2358 function save_data($room)
2365 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2368 // SHSPLIT: before save the $room you must save users,
2369 // detach from main struct and (then) reattach
2370 $user_park = array();
2371 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2372 $user_park[$i] = $room->user[$i];
2373 $room->user[$i] = FALSE;
2376 while ($room->shm_sz < SHM_DIMS_MAX) {
2377 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2380 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2381 if (@shm_put_var($shm, $tok, $room) != FALSE) {
2382 log_shme("Room::save_data");
2386 if (shm_remove($shm) === FALSE) {
2387 log_only("REMOVE FALLITA");
2391 $room->shm_sz += SHM_DIMS_DLT;
2397 // SHSPLIT: reattach users to the room class
2398 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
2399 User::save_data($user_park[$i], $i);
2400 $room->user[$i] = $user_park[$i];
2402 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
2407 static function lock_data($is_exclusive)
2411 // echo "LOCK: ".FTOK_PATH."/main";
2413 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2416 // echo "FTOK ".$tok."<br>";
2417 if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) {
2420 if (sem_acquire($res)) {
2421 self::$delta_t = microtime(TRUE);
2422 log_lock("LOCK room [".self::$delta_t."]");
2430 static function unlock_data($res)
2434 log_lock("UNLOCK room [".(microtime(TRUE) - (self::$delta_t))."]");
2436 return (sem_release($res));
2440 function standup_content($user)
2445 if ($user->stat != 'room')
2448 for ($i = 0 , $ct = 0 ; $ct < 4 && $i < MAX_PLAYERS ; $i++) {
2449 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2454 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2456 $content = ' j_stand_cont( [ ';
2458 for ($i = 0 , $ct = 0 ; $i < MAX_PLAYERS ; $i++) {
2459 if ($this->user[$i]->sess == "" || $this->user[$i]->stat != "room" || $this->user[$i]->name == "")
2462 $flags = $this->user[$i]->flags;
2464 if ($this->user[$i]->subst == "standup") {
2465 if ($user->idx_get() == $i) {
2469 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$i]->name));
2478 function table_content($user, $table_idx)
2484 // Si possono usare i dati nella classe table
2487 $sess = $user->sess;
2488 $table = $this->table[$table_idx];
2490 if ($user->stat != 'room')
2494 for ($i = 0 ; $i < $table->player_n ; $i++) {
2495 $user_cur = $this->user[$table->player[$i]];
2497 $flags = $user_cur->flags;
2499 if ($user->idx_get() == $table->player[$i])
2502 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2504 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2509 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2514 static function garbage_time_is_expired($tm)
2519 if (file_exists(PROXY_PATH) == FALSE)
2520 mkdir(PROXY_PATH, 0775, TRUE);
2521 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE)
2523 if (($s = fread($fp, 4)) == FALSE)
2525 if (mb_strlen($s, "ASCII") != 4)
2527 $arr = unpack('Le', $s);
2528 if ($arr['e'] > $tm)
2535 log_rd2("END: return ".($ret ? "TRUE" : "FALSE"));
2540 static function garbage_time_expire_set($tm)
2543 if (file_exists(PROXY_PATH) == FALSE)
2544 mkdir(PROXY_PATH, 0775, TRUE);
2545 if (($fp = @fopen(PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE)
2547 fwrite($fp, pack("L",$tm));
2559 function make_seed()
2561 list($usec, $sec) = explode(' ', microtime());
2562 return (float) $sec + ((float) $usec * 100000);
2565 function btrace_line($ar)
2567 GLOBAL $G_btrace_pref_sub;
2570 for ($i = 0 ; $i < count($ar) ; $i++) {
2571 $with_class = isset($ar[$i]['class']);
2572 $with_file = isset($ar[$i]['file']);
2573 $ret .= sprintf("%s%s%s (%s:%d)", ($i == 0 ? "" : ", "),
2574 ($with_class ? $ar[$i]['class'].$ar[$i]['type'] : ""),
2575 $ar[$i]['function'], ($with_file ? str_replace($G_btrace_pref_sub, "", $ar[$i]['file']) : ""),
2576 ($with_file ? $ar[$i]['line'] : ""));
2582 function trace_ftok($id, $add)
2584 // NOTE: without space to use sed to substitute "= @ftok(" with "= @ftok("
2585 $tok=@ftok($id, $add);
2587 log_shme($tok.": ".$id." + ".$add);
2592 function log_mop($step, $log)
2594 GLOBAL $sess, $PHP_SELF;
2596 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LMOP) == 0)
2599 if (isset($sess) == FALSE)
2604 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LMOP) == 0)
2607 if (BRISK_DEBUG & DBG_TRAC)
2608 $btrace = btrace_line(debug_backtrace());
2611 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2612 fwrite($fp, sprintf("LMOP: [%f] [%05d] [%s] [%s]\n", gettimeofday(TRUE), $step, $log, $btrace));
2618 function log_only2($log)
2620 GLOBAL $sess, $PHP_SELF;
2622 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2625 if (isset($sess) == FALSE)
2630 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2633 if (BRISK_DEBUG & DBG_TRAC)
2634 $btrace = btrace_line(debug_backtrace());
2637 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2638 fwrite($fp, sprintf("ONL2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2643 function log_crit($log)
2645 GLOBAL $sess, $PHP_SELF;
2647 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2650 if (isset($sess) == FALSE)
2655 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2658 if (BRISK_DEBUG & DBG_TRAC)
2659 $btrace = btrace_line(debug_backtrace());
2662 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2663 fwrite($fp, sprintf("CRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2668 function log_only($log)
2670 GLOBAL $sess, $PHP_SELF;
2672 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2675 if (isset($sess) == FALSE)
2680 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2683 if (BRISK_DEBUG & DBG_TRAC)
2684 $btrace = btrace_line(debug_backtrace());
2687 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2688 fwrite($fp, sprintf("ONLY: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2693 function log_main($log)
2695 GLOBAL $sess, $PHP_SELF;
2697 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2700 if (isset($sess) == FALSE)
2705 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2708 if (BRISK_DEBUG & DBG_TRAC)
2709 $btrace = btrace_line(debug_backtrace());
2712 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2713 fwrite($fp, sprintf("MAIN: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2718 function log_rd($log)
2720 GLOBAL $sess, $PHP_SELF;
2722 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2725 if (isset($sess) == FALSE)
2730 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2733 if (BRISK_DEBUG & DBG_TRAC)
2734 $btrace = btrace_line(debug_backtrace());
2737 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2738 fwrite($fp, sprintf("READ: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2743 function log_rd2($log)
2745 GLOBAL $sess, $PHP_SELF;
2747 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2750 if (isset($sess) == FALSE)
2755 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2758 if (BRISK_DEBUG & DBG_TRAC)
2759 $btrace = btrace_line(debug_backtrace());
2763 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2764 fwrite($fp, sprintf("REA2: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2769 function log_send($log)
2771 GLOBAL $sess, $PHP_SELF;
2773 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2776 if (isset($sess) == FALSE)
2781 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2784 if (BRISK_DEBUG & DBG_TRAC)
2785 $btrace = btrace_line(debug_backtrace());
2788 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2789 fwrite($fp, sprintf("SEND: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2794 function log_lock($log)
2796 GLOBAL $sess, $PHP_SELF;
2798 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2801 if (isset($sess) == FALSE)
2806 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2809 if (BRISK_DEBUG & DBG_TRAC)
2810 $btrace = btrace_line(debug_backtrace());
2813 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2814 fwrite($fp, sprintf("LOCK: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2819 function log_wr($log)
2821 GLOBAL $sess, $PHP_SELF;
2823 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2826 if (isset($sess) == FALSE)
2831 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2834 if (BRISK_DEBUG & DBG_TRAC)
2835 $btrace = btrace_line(debug_backtrace());
2838 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2839 fwrite($fp, sprintf("WRIT: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2844 function log_load($log)
2846 GLOBAL $sess, $PHP_SELF;
2848 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2851 if (isset($sess) == FALSE)
2856 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2859 if (BRISK_DEBUG & DBG_TRAC)
2860 $btrace = btrace_line(debug_backtrace());
2863 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2864 fwrite($fp, sprintf("LOAD: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2869 function log_auth($sess, $log)
2873 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2876 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2879 if (BRISK_DEBUG & DBG_TRAC)
2880 $btrace = btrace_line(debug_backtrace());
2883 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2884 fwrite($fp, sprintf("LOAD: [%s] [%d] [%s] [%s]\n", $sess, time(), $log, $btrace));
2889 function log_shme($log)
2891 GLOBAL $sess, $PHP_SELF;
2893 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SHME) == 0)
2896 if (isset($sess) == FALSE)
2901 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SHME) == 0)
2904 if (BRISK_DEBUG & DBG_TRAC)
2905 $btrace = btrace_line(debug_backtrace());
2908 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2909 fwrite($fp, sprintf("SHME: [%s] [%s] [%s]\n", $ssess, $log, $btrace));
2916 // function log_legal($curtime, $sess, $name, $where, $mesg)
2917 function log_legal($curtime, $user, $where, $mesg)
2921 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2922 /* Unix time | session | nickname | IP | where was | mesg */
2923 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2924 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2925 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2930 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2935 if ($sitted < PLAYERS_N) {
2943 if ($table == $cur_table)
2950 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2955 function show_notify($text, $tout, $butt, $w, $h)
2957 log_main("SHOW_NOTIFY: ".$text);
2958 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2961 function show_notify_ex($text, $tout, $butt, $w, $h, $is_opaque, $block_time)
2963 log_main("SHOW_NOTIFY OPAQUE: ".$text);
2964 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);
2968 function root_wellcome($user)
2970 GLOBAL $root_wellarr, $G_lang;
2974 $dt = date("H:i ", $curtime);
2976 for ($i = 0 ; $i < count($root_wellarr[$G_lang]) ; $i++)
2977 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$G_lang][$i]));
2984 function validate_sess($sess)
2986 if (strlen($sess) == SESS_LEN)
2992 function validate_name($name)
2994 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2996 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2998 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
3005 function playsound($filename)
3007 return (sprintf('playsound("flasou", "%s");', $filename));
3010 function secstoword($secs)
3016 $mins = floor($secs / 60);
3018 if ($G_lang == 'en') {
3020 $ret = sprintf("%d minute%s%s", $mins, ($mins > 1 ? "s" : ""), ($secs > 0 ? " and " : ""));
3023 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "s" : ""));
3027 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
3030 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
3035 function sharedmem_sz($tok)
3037 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
3038 log_main("shmop_open failed");
3041 $shm_sz = shmop_size($shm_id);
3042 shmop_close($shm_id);
3044 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
3051 static function lock_data($is_exclusive)
3055 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
3058 // echo "FTOK ".$tok."<br>";
3059 if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) {
3062 if (sem_acquire($res)) {
3063 self::$delta_t = microtime(TRUE);
3064 log_lock("LOCK warrant [".self::$delta_t."]");
3071 static function unlock_data($res)
3075 log_lock("UNLOCK warrant [".(microtime(TRUE) - (self::$delta_t))."]");
3077 return (sem_release($res));
3084 static function lock_data($is_exclusive)
3088 if (($tok = @ftok(FTOK_PATH."/poll", "B")) == -1) {
3091 // echo "FTOK ".$tok."<br>";
3092 if (($res = sem_get($tok, ($is_exclusive ? 1 : LOCK_SHARE_MAX) )) == FALSE) {
3095 if (sem_acquire($res)) {
3096 self::$delta_t = microtime(TRUE);
3097 log_lock("LOCK poll [".self::$delta_t."]");
3105 static function unlock_data($res)
3109 log_lock("UNLOCK poll [".(microtime(TRUE) - (self::$delta_t))."]");
3111 return (sem_release($res));