5 * Copyright (C) 2006 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");
26 define(MAX_POINTS, 5);
27 define(MAX_PLAYERS, (PLAYERS_N * TABLES_N));
29 define(COMM_GEN_N, 50);
31 define(STREAM_TIMEOUT, 20);
32 define(EXPIRE_TIME_RD, 180);
33 define(EXPIRE_TIME_SMAMMA, 360);
34 // BAN_TIME da allineare anche in commons.js
35 define(BAN_TIME, 900);
36 define(GARBAGE_TIMEOUT, 10);
37 define(NICKSERV, "<i>SERVER</i>");
38 define(BRISK_DEBUG, FALSE);
39 // define(DEBUGGING, "local");
41 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
42 $G_brisk_version = "0.6.3";
44 $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: "donate" e piccole rifiniture.',
45 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' );
46 $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.');
50 <div style=\\"text-align: left; padding: 8px;\\">
51 <b>Descrizione</b><br>
52 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
53 <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>
54 <b>Configurazione del browser.</b><br>
55 Occorre abilitare i cookies.<br>
56 Se usate <b>Internet Explorer 6</b> dovete settare: strumenti -> opzioni internet -> file temporanei:impostazioni->\\"verifica per nuove versioni della pagina scaricata\\" ad: \\"ogni volta che si visita la pagina\\".<br>
57 Se usate <b>Internet Explorer 7</b> dovete settare: strumenti -> cronologia esplorazioni -> impostazioni ad \\"apertura alla pagina web\\".<br>
59 <b>Uso del sito</b><br>
60 Potete sedervi a un tavolo o rimanere in piedi.<br>
61 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
64 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>
65 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
66 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
67 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
68 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
69 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.
71 <dt><b>Comandi della chat</b>
72 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
73 <dd>.. to be continue ..
79 <div id=\\"header\\" class=\\"header\\">
80 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
81 briscola chiamata in salsa ajax
83 <br><b>version '.$G_brisk_version.'</b><br><br>
84 Copyright 2006-2007 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
89 $from = array ( '\\', '@', '|' );
90 $to = array ( '\\\\', '@', '¦' );
92 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
97 var $value; /* 0 - 39 card value */
98 var $stat; /* 'bunch', 'hand', 'table', 'take' */
99 var $owner; /* (table position 0-4) */
100 // var $pos; /* Pos in hand. */
101 var $x; /* When played the X position on the table of the owner. */
102 var $y; /* When played the Y position on the table of the owner. */
104 function Card($value, $stat, $owner)
106 $this->value = $value;
108 $this->owner = $owner;
111 function assign($stat,$owner)
114 $this->owner = $owner;
117 function setpos($pos)
124 $this->stat = 'table';
129 function take($newown)
131 $this->stat = 'take';
132 $this->owner = $newown;
150 var $points; // points array
151 var $points_n; // number of row of points
166 $this->player = array();
168 $this->card = &$this->bunch_create();
169 $this->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
170 $this->asta_pla_n= -1;
171 $this->asta_card = -1;
172 $this->asta_pnt = -1;
174 $this->points = array( );
176 $this->total = array( 0, 0, 0, 0, 0);
177 $this->asta_win = -1;
178 $this->briscola = -1;
181 $this->old_reason = "";
182 $this->old_asta_pnt = -1;
185 $this->old_friend= -1;
189 function &bunch_create()
193 for ($i = 0 ; $i < 40 ; $i++) {
194 $ret[$i] =& new Card($i, 'bunch', 'no_owner');
201 function bunch_make()
203 $ct = array(0,0,0,0,0);
205 mt_srand(make_seed());
207 for ($i = 39 ; $i >= 0 ; $i--)
210 for ($i = 39 ; $i >= 0 ; $i--) {
214 log_main("RND ZERO", "");
219 $this->card[$id]->assign('hand', $owner);
221 $rest[$rn] = $rest[$i];
222 $pubbpos[$rn2] = $pubbpos[$i];
226 function init(&$userarr)
228 $this->mazzo = rand(0,PLAYERS_N-1);
232 $this->old_reason = "";
233 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
234 $this->total[$i] = 0;
235 $user_cur = &$userarr[$this->player[$i]];
236 $user_cur->exitislock = TRUE;
239 log_main("table::init","ci siamo");
242 function game_init(&$userarr)
244 log_rd2($sess,"GSTART 4");
246 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
250 $this->asta_pla_n = PLAYERS_N;
251 $this->asta_card = -1;
252 $this->asta_pnt = 60;
253 $this->asta_win = -1;
254 $this->briscola = -1;
258 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
259 $this->asta_pla[$i] = TRUE;
260 $user_cur = &$userarr[$this->player[$i]];
261 $user_cur->subst = 'asta';
262 $user_cur->asta_card = -2;
263 $user_cur->asta_pnt = -1;
264 $user_cur->handpt = $this->hand_points($i);
265 // SEE function calculate_points(&$table)
271 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
274 function getPlayer($idx)
276 return ($this->player[$idx]);
279 function setPlayer($idx, $player)
281 $this->player[$idx] = $player;
284 function user_add($idx)
286 $this->player[$this->player_n] = $idx;
289 return ($this->player_n - 1);
292 function user_rem(&$bri, &$user)
294 $tabpos = $user->table_pos;
296 /* verifico la consistenza dei dati */
297 if ($bri->user[$this->player[$tabpos]] == $user) {
299 /* aggiorna l'array dei giocatori al tavolo. */
300 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
301 $this->player[$i] = $this->player[$i+1];
302 $user_cur = &$bri->user[$this->player[$i]];
303 $user_cur->table_pos = $i;
308 log_main($user->sess, "INCONSISTENCY ON TABLE.");
312 function hand_points($idx)
314 GLOBAL $G_all_points;
318 for ($i = 0 ; $i < 40 ; $i++) {
319 if ($this->card[$i]->owner != $idx)
322 $ctt = $this->card[$i]->value % 10;
323 $tot += $G_all_points[$ctt];
329 function exitlock_show(&$userarr, $table_pos)
331 $ct = $this->exitlock_calc(&$userarr, $table_pos);
333 $ret = sprintf('exitlock_show(%d, %s);', $ct,
334 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
338 function exitlock_calc(&$userarr, $table_pos)
342 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
343 if ($userarr[$this->player[$i]]->exitislock == FALSE)
352 var $name; // name of the user
353 var $sess; // session of the user
354 var $lacc; // last access (for the cleanup)
355 var $laccwr; // last access (for the cleanup)
356 var $bantime; // timeout to temporary ban
357 var $stat; // status (outdoor, room, table, game, ...)
358 var $subst; // substatus for each status
359 var $step; // step of the current status
360 var $trans_step; // step to enable transition between pages (disable == -1)
361 var $comm; // commands array
364 var $handpt; // Total card points at the beginning of the current hand.
365 var $exitislock; // Player can exit from the table ?
366 var $table; // id of the current table (if in table state)
367 var $table_pos; // idx on the table
369 function User($name, $sess, $stat = "", $subst = "", $table = -1) {
372 $this->lacc = time();
373 $this->laccwr = time();
376 $this->subst = $subst;
378 $this->trans_step = -1;
379 $this->comm = array();
380 $this->asta_card = -2;
381 $this->asta_pnt = -1;
383 $this->exitislock = TRUE;
385 $this->table = $table;
392 var $comm; // commands for many people
393 var $step; // current step of the comm array
394 var $garbage_timeout;
397 $this->user = array();
399 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
400 $this->user[$i] =& new User("", "");
402 for ($i = 0 ; $i < TABLES_N ; $i++)
403 $this->table[$i] =& new Table();
404 $this->garbage_timeout = 0;
407 function garbage_manager($force)
410 /* Garbage collector degli utenti in timeout */
412 if ($force || $this->garbage_timeout < $curtime) {
414 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
415 $user_cur = &$this->user[$i];
416 if ($user_cur->sess == "")
419 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
420 log_rd2($user_cur->sess, "AUTO LOGOUT.");
422 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
423 log_auth($user_cur->sess, "Autologout session.");
425 $user_cur->sess = "";
426 $user_cur->name = "";
427 $user_cur->the_end = FALSE;
429 log_rd2($user_cur->sess, "AUTO LOGOUT.");
430 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
431 $this->room_wakeup(&$user_cur);
432 else if ($user_cur->subst == 'standup')
433 $this->room_outstandup(&$user_cur);
435 log_rd2($sess, "LOGOUT FROM WHAT ???");
439 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
440 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
441 $this->room_wakeup(&$user_cur);
442 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
443 $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);
448 log_rd2($user_cur->sess, "GARBAGE UPDATED!");
450 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
455 function room_wakeup(&$user)
457 $table_idx = $user->table;
458 $table = &$this->table[$table_idx];
460 log_main("WAKEUP", "begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
464 $from_table = ($user->stat == "table");
466 log_main("WAKEUP", "from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
468 for ($i = 0 ; $i < $table->player_n ; $i++) {
469 $user_cur = &$this->user[$table->player[$i]];
470 log_main("PREIMPOST", "INLOOP name: ".$user_cur->name);
472 if ($user_cur != $user) {
473 $user_cur->stat = "room";
474 $user_cur->subst = "sitdown";
475 $user_cur->laccwr = $curtime;
477 else if ($user->sess != "") {
478 $user_cur->stat = "room";
479 $user_cur->subst = "standup";
480 $user_cur->laccwr = $curtime;
481 $user_cur->table = -1;
486 $user->stat = "room";
487 $user->subst = "standup";
488 $user->laccwr = $curtime;
490 /* aggiorna l'array dei giocatori al tavolo. */
491 $table->user_rem(&$this, &$user);
493 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
494 $user_cur = &$this->user[$i];
495 if ($user_cur->sess == '' || $user_cur->stat != 'room')
498 log_main("VALORI", "name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
500 $ret = "gst.st = ".($user_cur->step+1)."; ";
501 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
502 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; document.location.assign("index.php");|';
503 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
504 log_main("DOCUMENT.index.php", "from table");
506 else if ($user_cur->stat == "room") {
507 log_main("DOCUMENT.index.php", "from table");
509 $ret .= table_content($this, $user_cur, $table_idx);
510 $ret .= standup_content($this, $user_cur);
512 $act_content = table_act_content(FALSE, 0, $e, $user->table);
513 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
516 if ($user_cur == $user) {
517 // set the new status
518 $ret .= 'subst = "standup"; ';
519 // clean the action buttons in other tables
520 for ($e = 0 ; $e < TABLES_N ; $e++) {
521 if ($this->table[$e]->player_n < PLAYERS_N)
522 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
526 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
527 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
530 log_wr($user_cur->sess, "ROOM_WAKEUP: ".$ret);
531 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
539 function room_outstandup(&$user)
541 $this->room_sitdown(&$user, -1);
544 function table_update(&$user)
546 log_main("table_update", "pre - USER: ".$user->name);
548 $table_idx = $user->table;
551 $table = &$this->table[$table_idx];
553 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
555 $user_cur = &$this->user[$i];
556 if ($user_cur->sess == '' || $user_cur->stat != 'room')
559 $ret = "gst.st = ".($user_cur->step+1)."; ";
561 $ret .= table_content($this, $user_cur, $table_idx);
563 if ($user_cur == $user) {
564 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
566 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
570 log_main("table_update", "post");
573 function room_sitdown(&$user, $table_idx)
575 log_main("room_sitdown", ($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
578 $table = &$this->table[$table_idx];
580 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
582 $user_cur = &$this->user[$i];
583 if ($user_cur->sess == '' || $user_cur->stat != 'room')
586 $ret = "gst.st = ".($user_cur->step+1)."; ";
588 $ret .= table_content($this, $user_cur, $table_idx);
589 $ret .= standup_content($this, $user_cur);
591 if ($user_cur == $user) {
592 $ret .= 'subst = "sitdown"; ';
593 // clean the action buttons in other tables
594 for ($e = 0 ; $e < TABLES_N ; $e++) {
595 $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
596 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
599 else if ($table_idx > -1) {
600 if ($table->player_n == PLAYERS_N) {
601 $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
602 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
605 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
610 function chatt_send(&$user, $mesg)
612 if ($user->stat == 'table') {
613 $table = &$this->table[$user->table];
616 $user_mesg = substr($mesg,6);
620 $dt = date("H:i ", $timecur);
621 if (strncmp($user_mesg, "/nick ", 6) == 0) {
622 log_main($user->sess, "chatt_send BEGIN");
624 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
625 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
626 $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));
631 $user_mesg = "COMMAND ".$user_mesg;
634 // update local graph
635 // update remote graphs
636 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
637 $user_cur = &$this->user[$i];
638 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
639 if ($user_cur->sess == '')
641 if ($user_cur->name == $name_new) {
642 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
643 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
648 if ($i == MAX_PLAYERS) {
649 $user->name = $name_new;
651 log_main($user->sess, "chatt_send start set");
654 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
655 log_main($user->sess, "chatt_send set loop");
657 $user_cur = &$this->user[$i];
658 if ($user_cur->sess == '')
660 if ($user_cur->stat == 'room') {
661 if ($user->stat == 'room' && $user->subst == 'standup') {
662 $this->standup_update(&$user);
664 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
665 $user->stat == 'table') {
666 log_main($user->sess, "chatt_send pre table update");
668 $this->table_update(&$user);
670 log_main($user->sess, "chatt_send post table update");
673 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
674 $table = &$this->table[$user->table];
676 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
677 $user_cur->comm[$user_cur->step % COMM_N] = sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
678 xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
679 xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
680 xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
681 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
682 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
683 if ($user_cur == $user)
684 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
685 xcape($user->name,ENT_COMPAT,"UTF-8"));
692 for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
693 if ($user->stat == 'room') {
694 $user_cur = &$this->user[$i];
695 if ($user_cur->sess == '' || $user_cur->stat != 'room')
699 $user_cur = &$this->user[$table->player[$i]];
702 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
703 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
704 $dt.xcape($user->name), xcape($user_mesg));
707 log_legal($timecur, $user->sess, $user->name,
708 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
712 function &get_user($sess, &$idx)
716 if (strlen($sess) == SESS_LEN) {
717 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
718 if (strcmp($sess, $this->user[$i]->sess) == 0) {
721 $ret = &$this->user[$i];
725 log_main($sess, sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
726 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
727 // log_main($sess, sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
730 log_main($sess, sprintf("get_user: Wrong strlen [%s]",$sess));
736 * function &add_user(&$bri, &$sess, &$idx, $name)
739 * if ($idx != -1 && ret == FALSE) => duplicated nick
740 * if ($idx == -2 && ret == FALSE) => invalid name
741 * if ($idx == -1 && ret == FALSE) => no space left
742 * if (ret == TRUE) => SUCCESS
744 function &add_user(&$sess, &$idx, $name)
749 if (($name_new = validate_name($name)) == FALSE) {
754 log_auth("XXX", sprintf("ARRIVA: [%s]", $sess));
755 if (validate_sess($sess) == FALSE)
758 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
760 if (strcmp($sess, $this->user[$i]->sess) == 0) {
764 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
767 if (strcmp($this->user[$i]->name, $name_new) == 0) {
775 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
777 if ($idx != -1 && $i == MAX_PLAYERS) {
781 $this->user[$idx]->sess = uniqid("");
782 $sess = $this->user[$idx]->sess;
786 $this->user[$idx]->sess = $sess;
788 $this->user[$idx]->name = $name_new;
789 $this->user[$idx]->stat = "room";
790 $this->user[$idx]->subst = "standup";
791 $this->user[$idx]->lacc = $curtime;
792 $this->user[$idx]->laccwr = $curtime;
793 $this->user[$idx]->bantime = 0;
795 log_main("XXX", sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
797 return ($this->user[$idx]);
803 function standup_update(&$user)
805 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
806 $user_cur = &$this->user[$i];
807 if ($user_cur->sess == '')
810 log_main("STANDUP START", $user_cur->stat);
812 if ($user_cur->stat == 'room') {
813 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($this, $user_cur);
814 if ($user_cur == $user)
815 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
817 log_main("FROM STANDUP", "NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
825 } // end class brisco
829 list($usec, $sec) = explode(' ', microtime());
830 return (float) $sec + ((float) $usec * 100000);
833 function log_main($sess, $log) {
834 if (BRISK_DEBUG != TRUE)
837 $fp = fopen("/tmp/brisk_main.log", 'a');
838 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
842 function log_rd($sess, $log) {
843 if (BRISK_DEBUG != TRUE)
846 $fp = fopen("/tmp/brisk_rd.log", 'a');
847 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
851 function log_rd2($sess, $log) {
852 if (BRISK_DEBUG != TRUE)
855 $fp = fopen("/tmp/brisk_rd2.log", 'a');
856 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
860 function log_send($sess, $log) {
861 if (BRISK_DEBUG != TRUE)
864 $fp = fopen("/tmp/brisk_send.log", 'a');
865 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
869 function log_auth($sess, $log) {
870 if (BRISK_DEBUG != TRUE)
873 $fp = fopen("/tmp/brisk_auth.log", 'a');
874 fwrite($fp, sprintf("SESS: [%d] [%s] [%s]\n", time(), $sess, $log));
878 function log_wr($sess, $log) {
879 if (BRISK_DEBUG != TRUE)
882 $fp = fopen("/tmp/brisk_wr.log", 'a');
883 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
887 function log_load($sess, $log) {
888 if (BRISK_DEBUG != TRUE)
891 $fp = fopen("/tmp/brisk_load.log", 'a');
892 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
896 function log_legal($timecur, $sess, $name, $where, $mesg)
900 $fp = fopen(LEGAL_PATH, 'a');
901 /* Unix time | session | nickname | IP | where was | mesg */
902 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|\n", $timecur, $sess, $name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
910 $brisco =& new brisco();
917 // echo "LOCK: ".FTOK_PATH."/main";
919 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
923 // echo "FTOK ".$tok."<br>";
924 if (($res = sem_get($tok)) == FALSE) {
925 echo "SEM_GET FAILED";
928 if (sem_acquire($res))
934 function unlock_data($res)
936 return (sem_release($res));
940 function &load_data()
942 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
947 if ($shm = shm_attach($tok,100000 * TABLES_N)) {
948 if(($bri = @shm_get_var($shm, $tok)) == false) {
949 log_main("XXX", "INIT MAIN DATA");
952 shm_put_var($shm, $tok, $bri);
965 function save_data(&$bri)
973 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
979 if (($shm = shm_attach($tok,100000 * TABLES_N)) == FALSE)
982 if (shm_put_var($shm, $tok, $bri) == FALSE)
984 // log_main("XXX", "QUI CI ARRIVA [".$bri->user[0]->name."]");
994 function table_act_content($isstanding, $sitted, $table, $cur_table)
999 if ($sitted < PLAYERS_N) {
1000 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
1004 if ($table == $cur_table)
1005 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
1012 function table_content($bri, $user, $table_idx)
1018 // Si possono usare i dati nella classe table
1021 $sess = $user->sess;
1022 $table = &$bri->table[$table_idx];
1024 if ($user->stat != 'room')
1027 for ($i = 0 ; $i < $table->player_n ; $i++) {
1028 $user_cur = &$bri->user[$table->player[$i]];
1030 if ($user_cur == $user)
1031 { $hilion = "<b>"; $hilioff = "</b>"; }
1033 { $hilion = ""; $hilioff = ""; }
1035 log_main($bri->user[$e]->name, sprintf("IN TABLE [%d]", $table_idx));
1037 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1040 for ( ; $i < PLAYERS_N ; $i++)
1044 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1049 function standup_content(&$bri, $user)
1054 if ($user->stat != 'room')
1057 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1058 if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
1063 $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1065 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1066 if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
1070 if ($bri->user[$e]->subst == "standup") {
1071 if (($ct % 4) == 0) {
1074 if ($bri->user[$e] == $user)
1075 { $hilion = "<b>"; $hilioff = "</b>"; }
1077 { $hilion = ""; $hilioff = ""; }
1079 $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($bri->user[$e]->name), $hilioff);
1080 if (($ct % 4) == 3) {
1081 $content .= '</tr>';
1086 $content .= '</table>';
1088 $content2 = '<input class=\\"button\\" name=\\"logout\\" value=\\"Esco.\\" onclick=\\"window.onunload = null; act_logout();\\" type=\\"button\\">';
1089 $ret .= sprintf('$("standup").innerHTML = "%s"; $("esco").innerHTML = "%s";',
1090 $content, $content2);
1096 function show_notify($text, $tout, $butt, $w, $h)
1098 log_main("SHOW_NOTIFY", $text);
1099 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
1102 function briscola_show($bri, $table, $user)
1107 if ($table->asta_card == 9)
1108 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
1110 /* text of caller cell */
1111 if ($user->table_pos == $table->asta_win)
1112 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
1114 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
1115 xcape($bri->user[$table->player[$table->asta_win]]->name), $ptnadd);
1117 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1119 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1120 $ret .= sprintf('$("caller").style.visibility = "visible";');
1121 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1122 $ret .= sprintf('$("astalascio").style.visibility = "";');
1123 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1124 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1130 function game_result($asta_pnt, $pnt)
1132 if ($asta_pnt == 61) {
1135 else if ($pnt == 60)
1141 if ($pnt >= $asta_pnt)
1148 function multoval($mult)
1152 else if ($mult == 4)
1153 return ("quadruplo");
1155 return (sprintf("%d-plo", $mult));
1158 function show_table_info(&$bri, &$table, $table_pos)
1160 $user = &$bri->user[$table->player[$table_pos]];
1162 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1163 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1166 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1167 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($bri->user[$table->player[$i]]->name));
1168 $noty .= sprintf("</tr>");
1171 log_main("show_table_info", "pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1173 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1174 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1175 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1176 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1181 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1182 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1183 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1184 $noty .= "</tr></table>";
1186 if ($table->old_reason != "") {
1187 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1190 if ($table->old_win != -1) {
1191 $win = $table->player[$table->old_win];
1192 $fri = $table->player[$table->old_friend];
1194 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1197 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
1198 xcape($bri->user[$win]->name),
1199 xcape($bri->user[$fri]->name));
1200 if ($table->old_pnt == 120) {
1201 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
1204 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
1205 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1206 'più di 60'), $table->old_pnt,
1207 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1211 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
1212 xcape($bri->user[$win]->name));
1213 if ($table->old_pnt == 120) {
1214 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
1217 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
1218 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1219 'più di 60'), $table->old_pnt,
1220 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1224 if ($table->mazzo == $table_pos)
1225 $noty .= "Fai <b>tu</b> il mazzo,";
1227 $unam = xcape($bri->user[$table->player[$table->mazzo]]->name);
1228 $noty .= "Il mazzo a <b>$unam</b>,";
1231 if ($user->subst == 'asta') {
1232 if ($table->asta_win == -1) // auction case
1233 $curplayer = $table->gstart % PLAYERS_N;
1235 $curplayer = $table->asta_win;
1237 else if ($user->subst == 'game') {
1238 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
1242 if ($curplayer == $table_pos) {
1243 $noty .= " tocca a <b>te</b> giocare.";
1246 $unam = xcape($bri->user[$table->player[$curplayer]]->name);
1247 $noty .= " tocca a <b>$unam</b> giocare.";
1250 if ($table->mult > 1) {
1251 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
1253 $noty .= "<hr><br>";
1255 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
1260 function root_wellcome($user)
1262 GLOBAL $root_wellarr;
1264 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
1265 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $root_wellarr[$i]));
1270 function table_wellcome($user)
1272 GLOBAL $table_wellarr;
1274 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
1275 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $table_wellarr[$i]));
1280 function show_room(&$bri, &$user)
1282 $ret .= sprintf('gst.st = %d;', $user->step);
1283 $ret .= sprintf('stat = "%s";', $user->stat);
1285 $ret .= root_wellcome($user);
1286 $ret .= sprintf('subst = "%s";', $user->subst);
1287 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
1288 for ($i = 0 ; $i < TABLES_N ; $i++) {
1289 $ret .= table_content($bri, $user, $i);
1290 $act_content = table_act_content(($user->subst == 'standup'),
1291 $bri->table[$i]->player_n, $i, $user->table);
1292 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
1294 $ret .= standup_content($bri, $user);
1302 is_transition (is from room to table ?)
1303 is_again (is another game)
1305 Examples of $is_transition, $is_again:
1306 from reload of the page: FALSE, FALSE
1307 from sitdown in room: TRUE, FALSE
1308 from table: asta cmd e tutti passano: TRUE, TRUE
1309 from table: fine partita: TRUE, TRUE
1311 function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again)
1313 $table_idx = $user->table;
1314 $table = &$bri->table[$table_idx];
1315 $table_pos = $user->table_pos;
1317 $ret = "table_init();";
1318 $ret .= $table->exitlock_show(&$bri->user, $table_pos);
1320 /* GENERAL STATUS */
1321 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
1322 $sendstep, $user->stat, $user->subst, $table_pos);
1324 $ret .= "background_set();";
1327 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
1328 $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
1329 xcape($bri->user[$table->player[($table_pos)%PLAYERS_N]]->name),
1330 xcape($bri->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
1331 xcape($bri->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
1332 (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
1333 (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
1335 /* NOTIFY FOR THE CARD MAKER */
1336 if ($is_transition) { // && $user->subst == "asta" superfluo
1337 $ret .= show_table_info(&$bri, &$table, $table_pos);
1340 $ret .= table_wellcome($user);
1342 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
1343 $ret .= playsound("cow.mp3");
1348 if ($is_transition) { // && $user->subst == "asta" superfluo
1351 for ($i = 0 ; $i < 8 ; $i++) {
1352 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
1354 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
1355 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
1361 log_rd($sess, "O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
1363 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
1364 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
1365 $table->card[$o]->value : -1),
1366 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
1371 $taked = array(0,0,0,0,0);
1372 $inhand = array(0,0,0,0,0);
1373 $ontabl = array(-1,-1,-1,-1,-1);
1376 for ($i = 0 ; $i < 40 ; $i++) {
1377 if ($table->card[$i]->stat == 'hand') {
1378 if ($table->card[$i]->owner == $table_pos) {
1379 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
1381 $inhand[$table->card[$i]->owner]++;
1383 else if ($table->card[$i]->stat == 'take') {
1384 log_main("Card taked:", $table->card[$i]->value."OWN: ".$table->card[$i]->owner);
1385 $taked[$table->card[$i]->owner]++;
1387 else if ($table->card[$i]->stat == 'table') {
1388 $ontabl[$table->card[$i]->owner] = $i;
1392 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1393 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
1395 log_main("Stat table:", $logg);
1397 /* Set ours cards. */
1399 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
1400 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
1401 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
1402 $oursarg .= ($i == 0 ? "" : ", ")."-1";
1403 $ret .= sprintf('card_setours(%s);', $oursarg);
1405 /* Dispose all cards */
1406 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1407 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
1408 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
1409 $inhand[$i], $taked[$i]);
1411 if ($ontabl[$i] != -1) {
1412 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
1413 $table->card[$ontabl[$i]]->value,
1414 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
1420 if ($user->subst == 'asta') {
1422 /* show users auction status */
1424 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1425 $user_cur = &$bri->user[$table->player[$i]];
1426 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
1427 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
1430 $showst .= ",-2,-2";
1431 $ret .= sprintf('show_astat(%s);', $showst);
1433 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
1434 /* show card chooser */
1435 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
1440 if ($table_pos == ($table->gstart % PLAYERS_N) &&
1441 $table->asta_win == -1)
1442 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1443 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
1445 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1446 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
1450 if ($table->asta_win == -1) { // auction case
1451 if ($table_pos == ($table->gstart % PLAYERS_N))
1452 $ret .= "remark_on();";
1454 $ret .= "remark_off();";
1456 else { // chooseed case
1457 if ($table_pos == $table->asta_win)
1458 $ret .= "remark_on();";
1460 $ret .= "remark_off();";
1463 else if ($user->subst == 'game') {
1465 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
1466 $ret .= "is_my_time = true; remark_on();";
1468 $ret .= "remark_off();";
1470 /* WHO CALL AND WATH */
1471 $ret .= briscola_show($bri, $table, $user);
1477 function calculate_winner(&$table)
1484 $cur_seed = $table->briscola - ($table->briscola % 10);
1486 for ($i = 0 ; $i < 40 ; $i++) {
1487 if ($table->card[$i]->stat != "table")
1490 log_wr($sess, sprintf("Card On table: [%d]", $i));
1492 $v = $table->card[$i]->value;
1493 $ontab[$table->card[$i]->owner] = $v;
1494 $ontid[$table->card[$i]->owner] = $i;
1495 /* se briscola setto il flag */
1496 if (($v - ($v % 10)) == $cur_seed)
1500 if ($briontab == FALSE) {
1501 $cur_win = $table->gstart;
1502 $cur_val = $ontab[$cur_win];
1503 $cur_seed = $cur_val - ($cur_val % 10);
1506 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1507 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
1508 if ($ontab[$i] < $cur_val) {
1509 $cur_val = $ontab[$i];
1515 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1516 $table->card[$ontid[$i]]->owner = $cur_win;
1517 $table->card[$ontid[$i]]->stat = "take";
1522 function calculate_points(&$table)
1524 GLOBAL $G_all_points;
1528 if ($table->asta_pnt == 60)
1529 $table->asta_pnt = 61;
1531 $table->old_reason = "";
1532 $table->old_win = $table->asta_win;
1533 $table->old_friend = $table->friend;
1534 $table->old_asta_pnt = $table->asta_pnt;
1536 for ($i = 0 ; $i < 40 ; $i++) {
1537 $ctt = $table->card[$i]->value % 10;
1538 $own = $table->card[$i]->owner;
1539 if ($own == $table->asta_win || $own == $table->friend)
1540 $pro += $G_all_points[$ctt];
1543 log_wr("XXX", sprintf("PRO: [%d]", $pro));
1546 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
1547 $table->points[$table->points_n % MAX_POINTS] = array();
1548 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1549 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
1551 $table->old_pnt = $pro;
1557 if ($pro >= $table->asta_pnt)
1562 $table->points[$table->points_n % MAX_POINTS] = array();
1563 for ($i = 0 ; $i < 5 ; $i++) {
1564 if ($i == $table->asta_win)
1565 $pt = ($i == $table->friend ? 4 : 2);
1566 else if ($i == $table->friend)
1571 log_wr("XXX", sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
1573 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
1575 log_wr("XXX", sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
1577 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
1578 $table->total[$i] += $pt;
1581 $table->old_pnt = $pro;
1585 function validate_sess($sess)
1587 if (strlen($sess) == SESS_LEN)
1593 function validate_name($name)
1595 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
1597 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
1599 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
1606 function playsound($filename)
1608 return (sprintf('playsound("flasou", "%s");', $filename));
1611 function secstoword($secs)
1613 $mins = floor($secs / 60);
1616 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
1619 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));