2 define(BRISKIN5_PLAYERS_N, 3);
3 define(BRISKIN5_MAX_PLAYERS, BRISKIN5_PLAYERS_N);
4 // define(BRISKIN5_SHM_MIN, (50000 * BRISKIN5_MAX_PLAYERS));
5 define(BRISKIN5_SHM_MIN, 32768);
6 define(BRISKIN5_SHM_MAX, (BRISKIN5_SHM_MIN + 1048576));
7 define(BRISKIN5_SHM_DLT, 32768);
9 $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.');
18 var $comm; // commands for many people
19 var $step; // current step of the comm array
27 function Briskin5 (&$room, $table_idx, $table_token) {
28 $this->user = array();
29 $this->table = array();
31 $this->the_end = FALSE;
32 $this->shm_sz = BRISKIN5_SHM_MIN;
33 if (($this->tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
39 $table =& $room->table[$table_idx];
41 log_wr("Briskin5 constructor");
43 for ($i = 0 ; $i < $table->player_n ; $i++) {
44 $user[$table->player[$i]]->table_token = $table_token;
45 $this->user[$i] =& User::spawn(&$user[$table->player[$i]], 0, $i);
47 $this->table[0] =& Table::spawn(&$table);
48 $this->table_idx = $table_idx;
49 $this->table_token = $table_token;
50 $this->garbage_timeout = 0;
52 log_wr("Briskin5 constructor end");
56 function &get_user($sess, &$idx)
58 GLOBAL $PHP_SELF, $G_false;
60 if (validate_sess($sess)) {
61 for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) {
62 if (strcmp($sess, $this->user[$i]->sess) == 0) {
65 $ret = &$this->user[$i];
69 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
70 // for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++)
71 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
74 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
81 function garbage_manager($force)
84 /* Garbage collector degli utenti in timeout */
87 if ($force || $this->garbage_timeout < $curtime) {
89 for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) {
90 $user_cur = &$this->user[$i];
91 if ($user_cur->sess == "" ||
92 ($user_cur->stat == 'table' && ($user_cur->subst == 'shutdowned' || $user_cur->subst == 'shutdowner')))
95 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
96 log_rd2($user_cur->sess." bin5 AUTO LOGOUT.");
98 if ($user_cur->stat == 'table') {
99 log_auth($user_cur->sess," bin5 Autologout session.");
101 /* SI DELEGA AL garbage_manager principale LA RIMOZIONE DELL'UTENTE
103 $tmp_sess = $user_cur->sess;
104 $user_cur->sess = "";
105 step_unproxy($tmp_sess);
106 $user_cur->name = "";
107 $user_cur->the_end = FALSE;
111 $this->table_wakeup(&$user_cur);
115 log_rd2($user_cur->sess." GARBAGE UPDATED!");
117 $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
130 function &load_data($table_idx, $table_token = "")
132 GLOBAL $G_false, $sess;
136 log_wr("TABLE_IDX ".FTOK_PATH."/table".$table_idx);
139 if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
140 log_main("ftok failed");
145 if (($shm_sz = sharedmem_sz($tok)) == -1) {
146 log_main("shmop_open failed");
150 if (($shm = shm_attach($tok, $shm_sz)) == FALSE)
153 if (($bri = @shm_get_var($shm, $tok)) == FALSE)
156 if ($table_token != "" && $bri->table_token != $table_token) {
157 log_wr("bri->table_token: ".$bri->table_token."table_token: ".$table_token);
172 log_wr("briskin5 load_data failed");
181 function save_data(&$bri)
188 log_main("SAVE BRISKIN5 DATA");
190 if (!isset($bri->tok))
193 while ($bri->shm_sz < BRISKIN5_SHM_MAX) {
194 if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE)
197 if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) {
201 if (shm_remove($shm) === FALSE) {
202 log_only("REMOVE FALLITA");
206 $bri->shm_sz += BRISKIN5_SHM_DLT;
209 log_crit("save data failed!");
219 function destroy_data($table_idx)
225 log_main("DESTROY BRISKIN5 DATA");
228 log_main("DESTROY2 BRISKIN5 DATA");
230 if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1)
233 if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE)
236 if (shmop_delete($shm) == 0) {
237 log_only("REMOVE FALLITA ");
242 log_main("DESTROY2 BRISKIN5 DATA SUCCESS");
244 // log_main("QUI CI ARRIVA [".$bri->user[0]->name."]");
254 function lock_data($table_idx)
258 log_wr("LOCK_DATA ".FTOK_PATH."/table".$table_idx);
259 // echo "LOCK: ".FTOK_PATH."/main";
261 // WARNING monitor this step
262 if (($tok = @ftok(FTOK_PATH."/table".$table_idx, "B")) == -1) {
265 // WARNING monitor this step
266 if (($res = @sem_get($tok)) == FALSE) {
269 if (sem_acquire($res)) {
270 log_lock("LOCK table ".$table_idx."[res: ".$res."]");
274 log_lock("LOCK table ".$table_idx.":FAILED");
279 function unlock_data($res)
283 log_lock("UNLOCK table [res: ".$res."]");
285 return (sem_release($res));
289 function chatt_send(&$user, $mesg)
291 if ($user->stat == 'table') {
292 $table = &$this->table[$user->table];
295 $user_mesg = substr($mesg,6);
299 $dt = date("H:i ", $curtime);
300 if (strncmp($user_mesg, "/nick ", 6) == 0) {
301 log_main($user->sess." chatt_send BEGIN");
303 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
304 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
305 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"Il nickname deve contenere almeno una lettera dell\'alfabeto o una cifra.");', $dt, NICKSERV);
310 $user_mesg = "COMMAND ".$user_mesg;
313 // update local graph
314 // update remote graphs
315 for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) {
316 $user_cur = &$this->user[$i];
317 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
318 if ($user_cur->sess == '')
320 if ($user_cur->name == $name_new) {
321 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
322 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"Nickname <b>%s</b> già in uso.%d");', $dt, NICKSERV, xcape($name_new), $this->table[$user->table]->auth_only == TRUE);
327 if ($i == BRISKIN5_MAX_PLAYERS) {
328 if ($user->flags & USER_FLAG_AUTH && strcasecmp($user->name,$name_new) != 0) {
329 if ($this->table[$user->table]->auth_only == TRUE) {
330 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
331 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>Non puoi cambiare nick a un tavolo per soli autenticati.</b>");', $dt, NICKSERV);
336 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
340 $user->name = $name_new;
342 log_main($user->sess." chatt_send start set");
345 for ($i = 0 ; $i < BRISKIN5_MAX_PLAYERS ; $i++) {
346 log_main($user->sess." chatt_send set loop");
348 $user_cur = &$this->user[$i];
349 if ($user_cur->sess == '')
351 if ($user_cur->stat == 'room') {
352 if ($user->stat == 'room' && $user->subst == 'standup') {
353 $this->standup_update(&$user);
355 else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
356 $user->stat == 'table') {
357 log_main($user->sess." chatt_send pre table update");
359 $this->table_update(&$user);
361 log_main($user->sess." chatt_send post table update");
364 else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
365 $table = &$this->table[$user->table];
367 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
368 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names([%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"]); ',
369 $this->user[$table->player[($user_cur->table_pos) % BRISKIN5_PLAYERS_N]]->flags,
370 xcape($this->user[$table->player[($user_cur->table_pos) % BRISKIN5_PLAYERS_N]]->name),
372 $this->user[$table->player[($user_cur->table_pos+1) % BRISKIN5_PLAYERS_N]]->flags,
373 xcape($this->user[$table->player[($user_cur->table_pos+1) % BRISKIN5_PLAYERS_N]]->name),
375 $this->user[$table->player[($user_cur->table_pos+2) % BRISKIN5_PLAYERS_N]]->flags,
376 xcape($this->user[$table->player[($user_cur->table_pos+2) % BRISKIN5_PLAYERS_N]]->name),
378 (BRISKIN5_PLAYERS_N == 3 ? 0: $this->user[$table->player[($user_cur->table_pos+3) % BRISKIN5_PLAYERS_N]]->flags),
379 (BRISKIN5_PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3) % BRISKIN5_PLAYERS_N]]->name)),
381 (BRISKIN5_PLAYERS_N == 3 ? 0: $this->user[$table->player[($user_cur->table_pos+4) % BRISKIN5_PLAYERS_N]]->flags),
382 (BRISKIN5_PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4) % BRISKIN5_PLAYERS_N]]->name)));
383 if ($user_cur == $user) {
384 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
385 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
386 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";',
387 $itin, xcape($user->name,ENT_COMPAT,"UTF-8"), $itou);
389 $user_cur->step_inc();
395 for ($i = 0 ; $i < ($user->stat == 'room' ? BRISKIN5_MAX_PLAYERS : BRISKIN5_PLAYERS_N) ; $i++) {
396 if ($user->stat == 'room') {
397 $user_cur = &$this->user[$i];
398 if ($user_cur->sess == '' || $user_cur->stat != 'room')
402 $user_cur = &$this->user[$table->player[$i]];
405 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
406 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s", [%d, "%s"],"%s");',
407 $dt, $user->flags, xcape($user->name), xcape($user_mesg));
408 $user_cur->step_inc();
410 log_legal($curtime, $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
414 function table_wakeup(&$user)
416 $table = &$this->table[0];
418 log_main("BRISKIN5_WAKEUP begin function table stat: ".$user->stat." subst: ".$user->subst);
422 log_main("BRISKIN5_WAKEUP from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
424 for ($i = 0 ; $i < $table->player_n ; $i++) {
425 $user_cur = &$this->user[$i];
426 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
428 if ($user_cur == $user)
429 $user_cur->subst = "shutdowner";
431 $user_cur->subst = "shutdowned";
432 $user_cur->laccwr = $curtime;
434 $ret = "gst.st = ".($user_cur->step+1)."; ";
435 $ret .= 'gst.st_loc++; the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|';
437 log_wr($user_cur->sess." BRISKIN5_WAKEUP: ".$ret);
438 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
439 $user_cur->step_inc();
442 $this->the_end = TRUE;
446 * If all players are freezed the room garbage_manager clean up table and users.
448 function is_abandoned()
453 $table = &$this->table[0];
455 for ($i = 0 ; $i < $table->player_n ; $i++) {
456 $user_cur = &$this->user[$i];
458 if ($user_cur->lacc + (EXPIRE_TIME_RD * 2) >= $curtime) {
466 } // end class Briskin5
468 function locshm_exists($tok)
472 if (($id = @shmop_open($tok,"a", 0, 0)) == FALSE) {
473 log_main($tok." SHM NOT exists");
479 log_main($tok." SHM exists");
487 function calculate_points(&$table)
489 GLOBAL $G_all_points;
493 if ($table->asta_pnt == 60)
494 $table->asta_pnt = 61;
496 $table->old_reason = "";
497 $table->old_win = $table->asta_win;
498 $table->old_friend = $table->friend;
499 $table->old_asta_pnt = $table->asta_pnt;
501 for ($i = 0 ; $i < 40 ; $i++) {
502 $ctt = $table->card[$i]->value % 10;
503 $own = $table->card[$i]->owner;
504 if ($own == $table->asta_win || $own == $table->friend)
505 $pro += $G_all_points[$ctt];
508 log_wr(sprintf("PRO: [%d]", $pro));
511 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
512 $table->points[$table->points_n % MAX_POINTS] = array();
513 for ($i = 0 ; $i < PLAYERS_N ; $i++)
514 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
516 $table->old_pnt = $pro;
522 if ($pro >= $table->asta_pnt)
527 $table->points[$table->points_n % MAX_POINTS] = array();
528 for ($i = 0 ; $i < 5 ; $i++) {
529 if ($i == $table->asta_win)
530 $pt = ($i == $table->friend ? 4 : 2);
531 else if ($i == $table->friend)
536 log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
538 $pt = $pt * $sig * $table->mult * ($pro == 120 ? 2 : 1);
540 log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
542 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
543 $table->total[$i] += $pt;
546 $table->old_pnt = $pro;
551 is_transition (is from room to table ?)
552 is_again (is another game)
554 Examples of $is_transition, $is_again:
555 from reload of the page: FALSE, FALSE
556 from sitdown in room: TRUE, FALSE
557 from table: asta cmd e tutti passano: TRUE, TRUE
558 from table: fine partita: TRUE, TRUE
560 function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
562 $table_idx = $user->table;
563 $table = &$room->table[$table_idx];
564 $table_pos = $user->table_pos;
566 $ret = "table_init();";
567 $ret .= $table->exitlock_show(&$room->user, $table_pos);
570 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
571 $sendstep, $user->stat, $user->subst, $table_pos);
573 log_rd(sprintf( 'SHOW_TABLE: gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;', $sendstep, $user->stat, $user->subst, $table_pos));
576 $ret .= "background_set();";
579 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
580 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
582 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
583 $ret .= sprintf('set_names([%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"]); ',
584 $room->user[$table->player[($table_pos)%PLAYERS_N]]->flags,
585 xcape($room->user[$table->player[($table_pos)%PLAYERS_N]]->name),
587 $room->user[$table->player[($table_pos+1)%PLAYERS_N]]->flags,
588 xcape($room->user[$table->player[($table_pos+1)%PLAYERS_N]]->name),
590 $room->user[$table->player[($table_pos+2)%PLAYERS_N]]->flags,
591 xcape($room->user[$table->player[($table_pos+2)%PLAYERS_N]]->name),
593 (PLAYERS_N == 3 ? 0 : $room->user[$table->player[($table_pos+3)%PLAYERS_N]]->flags),
594 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+3)%PLAYERS_N]]->name)),
596 (PLAYERS_N == 3 ? 0 : $room->user[$table->player[($table_pos+4)%PLAYERS_N]]->flags),
597 (PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+4)%PLAYERS_N]]->name)));
599 /* NOTIFY FOR THE CARD MAKER */
600 if ($is_transition) { // && $user->subst == "asta" superfluo
601 $ret .= show_table_info(&$room, &$table, $table_pos);
604 $ret .= table_wellcome($user);
606 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
607 $ret .= playsound("cow.mp3");
612 if ($is_transition) { // && $user->subst == "asta" superfluo
615 for ($i = 0 ; $i < 8 ; $i++) {
616 for ($e = 0 ; $e < PLAYERS_N ; $e++) {
618 for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
619 if ($table->card[$o]->owner == (($e + $table->gstart) % PLAYERS_N)) {
625 log_rd("O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
627 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % PLAYERS_N,
628 $i, ((($e + PLAYERS_N - $table_pos + $table->gstart) % PLAYERS_N) == 0 ?
629 $table->card[$o]->value : -1),
630 ($i == 7 && $e == (PLAYERS_N - 1) ? 1 : 0.5),$i+1);
635 $taked = array(0,0,0,0,0);
636 $inhand = array(0,0,0,0,0);
637 $ontabl = array(-1,-1,-1,-1,-1);
640 for ($i = 0 ; $i < 40 ; $i++) {
641 if ($table->card[$i]->stat == 'hand') {
642 if ($table->card[$i]->owner == $table_pos) {
643 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
645 $inhand[$table->card[$i]->owner]++;
647 else if ($table->card[$i]->stat == 'take') {
648 log_main("Card taked: ".$table->card[$i]->value."OWN: ".$table->card[$i]->owner);
649 $taked[$table->card[$i]->owner]++;
651 else if ($table->card[$i]->stat == 'table') {
652 $ontabl[$table->card[$i]->owner] = $i;
656 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
657 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
659 log_main("Stat table: ".$logg);
661 /* Set ours cards. */
663 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
664 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
665 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
666 $oursarg .= ($i == 0 ? "" : ", ")."-1";
667 $ret .= sprintf('card_setours(%s);', $oursarg);
669 /* Dispose all cards */
670 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
671 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
672 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
673 $inhand[$i], $taked[$i]);
675 if ($ontabl[$i] != -1) {
676 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
677 $table->card[$ontabl[$i]]->value,
678 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
684 if ($user->subst == 'asta') {
686 /* show users auction status */
688 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
689 $user_cur = &$room->user[$table->player[$i]];
690 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
691 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
695 $ret .= sprintf('show_astat(%s);', $showst);
697 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
698 /* show card chooser */
699 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
704 if ($table_pos == ($table->gstart % PLAYERS_N) &&
705 $table->asta_win == -1)
706 $ret .= sprintf('dispose_asta(%d,%d, %s);',
707 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
709 $ret .= sprintf('dispose_asta(%d,%d, %s);',
710 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
714 if ($table->asta_win == -1) { // auction case
715 if ($table_pos == ($table->gstart % PLAYERS_N))
716 $ret .= "remark_on();";
718 $ret .= "remark_off();";
720 else { // chooseed case
721 if ($table_pos == $table->asta_win)
722 $ret .= "remark_on();";
724 $ret .= "remark_off();";
727 else if ($user->subst == 'game') {
729 if (($table->gstart + $table->turn) % PLAYERS_N == $table_pos)
730 $ret .= "is_my_time = true; remark_on();";
732 $ret .= "remark_off();";
734 /* WHO CALL AND WATH */
735 $ret .= briscola_show($room, $table, $user);
739 } // end function show_table(...
741 function calculate_winner(&$table)
748 $cur_seed = $table->briscola - ($table->briscola % 10);
750 for ($i = 0 ; $i < 40 ; $i++) {
751 if ($table->card[$i]->stat != "table")
754 log_wr(sprintf("Card On table: [%d]", $i));
756 $v = $table->card[$i]->value;
757 $ontab[$table->card[$i]->owner] = $v;
758 $ontid[$table->card[$i]->owner] = $i;
759 /* se briscola setto il flag */
760 if (($v - ($v % 10)) == $cur_seed)
764 if ($briontab == FALSE) {
765 $cur_win = $table->gstart;
766 $cur_val = $ontab[$cur_win];
767 $cur_seed = $cur_val - ($cur_val % 10);
770 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
771 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
772 if ($ontab[$i] < $cur_val) {
773 $cur_val = $ontab[$i];
779 for ($i = 0 ; $i < PLAYERS_N ; $i++) {
780 $table->card[$ontid[$i]]->owner = $cur_win;
781 $table->card[$ontid[$i]]->stat = "take"; // Card stat
786 function show_table_info(&$room, &$table, $table_pos)
789 $user = &$room->user[$table->player[$table_pos]];
791 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
792 $noty = sprintf('<table class=\"points\"><tr><th></th>');
795 for ($i = 0 ; $i < PLAYERS_N ; $i++)
796 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($room->user[$table->player[$i]]->name));
797 $noty .= sprintf("</tr>");
800 log_main("show_table_info: pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
802 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
803 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
804 for ($e = 0 ; $e < PLAYERS_N ; $e++)
805 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
810 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
811 for ($e = 0 ; $e < PLAYERS_N ; $e++)
812 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
813 $noty .= "</tr></table>";
815 if ($table->old_reason != "") {
816 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
819 if ($table->old_win != -1) {
820 $win = $table->player[$table->old_win];
821 $fri = $table->player[$table->old_friend];
823 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
826 /* MLANG: "<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>", "hanno fatto <b>cappotto</b> EBBRAVI!.<hr>", "dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>", "<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>", "ha fatto <b>cappotto</b> EBBRAVO!.<hr>", "doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>", ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt : 'più di 60'), $table->old_pnt, ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso" */
827 $noty .= sprintf("<hr>Nell'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>",
828 xcape($room->user[$win]->name),
829 xcape($room->user[$fri]->name));
830 if ($table->old_pnt == 120) {
831 $noty .= sprintf("hanno fatto <b>cappotto</b> EBBRAVI!.<hr>");
834 $noty .= sprintf("dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno <b>%s</b>.<hr>",
835 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
836 'più di 60'), $table->old_pnt,
837 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
841 $noty .= sprintf("<hr>Nell'ultima mano <b>%s</b> si è chiamato in mano,<br>",
842 xcape($room->user[$win]->name));
843 if ($table->old_pnt == 120) {
844 $noty .= sprintf("ha fatto <b>cappotto</b> EBBRAVO!.<hr>");
847 $noty .= sprintf("doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha <b>%s</b>.<hr>",
848 ($table->old_asta_pnt > 61 ? "almeno ".$table->old_asta_pnt :
849 'più di 60'), $table->old_pnt,
850 ($wol == 1 ? "vinto" : ($wol == 0 ? "pareggiato" : "perso")));
854 /* MLANG: "Fai <b>tu</b> il mazzo,", "Il mazzo a <b>$unam</b>," */
855 if ($table->mazzo == $table_pos)
856 $noty .= "Fai <b>tu</b> il mazzo,";
858 $unam = xcape($room->user[$table->player[$table->mazzo]]->name);
859 $noty .= "Il mazzo a <b>$unam</b>,";
862 if ($user->subst == 'asta') {
863 if ($table->asta_win == -1) // auction case
864 $curplayer = $table->gstart % PLAYERS_N;
866 $curplayer = $table->asta_win;
868 else if ($user->subst == 'game') {
869 $curplayer = ($table->gstart + $table->turn) % PLAYERS_N;
872 /* MLANG: " tocca a <b>te</b> giocare.", " tocca a <b>$unam</b> giocare.", " La partita vale <b>%s</b>.", "torna alla partita" */
873 if ($curplayer == $table_pos) {
874 $noty .= " tocca a <b>te</b> giocare.";
877 $unam = xcape($room->user[$table->player[$curplayer]]->name);
878 $noty .= " tocca a <b>$unam</b> giocare.";
881 if ($table->mult > 1) {
882 $noty .= sprintf(" La partita vale <b>%s</b>.", multoval($table->mult));
885 $ret .= show_notify($noty, 3000, "torna alla partita", 500, 400);
886 /* NOTE: show_notify($noty, 3000, "torna alla partita", 500,
887 * 130 + ($table->points_n > 0 ? 50 : 0) +
888 * (120 * ($table->points_n / MAX_POINTS)));
889 * will be used when we refact notify js function following
896 function table_wellcome($user)
898 GLOBAL $table_wellarr;
901 for ($i = 0 ; $i < count($table_wellarr) ; $i++)
902 $ret .= sprintf('chatt_sub("%s", [2, "ChanServ: "],"%s");', "", str_replace('"', '\"', $table_wellarr[$i]));
908 function briscola_show($room, $table, $user)
913 if ($table->asta_card == 9)
914 $ptnadd = sprintf("<br>con %d punti", $table->asta_pnt);
916 /* text of caller cell */
917 if ($user->table_pos == $table->asta_win)
918 $ret .= sprintf('$("callerinfo").innerHTML = "Chiami%s:";', $ptnadd);
920 $ret .= sprintf('$("callerinfo").innerHTML = "Chiama %s%s:";',
921 xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd);
923 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
925 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
926 $ret .= sprintf('$("caller").style.visibility = "visible";');
927 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
928 $ret .= sprintf('$("astalascio").style.visibility = "";');
929 $ret .= sprintf('$("asta").style.visibility = "hidden";');
930 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
936 function game_result($asta_pnt, $pnt)
938 if ($asta_pnt == 61) {
947 if ($pnt >= $asta_pnt)