5 * Copyright (C) 2006-2011 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
24 define(BIN5_PLAYERS_N, 3);
25 define(BIN5_MAX_PLAYERS, BIN5_PLAYERS_N);
26 // define(BIN5_SHM_MIN, (50000 * BIN5_MAX_PLAYERS));
27 define(BIN5_SHM_MIN, 32768);
28 define(BIN5_SHM_MAX, (BIN5_SHM_MIN + 1048576));
29 define(BIN5_SHM_DLT, 32768);
30 define(BIN5_PROXY_PATH, PROXY_PATH."/bin5");
32 $mlang_bin5_bin5 = array(
33 'info_part' => array( 'it' => '<hr>Nell\'ultima mano ha chiamato <b>%s</b>, il socio era <b>%s</b>,<br>',
34 'en' => '<hr>In the last hand the declarer was <b>%s</b>, the partner was <b>%s</b>,<br>'),
35 'info_capp' => array( 'it' => 'hanno fatto <b>cappotto</b> EBBRAVI!.<br>',
36 'en' => 'and they made <b>capot</b> WELL DONE!.<br>'),
37 'info_pnt' => array( 'it' => 'dovevano fare <b>%s</b> punti e ne hanno fatti <b>%d</b>: hanno %s.<br>',
38 'en' => 'they had to do <b>%s</b> points and they had made <b>%d</b>: they have %s.<br>'),
39 'info_alea' => array( 'it' => 'almeno ',
41 'info_more' => array( 'it' => 'più di 60',
43 'info_win' => array( 'it' => '<b>vinto</b>',
44 'en' => '<b>win</b>'),
45 'info_peer' => array( 'it' => '<b>pareggiato</b>',
46 'en' => '<b>drew</b>'),
47 'info_lost' => array( 'it' => '<b>perso</b>',
48 'en' => '<b>lost</b>'),
50 'info_alon' => array( 'it' => '<hr>Nell\'ultima partita <b>%s</b> si è chiamato in mano,<br>',
51 'en' => '<hr>In the last hand <b>%s</b> play alone against each other,<br>'),
52 'info_apnt' => array( 'it' => 'doveva fare <b>%s</b> punti e ne ha fatti <b>%d</b>: ha %s.<br>',
53 'en' => 'he/she had to do <b>%s</b> points and they had made <b>%d</b>: he/she had %s.<br>'),
54 'info_acap' => array( 'it' => 'ha fatto <b>cappotto</b> EBBRAVO!.<hr>',
55 'en' => 'and he/she made <b>capot</b> WELL DONE!.<hr>'),
57 'info_omul' => array( 'it' => ' La partita valeva <b>%s</b>.',
58 'en' => ' EN: The game was worth <b>%s</b>.' ),
60 'info_yturn'=> array( 'it' => ' tocca a <b>te</b> giocare.',
61 'en' => ' it\'s <b>your</b> turn.'),
62 'info_turn' => array( 'it' => 'tocca a <b>%s</b> giocare.',
63 'en' => 'it\'s the <b>%s</b>\'s turn.'),
64 'info_mult' => array( 'it' => ' La partita vale <b>%s</b>.',
65 'en' => ' The game worth <b>%s</b>.' ),
66 'info_yshuf'=> array( 'it' => 'Fai <b>tu</b> il mazzo, ',
67 'en' => 'It\'s <b>your</b> shuffled the cards, '),
68 'info_shuf' => array( 'it' => 'Il mazzo a <b>%s</b>, ',
69 'en' => '<b>%s</b> shuffled the cards, '),
70 'btn_bkgame'=> array( 'it' => 'torna alla partita',
71 'en' => 'back to the game'),
72 'call_wptn' => array( 'it' => '<br>con %d punti',
73 'en' => '<br>with %d points'),
74 'call_ycall'=> array( 'it' => 'Chiami%s:',
76 'call_call' => array( 'it' => 'Chiama %s%s:',
77 'en' => 'The declarer is %s%s:')
83 $table_wellarr = Array( 'it' => Array ( 'Benvenuto al tavolo. Se almeno tre giocatori non sbloccano l\'uscita cliccando il lucchetto, chi esce non può risedersi a un qualunque tavolo per '.floor(BAN_TIME/60).' minuti.'),
84 'en' => Array ( 'EN 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.') );
86 function multoval($mult)
91 return ($G_lang == 'en' ? 'double' : 'doppio');
93 return ($G_lang == 'en' ? 'triple' : 'triplo');
95 return ($G_lang == 'en' ? 'quadruple' : 'quadruplo');
97 return (sprintf(($G_lang == 'en' ? "%d-ple" : "%d-plo"), $mult));
102 var $value; /* 0 - 39 card value */
103 var $stat; /* 'bunch', 'hand', 'table', 'take' */
104 var $owner; /* (table position 0-4) */
105 // var $pos; /* Pos in hand. */
106 var $x; /* When played the X position on the table of the owner. */
107 var $y; /* When played the Y position on the table of the owner. */
109 function Card($value, $stat, $owner)
111 $this->value = $value;
112 $this->stat = $stat; // Card stat
113 $this->owner = $owner;
116 function assign($stat,$owner)
118 $this->stat = $stat; // Card stat
119 $this->owner = $owner;
122 function setpos($pos)
129 $this->stat = 'table'; // Card stat
134 function take($newown)
136 $this->stat = 'take'; // Card stat
137 $this->owner = $newown;
141 class Bin5_table extends Table {
142 var $card; // il mazzo di carte
143 var $mazzo; // chi e' di mazzo
153 var $points; // points array
154 var $points_n; // number of row of points
168 function Bin5_table()
174 function create($idx)
176 if (($thiz =& new Bin5_table()) == FALSE)
182 $thiz->asta_pla = array(); // TRUE: in auction, FALSE: out of the auction
183 $thiz->asta_pla_n= -1;
184 $thiz->asta_card = -1;
185 $thiz->asta_pnt = -1;
188 $thiz->points = array( );
190 $thiz->total = array( 0, 0, 0, 0, 0);
191 $thiz->asta_win = -1;
192 $thiz->briscola = -1;
196 $thiz->old_reason = "";
197 $thiz->old_asta_pnt = -1;
198 $thiz->old_mult = -1;
201 $thiz->old_friend = -1;
208 function myclone(&$from)
210 if (($thiz =& new Bin5_table()) == FALSE)
215 $thiz->card = $from->card;
216 $thiz->mazzo = $from->mazzo; // REVIEW
217 $thiz->gstart = $from->gstart;
218 $thiz->turn = $from->turn;
220 $thiz->asta_pla = $from->asta_pla;
221 $thiz->asta_pla_n = $from->asta_pla_n;
222 $thiz->asta_card = $from->asta_card;
223 $thiz->asta_pnt = $from->asta_pnt;
225 $thiz->mult = $from->mult;
226 $thiz->points = $from->points;
227 $thiz->points_n = $from->points_n;
228 $thiz->total = $from->total;
230 $thiz->asta_win = $from->asta_win;
231 $thiz->briscola = $from->briscola;
232 $thiz->friend = $from->friend;
234 $thiz->old_reason = $from->old_reason;
235 $thiz->old_asta_pnt = $from->old_asta_pnt;
236 $thiz->old_mult = $from->mult;
237 $thiz->old_pnt = $from->old_pnt;
238 $thiz->old_win = $from->old_win;
239 $thiz->old_friend = $from->old_friend;
245 function parentcopy(&$from)
250 function spawn(&$from)
252 if (($thiz =& new Bin5_table()) == FALSE)
255 $thiz->parentcopy($from);
257 log_main("PLAYER_N - spawn.".$thiz->player_n);
259 $thiz->card = array();
260 $thiz->bunch_create();
261 $thiz->mazzo = rand(0,PLAYERS_N-1);
265 $thiz->old_reason = "";
267 // players are rearranged in an dedicated array
268 $thiz->player = array();
269 for ($i = 0 ; $i < $from->player_n ; $i++)
270 $thiz->player[$i] = $i;
272 log_main("TABLE_OLD_WIN - spawn:".$thiz->old_win);
278 // function bunch_create_old() function AND
282 // for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
283 // // for ($i = 0 ; $i < 40 ; $i++) {
284 // $ret[$i] =& new Card($i, 'bunch', 'no_owner');
291 function bunch_create()
295 for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
296 $this->card[$i] = new Card($i, 'bunch', 'no_owner');
300 function bunch_make()
302 log_main("bunch_make start");
303 $ct = array(0,0,0,0,0);
305 mt_srand(make_seed());
307 for ($i = (BIN5_PLAYERS_N == 5 ? 40 : 24) - 1 ; $i >= 0 ; $i--)
310 for ($i = (BIN5_PLAYERS_N == 5 ? 40 : 24) - 1 ; $i >= 0 ; $i--) {
314 log_main("RND ZERO");
318 $owner = $i % BIN5_PLAYERS_N;
319 $this->card[$id]->assign('hand', $owner);
321 $rest[$rn] = $rest[$i];
322 // $pubbpos[$rn2] = $pubbpos[$i];
324 log_main("bunch_make end");
327 function init($userarr)
330 $this->mazzo = rand(0,PLAYERS_N-1);
334 $this->old_reason = "";
336 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
337 $this->total[$i] = 0;
338 $user_cur = $userarr[$this->player[$i]];
339 $user_cur->exitislock = TRUE;
342 log_main("table::init: ci siamo");
345 function game_init($userarr)
349 $this->gstart = ($this->mazzo+1) % BIN5_PLAYERS_N;
353 $this->asta_pla_n = BIN5_PLAYERS_N;
354 $this->asta_card = -1;
355 $this->asta_pnt = 60;
356 $this->asta_win = -1;
357 $this->briscola = -1;
361 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
362 $this->asta_pla[$i] = TRUE;
363 $user_cur = $userarr[$this->player[$i]];
364 $user_cur->subst = 'asta';
365 $user_cur->asta_card = -2;
366 $user_cur->asta_pnt = -1;
367 $user_cur->handpt = $this->hand_points($i);
368 // SEE function calculate_points(&$table)
375 $this->mazzo = ($this->mazzo + 1) % BIN5_PLAYERS_N;
379 function hand_points($idx)
381 GLOBAL $G_all_points;
385 for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
386 // for ($i = 0 ; $i < 40 ; $i++) {
387 if ($this->card[$i]->owner != $idx)
390 $ctt = $this->card[$i]->value % 10;
391 $tot += $G_all_points[$ctt];
398 function exitlock_show($userarr, $table_pos)
400 $ct = $this->exitlock_calc($userarr, $table_pos);
402 $ret = sprintf('exitlock_show(%d, %s);', $ct,
403 ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false'));
407 function exitlock_calc(&$userarr, $table_pos)
411 for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) {
412 if ($userarr[$this->player[$i]]->exitislock == FALSE)
418 } // end class Bin5_table
423 define(BIN5_USER_FLAG_RING_ENDAUCT, 0x01);
425 class Bin5_user extends User {
428 var $handpt; // Total card points at the beginning of the current hand.
429 var $exitislock; // Player can exit from the table ?
430 var $privflags; // Flags for briskin5 only
436 function create($name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") {
437 if (($thiz =& new User()) == FALSE)
440 $thiz->asta_card = -2;
441 $thiz->asta_pnt = -1;
443 $thiz->exitislock = TRUE;
444 $thiz->privflags = 0;
450 function parentcopy(&$from)
455 function copy(&$from)
457 $this->parentcopy($from);
459 $this->asta_card = $from->asta_card;
460 $this->asta_pnt = $from->asta_pnt;
461 $this->handpt = $from->handpt;
462 $this->exitislock = $from->exitislock;
463 $this->privflags = $from->privflags;
467 function myclone(&$from)
469 if (($thiz =& new User()) == FALSE)
478 function spawn($from, $table, $table_pos)
480 GLOBAL $CO_bin5_pref_ring_endauct;
482 if (($thiz = new Bin5_user()) == FALSE)
485 $thiz->parentcopy($from);
487 /* NOTE: at this moment idx and table_pos fields have the same value
488 but diffentent functions, we keep them separated for a while */
489 $thiz->idx = $table_pos;
490 $thiz->asta_card = -2;
491 $thiz->asta_pnt = -1;
493 $thiz->exitislock = TRUE;
495 log_wr("Bin5 constructor");
497 $this->privflags = ($CO_bin5_pref_ring_endauct == "true" ? BIN5_USER_FLAG_RING_ENDAUCT : 0) | 0;
499 $thiz->table_orig = $table;
501 $thiz->table_pos = $table_pos;
508 function step_set($step)
510 $this->step = $step & 0x7fffffff;
515 function step_inc($delta = 1) {
516 $this->step += $delta;
517 /* modularization because unpack() not manage unsigned 32bit int correctly */
518 $this->step &= 0x7fffffff;
523 static function load_step($sess)
527 if (validate_sess($sess) == FALSE)
530 if (file_exists(BIN5_PROXY_PATH) == FALSE)
531 mkdir(BIN5_PROXY_PATH, 0775, TRUE);
532 if (($fp = @fopen(BIN5_PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
534 if (($s = fread($fp, 8)) == FALSE)
536 if (mb_strlen($s, "ASCII") != 8)
538 $arr = unpack('Ls/Li', $s);
541 // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
548 log_rd2("STEP_GET [".$sess."]: return false ");
556 if (validate_sess($this->sess) == FALSE)
558 if (file_exists(BIN5_PROXY_PATH) == FALSE)
559 mkdir(BIN5_PROXY_PATH, 0775, TRUE);
560 if (($fp = @fopen(BIN5_PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
562 fwrite($fp, pack("LL",$this->step, $this->idx));
565 log_main("step_set [".$this->sess. "] [".$this->step."]");
573 static function unproxy_step($tab_id, $sess)
575 log_rd2("UNPROXY: ".BIN5_PROXY_PATH."/table".$tab_id."/".$sess.".step");
576 if (file_exists(BIN5_PROXY_PATH."/table".$tab_id) == FALSE)
579 @unlink(BIN5_PROXY_PATH."/table".$tab_id."/".$sess.".step");
582 static function load_data($tab_id, $id, $sess)
584 log_main("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
587 if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) {
588 log_main("ftok failed");
592 if (($shm_sz = sharedmem_sz($tok)) == -1) {
593 log_main("shmop_open failed");
597 $shm_sz = SHM_DIMS_U_MIN;
599 if ($shm = shm_attach($tok, $shm_sz)) {
600 if (($user = @shm_get_var($shm, $tok)) == FALSE) {
604 if ($sess != FALSE && $user->sess != $sess) {
607 log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
609 if ($user == FALSE) {
610 log_only("INIT MAIN DATA");
612 // SHSPLIT FIXME: init_data for User class ??
613 $user = User::create($id, "", "");
614 if (@shm_put_var($shm, $tok, $user) == FALSE) {
615 log_shme("Bin5_user::save_data2");
617 log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
618 log_only(serialize($user));
622 if ($sess != FALSE) {
623 // This part isn't strictly required but is good to verify
624 // the coerence of cached and User class saved value of step field.
625 $old_step = $user->step;
626 $arr = Bin5_user::load_step($sess);
627 $user->step = $arr['s'];
628 if ($old_step != $user->step) {
629 log_crit("Bin5:: steps are diffetents User->step ".$user->step." Old_step: ".$old_step);
635 $user->shm_sz = $shm_sz;
641 // SHSPLIT: load users from the shared memory
646 log_crit("Bin5_user::load_data:ret FALSE");
651 static function save_data($user, $tab_id, $id)
657 if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) {
660 while ($user->shm_sz < SHM_DIMS_U_MAX) {
661 if (($shm = shm_attach($tok, $user->shm_sz)) == FALSE)
664 // log_only("PUT_VAR DI ".strlen(serialize($user)));
665 if (@shm_put_var($shm, $tok, $user) != FALSE) {
668 log_main("User[".$id."] saved.");
670 log_shme("Bin5_user::save_data");
674 if (shm_remove($shm) === FALSE) {
675 log_only("REMOVE FALLITA");
679 $user->shm_sz += SHM_DIMS_U_DLT;
688 } // end class Bin5_user
693 static $delta_t = array();
697 var $comm; // commands for many people
698 var $step; // current step of the comm array
699 // externalized var $garbage_timeout;
708 function Bin5 ($room, $table_idx, $table_token) {
709 $this->user = array();
710 $this->table = array();
712 $this->the_end = FALSE;
713 $this->shm_sz = BIN5_SHM_MIN;
714 if (($this->tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
720 $table = $room->table[$table_idx];
722 log_wr("Bin5 constructor");
724 for ($i = 0 ; $i < $table->player_n ; $i++) {
725 $user[$table->player[$i]]->table_token = $table_token;
726 $this->user[$i] = Bin5_user::spawn($user[$table->player[$i]], $table_idx, $i);
728 $this->table[0] = Bin5_table::spawn(&$table);
730 log_main("TABLE_OLD_WIN - Bin5:".$this->table[0]->old_win);
732 $this->table_idx = $table_idx;
733 $this->table_token = $table_token;
734 Bin5::garbage_time_expire_set(0);
736 log_wr("Bin5 constructor end");
740 function get_user($sess, &$idx)
744 if (validate_sess($sess)) {
745 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
746 if (strcmp($sess, $this->user[$i]->sess) == 0) {
749 $ret = &$this->user[$i];
753 log_main(sprintf("get_user: Wrong sess from page [%s]",$PHP_SELF));
754 // for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++)
755 // log_main(sprintf("get_user: Wrong sess compared with [%s]",$this->user[$i]->sess));
758 log_main(sprintf("get_user: Wrong strlen [%s]",$sess));
765 function garbage_manager($force)
769 /* Garbage collector degli utenti in timeout */
772 // externalized if ($force || $this->garbage_timeout < $curtime) {
773 if ($force || Bin5::garbage_time_is_expired($curtime)) {
774 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
775 $user_cur = $this->user[$i];
776 if ($user_cur->sess == "" ||
777 ($user_cur->stat == 'table' && ($user_cur->subst == 'shutdowned' || $user_cur->subst == 'shutdowner')))
780 if ($user_cur->lacc + EXPIRE_TIME_RD < $curtime) { // Auto logout dell'utente
781 log_rd2($user_cur->sess." bin5 AUTO LOGOUT.");
783 if ($user_cur->stat == 'table') {
784 log_auth($user_cur->sess," bin5 Autologout session.");
786 /* SI DELEGA AL garbage_manager principale LA RIMOZIONE DELL'UTENTE
788 $tmp_sess = $user_cur->sess;
789 $user_cur->sess = "";
790 Bin5_user::step_unproxy($tmp_sess);
791 $user_cur->name = "";
792 $user_cur->the_end = FALSE;
796 /* se gli altri utenti non erano d'accordo questo utente viene bannato */
797 $remcalc = $this->table[0]->exitlock_calc(&$this->user, $user_cur->table_pos);
799 require_once("${G_base}Obj/hardban.phh");
800 Hardbans::add(($user_cur->flags & USER_FLAG_AUTH ? $user_cur->name : FALSE),
801 $user_cur->ip, $user_cur->sess, $user_cur->laccwr + BAN_TIME);
803 // $user->bantime = $user->laccwr + BAN_TIME;
805 $this->table_wakeup($user_cur);
809 log_rd2($user_cur->sess." GARBAGE UPDATED!");
811 // externalized $this->garbage_timeout = $curtime + GARBAGE_TIMEOUT;
812 Bin5::garbage_time_expire_set($curtime + GARBAGE_TIMEOUT);
821 static function load_data($table_idx, $table_token = "")
825 log_wr("TABLE_FTOK ".FTOK_PATH."/bin5/table".$table_idx."/table");
828 if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
829 log_main("ftok failed");
833 if (($shm_sz = sharedmem_sz($tok)) == -1) {
834 log_main("shmop_open failed");
838 if (($shm = shm_attach($tok, $shm_sz)) == FALSE)
841 if (($bri = @shm_get_var($shm, $tok)) == FALSE)
844 if ($table_token != "" && $bri->table_token != $table_token) {
845 log_wr("bri->table_token: ".$bri->table_token."table_token: ".$table_token);
852 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
853 if (($bri->user[$i] = Bin5_user::load_data($table_idx, $i, FALSE)) == FALSE) {
854 log_crit("Bin5_user::load_data failed");
858 if ($i < BIN5_MAX_PLAYERS) {
868 log_wr("briskin5 load_data failed");
875 function save_data($bri)
882 log_main("SAVE BRISKIN5 DATA");
884 if (!isset($bri->tok))
887 $user_park = array();
888 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
889 $user_park[$i] = $bri->user[$i];
890 $bri->user[$i] = FALSE;
893 while ($bri->shm_sz < BIN5_SHM_MAX) {
894 if (($shm = shm_attach($bri->tok, $bri->shm_sz)) == FALSE)
897 if (@shm_put_var($shm, $bri->tok, $bri) != FALSE) {
899 log_shme("Bin5::save_data");
904 if (shm_remove($shm) === FALSE) {
905 log_only("REMOVE FALLITA");
909 $bri->shm_sz += BIN5_SHM_DLT;
915 // SHSPLIT: reattach users to the room class
916 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
917 Bin5_user::save_data($user_park[$i], $bri->table_idx, $i);
918 $bri->user[$i] = $user_park[$i];
920 log_load("FINISH: ".($ret == TRUE ? "TRUE" : "FALSE"));
927 function destroy_data($table_idx)
933 log_main("DESTROY BRISKIN5 DATA");
936 log_main("DESTROY2 BRISKIN5 DATA [".$this->table_idx."]");
937 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
938 $this->user[$i]->destroy_data($this->table_idx);
939 Bin5_user::unproxy_step($this->table_idx, $this->user[$i]->sess);
941 if (($tok = @ftok(FTOK_PATH."/bin5/table".$this->table_idx."/table", "B")) == -1)
944 if (($shm = @shmop_open($tok, 'a', 0, 0)) == FALSE)
947 if (shmop_delete($shm) == 0) {
948 log_only("REMOVE FALLITA ");
953 log_main("DESTROY2 BRISKIN5 DATA SUCCESS");
955 // log_main("QUI CI ARRIVA [".$bri->user[0]->name."]");
965 function lock_data($table_idx)
969 log_main("lockinfo: DATA ".FTOK_PATH."/bin5/table".$table_idx."/table");
970 // echo "LOCK: ".FTOK_PATH."/main";
972 // WARNING monitor this step
973 if (($tok = @ftok(FTOK_PATH."/bin5/table".$table_idx."/table", "B")) == -1) {
976 // WARNING monitor this step
977 if (($res = @sem_get($tok)) == FALSE) {
980 if (sem_acquire($res)) {
981 self::$delta_t[$table_idx] = microtime(TRUE);
982 log_lock("LOCK table [".$table_idx."] [".self::$delta_t[$table_idx]."]");
984 return (new Vect(array('res' => $res, 'tab' => $table_idx)));
987 log_lock("LOCK table ".$table_idx.":FAILED");
992 function unlock_data($res_vect)
996 $res = $res_vect->getbyid('res');
997 $tab = $res_vect->getbyid('tab');
999 log_lock("UNLOCK table [".$tab."] [".(microtime(TRUE) - (self::$delta_t[$tab]))."]");
1001 return (sem_release($res));
1005 function chatt_send($user, $mesg)
1007 GLOBAL $mlang_brisk, $G_lang;
1009 if ($user->stat == 'table') {
1010 $table = &$this->table[$user->table];
1013 $user_mesg = substr($mesg,6);
1017 $dt = date("H:i ", $curtime);
1018 if (strncmp($user_mesg, "/nick ", 6) == 0) {
1019 log_main($user->sess." chatt_send BEGIN");
1021 if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) {
1022 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1023 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $mlang_brisk['nickmust'][$G_lang]);
1028 $user_mesg = "COMMAND ".$user_mesg;
1031 // update local graph
1032 // update remote graphs
1033 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
1034 $user_cur = $this->user[$i];
1035 // if ($user_cur->sess == '' || $user_cur->stat != 'room')
1036 if ($user_cur->sess == '')
1038 if ($user_cur->name == $name_new) {
1039 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1041 $premsg = sprintf($mlang_brisk['nickdupl'][$G_lang], xcape($name_new));
1042 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"%s");', $dt, NICKSERV, $premsg);
1047 if ($i == BIN5_MAX_PLAYERS) {
1048 if ($user->flags & USER_FLAG_AUTH && strcasecmp($user->name,$name_new) != 0) {
1049 if ($this->table[$user->table]->auth_only == TRUE) {
1050 $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
1051 $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s", [2, "%s"],"<b>%s</b>");', $dt, NICKSERV, $mlang_brisk['authchan'][$G_lang]);
1056 $user->flags &= ~USER_FLAG_AUTH; // Remove auth if name changed
1060 $user->name = $name_new;
1062 log_main($user->sess." chatt_send start set");
1065 for ($i = 0 ; $i < BIN5_MAX_PLAYERS ; $i++) {
1066 log_main($user->sess." chatt_send set loop");
1068 $user_cur = &$this->user[$i];
1069 if ($user_cur->sess == '')
1072 if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
1073 $table = &$this->table[$user->table];
1075 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1076 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names([%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"]); ',
1077 $this->user[$table->player[($user_cur->table_pos) % BIN5_PLAYERS_N]]->flags,
1078 xcape($this->user[$table->player[($user_cur->table_pos) % BIN5_PLAYERS_N]]->name),
1080 $this->user[$table->player[($user_cur->table_pos+1) % BIN5_PLAYERS_N]]->flags,
1081 xcape($this->user[$table->player[($user_cur->table_pos+1) % BIN5_PLAYERS_N]]->name),
1083 $this->user[$table->player[($user_cur->table_pos+2) % BIN5_PLAYERS_N]]->flags,
1084 xcape($this->user[$table->player[($user_cur->table_pos+2) % BIN5_PLAYERS_N]]->name),
1086 (BIN5_PLAYERS_N == 3 ? 0: $this->user[$table->player[($user_cur->table_pos+3) % BIN5_PLAYERS_N]]->flags),
1087 (BIN5_PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3) % BIN5_PLAYERS_N]]->name)),
1089 (BIN5_PLAYERS_N == 3 ? 0: $this->user[$table->player[($user_cur->table_pos+4) % BIN5_PLAYERS_N]]->flags),
1090 (BIN5_PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4) % BIN5_PLAYERS_N]]->name)));
1091 if ($user_cur == $user) {
1092 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1093 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1094 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";',
1095 $itin, xcape($user->name,ENT_COMPAT,"UTF-8"), $itou);
1097 $user_cur->step_inc();
1103 for ($i = 0 ; $i < ($user->stat == 'room' ? BIN5_MAX_PLAYERS : BIN5_PLAYERS_N) ; $i++) {
1104 if ($user->stat == 'room') {
1105 $user_cur = &$this->user[$i];
1106 if ($user_cur->sess == '' || $user_cur->stat != 'room')
1110 $user_cur = &$this->user[$table->player[$i]];
1113 $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
1114 $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s", [%d, "%s"],"%s");',
1115 $dt, $user->flags, xcape($user->name), xcape($user_mesg));
1116 $user_cur->step_inc();
1118 log_legal($curtime, $user, ($user->stat == 'room' ? 'room' : 'table '.$user->table_orig),$user_mesg);
1122 function table_wakeup($user)
1124 $table = &$this->table[0];
1126 log_main("BIN5_WAKEUP begin function table stat: ".$user->stat." subst: ".$user->subst);
1130 log_main("BIN5_WAKEUP from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n);
1132 for ($i = 0 ; $i < $table->player_n ; $i++) {
1133 $user_cur = &$this->user[$i];
1134 log_main("PREIMPOST INLOOP name: ".$user_cur->name);
1136 if ($user_cur == $user)
1137 $user_cur->subst = "shutdowner";
1139 $user_cur->subst = "shutdowned";
1140 $user_cur->laccwr = $curtime;
1142 $ret = "gst.st = ".($user_cur->step+1)."; ";
1143 $ret .= 'gst.st_loc++; the_end=true; window.onbeforeunload = null; window.onunload = null; document.location.assign("../index.php");|';
1145 log_wr($user_cur->sess." BIN5_WAKEUP: ".$ret);
1146 $user_cur->comm[$user_cur->step % COMM_N] = $ret;
1147 $user_cur->step_inc();
1150 $this->the_end = TRUE;
1154 * If all players are freezed the room garbage_manager clean up table and users.
1156 function is_abandoned()
1161 $table = &$this->table[0];
1163 for ($i = 0 ; $i < $table->player_n ; $i++) {
1164 $user_cur = &$this->user[$i];
1166 if ($user_cur->lacc + (EXPIRE_TIME_RD * 2) >= $curtime) {
1176 static function garbage_time_is_expired($tm)
1181 if (file_exists(BIN5_PROXY_PATH) == FALSE)
1182 mkdir(BIN5_PROXY_PATH, 0775, TRUE);
1183 if (($fp = @fopen(BIN5_PROXY_PATH."/garbage_time.expired", 'rb')) == FALSE)
1185 if (($s = fread($fp, 4)) == FALSE)
1187 if (mb_strlen($s, "ASCII") != 4)
1189 $arr = unpack('Le', $s);
1190 if ($arr['e'] > $tm)
1197 log_rd2("END: return ".($ret ? "TRUE" : "FALSE"));
1202 static function garbage_time_expire_set($tm)
1205 if (file_exists(BIN5_PROXY_PATH) == FALSE)
1206 mkdir(BIN5_PROXY_PATH, 0775, TRUE);
1207 if (($fp = @fopen(BIN5_PROXY_PATH."/garbage_time.expired", 'wb')) == FALSE)
1209 fwrite($fp, pack("L",$tm));
1220 function locshm_exists($tok)
1224 if (($id = @shmop_open($tok,"a", 0, 0)) == FALSE) {
1225 log_main($tok." SHM NOT exists");
1231 log_main($tok." SHM exists");
1238 function asta2mult($asta_pnt)
1240 if ($asta_pnt > 110)
1242 else if ($asta_pnt > 100)
1244 else if ($asta_pnt > 90)
1246 else if ($asta_pnt > 80)
1248 else if ($asta_pnt > 70)
1254 // rendiamo qui l'elenco dei punti come return della func
1255 function calculate_points(&$table)
1257 GLOBAL $G_all_points;
1262 if ($table->asta_pnt == 60)
1263 $table->asta_pnt = 61;
1265 $table->old_reason = "";
1266 $table->old_win = $table->asta_win;
1267 $table->old_friend = $table->friend;
1268 $table->old_asta_pnt = $table->asta_pnt;
1269 $table->old_mult = $table->mult;
1271 for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
1272 // for ($i = 0 ; $i < 40 ; $i++) {
1273 $ctt = $table->card[$i]->value % 10;
1274 $own = $table->card[$i]->owner;
1275 if ($own == $table->asta_win || $own == $table->friend)
1276 $pro += $G_all_points[$ctt];
1279 log_wr(sprintf("PRO: [%d]", $pro));
1282 if ($table->asta_pnt == 61 && $pro == 60) { // PATTA !
1283 $table->points[$table->points_n % MAX_POINTS] = array();
1284 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1285 $table->points[$table->points_n % MAX_POINTS][$i] = 0;
1289 $table->old_pnt = $pro;
1295 if ($pro >= $table->asta_pnt)
1300 $gamult = asta2mult($table->asta_pnt);
1302 $table->points[$table->points_n % MAX_POINTS] = array();
1303 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1304 if ($i == $table->asta_win)
1305 $pt = ($i == $table->friend ? 4 : 2);
1306 else if ($i == $table->friend)
1313 log_wr(sprintf("PRO: pt[%d][%d] = %d", $table->points_n % MAX_POINTS, $i, $pt));
1315 $pt = $pt * $sig * ($gamult + $table->mult) * ($pro == 120 ? 2 : 1);
1317 log_wr(sprintf("PRO:[%d][%d][%d]", $sig, $table->mult, ($pro == 120 ? 2 : 1)));
1319 $table->points[$table->points_n % MAX_POINTS][$i] = $pt;
1320 $table->total[$i] += $pt;
1324 $table->old_pnt = $pro;
1331 is_transition (is from room to table ?)
1332 is_again (is another game)
1334 Examples of $is_transition, $is_again:
1335 from reload of the page: FALSE, FALSE
1336 from sitdown in room: TRUE, FALSE
1337 from table: asta cmd e tutti passano: TRUE, TRUE
1338 from table: fine partita: TRUE, TRUE
1340 function show_table(&$room, &$user, $sendstep, $is_transition, $is_again)
1342 $table_idx = $user->table;
1343 $table = $room->table[$table_idx];
1344 $table_pos = $user->table_pos;
1346 $ret = "table_init();";
1347 $ret .= $table->exitlock_show(&$room->user, $table_pos);
1349 /* GENERAL STATUS */
1350 $ret .= sprintf( 'gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;',
1351 $sendstep, $user->stat, $user->subst, $table_pos);
1353 log_rd(sprintf( 'SHOW_TABLE: gst.st = %d; stat = "%s"; subst = "%s"; table_pos = %d;', $sendstep, $user->stat, $user->subst, $table_pos));
1356 $ret .= "background_set();";
1359 $itin = ($user->flags & USER_FLAG_AUTH ? "<i>" : "");
1360 $itou = ($user->flags & USER_FLAG_AUTH ? "</i>" : "");
1362 $ret .= sprintf('$("myname").innerHTML = "<b>%s%s%s</b>";', $itin, xcape($user->name), $itou);
1363 $ret .= sprintf('set_names([%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"], [%d, "%s"]); ',
1364 $room->user[$table->player[($table_pos) % BIN5_PLAYERS_N]]->flags,
1365 xcape($room->user[$table->player[($table_pos) % BIN5_PLAYERS_N]]->name),
1367 $room->user[$table->player[($table_pos+1) % BIN5_PLAYERS_N]]->flags,
1368 xcape($room->user[$table->player[($table_pos+1) % BIN5_PLAYERS_N]]->name),
1370 $room->user[$table->player[($table_pos+2) % BIN5_PLAYERS_N]]->flags,
1371 xcape($room->user[$table->player[($table_pos+2) % BIN5_PLAYERS_N]]->name),
1373 (BIN5_PLAYERS_N == 3 ? 0 : $room->user[$table->player[($table_pos+3) % BIN5_PLAYERS_N]]->flags),
1374 (BIN5_PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+3) % BIN5_PLAYERS_N]]->name)),
1376 (BIN5_PLAYERS_N == 3 ? 0 : $room->user[$table->player[($table_pos+4) % BIN5_PLAYERS_N]]->flags),
1377 (BIN5_PLAYERS_N == 3 ? "" : xcape($room->user[$table->player[($table_pos+4) % BIN5_PLAYERS_N]]->name)));
1379 /* NOTIFY FOR THE CARD MAKER */
1380 if ($is_transition) { // && $user->subst == "asta" superfluo
1381 $ret .= show_table_info(&$room, &$table, $table_pos);
1384 $ret .= table_wellcome($user);
1386 if ($is_transition && !$is_again) { // appena seduti al tavolo, play della mucca
1387 $ret .= playsound("cow.mp3");
1392 if ($is_transition) { // && $user->subst == "asta" superfluo
1395 for ($i = 0 ; $i < 8 ; $i++) {
1396 for ($e = 0 ; $e < BIN5_PLAYERS_N ; $e++) {
1398 for ($o = 0 ; $o < (BIN5_PLAYERS_N == 5 ? 40 : 24) && $ct < $i+1 ; $o++) {
1399 // for ($o = 0 ; $o < 40 && $ct < $i+1 ; $o++) {
1400 if ($table->card[$o]->owner == (($e + $table->gstart) % BIN5_PLAYERS_N)) {
1406 log_rd("O ".$o." VAL ".$table->card[$o]->value." Owner: ".$table->card[$o]->owner);
1408 $ret .= sprintf( ' card_send(%d,%d,%d,%8.2f,%d);|', ($table->gstart + $e) % BIN5_PLAYERS_N,
1409 $i, ((($e + BIN5_PLAYERS_N - $table_pos + $table->gstart) % BIN5_PLAYERS_N) == 0 ?
1410 $table->card[$o]->value : -1),
1411 ($i == 7 && $e == (BIN5_PLAYERS_N - 1) ? 1 : 0.5),$i+1);
1416 $taked = array(0,0,0,0,0);
1417 $inhand = array(0,0,0,0,0);
1418 $ontabl = array(-1,-1,-1,-1,-1);
1421 for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
1422 // for ($i = 0 ; $i < 40 ; $i++) {
1423 if ($table->card[$i]->stat == 'hand') {
1424 if ($table->card[$i]->owner == $table_pos) {
1425 $cards[$inhand[$table->card[$i]->owner]] = $table->card[$i]->value;
1427 $inhand[$table->card[$i]->owner]++;
1429 else if ($table->card[$i]->stat == 'take') {
1430 log_main("Card taked: ".$table->card[$i]->value."OWN: ".$table->card[$i]->owner);
1431 $taked[$table->card[$i]->owner]++;
1433 else if ($table->card[$i]->stat == 'table') {
1434 $ontabl[$table->card[$i]->owner] = $i;
1438 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1439 $logg .= sprintf("INHAND: %d IN TABLE %d TAKED %d\n", $inhand[$i], $ontabl[$i], $taked[$i]);
1441 log_main("Stat table: ".$logg);
1443 /* Set ours cards. */
1445 for ($i = 0 ; $i < $inhand[$table_pos] ; $i++)
1446 $oursarg .= ($i == 0 ? "" : ", ").$cards[$i];
1447 for ($i = $inhand[$table_pos] ; $i < 8 ; $i++)
1448 $oursarg .= ($i == 0 ? "" : ", ")."-1";
1449 $ret .= sprintf('card_setours(%s);', $oursarg);
1451 /* Dispose all cards */
1452 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1453 /* Qui sotto al posto di + 1 c'era + ->gstart ... credo in modo errato */
1454 $ret .= sprintf('cards_dispose(%d,%d,%d);', $i,
1455 ($inhand[$i] <= 8 ? $inhand[$i] : 8) , $taked[$i]);
1457 if ($ontabl[$i] != -1) {
1458 $ret .= sprintf('card_place(%d,%d,%d,%d,%d);',$i, $inhand[$i],
1459 $table->card[$ontabl[$i]]->value,
1460 $table->card[$ontabl[$i]]->x, $table->card[$ontabl[$i]]->y);
1466 if ($user->subst == 'asta') {
1468 /* show users auction status */
1470 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1471 $user_cur = &$room->user[$table->player[$i]];
1472 $showst .= sprintf("%s%d", ($i == 0 ? "" : ", "),
1473 ($user_cur->asta_card < 9 ? $user_cur->asta_card : $user_cur->asta_pnt));
1475 if (BIN5_PLAYERS_N == 3)
1476 $showst .= ",-2,-2";
1477 $ret .= sprintf('document.title = "Brisk - Tavolo %d (asta)";', $user->table_orig);
1478 $ret .= sprintf('show_astat(%s);', $showst);
1480 if ($table->asta_win != -1 && $table->asta_win == $table_pos) {
1481 /* show card chooser */
1482 $ret .= sprintf('choose_seed(%s); $("astalascio").style.visibility = ""; $("asta").style.visibility = "hidden";',
1487 if ($table_pos == ($table->gstart % BIN5_PLAYERS_N) &&
1488 $table->asta_win == -1)
1489 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1490 $table->asta_card + 1, $table->asta_pnt+1, ($user->handpt <= 2 ? "true" : "false"));
1492 $ret .= sprintf('dispose_asta(%d,%d, %s);',
1493 $table->asta_card + 1, -($table->asta_pnt+1), ($user->handpt <= 2 ? "true" : "false"));
1497 if ($table->asta_win == -1) { // auction case
1498 if ($table_pos == ($table->gstart % BIN5_PLAYERS_N))
1499 $ret .= "remark_on();";
1501 $ret .= "remark_off();";
1503 else { // chooseed case
1504 if ($table_pos == $table->asta_win)
1505 $ret .= "remark_on();";
1507 $ret .= "remark_off();";
1510 else if ($user->subst == 'game') {
1512 if (($table->gstart + $table->turn) % BIN5_PLAYERS_N == $table_pos)
1513 $ret .= "is_my_time = true; remark_on();";
1515 $ret .= "remark_off();";
1517 /* WHO CALL AND WHAT */
1518 $ret .= briscola_show($room, $table, $user);
1522 } // end function show_table(...
1524 function calculate_winner(&$table)
1531 $cur_seed = $table->briscola - ($table->briscola % 10);
1533 for ($i = 0 ; $i < (BIN5_PLAYERS_N == 5 ? 40 : 24) ; $i++) {
1534 // for ($i = 0 ; $i < 40 ; $i++) {
1535 if ($table->card[$i]->stat != "table")
1538 log_wr(sprintf("Card On table: [%d]", $i));
1540 $v = $table->card[$i]->value;
1541 $ontab[$table->card[$i]->owner] = $v;
1542 $ontid[$table->card[$i]->owner] = $i;
1543 /* se briscola setto il flag */
1544 if (($v - ($v % 10)) == $cur_seed)
1548 if ($briontab == FALSE) {
1549 $cur_win = $table->gstart;
1550 $cur_val = $ontab[$cur_win];
1551 $cur_seed = $cur_val - ($cur_val % 10);
1554 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1555 if (($ontab[$i] - ($ontab[$i] % 10)) == $cur_seed) {
1556 if ($ontab[$i] < $cur_val) {
1557 $cur_val = $ontab[$i];
1563 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
1564 $table->card[$ontid[$i]]->owner = $cur_win;
1565 $table->card[$ontid[$i]]->stat = "take"; // Card stat
1570 function show_table_info(&$room, &$table, $table_pos)
1572 GLOBAL $G_lang, $mlang_bin5_bin5;
1575 $user = $room->user[$table->player[$table_pos]];
1577 $pnt_min = $table->points_n - MAX_POINTS < 0 ? 0 : $table->points_n - MAX_POINTS;
1578 $noty = sprintf('<table class=\"points\"><tr><th></th>');
1581 for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++)
1582 $noty .= sprintf('<th class=\"td_points\">%s</th>', xcape($room->user[$table->player[$i]]->name));
1583 $noty .= sprintf("</tr>");
1586 log_main("show_table_info: pnt_min: ".$pnt_min." Points_n: ".$table->points_n);
1588 for ($i = $pnt_min ; $i < $table->points_n ; $i++) {
1589 $noty .= sprintf('<tr><th class=\"td_points\">%d</th>', $i+1);
1590 for ($e = 0 ; $e < BIN5_PLAYERS_N ; $e++)
1591 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->points[$i % MAX_POINTS][$e]);
1596 $noty .= '<tr><th class=\"td_points\">Tot.</th>';
1597 for ($e = 0 ; $e < BIN5_PLAYERS_N ; $e++)
1598 $noty .= sprintf('<td class=\"td_points\">%d</td>', $table->total[$e]);
1599 $noty .= "</tr></table>";
1601 if ($table->old_reason != "") {
1602 $noty .= sprintf("<hr><b>%s</b><br>", xcape($table->old_reason));
1605 if ($table->old_win != -1) {
1606 log_main("TABLE_OLD_WIN:".$table->old_win);
1607 $win = $table->player[$table->old_win];
1608 log_main("TABLE_OLD_FRIEND:".$table->old_friend);
1609 $fri = $table->player[$table->old_friend];
1611 $wol = game_result($table->old_asta_pnt, $table->old_pnt);
1614 /* 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" */
1616 $noty .= sprintf($mlang_bin5_bin5['info_part'][$G_lang],
1617 xcape($room->user[$win]->name),
1618 xcape($room->user[$fri]->name));
1619 if ($table->old_pnt == 120) {
1620 $noty .= sprintf($mlang_bin5_bin5['info_capp'][$G_lang]);
1623 $noty .= sprintf($mlang_bin5_bin5['info_pnt'][$G_lang],
1624 ($table->old_asta_pnt > 61 ? $mlang_bin5_bin5['info_alea'][$G_lang].$table->old_asta_pnt :
1625 $mlang_bin5_bin5['info_more'][$G_lang]), $table->old_pnt,
1626 ($wol == 1 ? $mlang_bin5_bin5['info_win'][$G_lang] : ($wol == 0 ? $mlang_bin5_bin5['info_peer'][$G_lang] : $mlang_bin5_bin5['info_lost'][$G_lang])));
1630 $noty .= sprintf($mlang_bin5_bin5['info_alon'][$G_lang],
1631 xcape($room->user[$win]->name));
1632 if ($table->old_pnt == 120) {
1633 $noty .= sprintf($mlang_bin5_bin5['info_acap'][$G_lang]);
1636 $noty .= sprintf($mlang_bin5_bin5['info_apnt'][$G_lang],
1638 ($table->old_asta_pnt > 61 ? $mlang_bin5_bin5['info_alea'][$G_lang].$table->old_asta_pnt :
1639 $mlang_bin5_bin5['info_more'][$G_lang]), $table->old_pnt,
1641 ($wol == 1 ? $mlang_bin5_bin5['info_win'][$G_lang] : ($wol == 0 ? $mlang_bin5_bin5['info_peer'][$G_lang] : $mlang_bin5_bin5['info_lost'][$G_lang])));
1644 if (($table->old_mult + asta2mult($table->old_asta_pnt)) > 1) {
1645 $noty .= sprintf($mlang_bin5_bin5['info_omul'][$G_lang], multoval($table->old_mult + asta2mult($table->old_asta_pnt)));
1647 $noty .= "<hr><br>";
1649 /* MLANG: "Fai <b>tu</b> il mazzo,", "Il mazzo a <b>$unam</b>," */
1650 if ($table->mazzo == $table_pos)
1651 $noty .= $mlang_bin5_bin5['info_yshuf'][$G_lang];
1653 $unam = xcape($room->user[$table->player[$table->mazzo]]->name);
1654 $noty .= sprintf($mlang_bin5_bin5['info_shuf'][$G_lang], $unam);
1657 if ($user->subst == 'asta') {
1658 if ($table->asta_win == -1) // auction case
1659 $curplayer = $table->gstart % BIN5_PLAYERS_N;
1661 $curplayer = $table->asta_win;
1663 else if ($user->subst == 'game') {
1664 $curplayer = ($table->gstart + $table->turn) % BIN5_PLAYERS_N;
1667 /* MLANG: " tocca a <b>te</b> giocare.", " tocca a <b>$unam</b> giocare.", " La partita vale <b>%s</b>.", "torna alla partita" */
1668 if ($curplayer == $table_pos) {
1669 $noty .= $mlang_bin5_bin5['info_yturn'][$G_lang];
1672 $unam = xcape($room->user[$table->player[$curplayer]]->name);
1673 $noty .= sprintf($mlang_bin5_bin5['info_turn'][$G_lang], $unam);
1676 if (($table->mult + asta2mult($table->asta_pnt)) > 1) {
1677 $noty .= sprintf($mlang_bin5_bin5['info_mult'][$G_lang], multoval($table->mult + asta2mult($table->asta_pnt)));
1679 $noty .= "<hr><br>";
1680 $ret .= show_notify($noty, 3000, $mlang_bin5_bin5['btn_bkgame'][$G_lang], 500, 400);
1681 /* NOTE: show_notify($noty, 3000, "torna alla partita", 500,
1682 * 130 + ($table->points_n > 0 ? 50 : 0) +
1683 * (120 * ($table->points_n / MAX_POINTS)));
1684 * will be used when we refact notify js function following
1685 * photoo class logic
1691 function table_wellcome($user)
1693 GLOBAL $table_wellarr, $G_lang;
1696 for ($i = 0 ; $i < count($table_wellarr[$G_lang]) ; $i++)
1697 $ret .= sprintf('chatt_sub("%s", [2, "ChanServ: "],"%s");', "", str_replace('"', '\"', $table_wellarr[$G_lang][$i]));
1703 function briscola_show($room, $table, $user)
1705 GLOBAL $G_lang, $mlang_bin5_bin5;
1709 if ($table->asta_card == 9)
1710 $ptnadd = sprintf($mlang_bin5_bin5['call_wptn'][$G_lang], $table->asta_pnt);
1712 /* text of caller cell */
1713 if ($user->table_pos == $table->asta_win) {
1714 $prestr = sprintf('$("callerinfo").innerHTML = "%s";', $mlang_bin5_bin5['call_ycall'][$G_lang]);
1715 $ret .= sprintf($prestr, $ptnadd);
1718 $prestr = sprintf('$("callerinfo").innerHTML = "%s";', $mlang_bin5_bin5['call_call'][$G_lang]);
1719 $ret .= sprintf($prestr,
1720 xcape($room->user[$table->player[$table->asta_win]]->name), $ptnadd);
1722 $ret .= sprintf('set_iscalling(%d);', ($table->asta_win - $user->table_pos + BIN5_PLAYERS_N) % BIN5_PLAYERS_N);
1724 $ret .= sprintf('$("caller").style.backgroundImage = \'url("img/brisk_caller_sand%d.png")\';',
1726 $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola);
1727 $ret .= sprintf('$("caller").style.visibility = "visible";');
1728 $ret .= sprintf('$("chooseed").style.visibility = "hidden";');
1729 $ret .= sprintf('$("astalascio").style.visibility = "";');
1730 $ret .= sprintf('$("asta").style.visibility = "hidden";');
1731 $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);');
1737 function game_result($asta_pnt, $pnt)
1739 if ($asta_pnt == 61) {
1742 else if ($pnt == 60)
1748 if ($pnt >= $asta_pnt)
1755 function log_points($curtime, $user, $where, $mesg)
1759 if (($fp = @fopen(LEGAL_PATH."/points.log", 'a')) != FALSE) {
1760 /* Unix time | session | nickname | IP | where was | mesg */
1761 fwrite($fp, sprintf("%ld|%s|%s|%s|%s|%s|%s|\n", $curtime, $user->sess,
1762 ($user->flags & USER_FLAG_AUTH ? 'A' : 'N'),
1763 $user->name, $_SERVER['REMOTE_ADDR'], $where , $mesg));