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:
47 extern s_char *gettag();
50 static s_char the_prompt[1024];
77 s_char *ioq_gets(struct ioqueue *, s_char *, int);
82 while (ioq_gets(ioq, buf, sizeof(buf))) {
84 while (*p && !isspace(*p))
88 code = 10 + (*buf - 'a');
93 if (sscanf(p, "%d %d", &nbtu, &nmin) != 2) {
94 fprintf(stderr, "prompt: bad server prompt %s\n", p);
97 sprintf(the_prompt, "[%d:%d] Command : ", nbtu, nmin);
108 sprintf(the_prompt, "%s", p);
116 p[strlen(p)-1] = '\0';
117 sprintf(num_teles, "(%s) ", p + 1);
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",name);
196 mode = O_WRONLY | O_CREAT;
199 else if (how[1] == '!')
204 fprintf(stderr, "Null file name after redirect\n");
208 if ((fd = open(name, mode, 0600)) < 0) {
209 fprintf(stderr, "Redirect open failed\n");
212 redir_fp = fdopen(fd, "w");
218 * opens "pipe_fp" if successful
224 extern FILE *popen();
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))
265 fprintf(stderr, "WARNING! Server attempted unauthorized read of file %s\n",p);
269 fprintf(stderr, "Null file to execute\n");
274 if ((fd = open(p, O_RDONLY, 0)) < 0) {
276 if ((fd = open(p, O_RDONLY|O_BINARY, 0)) < 0) {
278 fprintf(stderr, "Can't open execute file\n");
283 /* copies 4k at a time to the socket */
284 while (termio(fd, sock, auxfi)) /*do copy*/;
285 /* Some platforms don't send the eof (cntl-D) at the end of
286 copying a file. If emp_client hangs at the end of an
287 execute, include the following line and notify wolfpack
288 of the platform you are using.
296 output(code, buf, auxfi)
306 (void) fflush(stdout);
308 (void) fflush(auxfi);
313 fprintf(auxfi, "Aborted\n");
319 fprintf(auxfi, "Error; ");
324 fprintf(auxfi, "Exit: ");
333 fprintf(auxfi, "%s", buf);
335 (void) fflush(auxfi);
337 (void) putc('\n', auxfi);
341 fprintf(redir_fp, "%s\n", buf);
343 fprintf(pipe_fp, "%s\n", buf);
350 (void) fflush(stdout);
352 (void) putc('\n', stdout);
358 register s_char *buf;
360 register s_char *sop;
363 while ((c = *buf++)) {
365 for (sop = SO; putc(*sop, stdout); sop++)
367 (void) putc(c & 0x7f, stdout);
368 for (sop = SE; putc(*sop, stdout); sop++)
371 (void) putc(c, stdout);