PageRenderTime 35ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/simX/d2x-xl
C | 895 lines | 635 code | 104 blank | 156 comment | 63 complexity | 79131e9654efb061d54323f72ee6e2af 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].type), 1, &sum1, &sum2);
  74. BEDoCheckSumCalc(&(gameData.segs.segments[i].sides[j].frame_num), 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].tmap_num);
  78. BEDoCheckSumCalc((ubyte *)&s, 2, &sum1, &sum2);
  79. s = INTEL_SHORT(gameData.segs.segments[i].sides[j].tmap_num2);
  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 object 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->computer_type), 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.type; 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].computer_type), 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->type = 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 *net_address)
  197. {
  198. short tmps;
  199. int loc, tmpi;
  200. loc = 0;
  201. memset(out_buffer, 0, sizeof(out_buffer));
  202. out_buffer[0] = seq.type;
  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.computer_type;
  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 (net_address != NULL)
  228. IPXSendPacketData(out_buffer, loc, server, node, net_address);
  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->type = 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 *net_address, int lite_flag) // 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.type), 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.game_flags), 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 (lite_flag)
  288. goto do_send;
  289. // will this work -- damn bitfields -- totally bogus when trying to do
  290. // this type 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.team_kills[0]);
  338. memcpy(out_buffer + loc, &tmps, 2);
  339. loc += 2; // SWAP_HERE
  340. tmps = INTEL_SHORT(netGame.team_kills[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.player_kills[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.level_time);
  360. memcpy(out_buffer + loc, &tmpi, 4);
  361. loc += 4; // SWAP_HERE
  362. tmpi = INTEL_INT(netGame.control_invul_time);
  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.player_flags[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 (net_address != NULL)
  383. IPXSendPacketData(out_buffer, loc, server, node, net_address);
  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 lite_flag)
  390. {
  391. int i, j;
  392. int loc = 0;
  393. short bitfield; // new_field;
  394. memcpy(&(netgame->type), 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->game_flags), 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 (lite_flag)
  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->team_kills[0]), data + loc, 2);
  480. loc += 2;
  481. netgame->team_kills[0] = INTEL_SHORT(netgame->team_kills[0]);
  482. memcpy(&(netgame->team_kills[1]), data + loc, 2);
  483. loc += 2;
  484. netgame->team_kills[1] = INTEL_SHORT(netgame->team_kills[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->player_kills[i]), data + loc, 2);
  492. loc += 2;
  493. netgame->player_kills[i] = INTEL_SHORT(netgame->player_kills[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->level_time), data + loc, 4);
  502. loc += 4;
  503. netgame->level_time = INTEL_INT(netgame->level_time);
  504. memcpy(&(netgame->control_invul_time), data + loc, 4);
  505. loc += 4;
  506. netgame->control_invul_time = INTEL_INT(netgame->control_invul_time);
  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->player_flags[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 *net_address)
  534. {
  535. int i = 0;
  536. memcpy (out_buffer, &extraGameInfo [1], sizeof (extra_gameinfo));
  537. EGI_INTEL_SHORT_2BUF (entropy.nMaxVirusCapacity);
  538. EGI_INTEL_SHORT_2BUF (entropy.nEnergyFillRate);
  539. EGI_INTEL_SHORT_2BUF (entropy.nShieldFillRate);
  540. EGI_INTEL_SHORT_2BUF (entropy.nShieldDamageRate);
  541. EGI_INTEL_INT_2BUF (nSpawnDelay);
  542. if (net_address != NULL)
  543. IPXSendPacketData(out_buffer, sizeof (extra_gameinfo), server, node, net_address);
  544. else if ((server == NULL) && (node == NULL))
  545. IPXSendBroadcastData(out_buffer, sizeof (extra_gameinfo));
  546. else
  547. IPXSendInternetPacketData(out_buffer, sizeof (extra_gameinfo), server, node);
  548. }
  549. void BEReceiveExtraGameInfo(ubyte *data, extra_gameinfo *extraGameInfo)
  550. {
  551. int i;
  552. memcpy (&extraGameInfo [1], data, sizeof (extra_gameinfo));
  553. BUF2_EGI_INTEL_SHORT (entropy.nMaxVirusCapacity);
  554. BUF2_EGI_INTEL_SHORT (entropy.nEnergyFillRate);
  555. BUF2_EGI_INTEL_SHORT (entropy.nShieldFillRate);
  556. BUF2_EGI_INTEL_SHORT (entropy.nShieldDamageRate);
  557. BUF2_EGI_INTEL_INT (nSpawnDelay);
  558. }
  559. void BESwapObject(object *objP)
  560. {
  561. // swap the short and int entries for this object
  562. objP->signature = INTEL_INT(objP->signature);
  563. objP->next = INTEL_SHORT(objP->next);
  564. objP->prev = INTEL_SHORT(objP->prev);
  565. objP->segnum = INTEL_SHORT(objP->segnum);
  566. objP->pos.x = INTEL_INT(objP->pos.x);
  567. objP->pos.y = INTEL_INT(objP->pos.y);
  568. objP->pos.z = INTEL_INT(objP->pos.z);
  569. objP->orient.rvec.x = INTEL_INT(objP->orient.rvec.x);
  570. objP->orient.rvec.y = INTEL_INT(objP->orient.rvec.y);
  571. objP->orient.rvec.z = INTEL_INT(objP->orient.rvec.z);
  572. objP->orient.fvec.x = INTEL_INT(objP->orient.fvec.x);
  573. objP->orient.fvec.y = INTEL_INT(objP->orient.fvec.y);
  574. objP->orient.fvec.z = INTEL_INT(objP->orient.fvec.z);
  575. objP->orient.uvec.x = INTEL_INT(objP->orient.uvec.x);
  576. objP->orient.uvec.y = INTEL_INT(objP->orient.uvec.y);
  577. objP->orient.uvec.z = INTEL_INT(objP->orient.uvec.z);
  578. objP->size = INTEL_INT(objP->size);
  579. objP->shields = INTEL_INT(objP->shields);
  580. objP->last_pos.x = INTEL_INT(objP->last_pos.x);
  581. objP->last_pos.y = INTEL_INT(objP->last_pos.y);
  582. objP->last_pos.z = INTEL_INT(objP->last_pos.z);
  583. objP->lifeleft = INTEL_INT(objP->lifeleft);
  584. switch (objP->movement_type) {
  585. case MT_PHYSICS:
  586. objP->mtype.phys_info.velocity.x = INTEL_INT(objP->mtype.phys_info.velocity.x);
  587. objP->mtype.phys_info.velocity.y = INTEL_INT(objP->mtype.phys_info.velocity.y);
  588. objP->mtype.phys_info.velocity.z = INTEL_INT(objP->mtype.phys_info.velocity.z);
  589. objP->mtype.phys_info.thrust.x = INTEL_INT(objP->mtype.phys_info.thrust.x);
  590. objP->mtype.phys_info.thrust.y = INTEL_INT(objP->mtype.phys_info.thrust.y);
  591. objP->mtype.phys_info.thrust.z = INTEL_INT(objP->mtype.phys_info.thrust.z);
  592. objP->mtype.phys_info.mass = INTEL_INT(objP->mtype.phys_info.mass);
  593. objP->mtype.phys_info.drag = INTEL_INT(objP->mtype.phys_info.drag);
  594. objP->mtype.phys_info.brakes = INTEL_INT(objP->mtype.phys_info.brakes);
  595. objP->mtype.phys_info.rotvel.x = INTEL_INT(objP->mtype.phys_info.rotvel.x);
  596. objP->mtype.phys_info.rotvel.y = INTEL_INT(objP->mtype.phys_info.rotvel.y);
  597. objP->mtype.phys_info.rotvel.z = INTEL_INT(objP->mtype.phys_info.rotvel.z);
  598. objP->mtype.phys_info.rotthrust.x = INTEL_INT(objP->mtype.phys_info.rotthrust.x);
  599. objP->mtype.phys_info.rotthrust.y = INTEL_INT(objP->mtype.phys_info.rotthrust.y);
  600. objP->mtype.phys_info.rotthrust.z = INTEL_INT(objP->mtype.phys_info.rotthrust.z);
  601. objP->mtype.phys_info.turnroll = INTEL_INT(objP->mtype.phys_info.turnroll);
  602. objP->mtype.phys_info.flags = INTEL_SHORT(objP->mtype.phys_info.flags);
  603. break;
  604. case MT_SPINNING:
  605. objP->mtype.spin_rate.x = INTEL_INT(objP->mtype.spin_rate.x);
  606. objP->mtype.spin_rate.y = INTEL_INT(objP->mtype.spin_rate.y);
  607. objP->mtype.spin_rate.z = INTEL_INT(objP->mtype.spin_rate.z);
  608. break;
  609. }
  610. switch (objP->control_type) {
  611. case CT_WEAPON:
  612. objP->ctype.laser_info.parent_type = INTEL_SHORT(objP->ctype.laser_info.parent_type);
  613. objP->ctype.laser_info.parent_num = INTEL_SHORT(objP->ctype.laser_info.parent_num);
  614. objP->ctype.laser_info.parent_signature = INTEL_INT(objP->ctype.laser_info.parent_signature);
  615. objP->ctype.laser_info.creation_time = INTEL_INT(objP->ctype.laser_info.creation_time);
  616. objP->ctype.laser_info.last_hitobj = INTEL_SHORT(objP->ctype.laser_info.last_hitobj);
  617. objP->ctype.laser_info.track_goal = INTEL_SHORT(objP->ctype.laser_info.track_goal);
  618. objP->ctype.laser_info.multiplier = INTEL_INT(objP->ctype.laser_info.multiplier);
  619. break;
  620. case CT_EXPLOSION:
  621. objP->ctype.expl_info.spawn_time = INTEL_INT(objP->ctype.expl_info.spawn_time);
  622. objP->ctype.expl_info.delete_time = INTEL_INT(objP->ctype.expl_info.delete_time);
  623. objP->ctype.expl_info.delete_objnum = INTEL_SHORT(objP->ctype.expl_info.delete_objnum);
  624. objP->ctype.expl_info.attach_parent = INTEL_SHORT(objP->ctype.expl_info.attach_parent);
  625. objP->ctype.expl_info.prev_attach = INTEL_SHORT(objP->ctype.expl_info.prev_attach);
  626. objP->ctype.expl_info.next_attach = INTEL_SHORT(objP->ctype.expl_info.next_attach);
  627. break;
  628. case CT_AI:
  629. objP->ctype.ai_info.hide_segment = INTEL_SHORT(objP->ctype.ai_info.hide_segment);
  630. objP->ctype.ai_info.hide_index = INTEL_SHORT(objP->ctype.ai_info.hide_index);
  631. objP->ctype.ai_info.path_length = INTEL_SHORT(objP->ctype.ai_info.path_length);
  632. objP->ctype.ai_info.danger_laser_num = INTEL_SHORT(objP->ctype.ai_info.danger_laser_num);
  633. objP->ctype.ai_info.danger_laser_signature = INTEL_INT(objP->ctype.ai_info.danger_laser_signature);
  634. objP->ctype.ai_info.dying_start_time = INTEL_INT(objP->ctype.ai_info.dying_start_time);
  635. break;
  636. case CT_LIGHT:
  637. objP->ctype.light_info.intensity = INTEL_INT(objP->ctype.light_info.intensity);
  638. break;
  639. case CT_POWERUP:
  640. objP->ctype.powerup_info.count = INTEL_INT(objP->ctype.powerup_info.count);
  641. objP->ctype.powerup_info.creation_time = INTEL_INT(objP->ctype.powerup_info.creation_time);
  642. // Below commented out 5/2/96 by Matt. I asked Allender why it was
  643. // here, and he didn't know, and it looks like it doesn't belong.
  644. // if (objP->id == POW_VULCAN_WEAPON)
  645. // objP->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
  646. break;
  647. }
  648. switch (objP->render_type) {
  649. case RT_MORPH:
  650. case RT_POLYOBJ: {
  651. int i;
  652. objP->rtype.pobj_info.model_num = INTEL_INT(objP->rtype.pobj_info.model_num);
  653. for (i=0;i<MAX_SUBMODELS;i++) {
  654. objP->rtype.pobj_info.anim_angles[i].p = INTEL_INT(objP->rtype.pobj_info.anim_angles[i].p);
  655. objP->rtype.pobj_info.anim_angles[i].b = INTEL_INT(objP->rtype.pobj_info.anim_angles[i].b);
  656. objP->rtype.pobj_info.anim_angles[i].h = INTEL_INT(objP->rtype.pobj_info.anim_angles[i].h);
  657. }
  658. objP->rtype.pobj_info.subobj_flags = INTEL_INT(objP->rtype.pobj_info.subobj_flags);
  659. objP->rtype.pobj_info.tmap_override = INTEL_INT(objP->rtype.pobj_info.tmap_override);
  660. objP->rtype.pobj_info.alt_textures = INTEL_INT(objP->rtype.pobj_info.alt_textures);
  661. break;
  662. }
  663. case RT_WEAPON_VCLIP:
  664. case RT_HOSTAGE:
  665. case RT_POWERUP:
  666. case RT_FIREBALL:
  667. case RT_THRUSTER:
  668. objP->rtype.vclip_info.nClipIndex = INTEL_INT(objP->rtype.vclip_info.nClipIndex);
  669. objP->rtype.vclip_info.xFrameTime = INTEL_INT(objP->rtype.vclip_info.xFrameTime);
  670. break;
  671. case RT_LASER:
  672. break;
  673. }
  674. // END OF SWAPPING OBJECT STRUCTURE
  675. }
  676. #else /* !WORDS_BIGENDIAN */
  677. // Calculates the checksum of a block of memory.
  678. ushort NetMiscCalcCheckSum(void * vptr, int len)
  679. {
  680. ubyte *ptr = (ubyte *)vptr;
  681. unsigned int sum1,sum2;
  682. sum1 = sum2 = 0;
  683. for (; len; len--) {
  684. sum1 += *ptr++;
  685. if (sum1 >= 255)
  686. sum1 -= 255;
  687. sum2 += sum1;
  688. }
  689. return (sum1 * 256 + sum2 % 255);
  690. }
  691. #endif /* WORDS_BIGENDIAN */
  692. // needs to be recoded to actually work with big endian!
  693. //--unused-- //Finds the difference between block1 and block2. Fills in diff_buffer and
  694. //--unused-- //returns the size of diff_buffer.
  695. //--unused-- int netmisc_find_diff(void *block1, void *block2, int block_size, void *diff_buffer)
  696. //--unused-- {
  697. //--unused-- int mode;
  698. //--unused-- ushort *c1, *c2, *diff_start, *c3;
  699. //--unused-- int i, j, size, diff, n , same;
  700. //--unused--
  701. //--unused-- size=(block_size+1)/sizeof(ushort);
  702. //--unused-- c1 = (ushort *)block1;
  703. //--unused-- c2 = (ushort *)block2;
  704. //--unused-- c3 = (ushort *)diff_buffer;
  705. //--unused--
  706. //--unused-- mode = same = diff = n = 0;
  707. //--unused--
  708. //--unused-- for (i=0; i<size; i++, c1++, c2++) {
  709. //--unused-- if (*c1 != *c2) {
  710. //--unused-- if (mode==0) {
  711. //--unused-- mode = 1;
  712. //--unused-- c3[n++] = same;
  713. //--unused-- same=0; diff=0;
  714. //--unused-- diff_start = c2;
  715. //--unused-- }
  716. //--unused-- *c1 = *c2;
  717. //--unused-- diff++;
  718. //--unused-- if (diff==65535) {
  719. //--unused-- mode = 0;
  720. //--unused-- // send how many diff ones.
  721. //--unused-- c3[n++]=diff;
  722. //--unused-- // send all the diff ones.
  723. //--unused-- for (j=0; j<diff; j++)
  724. //--unused-- c3[n++] = diff_start[j];
  725. //--unused-- same=0; diff=0;
  726. //--unused-- diff_start = c2;
  727. //--unused-- }
  728. //--unused-- } else {
  729. //--unused-- if (mode==1) {
  730. //--unused-- mode=0;
  731. //--unused-- // send how many diff ones.
  732. //--unused-- c3[n++]=diff;
  733. //--unused-- // send all the diff ones.
  734. //--unused-- for (j=0; j<diff; j++)
  735. //--unused-- c3[n++] = diff_start[j];
  736. //--unused-- same=0; diff=0;
  737. //--unused-- diff_start = c2;
  738. //--unused-- }
  739. //--unused-- same++;
  740. //--unused-- if (same==65535) {
  741. //--unused-- mode=1;
  742. //--unused-- // send how many the same
  743. //--unused-- c3[n++] = same;
  744. //--unused-- same=0; diff=0;
  745. //--unused-- diff_start = c2;
  746. //--unused-- }
  747. //--unused-- }
  748. //--unused--
  749. //--unused-- }
  750. //--unused-- if (mode==0) {
  751. //--unused-- // send how many the same
  752. //--unused-- c3[n++] = same;
  753. //--unused-- } else {
  754. //--unused-- // send how many diff ones.
  755. //--unused-- c3[n++]=diff;
  756. //--unused-- // send all the diff ones.
  757. //--unused-- for (j=0; j<diff; j++)
  758. //--unused-- c3[n++] = diff_start[j];
  759. //--unused-- }
  760. //--unused--
  761. //--unused-- return n*2;
  762. //--unused-- }
  763. //--unused-- //Applies diff_buffer to block1 to create a new block1. Returns the final
  764. //--unused-- //size of block1.
  765. //--unused-- int netmisc_apply_diff(void *block1, void *diff_buffer, int diff_size)
  766. //--unused-- {
  767. //--unused-- unsigned int i, j, n, size;
  768. //--unused-- ushort *c1, *c2;
  769. //--unused--
  770. //--unused-- c1 = (ushort *)diff_buffer;
  771. //--unused-- c2 = (ushort *)block1;
  772. //--unused--
  773. //--unused-- size = diff_size/2;
  774. //--unused--
  775. //--unused-- i=j=0;
  776. //--unused-- while (1) {
  777. //--unused-- j += c1[i]; // Same
  778. //--unused-- i++;
  779. //--unused-- if (i>=size) break;
  780. //--unused-- n = c1[i]; // ndiff
  781. //--unused-- i++;
  782. //--unused-- if (n>0) {
  783. //--unused-- //Assert(n* < 256);
  784. //--unused-- memcpy(&c2[j], &c1[i], n*2);
  785. //--unused-- i += n;
  786. //--unused-- j += n;
  787. //--unused-- }
  788. //--unused-- if (i>=size) break;
  789. //--unused-- }
  790. //--unused-- return j*2;
  791. //--unused-- }