PageRenderTime 64ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

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