Skip to content

Commit 640c46f

Browse files
committed
Replace with server config setting and setElementData parameter
1 parent 06e4c82 commit 640c46f

14 files changed

+51
-54
lines changed

Server/mods/deathmatch/local.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@
264264
Values: 0 - Off, 1 - Enabled. Default - 1 -->
265265
<database_credentials_protection>1</database_credentials_protection>
266266

267+
<!-- Enables extra protection for element data.
268+
When this option is enabled, the server ignores element data sync packets from the client,
269+
except for allowed keys.
270+
Values: 0 - Off, 1 - Enabled. Default - 0 -->
271+
<elementdata_whitelisted>0</elementdata_whitelisted>
272+
267273
<!-- Specifies the module(s) which are loaded with the server. To load several modules, add more <module>
268274
parameter(s). Optional parameter. -->
269275
<!-- <module src="sample_win32.dll"/> -->

Server/mods/deathmatch/logic/CCustomData.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,6 @@ bool CCustomData::Delete(const char* szName)
121121
return false;
122122
}
123123

124-
bool CCustomData::IsClientChangesAllowed(const char* szName) const
125-
{
126-
SCustomData* pData = Get(szName);
127-
if (!pData || pData->clientChangesMode == ECustomDataClientTrust::UNSET)
128-
return IsClientChangesAllowed();
129-
130-
return pData->clientChangesMode == ECustomDataClientTrust::ALLOW;
131-
}
132-
133124
void CCustomData::SetClientChangesMode(const char* szName, ECustomDataClientTrust mode)
134125
{
135126
SCustomData& pData = m_Data[szName];

Server/mods/deathmatch/logic/CCustomData.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ class CCustomData
5050

5151
bool Delete(const char* szName);
5252

53-
bool IsClientChangesAllowed(const char* szName) const;
5453
void SetClientChangesMode(const char* szName, ECustomDataClientTrust mode);
5554

56-
bool IsClientChangesAllowed() const noexcept { return m_clientChangesAllowed; };
57-
void SetClientChangesAllowed(bool enabled) noexcept { m_clientChangesAllowed = enabled; };
58-
5955
unsigned short CountOnlySynchronized();
6056

6157
CXMLNode* OutputToXML(CXMLNode* pNode);
@@ -72,5 +68,4 @@ class CCustomData
7268

7369
std::map<std::string, SCustomData> m_Data;
7470
std::map<std::string, SCustomData> m_SyncedData;
75-
bool m_clientChangesAllowed{true};
7671
};

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,7 @@ void CGame::Packet_CustomData(CCustomDataPacket& Packet)
26572657

26582658
pElement->GetCustomData(szName, false, &lastSyncType, &clientChangesMode);
26592659

2660-
const bool changesAllowed = clientChangesMode == ECustomDataClientTrust::UNSET ? pElement->GetCustomDataManager().IsClientChangesAllowed()
2660+
const bool changesAllowed = clientChangesMode == ECustomDataClientTrust::UNSET ? !m_pMainConfig->IsElementDataWhitelisted()
26612661
: clientChangesMode == ECustomDataClientTrust::ALLOW;
26622662
if (!changesAllowed)
26632663
{

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ CMainConfig::CMainConfig(CConsole* pConsole) : CXMLConfig(NULL)
7979
m_iBackupInterval = 3;
8080
m_iBackupAmount = 5;
8181
m_bSyncMapElementData = true;
82+
m_elementDataWhitelisted = false;
8283
}
8384

8485
bool CMainConfig::Load()
@@ -526,6 +527,8 @@ bool CMainConfig::Load()
526527
g_TickRateSettings.iLightSync = Clamp(200, g_TickRateSettings.iLightSync, 4000);
527528
}
528529

530+
GetBoolean(m_pRootNode, "elementdata_whitelisted", m_elementDataWhitelisted);
531+
529532
ApplyNetOptions();
530533

531534
return true;

Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class CMainConfig : public CXMLConfig
126126
const std::vector<SString>& GetOwnerEmailAddressList() const { return m_OwnerEmailAddressList; }
127127
bool IsDatabaseCredentialsProtectionEnabled() const { return m_bDatabaseCredentialsProtectionEnabled != 0; }
128128
bool IsFakeLagCommandEnabled() const { return m_bFakeLagCommandEnabled != 0; }
129+
bool IsElementDataWhitelisted() const { return m_elementDataWhitelisted; };
129130

