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, *s = src;
123 for (i = 0; i < size; i++)
138 INPUT_RECORD InpBuffer[10];
141 SECURITY_ATTRIBUTES security;
144 extern s_char *getenv();
145 extern s_char empireport[];
146 extern s_char empirehost[];
149 struct ioqueue server;
153 s_char *auxout_fname;
159 struct sockaddr_in sin;
167 err = WSAStartup(0x0101, &WsaData);
168 if (err == SOCKET_ERROR) {
169 printf("WSAStartup Failed\n");
173 mask = bit_newfdmask();
174 savemask = bit_newfdmask();
176 bzero((s_char *)argv, sizeof(argv));
177 saveargv(ac, av, argv);
180 for (i = j = 1; i < ac; ++i) {
182 if (strcmp(ptr, "-2") == 0) {
184 fprintf(stderr, "-2: Missing filename!\n");
187 auxout_fname = argv[i + 1];
190 } else if (strcmp(ptr, "-k") == 0) {
198 if (auxout_fname && (auxout_fp = fopen(auxout_fname, "a")) == NULL) {
199 fprintf(stderr, "Unable to open %s for append\n", auxout_fname);
203 pwd = getpwuid(getuid());
205 fprintf(stderr, "You don't exist. Go away\n");
210 if (!hostport(getenv("EMPIREPORT"), &sin) &&
211 !hostport("empire", &sin) && !hostport(empireport, &sin)) {
212 fprintf(stderr, "No empire port\n");
215 if (!hostaddr(getenv("EMPIREHOST"), &sin) &&
216 !hostaddr(empirehost, &sin)) {
217 fprintf(stderr, "No empire host\n");
220 if ((sock = hostconnect(&sin)) < 0)
222 cname = getenv("COUNTRY");
223 pname = getenv("PLAYER");
229 if (!login(sock, pwd->pw_name, cname, pname, send_kill)) {
231 if (!login(sock, "win-empcl2.8", cname, pname, send_kill)) {
236 ioq_init(&server, 2048);
238 mask = bit_newfdmask();
240 BIT_SETB(0, savemask);
241 BIT_SETB(sock, savemask);
243 (void)signal(SIGINT, intr);
245 (void)signal(SIGPIPE, SIG_IGN);
246 while (BIT_ISSETB(sock, savemask)) {
247 bit_copy(savemask, mask);
248 n = select(sock + 1, (fd_set *) mask, (fd_set *) 0, (fd_set *) 0,
249 (struct timeval *)0);
251 if (!handleintr(sock))
256 if (errno == EINTR) {
259 BIT_CLRB(sock, savemask);
262 if (BIT_ISSETB(0, mask)) {
263 if (!termio(0, sock, auxout_fp)) {
264 if (retry++ >= RETRY) {
265 BIT_CLRB(0, savemask);
271 if (BIT_ISSETB(sock, mask)) {
272 if (!serverio(sock, &server))
273 BIT_CLRB(sock, savemask);
275 servercmd(&server, auxout_fp);
283 security.nLength = sizeof(SECURITY_ATTRIBUTES);
284 security.lpSecurityDescriptor = NULL;
285 security.bInheritHandle = TRUE;
286 hStdIn = CreateFile("CONIN$",
287 GENERIC_READ | GENERIC_WRITE,
288 FILE_SHARE_READ | FILE_SHARE_WRITE,
289 &security, OPEN_EXISTING, (DWORD) NULL, NULL);
291 if (hStdIn == INVALID_HANDLE_VALUE) {
292 printf("Error getting hStdIn.\n");
295 err = GetConsoleMode(hStdIn, &stdinmode);
297 printf("Error getting console mode.\n");
300 stdinmode |= ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
301 err = SetConsoleMode(hStdIn, stdinmode);
303 printf("Error setting console mode.\n");
308 FD_SET(sock, &readfds);
309 n = select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0,
310 (struct timeval *)&tm);
312 if (errno == EINTR) {
313 errno = WSAGetLastError();
319 if (WaitForSingleObject(hStdIn, 10) != WAIT_TIMEOUT) {
320 if (!termio(-1, sock, auxout_fp)) {
321 if (retry++ >= RETRY) {
327 FlushConsoleInputBuffer(hStdIn);
329 if (FD_ISSET(sock, &readfds)) {
330 if (!serverio(sock, &server))
333 servercmd(&server, auxout_fp);
342 return 0; /* Shut the compiler up */
354 signal(SIGINT, intr);