2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * empdis.c: Empire dispatcher stuff
30 * Known contributors to this file:
37 #include "prototypes.h"
58 #define KEEP_COMMANDS 50
60 /* ring buffer of most recent command prompts and commands, user text */
61 static char player_commands[KEEP_COMMANDS][1024 + 8];
63 /* the slot holding the most recent command in player_commands[] */
64 static int player_commands_index = 0;
67 * Get a command from the current player into COMBUFP[1024], in UTF-8.
68 * This may block for input, yielding the processor. Flush buffered
69 * output when blocking, to make sure player sees the prompt.
70 * Return command's byte length on success, -1 on error.
73 getcommand(char *combufp)
75 struct natstr *natp = getnatp(player->cnum);
76 char buf[1024]; /* user text */
78 if (++player_commands_index >= KEEP_COMMANDS)
79 player_commands_index = 0;
80 sprintf(player_commands[player_commands_index], "%3d %3d [prompt]",
81 player_commands_index, player->cnum);
84 prprompt(natp->nat_minused, natp->nat_btu);
86 if (recvclient(buf, 1024) < 0) {
89 } while (buf[0] == 0);
91 if (++player_commands_index >= KEEP_COMMANDS)
92 player_commands_index = 0;
93 sprintf(player_commands[player_commands_index], "%3d %3d %s",
94 player_commands_index, player->cnum, buf);
96 if (player->flags & PF_UTF8)
97 return copy_utf8_no_funny(combufp, buf);
98 return copy_ascii_no_funny(combufp, buf);
102 init_player_commands(void)
106 for (i = 0; i < KEEP_COMMANDS; ++i)
107 *player_commands[i] = 0;
111 log_last_commands(void)
115 logerror("Most recent player commands:");
116 for (i = player_commands_index; i >= 0; --i)
117 if (*player_commands[i])
118 logerror("%s", player_commands[i] + 4);
119 for (i = KEEP_COMMANDS - 1; i > player_commands_index; --i)
120 if (*player_commands[i])
121 logerror("%s", player_commands[i] + 4);
127 register s_char *format;
130 pr("\t\tCurrent EMPIRE Command List\n"
131 "\t\t------- ------ ------- ----\n"
132 "Initial number is cost in B.T.U. units.\n"
133 "Next 2 chars (if present) are:\n"
134 "$ - must be non-broke\tc -- must have capital\n"
135 "Args in [brackets] are optional.\n"
136 "All-caps args in <angle brackets>"
137 " have the following meanings:\n"
138 " <NUM> :: a number in unspecified units\n"
139 " <COMM> :: a commodity such as `food', `guns', etc\n"
140 " <VAR> :: a commodity such as `food', `guns', etc\n"
141 " <TYPE> :: an item type such as `ship', `plane', etc\n");
142 for (i = 0; (format = player_coms[i].c_form) != 0; i++) {
143 if ((player_coms[i].c_permit & player->ncomstat) ==
144 player_coms[i].c_permit) {
145 pr("%2d ", player_coms[i].c_cost);
146 if ((player_coms[i].c_permit & MONEY) == MONEY)
150 if ((player_coms[i].c_permit & CAP) == CAP)
157 pr("For further info on command syntax see \"info Syntax\".\n");
162 * returns true if down
169 char buf[MAXTELSIZE + 1]; /* UTF-8 */
173 if ((down_fp = fopen(downfil, "rb")) == NULL)
175 if (fread(&tgm, sizeof(tgm), 1, down_fp) != 1) {
176 logerror("bad header on login message (downfil)");
180 if (tgm.tel_length >= (long)sizeof(buf)) {
181 logerror("text length (%ld) is too long for login message (downfil)", tgm.tel_length);
185 if (fread(buf, tgm.tel_length, 1, down_fp) != 1) {
186 logerror("bad length %ld on login message", tgm.tel_length);
190 buf[tgm.tel_length] = 0;
192 pr("\nThe game is down\n");
198 daychange(time_t now)
203 natp = getnatp(player->cnum);
204 tm = localtime(&now);
205 if ((tm->tm_yday % 128) != natp->nat_dayno) {
206 natp->nat_dayno = tm->tm_yday % 128;
207 natp->nat_minused = 0;
212 getminleft(time_t now, int mpd)
219 tm = localtime(&now);
220 natp = getnatp(player->cnum);
221 nminleft = mpd - natp->nat_minused;
222 n = 60 * 24 - (tm->tm_min + tm->tm_hour * 60);