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 $DBASE = "$DOCUMENT_ROOT".dirname("$PHP_SELF");
70 require_once("$DBASE/".BRISK_CONF);
75 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
76 $G_brisk_version = "spawn-0.10.8";
78 $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: i proxy verranno riabilitati con i login - versione beta2.',
79 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' );
80 $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.');
84 <div style=\\"text-align: left; padding: 8px;\\">
85 <b>Descrizione</b><br>
86 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
87 <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>
88 <b>Configurazione del browser.</b><br>
89 Occorre abilitare i cookies.<br>
91 <b>Uso del sito</b><br>
92 Potete sedervi a un tavolo o rimanere in piedi.<br>
93 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
96 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>
97 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
98 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
99 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
100 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
101 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.
103 <dt><b>Comandi della chat</b>
104 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
105 <dd>.. to be continue ..
111 <div id=\\"header\\" class=\\"header\\">
112 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
113 briscola chiamata in salsa ajax
115 <br><b>version '.$G_brisk_version.'</b><br><br>
116 Copyright 2006-2007 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
121 $from = array ( '\\', '@', '|' );
122 $to = array ( '\\\\', '@', '¦' );
124 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
129 var $value; /* 0 - 39 card value */
130 var $stat; /* 'bunch', 'hand', 'table', 'take' */
131 var $owner; /* (table position 0-4) */
132 // var $pos; /* Pos in hand. */
133 var $x; /* When played the X position on the table of the owner. */
134 var $y; /* When played the Y position on the table of the owner. */
136 function Card($value, $stat, $owner)
138 $this->value = $value;
139 $this->stat = $stat; // Card stat
140 $this->owner = $owner;
143 function assign($stat,$owner)
145 $this->stat = $stat; // Card stat
146 $this->owner = $owner;
149 function setpos($pos)
156 $this->stat = 'table'; // Card stat
161 function take($newown)
163 $this->stat = 'take'; // Card stat
164 $this->owner = $newown;
182 var $points; // points array
183 var $points_n; // number of row of points
207 if (($thiz =& new Table()) == FALSE)
210 $thiz->player = array();
213 $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
214 $thiz->asta_pla_n= -1;
215 $thiz->asta_card = -1;
216 $thiz->asta_pnt = -1;
218 $thiz->points = array( );
220 $thiz->total = array( 0, 0, 0, 0, 0);
221 $thiz->asta_win = -1;
222 $thiz->briscola = -1;
225 $thiz->old_reason = "";
226 $thiz->old_asta_pnt = -1;
229 $thiz->old_friend = -1;
231 $thiz->table_token = "";
232 $thiz->table_start = 0;
237 function &clone(&$from)
241 if (($thiz =& new Table()) == FALSE)
244 $thiz->player = array();
245 for ($i = 0 ; $i < $from->player_n ; $i++)
246 $thiz->player[$i] = $from->player[$i];
247 $thiz->player_n = $from->player_n;
248 $thiz->card = $from->card;
249 $thiz->mazzo = $from->mazzo; // REVIEW
250 $thiz->gstart = $from->gstart;
251 $thiz->turn = $from->turn;
253 $thiz->asta_pla = $from->asta_pla;
254 $thiz->asta_pla_n = $from->asta_pla_n;
255 $thiz->asta_card = $from->asta_card;
256 $thiz->asta_pnt = $from->asta_pnt;
258 $thiz->mult = $from->mult;
259 $thiz->points = $from->points;
260 $thiz->points_n = $from->points_n;
261 $thiz->total = $from->total;
263 $thiz->asta_win = $from->asta_win;
264 $thiz->briscola = $from->briscola;
265 $thiz->friend = $from->friend;
267 $thiz->old_reason = $from->old_reason;
268 $thiz->old_asta_pnt = $from->old_asta_pnt;
269 $thiz->old_pnt = $from->old_pnt;
270 $thiz->old_win = $from->old_win;
271 $thiz->old_friend = $from->old_friend;
273 $thiz->table_token = $from->table_token;
274 $thiz->table_start = $from->table_start;
279 function &spawn(&$from)
283 if (($thiz =& new Table()) == FALSE)
286 $thiz->player_n = $from->player_n;
287 $thiz->card = &$thiz->bunch_create();
288 $thiz->mazzo = $from->mazzo;
289 $thiz->gstart = $from->gstart;
290 $thiz->turn = $from->turn;
292 $thiz->asta_pla = $from->asta_pla;
293 $thiz->asta_pla_n = $from->asta_pla_n;
294 $thiz->asta_card = $from->asta_card;
295 $thiz->asta_pnt = $from->asta_pnt;
297 $thiz->mult = $from->mult;
298 $thiz->points = $from->points;
299 $thiz->points_n = $from->points_n;
300 $thiz->total = $from->total;
302 $thiz->asta_win = $from->asta_win;
303 $thiz->briscola = $from->briscola;
304 $thiz->friend = $from->friend;
306 $thiz->old_reason = $from->old_reason;
307 $thiz->old_asta_pnt = $from->old_asta_pnt;
308 $thiz->old_pnt = $from->old_pnt;
309 $thiz->old_win = $from->old_win;
310 $thiz->old_friend = $from->old_friend;
312 // players are rearranged in an dedicated array
313 $thiz->player = array();
314 for ($i = 0 ; $i < $from->player_n ; $i++)
315 $thiz->player[$i] = $i;
317 $thiz->table_token = $from->table_token;
318 $thiz->table_start = $from->table_start;
323 function &bunch_create()
327 for ($i = 0 ; $i < 40 ; $i++) {
328 $ret[$i] =& new Card($i, 'bunch', 'no_owner');
335 function bunch_make()
337 $ct = array(0,0,0,0,0);
339 mt_srand(make_seed());
341 for ($i = 39 ; $i >= 0 ; $i--)
344 for ($i = 39 ; $i >= 0 ; $i--) {
348 log_main("RND ZERO");
353 $this->card[$id]->assign('hand', $owner);
355 $rest[$rn] = $rest[$i];
356 // $pubbpos[$rn2] = $pubbpos[$i];
360 function init(&$userarr)
362 $this->mazzo = rand(0,PLAYERS_N-1);
366 $this->old_reason = "";
367 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
368 $this->total[$i] = 0;
369 $user_cur = &$userarr[$this->player[$i]];
370 $user_cur->exitislock = TRUE;
373 log_main("table::init: ci siamo");
376 function game_init(&$userarr)
380 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
384 $this->asta_pla_n = PLAYERS_N;
385 $this->asta_card = -1;
386 $this->asta_pnt = 60;
387 $this->asta_win = -1;
388 $this->briscola = -1;
392 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
393 $this->asta_pla[$i] = TRUE;
394 $user_cur = &$userarr[$this->player[$i]];
395 $user_cur->subst = 'asta';
396 $user_cur->asta_card = -2;
397 $user_cur->asta_pnt = -1;
398 $user_cur->handpt = $this->hand_points($i);
399 // SEE function calculate_points(&$table)
405 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
408 function getPlayer($idx)
410 return ($this->player[$idx]);
413 function setPlayer($idx, $player)
415 $this->player[$idx] = $player;
418 function user_add($idx)
420 $this->player[$this->player_n] = $idx;
423 return ($this->player_n - 1);
426 function user_rem(&$room, &$user)
428 $tabpos = $user->table_pos;
430 /* verifico la consistenza dei dati */
431 if ($room->user[$this->player[$tabpos]] == $user) {
433 /* aggiorna l'array dei giocatori al tavolo. */
434 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
435 $this->player[$i] = $this->player[$i+1];
436 $user_cur = &$room->user[$this->player[$i]];
437 $user_cur->table_pos = $i;
442 log_main("INCONSISTENCY ON TABLE.");
446 function hand_points($idx)
448 GLOBAL $G_all_points;
452 for ($i = 0 ; $i < 40 ; $i++) {
453 if ($this->card[$i]->owner != $idx)
456 $ctt = $this->card[$i]->value % 10;
457 $tot += $G_all_points[$ctt];
463 function exitlock_show(&$userarr, $table_pos)
465 $ct = $this->exitlock_calc(&$userarr, $table_pos);
467 $ret = sprintf('exitlock_show(%d, %s);', $ct,
468 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
472 function exitlock_calc(&$userarr, $table_pos)
476 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
477 if ($userarr[$this->player[$i]]->exitislock == FALSE)
486 var $name; // name of the user
487 var $sess; // session of the user
488 var $ip; // ip of the user
489 var $lacc; // last access (for the cleanup)
490 var $laccwr; // last access (for the cleanup)
491 var $bantime; // timeout to temporary ban
492 var $stat; // status (outdoor, room, table, game, ...)
493 var $subst; // substatus for each status
494 var $step; // step of the current status
495 var $trans_step; // step to enable transition between pages (disable == -1)
496 var $comm; // commands array
499 var $handpt; // Total card points at the beginning of the current hand.
500 var $exitislock; // Player can exit from the table ?
501 var $table; // id of the current table (if in table state)
502 var $table_pos; // idx on the table
503 var $table_token;// token that identify a game on a table
504 var $the_end; // Flag to change the end of the session
506 var $chat_lst; // Last chat line
507 var $chattime; // Array of chat times
508 var $chat_cur; // Current chat line number
509 var $chat_ban; // Time for ban chat
510 var $chat_dlt; // Delta t for ban
514 function &create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
517 if (($thiz =& new User()) == FALSE)
523 $thiz->lacc = time();
524 $thiz->laccwr = time();
527 $thiz->subst = $subst;
529 $thiz->trans_step = -1;
530 $thiz->comm = array();
531 $thiz->asta_card = -2;
532 $thiz->asta_pnt = -1;
534 $thiz->exitislock = TRUE;
536 $thiz->chattime = array_fill(0, CHAT_N, 0);
538 $thiz->chat_lst = "";
542 $thiz->table = $table;
543 $thiz->table_pos = -1;
544 $thiz->table_token = "";
549 function &clone(&$from)
553 if (($thiz =& new User()) == FALSE)
556 $thiz->name = $from->name;
557 $thiz->sess = $from->sess;
558 $thiz->ip = $from->ip;
559 $thiz->lacc = $from->lacc;
560 $thiz->laccwr = $from->laccwr;
561 $thiz->bantime = $from->bantime;
562 $thiz->stat = $from->stat;
563 $thiz->subst = $from->subst;
564 $thiz->step = $from->step;
565 $thiz->trans_step = $from->trans_step;
566 $thiz->comm = array();
568 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
569 for ($i = $i_start ; $i < $from->step ; $i++) {
571 $thiz->comm[$ii] = $from->comm[$ii];
573 $thiz->asta_card = $from->asta_card;
574 $thiz->asta_pnt = $from->asta_pnt;
575 $thiz->handpt = $from->handpt;
576 $thiz->exitislock = $from->exitislock;
578 $thiz->chattime = array();
579 for ($i = 0 ; $i < CHAT_N ; $i++)
580 $thiz->chattime[$i] = $from->chattime[$i];
581 $thiz->chat_cur = $from->chat_cur;
582 $thiz->chat_lst = $from->chat_lst;
583 $thiz->chat_ban = $from->chat_ban;
584 $thiz->chat_dlt = $from->chat_dlt;
586 $thiz->table = $from->table;
587 $thiz->table_pos = $from->table_pos;
588 $thiz->table_token = $from->table_token;
589 $thiz->the_end = $from->the_end;
594 function &spawn(&$from, $table, $table_pos)
598 if (($thiz =& new User()) == FALSE)
601 $thiz->name = $from->name;
602 $thiz->sess = $from->sess;
603 $thiz->ip = $from->ip;
604 $thiz->lacc = $from->lacc;
605 $thiz->laccwr = $from->laccwr;
606 $thiz->bantime = $from->bantime;
607 $thiz->stat = $from->stat;
608 $thiz->subst = $from->subst;
609 $thiz->step = $from->step;
610 $thiz->trans_step = $from->trans_step;
611 $thiz->comm = array();
614 $i_start = (1 > ($from->step - COMM_N) ? 1 : ($from->step - COMM_N));
615 for ($i = $i_start ; $i < $from->step ; $i++) {
616 log_wr("TRY PUSH:".$i);
618 $thiz->comm[$ii] = $from->comm[$ii];
621 $thiz->asta_card = $from->asta_card;
622 $thiz->asta_pnt = $from->asta_pnt;
623 $thiz->handpt = $from->handpt;
624 $thiz->exitislock = $from->exitislock;
625 $thiz->the_end = $from->the_end;
627 $thiz->chattime = array_fill(0, CHAT_N, 0);
629 $thiz->chat_lst = "";
633 $thiz->table = $table;
634 $thiz->table_pos = $table_pos;
635 $thiz->table_token = $from->table_token;
640 function stat_set($stat) {
641 log_main("sess: [".$this->sess. "] NEW STAT: [".$stat."]");
642 $this->stat = "$stat";
645 if (validate_sess($this->sess)) {
646 $fp = fopen(PROXY_PATH."/".$this->sess.".stat", 'w');
647 fwrite($fp, sprintf("%s\n",$this->stat));
653 function step_set($step) {
657 if (validate_sess($this->sess) == FALSE)
659 if (($fp = @fopen(PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
661 fwrite($fp, pack("l",$this->step), 4);
670 function step_inc($delta = 1) {
671 $this->step += $delta;
673 if (validate_sess($this->sess)) {
674 $fp = fopen(PROXY_PATH."/".$this->sess.".step", 'w');
675 fwrite($fp, pack("l",$this->step), 4);
685 $tmp_sess = $this->sess;
687 step_unproxy($tmp_sess);
689 while (array_pop($this->comm) != NULL);
691 $this->the_end = FALSE;
696 function step_get($sess) {
700 if (validate_sess($sess) == FALSE)
703 if (($fp = @fopen(PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
706 if (($s = fread($fp, 4)) == FALSE)
712 $arr = unpack('l', $s);
715 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
722 log_rd2("STEP_GET: return false ".$ct);
726 function step_unproxy($sess) {
727 log_rd2("UNPROXY: ".PROXY_PATH."/".$sess.".step");
728 @unlink(PROXY_PATH."/".$sess.".step");
735 var $comm; // commands for many people
736 var $step; // current step of the comm array
737 var $garbage_timeout;
741 $this->user = array();
742 $this->table = array();
744 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
745 $this->user[$i] =& User::create("", "");
748 for ($i = 0 ; $i < TABLES_N ; $i++)
749 $this->table[$i] =& Table::create();
750 $this->garbage_timeout = 0;
753 function garbage_manager($force)
757 log_rd2("garbage_manager START");
759 /* Garbage collector degli utenti in timeout */
761 if ($force || $this->garbage_timeout < $curtime) {
763 // Before all align times with table timeout
764 for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
765 $table_cur =& $this->table[$table_idx];
766 // if the table is complete and exists its shared mem we get the info about users lacc
768 if ($table_cur->player_n == PLAYERS_N) {
769 log_main("PLAYERS == N TABLE ".$table_idx);
771 if (($sem = Briskin5::lock_data($table_idx)) != FALSE) {
772 log_main("bin5 lock data success");
774 $no_recovery = FALSE;
775 if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
776 if ($table_cur->table_token != $bri->table_token) {
777 log_main("ERROR: not matching table_token. Room: ".$table_cur->table_token." Table: ".$bri->table_token);
778 log_main("ERROR: not matching table_start. Room: ".$table_cur->table_start." Table: ".$bri->table_start);
788 log_main("garbage_manager: bri loaded successfully.");
789 $bri->garbage_manager(TRUE);
791 $bri_table = &$bri->table[0];
793 // is the end of the table
794 if ($bri->the_end == TRUE) {
796 * DESTROY OF FINISHED TABLE && MOVE PLAYER TO ROOM AGAIN
798 log_main("garbage_manager: INSIDE THE END.");
800 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
801 // stat must be "table" by definition
802 $user_cur =& $this->user[$table_cur->player[$i]];
803 $bri_user =& $bri->user[$i];
805 $user_cur->subst = $bri_user->subst;
806 $user_cur->step = $bri_user->step;
807 $user_cur->lacc = $bri_user->lacc;
808 $user_cur->laccwr = $bri_user->lacc;
809 $user_cur->bantime = $bri_user->bantime;
812 $this->room_join_wakeup(&$user_cur, FALSE, 0);
813 $table_cur->table_token = "";
815 Briskin5::destroy_data($table_idx);
818 log_main("gm:: save_data");
820 for ($i = 0 ; $i < $bri_table->player_n ; $i++) {
821 $this->user[$table_cur->player[$i]]->lacc = $bri->user[$i]->lacc;
824 Briskin5::save_data(&$bri);
826 } // else if (($bri = &Briskin5::load_data($table_idx)) != FALSE) {
827 else if ($no_recovery == FALSE) {
828 log_crit("ERROR: table ".$table_idx." unrecoverable join");
830 for ($i = 0 ; $i < $table_cur->player_n ; $i++) {
831 $user_cur = &$this->user[$table_cur->player[$i]];
832 $user_cur->subst = "shutdowner";
833 $user_cur->step_inc();
835 $ret = sprintf('stat = "%s"; subst = "%s";', $user_cur->stat, $user_cur->subst);
836 $ret .= "gst.st = ".($user_cur->step+1)."; ";
837 $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);
838 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
839 $user_cur->step_inc();
842 $this->room_join_wakeup(&$user_cur, TRUE, -2);
843 $table_cur->table_token = "";
846 Briskin5::unlock_data($sem);
848 } // if ($table_cur->player_n == PLAYERS_N) {
849 } // for ($table_idx = 0 ; $table_idx < TABLES_N ; $table_idx++) {
851 log_rd2("out new loop.");
853 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
854 $user_cur = &$this->user[$i];
856 log_rd2("User: ".$user_cur->name." stat: ".$user_cur->stat." subst: ".$user_cur->subst);
858 if ($user_cur->sess == "")
861 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) {
862 // Auto logout dell'utente
863 log_rd2("AUTO LOGOUT.".($user_cur->lacc + EXPIRE_TIME_RD)." curtime ".$curtime);
865 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
866 log_auth($user_cur->sess, "Autologout session.");
869 /* factorized with ->reset()
870 $tmp_sess = $user_cur->sess;
871 $user_cur->sess = "";
872 step_unproxy($tmp_sess);
873 $user_cur->name = "";
874 while (array_pop($user_cur->comm) != NULL);
876 $user_cur->the_end = FALSE;
879 log_rd2("AUTO LOGOUT.");
880 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
881 $this->room_wakeup(&$user_cur);
882 else if ($user_cur->subst == 'standup')
883 $this->room_outstandup(&$user_cur);
885 log_rd2("LOGOUT FROM WHAT ???");
889 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
890 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
891 $this->room_wakeup(&$user_cur);
892 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
893 $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);
894 $user_cur->step_inc();
898 log_rd2("GARBAGE UPDATED!");
900 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
908 function room_wakeup(&$user)
910 $table_idx = $user->table;
911 $table = &$this->table[$table_idx];
913 log_main("WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
917 $from_table = ($user->stat == "table");
919 log_main("WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
921 for ($i = 0 ; $i < $table->player_n ; $i++) {
922 $user_cur = &$this->user[$table->player[$i]];
923 log_main("PREIMPOST: INLOOP name: ".$user_cur->name);
925 if ($user_cur != $user) {
926 $user_cur->stat_set("room");
927 $user_cur->subst = "sitdown";
928 $user_cur->laccwr = $curtime;
930 else if ($user->sess != "") {
931 $user_cur->stat_set("room");
932 $user_cur->subst = "standup";
933 $user_cur->laccwr = $curtime;
934 $user_cur->table = -1;
939 $user->stat_set("room");
940 $user->subst = "standup";
941 $user->laccwr = $curtime;
943 /* aggiorna l'array dei giocatori al tavolo. */
944 $table->user_rem(&$this, &$user);
946 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
947 $user_cur = &$this->user[$i];
948 if ($user_cur->sess == '' || $user_cur->stat != 'room')
951 log_main("VALORI: name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
953 $ret = "gst.st = ".($user_cur->step+1)."; ";
954 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
955 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; document.location.assign("index.php");|';
956 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
957 log_main("DOCUMENT.index.php: from table");
959 else if ($user_cur->stat == "room") {
960 log_main("DOCUMENT.index.php: from table");
962 $ret .= table_content($this, $user_cur, $table_idx);
963 $ret .= standup_content($this, $user_cur);
965 $act_content = table_act_content(FALSE, 0, $table_idx, $user->table);
966 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
969 if ($user_cur == $user) {
970 // set the new status
971 $ret .= 'subst = "standup"; ';
972 // clean the action buttons in other tables
973 for ($e = 0 ; $e < TABLES_N ; $e++) {
974 if ($this->table[$e]->player_n < PLAYERS_N)
975 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
979 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
980 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
983 log_wr("ROOM_WAKEUP: ".$ret);
984 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
985 $user_cur->step_inc();
989 function room_join_wakeup(&$user, $update_lacc = FALSE, $trans_delta)
991 $table_idx = $user->table;
992 $table = &$this->table[$table_idx];
994 log_main("JOIN_WAKEUP: begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
1001 log_main("JOIN WAKEUP: from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1003 for ($i = 0 ; $i < $table->player_n ; $i++) {
1004 $user_cur = &$this->user[$table->player[$i]];
1005 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1006 if ($user_cur->sess != "") {
1007 if ($update_lacc == TRUE) {
1008 $user_cur->laccwr = $curtime;
1010 log_main("cur: ".$user_cur->name." subst: ".$user_cur->subst);
1011 if ($user_cur->subst == "shutdowned") {
1012 $user_cur->stat_set("room");
1013 $user_cur->subst = "sitdown";
1015 else if ($user_cur->subst == "shutdowner") {
1016 $user_cur->stat_set("room");
1017 $user_cur->subst = "standup";
1018 $user_cur->table = -1;
1019 $user_wup[$user_wup_n++] = &$user_cur;
1021 $user_tab[$user_tab_n++] = &$user_cur;
1025 for ($wup_idx = 0 ; $wup_idx < $user_wup_n ; $wup_idx++)
1026 $table->user_rem(&$this, &$user_wup[$wup_idx]);
1028 /* aggiorna l'array dei giocatori al tavolo. */
1030 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1031 log_main("START LOOP");
1032 $user_cur = &$this->user[$i];
1033 if ($user_cur->sess == '' || $user_cur->stat != 'room') {
1034 log_main("name: ".$user_cur->name."skip subst: ".$user_cur->subst);
1039 log_main("VALORI name: ".$user_cur->name." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
1041 $ret = "gst.st = ".($user_cur->step+1)."; ";
1042 if ($user_cur->stat == "room") {
1043 log_main("DOCUMENT.index.php from table");
1045 $ret .= table_content($this, $user_cur, $table_idx);
1046 $ret .= standup_content($this, $user_cur);
1048 $act_content = table_act_content(FALSE, 0, $table_idx, $user_cur->table);
1049 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1051 for ($tab_idx = 0 ; $tab_idx < $user_tab_n ; $tab_idx++)
1052 if ($user_cur == $user_tab[$tab_idx])
1055 // for users that wakeup the room will be reconstructed by index_rd.php
1056 if ($tab_idx < $user_tab_n) {
1057 log_main("PRE show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1059 // ARRAY_POP DISABLED
1060 // if ($trans_delta == 0)
1061 // while (array_pop($user_cur->comm) != NULL);
1063 $user_cur->trans_step = $user_cur->step + 1 + $trans_delta;
1064 $user_cur->comm[$user_cur->step % COMM_N] = "";
1065 $user_cur->step_inc();
1066 $user_cur->comm[$user_cur->step % COMM_N] = show_room(&$this, ($user_cur->step + 1), &$user_cur);
1067 $user_cur->step_inc();
1068 log_main("POST show_room username: ".$user_cur->name." STEP: ".$user_cur->step);
1072 log_main("JOIN_WAKEUP wup_idx ".$wup_idx." wup_n ".$user_wup_n);
1074 log_main("JOIN_WAKEUP more");
1075 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
1076 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1077 log_main("JOIN_WAKEUP end more");
1079 log_wr("ROOM_JOIN_WAKEUP: ".$ret);
1080 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1081 $user_cur->step_inc();
1085 function room_outstandup(&$user)
1087 $this->room_sitdown(&$user, -1);
1090 function table_update(&$user)
1092 log_main("table_update: pre - USER: ".$user->name);
1094 $table_idx = $user->table;
1096 if ($table_idx > -1)
1097 $table = &$this->table[$table_idx];
1099 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1101 $user_cur = &$this->user[$i];
1102 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1105 $ret = "gst.st = ".($user_cur->step+1)."; ";
1106 if ($table_idx > -1)
1107 $ret .= table_content($this, $user_cur, $table_idx);
1109 if ($user_cur == $user) {
1110 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
1112 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1113 $user_cur->step_inc();
1116 log_main("table_update: post");
1119 function room_sitdown(&$user, $table_idx)
1121 log_main("room_sitdown ".($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
1123 if ($table_idx > -1)
1124 $table = &$this->table[$table_idx];
1126 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1128 $user_cur = &$this->user[$i];
1129 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1132 $ret = "gst.st = ".($user_cur->step+1)."; ";
1133 if ($table_idx > -1)
1134 $ret .= table_content($this, $user_cur, $table_idx);
1135 $ret .= standup_content($this, $user_cur);
1137 if ($user_cur == $user) {
1138 $ret .= 'subst = "sitdown"; ';
1139 // clean the action buttons in other tables
1140 for ($e = 0 ; $e < TABLES_N ; $e++) {
1141 $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
1142 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
1145 else if ($table_idx > -1) {
1146 if ($table->player_n == PLAYERS_N) {
1147 $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
1148 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
1151 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1152 $user_cur->step_inc();
1156 function chatt_send(&$user, $mesg)
1160 if ($user->stat == 'table') {
1161 $table = &$this->table[$user->table];
1164 $user_mesg = substr($mesg,6);
1168 $dt = date("H:i ", $timecur);
1169 if (strncmp($user_mesg, "/nick ", 6) == 0) {
1170 log_main("chatt_send BEGIN");
1172 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
1173 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1174 $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));
1179 $user_mesg = "COMMAND ".$user_mesg;
1182 // update local graph
1183 // update remote graphs
1184 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1185 $user_cur = &$this->user[$i];
1186 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1187 if ($user_cur->sess == '')
1189 if ($user_cur->name == $name_new) {
1190 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1191 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
1196 if ($i == MAX_PLAYERS) {
1197 $user->name = $name_new;
1199 log_main("chatt_send start set");
1202 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1203 log_main("chatt_send set loop");
1205 $user_cur = &$this->user[$i];
1206 if ($user_cur->sess == '')
1208 if ($user_cur->stat == 'room') {
1209 if ($user->stat == 'room' && $user->subst == 'standup') {
1210 $this->standup_update(&$user);
1212 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
1213 $user->stat == 'table') {
1214 log_main("chatt_send pre table update");
1216 $this->table_update(&$user);
1218 log_main("chatt_send post table update");
1221 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
1222 $table = &$this->table[$user->table];
1224 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1225 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
1226 xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
1227 xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
1228 xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
1229 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
1230 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
1231 if ($user_cur == $user)
1232 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
1233 xcape($user->name,ENT_COMPAT,"UTF-8"));
1234 $user_cur->step_inc();
1240 if ($timecur < ($user->chat_ban + $user->chat_dlt)) {
1242 $user->chat_dlt = $user->chat_dlt * 2;
1243 if ($user->chat_dlt > 120)
1244 $user->chat_dlt = 120;
1246 else if ($user->chat_lst == $user_mesg)
1248 else if ($timecur - $user->chattime[($user->chat_cur + 1) % CHAT_N] < CHAT_ILL_TIME) {
1249 $user->chat_ban = $timecur;
1250 $user->chat_dlt = 5;
1254 $user->chat_ban = 0;
1255 $user->chat_dlt = 0;
1258 for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
1259 if ($user->stat == 'room') {
1260 $user_cur = &$this->user[$i];
1261 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1265 $user_cur = &$this->user[$table->player[$i]];
1269 if ($user_cur != $user)
1272 $user_mesg = "== chat ban ==";
1275 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1276 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
1277 $dt.xcape($user->name), xcape($user_mesg));
1278 $user_cur->step_inc();
1280 log_legal($timecur, $user->sess, $user->name,
1281 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
1283 $user->chat_lst = "$user_mesg";
1284 $user->chattime[$user->chat_cur % CHAT_N] = $timecur;
1289 function &get_user($sess, &$idx)
1291 GLOBAL $PHP_SELF, $G_false;
1293 if (validate_sess($sess)) {
1294 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1295 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1298 $ret = &$this->user[$i];
1302 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
1303 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
1304 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
1307 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
1314 * function &add_user(&$room, &$sess, &$idx, $name, $ip)
1317 * if ($idx != -1 && ret == FALSE) => duplicated nick
1318 * if ($idx == -2 && ret == FALSE) => invalid name
1319 * if ($idx == -1 && ret == FALSE) => no space left
1320 * if (ret == TRUE) => SUCCESS
1322 function &add_user(&$sess, &$idx, $name, $ip)
1329 if (($name_new = validate_name($name)) == FALSE) {
1334 log_auth("XXX", sprintf("ARRIVA: [%s]", $sess));
1335 if (validate_sess($sess) == FALSE)
1338 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1340 if (strcmp($sess, $this->user[$i]->sess) == 0) {
1344 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
1347 if (strcmp($this->user[$i]->name, $name_new) == 0) {
1355 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1357 if ($idx != -1 && $i == MAX_PLAYERS) {
1361 $this->user[$idx]->sess = uniqid("");
1362 $sess = $this->user[$idx]->sess;
1366 $this->user[$idx]->sess = $sess;
1368 $this->user[$idx]->name = $name_new;
1369 $this->user[$idx]->stat_set("room");
1370 $this->user[$idx]->step_set(0);
1371 while (array_pop($this->user[$idx]->comm) != NULL);
1372 $this->user[$idx]->subst = "standup";
1373 $this->user[$idx]->lacc = $curtime;
1374 $this->user[$idx]->laccwr = $curtime;
1375 $this->user[$idx]->bantime = 0;
1376 $this->user[$idx]->ip = $ip;
1377 log_main(sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
1379 return ($this->user[$idx]);
1385 function standup_update(&$user)
1387 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
1388 $user_cur = &$this->user[$i];
1389 if ($user_cur->sess == '')
1392 log_main("STANDUP START: ".$user_cur->stat);
1394 if ($user_cur->stat == 'room') {
1395 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($this, $user_cur);
1396 if ($user_cur == $user)
1397 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
1399 log_main("FROM STANDUP: NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
1401 $user_cur->step_inc();
1407 function &init_data()
1409 $room =& new Room();
1415 function &load_data()
1417 GLOBAL $G_false, $sess;
1420 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1421 log_main("ftok failed");
1426 if (($shm_sz = sharedmem_sz($tok)) == -1) {
1427 log_main("shmop_open failed");
1431 $shm_sz = SHM_DIMS_MIN;
1433 if ($shm = shm_attach($tok, $shm_sz)) {
1434 $room = @shm_get_var($shm, $tok);
1436 log_only("bri == ".($room == FALSE ? "FALSE" : "TRUE")." bri === ".($room === FALSE ? "FALSE" : "TRUE")." bri isset ".(isset($room) ? "TRUE" : "FALSE"));
1438 log_only("bri count ".count($room));
1440 if ($room == FALSE) {
1441 log_only("INIT MAIN DATA");
1443 $room =& Room::init_data();
1444 if (@shm_put_var($shm, $tok, $room) == FALSE) {
1445 log_only("PUT_VAR FALLITA ".strlen(serialize($room)));
1446 log_only(serialize($room));
1449 $room->shm_sz = $shm_sz;
1464 function save_data(&$room)
1473 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1)
1476 while ($room->shm_sz < SHM_DIMS_MAX) {
1477 if (($shm = shm_attach($tok, $room->shm_sz)) == FALSE)
1480 // log_only("PUT_VAR DI ".strlen(serialize($room)));
1481 if (shm_put_var($shm, $tok, $room) != FALSE) {
1485 if (shm_remove($shm) === FALSE) {
1486 log_only("REMOVE FALLITA");
1490 $room->shm_sz += SHM_DIMS_DLT;
1499 function lock_data()
1503 // echo "LOCK: ".FTOK_PATH."/main";
1505 if (($tok = @ftok(FTOK_PATH."/main", "B")) == -1) {
1509 // echo "FTOK ".$tok."<br>";
1510 if (($res = sem_get($tok)) == FALSE) {
1511 echo "SEM_GET FAILED";
1514 if (sem_acquire($res)) {
1515 log_lock("LOCK room");
1522 function unlock_data($res)
1526 log_lock("UNLOCK room");
1528 return (sem_release($res));
1532 function make_seed()
1534 list($usec, $sec) = explode(' ', microtime());
1535 return (float) $sec + ((float) $usec * 100000);
1539 function log_only2($log) {
1542 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONL2) == 0)
1545 if (isset($sess) == FALSE)
1550 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONL2) == 0)
1553 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1554 fwrite($fp, sprintf("ONL2: [%s] [%s]\n", $ssess, $log));
1559 function log_crit($log) {
1562 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_CRIT) == 0)
1565 if (isset($sess) == FALSE)
1570 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_CRIT) == 0)
1573 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1574 fwrite($fp, sprintf("CRIT: [%s] [%s]\n", $ssess, $log));
1579 function log_only($log) {
1582 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_ONLY) == 0)
1585 if (isset($sess) == FALSE)
1590 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_ONLY) == 0)
1593 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1594 fwrite($fp, sprintf("ONLY: [%s] [%s]\n", $ssess, $log));
1599 function log_main($log) {
1602 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_MAIN) == 0)
1605 if (isset($sess) == FALSE)
1610 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_MAIN) == 0)
1613 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1614 fwrite($fp, sprintf("MAIN: [%s] [%s]\n", $ssess, $log));
1619 function log_rd($log) {
1622 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_READ) == 0)
1625 if (isset($sess) == FALSE)
1630 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_READ) == 0)
1633 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1634 fwrite($fp, sprintf("READ: [%s] [%s]\n", $ssess, $log));
1639 function log_rd2($log) {
1642 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_REA2) == 0)
1645 if (isset($sess) == FALSE)
1650 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_REA2) == 0)
1653 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1654 fwrite($fp, sprintf("REA2: [%s] [%s]\n", $ssess, $log));
1659 function log_send($log) {
1662 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_SEND) == 0)
1665 if (isset($sess) == FALSE)
1670 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_SEND) == 0)
1673 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1674 fwrite($fp, sprintf("SEND: [%s] [%s]\n", $ssess, $log));
1679 function log_lock($log) {
1682 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOCK) == 0)
1685 if (isset($sess) == FALSE)
1690 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOCK) == 0)
1693 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1694 fwrite($fp, sprintf("LOCK: [%s] [%s]\n", $ssess, $log));
1699 function log_wr($log) {
1702 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_WRIT) == 0)
1705 if (isset($sess) == FALSE)
1710 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_WRIT) == 0)
1713 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1714 fwrite($fp, sprintf("WRIT: [%s] [%s]\n", $ssess, $log));
1719 function log_load($log) {
1722 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_LOAD) == 0)
1725 if (isset($sess) == FALSE)
1730 if (( (BRISK_DEBUG | ($ssess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_LOAD) == 0)
1733 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1734 fwrite($fp, sprintf("LOAD: [%s] [%s]\n", $ssess, $log));
1739 function log_auth($sess, $log) {
1740 if (BRISK_SINGLE_SESS == "" && (BRISK_DEBUG & DBG_AUTH) == 0)
1743 if (( (BRISK_DEBUG | ($sess == BRISK_SINGLE_SESS ? BRISK_SINGLE_DEBUG : 0) ) & DBG_AUTH) == 0)
1746 if (($fp = @fopen(LEGAL_PATH."/brisk.log", 'a')) != FALSE) {
1747 fwrite($fp, sprintf("AUTH: [%s] [%d] [%s]\n", $sess, time(), $log));
1753 function log_legal($timecur, $sess, $name, $where, $mesg)
1757 if (($fp = @fopen(LEGAL_PATH."/legal.log", 'a')) != FALSE) {
1758 /* Unix time | session | nickname | IP | where was | mesg */
1759 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|\n", $timecur, $sess, $name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
1767 function lock_banlist()
1769 if (($tok = @ftok(FTOK_PATH."/main", "L")) == -1) {
1773 if (($res = sem_get($tok)) == FALSE) {
1774 echo "SEM_GET FAILED";
1777 if (sem_acquire($res))
1783 function unlock_banlist($res)
1785 return (sem_release($res));
1788 function table_act_content($isstanding, $sitted, $table, $cur_table)
1793 if ($sitted < PLAYERS_N) {
1794 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
1798 if ($table == $cur_table)
1799 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
1806 function table_content($room, $user, $table_idx)
1812 // Si possono usare i dati nella classe table
1815 $sess = $user->sess;
1816 $table = &$room->table[$table_idx];
1818 if ($user->stat != 'room')
1821 for ($i = 0 ; $i < $table->player_n ; $i++) {
1822 $user_cur = &$room->user[$table->player[$i]];
1824 if ($user_cur == $user)
1825 { $hilion = "<b>"; $hilioff = "</b>"; }
1827 { $hilion = ""; $hilioff = ""; }
1829 log_main($user_cur->name. sprintf(" IN TABLE [%d]", $table_idx));
1831 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1834 for ( ; $i < PLAYERS_N ; $i++)
1838 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1843 function standup_content(&$room, $user)
1848 if ($user->stat != 'room')
1851 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1852 if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "")
1857 $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1859 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1860 if ($room->user[$e]->sess == "" || $room->user[$e]->stat != "room" || $room->user[$e]->name == "")
1864 if ($room->user[$e]->subst == "standup") {
1865 if (($ct % 4) == 0) {
1868 if ($room->user[$e] == $user)
1869 { $hilion = "<b>"; $hilioff = "</b>"; }
1871 { $hilion = ""; $hilioff = ""; }
1873 $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($room->user[$e]->name), $hilioff);
1874 if (($ct % 4) == 3) {
1875 $content .= '</tr>';
1880 $content .= '</table>';
1882 $content2 = '<input class=\\"button\\" name=\\"logout\\" value=\\"Esco.\\" onclick=\\"window.onunload = null; act_logout();\\" type=\\"button\\">';
1883 $ret .= sprintf('$("standup").innerHTML = "%s"; $("esco").innerHTML = "%s";',
1884 $content, $content2);
1890 function show_notify($text, $tout, $butt, $w, $h)
1892 log_main("SHOW_NOTIFY: ".$text);
1893 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
1896 function briscola_show($room, $table, $user)
1901 if ($table->asta_card == 9)
1902 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
1904 /* text of caller cell */
1905 if ($user->table_pos == $table->asta_win)
1906 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
1908 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
1909 xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd);
1911 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1913 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1914 $ret .= sprintf('$("caller").style.visibility = "visible";');
1915 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1916 $ret .= sprintf('$("astalascio").style.visibility = "";');
1917 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1918 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1924 function game_result($asta_pnt, $pnt)
1926 if ($asta_pnt == 61) {
1929 else if ($pnt == 60)
1935 if ($pnt >= $asta_pnt)
1942 function multoval($mult)
1946 else if ($mult == 4)
1947 return ("quadruplo");
1949 return (sprintf("%d-plo", $mult));
1952 function show_table_info(&$room, &$table, $table_pos)
1955 $user = &$room->user[$table->player[$table_pos]];
1957 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1958 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1961 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1962 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($room->user[$table->player[$i]]->name));
1963 $noty .= sprintf("</tr>");
1966 log_main("show_table_info: pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1968 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1969 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1970 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1971 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1976 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1977 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1978 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1979 $noty .= "</tr></table>";
1981 if ($table->old_reason != "") {
1982 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1985 if ($table->old_win != -1) {
1986 $win = $table->player[$table->old_win];
1987 $fri = $table->player[$table->old_friend];
1989 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1992 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
1993 xcape($room->user[$win]->name),
1994 xcape($room->user[$fri]->name));
1995 if ($table->old_pnt == 120) {
1996 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
1999 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
2000 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
2001 'più di 60'), $table->old_pnt,
2002 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
2006 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
2007 xcape($room->user[$win]->name));
2008 if ($table->old_pnt == 120) {
2009 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
2012 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
2013 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
2014 'più di 60'), $table->old_pnt,
2015 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
2019 if ($table->mazzo == $table_pos)
2020 $noty .= "Fai <b>tu</b> il mazzo,";
2022 $unam = xcape($room->user[$table->player[$table->mazzo]]->name);
2023 $noty .= "Il mazzo a <b>$unam</b>,";
2026 if ($user->subst == 'asta') {
2027 if ($table->asta_win == -1) // auction case
2028 $curplayer = $table->gstart % PLAYERS_N;
2030 $curplayer = $table->asta_win;
2032 else if ($user->subst == 'game') {
2033 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
2037 if ($curplayer == $table_pos) {
2038 $noty .= " tocca a <b>te</b> giocare.";
2041 $unam = xcape($room->user[$table->player[$curplayer]]->name);
2042 $noty .= " tocca a <b>$unam</b> giocare.";
2045 if ($table->mult > 1) {
2046 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
2048 $noty .= "<hr><br>";
2050 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
2055 function root_wellcome($user)
2057 GLOBAL $root_wellarr;
2060 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
2061 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $root_wellarr[$i]));
2066 function table_wellcome($user)
2068 GLOBAL $table_wellarr;
2071 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
2072 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $table_wellarr[$i]));
2077 function show_room(&$room, $user_step, &$user)
2079 log_main("show_room: username: ".$user->name);
2082 $ret = sprintf('gst.st = %d;', $user_step);
2083 $ret .= sprintf('stat = "%s";', $user->stat);
2085 $ret .= root_wellcome($user);
2086 $ret .= sprintf('subst = "%s";', $user->subst);
2087 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
2088 for ($i = 0 ; $i < TABLES_N ; $i++) {
2089 $ret .= table_content($room, $user, $i);
2090 $act_content = table_act_content(($user->subst == 'standup'),
2091 $room->table[$i]->player_n, $i, $user->table);
2092 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
2094 $ret .= standup_content($room, $user);
2102 is_transition (is from room to table ?)
2103 is_again (is another game)
2105 Examples of $is_transition, $is_again:
2106 from reload of the page: FALSE, FALSE
2107 from sitdown in room: TRUE, FALSE
2108 from table: asta cmd e tutti passano: TRUE, TRUE
2109 from table: fine partita: TRUE, TRUE
2111 function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
2113 $table_idx = $user->table;
2114 $table = &$room->table[$table_idx];
2115 $table_pos = $user->table_pos;
2117 $ret = "table_init();";
2118 $ret .= $table->exitlock_show(&$room->user, $table_pos);
2120 /* GENERAL STATUS */
2121 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
2122 $sendstep, $user->stat, $user->subst, $table_pos);
2124 log_rd(sprintf( 'SHOW_TABLE: gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
2125 $sendstep, $user->stat, $user->subst, $table_pos));
2128 $ret .= "background_set();";
2131 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
2132 $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
2133 xcape($room->user[$table->player[($table_pos)%PLAYERS_N]]->name),
2134 xcape($room->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
2135 xcape($room->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
2136 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
2137 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
2139 /* NOTIFY FOR THE CARD MAKER */
2140 if ($is_transition) { // && $user->subst == "asta" superfluo
2141 $ret .= show_table_info(&$room, &$table, $table_pos);
2144 $ret .= table_wellcome($user);
2146 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
2147 $ret .= playsound("cow.mp3");
2152 if ($is_transition) { // && $user->subst == "asta" superfluo
2155 for ($i = 0 ; $i < 8 ; $i++) {
2156 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
2158 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
2159 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
2165 log_rd("O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
2167 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
2168 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
2169 $table->card[$o]->value : -1),
2170 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
2175 $taked = array(0,0,0,0,0);
2176 $inhand = array(0,0,0,0,0);
2177 $ontabl = array(-1,-1,-1,-1,-1);
2180 for ($i = 0 ; $i < 40 ; $i++) {
2181 if ($table->card[$i]->stat == 'hand') {
2182 if ($table->card[$i]->owner == $table_pos) {
2183 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
2185 $inhand[$table->card[$i]->owner]++;
2187 else if ($table->card[$i]->stat == 'take') {
2188 log_main("Card taked: ".$table->card[$i]->value."OWN: ".$table->card[$i]->owner);
2189 $taked[$table->card[$i]->owner]++;
2191 else if ($table->card[$i]->stat == 'table') {
2192 $ontabl[$table->card[$i]->owner] = $i;
2196 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2197 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
2199 log_main("Stat table: ".$logg);
2201 /* Set ours cards. */
2203 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
2204 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
2205 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
2206 $oursarg .= ($i == 0 ? "" : ", ")."-1";
2207 $ret .= sprintf('card_setours(%s);', $oursarg);
2209 /* Dispose all cards */
2210 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2211 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
2212 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
2213 $inhand[$i], $taked[$i]);
2215 if ($ontabl[$i] != -1) {
2216 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
2217 $table->card[$ontabl[$i]]->value,
2218 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
2224 if ($user->subst == 'asta') {
2226 /* show users auction status */
2228 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2229 $user_cur = &$room->user[$table->player[$i]];
2230 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
2231 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
2234 $showst .= ",-2,-2";
2235 $ret .= sprintf('show_astat(%s);', $showst);
2237 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
2238 /* show card chooser */
2239 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
2244 if ($table_pos == ($table->gstart % PLAYERS_N) &&
2245 $table->asta_win == -1)
2246 $ret .= sprintf('dispose_asta(%d,%d, %s);',
2247 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
2249 $ret .= sprintf('dispose_asta(%d,%d, %s);',
2250 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
2254 if ($table->asta_win == -1) { // auction case
2255 if ($table_pos == ($table->gstart % PLAYERS_N))
2256 $ret .= "remark_on();";
2258 $ret .= "remark_off();";
2260 else { // chooseed case
2261 if ($table_pos == $table->asta_win)
2262 $ret .= "remark_on();";
2264 $ret .= "remark_off();";
2267 else if ($user->subst == 'game') {
2269 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
2270 $ret .= "is_my_time = true; remark_on();";
2272 $ret .= "remark_off();";
2274 /* WHO CALL AND WATH */
2275 $ret .= briscola_show($room, $table, $user);
2279 } // end function show_table(...
2281 function calculate_winner(&$table)
2288 $cur_seed = $table->briscola - ($table->briscola % 10);
2290 for ($i = 0 ; $i < 40 ; $i++) {
2291 if ($table->card[$i]->stat != "table")
2294 log_wr(sprintf("Card On table: [%d]", $i));
2296 $v = $table->card[$i]->value;
2297 $ontab[$table->card[$i]->owner] = $v;
2298 $ontid[$table->card[$i]->owner] = $i;
2299 /* se briscola setto il flag */
2300 if (($v - ($v % 10)) == $cur_seed)
2304 if ($briontab == FALSE) {
2305 $cur_win = $table->gstart;
2306 $cur_val = $ontab[$cur_win];
2307 $cur_seed = $cur_val - ($cur_val % 10);
2310 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2311 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
2312 if ($ontab[$i] < $cur_val) {
2313 $cur_val = $ontab[$i];
2319 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
2320 $table->card[$ontid[$i]]->owner = $cur_win;
2321 $table->card[$ontid[$i]]->stat = "take"; // Card stat
2326 function calculate_points(&$table)
2328 GLOBAL $G_all_points;
2332 if ($table->asta_pnt == 60)
2333 $table->asta_pnt = 61;
2335 $table->old_reason = "";
2336 $table->old_win = $table->asta_win;
2337 $table->old_friend = $table->friend;
2338 $table->old_asta_pnt = $table->asta_pnt;
2340 for ($i = 0 ; $i < 40 ; $i++) {
2341 $ctt = $table->card[$i]->value % 10;
2342 $own = $table->card[$i]->owner;
2343 if ($own == $table->asta_win || $own == $table->friend)
2344 $pro += $G_all_points[$ctt];
2347 log_wr(sprintf("PRO: [%d]", $pro));
2350 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
2351 $table->points[$table->points_n % MAX_POINTS] = array();
2352 for ($i = 0 ; $i < PLAYERS_N ; $i++)
2353 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
2355 $table->old_pnt = $pro;
2361 if ($pro >= $table->asta_pnt)
2366 $table->points[$table->points_n % MAX_POINTS] = array();
2367 for ($i = 0 ; $i < 5 ; $i++) {
2368 if ($i == $table->asta_win)
2369 $pt = ($i == $table->friend ? 4 : 2);
2370 else if ($i == $table->friend)
2375 log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
2377 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
2379 log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
2381 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
2382 $table->total[$i] += $pt;
2385 $table->old_pnt = $pro;
2389 function validate_sess($sess)
2391 if (strlen($sess) == SESS_LEN)
2397 function validate_name($name)
2399 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
2401 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
2403 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
2410 function playsound($filename)
2412 return (sprintf('playsound("flasou", "%s");', $filename));
2415 function secstoword($secs)
2417 $mins = floor($secs / 60);
2420 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
2423 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));
2428 function sharedmem_sz($tok)
2430 if (($shm_id = @shmop_open($tok, 'a', 0, 0)) == FALSE) {
2431 log_main("shmop_open failed");
2434 $shm_sz = shmop_size($shm_id);
2435 shmop_close($shm_id);
2437 log_main("shm_sz: ".$shm_sz." SHM_DIMS: ".SHM_DIMS);