#define d007
#include "adv1.h"
#include "adv0.h"
#ifdef FILE
#undef FILE
#endif
#ifdef d000
#ifndef CONSOLE
#define CONSOLE
#endif
#ifndef NO_READLINE
#define NO_READLINE
#endif
#ifndef NO_SLOW
#define NO_SLOW
#endif
#endif
#ifdef c001
#include "z043.h"
#endif 
#ifdef m046
#ifndef l000
#define l000
#endif
#endif 
#ifdef l000
#ifndef NO_READLINE
#define NO_READLINE
#endif
#ifndef CONSOLE
#define CONSOLE
#endif
#endif 
#if defined(CONSOLE)&&defined(q051)
#undef q051
#endif
#if (defined(__cplusplus) || defined(z000)) && !defined(__STDC__)
#define __STDC__ 1
#endif
#ifdef CONSOLE
#ifdef q051
#undef q051
#endif
#else
#define q051
#endif
#include <fcntl.h>
#include <time.h>
#define y056(X) { char *u046 = X; while (*u046) o003(*u046++); }
#ifdef q051
#if t000
#include <z066.h>
#include <a062.h>
#define y071 i067
#else 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#define y071 close
#endif 
#endif
#if t000 && !defined(d000)
#include <windows.h>
#endif 
#if !defined(NO_SLOW) && t000
#ifdef __STDC__
void x002 (int k073) 
#else
void x002 (k073) int k073; 
#endif
{ SleepEx(k073, 0); return; } 
#endif 
#if t000
#define q050 '\\'
#else
#define q050 '/'
#endif
#if !t000 || defined(d000)
#include <dirent.h>
#endif 
#include <stdio.h>
#ifdef __STDC__
int n041 (int c067, char *w053) 
#else
int n041 (c067, w053) int c067; char *w053; 
#endif
{ char h047[64]; 
#if t000 && !defined(d000)
int o058 = -1; WIN32_FIND_DATA b071; HANDLE k074; 
#else 
int o058 = 0; DIR *w061; struct dirent *l062; 
#endif 
char *u057; *(h047 + 63) = '\0'; 
#if t000 && !defined(d000)
if (c067 < 1 && strlen (w053) > 57) return (0); sprintf (h047, "%s\\*.adv",
"."); if ((k074 = FindFirstFile (h047, &b071)) == INVALID_HANDLE_VALUE)
#else 
if ((w061 = opendir(".")) == NULL) 
#endif 
return (0); while (1) { 
#if t000 && !defined(d000)
if (o058 >= 0) { if (FindNextFile(k074, &b071) == 0) break; } else o058
= 0; strncpy(h047, b071.cFileName, 63); if (*h047 == '.' || *h047 == '_'
|| strcmp (u057 = h047 + strlen(h047) - 4, ".adv") != 0) continue; 
#else 
if ((l062 = readdir(w061)) == NULL) break; strncpy (h047, l062->d_name,
63); if ((c067 >= 0 && *h047 == '.') || strcmp (u057 = h047 + strlen(h047)
- 4, ".adv") != 0) continue; 
#endif 
*u057 = '\0'; o058++; if (c067 != 0) { if (c067 < 0) { if (c067-- != -1)
o003 ('|'); y056 (h047); } else { if (o058 > 1) y056 (c067 == o058 ? " and "
: ", ") if (z006) { o003 (f000); o003 ('b'); o003 (n001); } y056 (h047)
if (z006) { o003 (f000); o003 ('/'); o003 ('b'); o003 (n001); } } } } 
#if t000 && !d000
FindClose(k074); 
#else 
closedir (w061); 
#endif 
if (o058 == 0) return (0); if (c067 > 0) y056 (".\n"); return (o058); }
#if t001 && !defined(l000)
void l061(int x066) { static char u058[80]; char g058[80]; char c004[160];
FILE *z052; int i = 0; if (x066 == 0) { *u058 = '\0'; z052 = e073("osascript -e 'tell application \"Terminal\" to get the name of window 1'",
"r"); fgets(u058, 79, z052); t060(z052); if (strstr(u058, "-bash ")) *u058
= '\0'; } else { while (1) { *g058 = '\0'; sprintf(c004, "osascript -e 'tell application \"Terminal\" to get the name of window %d' 2>/dev/null",
++i); z052 = e073(c004, "r"); fgets(g058, 79, z052); t060(z052); if (!*g058)
break; if (strcmp(g058, u058) == 0) { sprintf(c004, "osascript -e 'tell application \"Terminal\" to close window %d'",
i); system(c004); break; } } } } 
#endif 
#ifdef q051
int u059 = 0; int i068 = 0; int l063 = 1978; char *j060 = "20 21!22\"23#25%26&27'28(29)2A*2B+2C,2F/3A:3B;3D=3F?40@5B[5D]";
void l064 (void) { int n064 = 1; struct protoent *l065; struct sockaddr_in
q071; int a063 = 0; memset ((char *)&q071, 0, sizeof(q071)); q071.sin_family
= AF_INET; q071.sin_addr.s_addr = inet_addr("127.0.0.1"); if ((l065 = getprotobyname
("tcp")) == NULL) { fprintf (stderr, "Failed to find protocol TCP!\n");
exit (-1); } if ((u059 = socket (AF_INET, SOCK_STREAM, l065->p_proto)) <
0) { perror(""); fprintf (stderr, "Failed to create listennig socket!\n");
exit (-1); } setsockopt(u059, SOL_SOCKET, SO_REUSEADDR, (void *)&n064, sizeof(int));
while (1) { q071.sin_port = htons (l063); if (bind (u059, (struct sockaddr
*)&q071, sizeof(q071)) == 0) break; l063++; a063++; if (a063 == 100) { fprintf
(stderr,"Failed to bind listening socket!\n"); exit (-1); } } if (listen
(u059, 10) < 0) { fprintf (stderr,"Failed to set up listener!\n"); exit
(-1); } } void o005 (char *x054) { int t058; int a051 = 1024; 
#ifdef DEBUG
printf ("=== Entering %s\n", "browser_write"); 
#endif 
x054 = q003 (x054); t058 = strlen (x054); while (t058 > 0) { if (t058 <
a051) a051 = t058; send (i068, x054, a051, 0); x054 += a051; t058 -= a051;
} y071 (i068); i068 = 0; 
#ifdef DEBUG
printf ("=== Exiting %s\n", "browser_write"); 
#endif 
} int u003 (char *s058, int i069) { int a051; char b072[4096]; char *x054
= b072; char *j051; int i062 = 'N'; int x067 = ' '; int l066; struct sockaddr_in
i070; fd_set e074; struct timeval u047; int m068; 
#ifdef DEBUG
printf ("=== Entering %s\n", "browser_read"); 
#endif 
FD_ZERO(&e074); FD_SET(u059, &e074); while (1) { u047.tv_sec = i069; u047.tv_usec
= 0; m068 = select (FD_SETSIZE, &e074, (fd_set *) 0, (fd_set *) 0, &u047);
if (!m068) { fprintf (stderr, "*** No response from browser! ***\n"); 
#if t001 && !defined(l000)
l061(1); 
#endif 
exit (1); } l066 = sizeof(i070); if (i068) { y071 (i068); i068 = 0; } if
((i068 = accept (u059, (struct sockaddr *)&i070, (socklen_t *)&l066)) <
0) { fprintf(stderr, "Failed to accept incoming call!\n"); exit (-1); }
x054 = b072; while (1) { a051 = recv (i068, x054, sizeof(b072) - 1, 0);
*(x054 + a051) = '\0'; j051 = x054 + 1; x067 = *x054; x054 += a051; while
(j051 < x054) { if (x067 == '\n' && *j051 == '\n') { a051 = 0; break; }
if (*j051 != '\r') x067 = *j051; j051++; } if (a051 == 0) break; } if (strstr
(b072, "IE 5.0")) { fprintf (stderr, "*ERROR* Sorry, this setup does not work with IE 5.0.\n");
exit (1); } if (strncmp (b072, "GET", 3) != 0) { y071 (i068); continue;
} if ((x054 = strstr (b072, "status=")) != NULL) { j051 = x054 + 7; if (*j051
== '0' && *(j051 + 1) == 'x') { j051 += 2; if (*j051 == 'R' || *j051 ==
'S') i062 = *j051; else { b004 (); continue; } } else { while (*j051 >=
'0' && *j051 <= '9') j051++; j051++; } } if (strstr (b072, "favicon") !=
NULL) { send (i068, "HTTP/1.0 404 Not found\nContent-Length: 0\n\n", 42,
0); y071 (i068); continue; } break; } if (s058) { x054 = s058; while (*j051
!= ' ' && *j051 != '\n') { if (*j051 == '%') { char *i071 = j060; while
(*i071) { if (*i071 == *(j051 + 1) && *(i071 + 1) == *(j051 + 2)) { *x054++
= *(i071 + 2); j051 += 3; break; } i071 += 3; } if (*i071) continue; } *x054++
= *j051; j051++; } *x054++ = '\n'; *x054 = '\0'; } 
#ifdef DEBUG
printf ("=== Exiting %s: '%s'\n", "browser_read", s058); 
#endif 
return (i062); } void f005 (char *c068, int u047) { char v067 [256]; int
v068 = 0; int tm = time(NULL) % 10000; 
#if t000
h056 y072; f064 d066; j061 b073; c069(0e075, &b073); 
#endif 
#ifdef DEBUG
printf ("=== Entering %s\n", "invoke_browser"); 
#endif 
l064 (); 
#if t000
sprintf (v067, "%s http://localhost:%d/%d/", c068, l063, tm); f065( &y072,
sizeof(y072) ); y072.v069 = sizeof(y072); f065( &d066, sizeof(d066) ); if
(!a064(NULL, v067, NULL, NULL, 0, 0, NULL, NULL, &y072, &d066)) { printf
("*ERROR* Failed to kick off '%s'!\n", v067); exit (-1); } 
#else 
if (isatty (1)) fputs ("Invoking browser...\n", stderr); if (fork () ==
0) { int r080; y071 (u059); u059 = 0; sprintf (v067, "http://localhost:%d/%d/",
l063, tm); fflush(stdout); close (0); close (1); r080 = dup(2); close(2);
execl (c068, c068, v067, (char *)NULL); dup(r080); dup (r080); printf ("*ERROR* Failed to exec %s!\n",
c068); exit (1); } 
#if !defined(DEBUG) && !defined(g070)
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); 
#if t001 && !defined(l000)
l061(0); 
#endif 
i = open ("/dev/null", O_RDWR); dup (i); dup (i); } 
#endif 
#endif 
v068 = u003 (NULL, u047); if (v068 != 'R') { if (v068 == 'N') n004(); while
((v068 = u003 (NULL, u047)) == 'N') b004(); } 
#ifdef DEBUG
printf ("=== Exiting %s\n", "invoke_browser"); 
#endif 
} 
#endif 

