Fix execute to filter input just like the main command loop
authorMarkus Armbruster <armbru@pond.sub.org>
Fri, 1 Jul 2011 18:12:37 +0000 (20:12 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 9 Jul 2011 13:16:21 +0000 (15:16 +0200)
When we added input filtering in v4.2.21, we missed the execute
command.  Because of that, funny characters can be treated differently
in batch files.

The main command loop uses getcommand(), which filters input.
execute() uses recvclient() directly, and doesn't filter input.  Both
feed the command to parse(), which drops unwanted control and
non-ASCII characters.

Input filtering drops unwanted control characters and, for ASCII
sessions, replaces non-ASCII characters by '?'.

Because of that, execute in ASCII sessions drops non-ASCII command
characters in batch files rather than replacing them.

Except where parts of the command are used raw: execute's command
echo, flash and wall message argument.  There, unwanted control
characters aren't dropped in UTF-8 sessions, and non-ASCII characters
are interpreted as UTF-8 in ASCII sessions.  Output filtering replaces
any resulting non-ASCII characters.

players column "last command" also uses the command raw, but commands
executed from batch files are not visible there, so it isn't affected.

To get rid of the differences, move the prompting from getcommand() to
command(), then switch execute() over to getcommand().

Side effect: the batch file's commands are now recorded in
player_commands[].  That's desirable.

src/lib/player/empdis.c
src/lib/player/player.c

index 93162521bc001839dc406d0e567c822bdcbff725..f3c5ef5c4cbd7f925946cbd24f0efde059b34566 100644 (file)
@@ -69,10 +69,8 @@ static void disable_coms(void);
 int
 getcommand(char *combufp)
 {
-    struct natstr *natp = getnatp(player->cnum);
     char buf[1024];            /* user text */
 
-    prprompt(natp->nat_timeused / 60, natp->nat_btu);
     if (recvclient(buf, sizeof(buf)) < 0)
        return -1;
 
index 03498f6eb852c2c7c9287f0d431e8c57c353aa3f..bf6d682a3d1e850785231e164fa2928b7f7a75cd 100644 (file)
@@ -115,16 +115,18 @@ player_main(struct player *p)
 static int
 command(void)
 {
+    struct natstr *natp = getnatp(player->cnum);
     char *redir;               /* UTF-8 */
     char scanspace[1024];
     time_t now;
 
+    prprompt(natp->nat_timeused / 60, natp->nat_btu);
     if (getcommand(player->combuf) < 0)
        return player->aborted;
 
     now = time(NULL);
     update_timeused(now);
-    if (!player->god && !may_play_now(getnatp(player->cnum), now))
+    if (!player->god && !may_play_now(natp, now))
        return 0;
 
     if (parse(player->combuf, scanspace, player->argp, player->comtail,
@@ -255,7 +257,7 @@ execute(void)
 
     while (!failed && status()) {
        player->nstat &= ~EXEC;
-       if (recvclient(buf, sizeof(buf)) < 0)
+       if (getcommand(buf) < 0)
            break;
        if (parse(buf, scanspace, player->argp, player->comtail,
                  &player->condarg, &redir) < 0) {