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 * main.c: client main function
30 * Known contributors to this file:
53 #include <sys/socket.h>
54 #include <netinet/in.h>
112 for (i = 0; i < size; i++)
116 bcopy(src, dest, size)
117 unsigned char *src, *dest;
121 unsigned char *d = dest,
124 for (i = 0; i < size; i++)
139 INPUT_RECORD InpBuffer[10];
142 SECURITY_ATTRIBUTES security;
145 extern s_char *getenv();
146 extern s_char empireport[];
147 extern s_char empirehost[];
150 struct ioqueue server;
154 s_char *auxout_fname;
160 struct sockaddr_in sin;
168 err = WSAStartup (0x0101, &WsaData);
169 if (err == SOCKET_ERROR) {
170 printf ("WSAStartup Failed\n");
174 mask = bit_newfdmask();
175 savemask = bit_newfdmask();
177 bzero((s_char *)argv, sizeof(argv));
178 saveargv(ac, av, argv);
181 for (i = j = 1; i < ac; ++i) {
183 if (strcmp(ptr, "-2") == 0) {
185 fprintf(stderr, "-2: Missing filename!\n");
188 auxout_fname = argv[i+1];
192 else if (strcmp(ptr, "-k") == 0) {
200 if (auxout_fname && (auxout_fp = fopen(auxout_fname, "a")) == NULL) {
201 fprintf(stderr, "Unable to open %s for append\n", auxout_fname);
205 pwd = getpwuid(getuid());
207 fprintf(stderr, "You don't exist. Go away\n");
212 if (!hostport(getenv("EMPIREPORT"), &sin) &&
213 !hostport("empire", &sin) &&
214 !hostport(empireport, &sin)) {
215 fprintf(stderr, "No empire port\n");
218 if (!hostaddr(getenv("EMPIREHOST"), &sin) &&
219 !hostaddr(empirehost, &sin)) {
220 fprintf(stderr, "No empire host\n");
223 if ((sock = hostconnect(&sin)) < 0)
225 cname = getenv("COUNTRY");
226 pname = getenv("PLAYER");
232 if (!login(sock, pwd->pw_name, cname, pname, send_kill)) {
234 if (!login(sock, "win-empcl2.8", cname, pname, send_kill)) {
239 ioq_init(&server, 2048);
241 mask = bit_newfdmask();
243 BIT_SETB(0, savemask);
244 BIT_SETB(sock, savemask);
246 (void) signal(SIGINT, intr);
248 (void) signal(SIGPIPE, SIG_IGN);
249 while (BIT_ISSETB(sock, savemask)) {
250 bit_copy(savemask, mask);
251 n = select(sock+1, (fd_set *)mask, (fd_set *)0, (fd_set *)0,
252 (struct timeval *)0);
254 if (!handleintr(sock))
259 if (errno == EINTR) {
262 BIT_CLRB(sock, savemask);
265 if (BIT_ISSETB(0, mask)) {
266 if (!termio(0, sock, auxout_fp)) {
267 if (retry++ >= RETRY) {
268 BIT_CLRB(0, savemask);
274 if (BIT_ISSETB(sock, mask)) {
275 if (!serverio(sock, &server))
276 BIT_CLRB(sock, savemask);
278 servercmd(&server, auxout_fp);
286 security.nLength = sizeof(SECURITY_ATTRIBUTES);
287 security.lpSecurityDescriptor = NULL;
288 security.bInheritHandle = TRUE;
289 hStdIn = CreateFile("CONIN$",
290 GENERIC_READ | GENERIC_WRITE,
291 FILE_SHARE_READ | FILE_SHARE_WRITE,
297 if (hStdIn == INVALID_HANDLE_VALUE) {
298 printf("Error getting hStdIn.\n");
301 err = GetConsoleMode(hStdIn, &stdinmode);
303 printf("Error getting console mode.\n");
306 stdinmode |= ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT;
307 err = SetConsoleMode(hStdIn, stdinmode);
309 printf("Error setting console mode.\n");
314 FD_SET(sock, &readfds);
315 n = select(sock+1, &readfds, (fd_set *)0, (fd_set *)0,
316 (struct timeval *)&tm);
318 if (errno == EINTR) {
319 errno = WSAGetLastError();
325 if (WaitForSingleObject(hStdIn, 10) != WAIT_TIMEOUT) {
326 if (!termio(-1, sock, auxout_fp)) {
327 if (retry++ >= RETRY) {
333 FlushConsoleInputBuffer(hStdIn);
335 if (FD_ISSET(sock, &readfds)) {
336 if (!serverio(sock, &server))
339 servercmd(&server, auxout_fp);
348 return 0; /* Shut the compiler up */
360 signal(SIGINT, intr);