+ function rules_change(&$bri, $user, $rules_id_s)
+ {
+ GLOBAL $G_lang;
+
+ //
+ // Rules: update version following loaded tcode
+ //
+ $ret = FALSE;
+ $curtime = time();
+
+ do {
+ if ($this->match_id != -1) {
+ // FIXME_LANG
+ $msg = sprintf("Stai già giocando la partita con codice %d.", $this->match_id);
+ break;
+ }
+
+ if ($this->asta_card != -1 || $this->asta_pla_n < BIN5_PLAYERS_N) {
+ // FIXME_LANG
+ $msg = sprintf("La partita è già stata avviata.");
+ break;
+ }
+
+ $rules_id = (int)$rules_id_s;
+ if (! in_array($rules_id, rules_keys())) {
+ // FIXME_LANG
+ $msg = "queste regole non esistono o non sono attive";
+ break;
+ }
+
+ if ($user->rules_get() == $rules_id) {
+ // FIXME_LANG
+ $msg = "hai già richiesto di usare queste regole";
+ break;
+ }
+
+ /* - the user is in the list, add the match_id to his profile
+ and check if he is the N'th to require continue - */
+
+ $rules_tot = 0;
+ for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+ $user_cur = &$bri->user[$this->player[$i]];
+
+ if ($user == $user_cur) {
+ $rules_tot += 1;
+ continue;
+ }
+
+ if ($user_cur->rules_get() == BIN5_USER_CONTINUE_INIT)
+ continue;
+
+ if ($user_cur->rules_get() != $rules_id)
+ break;
+ $rules_tot += 1;
+ }
+ if ($i < BIN5_PLAYERS_N) {
+ // FIXME_LANG
+ $msg = sprintf("<b>L'utente <i>%s</i> voleva già usare le %s.</b>",
+ xcape($user_cur->name), xcape(rules_id2descr($user_cur->rules_get(), $G_lang)));
+ break;
+ }
+
+ // set the match_id for the current user
+ $user->rules_set($rules_id);
+
+ $ret = TRUE;
+ // not all players set the continue match than we exit
+ if ($rules_tot < BIN5_PLAYERS_N) {
+ // FIXME_LANG
+ $msg = sprintf("<b>L'utente <i>%s</i> vorrebbe usare le %s.</b>",
+ xcape($user->name), xcape(rules_id2descr($rules_id, $G_lang)));
+ break;
+ }
+
+ /* - all users decide to continue the same match, update all infos and rearrange users
+ to the right positions on the table - */
+
+ /* update rules engine */
+ $rules_name = rules_id2name($rules_id);
+ $this->rules = new $rules_name($this);
+
+ // $this->game_init($bri->user);
+
+ /* reload of the page with the new layout */
+ for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+ $user_cur = &$bri->user[$this->player[$i]];
+ $this->rules->tourn_points($user_cur, $i);
+
+ $user_cur->rules_set(BIN5_USER_CONTINUE_INIT);
+ $user_cur->trans_step = $user_cur->step + 1;
+ $user_cur->comm[$user_cur->step % COMM_N] = sprintf('gst.st_loc++; gst.st=%d; xstm.stop(); window.onunload = null ; window.onbeforeunload = null ; document.location.assign("index.php");|', $user_cur->step+1);
+ $user_cur->step_inc();
+
+ // a void command force xynt-streamer to flush all data to client
+ $user_cur->trans_step = $user_cur->step + 1;
+ $user_cur->comm[$user_cur->step % COMM_N] = "";
+ $user_cur->step_inc();
+
+ $user_cur->comm[$user_cur->step % COMM_N] = show_table($bri, $user_cur, $user_cur->step+1, TRUE, FALSE);
+ $user_cur->step_inc();
+ }
+ return (TRUE);
+ } while (FALSE);
+
+ $dt = date("H:i ", $curtime);
+ if ($ret == TRUE) {
+ for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
+ $user_cur = &$bri->user[$this->player[$i]];
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
+ $user_cur->comm[$user_cur->step % COMM_N] .= nickserv_msg($dt, $msg);
+ $user_cur->step_inc();
+ }
+ }
+ else {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ $user->comm[$user->step % COMM_N] = xcape(sprintf("rules_set(%d);",
+ $this->rules->id));
+ $user->comm[$user->step % COMM_N] .= nickserv_msg($dt, $msg);
+ $user->step_inc();
+ }
+ } // end function rules_change