From 14da945d5d51f59706dc9a5d6552bb9baab34c7c Mon Sep 17 00:00:00 2001 From: meep-eep Date: Wed, 6 Dec 2006 03:56:34 +0000 Subject: [PATCH] Test minimum UQM version in Netplay. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2572 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/src/sc2code/netplay/netplay.h | 6 +++- sc2/src/sc2code/netplay/packethandlers.c | 38 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index be6cd969d..3879208b3 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.6: +- Validate UQM version of either side of a Netplay game - SvdB - Better abort and disconnect handling for Netplay - SvdB - Menu sounds in Setup track rest of game (#922), from Nic - Michael - Shifted the Mouse Error to a Popup Window, moved the message to diff --git a/sc2/src/sc2code/netplay/netplay.h b/sc2/src/sc2code/netplay/netplay.h index c7056ab69..4e2816bed 100644 --- a/sc2/src/sc2code/netplay/netplay.h +++ b/sc2/src/sc2code/netplay/netplay.h @@ -25,7 +25,11 @@ #define NETPLAY_FULL 2 #define NETPLAY_PROTOCOL_VERSION_MAJOR 0 -#define NETPLAY_PROTOCOL_VERSION_MINOR 2 +#define NETPLAY_PROTOCOL_VERSION_MINOR 3 + +#define NETPLAY_MIN_UQM_VERSION_MAJOR 0 +#define NETPLAY_MIN_UQM_VERSION_MINOR 5 +#define NETPLAY_MIN_UQM_VERSION_PATCH 4 #define NETPLAY_DEBUG /* Extra debugging for netplay */ diff --git a/sc2/src/sc2code/netplay/packethandlers.c b/sc2/src/sc2code/netplay/packethandlers.c index 5dbe19c0c..857baf8e9 100644 --- a/sc2/src/sc2code/netplay/packethandlers.c +++ b/sc2/src/sc2code/netplay/packethandlers.c @@ -57,6 +57,27 @@ testNetState(bool condition, PacketType type) { return condition; } +static int +versionCompare(int major1, int minor1, int patch1, + int major2, int minor2, int patch2) { + if (major1 < major2) + return -1; + if (major1 > major2) + return 1; + + if (minor1 < minor2) + return -1; + if (minor1 > minor2) + return 1; + + if (patch1 < patch2) + return -1; + if (patch1 > patch2) + return 1; + + return 0; +} + int PacketHandler_Init(NetConnection *conn, const Packet_Init *packet) { if (conn->stateFlags.reset.localReset) @@ -72,12 +93,29 @@ PacketHandler_Init(NetConnection *conn, const Packet_Init *packet) { if (packet->protoVersion.major != NETPLAY_PROTOCOL_VERSION_MAJOR || packet->protoVersion.minor != NETPLAY_PROTOCOL_VERSION_MINOR) { + sendAbort (conn, AbortReason_versionMismatch); + abortFeedback(conn->player, AbortReason_versionMismatch); log_add(log_Error, "Protocol version %d.%d not supported.\n", packet->protoVersion.major, packet->protoVersion.minor); errno = ENOSYS; return -1; } + if (versionCompare(packet->uqmVersion.major, packet->uqmVersion.minor, + packet->uqmVersion.patch, NETPLAY_MIN_UQM_VERSION_MAJOR, + NETPLAY_MIN_UQM_VERSION_MINOR, NETPLAY_MIN_UQM_VERSION_PATCH) + < 0) { + sendAbort (conn, AbortReason_versionMismatch); + abortFeedback(conn->player, AbortReason_versionMismatch); + log_add(log_Error, "Remote side is running a version of UQM that " + "is too old (%d.%d.%d; %d.%d.%d is required).\n", + packet->uqmVersion.major, packet->uqmVersion.minor, + packet->uqmVersion.patch, NETPLAY_MIN_UQM_VERSION_MAJOR, + NETPLAY_MIN_UQM_VERSION_MINOR, NETPLAY_MIN_UQM_VERSION_PATCH); + errno = ENOSYS; + return -1; + } + Netplay_remoteReady(conn); return 0;