From e2e69a29d505285c989b4f5ff2bf38489ba89b99 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 1 Jul 2011 20:12:37 +0200 Subject: [PATCH] Fix execute to filter input just like the main command loop 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 | 2 -- src/lib/player/player.c | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/player/empdis.c b/src/lib/player/empdis.c index 93162521..f3c5ef5c 100644 --- a/src/lib/player/empdis.c +++ b/src/lib/player/empdis.c @@ -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; diff --git a/src/lib/player/player.c b/src/lib/player/player.c index 03498f6e..bf6d682a 100644 --- a/src/lib/player/player.c +++ b/src/lib/player/player.c @@ -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) {