]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/player.c
(player_main): Add empth_yield() in the command processing loop to ensure
[empserver] / src / lib / player / player.c
index 7f8514ad77dc1c85954a474d21bf8fe28d9aade3..aa0f358cd9987b3be334ecd891a84fc202890703 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -72,7 +72,6 @@ player_main(struct player *p)
     player = p;
     time(&player->lasttime);
     time(&player->curup);
-    showvers(CLIENTPROTO);
     show_motd();
     if (init_nats() < 0)
        return;
@@ -104,8 +103,8 @@ player_main(struct player *p)
                                             nat_last_logout) : "?");
            pr("                  by: %s@%s\n",
               *natp->nat_userid ? natp->nat_userid : "nobody",
-              *natp->nat_hostname ? natp->nat_hostname : *natp->
-              nat_hostaddr ? natp->nat_hostaddr : "nowhere");
+              *natp->nat_hostname ? natp->nat_hostname
+              : *natp->nat_hostaddr ? natp->nat_hostaddr : "nowhere");
        }
     }
     if (*player->userid)
@@ -137,6 +136,7 @@ player_main(struct player *p)
        if (command() == 0 && !player->aborted)
            break;
        player->aborted = 0;
+       empth_yield();
     }
     /* #*# I put the following line in to prevent server crash -KHS */
     natp = getnatp(player->cnum);
@@ -159,7 +159,7 @@ int
 command(void)
 {
     unsigned int x;
-    char *redir;
+    char *redir;               /* UTF-8 */
     char scanspace[1024];
 
     if (getcommand(player->combuf) < 0)
@@ -304,21 +304,23 @@ status(void)
 int
 execute(void)
 {
-    char buf[512];
+    char buf[1024];
     int failed;
     char *p;
-    char *redir;
+    char *redir;               /* UTF-8 */
     char scanspace[1024];
 
     failed = 0;
-    redir = 0;
+    redir = NULL;
 
     p = getstarg(player->argp[1], "File? ", buf);
 
     if (p == NULL || *p == '\0')
        return RET_SYN;
 
+    /* FIXME should use raw argument here, to support UTF-8 file names */
     prexec(player->argp[1]);
+
     while (!failed && status()) {
        if (recvclient(buf, sizeof(buf)) < 0)
            break;
@@ -327,7 +329,7 @@ execute(void)
            failed = 1;
            continue;
        }
-       if (redir == 0)
+       if (redir == NULL)
            pr("\nExecute : %s\n", buf);
        if (dispatch(buf, redir) < 0)
            failed = 1;
@@ -335,7 +337,7 @@ execute(void)
     if (failed) {
        while (recvclient(buf, sizeof(buf)) >= 0) ;
     }
-    if (redir == 0)
+    if (redir == NULL)
        pr("Execute : %s\n", failed ? "aborted" : "terminated");
     return RET_OK;
 }
@@ -343,36 +345,37 @@ execute(void)
 int
 show_motd(void)
 {
-    int motdf;
+    FILE *motd_fp;
     struct telstr tgm;
-    char buf[MAXTELSIZE];
+    char buf[MAXTELSIZE + 1];  /* UTF-8 */
 
-    if ((motdf = open(motdfil, O_RDONLY, 0)) < 0)
-    {
+    if ((motd_fp = fopen(motdfil, "rb")) == NULL) {
        if (errno == ENOENT)
            return RET_OK;
-       else
-       {
+       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)) {
+    if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {
        logerror("bad header on login message (motdfil)");
-       close(motdf);
+       fclose(motd_fp);
+       return RET_FAIL;
+    }
+    if (tgm.tel_length >= (long)sizeof(buf)) {
+       logerror("text length (%ld) is too long for login message (motdfil)", tgm.tel_length);
+       fclose(motd_fp);
        return RET_FAIL;
     }
-    if (read(motdf, buf, tgm.tel_length) != tgm.tel_length) {
+    if (fread(buf, tgm.tel_length, 1, motd_fp) != 1) {
        logerror("bad length %ld on login message", tgm.tel_length);
-       close(motdf);
+       fclose(motd_fp);
        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(motdf);
+    uprnf(buf);
+    fclose(motd_fp);
     return RET_OK;
 }
 
@@ -384,7 +387,7 @@ match_user(char *file, struct player *p)
     char host[256];
     char user[256];
 
-    if ((fp = fopen(file, "rt")) == NULL) {
+    if ((fp = fopen(file, "r")) == NULL) {
        /*logerror("Cannot find file %s", file); */
        return 0;
     }