Add compatibility with previous broadcast versions.

This commit is contained in:
Bartosz Taudul 2022-10-26 23:21:17 +02:00
parent 544caef850
commit 86f88714ae
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 92 additions and 10 deletions

View File

@ -293,18 +293,71 @@ static void DrawContents()
auto msg = broadcastListen->Read( len, addr, 0 );
if( !msg ) break;
if( len > sizeof( tracy::BroadcastMessage ) ) continue;
uint16_t broadcastVersion;
memcpy( &broadcastVersion, msg, sizeof( uint16_t ) );
if( broadcastVersion <= tracy::BroadcastVersion )
{
uint32_t protoVer;
char procname[tracy::WelcomeMessageProgramNameSize];
int32_t activeTime;
uint16_t listenPort;
uint64_t pid;
switch( broadcastVersion )
{
case 3:
{
tracy::BroadcastMessage bm;
memcpy( &bm, msg, len );
if( bm.broadcastVersion == tracy::BroadcastVersion )
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = bm.listenPort;
pid = bm.pid;
break;
}
case 2:
{
const uint32_t protoVer = bm.protocolVersion;
const auto procname = bm.programName;
const auto activeTime = bm.activeTime;
const auto listenPort = bm.listenPort;
const auto pid = bm.pid;
auto address = addr.GetText();
if( len > sizeof( tracy::BroadcastMessage_v2 ) ) continue;
tracy::BroadcastMessage_v2 bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = bm.listenPort;
pid = 0;
break;
}
case 1:
{
if( len > sizeof( tracy::BroadcastMessage_v1 ) ) continue;
tracy::BroadcastMessage_v1 bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = bm.listenPort;
pid = 0;
break;
}
case 0:
{
if( len > sizeof( tracy::BroadcastMessage_v0 ) ) continue;
tracy::BroadcastMessage_v0 bm;
memcpy( &bm, msg, len );
protoVer = bm.protocolVersion;
strcpy( procname, bm.programName );
activeTime = bm.activeTime;
listenPort = 8086;
pid = 0;
break;
}
default:
assert( false );
break;
}
auto address = addr.GetText();
const auto ipNumerical = addr.GetNumber();
const auto clientId = uint64_t( ipNumerical ) | ( uint64_t( listenPort ) << 32 );
auto it = clients.find( clientId );

View File

@ -131,7 +131,36 @@ struct BroadcastMessage
char programName[WelcomeMessageProgramNameSize];
};
struct BroadcastMessage_v2
{
uint16_t broadcastVersion;
uint16_t listenPort;
uint32_t protocolVersion;
int32_t activeTime;
char programName[WelcomeMessageProgramNameSize];
};
struct BroadcastMessage_v1
{
uint32_t broadcastVersion;
uint32_t protocolVersion;
uint32_t listenPort;
uint32_t activeTime;
char programName[WelcomeMessageProgramNameSize];
};
struct BroadcastMessage_v0
{
uint32_t broadcastVersion;
uint32_t protocolVersion;
uint32_t activeTime;
char programName[WelcomeMessageProgramNameSize];
};
enum { BroadcastMessageSize = sizeof( BroadcastMessage ) };
enum { BroadcastMessageSize_v2 = sizeof( BroadcastMessage_v2 ) };
enum { BroadcastMessageSize_v1 = sizeof( BroadcastMessage_v1 ) };
enum { BroadcastMessageSize_v0 = sizeof( BroadcastMessage_v0 ) };
#pragma pack( pop )