X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fbrisk.phh;h=868c53830ffdd4d644d89e9961fd21b0e5050091;hb=bcb97f7356b9754c4f5f11d51bc6463a3b239925;hp=f929470be892e2a201e01032adcb710261f40170;hpb=04e1d4690aafd42fb24abf8c24dd9f036b4b08a8;p=brisk.git diff --git a/web/brisk.phh b/web/brisk.phh index f929470..868c538 100644 --- a/web/brisk.phh +++ b/web/brisk.phh @@ -29,13 +29,14 @@ define(COMM_GEN_N, 50); define(SESS_LEN, 13); define(STREAM_TIMEOUT, 20); define(EXPIRE_TIME_RD, 180); -define(EXPIRE_TIME_SMAMMA, 300); +define(EXPIRE_TIME_SMAMMA, 360); define(GARBAGE_TIMEOUT, 10); define(NICKSERV, "SERVER"); define(BRISK_DEBUG, FALSE); // define(DEBUGGING, "local"); -$G_brisk_version = "0.4.4"; +$G_all_points = array( 11,10,4,3,2, 0,0,0,0,0 ); +$G_brisk_version = "0.4.6"; $root_wellarr = Array ( 'Benvenuto in brisk (Ver. '.$G_brisk_version.').', 'Se vuoi iscriverti alla Mailing List, cliccala!' ); @@ -145,6 +146,7 @@ class Table { var $briscola; var $friend; + var $old_reason; var $old_asta_pnt; var $old_pnt; var $old_win; @@ -167,6 +169,7 @@ class Table { $this->briscola = -1; $this->friend = -1; $this->turn = 0; + $this->old_reason = ""; $this->old_asta_pnt = -1; $this->old_pnt = -1; $this->old_win = -1; @@ -210,20 +213,23 @@ class Table { } } - function init() + function init(&$userarr) { $this->mazzo = rand(0,PLAYERS_N-1); $this->points_n = 0; $this->mult = 1; $this->old_win =-1; + $this->old_reason = ""; for ($i = 0 ; $i < PLAYERS_N ; $i++) { $this->total[$i] = 0; + $user_cur = &$userarr[$this->player[$i]]; + $user_cur->exitislock = TRUE; } log_main("table::init","ci siamo"); } - function game_init(&$bri) + function game_init(&$userarr) { log_rd2($sess,"GSTART 4"); @@ -241,10 +247,12 @@ class Table { for ($i = 0 ; $i < PLAYERS_N ; $i++) { $this->asta_pla[$i] = TRUE; - $user_cur = &$bri->user[$this->player[$i]]; + $user_cur = &$userarr[$this->player[$i]]; $user_cur->subst = 'asta'; $user_cur->asta_card = -2; $user_cur->asta_pnt = -1; + $user_cur->handpt = $this->hand_points($i); + // SEE function calculate_points(&$table) } } @@ -291,6 +299,43 @@ class Table { } } + function hand_points($idx) + { + GLOBAL $G_all_points; + + $tot = 0; + + for ($i = 0 ; $i < 40 ; $i++) { + if ($this->card[$i]->owner != $idx) + continue; + + $ctt = $this->card[$i]->value % 10; + $tot += $G_all_points[$ctt]; + } + + return ($tot); + } + + function exitlock_show(&$userarr, $table_pos) + { + $ct = $this->exitlock_calc(&$userarr, $table_pos); + + $ret = sprintf('exitlock_show(%d, %s);', $ct, + ($userarr[$this->player[$table_pos]]->exitislock ? 'true' : 'false')); + return ($ret); + } + + function exitlock_calc(&$userarr, $table_pos) + { + $ct = 0; + + for ($i = 0 , $ct = 0 ; $i < PLAYERS_N ; $i++) { + if ($userarr[$this->player[$i]]->exitislock == FALSE) + $ct++; + } + + return ($ct); + } } // End class Table class User { @@ -305,7 +350,8 @@ class User { var $comm; // commands array var $asta_card; // var $asta_pnt; // - + var $handpt; // Total card points at the beginning of the current hand. + var $exitislock; // Player can exit from the table ? var $table; // id of the current table (if in table state) var $table_pos; // idx on the table @@ -321,6 +367,8 @@ class User { $this->comm = array(); $this->asta_card = -2; $this->asta_pnt = -1; + $this->handpt = -1; + $this->exitislock = TRUE; $this->table = $table; } @@ -368,14 +416,13 @@ class brisco { log_rd2($user_cur->sess, "AUTO LOGOUT."); if ($user_cur->subst == 'sitdown' || $user_cur->stat == 'table') - $this->room_wakeup(&$user_cur); + $this->room_wakeu +p(&$user_cur); else if ($user_cur->subst == 'standup') $this->room_outstandup(&$user_cur); else log_rd2($sess, "LOGOUT FROM WHAT ???"); } - // } // if (0 == 1) - } if ($user_cur->laccwr + EXPIRE_TIME_SMAMMA < $curtime) { // lo rimettiamo in piedi @@ -401,9 +448,17 @@ class brisco { log_main("WAKEUP", "begin function table:".$table_idx." stat: ".$user->stat." subst: ".$user->subst); + $curtime = time(); + $from_table = ($user->stat == "table"); if ($from_table) { log_main("WAKEUP", "from table [".$user->table."] nplayers_n: ".$this->table[$user->table]->player_n); + $lockcalc = $table->exitlock_calc(&$this->user, $table_pos); + if ($lockcalc < 3) { + // BAN TEMP! +asdasdasdas + } + for ($i = 0 ; $i < $table->player_n ; $i++) { $user_cur = &$this->user[$table->player[$i]]; log_main("PREIMPOST", "INLOOP name: ".$user_cur->name); @@ -411,10 +466,12 @@ class brisco { if ($user_cur != $user) { $user_cur->stat = "room"; $user_cur->subst = "sitdown"; + $user_cur->laccwr = $curtime; } else if ($user->sess != "") { $user_cur->stat = "room"; $user_cur->subst = "standup"; + $user_cur->laccwr = $curtime; $user_cur->table = -1; } } @@ -422,6 +479,7 @@ class brisco { else { $user->stat = "room"; $user->subst = "standup"; + $user->laccwr = $curtime; } /* aggiorna l'array dei giocatori al tavolo. */ $table->user_rem(&$this, &$user); @@ -555,7 +613,13 @@ class brisco { if (strncmp($user_mesg, "/nick ", 6) == 0) { log_main($user->sess, "chatt_send BEGIN"); - $name_new = str_replace(' ', '_', substr(trim(substr($user_mesg, 6)),0,12)); + if (($name_new = validate_name(substr($user_mesg, 6))) == FALSE) { + $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; + $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)); + $user->step++; + + return; + } $user_mesg = "COMMAND ".$user_mesg; // Search dup name // change @@ -662,6 +726,7 @@ class brisco { * * RETURN VALUE: * if ($idx != -1 && ret == FALSE) => duplicated nick + * if ($idx == -2 && ret == FALSE) => invalid name * if ($idx == -1 && ret == FALSE) => no space left * if (ret == TRUE) => SUCCESS */ @@ -670,6 +735,11 @@ class brisco { $idx = -1; $idfree = -1; + if (($name_new = validate_name($name)) == FALSE) { + $idx = -2; + return (FALSE); + } + log_auth("XXX", sprintf("ARRIVA: [%s]", $sess)); if (validate_sess($sess) == FALSE) $sess = ""; @@ -683,7 +753,7 @@ class brisco { if ($idfree == -1 && strcmp("", $this->user[$i]->sess) == 0) { $idfree = $i; } - if (strcmp($this->user[$i]->name, $name) == 0) { + if (strcmp($this->user[$i]->name, $name_new) == 0) { $idx = $i; break; } @@ -691,7 +761,7 @@ class brisco { if ($idx == -1) $idx = $idfree; - log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name)); + log_auth("XXX", sprintf("TROVATO A QUESTO PUNTO [%d] sess [%s] name [%s]", $idx, $sess, $name_new)); if ($idx != -1 && $i == MAX_PLAYERS) { /* SUCCESS */ @@ -703,11 +773,12 @@ class brisco { else { $this->user[$idx]->sess = $sess; } - $this->user[$idx]->name = $name; + $this->user[$idx]->name = $name_new; $this->user[$idx]->stat = "room"; $this->user[$idx]->subst = "standup"; + $this->user[$idx]->laccwr = time(); - log_main("XXX", sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name)); + log_main("XXX", sprintf("TROVATO LIBERO A [%d] sess [%s] name [%s]", $idx, $sess, $name_new)); return ($this->user[$idx]); } @@ -1021,6 +1092,7 @@ function briscola_show($bri, $table, $user) $ret .= sprintf('$("callerimg").src = "img/%02d.png";', $table->briscola); $ret .= sprintf('$("caller").style.visibility = "visible";'); $ret .= sprintf('$("chooseed").style.visibility = "hidden";'); + $ret .= sprintf('$("astalascio").style.visibility = "";'); $ret .= sprintf('$("asta").style.visibility = "hidden";'); $ret .= sprintf('show_astat(-2,-2,-2,-2,-2);'); @@ -1084,6 +1156,10 @@ function show_table_info(&$bri, &$table, $table_pos) $noty .= sprintf('