#ifdef FILE
#undef FILE
#endif
#ifdef w004
#ifndef CONSOLE
#define CONSOLE
#endif
#ifndef NO_READLINE
#define NO_READLINE
#endif
#ifndef NO_SLOW
#define NO_SLOW
#endif
#endif
#ifdef a000
#ifndef k032
#define k032
#endif
#include "f028.h"
#endif 
#ifdef t039
#ifndef k032
#define k032
#endif
#endif 
#ifdef k032
#ifndef NO_READLINE
#define NO_READLINE
#endif
#ifndef CONSOLE
#define CONSOLE
#endif
#endif 
#if defined(__unix__) || defined(__linux__)
#if !defined(HAVE_UNISTD_H) && !defined(m029)
#define HAVE_UNISTD_H
#endif 
#endif 
#if defined(CONSOLE)&&defined(e033)
#undef e033
#endif
#if !defined(w004)&&(defined(WIN32)||defined(_WIN32)||defined(__WIN32)||defined (_WIN32_)||defined(__WIN32__))
#define u031 1
#define m028 0
#define l029 0
#else
#define u031 0
#define m028 1
#define l029 0
#if defined(_MACH_)
#undef l029
#define l029 1
#endif
#endif
#if (defined(__cplusplus) || defined(z000)) && !defined(__STDC__)
#define __STDC__ 1
#endif
#ifdef CONSOLE
#ifdef e033
#undef e033
#endif
#else
#define e033
#endif
#if defined(HAVE_CONFIG_H)
#include "config.h"
#if defined (HAVE_STRING_H)
#include <string.h>
#else 
#if defined(HAVE_STRINGS_H)
#include <strings.h>
#endif 
#endif 
#if defined(HAVE_STDLIB_H)
#include <stdlib.h>
#endif 
#if defined (HAVE_SYS_STAT_H)
#include <sys/stat.h>
#endif 
#if defined (HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif 
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#else 
#if u031
#define unlink _unlink
#else 
int unlink(char *); 
#endif 
#endif 
#else 
#include <string.h>
#include <stdlib.h>
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#else
#if u031
#define unlink _unlink
#else 
int unlink(char *); 
#endif 
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif 
#include <time.h>
#include "adv0.h"
#define t006
#include "adv1.h"
#define l036(X) { char *q028 = X; while (*q028) x002(*q028++); }
#ifdef e033
#if u031
#include <u049.h>
#include <w047.h>
#define y064 x059
#else 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#define y064 close
#endif 
#endif
#if u031
#include <windows.h>
#endif 
#if !defined(NO_SLOW) && u031
#ifdef __STDC__
void j006 (int y065) 
#else
void j006 (y065) int y065; 
#endif
{ SleepEx(y065, 0); return; } 
#endif 
#if u031
#define y039 '\\'
#else
#define y039 '/'
#endif
#if !u031
#include <dirent.h>
#endif 
#include <stdio.h>
#ifdef __STDC__
int x039 (int t065, char *d039) 
#else
int x039 (t065, d039) int t065; char *d039; 
#endif
{ char r041[64]; 
#if u031
int b034 = -1; WIN32_FIND_DATA a049; HANDLE b050; 
#else 
int b034 = 0; DIR *f048; struct dirent *o047; 
#endif 
char *n055; *(r041 + 63) = '\0'; 
#if u031
if (t065 < 1 && strlen (d039) > 57) return (0); sprintf (r041, "%s\\*.adv",
"."); if ((b050 = FindFirstFile (r041, &a049)) == INVALID_HANDLE_VALUE)
#else 
if ((f048 = opendir(".")) == NULL) 
#endif 
return (0); while (1) { 
#if u031
if (b034 >= 0) { if (FindNextFile(b050, &a049) == 0) break; } else b034
= 0; strncpy(r041, a049.cFileName, 63); if (*r041 == '.' || *r041 == '_'
|| strcmp (n055 = r041 + strlen(r041) - 4, ".adv") != 0) continue; 
#else 
if ((o047 = readdir(f048)) == NULL) break; strncpy (r041, o047->d_name,
63); if ((t065 >= 0 && *r041 == '.') || strcmp (n055 = r041 + strlen(r041)
- 4, ".adv") != 0) continue; 
#endif 
*n055 = '\0'; b034++; if (t065 != 0) { if (t065 < 0) { if (t065-- != -1)
x002 ('|'); l036 (r041); } else { if (b034 > 1) l036 (t065 == b034 ? " and "
: ", ") if (y008) { x002 (y001); x002 ('b'); x002 (n001); } l036 (r041)
if (y008) { x002 (y001); x002 ('/'); x002 ('b'); x002 (n001); } } } } 
#if u031
FindClose(b050); 
#else 
closedir (f048); 
#endif 
if (b034 == 0) return (0); if (t065 > 0) l036 (".\n"); return (b034); }
#ifdef e033
int l049 = 0; int d044 = 0; int y066 = 1978; char *r052 = "20 21!22\"23#25%26&27'28(29)2A*2B+2C,2F/3A:3B;3D=3F?40@5B[5D]";
void a050 (void) { int t066 = 1; struct protoent *u050; struct sockaddr_in
c058; int l050 = 0; memset ((char *)&c058, 0, sizeof(c058)); c058.sin_family
= AF_INET; c058.sin_addr.s_addr = inet_addr("127.0.0.1"); if ((u050 = getprotobyname
("tcp")) == NULL) { fprintf (stderr, "Failed to find protocol TCP!\n");
exit (-1); } if ((l049 = socket (AF_INET, SOCK_STREAM, u050->p_proto)) <
0) { perror(""); fprintf (stderr, "Failed to create listennig socket!\n");
exit (-1); } setsockopt(l049, SOL_SOCKET, SO_REUSEADDR, (void *)&t066, sizeof(int));
while (1) { c058.sin_port = htons (y066); if (bind (l049, (struct sockaddr
*)&c058, sizeof(c058)) == 0) break; y066++; l050++; if (l050 == 100) { fprintf
(stderr,"Failed to bind listening socket!\n"); exit (-1); } } if (listen
(l049, 10) < 0) { fprintf (stderr,"Failed to set up listener!\n"); exit
(-1); } } void v003 (char *b033) { int c056; int y053 = 1024; 
#ifdef DEBUG
printf ("=== Entering %s\n", "browser_write"); 
#endif 
b033 = j005 (b033); c056 = strlen (b033); while (c056 > 0) { if (c056 <
y053) y053 = c056; send (d044, b033, y053, 0); b033 += y053; c056 -= y053;
} y064 (d044); d044 = 0; 
#ifdef DEBUG
printf ("=== Exiting %s\n", "browser_write"); 
#endif 
} int y007 (char *k065, int w048) { int y053; char j057[4096]; char *b033
= j057; char *s045; int m042 = 'N'; int d045 = ' '; int z046; struct sockaddr_in
g054; fd_set n056; struct timeval n039; int v052; 
#ifdef DEBUG
printf ("=== Entering %s\n", "browser_read"); 
#endif 
FD_ZERO(&n056); FD_SET(l049, &n056); while (1) { n039.tv_sec = w048; n039.tv_usec
= 0; v052 = select (FD_SETSIZE, &n056, (fd_set *) 0, (fd_set *) 0, &n039);
if (!v052) { fprintf (stderr, "*** No response from browser! ***\n"); exit
(1); } z046 = sizeof(g054); if (d044) { y064 (d044); d044 = 0; } if ((d044
= accept (l049, (struct sockaddr *)&g054, (socklen_t *)&z046)) < 0) { fprintf(stderr,
"Failed to accept incoming call!\n"); exit (-1); } b033 = j057; while (1)
{ y053 = recv (d044, b033, sizeof(j057) - 1, 0); *(b033 + y053) = '\0';
s045 = b033 + 1; d045 = *b033; b033 += y053; while (s045 < b033) { if (d045
== '\n' && *s045 == '\n') { y053 = 0; break; } if (*s045 != '\r') d045 =
*s045; s045++; } if (y053 == 0) break; } if (strstr (j057, "IE 5.0")) {
fprintf (stderr, "*ERROR* Sorry, this setup does not work with IE 5.0.\n");
exit (1); } if (strncmp (j057, "GET", 3) != 0) { y064 (d044); continue;
} if ((b033 = strstr (j057, "status=")) != NULL) { s045 = b033 + 7; if (*s045
== '0' && *(s045 + 1) == 'x') { s045 += 2; if (*s045 == 'R' || *s045 ==
'S') m042 = *s045; else { v004 (); continue; } } else { while (*s045 >=
'0' && *s045 <= '9') s045++; s045++; } } if (strstr (j057, "favicon") !=
NULL) { send (d044, "HTTP/1.0 404 Not found\nContent-Length: 0\n\n", 42,
0); y064 (d044); continue; } break; } if (k065) { b033 = k065; while (*s045
!= ' ' && *s045 != '\n') { if (*s045 == '%') { char *x060 = r052; while
(*x060) { if (*x060 == *(s045 + 1) && *(x060 + 1) == *(s045 + 2)) { *b033++
= *(x060 + 2); s045 += 3; break; } x060 += 3; } if (*x060) continue; } *b033++
= *s045; s045++; } *b033++ = '\n'; *b033 = '\0'; } 
#ifdef DEBUG
printf ("=== Exiting %s: '%s'\n", "browser_read", k065); 
#endif 
return (m042); } void m001 (char *e056, int n039) { char w049 [256]; int
t067 = 0; int tm = time(NULL) % 10000; 
#if u031
c059 v053; r053 a051; n057 t068; b051(0v054, &t068); 
#endif 
#ifdef DEBUG
printf ("=== Entering %s\n", "invoke_browser"); 
#endif 
a050 (); 
#if u031
sprintf (w049, "%s http://localhost:%d/%d/", e056, y066, tm); j058( &v053,
sizeof(v053) ); v053.r054 = sizeof(v053); j058( &a051, sizeof(a051) ); if
(!i049(NULL, w049, NULL, NULL, 0, 0, NULL, NULL, &v053, &a051)) { printf
("*ERROR* Failed to kick off '%s'!\n", w049); exit (-1); } 
#else 
if (isatty (1)) fputs ("Invoking browser...\n", stderr); if (fork () ==
0) { int m052; y064 (l049); l049 = 0; sprintf (w049, "http://localhost:%d/%d/",
y066, tm); fflush(stdout); close (0); close (1); m052 = dup(2); close(2);
execl (e056, e056, w049, (char *)NULL); dup(m052); dup (m052); printf ("*ERROR* Failed to exec %s!\n",
e056); exit (1); } 
#if !defined(DEBUG) && !defined(o048)
if (getppid() != 1) { int i; if (isatty (1)) fputs ("Daemonising game server...\n",
stderr); if (fork() > 0) exit (0); setsid (); close (0); close (1); close
(2); i = open ("/dev/null", O_RDWR); dup (i); dup (i); } 
#endif 
#endif 
t067 = y007 (NULL, n039); if (t067 != 'R') { if (t067 == 'N') b004(); while
((t067 = y007 (NULL, n039)) == 'N') v004(); } 
#ifdef DEBUG
printf ("=== Exiting %s\n", "invoke_browser"); 
#endif 
} 
#endif 

