]> git.pond.sub.org Git - empserver/commitdiff
(shut): Buffer passed to getstarg() was much too small. Deity could
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 12 Jun 2005 15:33:53 +0000 (15:33 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 12 Jun 2005 15:33:53 +0000 (15:33 +0000)
overrun it.

(shut): Fix retrieval of second argument.

(shut): Simplify formatting of broadcast messages.

src/lib/commands/shut.c

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