Skip to content

Commit 2bd4d7e

Browse files
committed
feat: configurable multi-command handler support with warning levels
1 parent 5425520 commit 2bd4d7e

File tree

11 files changed

+79
-7
lines changed

11 files changed

+79
-7
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ CClientGame::CClientGame(bool bLocalPlay) : m_ServerInfo(new CServerInfo())
120120

121121
m_bCursorEventsEnabled = false;
122122
m_bInitiallyFadedOut = true;
123+
m_eAllowMultiCommandHandlers = MULTI_COMMAND_ENABLED;
123124

124125
m_bIsPlayingBack = false;
125126
m_bFirstPlaybackFrame = false;
@@ -6137,6 +6138,16 @@ bool CClientGame::GetBirdsEnabled()
61376138
return m_bBirdsEnabled;
61386139
}
61396140

6141+
void CClientGame::SetAllowMultiCommandHandlers(CClientGame::eMultiCommandHandlerPolicy policy)
6142+
{
6143+
m_eAllowMultiCommandHandlers = policy;
6144+
}
6145+
6146+
CClientGame::eMultiCommandHandlerPolicy CClientGame::GetAllowMultiCommandHandlers() const
6147+
{
6148+
return m_eAllowMultiCommandHandlers;
6149+
}
6150+
61406151
void CClientGame::SetWeaponRenderEnabled(bool enabled)
61416152
{
61426153
g_pGame->SetWeaponRenderEnabled(enabled);

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ class CClientGame
192192
QUIT_CONNECTION_DESYNC,
193193
QUIT_TIMEOUT,
194194
};
195+
196+
enum eMultiCommandHandlerPolicy
197+
{
198+
MULTI_COMMAND_DISABLED = 0,
199+
MULTI_COMMAND_ENABLED = 1
200+
};
195201
enum
196202
{
197203
GLITCH_QUICKRELOAD,
@@ -469,6 +475,9 @@ class CClientGame
469475
void ReinitMarkers();
470476

471477
void OnWindowFocusChange(bool state);
478+
479+
void SetAllowMultiCommandHandlers(eMultiCommandHandlerPolicy policy);
480+
eMultiCommandHandlerPolicy GetAllowMultiCommandHandlers() const;
472481

473482
private:
474483
// CGUI Callbacks
@@ -872,6 +881,8 @@ class CClientGame
872881
// Key is the task and value is the CClientPed*
873882
RunNamedAnimTask_type m_mapOfRunNamedAnimTasks;
874883

884+
eMultiCommandHandlerPolicy m_eAllowMultiCommandHandlers;
885+
875886
long long m_timeLastDiscordStateUpdate;
876887
};
877888

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include "CClientGame.h"
1314
#include <game/CClock.h>
1415
#include <game/CFireManager.h>
1516
#include <game/CGarage.h>
@@ -23,6 +24,13 @@
2324
#include "net/SyncStructures.h"
2425
#include "CServerInfo.h"
2526

27+
28+
enum eMultiCommandHandlerPolicy
29+
{
30+
BLOCK_DUPLICATE_HANDLERS,
31+
ALLOW_MULTI_HANDLERS
32+
};
33+
2634
using std::list;
2735

2836
class CCore;
@@ -5567,6 +5575,10 @@ void CPacketHandler::Packet_SyncSettings(NetBitStreamInterface& bitStream)
55675575
if (bitStream.Can(eBitStreamVersion::ShotgunDamageFix))
55685576
bitStream.Read(ucAllowShotgunDamageFix);
55695577

5578+
uchar ucAllowMultiCommandHandlers = 1;
5579+
bitStream.Read(ucAllowMultiCommandHandlers);
5580+
g_pClientGame->SetAllowMultiCommandHandlers(static_cast<CClientGame::eMultiCommandHandlerPolicy>(ucAllowMultiCommandHandlers));
5581+
55705582
SMiscGameSettings miscGameSettings;
55715583
miscGameSettings.bUseAltPulseOrder = (ucUseAltPulseOrder != 0);
55725584
miscGameSettings.bAllowFastSprintFix = (ucAllowFastSprintFix != 0);

Client/mods/deathmatch/logic/CRegisteredCommands.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
3030

