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)
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));
147 function xcapemesg($s)
149 $from = array ( "\n");
150 $to = array ( "\\n");
152 return (str_replace($from, $to, $s));
161 var $auth_only; // se tavolo riservato o libero
168 var $table_start; // information field
176 function &create($idx)
180 if (($thiz =& new Table()) == FALSE)
184 $thiz->player = array();
186 $thiz->auth_only = FALSE;
188 $thiz->wag_own = NULL;
192 $thiz->table_token = "";
193 $thiz->table_start = 0;
195 $thiz->wakeup_time = 0;
200 function copy(&$from)
204 $this->idx = $from->idx;
205 $this->player = array();
206 for ($i = 0 ; $i < $from->player_n ; $i++)
207 $this->player[$i] = $from->player[$i];
208 $this->player_n = $from->player_n;
210 log_main("PLAYER_N - parent::copy.".$this->player_n);
212 $this->auth_only = $from->auth_only;
214 $this->wag_own = $from->wag_own;
215 $this->wag_com = $from->wag_com;
216 $this->wag_tout = $from->wag_tout;
218 $this->table_token = $from->table_token;
219 $this->table_start = $from->table_start;
221 $this->wakeup_time = $from->wakeup_time;
224 function &clone(&$from)
228 if (($thiz =& new Table()) == FALSE)
236 function &spawn(&$from)
240 if (($thiz =& new Table()) == FALSE)
243 $thiz->idx = $from->idx;
244 $thiz->player = array();
245 for ($i = 0 ; $i < $from->player_n ; $i++)
246 $thiz->player[$i] = $i;
247 $thiz->player_n = $from->player_n;
249 $thiz->auth_only = $from->auth_only;
251 $thiz->wag_own = $from->wag_own;
252 $thiz->wag_com = $from->wag_com;
253 $thiz->wag_tout = $from->wag_tout;
255 $thiz->table_token = $from->table_token;
256 $thiz->table_start = $from->table_start;
258 $thiz->wakeup_time = $from->wakeup_time;
263 function wag_set(&$user, $mesg)
267 $this->wag_own = &$user;
268 $this->wag_com = $mesg;
272 function wag_reset($timeout)
274 log_main("WAG_RESET");
276 unset($this->wag_own);
277 $this->wag_own = NULL;
279 $this->wag_tout = $timeout;
282 function getPlayer($idx)
284 return ($this->player[$idx]);
287 function setPlayer($idx, $player)
289 $this->player[$idx] = $player;
292 function user_add($idx)
294 $this->player[$this->player_n] = $idx;
297 return ($this->player_n - 1);
300 function user_rem(&$room, &$user)
302 $tabpos = $user->table_pos;
304 /* verifico la consistenza dei dati */
305 if ($room->user[$this->player[$tabpos]] == $user) {
307 /* aggiorna l'array dei giocatori al tavolo. */
308 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
309 $this->player[$i] = $this->player[$i+1];
310 $user_cur = &$room->user[$this->player[$i]];
311 $user_cur->table_pos = $i;
316 log_main("INCONSISTENCY ON TABLE.");
322 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
323 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
325 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
326 function act_content(&$user)
329 $isstanding = ($user->subst == 'standup');
330 $sitted = $this->player_n;
332 $cur_table = $user->table;
336 if ($sitted < PLAYERS_N) {
337 if ($this->auth_only) {
338 if ($user->flags & USER_FLAG_AUTH)
352 if ($table == $cur_table)
359 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
367 define(USER_FLAG_AUTH, 0x02);
368 define(USER_FLAG_LISTAUTH, 0x04);
371 define(USER_FLAG_S_NORM, 0x000); // done
372 define(USER_FLAG_S_PAU, 0x100); // done
373 define(USER_FLAG_S_OUT, 0x200); // done
374 define(USER_FLAG_S_DOG, 0x300); // done
375 define(USER_FLAG_S_EAT, 0x400); // done
376 define(USER_FLAG_S_WRK, 0x500); // done
377 define(USER_FLAG_S_SMK, 0x600); // done
378 define(USER_FLAG_S_EYE, 0x700); // done
380 define(USER_FLAG_S_ALL, 0xf00); // done
383 var $name; // name of the user
384 var $sess; // session of the user
385 var $ip; // ip of the user
386 var $lacc; // last access (for the cleanup)
387 var $laccwr; // last access (for the cleanup)
388 var $bantime; // timeout to temporary ban
389 var $stat; // status (outdoor, room, table, game, ...)
390 var $subst; // substatus for each status
391 var $step; // step of the current status
392 var $trans_step; // step to enable transition between pages (disable == -1)
393 var $comm; // commands array
394 // var $asta_card; //
396 // var $handpt; // Total card points at the beginning of the current hand.
397 // var $exitislock; // Player can exit from the table ?
399 // FIXME: the table_orig field must be removed after table field verify of index management (in spawned table
400 // it is allways ZERO
401 var $table_orig; // id of the current table (if in table state)
402 var $table; // id of the current table (if in table state)
403 var $table_pos; // idx on the table
404 var $table_token;// token that identify a game on a table
405 var $flags; // Bitfield with: AUTHENTICATE: 0x02
406 var $the_end; // Flag to change the end of the session
408 var $chat_lst; // Last chat line
409 var $chattime; // Array of chat times
410 var $chat_cur; // Current chat line number
411 var $chat_ban; // Time for ban chat
412 var $chat_dlt; // Delta t for ban
416 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
419 if (($thiz =& new User()) == FALSE)
425 $thiz->lacc = time();
426 $thiz->laccwr = time();
429 $thiz->subst = $subst;
431 $thiz->trans_step = -1;
432 $thiz->comm = array();
433 $thiz->asta_card = -2;
434 $thiz->asta_pnt = -1;
436 $thiz->exitislock = TRUE;
440 $thiz->chattime = array_fill(0, CHAT_N, 0);
442 $thiz->chat_lst = "";
446 $thiz->table_orig = $table;
447 $thiz->table = $table;
448 $thiz->table_pos = -1;
449 $thiz->table_token = "";
454 function copy(&$from)
458 $this->name = $from->name;
459 $this->sess = $from->sess;
460 $this->ip = $from->ip;
461 $this->lacc = $from->lacc;
462 $this->laccwr = $from->laccwr;
463 $this->bantime = $from->bantime;
464 $this->stat = $from->stat;
465 $this->subst = $from->subst;
466 $this->step = $from->step;
467 $this->trans_step = $from->trans_step;
468 $this->comm = array();
470 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
471 for ($i = $i_start ; $i < $from->step ; $i++) {
473 $this->comm[$ii] = $from->comm[$ii];
475 $this->asta_card = $from->asta_card;
476 $this->asta_pnt = $from->asta_pnt;
477 $this->handpt = $from->handpt;
478 $this->exitislock = $from->exitislock;
480 $this->flags = $from->flags;
482 $this->chattime = array();
483 for ($i = 0 ; $i < CHAT_N ; $i++)
484 $this->chattime[$i] = $from->chattime[$i];
485 $this->chat_cur = $from->chat_cur;
486 $this->chat_lst = $from->chat_lst;
487 $this->chat_ban = $from->chat_ban;
488 $this->chat_dlt = $from->chat_dlt;
490 $this->table_orig = $from->table_orig;
491 $this->table = $from->table;
492 $this->table_pos = $from->table_pos;
493 $this->table_token = $from->table_token;
494 $this->the_end = $from->the_end;
500 function &clone(&$from)
504 if (($thiz =& new User()) == FALSE)
512 function &spawn(&$from, $table, $table_pos)
516 if (($thiz =& new User()) == FALSE)
519 $thiz->name = $from->name;
520 $thiz->sess = $from->sess;
521 $thiz->ip = $from->ip;
522 $thiz->lacc = $from->lacc;
523 $thiz->laccwr = $from->laccwr;
524 $thiz->bantime = $from->bantime;
525 $thiz->stat = $from->stat;
526 $thiz->subst = $from->subst;
527 $thiz->step = $from->step;
528 $thiz->trans_step = $from->trans_step;
529 $thiz->comm = array();
532 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
533 for ($i = $i_start ; $i < $from->step ; $i++) {
534 log_wr("TRY PUSH:".$i);
536 $thiz->comm[$ii] = $from->comm[$ii];
539 $thiz->asta_card = $from->asta_card;
540 $thiz->asta_pnt = $from->asta_pnt;
541 $thiz->handpt = $from->handpt;
542 $thiz->exitislock = $from->exitislock;
543 $thiz->the_end = $from->the_end;
545 $thiz->flags = $from->flags;
547 $thiz->chattime = array_fill(0, CHAT_N, 0);
549 $thiz->chat_lst = "";
554 $thiz->table_orig = $table;
556 $thiz->table_pos = $table_pos;
557 $thiz->table_token = $from->table_token;
562 function stat_set($stat) {
563 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
564 $this->stat = "$stat";
567 if (validate_sess($this->sess)) {
568 if (file_exists(PROXY_PATH) == FALSE)
570 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
571 fwrite($fp, sprintf("%s\n",$this->stat));
577 function step_set($step) {
581 if (validate_sess($this->sess) == FALSE)
583 if (file_exists(PROXY_PATH) == FALSE)
585 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
587 fwrite($fp, pack("l",$this->step), 4);
596 function step_inc($delta = 1) {
597 $this->step += $delta;
599 if (validate_sess($this->sess)) {
600 if (file_exists(PROXY_PATH) == FALSE)
602 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
603 fwrite($fp, pack("l",$this->step), 4);
614 log_legal($curtime, $this, "STAT:LOGOUT", '');
616 $tmp_sess = $this->sess;
618 step_unproxy($tmp_sess);
619 $this->name = ""; // OK here
620 while (array_pop($this->comm) != NULL);
622 $this->chattime = array_fill(0, CHAT_N, 0);
624 $this->chat_lst = "";
627 $this->the_end = FALSE;
637 function step_get($sess) {
640 if (validate_sess($sess) == FALSE)
643 if (file_exists(PROXY_PATH) == FALSE)
645 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
647 if (($s = fread($fp, 4)) == FALSE)
651 $arr = unpack('l', $s);
654 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
661 log_rd2("STEP_GET: return false ");
666 function step_unproxy($sess) {
667 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
668 if (file_exists(PROXY_PATH) == FALSE)
670 @unlink(PROXY_PATH."/".$sess.".step");
677 var $comm; // commands for many people
678 var $step; // current step of the comm array
679 var $garbage_timeout;
683 $this->user = array();
684 $this->table = array();
686 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
687 $this->user[$i] =& User::create("", "");
690 for ($i = 0 ; $i < TABLES_N ; $i++) {
691 $this->table[$i] =& Table::create($i);
694 $row = ( (((int)($i / 4)) % 2) == 0 );
695 $col = ($i % 2 == 0);
696 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
699 $this->table[$i]->auth_only = FALSE;
703 $this->table[$i]->auth_only = TRUE;
705 $this->table[$i]->auth_only = FALSE;
707 $this->garbage_timeout = 0;
710 function garbage_manager($force)
714 log_rd2("garbage_manager START");
716 /* Garbage collector degli utenti in timeout */
718 if ($force || $this->garbage_timeout < $curtime) {
720 // Before all align times with table timeout
721 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
722 $table_cur =& $this->table[$table_idx];
723 // if the table is complete and exists its shared mem we get the info about users lacc
725 if ($table_cur->player_n == PLAYERS_N) {
726 log_main("PLAYERS == N TABLE ".$table_idx);
728 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
729 log_main("bin5 lock data success");
731 $no_recovery = FALSE;
732 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
733 if ($table_cur->table_token != $bri->table_token) {
734 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
735 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
745 log_main("garbage_manager: bri loaded successfully.");
746 $bri->garbage_manager(TRUE);
748 $bri_table = &$bri->table[0];
750 // is the end of the table
751 if ($bri->the_end == TRUE) {
753 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
755 log_main("garbage_manager: INSIDE THE END.");
757 $plist = "$table_cur->table_token|$table_cur->idx|$table_cur->player_n";
758 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
759 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
762 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
763 // stat must be "table" by definition
764 $user_cur =& $this->user[$table_cur->player[$i]];
765 $bri_user =& $bri->user[$i];
767 $user_cur->subst = $bri_user->subst;
768 $user_cur->step = $bri_user->step;
769 $user_cur->lacc = $bri_user->lacc;
770 $user_cur->laccwr = $bri_user->lacc;
771 $user_cur->bantime = $bri_user->bantime;
774 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
776 $this->room_join_wakeup(&$user_cur, FALSE, 0);
777 $table_cur->table_token = "";
778 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
779 Briskin5::destroy_data($table_idx);
782 log_main("gm:: save_data");
784 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
785 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
788 Briskin5::save_data(&$bri);
790 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
791 else if ($no_recovery == FALSE) {
792 log_crit("ERROR: table ".$table_idx." unrecoverable join");
794 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
795 $user_cur = &$this->user[$table_cur->player[$i]];
796 $user_cur->subst = "shutdowner";
797 $user_cur->step_inc();
799 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
800 $ret .= "gst.st = ".($user_cur->step+1)."; ";
801 $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);
802 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
803 $user_cur->step_inc();
806 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
807 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
808 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
810 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
812 $this->room_join_wakeup(&$user_cur, TRUE, -2);
813 $table_cur->table_token = "";
816 Briskin5::unlock_data($sem);
818 } // if ($table_cur->player_n == PLAYERS_N) {
819 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
821 log_rd2("out new loop.");
823 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
824 $user_cur = &$this->user[$i];
826 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
828 if ($user_cur->sess == "")
831 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
832 // Auto logout dell'utente
833 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
835 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
836 log_auth($user_cur->sess, "Autologout session.");
840 log_rd2("AUTO LOGOUT.");
841 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
842 $this->room_wakeup(&$user_cur);
843 else if ($user_cur->subst == 'standup')
844 $this->room_outstandup(&$user_cur);
846 log_rd2("LOGOUT FROM WHAT ???");
850 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
851 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
852 $this->room_wakeup(&$user_cur);
853 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
854 /* 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" */
855 $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);
856 $user_cur->step_inc();
860 log_rd2("GARBAGE UPDATED!");
862 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
869 function show_room($user_step, &$user)
871 log_main("show_room: username: ".$user->name);
873 $ret = sprintf('gst.st = %d; ', $user_step);
875 if ($user->flags & USER_FLAG_LISTAUTH) {
876 $ret .= 'list_set(\'auth\', false, \'(solo aut.)\' ); ';
879 $ret .= 'list_set(\'all\', false, \'\' ); ';
882 if ($user->subst == 'standup')
883 $ret .= "tra.show(); ";
885 $ret .= "tra.hide(); ";
887 $ret .= sprintf('stat = "%s";', $user->stat);
889 $ret .= root_wellcome($user);
890 $ret .= sprintf('subst = "%s";', $user->subst);
891 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
892 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
893 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
894 for ($i = 0 ; $i < TABLES_N ; $i++) {
895 $ret .= $this->table_content($user, $i);
896 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
897 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
898 $ret .= $this->table[$i]->act_content($user);
899 if ($this->table[$i]->wag_own != NULL)
900 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
902 $ret .= sprintf('tra.rem(%d); ', $i);
904 $ret .= $this->standup_content($user);
910 function room_wakeup(&$user)
912 $table_idx = $user->table;
913 $table = &$this->table[$table_idx];
915 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
919 $from_table = ($user->stat == "table");
921 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
923 for ($i = 0 ; $i < $table->player_n ; $i++) {
924 $user_cur = &$this->user[$table->player[$i]];
925 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
927 if ($user_cur != $user) {
928 $user_cur->stat_set("room");
929 $user_cur->subst = "sitdown";
930 $user_cur->laccwr = $curtime;
932 else if ($user->sess != "") {
933 $user_cur->stat_set("room");
934 $user_cur->subst = "standup";
935 $user_cur->laccwr = $curtime;
936 $user_cur->table = -1;
941 $user->stat_set("room");
942 $user->subst = "standup";
943 $user->laccwr = $curtime;
946 $remove_wagon = false;
947 if($table->wag_own == $user) {
948 $remove_wagon = true;
949 $table->wag_reset($curtime);
954 /* aggiorna l'array dei giocatori al tavolo. */
955 $table->user_rem(&$this, &$user);
957 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
958 $user_cur = &$this->user[$i];
959 if ($user_cur->sess == '' || $user_cur->stat != 'room')
962 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
964 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
965 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
966 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
967 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
968 log_main("DOCUMENT.index.php: from table");
970 else if ($user_cur->stat == "room") {
971 log_main("DOCUMENT.index.php: from table");
973 $ret .= $this->table_content($user_cur, $table_idx);
974 $ret .= $this->standup_content($user_cur);
976 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
977 $ret .= $table->act_content($user);
979 if ($user_cur == $user) {
980 // set the new status
981 $ret .= 'subst = "standup"; tra.show(); ';
982 // clean the action buttons in other tables
983 for ($e = 0 ; $e < TABLES_N ; $e++) {
984 if ($this->table[$e]->player_n < PLAYERS_N) {
985 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
986 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
987 $ret .= $this->table[$e]->act_content($user);
992 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
993 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
994 $ret .= $table->act_content($user_cur);
997 log_wr("ROOM_WAKEUP: ".$ret);
998 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
999 $user_cur->step_inc();
1003 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1005 $table_idx = $user->table;
1006 $table = &$this->table[$table_idx];
1008 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1011 $user_wup = array();
1013 $user_tab = array();
1015 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1017 for ($i = 0 ; $i < $table->player_n ; $i++) {
1018 $user_cur = &$this->user[$table->player[$i]];
1019 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1020 if ($user_cur->sess != "") {
1021 if ($update_lacc == TRUE) {
1022 $user_cur->laccwr = $curtime;
1024 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1025 if ($user_cur->subst == "shutdowned") {
1026 $user_cur->stat_set("room");
1027 $user_cur->subst = "sitdown";
1029 else if ($user_cur->subst == "shutdowner") {
1030 $user_cur->stat_set("room");
1031 $user_cur->subst = "standup";
1032 $user_cur->table = -1;
1033 $user_wup[$user_wup_n++] = &$user_cur;
1035 $remove_wagon = false;
1036 if($table->wag_own == $user_cur) {
1037 $remove_wagon = true;
1038 $table->wag_reset($curtime);
1041 $user_tab[$user_tab_n++] = &$user_cur;
1045 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1046 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1048 /* aggiorna l'array dei giocatori al tavolo. */
1050 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1051 log_main("START LOOP");
1052 $user_cur = &$this->user[$i];
1053 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1054 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1059 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1061 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1062 if ($user_cur->stat == "room") {
1063 log_main("DOCUMENT.index.php from table");
1065 $ret .= $this->table_content($user_cur, $table_idx);
1066 $ret .= $this->standup_content($user_cur);
1068 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1069 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1070 $ret .= $table->act_content($user_cur);
1073 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1074 if ($user_cur == $user_tab[$tab_idx])
1077 // for users that wakeup the room will be reconstructed by index_rd.php
1078 if ($tab_idx < $user_tab_n) {
1079 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1081 // ARRAY_POP DISABLED
1082 // if ($trans_delta == 0)
1083 // while (array_pop($user_cur->comm) != NULL);
1085 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1086 $user_cur->comm[$user_cur->step % COMM_N] = "";
1087 $user_cur->step_inc();
1088 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1089 $user_cur->step_inc();
1090 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1094 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1096 log_main("JOIN_WAKEUP more");
1097 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1098 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1099 $ret .= $table->act_content($user_cur);
1101 log_main("JOIN_WAKEUP end more");
1103 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1104 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1105 $user_cur->step_inc();
1109 function room_outstandup(&$user)
1111 $this->room_sitdown(&$user, -1);
1114 function table_update(&$user)
1116 log_main("table_update: pre - USER: ".$user->name);
1118 $table_idx = $user->table;
1120 if ($table_idx > -1)
1121 $table = &$this->table[$table_idx];
1123 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1125 $user_cur = &$this->user[$i];
1126 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1129 $ret = "gst.st = ".($user_cur->step+1)."; ";
1130 if ($table_idx > -1)
1131 $ret .= $this->table_content($user_cur, $table_idx);
1133 if ($user_cur == $user) {
1134 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1135 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1136 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1138 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1139 $user_cur->step_inc();
1142 log_main("table_update: post");
1145 function room_sitdown(&$user, $table_idx)
1147 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1151 if ($table_idx > -1 && $table_idx < TABLES_N) {
1152 $table = &$this->table[$table_idx];
1155 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1156 for ($i = 0 ; $i < TABLES_N ; $i++) {
1157 $user_cur =& $this->user[$table->player[$i]];
1158 if ($user_cur == $table->wag_own) {
1159 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1160 $table->wag_reset(time());
1167 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1169 $user_cur = &$this->user[$i];
1170 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1173 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1174 if ($table_idx > -1)
1175 $ret .= $this->table_content($user_cur, $table_idx);
1176 $ret .= $this->standup_content($user_cur);
1178 if ($user_cur == $user) {
1179 $ret .= 'subst = "sitdown"; tra.hide(); ';
1180 // clean the action buttons in other tables
1181 for ($e = 0 ; $e < TABLES_N ; $e++) {
1182 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1183 $ret .= $this->table[$e]->act_content($user_cur);
1186 else if ($table_idx > -1) {
1187 if ($table->player_n == PLAYERS_N) {
1188 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1189 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1190 $ret .= $table->act_content($user_cur);
1193 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1194 $user_cur->step_inc();
1198 function chatt_send(&$user, $mesg)
1200 GLOBAL $G_alarm_passwd;
1204 $msg = substr($mesg, 6, 128);
1206 $dt = date("H:i ", $curtime);
1216 $is_normchat = FALSE;
1217 $update_room = FALSE;
1219 if (strcmp($msg, "/tav") == 0 ||
1220 strncmp($msg, "/tav ", 5) == 0) {
1222 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1223 /* 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>" */
1224 $msg = "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>";
1225 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1230 $table = &$this->table[$user->table];
1232 if ($table->wag_own != NULL) {
1233 $msg = "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>";
1234 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1239 $dtime = $curtime - $table->wag_tout;
1240 if ($dtime < EXPIRE_TIME_WAG) {
1241 $msg = sprintf("<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>",
1242 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? "o" : "i"));
1243 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1248 $msg = substr($msg, 5);
1250 $table->wag_set($user, $msg);
1251 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1252 $to_room = $to_user;
1255 } // /tav chat command
1257 else if (strncmp($msg, "/alarm ", 7) == 0) {
1258 if (strncmp($msg, "/alarm to ", 10) == 0) {
1259 $sp_pos = strpos($msg, " ", 10);
1260 $target = substr($msg, 10, $sp_pos - 10);
1261 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1265 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1268 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1269 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1270 $msg = "<br>La password digitata non è corretta.<br><br>";
1271 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1276 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1277 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Alarm <b>%s</b> inviato a <b>%s</b>.");',
1278 $dt, NICKSERV, xcape(substr($msg, strlen($alarm_check))),
1279 ($target == "" ? "tutti" : xcape($target)) );
1281 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1282 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1283 /* MLANG: "chiudi" */
1284 $to_all = show_notify($msg, 0, "chiudi", 400, 120);
1286 } // /alarm chat command
1287 else if (strncmp($msg, "/listen ", 8) == 0) {
1288 $arg = substr($msg, 8);
1290 if (strcasecmp($arg, "auth") == 0) {
1291 $user->flags |= USER_FLAG_LISTAUTH;
1292 $to_user = 'list_set(\'auth\', true, \'(solo aut.)\'); ';
1295 $user->flags &= ~USER_FLAG_LISTAUTH;
1296 $to_user = 'list_set(\'all\', true, \'\'); ';
1299 else if (strncmp($msg, "/garante", 8) == 0) {
1300 if ($user->flags & USER_FLAG_AUTH) {
1301 $to_user = sprintf('authbox(300,200);');
1304 /* 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." */
1305 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
1308 else if (strncmp($msg, "/mesgtoadm", 8) == 0) {
1309 if ($user->flags & USER_FLAG_AUTH) {
1310 $to_user = sprintf('mesgtoadmbox(500,300);');
1313 /* MLANG: "<b>Per inviare un messaggio devi essere autenticato.</b>" */
1314 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per inviare un messaggio devi essere autenticato.</b>");', $dt, NICKSERV);
1317 else if (strncmp($msg, "/nick ", 6) == 0) {
1318 log_main("chatt_send BEGIN");
1321 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1322 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.");', $dt, NICKSERV);
1326 $msg = "COMMAND ".$msg;
1327 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1328 $user_cur = &$this->user[$i];
1330 if ($user_cur->sess == '')
1332 if ($user_cur->name == $name_new)
1335 if ($i < MAX_PLAYERS) {
1336 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Nickname <b>%s</b> già in uso.");', $dt, NICKSERV, xcape($name_new));
1340 /* 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>" */
1341 if ($user->flags & USER_FLAG_AUTH) {
1342 if (strcasecmp($user->name,$name_new) != 0) {
1343 if ($user->subst == 'standup' || ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)) {
1344 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1345 for ($i = 0 ; $i < TABLES_N ; $i++) {
1346 $to_user .= $this->table[$i]->act_content($user);
1350 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>");', $dt, NICKSERV);
1355 $user->name = $name_new; // OK - nick changed
1356 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1357 if (($user->flags & USER_FLAG_AUTH) == 0) {
1358 $userdb = new LoginDB();
1359 /* 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>" */
1360 if ($userdb->login_exists($name_new)) {
1361 $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));
1365 log_main("chatt_send start set");
1367 $update_room = TRUE;
1369 } // nick chat command
1371 else if (strncmp($msg, "/st ", 4) == 0) {
1372 log_main("chatt_send BEGIN");
1375 $st_str = substr($msg, 4);
1377 if (strcasecmp($st_str, "normale") == 0) {
1378 $st = USER_FLAG_S_NORM;
1380 else if (strcasecmp($st_str, "pausa") == 0) {
1381 $st = USER_FLAG_S_PAU;
1383 else if (strcasecmp($st_str, "fuori") == 0) {
1384 $st = USER_FLAG_S_OUT;
1386 else if (strcasecmp($st_str, "cane") == 0) {
1387 $st = USER_FLAG_S_DOG;
1389 else if (strcasecmp($st_str, "cibo") == 0) {
1390 $st = USER_FLAG_S_EAT;
1392 else if (strcasecmp($st_str, "lavoro") == 0) {
1393 $st = USER_FLAG_S_WRK;
1395 else if (strcasecmp($st_str, "sigaretta") == 0) {
1396 $st = USER_FLAG_S_SMK;
1398 else if (strcasecmp($st_str, "presente") == 0) {
1399 $st = USER_FLAG_S_EYE;
1402 /* MLANG: "Questo stato non esiste." */
1403 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Questo stato non esiste.");', $dt, NICKSERV);
1407 log_main("chatt_send start set");
1408 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1409 $update_room = TRUE;
1410 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1413 } // nick chat command
1415 else { // normal chat line
1416 $is_normchat = TRUE;
1417 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1419 $user->chat_dlt = $user->chat_dlt * 2;
1420 if ($user->chat_dlt > 120)
1421 $user->chat_dlt = 120;
1423 else if ($user->chat_lst == $msg)
1425 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1426 $user->chat_ban = $curtime;
1427 $user->chat_dlt = 5;
1431 $user->chat_ban = 0;
1432 $user->chat_dlt = 0;
1436 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1439 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1440 // temporary silentiation for troll (will became array check)
1441 if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1442 $to_room = $to_user;
1445 log_legal($curtime, $user,
1446 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1448 $user->chat_lst = "$msg";
1449 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1459 // Output to clients
1462 if ($to_user != FALSE) {
1463 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1464 $user->comm[$user->step % COMM_N] .= $to_user;
1468 if ($to_room != FALSE) {
1469 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1470 $user_cur = &$this->user[$i];
1471 if ($target != "" && $user_cur->name != $target)
1473 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1474 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1477 if ($is_normchat == TRUE) {
1478 if ($user_cur->flags & USER_FLAG_LISTAUTH) {
1479 if (($user->flags & USER_FLAG_AUTH) == 0) {
1485 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1486 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1487 $user_cur->step_inc();
1492 // Before all align times with table timeout
1493 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1494 $table_cur =& $this->table[$table_idx];
1495 // if the table is complete and exists its shared mem we get the info about users lacc
1497 if ($table_cur->player_n == PLAYERS_N) {
1498 log_main("PLAYERS == N TABLE ".$table_idx);
1500 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1501 log_main("bin5 lock data success");
1503 $no_recovery = FALSE;
1504 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1505 if ($table_cur->table_token != $bri->table_token) {
1506 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1511 if ($bri != FALSE) {
1512 $bri_table = &$bri->table[0];
1513 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1514 // stat must be "table" by definition
1515 $bri_user =& $bri->user[$i];
1517 if ($target != "" && $bri_user->name != $target)
1519 log_main("writa: ".$user_mesg);
1520 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1521 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1522 $bri_user->step_inc();
1524 Briskin5::save_data(&$bri);
1526 Briskin5::unlock_data($sem);
1528 } // if ($table_cur->player_n == PLAYERS_N) {
1529 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1530 } // if ($to_tabl == true ...
1533 if ($user->stat == 'room' && $user->subst == 'standup') {
1534 $this->standup_update(&$user);
1536 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1537 log_main("chatt_send pre table update");
1538 $this->table_update(&$user);
1539 log_main("chatt_send post table update");
1541 } // if ($update_room ...
1544 } // function chatt_send( ...
1546 function &get_user($sess, &$idx)
1548 GLOBAL $PHP_SELF, $G_false;
1550 if (validate_sess($sess)) {
1551 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1552 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1555 $ret = &$this->user[$i];
1559 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1560 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1561 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1564 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1573 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1576 * if ($idx > -1 && ret == FALSE) => duplicated nick
1577 * if ($idx == -2 && ret == FALSE) => invalid name
1578 * if ($idx == -3 && ret == FALSE) => wrong password
1579 * if ($idx == -1 && ret == FALSE) => no space left
1580 * if ($idx == 0 && ret == user) => SUCCESS
1581 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1586 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1588 GLOBAL $G_false, $CO_list;
1592 $authenticate = FALSE;
1593 $login_exists = FALSE;
1595 $ghost_auth = FALSE;
1599 if (($name_new = validate_name($name)) == FALSE) {
1604 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1605 if (validate_sess($sess) == FALSE)
1608 /* if pass != FALSE verify the login with pass */
1609 log_auth("XXX", "auth1");
1610 $userdb = new LoginDB();
1611 if ($pass != FALSE) {
1612 log_auth("XXX", "auth2");
1613 $authenticate = $userdb->login_verify($name_new, $pass);
1614 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1616 if ($authenticate == FALSE) {
1622 $login_exists = $userdb->login_exists($name_new);
1624 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1626 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1630 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1632 continue; // NOTE: CHECK IT !!
1634 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1635 if ($authenticate == FALSE) {
1641 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1648 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1650 if ($ghost > -1 && $ghost_auth && $authenticate) {
1653 $ghost_user =& $this->user[$ghost];
1655 $ghost_user->step_inc();
1658 $ghost_user->sess = $sess;
1661 $ghost_user->sess = $sess;
1664 // If user at the table we need to update the table data too
1665 $table_idx = $ghost_user->table;
1666 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1667 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1668 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1669 if ($bri->the_end != TRUE) {
1670 $bri->user[$ghost_user->table_pos]->step_inc();
1671 $bri->user[$ghost_user->table_pos]->sess = $sess;
1672 Briskin5::save_data(&$bri);
1675 Briskin5::unlock_data($brisem);
1680 return ($this->user[$ghost]);
1682 else if ($idx != -1 && $i == MAX_PLAYERS) {
1687 $this->user[$idx]->sess = $sess;
1690 $this->user[$idx]->sess = $sess;
1692 $this->user[$idx]->name = $name_new; // OK - add new user
1693 $this->user[$idx]->stat_set("room");
1694 $this->user[$idx]->step_set(0);
1695 while (array_pop($this->user[$idx]->comm) != NULL);
1696 $this->user[$idx]->subst = "standup";
1697 $this->user[$idx]->lacc = $curtime;
1698 $this->user[$idx]->laccwr = $curtime;
1699 $this->user[$idx]->bantime = 0;
1700 $this->user[$idx]->ip = $ip;
1702 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1704 if ($authenticate) {
1705 $this->user[$idx]->flags |= USER_FLAG_LISTAUTH;
1707 if (isset($CO_list) && strcmp($CO_list, "all") == 0) {
1708 $this->user[$idx]->flags &= ~USER_FLAG_LISTAUTH;
1713 log_main("ghost: rename!");
1714 $ghost_user =& $this->user[$ghost];
1716 if ($ghost_auth == FALSE) {
1717 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1718 $ghostname = 'ghost'.$sfx;
1719 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1720 if (strcmp("", $this->user[$i]->sess) == 0)
1723 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1728 if ($ghostname != '')
1732 $ghost_user->name = $ghostname;
1734 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1735 $this->standup_update(&$ghost_user);
1738 log_main("chatt_send pre table update");
1739 $this->table_update(&$ghost_user);
1740 log_main("chatt_send post table update");
1742 } // if ($ghost_auth == FALSE
1744 // FIXME: cacciare il vecchio utente room && table (if needed)
1745 $ghost_user->the_end = TRUE;
1746 $ghost_user->lacc = 0;
1747 $this->garbage_manager(TRUE);
1749 } // if ($ghost > -1) {
1751 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1755 return ($this->user[$real_idx]);
1761 function standup_update(&$user)
1763 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1764 $user_cur = &$this->user[$i];
1765 if ($user_cur->sess == '')
1768 log_main("STANDUP START: ".$user_cur->stat);
1770 if ($user_cur->stat == 'room') {
1771 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1772 if ($user_cur == $user) {
1773 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1774 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1776 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
1777 $itin, xcape($user->name), $itou);
1779 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1781 $user_cur->step_inc();
1787 function &init_data()
1789 $room =& new Room();
1795 function &load_data()
1797 GLOBAL $G_false, $sess;
1800 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1801 log_main("ftok failed");
1806 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1807 log_main("shmop_open failed");
1811 $shm_sz = SHM_DIMS_MIN;
1813 if ($shm = shm_attach($tok, $shm_sz)) {
1814 $room = @shm_get_var($shm, $tok);
1816 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1818 log_only("bri count ".count($room));
1820 if ($room == FALSE) {
1821 log_only("INIT MAIN DATA");
1823 $room =& Room::init_data();
1824 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1825 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1826 log_only(serialize($room));
1829 $room->shm_sz = $shm_sz;
1844 function save_data(&$room)
1852 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1855 while ($room->shm_sz < SHM_DIMS_MAX) {
1856 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1859 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1860 if (shm_put_var($shm, $tok, $room) != FALSE) {
1864 if (shm_remove($shm) === FALSE) {
1865 log_only("REMOVE FALLITA");
1869 $room->shm_sz += SHM_DIMS_DLT;
1878 function lock_data()
1882 // echo "LOCK: ".FTOK_PATH."/main";
1884 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1887 // echo "FTOK ".$tok."<br>";
1888 if (($res = sem_get($tok)) == FALSE) {
1891 if (sem_acquire($res)) {
1892 log_lock("LOCK room");
1899 function unlock_data($res)
1903 log_lock("UNLOCK room");
1905 return (sem_release($res));
1909 function standup_content($user)
1914 if ($user->stat != 'room')
1917 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1918 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1923 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1925 $content = ' j_stand_cont( [ ';
1927 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1928 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
1931 $flags = $this->user[$e]->flags;
1933 if ($this->user[$e]->subst == "standup") {
1934 if ($this->user[$e] == $user)
1939 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
1948 function table_content_old($user, $table_idx)
1954 // Si possono usare i dati nella classe table
1957 $sess = $user->sess;
1958 $table = &$this->table[$table_idx];
1960 if ($user->stat != 'room')
1963 for ($i = 0 ; $i < $table->player_n ; $i++) {
1964 $user_cur = &$this->user[$table->player[$i]];
1966 if ($user_cur == $user)
1967 { $hilion = "<b>"; $hilioff = "</b>"; }
1969 { $hilion = ""; $hilioff = ""; }
1971 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
1973 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1976 for ( ; $i < PLAYERS_N ; $i++)
1980 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1986 function table_content($user, $table_idx)
1992 // Si possono usare i dati nella classe table
1995 $sess = $user->sess;
1996 $table = &$this->table[$table_idx];
1998 if ($user->stat != 'room')
2002 for ($i = 0 ; $i < $table->player_n ; $i++) {
2003 $user_cur = &$this->user[$table->player[$i]];
2005 $flags = $user_cur->flags;
2007 if ($user_cur == $user)
2010 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2012 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2017 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2024 function make_seed()
2026 list($usec, $sec) = explode(' ', microtime());
2027 return (float) $sec + ((float) $usec * 100000);
2031 function log_only2($log) {
2034 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2037 if (isset($sess) == FALSE)
2042 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2045 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2046 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2051 function log_crit($log) {
2054 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2057 if (isset($sess) == FALSE)
2062 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2065 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2066 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2071 function log_only($log) {
2074 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2077 if (isset($sess) == FALSE)
2082 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2085 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2086 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2091 function log_main($log) {
2094 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2097 if (isset($sess) == FALSE)
2102 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2105 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2106 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2111 function log_rd($log) {
2114 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2117 if (isset($sess) == FALSE)
2122 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2125 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2126 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2131 function log_rd2($log) {
2134 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2137 if (isset($sess) == FALSE)
2142 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2145 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2146 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2151 function log_send($log) {
2154 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2157 if (isset($sess) == FALSE)
2162 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2165 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2166 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2171 function log_lock($log) {
2174 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2177 if (isset($sess) == FALSE)
2182 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2185 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2186 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2191 function log_wr($log) {
2194 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2197 if (isset($sess) == FALSE)
2202 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2205 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2206 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2211 function log_load($log) {
2214 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2217 if (isset($sess) == FALSE)
2222 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2225 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2226 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2231 function log_auth($sess, $log) {
2232 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2235 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2238 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2239 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2245 // function log_legal($curtime, $sess, $name, $where, $mesg)
2246 function log_legal($curtime, &$user, $where, $mesg)
2250 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2251 /* Unix time | session | nickname | IP | where was | mesg */
2252 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2253 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2254 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2262 function lock_banlist()
2264 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2268 if (($res = sem_get($tok)) == FALSE) {
2269 echo "SEM_GET FAILED";
2272 if (sem_acquire($res))
2278 function unlock_banlist($res)
2280 return (sem_release($res));
2283 function table_act_content_old($isstanding, $sitted, $table, $cur_table)
2288 if ($sitted < PLAYERS_N) {
2289 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
2293 if ($table == $cur_table)
2294 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
2301 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2306 if ($sitted < PLAYERS_N) {
2314 if ($table == $cur_table)
2321 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2326 function show_notify($text, $tout, $butt, $w, $h)
2328 log_main("SHOW_NOTIFY: ".$text);
2329 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2332 function multoval($mult)
2336 else if ($mult == 4)
2337 return ("quadruplo");
2339 return (sprintf("%d-plo", $mult));
2343 function root_wellcome($user)
2345 GLOBAL $root_wellarr;
2349 $dt = date("H:i ", $curtime);
2351 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2352 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$i]));
2359 function validate_sess($sess)
2361 if (strlen($sess) == SESS_LEN)
2367 function validate_name($name)
2369 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2371 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2373 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2380 function playsound($filename)
2382 return (sprintf('playsound("flasou", "%s");', $filename));
2385 function secstoword($secs)
2387 $mins = floor($secs / 60);
2390 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2393 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2398 function sharedmem_sz($tok)
2400 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2401 log_main("shmop_open failed");
2404 $shm_sz = shmop_size($shm_id);
2405 shmop_close($shm_id);
2407 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2412 function lock_data()
2416 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2419 // echo "FTOK ".$tok."<br>";
2420 if (($res = sem_get($tok)) == FALSE) {
2423 if (sem_acquire($res)) {
2424 log_lock("LOCK room");
2431 function unlock_data($res)
2435 log_lock("UNLOCK room");
2437 return (sem_release($res));