]> git.pond.sub.org Git - empserver/commitdiff
(turn): Change the command to allow for both an MOTD and a no-login
authorMarc Olzheim <marcolz@stack.nl>
Thu, 16 Dec 2004 14:17:08 +0000 (14:17 +0000)
committerMarc Olzheim <marcolz@stack.nl>
Thu, 16 Dec 2004 14:17:08 +0000 (14:17 +0000)
message.  Clean 'register' and 's_char' remnants on the way.
Circumvents bug #813167.

include/optlist.h
include/prototypes.h
info/Commands/turn.t
src/lib/commands/turn.c
src/lib/gen/emp_config.c
src/lib/global/path.c
src/lib/player/player.c

index e5b0295d5fd442b32193334fe4867d218fcc5263..9db5e2260c1308aeb30876fe412ea10d4139776d 100644 (file)
@@ -99,7 +99,7 @@ int start_unit_type[];
 #endif
 
 /* Variables that get values derived from econfig */
 #endif
 
 /* Variables that get values derived from econfig */
-extern char *upfil;
+extern char *motdfil;
 extern char *downfil;
 extern char *disablefil;
 extern char *banfil;
 extern char *downfil;
 extern char *disablefil;
 extern char *banfil;
index 781e562aeb71de292d002f3963f7cfe3906c920c..3df917ca95fd0a7fa67fbd3406ed7423b143529f 100644 (file)
@@ -261,7 +261,7 @@ extern int natbyname(s_char *, natid *);
 extern int natpass(int, s_char *);
 /* player.c */
 extern struct player *player;  /* current player's context */
 extern int natpass(int, s_char *);
 /* player.c */
 extern struct player *player;  /* current player's context */
-extern s_char *praddr(struct player *);
+extern char *praddr(struct player *);
 extern void player_main(struct player *);
 extern int match_user(char *, struct player *);
 extern int status(void);
 extern void player_main(struct player *);
 extern int match_user(char *, struct player *);
 extern int status(void);
index cb621b788c23d2a8085d20a651651ea5e9802af8..db918c30472999f2e9183af2c0579526ce13802c 100644 (file)
@@ -1,9 +1,10 @@
 .TH Command TURN
 .NA turn "Allow/disallow logins. Change login message."
 .LV Expert
 .TH Command TURN
 .NA turn "Allow/disallow logins. Change login message."
 .LV Expert
-.SY "turn <on|off|mess>"
-Use "turn on" or "turn off" to enable/disable logins.  If you just
-want to change the login message, then use "turn mess".  In all three
-cases, you will be put into the telegram prompter to enter a new motd
-(message of the day) which is printed when the player logs in.
+.SY "turn <on|off|motd>"
+Use "turn on" or "turn off" to enable/disable logins.  If you want to
+change the login message, then use "turn motd".  With "turn motd" and
+"turn off", you will be put into the telegram prompter to enter a new
+motd (message of the day) which is printed when the player logs in, or
+an additional "no-login" message printed while logins are disabled.
 .SA "Deity"
 .SA "Deity"
index e54bfb2899687203191f9e682fe889e2c578e7ed..4344b9837386129943ace4926f66d7655caa3008 100644 (file)
 #include "commands.h"
 #include "optlist.h"
 
 #include "commands.h"
 #include "optlist.h"
 
+#include <errno.h>
 #include <fcntl.h>
 
 #include <fcntl.h>
 