130131
SString GetSetting(const SString& configSetting);
131132
bool GetSetting(const SString& configSetting, SString& strValue);
@@ -227,4 +228,5 @@ class CMainConfig : public CXMLConfig
227228
int m_bFakeLagCommandEnabled;
228229
int m_iPlayerTriggeredEventIntervalMs;
229230
int m_iMaxPlayerTriggeredEventsPerInterval;
231+
bool m_elementDataWhitelisted;
230232
};

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,14 +954,19 @@ bool CStaticFunctionDefinitions::SetElementID(CElement* pElement, const char* sz
954954
return true;
955955
}
956956

957-
bool CStaticFunctionDefinitions::SetElementData(CElement* pElement, const char* szName, const CLuaArgument& Variable, ESyncType syncType)
957+
bool CStaticFunctionDefinitions::SetElementData(CElement* pElement, const char* szName, const CLuaArgument& Variable, ESyncType syncType,
958+
std::optional<ECustomDataClientTrust> clientTrust)
958959
{
959960
assert(pElement);
960961
assert(szName);
961962
assert(strlen(szName) <= MAX_CUSTOMDATA_NAME_LENGTH);
962963

963-
ESyncType lastSyncType = ESyncType::BROADCAST;
964-
CLuaArgument* pCurrentVariable = pElement->GetCustomData(szName, false, &lastSyncType);
964+
ESyncType lastSyncType = ESyncType::BROADCAST;
965+
ECustomDataClientTrust lastClientTrust{};
966+
CLuaArgument* pCurrentVariable = pElement->GetCustomData(szName, false, &lastSyncType, &lastClientTrust);
967+
968+
if (clientTrust.has_value() && lastClientTrust != clientTrust.value())
969+
pElement->GetCustomDataManager().SetClientChangesMode(szName, clientTrust.value());
965970

966971
if (!pCurrentVariable || *pCurrentVariable != Variable || lastSyncType != syncType)
967972
{
@@ -984,7 +989,7 @@ bool CStaticFunctionDefinitions::SetElementData(CElement* pElement, const char*
984989
// Unsubscribe all the players
985990
if (lastSyncType == ESyncType::SUBSCRIBE && syncType != ESyncType::SUBSCRIBE)
986991
m_pPlayerManager->ClearElementData(pElement, szName);
987-
992+
988993
// Set its custom data
989994
pElement->SetCustomData(szName, Variable, syncType);
990995
return true;

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class CStaticFunctionDefinitions
8383
// Element set funcs
8484
static bool ClearElementVisibleTo(CElement* pElement);
8585
static bool SetElementID(CElement* pElement, const char* szID);
86-
static bool SetElementData(CElement* pElement, const char* szName, const CLuaArgument& Variable, ESyncType syncType);
86+
static bool SetElementData(CElement* pElement, const char* szName, const CLuaArgument& Variable, ESyncType syncType,
87+
std::optional<ECustomDataClientTrust> clientTrust);
8788
static bool RemoveElementData(CElement* pElement, const char* szName);
8889
static bool AddElementDataSubscriber(CElement* pElement, const char* szName, CPlayer* pPlayer);
8990
static bool RemoveElementDataSubscriber(CElement* pElement, const char* szName, CPlayer* pPlayer);

Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ ADD_ENUM(ESyncType::LOCAL, "local")
285285
ADD_ENUM(ESyncType::SUBSCRIBE, "subscribe")
286286
IMPLEMENT_ENUM_CLASS_END("sync-mode")
287287

288+
IMPLEMENT_ENUM_CLASS_BEGIN(ECustomDataClientTrust)
289+
ADD_ENUM(ECustomDataClientTrust::UNSET, "default")
290+
ADD_ENUM(ECustomDataClientTrust::ALLOW, "allow")
291+
ADD_ENUM(ECustomDataClientTrust::DENY, "deny")
292+
IMPLEMENT_ENUM_CLASS_END("client-trust-mode")
293+
288294
//
289295
// CResource from userdata
290296
//

Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ DECLARE_ENUM(CAccessControlListRight::ERightType);
3838
DECLARE_ENUM(CElement::EElementType);
3939
DECLARE_ENUM(CAccountPassword::EAccountPasswordType);
4040
DECLARE_ENUM_CLASS(ESyncType);
41+
DECLARE_ENUM_CLASS(ECustomDataClientTrust)
4142

4243
enum eHudComponent
4344
{

0 commit comments

Comments
 (0)