Skip to content

Commit 7cf9dc4

Browse files
committed
Fixed client setElementData not updating the server when enabling synchronization on an existing key with the same value
1 parent 7b5bccb commit 7cf9dc4

File tree

5 files changed

+29
-35
lines changed

5 files changed

+29
-35
lines changed

Client/mods/deathmatch/logic/CClientEntity.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,23 @@ void CClientEntity::SetID(ElementID ID)
282282
}
283283
}
284284

285-
CLuaArgument* CClientEntity::GetCustomData(const char* szName, bool bInheritData)
285+
CLuaArgument* CClientEntity::GetCustomData(const char* szName, bool bInheritData, bool* pbIsSynced)
286286
{
287287
assert(szName);
288288

289289
// Grab it and return a pointer to the variable
290290
SCustomData* pData = m_pCustomData->Get(szName);
291291
if (pData)
292292
{
293+
if (pbIsSynced)
294+
*pbIsSynced = pData->bSynchronized;
293295
return &pData->Variable;
294296
}
295297

296298
// If none, try returning parent's custom data
297299
if (bInheritData && m_pParent)
298300
{
299-
return m_pParent->GetCustomData(szName, true);
301+
return m_pParent->GetCustomData(szName, true, pbIsSynced);
300302
}
301303

302304
// None available
@@ -458,7 +460,7 @@ bool CClientEntity::GetCustomDataBool(const char* szName, bool& bOut, bool bInhe
458460
return false;
459461
}
460462

461-
void CClientEntity::SetCustomData(const char* szName, const CLuaArgument& Variable)
463+
void CClientEntity::SetCustomData(const char* szName, const CLuaArgument& Variable, bool bSynchronized)
462464
{
463465
assert(szName);
464466
if (strlen(szName) > MAX_CUSTOMDATA_NAME_LENGTH)
@@ -477,7 +479,7 @@ void CClientEntity::SetCustomData(const char* szName, const CLuaArgument& Variab
477479
}
478480

479481
// Set the new data
480-
m_pCustomData->Set(szName, Variable);
482+
m_pCustomData->Set(szName, Variable, bSynchronized);
481483

482484
// Trigger the onClientElementDataChange event on us
483485
CLuaArguments Arguments;

Client/mods/deathmatch/logic/CClientEntity.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ class CClientEntity : public CClientEntityBase
194194
void SetID(ElementID ID);
195195

196196
CCustomData* GetCustomDataPointer(void) { return m_pCustomData; }
197-
CLuaArgument* GetCustomData(const char* szName, bool bInheritData);
197+
CLuaArgument* GetCustomData(const char* szName, bool bInheritData, bool* pbIsSynced = nullptr);
198198
bool GetCustomDataString(const char* szKey, SString& strOut, bool bInheritData);
199199
bool GetCustomDataFloat(const char* szKey, float& fOut, bool bInheritData);
200200
bool GetCustomDataInt(const char* szKey, int& iOut, bool bInheritData);
201201
bool GetCustomDataBool(const char* szKey, bool& bOut, bool bInheritData);
202-
void SetCustomData(const char* szName, const CLuaArgument& Variable);
202+
void SetCustomData(const char* szName, const CLuaArgument& Variable, bool bSynchronized = true);
203203
void DeleteCustomData(const char* szName);
204204

205205
virtual bool GetMatrix(CMatrix& matrix) const;

Client/mods/deathmatch/logic/CCustomData.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SCustomData* CCustomData::Get(const char* szName)
3232
return NULL;
3333
}
3434

35-
void CCustomData::Set(const char* szName, const CLuaArgument& Variable)
35+
void CCustomData::Set(const char* szName, const CLuaArgument& Variable, bool bSynchronized)
3636
{
3737
assert(szName);
3838

@@ -42,12 +42,14 @@ void CCustomData::Set(const char* szName, const CLuaArgument& Variable)
4242
{
4343
// Update existing
4444
pData->Variable = Variable;
45+
pData->bSynchronized = bSynchronized;
4546
}
4647
else
4748
{
4849
// Add new
4950
SCustomData newData;
5051
newData.Variable = Variable;
52+
newData.bSynchronized = bSynchronized;
5153
m_Data[szName] = newData;
5254
}
5355
}

Client/mods/deathmatch/logic/CCustomData.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
struct SCustomData
1919
{
2020
CLuaArgument Variable;
21+
bool bSynchronized;
2122
};
2223

2324
class CCustomData
@@ -26,7 +27,7 @@ class CCustomData
2627
void Copy(CCustomData* pCustomData);
2728

2829
SCustomData* Get(const char* szName);
29-
void Set(const char* szName, const CLuaArgument& Variable);
30+
void Set(const char* szName, const CLuaArgument& Variable, bool bSynchronized = true);
3031

3132
bool Delete(const char* szName);
3233

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -951,39 +951,28 @@ bool CStaticFunctionDefinitions::SetElementData(CClientEntity& Entity, const cha
951951
assert(szName);
952952
assert(strlen(szName) <= MAX_CUSTOMDATA_NAME_LENGTH);
953953

954-
CLuaArgument* pCurrentVariable = Entity.GetCustomData(szName, false);
955-
if (!pCurrentVariable || Variable != *pCurrentVariable)
954+
bool bIsSynced;
955+
CLuaArgument* pCurrentVariable = Entity.GetCustomData(szName, false, &bIsSynced);
956+
if (!pCurrentVariable || Variable != *pCurrentVariable || bIsSynced != bSynchronize)
956957
{
957958
if (bSynchronize && !Entity.IsLocalEntity())
958959
{
959-
// Allocate a bitstream
960960
NetBitStreamInterface* pBitStream = g_pNet->AllocateNetBitStream();
961-
if (pBitStream)
962-
{
963-
// Write element ID, name length and the name. Also write the variable.
964-
pBitStream->Write(Entity.GetID());
965-
unsigned short usNameLength = static_cast<unsigned short>(strlen(szName));
966-
pBitStream->WriteCompressed(usNameLength);
967-
pBitStream->Write(szName, usNameLength);
968-
Variable.WriteToBitStream(*pBitStream);
969-
970-
// Send the packet and deallocate
971-
g_pNet->SendPacket(PACKET_ID_CUSTOM_DATA, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
972-
g_pNet->DeallocateNetBitStream(pBitStream);
973-
974-
// Set its custom data
975-
Entity.SetCustomData(szName, Variable);
976-
977-
return true;
978-
}
961+
// Write element ID, name length and the name. Also write the variable.
962+
pBitStream->Write(Entity.GetID());
963+
unsigned short usNameLength = static_cast<unsigned short>(strlen(szName));
964+
pBitStream->WriteCompressed(usNameLength);
965+
pBitStream->Write(szName, usNameLength);
966+
Variable.WriteToBitStream(*pBitStream);
967+
968+
// Send the packet and deallocate
969+
g_pNet->SendPacket(PACKET_ID_CUSTOM_DATA, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
970+
g_pNet->DeallocateNetBitStream(pBitStream);
979971
}
980-
else
981-
{
982-
// Set its custom data
983-
Entity.SetCustomData(szName, Variable);
984972

985-
return true;
986-
}
973+
// Set its custom data
974+
Entity.SetCustomData(szName, Variable, bSynchronize);
975+
return true;
987976
}
988977

989978
return false;

0 commit comments

Comments
 (0)