+/*
+ * Enable / disable logins and set the message of the day.
+ */
 int
 turn(void)
 {
     int fd;
     struct telstr tgm;
 int
 turn(void)
 {
     int fd;
     struct telstr tgm;
-    register s_char *p;
-    s_char buf[MAXTELSIZE];
+    char *p;
+    char buf[MAXTELSIZE];
+    char *msgfilepath;
 
 
-    p = getstarg(player->argp[1], "on, off or message? ", buf);
+    p = getstarg(player->argp[1], "on, off or motd? ", buf);
     if (!p)
        return RET_SYN;
     if (strcmp(p, "off") == 0) {
     if (!p)
        return RET_SYN;
     if (strcmp(p, "off") == 0) {
-       (void)unlink(upfil);
-#if !defined(_WIN32)
-       fd = open(downfil, O_RDWR | O_CREAT | O_TRUNC, 0660);
-#else
-       fd = open(downfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
-#endif
-       pr("off ");
+       msgfilepath = downfil;
     } else if (strcmp(p, "on") == 0) {
     } else if (strcmp(p, "on") == 0) {
-       (void)unlink(downfil);
-#if !defined(_WIN32)
-       fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC, 0660);
-#else
-       fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
-#endif
-       pr("on ");
+       pr("Removing no-login message and re-enabling logins.\n");
+       if ((unlink(downfil) == -1) && (errno != ENOENT))
+       {
+           pr("Could not remove no-login file, logins still disabled.\n");
+           logerror("Could not remove no-login file (%s).\n", downfil);
+           return RET_SYS;
+       }
+       return RET_OK;
     } else {
     } else {
+       msgfilepath = motdfil;
+    }
+
+    if (msgfilepath == downfil)
+       pr("Enter a message shown to countries trying to log in.\n");
+    else
+       pr("Enter a new message of the day.\n");
+
+    time(&tgm.tel_date);
+    tgm.tel_length = getele("The World", buf);
+
+    if (tgm.tel_length < 0)
+    {
+       pr("Ignored\n");
+       if (msgfilepath == downfil)
+           pr("NOT disabling logins.\n");
+       return RET_SYN;
+    } else if (tgm.tel_length == 0)
+    {
+       if (msgfilepath == motdfil)
+       {
+           pr("Removing exsting motd.\n");
+           if ((unlink(msgfilepath) == -1) && (errno != ENOENT))
+           {
+               pr("Could not remove motd.\n");
+               logerror("Could not remove motd file (%s).\n", msgfilepath);
+               return RET_SYS;
+           }
+           return RET_OK;
+       } else
+           pr("Writing empty no-login message.\n");
+    }
+
 #if !defined(_WIN32)
 #if !defined(_WIN32)
-       fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC, 0660);
+    fd = open(msgfilepath, O_RDWR | O_CREAT | O_TRUNC, 0660);
 #else
 #else
-       fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
+    fd = open(msgfilepath, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660);
 #endif
 #endif
-       pr("motd ");
+    if (fd == -1)
+    {
+       pr("Something went wrong opening the message file.\n");
+       logerror("Could not open message file (%s).\n", msgfilepath);
+       return RET_SYS;
     }
     }
-    (void)time(&tgm.tel_date);
-    if ((tgm.tel_length = getele("The World", buf)) <= 0) {
-       pr("Ignored\n");
-       close(fd);
-       return RET_SYN;
+
+    if (msgfilepath == downfil)
+       pr("Logins disabled.\n");
+
+    if ((write(fd, &tgm, sizeof(tgm)) < sizeof(tgm)) ||
+       (write(fd, buf, tgm.tel_length) < tgm.tel_length) ||
+       (close(fd) == -1))
+    {
+       pr("Something went wrong writing the message file.\n");
+       logerror("Could not properly write message file (%s).\n",
+           msgfilepath);
+       return RET_SYS;
     }
     }
-    (void)write(fd, (s_char *)&tgm, sizeof(tgm));
-    (void)write(fd, buf, tgm.tel_length);
-    (void)close(fd);
     pr("\n");
     pr("\n");
+
     return RET_OK;
 }
     return RET_OK;
 }
