]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/player.c
Show treasury status on EOF, quit, shutdown
[empserver] / src / lib / player / player.c
index d93211eb939a460437a450be5a20aef612158e2d..c770c55388ae646f2c19df4043ad729d715bcc1b 100644 (file)
@@ -115,20 +115,21 @@ player_main(struct player *p)
 static int
 command(void)
 {
+    struct natstr *natp = getnatp(player->cnum);
     char *redir;               /* UTF-8 */
-    char scanspace[1024];
     time_t now;
 
+    prprompt(natp->nat_timeused / 60, natp->nat_btu);
     if (getcommand(player->combuf) < 0)
        return player->aborted;
 
     now = time(NULL);
     update_timeused(now);
-    if (!player->god && !may_play_now(getnatp(player->cnum), now))
+    if (!player->god && !may_play_now(natp, now))
        return 0;
 
-    if (parse(player->combuf, scanspace, player->argp, player->comtail,
-             &player->condarg, &redir) < 0) {
+    if (parse(player->combuf, player->argbuf, player->argp,
+             player->comtail, &player->condarg, &redir) < 0) {
        pr("See \"info Syntax\"?\n");
     } else {
        if (dispatch(player->combuf, redir) < 0)
@@ -144,8 +145,6 @@ status(void)
     int old_nstat;
     char buf[128];
 
-    if (player->eof || player->state == PS_SHUTDOWN)
-       return 0;
     natp = getnatp(player->cnum);
     if (player->dolcost > 100.0)
        pr("That just cost you $%.2f\n", player->dolcost);
@@ -172,8 +171,10 @@ status(void)
 
     time(&player->curup);
     update_timeused(player->curup);
-    if (!may_play_now(natp, player->curup))
+    if (player->eof || player->state == PS_SHUTDOWN
+       || !may_play_now(natp, player->curup))
        return 0;
+
     if (player->btused) {
        natp->nat_btu -= player->btused;
        player->btused = 0;
@@ -202,19 +203,6 @@ status(void)
     return 1;
 }
 
-/* Is ARG one of the player's last command's arguments?  */
-static int
-is_command_arg(char *arg)
-{
-    int i;
-
-    for (i = 1; i < 128 && player->argp[i]; i++) {
-       if (arg == player->argp[i])
-           return 1;
-    }
-    return 0;
-}
-
 /*
  * Make all objects stale if ARG is one of the player's command arguments.
  * See ef_make_stale() for what "making stale" means.
@@ -228,7 +216,8 @@ is_command_arg(char *arg)
 void
 make_stale_if_command_arg(char *arg)
 {
-    if (is_command_arg(arg))
+    if (player->argbuf <= arg
+       && arg <= player->argbuf + sizeof(player->argbuf))
        ef_make_stale();
 }
 
@@ -240,29 +229,32 @@ make_stale_if_command_arg(char *arg)
 int
 execute(void)
 {
-    char buf[1024];
+    char buf[1024];            /* UTF-8 */
     int failed;
-    char *p;
+    char *p;                   /* UTF-8 */
     char *redir;               /* UTF-8 */
-    char scanspace[1024];
 
     failed = 0;
 
-    p = getstarg(player->comtail[1], "File? ", buf);
+    p = player->comtail[1];
+    if (!p)
+       p = ugetstring("File? ", buf);
     if (p == NULL || *p == '\0')
        return RET_SYN;
     prexec(p);
 
     while (!failed && status()) {
        player->nstat &= ~EXEC;
-       if (recvclient(buf, sizeof(buf)) < 0)
+       if (getcommand(player->combuf) < 0)
            break;
-       if (parse(buf, scanspace, player->argp, player->comtail,
-                 &player->condarg, &redir) < 0) {
+       if (parse(player->combuf, player->argbuf, player->argp,
+                 player->comtail, &player->condarg, &redir) < 0) {
            failed = 1;
            continue;
        }
-       pr("\nExecute : %s\n", buf);
+       pr("\nExecute : ");
+       uprnf(buf);
+       pr("\n");
        if (redir) {
            pr("Execute : redirection not supported\n");
            failed = 1;