From 82f805b197d8988e12484cca9b424a17d81cfcf4 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 2 Aug 2003 07:32:59 +0000 Subject: [PATCH] bigendian networking fixes --- ChangeLog | 3 +++ arch/linux/linuxnet.c | 9 ++++++--- main/multi.c | 44 +++++++++++++++++++++++-------------------- main/multibot.c | 27 +++++++++++--------------- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index dea50454..83f470bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2003-08-02 Martin Schaffner + * arch/linux/linuxnet.c, main/multi.c, main/multibot.c: bigendian + networking fixes + * cfile/cfile.c: revert to always using custom fgets * main/endlevel.c, main/mission.c: handle missing exit sequence diff --git a/arch/linux/linuxnet.c b/arch/linux/linuxnet.c index 0e84f527..e1a556ec 100644 --- a/arch/linux/linuxnet.c +++ b/arch/linux/linuxnet.c @@ -1,4 +1,4 @@ -/* $Id: linuxnet.c,v 1.8 2003-03-19 23:20:09 btb Exp $ */ +/* $Id: linuxnet.c,v 1.9 2003-08-02 07:32:59 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -40,6 +40,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. //added 05/17/99 Matt Mueller - needed to redefine FD_* so that no asm is used //#include "checker.h" //end addition -MM +#include "byteswap.h" + #define MAX_IPX_DATA 576 int ipx_fd; @@ -161,7 +163,7 @@ int ipx_get_packet_data( ubyte * data ) sizeof(buf), &rd)) > 4) { if (!memcmp(rd.src_network, ipx_MyAddress, 10)) continue; /* don't get own pkts */ -//--killed-- pkt_num = *(uint *)buf; +//--killed-- pkt_num = INTEL_INT(*(uint *)buf); //--killed-- if (pkt_num >= best_id) { memcpy(data, buf + 4, size - 4); return size-4; @@ -183,7 +185,8 @@ void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *ad memcpy(ipx_header.Destination.Node, immediate_address, 6); *(u_short *)ipx_header.Destination.Socket = htons(ipx_socket_data.socket); ipx_header.PacketType = 4; /* Packet Exchange */ - *(uint *)buf = ipx_packetnum++; + *(uint *)buf = INTEL_INT(ipx_packetnum); + ipx_packetnum++; //ipx_packettotal+=datasize+4; //if (f2i(Players[Player_num].time_level) && (f2i(Players[Player_num].time_level)%10!=ipx_lastspeed)) //{ diff --git a/main/multi.c b/main/multi.c index 05ecc593..df20ac3d 100644 --- a/main/multi.c +++ b/main/multi.c @@ -1,4 +1,4 @@ -/* $Id: multi.c,v 1.10 2003-06-16 07:11:40 btb Exp $ */ +/* $Id: multi.c,v 1.11 2003-08-02 07:32:59 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -1644,7 +1644,7 @@ multi_do_message(char *buf) void multi_do_position(char *buf) { -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN shortpos sp; #endif @@ -1662,7 +1662,7 @@ multi_do_position(char *buf) } -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN extract_shortpos(&Objects[Players[pnum].objnum], (shortpos *)(buf+1),0); #else memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + 1), 9); @@ -2100,7 +2100,7 @@ multi_do_controlcen_fire(char *buf) int count = 1; memcpy(&to_target, buf+count, 12); count += 12; -#ifdef MACINTOSH // swap the vector to_target +#ifdef WORDS_BIGENDIAN // swap the vector to_target to_target.x = (fix)INTEL_INT((int)to_target.x); to_target.y = (fix)INTEL_INT((int)to_target.y); to_target.z = (fix)INTEL_INT((int)to_target.z); @@ -2136,7 +2136,7 @@ multi_do_create_powerup(char *buf) } new_pos = *(vms_vector *)(buf+count); count+=sizeof(vms_vector); -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN new_pos.x = (fix)SWAPINT((int)new_pos.x); new_pos.y = (fix)SWAPINT((int)new_pos.y); new_pos.z = (fix)SWAPINT((int)new_pos.z); @@ -2851,7 +2851,7 @@ multi_send_reappear() void multi_send_position(int objnum) { -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN shortpos sp; #endif int count=0; @@ -2861,7 +2861,7 @@ multi_send_position(int objnum) } multibuf[count++] = (char)MULTI_POSITION; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN create_shortpos((shortpos *)(multibuf+count), Objects+objnum,0); count += sizeof(shortpos); #else @@ -3050,13 +3050,13 @@ multi_send_create_explosion(int pnum) void multi_send_controlcen_fire(vms_vector *to_goal, int best_gun_num, int objnum) { -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN vms_vector swapped_vec; #endif int count = 0; multibuf[count] = MULTI_CONTROLCEN_FIRE; count += 1; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN memcpy(multibuf+count, to_goal, 12); count += 12; #else swapped_vec.x = (fix)INTEL_INT( (int)to_goal->x ); @@ -3078,7 +3078,7 @@ multi_send_create_powerup(int powerup_type, int segnum, int objnum, vms_vector * // placement of used powerups like missiles and cloaking // powerups. -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN vms_vector swapped_vec; #endif int count = 0; @@ -3091,7 +3091,7 @@ multi_send_create_powerup(int powerup_type, int segnum, int objnum, vms_vector * multibuf[count] = powerup_type; count += 1; *(short *)(multibuf+count) = INTEL_SHORT( (short)segnum ); count += 2; *(short *)(multibuf+count) = INTEL_SHORT( (short)objnum ); count += 2; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN *(vms_vector *)(multibuf+count) = *pos; count += sizeof(vms_vector); #else swapped_vec.x = (fix)INTEL_INT( (int)pos->x ); @@ -3907,7 +3907,7 @@ void multi_do_drop_weapon (char *buf) void multi_send_guided_info (object *miss,char done) { -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN shortpos sp; #endif int count=0; @@ -3918,7 +3918,7 @@ void multi_send_guided_info (object *miss,char done) multibuf[count++]=(char)Player_num; multibuf[count++]=done; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN create_shortpos((shortpos *)(multibuf+count), miss,0); count+=sizeof(shortpos); #else @@ -3937,7 +3937,7 @@ void multi_do_guided (char *buf) char pnum=buf[1]; int count=3; static int fun=200; -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN shortpos sp; #endif @@ -3969,7 +3969,7 @@ void multi_do_guided (char *buf) return; } -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN extract_shortpos(Guided_missile[(int)pnum], (shortpos *)(buf+count),0); #else memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + count), 9); @@ -4326,7 +4326,9 @@ void multi_do_powerup_update (char *buf) extern active_door ActiveDoors[]; extern int Num_open_doors; // Number of open doors -void multi_send_active_door (char i) + +#if 0 // never used... +void multi_send_active_door (int i) { int count; @@ -4334,13 +4336,13 @@ void multi_send_active_door (char i) multibuf[1]=i; multibuf[2]=Num_open_doors; count = 3; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN memcpy ((char *)(&multibuf[3]),&ActiveDoors[(int)i],sizeof(struct active_door)); count += sizeof(active_door); #else *(int *)(multibuf + count) = INTEL_INT(ActiveDoors[i].n_parts); count += 4; *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].front_wallnum[0]); count += 2; - *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].front_wallnum[1]) count += 2; + *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].front_wallnum[1]); count += 2; *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].back_wallnum[0]); count += 2; *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].back_wallnum[1]); count += 2; *(int *)(multibuf + count) = INTEL_INT(ActiveDoors[i].time); count += 4; @@ -4348,6 +4350,8 @@ void multi_send_active_door (char i) //multi_send_data (multibuf,sizeof(struct active_door)+3,1); multi_send_data (multibuf,count,1); } +#endif + void multi_do_active_door (char *buf) { @@ -4356,7 +4360,7 @@ void multi_do_active_door (char *buf) Num_open_doors=buf[2]; count = 3; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN memcpy (&ActiveDoors[(int)i],buf+count,sizeof(struct active_door)); #else ActiveDoors[i].n_parts = INTEL_INT( *(int *)(buf+count) ); count += 4; @@ -4375,7 +4379,7 @@ void multi_send_sound_function (char whichfunc,char sound) multibuf[0]=MULTI_SOUND_FUNCTION; count++; multibuf[1]=Player_num; count++; multibuf[2]=whichfunc; count++; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN *(uint *)(multibuf+count)=sound; count++; #else multibuf[3] = sound; count++; // this would probably work on the PC as well. Jason? diff --git a/main/multibot.c b/main/multibot.c index 5c751b67..a952e992 100644 --- a/main/multibot.c +++ b/main/multibot.c @@ -1,3 +1,4 @@ +/* $Id: multibot.c,v 1.3 2003-08-02 07:32:59 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -7,19 +8,13 @@ IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. +AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* - * $Source: /cvs/cvsroot/d2x/main/multibot.c,v $ - * $Revision: 1.2 $ - * $Author: bradleyb $ - * $Date: 2001-10-23 21:53:19 $ * - * FIXME: put description here - * - * $Log: not supported by cvs2svn $ + * Multiplayer robot code * */ @@ -457,7 +452,7 @@ multi_send_robot_position_sub(int objnum) { int loc = 0; short s; -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN shortpos sp; #endif @@ -469,7 +464,7 @@ multi_send_robot_position_sub(int objnum) *(short *)(multibuf+loc) = INTEL_SHORT(s); loc += 3; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN create_shortpos((shortpos *)(multibuf+loc), Objects+objnum,0); loc += sizeof(shortpos); #else create_shortpos(&sp, Objects+objnum, 1); @@ -522,7 +517,7 @@ multi_send_robot_fire(int objnum, int gun_num, vms_vector *fire) // Send robot fire event int loc = 0; short s; -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN vms_vector swapped_vec; #endif @@ -532,7 +527,7 @@ multi_send_robot_fire(int objnum, int gun_num, vms_vector *fire) *(short *)(multibuf+loc) = INTEL_SHORT(s); loc += 3; multibuf[loc] = gun_num; loc += 1; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN *(vms_vector *)(multibuf+loc) = *fire; loc += sizeof(vms_vector); // 12 // -------------------------- // Total = 18 @@ -650,7 +645,7 @@ multi_send_create_robot_powerups(object *del_obj) int loc = 0; int i; -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN vms_vector swapped_vec; #endif @@ -660,7 +655,7 @@ multi_send_create_robot_powerups(object *del_obj) multibuf[loc] = del_obj->contains_type; loc += 1; multibuf[loc] = del_obj->contains_id; loc += 1; *(short *)(multibuf+loc) = INTEL_SHORT(del_obj->segnum); loc += 2; -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN *(vms_vector *)(multibuf+loc) = del_obj->pos; loc += 12; #else swapped_vec.x = (fix)INTEL_INT((int)del_obj->pos.x); @@ -776,7 +771,7 @@ multi_do_robot_position(char *buf) short botnum; char pnum; int loc = 1; -#ifdef MACINTOSH +#ifdef WORDS_BIGENDIAN shortpos sp; #endif @@ -819,7 +814,7 @@ multi_do_robot_position(char *buf) set_thrust_from_velocity(&Objects[botnum]); // Try to smooth out movement // Objects[botnum].phys_info.drag = Robot_info[Objects[botnum].id].drag >> 4; // Set drag to low -#ifndef MACINTOSH +#ifndef WORDS_BIGENDIAN extract_shortpos(&Objects[botnum], (shortpos *)(buf+loc), 0); #else memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + loc), 9); loc += 9; -- 2.39.2