index 9c6ad4413cba3398655553e6848e195128e56d3a..0fe115529eeffe085d383a40ae6cc700f1a09e9c 100644 (file)
@@ -173,7 +173,7 @@ struct otherfiles {
 /* list of other well known files... -maybe tailor these oneday
  * anyway - meantime they are all relative to datadir */
 static struct otherfiles ofiles[] = {
 /* list of other well known files... -maybe tailor these oneday
  * anyway - meantime they are all relative to datadir */
 static struct otherfiles ofiles[] = {
-    {&upfil, "up"},
+    {&motdfil, "motd"},
     {&downfil, "down"},
     {&disablefil, "disable"},
     {&banfil, "ban"},
     {&downfil, "down"},
     {&disablefil, "disable"},
     {&banfil, "ban"},
index a93cc5b133036e78ac243c1f984e3a684692a757..cf2e515dc711e1420738cff695ae2e6734fefa0c 100644 (file)
@@ -39,7 +39,7 @@ char *infodir = EMPDIR "/info.nr";
 char *datadir  = EMPDIR "/data";
 char *teldir   = EMPDIR "/data/tel";
 
 char *datadir  = EMPDIR "/data";
 char *teldir   = EMPDIR "/data/tel";
 
-char *upfil    = EMPDIR "/data/up";
+char *motdfil  = EMPDIR "/data/motd";
 char *downfil  = EMPDIR "/data/down";
 char *disablefil = EMPDIR "/data/disable";
 char *telfil   = EMPDIR "/data/tel/tel";
 char *downfil  = EMPDIR "/data/down";
 char *disablefil = EMPDIR "/data/disable";
 char *telfil   = EMPDIR "/data/tel/tel";
index a4ba8ba46cae1c4807b211a4d5d0ed315be1c016..0506e391fec345d229d2d801a7d796b5ebe9c86d 100644 (file)
@@ -56,6 +56,7 @@
 #include <sys/time.h>
 #endif
 #include <stdio.h>
 #include <sys/time.h>
 #endif
 #include <stdio.h>
+#include <errno.h>
 #include <fcntl.h>
 
 struct player *player;
 #include <fcntl.h>
 
 struct player *player;
@@ -65,12 +66,12 @@ player_main(struct player *p)
 {
     struct natstr *natp;
     int secs;
 {
     struct natstr *natp;
     int secs;
-    s_char buf[128];
+    char buf[128];
 
     p->state = PS_PLAYING;
     player = p;
     time(&player->lasttime);
 
     p->state = PS_PLAYING;
     player = p;
     time(&player->lasttime);
-    (void)time(&player->curup);
+    time(&player->curup);
     showvers(CLIENTPROTO);
     show_motd();
     if (init_nats() < 0)
     showvers(CLIENTPROTO);
     show_motd();
     if (init_nats() < 0)
@@ -102,9 +103,9 @@ player_main(struct player *p)
               natp->nat_last_logout ? ctime(&natp->
                                             nat_last_logout) : "?");
            pr("                  by: %s@%s\n",
               natp->nat_last_logout ? ctime(&natp->
                                             nat_last_logout) : "?");
            pr("                  by: %s@%s\n",
-              *natp->nat_userid ? natp->nat_userid : (s_char *)"nobody",
+              *natp->nat_userid ? natp->nat_userid : "nobody",
               *natp->nat_hostname ? natp->nat_hostname : *natp->
               *natp->nat_hostname ? natp->nat_hostname : *natp->
-              nat_hostaddr ? natp->nat_hostaddr : (s_char *)"nowhere");
+              nat_hostaddr ? natp->nat_hostaddr : "nowhere");
        }
     }
     if (*player->userid)
        }
     }
     if (*player->userid)
