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.
22 define(FTOK_PATH, "/var/lib/brisk");
23 define(LEGAL_PATH, "/tmp/legal_brisk");
24 define(PROXY_PATH, "/var/lib/brisk_proxy");
27 define(MAX_POINTS, 5);
28 define(MAX_PLAYERS, (20 + (PLAYERS_N * TABLES_N)));
29 define(SHM_DIMS_MIN, (50000 + 10000 * TABLES_N + 15000 * MAX_PLAYERS));
30 define(SHM_DIMS_MAX, SHM_DIMS_MIN + 1048576);
31 define(SHM_DIMS_DLT, 65536);
34 define(COMM_GEN_N, 50);
37 define(CHAT_ILL_TIME, 6);
40 define(STREAM_TIMEOUT, 20);
41 define(EXPIRE_TIME_RD, 180);
42 define(EXPIRE_TIME_SMAMMA, 360);
43 // BAN_TIME da allineare anche in commons.js
44 define(BAN_TIME, 900);
45 define(GARBAGE_TIMEOUT, 10);
46 define(NICKSERV, "<i>SERVER</i>");
48 define(DBG_ONL2, 0x0001);
49 define(DBG_ONLY, 0x0002);
50 define(DBG_MAIN, 0x0004);
51 define(DBG_READ, 0x0008);
52 define(DBG_REA2, 0x0010);
53 define(DBG_SEND, 0x0020);
54 define(DBG_LOCK, 0x0040);
55 define(DBG_WRIT, 0x0080);
56 define(DBG_LOAD, 0x0100);
57 define(DBG_AUTH, 0x0200);
58 define(DBG_CRIT, 0x0400);
60 define(BRISK_DEBUG, 0);
62 define(BRISK_SINGLE_DEBUG,0);
63 define(BRISK_SINGLE_SESS, "");
64 // define(DEBUGGING, "local");
68 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
69 $G_brisk_version = "spawn-0.10.6";
71 $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: dimensionamento dinamico dell\'area dati e ottimizzazione della stessa, versione beta2.',
72 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' );
73 $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.');
77 <div style=\\"text-align: left; padding: 8px;\\">
78 <b>Descrizione</b><br>
79 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
80 <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>
81 <b>Configurazione del browser.</b><br>
82 Occorre abilitare i cookies.<br>
84 <b>Uso del sito</b><br>
85 Potete sedervi a un tavolo o rimanere in piedi.<br>
86 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
89 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>
90 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
91 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
92 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
93 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
94 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.
96 <dt><b>Comandi della chat</b>
97 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
98 <dd>.. to be continue ..
104 <div id=\\"header\\" class=\\"header\\">
105 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
106 briscola chiamata in salsa ajax
108 <br><b>version '.$G_brisk_version.'</b><br><br>
109 Copyright 2006-2007 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
114 $from = array ( '\\', '@', '|' );
115 $to = array ( '\\\\', '@', '¦' );
117 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
122 var $value; /* 0 - 39 card value */
123 var $stat; /* 'bunch', 'hand', 'table', 'take' */
124 var $owner; /* (table position 0-4) */
125 // var $pos; /* Pos in hand. */
126 var $x; /* When played the X position on the table of the owner. */
127 var $y; /* When played the Y position on the table of the owner. */
129 function Card($value, $stat, $owner)
131 $this->value = $value;
132 $this->stat = $stat; // Card stat
133 $this->owner = $owner;
136 function assign($stat,$owner)
138 $this->stat = $stat; // Card stat
139 $this->owner = $owner;
142 function setpos($pos)
149 $this->stat = 'table'; // Card stat
154 function take($newown)
156 $this->stat = 'take'; // Card stat
157 $this->owner = $newown;
175 var $points; // points array
176 var $points_n; // number of row of points
200 if (($thiz =& new Table()) == FALSE)
203 $thiz->player = array();
206 $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
207 $thiz->asta_pla_n= -1;
208 $thiz->asta_card = -1;
209 $thiz->asta_pnt = -1;
211 $thiz->points = array( );
213 $thiz->total = array( 0, 0, 0, 0, 0);
214 $thiz->asta_win = -1;
215 $thiz->briscola = -1;
218 $thiz->old_reason = "";
219 $thiz->old_asta_pnt = -1;
222 $thiz->old_friend = -1;
224 $thiz->table_token = "";
225 $thiz->table_start = 0;
230 function &clone(&$from)
234 if (($thiz =& new Table()) == FALSE)
237 $thiz->player = array();
238 for ($i = 0 ; $i < $from->player_n ; $i++)
239 $thiz->player[$i] = $from->player[$i];
240 $thiz->player_n = $from->player_n;
241 $thiz->card = $from->card;
242 $thiz->mazzo = $from->mazzo; // REVIEW
243 $thiz->gstart = $from->gstart;
244 $thiz->turn = $from->turn;
246 $thiz->asta_pla = $from->asta_pla;
247 $thiz->asta_pla_n = $from->asta_pla_n;
248 $thiz->asta_card = $from->asta_card;
249 $thiz->asta_pnt = $from->asta_pnt;
251 $thiz->mult = $from->mult;
252 $thiz->points = $from->points;
253 $thiz->points_n = $from->points_n;
254 $thiz->total = $from->total;
256 $thiz->asta_win = $from->asta_win;
257 $thiz->briscola = $from->briscola;
258 $thiz->friend = $from->friend;
260 $thiz->old_reason = $from->old_reason;
261 $thiz->old_asta_pnt = $from->old_asta_pnt;
262 $thiz->old_pnt = $from->old_pnt;
263 $thiz->old_win = $from->old_win;
264 $thiz->old_friend = $from->old_friend;
266 $thiz->table_token = $from->table_token;
267 $thiz->table_start = $from->table_start;
272 function &spawn(&$from)
276 if (($thiz =& new Table()) == FALSE)
279 $thiz->player_n = $from->player_n;
280 $thiz->card = &$thiz->bunch_create();
281 $thiz->mazzo = $from->mazzo;
282 $thiz->gstart = $from->gstart;
283 $thiz->turn = $from->turn;
285 $thiz->asta_pla = $from->asta_pla;
286 $thiz->asta_pla_n = $from->asta_pla_n;
287 $thiz->asta_card = $from->asta_card;
288 $thiz->asta_pnt = $from->asta_pnt;
290 $thiz->mult = $from->mult;
291 $thiz->points = $from->points;
292 $thiz->points_n = $from->points_n;
293 $thiz->total = $from->total;
295 $thiz->asta_win = $from->asta_win;
296 $thiz->briscola = $from->briscola;
297 $thiz->friend = $from->friend;
299 $thiz->old_reason = $from->old_reason;
300 $thiz->old_asta_pnt = $from->old_asta_pnt;
301 $thiz->old_pnt = $from->old_pnt;
302 $thiz->old_win = $from->old_win;
303 $thiz->old_friend = $from->old_friend;
305 // players are rearranged in an dedicated array
306 $thiz->player = array();
307 for ($i = 0 ; $i < $from->player_n ; $i++)
308 $thiz->player[$i] = $i;
310 $thiz->table_token = $from->table_token;
311 $thiz->table_start = $from->table_start;
316 function &bunch_create()
320 for ($i = 0 ; $i < 40 ; $i++) {
321 $ret[$i] =& new Card($i, 'bunch', 'no_owner');
328 function bunch_make()
330 $ct = array(0,0,0,0,0);
332 mt_srand(make_seed());
334 for ($i = 39 ; $i >= 0 ; $i--)
337 for ($i = 39 ; $i >= 0 ; $i--) {
341 log_main("RND ZERO");
346 $this->card[$id]->assign('hand', $owner);
348 $rest[$rn] = $rest[$i];
349 // $pubbpos[$rn2] = $pubbpos[$i];
353 function init(&$userarr)
355 $this->mazzo = rand(0,PLAYERS_N-1);
359 $this->old_reason = "";
360 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
361 $this->total[$i] = 0;
362 $user_cur = &$userarr[$this->player[$i]];
363 $user_cur->exitislock = TRUE;
366 log_main("table::init: ci siamo");
369 function game_init(&$userarr)
373 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
377 $this->asta_pla_n = PLAYERS_N;
378 $this->asta_card = -1;
379 $this->asta_pnt = 60;
380 $this->asta_win = -1;
381 $this->briscola = -1;
385 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
386 $this->asta_pla[$i] = TRUE;
387 $user_cur = &$userarr[$this->player[$i]];
388 $user_cur->subst = 'asta';
389 $user_cur->asta_card = -2;
390 $user_cur->asta_pnt = -1;
391 $user_cur->handpt = $this->hand_points($i);
392 // SEE function calculate_points(&$table)
398 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
401 function getPlayer($idx)
403 return ($this->player[$idx]);
406 function setPlayer($idx, $player)
408 $this->player[$idx] = $player;
411 function user_add($idx)
413 $this->player[$this->player_n] = $idx;
416 return ($this->player_n - 1);
419 function user_rem(&$room, &$user)
421 $tabpos = $user->table_pos;
423 /* verifico la consistenza dei dati */
424 if ($room->user[$this->player[$tabpos]] == $user) {
426 /* aggiorna l'array dei giocatori al tavolo. */
427 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
428 $this->player[$i] = $this->player[$i+1];
429 $user_cur = &$room->user[$this->player[$i]];
430 $user_cur->table_pos = $i;
435 log_main("INCONSISTENCY ON TABLE.");
439 function hand_points($idx)
441 GLOBAL $G_all_points;
445 for ($i = 0 ; $i < 40 ; $i++) {
446 if ($this->card[$i]->owner != $idx)
449 $ctt = $this->card[$i]->value % 10;
450 $tot += $G_all_points[$ctt];
456 function exitlock_show(&$userarr, $table_pos)
458 $ct = $this->exitlock_calc(&$userarr, $table_pos);
460 $ret = sprintf('exitlock_show(%d, %s);', $ct,
461 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
465 function exitlock_calc(&$userarr, $table_pos)
469 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
470 if ($userarr[$this->player[$i]]->exitislock == FALSE)
479 var $name; // name of the user
480 var $sess; // session of the user
481 var $ip; // ip of the user
482 var $lacc; // last access (for the cleanup)
483 var $laccwr; // last access (for the cleanup)
484 var $bantime; // timeout to temporary ban
485 var $stat; // status (outdoor, room, table, game, ...)
486 var $subst; // substatus for each status
487 var $step; // step of the current status
488 var $trans_step; // step to enable transition between pages (disable == -1)
489 var $comm; // commands array
492 var $handpt; // Total card points at the beginning of the current hand.
493 var $exitislock; // Player can exit from the table ?
494 var $table; // id of the current table (if in table state)
495 var $table_pos; // idx on the table
496 var $table_token;// token that identify a game on a table
497 var $the_end; // Flag to change the end of the session
499 var $chat_lst; // Last chat line
500 var $chattime; // Array of chat times
501 var $chat_cur; // Current chat line number
502 var $chat_ban; // Time for ban chat
503 var $chat_dlt; // Delta t for ban
507 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
510 if (($thiz =& new User()) == FALSE)
516 $thiz->lacc = time();
517 $thiz->laccwr = time();
520 $thiz->subst = $subst;
522 $thiz->trans_step = -1;
523 $thiz->comm = array();
524 $thiz->asta_card = -2;
525 $thiz->asta_pnt = -1;
527 $thiz->exitislock = TRUE;
529 $thiz->chattime = array_fill(0, CHAT_N, 0);
531 $thiz->chat_lst = "";
535 $thiz->table = $table;
536 $thiz->table_pos = -1;
537 $thiz->table_token = "";
542 function &clone(&$from)
546 if (($thiz =& new User()) == FALSE)
549 $thiz->name = $from->name;
550 $thiz->sess = $from->sess;
551 $thiz->ip = $from->ip;
552 $thiz->lacc = $from->lacc;
553 $thiz->laccwr = $from->laccwr;
554 $thiz->bantime = $from->bantime;
555 $thiz->stat = $from->stat;
556 $thiz->subst = $from->subst;
557 $thiz->step = $from->step;
558 $thiz->trans_step = $from->trans_step;
559 $thiz->comm = array();
561 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
562 for ($i = $i_start ; $i < $from->step ; $i++) {
564 $thiz->comm[$ii] = $from->comm[$ii];
566 $thiz->asta_card = $from->asta_card;
567 $thiz->asta_pnt = $from->asta_pnt;
568 $thiz->handpt = $from->handpt;
569 $thiz->exitislock = $from->exitislock;
571 $thiz->chattime = array();
572 for ($i = 0 ; $i < CHAT_N ; $i++)
573 $thiz->chattime[$i] = $from->chattime[$i];
574 $thiz->chat_cur = $from->chat_cur;
575 $thiz->chat_lst = $from->chat_lst;
576 $thiz->chat_ban = $from->chat_ban;
577 $thiz->chat_dlt = $from->chat_dlt;
579 $thiz->table = $from->table;
580 $thiz->table_pos = $from->table_pos;
581 $thiz->table_token = $from->table_token;
582 $thiz->the_end = $from->the_end;
587 function &spawn(&$from, $table, $table_pos)
591 if (($thiz =& new User()) == FALSE)
594 $thiz->name = $from->name;
595 $thiz->sess = $from->sess;
596 $thiz->ip = $from->ip;
597 $thiz->lacc = $from->lacc;
598 $thiz->laccwr = $from->laccwr;
599 $thiz->bantime = $from->bantime;
600 $thiz->stat = $from->stat;
601 $thiz->subst = $from->subst;
602 $thiz->step = $from->step;
603 $thiz->trans_step = $from->trans_step;
604 $thiz->comm = array();
607 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
608 for ($i = $i_start ; $i < $from->step ; $i++) {
609 log_wr("TRY PUSH:".$i);
611 $thiz->comm[$ii] = $from->comm[$ii];
614 $thiz->asta_card = $from->asta_card;
615 $thiz->asta_pnt = $from->asta_pnt;
616 $thiz->handpt = $from->handpt;
617 $thiz->exitislock = $from->exitislock;
618 $thiz->the_end = $from->the_end;
620 $thiz->chattime = array_fill(0, CHAT_N, 0);
622 $thiz->chat_lst = "";
626 $thiz->table = $table;
627 $thiz->table_pos = $table_pos;
628 $thiz->table_token = $from->table_token;
633 function stat_set($stat) {
634 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
635 $this->stat = "$stat";
638 if (validate_sess($this->sess)) {
639 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
640 fwrite($fp, sprintf("%s\n",$this->stat));
646 function step_set($step) {
650 if (validate_sess($this->sess) == FALSE)
652 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
654 fwrite($fp, pack("l",$this->step), 4);
663 function step_inc($delta = 1) {
664 $this->step += $delta;
666 if (validate_sess($this->sess)) {
667 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
668 fwrite($fp, pack("l",$this->step), 4);
678 $tmp_sess = $this->sess;
680 step_unproxy($tmp_sess);
682 while (array_pop($this->comm) != NULL);
684 $this->the_end = FALSE;
689 function step_get($sess) {
693 if (validate_sess($sess) == FALSE)
696 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
699 if (($s = fread($fp, 4)) == FALSE)
705 $arr = unpack('l', $s);
708 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
715 log_rd2("STEP_GET: return false ".$ct);
719 function step_unproxy($sess) {
720 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
721 @unlink(PROXY_PATH."/".$sess.".step");
728 var $comm; // commands for many people
729 var $step; // current step of the comm array
730 var $garbage_timeout;
734 $this->user = array();
735 $this->table = array();
737 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
738 $this->user[$i] =& User::create("", "");
741 for ($i = 0 ; $i < TABLES_N ; $i++)
742 $this->table[$i] =& Table::create();
743 $this->garbage_timeout = 0;
746 function garbage_manager($force)
750 log_rd2("garbage_manager START");
752 /* Garbage collector degli utenti in timeout */
754 if ($force || $this->garbage_timeout < $curtime) {
756 // Before all align times with table timeout
757 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
758 $table_cur =& $this->table[$table_idx];
759 // if the table is complete and exists its shared mem we get the info about users lacc
761 if ($table_cur->player_n == PLAYERS_N) {
762 log_main("PLAYERS == N TABLE ".$table_idx);
764 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
765 log_main("bin5 lock data success");
767 $no_recovery = FALSE;
768 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
769 if ($table_cur->table_token != $bri->table_token) {
770 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
771 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
781 log_main("garbage_manager: bri loaded successfully.");
782 $bri->garbage_manager(TRUE);
784 $bri_table = &$bri->table[0];
786 // is the end of the table
787 if ($bri->the_end == TRUE) {
789 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
791 log_main("garbage_manager: INSIDE THE END.");
793 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
794 // stat must be "table" by definition
795 $user_cur =& $this->user[$table_cur->player[$i]];
796 $bri_user =& $bri->user[$i];
798 $user_cur->subst = $bri_user->subst;
799 $user_cur->step = $bri_user->step;
800 $user_cur->lacc = $bri_user->lacc;
801 $user_cur->laccwr = $bri_user->lacc;
802 $user_cur->bantime = $bri_user->bantime;
805 $this->room_join_wakeup(&$user_cur, FALSE, 0);
806 $table_cur->table_token = "";
808 Briskin5::destroy_data($table_idx);
811 log_main("gm:: save_data");
813 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
814 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
817 Briskin5::save_data(&$bri);
819 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
820 else if ($no_recovery == FALSE) {
821 log_crit("ERROR: table ".$table_idx." unrecoverable join");
823 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
824 $user_cur = &$this->user[$table_cur->player[$i]];
825 $user_cur->subst = "shutdowner";
826 $user_cur->step_inc();
828 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
829 $ret .= "gst.st = ".($user_cur->step+1)."; ";
830 $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);
831 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
832 $user_cur->step_inc();
835 $this->room_join_wakeup(&$user_cur, TRUE, -2);
836 $table_cur->table_token = "";
839 Briskin5::unlock_data($sem);
841 } // if ($table_cur->player_n == PLAYERS_N) {
842 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
844 log_rd2("out new loop.");
846 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
847 $user_cur = &$this->user[$i];
849 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
851 if ($user_cur->sess == "")
854 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
855 // Auto logout dell'utente
856 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
858 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
859 log_auth($user_cur->sess, "Autologout session.");
862 /* factorized with ->reset()
863 $tmp_sess = $user_cur->sess;
864 $user_cur->sess = "";
865 step_unproxy($tmp_sess);
866 $user_cur->name = "";
867 while (array_pop($user_cur->comm) != NULL);
869 $user_cur->the_end = FALSE;
872 log_rd2("AUTO LOGOUT.");
873 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
874 $this->room_wakeup(&$user_cur);
875 else if ($user_cur->subst == 'standup')
876 $this->room_outstandup(&$user_cur);
878 log_rd2("LOGOUT FROM WHAT ???");
882 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
883 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
884 $this->room_wakeup(&$user_cur);
885 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
886 $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);
887 $user_cur->step_inc();
891 log_rd2("GARBAGE UPDATED!");
893 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
901 function room_wakeup(&$user)
903 $table_idx = $user->table;
904 $table = &$this->table[$table_idx];
906 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
910 $from_table = ($user->stat == "table");
912 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
914 for ($i = 0 ; $i < $table->player_n ; $i++) {
915 $user_cur = &$this->user[$table->player[$i]];
916 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
918 if ($user_cur != $user) {
919 $user_cur->stat_set("room");
920 $user_cur->subst = "sitdown";
921 $user_cur->laccwr = $curtime;
923 else if ($user->sess != "") {
924 $user_cur->stat_set("room");
925 $user_cur->subst = "standup";
926 $user_cur->laccwr = $curtime;
927 $user_cur->table = -1;
932 $user->stat_set("room");
933 $user->subst = "standup";
934 $user->laccwr = $curtime;
936 /* aggiorna l'array dei giocatori al tavolo. */
937 $table->user_rem(&$this, &$user);
939 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
940 $user_cur = &$this->user[$i];
941 if ($user_cur->sess == '' || $user_cur->stat != 'room')
944 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
946 $ret = "gst.st = ".($user_cur->step+1)."; ";
947 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
948 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; document.location.assign("index.php");|';
949 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
950 log_main("DOCUMENT.index.php: from table");
952 else if ($user_cur->stat == "room") {
953 log_main("DOCUMENT.index.php: from table");
955 $ret .= table_content($this, $user_cur, $table_idx);
956 $ret .= standup_content($this, $user_cur);
958 $act_content = table_act_content(FALSE, 0, $table_idx, $user->table);
959 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
962 if ($user_cur == $user) {
963 // set the new status
964 $ret .= 'subst = "standup"; ';
965 // clean the action buttons in other tables
966 for ($e = 0 ; $e < TABLES_N ; $e++) {
967 if ($this->table[$e]->player_n < PLAYERS_N)
968 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
972 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
973 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
976 log_wr("ROOM_WAKEUP: ".$ret);
977 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
978 $user_cur->step_inc();
982 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
984 $table_idx = $user->table;
985 $table = &$this->table[$table_idx];
987 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
994 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
996 for ($i = 0 ; $i < $table->player_n ; $i++) {
997 $user_cur = &$this->user[$table->player[$i]];
998 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
999 if ($user_cur->sess != "") {
1000 if ($update_lacc == TRUE) {
1001 $user_cur->laccwr = $curtime;
1003 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1004 if ($user_cur->subst == "shutdowned") {
1005 $user_cur->stat_set("room");
1006 $user_cur->subst = "sitdown";
1008 else if ($user_cur->subst == "shutdowner") {
1009 $user_cur->stat_set("room");
1010 $user_cur->subst = "standup";
1011 $user_cur->table = -1;
1012 $user_wup[$user_wup_n++] = &$user_cur;
1014 $user_tab[$user_tab_n++] = &$user_cur;
1018 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1019 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1021 /* aggiorna l'array dei giocatori al tavolo. */
1023 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1024 log_main("START LOOP");
1025 $user_cur = &$this->user[$i];
1026 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1027 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1032 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1034 $ret = "gst.st = ".($user_cur->step+1)."; ";
1035 if ($user_cur->stat == "room") {
1036 log_main("DOCUMENT.index.php from table");
1038 $ret .= table_content($this, $user_cur, $table_idx);
1039 $ret .= standup_content($this, $user_cur);
1041 $act_content = table_act_content(FALSE, 0, $table_idx, $user_cur->table);
1042 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1044 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1045 if ($user_cur == $user_tab[$tab_idx])
1048 // for users that wakeup the room will be reconstructed by index_rd.php
1049 if ($tab_idx < $user_tab_n) {
1050 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1052 // ARRAY_POP DISABLED
1053 // if ($trans_delta == 0)
1054 // while (array_pop($user_cur->comm) != NULL);
1056 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1057 $user_cur->comm[$user_cur->step % COMM_N] = "";
1058 $user_cur->step_inc();
1059 $user_cur->comm[$user_cur->step % COMM_N] = show_room(&$this, ($user_cur->step + 1), &$user_cur);
1060 $user_cur->step_inc();
1061 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1065 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1067 log_main("JOIN_WAKEUP more");
1068 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
1069 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1070 log_main("JOIN_WAKEUP end more");
1072 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1073 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1074 $user_cur->step_inc();
1078 function room_outstandup(&$user)
1080 $this->room_sitdown(&$user, -1);
1083 function table_update(&$user)
1085 log_main("table_update: pre - USER: ".$user->name);
1087 $table_idx = $user->table;
1089 if ($table_idx > -1)
1090 $table = &$this->table[$table_idx];
1092 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1094 $user_cur = &$this->user[$i];
1095 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1098 $ret = "gst.st = ".($user_cur->step+1)."; ";
1099 if ($table_idx > -1)
1100 $ret .= table_content($this, $user_cur, $table_idx);
1102 if ($user_cur == $user) {
1103 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
1105 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1106 $user_cur->step_inc();
1109 log_main("table_update: post");
1112 function room_sitdown(&$user, $table_idx)
1114 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1116 if ($table_idx > -1)
1117 $table = &$this->table[$table_idx];
1119 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1121 $user_cur = &$this->user[$i];
1122 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1125 $ret = "gst.st = ".($user_cur->step+1)."; ";
1126 if ($table_idx > -1)
1127 $ret .= table_content($this, $user_cur, $table_idx);
1128 $ret .= standup_content($this, $user_cur);
1130 if ($user_cur == $user) {
1131 $ret .= 'subst = "sitdown"; ';
1132 // clean the action buttons in other tables
1133 for ($e = 0 ; $e < TABLES_N ; $e++) {
1134 $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
1135 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
1138 else if ($table_idx > -1) {
1139 if ($table->player_n == PLAYERS_N) {
1140 $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
1141 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1144 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1145 $user_cur->step_inc();
1149 function chatt_send(&$user, $mesg)
1153 if ($user->stat == 'table') {
1154 $table = &$this->table[$user->table];
1157 $user_mesg = substr($mesg,6);
1161 $dt = date("H:i ", $timecur);
1162 if (strncmp($user_mesg, "/nick ", 6) == 0) {
1163 log_main("chatt_send BEGIN");
1165 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
1166 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1167 $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));
1172 $user_mesg = "COMMAND ".$user_mesg;
1175 // update local graph
1176 // update remote graphs
1177 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1178 $user_cur = &$this->user[$i];
1179 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1180 if ($user_cur->sess == '')
1182 if ($user_cur->name == $name_new) {
1183 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1184 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
1189 if ($i == MAX_PLAYERS) {
1190 $user->name = $name_new;
1192 log_main("chatt_send start set");
1195 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1196 log_main("chatt_send set loop");
1198 $user_cur = &$this->user[$i];
1199 if ($user_cur->sess == '')
1201 if ($user_cur->stat == 'room') {
1202 if ($user->stat == 'room' && $user->subst == 'standup') {
1203 $this->standup_update(&$user);
1205 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
1206 $user->stat == 'table') {
1207 log_main("chatt_send pre table update");
1209 $this->table_update(&$user);
1211 log_main("chatt_send post table update");
1214 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
1215 $table = &$this->table[$user->table];
1217 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1218 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
1219 xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
1220 xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
1221 xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
1222 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
1223 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
1224 if ($user_cur == $user)
1225 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
1226 xcape($user->name,ENT_COMPAT,"UTF-8"));
1227 $user_cur->step_inc();
1233 if ($timecur < ($user->chat_ban + $user->chat_dlt)) {
1235 $user->chat_dlt = $user->chat_dlt * 2;
1236 if ($user->chat_dlt > 120)
1237 $user->chat_dlt = 120;
1239 else if ($user->chat_lst == $user_mesg)
1241 else if ($timecur - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1242 $user->chat_ban = $timecur;
1243 $user->chat_dlt = 5;
1247 $user->chat_ban = 0;
1248 $user->chat_dlt = 0;
1251 for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
1252 if ($user->stat == 'room') {
1253 $user_cur = &$this->user[$i];
1254 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1258 $user_cur = &$this->user[$table->player[$i]];
1260 if ($only_you && $user_cur != $user)
1263 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1264 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
1265 $dt.xcape($user->name), xcape($user_mesg));
1266 $user_cur->step_inc();
1268 log_legal($timecur, $user->sess, $user->name,
1269 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
1271 $user->chat_lst = "$user_mesg";
1272 $user->chattime[$user->chat_cur % CHAT_N] = $timecur;
1277 function &get_user($sess, &$idx)
1279 GLOBAL $PHP_SELF, $G_false;
1281 if (validate_sess($sess)) {
1282 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1283 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1286 $ret = &$this->user[$i];
1290 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1291 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1292 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1295 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1302 * function &add_user(&$room, &$sess, &$idx, $name, $ip)
1305 * if ($idx != -1 && ret == FALSE) => duplicated nick
1306 * if ($idx == -2 && ret == FALSE) => invalid name
1307 * if ($idx == -1 && ret == FALSE) => no space left
1308 * if (ret == TRUE) => SUCCESS
1310 function &add_user(&$sess, &$idx, $name, $ip)
1317 if (($name_new = validate_name($name)) == FALSE) {
1322 log_auth("XXX", sprintf("ARRIVA: [%s]", $sess));
1323 if (validate_sess($sess) == FALSE)
1326 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1328 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1332 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1335 if (strcmp($this->user[$i]->name, $name_new) == 0) {
1343 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1345 if ($idx != -1 && $i == MAX_PLAYERS) {
1349 $this->user[$idx]->sess = uniqid("");
1350 $sess = $this->user[$idx]->sess;
1354 $this->user[$idx]->sess = $sess;
1356 $this->user[$idx]->name = $name_new;
1357 $this->user[$idx]->stat_set("room");
1358 $this->user[$idx]->step_set(0);
1359 while (array_pop($this->user[$idx]->comm) != NULL);
1360 $this->user[$idx]->subst = "standup";
1361 $this->user[$idx]->lacc = $curtime;
1362 $this->user[$idx]->laccwr = $curtime;
1363 $this->user[$idx]->bantime = 0;
1364 $this->user[$idx]->ip = $ip;
1365 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1367 return ($this->user[$idx]);
1373 function standup_update(&$user)
1375 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1376 $user_cur = &$this->user[$i];
1377 if ($user_cur->sess == '')
1380 log_main("STANDUP START: ".$user_cur->stat);
1382 if ($user_cur->stat == 'room') {
1383 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($this, $user_cur);
1384 if ($user_cur == $user)
1385 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
1387 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1389 $user_cur->step_inc();
1395 function &init_data()
1397 $room =& new Room();
1403 function &load_data()
1405 GLOBAL $G_false, $sess;
1408 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1409 log_main("ftok failed");
1414 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1415 log_main("shmop_open failed");
1419 $shm_sz = SHM_DIMS_MIN;
1421 if ($shm = shm_attach($tok, $shm_sz)) {
1422 $room = @shm_get_var($shm, $tok);
1424 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1426 log_only("bri count ".count($room));
1428 if ($room == FALSE) {
1429 log_only("INIT MAIN DATA");
1431 $room =& Room::init_data();
1432 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1433 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1434 log_only(serialize($room));
1437 $room->shm_sz = $shm_sz;
1452 function save_data(&$room)
1461 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1464 while ($room->shm_sz < SHM_DIMS_MAX) {
1465 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1468 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1469 if (shm_put_var($shm, $tok, $room) != FALSE) {
1473 if (shm_remove($shm) === FALSE) {
1474 log_only("REMOVE FALLITA");
1478 $room->shm_sz += SHM_DIMS_DLT;
1487 function lock_data()
1491 // echo "LOCK: ".FTOK_PATH."/main";
1493 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1497 // echo "FTOK ".$tok."<br>";
1498 if (($res = sem_get($tok)) == FALSE) {
1499 echo "SEM_GET FAILED";
1502 if (sem_acquire($res)) {
1503 log_lock("LOCK room");
1510 function unlock_data($res)
1514 log_lock("UNLOCK room");
1516 return (sem_release($res));
1520 function make_seed()
1522 list($usec, $sec) = explode(' ', microtime());
1523 return (float) $sec + ((float) $usec * 100000);
1527 function log_only2($log) {
1530 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
1533 if (isset($sess) == FALSE)
1538 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
1541 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1542 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
1547 function log_crit($log) {
1550 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
1553 if (isset($sess) == FALSE)
1558 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
1561 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1562 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
1567 function log_only($log) {
1570 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
1573 if (isset($sess) == FALSE)
1578 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
1581 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1582 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
1587 function log_main($log) {
1590 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
1593 if (isset($sess) == FALSE)
1598 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
1601 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1602 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
1607 function log_rd($log) {
1610 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
1613 if (isset($sess) == FALSE)
1618 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
1621 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1622 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
1627 function log_rd2($log) {
1630 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
1633 if (isset($sess) == FALSE)
1638 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
1641 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1642 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
1647 function log_send($log) {
1650 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
1653 if (isset($sess) == FALSE)
1658 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
1661 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1662 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
1667 function log_lock($log) {
1670 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
1673 if (isset($sess) == FALSE)
1678 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
1681 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1682 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
1687 function log_wr($log) {
1690 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
1693 if (isset($sess) == FALSE)
1698 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
1701 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1702 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
1707 function log_load($log) {
1710 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
1713 if (isset($sess) == FALSE)
1718 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
1721 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1722 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
1727 function log_auth($sess, $log) {
1728 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
1731 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
1734 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1735 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
1741 function log_legal($timecur, $sess, $name, $where, $mesg)
1745 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
1746 /* Unix time | session | nickname | IP | where was | mesg */
1747 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|\n", $timecur, $sess, $name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
1755 function lock_banlist()
1757 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
1761 if (($res = sem_get($tok)) == FALSE) {
1762 echo "SEM_GET FAILED";
1765 if (sem_acquire($res))
1771 function unlock_banlist($res)
1773 return (sem_release($res));
1776 function table_act_content($isstanding, $sitted, $table, $cur_table)
1781 if ($sitted < PLAYERS_N) {
1782 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
1786 if ($table == $cur_table)
1787 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
1794 function table_content($room, $user, $table_idx)
1800 // Si possono usare i dati nella classe table
1803 $sess = $user->sess;
1804 $table = &$room->table[$table_idx];
1806 if ($user->stat != 'room')
1809 for ($i = 0 ; $i < $table->player_n ; $i++) {
1810 $user_cur = &$room->user[$table->player[$i]];
1812 if ($user_cur == $user)
1813 { $hilion = "<b>"; $hilioff = "</b>"; }
1815 { $hilion = ""; $hilioff = ""; }
1817 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
1819 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1822 for ( ; $i < PLAYERS_N ; $i++)
1826 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1831 function standup_content(&$room, $user)
1836 if ($user->stat != 'room')
1839 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1840 if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "")
1845 $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1847 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1848 if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "")
1852 if ($room->user[$e]->subst == "standup") {
1853 if (($ct % 4) == 0) {
1856 if ($room->user[$e] == $user)
1857 { $hilion = "<b>"; $hilioff = "</b>"; }
1859 { $hilion = ""; $hilioff = ""; }
1861 $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($room->user[$e]->name), $hilioff);
1862 if (($ct % 4) == 3) {
1863 $content .= '</tr>';
1868 $content .= '</table>';
1870 $content2 = '<input class=\\"button\\" name=\\"logout\\" value=\\"Esco.\\" onclick=\\"window.onunload = null; act_logout();\\" type=\\"button\\">';
1871 $ret .= sprintf('$("standup").innerHTML = "%s"; $("esco").innerHTML = "%s";',
1872 $content, $content2);
1878 function show_notify($text, $tout, $butt, $w, $h)
1880 log_main("SHOW_NOTIFY: ".$text);
1881 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
1884 function briscola_show($room, $table, $user)
1889 if ($table->asta_card == 9)
1890 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
1892 /* text of caller cell */
1893 if ($user->table_pos == $table->asta_win)
1894 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
1896 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
1897 xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd);
1899 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1901 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1902 $ret .= sprintf('$("caller").style.visibility = "visible";');
1903 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1904 $ret .= sprintf('$("astalascio").style.visibility = "";');
1905 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1906 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1912 function game_result($asta_pnt, $pnt)
1914 if ($asta_pnt == 61) {
1917 else if ($pnt == 60)
1923 if ($pnt >= $asta_pnt)
1930 function multoval($mult)
1934 else if ($mult == 4)
1935 return ("quadruplo");
1937 return (sprintf("%d-plo", $mult));
1940 function show_table_info(&$room, &$table, $table_pos)
1943 $user = &$room->user[$table->player[$table_pos]];
1945 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1946 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1949 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1950 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($room->user[$table->player[$i]]->name));
1951 $noty .= sprintf("</tr>");
1954 log_main("show_table_info: pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1956 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1957 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1958 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1959 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1964 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1965 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1966 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1967 $noty .= "</tr></table>";
1969 if ($table->old_reason != "") {
1970 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1973 if ($table->old_win != -1) {
1974 $win = $table->player[$table->old_win];
1975 $fri = $table->player[$table->old_friend];
1977 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1980 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
1981 xcape($room->user[$win]->name),
1982 xcape($room->user[$fri]->name));
1983 if ($table->old_pnt == 120) {
1984 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
1987 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
1988 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1989 'più di 60'), $table->old_pnt,
1990 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1994 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
1995 xcape($room->user[$win]->name));
1996 if ($table->old_pnt == 120) {
1997 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
2000 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
2001 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
2002 'più di 60'), $table->old_pnt,
2003 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
2007 if ($table->mazzo == $table_pos)
2008 $noty .= "Fai <b>tu</b> il mazzo,";
2010 $unam = xcape($room->user[$table->player[$table->mazzo]]->name);
2011 $noty .= "Il mazzo a <b>$unam</b>,";
2014 if ($user->subst == 'asta') {
2015 if ($table->asta_win == -1) // auction case
2016 $curplayer = $table->gstart % PLAYERS_N;
2018 $curplayer = $table->asta_win;
2020 else if ($user->subst == 'game') {
2021 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
2025 if ($curplayer == $table_pos) {
2026 $noty .= " tocca a <b>te</b> giocare.";
2029 $unam = xcape($room->user[$table->player[$curplayer]]->name);
2030 $noty .= " tocca a <b>$unam</b> giocare.";
2033 if ($table->mult > 1) {
2034 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
2036 $noty .= "<hr><br>";
2038 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
2043 function root_wellcome($user)
2045 GLOBAL $root_wellarr;
2048 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2049 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $root_wellarr[$i]));
2054 function table_wellcome($user)
2056 GLOBAL $table_wellarr;
2059 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
2060 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $table_wellarr[$i]));
2065 function show_room(&$room, $user_step, &$user)
2067 log_main("show_room: username: ".$user->name);
2070 $ret = sprintf('gst.st = %d;', $user_step);
2071 $ret .= sprintf('stat = "%s";', $user->stat);
2073 $ret .= root_wellcome($user);
2074 $ret .= sprintf('subst = "%s";', $user->subst);
2075 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
2076 for ($i = 0 ; $i < TABLES_N ; $i++) {
2077 $ret .= table_content($room, $user, $i);
2078 $act_content = table_act_content(($user->subst == 'standup'),
2079 $room->table[$i]->player_n, $i, $user->table);
2080 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
2082 $ret .= standup_content($room, $user);
2090 is_transition (is from room to table ?)
2091 is_again (is another game)
2093 Examples of $is_transition, $is_again:
2094 from reload of the page: FALSE, FALSE
2095 from sitdown in room: TRUE, FALSE
2096 from table: asta cmd e tutti passano: TRUE, TRUE
2097 from table: fine partita: TRUE, TRUE
2099 function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
2101 $table_idx = $user->table;
2102 $table = &$room->table[$table_idx];
2103 $table_pos = $user->table_pos;
2105 $ret = "table_init();";
2106 $ret .= $table->exitlock_show(&$room->user, $table_pos);
2108 /* GENERAL STATUS */
2109 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
2110 $sendstep, $user->stat, $user->subst, $table_pos);
2112 log_rd(sprintf( 'SHOW_TABLE: gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
2113 $sendstep, $user->stat, $user->subst, $table_pos));
2116 $ret .= "background_set();";
2119 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
2120 $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
2121 xcape($room->user[$table->player[($table_pos)%PLAYERS_N]]->name),
2122 xcape($room->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
2123 xcape($room->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
2124 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
2125 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
2127 /* NOTIFY FOR THE CARD MAKER */
2128 if ($is_transition) { // && $user->subst == "asta" superfluo
2129 $ret .= show_table_info(&$room, &$table, $table_pos);
2132 $ret .= table_wellcome($user);
2134 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
2135 $ret .= playsound("cow.mp3");
2140 if ($is_transition) { // && $user->subst == "asta" superfluo
2143 for ($i = 0 ; $i < 8 ; $i++) {
2144 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
2146 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
2147 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
2153 log_rd("O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
2155 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
2156 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
2157 $table->card[$o]->value : -1),
2158 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
2163 $taked = array(0,0,0,0,0);
2164 $inhand = array(0,0,0,0,0);
2165 $ontabl = array(-1,-1,-1,-1,-1);
2168 for ($i = 0 ; $i < 40 ; $i++) {
2169 if ($table->card[$i]->stat == 'hand') {
2170 if ($table->card[$i]->owner == $table_pos) {
2171 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
2173 $inhand[$table->card[$i]->owner]++;
2175 else if ($table->card[$i]->stat == 'take') {
2176 log_main("Card taked: ".$table->card[$i]->value."OWN: ".$table->card[$i]->owner);
2177 $taked[$table->card[$i]->owner]++;
2179 else if ($table->card[$i]->stat == 'table') {
2180 $ontabl[$table->card[$i]->owner] = $i;
2184 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2185 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
2187 log_main("Stat table: ".$logg);
2189 /* Set ours cards. */
2191 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
2192 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
2193 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
2194 $oursarg .= ($i == 0 ? "" : ", ")."-1";
2195 $ret .= sprintf('card_setours(%s);', $oursarg);
2197 /* Dispose all cards */
2198 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2199 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
2200 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
2201 $inhand[$i], $taked[$i]);
2203 if ($ontabl[$i] != -1) {
2204 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
2205 $table->card[$ontabl[$i]]->value,
2206 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
2212 if ($user->subst == 'asta') {
2214 /* show users auction status */
2216 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2217 $user_cur = &$room->user[$table->player[$i]];
2218 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
2219 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
2222 $showst .= ",-2,-2";
2223 $ret .= sprintf('show_astat(%s);', $showst);
2225 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
2226 /* show card chooser */
2227 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
2232 if ($table_pos == ($table->gstart % PLAYERS_N) &&
2233 $table->asta_win == -1)
2234 $ret .= sprintf('dispose_asta(%d,%d, %s);',
2235 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
2237 $ret .= sprintf('dispose_asta(%d,%d, %s);',
2238 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
2242 if ($table->asta_win == -1) { // auction case
2243 if ($table_pos == ($table->gstart % PLAYERS_N))
2244 $ret .= "remark_on();";
2246 $ret .= "remark_off();";
2248 else { // chooseed case
2249 if ($table_pos == $table->asta_win)
2250 $ret .= "remark_on();";
2252 $ret .= "remark_off();";
2255 else if ($user->subst == 'game') {
2257 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
2258 $ret .= "is_my_time = true; remark_on();";
2260 $ret .= "remark_off();";
2262 /* WHO CALL AND WATH */
2263 $ret .= briscola_show($room, $table, $user);
2267 } // end function show_table(...
2269 function calculate_winner(&$table)
2276 $cur_seed = $table->briscola - ($table->briscola % 10);
2278 for ($i = 0 ; $i < 40 ; $i++) {
2279 if ($table->card[$i]->stat != "table")
2282 log_wr(sprintf("Card On table: [%d]", $i));
2284 $v = $table->card[$i]->value;
2285 $ontab[$table->card[$i]->owner] = $v;
2286 $ontid[$table->card[$i]->owner] = $i;
2287 /* se briscola setto il flag */
2288 if (($v - ($v % 10)) == $cur_seed)
2292 if ($briontab == FALSE) {
2293 $cur_win = $table->gstart;
2294 $cur_val = $ontab[$cur_win];
2295 $cur_seed = $cur_val - ($cur_val % 10);
2298 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2299 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
2300 if ($ontab[$i] < $cur_val) {
2301 $cur_val = $ontab[$i];
2307 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2308 $table->card[$ontid[$i]]->owner = $cur_win;
2309 $table->card[$ontid[$i]]->stat = "take"; // Card stat
2314 function calculate_points(&$table)
2316 GLOBAL $G_all_points;
2320 if ($table->asta_pnt == 60)
2321 $table->asta_pnt = 61;
2323 $table->old_reason = "";
2324 $table->old_win = $table->asta_win;
2325 $table->old_friend = $table->friend;
2326 $table->old_asta_pnt = $table->asta_pnt;
2328 for ($i = 0 ; $i < 40 ; $i++) {
2329 $ctt = $table->card[$i]->value % 10;
2330 $own = $table->card[$i]->owner;
2331 if ($own == $table->asta_win || $own == $table->friend)
2332 $pro += $G_all_points[$ctt];
2335 log_wr(sprintf("PRO: [%d]", $pro));
2338 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
2339 $table->points[$table->points_n % MAX_POINTS] = array();
2340 for ($i = 0 ; $i < PLAYERS_N ; $i++)
2341 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
2343 $table->old_pnt = $pro;
2349 if ($pro >= $table->asta_pnt)
2354 $table->points[$table->points_n % MAX_POINTS] = array();
2355 for ($i = 0 ; $i < 5 ; $i++) {
2356 if ($i == $table->asta_win)
2357 $pt = ($i == $table->friend ? 4 : 2);
2358 else if ($i == $table->friend)
2363 log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
2365 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
2367 log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
2369 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
2370 $table->total[$i] += $pt;
2373 $table->old_pnt = $pro;
2377 function validate_sess($sess)
2379 if (strlen($sess) == SESS_LEN)
2385 function validate_name($name)
2387 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2389 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2391 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2398 function playsound($filename)
2400 return (sprintf('playsound("flasou", "%s");', $filename));
2403 function secstoword($secs)
2405 $mins = floor($secs / 60);
2408 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2411 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2416 function sharedmem_sz($tok)
2418 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2419 log_main("shmop_open failed");
2422 $shm_sz = shmop_size($shm_id);
2423 shmop_close($shm_id);
2425 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);