3131
if (CommandExists(szKey, NULL))
3232
{
33-
g_pClientGame->GetScriptDebugging()->LogWarning(pLuaMain->GetVM(), "addCommandHandler: Attempt to register duplicate command '%s'", szKey);
34-
return false;
33+
CClientGame::eMultiCommandHandlerPolicy allowMultiHandlers = g_pClientGame->GetAllowMultiCommandHandlers();
34+
35+
// If not allowing duplicate handlers, show warning and block
36+
if (allowMultiHandlers == CClientGame::MULTI_COMMAND_DISABLED)
37+
{
38+
g_pClientGame->GetScriptDebugging()->LogWarning(pLuaMain->GetVM(), "addCommandHandler: Duplicate command registration blocked for '%s' (multiple handlers disabled)", szKey);
39+
return false;
40+
}
41+
// If allowing with warning (default), log warning and proceed
42+
else if (allowMultiHandlers == CClientGame::MULTI_COMMAND_ENABLED)
43+
{
44+
g_pClientGame->GetScriptDebugging()->LogWarning(pLuaMain->GetVM(), "addCommandHandler: Attempt to register duplicate command '%s'", szKey);
45+
}
3546
}
3647

3748
// Check if we already have this key and handler

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4831,9 +4831,10 @@ void CGame::SendSyncSettings(CPlayer* pPlayer)
48314831
uchar ucAllowFastSprintFix = true;
48324832
uchar ucAllowDrivebyAnimFix = true;
48334833
uchar ucAllowShotgunDamageFix = true;
4834+
uchar ucAllowMultiCommandHandlers = m_pMainConfig->GetAllowMultiCommandHandlers();
48344835

48354836
CSyncSettingsPacket packet(weaponTypesUsingBulletSync, ucVehExtrapolateEnabled, sVehExtrapolateBaseMs, sVehExtrapolatePercent, sVehExtrapolateMaxMs,
4836-
ucUseAltPulseOrder, ucAllowFastSprintFix, ucAllowDrivebyAnimFix, ucAllowShotgunDamageFix);
4837+
ucUseAltPulseOrder, ucAllowFastSprintFix, ucAllowDrivebyAnimFix, ucAllowShotgunDamageFix, ucAllowMultiCommandHandlers);
48374838
if (pPlayer)
48384839
pPlayer->Send(packet);
48394840
else

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ CMainConfig::CMainConfig(CConsole* pConsole) : CXMLConfig(NULL)
8181
m_bSyncMapElementData = true;
8282
m_elementDataWhitelisted = false;
8383
m_checkDuplicateSerials = true;
84+
m_iAllowMultiCommandHandlers = 1;
8485
}
8586

8687
bool CMainConfig::Load()
@@ -539,6 +540,8 @@ bool CMainConfig::Load()
539540

540541
GetBoolean(m_pRootNode, "elementdata_whitelisted", m_elementDataWhitelisted);
541542
GetBoolean(m_pRootNode, "check_duplicate_serials", m_checkDuplicateSerials);
543+
GetInteger(m_pRootNode, "allow_multi_command_handlers", m_iAllowMultiCommandHandlers);
544+
m_iAllowMultiCommandHandlers = Clamp(0, m_iAllowMultiCommandHandlers, 2);
542545

543546
ApplyNetOptions();
544547

Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class CMainConfig : public CXMLConfig
150150

151151
int GetPlayerTriggeredEventInterval() const { return m_iPlayerTriggeredEventIntervalMs; }
152152
int GetMaxPlayerTriggeredEventsPerInterval() const { return m_iMaxPlayerTriggeredEventsPerInterval; }
153+
int GetAllowMultiCommandHandlers() const { return m_iAllowMultiCommandHandlers; }
153154

154155
private:
155156
void RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted, const char* szConsoleHelpText);
@@ -235,4 +236,5 @@ class CMainConfig : public CXMLConfig
235236
bool m_elementDataWhitelisted;
236237
bool m_checkDuplicateSerials;
237238
int m_checkResourceClientFiles;
239+
int m_iAllowMultiCommandHandlers;
238240
};

Server/mods/deathmatch/logic/CRegisteredCommands.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "CPlayer.h"
2121
#include "CGame.h"
2222
#include "CScriptDebugging.h"
23+
#include "CMainConfig.h"
2324

