From 8991604df65480888cf6a97f394c3c35277e2dc5 Mon Sep 17 00:00:00 2001 From: ehouse Date: Fri, 8 Oct 2004 23:54:57 +0000 Subject: [PATCH] deal with older stream version --- common/comms.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/common/comms.c b/common/comms.c index 1c3130d82..5b02744d3 100644 --- a/common/comms.c +++ b/common/comms.c @@ -24,6 +24,7 @@ #include "comms.h" #include "util.h" +#include "game.h" #include "xwstream.h" #include "memstream.h" @@ -51,6 +52,8 @@ typedef struct AddressRecord { XP_PlayerAddr channelNo; } AddressRecord; +#define ADDRESSRECORD_SIZE_68K 20 + struct CommsCtxt { XW_UtilCtxt* util; @@ -206,12 +209,22 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util, XP_MEMSET( rec, 0, sizeof(*rec) ); addr = &rec->addr; - addr->conType = stream_getU8( stream ); - if ( addr->conType == COMMS_CONN_IP ) { - addr->u.ip.ipAddr = stream_getU32( stream ); - addr->u.ip.port = stream_getU16( stream ); + + if ( stream_getVersion(stream) <= STREAM_VERS_405 ) { + unsigned char trash[ADDRESSRECORD_SIZE_68K]; + /* Older versions used sizeof and wrote out the whole struct using + stream_putBytes. Size under 68K was 20. */ + /* now discard the bytes */ + stream_getBytes( stream, trash, ADDRESSRECORD_SIZE_68K ); + addr->conType = COMMS_CONN_IR; + } else { + addr->conType = stream_getU8( stream ); + if ( addr->conType == COMMS_CONN_IP ) { + addr->u.ip.ipAddr = stream_getU32( stream ); + addr->u.ip.port = stream_getU16( stream ); + } } - + rec->nextMsgID = stream_getU16( stream ); rec->lastMsgReceived = stream_getU16( stream ); rec->channelNo = stream_getU16( stream );