/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2000, 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
#include "tel.h"
#include "proto.h"
#include "com.h"
-#include "deity.h"
-#include "keyword.h"
#include "file.h"
#include "empio.h"
#include "subs.h"
#include <signal.h>
#define KEEP_COMMANDS 50
-s_char player_commands[KEEP_COMMANDS][1024 + 8];
-int player_commands_index = 0;
+/* ring buffer of most recent command prompts and commands, user text */
+static char player_commands[KEEP_COMMANDS][1024 + 8];
+
+/* the slot holding the most recent command in player_commands[] */
+static int player_commands_index = 0;
+
+/*
+ * Get a command from the current player into COMBUFP[1024], in UTF-8.
+ * Return command's byte length on success, -1 on error.
+ */
int
-getcommand(s_char *combufp)
+getcommand(char *combufp)
{
- struct natstr *natp;
- s_char buf[1024];
+ struct natstr *natp = getnatp(player->cnum);
+ char buf[1024]; /* user text */
+ int i;
-/* Note this now assumes a 1024 byte buffer is being passed in */
- natp = getnatp(player->cnum);
if (++player_commands_index >= KEEP_COMMANDS)
player_commands_index = 0;
sprintf(player_commands[player_commands_index], "%3d %3d [prompt]",
player_commands_index, player->cnum);
+
do {
prprompt(natp->nat_minused, natp->nat_btu);
buf[0] = 0;
return -1;
}
} while (buf[0] == 0);
+
if (++player_commands_index >= KEEP_COMMANDS)
player_commands_index = 0;
sprintf(player_commands[player_commands_index], "%3d %3d %s",
player_commands_index, player->cnum, buf);
- strcpy(combufp, buf);
- return (strlen(combufp));
+
+ if (player->flags & PF_UTF8)
+ return copy_utf8_no_funny(combufp, buf);
+ return copy_ascii_no_funny(combufp, buf);
}
void
int
explain(void)
{
- extern struct cmndstr player_coms[];
register s_char *format;
register int i;
int
gamedown(void)
{
- int downf;
+ FILE *down_fp;
struct telstr tgm;
- s_char buf[1024];
+ char buf[MAXTELSIZE + 1]; /* message text */
if (player->god)
return 0;
-#if !defined(_WIN32)
- if ((downf = open(downfil, O_RDONLY, 0)) < 0)
-#else
- if ((downf = open(downfil, O_RDONLY | O_BINARY, 0)) < 0)
-#endif
+ if ((down_fp = fopen(downfil, "rb")) == NULL)
return 0;
- if (read(downf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) {
+ if (fread(&tgm, sizeof(tgm), 1, down_fp) != 1) {
logerror("bad header on login message (downfil)");
- close(downf);
+ fclose(down_fp);
return 1;
}
- if (read(downf, buf, tgm.tel_length) != tgm.tel_length) {
- logerror("bad length %d on login message", tgm.tel_length);
- close(downf);
+ if (tgm.tel_length >= (long)sizeof(buf)) {
+ logerror("text length (%ld) is too long for login message (downfil)", tgm.tel_length);
+ fclose(down_fp);
+ return 1;
+ }
+ if (fread(buf, tgm.tel_length, 1, down_fp) != 1) {
+ logerror("bad length %ld on login message", tgm.tel_length);
+ fclose(down_fp);
return 1;
}
- if (tgm.tel_length >= (long)sizeof(buf))
- tgm.tel_length = sizeof(buf) - 1;
buf[tgm.tel_length] = 0;
- pr(buf);
+ uprnf(buf);
pr("\nThe game is down\n");
- (void)close(downf);
+ fclose(down_fp);
return 1;
}
}
int
-getminleft(time_t now, int *hour, int *mpd)
+getminleft(time_t now, int mpd)
{
- s_char *bp;
struct tm *tm;
int nminleft;
- int curtime;
struct natstr *natp;
int n;
tm = localtime(&now);
- curtime = tm->tm_min + tm->tm_hour * 60;
- if (NULL != (bp = kw_find("minutes")))
- kw_parse(CF_VALUE, bp, mpd);
natp = getnatp(player->cnum);
- nminleft = *mpd - natp->nat_minused;
- if (NULL != (bp = kw_find("hours"))) {
- /*
- * assume hours has already been set; just verify
- * that it is present
- */
- n = hour[1] - curtime;
- if (n < nminleft)
- nminleft = n;
- }
+ nminleft = mpd - natp->nat_minused;
n = 60 * 24 - (tm->tm_min + tm->tm_hour * 60);
if (n < nminleft)
nminleft = n;