5 * Copyright (C) 2006-2008 matteo.nastasi@milug.org
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details. You should have received a
16 * copy of the GNU General Public License along with this program; if
17 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
18 * Suite 330, Boston, MA 02111-1307, USA.
23 define(BRISK_CONF, "brisk.conf.pho");
24 define(FTOK_PATH, "/var/lib/brisk");
25 define(LEGAL_PATH, "/tmp/legal_brisk");
26 define(PROXY_PATH, "/var/lib/brisk_proxy");
29 define(MAX_POINTS, 5);
30 define(MAX_PLAYERS, (20 + (PLAYERS_N * TABLES_N)));
31 define(SHM_DIMS_MIN, (50000 + 10000 * TABLES_N + 15000 * MAX_PLAYERS));
32 define(SHM_DIMS_MAX, SHM_DIMS_MIN + 1048576);
33 define(SHM_DIMS_DLT, 65536);
36 define(COMM_GEN_N, 50);
39 define(CHAT_ILL_TIME, 6);
42 define(STREAM_TIMEOUT, 20);
43 define(EXPIRE_TIME_RD, 180);
44 define(EXPIRE_TIME_SMAMMA, 360);
45 // BAN_TIME da allineare anche in commons.js
46 define(BAN_TIME, 900);
47 define(GARBAGE_TIMEOUT, 10);
48 define(NICKSERV, "<i>SERVER</i>");
50 define(DBG_ONL2, 0x0001);
51 define(DBG_ONLY, 0x0002);
52 define(DBG_MAIN, 0x0004);
53 define(DBG_READ, 0x0008);
54 define(DBG_REA2, 0x0010);
55 define(DBG_SEND, 0x0020);
56 define(DBG_LOCK, 0x0040);
57 define(DBG_WRIT, 0x0080);
58 define(DBG_LOAD, 0x0100);
59 define(DBG_AUTH, 0x0200);
60 define(DBG_CRIT, 0x0400);
62 define(BRISK_DEBUG, 0);
64 define(BRISK_SINGLE_DEBUG,0);
65 define(BRISK_SINGLE_SESS, "");
66 // define(DEBUGGING, "local");
68 require_once("$DOCUMENT_ROOT/Etc/".BRISK_CONF);
73 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
74 $G_brisk_version = "spawn-0.11.0";
76 $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: white-list per proxy verificati - versione beta2.',
77 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' );
78 $table_wellarr = Array ( 'Benvenuto al tavolo. Se almeno tre giocatori non sbloccano l\'uscita cliccando il lucchetto, chi esce non può risedersi a un qualunque tavolo per '.floor(BAN_TIME/60).' minuti.');
82 <div style=\\"text-align: left; padding: 8px;\\">
83 <b>Descrizione</b><br>
84 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
85 <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>
86 <b>Configurazione del browser.</b><br>
87 Occorre abilitare i cookies.<br>
89 <b>Uso del sito</b><br>
90 Potete sedervi a un tavolo o rimanere in piedi.<br>
91 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
94 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>
95 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
96 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
97 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
98 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
99 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.
101 <dt><b>Comandi della chat</b>
102 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
103 <dd>.. to be continue ..
109 <div id=\\"header\\" class=\\"header\\">
110 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
111 briscola chiamata in salsa ajax
113 <br><b>version '.$G_brisk_version.'</b><br><br>
114 Copyright 2006-2007 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
119 $from = array ( '\\', '@', '|' );
120 $to = array ( '\\\\', '@', '¦' );
122 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
127 var $value; /* 0 - 39 card value */
128 var $stat; /* 'bunch', 'hand', 'table', 'take' */
129 var $owner; /* (table position 0-4) */
130 // var $pos; /* Pos in hand. */
131 var $x; /* When played the X position on the table of the owner. */
132 var $y; /* When played the Y position on the table of the owner. */
134 function Card($value, $stat, $owner)
136 $this->value = $value;
137 $this->stat = $stat; // Card stat
138 $this->owner = $owner;
141 function assign($stat,$owner)
143 $this->stat = $stat; // Card stat
144 $this->owner = $owner;
147 function setpos($pos)
154 $this->stat = 'table'; // Card stat
159 function take($newown)
161 $this->stat = 'take'; // Card stat
162 $this->owner = $newown;
180 var $points; // points array
181 var $points_n; // number of row of points
205 if (($thiz =& new Table()) == FALSE)
208 $thiz->player = array();
211 $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
212 $thiz->asta_pla_n= -1;
213 $thiz->asta_card = -1;
214 $thiz->asta_pnt = -1;
216 $thiz->points = array( );
218 $thiz->total = array( 0, 0, 0, 0, 0);
219 $thiz->asta_win = -1;
220 $thiz->briscola = -1;
223 $thiz->old_reason = "";
224 $thiz->old_asta_pnt = -1;
227 $thiz->old_friend = -1;
229 $thiz->table_token = "";
230 $thiz->table_start = 0;
235 function &clone(&$from)
239 if (($thiz =& new Table()) == FALSE)
242 $thiz->player = array();
243 for ($i = 0 ; $i < $from->player_n ; $i++)
244 $thiz->player[$i] = $from->player[$i];
245 $thiz->player_n = $from->player_n;
246 $thiz->card = $from->card;
247 $thiz->mazzo = $from->mazzo; // REVIEW
248 $thiz->gstart = $from->gstart;
249 $thiz->turn = $from->turn;
251 $thiz->asta_pla = $from->asta_pla;
252 $thiz->asta_pla_n = $from->asta_pla_n;
253 $thiz->asta_card = $from->asta_card;
254 $thiz->asta_pnt = $from->asta_pnt;
256 $thiz->mult = $from->mult;
257 $thiz->points = $from->points;
258 $thiz->points_n = $from->points_n;
259 $thiz->total = $from->total;
261 $thiz->asta_win = $from->asta_win;
262 $thiz->briscola = $from->briscola;
263 $thiz->friend = $from->friend;
265 $thiz->old_reason = $from->old_reason;
266 $thiz->old_asta_pnt = $from->old_asta_pnt;
267 $thiz->old_pnt = $from->old_pnt;
268 $thiz->old_win = $from->old_win;
269 $thiz->old_friend = $from->old_friend;
271 $thiz->table_token = $from->table_token;
272 $thiz->table_start = $from->table_start;
277 function &spawn(&$from)
281 if (($thiz =& new Table()) == FALSE)
284 $thiz->player_n = $from->player_n;
285 $thiz->card = &$thiz->bunch_create();
286 $thiz->mazzo = $from->mazzo;
287 $thiz->gstart = $from->gstart;
288 $thiz->turn = $from->turn;
290 $thiz->asta_pla = $from->asta_pla;
291 $thiz->asta_pla_n = $from->asta_pla_n;
292 $thiz->asta_card = $from->asta_card;
293 $thiz->asta_pnt = $from->asta_pnt;
295 $thiz->mult = $from->mult;
296 $thiz->points = $from->points;
297 $thiz->points_n = $from->points_n;
298 $thiz->total = $from->total;
300 $thiz->asta_win = $from->asta_win;
301 $thiz->briscola = $from->briscola;
302 $thiz->friend = $from->friend;
304 $thiz->old_reason = $from->old_reason;
305 $thiz->old_asta_pnt = $from->old_asta_pnt;
306 $thiz->old_pnt = $from->old_pnt;
307 $thiz->old_win = $from->old_win;
308 $thiz->old_friend = $from->old_friend;
310 // players are rearranged in an dedicated array
311 $thiz->player = array();
312 for ($i = 0 ; $i < $from->player_n ; $i++)
313 $thiz->player[$i] = $i;
315 $thiz->table_token = $from->table_token;
316 $thiz->table_start = $from->table_start;
321 function &bunch_create()
325 for ($i = 0 ; $i < 40 ; $i++) {
326 $ret[$i] =& new Card($i, 'bunch', 'no_owner');
333 function bunch_make()
335 $ct = array(0,0,0,0,0);
337 mt_srand(make_seed());
339 for ($i = 39 ; $i >= 0 ; $i--)
342 for ($i = 39 ; $i >= 0 ; $i--) {
346 log_main("RND ZERO");
351 $this->card[$id]->assign('hand', $owner);
353 $rest[$rn] = $rest[$i];
354 // $pubbpos[$rn2] = $pubbpos[$i];
358 function init(&$userarr)
360 $this->mazzo = rand(0,PLAYERS_N-1);
364 $this->old_reason = "";
365 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
366 $this->total[$i] = 0;
367 $user_cur = &$userarr[$this->player[$i]];
368 $user_cur->exitislock = TRUE;
371 log_main("table::init: ci siamo");
374 function game_init(&$userarr)
378 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
382 $this->asta_pla_n = PLAYERS_N;
383 $this->asta_card = -1;
384 $this->asta_pnt = 60;
385 $this->asta_win = -1;
386 $this->briscola = -1;
390 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
391 $this->asta_pla[$i] = TRUE;
392 $user_cur = &$userarr[$this->player[$i]];
393 $user_cur->subst = 'asta';
394 $user_cur->asta_card = -2;
395 $user_cur->asta_pnt = -1;
396 $user_cur->handpt = $this->hand_points($i);
397 // SEE function calculate_points(&$table)
403 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
406 function getPlayer($idx)
408 return ($this->player[$idx]);
411 function setPlayer($idx, $player)
413 $this->player[$idx] = $player;
416 function user_add($idx)
418 $this->player[$this->player_n] = $idx;
421 return ($this->player_n - 1);
424 function user_rem(&$room, &$user)
426 $tabpos = $user->table_pos;
428 /* verifico la consistenza dei dati */
429 if ($room->user[$this->player[$tabpos]] == $user) {
431 /* aggiorna l'array dei giocatori al tavolo. */
432 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
433 $this->player[$i] = $this->player[$i+1];
434 $user_cur = &$room->user[$this->player[$i]];
435 $user_cur->table_pos = $i;
440 log_main("INCONSISTENCY ON TABLE.");
444 function hand_points($idx)
446 GLOBAL $G_all_points;
450 for ($i = 0 ; $i < 40 ; $i++) {
451 if ($this->card[$i]->owner != $idx)
454 $ctt = $this->card[$i]->value % 10;
455 $tot += $G_all_points[$ctt];
461 function exitlock_show(&$userarr, $table_pos)
463 $ct = $this->exitlock_calc(&$userarr, $table_pos);
465 $ret = sprintf('exitlock_show(%d, %s);', $ct,
466 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
470 function exitlock_calc(&$userarr, $table_pos)
474 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
475 if ($userarr[$this->player[$i]]->exitislock == FALSE)
484 var $name; // name of the user
485 var $sess; // session of the user
486 var $ip; // ip of the user
487 var $lacc; // last access (for the cleanup)
488 var $laccwr; // last access (for the cleanup)
489 var $bantime; // timeout to temporary ban
490 var $stat; // status (outdoor, room, table, game, ...)
491 var $subst; // substatus for each status
492 var $step; // step of the current status
493 var $trans_step; // step to enable transition between pages (disable == -1)
494 var $comm; // commands array
497 var $handpt; // Total card points at the beginning of the current hand.
498 var $exitislock; // Player can exit from the table ?
499 var $table; // id of the current table (if in table state)
500 var $table_pos; // idx on the table
501 var $table_token;// token that identify a game on a table
502 var $the_end; // Flag to change the end of the session
504 var $chat_lst; // Last chat line
505 var $chattime; // Array of chat times
506 var $chat_cur; // Current chat line number
507 var $chat_ban; // Time for ban chat
508 var $chat_dlt; // Delta t for ban
512 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
515 if (($thiz =& new User()) == FALSE)
521 $thiz->lacc = time();
522 $thiz->laccwr = time();
525 $thiz->subst = $subst;
527 $thiz->trans_step = -1;
528 $thiz->comm = array();
529 $thiz->asta_card = -2;
530 $thiz->asta_pnt = -1;
532 $thiz->exitislock = TRUE;
534 $thiz->chattime = array_fill(0, CHAT_N, 0);
536 $thiz->chat_lst = "";
540 $thiz->table = $table;
541 $thiz->table_pos = -1;
542 $thiz->table_token = "";
547 function &clone(&$from)
551 if (($thiz =& new User()) == FALSE)
554 $thiz->name = $from->name;
555 $thiz->sess = $from->sess;
556 $thiz->ip = $from->ip;
557 $thiz->lacc = $from->lacc;
558 $thiz->laccwr = $from->laccwr;
559 $thiz->bantime = $from->bantime;
560 $thiz->stat = $from->stat;
561 $thiz->subst = $from->subst;
562 $thiz->step = $from->step;
563 $thiz->trans_step = $from->trans_step;
564 $thiz->comm = array();
566 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
567 for ($i = $i_start ; $i < $from->step ; $i++) {
569 $thiz->comm[$ii] = $from->comm[$ii];
571 $thiz->asta_card = $from->asta_card;
572 $thiz->asta_pnt = $from->asta_pnt;
573 $thiz->handpt = $from->handpt;
574 $thiz->exitislock = $from->exitislock;
576 $thiz->chattime = array();
577 for ($i = 0 ; $i < CHAT_N ; $i++)
578 $thiz->chattime[$i] = $from->chattime[$i];
579 $thiz->chat_cur = $from->chat_cur;
580 $thiz->chat_lst = $from->chat_lst;
581 $thiz->chat_ban = $from->chat_ban;
582 $thiz->chat_dlt = $from->chat_dlt;
584 $thiz->table = $from->table;
585 $thiz->table_pos = $from->table_pos;
586 $thiz->table_token = $from->table_token;
587 $thiz->the_end = $from->the_end;
592 function &spawn(&$from, $table, $table_pos)
596 if (($thiz =& new User()) == FALSE)
599 $thiz->name = $from->name;
600 $thiz->sess = $from->sess;
601 $thiz->ip = $from->ip;
602 $thiz->lacc = $from->lacc;
603 $thiz->laccwr = $from->laccwr;
604 $thiz->bantime = $from->bantime;
605 $thiz->stat = $from->stat;
606 $thiz->subst = $from->subst;
607 $thiz->step = $from->step;
608 $thiz->trans_step = $from->trans_step;
609 $thiz->comm = array();
612 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
613 for ($i = $i_start ; $i < $from->step ; $i++) {
614 log_wr("TRY PUSH:".$i);
616 $thiz->comm[$ii] = $from->comm[$ii];
619 $thiz->asta_card = $from->asta_card;
620 $thiz->asta_pnt = $from->asta_pnt;
621 $thiz->handpt = $from->handpt;
622 $thiz->exitislock = $from->exitislock;
623 $thiz->the_end = $from->the_end;
625 $thiz->chattime = array_fill(0, CHAT_N, 0);
627 $thiz->chat_lst = "";
631 $thiz->table = $table;
632 $thiz->table_pos = $table_pos;
633 $thiz->table_token = $from->table_token;
638 function stat_set($stat) {
639 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
640 $this->stat = "$stat";
643 if (validate_sess($this->sess)) {
644 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
645 fwrite($fp, sprintf("%s\n",$this->stat));
651 function step_set($step) {
655 if (validate_sess($this->sess) == FALSE)
657 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
659 fwrite($fp, pack("l",$this->step), 4);
668 function step_inc($delta = 1) {
669 $this->step += $delta;
671 if (validate_sess($this->sess)) {
672 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
673 fwrite($fp, pack("l",$this->step), 4);
683 $tmp_sess = $this->sess;
685 step_unproxy($tmp_sess);
687 while (array_pop($this->comm) != NULL);
689 $this->the_end = FALSE;
694 function step_get($sess) {
698 if (validate_sess($sess) == FALSE)
701 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
704 if (($s = fread($fp, 4)) == FALSE)
710 $arr = unpack('l', $s);
713 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
720 log_rd2("STEP_GET: return false ".$ct);
724 function step_unproxy($sess) {
725 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
726 @unlink(PROXY_PATH."/".$sess.".step");
733 var $comm; // commands for many people
734 var $step; // current step of the comm array
735 var $garbage_timeout;
739 $this->user = array();
740 $this->table = array();
742 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
743 $this->user[$i] =& User::create("", "");
746 for ($i = 0 ; $i < TABLES_N ; $i++)
747 $this->table[$i] =& Table::create();
748 $this->garbage_timeout = 0;
751 function garbage_manager($force)
755 log_rd2("garbage_manager START");
757 /* Garbage collector degli utenti in timeout */
759 if ($force || $this->garbage_timeout < $curtime) {
761 // Before all align times with table timeout
762 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
763 $table_cur =& $this->table[$table_idx];
764 // if the table is complete and exists its shared mem we get the info about users lacc
766 if ($table_cur->player_n == PLAYERS_N) {
767 log_main("PLAYERS == N TABLE ".$table_idx);
769 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
770 log_main("bin5 lock data success");
772 $no_recovery = FALSE;
773 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
774 if ($table_cur->table_token != $bri->table_token) {
775 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
776 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
786 log_main("garbage_manager: bri loaded successfully.");
787 $bri->garbage_manager(TRUE);
789 $bri_table = &$bri->table[0];
791 // is the end of the table
792 if ($bri->the_end == TRUE) {
794 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
796 log_main("garbage_manager: INSIDE THE END.");
798 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
799 // stat must be "table" by definition
800 $user_cur =& $this->user[$table_cur->player[$i]];
801 $bri_user =& $bri->user[$i];
803 $user_cur->subst = $bri_user->subst;
804 $user_cur->step = $bri_user->step;
805 $user_cur->lacc = $bri_user->lacc;
806 $user_cur->laccwr = $bri_user->lacc;
807 $user_cur->bantime = $bri_user->bantime;
810 $this->room_join_wakeup(&$user_cur, FALSE, 0);
811 $table_cur->table_token = "";
813 Briskin5::destroy_data($table_idx);
816 log_main("gm:: save_data");
818 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
819 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
822 Briskin5::save_data(&$bri);
824 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
825 else if ($no_recovery == FALSE) {
826 log_crit("ERROR: table ".$table_idx." unrecoverable join");
828 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
829 $user_cur = &$this->user[$table_cur->player[$i]];
830 $user_cur->subst = "shutdowner";
831 $user_cur->step_inc();
833 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
834 $ret .= "gst.st = ".($user_cur->step+1)."; ";
835 $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);
836 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
837 $user_cur->step_inc();
840 $this->room_join_wakeup(&$user_cur, TRUE, -2);
841 $table_cur->table_token = "";
844 Briskin5::unlock_data($sem);
846 } // if ($table_cur->player_n == PLAYERS_N) {
847 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
849 log_rd2("out new loop.");
851 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
852 $user_cur = &$this->user[$i];
854 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
856 if ($user_cur->sess == "")
859 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
860 // Auto logout dell'utente
861 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
863 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
864 log_auth($user_cur->sess, "Autologout session.");
867 /* factorized with ->reset()
868 $tmp_sess = $user_cur->sess;
869 $user_cur->sess = "";
870 step_unproxy($tmp_sess);
871 $user_cur->name = "";
872 while (array_pop($user_cur->comm) != NULL);
874 $user_cur->the_end = FALSE;
877 log_rd2("AUTO LOGOUT.");
878 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
879 $this->room_wakeup(&$user_cur);
880 else if ($user_cur->subst == 'standup')
881 $this->room_outstandup(&$user_cur);
883 log_rd2("LOGOUT FROM WHAT ???");
887 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
888 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
889 $this->room_wakeup(&$user_cur);
890 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
891 $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);
892 $user_cur->step_inc();
896 log_rd2("GARBAGE UPDATED!");
898 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
906 function room_wakeup(&$user)
908 $table_idx = $user->table;
909 $table = &$this->table[$table_idx];
911 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
915 $from_table = ($user->stat == "table");
917 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
919 for ($i = 0 ; $i < $table->player_n ; $i++) {
920 $user_cur = &$this->user[$table->player[$i]];
921 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
923 if ($user_cur != $user) {
924 $user_cur->stat_set("room");
925 $user_cur->subst = "sitdown";
926 $user_cur->laccwr = $curtime;
928 else if ($user->sess != "") {
929 $user_cur->stat_set("room");
930 $user_cur->subst = "standup";
931 $user_cur->laccwr = $curtime;
932 $user_cur->table = -1;
937 $user->stat_set("room");
938 $user->subst = "standup";
939 $user->laccwr = $curtime;
941 /* aggiorna l'array dei giocatori al tavolo. */
942 $table->user_rem(&$this, &$user);
944 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
945 $user_cur = &$this->user[$i];
946 if ($user_cur->sess == '' || $user_cur->stat != 'room')
949 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
951 $ret = "gst.st = ".($user_cur->step+1)."; ";
952 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
953 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; document.location.assign("index.php");|';
954 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
955 log_main("DOCUMENT.index.php: from table");
957 else if ($user_cur->stat == "room") {
958 log_main("DOCUMENT.index.php: from table");
960 $ret .= table_content($this, $user_cur, $table_idx);
961 $ret .= standup_content($this, $user_cur);
963 $act_content = table_act_content(FALSE, 0, $table_idx, $user->table);
964 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
967 if ($user_cur == $user) {
968 // set the new status
969 $ret .= 'subst = "standup"; ';
970 // clean the action buttons in other tables
971 for ($e = 0 ; $e < TABLES_N ; $e++) {
972 if ($this->table[$e]->player_n < PLAYERS_N)
973 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
977 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
978 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
981 log_wr("ROOM_WAKEUP: ".$ret);
982 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
983 $user_cur->step_inc();
987 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
989 $table_idx = $user->table;
990 $table = &$this->table[$table_idx];
992 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
999 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1001 for ($i = 0 ; $i < $table->player_n ; $i++) {
1002 $user_cur = &$this->user[$table->player[$i]];
1003 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1004 if ($user_cur->sess != "") {
1005 if ($update_lacc == TRUE) {
1006 $user_cur->laccwr = $curtime;
1008 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1009 if ($user_cur->subst == "shutdowned") {
1010 $user_cur->stat_set("room");
1011 $user_cur->subst = "sitdown";
1013 else if ($user_cur->subst == "shutdowner") {
1014 $user_cur->stat_set("room");
1015 $user_cur->subst = "standup";
1016 $user_cur->table = -1;
1017 $user_wup[$user_wup_n++] = &$user_cur;
1019 $user_tab[$user_tab_n++] = &$user_cur;
1023 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1024 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1026 /* aggiorna l'array dei giocatori al tavolo. */
1028 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1029 log_main("START LOOP");
1030 $user_cur = &$this->user[$i];
1031 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1032 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1037 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1039 $ret = "gst.st = ".($user_cur->step+1)."; ";
1040 if ($user_cur->stat == "room") {
1041 log_main("DOCUMENT.index.php from table");
1043 $ret .= table_content($this, $user_cur, $table_idx);
1044 $ret .= standup_content($this, $user_cur);
1046 $act_content = table_act_content(FALSE, 0, $table_idx, $user_cur->table);
1047 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1049 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1050 if ($user_cur == $user_tab[$tab_idx])
1053 // for users that wakeup the room will be reconstructed by index_rd.php
1054 if ($tab_idx < $user_tab_n) {
1055 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1057 // ARRAY_POP DISABLED
1058 // if ($trans_delta == 0)
1059 // while (array_pop($user_cur->comm) != NULL);
1061 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1062 $user_cur->comm[$user_cur->step % COMM_N] = "";
1063 $user_cur->step_inc();
1064 $user_cur->comm[$user_cur->step % COMM_N] = show_room(&$this, ($user_cur->step + 1), &$user_cur);
1065 $user_cur->step_inc();
1066 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1070 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1072 log_main("JOIN_WAKEUP more");
1073 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
1074 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1075 log_main("JOIN_WAKEUP end more");
1077 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1078 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1079 $user_cur->step_inc();
1083 function room_outstandup(&$user)
1085 $this->room_sitdown(&$user, -1);
1088 function table_update(&$user)
1090 log_main("table_update: pre - USER: ".$user->name);
1092 $table_idx = $user->table;
1094 if ($table_idx > -1)
1095 $table = &$this->table[$table_idx];
1097 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1099 $user_cur = &$this->user[$i];
1100 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1103 $ret = "gst.st = ".($user_cur->step+1)."; ";
1104 if ($table_idx > -1)
1105 $ret .= table_content($this, $user_cur, $table_idx);
1107 if ($user_cur == $user) {
1108 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
1110 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1111 $user_cur->step_inc();
1114 log_main("table_update: post");
1117 function room_sitdown(&$user, $table_idx)
1119 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1121 if ($table_idx > -1)
1122 $table = &$this->table[$table_idx];
1124 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1126 $user_cur = &$this->user[$i];
1127 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1130 $ret = "gst.st = ".($user_cur->step+1)."; ";
1131 if ($table_idx > -1)
1132 $ret .= table_content($this, $user_cur, $table_idx);
1133 $ret .= standup_content($this, $user_cur);
1135 if ($user_cur == $user) {
1136 $ret .= 'subst = "sitdown"; ';
1137 // clean the action buttons in other tables
1138 for ($e = 0 ; $e < TABLES_N ; $e++) {
1139 $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
1140 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
1143 else if ($table_idx > -1) {
1144 if ($table->player_n == PLAYERS_N) {
1145 $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
1146 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1149 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1150 $user_cur->step_inc();
1154 function chatt_send(&$user, $mesg)
1158 if ($user->stat == 'table') {
1159 $table = &$this->table[$user->table];
1162 $user_mesg = substr($mesg,6);
1166 $dt = date("H:i ", $timecur);
1167 if (strncmp($user_mesg, "/nick ", 6) == 0) {
1168 log_main("chatt_send BEGIN");
1170 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
1171 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1172 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Il nickname deve contenere almeno una lettera o una cifra.");', $dt.NICKSERV, xcape($name_new));
1177 $user_mesg = "COMMAND ".$user_mesg;
1180 // update local graph
1181 // update remote graphs
1182 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1183 $user_cur = &$this->user[$i];
1184 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1185 if ($user_cur->sess == '')
1187 if ($user_cur->name == $name_new) {
1188 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1189 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
1194 if ($i == MAX_PLAYERS) {
1195 $user->name = $name_new;
1197 log_main("chatt_send start set");
1200 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1201 log_main("chatt_send set loop");
1203 $user_cur = &$this->user[$i];
1204 if ($user_cur->sess == '')
1206 if ($user_cur->stat == 'room') {
1207 if ($user->stat == 'room' && $user->subst == 'standup') {
1208 $this->standup_update(&$user);
1210 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
1211 $user->stat == 'table') {
1212 log_main("chatt_send pre table update");
1214 $this->table_update(&$user);
1216 log_main("chatt_send post table update");
1219 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
1220 $table = &$this->table[$user->table];
1222 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1223 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
1224 xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
1225 xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
1226 xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
1227 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
1228 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
1229 if ($user_cur == $user)
1230 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
1231 xcape($user->name,ENT_COMPAT,"UTF-8"));
1232 $user_cur->step_inc();
1238 if ($timecur < ($user->chat_ban + $user->chat_dlt)) {
1240 $user->chat_dlt = $user->chat_dlt * 2;
1241 if ($user->chat_dlt > 120)
1242 $user->chat_dlt = 120;
1244 else if ($user->chat_lst == $user_mesg)
1246 else if ($timecur - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1247 $user->chat_ban = $timecur;
1248 $user->chat_dlt = 5;
1252 $user->chat_ban = 0;
1253 $user->chat_dlt = 0;
1256 for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
1257 if ($user->stat == 'room') {
1258 $user_cur = &$this->user[$i];
1259 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1263 $user_cur = &$this->user[$table->player[$i]];
1267 if ($user_cur != $user)
1270 $user_mesg = "== chat ban ==";
1273 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1274 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
1275 $dt.xcape($user->name), xcape($user_mesg));
1276 $user_cur->step_inc();
1278 log_legal($timecur, $user->sess, $user->name,
1279 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
1281 $user->chat_lst = "$user_mesg";
1282 $user->chattime[$user->chat_cur % CHAT_N] = $timecur;
1287 function &get_user($sess, &$idx)
1289 GLOBAL $PHP_SELF, $G_false;
1291 if (validate_sess($sess)) {
1292 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1293 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1296 $ret = &$this->user[$i];
1300 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1301 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1302 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1305 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1312 * function &add_user(&$room, &$sess, &$idx, $name, $ip)
1315 * if ($idx != -1 && ret == FALSE) => duplicated nick
1316 * if ($idx == -2 && ret == FALSE) => invalid name
1317 * if ($idx == -1 && ret == FALSE) => no space left
1318 * if (ret == TRUE) => SUCCESS
1320 function &add_user(&$sess, &$idx, $name, $ip)
1327 if (($name_new = validate_name($name)) == FALSE) {
1332 log_auth("XXX", sprintf("ARRIVA: [%s]", $sess));
1333 if (validate_sess($sess) == FALSE)
1336 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1338 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1342 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1345 if (strcmp($this->user[$i]->name, $name_new) == 0) {
1353 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1355 if ($idx != -1 && $i == MAX_PLAYERS) {
1359 $this->user[$idx]->sess = uniqid("");
1360 $sess = $this->user[$idx]->sess;
1364 $this->user[$idx]->sess = $sess;
1366 $this->user[$idx]->name = $name_new;
1367 $this->user[$idx]->stat_set("room");
1368 $this->user[$idx]->step_set(0);
1369 while (array_pop($this->user[$idx]->comm) != NULL);
1370 $this->user[$idx]->subst = "standup";
1371 $this->user[$idx]->lacc = $curtime;
1372 $this->user[$idx]->laccwr = $curtime;
1373 $this->user[$idx]->bantime = 0;
1374 $this->user[$idx]->ip = $ip;
1375 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1377 return ($this->user[$idx]);
1383 function standup_update(&$user)
1385 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1386 $user_cur = &$this->user[$i];
1387 if ($user_cur->sess == '')
1390 log_main("STANDUP START: ".$user_cur->stat);
1392 if ($user_cur->stat == 'room') {
1393 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($this, $user_cur);
1394 if ($user_cur == $user)
1395 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
1397 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1399 $user_cur->step_inc();
1405 function &init_data()
1407 $room =& new Room();
1413 function &load_data()
1415 GLOBAL $G_false, $sess;
1418 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1419 log_main("ftok failed");
1424 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1425 log_main("shmop_open failed");
1429 $shm_sz = SHM_DIMS_MIN;
1431 if ($shm = shm_attach($tok, $shm_sz)) {
1432 $room = @shm_get_var($shm, $tok);
1434 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1436 log_only("bri count ".count($room));
1438 if ($room == FALSE) {
1439 log_only("INIT MAIN DATA");
1441 $room =& Room::init_data();
1442 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1443 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1444 log_only(serialize($room));
1447 $room->shm_sz = $shm_sz;
1462 function save_data(&$room)
1471 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1474 while ($room->shm_sz < SHM_DIMS_MAX) {
1475 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1478 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1479 if (shm_put_var($shm, $tok, $room) != FALSE) {
1483 if (shm_remove($shm) === FALSE) {
1484 log_only("REMOVE FALLITA");
1488 $room->shm_sz += SHM_DIMS_DLT;
1497 function lock_data()
1501 // echo "LOCK: ".FTOK_PATH."/main";
1503 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1507 // echo "FTOK ".$tok."<br>";
1508 if (($res = sem_get($tok)) == FALSE) {
1509 echo "SEM_GET FAILED";
1512 if (sem_acquire($res)) {
1513 log_lock("LOCK room");
1520 function unlock_data($res)
1524 log_lock("UNLOCK room");
1526 return (sem_release($res));
1530 function make_seed()
1532 list($usec, $sec) = explode(' ', microtime());
1533 return (float) $sec + ((float) $usec * 100000);
1537 function log_only2($log) {
1540 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
1543 if (isset($sess) == FALSE)
1548 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
1551 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1552 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
1557 function log_crit($log) {
1560 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
1563 if (isset($sess) == FALSE)
1568 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
1571 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1572 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
1577 function log_only($log) {
1580 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
1583 if (isset($sess) == FALSE)
1588 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
1591 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1592 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
1597 function log_main($log) {
1600 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
1603 if (isset($sess) == FALSE)
1608 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
1611 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1612 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
1617 function log_rd($log) {
1620 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
1623 if (isset($sess) == FALSE)
1628 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
1631 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1632 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
1637 function log_rd2($log) {
1640 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
1643 if (isset($sess) == FALSE)
1648 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
1651 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1652 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
1657 function log_send($log) {
1660 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
1663 if (isset($sess) == FALSE)
1668 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
1671 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1672 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
1677 function log_lock($log) {
1680 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
1683 if (isset($sess) == FALSE)
1688 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
1691 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1692 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
1697 function log_wr($log) {
1700 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
1703 if (isset($sess) == FALSE)
1708 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
1711 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1712 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
1717 function log_load($log) {
1720 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
1723 if (isset($sess) == FALSE)
1728 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
1731 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1732 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
1737 function log_auth($sess, $log) {
1738 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
1741 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
1744 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1745 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
1751 function log_legal($timecur, $sess, $name, $where, $mesg)
1755 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
1756 /* Unix time | session | nickname | IP | where was | mesg */
1757 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|\n", $timecur, $sess, $name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
1765 function lock_banlist()
1767 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
1771 if (($res = sem_get($tok)) == FALSE) {
1772 echo "SEM_GET FAILED";
1775 if (sem_acquire($res))
1781 function unlock_banlist($res)
1783 return (sem_release($res));
1786 function table_act_content($isstanding, $sitted, $table, $cur_table)
1791 if ($sitted < PLAYERS_N) {
1792 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
1796 if ($table == $cur_table)
1797 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
1804 function table_content($room, $user, $table_idx)
1810 // Si possono usare i dati nella classe table
1813 $sess = $user->sess;
1814 $table = &$room->table[$table_idx];
1816 if ($user->stat != 'room')
1819 for ($i = 0 ; $i < $table->player_n ; $i++) {
1820 $user_cur = &$room->user[$table->player[$i]];
1822 if ($user_cur == $user)
1823 { $hilion = "<b>"; $hilioff = "</b>"; }
1825 { $hilion = ""; $hilioff = ""; }
1827 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
1829 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1832 for ( ; $i < PLAYERS_N ; $i++)
1836 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1841 function standup_content(&$room, $user)
1846 if ($user->stat != 'room')
1849 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1850 if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "")
1855 $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1857 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1858 if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "")
1862 if ($room->user[$e]->subst == "standup") {
1863 if (($ct % 4) == 0) {
1866 if ($room->user[$e] == $user)
1867 { $hilion = "<b>"; $hilioff = "</b>"; }
1869 { $hilion = ""; $hilioff = ""; }
1871 $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($room->user[$e]->name), $hilioff);
1872 if (($ct % 4) == 3) {
1873 $content .= '</tr>';
1878 $content .= '</table>';
1880 $content2 = '<input class=\\"button\\" name=\\"logout\\" value=\\"Esco.\\" onclick=\\"window.onunload = null; act_logout();\\" type=\\"button\\">';
1881 $ret .= sprintf('$("standup").innerHTML = "%s"; $("esco").innerHTML = "%s";',
1882 $content, $content2);
1888 function show_notify($text, $tout, $butt, $w, $h)
1890 log_main("SHOW_NOTIFY: ".$text);
1891 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
1894 function briscola_show($room, $table, $user)
1899 if ($table->asta_card == 9)
1900 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
1902 /* text of caller cell */
1903 if ($user->table_pos == $table->asta_win)
1904 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
1906 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
1907 xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd);
1909 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1911 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1912 $ret .= sprintf('$("caller").style.visibility = "visible";');
1913 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1914 $ret .= sprintf('$("astalascio").style.visibility = "";');
1915 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1916 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1922 function game_result($asta_pnt, $pnt)
1924 if ($asta_pnt == 61) {
1927 else if ($pnt == 60)
1933 if ($pnt >= $asta_pnt)
1940 function multoval($mult)
1944 else if ($mult == 4)
1945 return ("quadruplo");
1947 return (sprintf("%d-plo", $mult));
1950 function show_table_info(&$room, &$table, $table_pos)
1953 $user = &$room->user[$table->player[$table_pos]];
1955 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1956 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1959 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1960 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($room->user[$table->player[$i]]->name));
1961 $noty .= sprintf("</tr>");
1964 log_main("show_table_info: pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1966 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1967 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1968 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1969 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1974 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1975 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1976 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1977 $noty .= "</tr></table>";
1979 if ($table->old_reason != "") {
1980 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1983 if ($table->old_win != -1) {
1984 $win = $table->player[$table->old_win];
1985 $fri = $table->player[$table->old_friend];
1987 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1990 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
1991 xcape($room->user[$win]->name),
1992 xcape($room->user[$fri]->name));
1993 if ($table->old_pnt == 120) {
1994 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
1997 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
1998 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1999 'più di 60'), $table->old_pnt,
2000 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
2004 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
2005 xcape($room->user[$win]->name));
2006 if ($table->old_pnt == 120) {
2007 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
2010 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
2011 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
2012 'più di 60'), $table->old_pnt,
2013 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
2017 if ($table->mazzo == $table_pos)
2018 $noty .= "Fai <b>tu</b> il mazzo,";
2020 $unam = xcape($room->user[$table->player[$table->mazzo]]->name);
2021 $noty .= "Il mazzo a <b>$unam</b>,";
2024 if ($user->subst == 'asta') {
2025 if ($table->asta_win == -1) // auction case
2026 $curplayer = $table->gstart % PLAYERS_N;
2028 $curplayer = $table->asta_win;
2030 else if ($user->subst == 'game') {
2031 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
2035 if ($curplayer == $table_pos) {
2036 $noty .= " tocca a <b>te</b> giocare.";
2039 $unam = xcape($room->user[$table->player[$curplayer]]->name);
2040 $noty .= " tocca a <b>$unam</b> giocare.";
2043 if ($table->mult > 1) {
2044 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
2046 $noty .= "<hr><br>";
2048 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
2053 function root_wellcome($user)
2055 GLOBAL $root_wellarr;
2058 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2059 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $root_wellarr[$i]));
2064 function table_wellcome($user)
2066 GLOBAL $table_wellarr;
2069 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
2070 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $table_wellarr[$i]));
2075 function show_room(&$room, $user_step, &$user)
2077 log_main("show_room: username: ".$user->name);
2080 $ret = sprintf('gst.st = %d;', $user_step);
2081 $ret .= sprintf('stat = "%s";', $user->stat);
2083 $ret .= root_wellcome($user);
2084 $ret .= sprintf('subst = "%s";', $user->subst);
2085 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
2086 for ($i = 0 ; $i < TABLES_N ; $i++) {
2087 $ret .= table_content($room, $user, $i);
2088 $act_content = table_act_content(($user->subst == 'standup'),
2089 $room->table[$i]->player_n, $i, $user->table);
2090 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
2092 $ret .= standup_content($room, $user);
2100 is_transition (is from room to table ?)
2101 is_again (is another game)
2103 Examples of $is_transition, $is_again:
2104 from reload of the page: FALSE, FALSE
2105 from sitdown in room: TRUE, FALSE
2106 from table: asta cmd e tutti passano: TRUE, TRUE
2107 from table: fine partita: TRUE, TRUE
2109 function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
2111 $table_idx = $user->table;
2112 $table = &$room->table[$table_idx];
2113 $table_pos = $user->table_pos;
2115 $ret = "table_init();";
2116 $ret .= $table->exitlock_show(&$room->user, $table_pos);
2118 /* GENERAL STATUS */
2119 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
2120 $sendstep, $user->stat, $user->subst, $table_pos);
2122 log_rd(sprintf( 'SHOW_TABLE: gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
2123 $sendstep, $user->stat, $user->subst, $table_pos));
2126 $ret .= "background_set();";
2129 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
2130 $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
2131 xcape($room->user[$table->player[($table_pos)%PLAYERS_N]]->name),
2132 xcape($room->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
2133 xcape($room->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
2134 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
2135 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
2137 /* NOTIFY FOR THE CARD MAKER */
2138 if ($is_transition) { // && $user->subst == "asta" superfluo
2139 $ret .= show_table_info(&$room, &$table, $table_pos);
2142 $ret .= table_wellcome($user);
2144 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
2145 $ret .= playsound("cow.mp3");
2150 if ($is_transition) { // && $user->subst == "asta" superfluo
2153 for ($i = 0 ; $i < 8 ; $i++) {
2154 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
2156 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
2157 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
2163 log_rd("O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
2165 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
2166 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
2167 $table->card[$o]->value : -1),
2168 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
2173 $taked = array(0,0,0,0,0);
2174 $inhand = array(0,0,0,0,0);
2175 $ontabl = array(-1,-1,-1,-1,-1);
2178 for ($i = 0 ; $i < 40 ; $i++) {
2179 if ($table->card[$i]->stat == 'hand') {
2180 if ($table->card[$i]->owner == $table_pos) {
2181 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
2183 $inhand[$table->card[$i]->owner]++;
2185 else if ($table->card[$i]->stat == 'take') {
2186 log_main("Card taked: ".$table->card[$i]->value."OWN: ".$table->card[$i]->owner);
2187 $taked[$table->card[$i]->owner]++;
2189 else if ($table->card[$i]->stat == 'table') {
2190 $ontabl[$table->card[$i]->owner] = $i;
2194 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2195 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
2197 log_main("Stat table: ".$logg);
2199 /* Set ours cards. */
2201 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
2202 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
2203 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
2204 $oursarg .= ($i == 0 ? "" : ", ")."-1";
2205 $ret .= sprintf('card_setours(%s);', $oursarg);
2207 /* Dispose all cards */
2208 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2209 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
2210 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
2211 $inhand[$i], $taked[$i]);
2213 if ($ontabl[$i] != -1) {
2214 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
2215 $table->card[$ontabl[$i]]->value,
2216 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
2222 if ($user->subst == 'asta') {
2224 /* show users auction status */
2226 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2227 $user_cur = &$room->user[$table->player[$i]];
2228 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
2229 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
2232 $showst .= ",-2,-2";
2233 $ret .= sprintf('show_astat(%s);', $showst);
2235 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
2236 /* show card chooser */
2237 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
2242 if ($table_pos == ($table->gstart % PLAYERS_N) &&
2243 $table->asta_win == -1)
2244 $ret .= sprintf('dispose_asta(%d,%d, %s);',
2245 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
2247 $ret .= sprintf('dispose_asta(%d,%d, %s);',
2248 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
2252 if ($table->asta_win == -1) { // auction case
2253 if ($table_pos == ($table->gstart % PLAYERS_N))
2254 $ret .= "remark_on();";
2256 $ret .= "remark_off();";
2258 else { // chooseed case
2259 if ($table_pos == $table->asta_win)
2260 $ret .= "remark_on();";
2262 $ret .= "remark_off();";
2265 else if ($user->subst == 'game') {
2267 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
2268 $ret .= "is_my_time = true; remark_on();";
2270 $ret .= "remark_off();";
2272 /* WHO CALL AND WATH */
2273 $ret .= briscola_show($room, $table, $user);
2277 } // end function show_table(...
2279 function calculate_winner(&$table)
2286 $cur_seed = $table->briscola - ($table->briscola % 10);
2288 for ($i = 0 ; $i < 40 ; $i++) {
2289 if ($table->card[$i]->stat != "table")
2292 log_wr(sprintf("Card On table: [%d]", $i));
2294 $v = $table->card[$i]->value;
2295 $ontab[$table->card[$i]->owner] = $v;
2296 $ontid[$table->card[$i]->owner] = $i;
2297 /* se briscola setto il flag */
2298 if (($v - ($v % 10)) == $cur_seed)
2302 if ($briontab == FALSE) {
2303 $cur_win = $table->gstart;
2304 $cur_val = $ontab[$cur_win];
2305 $cur_seed = $cur_val - ($cur_val % 10);
2308 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2309 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
2310 if ($ontab[$i] < $cur_val) {
2311 $cur_val = $ontab[$i];
2317 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2318 $table->card[$ontid[$i]]->owner = $cur_win;
2319 $table->card[$ontid[$i]]->stat = "take"; // Card stat
2324 function calculate_points(&$table)
2326 GLOBAL $G_all_points;
2330 if ($table->asta_pnt == 60)
2331 $table->asta_pnt = 61;
2333 $table->old_reason = "";
2334 $table->old_win = $table->asta_win;
2335 $table->old_friend = $table->friend;
2336 $table->old_asta_pnt = $table->asta_pnt;
2338 for ($i = 0 ; $i < 40 ; $i++) {
2339 $ctt = $table->card[$i]->value % 10;
2340 $own = $table->card[$i]->owner;
2341 if ($own == $table->asta_win || $own == $table->friend)
2342 $pro += $G_all_points[$ctt];
2345 log_wr(sprintf("PRO: [%d]", $pro));
2348 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
2349 $table->points[$table->points_n % MAX_POINTS] = array();
2350 for ($i = 0 ; $i < PLAYERS_N ; $i++)
2351 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
2353 $table->old_pnt = $pro;
2359 if ($pro >= $table->asta_pnt)
2364 $table->points[$table->points_n % MAX_POINTS] = array();
2365 for ($i = 0 ; $i < 5 ; $i++) {
2366 if ($i == $table->asta_win)
2367 $pt = ($i == $table->friend ? 4 : 2);
2368 else if ($i == $table->friend)
2373 log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
2375 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
2377 log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
2379 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
2380 $table->total[$i] += $pt;
2383 $table->old_pnt = $pro;
2387 function validate_sess($sess)
2389 if (strlen($sess) == SESS_LEN)
2395 function validate_name($name)
2397 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2399 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2401 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2408 function playsound($filename)
2410 return (sprintf('playsound("flasou", "%s");', $filename));
2413 function secstoword($secs)
2415 $mins = floor($secs / 60);
2418 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2421 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2426 function sharedmem_sz($tok)
2428 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2429 log_main("shmop_open failed");
2432 $shm_sz = shmop_size($shm_id);
2433 shmop_close($shm_id);
2435 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);