(shut): Buffer passed to getstarg() was much too small. Deity could

overrun it.

(shut): Fix retrieval of second argument.

(shut): Simplify formatting of broadcast messages.
This commit is contained in:
Markus Armbruster 2005-06-12 15:33:53 +00:00
parent cb454a1f56
commit 24672e351b

View file

@ -46,8 +46,8 @@ shut(void)
{ {
int shutdown_minutes; int shutdown_minutes;
int shutdown_was_pending; int shutdown_was_pending;
s_char buf[100]; char buf[1024];
s_char newbuf[100]; s_char msgbuf[100]; /* user text */
struct natstr *us; struct natstr *us;
s_char *p; s_char *p;
@ -61,20 +61,20 @@ shut(void)
if (shutdown_minutes < 0) if (shutdown_minutes < 0)
return RET_SYN; return RET_SYN;
if (!updates_disabled()) if (!updates_disabled())
if (!(p = getstarg(player->argp[3], "Disable update [y]? ", buf)) if (!(p = getstarg(player->argp[2], "Disable update [y]? ", buf))
|| *p != 'n') || *p != 'n')
disa(); disa();
shutdown_was_pending = shutdown_pending; shutdown_was_pending = shutdown_pending;
shutdown_pending = shutdown_minutes + !!shutdown_minutes; shutdown_pending = shutdown_minutes + !!shutdown_minutes;
buf[0] = '\0'; msgbuf[0] = '\0';
if (shutdown_was_pending) { if (shutdown_was_pending) {
if (shutdown_minutes) { if (shutdown_minutes) {
sprintf(buf, sprintf(msgbuf,
"The shutdown time has been changed to %d minutes", ": The shutdown time has been changed to %d minutes!",
shutdown_minutes); shutdown_minutes);
} else { } else {
sprintf(buf, "The server shutdown has been cancelled"); sprintf(msgbuf, ": The server shutdown has been cancelled!");
} }
} else if (shutdown_minutes) { } else if (shutdown_minutes) {
pr("Shutdown sequence begun.\n"); pr("Shutdown sequence begun.\n");
@ -83,19 +83,17 @@ shut(void)
0, "shutdownSeq", "Counts down server shutdown", 0); 0, "shutdownSeq", "Counts down server shutdown", 0);
} }
us = getnatp(player->cnum); us = getnatp(player->cnum);
if (buf[0]) { if (msgbuf[0]) {
sprintf(newbuf, ": %s!", buf); sendmessage(us, 0, msgbuf, 1);
sendmessage(us, 0, newbuf, 1); pr("%s\n", msgbuf + 2);
pr("%s.\n", buf); logerror(msgbuf + 2);
logerror(buf);
} }
if (shutdown_minutes) { if (shutdown_minutes) {
sprintf(buf, "The server will shut down in %d minutes", sprintf(msgbuf, ": The server will shut down in %d minutes!",
shutdown_minutes); shutdown_minutes);
sprintf(newbuf, ": %s!", buf); sendmessage(us, 0, msgbuf, 1);
sendmessage(us, 0, newbuf, 1); pr("%s\n", msgbuf + 2);
pr("%s.\n", buf); logerror(msgbuf + 2);
logerror(buf);
} }
return RET_OK; return RET_OK;
} }