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");
25 define(MAX_POINTS, 5);
26 define(MAX_PLAYERS, (PLAYERS_N * TABLES_N));
28 define(COMM_GEN_N, 50);
30 define(STREAM_TIMEOUT, 20);
31 define(EXPIRE_TIME_RD, 180);
32 define(EXPIRE_TIME_SMAMMA, 360);
33 // BAN_TIME da allineare anche in commons.js
34 define(BAN_TIME, 900);
35 define(GARBAGE_TIMEOUT, 10);
36 define(NICKSERV, "<i>SERVER</i>");
37 define(BRISK_DEBUG, FALSE);
38 // define(DEBUGGING, "local");
40 $G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 );
41 $G_brisk_version = "0.6.0";
43 $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.'), <b>NOVITA\'</b>: Internet Explorer 6 e 7 supportati (guarda l\'help per maggiori Info).',
44 'Se vuoi iscriverti alla <a target="_blank" href="http://www.milug.org/cgi-bin/mailman/listinfo/ml-briscola">Mailing List</a>, cliccala!' );
45 $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.');
49 <div style=\\"text-align: left; padding: 8px;\\">
50 <b>Descrizione</b><br>
51 Questa è un\'implementazione della briscola in cinque, così come è spiegata su
52 <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>
53 <b>Configurazione del browser.</b><br>
54 Occorre abilitare i cookies.<br>
55 Se usate Internet Explorer dovete anche settare: strumenti->cronologia_esplorazioni->impostazioni ad \\"apertura alla pagina web\\".<br>
57 <b>Uso del sito</b><br>
58 Potete sedervi a un tavolo o rimanere in piedi.<br>
59 Se al vostro tavolo si raggiungono i 5 giocatori inizia automaticamente la partita.<br>
62 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>
63 Chi vince l\'asta dovrà decidere il seme della carta scelta e inizierà la mano.<br>
64 Per giocare le carte dovrete trascinarle nel quadrato al centro del vostro schermo.<br><br>
65 Il vostro turno è sempre segnalato da una cornice verde lampeggiante intorno quadrato al centro del vostro schermo.<br><br>
66 Durante la partita, se vorrete ricaricare la pagina, usate l\'apposito bottone \\"reload\\" in basso a destra.<br>
67 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.
69 <dt><b>Comandi della chat</b>
70 <dd><b>/nick <i><nuovo_nickname></i></b> - cambio di nickname
71 <dd>.. to be continue ..
77 <div id=\\"header\\" class=\\"header\\">
78 <img class=\\"nobo\\" src=\\"img/brisk_logo64.png\\">
79 briscola chiamata in salsa ajax
81 <br><b>version '.$G_brisk_version.'</b><br><br>
82 Copyright 2006-2007 <a href=\\"mailto:brisk@alternativeoutput.it\\">Matteo Nastasi</a> (aka mop)<br><br>';
87 $from = array ( '\\', '@', '|' );
88 $to = array ( '\\\\', '@', '¦' );
90 return (str_replace($from, $to, htmlentities($s,ENT_COMPAT,"UTF-8")));
95 var $value; /* 0 - 39 card value */
96 var $stat; /* 'bunch', 'hand', 'table', 'take' */
97 var $owner; /* (table position 0-4) */
98 // var $pos; /* Pos in hand. */
99 var $x; /* When played the X position on the table of the owner. */
100 var $y; /* When played the Y position on the table of the owner. */
102 function Card($value, $stat, $owner)
104 $this->value = $value;
106 $this->owner = $owner;
109 function assign($stat,$owner)
112 $this->owner = $owner;
115 function setpos($pos)
122 $this->stat = 'table';
127 function take($newown)
129 $this->stat = 'take';
130 $this->owner = $newown;
148 var $points; // points array
149 var $points_n; // number of row of points
164 $this->player = array();
166 $this->card = &$this->bunch_create();
167 $this->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
168 $this->asta_pla_n= -1;
169 $this->asta_card = -1;
170 $this->asta_pnt = -1;
172 $this->points = array( );
174 $this->total = array( 0, 0, 0, 0, 0);
175 $this->asta_win = -1;
176 $this->briscola = -1;
179 $this->old_reason = "";
180 $this->old_asta_pnt = -1;
183 $this->old_friend= -1;
187 function &bunch_create()
191 for ($i = 0 ; $i < 40 ; $i++) {
192 $ret[$i] = new Card($i, 'bunch', 'no_owner');
198 function bunch_make()
200 $ct = array(0,0,0,0,0);
202 mt_srand(make_seed());
204 for ($i = 39 ; $i >= 0 ; $i--)
207 for ($i = 39 ; $i >= 0 ; $i--) {
211 log_main("RND ZERO", "");
216 $this->card[$id]->assign('hand', $owner);
218 $rest[$rn] = $rest[$i];
219 $pubbpos[$rn2] = $pubbpos[$i];
223 function init(&$userarr)
225 $this->mazzo = rand(0,PLAYERS_N-1);
229 $this->old_reason = "";
230 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
231 $this->total[$i] = 0;
232 $user_cur = &$userarr[$this->player[$i]];
233 $user_cur->exitislock = TRUE;
236 log_main("table::init","ci siamo");
239 function game_init(&$userarr)
241 log_rd2($sess,"GSTART 4");
243 $this->gstart = ($this->mazzo+1) % PLAYERS_N;
247 $this->asta_pla_n = PLAYERS_N;
248 $this->asta_card = -1;
249 $this->asta_pnt = 60;
250 $this->asta_win = -1;
251 $this->briscola = -1;
255 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
256 $this->asta_pla[$i] = TRUE;
257 $user_cur = &$userarr[$this->player[$i]];
258 $user_cur->subst = 'asta';
259 $user_cur->asta_card = -2;
260 $user_cur->asta_pnt = -1;
261 $user_cur->handpt = $this->hand_points($i);
262 // SEE function calculate_points(&$table)
268 $this->mazzo = ($this->mazzo + 1) % PLAYERS_N;
271 function getPlayer($idx)
273 return ($this->player[$idx]);
276 function setPlayer($idx, $player)
278 $this->player[$idx] = $player;
281 function user_add($idx)
283 $this->player[$this->player_n] = $idx;
286 return ($this->player_n - 1);
289 function user_rem(&$bri, &$user)
291 $tabpos = $user->table_pos;
293 /* verifico la consistenza dei dati */
294 if ($bri->user[$this->player[$tabpos]] == $user) {
296 /* aggiorna l'array dei giocatori al tavolo. */
297 for ($i = $tabpos ; $i < $this->player_n-1 ; $i++) {
298 $this->player[$i] = $this->player[$i+1];
299 $user_cur = &$bri->user[$this->player[$i]];
300 $user_cur->table_pos = $i;
305 log_main($user->sess, "INCONSISTENCY ON TABLE.");
309 function hand_points($idx)
311 GLOBAL $G_all_points;
315 for ($i = 0 ; $i < 40 ; $i++) {
316 if ($this->card[$i]->owner != $idx)
319 $ctt = $this->card[$i]->value % 10;
320 $tot += $G_all_points[$ctt];
326 function exitlock_show(&$userarr, $table_pos)
328 $ct = $this->exitlock_calc(&$userarr, $table_pos);
330 $ret = sprintf('exitlock_show(%d, %s);', $ct,
331 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
335 function exitlock_calc(&$userarr, $table_pos)
339 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
340 if ($userarr[$this->player[$i]]->exitislock == FALSE)
349 var $name; // name of the user
350 var $sess; // session of the user
351 var $lacc; // last access (for the cleanup)
352 var $laccwr; // last access (for the cleanup)
353 var $bantime; // timeout to temporary ban
354 var $stat; // status (outdoor, room, table, game, ...)
355 var $subst; // substatus for each status
356 var $step; // step of the current status
357 var $trans_step; // step to enable transition between pages (disable == -1)
358 var $comm; // commands array
361 var $handpt; // Total card points at the beginning of the current hand.
362 var $exitislock; // Player can exit from the table ?
363 var $table; // id of the current table (if in table state)
364 var $table_pos; // idx on the table
366 function User($name, $sess, $stat = "", $subst = "", $table = -1) {
369 $this->lacc = time();
370 $this->laccwr = time();
373 $this->subst = $subst;
375 $this->trans_step = -1;
376 $this->comm = array();
377 $this->asta_card = -2;
378 $this->asta_pnt = -1;
380 $this->exitislock = TRUE;
382 $this->table = $table;
389 var $comm; // commands for many people
390 var $step; // current step of the comm array
391 var $garbage_timeout;
394 $this->user = array();
396 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
397 $this->user[$i] = new User("", "");
399 for ($i = 0 ; $i < TABLES_N ; $i++)
400 $this->table[$i] = new Table();
401 $this->garbage_timeout = 0;
404 function garbage_manager($force)
407 /* Garbage collector degli utenti in timeout */
409 if ($force || $this->garbage_timeout < $curtime) {
411 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
412 $user_cur = &$this->user[$i];
413 if ($user_cur->sess == "")
416 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
417 log_rd2($user_cur->sess, "AUTO LOGOUT.");
419 if ($user_cur->stat == 'table' || $user_cur->stat == 'room') {
420 log_auth($user_cur->sess, "Autologout session.");
422 $user_cur->sess = "";
423 $user_cur->name = "";
424 $user_cur->the_end = FALSE;
426 log_rd2($user_cur->sess, "AUTO LOGOUT.");
427 if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table')
428 $this->room_wakeup(&$user_cur);
429 else if ($user_cur->subst == 'standup')
430 $this->room_outstandup(&$user_cur);
432 log_rd2($sess, "LOGOUT FROM WHAT ???");
436 if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi
437 if ($user_cur->stat == 'room' && $user_cur->subst == 'sitdown') {
438 $this->room_wakeup(&$user_cur);
439 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
440 $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);
445 log_rd2($user_cur->sess, "GARBAGE UPDATED!");
447 $this->garbage_timeout = time() + GARBAGE_TIMEOUT;
452 function room_wakeup(&$user)
454 $table_idx = $user->table;
455 $table = &$this->table[$table_idx];
457 log_main("WAKEUP", "begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst);
461 $from_table = ($user->stat == "table");
463 log_main("WAKEUP", "from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
465 for ($i = 0 ; $i < $table->player_n ; $i++) {
466 $user_cur = &$this->user[$table->player[$i]];
467 log_main("PREIMPOST", "INLOOP name: ".$user_cur->name);
469 if ($user_cur != $user) {
470 $user_cur->stat = "room";
471 $user_cur->subst = "sitdown";
472 $user_cur->laccwr = $curtime;
474 else if ($user->sess != "") {
475 $user_cur->stat = "room";
476 $user_cur->subst = "standup";
477 $user_cur->laccwr = $curtime;
478 $user_cur->table = -1;
483 $user->stat = "room";
484 $user->subst = "standup";
485 $user->laccwr = $curtime;
487 /* aggiorna l'array dei giocatori al tavolo. */
488 $table->user_rem(&$this, &$user);
490 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
491 $user_cur = &$this->user[$i];
492 if ($user_cur->sess == '' || $user_cur->stat != 'room')
495 log_main("VALORI", "name: ".$user_cur->name."from_table: ".$from_table." tab: ".$user_cur->table." taix: ".$table_idx." ucur: ".$user_cur." us: ".$user);
497 $ret = "gst.st = ".($user_cur->step+1)."; ";
498 if ($from_table && ($user_cur->table == $table_idx || $user_cur == $user)) {
499 $ret .= 'gst.st_loc++; the_end=true; window.onunload = null; document.location.assign("index.php");|';
500 // $ret .= 'gst.st_loc++; document.location.assign("index.php");|';
501 log_main("DOCUMENT.index.php", "from table");
503 else if ($user_cur->stat == "room") {
504 log_main("DOCUMENT.index.php", "from table");
506 $ret .= table_content($this, $user_cur, $table_idx);
507 $ret .= standup_content($this, $user_cur);
509 $act_content = table_act_content(FALSE, 0, $e, $user->table);
510 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
513 if ($user_cur == $user) {
514 // set the new status
515 $ret .= 'subst = "standup"; ';
516 // clean the action buttons in other tables
517 for ($e = 0 ; $e < TABLES_N ; $e++) {
518 if ($this->table[$e]->player_n < PLAYERS_N)
519 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, table_act_content(TRUE, 0, $e, $user->table));
523 $act_content = table_act_content(($user_cur->subst == 'standup'), $table->player_n, $table_idx, $user_cur->table);
524 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
527 log_wr($user_cur->sess, "ROOM_WAKEUP: ".$ret);
528 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
536 function room_outstandup(&$user)
538 $this->room_sitdown(&$user, -1);
541 function table_update(&$user)
543 log_main("table_update", "pre - USER: ".$user->name);
545 $table_idx = $user->table;
548 $table = &$this->table[$table_idx];
550 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
552 $user_cur = &$this->user[$i];
553 if ($user_cur->sess == '' || $user_cur->stat != 'room')
556 $ret = "gst.st = ".($user_cur->step+1)."; ";
558 $ret .= table_content($this, $user_cur, $table_idx);
560 if ($user_cur == $user) {
561 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
563 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
567 log_main("table_update", "post");
570 function room_sitdown(&$user, $table_idx)
572 log_main("room_sitdown", ($user == FALSE ? "USER: FALSE" : "USER: ".$user->name));
575 $table = &$this->table[$table_idx];
577 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
579 $user_cur = &$this->user[$i];
580 if ($user_cur->sess == '' || $user_cur->stat != 'room')
583 $ret = "gst.st = ".($user_cur->step+1)."; ";
585 $ret .= table_content($this, $user_cur, $table_idx);
586 $ret .= standup_content($this, $user_cur);
588 if ($user_cur == $user) {
589 $ret .= 'subst = "sitdown"; ';
590 // clean the action buttons in other tables
591 for ($e = 0 ; $e < TABLES_N ; $e++) {
592 $act_content = table_act_content(FALSE, 0, $e, $user_cur->table);
593 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $e, $act_content);
596 else if ($table_idx > -1) {
597 if ($table->player_n == PLAYERS_N) {
598 $act_content = table_act_content(($user_cur->subst == 'standup'), PLAYERS_N, $table_idx, $user_cur->table);
599 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $table_idx, $act_content);
602 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
607 function chatt_send(&$user, $mesg)
609 if ($user->stat == 'table') {
610 $table = &$this->table[$user->table];
613 $user_mesg = substr($mesg,6);
615 $dt = date("H:i ",time());
616 if (strncmp($user_mesg, "/nick ", 6) == 0) {
617 log_main($user->sess, "chatt_send BEGIN");
619 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
620 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
621 $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));
626 $user_mesg = "COMMAND ".$user_mesg;
629 // update local graph
630 // update remote graphs
631 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
632 $user_cur = &$this->user[$i];
633 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
634 if ($user_cur->sess == '')
636 if ($user_cur->name == $name_new) {
637 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
638 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
643 if ($i == MAX_PLAYERS) {
644 $user->name = $name_new;
646 log_main($user->sess, "chatt_send start set");
649 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
650 log_main($user->sess, "chatt_send set loop");
652 $user_cur = &$this->user[$i];
653 if ($user_cur->sess == '')
655 if ($user_cur->stat == 'room') {
656 if ($user->stat == 'room' && $user->subst == 'standup') {
657 $this->standup_update(&$user);
659 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
660 $user->stat == 'table') {
661 log_main($user->sess, "chatt_send pre table update");
663 $this->table_update(&$user);
665 log_main($user->sess, "chatt_send post table update");
668 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
669 $table = &$this->table[$user->table];
671 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
672 $user_cur->comm[$user_cur->step % COMM_N] = sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
673 xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
674 xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
675 xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
676 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
677 (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
678 if ($user_cur == $user)
679 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
680 xcape($user->name,ENT_COMPAT,"UTF-8"));
687 for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
688 if ($user->stat == 'room') {
689 $user_cur = &$this->user[$i];
690 if ($user_cur->sess == '' || $user_cur->stat != 'room')
694 $user_cur = &$this->user[$table->player[$i]];
697 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
698 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
699 $dt.xcape($user->name), xcape($user_mesg));
705 function &get_user($sess, &$idx)
709 if (strlen($sess) == SESS_LEN) {
710 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
711 if (strcmp($sess, $this->user[$i]->sess) == 0) {
714 return ($this->user[$i]);
717 log_main($sess, sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
718 // for ($i = 0 ; $i < MAX_PLAYERS ; $i++)
719 // log_main($sess, sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
722 log_main($sess, sprintf("get_user: Wrong strlen [%s]",$sess));
728 * function &add_user(&$bri, &$sess, &$idx, $name)
731 * if ($idx != -1 && ret == FALSE) => duplicated nick
732 * if ($idx == -2 && ret == FALSE) => invalid name
733 * if ($idx == -1 && ret == FALSE) => no space left
734 * if (ret == TRUE) => SUCCESS
736 function &add_user(&$sess, &$idx, $name)
741 if (($name_new = validate_name($name)) == FALSE) {
746 log_auth("XXX", sprintf("ARRIVA: [%s]", $sess));
747 if (validate_sess($sess) == FALSE)
750 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
752 if (strcmp($sess, $this->user[$i]->sess) == 0) {
756 if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) {
759 if (strcmp($this->user[$i]->name, $name_new) == 0) {
767 log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
769 if ($idx != -1 && $i == MAX_PLAYERS) {
772 $this->user[$idx]->sess = uniqid("");
773 $sess = $this->user[$idx]->sess;
777 $this->user[$idx]->sess = $sess;
779 $this->user[$idx]->name = $name_new;
780 $this->user[$idx]->stat = "room";
781 $this->user[$idx]->subst = "standup";
782 $this->user[$idx]->laccwr = time();
784 log_main("XXX", sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new));
786 return ($this->user[$idx]);
792 function standup_update(&$user)
794 for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
795 $user_cur = &$this->user[$i];
796 if ($user_cur->sess == '')
799 log_main("STANDUP START", $user_cur->stat);
801 if ($user_cur->stat == 'room') {
802 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ".standup_content($this, $user_cur);
803 if ($user_cur == $user)
804 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>: ";', xcape($user->name));
806 log_main("FROM STANDUP", "NAME: ".$user_cur->name." SENDED: ".$user_cur->comm[$user_cur->step % COMM_N]);
814 } // end class brisco
818 list($usec, $sec) = explode(' ', microtime());
819 return (float) $sec + ((float) $usec * 100000);
822 function log_main($sess, $log) {
823 if (BRISK_DEBUG != TRUE)
826 $fp = fopen("/tmp/brisk_main.log", 'a');
827 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
831 function log_rd($sess, $log) {
832 if (BRISK_DEBUG != TRUE)
835 $fp = fopen("/tmp/brisk_rd.log", 'a');
836 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
840 function log_rd2($sess, $log) {
841 if (BRISK_DEBUG != TRUE)
844 $fp = fopen("/tmp/brisk_rd2.log", 'a');
845 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
849 function log_send($sess, $log) {
850 if (BRISK_DEBUG != TRUE)
853 $fp = fopen("/tmp/brisk_send.log", 'a');
854 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
858 function log_auth($sess, $log) {
859 if (BRISK_DEBUG != TRUE)
862 $fp = fopen("/tmp/brisk_auth.log", 'a');
863 fwrite($fp, sprintf("SESS: [%d] [%s] [%s]\n", time(), $sess, $log));
867 function log_wr($sess, $log) {
868 if (BRISK_DEBUG != TRUE)
871 $fp = fopen("/tmp/brisk_wr.log", 'a');
872 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
876 function log_load($sess, $log) {
877 if (BRISK_DEBUG != TRUE)
880 $fp = fopen("/tmp/brisk_load.log", 'a');
881 fwrite($fp, sprintf("SESS: [%s] [%s]\n", $sess, $log));
887 $brisco = new brisco();
894 // echo "LOCK: ".FTOK_PATH."/main";
896 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
900 // echo "FTOK ".$tok."<br>";
901 if (($res = sem_get($tok)) == FALSE) {
902 echo "SEM_GET FAILED";
905 if (sem_acquire($res))
911 function unlock_data($res)
913 return (sem_release($res));
917 function &load_data()
919 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1) {
924 if ($shm = shm_attach($tok,100000 * TABLES_N)) {
925 if(($bri = @shm_get_var($shm, $tok)) == false) {
926 log_main("XXX", "INIT MAIN DATA");
929 shm_put_var($shm, $tok, $bri);
941 function save_data(&$bri)
949 if (($tok = ftok(FTOK_PATH."/main", "B")) == -1)
955 if (($shm = shm_attach($tok,100000 * TABLES_N)) == FALSE)
958 if (shm_put_var($shm, $tok, $bri) == FALSE)
960 // log_main("XXX", "QUI CI ARRIVA [".$bri->user[0]->name."]");
970 function table_act_content($isstanding, $sitted, $table, $cur_table)
975 if ($sitted < PLAYERS_N) {
976 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xhenter%d\\" value=\\"Mi siedo.\\" onclick=\\"act_sitdown(%d);\\">', $table, $table);
980 if ($table == $cur_table)
981 $ret = sprintf('<input type=\\"button\\" class=\\"button\\" name=\\"xwakeup\\" value=\\"Mi alzo.\\" onclick=\\"act_wakeup();\\">');
988 function table_content($bri, $user, $table_idx)
994 // Si possono usare i dati nella classe table
998 $table = &$bri->table[$table_idx];
1000 if ($user->stat != 'room')
1003 for ($i = 0 ; $i < $table->player_n ; $i++) {
1004 $user_cur = &$bri->user[$table->player[$i]];
1006 if ($user_cur == $user)
1007 { $hilion = "<b>"; $hilioff = "</b>"; }
1009 { $hilion = ""; $hilioff = ""; }
1011 log_main($bri->user[$e]->name, sprintf("IN TABLE [%d]", $table_idx));
1013 $content .= sprintf("%s%s%s<br>",$hilion, xcape($user_cur->name), $hilioff);
1016 for ( ; $i < PLAYERS_N ; $i++)
1020 $ret .= sprintf('$("table%d").innerHTML = "%s";', $table_idx, $content);
1025 function standup_content(&$bri, $user)
1030 if ($user->stat != 'room')
1033 for ($e = 0 , $ct = 0 ; $ct < 4 && $e < MAX_PLAYERS ; $e++) {
1034 if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
1039 $content .= sprintf('<table cols=\\"%d\\" class=\\"table_standup\\">', $ct);
1041 for ($e = 0 , $ct = 0 ; $e < MAX_PLAYERS ; $e++) {
1042 if ($bri->user[$e]->sess == "" || $bri->user[$e]->stat != "room" || $bri->user[$e]->name == "")
1046 if ($bri->user[$e]->subst == "standup") {
1047 if (($ct % 4) == 0) {
1050 if ($bri->user[$e] == $user)
1051 { $hilion = "<b>"; $hilioff = "</b>"; }
1053 { $hilion = ""; $hilioff = ""; }
1055 $content .= sprintf('<td class=\\"room_standup\\">%s%s%s</td>',$hilion, xcape($bri->user[$e]->name), $hilioff);
1056 if (($ct % 4) == 3) {
1057 $content .= '</tr>';
1062 $content .= '</table>';
1064 $content2 = '<input class=\\"button\\" name=\\"logout\\" value=\\"Esco.\\" onclick=\\"window.onunload = null; act_logout();\\" type=\\"button\\">';
1065 $ret .= sprintf('$("standup").innerHTML = "%s"; $("esco").innerHTML = "%s";',
1066 $content, $content2);
1072 function show_notify($text, $tout, $butt, $w, $h)
1074 log_main("SHOW_NOTIFY", $text);
1075 return sprintf('var noti = new notify(gst,"%s",%d,"%s",%d,%d);', $text, $tout, $butt, $w, $h);
1078 function briscola_show($bri, $table, $user)
1083 if ($table->asta_card == 9)
1084 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
1086 /* text of caller cell */
1087 if ($user->table_pos == $table->asta_win)
1088 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
1090 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
1091 xcape($bri->user[$table->player[$table->asta_win]]->name), $ptnadd);
1093 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1095 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1096 $ret .= sprintf('$("caller").style.visibility = "visible";');
1097 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1098 $ret .= sprintf('$("astalascio").style.visibility = "";');
1099 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1100 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1106 function game_result($asta_pnt, $pnt)
1108 if ($asta_pnt == 61) {
1111 else if ($pnt == 60)
1117 if ($pnt >= $asta_pnt)
1124 function multoval($mult)
1128 else if ($mult == 4)
1129 return ("quadruplo");
1131 return (sprintf("%d-plo", $mult));
1134 function show_table_info(&$bri, &$table, $table_pos)
1136 $user = &$bri->user[$table->player[$table_pos]];
1138 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1139 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1142 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1143 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($bri->user[$table->player[$i]]->name));
1144 $noty .= sprintf("</tr>");
1147 log_main("show_table_info", "pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1149 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1150 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1151 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1152 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1157 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1158 for ($e = 0 ; $e < PLAYERS_N ; $e++)
1159 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1160 $noty .= "</tr></table>";
1162 if ($table->old_reason != "") {
1163 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1166 if ($table->old_win != -1) {
1167 $win = $table->player[$table->old_win];
1168 $fri = $table->player[$table->old_friend];
1170 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1173 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
1174 xcape($bri->user[$win]->name),
1175 xcape($bri->user[$fri]->name));
1176 if ($table->old_pnt == 120) {
1177 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
1180 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
1181 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1182 'più di 60'), $table->old_pnt,
1183 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1187 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
1188 xcape($bri->user[$win]->name));
1189 if ($table->old_pnt == 120) {
1190 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
1193 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
1194 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
1195 'più di 60'), $table->old_pnt,
1196 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
1200 if ($table->mazzo == $table_pos)
1201 $noty .= "Fai <b>tu</b> il mazzo,";
1203 $unam = xcape($bri->user[$table->player[$table->mazzo]]->name);
1204 $noty .= "Il mazzo a <b>$unam</b>,";
1207 if ($user->subst == 'asta') {
1208 if ($table->asta_win == -1) // auction case
1209 $curplayer = $table->gstart % PLAYERS_N;
1211 $curplayer = $table->asta_win;
1213 else if ($user->subst == 'game') {
1214 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
1218 if ($curplayer == $table_pos) {
1219 $noty .= " tocca a <b>te</b> giocare.";
1222 $unam = xcape($bri->user[$table->player[$curplayer]]->name);
1223 $noty .= " tocca a <b>$unam</b> giocare.";
1226 if ($table->mult > 1) {
1227 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
1229 $noty .= "<hr><br>";
1231 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
1236 function root_wellcome($user)
1238 GLOBAL $root_wellarr;
1240 for ($i = 0 ; $i < count($root_wellarr) ; $i++)
1241 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $root_wellarr[$i]));
1246 function table_wellcome($user)
1248 GLOBAL $table_wellarr;
1250 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
1251 $ret .= sprintf('chatt_sub("ChanServ: ","%s");', str_replace('"', '\"', $table_wellarr[$i]));
1256 function show_room(&$bri, &$user)
1258 $ret .= sprintf('gst.st = %d;', $user->step);
1259 $ret .= sprintf('stat = "%s";', $user->stat);
1261 $ret .= root_wellcome($user);
1262 $ret .= sprintf('subst = "%s";', $user->subst);
1263 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
1264 for ($i = 0 ; $i < TABLES_N ; $i++) {
1265 $ret .= table_content($bri, $user, $i);
1266 $act_content = table_act_content(($user->subst == 'standup'),
1267 $bri->table[$i]->player_n, $i, $user->table);
1268 $ret .= sprintf('$("table_act%d").innerHTML = "%s";', $i, $act_content);
1270 $ret .= standup_content($bri, $user);
1278 is_transition (is from room to table ?)
1279 is_again (is another game)
1281 Examples of $is_transition, $is_again:
1282 from reload of the page: FALSE, FALSE
1283 from sitdown in room: TRUE, FALSE
1284 from table: asta cmd e tutti passano: TRUE, TRUE
1285 from table: fine partita: TRUE, TRUE
1287 function show_table(&$bri, &$user, $sendstep, $is_transition, $is_again)
1289 $table_idx = $user->table;
1290 $table = &$bri->table[$table_idx];
1291 $table_pos = $user->table_pos;
1293 $ret = "table_init();";
1294 $ret .= $table->exitlock_show(&$bri->user, $table_pos);
1296 /* GENERAL STATUS */
1297 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
1298 $sendstep, $user->stat, $user->subst, $table_pos);
1300 $ret .= "background_set();";
1303 $ret .= sprintf('$("myname").innerHTML = "<b>%s</b>";', xcape($user->name,ENT_COMPAT,"UTF-8"));
1304 $ret .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
1305 xcape($bri->user[$table->player[($table_pos)%PLAYERS_N]]->name),
1306 xcape($bri->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
1307 xcape($bri->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
1308 (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
1309 (PLAYERS_N == 3 ? "" : xcape($bri->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
1311 /* NOTIFY FOR THE CARD MAKER */
1312 if ($is_transition) { // && $user->subst == "asta" superfluo
1313 $ret .= show_table_info(&$bri, &$table, $table_pos);
1316 $ret .= table_wellcome($user);
1318 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
1319 $ret .= playsound("cow.mp3");
1324 if ($is_transition) { // && $user->subst == "asta" superfluo
1327 for ($i = 0 ; $i < 8 ; $i++) {
1328 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
1330 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
1331 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
1337 log_rd($sess, "O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
1339 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
1340 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
1341 $table->card[$o]->value : -1),
1342 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
1347 $taked = array(0,0,0,0,0);
1348 $inhand = array(0,0,0,0,0);
1349 $ontabl = array(-1,-1,-1,-1,-1);
1352 for ($i = 0 ; $i < 40 ; $i++) {
1353 if ($table->card[$i]->stat == 'hand') {
1354 if ($table->card[$i]->owner == $table_pos) {
1355 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
1357 $inhand[$table->card[$i]->owner]++;
1359 else if ($table->card[$i]->stat == 'take') {
1360 log_main("Card taked:", $table->card[$i]->value."OWN: ".$table->card[$i]->owner);
1361 $taked[$table->card[$i]->owner]++;
1363 else if ($table->card[$i]->stat == 'table') {
1364 $ontabl[$table->card[$i]->owner] = $i;
1368 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1369 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
1371 log_main("Stat table:", $logg);
1373 /* Set ours cards. */
1375 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
1376 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
1377 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
1378 $oursarg .= ($i == 0 ? "" : ", ")."-1";
1379 $ret .= sprintf('card_setours(%s);', $oursarg);
1381 /* Dispose all cards */
1382 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1383 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
1384 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
1385 $inhand[$i], $taked[$i]);
1387 if ($ontabl[$i] != -1) {
1388 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
1389 $table->card[$ontabl[$i]]->value,
1390 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
1396 if ($user->subst == 'asta') {
1398 /* show users auction status */
1400 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1401 $user_cur = &$bri->user[$table->player[$i]];
1402 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
1403 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
1406 $showst .= ",-2,-2";
1407 $ret .= sprintf('show_astat(%s);', $showst);
1409 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
1410 /* show card chooser */
1411 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
1416 if ($table_pos == ($table->gstart % PLAYERS_N) &&
1417 $table->asta_win == -1)
1418 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1419 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
1421 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1422 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
1426 if ($table->asta_win == -1) { // auction case
1427 if ($table_pos == ($table->gstart % PLAYERS_N))
1428 $ret .= "remark_on();";
1430 $ret .= "remark_off();";
1432 else { // chooseed case
1433 if ($table_pos == $table->asta_win)
1434 $ret .= "remark_on();";
1436 $ret .= "remark_off();";
1439 else if ($user->subst == 'game') {
1441 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
1442 $ret .= "is_my_time = true; remark_on();";
1444 $ret .= "remark_off();";
1446 /* WHO CALL AND WATH */
1447 $ret .= briscola_show($bri, $table, $user);
1453 function calculate_winner(&$table)
1460 $cur_seed = $table->briscola - ($table->briscola % 10);
1462 for ($i = 0 ; $i < 40 ; $i++) {
1463 if ($table->card[$i]->stat != "table")
1466 log_wr($sess, sprintf("Card On table: [%d]", $i));
1468 $v = $table->card[$i]->value;
1469 $ontab[$table->card[$i]->owner] = $v;
1470 $ontid[$table->card[$i]->owner] = $i;
1471 /* se briscola setto il flag */
1472 if (($v - ($v % 10)) == $cur_seed)
1476 if ($briontab == FALSE) {
1477 $cur_win = $table->gstart;
1478 $cur_val = $ontab[$cur_win];
1479 $cur_seed = $cur_val - ($cur_val % 10);
1482 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1483 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
1484 if ($ontab[$i] < $cur_val) {
1485 $cur_val = $ontab[$i];
1491 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
1492 $table->card[$ontid[$i]]->owner = $cur_win;
1493 $table->card[$ontid[$i]]->stat = "take";
1498 function calculate_points(&$table)
1500 GLOBAL $G_all_points;
1504 if ($table->asta_pnt == 60)
1505 $table->asta_pnt = 61;
1507 $table->old_reason = "";
1508 $table->old_win = $table->asta_win;
1509 $table->old_friend = $table->friend;
1510 $table->old_asta_pnt = $table->asta_pnt;
1512 for ($i = 0 ; $i < 40 ; $i++) {
1513 $ctt = $table->card[$i]->value % 10;
1514 $own = $table->card[$i]->owner;
1515 if ($own == $table->asta_win || $own == $table->friend)
1516 $pro += $G_all_points[$ctt];
1519 log_wr("XXX", sprintf("PRO: [%d]", $pro));
1522 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
1523 $table->points[$table->points_n % MAX_POINTS] = array();
1524 for ($i = 0 ; $i < PLAYERS_N ; $i++)
1525 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
1527 $table->old_pnt = $pro;
1533 if ($pro >= $table->asta_pnt)
1538 $table->points[$table->points_n % MAX_POINTS] = array();
1539 for ($i = 0 ; $i < 5 ; $i++) {
1540 if ($i == $table->asta_win)
1541 $pt = ($i == $table->friend ? 4 : 2);
1542 else if ($i == $table->friend)
1547 log_wr("XXX", sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
1549 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
1551 log_wr("XXX", sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
1553 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
1554 $table->total[$i] += $pt;
1557 $table->old_pnt = $pro;
1561 function validate_sess($sess)
1563 if (strlen($sess) == SESS_LEN)
1569 function validate_name($name)
1571 $name_new = str_replace(' ', '_', substr(trim($name),0,12));
1573 for ($i = 0 ; $i < strlen($name_new) ; $i++) {
1575 if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
1582 function playsound($filename)
1584 return (sprintf('playsound("flasou", "%s");', $filename));
1587 function secstoword($secs)
1589 $mins = floor($secs / 60);
1592 $ret = sprintf("%d minut%s%s", $mins, ($mins > 1 ? "i" : "o"), ($secs > 0 ? " e " : ""));
1595 $ret .= sprintf("%d second%s", $secs, ($secs > 1 ? "i" : "o"));