-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
1516 lines (1353 loc) · 33.7 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* main.c
*/
#include "copyright.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
#include <pwd.h>
#ifdef hpux
#include <time.h>
#else /* hpux */
#include <sys/time.h>
#endif /* hpux */
#ifndef hpux
#include <sys/wait.h>
#endif /* hpux */
#include <sys/file.h>
#include "netrek.h"
#ifdef RECORD
#include "recorder.h"
#endif
jmp_buf env;
void gb();
#ifdef GATEWAY
/*-----------------------------------------------------------*/
/* we want these for the client subnet validation */
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
extern char *getenv ();
char *home, homedot[256];
#define DEFAULT_GATEWAY "rebel"
unsigned long mkaddr ();
int serv_port; /* used for blessedness checking */
static char *gateway = DEFAULT_GATEWAY;
#ifdef TREKHOPD
static int trekhopd_port = 6592;
int use_trekhopd = 0;
int port_req = 6592;
char *host_req = "rebel";
#endif
typedef struct {
char id[16];
char inet_addr[24];
int remote_port;
int gw_port;
char full_name[64];
char comment[40];
} SERVER_LIST;
#define MAX_SERVER 128
static SERVER_LIST servers[MAX_SERVER]; /* that ought to be enough */
#define SERVER_DIR "/usr/local/games/"
#define SERVER_FILE ".trekgwrc"
static int server_count = 0;
#define WSPC " \t"
unsigned long
strToNetaddr(str)
char *str;
{
SERVER_LIST *slp;
char *t;
unsigned long answer;
int i;
if (!server_count) {
fprintf(stderr, "netrek: No server list, cannot resolve id\n");
exit(1);
}
/* find the one we want */
for (i = 0, slp = servers; i < server_count; i++, slp++) {
if (!strcmp(str, slp->id) || !strcmp(str, slp->full_name)) {
printf("%s is %s(%d) (%s)\n", slp->id, slp->full_name,
slp->remote_port, slp->comment);
xtrekPort = slp->gw_port;
str = slp->inet_addr;
break;
}
}
if (i == server_count) {
fprintf(stderr, "netrek: Specified server not found.\n");
exit(1);
}
/* now "str" is either the original string or slp->inet_addr */
/* (this will be wrong if -H isn't last on command line) */
answer = 0;
t = str;
for (i = 0; i < 4; i++) {
answer = (answer << 8) | atoi(t);
while (*t && *t != '.')
t++;
if (*t)
t++;
}
#ifdef TREKHOPD
/* do things slightly different */
if (slp->id == NULL) {
fprintf(stderr, "ERROR: host ID '%s' unknown\n", str);
exit(1);
}
xtrekPort = trekhopd_port; /* ought to have an arg to specify this */
port_req = slp->remote_port;
host_req = slp->full_name;
printf("Connecting to %s (%d) via trekhopd (%s %d)\n", host_req,
port_req, serverName, xtrekPort);
#else
printf("Connecting to %s through %s port %d\n", str, serverName, xtrekPort);
#endif
return (answer);
}
/* for trekhopd, only gw_local_port is important */
/* (should be possible to eliminate that too, but I want minimal changes) */
typedef struct {
int uid;
int serv_port;
int port;
int local_port;
} UDPMAP;
#define MAX_UDPMAP 32
static UDPMAP udpmap[MAX_UDPMAP];
static int map_count;
void
getUdpPort()
{
int i;
uid_t uid;
uid = getuid();
gw_mach = gateway;
for (i = 0; i < map_count; i++) {
if (uid == udpmap[i].uid) {
gw_serv_port = udpmap[i].serv_port;
gw_port = udpmap[i].port;
gw_local_port = udpmap[i].local_port;
return;
}
}
/* not recognized; use default UDP port */
gw_serv_port = 5000;
gw_port = 5001;
gw_local_port = 5000;
}
/*
* More network "correct" routine
*/
unsigned long
mkaddr (m)
char *m;
{
struct in_addr ad;
struct hostent *hp;
hp = gethostbyname (m);
if (!hp)
{
ad.s_addr = inet_addr (m);
if (ad.s_addr == -1)
{
fprintf (stderr, "netrek: unknown host \'%s\'\n", m);
exit (1);
}
}
else
MCOPY(hp->h_addr, (char *) &ad, hp->h_length);
return ad.s_addr;
}
/*
* This is not very robust.
*/
void
read_servers()
{
FILE *fp;
SERVER_LIST *slp;
UDPMAP *ump;
char buf[128];
int state;
char *cp;
char file[BUFSIZ];
int line;
int error = 0;
server_count = map_count = 0;
fp = NULL;
if (getenv ("HOME") != NULL)
{
strcpy (homedot, getenv ("HOME"));
strcat (homedot, "/");
strcat (homedot, SERVER_FILE);
fp = fopen (homedot, "r");
strcpy(file, homedot);
}
if (fp == NULL)
{
/* failed, try common one */
strcpy (buf, SERVER_DIR);
strcat (buf, SERVER_FILE);
fp = fopen (buf, "r");
strcpy(file, buf);
}
if (fp == NULL)
{
/* failed, try current directory */
fp = fopen (SERVER_FILE, "r");
strcpy(file, SERVER_FILE);
}
if (fp == NULL)
{
/* failed, give up */
perror ("warning: Unable to open server list");
fprintf (stderr, "Tried to open '%s', '%s', and './%s'\n",
homedot, buf, SERVER_FILE);
return;
}
state = 0;
line = 1;
while (!error) {
fgets(buf, 128, fp);
if (ferror(fp) || feof(fp)) {
if (ferror(fp))
perror("fgets");
break;
}
line++;
/* skip blank lines and lines which start with '#' */
if (*buf == '\0' || *buf == '\n' || *buf == '#')
continue;
buf[strlen(buf) - 1] = '\0'; /* strip the trailing '\n' */
switch (state) {
case 0: /* "trekhopd" or "gw" */
#ifdef TREKHOPD
use_trekhopd = 0;
if (!strcmp(buf, "trekhopd"))
use_trekhopd = 1;
#endif
state++;
break;
case 1: /* gateway host */
gateway = (char *) malloc(strlen(buf) + 1);
strcpy(gateway, buf);
state++;
break;
case 2: /* trekhopd port */
trekhopd_port = atoi(buf);
state++;
break;
case 3: /* UDP map */
if (!strcmp(buf, "END")) {
state++;
break;
}
if (map_count >= MAX_UDPMAP)
{
fprintf (stderr, "UDP map too large; max is %d entries\n",
MAX_UDPMAP);
break;
}
ump = &udpmap[map_count];
cp = strtok(buf, WSPC);/* skip ascii uid */
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on user id.\n",
file, line);
break;
}
ump->uid = atoi(cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on server port.\n",
file, line);
break;
}
ump->serv_port = atoi(cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on port.\n",
file, line);
break;
}
ump->port = atoi(cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on local port.\n",
file, line);
break;
}
ump->local_port = atoi(cp);
#ifdef DEBUG
printf("%2d: %-8d %-8d %-8d %-8d\n", map_count,
ump->uid, ump->serv_port, ump->port, ump->local_port);
#endif
map_count++;
break;
case 4: /* host description */
if (!strcmp(buf, "END")) {
state++;
break;
}
if (server_count >= MAX_SERVER)
{
fprintf (stderr, "server list too large; max is %d entries\n",
MAX_SERVER);
break;
}
slp = &servers[server_count];
cp = strtok(buf, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on id.\n",
file, line);
break;
}
strcpy(slp->id, cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on address.\n",
file, line);
break;
}
strcpy(slp->inet_addr, cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on remote port.\n",
file, line);
break;
}
slp->remote_port = atoi(cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on gateway port.\n",
file, line);
break;
}
slp->gw_port = atoi(cp);
cp = strtok(NULL, WSPC);
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on server name.\n",
file, line);
break;
}
strcpy(slp->full_name, cp);
cp = strtok(NULL, "\"\t");
if(!cp) {
error++;
fprintf(stderr, "%s:%d: syntax error on server comments.\n",
file, line);
break;
}
strcpy(slp->comment, cp);
#ifdef DEBUG
printf("%2d: %-9s %-15s %-5d %-5d %-25s \"%s\"\n", server_count,
slp->id, slp->inet_addr, slp->remote_port, slp->gw_port,
slp->full_name, slp->comment);
#endif
server_count++;
break;
case 5: /* all done! */
break;
default:
fprintf(stderr, "Whoops!\n");
exit(2);
}
}
fclose(fp);
if(error)
exit(1);
}
#endif /* GATEWAY */
#ifdef EM
void handle_segfault();
void handle_exception();
#endif
void get_core(); /* NEW */
#ifdef PACKET_LOG
extern int log_packets;
#endif
#ifdef FOR_MORONS
extern int For_Morons;
#endif
/* move these to data.c one of these days */
char *defaultsFile = NULL;
char *pseudo_name = NULL,
*pseudo_passwd = NULL;
void
main(argc, argv)
int argc;
char **argv;
{
int team, s_type;
int usage = 0;
int err = 0;
char *name, *ptr, *cp;
struct passwd *pwent;
int passive = 0, disable_autologin = 0;
extern char *getenv();
#ifdef SPTEST
int sptest=0;
#endif
int noargs = 1; /* no server or metaserver supplied */
#ifdef GATEWAY
int hset = 0;
#endif
int whosplaying = 0;
#ifdef META
int usemeta = 0;
char *metafile = NULL;
#endif
program = argv[0];
#ifdef GATEWAY
/* restrict this client to certain machines */
{
struct sockaddr_in saddr;
struct hostent *hp;
char myname[64];
long myaddr, myaddr_restricted, myaddr_mask;
if (gethostname (myname, 64) < 0)
{
perror ("gethostname");
exit (1);
}
if ((myaddr = inet_addr (myname)) == -1)
{
if ((hp = gethostbyname (myname)) == NULL)
{
fprintf (stderr, "unable to get addr for local host\n");
exit (1);
}
myaddr = *(long *) hp->h_addr;
}
if ((myaddr_restricted = inet_addr(MYADDR)) == -1){
fprintf(stderr, "Malformed dot address \"%s\"\n", MYADDR);
exit(1);
}
if ((myaddr_mask = inet_addr(MYADDR_MASK)) == -1){
fprintf(stderr, "Malformed dot address mask \"%s\"\n", MYADDR_MASK);
exit(1);
}
/*printf("myname = '%s', myaddr = 0x%.8lx\n", myname, myaddr); */
if ((myaddr & myaddr_mask) != myaddr_restricted)
{
fprintf (stderr, "Sorry, you may not run this client on this host\n");
exit (1);
}
}
#endif
defaultsFile = getenv("XTREKRC");
name = *argv++;
argc--;
if ((ptr = strrchr(name, '/')) != NULL)
name = ptr + 1;
#ifdef GATEWAY
read_servers();
netaddr = 0;
serverName = gateway;
serverNameRemote = NULL;
#endif
while (*argv) {
if (**argv == '-')
++* argv;
else
break;
argc--;
ptr = *argv++;
while (*ptr) {
switch (*ptr) {
case 'v':
printVersion(name);
break;
case 'u':
usage++;
break;
case 's':
if (*argv) {
xtrekPort = atoi(*argv);
passive = 1;
argv++;
argc--;
}
break;
case 'p':
if (*argv) {
xtrekPort = atoi(*argv);
argv++;
argc--;
}
break;
#ifndef GATEWAY
case 'c':
whosplaying = 1;
break;
#endif
#ifdef META
case 'm':
usemeta = 1;
noargs = 0;
break;
case 'M': /* note incompatibility with Moron mode */
if (*argv && *argv[0] != '-') {
metafile = *argv;
argv++;
argc--;
}
break;
#endif
case 'C':
if (*argv && *argv[0] != '-') {
pseudo_name = *argv;
argv++;
argc--;
}
else
disable_autologin = 1;
break;
case 'A':
if (*argv){
pseudo_passwd = *argv;
argv++;
argc--;
}
break;
case 'd':
display = *argv;
argc--;
argv++;
break;
#ifdef RSA
case 'o':
RSA_Client = -1; /* will be reset leter, set negative here *
* to flag that it should override xtrekrc */
printf("Using standard binary verification\n");
break;
case 'V':
RSA_Client = -2; /* will be reset leter, set negative here *
* to flag that it should override xtrekrc */
printf("Using RSA binary verification\n");
break;
#else
case 'V':
printf("This client does not support RSA binary verification\n");
case 'o':
printf("Using standard binary verification\n");
break;
#endif
#ifdef FOR_MORONS
case 'M':
if (For_Morons) {
For_Morons = 0;
} else {
For_Morons = 1;
}
break;
#endif
case 'h':
#ifdef GATEWAY
gw_mach = *argv;
#endif
serverName = *argv;
argc--;
argv++;
noargs = 0;
break;
#ifdef GATEWAY
case 'H':
hset++;
serverNameRemote = *argv;
netaddr = strToNetaddr(*argv);
argc--;
argv++;
noargs = 0;
break;
#endif
case 't': /* USED?? */
title = *argv;
argc--;
argv++;
break;
case 'r':
defaultsFile = *argv;
argv++;
argc--;
break;
case 'D':
debug++;
if(debug == 2) {
printf("udpDebug turned on\n");
udpDebug = 1;
}
break;
#ifdef PACKET_LOG
case 'P':
log_packets++;
break;
#endif
#ifdef RECORD
case 'R':
recordFileName = *argv;
argv++;
argc--;
recordGame = 1;
break;
case 'F':
recordFileName = *argv;
argv++;
argc--;
playback = 1;
break;
case 'Z':
paradise_compat = 1;
shortversion = OLDSHORTVERSION;
break;
#endif
#ifdef LOGMESG
case 'l':
logMess = 1;
logFileName = *argv;
argv++;
argc--;
break;
#endif
#ifdef SPTEST
case 'S':
spt_getwin(atoi(*argv));
argv++;
argc--;
break;
#endif
#ifdef FORKNETREK
case 'w':
if (*argv) {
waitnum = atoi(*argv);
argv++;
argc--;
}
break;
#endif
default:
fprintf(stderr, "%s: unknown option '%c'\n", name, *ptr);
err++;
break;
}
if(argc < 0){
printUsage(name);
exit(1);
}
ptr++;
}
}
#ifdef RECORD
if(paradise_compat)
fprintf(RECORDFD, "Paradise compabitiblity mode enabled (shortversion=%d).\n", shortversion);
if(recordGame && playback) {
fprintf(RECORDFD,
"Record Game (-f) and Playback (-F) are mutually exclusive!\n");
exit(1);
}
#endif
#ifdef EXPIRATIONDATE
{
time_t nowtime;
nowtime = time(NULL);
if (nowtime > EXPIRATIONDATE) {
printf("This program has reached its planned-obsolescence date!\n")
printf("Please try to get a newer version!\n");
exit(666);
} else {
nowtime = EXPIRATIONDATE;
printf("This program will become non-functioonal after %s\n"
ctime(&nowtime));
}
}
#endif
#ifdef LOGMESG
/* open messages logfile */
if (logMess){
logFile = fopen(logFileName, "w+");
if (logFile == NULL) {
perror(logFileName);
exit(1);
}
}
#endif
#ifdef EM
#ifndef NO_TRAP
SIGNAL(SIGSEGV, handle_segfault);
SIGNAL(SIGFPE, handle_exception);
#endif /* DEBUG */
#endif /* EM */
SIGNAL(SIGPIPE, SIG_IGN);
#ifdef nodef
SIGNAL(SIGINT, gb); /* ghostbust debug test */
#endif
if(initDefaults(defaultsFile) == 0){
makeDefault();
/* do it again */
(void) initDefaults(defaultsFile);
}
if (usage || err || argc > 0) {
printUsage(name);
exit(1);
}
#ifdef RECORD
/* playback / record start used to be here */
#endif
#ifdef SHOW_DEFAULTS
show_defaults("B-startup", "metaDefault", "off",
"If no server argument, use metaserver.");
#endif
#ifdef RECORD
if(playback) {
noargs = 0;
usemeta = 0;
serverName = "playback";
W_Initialize(display); /* moved from newwin.c */
} else
#endif
{
if(noargs){
if(booleanDefault("metaDefault", 0))
usemeta = 1;
else if(!getdefault("server")){ /* NEW BEHAVIOR, no arguments, show special metaserver message */
printMetaInfo(name);
exit(1);
}
}
#ifdef GATEWAY
if (!netaddr && !usemeta){
#ifdef TREKHOPD
use_trekhopd = 0;
#endif
serverNameRemote = serverName;
fprintf(stderr,
"netrek: no remote address set (-H). Restricted server will not work.\n");
}
#endif
#ifdef nodef
/* compatability */
if (argc > 0)
display = argv[0];
#endif
/* SUPPRESS 8 */
srandom(getpid() * time((long *) 0));
#ifdef EM
#ifdef SHOW_DEFAULTS
show_defaults("B-startup", "# <feature>[.<alias/server-name>]", "value",
"All defaults variables support appending a server alias or server name\n\
after the variable name. The value specified will be used only if you are \n\
connected to that server. Values are searched by server-name, then by alias\n\
then by base variable name.");
#endif
/*
* server nicknames: * if you do netrek -h foo * and "server.foo:
* etrek.netrek.com" exists in your netrekrc * the server that is called
* is netrek.netrek.com * also, port.foo: x will make the port called x
*/
#ifdef SHOW_DEFAULTS
show_defaults("B-startup", "server.alias", "x.y.z",
"Aliases. Replace x.y.z with full server name, and specify <alias>\n\
From then on you can specify that server by doing 'netrek -h <alias>'");
#endif
#ifdef SHOW_DEFAULTS
show_defaults("B-startup", "server", "default.server.edu",
"Name of the default server to use if the -h flag isn't given.");
#endif
if(!serverName){
serverName = getdefault("server");
if(!serverName)
serverName = DEFAULT_SERVER;
}
#endif
/* look for alias */
{
char buf[100], *real_name, *server;
#ifdef GATEWAY
if(hset)
server = serverNameRemote;
else
server = serverName;
#else
server = serverName;
#endif
sprintf(buf, "server.%s", server);
real_name = _getdefault(buf);
if(real_name && strcmp(server, real_name) != 0){
serverAlias = server;
server = real_name;
#ifdef GATEWAY
serverNameRemote = server;
if(!hset)
serverName = server;
#else
serverName = server;
#endif
}
if(!serverAlias){
serverAlias = getalias(server);
}
}
/* if defaults is re-read, these pointers would be freed, store them
instead */
if(serverName)
serverName = strdup(serverName);
#ifdef GATEWAY
if(serverNameRemote)
serverNameRemote = strdup(serverNameRemote);
#endif
if(serverAlias)
serverAlias = strdup(serverAlias);
if (xtrekPort < 0) {
#ifdef SHOW_DEFAULTS
show_defaults("B-startup", "port", "2592",
"Number of the default port to use if the -p flag isn't given.");
#endif
xtrekPort = intDefault("port", -1);
if(xtrekPort < 0)
xtrekPort = DEFAULT_PORT;
}
#ifndef GATEWAY
if(whosplaying){
check_whosplaying(serverName, xtrekPort);
exit(0);
}
#endif
W_Initialize(display); /* moved from newwin.c */
#ifdef META
if(usemeta)
/* either we return from this with a new serverName or we exit */
do_metaserver(metafile);
#endif
#ifdef RSA
#ifdef SHOW_DEFAULTS
show_defaults("C-startup", "useRSA", RSA_Client?"on":"off",
"Use RSA by default.");
#endif
if(RSA_Client >= 0)
RSA_Client = booleanDefault("useRSA", RSA_Client);
else
/* RSA mode was specified in the command line args */
RSA_Client = (RSA_Client == -2) ? 1 : 0;
#endif
#ifdef GATEWAY
/* pick a nice set of UDP ports */
getUdpPort();
#endif
} /* if not playback */
#ifdef FOR_MORONS
#ifdef SHOW_DEFAULTS
show_defaults("misc", "forMorons", For_Morons?"on":"off",
"EM");
#endif
For_Morons = booleanDefault("ForMorons", For_Morons);
#endif
newwin(display, name); /* open memory...? Leftover from xtrek code! */
/* Get login name */
if ((pwent = getpwuid(getuid())) != NULL)
(void) strncpy(login, pwent->pw_name, sizeof(login));
else
(void) strncpy(login, "****", sizeof(login));
login[sizeof(login) - 1] = '\0';
openmem();
#ifdef RECORD
if(playback) {
#ifdef RECORD_DEBUG
fprintf(RECORDFD, "Calling startPlayback()...recordGame=%d\n",
recordGame);
#endif
startPlayback();
}
else
#endif
{
#ifdef RECORD
if(!playback) {
/* Find out if we're going to record. If so, find out if the filename
if ok now... it might require input if they give us an existing
filename and if we have to do this before we connect, otherwise
they might ghostbust (if they take too long)
*/
if(recordGame || (recordGame = booleanDefault("recordGame", recordGame)))
{
if(!recordFileName)
recordFileName = getdefault("recordFile");
check_record_filename();
}
}
#endif
if (!passive) {
callServer(xtrekPort, serverName);
} else {
connectToServer(xtrekPort);
}
}
#ifdef HOCKEY
#ifdef SHOW_DEFAULTS
show_defaults("hockey", "puckName", PUCK_NAME,
"Puck name [used by the client along with puckHost to find the \n\
hockey puck].");
#endif
if ((cp = getdefault("puckName")) != 0)
(void) strncpy(puck_name, cp, sizeof(puck_name));
puck_name[sizeof(puck_name) - 1] = '\0';
#ifdef SHOW_DEFAULTS