2425
CRegisteredCommands::CRegisteredCommands(CAccessControlListManager* pACLManager)
2526
{
@@ -39,8 +40,19 @@ bool CRegisteredCommands::AddCommand(CLuaMain* pLuaMain, const char* szKey, cons
3940

4041
if (CommandExists(szKey, NULL))
4142
{
42-
g_pGame->GetScriptDebugging()->LogWarning(pLuaMain->GetVM(), "addCommandHandler: Attempt to register duplicate command '%s'", szKey);
43-
return false;
43+
int iAllowMultiCommandHandlers = g_pGame->GetConfig()->GetAllowMultiCommandHandlers();
44+
45+
if (iAllowMultiCommandHandlers == 0)
46+
{
47+
// Block silently
48+
return false;
49+
}
50+
else if (iAllowMultiCommandHandlers == 1)
51+
{
52+
// Allow with warning (default behavior)
53+
g_pGame->GetScriptDebugging()->LogWarning(pLuaMain->GetVM(), "Attempt to register duplicate command '%s'", szKey);
54+
}
55+
// For iAllowMultiCommandHandlers == 2, allow silently (no action needed)
4456
}
4557

4658
// Check if we already have this key and handler

Server/mods/deathmatch/logic/packets/CSyncSettingsPacket.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
CSyncSettingsPacket::CSyncSettingsPacket(const std::set<eWeaponType>& weaponTypesUsingBulletSync, uchar ucVehExtrapolateEnabled, short sVehExtrapolateBaseMs,
1717
short sVehExtrapolatePercent, short sVehExtrapolateMaxMs, uchar ucUseAltPulseOrder, uchar ucAllowFastSprintFix,
18-
uchar ucAllowDrivebyAnimationFix, uchar ucAllowShotgunDamageFix)
18+
uchar ucAllowDrivebyAnimationFix, uchar ucAllowShotgunDamageFix, uchar ucAllowMultiCommandHandlers)
1919
{
2020
m_weaponTypesUsingBulletSync = weaponTypesUsingBulletSync;
2121
m_ucVehExtrapolateEnabled = ucVehExtrapolateEnabled;
@@ -26,6 +26,7 @@ CSyncSettingsPacket::CSyncSettingsPacket(const std::set<eWeaponType>& weaponType
2626
m_ucAllowFastSprintFix = ucAllowFastSprintFix;
2727
m_ucAllowDrivebyAnimationFix = ucAllowDrivebyAnimationFix;
2828
m_ucAllowShotgunDamageFix = ucAllowShotgunDamageFix;
29+
m_ucAllowMultiCommandHandlers = ucAllowMultiCommandHandlers;
2930
}
3031

3132
bool CSyncSettingsPacket::Read(NetBitStreamInterface& BitStream)
@@ -71,5 +72,7 @@ bool CSyncSettingsPacket::Write(NetBitStreamInterface& BitStream) const
7172
BitStream.Write(m_ucAllowShotgunDamageFix);
7273
}
7374

75+
BitStream.Write(m_ucAllowMultiCommandHandlers);
76+
7477
return true;
7578
}

Server/mods/deathmatch/logic/packets/CSyncSettingsPacket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CSyncSettingsPacket final : public CPacket
1919
CSyncSettingsPacket(){};
2020
CSyncSettingsPacket(const std::set<eWeaponType>& weaponTypesUsingBulletSync, uchar ucVehExtrapolateEnabled, short sVehExtrapolateBaseMs,
2121
short sVehExtrapolatePercent, short sVehExtrapolateMaxMs, uchar ucUseAltPulseOrder, uchar ucAllowFastSprintFix,
22-
uchar ucAllowDrivebyAnimationFix, uchar ucAllowShotgunDamageFix);
22+
uchar ucAllowDrivebyAnimationFix, uchar ucAllowShotgunDamageFix, uchar ucAllowMultiCommandHandlers);
2323

2424
ePacketID GetPacketID() const { return PACKET_ID_SYNC_SETTINGS; };
2525
unsigned long GetFlags() const { return PACKET_HIGH_PRIORITY | PACKET_RELIABLE | PACKET_SEQUENCED; };
@@ -36,4 +36,5 @@ class CSyncSettingsPacket final : public CPacket
3636
uchar m_ucAllowFastSprintFix;
3737
uchar m_ucAllowDrivebyAnimationFix;
3838
uchar m_ucAllowShotgunDamageFix;
39+
uchar m_ucAllowMultiCommandHandlers;
3940
};

0 commit comments

Comments
 (0)