PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/v1.8-final/main/netmisc-old.c

https://github.com/simX/d2x-xl
C | 891 lines | 633 code | 102 blank | 156 comment | 63 complexity | b800c6e743cd323ed1a7dfd70fddc19f MD5 | raw file
Possible License(s): GPL-2.0
  1. /* $Id: netmisc.c,v 1.9 2003/10/04 19:13:32 btb Exp $ */
  2. /*
  3. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  4. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  5. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  6. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  7. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  8. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  9. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  10. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  11. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  12. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  13. */
  14. /*
  15. *
  16. * Misc routines for network.
  17. *
  18. * Old Log:
  19. * Revision 1.1 1995/05/16 15:28:41 allender
  20. * Initial revision
  21. *
  22. * Revision 2.0 1995/02/27 11:27:24 john
  23. * New version 2.0, which has no anonymous unions, builds with
  24. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25. *
  26. * Revision 1.3 1994/11/19 15:19:34 mike
  27. * rip out unused code and data.
  28. *
  29. * Revision 1.2 1994/08/09 19:31:53 john
  30. * Networking changes.
  31. *
  32. * Revision 1.1 1994/08/08 11:06:07 john
  33. * Initial revision
  34. *
  35. *
  36. */
  37. #ifdef HAVE_CONFIG_H
  38. #include <conf.h>
  39. #endif
  40. #ifdef RCS
  41. static char rcsid[] = "$Id: netmisc.c,v 1.9 2003/10/04 19:13:32 btb Exp $";
  42. #endif
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include "inferno.h"
  46. #include "pstypes.h"
  47. #include "mono.h"
  48. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  49. #include "byteswap.h"
  50. #include "segment.h"
  51. #include "gameseg.h"
  52. #include "network.h"
  53. #include "wall.h"
  54. // routine to calculate the checksum of the segments. We add these specialized routines
  55. // since the current way is byte order dependent.
  56. void BEDoCheckSumCalc(ubyte *b, int len, unsigned int *s1, unsigned int *s2)
  57. {
  58. while(len--) {
  59. *s1 += *b++;
  60. if (*s1 >= 255) *s1 -= 255;
  61. *s2 += *s1;
  62. }
  63. }
  64. ushort BECalcSegmentCheckSum()
  65. {
  66. int i, j, k;
  67. unsigned int sum1,sum2;
  68. short s;
  69. int t;
  70. sum1 = sum2 = 0;
  71. for (i = 0; i < gameData.segs.nLastSegment + 1; i++) {
  72. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  73. BEDoCheckSumCalc(&(gameData.segs.segments[i].sides[j].nType), 1, &sum1, &sum2);
  74. BEDoCheckSumCalc(&(gameData.segs.segments[i].sides[j].nFrame), 1, &sum1, &sum2);
  75. s = INTEL_SHORT(WallNumI (i, j));
  76. BEDoCheckSumCalc((ubyte *)&s, 2, &sum1, &sum2);
  77. s = INTEL_SHORT(gameData.segs.segments[i].sides[j].nBaseTex);
  78. BEDoCheckSumCalc((ubyte *)&s, 2, &sum1, &sum2);
  79. s = INTEL_SHORT(gameData.segs.segments[i].sides[j].nOvlTex);
  80. BEDoCheckSumCalc((ubyte *)&s, 2, &sum1, &sum2);
  81. for (k = 0; k < 4; k++) {
  82. t = INTEL_INT(((int)gameData.segs.segments[i].sides[j].uvls[k].u));
  83. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  84. t = INTEL_INT(((int)gameData.segs.segments[i].sides[j].uvls[k].v));
  85. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  86. t = INTEL_INT(((int)gameData.segs.segments[i].sides[j].uvls[k].l));
  87. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  88. }
  89. for (k = 0; k < 2; k++) {
  90. t = INTEL_INT(((int)gameData.segs.segments[i].sides[j].normals[k].x));
  91. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  92. t = INTEL_INT(((int)gameData.segs.segments[i].sides[j].normals[k].y));
  93. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  94. t = INTEL_INT(((int)gameData.segs.segments[i].sides[j].normals[k].z));
  95. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  96. }
  97. }
  98. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  99. s = INTEL_SHORT(gameData.segs.segments[i].children[j]);
  100. BEDoCheckSumCalc((ubyte *)&s, 2, &sum1, &sum2);
  101. }
  102. for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) {
  103. s = INTEL_SHORT(gameData.segs.segments[i].verts[j]);
  104. BEDoCheckSumCalc((ubyte *)&s, 2, &sum1, &sum2);
  105. }
  106. t = INTEL_INT(gameData.segs.segments[i].objects);
  107. BEDoCheckSumCalc((ubyte *)&t, 4, &sum1, &sum2);
  108. }
  109. sum2 %= 255;
  110. return ((sum1<<8)+ sum2);
  111. }
  112. // this routine totally and completely relies on the fact that the network
  113. // checksum must be calculated on the segments!!!!!
  114. ushort NetMiscCalcCheckSum(void * vptr, int len)
  115. {
  116. vptr = vptr;
  117. len = len;
  118. return BECalcSegmentCheckSum();
  119. }
  120. // following are routine for macintosh only that will swap the elements of
  121. // structures send through the networking code. The structures and
  122. // this code must be kept in total sync
  123. #include "ipx.h"
  124. #include "multi.h"
  125. #ifdef NETWORK
  126. #include "network.h"
  127. #endif
  128. #include "object.h"
  129. #include "powerup.h"
  130. #include "error.h"
  131. sbyte out_buffer[IPX_MAX_DATA_SIZE]; // used for tmp netgame packets as well as sending tObject data
  132. extern struct ipx_recv_data ipx_udpSrc;
  133. void BEReceiveNetPlayerInfo(ubyte *data, netplayer_info *info)
  134. {
  135. int loc = 0;
  136. memcpy(info->callsign, data + loc, CALLSIGN_LEN+1);
  137. loc += CALLSIGN_LEN+1;
  138. memcpy(&(info->network.ipx.server), data + loc, 4);
  139. loc += 4;
  140. memcpy(&(info->network.ipx.node), data + loc, 6);
  141. loc += 6;
  142. info->version_major = data[loc];
  143. loc++;
  144. info->version_minor = data[loc];
  145. loc++;
  146. memcpy(&(info->computerType), data + loc, 1);
  147. loc++; // memcpy to avoid compile time warning about enum
  148. info->connected = data[loc];
  149. loc++;
  150. memcpy(&(info->socket), data + loc, 2);
  151. loc += 2;
  152. memcpy (&(info->rank),data + loc,1);
  153. loc++;
  154. // MWA don't think we need to swap this because we need it in high
  155. // order info->socket = INTEL_SHORT(info->socket);
  156. }
  157. void BESendNetPlayersPacket(ubyte *server, ubyte *node)
  158. {
  159. int i, tmpi;
  160. int loc = 0;
  161. short tmps;
  162. memset(out_buffer, 0, sizeof(out_buffer));
  163. out_buffer[0] = netPlayers.nType; loc++;
  164. tmpi = INTEL_INT(netPlayers.Security);
  165. memcpy(out_buffer + loc, &tmpi, 4); loc += 4;
  166. for (i = 0; i < MAX_PLAYERS+4; i++) {
  167. memcpy(out_buffer + loc, netPlayers.players[i].callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1;
  168. memcpy(out_buffer + loc, netPlayers.players[i].network.ipx.server, 4); loc += 4;
  169. memcpy(out_buffer + loc, netPlayers.players[i].network.ipx.node, 6); loc += 6;
  170. memcpy(out_buffer + loc, &(netPlayers.players[i].version_major), 1); loc++;
  171. memcpy(out_buffer + loc, &(netPlayers.players[i].version_minor), 1); loc++;
  172. memcpy(out_buffer + loc, &(netPlayers.players[i].computerType), 1); loc++;
  173. memcpy(out_buffer + loc, &(netPlayers.players[i].connected), 1); loc++;
  174. tmps = INTEL_SHORT(netPlayers.players[i].socket);
  175. memcpy(out_buffer + loc, &tmps, 2); loc += 2;
  176. memcpy(out_buffer + loc, &(netPlayers.players[i].rank), 1); loc++;
  177. }
  178. if ((server == NULL) && (node == NULL))
  179. IPXSendBroadcastData(out_buffer, loc);
  180. else
  181. IPXSendInternetPacketData(out_buffer, loc, server, node);
  182. }
  183. void BEReceiveNetPlayersPacket(ubyte *data, allNetPlayers_info *pinfo)
  184. {
  185. int i, loc = 0;
  186. pinfo->nType = data[loc];
  187. loc++;
  188. memcpy(&(pinfo->Security), data + loc, 4);
  189. loc += 4;
  190. pinfo->Security = INTEL_INT(pinfo->Security);
  191. for (i = 0; i < MAX_PLAYERS+4; i++) {
  192. BEReceiveNetPlayerInfo(data + loc, &(pinfo->players[i]));
  193. loc += 26; // sizeof(netplayer_info) on the PC
  194. }
  195. }
  196. void BESendSequencePacket(sequence_packet seq, ubyte *server, ubyte *node, ubyte *netAddress)
  197. {
  198. short tmps;
  199. int loc, tmpi;
  200. loc = 0;
  201. memset(out_buffer, 0, sizeof(out_buffer));
  202. out_buffer[0] = seq.nType;
  203. loc++;
  204. tmpi = INTEL_INT(seq.Security);
  205. memcpy(out_buffer + loc, &tmpi, 4);
  206. loc += 4;
  207. loc += 3;
  208. memcpy(out_buffer + loc, seq.player.callsign, CALLSIGN_LEN+1);
  209. loc += CALLSIGN_LEN+1;
  210. memcpy(out_buffer + loc, seq.player.network.ipx.server, 4);
  211. loc += 4;
  212. memcpy(out_buffer + loc, seq.player.network.ipx.node, 6);
  213. loc += 6;
  214. out_buffer[loc] = seq.player.version_major;
  215. loc++;
  216. out_buffer[loc] = seq.player.version_minor;
  217. loc++;
  218. out_buffer[loc] = seq.player.computerType;
  219. loc++;
  220. out_buffer[loc] = seq.player.connected;
  221. loc++;
  222. tmps = INTEL_SHORT(seq.player.socket);
  223. memcpy(out_buffer + loc, &tmps, 2);
  224. loc += 2;
  225. out_buffer[loc]=seq.player.rank;
  226. loc++; // for pad byte
  227. if (netAddress != NULL)
  228. IPXSendPacketData(out_buffer, loc, server, node, netAddress);
  229. else if (!server && !node)
  230. IPXSendBroadcastData(out_buffer, loc);
  231. else
  232. IPXSendInternetPacketData(out_buffer, loc, server, node);
  233. }
  234. void BEReceiveSequencePacket(ubyte *data, sequence_packet *seq)
  235. {
  236. int loc = 0;
  237. seq->nType = data[0]; loc++;
  238. memcpy(&(seq->Security), data + loc, 4); loc += 4; loc += 3; // +3 for pad byte
  239. seq->Security = INTEL_INT(seq->Security);
  240. BEReceiveNetPlayerInfo(data + loc, &(seq->player));
  241. }
  242. void BESendNetGamePacket(ubyte *server, ubyte *node, ubyte *netAddress, int liteFlag) // lite says shorter netgame packets
  243. {
  244. uint tmpi;
  245. ushort tmps; // p;
  246. int i, j;
  247. int loc = 0;
  248. memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
  249. memcpy(out_buffer + loc, &(netGame.nType), 1);
  250. loc++;
  251. tmpi = INTEL_INT(netGame.Security);
  252. memcpy(out_buffer + loc, &tmpi, 4);
  253. loc += 4;
  254. memcpy(out_buffer + loc, netGame.game_name, NETGAME_NAME_LEN+1);
  255. loc += (NETGAME_NAME_LEN+1);
  256. memcpy(out_buffer + loc, netGame.mission_title, MISSION_NAME_LEN+1);
  257. loc += (MISSION_NAME_LEN+1);
  258. memcpy(out_buffer + loc, netGame.mission_name, 9);
  259. loc += 9;
  260. tmpi = INTEL_INT(netGame.levelnum);
  261. memcpy(out_buffer + loc, &tmpi, 4);
  262. loc += 4;
  263. memcpy(out_buffer + loc, &(netGame.gamemode), 1);
  264. loc++;
  265. memcpy(out_buffer + loc, &(netGame.RefusePlayers), 1);
  266. loc++;
  267. memcpy(out_buffer + loc, &(netGame.difficulty), 1);
  268. loc++;
  269. memcpy(out_buffer + loc, &(netGame.game_status), 1);
  270. loc++;
  271. memcpy(out_buffer + loc, &(netGame.numplayers), 1);
  272. loc++;
  273. memcpy(out_buffer + loc, &(netGame.max_numplayers), 1);
  274. loc++;
  275. memcpy(out_buffer + loc, &(netGame.numconnected), 1);
  276. loc++;
  277. memcpy(out_buffer + loc, &(netGame.gameFlags), 1);
  278. loc++;
  279. memcpy(out_buffer + loc, &(netGame.protocol_version), 1);
  280. loc++;
  281. memcpy(out_buffer + loc, &(netGame.version_major), 1);
  282. loc++;
  283. memcpy(out_buffer + loc, &(netGame.version_minor), 1);
  284. loc++;
  285. memcpy(out_buffer + loc, &(netGame.team_vector), 1);
  286. loc++;
  287. if (liteFlag)
  288. goto do_send;
  289. // will this work -- damn bitfields -- totally bogus when trying to do
  290. // this nType of stuff
  291. // Watcom makes bitfields from left to right. CW7 on the mac goes
  292. // from right to left. then they are endian swapped
  293. tmps = *(ushort *)((ubyte *)(&netGame.team_vector) + 1); // get the values for the first short bitfield
  294. tmps = INTEL_SHORT(tmps);
  295. memcpy(out_buffer + loc, &tmps, 2);
  296. loc += 2;
  297. tmps = *(ushort *)((ubyte *)(&netGame.team_vector) + 3); // get the values for the second short bitfield
  298. tmps = INTEL_SHORT(tmps);
  299. memcpy(out_buffer + loc, &tmps, 2);
  300. loc += 2;
  301. #if 0 // removed since I reordered bitfields on mac
  302. p = *(ushort *)((ubyte *)(&netGame.team_vector) + 1); // get the values for the first short bitfield
  303. tmps = 0;
  304. for (i = 15; i >= 0; i--) {
  305. if (p & (1 << i))
  306. tmps |= (1 << (15 - i);
  307. }
  308. tmps = INTEL_SHORT(tmps);
  309. memcpy(out_buffer + loc, &tmps, 2);
  310. loc += 2;
  311. p = *(ushort *)((ubyte *)(&netGame.team_vector) + 3); // get the values for the second short bitfield
  312. tmps = 0;
  313. for (i = 15; i >= 0; i--) {
  314. if (p & (1 << i))
  315. tmps |= (1 << (15 - i);
  316. }
  317. tmps = INTEL_SHORT(tmps);
  318. memcpy(out_buffer + loc, &tmps, 2);
  319. loc += 2;
  320. #endif
  321. memcpy(out_buffer + loc, netGame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1);
  322. for (i = 0; i < MAX_PLAYERS; i++) {
  323. tmpi = INTEL_INT(netGame.locations[i]);
  324. memcpy(out_buffer + loc, &tmpi, 4);
  325. loc += 4; // SWAP HERE!!!
  326. }
  327. for (i = 0; i < MAX_PLAYERS; i++) {
  328. for (j = 0; j < MAX_PLAYERS; j++) {
  329. tmps = INTEL_SHORT(netGame.kills[i][j]);
  330. memcpy(out_buffer + loc, &tmps, 2);
  331. loc += 2; // SWAP HERE!!!
  332. }
  333. }
  334. tmps = INTEL_SHORT(netGame.segments_checksum);
  335. memcpy(out_buffer + loc, &tmps, 2);
  336. loc += 2; // SWAP_HERE
  337. tmps = INTEL_SHORT(netGame.teamKills[0]);
  338. memcpy(out_buffer + loc, &tmps, 2);
  339. loc += 2; // SWAP_HERE
  340. tmps = INTEL_SHORT(netGame.teamKills[1]);
  341. memcpy(out_buffer + loc, &tmps, 2);
  342. loc += 2; // SWAP_HERE
  343. for (i = 0; i < MAX_PLAYERS; i++) {
  344. tmps = INTEL_SHORT(netGame.killed[i]);
  345. memcpy(out_buffer + loc, &tmps, 2);
  346. loc += 2; // SWAP HERE!!!
  347. }
  348. for (i = 0; i < MAX_PLAYERS; i++) {
  349. tmps = INTEL_SHORT(netGame.playerKills[i]);
  350. memcpy(out_buffer + loc, &tmps, 2);
  351. loc += 2; // SWAP HERE!!!
  352. }
  353. tmpi = INTEL_INT(netGame.KillGoal);
  354. memcpy(out_buffer + loc, &tmpi, 4);
  355. loc += 4; // SWAP_HERE
  356. tmpi = INTEL_INT(netGame.PlayTimeAllowed);
  357. memcpy(out_buffer + loc, &tmpi, 4);
  358. loc += 4; // SWAP_HERE
  359. tmpi = INTEL_INT(netGame.levelTime);
  360. memcpy(out_buffer + loc, &tmpi, 4);
  361. loc += 4; // SWAP_HERE
  362. tmpi = INTEL_INT(netGame.control_invulTime);
  363. memcpy(out_buffer + loc, &tmpi, 4);
  364. loc += 4; // SWAP_HERE
  365. tmpi = INTEL_INT(netGame.monitor_vector);
  366. memcpy(out_buffer + loc, &tmpi, 4);
  367. loc += 4; // SWAP_HERE
  368. for (i = 0; i < MAX_PLAYERS; i++) {
  369. tmpi = INTEL_INT(netGame.player_score[i]);
  370. memcpy(out_buffer + loc, &tmpi, 4);
  371. loc += 4; // SWAP_HERE
  372. }
  373. for (i = 0; i < MAX_PLAYERS; i++) {
  374. memcpy(out_buffer + loc, &(netGame.playerFlags[i]), 1); loc++;
  375. }
  376. tmps = INTEL_SHORT(netGame.nPacketsPerSec);
  377. memcpy(out_buffer + loc, &tmps, 2);
  378. loc += 2;
  379. memcpy(out_buffer + loc, &(netGame.bShortPackets), 1);
  380. loc++;
  381. do_send:
  382. if (netAddress != NULL)
  383. IPXSendPacketData(out_buffer, loc, server, node, netAddress);
  384. else if ((server == NULL) && (node == NULL))
  385. IPXSendBroadcastData(out_buffer, loc);
  386. else
  387. IPXSendInternetPacketData(out_buffer, loc, server, node);
  388. }
  389. void BEReceiveNetGamePacket(ubyte *data, netgame_info *netgame, int liteFlag)
  390. {
  391. int i, j;
  392. int loc = 0;
  393. short bitfield; // new_field;
  394. memcpy(&(netgame->nType), data + loc, 1);
  395. loc++;
  396. memcpy(&(netgame->Security), data + loc, 4);
  397. loc += 4;
  398. netgame->Security = INTEL_INT(netgame->Security);
  399. memcpy(netgame->game_name, data + loc, NETGAME_NAME_LEN+1);
  400. loc += (NETGAME_NAME_LEN+1);
  401. memcpy(netgame->mission_title, data + loc, MISSION_NAME_LEN+1);
  402. loc += (MISSION_NAME_LEN+1);
  403. memcpy(netgame->mission_name, data + loc, 9);
  404. loc += 9;
  405. memcpy(&(netgame->levelnum), data + loc, 4);
  406. loc += 4;
  407. netgame->levelnum = INTEL_INT(netgame->levelnum);
  408. memcpy(&(netgame->gamemode), data + loc, 1);
  409. loc++;
  410. memcpy(&(netgame->RefusePlayers), data + loc, 1);
  411. loc++;
  412. memcpy(&(netgame->difficulty), data + loc, 1);
  413. loc++;
  414. memcpy(&(netgame->game_status), data + loc, 1);
  415. loc++;
  416. memcpy(&(netgame->numplayers), data + loc, 1);
  417. loc++;
  418. memcpy(&(netgame->max_numplayers), data + loc, 1);
  419. loc++;
  420. memcpy(&(netgame->numconnected), data + loc, 1);
  421. loc++;
  422. memcpy(&(netgame->gameFlags), data + loc, 1);
  423. loc++;
  424. memcpy(&(netgame->protocol_version), data + loc, 1);
  425. loc++;
  426. memcpy(&(netgame->version_major), data + loc, 1);
  427. loc++;
  428. memcpy(&(netgame->version_minor), data + loc, 1);
  429. loc++;
  430. memcpy(&(netgame->team_vector), data + loc, 1);
  431. loc++;
  432. if (liteFlag)
  433. return;
  434. memcpy(&bitfield, data + loc, 2);
  435. loc += 2;
  436. bitfield = INTEL_SHORT(bitfield);
  437. memcpy(((ubyte *)(&netgame->team_vector) + 1), &bitfield, 2);
  438. memcpy(&bitfield, data + loc, 2);
  439. loc += 2;
  440. bitfield = INTEL_SHORT(bitfield);
  441. memcpy(((ubyte *)(&netgame->team_vector) + 3), &bitfield, 2);
  442. #if 0 // not used since reordering mac bitfields
  443. memcpy(&bitfield, data + loc, 2);
  444. loc += 2;
  445. new_field = 0;
  446. for (i = 15; i >= 0; i--) {
  447. if (bitfield & (1 << i))
  448. new_field |= (1 << (15 - i);
  449. }
  450. new_field = INTEL_SHORT(new_field);
  451. memcpy(((ubyte *)(&netgame->team_vector) + 1), &new_field, 2);
  452. memcpy(&bitfield, data + loc, 2);
  453. loc += 2;
  454. new_field = 0;
  455. for (i = 15; i >= 0; i--) {
  456. if (bitfield & (1 << i))
  457. new_field |= (1 << (15 - i);
  458. }
  459. new_field = INTEL_SHORT(new_field);
  460. memcpy(((ubyte *)(&netgame->team_vector) + 3), &new_field, 2);
  461. #endif
  462. memcpy(netgame->team_name, data + loc, 2*(CALLSIGN_LEN+1));
  463. loc += 2*(CALLSIGN_LEN+1);
  464. for (i = 0; i < MAX_PLAYERS; i++) {
  465. memcpy(&(netgame->locations[i]), data + loc, 4);
  466. loc += 4;
  467. netgame->locations[i] = INTEL_INT(netgame->locations[i]);
  468. }
  469. for (i = 0; i < MAX_PLAYERS; i++) {
  470. for (j = 0; j < MAX_PLAYERS; j++) {
  471. memcpy(&(netgame->kills[i][j]), data + loc, 2);
  472. loc += 2;
  473. netgame->kills[i][j] = INTEL_SHORT(netgame->kills[i][j]);
  474. }
  475. }
  476. memcpy(&(netgame->segments_checksum), data + loc, 2);
  477. loc += 2;
  478. netgame->segments_checksum = INTEL_SHORT(netgame->segments_checksum);
  479. memcpy(&(netgame->teamKills[0]), data + loc, 2);
  480. loc += 2;
  481. netgame->teamKills[0] = INTEL_SHORT(netgame->teamKills[0]);
  482. memcpy(&(netgame->teamKills[1]), data + loc, 2);
  483. loc += 2;
  484. netgame->teamKills[1] = INTEL_SHORT(netgame->teamKills[1]);
  485. for (i = 0; i < MAX_PLAYERS; i++) {
  486. memcpy(&(netgame->killed[i]), data + loc, 2);
  487. loc += 2;
  488. netgame->killed[i] = INTEL_SHORT(netgame->killed[i]);
  489. }
  490. for (i = 0; i < MAX_PLAYERS; i++) {
  491. memcpy(&(netgame->playerKills[i]), data + loc, 2);
  492. loc += 2;
  493. netgame->playerKills[i] = INTEL_SHORT(netgame->playerKills[i]);
  494. }
  495. memcpy(&(netgame->KillGoal), data + loc, 4);
  496. loc += 4;
  497. netgame->KillGoal = INTEL_INT(netgame->KillGoal);
  498. memcpy(&(netgame->PlayTimeAllowed), data + loc, 4);
  499. loc += 4;
  500. netgame->PlayTimeAllowed = INTEL_INT(netgame->PlayTimeAllowed);
  501. memcpy(&(netgame->levelTime), data + loc, 4);
  502. loc += 4;
  503. netgame->levelTime = INTEL_INT(netgame->levelTime);
  504. memcpy(&(netgame->control_invulTime), data + loc, 4);
  505. loc += 4;
  506. netgame->control_invulTime = INTEL_INT(netgame->control_invulTime);
  507. memcpy(&(netgame->monitor_vector), data + loc, 4);
  508. loc += 4;
  509. netgame->monitor_vector = INTEL_INT(netgame->monitor_vector);
  510. for (i = 0; i < MAX_PLAYERS; i++) {
  511. memcpy(&(netgame->player_score[i]), data + loc, 4);
  512. loc += 4;
  513. netgame->player_score[i] = INTEL_INT(netgame->player_score[i]);
  514. }
  515. for (i = 0; i < MAX_PLAYERS; i++) {
  516. memcpy(&(netgame->playerFlags[i]), data + loc, 1);
  517. loc++;
  518. }
  519. memcpy(&(netgame->nPacketsPerSec), data + loc, 2);
  520. loc += 2;
  521. netgame->nPacketsPerSec = INTEL_SHORT(netgame->nPacketsPerSec);
  522. memcpy(&(netgame->bShortPackets), data + loc, 1);
  523. loc ++;
  524. }
  525. #define EGI_INTEL_SHORT_2BUF(_m) \
  526. *((short *) (out_buffer + ((char *) &extraGameInfo [1]. _m - (char *) &extraGameInfo [1]))) = INTEL_SHORT (extraGameInfo [1]. _m);
  527. #define EGI_INTEL_INT_2BUF(_m) \
  528. *((int *) (out_buffer + ((char *) &extraGameInfo [1]. _m - (char *) &extraGameInfo [1]))) = INTEL_INT (extraGameInfo [1]. _m);
  529. #define BUF2_EGI_INTEL_SHORT(_m) \
  530. extraGameInfo [1]. _m = INTEL_SHORT (*((short *) (out_buffer + ((char *) &extraGameInfo [1]. _m - (char *) &extraGameInfo [1]))));
  531. #define BUF2_EGI_INTEL_INT(_m) \
  532. extraGameInfo [1]. _m = INTEL_INT (*((int *) (out_buffer + ((char *) &extraGameInfo [1]. _m - (char *) &extraGameInfo [1]))));
  533. void BESendExtraGameInfo(ubyte *server, ubyte *node, ubyte *netAddress)
  534. {
  535. memcpy (out_buffer, &extraGameInfo [1], sizeof (extra_gameinfo));
  536. EGI_INTEL_SHORT_2BUF (entropy.nMaxVirusCapacity);
  537. EGI_INTEL_SHORT_2BUF (entropy.nEnergyFillRate);
  538. EGI_INTEL_SHORT_2BUF (entropy.nShieldFillRate);
  539. EGI_INTEL_SHORT_2BUF (entropy.nShieldDamageRate);
  540. EGI_INTEL_INT_2BUF (nSpawnDelay);
  541. if (netAddress != NULL)
  542. IPXSendPacketData(out_buffer, sizeof (extra_gameinfo), server, node, netAddress);
  543. else if ((server == NULL) && (node == NULL))
  544. IPXSendBroadcastData(out_buffer, sizeof (extra_gameinfo));
  545. else
  546. IPXSendInternetPacketData(out_buffer, sizeof (extra_gameinfo), server, node);
  547. }
  548. void BEReceiveExtraGameInfo(ubyte *data, extra_gameinfo *extraGameInfo)
  549. {
  550. memcpy (&extraGameInfo [1], data, sizeof (extra_gameinfo));
  551. BUF2_EGI_INTEL_SHORT (entropy.nMaxVirusCapacity);
  552. BUF2_EGI_INTEL_SHORT (entropy.nEnergyFillRate);
  553. BUF2_EGI_INTEL_SHORT (entropy.nShieldFillRate);
  554. BUF2_EGI_INTEL_SHORT (entropy.nShieldDamageRate);
  555. BUF2_EGI_INTEL_INT (nSpawnDelay);
  556. }
  557. void BESwapObject(tObject *objP)
  558. {
  559. // swap the short and int entries for this tObject
  560. objP->nSignature = INTEL_INT(objP->nSignature);
  561. objP->next = INTEL_SHORT(objP->next);
  562. objP->prev = INTEL_SHORT(objP->prev);
  563. objP->nSegment = INTEL_SHORT(objP->nSegment);
  564. objP->pos.x = INTEL_INT(objP->pos.x);
  565. objP->pos.y = INTEL_INT(objP->pos.y);
  566. objP->pos.z = INTEL_INT(objP->pos.z);
  567. objP->orient.rVec.x = INTEL_INT(objP->orient.rVec.x);
  568. objP->orient.rVec.y = INTEL_INT(objP->orient.rVec.y);
  569. objP->orient.rVec.z = INTEL_INT(objP->orient.rVec.z);
  570. objP->orient.fVec.x = INTEL_INT(objP->orient.fVec.x);
  571. objP->orient.fVec.y = INTEL_INT(objP->orient.fVec.y);
  572. objP->orient.fVec.z = INTEL_INT(objP->orient.fVec.z);
  573. objP->orient.uVec.x = INTEL_INT(objP->orient.uVec.x);
  574. objP->orient.uVec.y = INTEL_INT(objP->orient.uVec.y);
  575. objP->orient.uVec.z = INTEL_INT(objP->orient.uVec.z);
  576. objP->size = INTEL_INT(objP->size);
  577. objP->shields = INTEL_INT(objP->shields);
  578. objP->last_pos.x = INTEL_INT(objP->last_pos.x);
  579. objP->last_pos.y = INTEL_INT(objP->last_pos.y);
  580. objP->last_pos.z = INTEL_INT(objP->last_pos.z);
  581. objP->lifeleft = INTEL_INT(objP->lifeleft);
  582. switch (objP->movementType) {
  583. case MT_PHYSICS:
  584. objP->mType.physInfo.velocity.x = INTEL_INT(objP->mType.physInfo.velocity.x);
  585. objP->mType.physInfo.velocity.y = INTEL_INT(objP->mType.physInfo.velocity.y);
  586. objP->mType.physInfo.velocity.z = INTEL_INT(objP->mType.physInfo.velocity.z);
  587. objP->mType.physInfo.thrust.x = INTEL_INT(objP->mType.physInfo.thrust.x);
  588. objP->mType.physInfo.thrust.y = INTEL_INT(objP->mType.physInfo.thrust.y);
  589. objP->mType.physInfo.thrust.z = INTEL_INT(objP->mType.physInfo.thrust.z);
  590. objP->mType.physInfo.mass = INTEL_INT(objP->mType.physInfo.mass);
  591. objP->mType.physInfo.drag = INTEL_INT(objP->mType.physInfo.drag);
  592. objP->mType.physInfo.brakes = INTEL_INT(objP->mType.physInfo.brakes);
  593. objP->mType.physInfo.rotVel.x = INTEL_INT(objP->mType.physInfo.rotVel.x);
  594. objP->mType.physInfo.rotVel.y = INTEL_INT(objP->mType.physInfo.rotVel.y);
  595. objP->mType.physInfo.rotVel.z = INTEL_INT(objP->mType.physInfo.rotVel.z);
  596. objP->mType.physInfo.rotThrust.x = INTEL_INT(objP->mType.physInfo.rotThrust.x);
  597. objP->mType.physInfo.rotThrust.y = INTEL_INT(objP->mType.physInfo.rotThrust.y);
  598. objP->mType.physInfo.rotThrust.z = INTEL_INT(objP->mType.physInfo.rotThrust.z);
  599. objP->mType.physInfo.turnRoll = INTEL_INT(objP->mType.physInfo.turnRoll);
  600. objP->mType.physInfo.flags = INTEL_SHORT(objP->mType.physInfo.flags);
  601. break;
  602. case MT_SPINNING:
  603. objP->mType.spinRate.x = INTEL_INT(objP->mType.spinRate.x);
  604. objP->mType.spinRate.y = INTEL_INT(objP->mType.spinRate.y);
  605. objP->mType.spinRate.z = INTEL_INT(objP->mType.spinRate.z);
  606. break;
  607. }
  608. switch (objP->controlType) {
  609. case CT_WEAPON:
  610. objP->cType.laserInfo.parentType = INTEL_SHORT(objP->cType.laserInfo.parentType);
  611. objP->cType.laserInfo.nParentObj = INTEL_SHORT(objP->cType.laserInfo.nParentObj);
  612. objP->cType.laserInfo.nParentSig = INTEL_INT(objP->cType.laserInfo.nParentSig);
  613. objP->cType.laserInfo.creationTime = INTEL_INT(objP->cType.laserInfo.creationTime);
  614. objP->cType.laserInfo.nLastHitObj = INTEL_SHORT(objP->cType.laserInfo.nLastHitObj);
  615. objP->cType.laserInfo.nTrackGoal = INTEL_SHORT(objP->cType.laserInfo.nTrackGoal);
  616. objP->cType.laserInfo.multiplier = INTEL_INT(objP->cType.laserInfo.multiplier);
  617. break;
  618. case CT_EXPLOSION:
  619. objP->cType.explInfo.nSpawnTime = INTEL_INT(objP->cType.explInfo.nSpawnTime);
  620. objP->cType.explInfo.nDeleteTime = INTEL_INT(objP->cType.explInfo.nDeleteTime);
  621. objP->cType.explInfo.nDeleteObj = INTEL_SHORT(objP->cType.explInfo.nDeleteObj);
  622. objP->cType.explInfo.nAttachParent = INTEL_SHORT(objP->cType.explInfo.nAttachParent);
  623. objP->cType.explInfo.nPrevAttach = INTEL_SHORT(objP->cType.explInfo.nPrevAttach);
  624. objP->cType.explInfo.nNextAttach = INTEL_SHORT(objP->cType.explInfo.nNextAttach);
  625. break;
  626. case CT_AI:
  627. objP->cType.aiInfo.nHideSegment = INTEL_SHORT(objP->cType.aiInfo.nHideSegment);
  628. objP->cType.aiInfo.nHideIndex = INTEL_SHORT(objP->cType.aiInfo.nHideIndex);
  629. objP->cType.aiInfo.nPathLength = INTEL_SHORT(objP->cType.aiInfo.nPathLength);
  630. objP->cType.aiInfo.nDangerLaser = INTEL_SHORT(objP->cType.aiInfo.nDangerLaser);
  631. objP->cType.aiInfo.nDangerLaserSig = INTEL_INT(objP->cType.aiInfo.nDangerLaserSig);
  632. objP->cType.aiInfo.xDyingStartTime = INTEL_INT(objP->cType.aiInfo.xDyingStartTime);
  633. break;
  634. case CT_LIGHT:
  635. objP->cType.lightInfo.intensity = INTEL_INT(objP->cType.lightInfo.intensity);
  636. break;
  637. case CT_POWERUP:
  638. objP->cType.powerupInfo.count = INTEL_INT(objP->cType.powerupInfo.count);
  639. objP->cType.powerupInfo.creationTime = INTEL_INT(objP->cType.powerupInfo.creationTime);
  640. // Below commented out 5/2/96 by Matt. I asked Allender why it was
  641. // here, and he didn't know, and it looks like it doesn't belong.
  642. // if (objP->id == POW_VULCAN_WEAPON)
  643. // objP->cType.powerupInfo.count = VULCAN_WEAPON_AMMO_AMOUNT;
  644. break;
  645. }
  646. switch (objP->renderType) {
  647. case RT_MORPH:
  648. case RT_POLYOBJ: {
  649. int i;
  650. objP->rType.polyObjInfo.nModel = INTEL_INT(objP->rType.polyObjInfo.nModel);
  651. for (i=0;i<MAX_SUBMODELS;i++) {
  652. objP->rType.polyObjInfo.animAngles[i].p = INTEL_INT(objP->rType.polyObjInfo.animAngles[i].p);
  653. objP->rType.polyObjInfo.animAngles[i].b = INTEL_INT(objP->rType.polyObjInfo.animAngles[i].b);
  654. objP->rType.polyObjInfo.animAngles[i].h = INTEL_INT(objP->rType.polyObjInfo.animAngles[i].h);
  655. }
  656. objP->rType.polyObjInfo.nSubObjFlags = INTEL_INT(objP->rType.polyObjInfo.nSubObjFlags);
  657. objP->rType.polyObjInfo.nTexOverride = INTEL_INT(objP->rType.polyObjInfo.nTexOverride);
  658. objP->rType.polyObjInfo.nAltTextures = INTEL_INT(objP->rType.polyObjInfo.nAltTextures);
  659. break;
  660. }
  661. case RT_WEAPON_VCLIP:
  662. case RT_HOSTAGE:
  663. case RT_POWERUP:
  664. case RT_FIREBALL:
  665. case RT_THRUSTER:
  666. objP->rType.vClipInfo.nClipIndex = INTEL_INT(objP->rType.vClipInfo.nClipIndex);
  667. objP->rType.vClipInfo.xFrameTime = INTEL_INT(objP->rType.vClipInfo.xFrameTime);
  668. break;
  669. case RT_LASER:
  670. break;
  671. }
  672. // END OF SWAPPING OBJECT STRUCTURE
  673. }
  674. #else /* !WORDS_BIGENDIAN */
  675. // Calculates the checksum of a block of memory.
  676. ushort NetMiscCalcCheckSum(void * vptr, int len)
  677. {
  678. ubyte *ptr = (ubyte *)vptr;
  679. unsigned int sum1,sum2;
  680. sum1 = sum2 = 0;
  681. for (; len; len--) {
  682. sum1 += *ptr++;
  683. if (sum1 >= 255)
  684. sum1 -= 255;
  685. sum2 += sum1;
  686. }
  687. return (sum1 * 256 + sum2 % 255);
  688. }
  689. #endif /* WORDS_BIGENDIAN */
  690. // needs to be recoded to actually work with big endian!
  691. //--unused-- //Finds the difference between block1 and block2. Fills in diff_buffer and
  692. //--unused-- //returns the size of diff_buffer.
  693. //--unused-- int netmisc_find_diff(void *block1, void *block2, int block_size, void *diff_buffer)
  694. //--unused-- {
  695. //--unused-- int mode;
  696. //--unused-- ushort *c1, *c2, *diff_start, *c3;
  697. //--unused-- int i, j, size, diff, n , same;
  698. //--unused--
  699. //--unused-- size=(block_size+1)/sizeof(ushort);
  700. //--unused-- c1 = (ushort *)block1;
  701. //--unused-- c2 = (ushort *)block2;
  702. //--unused-- c3 = (ushort *)diff_buffer;
  703. //--unused--
  704. //--unused-- mode = same = diff = n = 0;
  705. //--unused--
  706. //--unused-- for (i=0; i<size; i++, c1++, c2++) {
  707. //--unused-- if (*c1 != *c2) {
  708. //--unused-- if (mode==0) {
  709. //--unused-- mode = 1;
  710. //--unused-- c3[n++] = same;
  711. //--unused-- same=0; diff=0;
  712. //--unused-- diff_start = c2;
  713. //--unused-- }
  714. //--unused-- *c1 = *c2;
  715. //--unused-- diff++;
  716. //--unused-- if (diff==65535) {
  717. //--unused-- mode = 0;
  718. //--unused-- // send how many diff ones.
  719. //--unused-- c3[n++]=diff;
  720. //--unused-- // send all the diff ones.
  721. //--unused-- for (j=0; j<diff; j++)
  722. //--unused-- c3[n++] = diff_start[j];
  723. //--unused-- same=0; diff=0;
  724. //--unused-- diff_start = c2;
  725. //--unused-- }
  726. //--unused-- } else {
  727. //--unused-- if (mode==1) {
  728. //--unused-- mode=0;
  729. //--unused-- // send how many diff ones.
  730. //--unused-- c3[n++]=diff;
  731. //--unused-- // send all the diff ones.
  732. //--unused-- for (j=0; j<diff; j++)
  733. //--unused-- c3[n++] = diff_start[j];
  734. //--unused-- same=0; diff=0;
  735. //--unused-- diff_start = c2;
  736. //--unused-- }
  737. //--unused-- same++;
  738. //--unused-- if (same==65535) {
  739. //--unused-- mode=1;
  740. //--unused-- // send how many the same
  741. //--unused-- c3[n++] = same;
  742. //--unused-- same=0; diff=0;
  743. //--unused-- diff_start = c2;
  744. //--unused-- }
  745. //--unused-- }
  746. //--unused--
  747. //--unused-- }
  748. //--unused-- if (mode==0) {
  749. //--unused-- // send how many the same
  750. //--unused-- c3[n++] = same;
  751. //--unused-- } else {
  752. //--unused-- // send how many diff ones.
  753. //--unused-- c3[n++]=diff;
  754. //--unused-- // send all the diff ones.
  755. //--unused-- for (j=0; j<diff; j++)
  756. //--unused-- c3[n++] = diff_start[j];
  757. //--unused-- }
  758. //--unused--
  759. //--unused-- return n*2;
  760. //--unused-- }
  761. //--unused-- //Applies diff_buffer to block1 to create a new block1. Returns the final
  762. //--unused-- //size of block1.
  763. //--unused-- int netmisc_apply_diff(void *block1, void *diff_buffer, int diff_size)
  764. //--unused-- {
  765. //--unused-- unsigned int i, j, n, size;
  766. //--unused-- ushort *c1, *c2;
  767. //--unused--
  768. //--unused-- c1 = (ushort *)diff_buffer;
  769. //--unused-- c2 = (ushort *)block1;
  770. //--unused--
  771. //--unused-- size = diff_size/2;
  772. //--unused--
  773. //--unused-- i=j=0;
  774. //--unused-- while (1) {
  775. //--unused-- j += c1[i]; // Same
  776. //--unused-- i++;
  777. //--unused-- if (i>=size) break;
  778. //--unused-- n = c1[i]; // ndiff
  779. //--unused-- i++;
  780. //--unused-- if (n>0) {
  781. //--unused-- //Assert(n* < 256);
  782. //--unused-- memcpy(&c2[j], &c1[i], n*2);
  783. //--unused-- i += n;
  784. //--unused-- j += n;
  785. //--unused-- }
  786. //--unused-- if (i>=size) break;
  787. //--unused-- }
  788. //--unused-- return j*2;
  789. //--unused-- }