]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/player.c
(execute): Use player->comtail[1] instead of player->argp[1]. This
[empserver] / src / lib / player / player.c
index 52eaefaf8e69dda0a879622cdf5a7f4bdc537c2b..89f63a7d0e033d2d606292ab50b297b3147546ae 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  * 
  *  Known contributors to this file:
  *     Steve McClure, 2000
- *     
  */
 
 #include <config.h>
 
-#include "prototypes.h"
-#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "com.h"
+#include "empio.h"
+#include "empthread.h"
+#include "file.h"
+#include "journal.h"
 #include "misc.h"
+#include "nat.h"
+#include "optlist.h"
 #include "player.h"
 #include "proto.h"
-#include "com.h"
-#include "nat.h"
+#include "prototypes.h"
 #include "sect.h"
-#include "file.h"
-#include "proto.h"
-#include "empio.h"
-#include "empthread.h"
 #include "tel.h"
-#include "gen.h"
-#include "subs.h"
-#include "common.h"
-#include "optlist.h"
 
-#if !defined(_WIN32)
-#include <unistd.h>
-#include <sys/time.h>
-#endif
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
 
+static int command(void);
 static int status(void);
 
 struct player *player;
@@ -76,8 +67,10 @@ player_main(struct player *p)
     time(&player->lasttime);
     time(&player->curup);
     show_motd();
-    if (init_nats() < 0)
+    if (init_nats() < 0) {
+       pr("Server confused, try again later\n");
        return;
+    }
     natp = getnatp(player->cnum);
     if (!gamehours(player->curup)) {
        pr("Empire hours restriction in force\n");
@@ -107,6 +100,7 @@ player_main(struct player *p)
 
     time(&natp->nat_last_login);
     putnat(natp);
+    journal_login();
     if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) {
        if (natp->nat_tgms == 1)
            pr("You have a new telegram waiting ...\n");
@@ -136,30 +130,21 @@ player_main(struct player *p)
        natp->nat_minused += 1;
     putnat(natp);
     pr("Bye-bye\n");
+    journal_logout();
 }
 
-int
+static int
 command(void)
 {
-    unsigned int x;
     char *redir;               /* UTF-8 */
     char scanspace[1024];
 
     if (getcommand(player->combuf) < 0)
        return 0;
-    if (parse(player->combuf, player->argp, &player->condarg,
-             scanspace, &redir) < 0) {
+    if (parse(player->combuf, scanspace, player->argp, player->comtail,
+             &player->condarg, &redir) < 0) {
        pr("See \"info Syntax\"?\n");
     } else {
-       /* XXX don't use alarm; use a scavenger thread */
-       /* DONT USE IT!!!! alarm and sleep may and dont work
-          together -- Sasha */
-       /* alarm((unsigned int)60*60); 1 hour */
-       if (player->condarg != NULL)
-           for (x = 0; x < strlen(player->condarg); x++)
-               if (isupper(*(player->condarg + x)))
-                   *(player->condarg + x) =
-                       tolower(*(player->condarg + x));
        if (dispatch(player->combuf, redir) < 0)
            pr("Try \"list of commands\" or \"info\"\n");
     }
@@ -181,7 +166,6 @@ status(void)
        putnat(natp);
        return 0;
     }
-    player->visitor = natp->nat_stat < STAT_SANCT;
     if (player->dolcost != 0.0) {
        if (player->dolcost > 100.0)
            pr("That just cost you $%.2f\n", player->dolcost);
@@ -266,7 +250,7 @@ status(void)
               numstr(buf, natp->nat_ann));
        natp->nat_ann = 0;
     }
-    if (!player->visitor && !player->god && (player->nstat & CAP) == 0)
+    if (natp->nat_stat == STAT_ACTIVE && (player->nstat & CAP) == 0)
        pr("You lost your capital... better designate one\n");
     putnat(natp);
     if (gamedown() && !player->god) {
@@ -294,19 +278,19 @@ execute(void)
     failed = 0;
     redir = NULL;
 
-    p = getstarg(player->argp[1], "File? ", buf);
-
+    if (player->comtail[1])
+       p = player->comtail[1];
+    else
+       p = getstring("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]);
+    prexec(p);
 
     while (!failed && status()) {
        if (recvclient(buf, sizeof(buf)) < 0)
            break;
-       if (parse(buf, player->argp, &player->condarg,
-                 scanspace, &redir) < 0) {
+       if (parse(buf, scanspace, player->argp, player->comtail,
+                 &player->condarg, &redir) < 0) {
            failed = 1;
            continue;
        }
@@ -320,6 +304,7 @@ execute(void)
     }
     if (redir == NULL)
        pr("Execute : %s\n", failed ? "aborted" : "terminated");
+    player->eof = 0;
     return RET_OK;
 }