@@ -158,8 +159,8 @@ int
 command(void)
 {
     unsigned int x;
 command(void)
 {
     unsigned int x;
-    s_char *redir;
-    s_char scanspace[1024];
+    char *redir;
+    char scanspace[1024];
 
     if (getcommand(player->combuf) < 0)
        return 0;
 
     if (getcommand(player->combuf) < 0)
        return 0;
@@ -171,7 +172,7 @@ command(void)
        /* DONT USE IT!!!! alarm and sleep may and dont work
           together -- Sasha */
        /* alarm((unsigned int)60*60); 1 hour */
        /* DONT USE IT!!!! alarm and sleep may and dont work
           together -- Sasha */
        /* alarm((unsigned int)60*60); 1 hour */
-       if (player->condarg != (s_char *)0)
+       if (player->condarg != NULL)
            for (x = 0; x < strlen(player->condarg); x++)
                if (isupper(*(player->condarg + x)))
                    *(player->condarg + x) =
            for (x = 0; x < strlen(player->condarg); x++)
                if (isupper(*(player->condarg + x)))
                    *(player->condarg + x) =
@@ -188,7 +189,7 @@ status(void)
     struct natstr *natp;
     int minute;
     struct sctstr sect;
     struct natstr *natp;
     int minute;
     struct sctstr sect;
-    s_char buf[128];
+    char buf[128];
 
     if (player->state == PS_SHUTDOWN)
        return 0;
 
     if (player->state == PS_SHUTDOWN)
        return 0;
@@ -236,7 +237,7 @@ status(void)
     if (natp->nat_flags & NF_SACKED)
        player->nstat &= ~CAP;  /* No capital yet */
     player->ncomstat = player->nstat;
     if (natp->nat_flags & NF_SACKED)
        player->nstat &= ~CAP;  /* No capital yet */
     player->ncomstat = player->nstat;
-    (void)time(&player->curup);
+    time(&player->curup);
     minute = (player->curup - player->lasttime) / 60;
     if (minute > 0) {
        player->minleft -= minute;
     minute = (player->curup - player->lasttime) / 60;
     if (minute > 0) {
        player->minleft -= minute;
@@ -303,18 +304,18 @@ status(void)
 int
 execute(void)
 {
 int
 execute(void)
 {
-    s_char buf[512];
+    char buf[512];
     int failed;
     int failed;
-    s_char *p;
-    s_char *redir;
-    s_char scanspace[1024];
+    char *p;
+    char *redir;
+    char scanspace[1024];
 
     failed = 0;
     redir = 0;
 
     p = getstarg(player->argp[1], "File? ", buf);
 
 
     failed = 0;
     redir = 0;
 
     p = getstarg(player->argp[1], "File? ", buf);
 
-    if (p == (s_char *)0 || *p == '\0')
+    if (p == NULL || *p == '\0')
        return RET_SYN;
 
     prexec(player->argp[1]);
        return RET_SYN;
 
     prexec(player->argp[1]);
@@ -342,31 +343,40 @@ execute(void)
 int
 show_motd(void)
 {
 int
 show_motd(void)
 {
-    int upf;
+    int motdf;
     struct telstr tgm;
     struct telstr tgm;
-    s_char buf[MAXTELSIZE];
+    char buf[MAXTELSIZE];
 
 #if !defined(_WIN32)
 
 #if !defined(_WIN32)
-    if ((upf = open(upfil, O_RDONLY, 0)) < 0)
+    if ((motdf = open(motdfil, O_RDONLY, 0)) < 0)
 #else
 #else
-    if ((upf = open(upfil, O_RDONLY | O_BINARY, 0)) < 0)
+    if ((motdf = open(motdfil, O_RDONLY | O_BINARY, 0)) < 0)
 #endif
 #endif
-       return RET_FAIL;
-    if (read(upf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) {
-       logerror("bad header on login message (upfil)");
-       close(upf);
+    {
+       if (errno == ENOENT)
+           return RET_OK;
+       else
+       {
+           pr ("Could not open motd.\n");
+           logerror("Could not open motd (%s).\n", motdfil);
+           return RET_SYS;
+       }
+    }
+    if (read(motdf, &tgm, sizeof(tgm)) != sizeof(tgm)) {
+       logerror("bad header on login message (motdfil)");
+       close(motdf);
        return RET_FAIL;
     }
        return RET_FAIL;
     }
-    if (read(upf, buf, tgm.tel_length) != tgm.tel_length) {
+    if (read(motdf, buf, tgm.tel_length) != tgm.tel_length) {
        logerror("bad length %ld on login message", tgm.tel_length);
        logerror("bad length %ld on login message", tgm.tel_length);
-       close(upf);
+       close(motdf);
        return RET_FAIL;
     }
     if (tgm.tel_length >= (long)sizeof(buf))
        tgm.tel_length = sizeof(buf) - 1;
     buf[tgm.tel_length] = 0;
     prnf(buf);
        return RET_FAIL;
     }
     if (tgm.tel_length >= (long)sizeof(buf))
        tgm.tel_length = sizeof(buf) - 1;
     buf[tgm.tel_length] = 0;
     prnf(buf);
-    (void)close(upf);
+    (void)close(motdf);
     return RET_OK;
 }
 
     return RET_OK;
 }
 
@@ -375,8 +385,8 @@ match_user(char *file, struct player *p)
 {
     FILE *fp;
     int match = 0;
 {
     FILE *fp;
     int match = 0;
-    s_char host[256];
-    s_char user[256];
+    char host[256];
+    char user[256];
 
     if ((fp = fopen(file, "r")) == NULL) {
        /*logerror("Cannot find file %s", file); */
 
     if ((fp = fopen(file, "r")) == NULL) {
        /*logerror("Cannot find file %s", file); */
@@ -408,7 +418,7 @@ quit(void)
     return RET_OK;
 }
 
     return RET_OK;
 }
 
-s_char *
+char *
 praddr(struct player *p)
 {
     return prbuf("%s@%s", p->userid,
 praddr(struct player *p)
 {
     return prbuf("%s@%s", p->userid,