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.1";
44 $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: log per il tracciamento di eventuali illeciti.',
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 Internet Explorer dovete anche settare: strumenti->cronologia_esplorazioni->impostazioni ad \\"apertura alla pagina web\\".<br>
58 <b>Uso del sito</b><br>
59 Potete sedervi a un tavolo o rimanere in piedi.<br>
60 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
63 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>
64 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
65 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
66 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno al quadrato al centro del vostro schermo.<br><br>
67 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
68 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.
70 <dt><b>Comandi della chat</b>
71 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
72 <dd>.. to be continue ..
78 <div id=\\"header\\" class=\\"header\\">
79 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
80 briscola chiamata in salsa ajax
82 <br><b>version '.$G_brisk_version.'</b><br><br>
83 Copyright 2006-2007 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
88 $from = array ( '\\', '@', '|' );
89 $to = array ( '\\\\', '@', '¦' );
91 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
96 var $value; /* 0 - 39 card value */
97 var $stat; /* 'bunch', 'hand', 'table', 'take' */
98 var $owner; /* (table position 0-4) */
99 // var $pos; /* Pos in hand. */
100 var $x; /* When played the X position on the table of the owner. */
101 var $y; /* When played the Y position on the table of the owner. */
103 function Card($value, $stat, $owner)
105 $this->value = $value;
107 $this->owner = $owner;
110 function assign($stat,$owner)
113 $this->owner = $owner;
116 function setpos($pos)
123 $this->stat = 'table';
128 function take($newown)
130 $this->stat = 'take';
131 $this->owner = $newown;
149 var $points; // points array
150 var $points_n; // number of row of points
165 $this->player = array();
167 $this->card = &$this->bunch_create();
168 $this->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
169 $this->asta_pla_n= -1;
170 $this->asta_card = -1;
171 $this->asta_pnt = -1;
173 $this->points = array( );
175 $this->total = array( 0, 0, 0, 0, 0);
176 $this->asta_win = -1;
177 $this->briscola = -1;
180 $this->old_reason = "";
181 $this->old_asta_pnt = -1;
184 $this->old_friend= -1;
188 function &bunch_create()
192 for ($i = 0 ; $i < 40 ; $i++) {
193 $ret[$i] = new Card($i, 'bunch', 'no_owner');
199 function bunch_make()
201 $ct = array(0,0,0,0,0);
203 mt_srand(make_seed());
205 for ($i = 39 ; $i >= 0 ; $i--)
208 for ($i = 39 ; $i >= 0 ; $i--) {
212 log_main("RND ZERO", "");
217 $this->card[$id]->assign('hand', $owner);
219 $rest[$rn] = $rest[$i];
220 $pubbpos[$rn2] = $pubbpos[$i];
224 function init(&$userarr)
226 $this->mazzo = rand(0,PLAYERS_N-1);
230 $this->old_reason = "";
231 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
232 $this->total[$i] = 0;
233 $user_cur = &$userarr[$this->player[$i]];
234 $user_cur->exitislock = TRUE;
237 log_main("table::init","ci siamo");
240 function game_init(&$userarr)
242 log_rd2($sess,"GSTART 4");
244 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
248 $this->asta_pla_n = PLAYERS_N;
249 $this->asta_card = -1;
250 $this->asta_pnt = 60;
251 $this->asta_win = -1;
252 $this->briscola = -1;
256 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
257 $this->asta_pla[$i] = TRUE;
258 $user_cur = &$userarr[$this->player[$i]];
259 $user_cur->subst = 'asta';
260 $user_cur->asta_card = -2;
261 $user_cur->asta_pnt = -1;
262 $user_cur->handpt = $this->hand_points($i);
263 // SEE function calculate_points(&$table)
269 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
272 function getPlayer($idx)
274 return ($this->player[$idx]);
277 function setPlayer($idx, $player)
279 $this->player[$idx] = $player;
282 function user_add($idx)
284 $this->player[$this->player_n] = $idx;
287 return ($this->player_n - 1);
290 function user_rem(&$bri, &$user)
292 $tabpos = $user->table_pos;
294 /* verifico la consistenza dei dati */
295 if ($bri->user[$this->player[$tabpos]] == $user) {
297 /* aggiorna l'array dei giocatori al tavolo. */
298 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
299 $this->player[$i] = $this->player[$i+1];
300 $user_cur = &$bri->user[$this->player[$i]];
301 $user_cur->table_pos = $i;
306 log_main($user->sess, "INCONSISTENCY ON TABLE.");
310 function hand_points($idx)
312 GLOBAL $G_all_points;
316 for ($i = 0 ; $i < 40 ; $i++) {
317 if ($this->card[$i]->owner != $idx)
320 $ctt = $this->card[$i]->value % 10;
321 $tot += $G_all_points[$ctt];
327 function exitlock_show(&$userarr, $table_pos)
329 $ct = $this->exitlock_calc(&$userarr, $table_pos);
331 $ret = sprintf('exitlock_show(%d, %s);', $ct,
332 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
336 function exitlock_calc(&$userarr, $table_pos)
340 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
341 if ($userarr[$this->player[$i]]->exitislock == FALSE)
350 var $name; // name of the user
351 var $sess; // session of the user
352 var $lacc; // last access (for the cleanup)
353 var $laccwr; // last access (for the cleanup)
354 var $bantime; // timeout to temporary ban
355 var $stat; // status (outdoor, room, table, game, ...)
356 var $subst; // substatus for each status
357 var $step; // step of the current status
358 var $trans_step; // step to enable transition between pages (disable == -1)
359 var $comm; // commands array
362 var $handpt; // Total card points at the beginning of the current hand.
363 var $exitislock; // Player can exit from the table ?
364 var $table; // id of the current table (if in table state)
365 var $table_pos; // idx on the table
367 function User($name, $sess, $stat = "", $subst = "", $table = -1) {
370 $this->lacc = time();
371 $this->laccwr = time();
374 $this->subst = $subst;
376 $this->trans_step = -1;
377 $this->comm = array();
378 $this->asta_card = -2;
379 $this->asta_pnt = -1;
381 $this->exitislock = TRUE;
383 $this->table = $table;
390 var $comm; // commands for many people
391 var $step; // current step of the comm array
392 var $garbage_timeout;
395 $this->user = array();
397 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
398 $this->user[$i] = new User("", "");
400 for ($i = 0 ; $i < TABLES_N ; $i++)
401 $this->table[$i] = new Table();
402 $this->garbage_timeout = 0;
405 function garbage_manager($force)
408 /* Garbage collector degli utenti in timeout */
410 if ($force || $this->garbage_timeout < $curtime) {
412 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
413 $user_cur = &$this->user[$i];
414 if ($user_cur->sess == "")
417 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
418 log_rd2($user_cur->sess, "AUTO LOGOUT.");
420 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
421 log_auth($user_cur->sess, "Autologout session.");
423 $user_cur->sess = "";
424 $user_cur->name = "";
425 $user_cur->the_end = FALSE;
427 log_rd2($user_cur->sess, "AUTO LOGOUT.");
428 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
429 $this->room_wakeup(&$user_cur);
430 else if ($user_cur->subst == 'standup')
431 $this->room_outstandup(&$user_cur);
433 log_rd2($sess, "LOGOUT FROM WHAT ???");
437 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
438 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
439 $this->room_wakeup(&$user_cur);
440 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
441 $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);
446 log_rd2($user_cur->sess, "GARBAGE UPDATED!");
448 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
453 function room_wakeup(&$user)
455 $table_idx = $user->table;
456 $table = &$this->table[$table_idx];
458 log_main("WAKEUP", "begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
462 $from_table = ($user->stat == "table");
464 log_main("WAKEUP", "from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
466 for ($i = 0 ; $i < $table->player_n ; $i++) {
467 $user_cur = &$this->user[$table->player[$i]];
468 log_main("PREIMPOST", "INLOOP name: ".$user_cur->name);
470 if ($user_cur != $user) {
471 $user_cur->stat = "room";
472 $user_cur->subst = "sitdown";
473 $user_cur->laccwr = $curtime;
475 else if ($user->sess != "") {
476 $user_cur->stat = "room";
477 $user_cur->subst = "standup";
478 $user_cur->laccwr = $curtime;
479 $user_cur->table = -1;
484 $user->stat = "room";
485 $user->subst = "standup";
486 $user->laccwr = $curtime;
488 /* aggiorna l'array dei giocatori al tavolo. */
489 $table->user_rem(&$this, &$user);
491 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
492 $user_cur = &$this->user[$i];
493 if ($user_cur->sess == '' || $user_cur->stat != 'room')
496 log_main("VALORI", "name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
498 $ret = "gst.st = ".($user_cur->step+1)."; ";
499 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
500 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; document.location.assign("index.php");|';
501 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
502 log_main("DOCUMENT.index.php", "from table");
504 else if ($user_cur->stat == "room") {
505 log_main("DOCUMENT.index.php", "from table");
507 $ret .= table_content($this, $user_cur, $table_idx);
508 $ret .= standup_content($this, $user_cur);
510 $act_content = table_act_content(FALSE, 0, $e, $user->table);
511 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
514 if ($user_cur == $user) {
515 // set the new status
516 $ret .= 'subst = "standup"; ';
517 // clean the action buttons in other tables
518 for ($e = 0 ; $e < TABLES_N ; $e++) {
519 if ($this->table[$e]->player_n < PLAYERS_N)
520 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
524 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
525 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
528 log_wr($user_cur->sess, "ROOM_WAKEUP: ".$ret);
529 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
537 function room_outstandup(&$user)
539 $this->room_sitdown(&$user, -1);
542 function table_update(&$user)
544 log_main("table_update", "pre - USER: ".$user->name);
546 $table_idx = $user->table;
549 $table = &$this->table[$table_idx];
551 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
553 $user_cur = &$this->user[$i];
554 if ($user_cur->sess == '' || $user_cur->stat != 'room')
557 $ret = "gst.st = ".($user_cur->step+1)."; ";
559 $ret .= table_content($this, $user_cur, $table_idx);
561 if ($user_cur == $user) {
562 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
564 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
568 log_main("table_update", "post");
571 function room_sitdown(&$user, $table_idx)
573 log_main("room_sitdown", ($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
576 $table = &$this->table[$table_idx];
578 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
580 $user_cur = &$this->user[$i];
581 if ($user_cur->sess == '' || $user_cur->stat != 'room')
584 $ret = "gst.st = ".($user_cur->step+1)."; ";
586 $ret .= table_content($this, $user_cur, $table_idx);
587 $ret .= standup_content($this, $user_cur);
589 if ($user_cur == $user) {
590 $ret .= 'subst = "sitdown"; ';
591 // clean the action buttons in other tables
592 for ($e = 0 ; $e < TABLES_N ; $e++) {
593 $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
594 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
597 else if ($table_idx > -1) {
598 if ($table->player_n == PLAYERS_N) {
599 $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
600 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
603 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
608 function chatt_send(&$user, $mesg)
610 if ($user->stat == 'table') {
611 $table = &$this->table[$user->table];
614 $user_mesg = substr($mesg,6);
618 $dt = date("H:i ", $timecur);
619 if (strncmp($user_mesg, "/nick ", 6) == 0) {
620 log_main($user->sess, "chatt_send BEGIN");
622 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
623 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
624 $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));
629 $user_mesg = "COMMAND ".$user_mesg;
632 // update local graph
633 // update remote graphs
634 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
635 $user_cur = &$this->user[$i];
636 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
637 if ($user_cur->sess == '')
639 if ($user_cur->name == $name_new) {
640 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
641 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
646 if ($i == MAX_PLAYERS) {
647 $user->name = $name_new;
649 log_main($user->sess, "chatt_send start set");
652 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
653 log_main($user->sess, "chatt_send set loop");
655 $user_cur = &$this->user[$i];
656 if ($user_cur->sess == '')
658 if ($user_cur->stat == 'room') {
659 if ($user->stat == 'room' && $user->subst == 'standup') {
660 $this->standup_update(&$user);
662 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
663 $user->stat == 'table') {
664 log_main($user->sess, "chatt_send pre table update");
666 $this->table_update(&$user);
668 log_main($user->sess, "chatt_send post table update");
671 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
672 $table = &$this->table[$user->table];
674 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
675 $user_cur->comm[$user_cur->step % COMM_N] = sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
676 xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
677 xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
678 xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
679 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
680 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
681 if ($user_cur == $user)
682 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
683 xcape($user->name,ENT_COMPAT,"UTF-8"));
690 for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
691 if ($user->stat == 'room') {
692 $user_cur = &$this->user[$i];
693 if ($user_cur->sess == '' || $user_cur->stat != 'room')
697 $user_cur = &$this->user[$table->player[$i]];
700 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
701 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
702 $dt.xcape($user->name), xcape($user_mesg));
705 log_legal($timecur, $user->sess, $user->name,
706 ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
710 function &get_user($sess, &$idx)
714 if (strlen($sess) == SESS_LEN) {
715 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
716 if (strcmp($sess, $this->user[$i]->sess) == 0) {
719 return ($this->user[$i]);
722 log_main($sess, sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
723 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
724 // log_main($sess, sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
727 log_main($sess, sprintf("get_user: Wrong strlen [%s]",$sess));
733 * function &add_user(&$bri, &$sess, &$idx, $name)
736 * if ($idx != -1 && ret == FALSE) => duplicated nick
737 * if ($idx == -2 && ret == FALSE) => invalid name
738 * if ($idx == -1 && ret == FALSE) => no space left
739 * if (ret == TRUE) => SUCCESS
741 function &add_user(&$sess, &$idx, $name)
746 if (($name_new = validate_name($name)) == FALSE) {
751 log_auth("XXX", sprintf("ARRIVA: [%s]", $sess));
752 if (validate_sess($sess) == FALSE)
755 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
757 if (strcmp($sess, $this->user[$i]->sess) == 0) {
761 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
764 if (strcmp($this->user[$i]->name, $name_new) == 0) {
772 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
774 if ($idx != -1 && $i == MAX_PLAYERS) {
777 $this->user[$idx]->sess = uniqid("");
778 $sess = $this->user[$idx]->sess;
782 $this->user[$idx]->sess = $sess;
784 $this->user[$idx]->name = $name_new;
785 $this->user[$idx]->stat = "room";
786 $this->user[$idx]->subst = "standup";
787 $this->user[$idx]->laccwr = time();
788 $this->user[$idx]->bantime = 0;
790 log_main("XXX", sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
792 return ($this->user[$idx]);
798 function standup_update(&$user)
800 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
801 $user_cur = &$this->user[$i];
802 if ($user_cur->sess == '')
805 log_main("STANDUP START", $user_cur->stat);
807 if ($user_cur->stat == 'room') {
808 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($this, $user_cur);
809 if ($user_cur == $user)
810 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
812 log_main("FROM STANDUP", "NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
820 } // end class brisco
824 list($usec, $sec) = explode(' ', microtime());
825 return (float) $sec + ((float) $usec * 100000);
828 function log_main($sess, $log) {
829 if (BRISK_DEBUG != TRUE)
832 $fp = fopen("/tmp/brisk_main.log", 'a');
833 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
837 function log_rd($sess, $log) {
838 if (BRISK_DEBUG != TRUE)
841 $fp = fopen("/tmp/brisk_rd.log", 'a');
842 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
846 function log_rd2($sess, $log) {
847 if (BRISK_DEBUG != TRUE)
850 $fp = fopen("/tmp/brisk_rd2.log", 'a');
851 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
855 function log_send($sess, $log) {
856 if (BRISK_DEBUG != TRUE)
859 $fp = fopen("/tmp/brisk_send.log", 'a');
860 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
864 function log_auth($sess, $log) {
865 if (BRISK_DEBUG != TRUE)
868 $fp = fopen("/tmp/brisk_auth.log", 'a');
869 fwrite($fp, sprintf("SESS: [%d] [%s] [%s]\n", time(), $sess, $log));
873 function log_wr($sess, $log) {
874 if (BRISK_DEBUG != TRUE)
877 $fp = fopen("/tmp/brisk_wr.log", 'a');
878 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
882 function log_load($sess, $log) {
883 if (BRISK_DEBUG != TRUE)
886 $fp = fopen("/tmp/brisk_load.log", 'a');
887 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
891 function log_legal($timecur, $sess, $name, $where, $mesg)
895 $fp = fopen(LEGAL_PATH, 'a');
896 /* Unix time | session | nickname | IP | where was | mesg */
897 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|\n", $timecur, $sess, $name, $_SERVER['REMOTE_ADDR'], $where , $mesg));
905 $brisco = new brisco();
912 // echo "LOCK: ".FTOK_PATH."/main";
914 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
918 // echo "FTOK ".$tok."<br>";
919 if (($res = sem_get($tok)) == FALSE) {
920 echo "SEM_GET FAILED";
923 if (sem_acquire($res))
929 function unlock_data($res)
931 return (sem_release($res));
935 function &load_data()
937 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
942 if ($shm = shm_attach($tok,100000 * TABLES_N)) {
943 if(($bri = @shm_get_var($shm, $tok)) == false) {
944 log_main("XXX", "INIT MAIN DATA");
947 shm_put_var($shm, $tok, $bri);
959 function save_data(&$bri)
967 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
973 if (($shm = shm_attach($tok,100000 * TABLES_N)) == FALSE)
976 if (shm_put_var($shm, $tok, $bri) == FALSE)
978 // log_main("XXX", "QUI CI ARRIVA [".$bri->user[0]->name."]");
988 function table_act_content($isstanding, $sitted, $table, $cur_table)
993 if ($sitted < PLAYERS_N) {
994 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
998 if ($table == $cur_table)
999 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
1006 function table_content($bri, $user, $table_idx)
1012 // Si possono usare i dati nella classe table
1015 $sess = $user->sess;
1016 $table = &$bri->table[$table_idx];
1018 if ($user->stat != 'room')
1021 for ($i = 0 ; $i < $table->player_n ; $i++) {
1022 $user_cur = &$bri->user[$table->player[$i]];
1024 if ($user_cur == $user)
1025 { $hilion = "<b>"; $hilioff = "</b>"; }
1027 { $hilion = ""; $hilioff = ""; }
1029 log_main($bri->user[$e]->name, sprintf("IN TABLE [%d]", $table_idx));
1031 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1034 for ( ; $i < PLAYERS_N ; $i++)
1038 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1043 function standup_content(&$bri, $user)
1048 if ($user->stat != 'room')
1051 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1052 if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
1057 $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1059 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1060 if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
1064 if ($bri->user[$e]->subst == "standup") {
1065 if (($ct % 4) == 0) {
1068 if ($bri->user[$e] == $user)
1069 { $hilion = "<b>"; $hilioff = "</b>"; }
1071 { $hilion = ""; $hilioff = ""; }
1073 $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($bri->user[$e]->name), $hilioff);
1074 if (($ct % 4) == 3) {
1075 $content .= '</tr>';
1080 $content .= '</table>';
1082 $content2 = '<input class=\\"button\\" name=\\"logout\\" value=\\"Esco.\\" onclick=\\"window.onunload = null; act_logout();\\" type=\\"button\\">';
1083 $ret .= sprintf('$("standup").innerHTML = "%s"; $("esco").innerHTML = "%s";',
1084 $content, $content2);
1090 function show_notify($text, $tout, $butt, $w, $h)
1092 log_main("SHOW_NOTIFY", $text);
1093 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
1096 function briscola_show($bri, $table, $user)
1101 if ($table->asta_card == 9)
1102 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
1104 /* text of caller cell */
1105 if ($user->table_pos == $table->asta_win)
1106 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
1108 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
1109 xcape($bri->user[$table->player[$table->asta_win]]->name), $ptnadd);
1111 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1113 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1114 $ret .= sprintf('$("caller").style.visibility = "visible";');
1115 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1116 $ret .= sprintf('$("astalascio").style.visibility = "";');
1117 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1118 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1124 function game_result($asta_pnt, $pnt)
1126 if ($asta_pnt == 61) {
1129 else if ($pnt == 60)
1135 if ($pnt >= $asta_pnt)
1142 function multoval($mult)
1146 else if ($mult == 4)
1147 return ("quadruplo");
1149 return (sprintf("%d-plo", $mult));
1152 function show_table_info(&$bri, &$table, $table_pos)
1154 $user = &$bri->user[$table->player[$table_pos]];
1156 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1157 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1160 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1161 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($bri->user[$table->player[$i]]->name));
1162 $noty .= sprintf("</tr>");
1165 log_main("show_table_info", "pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1167 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1168 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1169 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1170 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1175 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1176 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1177 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1178 $noty .= "</tr></table>";
1180 if ($table->old_reason != "") {
1181 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1184 if ($table->old_win != -1) {
1185 $win = $table->player[$table->old_win];
1186 $fri = $table->player[$table->old_friend];
1188 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1191 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
1192 xcape($bri->user[$win]->name),
1193 xcape($bri->user[$fri]->name));
1194 if ($table->old_pnt == 120) {
1195 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
1198 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
1199 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1200 'più di 60'), $table->old_pnt,
1201 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1205 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
1206 xcape($bri->user[$win]->name));
1207 if ($table->old_pnt == 120) {
1208 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
1211 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
1212 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1213 'più di 60'), $table->old_pnt,
1214 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1218 if ($table->mazzo == $table_pos)
1219 $noty .= "Fai <b>tu</b> il mazzo,";
1221 $unam = xcape($bri->user[$table->player[$table->mazzo]]->name);
1222 $noty .= "Il mazzo a <b>$unam</b>,";
1225 if ($user->subst == 'asta') {
1226 if ($table->asta_win == -1) // auction case
1227 $curplayer = $table->gstart % PLAYERS_N;
1229 $curplayer = $table->asta_win;
1231 else if ($user->subst == 'game') {
1232 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
1236 if ($curplayer == $table_pos) {
1237 $noty .= " tocca a <b>te</b> giocare.";
1240 $unam = xcape($bri->user[$table->player[$curplayer]]->name);
1241 $noty .= " tocca a <b>$unam</b> giocare.";
1244 if ($table->mult > 1) {
1245 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
1247 $noty .= "<hr><br>";
1249 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
1254 function root_wellcome($user)
1256 GLOBAL $root_wellarr;
1258 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
1259 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $root_wellarr[$i]));
1264 function table_wellcome($user)
1266 GLOBAL $table_wellarr;
1268 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
1269 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $table_wellarr[$i]));
1274 function show_room(&$bri, &$user)
1276 $ret .= sprintf('gst.st = %d;', $user->step);
1277 $ret .= sprintf('stat = "%s";', $user->stat);
1279 $ret .= root_wellcome($user);
1280 $ret .= sprintf('subst = "%s";', $user->subst);
1281 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
1282 for ($i = 0 ; $i < TABLES_N ; $i++) {
1283 $ret .= table_content($bri, $user, $i);
1284 $act_content = table_act_content(($user->subst == 'standup'),
1285 $bri->table[$i]->player_n, $i, $user->table);
1286 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
1288 $ret .= standup_content($bri, $user);
1296 is_transition (is from room to table ?)
1297 is_again (is another game)
1299 Examples of $is_transition, $is_again:
1300 from reload of the page: FALSE, FALSE
1301 from sitdown in room: TRUE, FALSE
1302 from table: asta cmd e tutti passano: TRUE, TRUE
1303 from table: fine partita: TRUE, TRUE
1305 function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again)
1307 $table_idx = $user->table;
1308 $table = &$bri->table[$table_idx];
1309 $table_pos = $user->table_pos;
1311 $ret = "table_init();";
1312 $ret .= $table->exitlock_show(&$bri->user, $table_pos);
1314 /* GENERAL STATUS */
1315 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
1316 $sendstep, $user->stat, $user->subst, $table_pos);
1318 $ret .= "background_set();";
1321 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
1322 $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
1323 xcape($bri->user[$table->player[($table_pos)%PLAYERS_N]]->name),
1324 xcape($bri->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
1325 xcape($bri->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
1326 (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
1327 (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
1329 /* NOTIFY FOR THE CARD MAKER */
1330 if ($is_transition) { // && $user->subst == "asta" superfluo
1331 $ret .= show_table_info(&$bri, &$table, $table_pos);
1334 $ret .= table_wellcome($user);
1336 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
1337 $ret .= playsound("cow.mp3");
1342 if ($is_transition) { // && $user->subst == "asta" superfluo
1345 for ($i = 0 ; $i < 8 ; $i++) {
1346 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
1348 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
1349 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
1355 log_rd($sess, "O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
1357 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
1358 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
1359 $table->card[$o]->value : -1),
1360 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
1365 $taked = array(0,0,0,0,0);
1366 $inhand = array(0,0,0,0,0);
1367 $ontabl = array(-1,-1,-1,-1,-1);
1370 for ($i = 0 ; $i < 40 ; $i++) {
1371 if ($table->card[$i]->stat == 'hand') {
1372 if ($table->card[$i]->owner == $table_pos) {
1373 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
1375 $inhand[$table->card[$i]->owner]++;
1377 else if ($table->card[$i]->stat == 'take') {
1378 log_main("Card taked:", $table->card[$i]->value."OWN: ".$table->card[$i]->owner);
1379 $taked[$table->card[$i]->owner]++;
1381 else if ($table->card[$i]->stat == 'table') {
1382 $ontabl[$table->card[$i]->owner] = $i;
1386 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1387 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
1389 log_main("Stat table:", $logg);
1391 /* Set ours cards. */
1393 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
1394 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
1395 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
1396 $oursarg .= ($i == 0 ? "" : ", ")."-1";
1397 $ret .= sprintf('card_setours(%s);', $oursarg);
1399 /* Dispose all cards */
1400 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1401 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
1402 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
1403 $inhand[$i], $taked[$i]);
1405 if ($ontabl[$i] != -1) {
1406 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
1407 $table->card[$ontabl[$i]]->value,
1408 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
1414 if ($user->subst == 'asta') {
1416 /* show users auction status */
1418 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1419 $user_cur = &$bri->user[$table->player[$i]];
1420 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
1421 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
1424 $showst .= ",-2,-2";
1425 $ret .= sprintf('show_astat(%s);', $showst);
1427 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
1428 /* show card chooser */
1429 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
1434 if ($table_pos == ($table->gstart % PLAYERS_N) &&
1435 $table->asta_win == -1)
1436 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1437 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
1439 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1440 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
1444 if ($table->asta_win == -1) { // auction case
1445 if ($table_pos == ($table->gstart % PLAYERS_N))
1446 $ret .= "remark_on();";
1448 $ret .= "remark_off();";
1450 else { // chooseed case
1451 if ($table_pos == $table->asta_win)
1452 $ret .= "remark_on();";
1454 $ret .= "remark_off();";
1457 else if ($user->subst == 'game') {
1459 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
1460 $ret .= "is_my_time = true; remark_on();";
1462 $ret .= "remark_off();";
1464 /* WHO CALL AND WATH */
1465 $ret .= briscola_show($bri, $table, $user);
1471 function calculate_winner(&$table)
1478 $cur_seed = $table->briscola - ($table->briscola % 10);
1480 for ($i = 0 ; $i < 40 ; $i++) {
1481 if ($table->card[$i]->stat != "table")
1484 log_wr($sess, sprintf("Card On table: [%d]", $i));
1486 $v = $table->card[$i]->value;
1487 $ontab[$table->card[$i]->owner] = $v;
1488 $ontid[$table->card[$i]->owner] = $i;
1489 /* se briscola setto il flag */
1490 if (($v - ($v % 10)) == $cur_seed)
1494 if ($briontab == FALSE) {
1495 $cur_win = $table->gstart;
1496 $cur_val = $ontab[$cur_win];
1497 $cur_seed = $cur_val - ($cur_val % 10);
1500 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1501 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
1502 if ($ontab[$i] < $cur_val) {
1503 $cur_val = $ontab[$i];
1509 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1510 $table->card[$ontid[$i]]->owner = $cur_win;
1511 $table->card[$ontid[$i]]->stat = "take";
1516 function calculate_points(&$table)
1518 GLOBAL $G_all_points;
1522 if ($table->asta_pnt == 60)
1523 $table->asta_pnt = 61;
1525 $table->old_reason = "";
1526 $table->old_win = $table->asta_win;
1527 $table->old_friend = $table->friend;
1528 $table->old_asta_pnt = $table->asta_pnt;
1530 for ($i = 0 ; $i < 40 ; $i++) {
1531 $ctt = $table->card[$i]->value % 10;
1532 $own = $table->card[$i]->owner;
1533 if ($own == $table->asta_win || $own == $table->friend)
1534 $pro += $G_all_points[$ctt];
1537 log_wr("XXX", sprintf("PRO: [%d]", $pro));
1540 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
1541 $table->points[$table->points_n % MAX_POINTS] = array();
1542 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1543 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
1545 $table->old_pnt = $pro;
1551 if ($pro >= $table->asta_pnt)
1556 $table->points[$table->points_n % MAX_POINTS] = array();
1557 for ($i = 0 ; $i < 5 ; $i++) {
1558 if ($i == $table->asta_win)
1559 $pt = ($i == $table->friend ? 4 : 2);
1560 else if ($i == $table->friend)
1565 log_wr("XXX", sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
1567 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
1569 log_wr("XXX", sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
1571 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
1572 $table->total[$i] += $pt;
1575 $table->old_pnt = $pro;
1579 function validate_sess($sess)
1581 if (strlen($sess) == SESS_LEN)
1587 function validate_name($name)
1589 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
1591 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
1593 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
1600 function playsound($filename)
1602 return (sprintf('playsound("flasou", "%s");', $filename));
1605 function secstoword($secs)
1607 $mins = floor($secs / 60);
1610 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
1613 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));