2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 * servercmd.c: Change the state depending on the command from the server.
30 * Known contributors to this file:
51 extern s_char *gettag();
54 static s_char the_prompt[1024];
80 s_char *ioq_gets(struct ioqueue *, s_char *, int);
85 while (ioq_gets(ioq, buf, sizeof(buf))) {
87 while (*p && !isspace(*p))
91 code = 10 + (*buf - 'a');
96 if (sscanf(p, "%d %d", &nbtu, &nmin) != 2) {
97 fprintf(stderr, "prompt: bad server prompt %s\n", p);
100 sprintf(the_prompt, "[%d:%d] Command : ", nbtu, nmin);
111 sprintf(the_prompt, "%s", p);
119 p[strlen(p) - 1] = '\0';
120 sprintf(num_teles, "(%s) ", p + 1);
121 if (!redir_fp && !pipe_fp && !exec_fd) {
129 output(code, p, auxfi);
139 if (mode == C_PROMPT) {
141 (void)fclose(redir_fp);
143 } else if (pipe_fp) {
145 (void)pclose(pipe_fp);
148 } else if (exec_fd > 0) {
152 open("/dev/tty", O_RDONLY, 0);
155 if (mode == C_PROMPT)
157 printf("%s%s", num_teles, the_prompt);
158 (void)fflush(stdout);
160 fprintf(auxfi, "\n%s%s", num_teles, the_prompt);
166 * opens redir_fp if successful
179 (void)fclose(redir_fp);
183 if (*p && ((*p == '>') || (*p == '!')))
186 while (*p && isspace(*p))
189 while (*p && !isspace(*p))
193 fprintf(stderr, "WARNING! Server redirected output to file %s\n",
197 mode = O_WRONLY | O_CREAT;
200 else if (how[1] == '!')
205 fprintf(stderr, "Null file name after redirect\n");
209 if ((fd = open(name, mode, 0600)) < 0) {
210 fprintf(stderr, "Redirect open failed\n");
213 redir_fp = fdopen(fd, "w");
219 * opens "pipe_fp" if successful
230 while (*p && isspace(*p))
233 fprintf(stderr, "WARNING! Server attempted to run: %s\n", p);
237 fprintf(stderr, "Null program name after redirect\n");
242 if ((pipe_fp = popen(p, "w")) == 0) {
246 fprintf(stderr, "Pipe open failed\n");
262 while (*p && isspace(*p))
266 "WARNING! Server attempted unauthorized read of file %s\n",
271 fprintf(stderr, "Null file to execute\n");
276 if ((fd = open(p, O_RDONLY, 0)) < 0) {
278 if ((fd = open(p, O_RDONLY | O_BINARY, 0)) < 0) {
280 fprintf(stderr, "Can't open execute file\n");
285 /* copies 4k at a time to the socket */
286 while (termio(fd, sock, auxfi)) /*do copy */
288 /* Some platforms don't send the eof (cntl-D) at the end of
289 copying a file. If emp_client hangs at the end of an
290 execute, include the following line and notify wolfpack
291 of the platform you are using.
299 output(code, buf, auxfi)
309 (void)fflush(stdout);
316 fprintf(auxfi, "Aborted\n");
322 fprintf(auxfi, "Error; ");
327 fprintf(auxfi, "Exit: ");
336 fprintf(auxfi, "%s", buf);
340 (void)putc('\n', auxfi);
344 fprintf(redir_fp, "%s\n", buf);
346 fprintf(pipe_fp, "%s\n", buf);
353 (void)fflush(stdout);
355 (void)putc('\n', stdout);
361 register s_char *buf;
363 register s_char *sop;
366 while ((c = *buf++)) {
368 for (sop = SO; putc(*sop, stdout); sop++) ;
369 (void)putc(c & 0x7f, stdout);
370 for (sop = SE; putc(*sop, stdout); sop++) ;
372 (void)putc(c, stdout);