5 * Copyright (C) 2006-2008 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, 0xffffffff);
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.5 - trusty";
85 /* MLANG: ALL THE INFO STRINGS IN brisk.phh */
86 $root_wellarr = Array ( 'Brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: il rendering degli utenti in piedi è stato riscritto.',
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
121 <div id=\\"header\\" class=\\"header\\">
122 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
123 briscola chiamata in salsa ajax
125 <br><b>version '.$G_brisk_version.'</b><br><br>
126 Copyright 2006-2008 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
131 $from = array ( '\\', '@', '|' );
132 $to = array ( '\\\\', '@', '¦' );
134 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
139 $from = array ( '\\', '|' );
140 $to = array ( '\\\\', '\\|' );
142 return (str_replace($from, $to, $s));
146 var $value; /* 0 - 39 card value */
147 var $stat; /* 'bunch', 'hand', 'table', 'take' */
148 var $owner; /* (table position 0-4) */
149 // var $pos; /* Pos in hand. */
150 var $x; /* When played the X position on the table of the owner. */
151 var $y; /* When played the Y position on the table of the owner. */
153 function Card($value, $stat, $owner)
155 $this->value = $value;
156 $this->stat = $stat; // Card stat
157 $this->owner = $owner;
160 function assign($stat,$owner)
162 $this->stat = $stat; // Card stat
163 $this->owner = $owner;
166 function setpos($pos)
173 $this->stat = 'table'; // Card stat
178 function take($newown)
180 $this->stat = 'take'; // Card stat
181 $this->owner = $newown;
205 var $points; // points array
206 var $points_n; // number of row of points
228 function &create($idx)
232 if (($thiz =& new Table()) == FALSE)
236 $thiz->player = array();
239 $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
240 $thiz->asta_pla_n= -1;
241 $thiz->asta_card = -1;
242 $thiz->asta_pnt = -1;
245 $thiz->auth_only = FALSE;
247 $thiz->points = array( );
249 $thiz->total = array( 0, 0, 0, 0, 0);
250 $thiz->asta_win = -1;
251 $thiz->briscola = -1;
255 $thiz->wag_own = NULL;
259 $thiz->old_reason = "";
260 $thiz->old_asta_pnt = -1;
263 $thiz->old_friend = -1;
265 $thiz->table_token = "";
266 $thiz->table_start = 0;
268 $thiz->wakeup_time = 0;
273 function &clone(&$from)
277 if (($thiz =& new Table()) == FALSE)
280 $thiz->idx = $from->idx;
281 $thiz->player = array();
282 for ($i = 0 ; $i < $from->player_n ; $i++)
283 $thiz->player[$i] = $from->player[$i];
284 $thiz->player_n = $from->player_n;
285 $thiz->card = $from->card;
286 $thiz->mazzo = $from->mazzo; // REVIEW
287 $thiz->gstart = $from->gstart;
288 $thiz->turn = $from->turn;
290 $thiz->auth_only = $from->auth_only;
292 $thiz->wag_own = $from->wag_own;
293 $thiz->wag_com = $from->wag_com;
294 $thiz->wag_tout = $from->wag_taut;
296 $thiz->asta_pla = $from->asta_pla;
297 $thiz->asta_pla_n = $from->asta_pla_n;
298 $thiz->asta_card = $from->asta_card;
299 $thiz->asta_pnt = $from->asta_pnt;
301 $thiz->mult = $from->mult;
302 $thiz->points = $from->points;
303 $thiz->points_n = $from->points_n;
304 $thiz->total = $from->total;
306 $thiz->asta_win = $from->asta_win;
307 $thiz->briscola = $from->briscola;
308 $thiz->friend = $from->friend;
310 $thiz->old_reason = $from->old_reason;
311 $thiz->old_asta_pnt = $from->old_asta_pnt;
312 $thiz->old_pnt = $from->old_pnt;
313 $thiz->old_win = $from->old_win;
314 $thiz->old_friend = $from->old_friend;
316 $thiz->table_token = $from->table_token;
317 $thiz->table_start = $from->table_start;
319 $thiz->wakeup_time = $from->wakeup_time;
324 function &spawn(&$from)
328 if (($thiz =& new Table()) == FALSE)
331 $thiz->idx = $from->idx;
332 $thiz->player_n = $from->player_n;
333 $thiz->card = &$thiz->bunch_create();
334 $thiz->mazzo = $from->mazzo;
335 $thiz->gstart = $from->gstart;
336 $thiz->turn = $from->turn;
338 $thiz->auth_only = $from->auth_only;
340 $thiz->wag_own = $from->wag_own;
341 $thiz->wag_com = $from->wag_com;
342 $thiz->wag_tout = $from->wag_taut;
344 $thiz->asta_pla = $from->asta_pla;
345 $thiz->asta_pla_n = $from->asta_pla_n;
346 $thiz->asta_card = $from->asta_card;
347 $thiz->asta_pnt = $from->asta_pnt;
349 $thiz->mult = $from->mult;
350 $thiz->points = $from->points;
351 $thiz->points_n = $from->points_n;
352 $thiz->total = $from->total;
354 $thiz->asta_win = $from->asta_win;
355 $thiz->briscola = $from->briscola;
356 $thiz->friend = $from->friend;
358 $thiz->old_reason = $from->old_reason;
359 $thiz->old_asta_pnt = $from->old_asta_pnt;
360 $thiz->old_pnt = $from->old_pnt;
361 $thiz->old_win = $from->old_win;
362 $thiz->old_friend = $from->old_friend;
364 // players are rearranged in an dedicated array
365 $thiz->player = array();
366 for ($i = 0 ; $i < $from->player_n ; $i++)
367 $thiz->player[$i] = $i;
369 $thiz->table_token = $from->table_token;
370 $thiz->table_start = $from->table_start;
372 $thiz->wakeup_time = $from->wakeup_time;
377 function &bunch_create()
381 for ($i = 0 ; $i < 40 ; $i++) {
382 $ret[$i] =& new Card($i, 'bunch', 'no_owner');
389 function wag_set(&$user, $mesg)
393 $this->wag_own = &$user;
394 $this->wag_com = $mesg;
398 function wag_reset($timeout)
400 log_main("WAG_RESET");
402 unset($this->wag_own);
403 $this->wag_own = NULL;
405 $this->wag_tout = $timeout;
408 function bunch_make()
410 $ct = array(0,0,0,0,0);
412 mt_srand(make_seed());
414 for ($i = 39 ; $i >= 0 ; $i--)
417 for ($i = 39 ; $i >= 0 ; $i--) {
421 log_main("RND ZERO");
426 $this->card[$id]->assign('hand', $owner);
428 $rest[$rn] = $rest[$i];
429 // $pubbpos[$rn2] = $pubbpos[$i];
433 function init(&$userarr)
435 $this->mazzo = rand(0,PLAYERS_N-1);
439 $this->old_reason = "";
440 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
441 $this->total[$i] = 0;
442 $user_cur = &$userarr[$this->player[$i]];
443 $user_cur->exitislock = TRUE;
446 log_main("table::init: ci siamo");
449 function game_init(&$userarr)
453 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
457 $this->asta_pla_n = PLAYERS_N;
458 $this->asta_card = -1;
459 $this->asta_pnt = 60;
460 $this->asta_win = -1;
461 $this->briscola = -1;
465 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
466 $this->asta_pla[$i] = TRUE;
467 $user_cur = &$userarr[$this->player[$i]];
468 $user_cur->subst = 'asta';
469 $user_cur->asta_card = -2;
470 $user_cur->asta_pnt = -1;
471 $user_cur->handpt = $this->hand_points($i);
472 // SEE function calculate_points(&$table)
478 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
481 function getPlayer($idx)
483 return ($this->player[$idx]);
486 function setPlayer($idx, $player)
488 $this->player[$idx] = $player;
491 function user_add($idx)
493 $this->player[$this->player_n] = $idx;
496 return ($this->player_n - 1);
499 function user_rem(&$room, &$user)
501 $tabpos = $user->table_pos;
503 /* verifico la consistenza dei dati */
504 if ($room->user[$this->player[$tabpos]] == $user) {
506 /* aggiorna l'array dei giocatori al tavolo. */
507 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
508 $this->player[$i] = $this->player[$i+1];
509 $user_cur = &$room->user[$this->player[$i]];
510 $user_cur->table_pos = $i;
515 log_main("INCONSISTENCY ON TABLE.");
519 function hand_points($idx)
521 GLOBAL $G_all_points;
525 for ($i = 0 ; $i < 40 ; $i++) {
526 if ($this->card[$i]->owner != $idx)
529 $ctt = $this->card[$i]->value % 10;
530 $tot += $G_all_points[$ctt];
536 function exitlock_show(&$userarr, $table_pos)
538 $ct = $this->exitlock_calc(&$userarr, $table_pos);
540 $ret = sprintf('exitlock_show(%d, %s);', $ct,
541 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
545 function exitlock_calc(&$userarr, $table_pos)
549 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
550 if ($userarr[$this->player[$i]]->exitislock == FALSE)
560 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
561 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
563 // function act_content($isstanding, $sitted, $table, $cur_table, $allowed)
564 function act_content(&$user)
567 $isstanding = ($user->subst == 'standup');
568 $sitted = $this->player_n;
570 $cur_table = $user->table;
574 if ($sitted < PLAYERS_N) {
575 if ($this->auth_only) {
576 if ($user->flags & USER_FLAG_AUTH)
590 if ($table == $cur_table)
597 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
607 define(USER_FLAG_AUTH, 0x02);
610 define(USER_FLAG_S_NORM, 0x000); // done
611 define(USER_FLAG_S_PAU, 0x100); // done
612 define(USER_FLAG_S_OUT, 0x200); // done
613 define(USER_FLAG_S_DOG, 0x300); // done
614 define(USER_FLAG_S_EAT, 0x400); // done
615 define(USER_FLAG_S_WRK, 0x500); // done
616 define(USER_FLAG_S_SMK, 0x600); // done
617 define(USER_FLAG_S_EYE, 0x700); // done
619 define(USER_FLAG_S_ALL, 0xf00); // done
622 var $name; // name of the user
623 var $sess; // session of the user
624 var $ip; // ip of the user
625 var $lacc; // last access (for the cleanup)
626 var $laccwr; // last access (for the cleanup)
627 var $bantime; // timeout to temporary ban
628 var $stat; // status (outdoor, room, table, game, ...)
629 var $subst; // substatus for each status
630 var $step; // step of the current status
631 var $trans_step; // step to enable transition between pages (disable == -1)
632 var $comm; // commands array
635 var $handpt; // Total card points at the beginning of the current hand.
636 var $exitislock; // Player can exit from the table ?
637 var $table; // id of the current table (if in table state)
638 var $table_pos; // idx on the table
639 var $table_token;// token that identify a game on a table
640 var $flags; // Bitfield with: AUTHENTICATE: 0x02
641 var $the_end; // Flag to change the end of the session
643 var $chat_lst; // Last chat line
644 var $chattime; // Array of chat times
645 var $chat_cur; // Current chat line number
646 var $chat_ban; // Time for ban chat
647 var $chat_dlt; // Delta t for ban
651 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
654 if (($thiz =& new User()) == FALSE)
660 $thiz->lacc = time();
661 $thiz->laccwr = time();
664 $thiz->subst = $subst;
666 $thiz->trans_step = -1;
667 $thiz->comm = array();
668 $thiz->asta_card = -2;
669 $thiz->asta_pnt = -1;
671 $thiz->exitislock = TRUE;
675 $thiz->chattime = array_fill(0, CHAT_N, 0);
677 $thiz->chat_lst = "";
681 $thiz->table = $table;
682 $thiz->table_pos = -1;
683 $thiz->table_token = "";
688 function &clone(&$from)
692 if (($thiz =& new User()) == FALSE)
695 $thiz->name = $from->name;
696 $thiz->sess = $from->sess;
697 $thiz->ip = $from->ip;
698 $thiz->lacc = $from->lacc;
699 $thiz->laccwr = $from->laccwr;
700 $thiz->bantime = $from->bantime;
701 $thiz->stat = $from->stat;
702 $thiz->subst = $from->subst;
703 $thiz->step = $from->step;
704 $thiz->trans_step = $from->trans_step;
705 $thiz->comm = array();
707 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
708 for ($i = $i_start ; $i < $from->step ; $i++) {
710 $thiz->comm[$ii] = $from->comm[$ii];
712 $thiz->asta_card = $from->asta_card;
713 $thiz->asta_pnt = $from->asta_pnt;
714 $thiz->handpt = $from->handpt;
715 $thiz->exitislock = $from->exitislock;
717 $thiz->flags = $from->flags;
719 $thiz->chattime = array();
720 for ($i = 0 ; $i < CHAT_N ; $i++)
721 $thiz->chattime[$i] = $from->chattime[$i];
722 $thiz->chat_cur = $from->chat_cur;
723 $thiz->chat_lst = $from->chat_lst;
724 $thiz->chat_ban = $from->chat_ban;
725 $thiz->chat_dlt = $from->chat_dlt;
727 $thiz->table = $from->table;
728 $thiz->table_pos = $from->table_pos;
729 $thiz->table_token = $from->table_token;
730 $thiz->the_end = $from->the_end;
735 function &spawn(&$from, $table, $table_pos)
739 if (($thiz =& new User()) == FALSE)
742 $thiz->name = $from->name;
743 $thiz->sess = $from->sess;
744 $thiz->ip = $from->ip;
745 $thiz->lacc = $from->lacc;
746 $thiz->laccwr = $from->laccwr;
747 $thiz->bantime = $from->bantime;
748 $thiz->stat = $from->stat;
749 $thiz->subst = $from->subst;
750 $thiz->step = $from->step;
751 $thiz->trans_step = $from->trans_step;
752 $thiz->comm = array();
755 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
756 for ($i = $i_start ; $i < $from->step ; $i++) {
757 log_wr("TRY PUSH:".$i);
759 $thiz->comm[$ii] = $from->comm[$ii];
762 $thiz->asta_card = $from->asta_card;
763 $thiz->asta_pnt = $from->asta_pnt;
764 $thiz->handpt = $from->handpt;
765 $thiz->exitislock = $from->exitislock;
766 $thiz->the_end = $from->the_end;
768 $thiz->flags = $from->flags;
770 $thiz->chattime = array_fill(0, CHAT_N, 0);
772 $thiz->chat_lst = "";
777 $thiz->table = $table;
778 $thiz->table_pos = $table_pos;
779 $thiz->table_token = $from->table_token;
784 function stat_set($stat) {
785 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
786 $this->stat = "$stat";
789 if (validate_sess($this->sess)) {
790 if (file_exists(PROXY_PATH) == FALSE)
792 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
793 fwrite($fp, sprintf("%s\n",$this->stat));
799 function step_set($step) {
803 if (validate_sess($this->sess) == FALSE)
805 if (file_exists(PROXY_PATH) == FALSE)
807 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
809 fwrite($fp, pack("l",$this->step), 4);
818 function step_inc($delta = 1) {
819 $this->step += $delta;
821 if (validate_sess($this->sess)) {
822 if (file_exists(PROXY_PATH) == FALSE)
824 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
825 fwrite($fp, pack("l",$this->step), 4);
836 log_legal($curtime, $this, "STAT:LOGOUT", '');
838 $tmp_sess = $this->sess;
840 step_unproxy($tmp_sess);
841 $this->name = ""; // OK here
842 while (array_pop($this->comm) != NULL);
844 $this->chattime = array_fill(0, CHAT_N, 0);
846 $this->chat_lst = "";
849 $this->the_end = FALSE;
854 function step_get($sess) {
857 if (validate_sess($sess) == FALSE)
860 if (file_exists(PROXY_PATH) == FALSE)
862 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
864 if (($s = fread($fp, 4)) == FALSE)
868 $arr = unpack('l', $s);
871 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
878 log_rd2("STEP_GET: return false ");
883 function step_unproxy($sess) {
884 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
885 if (file_exists(PROXY_PATH) == FALSE)
887 @unlink(PROXY_PATH."/".$sess.".step");
894 var $comm; // commands for many people
895 var $step; // current step of the comm array
896 var $garbage_timeout;
900 $this->user = array();
901 $this->table = array();
903 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
904 $this->user[$i] =& User::create("", "");
907 for ($i = 0 ; $i < TABLES_N ; $i++) {
908 $this->table[$i] =& Table::create($i);
910 $row = ( (((int)($i / 4)) % 2) == 0 );
911 $col = ($i % 2 == 0);
912 $this->table[$i]->auth_only = (($row && $col) || (!$row && !$col));
915 $this->table[$i]->auth_only = FALSE;
918 $this->garbage_timeout = 0;
921 function garbage_manager($force)
925 log_rd2("garbage_manager START");
927 /* Garbage collector degli utenti in timeout */
929 if ($force || $this->garbage_timeout < $curtime) {
931 // Before all align times with table timeout
932 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
933 $table_cur =& $this->table[$table_idx];
934 // if the table is complete and exists its shared mem we get the info about users lacc
936 if ($table_cur->player_n == PLAYERS_N) {
937 log_main("PLAYERS == N TABLE ".$table_idx);
939 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
940 log_main("bin5 lock data success");
942 $no_recovery = FALSE;
943 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
944 if ($table_cur->table_token != $bri->table_token) {
945 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
946 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
956 log_main("garbage_manager: bri loaded successfully.");
957 $bri->garbage_manager(TRUE);
959 $bri_table = &$bri->table[0];
961 // is the end of the table
962 if ($bri->the_end == TRUE) {
964 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
966 log_main("garbage_manager: INSIDE THE END.");
968 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
969 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
970 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
973 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
974 // stat must be "table" by definition
975 $user_cur =& $this->user[$table_cur->player[$i]];
976 $bri_user =& $bri->user[$i];
978 $user_cur->subst = $bri_user->subst;
979 $user_cur->step = $bri_user->step;
980 $user_cur->lacc = $bri_user->lacc;
981 $user_cur->laccwr = $bri_user->lacc;
982 $user_cur->bantime = $bri_user->bantime;
985 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME", $plist);
987 $this->room_join_wakeup(&$user_cur, FALSE, 0);
988 $table_cur->table_token = "";
989 $table_cur->wakeup_time = $curtime + WAKEUP_TIME;
990 Briskin5::destroy_data($table_idx);
993 log_main("gm:: save_data");
995 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
996 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
999 Briskin5::save_data(&$bri);
1001 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1002 else if ($no_recovery == FALSE) {
1003 log_crit("ERROR: table ".$table_idx." unrecoverable join");
1005 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1006 $user_cur = &$this->user[$table_cur->player[$i]];
1007 $user_cur->subst = "shutdowner";
1008 $user_cur->step_inc();
1010 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
1011 $ret .= "gst.st = ".($user_cur->step+1)."; ";
1012 $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);
1013 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1014 $user_cur->step_inc();
1017 $plist = "$table_cur->table_token|$user_cur->table|$table_cur->player_n";
1018 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
1019 $plist .= '|'.$this->user[$table_cur->player[$i]]->sess;
1021 log_legal($curtime, $user_cur, "STAT:DESTROY_GAME(RECOVERY)", $plist);
1023 $this->room_join_wakeup(&$user_cur, TRUE, -2);
1024 $table_cur->table_token = "";
1027 Briskin5::unlock_data($sem);
1029 } // if ($table_cur->player_n == PLAYERS_N) {
1030 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1032 log_rd2("out new loop.");
1034 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1035 $user_cur = &$this->user[$i];
1037 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
1039 if ($user_cur->sess == "")
1042 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
1043 // Auto logout dell'utente
1044 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
1046 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
1047 log_auth($user_cur->sess, "Autologout session.");
1051 log_rd2("AUTO LOGOUT.");
1052 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
1053 $this->room_wakeup(&$user_cur);
1054 else if ($user_cur->subst == 'standup')
1055 $this->room_outstandup(&$user_cur);
1057 log_rd2("LOGOUT FROM WHAT ???");
1061 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
1062 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
1063 $this->room_wakeup(&$user_cur);
1064 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1065 /* 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" */
1066 $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);
1067 $user_cur->step_inc();
1071 log_rd2("GARBAGE UPDATED!");
1073 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
1080 function show_room($user_step, &$user)
1082 log_main("show_room: username: ".$user->name);
1085 $ret = sprintf('gst.st = %d; ', $user_step);
1086 if ($user->subst == 'standup')
1087 $ret .= "tra.show(); ";
1089 $ret .= "tra.hide(); ";
1091 $ret .= sprintf('stat = "%s";', $user->stat);
1093 $ret .= root_wellcome($user);
1094 $ret .= sprintf('subst = "%s";', $user->subst);
1095 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1096 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1097 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1098 for ($i = 0 ; $i < TABLES_N ; $i++) {
1099 $ret .= $this->table_content($user, $i);
1100 // $ret .= table_act_content(($user->subst == 'standup'), $this->table[$i]->player_n, $i, $user->table,
1101 // ($this->table[$i]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1102 $ret .= $this->table[$i]->act_content($user);
1103 if ($this->table[$i]->wag_own != NULL)
1104 $ret .= sprintf('tra.add(%d, "%s: %s"); ', $i, $this->table[$i]->wag_own->name, $this->table[$i]->wag_com);
1106 $ret .= sprintf('tra.rem(%d); ', $i);
1108 $ret .= $this->standup_content($user);
1114 function room_wakeup(&$user)
1116 $table_idx = $user->table;
1117 $table = &$this->table[$table_idx];
1119 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1123 $from_table = ($user->stat == "table");
1125 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1127 for ($i = 0 ; $i < $table->player_n ; $i++) {
1128 $user_cur = &$this->user[$table->player[$i]];
1129 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
1131 if ($user_cur != $user) {
1132 $user_cur->stat_set("room");
1133 $user_cur->subst = "sitdown";
1134 $user_cur->laccwr = $curtime;
1136 else if ($user->sess != "") {
1137 $user_cur->stat_set("room");
1138 $user_cur->subst = "standup";
1139 $user_cur->laccwr = $curtime;
1140 $user_cur->table = -1;
1145 $user->stat_set("room");
1146 $user->subst = "standup";
1147 $user->laccwr = $curtime;
1150 $remove_wagon = false;
1151 if($table->wag_own == $user) {
1152 $remove_wagon = true;
1153 $table->wag_reset($curtime);
1158 /* aggiorna l'array dei giocatori al tavolo. */
1159 $table->user_rem(&$this, &$user);
1161 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1162 $user_cur = &$this->user[$i];
1163 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1166 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1168 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1169 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
1170 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; window.onbeforeunload = null; document.location.assign("index.php");|';
1171 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
1172 log_main("DOCUMENT.index.php: from table");
1174 else if ($user_cur->stat == "room") {
1175 log_main("DOCUMENT.index.php: from table");
1177 $ret .= $this->table_content($user_cur, $table_idx);
1178 $ret .= $this->standup_content($user_cur);
1180 // $ret .= table_act_content(FALSE, 0, $table_idx, $user->table, FALSE);
1181 $ret .= $table->act_content($user);
1183 if ($user_cur == $user) {
1184 // set the new status
1185 $ret .= 'subst = "standup"; tra.show(); ';
1186 // clean the action buttons in other tables
1187 for ($e = 0 ; $e < TABLES_N ; $e++) {
1188 if ($this->table[$e]->player_n < PLAYERS_N) {
1189 // $ret .= table_act_content(TRUE, 0, $e, $user->table,
1190 // ($this->table[$e]->auth_only == FALSE ? TRUE : $user->flags & USER_FLAG_AUTH));
1191 $ret .= $this->table[$e]->act_content($user);
1196 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1197 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1198 $ret .= $table->act_content($user_cur);
1201 log_wr("ROOM_WAKEUP: ".$ret);
1202 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1203 $user_cur->step_inc();
1207 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
1209 $table_idx = $user->table;
1210 $table = &$this->table[$table_idx];
1212 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1215 $user_wup = array();
1217 $user_tab = array();
1219 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1221 for ($i = 0 ; $i < $table->player_n ; $i++) {
1222 $user_cur = &$this->user[$table->player[$i]];
1223 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1224 if ($user_cur->sess != "") {
1225 if ($update_lacc == TRUE) {
1226 $user_cur->laccwr = $curtime;
1228 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1229 if ($user_cur->subst == "shutdowned") {
1230 $user_cur->stat_set("room");
1231 $user_cur->subst = "sitdown";
1233 else if ($user_cur->subst == "shutdowner") {
1234 $user_cur->stat_set("room");
1235 $user_cur->subst = "standup";
1236 $user_cur->table = -1;
1237 $user_wup[$user_wup_n++] = &$user_cur;
1239 $remove_wagon = false;
1240 if($table->wag_own == $user_cur) {
1241 $remove_wagon = true;
1242 $table->wag_reset($curtime);
1245 $user_tab[$user_tab_n++] = &$user_cur;
1249 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1250 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1252 /* aggiorna l'array dei giocatori al tavolo. */
1254 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1255 log_main("START LOOP");
1256 $user_cur = &$this->user[$i];
1257 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1258 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1263 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1265 $ret = "gst.st = ".($user_cur->step+1)."; ".($remove_wagon ? sprintf("tra.rem(%d);",$table_idx) : "");
1266 if ($user_cur->stat == "room") {
1267 log_main("DOCUMENT.index.php from table");
1269 $ret .= $this->table_content($user_cur, $table_idx);
1270 $ret .= $this->standup_content($user_cur);
1272 // $ret .= table_act_content(FALSE, 0, $table_idx, $user_cur->table,
1273 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1274 $ret .= $table->act_content($user_cur);
1277 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1278 if ($user_cur == $user_tab[$tab_idx])
1281 // for users that wakeup the room will be reconstructed by index_rd.php
1282 if ($tab_idx < $user_tab_n) {
1283 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1285 // ARRAY_POP DISABLED
1286 // if ($trans_delta == 0)
1287 // while (array_pop($user_cur->comm) != NULL);
1289 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1290 $user_cur->comm[$user_cur->step % COMM_N] = "";
1291 $user_cur->step_inc();
1292 $user_cur->comm[$user_cur->step % COMM_N] = $this->show_room(($user_cur->step + 1), &$user_cur);
1293 $user_cur->step_inc();
1294 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1298 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1300 log_main("JOIN_WAKEUP more");
1301 // $ret .= table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table,
1302 // ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1303 $ret .= $table->act_content($user_cur);
1305 log_main("JOIN_WAKEUP end more");
1307 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1308 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1309 $user_cur->step_inc();
1313 function room_outstandup(&$user)
1315 $this->room_sitdown(&$user, -1);
1318 function table_update(&$user)
1320 log_main("table_update: pre - USER: ".$user->name);
1322 $table_idx = $user->table;
1324 if ($table_idx > -1)
1325 $table = &$this->table[$table_idx];
1327 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1329 $user_cur = &$this->user[$i];
1330 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1333 $ret = "gst.st = ".($user_cur->step+1)."; ";
1334 if ($table_idx > -1)
1335 $ret .= $this->table_content($user_cur, $table_idx);
1337 if ($user_cur == $user) {
1338 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1339 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1340 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";', $itin, xcape($user->name), $itou);
1342 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1343 $user_cur->step_inc();
1346 log_main("table_update: post");
1349 function room_sitdown(&$user, $table_idx)
1351 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1355 if ($table_idx > -1 && $table_idx < TABLES_N) {
1356 $table = &$this->table[$table_idx];
1359 if ($table->wag_own != NULL && $table->player_n == PLAYERS_N) {
1360 for ($i = 0 ; $i < TABLES_N ; $i++) {
1361 $user_cur =& $this->user[$table->player[$i]];
1362 if ($user_cur == $table->wag_own) {
1363 $train_app = sprintf("tra.rem(%d); ", $table_idx);
1364 $table->wag_reset(time());
1371 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1373 $user_cur = &$this->user[$i];
1374 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1377 $ret = "gst.st = ".($user_cur->step+1)."; ".$train_app;
1378 if ($table_idx > -1)
1379 $ret .= $this->table_content($user_cur, $table_idx);
1380 $ret .= $this->standup_content($user_cur);
1382 if ($user_cur == $user) {
1383 $ret .= 'subst = "sitdown"; tra.hide(); ';
1384 // clean the action buttons in other tables
1385 for ($e = 0 ; $e < TABLES_N ; $e++) {
1386 // $ret .= table_act_content(FALSE, 0, $e, $user_cur->table, FALSE);
1387 $ret .= $this->table[$e]->act_content($user_cur);
1390 else if ($table_idx > -1) {
1391 if ($table->player_n == PLAYERS_N) {
1392 // $ret .= table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table,
1393 /// ($table->auth_only == FALSE ? TRUE : $user_cur->flags & USER_FLAG_AUTH));
1394 $ret .= $table->act_content($user_cur);
1397 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1398 $user_cur->step_inc();
1402 function chatt_send(&$user, $mesg)
1404 GLOBAL $G_alarm_passwd;
1408 $msg = substr($mesg, 6, 128);
1410 $dt = date("H:i ", $curtime);
1420 $update_room = FALSE;
1422 if (strcmp($msg, "/tav") == 0 ||
1423 strncmp($msg, "/tav ", 5) == 0) {
1425 if ($user->stat != 'room' || $user->subst != 'sitdown') {
1426 /* 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>" */
1427 $msg = "<br>Per attivare il messaggio di segnalazione del tavolo occorre essere seduti.<br><br>";
1428 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1433 $table = &$this->table[$user->table];
1435 if ($table->wag_own != NULL) {
1436 $msg = "<br>Il messaggio di segnalazione del tavolo è già attivato.<br><br>";
1437 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1442 $dtime = $curtime - $table->wag_tout;
1443 if ($dtime < EXPIRE_TIME_WAG) {
1444 $msg = sprintf("<br>Il messaggio di segnalazione del tavolo<br>è disattivato ancora per %d second%s.<br><br>",
1445 EXPIRE_TIME_WAG - $dtime, (EXPIRE_TIME_WAG - $dtime == 1 ? "o" : "i"));
1446 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1451 $msg = substr($msg, 5);
1453 $table->wag_set($user, $msg);
1454 $to_user = sprintf('tra.add(%d, "%s");', $user->table, xcape(sprintf("%s: %s", $user->name, $msg)));
1455 $to_room = $to_user;
1458 } // /tav chat command
1460 else if (strncmp($msg, "/alarm ", 7) == 0) {
1461 if (strncmp($msg, "/alarm to ", 10) == 0) {
1462 $sp_pos = strpos($msg, " ", 10);
1463 $target = substr($msg, 10, $sp_pos - 10);
1464 $alarm_check = "/alarm to ".$target." ".$G_alarm_passwd." ";
1468 $alarm_check = "/alarm ".$G_alarm_passwd." ";
1471 if (strncmp($msg, $alarm_check, strlen($alarm_check)) != 0) {
1472 /* MLANG: "<br>La password digitata non è corretta.<br><br>" */
1473 $msg = "<br>La password digitata non è corretta.<br><br>";
1474 $to_user = show_notify($msg, 0, "chiudi", 400, 100);
1479 /* MLANG: "Alarm <b>%s</b> inviato a <b>%s</b>." */
1480 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Alarm <b>%s</b> inviato a <b>%s</b>.");',
1481 $dt, NICKSERV, xcape(substr($msg, strlen($alarm_check))),
1482 ($target == "" ? "tutti" : xcape($target)) );
1484 $msg = sprintf("<br><b>%s<br><br>%s</b><br><br>",
1485 $dt.NICKSERV, xcape(substr($msg, strlen($alarm_check))));
1486 /* MLANG: "chiudi" */
1487 $to_all = show_notify($msg, 0, "chiudi", 400, 120);
1489 } // /alarm chat command
1490 else if (strncmp($msg, "/garante", 8) == 0) {
1491 if ($user->flags & USER_FLAG_AUTH) {
1492 $to_user = sprintf('authbox(300,200);');
1495 /* 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." */
1496 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Per autenticare qualcuno devi a tua volta essere autenticato.</b>");', $dt, NICKSERV);
1499 else if (strncmp($msg, "/nick ", 6) == 0) {
1500 log_main("chatt_send BEGIN");
1503 if (($name_new = validate_name(substr($msg, 6))) == FALSE) {
1504 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.");', $dt, NICKSERV);
1508 $msg = "COMMAND ".$msg;
1509 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1510 $user_cur = &$this->user[$i];
1512 if ($user_cur->sess == '')
1514 if ($user_cur->name == $name_new)
1517 if ($i < MAX_PLAYERS) {
1518 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"Nickname <b>%s</b> già in uso.");', $dt, NICKSERV, xcape($name_new));
1522 /* 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>" */
1523 if ($user->flags & USER_FLAG_AUTH) {
1524 if (strcasecmp($user->name,$name_new) != 0) {
1525 if ($user->subst == 'standup' || ($user->subst != 'standup' && $this->table[$user->table]->auth_only == FALSE)) {
1526 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1527 for ($i = 0 ; $i < TABLES_N ; $i++) {
1528 $to_user .= $this->table[$i]->act_content($user);
1532 $to_user = sprintf('chatt_sub("%s", [2, "%s"],"<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>");', $dt, NICKSERV);
1537 $user->name = $name_new; // OK - nick changed
1538 /* se nome gia' in uso, segnala cosa potrebbe capitare */
1539 if (($user->flags & USER_FLAG_AUTH) == 0) {
1540 $userdb = new LoginDB();
1541 /* 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>" */
1542 if ($userdb->login_exists($name_new)) {
1543 $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));
1547 log_main("chatt_send start set");
1549 $update_room = TRUE;
1551 } // nick chat command
1553 else if (strncmp($msg, "/st ", 4) == 0) {
1554 log_main("chatt_send BEGIN");
1557 $st_str = substr($msg, 4);
1559 if (strcasecmp($st_str, "normale") == 0) {
1560 $st = USER_FLAG_S_NORM;
1562 else if (strcasecmp($st_str, "pausa") == 0) {
1563 $st = USER_FLAG_S_PAU;
1565 else if (strcasecmp($st_str, "fuori") == 0) {
1566 $st = USER_FLAG_S_OUT;
1568 else if (strcasecmp($st_str, "cane") == 0) {
1569 $st = USER_FLAG_S_DOG;
1571 else if (strcasecmp($st_str, "cibo") == 0) {
1572 $st = USER_FLAG_S_EAT;
1574 else if (strcasecmp($st_str, "lavoro") == 0) {
1575 $st = USER_FLAG_S_WRK;
1577 else if (strcasecmp($st_str, "sigaretta") == 0) {
1578 $st = USER_FLAG_S_SMK;
1580 else if (strcasecmp($st_str, "presente") == 0) {
1581 $st = USER_FLAG_S_EYE;
1584 /* MLANG: "Questo stato non esiste." */
1585 $to_user = sprintf('chatt_sub("%s", [2,"%s"],"Questo stato non esiste.");', $dt, NICKSERV);
1589 log_main("chatt_send start set");
1590 if (($user->flags & USER_FLAG_S_ALL) != $st) {
1591 $update_room = TRUE;
1592 $user->flags = ($user->flags & ~USER_FLAG_S_ALL) | $st;
1595 } // nick chat command
1597 else { // normal chat line
1598 if ($curtime < ($user->chat_ban + $user->chat_dlt)) {
1600 $user->chat_dlt = $user->chat_dlt * 2;
1601 if ($user->chat_dlt > 120)
1602 $user->chat_dlt = 120;
1604 else if ($user->chat_lst == $msg)
1606 else if ($curtime - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1607 $user->chat_ban = $curtime;
1608 $user->chat_dlt = 5;
1612 $user->chat_ban = 0;
1613 $user->chat_dlt = 0;
1617 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape("== chat ban =="));
1620 $to_user = sprintf('chatt_sub("%s", [%d, "%s"],"%s");', $dt, $user->flags, xcape($user->name), xcape($msg));
1621 // temporary silentiation for troll (will became array check)
1622 if (strcasecmp($user->name,'JackRokka') != 0 && $user->sess != '47ea653f602e8')
1623 $to_room = $to_user;
1626 log_legal($curtime, $user,
1627 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$msg);
1629 $user->chat_lst = "$msg";
1630 $user->chattime[$user->chat_cur % CHAT_N] = $curtime;
1640 // Output to clients
1643 if ($to_user != FALSE) {
1644 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1645 $user->comm[$user->step % COMM_N] .= $to_user;
1649 if ($to_room != FALSE) {
1650 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1651 $user_cur = &$this->user[$i];
1652 if ($target != "" && $user_cur->name != $target)
1654 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1655 if ($user_cur->sess == '' || $user_cur->stat == 'table' || $user_cur == $user)
1658 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1659 $user_cur->comm[$user_cur->step % COMM_N] .= $to_room;
1660 $user_cur->step_inc();
1665 // Before all align times with table timeout
1666 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1667 $table_cur =& $this->table[$table_idx];
1668 // if the table is complete and exists its shared mem we get the info about users lacc
1670 if ($table_cur->player_n == PLAYERS_N) {
1671 log_main("PLAYERS == N TABLE ".$table_idx);
1673 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
1674 log_main("bin5 lock data success");
1676 $no_recovery = FALSE;
1677 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1678 if ($table_cur->table_token != $bri->table_token) {
1679 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
1684 if ($bri != FALSE) {
1685 $bri_table = &$bri->table[0];
1686 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
1687 // stat must be "table" by definition
1688 $bri_user =& $bri->user[$i];
1690 if ($target != "" && $bri_user->name != $target)
1692 log_main("writa: ".$user_mesg);
1693 $bri_user->comm[$bri_user->step % COMM_N] = "gst.st = ".($bri_user->step+1)."; ";
1694 $bri_user->comm[$bri_user->step % COMM_N] .= $to_tabl;
1695 $bri_user->step_inc();
1697 Briskin5::save_data(&$bri);
1699 Briskin5::unlock_data($sem);
1701 } // if ($table_cur->player_n == PLAYERS_N) {
1702 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
1703 } // if ($to_tabl == true ...
1706 if ($user->stat == 'room' && $user->subst == 'standup') {
1707 $this->standup_update(&$user);
1709 else if ($user->stat == 'room' && $user->subst == 'sitdown') {
1710 log_main("chatt_send pre table update");
1711 $this->table_update(&$user);
1712 log_main("chatt_send post table update");
1714 } // if ($update_room ...
1717 } // function chatt_send( ...
1719 function &get_user($sess, &$idx)
1721 GLOBAL $PHP_SELF, $G_false;
1723 if (validate_sess($sess)) {
1724 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1725 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1728 $ret = &$this->user[$i];
1732 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1733 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1734 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1737 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1746 * function &add_user(&$room, &$sess, &$idx, $name, $pass, $ip)
1749 * if ($idx > -1 && ret == FALSE) => duplicated nick
1750 * if ($idx == -2 && ret == FALSE) => invalid name
1751 * if ($idx == -3 && ret == FALSE) => wrong password
1752 * if ($idx == -1 && ret == FALSE) => no space left
1753 * if ($idx == 0 && ret == user) => SUCCESS
1754 * if ($idx == -$idx && ret == user) => SUCCESS (but the login exists in the auth db
1759 function &add_user(&$sess, &$idx, $name, $pass, $ip)
1765 $authenticate = FALSE;
1766 $login_exists = FALSE;
1768 $ghost_auth = FALSE;
1772 if (($name_new = validate_name($name)) == FALSE) {
1777 log_auth("XXX", sprintf("ARRIVA: [%s] pass:[%s]", $sess, ($pass == FALSE ? "FALSE" : $pass)));
1778 if (validate_sess($sess) == FALSE)
1781 /* if pass != FALSE verify the login with pass */
1782 log_auth("XXX", "auth1");
1783 $userdb = new LoginDB();
1784 if ($pass != FALSE) {
1785 log_auth("XXX", "auth2");
1786 $authenticate = $userdb->login_verify($name_new, $pass);
1787 log_auth("XXX", "authenticate: ".($authenticate == TRUE ? "TRUE" : "FALSE"));
1789 if ($authenticate == FALSE) {
1795 $login_exists = $userdb->login_exists($name_new);
1797 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1799 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1803 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1805 continue; // NOTE: CHECK IT !!
1807 if (strcasecmp($this->user[$i]->name, $name_new) == 0) {
1808 if ($authenticate == FALSE) {
1814 $ghost_auth = ($this->user[$i]->flags & USER_FLAG_AUTH);
1821 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1823 if ($ghost > -1 && $ghost_auth && $authenticate) {
1826 $ghost_user =& $this->user[$ghost];
1828 $ghost_user->step_inc();
1831 $ghost_user->sess = $sess;
1834 $ghost_user->sess = $sess;
1837 // If user at the table we need to update the table data too
1838 $table_idx = $ghost_user->table;
1839 if ($ghost_user->stat == "table" && $this->table[$table_idx]->player_n == PLAYERS_N) {
1840 if (($brisem = Briskin5::lock_data($table_idx)) != FALSE) {
1841 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
1842 if ($bri->the_end != TRUE) {
1843 $bri->user[$ghost_user->table_pos]->step_inc();
1844 $bri->user[$ghost_user->table_pos]->sess = $sess;
1845 Briskin5::save_data(&$bri);
1848 Briskin5::unlock_data($brisem);
1853 return ($this->user[$ghost]);
1855 else if ($idx != -1 && $i == MAX_PLAYERS) {
1860 $this->user[$idx]->sess = $sess;
1863 $this->user[$idx]->sess = $sess;
1865 $this->user[$idx]->name = $name_new; // OK - add new user
1866 $this->user[$idx]->stat_set("room");
1867 $this->user[$idx]->step_set(0);
1868 while (array_pop($this->user[$idx]->comm) != NULL);
1869 $this->user[$idx]->subst = "standup";
1870 $this->user[$idx]->lacc = $curtime;
1871 $this->user[$idx]->laccwr = $curtime;
1872 $this->user[$idx]->bantime = 0;
1873 $this->user[$idx]->ip = $ip;
1875 $this->user[$idx]->flags = ($authenticate ? USER_FLAG_AUTH : 0x00);
1878 log_main("ghost: rename!");
1879 $ghost_user =& $this->user[$ghost];
1881 if ($ghost_auth == FALSE) {
1882 for ($sfx = 1 ; $sfx <= MAX_PLAYERS ; $sfx++) {
1883 $ghostname = 'ghost'.$sfx;
1884 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1885 if (strcmp("", $this->user[$i]->sess) == 0)
1888 if (strcmp($this->user[$i]->name, $ghostname) == 0) {
1893 if ($ghostname != '')
1897 $ghost_user->name = $ghostname;
1899 if ($ghost_user->stat == 'room' && $ghost_user->subst == 'standup') {
1900 $this->standup_update(&$ghost_user);
1903 log_main("chatt_send pre table update");
1904 $this->table_update(&$ghost_user);
1905 log_main("chatt_send post table update");
1907 } // if ($ghost_auth == FALSE
1909 // FIXME: cacciare il vecchio utente room && table (if needed)
1910 $ghost_user->the_end = TRUE;
1911 $ghost_user->lacc = 0;
1912 $this->garbage_manager(TRUE);
1914 } // if ($ghost > -1) {
1916 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1920 return ($this->user[$real_idx]);
1926 function standup_update(&$user)
1928 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1929 $user_cur = &$this->user[$i];
1930 if ($user_cur->sess == '')
1933 log_main("STANDUP START: ".$user_cur->stat);
1935 if ($user_cur->stat == 'room') {
1936 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".$this->standup_content($user_cur);
1937 if ($user_cur == $user) {
1938 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1939 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1941 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>: ";',
1942 $itin, xcape($user->name), $itou);
1944 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1946 $user_cur->step_inc();
1952 function &init_data()
1954 $room =& new Room();
1960 function &load_data()
1962 GLOBAL $G_false, $sess;
1965 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1966 log_main("ftok failed");
1971 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1972 log_main("shmop_open failed");
1976 $shm_sz = SHM_DIMS_MIN;
1978 if ($shm = shm_attach($tok, $shm_sz)) {
1979 $room = @shm_get_var($shm, $tok);
1981 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1983 log_only("bri count ".count($room));
1985 if ($room == FALSE) {
1986 log_only("INIT MAIN DATA");
1988 $room =& Room::init_data();
1989 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1990 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1991 log_only(serialize($room));
1994 $room->shm_sz = $shm_sz;
2009 function save_data(&$room)
2017 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
2020 while ($room->shm_sz < SHM_DIMS_MAX) {
2021 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
2024 // log_only("PUT_VAR DI ".strlen(serialize($room)));
2025 if (shm_put_var($shm, $tok, $room) != FALSE) {
2029 if (shm_remove($shm) === FALSE) {
2030 log_only("REMOVE FALLITA");
2034 $room->shm_sz += SHM_DIMS_DLT;
2043 function lock_data()
2047 // echo "LOCK: ".FTOK_PATH."/main";
2049 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
2052 // echo "FTOK ".$tok."<br>";
2053 if (($res = sem_get($tok)) == FALSE) {
2056 if (sem_acquire($res)) {
2057 log_lock("LOCK room");
2064 function unlock_data($res)
2068 log_lock("UNLOCK room");
2070 return (sem_release($res));
2074 function standup_content($user)
2079 if ($user->stat != 'room')
2082 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
2083 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2088 // $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
2090 $content = ' j_stand_cont( [ ';
2092 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
2093 if ($this->user[$e]->sess == "" || $this->user[$e]->stat != "room" || $this->user[$e]->name == "")
2096 $flags = $this->user[$e]->flags;
2098 if ($this->user[$e]->subst == "standup") {
2099 if ($this->user[$e] == $user)
2104 $content .= sprintf('%s[ %d, "%s" ]',($ct > 0 ? ', ' : ''), $flags, xcape($this->user[$e]->name));
2113 function table_content_old($user, $table_idx)
2119 // Si possono usare i dati nella classe table
2122 $sess = $user->sess;
2123 $table = &$this->table[$table_idx];
2125 if ($user->stat != 'room')
2128 for ($i = 0 ; $i < $table->player_n ; $i++) {
2129 $user_cur = &$this->user[$table->player[$i]];
2131 if ($user_cur == $user)
2132 { $hilion = "<b>"; $hilioff = "</b>"; }
2134 { $hilion = ""; $hilioff = ""; }
2136 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2138 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
2141 for ( ; $i < PLAYERS_N ; $i++)
2145 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
2151 function table_content($user, $table_idx)
2157 // Si possono usare i dati nella classe table
2160 $sess = $user->sess;
2161 $table = &$this->table[$table_idx];
2163 if ($user->stat != 'room')
2167 for ($i = 0 ; $i < $table->player_n ; $i++) {
2168 $user_cur = &$this->user[$table->player[$i]];
2170 $flags = $user_cur->flags;
2172 if ($user_cur == $user)
2175 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
2177 $content .= sprintf('%s[ %d, "%s" ]',($i == 0 ? '' : ', '), $flags, xcape($user_cur->name));
2182 $ret .= sprintf('j_tab_cont(%d, %s);', $table_idx, $content);
2189 function make_seed()
2191 list($usec, $sec) = explode(' ', microtime());
2192 return (float) $sec + ((float) $usec * 100000);
2196 function log_only2($log) {
2199 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
2202 if (isset($sess) == FALSE)
2207 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
2210 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2211 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
2216 function log_crit($log) {
2219 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
2222 if (isset($sess) == FALSE)
2227 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
2230 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2231 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
2236 function log_only($log) {
2239 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
2242 if (isset($sess) == FALSE)
2247 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
2250 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2251 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
2256 function log_main($log) {
2259 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
2262 if (isset($sess) == FALSE)
2267 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
2270 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2271 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
2276 function log_rd($log) {
2279 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
2282 if (isset($sess) == FALSE)
2287 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
2290 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2291 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
2296 function log_rd2($log) {
2299 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
2302 if (isset($sess) == FALSE)
2307 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
2310 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2311 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
2316 function log_send($log) {
2319 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
2322 if (isset($sess) == FALSE)
2327 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
2330 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2331 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
2336 function log_lock($log) {
2339 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
2342 if (isset($sess) == FALSE)
2347 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
2350 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2351 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
2356 function log_wr($log) {
2359 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
2362 if (isset($sess) == FALSE)
2367 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
2370 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2371 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
2376 function log_load($log) {
2379 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
2382 if (isset($sess) == FALSE)
2387 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
2390 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2391 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
2396 function log_auth($sess, $log) {
2397 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
2400 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
2403 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
2404 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
2410 // function log_legal($curtime, $sess, $name, $where, $mesg)
2411 function log_legal($curtime, &$user, $where, $mesg)
2415 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
2416 /* Unix time | session | nickname | IP | where was | mesg */
2417 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
2418 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
2419 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
2427 function lock_banlist()
2429 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
2433 if (($res = sem_get($tok)) == FALSE) {
2434 echo "SEM_GET FAILED";
2437 if (sem_acquire($res))
2443 function unlock_banlist($res)
2445 return (sem_release($res));
2448 function table_act_content_old($isstanding, $sitted, $table, $cur_table)
2453 if ($sitted < PLAYERS_N) {
2454 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
2458 if ($table == $cur_table)
2459 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
2466 function table_act_content($isstanding, $sitted, $table, $cur_table, $allowed)
2471 if ($sitted < PLAYERS_N) {
2479 if ($table == $cur_table)
2486 $ret = sprintf('j_tab_act_cont(%d, \'%s\');', $table, $act);
2491 function show_notify($text, $tout, $butt, $w, $h)
2493 log_main("SHOW_NOTIFY: ".$text);
2494 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
2497 function multoval($mult)
2501 else if ($mult == 4)
2502 return ("quadruplo");
2504 return (sprintf("%d-plo", $mult));
2508 function root_wellcome($user)
2510 GLOBAL $root_wellarr;
2514 $dt = date("H:i ", $curtime);
2516 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2517 $ret .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, str_replace('"', '\"', $root_wellarr[$i]));
2524 function validate_sess($sess)
2526 if (strlen($sess) == SESS_LEN)
2532 function validate_name($name)
2534 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2536 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2538 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2545 function playsound($filename)
2547 return (sprintf('playsound("flasou", "%s");', $filename));
2550 function secstoword($secs)
2552 $mins = floor($secs / 60);
2555 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2558 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2563 function sharedmem_sz($tok)
2565 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2566 log_main("shmop_open failed");
2569 $shm_sz = shmop_size($shm_id);
2570 shmop_close($shm_id);
2572 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);
2577 function lock_data()
2581 if (($tok = @ftok(FTOK_PATH."/warrant", "B")) == -1) {
2584 // echo "FTOK ".$tok."<br>";
2585 if (($res = sem_get($tok)) == FALSE) {
2588 if (sem_acquire($res)) {
2589 log_lock("LOCK room");
2596 function unlock_data($res)
2600 log_lock("UNLOCK room");
2602 return (sem_release($res));