IPXSETUP.C 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. // ipxsetup.c
  2. #define DOOM2
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <dos.h>
  7. #include <string.h>
  8. #include <process.h>
  9. #include <stdarg.h>
  10. #include <bios.h>
  11. #include "ipxnet.h"
  12. //#include "ipxstr.h"
  13. #include "ipx_frch.h" // FRENCH VERSION
  14. int gameid;
  15. int numnetnodes;
  16. int socketid = 0x869c; // 0x869c is the official DOOM socket
  17. int myargc;
  18. char **myargv;
  19. setupdata_t nodesetup[MAXNETNODES];
  20. /*
  21. =================
  22. =
  23. = Error
  24. =
  25. = For abnormal program terminations
  26. =
  27. =================
  28. */
  29. void Error (char *error, ...)
  30. {
  31. va_list argptr;
  32. if (vectorishooked)
  33. setvect (doomcom.intnum,olddoomvect);
  34. va_start (argptr,error);
  35. vprintf (error,argptr);
  36. va_end (argptr);
  37. printf ("\n");
  38. ShutdownNetwork ();
  39. exit (1);
  40. }
  41. /*
  42. =================
  43. =
  44. = CheckParm
  45. =
  46. = Checks for the given parameter in the program's command line arguments
  47. =
  48. = Returns the argument number (1 to argc-1) or 0 if not present
  49. =
  50. =================
  51. */
  52. int CheckParm(char *parm)
  53. {
  54. int i;
  55. for(i = 1; i < myargc; i++)
  56. if(stricmp(parm, myargv[i]) == 0)
  57. return i;
  58. return 0;
  59. }
  60. /*
  61. =============
  62. =
  63. = NetISR
  64. =
  65. =============
  66. */
  67. void interrupt NetISR (void)
  68. {
  69. if (doomcom.command == CMD_SEND)
  70. {
  71. localtime++;
  72. SendPacket (doomcom.remotenode);
  73. }
  74. else if (doomcom.command == CMD_GET)
  75. {
  76. GetPacket ();
  77. }
  78. }
  79. /*
  80. ===================
  81. =
  82. = LookForNodes
  83. =
  84. = Finds all the nodes for the game and works out player numbers among
  85. them
  86. =
  87. = Exits with nodesetup[0..numnodes] and nodeadr[0..numnodes] filled in
  88. ===================
  89. */
  90. void LookForNodes (void)
  91. {
  92. int i,j,k;
  93. int netids[MAXNETNODES];
  94. int netplayer[MAXNETNODES];
  95. struct time time;
  96. int oldsec;
  97. setupdata_t *setup, *dest;
  98. char str[80];
  99. int total, console;
  100. //
  101. // wait until we get [numnetnodes] packets, then start playing
  102. // the playernumbers are assigned by netid
  103. //
  104. printf(STR_ATTEMPT, numnetnodes);
  105. printf (STR_LOOKING);
  106. oldsec = -1;
  107. setup = (setupdata_t *)&doomcom.data;
  108. localtime = -1; // in setup time, not game time
  109. //
  110. // build local setup info
  111. //
  112. nodesetup[0].nodesfound = 1;
  113. nodesetup[0].nodeswanted = numnetnodes;
  114. doomcom.numnodes = 1;
  115. do
  116. {
  117. //
  118. // check for aborting
  119. //
  120. while ( bioskey(1) )
  121. {
  122. if ( (bioskey (0) & 0xff) == 27)
  123. Error ("\n\n"STR_NETABORT);
  124. }
  125. //
  126. // listen to the network
  127. //
  128. while (GetPacket ())
  129. {
  130. if (doomcom.remotenode == -1)
  131. dest = &nodesetup[doomcom.numnodes];
  132. else
  133. dest = &nodesetup[doomcom.remotenode];
  134. if (remotetime != -1)
  135. { // an early game packet, not a setup packet
  136. if (doomcom.remotenode == -1)
  137. Error (STR_UNKNOWN);
  138. // if it allready started, it must have found all nodes
  139. dest->nodesfound = dest->nodeswanted;
  140. continue;
  141. }
  142. // update setup ingo
  143. memcpy (dest, setup, sizeof(*dest) );
  144. if (doomcom.remotenode != -1)
  145. continue; // allready know that node address
  146. //
  147. // this is a new node
  148. //
  149. memcpy (&nodeadr[doomcom.numnodes], &remoteadr
  150. , sizeof(nodeadr[doomcom.numnodes]) );
  151. //
  152. // if this node has a lower address, take all startup info
  153. //
  154. if ( memcmp (&remoteadr, &nodeadr[0], sizeof(&remoteadr) )
  155. < 0 )
  156. {
  157. }
  158. doomcom.numnodes++;
  159. printf ("\n"STR_FOUND"\n");
  160. if (doomcom.numnodes < numnetnodes)
  161. printf (STR_LOOKING);
  162. }
  163. //
  164. // we are done if all nodes have found all other nodes
  165. //
  166. for (i=0 ; i<doomcom.numnodes ; i++)
  167. if (nodesetup[i].nodesfound != nodesetup[i].nodeswanted)
  168. break;
  169. if (i == nodesetup[0].nodeswanted)
  170. break; // got them all
  171. //
  172. // send out a broadcast packet every second
  173. //
  174. gettime (&time);
  175. if (time.ti_sec == oldsec)
  176. continue;
  177. oldsec = time.ti_sec;
  178. printf (".");
  179. doomcom.datalength = sizeof(*setup);
  180. nodesetup[0].nodesfound = doomcom.numnodes;
  181. memcpy (&doomcom.data, &nodesetup[0], sizeof(*setup));
  182. SendPacket (MAXNETNODES); // send to all
  183. } while (1);
  184. //
  185. // count players
  186. //
  187. total = 0;
  188. console = 0;
  189. for (i=0 ; i<numnetnodes ; i++)
  190. {
  191. if (nodesetup[i].drone)
  192. continue;
  193. total++;
  194. if (total > MAXPLAYERS)
  195. Error (STR_MORETHAN,MAXPLAYERS);
  196. if (memcmp (&nodeadr[i], &nodeadr[0], sizeof(nodeadr[0])) < 0)
  197. console++;
  198. }
  199. if (!total)
  200. Error (STR_NONESPEC);
  201. doomcom.consoleplayer = console;
  202. doomcom.numplayers = total;
  203. printf (STR_CONSOLEIS"\n", console+1, total);
  204. }
  205. //========================================================
  206. //
  207. // Find a Response File
  208. //
  209. //========================================================
  210. void FindResponseFile (void)
  211. {
  212. int i;
  213. #define MAXARGVS 100
  214. for (i = 1;i < myargc;i++)
  215. if (myargv[i][0] == '@')
  216. {
  217. FILE * handle;
  218. int size;
  219. int k;
  220. int index;
  221. int indexinfile;
  222. char *infile;
  223. char *file;
  224. char *moreargs[20];
  225. char *firstargv;
  226. // READ THE RESPONSE FILE INTO MEMORY
  227. handle = fopen (&myargv[i][1],"rb");
  228. if (!handle)
  229. Error (STR_NORESP);
  230. printf(STR_FOUNDRESP" \"%s\"!\n",strupr(&myargv[i][1]));
  231. fseek (handle,0,SEEK_END);
  232. size = ftell(handle);
  233. fseek (handle,0,SEEK_SET);
  234. file = malloc (size);
  235. fread (file,size,1,handle);
  236. fclose (handle);
  237. // KEEP ALL CMDLINE ARGS FOLLOWING @RESPONSEFILE ARG
  238. for (index = 0,k = i+1; k < myargc; k++)
  239. moreargs[index++] = myargv[k];
  240. firstargv = myargv[0];
  241. myargv = malloc(sizeof(char *)*MAXARGVS);
  242. memset(myargv,0,sizeof(char *)*MAXARGVS);
  243. myargv[0] = firstargv;
  244. infile = file;
  245. indexinfile = k = 0;
  246. indexinfile++; // SKIP PAST ARGV[0] (KEEP IT)
  247. do
  248. {
  249. myargv[indexinfile++] = infile+k;
  250. while(k < size &&
  251. ((*(infile+k)>= ' '+1) && (*(infile+k)<='z')))
  252. k++;
  253. *(infile+k) = 0;
  254. while(k < size &&
  255. ((*(infile+k)<= ' ') || (*(infile+k)>'z')))
  256. k++;
  257. } while(k < size);
  258. for (k = 0;k < index;k++)
  259. myargv[indexinfile++] = moreargs[k];
  260. myargc = indexinfile;
  261. // DISPLAY ARGS
  262. // printf("%d command-line args:\n",myargc);
  263. // for (k=1;k<myargc;k++)
  264. // printf("%s\n",myargv[k]);
  265. break;
  266. }
  267. }
  268. /*
  269. =============
  270. =
  271. = main
  272. =
  273. =============
  274. */
  275. void main (void)
  276. {
  277. int i;
  278. unsigned char far *vector;
  279. //
  280. // determine game parameters
  281. //
  282. gameid = 0;
  283. numnetnodes = 2;
  284. doomcom.ticdup = 1;
  285. doomcom.extratics = 1;
  286. doomcom.episode = 1;
  287. doomcom.map = 1;
  288. doomcom.skill = 2;
  289. doomcom.deathmatch = 0;
  290. printf("\n"
  291. "-----------------------------\n"
  292. #ifdef DOOM2
  293. STR_DOOMNETDRV"\n"
  294. #else
  295. "DOOM NETWORK DEVICE DRIVER\n"
  296. #endif
  297. "v1.22\n"
  298. "-----------------------------\n");
  299. myargc = _argc;
  300. myargv = _argv;
  301. FindResponseFile();
  302. if((i = CheckParm("-nodes")) != 0)
  303. numnetnodes = atoi(myargv[i+1]);
  304. if((i = CheckParm("-vector")) != 0)
  305. {
  306. doomcom.intnum = sscanf ("0x%x",myargv[i+1]);
  307. vector = *(char far * far *)(doomcom.intnum*4);
  308. if(vector != NULL && *vector != 0xcf)
  309. {
  310. printf(STR_VECTSPEC"\n", doomcom.intnum);
  311. exit(-1);
  312. }
  313. }
  314. else
  315. {
  316. for(doomcom.intnum = 0x60 ; doomcom.intnum <= 0x66 ;
  317. doomcom.intnum++)
  318. {
  319. vector = *(char far * far *)(doomcom.intnum*4);
  320. if(vector == NULL || *vector == 0xcf)
  321. break;
  322. }
  323. if(doomcom.intnum == 0x67)
  324. {
  325. printf(STR_NONULL"\n");
  326. exit(-1);
  327. }
  328. }
  329. printf(STR_COMMVECT"\n",doomcom.intnum);
  330. if((i = CheckParm("-port")) != 0)
  331. {
  332. socketid = atoi (myargv[i+1]);
  333. printf (STR_USEALT"\n", socketid);
  334. }
  335. InitNetwork ();
  336. LookForNodes ();
  337. localtime = 0;
  338. LaunchDOOM ();
  339. ShutdownNetwork ();
  340. if (vectorishooked)
  341. setvect (doomcom.intnum,olddoomvect);
  342. exit(0);
  343. }