+ function chatt_send(&$user, $mesg)
+ {
+ if ($user->stat == 'table') {
+ $table = &$this->table[$user->table];
+ }
+
+ $user_mesg = substr($mesg,6);
+
+ $timecur = time();
+
+ $dt = date("H:i ", $timecur);
+ if (strncmp($user_mesg, "/nick ", 6) == 0) {
+ log_main($user->sess, "chatt_send BEGIN");
+
+ 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_inc();
+
+ return;
+ }
+ $user_mesg = "COMMAND ".$user_mesg;
+ // Search dup name
+ // change
+ // update local graph
+ // update remote graphs
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ $user_cur = &$this->user[$i];
+ // if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ if ($user_cur->sess == '')
+ continue;
+ if ($user_cur->name == $name_new) {
+ $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; ";
+ $user->comm[$user->step % COMM_N] .= sprintf('chatt_sub("%s","Nickname <b>%s</b> già in uso.");', $dt.NICKSERV, xcape($name_new));
+ $user->step_inc();
+ break;
+ }
+ }
+ if ($i == MAX_PLAYERS) {
+ $user->name = $name_new;
+
+ log_main($user->sess, "chatt_send start set");
+
+
+ for ($i = 0 ; $i < MAX_PLAYERS ; $i++) {
+ log_main($user->sess, "chatt_send set loop");
+
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '')
+ continue;
+ if ($user_cur->stat == 'room') {
+ if ($user->stat == 'room' && $user->subst == 'standup') {
+ $this->standup_update(&$user);
+ }
+ else if ($user->stat == 'room' && $user->subst == 'sitdown' ||
+ $user->stat == 'table') {
+ log_main($user->sess, "chatt_send pre table update");
+
+ $this->table_update(&$user);
+
+ log_main($user->sess, "chatt_send post table update");
+ }
+ }
+ else if ($user_cur->stat == 'table' && $user_cur->table == $user->table) {
+ $table = &$this->table[$user->table];
+
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
+ $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('set_names(" %s", " %s", " %s", " %s", " %s"); ',
+ xcape($this->user[$table->player[($user_cur->table_pos)%PLAYERS_N]]->name),
+ xcape($this->user[$table->player[($user_cur->table_pos+1)%PLAYERS_N]]->name),
+ xcape($this->user[$table->player[($user_cur->table_pos+2)%PLAYERS_N]]->name),
+ (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+3)%PLAYERS_N]]->name)),
+ (PLAYERS_N == 3 ? "" : xcape($this->user[$table->player[($user_cur->table_pos+4)%PLAYERS_N]]->name)));
+ if ($user_cur == $user)
+ $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('$("myname").innerHTML = "<b>%s</b>";',
+ xcape($user->name,ENT_COMPAT,"UTF-8"));
+ $user_cur->step_inc();
+ }
+ }
+ }
+ }
+ else {
+ for ($i = 0 ; $i < ($user->stat == 'room' ? MAX_PLAYERS : PLAYERS_N) ; $i++) {
+ if ($user->stat == 'room') {
+ $user_cur = &$this->user[$i];
+ if ($user_cur->sess == '' || $user_cur->stat != 'room')
+ continue;
+ }
+ else {
+ $user_cur = &$this->user[$table->player[$i]];
+ }
+
+ $user_cur->comm[$user_cur->step % COMM_N] = "gst.st = ".($user_cur->step+1)."; ";
+ $user_cur->comm[$user_cur->step % COMM_N] .= sprintf('chatt_sub("%s","%s");',
+ $dt.xcape($user->name), xcape($user_mesg));
+ $user_cur->step_inc();
+ }
+ log_legal($timecur, $user->sess, $user->name,
+ ($user->stat == 'room' ? 'room' : 'table '.$user->table),$user_mesg);
+ }
+ }