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.6 - trusty";
85 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
86 $root_wellarr = Array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: menu comandi e filtro sui non autenticati.',
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)
123 <div id=\\"header\\" class=\\"header\\">
124 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
125 briscola chiamata in salsa ajax
127 <br><b>version '.$G_brisk_version.'</b><br><br>
128 Copyright 2006-2008 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
133 $from = array ( '\\', '@', '|' );
134 $to = array ( '\\\\', '@', '¦' );
136 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
141 $from = array ( '\\', '|', "\t", "\n");
142 $to = array ( '\\\\', '\\|', "\\t", "\\n");
144 return (str_replace($from, $to, $s));
153 var $auth_only; // se tavolo riservato o libero
160 var $table_start; // information field
168 function &create($idx)
172 if (($thiz =& new Table()) == FALSE)
176 $thiz->player = array();
178 $thiz->auth_only = FALSE;
180 $thiz->wag_own = NULL;
184 $thiz->table_token = "";
185 $thiz->table_start = 0;
187 $thiz->wakeup_time = 0;
192 function copy(&$from)
196 $this->idx = $from->idx;
197 $this->player = array();
198 for ($i = 0 ; $i < $from->player_n ; $i++)
199 $this->player[$i] = $from->player[$i];
200 $this->player_n = $from->player_n;
202 log_main("PLAYER_N - parent::copy.".$this->player_n);
204 $this->auth_only = $from->auth_only;
206 $this->wag_own = $from->wag_own;
207 $this->wag_com = $from->wag_com;
208 $this->wag_tout = $from->wag_tout;
210 $this->table_token = $from->table_token;
211 $this->table_start = $from->table_start;
213 $this->wakeup_time = $from->wakeup_time;
216 function &clone(&$from)
220 if (($thiz =& new Table()) == FALSE)
228 function &spawn(&$from)
232 if (($thiz =& new Table()) == FALSE)
235 $thiz->idx = $from->idx;
236 $thiz->player = array();
237 for ($i = 0 ; $i < $from->player_n ; $i++)
238 $thiz->player[$i] = $i;
239 $thiz->player_n = $from->player_n;
241 $thiz->auth_only = $from->auth_only;
243 $thiz->wag_own = $from->wag_own;
244 $thiz->wag_com = $from->wag_com;
245 $thiz->wag_tout = $from->wag_tout;
247 $thiz->table_token = $from->table_token;
248 $thiz->table_start = $from->table_start;
250 $thiz->wakeup_time = $from->wakeup_time;
255 function wag_set(&$user, $mesg)
259 $this->wag_own = &$user;
260 $this->wag_com = $mesg;
264 function wag_reset($timeout)
266 log_main("WAG_RESET");
268 unset($this->wag_own);
269 $this->wag_own = NULL;
271 $this->wag_tout = $timeout;
274 function getPlayer($idx)
276 return ($this->player[$idx]);
279 function setPlayer($idx, $player)
281 $this->player[$idx] = $player;
284 function user_add($idx)
286 $this->player[$this->player_n] = $idx;
289 return ($this->player_n - 1);
292 function user_rem(&$room, &$user)
294 $tabpos = $user->table_pos;
296 /* verifico la consistenza dei dati */
297 if ($room->user[$this->player[$tabpos]] == $user) {
299 /* aggiorna l'array dei giocatori al tavolo. */
300 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
301 $this->player[$i] = $this->player[$i+1];
302 $user_cur = &$room->user[$this->player[$i]];
303 $user_cur->table_pos = $i;
308 log_main("INCONSISTENCY ON TABLE.");
314 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
315 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
317 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
318 function act_content(&$user)
321 $isstanding = ($user->subst == 'standup');
322 $sitted = $this->player_n;
324 $cur_table = $user->table;
328 if ($sitted < PLAYERS_N) {
329 if ($this->auth_only) {
330 if ($user->flags & USER_FLAG_AUTH)
344 if ($table == $cur_table)
351 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
359 define(USER_FLAG_AUTH, 0x02);
360 define(USER_FLAG_LISTAUTH, 0x04);
363 define(USER_FLAG_S_NORM, 0x000); // done
364 define(USER_FLAG_S_PAU, 0x100); // done
365 define(USER_FLAG_S_OUT, 0x200); // done
366 define(USER_FLAG_S_DOG, 0x300); // done
367 define(USER_FLAG_S_EAT, 0x400); // done
368 define(USER_FLAG_S_WRK, 0x500); // done
369 define(USER_FLAG_S_SMK, 0x600); // done
370 define(USER_FLAG_S_EYE, 0x700); // done
372 define(USER_FLAG_S_ALL, 0xf00); // done
375 var $name; // name of the user
376 var $sess; // session of the user
377 var $ip; // ip of the user
378 var $lacc; // last access (for the cleanup)
379 var $laccwr; // last access (for the cleanup)
380 var $bantime; // timeout to temporary ban
381 var $stat; // status (outdoor, room, table, game, ...)
382 var $subst; // substatus for each status
383 var $step; // step of the current status
384 var $trans_step; // step to enable transition between pages (disable == -1)
385 var $comm; // commands array
386 // var $asta_card; //
388 // var $handpt; // Total card points at the beginning of the current hand.
389 // var $exitislock; // Player can exit from the table ?
391 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
392 // it is allways ZERO
393 var $table_orig; // id of the current table (if in table state)
394 var $table; // id of the current table (if in table state)
395 var $table_pos; // idx on the table
396 var $table_token;// token that identify a game on a table
397 var $flags; // Bitfield with: AUTHENTICATE: 0x02
398 var $the_end; // Flag to change the end of the session
400 var $chat_lst; // Last chat line
401 var $chattime; // Array of chat times
402 var $chat_cur; // Current chat line number
403 var $chat_ban; // Time for ban chat
404 var $chat_dlt; // Delta t for ban
408 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
411 if (($thiz =& new User()) == FALSE)
417 $thiz->lacc = time();
418 $thiz->laccwr = time();
421 $thiz->subst = $subst;
423 $thiz->trans_step = -1;
424 $thiz->comm = array();
425 $thiz->asta_card = -2;
426 $thiz->asta_pnt = -1;
428 $thiz->exitislock = TRUE;
432 $thiz->chattime = array_fill(0, CHAT_N, 0);
434 $thiz->chat_lst = "";
438 $thiz->table_orig = $table;
439 $thiz->table = $table;
440 $thiz->table_pos = -1;
441 $thiz->table_token = "";
446 function copy(&$from)
450 $this->name = $from->name;
451 $this->sess = $from->sess;
452 $this->ip = $from->ip;
453 $this->lacc = $from->lacc;
454 $this->laccwr = $from->laccwr;
455 $this->bantime = $from->bantime;
456 $this->stat = $from->stat;
457 $this->subst = $from->subst;
458 $this->step = $from->step;
459 $this->trans_step = $from->trans_step;
460 $this->comm = array();
462 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
463 for ($i = $i_start ; $i < $from->step ; $i++) {
465 $this->comm[$ii] = $from->comm[$ii];
467 $this->asta_card = $from->asta_card;
468 $this->asta_pnt = $from->asta_pnt;
469 $this->handpt = $from->handpt;
470 $this->exitislock = $from->exitislock;
472 $this->flags = $from->flags;
474 $this->chattime = array();
475 for ($i = 0 ; $i < CHAT_N ; $i++)
476 $this->chattime[$i] = $from->chattime[$i];
477 $this->chat_cur = $from->chat_cur;
478 $this->chat_lst = $from->chat_lst;
479 $this->chat_ban = $from->chat_ban;
480 $this->chat_dlt = $from->chat_dlt;
482 $this->table_orig = $from->table_orig;
483 $this->table = $from->table;
484 $this->table_pos = $from->table_pos;
485 $this->table_token = $from->table_token;
486 $this->the_end = $from->the_end;
492 function &clone(&$from)
496 if (($thiz =& new User()) == FALSE)
504 function &spawn(&$from, $table, $table_pos)
508 if (($thiz =& new User()) == FALSE)
511 $thiz->name = $from->name;
512 $thiz->sess = $from->sess;
513 $thiz->ip = $from->ip;
514 $thiz->lacc = $from->lacc;
515 $thiz->laccwr = $from->laccwr;
516 $thiz->bantime = $from->bantime;
517 $thiz->stat = $from->stat;
518 $thiz->subst = $from->subst;
519 $thiz->step = $from->step;
520 $thiz->trans_step = $from->trans_step;
521 $thiz->comm = array();
524 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
525 for ($i = $i_start ; $i < $from->step ; $i++) {
526 log_wr("TRY PUSH:".$i);
528 $thiz->comm[$ii] = $from->comm[$ii];
531 $thiz->asta_card = $from->asta_card;
532 $thiz->asta_pnt = $from->asta_pnt;
533 $thiz->handpt = $from->handpt;
534 $thiz->exitislock = $from->exitislock;
535 $thiz->the_end = $from->the_end;
537 $thiz->flags = $from->flags;
539 $thiz->chattime = array_fill(0, CHAT_N, 0);
541 $thiz->chat_lst = "";
546 $thiz->table_orig = $table;
548 $thiz->table_pos = $table_pos;
549 $thiz->table_token = $from->table_token;
554 function stat_set($stat) {
555 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
556 $this->stat = "$stat";
559 if (validate_sess($this->sess)) {
560 if (file_exists(PROXY_PATH) == FALSE)
562 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
563 fwrite($fp, sprintf("%s\n",$this->stat));
569 function step_set($step) {
573 if (validate_sess($this->sess) == FALSE)
575 if (file_exists(PROXY_PATH) == FALSE)
577 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
579 fwrite($fp, pack("l",$this->step), 4);
588 function step_inc($delta = 1) {
589 $this->step += $delta;
591 if (validate_sess($this->sess)) {
592 if (file_exists(PROXY_PATH) == FALSE)
594 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
595 fwrite($fp, pack("l",$this->step), 4);
606 log_legal($curtime, $this, "STAT:LOGOUT", '');
608 $tmp_sess = $this->sess;
610 step_unproxy($tmp_sess);
611 $this->name = ""; // OK here
612 while (array_pop($this->comm) != NULL);
614 $this->chattime = array_fill(0, CHAT_N, 0);
616 $this->chat_lst = "";
619 $this->the_end = FALSE;
629 function step_get($sess) {
632 if (validate_sess($sess) == FALSE)
635 if (file_exists(PROXY_PATH) == FALSE)
637 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
639 if (($s = fread($fp, 4)) == FALSE)
643 $arr = unpack('l', $s);
646 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
653 log_rd2("STEP_GET: return false ");
658 function step_unproxy($sess) {
659 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
660 if (file_exists(PROXY_PATH) == FALSE)
662 @unlink(PROXY_PATH."/".$sess.".step");
669 var $comm; // commands for many people
670 var $step; // current step of the comm array
671 var $garbage_timeout;
675 $this->user = array();
676 $this->table = array();
678 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
679 $this->user[$i] =& User::create("", "");
682 for ($i = 0 ; $i < TABLES_N ; $i++) {
683 $this->table[$i] =& Table::create($i);
686 $row = ( (((int)($i / 4)) % 2) == 0 );
687 $col = ($i % 2 == 0);
688 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
691 $this->table[$i]->auth_only = FALSE;
695 $this->table[$i]->auth_only = TRUE;
697 $this->table[$i]->auth_only = FALSE;
699 $this->garbage_timeout = 0;
702 function garbage_manager($force)
706 log_rd2("garbage_manager START");
708 /* Garbage collector degli utenti in timeout */
710 if ($force || $this->garbage_timeout < $curtime) {
712 // Before all align times with table timeout
713 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
714 $table_cur =& $this->table[$table_idx];
715 // if the table is complete and exists its shared mem we get the info about users lacc
717 if ($table_cur->player_n == PLAYERS_N) {
718 log_main("PLAYERS == N TABLE ".$table_idx);
720 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
721 log_main("bin5 lock data success");
723 $no_recovery = FALSE;
724 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
725 if ($table_cur->table_token != $bri->table_token) {
726 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
727 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
737 log_main("garbage_manager: bri loaded successfully.");
738 $bri->garbage_manager(TRUE);
740 $bri_table = &$bri->table[0];
742 // is the end of the table
743 if ($bri->the_end == TRUE) {
745 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
747 log_main("garbage_manager: INSIDE THE END.");
749 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
750 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
751 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
754 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
755 // stat must be "table" by definition
756 $user_cur =& $this->user[$table_cur->player[$i]];
757 $bri_user =& $bri->user[$i];
759 $user_cur->subst = $bri_user->subst;
760 $user_cur->step = $bri_user->step;
761 $user_cur->lacc = $bri_user->lacc;
762 $user_cur->laccwr = $bri_user->lacc;
763 $user_cur->bantime = $bri_user->bantime;
766 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
768 $this->room_join_wakeup(&$user_cur, FALSE, 0);
769 $table_cur->table_token = "";
770 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
771 Briskin5::destroy_data($table_idx);
774 log_main("gm:: save_data");
776 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
777 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
780 Briskin5::save_data(&$bri);
782 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
783 else if ($no_recovery == FALSE) {
784 log_crit("ERROR: table ".$table_idx." unrecoverable join");
786 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
787 $user_cur = &$this->user[$table_cur->player[$i]];
788 $user_cur->subst = "shutdowner";
789 $user_cur->step_inc();
791 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
792 $ret .= "gst.st = ".($user_cur->step+1)."; ";
793 $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);
794 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
795 $user_cur->step_inc();
798 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
799 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
800 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
802 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
804 $this->room_join_wakeup(&$user_cur, TRUE, -2);
805 $table_cur->table_token = "";
808 Briskin5::unlock_data($sem);
810 } // if ($table_cur->player_n == PLAYERS_N) {
811 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
813 log_rd2("out new loop.");
815 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
816 $user_cur = &$this->user[$i];
818 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
820 if ($user_cur->sess == "")
823 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
824 // Auto logout dell'utente
825 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
827 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
828 log_auth($user_cur->sess, "Autologout session.");
832 log_rd2("AUTO LOGOUT.");
833 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
834 $this->room_wakeup(&$user_cur);
835 else if ($user_cur->subst == 'standup')
836 $this->room_outstandup(&$user_cur);
838 log_rd2("LOGOUT FROM WHAT ???");
842 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
843 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
844 $this->room_wakeup(&$user_cur);
845 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
846 /* 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" */
847 $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);
848 $user_cur->step_inc();
852 log_rd2("GARBAGE UPDATED!");
854 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
861 function show_room($user_step, &$user)
863 log_main("show_room: username: ".$user->name);
865 $ret = sprintf('gst.st = %d; ', $user_step);
867 if ($user->flags & USER_FLAG_LISTAUTH) {
868 $ret .= 'list_set(\'auth\', false, \'(solo aut.)\' ); ';
871 $ret .= 'list_set(\'all\', false, \'\' ); ';
874 if ($user->subst == 'standup')
875 $ret .= "tra.show(); ";
877 $ret .= "tra.hide(); ";
879 $ret .= sprintf('stat = "%s";', $user->stat);
881 $ret .= root_wellcome($user);
882 $ret .= sprintf('subst = "%s";', $user->subst);
883 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
884 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
885 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
886 for ($i = 0 ; $i < TABLES_N ; $i++) {
887 $ret .= $this->table_content($user, $i);
888 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
889 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
890 $ret .= $this->table[$i]->act_content($user);
891 if ($this->table[$i]->wag_own != NULL)
892 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
894 $ret .= sprintf('tra.rem(%d); ', $i);
896 $ret .= $this->standup_content($user);
902 function room_wakeup(&$user)
904 $table_idx = $user->table;
905 $table = &$this->table[$table_idx];
907 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
911 $from_table = ($user->stat == "table");
913 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
915 for ($i = 0 ; $i < $table->player_n ; $i++) {
916 $user_cur = &$this->user[$table->player[$i]];
917 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
919 if ($user_cur != $user) {
920 $user_cur->stat_set("room");
921 $user_cur->subst = "sitdown";
922 $user_cur->laccwr = $curtime;
924 else if ($user->sess != "") {
925 $user_cur->stat_set("room");
926 $user_cur->subst = "standup";
927 $user_cur->laccwr = $curtime;
928 $user_cur->table = -1;
933 $user->stat_set("room");
934 $user->subst = "standup";
935 $user->laccwr = $curtime;
938 $remove_wagon = false;
939 if($table->wag_own == $user) {
940 $remove_wagon = true;
941 $table->wag_reset($curtime);
946 /* aggiorna l'array dei giocatori al tavolo. */
947 $table->user_rem(&$this, &$user);
949 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
950 $user_cur = &$this->user[$i];
951 if ($user_cur->sess == '' || $user_cur->stat != 'room')
954 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
956 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
957 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
958 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
959 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
960 log_main("DOCUMENT.index.php: from table");
962 else if ($user_cur->stat == "room") {
963 log_main("DOCUMENT.index.php: from table");
965 $ret .= $this->table_content($user_cur, $table_idx);
966 $ret .= $this->standup_content($user_cur);
968 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
969 $ret .= $table->act_content($user);
971 if ($user_cur == $user) {
972 // set the new status
973 $ret .= 'subst = "standup"; tra.show(); ';
974 // clean the action buttons in other tables
975 for ($e = 0 ; $e < TABLES_N ; $e++) {
976 if ($this->table[$e]->player_n < PLAYERS_N) {
977 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
978 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
979 $ret .= $this->table[$e]->act_content($user);
984 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
985 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
986 $ret .= $table->act_content($user_cur);
989 log_wr("ROOM_WAKEUP: ".$ret);
990 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
991 $user_cur->step_inc();
995 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
997 $table_idx = $user->table;
998 $table = &$this->table[$table_idx];
1000 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1003 $user_wup = array();
1005 $user_tab = array();
1007 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1009 for ($i = 0 ; $i < $table->player_n ; $i++) {
1010 $user_cur = &$this->user[$table->player[$i]];
1011 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1012 if ($user_cur->sess != "") {
1013 if ($update_lacc == TRUE) {
1014 $user_cur->laccwr = $curtime;
1016 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1017 if ($user_cur->subst == "shutdowned") {
1018 $user_cur->stat_set("room");
1019 $user_cur->subst = "sitdown";
1021 else if ($user_cur->subst == "shutdowner") {
1022 $user_cur->stat_set("room");
1023 $user_cur->subst = "standup";
1024 $user_cur->table = -1;
1025 $user_wup[$user_wup_n++] = &$user_cur;
1027 $remove_wagon = false;
1028 if($table->wag_own == $user_cur) {
1029 $remove_wagon = true;
1030 $table->wag_reset($curtime);
1033 $user_tab[$user_tab_n++] = &$user_cur;
1037 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1038 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1040 /* aggiorna l'array dei giocatori al tavolo. */
1042 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1043 log_main("START LOOP");
1044 $user_cur = &$this->user[$i];
1045 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1046 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1051 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1053 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1054 if ($user_cur->stat == "room") {
1055 log_main("DOCUMENT.index.php from table");
1057 $ret .= $this->table_content($user_cur, $table_idx);
1058 $ret .= $this->standup_content($user_cur);
1060 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1061 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1062 $ret .= $table->act_content($user_cur);
1065 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1066 if ($user_cur == $user_tab[$tab_idx])
1069 // for users that wakeup the room will be reconstructed by index_rd.php
1070 if ($tab_idx < $user_tab_n) {
1071 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1073 // ARRAY_POP DISABLED
1074 // if ($trans_delta == 0)
1075 // while (array_pop($user_cur->comm) != NULL);
1077 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1078 $user_cur->comm[$user_cur->step % COMM_N] = "";
1079 $user_cur->step_inc();
1080 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1081 $user_cur->step_inc();
1082 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1086 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1088 log_main("JOIN_WAKEUP more");
1089 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1090 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1091 $ret .= $table->act_content($user_cur);
1093 log_main("JOIN_WAKEUP end more");
1095 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1096 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1097 $user_cur->step_inc();
1101 function room_outstandup(&$user)
1103 $this->room_sitdown(&$user, -1);
1106 function table_update(&$user)
1108 log_main("table_update: pre - USER: ".$user->name);
1110 $table_idx = $user->table;
1112 if ($table_idx > -1)
1113 $table = &$this->table[$table_idx];
1115 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1117 $user_cur = &$this->user[$i];
1118 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1121 $ret = "gst.st = ".($user_cur->step+1)."; ";
1122 if ($table_idx > -1)
1123 $ret .= $this->table_content($user_cur, $table_idx);
1125 if ($user_cur == $user) {
1126 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1127 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1128 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1130 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1131 $user_cur->step_inc();
1134 log_main("table_update: post");
1137 function room_sitdown(&$user, $table_idx)
1139 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1143 if ($table_idx > -1 && $table_idx < TABLES_N) {
1144 $table = &$this->table[$table_idx];
1147 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1148 for ($i = 0 ; $i < TABLES_N ; $i++) {
1149 $user_cur =& $this->user[$table->player[$i]];
1150 if ($user_cur == $table->wag_own) {
1151 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1152 $table->wag_reset(time());
1159 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1161 $user_cur = &$this->user[$i];
1162 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1165 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1166 if ($table_idx > -1)
1167 $ret .= $this->table_content($user_cur, $table_idx);
1168 $ret .= $this->standup_content($user_cur);
1170 if ($user_cur == $user) {
1171 $ret .= 'subst = "sitdown"; tra.hide(); ';
1172 // clean the action buttons in other tables
1173 for ($e = 0 ; $e < TABLES_N ; $e++) {
1174 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1175 $ret .= $this->table[$e]->act_content($user_cur);
1178 else if ($table_idx > -1) {
1179 if ($table->player_n == PLAYERS_N) {
1180 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1181 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1182 $ret .= $table->act_content($user_cur);
1185 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1186 $user_cur->step_inc();
1190 function chatt_send(&$user, $mesg)
1192 GLOBAL $G_alarm_passwd;
1196 $msg = substr($mesg, 6, 128);
1198 $dt = date("H:i ", $curtime);
1208 $is_normchat = FALSE;
1209 $update_room = FALSE;
1211 if (strcmp($msg, "/tav") == 0 ||
1212 strncmp($msg, "/tav ", 5) == 0) {
1214 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1215 /* 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>" */
1216 $msg = "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>";
1217 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1222 $table = &$this->table[$user->table];
1224 if ($table->wag_own != NULL) {
1225 $msg = "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>";
1226 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1231 $dtime = $curtime - $table->wag_tout;
1232 if ($dtime < EXPIRE_TIME_WAG) {
1233 $msg = sprintf("<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>",
1234 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? "o" : "i"));
1235 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1240 $msg = substr($msg, 5);
1242 $table->wag_set($user, $msg);
1243 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1244 $to_room = $to_user;
1247 } // /tav chat command
1249 else if (strncmp($msg, "/alarm ", 7) == 0) {
1250 if (strncmp($msg, "/alarm to ", 10) == 0) {
1251 $sp_pos = strpos($msg, " ", 10);
1252 $target = substr($msg, 10, $sp_pos - 10);
1253 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1257 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1260 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1261 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1262 $msg = "<br>La password digitata non è corretta.<br><br>";
1263 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1268 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1269 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Alarm <b>%s</b> inviato a <b>%s</b>.");',
1270 $dt, NICKSERV, xcape(substr($msg, strlen($alarm_check))),
1271 ($target == "" ? "tutti" : xcape($target)) );
1273 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1274 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1275 /* MLANG: "chiudi" */
1276 $to_all = show_notify($msg, 0, "chiudi", 400, 120);
1278 } // /alarm chat command
1279 else if (strncmp($msg, "/listen ", 8) == 0) {
1280 $arg = substr($msg, 8);
1282 if (strcasecmp($arg, "auth") == 0) {
1283 $user->flags |= USER_FLAG_LISTAUTH;
1284 $to_user = 'list_set(\'auth\', true, \'(solo aut.)\'); ';
1287 $user->flags &= ~USER_FLAG_LISTAUTH;
1288 $to_user = 'list_set(\'all\', true, \'\'); ';
1291 else if (strncmp($msg, "/garante", 8) == 0) {
1292 if ($user->flags & USER_FLAG_AUTH) {
1293 $to_user = sprintf('authbox(300,200);');
1296 /* 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." */
1297 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
1300 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1301 if ($user->flags & USER_FLAG_AUTH) {
1302 $to_user = sprintf('mesgtoadmbox(500,300);');
1305 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1306 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per inviare un messaggio devi essere autenticato.</b>");', $dt, NICKSERV);
1309 else if (strncmp($msg, "/nick ", 6) == 0) {
1310 log_main("chatt_send BEGIN");
1313 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1314 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.");', $dt, NICKSERV);
1318 $msg = "COMMAND ".$msg;
1319 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1320 $user_cur = &$this->user[$i];
1322 if ($user_cur->sess == '')
1324 if ($user_cur->name == $name_new)
1327 if ($i < MAX_PLAYERS) {
1328 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Nickname <b>%s</b> già in uso.");', $dt, NICKSERV, xcape($name_new));
1332 /* 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>" */
1333 if ($user->flags & USER_FLAG_AUTH) {
1334 if (strcasecmp($user->name,$name_new) != 0) {
1335 if ($user->subst == 'standup' || ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)) {
1336 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1337 for ($i = 0 ; $i < TABLES_N ; $i++) {
1338 $to_user .= $this->table[$i]->act_content($user);
1342 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>");', $dt, NICKSERV);
1347 $user->name = $name_new; // OK - nick changed
1348 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1349 if (($user->flags & USER_FLAG_AUTH) == 0) {
1350 $userdb = new LoginDB();
1351 /* 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>" */
1352 if ($userdb->login_exists($name_new)) {
1353 $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));
1357 log_main("chatt_send start set");
1359 $update_room = TRUE;
1361 } // nick chat command
1363 else if (strncmp($msg, "/st ", 4) == 0) {
1364 log_main("chatt_send BEGIN");
1367 $st_str = substr($msg, 4);
1369 if (strcasecmp($st_str, "normale") == 0) {
1370 $st = USER_FLAG_S_NORM;
1372 else if (strcasecmp($st_str, "pausa") == 0) {
1373 $st = USER_FLAG_S_PAU;
1375 else if (strcasecmp($st_str, "fuori") == 0) {
1376 $st = USER_FLAG_S_OUT;
1378 else if (strcasecmp($st_str, "cane") == 0) {
1379 $st = USER_FLAG_S_DOG;
1381 else if (strcasecmp($st_str, "cibo") == 0) {
1382 $st = USER_FLAG_S_EAT;
1384 else if (strcasecmp($st_str, "lavoro") == 0) {
1385 $st = USER_FLAG_S_WRK;
1387 else if (strcasecmp($st_str, "sigaretta") == 0) {
1388 $st = USER_FLAG_S_SMK;
1390 else if (strcasecmp($st_str, "presente") == 0) {
1391 $st = USER_FLAG_S_EYE;
1394 /* MLANG: "Questo stato non esiste." */
1395 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Questo stato non esiste.");', $dt, NICKSERV);
1399 log_main("chatt_send start set");
1400 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1401 $update_room = TRUE;
1402 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1405 } // nick chat command
1407 else { // normal chat line
1408 $is_normchat = TRUE;
1409 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1411 $user->chat_dlt = $user->chat_dlt * 2;
1412 if ($user->chat_dlt > 120)
1413 $user->chat_dlt = 120;
1415 else if ($user->chat_lst == $msg)
1417 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1418 $user->chat_ban = $curtime;
1419 $user->chat_dlt = 5;
1423 $user->chat_ban = 0;
1424 $user->chat_dlt = 0;
1428 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1431 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1432 // temporary silentiation for troll (will became array check)
1433 if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1434 $to_room = $to_user;
1437 log_legal($curtime, $user,
1438 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1440 $user->chat_lst = "$msg";
1441 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1451 // Output to clients
1454 if ($to_user != FALSE) {
1455 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1456 $user->comm[$user->step % COMM_N] .= $to_user;
1460 if ($to_room != FALSE) {
1461 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1462 $user_cur = &$this->user[$i];
1463 if ($target != "" && $user_cur->name != $target)
1465 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1466 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1469 if ($is_normchat == TRUE) {
1470 if ($user_cur->flags & USER_FLAG_LISTAUTH) {
1471 if (($user->flags & USER_FLAG_AUTH) == 0) {
1477 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1478 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1479 $user_cur->step_inc();
1484 // Before all align times with table timeout
1485 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1486 $table_cur =& $this->table[$table_idx];
1487 // if the table is complete and exists its shared mem we get the info about users lacc
1489 if ($table_cur->player_n == PLAYERS_N) {
1490 log_main("PLAYERS == N TABLE ".$table_idx);
1492 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1493 log_main("bin5 lock data success");
1495 $no_recovery = FALSE;
1496 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1497 if ($table_cur->table_token != $bri->table_token) {
1498 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1503 if ($bri != FALSE) {
1504 $bri_table = &$bri->table[0];
1505 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1506 // stat must be "table" by definition
1507 $bri_user =& $bri->user[$i];
1509 if ($target != "" && $bri_user->name != $target)
1511 log_main("writa: ".$user_mesg);
1512 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1513 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1514 $bri_user->step_inc();
1516 Briskin5::save_data(&$bri);
1518 Briskin5::unlock_data($sem);
1520 } // if ($table_cur->player_n == PLAYERS_N) {
1521 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1522 } // if ($to_tabl == true ...
1525 if ($user->stat == 'room' && $user->subst == 'standup') {
1526 $this->standup_update(&$user);
1528 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1529 log_main("chatt_send pre table update");
1530 $this->table_update(&$user);
1531 log_main("chatt_send post table update");
1533 } // if ($update_room ...
1536 } // function chatt_send( ...
1538 function &get_user($sess, &$idx)
1540 GLOBAL $PHP_SELF, $G_false;
1542 if (validate_sess($sess)) {
1543 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1544 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1547 $ret = &$this->user[$i];
1551 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1552 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1553 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1556 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1565 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1568 * if ($idx > -1 && ret == FALSE) => duplicated nick
1569 * if ($idx == -2 && ret == FALSE) => invalid name
1570 * if ($idx == -3 && ret == FALSE) => wrong password
1571 * if ($idx == -1 && ret == FALSE) => no space left
1572 * if ($idx == 0 && ret == user) => SUCCESS
1573 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1578 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1580 GLOBAL $G_false, $CO_list;
1584 $authenticate = FALSE;
1585 $login_exists = FALSE;
1587 $ghost_auth = FALSE;
1591 if (($name_new = validate_name($name)) == FALSE) {
1596 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1597 if (validate_sess($sess) == FALSE)
1600 /* if pass != FALSE verify the login with pass */
1601 log_auth("XXX", "auth1");
1602 $userdb = new LoginDB();
1603 if ($pass != FALSE) {
1604 log_auth("XXX", "auth2");
1605 $authenticate = $userdb->login_verify($name_new, $pass);
1606 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1608 if ($authenticate == FALSE) {
1614 $login_exists = $userdb->login_exists($name_new);
1616 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1618 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1622 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1624 continue; // NOTE: CHECK IT !!
1626 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1627 if ($authenticate == FALSE) {
1633 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1640 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1642 if ($ghost > -1 && $ghost_auth && $authenticate) {
1645 $ghost_user =& $this->user[$ghost];
1647 $ghost_user->step_inc();
1650 $ghost_user->sess = $sess;
1653 $ghost_user->sess = $sess;
1656 // If user at the table we need to update the table data too
1657 $table_idx = $ghost_user->table;
1658 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1659 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1660 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1661 if ($bri->the_end != TRUE) {
1662 $bri->user[$ghost_user->table_pos]->step_inc();
1663 $bri->user[$ghost_user->table_pos]->sess = $sess;
1664 Briskin5::save_data(&$bri);
1667 Briskin5::unlock_data($brisem);
1672 return ($this->user[$ghost]);
1674 else if ($idx != -1 && $i == MAX_PLAYERS) {
1679 $this->user[$idx]->sess = $sess;
1682 $this->user[$idx]->sess = $sess;
1684 $this->user[$idx]->name = $name_new; // OK - add new user
1685 $this->user[$idx]->stat_set("room");
1686 $this->user[$idx]->step_set(0);
1687 while (array_pop($this->user[$idx]->comm) != NULL);
1688 $this->user[$idx]->subst = "standup";
1689 $this->user[$idx]->lacc = $curtime;
1690 $this->user[$idx]->laccwr = $curtime;
1691 $this->user[$idx]->bantime = 0;
1692 $this->user[$idx]->ip = $ip;
1694 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1696 if ($authenticate) {
1697 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1699 if (isset($CO_list) && strcmp($CO_list, "all") == 0) {
1700 $this->user[$idx]->flags &= ~USER_FLAG_LISTAUTH;
1705 log_main("ghost: rename!");
1706 $ghost_user =& $this->user[$ghost];
1708 if ($ghost_auth == FALSE) {
1709 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1710 $ghostname = 'ghost'.$sfx;
1711 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1712 if (strcmp("", $this->user[$i]->sess) == 0)
1715 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1720 if ($ghostname != '')
1724 $ghost_user->name = $ghostname;
1726 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1727 $this->standup_update(&$ghost_user);
1730 log_main("chatt_send pre table update");
1731 $this->table_update(&$ghost_user);
1732 log_main("chatt_send post table update");
1734 } // if ($ghost_auth == FALSE
1736 // FIXME: cacciare il vecchio utente room && table (if needed)
1737 $ghost_user->the_end = TRUE;
1738 $ghost_user->lacc = 0;
1739 $this->garbage_manager(TRUE);
1741 } // if ($ghost > -1) {
1743 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1747 return ($this->user[$real_idx]);
1753 function standup_update(&$user)
1755 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1756 $user_cur = &$this->user[$i];
1757 if ($user_cur->sess == '')
1760 log_main("STANDUP START: ".$user_cur->stat);
1762 if ($user_cur->stat == 'room') {
1763 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1764 if ($user_cur == $user) {
1765 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1766 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1768 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
1769 $itin, xcape($user->name), $itou);
1771 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1773 $user_cur->step_inc();
1779 function &init_data()
1781 $room =& new Room();
1787 function &load_data()
1789 GLOBAL $G_false, $sess;
1792 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1793 log_main("ftok failed");
1798 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1799 log_main("shmop_open failed");
1803 $shm_sz = SHM_DIMS_MIN;
1805 if ($shm = shm_attach($tok, $shm_sz)) {
1806 $room = @shm_get_var($shm, $tok);
1808 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1810 log_only("bri count ".count($room));
1812 if ($room == FALSE) {
1813 log_only("INIT MAIN DATA");
1815 $room =& Room::init_data();
1816 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1817 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1818 log_only(serialize($room));
1821 $room->shm_sz = $shm_sz;
1836 function save_data(&$room)
1844 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1847 while ($room->shm_sz < SHM_DIMS_MAX) {
1848 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1851 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1852 if (shm_put_var($shm, $tok, $room) != FALSE) {
1856 if (shm_remove($shm) === FALSE) {
1857 log_only("REMOVE FALLITA");
1861 $room->shm_sz += SHM_DIMS_DLT;
1870 function lock_data()
1874 // echo "LOCK: ".FTOK_PATH."/main";
1876 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1879 // echo "FTOK ".$tok."<br>";
1880 if (($res = sem_get($tok)) == FALSE) {
1883 if (sem_acquire($res)) {
1884 log_lock("LOCK room");
1891 function unlock_data($res)
1895 log_lock("UNLOCK room");
1897 return (sem_release($res));
1901 function standup_content($user)
1906 if ($user->stat != 'room')
1909 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1910 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1915 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1917 $content = ' j_stand_cont( [ ';
1919 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1920 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1923 $flags = $this->user[$e]->flags;
1925 if ($this->user[$e]->subst == "standup") {
1926 if ($this->user[$e] == $user)
1931 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
1940 function table_content_old($user, $table_idx)
1946 // Si possono usare i dati nella classe table
1949 $sess = $user->sess;
1950 $table = &$this->table[$table_idx];
1952 if ($user->stat != 'room')
1955 for ($i = 0 ; $i < $table->player_n ; $i++) {
1956 $user_cur = &$this->user[$table->player[$i]];
1958 if ($user_cur == $user)
1959 { $hilion = "<b>"; $hilioff = "</b>"; }
1961 { $hilion = ""; $hilioff = ""; }
1963 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
1965 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1968 for ( ; $i < PLAYERS_N ; $i++)
1972 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1978 function table_content($user, $table_idx)
1984 // Si possono usare i dati nella classe table
1987 $sess = $user->sess;
1988 $table = &$this->table[$table_idx];
1990 if ($user->stat != 'room')
1994 for ($i = 0 ; $i < $table->player_n ; $i++) {
1995 $user_cur = &$this->user[$table->player[$i]];
1997 $flags = $user_cur->flags;
1999 if ($user_cur == $user)
2002 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2004 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2009 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2016 function make_seed()
2018 list($usec, $sec) = explode(' ', microtime());
2019 return (float) $sec + ((float) $usec * 100000);
2023 function log_only2($log) {
2026 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2029 if (isset($sess) == FALSE)
2034 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2037 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2038 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2043 function log_crit($log) {
2046 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2049 if (isset($sess) == FALSE)
2054 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2057 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2058 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2063 function log_only($log) {
2066 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2069 if (isset($sess) == FALSE)
2074 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2077 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2078 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2083 function log_main($log) {
2086 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2089 if (isset($sess) == FALSE)
2094 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2097 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2098 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2103 function log_rd($log) {
2106 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2109 if (isset($sess) == FALSE)
2114 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2117 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2118 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2123 function log_rd2($log) {
2126 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2129 if (isset($sess) == FALSE)
2134 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2137 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2138 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2143 function log_send($log) {
2146 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2149 if (isset($sess) == FALSE)
2154 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2157 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2158 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2163 function log_lock($log) {
2166 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2169 if (isset($sess) == FALSE)
2174 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2177 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2178 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2183 function log_wr($log) {
2186 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2189 if (isset($sess) == FALSE)
2194 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2197 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2198 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2203 function log_load($log) {
2206 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2209 if (isset($sess) == FALSE)
2214 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2217 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2218 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2223 function log_auth($sess, $log) {
2224 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2227 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2230 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2231 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2237 // function log_legal($curtime, $sess, $name, $where, $mesg)
2238 function log_legal($curtime, &$user, $where, $mesg)
2242 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2243 /* Unix time | session | nickname | IP | where was | mesg */
2244 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2245 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2246 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2254 function lock_banlist()
2256 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2260 if (($res = sem_get($tok)) == FALSE) {
2261 echo "SEM_GET FAILED";
2264 if (sem_acquire($res))
2270 function unlock_banlist($res)
2272 return (sem_release($res));
2275 function table_act_content_old($isstanding, $sitted, $table, $cur_table)
2280 if ($sitted < PLAYERS_N) {
2281 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
2285 if ($table == $cur_table)
2286 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
2293 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2298 if ($sitted < PLAYERS_N) {
2306 if ($table == $cur_table)
2313 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2318 function show_notify($text, $tout, $butt, $w, $h)
2320 log_main("SHOW_NOTIFY: ".$text);
2321 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2324 function multoval($mult)
2328 else if ($mult == 4)
2329 return ("quadruplo");
2331 return (sprintf("%d-plo", $mult));
2335 function root_wellcome($user)
2337 GLOBAL $root_wellarr;
2341 $dt = date("H:i ", $curtime);
2343 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2344 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$i]));
2351 function validate_sess($sess)
2353 if (strlen($sess) == SESS_LEN)
2359 function validate_name($name)
2361 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2363 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2365 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2372 function playsound($filename)
2374 return (sprintf('playsound("flasou", "%s");', $filename));
2377 function secstoword($secs)
2379 $mins = floor($secs / 60);
2382 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2385 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2390 function sharedmem_sz($tok)
2392 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2393 log_main("shmop_open failed");
2396 $shm_sz = shmop_size($shm_id);
2397 shmop_close($shm_id);
2399 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2404 function lock_data()
2408 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2411 // echo "FTOK ".$tok."<br>";
2412 if (($res = sem_get($tok)) == FALSE) {
2415 if (sem_acquire($res)) {
2416 log_lock("LOCK room");
2423 function unlock_data($res)
2427 log_lock("UNLOCK room");
2429 return (sem_release($res));