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");
32 define(MAX_POINTS, 5);
33 define(MAX_PLAYERS, (20 + (PLAYERS_N * TABLES_N)));
34 define(SHM_DIMS_MIN, (50000 + 10000 * TABLES_N + 15000 * MAX_PLAYERS));
35 define(SHM_DIMS_MAX, SHM_DIMS_MIN + 1048576);
36 define(SHM_DIMS_DLT, 65536);
39 define(COMM_GEN_N, 50);
42 define(CHAT_ILL_TIME, 6);
45 define(STREAM_TIMEOUT, 20);
46 define(EXPIRE_TIME_RD, 180);
47 define(EXPIRE_TIME_SMAMMA, 360);
48 define(EXPIRE_TIME_WAG, 10);
49 define(WAKEUP_TIME, 12);
50 // BAN_TIME da allineare anche in commons.js
51 define(BAN_TIME, 3600);
52 define(GARBAGE_TIMEOUT, 10);
53 define(NICKSERV, "<i>BriskServ</i>");
55 define(DBG_ONL2, 0x0001);
56 define(DBG_ONLY, 0x0002);
57 define(DBG_MAIN, 0x0004);
58 define(DBG_READ, 0x0008);
59 define(DBG_REA2, 0x0010);
60 define(DBG_SEND, 0x0020);
61 define(DBG_LOCK, 0x0040);
62 define(DBG_WRIT, 0x0080);
63 define(DBG_LOAD, 0x0100);
64 define(DBG_AUTH, 0x0200);
65 define(DBG_CRIT, 0x0400);
67 // NOTE: BRISK DEBUG must be a numerical constant, not the result of operations on symbols
68 define(BRISK_DEBUG, 0xffffffbf);
70 define(BRISK_SINGLE_DEBUG,0);
71 define(BRISK_SINGLE_SESS, "");
72 // define(DEBUGGING, "local");
74 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
82 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
83 $G_brisk_version = "2.1.8 - trusty";
85 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
86 $root_wellarr = Array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: Sponsor alternati, menù rivisto, AUTO-GARANZIE, sondaggi quasi ultimati.',
87 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' );
90 <div style=\\"text-align: left; padding: 8px;\\">
91 <b>Descrizione</b><br>
92 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
93 <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>
94 <b>Configurazione del browser.</b><br>
95 Occorre abilitare i cookies.<br>
97 <b>Uso del sito</b><br>
98 Potete sedervi a un tavolo o rimanere in piedi.<br>
99 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
102 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>
103 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
104 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
105 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
106 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
107 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.
109 <dt><b>Comandi della chat</b>
110 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
111 <dd><b>/tav <i><frase di invito></i></b> - invito per gli altri giocatori al tavolo dove si è seduti
112 <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\\"
113 <dd><b>/garante</b> - se si è autenticati permette di garantire per un utente fidato
114 <dd><b>/mesgtoadm</b> - se si è autenticati permette di lasciare un messaggio all\'amministratore del sito
115 <dd><b>/listen <all or auth></b> - se si è autenticati permette leggere solo i messaggi degli altri autenticati (auth) o di tutti (all)
121 $G_room_passwdhowto= '<br><h2>Come registrarsi su Brisk</h2>
122 <div style=\\"text-align: left; padding: 8px;\\">
123 Attualmente ci sono due metodi per ottenere una password sul sito:<br><br>
125 <li><b>Facendosi garantire da un utente di Brisk che già possidede una password</b><br><br>
126 <li><b>Auto-garantendosi utilizzando uno dei seguenti sistemi di identificazione digitale:</b><br><br>
128 <li>Carta Regionale dei Servizi della Lombardia (la tessera sanitaria)
129 <li>Carta Regionale dei Servizi del Friuli Venezia Giulia (la tessera sanitaria)
132 <b>Per auto-garantisi occorre possedere:</b><br><br>
134 <li>il codice PIN della propria carta
135 <li>il lettore di smart-card per collegare la carta al PC (acquistabile di solito presso le edicole)
138 <b>Per effettuare la registrazione collegarsi al sito:</b><br><br>
140 <dd><a class=\\"flat\\" target=\\"_blank\\" href=\\"https://brisk.mine.nu\\">https://brisk.mine.nu</a>
143 Se sei in possesso di una carta che permette l\'identificazione via internet che non è nell\'elenco qui sopra
144 <a class=\\"flat\\" href=\\"mailto:authadmbrisk@alternativeoutput.it\\">fai una segnalazione</a>.
150 <dd>Seguendo la procedura di auto-garanzia all\'url: <a href="https://brisk.mine.nu">https://brisk.mine.nu</a>
155 <div id=\\"header\\" class=\\"header\\">
156 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
157 briscola chiamata in salsa ajax
159 <br><b>version '.$G_brisk_version.'</b><br><br>
160 Copyright 2006-2008 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
163 function csplitter($in, $sep)
169 for ($i = 0 ; $i < strlen($in) ; $i++) {
173 else if ($in{$i} == $sep) {
177 $out[$id] .= $in{$i};
181 $out[$id] .= $in{$i};
192 $from = array ( '\\', '@', '|' );
193 $to = array ( '\\\\', '@', '¦' );
195 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
200 $from = array ( '\\', '|', "\t", "\n");
201 $to = array ( '\\\\', '\\|', "\\t", "\\n");
203 return (str_replace($from, $to, $s));
206 function xcapemesg($s)
208 $from = array ( "\n");
209 $to = array ( "\\n");
211 return (str_replace($from, $to, $s));
220 var $auth_only; // se tavolo riservato o libero
227 var $table_start; // information field
235 function &create($idx)
239 if (($thiz =& new Table()) == FALSE)
243 $thiz->player = array();
245 $thiz->auth_only = FALSE;
247 $thiz->wag_own = NULL;
251 $thiz->table_token = "";
252 $thiz->table_start = 0;
254 $thiz->wakeup_time = 0;
259 function copy(&$from)
263 $this->idx = $from->idx;
264 $this->player = array();
265 for ($i = 0 ; $i < $from->player_n ; $i++)
266 $this->player[$i] = $from->player[$i];
267 $this->player_n = $from->player_n;
269 log_main("PLAYER_N - parent::copy.".$this->player_n);
271 $this->auth_only = $from->auth_only;
273 $this->wag_own = $from->wag_own;
274 $this->wag_com = $from->wag_com;
275 $this->wag_tout = $from->wag_tout;
277 $this->table_token = $from->table_token;
278 $this->table_start = $from->table_start;
280 $this->wakeup_time = $from->wakeup_time;
283 function &clone(&$from)
287 if (($thiz =& new Table()) == FALSE)
295 function &spawn(&$from)
299 if (($thiz =& new Table()) == FALSE)
302 $thiz->idx = $from->idx;
303 $thiz->player = array();
304 for ($i = 0 ; $i < $from->player_n ; $i++)
305 $thiz->player[$i] = $i;
306 $thiz->player_n = $from->player_n;
308 $thiz->auth_only = $from->auth_only;
310 $thiz->wag_own = $from->wag_own;
311 $thiz->wag_com = $from->wag_com;
312 $thiz->wag_tout = $from->wag_tout;
314 $thiz->table_token = $from->table_token;
315 $thiz->table_start = $from->table_start;
317 $thiz->wakeup_time = $from->wakeup_time;
322 function wag_set(&$user, $mesg)
326 $this->wag_own = &$user;
327 $this->wag_com = $mesg;
331 function wag_reset($timeout)
333 log_main("WAG_RESET");
335 unset($this->wag_own);
336 $this->wag_own = NULL;
338 $this->wag_tout = $timeout;
341 function getPlayer($idx)
343 return ($this->player[$idx]);
346 function setPlayer($idx, $player)
348 $this->player[$idx] = $player;
351 function user_add($idx)
353 $this->player[$this->player_n] = $idx;
356 return ($this->player_n - 1);
359 function user_rem(&$room, &$user)
361 $tabpos = $user->table_pos;
363 /* verifico la consistenza dei dati */
364 if ($room->user[$this->player[$tabpos]] == $user) {
366 /* aggiorna l'array dei giocatori al tavolo. */
367 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
368 $this->player[$i] = $this->player[$i+1];
369 $user_cur = &$room->user[$this->player[$i]];
370 $user_cur->table_pos = $i;
375 log_main("INCONSISTENCY ON TABLE.");
381 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
382 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
384 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
385 function act_content(&$user)
388 $isstanding = ($user->subst == 'standup');
389 $sitted = $this->player_n;
391 $cur_table = $user->table;
395 if ($sitted < PLAYERS_N) {
396 if ($this->auth_only) {
397 if ($user->flags & USER_FLAG_AUTH)
411 if ($table == $cur_table)
418 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
426 define(USER_FLAG_AUTH, 0x02);
427 define(USER_FLAG_LISTAUTH, 0x04);
430 define(USER_FLAG_S_NORM, 0x000); // done
431 define(USER_FLAG_S_PAU, 0x100); // done
432 define(USER_FLAG_S_OUT, 0x200); // done
433 define(USER_FLAG_S_DOG, 0x300); // done
434 define(USER_FLAG_S_EAT, 0x400); // done
435 define(USER_FLAG_S_WRK, 0x500); // done
436 define(USER_FLAG_S_SMK, 0x600); // done
437 define(USER_FLAG_S_EYE, 0x700); // done
439 define(USER_FLAG_S_ALL, 0xf00); // done
442 var $name; // name of the user
443 var $sess; // session of the user
444 var $ip; // ip of the user
445 var $lacc; // last access (for the cleanup)
446 var $laccwr; // last access (for the cleanup)
447 var $bantime; // timeout to temporary ban
448 var $stat; // status (outdoor, room, table, game, ...)
449 var $subst; // substatus for each status
450 var $step; // step of the current status
451 var $trans_step; // step to enable transition between pages (disable == -1)
452 var $comm; // commands array
453 // var $asta_card; //
455 // var $handpt; // Total card points at the beginning of the current hand.
456 // var $exitislock; // Player can exit from the table ?
458 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
459 // it is allways ZERO
460 var $table_orig; // id of the current table (if in table state)
461 var $table; // id of the current table (if in table state)
462 var $table_pos; // idx on the table
463 var $table_token;// token that identify a game on a table
464 var $flags; // Bitfield with: AUTHENTICATE: 0x02
465 var $the_end; // Flag to change the end of the session
467 var $chat_lst; // Last chat line
468 var $chattime; // Array of chat times
469 var $chat_cur; // Current chat line number
470 var $chat_ban; // Time for ban chat
471 var $chat_dlt; // Delta t for ban
475 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
478 if (($thiz =& new User()) == FALSE)
484 $thiz->lacc = time();
485 $thiz->laccwr = time();
488 $thiz->subst = $subst;
490 $thiz->trans_step = -1;
491 $thiz->comm = array();
492 $thiz->asta_card = -2;
493 $thiz->asta_pnt = -1;
495 $thiz->exitislock = TRUE;
499 $thiz->chattime = array_fill(0, CHAT_N, 0);
501 $thiz->chat_lst = "";
505 $thiz->table_orig = $table;
506 $thiz->table = $table;
507 $thiz->table_pos = -1;
508 $thiz->table_token = "";
513 function copy(&$from)
517 $this->name = $from->name;
518 $this->sess = $from->sess;
519 $this->ip = $from->ip;
520 $this->lacc = $from->lacc;
521 $this->laccwr = $from->laccwr;
522 $this->bantime = $from->bantime;
523 $this->stat = $from->stat;
524 $this->subst = $from->subst;
525 $this->step = $from->step;
526 $this->trans_step = $from->trans_step;
527 $this->comm = array();
529 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
530 for ($i = $i_start ; $i < $from->step ; $i++) {
532 $this->comm[$ii] = $from->comm[$ii];
534 $this->asta_card = $from->asta_card;
535 $this->asta_pnt = $from->asta_pnt;
536 $this->handpt = $from->handpt;
537 $this->exitislock = $from->exitislock;
539 $this->flags = $from->flags;
541 $this->chattime = array();
542 for ($i = 0 ; $i < CHAT_N ; $i++)
543 $this->chattime[$i] = $from->chattime[$i];
544 $this->chat_cur = $from->chat_cur;
545 $this->chat_lst = $from->chat_lst;
546 $this->chat_ban = $from->chat_ban;
547 $this->chat_dlt = $from->chat_dlt;
549 $this->table_orig = $from->table_orig;
550 $this->table = $from->table;
551 $this->table_pos = $from->table_pos;
552 $this->table_token = $from->table_token;
553 $this->the_end = $from->the_end;
559 function &clone(&$from)
563 if (($thiz =& new User()) == FALSE)
571 function &spawn(&$from, $table, $table_pos)
575 if (($thiz =& new User()) == FALSE)
578 $thiz->name = $from->name;
579 $thiz->sess = $from->sess;
580 $thiz->ip = $from->ip;
581 $thiz->lacc = $from->lacc;
582 $thiz->laccwr = $from->laccwr;
583 $thiz->bantime = $from->bantime;
584 $thiz->stat = $from->stat;
585 $thiz->subst = $from->subst;
586 $thiz->step = $from->step;
587 $thiz->trans_step = $from->trans_step;
588 $thiz->comm = array();
591 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
592 for ($i = $i_start ; $i < $from->step ; $i++) {
593 log_wr("TRY PUSH:".$i);
595 $thiz->comm[$ii] = $from->comm[$ii];
598 $thiz->asta_card = $from->asta_card;
599 $thiz->asta_pnt = $from->asta_pnt;
600 $thiz->handpt = $from->handpt;
601 $thiz->exitislock = $from->exitislock;
602 $thiz->the_end = $from->the_end;
604 $thiz->flags = $from->flags;
606 $thiz->chattime = array_fill(0, CHAT_N, 0);
608 $thiz->chat_lst = "";
613 $thiz->table_orig = $table;
615 $thiz->table_pos = $table_pos;
616 $thiz->table_token = $from->table_token;
621 function stat_set($stat) {
622 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
623 $this->stat = "$stat";
626 if (validate_sess($this->sess)) {
627 if (file_exists(PROXY_PATH) == FALSE)
629 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
630 fwrite($fp, sprintf("%s\n",$this->stat));
636 function step_set($step) {
640 if (validate_sess($this->sess) == FALSE)
642 if (file_exists(PROXY_PATH) == FALSE)
644 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
646 fwrite($fp, pack("l",$this->step), 4);
655 function step_inc($delta = 1) {
656 $this->step += $delta;
658 if (validate_sess($this->sess)) {
659 if (file_exists(PROXY_PATH) == FALSE)
661 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
662 fwrite($fp, pack("l",$this->step), 4);
673 log_legal($curtime, $this, "STAT:LOGOUT", '');
675 $tmp_sess = $this->sess;
677 step_unproxy($tmp_sess);
678 $this->name = ""; // OK here
679 while (array_pop($this->comm) != NULL);
681 $this->chattime = array_fill(0, CHAT_N, 0);
683 $this->chat_lst = "";
686 $this->the_end = FALSE;
696 function step_get($sess) {
699 if (validate_sess($sess) == FALSE)
702 if (file_exists(PROXY_PATH) == FALSE)
704 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
706 if (($s = fread($fp, 4)) == FALSE)
710 $arr = unpack('l', $s);
713 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
720 log_rd2("STEP_GET: return false ");
725 function step_unproxy($sess) {
726 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
727 if (file_exists(PROXY_PATH) == FALSE)
729 @unlink(PROXY_PATH."/".$sess.".step");
736 var $comm; // commands for many people
737 var $step; // current step of the comm array
738 var $garbage_timeout;
742 $this->user = array();
743 $this->table = array();
745 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
746 $this->user[$i] =& User::create("", "");
749 for ($i = 0 ; $i < TABLES_N ; $i++) {
750 $this->table[$i] =& Table::create($i);
753 $row = ( (((int)($i / 4)) % 2) == 0 );
754 $col = ($i % 2 == 0);
755 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
758 $this->table[$i]->auth_only = FALSE;
762 $this->table[$i]->auth_only = TRUE;
764 $this->table[$i]->auth_only = FALSE;
766 $this->garbage_timeout = 0;
769 function garbage_manager($force)
773 log_rd2("garbage_manager START");
775 /* Garbage collector degli utenti in timeout */
777 if ($force || $this->garbage_timeout < $curtime) {
779 // FIXME BRISK4: include for each kind of table
780 require_once("briskin5/Obj/briskin5.phh");
782 // Before all align times with table timeout
783 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
784 $table_cur =& $this->table[$table_idx];
785 // if the table is complete and exists its shared mem we get the info about users lacc
787 if ($table_cur->player_n == PLAYERS_N) {
788 log_main("PLAYERS == N TABLE ".$table_idx);
790 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
791 log_main("bin5 lock data success");
793 $no_recovery = FALSE;
794 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
795 if ($table_cur->table_token != $bri->table_token) {
796 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
797 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
807 log_main("garbage_manager: bri loaded successfully.");
808 $bri->garbage_manager(TRUE);
810 $bri_table = &$bri->table[0];
812 // is the end of the table
813 if ($bri->the_end == TRUE) {
815 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
817 log_main("garbage_manager: INSIDE THE END.");
819 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
820 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
821 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
824 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
825 // stat must be "table" by definition
826 $user_cur =& $this->user[$table_cur->player[$i]];
827 $bri_user =& $bri->user[$i];
829 $user_cur->subst = $bri_user->subst;
830 $user_cur->step = $bri_user->step;
831 $user_cur->lacc = $bri_user->lacc;
832 $user_cur->laccwr = $bri_user->lacc;
833 $user_cur->bantime = $bri_user->bantime;
836 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
838 $this->room_join_wakeup(&$user_cur, FALSE, 0);
839 $table_cur->table_token = "";
840 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
841 Briskin5::destroy_data($table_idx);
844 log_main("gm:: save_data");
846 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
847 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
850 Briskin5::save_data(&$bri);
852 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
853 else if ($no_recovery == FALSE) {
854 log_crit("ERROR: table ".$table_idx." unrecoverable join");
856 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
857 $user_cur = &$this->user[$table_cur->player[$i]];
858 $user_cur->subst = "shutdowner";
859 $user_cur->step_inc();
861 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
862 $ret .= "gst.st = ".($user_cur->step+1)."; ";
863 $ret .= show_notify("<br>I dati del tavolo n° ".$user_cur->table." sono inconsistenti, verranno resettati.<br><br>Torni in piedi.<br><br>", 2000, "Chiudi.", 400, 110);
864 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
865 $user_cur->step_inc();
868 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
869 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
870 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
872 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
874 $this->room_join_wakeup(&$user_cur, TRUE, -2);
875 $table_cur->table_token = "";
878 Briskin5::unlock_data($sem);
880 } // if ($table_cur->player_n == PLAYERS_N) {
881 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
883 log_rd2("out new loop.");
885 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
886 $user_cur = &$this->user[$i];
888 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
890 if ($user_cur->sess == "")
893 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
894 // Auto logout dell'utente
895 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
897 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
898 log_auth($user_cur->sess, "Autologout session.");
902 log_rd2("AUTO LOGOUT.");
903 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
904 $this->room_wakeup(&$user_cur);
905 else if ($user_cur->subst == 'standup')
906 $this->room_outstandup(&$user_cur);
908 log_rd2("LOGOUT FROM WHAT ???");
912 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
913 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
914 $this->room_wakeup(&$user_cur);
915 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
916 /* 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" */
917 $user_cur->comm[$user_cur->step % COMM_N] .= show_notify("<br>Sei stato inattivo per ".(EXPIRE_TIME_SMAMMA/60.0)." minuti. <br><br>Quindi ritorni tra i <b>Giocatori in piedi</b>.", 0, "torna ai tavoli", 400, 100);
918 $user_cur->step_inc();
922 log_rd2("GARBAGE UPDATED!");
924 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
931 function show_room($user_step, &$user)
933 log_main("show_room: username: ".$user->name);
935 $ret = sprintf('gst.st = %d; ', $user_step);
937 if ($user->flags & USER_FLAG_LISTAUTH) {
938 $ret .= 'list_set(\'auth\', false, \'(solo aut.)\' ); ';
941 $ret .= 'list_set(\'all\', false, \'\' ); ';
944 if ($user->subst == 'standup')
945 $ret .= "tra.show(); ";
947 $ret .= "tra.hide(); ";
949 $ret .= sprintf('stat = "%s";', $user->stat);
951 $ret .= root_wellcome($user);
952 $ret .= sprintf('subst = "%s";', $user->subst);
953 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
954 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
955 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
956 for ($i = 0 ; $i < TABLES_N ; $i++) {
957 $ret .= $this->table_content($user, $i);
958 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
959 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
960 $ret .= $this->table[$i]->act_content($user);
961 if ($this->table[$i]->wag_own != NULL)
962 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
964 $ret .= sprintf('tra.rem(%d); ', $i);
966 $ret .= $this->standup_content($user);
972 function room_wakeup(&$user)
974 $table_idx = $user->table;
975 $table = &$this->table[$table_idx];
977 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
981 $from_table = ($user->stat == "table");
983 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
985 for ($i = 0 ; $i < $table->player_n ; $i++) {
986 $user_cur = &$this->user[$table->player[$i]];
987 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
989 if ($user_cur != $user) {
990 $user_cur->stat_set("room");
991 $user_cur->subst = "sitdown";
992 $user_cur->laccwr = $curtime;
994 else if ($user->sess != "") {
995 $user_cur->stat_set("room");
996 $user_cur->subst = "standup";
997 $user_cur->laccwr = $curtime;
998 $user_cur->table = -1;
1003 $user->stat_set("room");
1004 $user->subst = "standup";
1005 $user->laccwr = $curtime;
1008 $remove_wagon = false;
1009 if($table->wag_own == $user) {
1010 $remove_wagon = true;
1011 $table->wag_reset($curtime);
1016 /* aggiorna l'array dei giocatori al tavolo. */
1017 $table->user_rem(&$this, &$user);
1019 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1020 $user_cur = &$this->user[$i];
1021 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1024 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1026 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1027 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
1028 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1029 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1030 log_main("DOCUMENT.index.php: from table");
1032 else if ($user_cur->stat == "room") {
1033 log_main("DOCUMENT.index.php: from table");
1035 $ret .= $this->table_content($user_cur, $table_idx);
1036 $ret .= $this->standup_content($user_cur);
1038 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1039 $ret .= $table->act_content($user);
1041 if ($user_cur == $user) {
1042 // set the new status
1043 $ret .= 'subst = "standup"; tra.show(); ';
1044 // clean the action buttons in other tables
1045 for ($e = 0 ; $e < TABLES_N ; $e++) {
1046 if ($this->table[$e]->player_n < PLAYERS_N) {
1047 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1048 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1049 $ret .= $this->table[$e]->act_content($user);
1054 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1055 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1056 $ret .= $table->act_content($user_cur);
1059 log_wr("ROOM_WAKEUP: ".$ret);
1060 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1061 $user_cur->step_inc();
1065 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1067 $table_idx = $user->table;
1068 $table = &$this->table[$table_idx];
1070 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1073 $user_wup = array();
1075 $user_tab = array();
1077 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1079 for ($i = 0 ; $i < $table->player_n ; $i++) {
1080 $user_cur = &$this->user[$table->player[$i]];
1081 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1082 if ($user_cur->sess != "") {
1083 if ($update_lacc == TRUE) {
1084 $user_cur->laccwr = $curtime;
1086 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1087 if ($user_cur->subst == "shutdowned") {
1088 $user_cur->stat_set("room");
1089 $user_cur->subst = "sitdown";
1091 else if ($user_cur->subst == "shutdowner") {
1092 $user_cur->stat_set("room");
1093 $user_cur->subst = "standup";
1094 $user_cur->table = -1;
1095 $user_wup[$user_wup_n++] = &$user_cur;
1097 $remove_wagon = false;
1098 if($table->wag_own == $user_cur) {
1099 $remove_wagon = true;
1100 $table->wag_reset($curtime);
1103 $user_tab[$user_tab_n++] = &$user_cur;
1107 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1108 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1110 /* aggiorna l'array dei giocatori al tavolo. */
1112 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1113 log_main("START LOOP");
1114 $user_cur = &$this->user[$i];
1115 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1116 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1121 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1123 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1124 if ($user_cur->stat == "room") {
1125 log_main("DOCUMENT.index.php from table");
1127 $ret .= $this->table_content($user_cur, $table_idx);
1128 $ret .= $this->standup_content($user_cur);
1130 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1131 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1132 $ret .= $table->act_content($user_cur);
1135 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1136 if ($user_cur == $user_tab[$tab_idx])
1139 // for users that wakeup the room will be reconstructed by index_rd.php
1140 if ($tab_idx < $user_tab_n) {
1141 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1143 // ARRAY_POP DISABLED
1144 // if ($trans_delta == 0)
1145 // while (array_pop($user_cur->comm) != NULL);
1147 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1148 $user_cur->comm[$user_cur->step % COMM_N] = "";
1149 $user_cur->step_inc();
1150 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1151 $user_cur->step_inc();
1152 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1156 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1158 log_main("JOIN_WAKEUP more");
1159 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1160 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1161 $ret .= $table->act_content($user_cur);
1163 log_main("JOIN_WAKEUP end more");
1165 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1166 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1167 $user_cur->step_inc();
1171 function room_outstandup(&$user)
1173 $this->room_sitdown(&$user, -1);
1176 function table_update(&$user)
1178 log_main("table_update: pre - USER: ".$user->name);
1180 $table_idx = $user->table;
1182 if ($table_idx > -1)
1183 $table = &$this->table[$table_idx];
1185 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1187 $user_cur = &$this->user[$i];
1188 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1191 $ret = "gst.st = ".($user_cur->step+1)."; ";
1192 if ($table_idx > -1)
1193 $ret .= $this->table_content($user_cur, $table_idx);
1195 if ($user_cur == $user) {
1196 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1197 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1198 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1200 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1201 $user_cur->step_inc();
1204 log_main("table_update: post");
1207 function room_sitdown(&$user, $table_idx)
1209 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1213 if ($table_idx > -1 && $table_idx < TABLES_N) {
1214 $table = &$this->table[$table_idx];
1217 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1218 for ($i = 0 ; $i < TABLES_N ; $i++) {
1219 $user_cur =& $this->user[$table->player[$i]];
1220 if ($user_cur == $table->wag_own) {
1221 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1222 $table->wag_reset(time());
1229 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1231 $user_cur = &$this->user[$i];
1232 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1235 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1236 if ($table_idx > -1)
1237 $ret .= $this->table_content($user_cur, $table_idx);
1238 $ret .= $this->standup_content($user_cur);
1240 if ($user_cur == $user) {
1241 $ret .= 'subst = "sitdown"; tra.hide(); ';
1242 // clean the action buttons in other tables
1243 for ($e = 0 ; $e < TABLES_N ; $e++) {
1244 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1245 $ret .= $this->table[$e]->act_content($user_cur);
1248 else if ($table_idx > -1) {
1249 if ($table->player_n == PLAYERS_N) {
1250 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1251 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1252 $ret .= $table->act_content($user_cur);
1255 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1256 $user_cur->step_inc();
1260 function chatt_send(&$user, $mesg)
1262 GLOBAL $G_alarm_passwd;
1266 $msg = substr($mesg, 6, 128);
1268 $dt = date("H:i ", $curtime);
1278 $is_normchat = FALSE;
1279 $update_room = FALSE;
1281 if (strcmp($msg, "/tav") == 0 ||
1282 strncmp($msg, "/tav ", 5) == 0) {
1284 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1285 /* 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>" */
1286 $msg = "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>";
1287 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1292 $table = &$this->table[$user->table];
1294 if ($table->wag_own != NULL) {
1295 $msg = "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>";
1296 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1301 $dtime = $curtime - $table->wag_tout;
1302 if ($dtime < EXPIRE_TIME_WAG) {
1303 $msg = sprintf("<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>",
1304 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? "o" : "i"));
1305 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1310 $msg = substr($msg, 5);
1312 $table->wag_set($user, $msg);
1313 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1314 $to_room = $to_user;
1317 } // /tav chat command
1319 else if (strncmp($msg, "/alarm ", 7) == 0) {
1320 if (strncmp($msg, "/alarm to ", 10) == 0) {
1321 $sp_pos = strpos($msg, " ", 10);
1322 $target = substr($msg, 10, $sp_pos - 10);
1323 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1327 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1330 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1331 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1332 $msg = "<br>La password digitata non è corretta.<br><br>";
1333 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1338 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1339 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Alarm <b>%s</b> inviato a <b>%s</b>.");',
1340 $dt, NICKSERV, xcape(substr($msg, strlen($alarm_check))),
1341 ($target == "" ? "tutti" : xcape($target)) );
1343 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1344 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1345 /* MLANG: "chiudi" */
1346 $to_all = show_notify($msg, 0, "chiudi", 400, 120);
1348 } // /alarm chat command
1349 else if (strncmp($msg, "/listen ", 8) == 0) {
1350 $arg = substr($msg, 8);
1352 if (strcasecmp($arg, "auth") == 0) {
1353 $user->flags |= USER_FLAG_LISTAUTH;
1354 $to_user = 'list_set(\'auth\', true, \'(solo aut.)\'); ';
1357 $user->flags &= ~USER_FLAG_LISTAUTH;
1358 $to_user = 'list_set(\'all\', true, \'\'); ';
1361 else if (strncmp($msg, "/garante", 8) == 0) {
1362 if ($user->flags & USER_FLAG_AUTH) {
1363 $to_user = sprintf('authbox(300,200);');
1366 /* 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." */
1367 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
1370 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1371 if ($user->flags & USER_FLAG_AUTH) {
1372 $to_user = sprintf('mesgtoadmbox(500,300);');
1375 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1376 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per inviare un messaggio devi essere autenticato.</b>");', $dt, NICKSERV);
1379 else if (strncmp($msg, "/nick ", 6) == 0) {
1380 log_main("chatt_send BEGIN");
1383 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1384 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.");', $dt, NICKSERV);
1388 $msg = "COMMAND ".$msg;
1389 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1390 $user_cur = &$this->user[$i];
1392 if ($user_cur->sess == '')
1394 if ($user_cur->name == $name_new)
1397 if ($i < MAX_PLAYERS) {
1398 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Nickname <b>%s</b> già in uso.");', $dt, NICKSERV, xcape($name_new));
1402 /* 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>" */
1403 if ($user->flags & USER_FLAG_AUTH) {
1404 if (strcasecmp($user->name,$name_new) != 0) {
1405 if ($user->subst == 'standup' || ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)) {
1406 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1407 for ($i = 0 ; $i < TABLES_N ; $i++) {
1408 $to_user .= $this->table[$i]->act_content($user);
1412 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>");', $dt, NICKSERV);
1417 $user->name = $name_new; // OK - nick changed
1418 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1419 if (($user->flags & USER_FLAG_AUTH) == 0) {
1420 $userdb = new LoginDB();
1421 /* 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>" */
1422 if ($userdb->login_exists($name_new)) {
1423 $to_user .= sprintf('chatt_sub("%s", [2, "%s"],"Il nickname <b>\'%s\'</b> è già registrato, <b>se il suo proprietario si autentificherà verrai rinominato d\'ufficio come ghost<i>N</i>.</b>");', $dt, NICKSERV, xcape($name_new));
1427 log_main("chatt_send start set");
1429 $update_room = TRUE;
1431 } // nick chat command
1433 else if (strncmp($msg, "/st ", 4) == 0) {
1434 log_main("chatt_send BEGIN");
1437 $st_str = substr($msg, 4);
1439 if (strcasecmp($st_str, "normale") == 0) {
1440 $st = USER_FLAG_S_NORM;
1442 else if (strcasecmp($st_str, "pausa") == 0) {
1443 $st = USER_FLAG_S_PAU;
1445 else if (strcasecmp($st_str, "fuori") == 0) {
1446 $st = USER_FLAG_S_OUT;
1448 else if (strcasecmp($st_str, "cane") == 0) {
1449 $st = USER_FLAG_S_DOG;
1451 else if (strcasecmp($st_str, "cibo") == 0) {
1452 $st = USER_FLAG_S_EAT;
1454 else if (strcasecmp($st_str, "lavoro") == 0) {
1455 $st = USER_FLAG_S_WRK;
1457 else if (strcasecmp($st_str, "sigaretta") == 0) {
1458 $st = USER_FLAG_S_SMK;
1460 else if (strcasecmp($st_str, "presente") == 0) {
1461 $st = USER_FLAG_S_EYE;
1464 /* MLANG: "Questo stato non esiste." */
1465 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Questo stato non esiste.");', $dt, NICKSERV);
1469 log_main("chatt_send start set");
1470 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1471 $update_room = TRUE;
1472 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1475 } // nick chat command
1477 else { // normal chat line
1478 $is_normchat = TRUE;
1479 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1481 $user->chat_dlt = $user->chat_dlt * 2;
1482 if ($user->chat_dlt > 120)
1483 $user->chat_dlt = 120;
1485 else if ($user->chat_lst == $msg)
1487 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1488 $user->chat_ban = $curtime;
1489 $user->chat_dlt = 5;
1493 $user->chat_ban = 0;
1494 $user->chat_dlt = 0;
1498 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1501 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1502 // temporary silentiation for troll (will became array check)
1503 if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1504 $to_room = $to_user;
1507 log_legal($curtime, $user,
1508 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1510 $user->chat_lst = "$msg";
1511 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1521 // Output to clients
1524 if ($to_user != FALSE) {
1525 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1526 $user->comm[$user->step % COMM_N] .= $to_user;
1530 if ($to_room != FALSE) {
1531 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1532 $user_cur = &$this->user[$i];
1533 if ($target != "" && $user_cur->name != $target)
1535 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1536 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1539 if ($is_normchat == TRUE) {
1540 if ($user_cur->flags & USER_FLAG_LISTAUTH) {
1541 if (($user->flags & USER_FLAG_AUTH) == 0) {
1547 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1548 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1549 $user_cur->step_inc();
1554 // FIXME BRISK4: include for each kind of table
1555 require_once("briskin5/Obj/briskin5.phh");
1556 // Before all align times with table timeout
1557 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1558 $table_cur =& $this->table[$table_idx];
1559 // if the table is complete and exists its shared mem we get the info about users lacc
1561 if ($table_cur->player_n == PLAYERS_N) {
1562 log_main("PLAYERS == N TABLE ".$table_idx);
1564 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1565 log_main("bin5 lock data success");
1567 $no_recovery = FALSE;
1568 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1569 if ($table_cur->table_token != $bri->table_token) {
1570 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1575 if ($bri != FALSE) {
1576 $bri_table = &$bri->table[0];
1577 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1578 // stat must be "table" by definition
1579 $bri_user =& $bri->user[$i];
1581 if ($target != "" && $bri_user->name != $target)
1583 log_main("writa: ".$user_mesg);
1584 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1585 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1586 $bri_user->step_inc();
1588 Briskin5::save_data(&$bri);
1590 Briskin5::unlock_data($sem);
1592 } // if ($table_cur->player_n == PLAYERS_N) {
1593 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1594 } // if ($to_tabl == true ...
1597 if ($user->stat == 'room' && $user->subst == 'standup') {
1598 $this->standup_update(&$user);
1600 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1601 log_main("chatt_send pre table update");
1602 $this->table_update(&$user);
1603 log_main("chatt_send post table update");
1605 } // if ($update_room ...
1608 } // function chatt_send( ...
1610 function &get_user($sess, &$idx)
1612 GLOBAL $PHP_SELF, $G_false;
1614 if (validate_sess($sess)) {
1615 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1616 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1619 $ret = &$this->user[$i];
1623 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1624 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1625 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1628 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1637 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1640 * if ($idx > -1 && ret == FALSE) => duplicated nick
1641 * if ($idx == -2 && ret == FALSE) => invalid name
1642 * if ($idx == -3 && ret == FALSE) => wrong password
1643 * if ($idx == -1 && ret == FALSE) => no space left
1644 * if ($idx == 0 && ret == user) => SUCCESS
1645 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1650 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1652 GLOBAL $G_false, $CO_list;
1656 $authenticate = FALSE;
1657 $login_exists = FALSE;
1659 $ghost_auth = FALSE;
1663 if (($name_new = validate_name($name)) == FALSE) {
1668 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1669 if (validate_sess($sess) == FALSE)
1672 /* if pass != FALSE verify the login with pass */
1673 log_auth("XXX", "auth1");
1674 $userdb = new LoginDB();
1675 if ($pass != FALSE) {
1676 log_auth("XXX", "auth2");
1677 $authenticate = $userdb->login_verify($name_new, $pass);
1678 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1680 if ($authenticate == FALSE) {
1686 $login_exists = $userdb->login_exists($name_new);
1688 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1690 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1694 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1696 continue; // NOTE: CHECK IT !!
1698 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1699 if ($authenticate == FALSE) {
1705 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1712 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1714 if ($ghost > -1 && $ghost_auth && $authenticate) {
1717 $ghost_user =& $this->user[$ghost];
1719 $ghost_user->step_inc();
1722 $ghost_user->sess = $sess;
1725 $ghost_user->sess = $sess;
1728 // If user at the table we need to update the table data too
1729 $table_idx = $ghost_user->table;
1730 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1731 // FIXME BRISK4: include for each kind of table
1732 require_once("briskin5/Obj/briskin5.phh");
1733 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1734 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1735 if ($bri->the_end != TRUE) {
1736 $bri->user[$ghost_user->table_pos]->step_inc();
1737 $bri->user[$ghost_user->table_pos]->sess = $sess;
1738 Briskin5::save_data(&$bri);
1741 Briskin5::unlock_data($brisem);
1746 return ($this->user[$ghost]);
1748 else if ($idx != -1 && $i == MAX_PLAYERS) {
1753 $this->user[$idx]->sess = $sess;
1756 $this->user[$idx]->sess = $sess;
1758 $this->user[$idx]->name = $name_new; // OK - add new user
1759 $this->user[$idx]->stat_set("room");
1760 $this->user[$idx]->step_set(0);
1761 while (array_pop($this->user[$idx]->comm) != NULL);
1762 $this->user[$idx]->subst = "standup";
1763 $this->user[$idx]->lacc = $curtime;
1764 $this->user[$idx]->laccwr = $curtime;
1765 $this->user[$idx]->bantime = 0;
1766 $this->user[$idx]->ip = $ip;
1768 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1770 if ($authenticate) {
1771 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1773 if (isset($CO_list) && strcmp($CO_list, "all") == 0) {
1774 $this->user[$idx]->flags &= ~USER_FLAG_LISTAUTH;
1779 log_main("ghost: rename!");
1780 $ghost_user =& $this->user[$ghost];
1782 if ($ghost_auth == FALSE) {
1783 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1784 $ghostname = 'ghost'.$sfx;
1785 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1786 if (strcmp("", $this->user[$i]->sess) == 0)
1789 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1794 if ($ghostname != '')
1798 $ghost_user->name = $ghostname;
1800 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1801 $this->standup_update(&$ghost_user);
1804 log_main("chatt_send pre table update");
1805 $this->table_update(&$ghost_user);
1806 log_main("chatt_send post table update");
1808 } // if ($ghost_auth == FALSE
1810 // FIXME: cacciare il vecchio utente room && table (if needed)
1811 $ghost_user->the_end = TRUE;
1812 $ghost_user->lacc = 0;
1813 $this->garbage_manager(TRUE);
1815 } // if ($ghost > -1) {
1817 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1821 return ($this->user[$real_idx]);
1827 function standup_update(&$user)
1829 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1830 $user_cur = &$this->user[$i];
1831 if ($user_cur->sess == '')
1834 log_main("STANDUP START: ".$user_cur->stat);
1836 if ($user_cur->stat == 'room') {
1837 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1838 if ($user_cur == $user) {
1839 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1840 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1842 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
1843 $itin, xcape($user->name), $itou);
1845 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1847 $user_cur->step_inc();
1853 function &init_data()
1855 $room =& new Room();
1861 function &load_data()
1863 GLOBAL $G_false, $sess;
1866 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1867 log_main("ftok failed");
1872 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1873 log_main("shmop_open failed");
1877 $shm_sz = SHM_DIMS_MIN;
1879 if ($shm = shm_attach($tok, $shm_sz)) {
1880 $room = @shm_get_var($shm, $tok);
1882 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1884 log_only("bri count ".count($room));
1886 if ($room == FALSE) {
1887 log_only("INIT MAIN DATA");
1889 $room =& Room::init_data();
1890 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1891 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1892 log_only(serialize($room));
1895 $room->shm_sz = $shm_sz;
1910 function save_data(&$room)
1918 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1921 while ($room->shm_sz < SHM_DIMS_MAX) {
1922 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1925 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1926 if (shm_put_var($shm, $tok, $room) != FALSE) {
1930 if (shm_remove($shm) === FALSE) {
1931 log_only("REMOVE FALLITA");
1935 $room->shm_sz += SHM_DIMS_DLT;
1944 function lock_data()
1948 // echo "LOCK: ".FTOK_PATH."/main";
1950 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1953 // echo "FTOK ".$tok."<br>";
1954 if (($res = sem_get($tok)) == FALSE) {
1957 if (sem_acquire($res)) {
1958 log_lock("LOCK room");
1965 function unlock_data($res)
1969 log_lock("UNLOCK room");
1971 return (sem_release($res));
1975 function standup_content($user)
1980 if ($user->stat != 'room')
1983 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1984 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1989 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1991 $content = ' j_stand_cont( [ ';
1993 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1994 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1997 $flags = $this->user[$e]->flags;
1999 if ($this->user[$e]->subst == "standup") {
2000 if ($this->user[$e] == $user)
2005 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
2014 function table_content_old($user, $table_idx)
2020 // Si possono usare i dati nella classe table
2023 $sess = $user->sess;
2024 $table = &$this->table[$table_idx];
2026 if ($user->stat != 'room')
2029 for ($i = 0 ; $i < $table->player_n ; $i++) {
2030 $user_cur = &$this->user[$table->player[$i]];
2032 if ($user_cur == $user)
2033 { $hilion = "<b>"; $hilioff = "</b>"; }
2035 { $hilion = ""; $hilioff = ""; }
2037 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2039 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
2042 for ( ; $i < PLAYERS_N ; $i++)
2046 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
2052 function table_content($user, $table_idx)
2058 // Si possono usare i dati nella classe table
2061 $sess = $user->sess;
2062 $table = &$this->table[$table_idx];
2064 if ($user->stat != 'room')
2068 for ($i = 0 ; $i < $table->player_n ; $i++) {
2069 $user_cur = &$this->user[$table->player[$i]];
2071 $flags = $user_cur->flags;
2073 if ($user_cur == $user)
2076 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2078 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2083 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2090 function make_seed()
2092 list($usec, $sec) = explode(' ', microtime());
2093 return (float) $sec + ((float) $usec * 100000);
2097 function log_only2($log) {
2100 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2103 if (isset($sess) == FALSE)
2108 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2111 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2112 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2117 function log_crit($log) {
2120 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2123 if (isset($sess) == FALSE)
2128 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2131 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2132 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2137 function log_only($log) {
2140 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2143 if (isset($sess) == FALSE)
2148 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2151 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2152 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2157 function log_main($log) {
2160 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2163 if (isset($sess) == FALSE)
2168 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2171 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2172 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2177 function log_rd($log) {
2180 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2183 if (isset($sess) == FALSE)
2188 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2191 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2192 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2197 function log_rd2($log) {
2200 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2203 if (isset($sess) == FALSE)
2208 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2211 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2212 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2217 function log_send($log) {
2220 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2223 if (isset($sess) == FALSE)
2228 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2231 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2232 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2237 function log_lock($log) {
2240 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2243 if (isset($sess) == FALSE)
2248 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2251 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2252 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2257 function log_wr($log) {
2260 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2263 if (isset($sess) == FALSE)
2268 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2271 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2272 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2277 function log_load($log) {
2280 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2283 if (isset($sess) == FALSE)
2288 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2291 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2292 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2297 function log_auth($sess, $log) {
2298 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2301 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2304 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2305 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2311 // function log_legal($curtime, $sess, $name, $where, $mesg)
2312 function log_legal($curtime, &$user, $where, $mesg)
2316 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2317 /* Unix time | session | nickname | IP | where was | mesg */
2318 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2319 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2320 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2328 function lock_banlist()
2330 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2334 if (($res = sem_get($tok)) == FALSE) {
2335 echo "SEM_GET FAILED";
2338 if (sem_acquire($res))
2344 function unlock_banlist($res)
2346 return (sem_release($res));
2349 function table_act_content_old($isstanding, $sitted, $table, $cur_table)
2354 if ($sitted < PLAYERS_N) {
2355 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
2359 if ($table == $cur_table)
2360 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
2367 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2372 if ($sitted < PLAYERS_N) {
2380 if ($table == $cur_table)
2387 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2392 function show_notify($text, $tout, $butt, $w, $h)
2394 log_main("SHOW_NOTIFY: ".$text);
2395 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2398 function multoval($mult)
2402 else if ($mult == 4)
2403 return ("quadruplo");
2405 return (sprintf("%d-plo", $mult));
2409 function root_wellcome($user)
2411 GLOBAL $root_wellarr;
2415 $dt = date("H:i ", $curtime);
2417 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2418 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$i]));
2425 function validate_sess($sess)
2427 if (strlen($sess) == SESS_LEN)
2433 function validate_name($name)
2435 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2437 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2439 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2446 function playsound($filename)
2448 return (sprintf('playsound("flasou", "%s");', $filename));
2451 function secstoword($secs)
2453 $mins = floor($secs / 60);
2456 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2459 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2464 function sharedmem_sz($tok)
2466 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2467 log_main("shmop_open failed");
2470 $shm_sz = shmop_size($shm_id);
2471 shmop_close($shm_id);
2473 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2478 function lock_data()
2482 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2485 // echo "FTOK ".$tok."<br>";
2486 if (($res = sem_get($tok)) == FALSE) {
2489 if (sem_acquire($res)) {
2490 log_lock("LOCK warrant");
2497 function unlock_data($res)
2501 log_lock("UNLOCK warrant");
2503 return (sem_release($res));
2508 function lock_data()
2512 if (($tok = @ftok(FTOK_PATH."/poll", "B")) == -1) {
2515 // echo "FTOK ".$tok."<br>";
2516 if (($res = sem_get($tok)) == FALSE) {
2519 if (sem_acquire($res)) {
2520 log_lock("LOCK poll");
2527 function unlock_data($res)
2531 log_lock("UNLOCK poll");
2533 return (sem_release($res));