Skip to content

Commit

Permalink
Add compatibility version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
dotSILENT committed Jan 20, 2019
1 parent 97f5314 commit 2774eef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/Actions.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/Actions.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#include "raknet/BitStream.h"
#include "sampgdk/sampgdk.h"
#include "PacketEnum.h"
#include <cstdint>

// 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,
Expand Down
8 changes: 8 additions & 0 deletions src/chandlingsvr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2774eef

Please sign in to comment.