Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enum classes for BitStream #1737

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ void CClientGame::DoPulses()
m_bWaitingForLocalConnect = false;

// Assume local server has the same bitstream version
g_pNet->SetServerBitStreamVersion(MTA_DM_BITSTREAM_VERSION);
g_pNet->SetServerBitStreamVersion(static_cast<unsigned short>(MTA_DM_BITSTREAM_VERSION));

// Run the game normally.
StartGame(m_strLocalNick, m_Server.GetPassword().c_str(), m_ServerType);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/net/CNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CNet

virtual void SetServerBitStreamVersion(unsigned short usServerBitStreamVersion) = 0;
virtual unsigned short GetServerBitStreamVersion() = 0;
bool CanServerBitStream(eBitStreamVersion query) { return static_cast<eBitStreamVersion>(GetServerBitStreamVersion()) >= query; }

virtual void GetStatus(char* szStatus, size_t maxLength) = 0;
virtual unsigned short GetNetRev() = 0;
Expand Down
4 changes: 3 additions & 1 deletion Client/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _CLIENT_NET_MODULE_VERSION 0x0AB // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x06F // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

// (0x000 - 0xfff) Update bitstream.h when net messages change (post-release). (Changing will also require additional backward compatibility code).
#define MTA_DM_BITSTREAM_VERSION eBitStreamVersion::Latest

// To avoid user confusion, make sure the ASE version matches only if communication is possible
#if defined(MTA_DM_CONNECT_TO_PUBLIC)
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class CPlayer : public CPed, public CClient
void SetMTAVersion(unsigned short usMTAVersion) { m_usMTAVersion = usMTAVersion; };
unsigned short GetBitStreamVersion() { return m_usBitStreamVersion; };
void SetBitStreamVersion(unsigned short usBitStreamVersion) { m_usBitStreamVersion = usBitStreamVersion; };
bool CanBitStream(eBitStreamVersion query) { return static_cast<eBitStreamVersion>(m_usBitStreamVersion) >= query; }
void SetPlayerVersion(const CMtaVersion& strPlayerVersion);
const CMtaVersion& GetPlayerVersion() { return m_strPlayerVersion; };
bool ShouldIgnoreMinClientVersionChecks();
Expand Down
4 changes: 3 additions & 1 deletion Server/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
#define _NETCODE_VERSION_BRANCH_ID 0x4 // Use 0x1 - 0xF to indicate an incompatible branch is being used (0x0 is reserved, 0x4 is trunk)
#define _SERVER_NET_MODULE_VERSION 0x0AB // (0x000 - 0xfff) Lvl9 wizards only
#define _NETCODE_VERSION 0x1DA // (0x000 - 0xfff) Increment when net messages change (pre-release)
#define MTA_DM_BITSTREAM_VERSION 0x06F // (0x000 - 0xfff) Increment when net messages change (post-release). (Changing will also require additional backward compatibility code).

// (0x000 - 0xfff) Update bitstream.h when net messages change (post-release). (Changing will also require additional backward compatibility code).
#define MTA_DM_BITSTREAM_VERSION eBitStreamVersion::Latest

// To avoid user confusion, make sure the ASE version matches only if communication is possible
#if defined(MTA_DM_CONNECT_FROM_PUBLIC)
Expand Down
28 changes: 27 additions & 1 deletion Shared/sdk/net/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,28 @@ class NetBitStreamInterfaceNoVersion : public CRefCountable
}
};

// eBitStreamVersion allows us to track what BitStream version is being used without placing magic numbers everywhere.
// It also helps us know what code branches can be removed when we increment a major version of MTA.
// Make sure you only add new items to the end of the list, above the "Latest" entry.
enum class eBitStreamVersion : unsigned short
{
Unk = 0x06F,

//
// 1.5.8 RELEASED - 2020-10-11
//

// This allows us to automatically increment the BitStreamVersion when things are added to this enum.
// Make sure you only add things above this comment.
Latest,
};

// This is a temporary check during the introduction of eBitStreamVersion.
// We only check it server-side because static_assert is not available for all client projects.
#ifndef MTA_CLIENT
static_assert(static_cast<unsigned short>(eBitStreamVersion::Latest) == 0x070);
#endif

class NetBitStreamInterface : public NetBitStreamInterfaceNoVersion
{
NetBitStreamInterface(const NetBitStreamInterface&);
Expand All @@ -358,8 +380,12 @@ class NetBitStreamInterface : public NetBitStreamInterfaceNoVersion
virtual ~NetBitStreamInterface() { DEBUG_DESTROY_COUNT("NetBitStreamInterface"); }

public:
virtual operator NetBitStreamInterface&() { return *this; }
virtual operator NetBitStreamInterface&() { return *this; }
virtual unsigned short Version() const = 0;

bool Can(eBitStreamVersion query) {
return static_cast<eBitStreamVersion>(Version()) >= query;
}
};

// Interface for all sync structures
Expand Down