From 2774eef72e6d9adbeb7ed4001cb8db9539a76bc1 Mon Sep 17 00:00:00 2001 From: dotSILENT Date: Sun, 20 Jan 2019 20:49:18 +0100 Subject: [PATCH] Add compatibility version checking --- src/Actions.cpp | 19 +++++++++++++++++-- src/Actions.h | 3 ++- src/chandlingsvr.h | 8 ++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Actions.cpp b/src/Actions.cpp index c84df37..4221f47 100644 --- a/src/Actions.cpp +++ b/src/Actions.cpp @@ -1,6 +1,8 @@ #include "Actions.h" +#include "sampgdk/sampgdk.h" #include "CPlayer.h" #include "HandlingManager.h" +#include "chandlingsvr.h" bool Actions::Process(CHandlingAction id, RakNet::BitStream *bs, int playerid) { @@ -9,8 +11,21 @@ bool Actions::Process(CHandlingAction id, RakNet::BitStream *bs, int playerid) case ACTION_INIT: if (IS_VALID_PLAYERID(playerid)) { - sampgdk::logprintf("[chandling] Player %d reports having chandling plugin", playerid); - gPlayers[playerid].setHasCHandling(); + uint32_t compat_ver; + bs->Read(compat_ver); + + CHandlingActionPacket pkt(ACTION_INIT_RESPONSE); + pkt.data.Write((uint32_t)CHANDLING_COMPAT_VERSION); + + if (compat_ver >= CHANDLING_COMPAT_VERSION) + { + pkt.data.Write(true); + gPlayers[playerid].setHasCHandling(); + sampgdk::logprintf("[chandling] Player %d reports having chandling plugin", playerid); + } + else pkt.data.Write(false); + + pRakServer->Send(&pkt.data, HIGH_PRIORITY, RELIABLE_ORDERED, 0, pRakServer->GetPlayerIDFromIndex(playerid), false); } return true; diff --git a/src/Actions.h b/src/Actions.h index 0db0f0b..484f712 100644 --- a/src/Actions.h +++ b/src/Actions.h @@ -1,13 +1,14 @@ #pragma once #include "raknet/BitStream.h" -#include "sampgdk/sampgdk.h" #include "PacketEnum.h" +#include // action identifier is sent as single byte enum CHandlingAction : unsigned char { ACTION_INIT = 10, // This is the only packet that is sent by the player, to indicate that we can speak to him + ACTION_INIT_RESPONSE, ACTION_RESET_MODEL = 15, ACTION_RESET_VEHICLE, diff --git a/src/chandlingsvr.h b/src/chandlingsvr.h index c1160eb..7104c8f 100644 --- a/src/chandlingsvr.h +++ b/src/chandlingsvr.h @@ -2,6 +2,14 @@ #define CHANDLING_VERSION "v1.0-dev" +/* + * The compaatibility version number decides if the client supports our CHandling version or not + * Clients with smaller compat version won't be able to use CHandling + * + * Increase this number only if doing things that break the compatibility with older client +*/ +#define CHANDLING_COMPAT_VERSION 0x1001D + #define MAX_VEHICLE_MODELS (212) #ifndef MAX_VEHICLES #define MAX_VEHICLES (2000)