PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/v1.14.90/network/netmisc-old.cpp

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