]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/player.c
Fix trailing whitespace
[empserver] / src / lib / player / player.c
index 43249fdd36c979ccf5a41e18de77a2838e6e3d3e..14a7aaddac8e267840b9017d5afcb60ceb55b3c6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  player.c: Main command loop for a player
- * 
+ *
  *  Known contributors to this file:
  *     Steve McClure, 2000
+ *     Markus Armbruster, 2004-2008
+ *     Ron Koenderink, 2004-2007
  */
 
 #include <config.h>
@@ -110,9 +112,8 @@ player_main(struct player *p)
     }
 
     while (status()) {
-       if (command() == 0 && !player->aborted)
-           break;
-       player->aborted = 0;
+       command();
+       player->aborted = player->eof;
        empth_yield();
     }
     /* #*# I put the following line in to prevent server crash -KHS */
@@ -157,24 +158,27 @@ status(void)
     int old_nstat, minute;
     char buf[128];
 
-    if (player->state == PS_SHUTDOWN)
+    if (player->eof || player->state == PS_SHUTDOWN)
        return 0;
     natp = getnatp(player->cnum);
-    if (io_error(player->iop) || io_eof(player->iop)) {
-       putnat(natp);
-       return 0;
-    }
     if (player->dolcost > 100.0)
        pr("That just cost you $%.2f\n", player->dolcost);
     else if (player->dolcost < -100.0)
        pr("You just made $%.2f\n", -player->dolcost);
-    natp->nat_money -= roundavg(player->dolcost);
-    player->dolcost = 0.0;
+    if (player->dolcost != 0.0) {
+       /*
+        * Hackish work around for a race condition in the nightly
+        * build's regression tests: sometimes the update starts right
+        * after the force command yields, sometimes a bit later.  If
+        * it is late, we use one random number here, for the bye,
+        * and throwing off the random sequence.
+        */
+       natp->nat_money -= roundavg(player->dolcost);
+       player->dolcost = 0.0;
+    }
 
     old_nstat = player->nstat;
     player_set_nstat(player, natp);
-    if (player->god)
-       player->nstat |= CAP | MONEY;
     if ((old_nstat & MONEY) && !(player->nstat & MONEY))
        pr("You are now broke; industries are on strike.\n");
     if (!(old_nstat & MONEY) && (player->nstat & MONEY))
@@ -239,7 +243,6 @@ status(void)
 }
 
 /*
- * actually a command; redirection and piping ignored.
  * XXX This whole mess should be redone; execute block should
  * start with "exec start", and should end with "exec end".
  * We'll wait until 1.2 I guess.
@@ -254,7 +257,6 @@ execute(void)
     char scanspace[1024];
 
     failed = 0;
-    redir = NULL;
 
     if (player->comtail[1])
        p = player->comtail[1];
@@ -265,6 +267,7 @@ execute(void)
     prexec(p);
 
     while (!failed && status()) {
+       player->nstat &= ~EXEC;
        if (recvclient(buf, sizeof(buf)) < 0)
            break;
        if (parse(buf, scanspace, player->argp, player->comtail,
@@ -272,16 +275,18 @@ execute(void)
            failed = 1;
            continue;
        }
-       if (redir == NULL)
-           pr("\nExecute : %s\n", buf);
-       if (dispatch(buf, redir) < 0)
+       pr("\nExecute : %s\n", buf);
+       if (redir) {
+           pr("Execute : redirection not supported\n");
+           failed = 1;
+       } else if (dispatch(buf, NULL) < 0)
            failed = 1;
     }
     if (failed) {
        while (recvclient(buf, sizeof(buf)) >= 0) ;
     }
-    if (redir == NULL)
-       pr("Execute : %s\n", failed ? "aborted" : "terminated");
+
+    pr("Execute : %s\n", failed ? "aborted" : "terminated");
     player->eof = 0;
     return RET_OK;
 }
@@ -294,12 +299,12 @@ show_motd(void)
     char buf[MAXTELSIZE + 1];  /* UTF-8 */
 
     if ((motd_fp = fopen(motdfil, "rb")) == NULL) {
-       if (errno == ENOENT)
+       if (errno == ENOENT)
            return RET_OK;
        else {
            pr ("Could not open motd.\n");
            logerror("Could not open motd (%s).\n", motdfil);
-           return RET_SYS;
+           return RET_FAIL;
        }
     }
     if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {