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.7 - trusty";
85 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
86 $root_wellarr = Array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: menu comandi, filtro opzionale sui non autenticati e "return bug" corretto.',
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>';
165 $from = array ( '\\', '@', '|' );
166 $to = array ( '\\\\', '@', '¦' );
168 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
173 $from = array ( '\\', '|', "\t", "\n");
174 $to = array ( '\\\\', '\\|', "\\t", "\\n");
176 return (str_replace($from, $to, $s));
179 function xcapemesg($s)
181 $from = array ( "\n");
182 $to = array ( "\\n");
184 return (str_replace($from, $to, $s));
193 var $auth_only; // se tavolo riservato o libero
200 var $table_start; // information field
208 function &create($idx)
212 if (($thiz =& new Table()) == FALSE)
216 $thiz->player = array();
218 $thiz->auth_only = FALSE;
220 $thiz->wag_own = NULL;
224 $thiz->table_token = "";
225 $thiz->table_start = 0;
227 $thiz->wakeup_time = 0;
232 function copy(&$from)
236 $this->idx = $from->idx;
237 $this->player = array();
238 for ($i = 0 ; $i < $from->player_n ; $i++)
239 $this->player[$i] = $from->player[$i];
240 $this->player_n = $from->player_n;
242 log_main("PLAYER_N - parent::copy.".$this->player_n);
244 $this->auth_only = $from->auth_only;
246 $this->wag_own = $from->wag_own;
247 $this->wag_com = $from->wag_com;
248 $this->wag_tout = $from->wag_tout;
250 $this->table_token = $from->table_token;
251 $this->table_start = $from->table_start;
253 $this->wakeup_time = $from->wakeup_time;
256 function &clone(&$from)
260 if (($thiz =& new Table()) == FALSE)
268 function &spawn(&$from)
272 if (($thiz =& new Table()) == FALSE)
275 $thiz->idx = $from->idx;
276 $thiz->player = array();
277 for ($i = 0 ; $i < $from->player_n ; $i++)
278 $thiz->player[$i] = $i;
279 $thiz->player_n = $from->player_n;
281 $thiz->auth_only = $from->auth_only;
283 $thiz->wag_own = $from->wag_own;
284 $thiz->wag_com = $from->wag_com;
285 $thiz->wag_tout = $from->wag_tout;
287 $thiz->table_token = $from->table_token;
288 $thiz->table_start = $from->table_start;
290 $thiz->wakeup_time = $from->wakeup_time;
295 function wag_set(&$user, $mesg)
299 $this->wag_own = &$user;
300 $this->wag_com = $mesg;
304 function wag_reset($timeout)
306 log_main("WAG_RESET");
308 unset($this->wag_own);
309 $this->wag_own = NULL;
311 $this->wag_tout = $timeout;
314 function getPlayer($idx)
316 return ($this->player[$idx]);
319 function setPlayer($idx, $player)
321 $this->player[$idx] = $player;
324 function user_add($idx)
326 $this->player[$this->player_n] = $idx;
329 return ($this->player_n - 1);
332 function user_rem(&$room, &$user)
334 $tabpos = $user->table_pos;
336 /* verifico la consistenza dei dati */
337 if ($room->user[$this->player[$tabpos]] == $user) {
339 /* aggiorna l'array dei giocatori al tavolo. */
340 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
341 $this->player[$i] = $this->player[$i+1];
342 $user_cur = &$room->user[$this->player[$i]];
343 $user_cur->table_pos = $i;
348 log_main("INCONSISTENCY ON TABLE.");
354 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
355 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
357 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
358 function act_content(&$user)
361 $isstanding = ($user->subst == 'standup');
362 $sitted = $this->player_n;
364 $cur_table = $user->table;
368 if ($sitted < PLAYERS_N) {
369 if ($this->auth_only) {
370 if ($user->flags & USER_FLAG_AUTH)
384 if ($table == $cur_table)
391 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
399 define(USER_FLAG_AUTH, 0x02);
400 define(USER_FLAG_LISTAUTH, 0x04);
403 define(USER_FLAG_S_NORM, 0x000); // done
404 define(USER_FLAG_S_PAU, 0x100); // done
405 define(USER_FLAG_S_OUT, 0x200); // done
406 define(USER_FLAG_S_DOG, 0x300); // done
407 define(USER_FLAG_S_EAT, 0x400); // done
408 define(USER_FLAG_S_WRK, 0x500); // done
409 define(USER_FLAG_S_SMK, 0x600); // done
410 define(USER_FLAG_S_EYE, 0x700); // done
412 define(USER_FLAG_S_ALL, 0xf00); // done
415 var $name; // name of the user
416 var $sess; // session of the user
417 var $ip; // ip of the user
418 var $lacc; // last access (for the cleanup)
419 var $laccwr; // last access (for the cleanup)
420 var $bantime; // timeout to temporary ban
421 var $stat; // status (outdoor, room, table, game, ...)
422 var $subst; // substatus for each status
423 var $step; // step of the current status
424 var $trans_step; // step to enable transition between pages (disable == -1)
425 var $comm; // commands array
426 // var $asta_card; //
428 // var $handpt; // Total card points at the beginning of the current hand.
429 // var $exitislock; // Player can exit from the table ?
431 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
432 // it is allways ZERO
433 var $table_orig; // id of the current table (if in table state)
434 var $table; // id of the current table (if in table state)
435 var $table_pos; // idx on the table
436 var $table_token;// token that identify a game on a table
437 var $flags; // Bitfield with: AUTHENTICATE: 0x02
438 var $the_end; // Flag to change the end of the session
440 var $chat_lst; // Last chat line
441 var $chattime; // Array of chat times
442 var $chat_cur; // Current chat line number
443 var $chat_ban; // Time for ban chat
444 var $chat_dlt; // Delta t for ban
448 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
451 if (($thiz =& new User()) == FALSE)
457 $thiz->lacc = time();
458 $thiz->laccwr = time();
461 $thiz->subst = $subst;
463 $thiz->trans_step = -1;
464 $thiz->comm = array();
465 $thiz->asta_card = -2;
466 $thiz->asta_pnt = -1;
468 $thiz->exitislock = TRUE;
472 $thiz->chattime = array_fill(0, CHAT_N, 0);
474 $thiz->chat_lst = "";
478 $thiz->table_orig = $table;
479 $thiz->table = $table;
480 $thiz->table_pos = -1;
481 $thiz->table_token = "";
486 function copy(&$from)
490 $this->name = $from->name;
491 $this->sess = $from->sess;
492 $this->ip = $from->ip;
493 $this->lacc = $from->lacc;
494 $this->laccwr = $from->laccwr;
495 $this->bantime = $from->bantime;
496 $this->stat = $from->stat;
497 $this->subst = $from->subst;
498 $this->step = $from->step;
499 $this->trans_step = $from->trans_step;
500 $this->comm = array();
502 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
503 for ($i = $i_start ; $i < $from->step ; $i++) {
505 $this->comm[$ii] = $from->comm[$ii];
507 $this->asta_card = $from->asta_card;
508 $this->asta_pnt = $from->asta_pnt;
509 $this->handpt = $from->handpt;
510 $this->exitislock = $from->exitislock;
512 $this->flags = $from->flags;
514 $this->chattime = array();
515 for ($i = 0 ; $i < CHAT_N ; $i++)
516 $this->chattime[$i] = $from->chattime[$i];
517 $this->chat_cur = $from->chat_cur;
518 $this->chat_lst = $from->chat_lst;
519 $this->chat_ban = $from->chat_ban;
520 $this->chat_dlt = $from->chat_dlt;
522 $this->table_orig = $from->table_orig;
523 $this->table = $from->table;
524 $this->table_pos = $from->table_pos;
525 $this->table_token = $from->table_token;
526 $this->the_end = $from->the_end;
532 function &clone(&$from)
536 if (($thiz =& new User()) == FALSE)
544 function &spawn(&$from, $table, $table_pos)
548 if (($thiz =& new User()) == FALSE)
551 $thiz->name = $from->name;
552 $thiz->sess = $from->sess;
553 $thiz->ip = $from->ip;
554 $thiz->lacc = $from->lacc;
555 $thiz->laccwr = $from->laccwr;
556 $thiz->bantime = $from->bantime;
557 $thiz->stat = $from->stat;
558 $thiz->subst = $from->subst;
559 $thiz->step = $from->step;
560 $thiz->trans_step = $from->trans_step;
561 $thiz->comm = array();
564 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
565 for ($i = $i_start ; $i < $from->step ; $i++) {
566 log_wr("TRY PUSH:".$i);
568 $thiz->comm[$ii] = $from->comm[$ii];
571 $thiz->asta_card = $from->asta_card;
572 $thiz->asta_pnt = $from->asta_pnt;
573 $thiz->handpt = $from->handpt;
574 $thiz->exitislock = $from->exitislock;
575 $thiz->the_end = $from->the_end;
577 $thiz->flags = $from->flags;
579 $thiz->chattime = array_fill(0, CHAT_N, 0);
581 $thiz->chat_lst = "";
586 $thiz->table_orig = $table;
588 $thiz->table_pos = $table_pos;
589 $thiz->table_token = $from->table_token;
594 function stat_set($stat) {
595 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
596 $this->stat = "$stat";
599 if (validate_sess($this->sess)) {
600 if (file_exists(PROXY_PATH) == FALSE)
602 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
603 fwrite($fp, sprintf("%s\n",$this->stat));
609 function step_set($step) {
613 if (validate_sess($this->sess) == FALSE)
615 if (file_exists(PROXY_PATH) == FALSE)
617 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
619 fwrite($fp, pack("l",$this->step), 4);
628 function step_inc($delta = 1) {
629 $this->step += $delta;
631 if (validate_sess($this->sess)) {
632 if (file_exists(PROXY_PATH) == FALSE)
634 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
635 fwrite($fp, pack("l",$this->step), 4);
646 log_legal($curtime, $this, "STAT:LOGOUT", '');
648 $tmp_sess = $this->sess;
650 step_unproxy($tmp_sess);
651 $this->name = ""; // OK here
652 while (array_pop($this->comm) != NULL);
654 $this->chattime = array_fill(0, CHAT_N, 0);
656 $this->chat_lst = "";
659 $this->the_end = FALSE;
669 function step_get($sess) {
672 if (validate_sess($sess) == FALSE)
675 if (file_exists(PROXY_PATH) == FALSE)
677 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
679 if (($s = fread($fp, 4)) == FALSE)
683 $arr = unpack('l', $s);
686 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
693 log_rd2("STEP_GET: return false ");
698 function step_unproxy($sess) {
699 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
700 if (file_exists(PROXY_PATH) == FALSE)
702 @unlink(PROXY_PATH."/".$sess.".step");
709 var $comm; // commands for many people
710 var $step; // current step of the comm array
711 var $garbage_timeout;
715 $this->user = array();
716 $this->table = array();
718 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
719 $this->user[$i] =& User::create("", "");
722 for ($i = 0 ; $i < TABLES_N ; $i++) {
723 $this->table[$i] =& Table::create($i);
726 $row = ( (((int)($i / 4)) % 2) == 0 );
727 $col = ($i % 2 == 0);
728 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
731 $this->table[$i]->auth_only = FALSE;
735 $this->table[$i]->auth_only = TRUE;
737 $this->table[$i]->auth_only = FALSE;
739 $this->garbage_timeout = 0;
742 function garbage_manager($force)
746 log_rd2("garbage_manager START");
748 /* Garbage collector degli utenti in timeout */
750 if ($force || $this->garbage_timeout < $curtime) {
752 // FIXME BRISK4: include for each kind of table
753 require_once("briskin5/Obj/briskin5.phh");
755 // Before all align times with table timeout
756 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
757 $table_cur =& $this->table[$table_idx];
758 // if the table is complete and exists its shared mem we get the info about users lacc
760 if ($table_cur->player_n == PLAYERS_N) {
761 log_main("PLAYERS == N TABLE ".$table_idx);
763 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
764 log_main("bin5 lock data success");
766 $no_recovery = FALSE;
767 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
768 if ($table_cur->table_token != $bri->table_token) {
769 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
770 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
780 log_main("garbage_manager: bri loaded successfully.");
781 $bri->garbage_manager(TRUE);
783 $bri_table = &$bri->table[0];
785 // is the end of the table
786 if ($bri->the_end == TRUE) {
788 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
790 log_main("garbage_manager: INSIDE THE END.");
792 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
793 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
794 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
797 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
798 // stat must be "table" by definition
799 $user_cur =& $this->user[$table_cur->player[$i]];
800 $bri_user =& $bri->user[$i];
802 $user_cur->subst = $bri_user->subst;
803 $user_cur->step = $bri_user->step;
804 $user_cur->lacc = $bri_user->lacc;
805 $user_cur->laccwr = $bri_user->lacc;
806 $user_cur->bantime = $bri_user->bantime;
809 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
811 $this->room_join_wakeup(&$user_cur, FALSE, 0);
812 $table_cur->table_token = "";
813 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
814 Briskin5::destroy_data($table_idx);
817 log_main("gm:: save_data");
819 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
820 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
823 Briskin5::save_data(&$bri);
825 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
826 else if ($no_recovery == FALSE) {
827 log_crit("ERROR: table ".$table_idx." unrecoverable join");
829 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
830 $user_cur = &$this->user[$table_cur->player[$i]];
831 $user_cur->subst = "shutdowner";
832 $user_cur->step_inc();
834 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
835 $ret .= "gst.st = ".($user_cur->step+1)."; ";
836 $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);
837 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
838 $user_cur->step_inc();
841 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
842 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
843 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
845 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
847 $this->room_join_wakeup(&$user_cur, TRUE, -2);
848 $table_cur->table_token = "";
851 Briskin5::unlock_data($sem);
853 } // if ($table_cur->player_n == PLAYERS_N) {
854 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
856 log_rd2("out new loop.");
858 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
859 $user_cur = &$this->user[$i];
861 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
863 if ($user_cur->sess == "")
866 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
867 // Auto logout dell'utente
868 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
870 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
871 log_auth($user_cur->sess, "Autologout session.");
875 log_rd2("AUTO LOGOUT.");
876 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
877 $this->room_wakeup(&$user_cur);
878 else if ($user_cur->subst == 'standup')
879 $this->room_outstandup(&$user_cur);
881 log_rd2("LOGOUT FROM WHAT ???");
885 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
886 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
887 $this->room_wakeup(&$user_cur);
888 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
889 /* 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" */
890 $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);
891 $user_cur->step_inc();
895 log_rd2("GARBAGE UPDATED!");
897 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
904 function show_room($user_step, &$user)
906 log_main("show_room: username: ".$user->name);
908 $ret = sprintf('gst.st = %d; ', $user_step);
910 if ($user->flags & USER_FLAG_LISTAUTH) {
911 $ret .= 'list_set(\'auth\', false, \'(solo aut.)\' ); ';
914 $ret .= 'list_set(\'all\', false, \'\' ); ';
917 if ($user->subst == 'standup')
918 $ret .= "tra.show(); ";
920 $ret .= "tra.hide(); ";
922 $ret .= sprintf('stat = "%s";', $user->stat);
924 $ret .= root_wellcome($user);
925 $ret .= sprintf('subst = "%s";', $user->subst);
926 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
927 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
928 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
929 for ($i = 0 ; $i < TABLES_N ; $i++) {
930 $ret .= $this->table_content($user, $i);
931 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
932 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
933 $ret .= $this->table[$i]->act_content($user);
934 if ($this->table[$i]->wag_own != NULL)
935 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
937 $ret .= sprintf('tra.rem(%d); ', $i);
939 $ret .= $this->standup_content($user);
945 function room_wakeup(&$user)
947 $table_idx = $user->table;
948 $table = &$this->table[$table_idx];
950 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
954 $from_table = ($user->stat == "table");
956 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
958 for ($i = 0 ; $i < $table->player_n ; $i++) {
959 $user_cur = &$this->user[$table->player[$i]];
960 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
962 if ($user_cur != $user) {
963 $user_cur->stat_set("room");
964 $user_cur->subst = "sitdown";
965 $user_cur->laccwr = $curtime;
967 else if ($user->sess != "") {
968 $user_cur->stat_set("room");
969 $user_cur->subst = "standup";
970 $user_cur->laccwr = $curtime;
971 $user_cur->table = -1;
976 $user->stat_set("room");
977 $user->subst = "standup";
978 $user->laccwr = $curtime;
981 $remove_wagon = false;
982 if($table->wag_own == $user) {
983 $remove_wagon = true;
984 $table->wag_reset($curtime);
989 /* aggiorna l'array dei giocatori al tavolo. */
990 $table->user_rem(&$this, &$user);
992 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
993 $user_cur = &$this->user[$i];
994 if ($user_cur->sess == '' || $user_cur->stat != 'room')
997 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
999 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1000 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
1001 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1002 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1003 log_main("DOCUMENT.index.php: from table");
1005 else if ($user_cur->stat == "room") {
1006 log_main("DOCUMENT.index.php: from table");
1008 $ret .= $this->table_content($user_cur, $table_idx);
1009 $ret .= $this->standup_content($user_cur);
1011 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1012 $ret .= $table->act_content($user);
1014 if ($user_cur == $user) {
1015 // set the new status
1016 $ret .= 'subst = "standup"; tra.show(); ';
1017 // clean the action buttons in other tables
1018 for ($e = 0 ; $e < TABLES_N ; $e++) {
1019 if ($this->table[$e]->player_n < PLAYERS_N) {
1020 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1021 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1022 $ret .= $this->table[$e]->act_content($user);
1027 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1028 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1029 $ret .= $table->act_content($user_cur);
1032 log_wr("ROOM_WAKEUP: ".$ret);
1033 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1034 $user_cur->step_inc();
1038 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1040 $table_idx = $user->table;
1041 $table = &$this->table[$table_idx];
1043 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1046 $user_wup = array();
1048 $user_tab = array();
1050 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1052 for ($i = 0 ; $i < $table->player_n ; $i++) {
1053 $user_cur = &$this->user[$table->player[$i]];
1054 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1055 if ($user_cur->sess != "") {
1056 if ($update_lacc == TRUE) {
1057 $user_cur->laccwr = $curtime;
1059 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1060 if ($user_cur->subst == "shutdowned") {
1061 $user_cur->stat_set("room");
1062 $user_cur->subst = "sitdown";
1064 else if ($user_cur->subst == "shutdowner") {
1065 $user_cur->stat_set("room");
1066 $user_cur->subst = "standup";
1067 $user_cur->table = -1;
1068 $user_wup[$user_wup_n++] = &$user_cur;
1070 $remove_wagon = false;
1071 if($table->wag_own == $user_cur) {
1072 $remove_wagon = true;
1073 $table->wag_reset($curtime);
1076 $user_tab[$user_tab_n++] = &$user_cur;
1080 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1081 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1083 /* aggiorna l'array dei giocatori al tavolo. */
1085 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1086 log_main("START LOOP");
1087 $user_cur = &$this->user[$i];
1088 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1089 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1094 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1096 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1097 if ($user_cur->stat == "room") {
1098 log_main("DOCUMENT.index.php from table");
1100 $ret .= $this->table_content($user_cur, $table_idx);
1101 $ret .= $this->standup_content($user_cur);
1103 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1104 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1105 $ret .= $table->act_content($user_cur);
1108 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1109 if ($user_cur == $user_tab[$tab_idx])
1112 // for users that wakeup the room will be reconstructed by index_rd.php
1113 if ($tab_idx < $user_tab_n) {
1114 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1116 // ARRAY_POP DISABLED
1117 // if ($trans_delta == 0)
1118 // while (array_pop($user_cur->comm) != NULL);
1120 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1121 $user_cur->comm[$user_cur->step % COMM_N] = "";
1122 $user_cur->step_inc();
1123 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1124 $user_cur->step_inc();
1125 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1129 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1131 log_main("JOIN_WAKEUP more");
1132 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1133 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1134 $ret .= $table->act_content($user_cur);
1136 log_main("JOIN_WAKEUP end more");
1138 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1139 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1140 $user_cur->step_inc();
1144 function room_outstandup(&$user)
1146 $this->room_sitdown(&$user, -1);
1149 function table_update(&$user)
1151 log_main("table_update: pre - USER: ".$user->name);
1153 $table_idx = $user->table;
1155 if ($table_idx > -1)
1156 $table = &$this->table[$table_idx];
1158 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1160 $user_cur = &$this->user[$i];
1161 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1164 $ret = "gst.st = ".($user_cur->step+1)."; ";
1165 if ($table_idx > -1)
1166 $ret .= $this->table_content($user_cur, $table_idx);
1168 if ($user_cur == $user) {
1169 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1170 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1171 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1173 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1174 $user_cur->step_inc();
1177 log_main("table_update: post");
1180 function room_sitdown(&$user, $table_idx)
1182 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1186 if ($table_idx > -1 && $table_idx < TABLES_N) {
1187 $table = &$this->table[$table_idx];
1190 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1191 for ($i = 0 ; $i < TABLES_N ; $i++) {
1192 $user_cur =& $this->user[$table->player[$i]];
1193 if ($user_cur == $table->wag_own) {
1194 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1195 $table->wag_reset(time());
1202 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1204 $user_cur = &$this->user[$i];
1205 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1208 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1209 if ($table_idx > -1)
1210 $ret .= $this->table_content($user_cur, $table_idx);
1211 $ret .= $this->standup_content($user_cur);
1213 if ($user_cur == $user) {
1214 $ret .= 'subst = "sitdown"; tra.hide(); ';
1215 // clean the action buttons in other tables
1216 for ($e = 0 ; $e < TABLES_N ; $e++) {
1217 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1218 $ret .= $this->table[$e]->act_content($user_cur);
1221 else if ($table_idx > -1) {
1222 if ($table->player_n == PLAYERS_N) {
1223 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1224 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1225 $ret .= $table->act_content($user_cur);
1228 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1229 $user_cur->step_inc();
1233 function chatt_send(&$user, $mesg)
1235 GLOBAL $G_alarm_passwd;
1239 $msg = substr($mesg, 6, 128);
1241 $dt = date("H:i ", $curtime);
1251 $is_normchat = FALSE;
1252 $update_room = FALSE;
1254 if (strcmp($msg, "/tav") == 0 ||
1255 strncmp($msg, "/tav ", 5) == 0) {
1257 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1258 /* 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>" */
1259 $msg = "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>";
1260 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1265 $table = &$this->table[$user->table];
1267 if ($table->wag_own != NULL) {
1268 $msg = "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>";
1269 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1274 $dtime = $curtime - $table->wag_tout;
1275 if ($dtime < EXPIRE_TIME_WAG) {
1276 $msg = sprintf("<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>",
1277 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? "o" : "i"));
1278 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1283 $msg = substr($msg, 5);
1285 $table->wag_set($user, $msg);
1286 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1287 $to_room = $to_user;
1290 } // /tav chat command
1292 else if (strncmp($msg, "/alarm ", 7) == 0) {
1293 if (strncmp($msg, "/alarm to ", 10) == 0) {
1294 $sp_pos = strpos($msg, " ", 10);
1295 $target = substr($msg, 10, $sp_pos - 10);
1296 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1300 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1303 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1304 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1305 $msg = "<br>La password digitata non è corretta.<br><br>";
1306 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1311 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1312 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Alarm <b>%s</b> inviato a <b>%s</b>.");',
1313 $dt, NICKSERV, xcape(substr($msg, strlen($alarm_check))),
1314 ($target == "" ? "tutti" : xcape($target)) );
1316 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1317 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1318 /* MLANG: "chiudi" */
1319 $to_all = show_notify($msg, 0, "chiudi", 400, 120);
1321 } // /alarm chat command
1322 else if (strncmp($msg, "/listen ", 8) == 0) {
1323 $arg = substr($msg, 8);
1325 if (strcasecmp($arg, "auth") == 0) {
1326 $user->flags |= USER_FLAG_LISTAUTH;
1327 $to_user = 'list_set(\'auth\', true, \'(solo aut.)\'); ';
1330 $user->flags &= ~USER_FLAG_LISTAUTH;
1331 $to_user = 'list_set(\'all\', true, \'\'); ';
1334 else if (strncmp($msg, "/garante", 8) == 0) {
1335 if ($user->flags & USER_FLAG_AUTH) {
1336 $to_user = sprintf('authbox(300,200);');
1339 /* 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." */
1340 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
1343 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1344 if ($user->flags & USER_FLAG_AUTH) {
1345 $to_user = sprintf('mesgtoadmbox(500,300);');
1348 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1349 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per inviare un messaggio devi essere autenticato.</b>");', $dt, NICKSERV);
1352 else if (strncmp($msg, "/nick ", 6) == 0) {
1353 log_main("chatt_send BEGIN");
1356 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1357 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.");', $dt, NICKSERV);
1361 $msg = "COMMAND ".$msg;
1362 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1363 $user_cur = &$this->user[$i];
1365 if ($user_cur->sess == '')
1367 if ($user_cur->name == $name_new)
1370 if ($i < MAX_PLAYERS) {
1371 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Nickname <b>%s</b> già in uso.");', $dt, NICKSERV, xcape($name_new));
1375 /* 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>" */
1376 if ($user->flags & USER_FLAG_AUTH) {
1377 if (strcasecmp($user->name,$name_new) != 0) {
1378 if ($user->subst == 'standup' || ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)) {
1379 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1380 for ($i = 0 ; $i < TABLES_N ; $i++) {
1381 $to_user .= $this->table[$i]->act_content($user);
1385 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>");', $dt, NICKSERV);
1390 $user->name = $name_new; // OK - nick changed
1391 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1392 if (($user->flags & USER_FLAG_AUTH) == 0) {
1393 $userdb = new LoginDB();
1394 /* 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>" */
1395 if ($userdb->login_exists($name_new)) {
1396 $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));
1400 log_main("chatt_send start set");
1402 $update_room = TRUE;
1404 } // nick chat command
1406 else if (strncmp($msg, "/st ", 4) == 0) {
1407 log_main("chatt_send BEGIN");
1410 $st_str = substr($msg, 4);
1412 if (strcasecmp($st_str, "normale") == 0) {
1413 $st = USER_FLAG_S_NORM;
1415 else if (strcasecmp($st_str, "pausa") == 0) {
1416 $st = USER_FLAG_S_PAU;
1418 else if (strcasecmp($st_str, "fuori") == 0) {
1419 $st = USER_FLAG_S_OUT;
1421 else if (strcasecmp($st_str, "cane") == 0) {
1422 $st = USER_FLAG_S_DOG;
1424 else if (strcasecmp($st_str, "cibo") == 0) {
1425 $st = USER_FLAG_S_EAT;
1427 else if (strcasecmp($st_str, "lavoro") == 0) {
1428 $st = USER_FLAG_S_WRK;
1430 else if (strcasecmp($st_str, "sigaretta") == 0) {
1431 $st = USER_FLAG_S_SMK;
1433 else if (strcasecmp($st_str, "presente") == 0) {
1434 $st = USER_FLAG_S_EYE;
1437 /* MLANG: "Questo stato non esiste." */
1438 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Questo stato non esiste.");', $dt, NICKSERV);
1442 log_main("chatt_send start set");
1443 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1444 $update_room = TRUE;
1445 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1448 } // nick chat command
1450 else { // normal chat line
1451 $is_normchat = TRUE;
1452 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1454 $user->chat_dlt = $user->chat_dlt * 2;
1455 if ($user->chat_dlt > 120)
1456 $user->chat_dlt = 120;
1458 else if ($user->chat_lst == $msg)
1460 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1461 $user->chat_ban = $curtime;
1462 $user->chat_dlt = 5;
1466 $user->chat_ban = 0;
1467 $user->chat_dlt = 0;
1471 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1474 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1475 // temporary silentiation for troll (will became array check)
1476 if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1477 $to_room = $to_user;
1480 log_legal($curtime, $user,
1481 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1483 $user->chat_lst = "$msg";
1484 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1494 // Output to clients
1497 if ($to_user != FALSE) {
1498 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1499 $user->comm[$user->step % COMM_N] .= $to_user;
1503 if ($to_room != FALSE) {
1504 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1505 $user_cur = &$this->user[$i];
1506 if ($target != "" && $user_cur->name != $target)
1508 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1509 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1512 if ($is_normchat == TRUE) {
1513 if ($user_cur->flags & USER_FLAG_LISTAUTH) {
1514 if (($user->flags & USER_FLAG_AUTH) == 0) {
1520 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1521 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1522 $user_cur->step_inc();
1527 // FIXME BRISK4: include for each kind of table
1528 require_once("briskin5/Obj/briskin5.phh");
1529 // Before all align times with table timeout
1530 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1531 $table_cur =& $this->table[$table_idx];
1532 // if the table is complete and exists its shared mem we get the info about users lacc
1534 if ($table_cur->player_n == PLAYERS_N) {
1535 log_main("PLAYERS == N TABLE ".$table_idx);
1537 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1538 log_main("bin5 lock data success");
1540 $no_recovery = FALSE;
1541 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1542 if ($table_cur->table_token != $bri->table_token) {
1543 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1548 if ($bri != FALSE) {
1549 $bri_table = &$bri->table[0];
1550 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1551 // stat must be "table" by definition
1552 $bri_user =& $bri->user[$i];
1554 if ($target != "" && $bri_user->name != $target)
1556 log_main("writa: ".$user_mesg);
1557 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1558 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1559 $bri_user->step_inc();
1561 Briskin5::save_data(&$bri);
1563 Briskin5::unlock_data($sem);
1565 } // if ($table_cur->player_n == PLAYERS_N) {
1566 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1567 } // if ($to_tabl == true ...
1570 if ($user->stat == 'room' && $user->subst == 'standup') {
1571 $this->standup_update(&$user);
1573 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1574 log_main("chatt_send pre table update");
1575 $this->table_update(&$user);
1576 log_main("chatt_send post table update");
1578 } // if ($update_room ...
1581 } // function chatt_send( ...
1583 function &get_user($sess, &$idx)
1585 GLOBAL $PHP_SELF, $G_false;
1587 if (validate_sess($sess)) {
1588 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1589 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1592 $ret = &$this->user[$i];
1596 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1597 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1598 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1601 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1610 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1613 * if ($idx > -1 && ret == FALSE) => duplicated nick
1614 * if ($idx == -2 && ret == FALSE) => invalid name
1615 * if ($idx == -3 && ret == FALSE) => wrong password
1616 * if ($idx == -1 && ret == FALSE) => no space left
1617 * if ($idx == 0 && ret == user) => SUCCESS
1618 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1623 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1625 GLOBAL $G_false, $CO_list;
1629 $authenticate = FALSE;
1630 $login_exists = FALSE;
1632 $ghost_auth = FALSE;
1636 if (($name_new = validate_name($name)) == FALSE) {
1641 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1642 if (validate_sess($sess) == FALSE)
1645 /* if pass != FALSE verify the login with pass */
1646 log_auth("XXX", "auth1");
1647 $userdb = new LoginDB();
1648 if ($pass != FALSE) {
1649 log_auth("XXX", "auth2");
1650 $authenticate = $userdb->login_verify($name_new, $pass);
1651 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1653 if ($authenticate == FALSE) {
1659 $login_exists = $userdb->login_exists($name_new);
1661 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1663 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1667 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1669 continue; // NOTE: CHECK IT !!
1671 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1672 if ($authenticate == FALSE) {
1678 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1685 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1687 if ($ghost > -1 && $ghost_auth && $authenticate) {
1690 $ghost_user =& $this->user[$ghost];
1692 $ghost_user->step_inc();
1695 $ghost_user->sess = $sess;
1698 $ghost_user->sess = $sess;
1701 // If user at the table we need to update the table data too
1702 $table_idx = $ghost_user->table;
1703 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1704 // FIXME BRISK4: include for each kind of table
1705 require_once("briskin5/Obj/briskin5.phh");
1706 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1707 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1708 if ($bri->the_end != TRUE) {
1709 $bri->user[$ghost_user->table_pos]->step_inc();
1710 $bri->user[$ghost_user->table_pos]->sess = $sess;
1711 Briskin5::save_data(&$bri);
1714 Briskin5::unlock_data($brisem);
1719 return ($this->user[$ghost]);
1721 else if ($idx != -1 && $i == MAX_PLAYERS) {
1726 $this->user[$idx]->sess = $sess;
1729 $this->user[$idx]->sess = $sess;
1731 $this->user[$idx]->name = $name_new; // OK - add new user
1732 $this->user[$idx]->stat_set("room");
1733 $this->user[$idx]->step_set(0);
1734 while (array_pop($this->user[$idx]->comm) != NULL);
1735 $this->user[$idx]->subst = "standup";
1736 $this->user[$idx]->lacc = $curtime;
1737 $this->user[$idx]->laccwr = $curtime;
1738 $this->user[$idx]->bantime = 0;
1739 $this->user[$idx]->ip = $ip;
1741 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1743 if ($authenticate) {
1744 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1746 if (isset($CO_list) && strcmp($CO_list, "all") == 0) {
1747 $this->user[$idx]->flags &= ~USER_FLAG_LISTAUTH;
1752 log_main("ghost: rename!");
1753 $ghost_user =& $this->user[$ghost];
1755 if ($ghost_auth == FALSE) {
1756 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1757 $ghostname = 'ghost'.$sfx;
1758 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1759 if (strcmp("", $this->user[$i]->sess) == 0)
1762 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1767 if ($ghostname != '')
1771 $ghost_user->name = $ghostname;
1773 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1774 $this->standup_update(&$ghost_user);
1777 log_main("chatt_send pre table update");
1778 $this->table_update(&$ghost_user);
1779 log_main("chatt_send post table update");
1781 } // if ($ghost_auth == FALSE
1783 // FIXME: cacciare il vecchio utente room && table (if needed)
1784 $ghost_user->the_end = TRUE;
1785 $ghost_user->lacc = 0;
1786 $this->garbage_manager(TRUE);
1788 } // if ($ghost > -1) {
1790 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1794 return ($this->user[$real_idx]);
1800 function standup_update(&$user)
1802 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1803 $user_cur = &$this->user[$i];
1804 if ($user_cur->sess == '')
1807 log_main("STANDUP START: ".$user_cur->stat);
1809 if ($user_cur->stat == 'room') {
1810 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1811 if ($user_cur == $user) {
1812 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1813 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1815 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
1816 $itin, xcape($user->name), $itou);
1818 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1820 $user_cur->step_inc();
1826 function &init_data()
1828 $room =& new Room();
1834 function &load_data()
1836 GLOBAL $G_false, $sess;
1839 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1840 log_main("ftok failed");
1845 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1846 log_main("shmop_open failed");
1850 $shm_sz = SHM_DIMS_MIN;
1852 if ($shm = shm_attach($tok, $shm_sz)) {
1853 $room = @shm_get_var($shm, $tok);
1855 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1857 log_only("bri count ".count($room));
1859 if ($room == FALSE) {
1860 log_only("INIT MAIN DATA");
1862 $room =& Room::init_data();
1863 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1864 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1865 log_only(serialize($room));
1868 $room->shm_sz = $shm_sz;
1883 function save_data(&$room)
1891 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1894 while ($room->shm_sz < SHM_DIMS_MAX) {
1895 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1898 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1899 if (shm_put_var($shm, $tok, $room) != FALSE) {
1903 if (shm_remove($shm) === FALSE) {
1904 log_only("REMOVE FALLITA");
1908 $room->shm_sz += SHM_DIMS_DLT;
1917 function lock_data()
1921 // echo "LOCK: ".FTOK_PATH."/main";
1923 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1926 // echo "FTOK ".$tok."<br>";
1927 if (($res = sem_get($tok)) == FALSE) {
1930 if (sem_acquire($res)) {
1931 log_lock("LOCK room");
1938 function unlock_data($res)
1942 log_lock("UNLOCK room");
1944 return (sem_release($res));
1948 function standup_content($user)
1953 if ($user->stat != 'room')
1956 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1957 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1962 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1964 $content = ' j_stand_cont( [ ';
1966 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1967 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1970 $flags = $this->user[$e]->flags;
1972 if ($this->user[$e]->subst == "standup") {
1973 if ($this->user[$e] == $user)
1978 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
1987 function table_content_old($user, $table_idx)
1993 // Si possono usare i dati nella classe table
1996 $sess = $user->sess;
1997 $table = &$this->table[$table_idx];
1999 if ($user->stat != 'room')
2002 for ($i = 0 ; $i < $table->player_n ; $i++) {
2003 $user_cur = &$this->user[$table->player[$i]];
2005 if ($user_cur == $user)
2006 { $hilion = "<b>"; $hilioff = "</b>"; }
2008 { $hilion = ""; $hilioff = ""; }
2010 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2012 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
2015 for ( ; $i < PLAYERS_N ; $i++)
2019 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
2025 function table_content($user, $table_idx)
2031 // Si possono usare i dati nella classe table
2034 $sess = $user->sess;
2035 $table = &$this->table[$table_idx];
2037 if ($user->stat != 'room')
2041 for ($i = 0 ; $i < $table->player_n ; $i++) {
2042 $user_cur = &$this->user[$table->player[$i]];
2044 $flags = $user_cur->flags;
2046 if ($user_cur == $user)
2049 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2051 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2056 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2063 function make_seed()
2065 list($usec, $sec) = explode(' ', microtime());
2066 return (float) $sec + ((float) $usec * 100000);
2070 function log_only2($log) {
2073 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2076 if (isset($sess) == FALSE)
2081 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2084 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2085 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2090 function log_crit($log) {
2093 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2096 if (isset($sess) == FALSE)
2101 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2104 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2105 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2110 function log_only($log) {
2113 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2116 if (isset($sess) == FALSE)
2121 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2124 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2125 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2130 function log_main($log) {
2133 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2136 if (isset($sess) == FALSE)
2141 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2144 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2145 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2150 function log_rd($log) {
2153 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2156 if (isset($sess) == FALSE)
2161 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2164 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2165 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2170 function log_rd2($log) {
2173 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2176 if (isset($sess) == FALSE)
2181 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2184 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2185 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2190 function log_send($log) {
2193 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2196 if (isset($sess) == FALSE)
2201 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2204 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2205 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2210 function log_lock($log) {
2213 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2216 if (isset($sess) == FALSE)
2221 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2224 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2225 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2230 function log_wr($log) {
2233 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2236 if (isset($sess) == FALSE)
2241 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2244 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2245 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2250 function log_load($log) {
2253 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2256 if (isset($sess) == FALSE)
2261 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2264 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2265 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2270 function log_auth($sess, $log) {
2271 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2274 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2277 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2278 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2284 // function log_legal($curtime, $sess, $name, $where, $mesg)
2285 function log_legal($curtime, &$user, $where, $mesg)
2289 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2290 /* Unix time | session | nickname | IP | where was | mesg */
2291 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2292 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2293 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2301 function lock_banlist()
2303 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2307 if (($res = sem_get($tok)) == FALSE) {
2308 echo "SEM_GET FAILED";
2311 if (sem_acquire($res))
2317 function unlock_banlist($res)
2319 return (sem_release($res));
2322 function table_act_content_old($isstanding, $sitted, $table, $cur_table)
2327 if ($sitted < PLAYERS_N) {
2328 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
2332 if ($table == $cur_table)
2333 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
2340 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2345 if ($sitted < PLAYERS_N) {
2353 if ($table == $cur_table)
2360 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2365 function show_notify($text, $tout, $butt, $w, $h)
2367 log_main("SHOW_NOTIFY: ".$text);
2368 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2371 function multoval($mult)
2375 else if ($mult == 4)
2376 return ("quadruplo");
2378 return (sprintf("%d-plo", $mult));
2382 function root_wellcome($user)
2384 GLOBAL $root_wellarr;
2388 $dt = date("H:i ", $curtime);
2390 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2391 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$i]));
2398 function validate_sess($sess)
2400 if (strlen($sess) == SESS_LEN)
2406 function validate_name($name)
2408 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2410 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2412 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2419 function playsound($filename)
2421 return (sprintf('playsound("flasou", "%s");', $filename));
2424 function secstoword($secs)
2426 $mins = floor($secs / 60);
2429 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2432 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2437 function sharedmem_sz($tok)
2439 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2440 log_main("shmop_open failed");
2443 $shm_sz = shmop_size($shm_id);
2444 shmop_close($shm_id);
2446 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2451 function lock_data()
2455 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2458 // echo "FTOK ".$tok."<br>";
2459 if (($res = sem_get($tok)) == FALSE) {
2462 if (sem_acquire($res)) {
2463 log_lock("LOCK room");
2470 function unlock_data($res)
2474 log_lock("UNLOCK room");
2476 return (sem_release($res));