-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPXSETUP.C
429 lines (359 loc) · 8.35 KB
/
IPXSETUP.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
// ipxsetup.c
#define DOOM2
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <string.h>
#include <process.h>
#include <stdarg.h>
#include <bios.h>
#include "ipxnet.h"
#include "ipxstr.h"
//#include "ipx_frch.h" // FRENCH VERSION
int gameid;
int numnetnodes;
int socketid = 0x869c; // 0x869c is the official DOOM socket
int myargc;
char **myargv;
setupdata_t nodesetup[MAXNETNODES];
network_t networks[8];
/*
=================
=
= Error
=
= For abnormal program terminations
=
=================
*/
void Error (char *error, ...)
{
va_list argptr;
if (vectorishooked)
setvect (doomcom.intnum,olddoomvect);
va_start (argptr,error);
vprintf (error,argptr);
va_end (argptr);
printf ("\n");
ShutdownNetwork ();
exit (1);
}
/*
=================
=
= CheckParm
=
= Checks for the given parameter in the program's command line arguments
=
= Returns the argument number (1 to argc-1) or 0 if not present
=
=================
*/
int CheckParm(char *parm)
{
int i;
for(i = 1; i < myargc; i++)
if(stricmp(parm, myargv[i]) == 0)
return i;
return 0;
}
/*
=============
=
= NetISR
=
=============
*/
void interrupt NetISR (void)
{
if (doomcom.command == CMD_SEND)
{
localtime++;
SendPacket (doomcom.remotenode,0);
}
else if (doomcom.command == CMD_GET)
{
GetPacket ();
}
}
/*
===================
=
= LookForNodes
=
= Finds all the nodes for the game and works out player numbers among
them
=
= Exits with nodesetup[0..numnodes] and nodeadr[0..numnodes] filled in
===================
*/
void LookForNodes (void) {
int i,j,k;
int netids[MAXNETNODES];
int netplayer[MAXNETNODES];
struct time time;
int oldsec;
setupdata_t *setup, *dest;
char str[80];
int total, console;
//
// wait until we get [numnetnodes] packets, then start playing
// the playernumbers are assigned by netid
//
printf(STR_ATTEMPT, numnetnodes);
printf (STR_LOOKING);
oldsec = -1;
setup = (setupdata_t *)&doomcom.data;
localtime = -1; // in setup time, not game time
//
// build local setup info
//
nodesetup[0].nodesfound = 1;
nodesetup[0].nodeswanted = numnetnodes;
doomcom.numnodes = 1;
do {
//
// check for aborting
//
while ( bioskey(1) ) {
if ((bioskey (0) & 0xff) == 27) {
Error ("\n\n"STR_NETABORT);
}
}
//
// listen to the network
//
while (GetPacket ()) {
if (doomcom.remotenode == -1) {
dest = &nodesetup[doomcom.numnodes];
}
else {
dest = &nodesetup[doomcom.remotenode];
}
if (remotetime != -1) { // an early game packet, not a setup packet
if (doomcom.remotenode == -1) {
Error (STR_UNKNOWN);
// if it allready started, it must have found all nodes
}
dest->nodesfound = dest->nodeswanted;
continue;
}
// update setup ingo
memcpy (dest, setup, sizeof(*dest) );
if (doomcom.remotenode != -1) {
continue; // allready know that node address
}
//
// this is a new node
//
memcpy (&nodeadr[doomcom.numnodes], &remoteadr
, sizeof(nodeadr[doomcom.numnodes]) );
//
// if this node has a lower address, take all startup info
//
if(memcmp(&remoteadr,&nodeadr[0],sizeof(&remoteadr)) < 0 ) {
}
doomcom.numnodes++;
printf ("\n"STR_FOUND"\n");
if(doomcom.numnodes < numnetnodes) {
printf (STR_LOOKING);
}
}
//
// we are done if all nodes have found all other nodes
//
for (i=0 ; i<doomcom.numnodes ; i++) {
if (nodesetup[i].nodesfound != nodesetup[i].nodeswanted) {
break;
}
}
if (i == nodesetup[0].nodeswanted) break; // got them all
//
// send out a broadcast packet every second
//
gettime (&time);
if (time.ti_sec == oldsec) continue;
oldsec = time.ti_sec;
printf (".");
doomcom.datalength = sizeof(*setup);
nodesetup[0].nodesfound = doomcom.numnodes;
memcpy (&doomcom.data, &nodesetup[0], sizeof(*setup));
SendPacket (MAXNETNODES,NULL); // send to all
for(i=0;i<8;i++) {
if(memcmp(&networks[i].network,"\0\0\0\0",4)) {
SendPacket (MAXNETNODES,(char *)&networks[i].network); // send to all
}
}
// SendPacket (MAXNETNODES,0x416); // send to all
} while (1);
//
// count players
//
total = 0;
console = 0;
for (i=0 ; i<numnetnodes ; i++) {
if (nodesetup[i].drone) continue;
total++;
if (total > MAXPLAYERS) Error (STR_MORETHAN,MAXPLAYERS);
if (memcmp (&nodeadr[i], &nodeadr[0], sizeof(nodeadr[0])) < 0) {
console++;
}
}
if (!total) Error (STR_NONESPEC);
doomcom.consoleplayer = console;
doomcom.numplayers = total;
printf (STR_CONSOLEIS"\n", console+1, total);
}
//========================================================
//
// Find a Response File
//
//========================================================
void FindResponseFile (void)
{
int i;
#define MAXARGVS 100
for (i = 1;i < myargc;i++)
if (myargv[i][0] == '@')
{
FILE * handle;
int size;
int k;
int index;
int indexinfile;
char *infile;
char *file;
char *moreargs[20];
char *firstargv;
// READ THE RESPONSE FILE INTO MEMORY
handle = fopen (&myargv[i][1],"rb");
if (!handle)
Error (STR_NORESP);
printf(STR_FOUNDRESP" \"%s\"!\n",strupr(&myargv[i][1]));
fseek (handle,0,SEEK_END);
size = ftell(handle);
fseek (handle,0,SEEK_SET);
file = malloc (size);
fread (file,size,1,handle);
fclose (handle);
// KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
for (index = 0,k = i+1; k < myargc; k++)
moreargs[index++] = myargv[k];
firstargv = myargv[0];
myargv = malloc(sizeof(char *)*MAXARGVS);
memset(myargv,0,sizeof(char *)*MAXARGVS);
myargv[0] = firstargv;
infile = file;
indexinfile = k = 0;
indexinfile++; // SKIP PAST ARGV[0] (KEEP IT)
do
{
myargv[indexinfile++] = infile+k;
while(k < size &&
((*(infile+k)>= ' '+1) && (*(infile+k)<='z')))
k++;
*(infile+k) = 0;
while(k < size &&
((*(infile+k)<= ' ') || (*(infile+k)>'z')))
k++;
} while(k < size);
for (k = 0;k < index;k++)
myargv[indexinfile++] = moreargs[k];
myargc = indexinfile;
// DISPLAY ARGS
// printf("%d command-line args:\n",myargc);
// for (k=1;k<myargc;k++)
// printf("%s\n",myargv[k]);
break;
}
}
/*
=============
=
= main
=
=============
*/
void main (void) {
int i;
unsigned char far *vector;
char *t;
unsigned long x;
//
// determine game parameters
//
gameid = 0;
numnetnodes = 2;
doomcom.ticdup = 1;
doomcom.extratics = 1;
doomcom.episode = 1;
doomcom.map = 1;
doomcom.skill = 2;
doomcom.deathmatch = 0;
printf("\n"
"-----------------------------\n"
#ifdef DOOM2
STR_DOOMNETDRV"\n"
#else
"DOOM NETWORK DEVICE DRIVER\n"
#endif
"v1.22\n"
"-----------------------------\n");
myargc = _argc;
myargv = _argv;
FindResponseFile();
memset(&networks,0,sizeof(networks));
if((i = CheckParm("-nets")) != 0) {
t = strtok(myargv[i+1],",");
i=0;
while(t != NULL && i < 8) {
x = (unsigned long)strtol(t,NULL,16);
networks[i].network[3]=(x >> 0) & 0xFF;
networks[i].network[2]=(x >> 8) & 0xFF;
networks[i].network[1]=(x >> 16) & 0xFF;
networks[i].network[0]=(x >> 24) & 0xFF;
t=strtok(NULL,",");
i++;
}
}
if((i = CheckParm("-nodes")) != 0) {
numnetnodes = atoi(myargv[i+1]);
}
if((i = CheckParm("-vector")) != 0) {
doomcom.intnum = sscanf ("0x%x",myargv[i+1]);
vector = *(char far * far *)(doomcom.intnum*4);
if(vector != NULL && *vector != 0xcf) {
printf(STR_VECTSPEC"\n", doomcom.intnum);
exit(-1);
}
}
else {
for(doomcom.intnum = 0x60 ; doomcom.intnum <= 0x66 ; doomcom.intnum++) {
vector = *(char far * far *)(doomcom.intnum*4);
if(vector == NULL || *vector == 0xcf) break;
}
if(doomcom.intnum == 0x67) {
printf(STR_NONULL"\n");
exit(-1);
}
}
printf(STR_COMMVECT"\n",doomcom.intnum);
if((i = CheckParm("-port")) != 0) {
socketid = atoi (myargv[i+1]);
printf (STR_USEALT"\n", socketid);
}
InitNetwork ();
/*
Looking up the networks only once currently. This means if
network topology changes during a match communication may be lost.
Looking up the local target on every sendpacket is not worth the overhead for now.
*/
LookupNets();
LookForNodes ();
localtime = 0;
LaunchDOOM ();
ShutdownNetwork ();
if(vectorishooked) setvect (doomcom.intnum,olddoomvect);
exit(0);
}