2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * empdis.c: Empire dispatcher stuff
30 * Known contributors to this file:
35 #include "prototypes.h"
56 #define KEEP_COMMANDS 50
57 s_char player_commands[KEEP_COMMANDS][1024 + 8];
58 int player_commands_index = 0;
61 getcommand(s_char *combufp)
66 /* Note this now assumes a 1024 byte buffer is being passed in */
67 natp = getnatp(player->cnum);
68 if (++player_commands_index >= KEEP_COMMANDS)
69 player_commands_index = 0;
70 sprintf(player_commands[player_commands_index], "%3d %3d [prompt]",
71 player_commands_index, player->cnum);
73 prprompt(natp->nat_minused, natp->nat_btu);
75 if (recvclient(buf, 1024) < 0) {
78 } while (buf[0] == 0);
79 if (++player_commands_index >= KEEP_COMMANDS)
80 player_commands_index = 0;
81 sprintf(player_commands[player_commands_index], "%3d %3d %s",
82 player_commands_index, player->cnum, buf);
84 return (strlen(combufp));
88 init_player_commands(void)
92 for (i = 0; i < KEEP_COMMANDS; ++i)
93 *player_commands[i] = 0;
97 log_last_commands(void)
101 logerror("Most recent player commands:");
102 for (i = player_commands_index; i >= 0; --i)
103 if (*player_commands[i])
104 logerror("%s", player_commands[i] + 4);
105 for (i = KEEP_COMMANDS - 1; i > player_commands_index; --i)
106 if (*player_commands[i])
107 logerror("%s", player_commands[i] + 4);
113 register s_char *format;
116 pr("\t\tCurrent EMPIRE Command List\n");
117 pr("\t\t------- ------ ------- ----\n");
118 pr("Initial number is cost in B.T.U. units.\n");
119 pr("Next 2 chars (if present) are:\n");
120 pr("$ - must be non-broke\tc -- must have capital\n");
121 pr("Args in [brackets] are optional.\n");
122 if (player->nstat > 4) {
123 pr("All-caps args in <angle brackets>");
124 pr(" have the following meanings:\n");
125 pr(" <NUM> :: a number in unspecified units\n");
126 pr(" <COMM> :: a commodity such as `food', `guns', etc\n");
127 pr(" <VAR> :: a commodity such as `food', `guns', etc\n");
128 pr(" <TYPE> :: an item type such as `ship', `plane', etc\n");
130 for (i = 0; (format = player_coms[i].c_form) != 0; i++) {
131 if ((player_coms[i].c_permit & player->ncomstat) ==
132 player_coms[i].c_permit) {
133 pr("%2d ", player_coms[i].c_cost);
134 if ((player_coms[i].c_permit & MONEY) == MONEY)
138 if ((player_coms[i].c_permit & CAP) == CAP)
145 pr("For further info on command syntax see \"info Syntax\".\n");
150 * returns true if down
157 s_char buf[MAXTELSIZE]; /* buf is message text */
161 if ((down_fp = fopen(downfil, "rb")) == NULL)
163 if (fread((void *)&tgm, sizeof(tgm), 1, down_fp) != 1) {
164 logerror("bad header on login message (downfil)");
168 if (tgm.tel_length >= (long)sizeof(buf)) {
169 logerror("text length (%ld) is too long for login message (downfil)", tgm.tel_length);
173 if (fread(buf, tgm.tel_length, 1, down_fp) != 1) {
174 logerror("bad length %ld on login message", tgm.tel_length);
178 buf[tgm.tel_length] = 0;
180 pr("\nThe game is down\n");
186 daychange(time_t now)
191 natp = getnatp(player->cnum);
192 tm = localtime(&now);
193 if ((tm->tm_yday % 128) != natp->nat_dayno) {
194 natp->nat_dayno = tm->tm_yday % 128;
195 natp->nat_minused = 0;
200 getminleft(time_t now, int mpd)
207 tm = localtime(&now);
208 natp = getnatp(player->cnum);
209 nminleft = mpd - natp->nat_minused;
210 n = 60 * 24 - (tm->tm_min + tm->tm_hour * 60);