]> icculus.org git repositories - btb/d2x.git/blob - main/netpkt.c
Lotsa networking stuff from d1x
[btb/d2x.git] / main / netpkt.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  * $Source: /cvs/cvsroot/d2x/main/netpkt.c,v $
16  * $Revision: 1.1 $
17  * $Author: bradleyb $
18  * $Date: 2002-02-14 09:05:33 $
19  *
20  * Network packet conversions
21  * Based on macnet.c from MAC version of Descent 1
22  *
23  * $Log: not supported by cvs2svn $
24  *
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include <conf.h>
29 #endif
30
31 #include <string.h>
32 #include "pstypes.h"
33 #include "multi.h"
34 #include "network.h"
35 #include "object.h"
36 #include "powerup.h"
37 #include "error.h"
38 #include "ipx.h"
39 #include "netpkt.h"
40
41 void receive_netplayer_info(ubyte *data, netplayer_info *info, int dxx)
42 {
43         int loc = 0;
44         
45         memcpy(info->callsign, &(data[loc]), CALLSIGN_LEN);           loc += CALLSIGN_LEN;
46         info->callsign[CALLSIGN_LEN] = 0;
47         if (!dxx) loc++;
48         memcpy(&(info->network.ipx.server), &(data[loc]), 4);                             loc += 4;
49         memcpy(&(info->network.ipx.node), &(data[loc]), 6);                                       loc += 6;
50         memcpy(&(info->socket), &(data[loc]), 2);                                 loc += 2;
51 //MWA  don't think we need to swap this because we need it in high order        info->socket = swapshort(info->socket);
52         info->connected = data[loc]; loc++;
53         #ifndef SHAREWARE
54  //edited 03/04/99 Matt Mueller - sub_protocol was being set wrong in non-dxx games.. I still think its screwed somewhere else too though
55         if (dxx){     
56                 info->sub_protocol = data[loc]; loc++;
57 //              printf ("%i "__FUNCTION__ " name=%s sub_protocol=%i\n",Player_num,info->callsign,info->sub_protocol);
58         }else
59                 info->sub_protocol = 0;
60 //end edit -MM
61         #endif
62 }
63
64 void send_sequence_packet(sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address)
65 {
66         short tmps;
67         int loc;
68
69         loc = 0;
70         memset(out_buffer, 0, sizeof(out_buffer));
71         out_buffer[0] = seq.type;                       loc++;
72         memcpy(&(out_buffer[loc]), seq.player.callsign, CALLSIGN_LEN+1);                loc += CALLSIGN_LEN+1;
73         memcpy(&(out_buffer[loc]), seq.player.network.ipx.server, 4);     loc += 4;
74         memcpy(&(out_buffer[loc]), seq.player.network.ipx.node, 6);       loc += 6;
75         tmps = swapshort(seq.player.socket);
76         memcpy(&(out_buffer[loc]), &tmps, 2);           loc += 2;
77         out_buffer[loc] = seq.player.connected; loc++;
78         out_buffer[loc] = MULTI_PROTO_DXX_MINOR; loc++;
79
80         if (net_address != NULL)        
81                 ipx_send_packet_data( out_buffer, loc, server, node, net_address);
82         else if ((server == NULL) && (node == NULL))
83                 ipx_send_broadcast_packet_data( out_buffer, loc );
84         else
85                 ipx_send_internetwork_packet_data( out_buffer, loc, server, node);
86 }
87
88 void receive_sequence_packet(ubyte *data, sequence_packet *seq)
89 {
90         int loc = 0;
91         
92         seq->type = data[0];                            loc++;
93         receive_netplayer_info(&(data[loc]), &(seq->player), 0);
94 }
95
96
97 void send_netgame_packet(ubyte *server, ubyte *node)
98 {
99         uint tmpi;
100         ushort tmps;
101         int i, j;
102         int loc = 0;
103         
104 #ifndef SHAREWARE
105         if (Netgame.protocol_version == MULTI_PROTO_DXX_VER) {
106                 send_dxx_netgame_packet(server, node);
107                 return;
108         }
109 #endif
110         memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
111         out_buffer[loc] = Netgame.type; loc++;
112         memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1);
113         memcpy(&(out_buffer[loc]), Netgame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1);
114         out_buffer[loc] = Netgame.gamemode; loc++;
115         out_buffer[loc] = Netgame.difficulty; loc++;
116         out_buffer[loc] = Netgame.game_status; loc++;
117         out_buffer[loc] = Netgame.numplayers; loc++;
118         out_buffer[loc] = Netgame.max_numplayers; loc++;
119         out_buffer[loc] = Netgame.game_flags; loc++;
120         for (i = 0; i < MAX_PLAYERS; i++) {
121                 memcpy(&(out_buffer[loc]), NetPlayers.players[i].callsign, CALLSIGN_LEN+1);     loc += CALLSIGN_LEN+1;
122                 memcpy(&(out_buffer[loc]), NetPlayers.players[i].network.ipx.server, 4);                                  loc += 4;
123                 memcpy(&(out_buffer[loc]), NetPlayers.players[i].network.ipx.node, 6);                                    loc += 6;
124                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].socket), 2);                           loc += 2;
125                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].connected), 1);                              loc++;
126         }
127         if (Netgame.protocol_version == MULTI_PROTO_DXX_VER) {
128                 for (i = 0; i < MAX_PLAYERS; i++) {
129                         out_buffer[loc] = Netgame.locations[i]; loc++;
130                 }
131         } else {
132                 for (i = 0; i < MAX_PLAYERS; i++) {
133                         tmpi = swapint(Netgame.locations[i]);
134                         memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                 // SWAP HERE!!!
135                 }
136         }
137
138         for (i = 0; i < MAX_PLAYERS; i++) {
139                 for (j = 0; j < MAX_PLAYERS; j++) {
140                         tmps = swapshort(Netgame.kills[i][j]);
141                         memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                 // SWAP HERE!!!
142                 }
143         }
144
145         tmpi = swapint(Netgame.levelnum);
146         memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
147         out_buffer[loc] = Netgame.protocol_version; loc++;
148         out_buffer[loc] = Netgame.team_vector; loc++;
149         tmps = swapshort(Netgame.segments_checksum);
150         memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                         // SWAP_HERE
151         tmps = swapshort(Netgame.team_kills[0]);
152         memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                         // SWAP_HERE
153         tmps = swapshort(Netgame.team_kills[1]);
154         memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                         // SWAP_HERE
155         for (i = 0; i < MAX_PLAYERS; i++) {
156                 tmps = swapshort(Netgame.killed[i]);
157                 memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                 // SWAP HERE!!!
158         }
159         for (i = 0; i < MAX_PLAYERS; i++) {
160                 tmps = swapshort(Netgame.player_kills[i]);
161                 memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                 // SWAP HERE!!!
162         }
163
164 #ifndef SHAREWARE
165         tmpi = swapint(Netgame.level_time);
166         memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
167         tmpi = swapint(Netgame.control_invul_time);
168         memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
169         tmpi = swapint(Netgame.monitor_vector);
170         memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
171         for (i = 0; i < 8; i++) {
172                 tmpi = swapint(Netgame.player_score[i]);
173                 memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
174         }
175         for (i = 0; i < 8; i++) {
176                 memcpy(&(out_buffer[loc]), &(Netgame.player_flags[i]), 1); loc++;
177         }
178         memcpy(&(out_buffer[loc]), Netgame.mission_name, 9); loc += 9;
179         memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1);
180         if (Netgame.protocol_version == MULTI_PROTO_DXX_VER) {
181             out_buffer[loc] = Netgame.PacketsPerSec; loc++;
182             tmpi = swapint(Netgame.flags);
183             memcpy(&out_buffer[loc], &tmpi, 4); loc += 4;
184         }
185 #endif
186
187         if (server == NULL)
188                 ipx_send_broadcast_packet_data(out_buffer, loc);
189         else
190                 ipx_send_internetwork_packet_data( out_buffer, loc, server, node );
191 }
192
193 void receive_netgame_packet(ubyte *data, netgame_info *netgame, AllNetPlayers_info *netplayers, int dxx)
194 {
195         int i, j;
196         int loc = 0;
197 #ifndef SHAREWARE
198         if (dxx) {
199                 receive_dxx_netgame_packet(data, netgame, netplayers);
200                 return;
201         }
202 #endif
203
204         netgame->type = data[loc];      loc++;
205         memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1);
206         memcpy(netgame->team_name, &(data[loc]), 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1);
207         netgame->gamemode = data[loc]; loc++;
208         netgame->difficulty = data[loc]; loc++;
209         netgame->game_status = data[loc]; loc++;
210         netgame->numplayers = data[loc]; loc++;
211         netgame->max_numplayers = data[loc]; loc++;
212         netgame->game_flags = data[loc]; loc++;
213         for (i = 0; i < MAX_PLAYERS; i++) {
214                 receive_netplayer_info(&(data[loc]), &(netplayers->players[i]), 0);
215                 loc += sizeof(netplayer_info);//NETPLAYER_ORIG_SIZE;
216         }
217 #if 0
218         if (dxx) {
219                 for (i = 0; i < MAX_PLAYERS; i++) {
220                         netgame->locations[i] = data[loc]; loc++;
221                 }
222         } else
223 #endif
224         {
225                 for (i = 0; i < MAX_PLAYERS; i++) {
226                         memcpy(&(netgame->locations[i]), &(data[loc]), 4); loc += 4;                    // SWAP HERE!!!
227                         netgame->locations[i] = swapint(netgame->locations[i]);
228                 }
229         }
230
231         for (i = 0; i < MAX_PLAYERS; i++) {
232                 for (j = 0; j < MAX_PLAYERS; j++) {
233                         memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2;                     // SWAP HERE!!!
234                         netgame->kills[i][j] = swapshort(netgame->kills[i][j]);
235                 }
236         }
237
238         memcpy(&(netgame->levelnum), &(data[loc]), 4); loc += 4;                                // SWAP_HERE
239         netgame->levelnum = swapint(netgame->levelnum);
240         netgame->protocol_version = data[loc]; loc++;
241         netgame->team_vector = data[loc]; loc++;
242         memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2;                               // SWAP_HERE
243         netgame->segments_checksum = swapshort(netgame->segments_checksum);
244         memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2;                           // SWAP_HERE
245         netgame->team_kills[0] = swapshort(netgame->team_kills[0]);
246         memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2;                           // SWAP_HERE
247         netgame->team_kills[1] = swapshort(netgame->team_kills[1]);
248         for (i = 0; i < MAX_PLAYERS; i++) {
249                 memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2;                       // SWAP HERE!!!
250                 netgame->killed[i] = swapshort(netgame->killed[i]);
251         }
252         for (i = 0; i < MAX_PLAYERS; i++) {
253                 memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2;                 // SWAP HERE!!!
254                 netgame->player_kills[i] = swapshort(netgame->player_kills[i]);
255         }
256
257 #ifndef SHAREWARE
258         memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4;                              // SWAP_HERE
259         netgame->level_time = swapint(netgame->level_time);
260         memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4;                              // SWAP_HERE
261         netgame->control_invul_time = swapint(netgame->control_invul_time);
262         memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4;                          // SWAP_HERE
263         netgame->monitor_vector = swapint(netgame->monitor_vector);
264         for (i = 0; i < 8; i++) {
265                 memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4;                         // SWAP_HERE
266                 netgame->player_score[i] = swapint(netgame->player_score[i]);
267         }
268         memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8;
269 #if 0
270         for (i = 0; i < 8; i++) {
271                 memcpy(&(netgame->player_flags[i]), &(data[loc]), 1); loc++;
272         }
273 #endif
274
275         memcpy(netgame->mission_name, &(data[loc]), 9); loc += 9;
276         memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1);
277 #if 0
278         if (dxx && netgame->protocol_version == MULTI_PROTO_DXX_VER) {
279             netgame->packets_per_sec = data[loc]; loc++;
280             memcpy(&netgame->flags, &data[loc], 4); loc += 4;
281             netgame->flags = swapint(netgame->flags);
282         }
283 #endif
284 #endif
285 }
286
287 #ifndef SHAREWARE
288 void store_netplayer_info(ubyte *data, netplayer_info *player, int dxx)
289 {
290         memcpy(data, player->callsign, CALLSIGN_LEN);      data += CALLSIGN_LEN;
291         if (!dxx) *(data++) = 0;
292         memcpy(data, player->network.ipx.server, 4);               data += 4;
293         memcpy(data, player->network.ipx.node, 6);                         data += 6;
294         memcpy(data, &player->socket, 2);                data += 2;
295         *data = player->connected;     data++;
296         if (dxx) {
297                 *data = player->sub_protocol;  data++;
298 //          printf ("%i "__FUNCTION__ " name=%s sub_protocol=%i\n",Player_num,player->callsign,player->sub_protocol);
299         }
300 }
301
302 void send_dxx_netgame_packet(ubyte *server, ubyte *node)
303 {
304         uint tmpi;
305         ushort tmps;
306         int i, j;
307         int loc = 0;
308         
309         memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
310         out_buffer[loc] = Netgame.type; loc++;
311         out_buffer[loc] = MULTI_PROTO_DXX_VER; loc++;
312         out_buffer[loc] = Netgame.subprotocol; loc++;
313         out_buffer[loc] = Netgame.required_subprotocol; loc++;
314         memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN;
315         memcpy(&(out_buffer[loc]), Netgame.mission_name, 8); loc += 8;
316         memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN); loc += MISSION_NAME_LEN;
317         out_buffer[loc] = Netgame.levelnum; loc++;
318         out_buffer[loc] = Netgame.gamemode; loc++;
319         out_buffer[loc] = Netgame.difficulty; loc++;
320         out_buffer[loc] = Netgame.game_status; loc++;
321         out_buffer[loc] = Netgame.game_flags; loc++;
322         out_buffer[loc] = Netgame.max_numplayers; loc++;
323         out_buffer[loc] = Netgame.team_vector; loc++;
324         if (Netgame.type == PID_DXX_GAME_LITE) {
325                 int master = -1;
326                 j = 0;
327                 for (i = 0; i < Netgame.numplayers; i++)
328                         if (Players[i].connected) {
329                                 if (master == -1)
330                                         master = i;
331                                 j++;
332                         }
333                 out_buffer[loc] = j; loc++; /* numconnected */
334                 if (master == -1)   /* should not happen, but... */
335                         master = Player_num; 
336                 store_netplayer_info(&(out_buffer[loc]), &NetPlayers.players[master], 1); loc += sizeof(netplayer_info); //NETPLAYER_DXX_SIZE;
337                 //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them
338                 tmpi = swapint(Netgame.flags);
339                 memcpy(&out_buffer[loc], &tmpi, 4); loc += 4;
340                 //end addition -MM
341         } else {
342                 out_buffer[loc] = Netgame.numplayers; loc++;
343                 out_buffer[loc] = sizeof(netplayer_info); //NETPLAYER_DXX_SIZE; // sizeof netplayer struct
344                 loc++;
345                 for (i = 0; i < MAX_PLAYERS; i++) {
346                         store_netplayer_info(&(out_buffer[loc]), &NetPlayers.players[i], 1);
347                         loc += sizeof(netplayer_info); //NETPLAYER_DXX_SIZE;
348                 }
349                 memcpy(&(out_buffer[loc]), Netgame.team_name[0], CALLSIGN_LEN); loc += CALLSIGN_LEN;
350                 memcpy(&(out_buffer[loc]), Netgame.team_name[1], CALLSIGN_LEN); loc += CALLSIGN_LEN;
351                 for (i = 0; i < MAX_PLAYERS; i++) {
352                         out_buffer[loc] = Netgame.locations[i]; loc++;
353                 }
354                 for (i = 0; i < MAX_PLAYERS; i++) {
355                         for (j = 0; j < MAX_PLAYERS; j++) {
356                                 tmps = swapshort(Netgame.kills[i][j]);
357                                 memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;         // SWAP HERE!!!
358                         }
359                 }
360                 tmps = swapshort(Netgame.segments_checksum);
361                 memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                         // SWAP_HERE
362                 tmps = swapshort(Netgame.team_kills[0]);
363                 memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                         // SWAP_HERE
364                 tmps = swapshort(Netgame.team_kills[1]);
365                 memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                         // SWAP_HERE
366                 for (i = 0; i < MAX_PLAYERS; i++) {
367                         tmps = swapshort(Netgame.killed[i]);
368                         memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                 // SWAP HERE!!!
369                 }
370                 for (i = 0; i < MAX_PLAYERS; i++) {
371                         tmps = swapshort(Netgame.player_kills[i]);
372                         memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;                 // SWAP HERE!!!
373                 }
374                 tmpi = swapint(Netgame.level_time);
375                 memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
376                 tmpi = swapint(Netgame.control_invul_time);
377                 memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
378                 tmpi = swapint(Netgame.monitor_vector);
379                 memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
380                 for (i = 0; i < 8; i++) {
381                         tmpi = swapint(Netgame.player_score[i]);
382                         memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;                         // SWAP_HERE
383                 }
384                 memcpy(&(out_buffer[loc]), Netgame.player_flags, MAX_PLAYERS); loc += MAX_PLAYERS;
385                 out_buffer[loc] = Netgame.PacketsPerSec; loc++;
386                 tmpi = swapint(Netgame.flags);
387                 memcpy(&out_buffer[loc], &tmpi, 4); loc += 4;
388         }
389
390         if (server == NULL)
391                 ipx_send_broadcast_packet_data(out_buffer, loc);
392         else
393                 ipx_send_internetwork_packet_data(out_buffer, loc, server, node);
394 }
395
396 void receive_dxx_netgame_packet(ubyte *data, netgame_info *netgame, AllNetPlayers_info *netplayers) {
397         int i, j;
398         int loc = 0;
399         
400         netgame->type = data[loc];      loc++;
401         if (netgame->type == PID_DXX_GAME_LITE) {
402                 memset(netgame, 0, sizeof(netgame_info));
403                 netgame->type = PID_DXX_GAME_LITE;
404         }
405         netgame->protocol_version = data[loc]; loc++;
406         netgame->subprotocol = data[loc]; loc++;
407         netgame->required_subprotocol = data[loc]; loc++;
408         memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN;
409         netgame->game_name[NETGAME_NAME_LEN] = 0;
410         memcpy(netgame->mission_name, &(data[loc]), 8); loc += 8;
411         netgame->mission_name[8] = 0;
412         memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN); loc += MISSION_NAME_LEN;
413         netgame->mission_title[MISSION_NAME_LEN] = 0;
414         netgame->levelnum = ((signed char *)data)[loc]; loc++;
415         netgame->gamemode = data[loc]; loc++;
416         netgame->difficulty = data[loc]; loc++;
417         netgame->game_status = data[loc]; loc++;
418         netgame->game_flags = data[loc]; loc++;
419         netgame->max_numplayers = data[loc]; loc++;
420         netgame->team_vector = data[loc]; loc++;
421         if (netgame->type == PID_DXX_GAME_LITE) {
422                 j = netgame->numplayers = data[loc]; loc++;
423                 for (i = 0; i < j; i++)
424                         netplayers->players[i].connected = 1;
425                 receive_netplayer_info(&(data[loc]), &(netplayers->players[0]), 1);loc += sizeof(netplayer_info); //NETPLAYER_DXX_SIZE;
426                 //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them
427                 if (netgame->subprotocol>=1){
428                         memcpy(&netgame->flags, &data[loc], 4); loc += 4;
429                         netgame->flags = swapint(netgame->flags);
430                 }
431                 //end addition -MM
432         } else {
433                 netgame->numplayers = data[loc]; loc++;
434                 j = data[loc]; loc++; // sizeof netplayer struct
435                 if (j > 29) { /* sanity: 304+29*8=536, just below IPX_MAX=542 */
436                     netgame->protocol_version = 0; return;
437                 }
438                 for (i = 0; i < MAX_PLAYERS; i++) {
439                         receive_netplayer_info(&(data[loc]), &(netplayers->players[i]), 1);
440                         loc += j;
441                 }
442                 memcpy(netgame->team_name[0], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN;
443                 netgame->team_name[0][CALLSIGN_LEN] = 0;
444                 memcpy(netgame->team_name[1], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN;
445                 netgame->team_name[1][CALLSIGN_LEN] = 0;
446                 for (i = 0; i < MAX_PLAYERS; i++) {
447                         netgame->locations[i] = data[loc]; loc++;
448                 }
449                 for (i = 0; i < MAX_PLAYERS; i++) {
450                         for (j = 0; j < MAX_PLAYERS; j++) {
451                                 memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2;                     // SWAP HERE!!!
452                                 netgame->kills[i][j] = swapshort(netgame->kills[i][j]);
453                         }
454                 }
455                 memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2;                               // SWAP_HERE
456                 netgame->segments_checksum = swapshort(netgame->segments_checksum);
457                 memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2;                           // SWAP_HERE
458                 netgame->team_kills[0] = swapshort(netgame->team_kills[0]);
459                 memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2;                           // SWAP_HERE
460                 netgame->team_kills[1] = swapshort(netgame->team_kills[1]);
461                 for (i = 0; i < MAX_PLAYERS; i++) {
462                         memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2;                       // SWAP HERE!!!
463                         netgame->killed[i] = swapshort(netgame->killed[i]);
464                 }
465                 for (i = 0; i < MAX_PLAYERS; i++) {
466                         memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2;                 // SWAP HERE!!!
467                         netgame->player_kills[i] = swapshort(netgame->player_kills[i]);
468                 }
469                 memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4;                              // SWAP_HERE
470                 netgame->level_time = swapint(netgame->level_time);
471                 memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4;                              // SWAP_HERE
472                 netgame->control_invul_time = swapint(netgame->control_invul_time);
473                 memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4;                          // SWAP_HERE
474                 netgame->monitor_vector = swapint(netgame->monitor_vector);
475                 for (i = 0; i < 8; i++) {
476                         memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4;                         // SWAP_HERE
477                         netgame->player_score[i] = swapint(netgame->player_score[i]);
478                 }
479                 memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8;
480                 netgame->PacketsPerSec = data[loc]; loc++;
481                 memcpy(&netgame->flags, &data[loc], 4); loc += 4;
482                 netgame->flags = swapint(netgame->flags);
483         }
484 }
485 #endif
486
487 void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet)
488 {
489         int loc, tmpi;
490         short tmps;
491 #ifndef SHAREWARE
492         ushort tmpus;
493 #endif
494         object *pl_obj = &Objects[Players[Player_num].objnum];
495         
496         loc = 0;
497         memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
498 #ifdef SHAREWARE
499         out_buffer[0] = PID_PDATA;              loc++;
500         tmpi = swapint(MySyncPack.numpackets);
501         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
502         tmps = swapshort(Players[Player_num].objnum);
503         memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
504         out_buffer[loc] = Player_num; loc++;
505         tmps = swapshort(pl_obj->segnum);
506         memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
507
508         tmpi = swapint((int)pl_obj->pos.x);
509         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
510         tmpi = swapint((int)pl_obj->pos.y);
511         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
512         tmpi = swapint((int)pl_obj->pos.z);
513         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
514         
515         tmpi = swapint((int)pl_obj->orient.rvec.x);
516         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
517         tmpi = swapint((int)pl_obj->orient.rvec.y);
518         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
519         tmpi = swapint((int)pl_obj->orient.rvec.z);
520         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
521         tmpi = swapint((int)pl_obj->orient.uvec.x);
522         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
523         tmpi = swapint((int)pl_obj->orient.uvec.y);
524         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
525         tmpi = swapint((int)pl_obj->orient.uvec.z);
526         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
527         tmpi = swapint((int)pl_obj->orient.fvec.x);
528         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
529         tmpi = swapint((int)pl_obj->orient.fvec.y);
530         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
531         tmpi = swapint((int)pl_obj->orient.fvec.z);
532         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
533         
534         tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x);
535         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
536         tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y);
537         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
538         tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z);
539         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
540         tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.x);
541         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
542         tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.y);
543         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
544         tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.z);
545         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
546         tmpi = swapint((int)pl_obj->mtype.phys_info.mass);
547         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
548         tmpi = swapint((int)pl_obj->mtype.phys_info.drag);
549         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
550         tmpi = swapint((int)pl_obj->mtype.phys_info.brakes);
551         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
552         tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x);
553         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
554         tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y);
555         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
556         tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z);
557         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
558         tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.x);
559         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
560         tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.y);
561         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
562         tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.z);
563         memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
564         tmps = swapshort((short)pl_obj->mtype.phys_info.turnroll);
565         memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
566         tmps = swapshort(pl_obj->mtype.phys_info.flags);
567         memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
568         
569         out_buffer[loc] = pl_obj->render_type; loc++;
570         out_buffer[loc] = Current_level_num; loc++;
571         tmps = swapshort(MySyncPack.data_size);
572         memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
573         memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size);
574         loc += MySyncPack.data_size;
575 #else
576         if (short_packet == 1) {
577                 loc = 0;
578                 out_buffer[loc] = PID_SHORTPDATA; loc++;
579                 out_buffer[loc] = Player_num; loc++;
580                 out_buffer[loc] = pl_obj->render_type; loc++;
581                 out_buffer[loc] = Current_level_num; loc++;
582                 create_shortpos((shortpos *)(out_buffer + loc), pl_obj, 0);
583                 loc += 9+2*3+2+2*3; // go past shortpos structure
584                 *(ushort *)(out_buffer + loc) = MySyncPack.data_size; loc += 2;
585                 memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size);
586                 loc += MySyncPack.data_size;
587         } else if (short_packet == 2) {
588                 loc = 0;
589                 out_buffer[loc] = PID_PDATA_SHORT2; loc++;
590                 out_buffer[loc] = MySyncPack.numpackets & 255; loc++;
591                 create_shortpos((shortpos *)(out_buffer + loc), pl_obj, 0);
592                 loc += 9+2*3+2+2*3; // go past shortpos structure
593                 tmpus = MySyncPack.data_size | (Player_num << 12) | (pl_obj->render_type << 15);
594                 *(ushort *)(out_buffer + loc) = tmpus; loc += 2;
595                 out_buffer[loc] = Current_level_num; loc++;
596                 memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size);
597                 loc += MySyncPack.data_size;
598         } else {
599                 out_buffer[0] = PID_PDATA;              loc++;  loc += 3;               // skip three for pad byte
600                 tmpi = swapint(MySyncPack.numpackets);
601                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
602
603                 tmpi = swapint((int)pl_obj->pos.x);
604                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
605                 tmpi = swapint((int)pl_obj->pos.y);
606                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
607                 tmpi = swapint((int)pl_obj->pos.z);
608                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
609
610                 tmpi = swapint((int)pl_obj->orient.rvec.x);
611                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
612                 tmpi = swapint((int)pl_obj->orient.rvec.y);
613                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
614                 tmpi = swapint((int)pl_obj->orient.rvec.z);
615                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
616                 tmpi = swapint((int)pl_obj->orient.uvec.x);
617                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
618                 tmpi = swapint((int)pl_obj->orient.uvec.y);
619                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
620                 tmpi = swapint((int)pl_obj->orient.uvec.z);
621                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
622                 tmpi = swapint((int)pl_obj->orient.fvec.x);
623                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
624                 tmpi = swapint((int)pl_obj->orient.fvec.y);
625                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
626                 tmpi = swapint((int)pl_obj->orient.fvec.z);
627                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
628
629                 tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x);
630                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
631                 tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y);
632                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
633                 tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z);
634                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
635
636                 tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x);
637                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
638                 tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y);
639                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
640                 tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z);
641                 memcpy(&(out_buffer[loc]), &tmpi, 4);   loc += 4;
642
643                 tmps = swapshort(pl_obj->segnum);
644                 memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
645                 tmps = swapshort(MySyncPack.data_size);
646                 memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;
647
648                 out_buffer[loc] = Player_num; loc++;
649                 out_buffer[loc] = pl_obj->render_type; loc++;
650                 out_buffer[loc] = Current_level_num; loc++;
651                 memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size);
652                 loc += MySyncPack.data_size;
653         }
654 #endif
655 #if 0 // adb: not possible (always array passed)
656         if (address == NULL)
657                 ipx_send_internetwork_packet_data( out_buffer, loc, server, node );
658         else
659 #endif
660                 ipx_send_packet_data( out_buffer, loc, server, node, address);
661 }
662
663 void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet)
664 {
665         int loc;
666         
667 #ifdef SHAREWARE
668         loc = 0;
669
670         info->type = data[0];                                                   loc++;
671         memcpy(&(info->numpackets), &(data[loc]), 4);   loc += 4;
672         info->numpackets = swapint(info->numpackets);
673         memcpy(&(info->objnum), &(data[loc]), 2);               loc += 2;
674         info->objnum = swapshort(info->objnum);
675         info->playernum = data[loc];                                    loc++;
676
677         memcpy(&(info->obj_segnum), &(data[loc]), 2);   loc += 2;
678         info->obj_segnum = swapshort(info->obj_segnum);
679
680         memcpy(&(info->obj_pos.x), &(data[loc]), 4);    loc += 4;
681         info->obj_pos.x = (fix)swapint((int)info->obj_pos.x);
682         memcpy(&(info->obj_pos.y), &(data[loc]), 4);    loc += 4;
683         info->obj_pos.y = (fix)swapint((int)info->obj_pos.y);
684         memcpy(&(info->obj_pos.z), &(data[loc]), 4);    loc += 4;
685         info->obj_pos.z = (fix)swapint((int)info->obj_pos.z);
686
687         memcpy(&(info->obj_orient.rvec.x), &(data[loc]), 4);    loc += 4;
688         info->obj_orient.rvec.x = (fix)swapint((int)info->obj_orient.rvec.x);
689         memcpy(&(info->obj_orient.rvec.y), &(data[loc]), 4);    loc += 4;
690         info->obj_orient.rvec.y = (fix)swapint((int)info->obj_orient.rvec.y);
691         memcpy(&(info->obj_orient.rvec.z), &(data[loc]), 4);    loc += 4;
692         info->obj_orient.rvec.z = (fix)swapint((int)info->obj_orient.rvec.z);
693         memcpy(&(info->obj_orient.uvec.x), &(data[loc]), 4);    loc += 4;
694         info->obj_orient.uvec.x = (fix)swapint((int)info->obj_orient.uvec.x);
695         memcpy(&(info->obj_orient.uvec.y), &(data[loc]), 4);    loc += 4;
696         info->obj_orient.uvec.y = (fix)swapint((int)info->obj_orient.uvec.y);
697         memcpy(&(info->obj_orient.uvec.z), &(data[loc]), 4);    loc += 4;
698         info->obj_orient.uvec.z = (fix)swapint((int)info->obj_orient.uvec.z);
699         memcpy(&(info->obj_orient.fvec.x), &(data[loc]), 4);    loc += 4;
700         info->obj_orient.fvec.x = (fix)swapint((int)info->obj_orient.fvec.x);
701         memcpy(&(info->obj_orient.fvec.y), &(data[loc]), 4);    loc += 4;
702         info->obj_orient.fvec.y = (fix)swapint((int)info->obj_orient.fvec.y);
703         memcpy(&(info->obj_orient.fvec.z), &(data[loc]), 4);    loc += 4;
704         info->obj_orient.fvec.z = (fix)swapint((int)info->obj_orient.fvec.z);
705         
706         memcpy(&(info->obj_phys_info.velocity.x), &(data[loc]), 4);     loc += 4;
707         info->obj_phys_info.velocity.x = (fix)swapint((int)info->obj_phys_info.velocity.x);
708         memcpy(&(info->obj_phys_info.velocity.y), &(data[loc]), 4);     loc += 4;
709         info->obj_phys_info.velocity.y = (fix)swapint((int)info->obj_phys_info.velocity.y);
710         memcpy(&(info->obj_phys_info.velocity.z), &(data[loc]), 4);     loc += 4;
711         info->obj_phys_info.velocity.z = (fix)swapint((int)info->obj_phys_info.velocity.z);
712
713         memcpy(&(info->obj_phys_info.thrust.x), &(data[loc]), 4);       loc += 4;
714         info->obj_phys_info.thrust.x = (fix)swapint((int)info->obj_phys_info.thrust.x);
715         memcpy(&(info->obj_phys_info.thrust.y), &(data[loc]), 4);       loc += 4;
716         info->obj_phys_info.thrust.y = (fix)swapint((int)info->obj_phys_info.thrust.y);
717         memcpy(&(info->obj_phys_info.thrust.z), &(data[loc]), 4);       loc += 4;
718         info->obj_phys_info.thrust.z = (fix)swapint((int)info->obj_phys_info.thrust.z);
719
720         memcpy(&(info->obj_phys_info.mass), &(data[loc]), 4);   loc += 4;
721         info->obj_phys_info.mass = (fix)swapint((int)info->obj_phys_info.mass);
722         memcpy(&(info->obj_phys_info.drag), &(data[loc]), 4);   loc += 4;
723         info->obj_phys_info.drag = (fix)swapint((int)info->obj_phys_info.drag);
724         memcpy(&(info->obj_phys_info.brakes), &(data[loc]), 4); loc += 4;
725         info->obj_phys_info.brakes = (fix)swapint((int)info->obj_phys_info.brakes);
726
727         memcpy(&(info->obj_phys_info.rotvel.x), &(data[loc]), 4);       loc += 4;
728         info->obj_phys_info.rotvel.x = (fix)swapint((int)info->obj_phys_info.rotvel.x);
729         memcpy(&(info->obj_phys_info.rotvel.y), &(data[loc]), 4);       loc += 4;
730         info->obj_phys_info.rotvel.y = (fix)swapint((int)info->obj_phys_info.rotvel.y);
731         memcpy(&(info->obj_phys_info.rotvel.z), &(data[loc]), 4);       loc += 4;
732         info->obj_phys_info.rotvel.z = (fix)swapint((int)info->obj_phys_info.rotvel.z);
733
734         memcpy(&(info->obj_phys_info.rotthrust.x), &(data[loc]), 4);    loc += 4;
735         info->obj_phys_info.rotthrust.x = (fix)swapint((int)info->obj_phys_info.rotthrust.x);
736         memcpy(&(info->obj_phys_info.rotthrust.y), &(data[loc]), 4);    loc += 4;
737         info->obj_phys_info.rotthrust.y = (fix)swapint((int)info->obj_phys_info.rotthrust.y);
738         memcpy(&(info->obj_phys_info.rotthrust.z), &(data[loc]), 4);    loc += 4;
739         info->obj_phys_info.rotthrust.z = (fix)swapint((int)info->obj_phys_info.rotthrust.z);
740
741         memcpy(&(info->obj_phys_info.turnroll), &(data[loc]), 2);       loc += 2;
742         info->obj_phys_info.turnroll = (fixang)swapshort((short)info->obj_phys_info.turnroll);
743
744         memcpy(&(info->obj_phys_info.flags), &(data[loc]), 2);  loc += 2;
745         info->obj_phys_info.flags = (ushort)swapshort(info->obj_phys_info.flags);
746
747         info->obj_render_type = data[loc];              loc++;
748         info->level_num = data[loc];                    loc++;  
749         memcpy( &(info->data_size), &(data[loc]), 2);   loc += 2;
750         info->data_size = swapshort(info->data_size);
751         memcpy(info->data, &(data[loc]), info->data_size);
752 #else
753         if (short_packet == 1) {
754                 loc = 0;
755                 info->type = data[loc]; loc++;
756                 info->playernum = data[loc]; loc++;
757                 info->obj_render_type = data[loc]; loc++;
758                 info->level_num = data[loc]; loc++;
759                 loc += 9+2*3+2+2*3; // skip shortpos structure
760                 info->data_size = *(ushort *)(data + loc); loc+=2;
761                 memcpy(info->data, &(data[loc]), info->data_size);
762         } else if (short_packet == 2) {
763                 ushort tmpus;
764
765                 loc = 0;
766                 info->type = data[loc];         loc++;
767                 info->numpackets = data[loc];   loc++;
768                 loc += 9+2*3+2+2*3; // skip shortpos structure
769                 tmpus = *(ushort *)(data + loc); loc+=2;
770                 info->data_size = tmpus & 0xfff;
771                 info->playernum = (tmpus >> 12) & 7;
772                 info->obj_render_type = tmpus >> 15;
773                 info->numpackets |= Players[info->playernum].n_packets_got & (~255);
774                 if (info->numpackets - Players[info->playernum].n_packets_got > 224)
775                         info->numpackets -= 256;
776                 else if (Players[info->playernum].n_packets_got - info->numpackets > 128)
777                         info->numpackets += 256;
778                 info->level_num = data[loc];    loc++;
779                 memcpy(info->data, &(data[loc]), info->data_size);
780         } else {
781                 loc = 0;
782                 info->type = data[loc];                 loc++;  loc += 3;               // skip three for pad byte
783                 memcpy(&(info->numpackets), &(data[loc]), 4);   loc += 4;
784                 info->numpackets = swapint(info->numpackets);
785
786                 memcpy(&(info->obj_pos.x), &(data[loc]), 4);    loc += 4;
787                 info->obj_pos.x = swapint((int)info->obj_pos.x);
788                 memcpy(&(info->obj_pos.y), &(data[loc]), 4);    loc += 4;
789                 info->obj_pos.y = swapint((int)info->obj_pos.y);
790                 memcpy(&(info->obj_pos.z), &(data[loc]), 4);    loc += 4;
791                 info->obj_pos.z = swapint((int)info->obj_pos.z);
792         
793                 memcpy(&(info->obj_orient.rvec.x), &(data[loc]), 4);    loc += 4;
794                 info->obj_orient.rvec.x = swapint((int)info->obj_orient.rvec.x);
795                 memcpy(&(info->obj_orient.rvec.y), &(data[loc]), 4);    loc += 4;
796                 info->obj_orient.rvec.y = swapint((int)info->obj_orient.rvec.y);
797                 memcpy(&(info->obj_orient.rvec.z), &(data[loc]), 4);    loc += 4;
798                 info->obj_orient.rvec.z = swapint((int)info->obj_orient.rvec.z);
799                 memcpy(&(info->obj_orient.uvec.x), &(data[loc]), 4);    loc += 4;
800                 info->obj_orient.uvec.x = swapint((int)info->obj_orient.uvec.x);
801                 memcpy(&(info->obj_orient.uvec.y), &(data[loc]), 4);    loc += 4;
802                 info->obj_orient.uvec.y = swapint((int)info->obj_orient.uvec.y);
803                 memcpy(&(info->obj_orient.uvec.z), &(data[loc]), 4);    loc += 4;
804                 info->obj_orient.uvec.z = swapint((int)info->obj_orient.uvec.z);
805                 memcpy(&(info->obj_orient.fvec.x), &(data[loc]), 4);    loc += 4;
806                 info->obj_orient.fvec.x = swapint((int)info->obj_orient.fvec.x);
807                 memcpy(&(info->obj_orient.fvec.y), &(data[loc]), 4);    loc += 4;
808                 info->obj_orient.fvec.y = swapint((int)info->obj_orient.fvec.y);
809                 memcpy(&(info->obj_orient.fvec.z), &(data[loc]), 4);    loc += 4;
810                 info->obj_orient.fvec.z = swapint((int)info->obj_orient.fvec.z);
811
812                 memcpy(&(info->phys_velocity.x), &(data[loc]), 4);      loc += 4;
813                 info->phys_velocity.x = swapint((int)info->phys_velocity.x);
814                 memcpy(&(info->phys_velocity.y), &(data[loc]), 4);      loc += 4;
815                 info->phys_velocity.y = swapint((int)info->phys_velocity.y);
816                 memcpy(&(info->phys_velocity.z), &(data[loc]), 4);      loc += 4;
817                 info->phys_velocity.z = swapint((int)info->phys_velocity.z);
818
819                 memcpy(&(info->phys_rotvel.x), &(data[loc]), 4);        loc += 4;
820                 info->phys_rotvel.x = swapint((int)info->phys_rotvel.x);
821                 memcpy(&(info->phys_rotvel.y), &(data[loc]), 4);        loc += 4;
822                 info->phys_rotvel.y = swapint((int)info->phys_rotvel.y);
823                 memcpy(&(info->phys_rotvel.z), &(data[loc]), 4);        loc += 4;
824                 info->phys_rotvel.z = swapint((int)info->phys_rotvel.z);
825         
826                 memcpy(&(info->obj_segnum), &(data[loc]), 2);   loc += 2;
827                 info->obj_segnum = swapshort(info->obj_segnum);
828                 memcpy(&(info->data_size), &(data[loc]), 2);    loc += 2;
829                 info->data_size = swapshort(info->data_size);
830         
831                 info->playernum = data[loc];            loc++;
832                 info->obj_render_type = data[loc];      loc++;
833                 info->level_num = data[loc];            loc++;
834                 memcpy(info->data, &(data[loc]), info->data_size);
835         }
836 #endif
837 }
838
839 void send_endlevel_packet(endlevel_info *info, ubyte *server, ubyte *node, ubyte *address)
840 {
841         int i, j;
842         int loc = 0;
843         ushort tmps;
844         
845         memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
846         out_buffer[loc] = info->type;                   loc++;
847         out_buffer[loc] = info->player_num;             loc++;
848         out_buffer[loc] = info->connected;              loc++;
849         for (i = 0; i < MAX_PLAYERS; i++) {
850                 for (j = 0; j < MAX_PLAYERS; j++) {
851                         tmps = swapshort(info->kill_matrix[i][j]);
852                         memcpy(&(out_buffer[loc]), &tmps, 2);
853                         loc += 2;
854                 }
855         }
856         tmps = swapshort(info->kills);
857         memcpy(&(out_buffer[loc]), &tmps, 2);  loc += 2;
858         tmps = swapshort(info->killed);
859         memcpy(&(out_buffer[loc]), &tmps, 2);  loc += 2;
860         out_buffer[loc] = info->seconds_left; loc++;    
861
862         ipx_send_packet_data( out_buffer, loc, server, node, address);
863 }
864
865 void receive_endlevel_packet(ubyte *data, endlevel_info *info)
866 {
867         int i, j;
868         int loc = 0;
869
870         info->type = data[loc];                                         loc++;
871         info->player_num = data[loc];                           loc++;
872         info->connected = data[loc];                            loc++;
873
874         for (i = 0; i < MAX_PLAYERS; i++) {
875                 for (j = 0; j < MAX_PLAYERS; j++) {
876                         memcpy(&(info->kill_matrix[i][j]), &(data[loc]), 2);    loc += 2;
877                         info->kill_matrix[i][j] = swapshort(info->kill_matrix[i][j]);
878                 }
879         }
880         memcpy(&(info->kills), &(data[loc]), 2);  loc += 2;
881         info->kills = swapshort(info->kills);
882         memcpy(&(info->killed), &(data[loc]), 2);  loc += 2;
883         info->killed = swapshort(info->killed);
884         info->seconds_left = data[loc];
885 }
886
887 void swap_object(object *obj)
888 {
889 // swap the short and int entries for this object
890         obj->signature                  = swapint(obj->signature);
891         obj->next                               = swapshort(obj->next);
892         obj->prev                               = swapshort(obj->prev);
893         obj->segnum                             = swapshort(obj->segnum);
894         obj->attached_obj               = swapshort(obj->attached_obj);
895         obj->pos.x                              = swapint(obj->pos.x);
896         obj->pos.y                              = swapint(obj->pos.y);
897         obj->pos.z                              = swapint(obj->pos.z);
898
899         obj->orient.rvec.x              = swapint(obj->orient.rvec.x);
900         obj->orient.rvec.y              = swapint(obj->orient.rvec.y);
901         obj->orient.rvec.z              = swapint(obj->orient.rvec.z);
902         obj->orient.fvec.x              = swapint(obj->orient.fvec.x);
903         obj->orient.fvec.y              = swapint(obj->orient.fvec.y);
904         obj->orient.fvec.z              = swapint(obj->orient.fvec.z);
905         obj->orient.uvec.x              = swapint(obj->orient.uvec.x);
906         obj->orient.uvec.y              = swapint(obj->orient.uvec.y);
907         obj->orient.uvec.z              = swapint(obj->orient.uvec.z);
908         
909         obj->size                               = swapint(obj->size);
910         obj->shields                    = swapint(obj->shields);
911         
912         obj->last_pos.x                 = swapint(obj->last_pos.x);
913         obj->last_pos.y                 = swapint(obj->last_pos.y);
914         obj->last_pos.z                 = swapint(obj->last_pos.z);
915         
916         obj->lifeleft                   = swapint(obj->lifeleft);
917         
918         switch (obj->movement_type) {
919         
920         case MT_PHYSICS:
921         
922                 obj->mtype.phys_info.velocity.x = swapint(obj->mtype.phys_info.velocity.x);
923                 obj->mtype.phys_info.velocity.y = swapint(obj->mtype.phys_info.velocity.y);
924                 obj->mtype.phys_info.velocity.z = swapint(obj->mtype.phys_info.velocity.z);
925         
926                 obj->mtype.phys_info.thrust.x   = swapint(obj->mtype.phys_info.thrust.x);
927                 obj->mtype.phys_info.thrust.y   = swapint(obj->mtype.phys_info.thrust.y);
928                 obj->mtype.phys_info.thrust.z   = swapint(obj->mtype.phys_info.thrust.z);
929         
930                 obj->mtype.phys_info.mass               = swapint(obj->mtype.phys_info.mass);
931                 obj->mtype.phys_info.drag               = swapint(obj->mtype.phys_info.drag);
932                 obj->mtype.phys_info.brakes             = swapint(obj->mtype.phys_info.brakes);
933         
934                 obj->mtype.phys_info.rotvel.x   = swapint(obj->mtype.phys_info.rotvel.x);
935                 obj->mtype.phys_info.rotvel.y   = swapint(obj->mtype.phys_info.rotvel.y);
936                 obj->mtype.phys_info.rotvel.z   = swapint(obj->mtype.phys_info.rotvel.z);
937         
938                 obj->mtype.phys_info.rotthrust.x = swapint(obj->mtype.phys_info.rotthrust.x);
939                 obj->mtype.phys_info.rotthrust.y = swapint(obj->mtype.phys_info.rotthrust.y);
940                 obj->mtype.phys_info.rotthrust.z = swapint(obj->mtype.phys_info.rotthrust.z);
941         
942                 obj->mtype.phys_info.turnroll   = swapint(obj->mtype.phys_info.turnroll);
943                 obj->mtype.phys_info.flags              = swapshort(obj->mtype.phys_info.flags);
944         
945                 break;
946         
947         case MT_SPINNING:
948                 
949                 obj->mtype.spin_rate.x = swapint(obj->mtype.spin_rate.x);
950                 obj->mtype.spin_rate.y = swapint(obj->mtype.spin_rate.y);
951                 obj->mtype.spin_rate.z = swapint(obj->mtype.spin_rate.z);
952                 break;
953         }
954         
955         switch (obj->control_type) {
956         
957         case CT_WEAPON:
958                 obj->ctype.laser_info.parent_type               = swapshort(obj->ctype.laser_info.parent_type);
959                 obj->ctype.laser_info.parent_num                = swapshort(obj->ctype.laser_info.parent_num);
960                 obj->ctype.laser_info.parent_signature  = swapshort(obj->ctype.laser_info.parent_signature);
961                 obj->ctype.laser_info.creation_time             = swapint(obj->ctype.laser_info.creation_time);
962                 obj->ctype.laser_info.last_hitobj               = swapint(obj->ctype.laser_info.last_hitobj);
963                 obj->ctype.laser_info.multiplier                = swapint(obj->ctype.laser_info.multiplier);
964                 break;
965         
966         case CT_EXPLOSION:
967                 obj->ctype.expl_info.spawn_time         = swapint(obj->ctype.expl_info.spawn_time);
968                 obj->ctype.expl_info.delete_time        = swapint(obj->ctype.expl_info.delete_time);
969                 obj->ctype.expl_info.delete_objnum      = swapshort(obj->ctype.expl_info.delete_objnum);
970                 obj->ctype.expl_info.attach_parent      = swapshort(obj->ctype.expl_info.attach_parent);
971                 obj->ctype.expl_info.prev_attach        = swapshort(obj->ctype.expl_info.prev_attach);
972                 obj->ctype.expl_info.next_attach        = swapshort(obj->ctype.expl_info.next_attach);
973                 break;
974         
975         case CT_AI:
976                 obj->ctype.ai_info.hide_segment                 = swapshort(obj->ctype.ai_info.hide_segment);
977                 obj->ctype.ai_info.hide_index                   = swapshort(obj->ctype.ai_info.hide_index);
978                 obj->ctype.ai_info.path_length                  = swapshort(obj->ctype.ai_info.path_length);
979                 obj->ctype.ai_info.cur_path_index               = swapshort(obj->ctype.ai_info.cur_path_index);
980 //              obj->ctype.ai_info.follow_path_start_seg        = swapshort(obj->ctype.ai_info.follow_path_start_seg);
981 //              obj->ctype.ai_info.follow_path_end_seg          = swapshort(obj->ctype.ai_info.follow_path_end_seg);
982                 obj->ctype.ai_info.danger_laser_signature = swapint(obj->ctype.ai_info.danger_laser_signature);
983                 obj->ctype.ai_info.danger_laser_num             = swapshort(obj->ctype.ai_info.danger_laser_num);
984                 break;
985         
986         case CT_LIGHT:
987                 obj->ctype.light_info.intensity = swapint(obj->ctype.light_info.intensity);
988                 break;
989         
990         case CT_POWERUP:
991                 obj->ctype.powerup_info.count = swapint(obj->ctype.powerup_info.count);
992                 if (obj->id == POW_VULCAN_WEAPON)
993                         obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
994                 break;
995         
996         }
997         
998         switch (obj->render_type) {
999         
1000         case RT_MORPH:
1001         case RT_POLYOBJ: {
1002                 int i;
1003         
1004                 obj->rtype.pobj_info.model_num          = swapint(obj->rtype.pobj_info.model_num);
1005         
1006                 for (i=0;i<MAX_SUBMODELS;i++) {
1007                         obj->rtype.pobj_info.anim_angles[i].p = swapint(obj->rtype.pobj_info.anim_angles[i].p);
1008                         obj->rtype.pobj_info.anim_angles[i].b = swapint(obj->rtype.pobj_info.anim_angles[i].b);
1009                         obj->rtype.pobj_info.anim_angles[i].h = swapint(obj->rtype.pobj_info.anim_angles[i].h);
1010                 }
1011         
1012                 obj->rtype.pobj_info.subobj_flags       = swapint(obj->rtype.pobj_info.subobj_flags);
1013                 obj->rtype.pobj_info.tmap_override      = swapint(obj->rtype.pobj_info.tmap_override);
1014                 obj->rtype.pobj_info.alt_textures       = swapint(obj->rtype.pobj_info.alt_textures);
1015                 break;
1016         }
1017         
1018         case RT_WEAPON_VCLIP:
1019         case RT_HOSTAGE:
1020         case RT_POWERUP:
1021         case RT_FIREBALL:
1022                 obj->rtype.vclip_info.vclip_num = swapint(obj->rtype.vclip_info.vclip_num);
1023                 obj->rtype.vclip_info.frametime = swapint(obj->rtype.vclip_info.frametime);
1024                 break;
1025         
1026         case RT_LASER:
1027                 break;
1028         
1029         }
1030 //  END OF SWAPPING OBJECT STRUCTURE
1031
1032 }