Skip to content

Commit 6ce97ca

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/command_case_sensitivity'
2 parents a1f4fcf + ea23129 commit 6ce97ca

File tree

6 files changed

+83
-74
lines changed

6 files changed

+83
-74
lines changed

src/core/modules/commands/commands.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ enum CommandReturn
4545
};
4646

4747

48+
//-----------------------------------------------------------------------------
49+
// Functions.
50+
//-----------------------------------------------------------------------------
51+
template<class InputMap, class Result>
52+
bool find_manager(InputMap input, const char* name, Result& result)
53+
{
54+
InputMap::iterator iter = input.begin();
55+
while (iter != input.end())
56+
{
57+
// TODO: Doesn't not work for multi-byte characters
58+
if (V_stricmp(iter->second->GetName(), name) == 0) {
59+
result = iter;
60+
return true;
61+
}
62+
++iter;
63+
}
64+
return false;
65+
}
66+
67+
4868
//-----------------------------------------------------------------------------
4969
// CCommand extension class.
5070
//-----------------------------------------------------------------------------

src/core/modules/commands/commands_client.cpp

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,30 @@ static CListenerManager s_ClientCommandFilters;
6363
//-----------------------------------------------------------------------------
6464
CClientCommandManager* GetClientCommand(const char* szName)
6565
{
66-
// Find if the given name is a registered client command
67-
ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find(szName);
68-
if( commandMapIter == g_ClientCommandMap.end())
66+
CClientCommandManager* manager = NULL;
67+
ClientCommandMap::iterator iter;
68+
if (!find_manager<ClientCommandMap, ClientCommandMap::iterator>(g_ClientCommandMap, szName, iter))
6969
{
70-
// If the command is not already registered, add the name and the CClientCommandManager instance to the mapping
71-
g_ClientCommandMap.insert(std::make_pair(szName, new CClientCommandManager(szName)));
72-
73-
// Get the client command in the mapping
74-
commandMapIter = g_ClientCommandMap.find(szName);
70+
manager = new CClientCommandManager(szName);
71+
g_ClientCommandMap.insert(std::make_pair(szName, manager));
7572
}
76-
77-
// Return the CClientCommandManager instance for the command
78-
return commandMapIter->second;
73+
else
74+
{
75+
manager = iter->second;
76+
}
77+
return manager;
7978
}
8079

8180
//-----------------------------------------------------------------------------
8281
// Removes a CClientCommandManager instance for the given name.
8382
//-----------------------------------------------------------------------------
8483
void RemoveCClientCommandManager(const char* szName)
8584
{
86-
// Find if the given name is a registered client command
87-
ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find(szName);
88-
if( commandMapIter != g_ClientCommandMap.end())
85+
ClientCommandMap::iterator iter;
86+
if (find_manager<ClientCommandMap, ClientCommandMap::iterator>(g_ClientCommandMap, szName, iter))
8987
{
90-
// If the command is registered, delete the CClientCommandManager instance
91-
// and remove the command from the mapping
92-
delete commandMapIter->second;
93-
g_ClientCommandMap.erase(commandMapIter);
88+
delete iter->second;
89+
g_ClientCommandMap.erase(iter);
9490
}
9591
}
9692

@@ -140,24 +136,15 @@ PLUGIN_RESULT DispatchClientCommand(edict_t* pEntity, const CCommand &command)
140136
END_BOOST_PY_NORET()
141137
}
142138

143-
// Get the command's name
144-
const char* szCommand = command.Arg(0);
145-
146-
// Find if the command exists in the mapping
147-
ClientCommandMap::iterator commandMapIter = g_ClientCommandMap.find(szCommand);
148-
if( commandMapIter != g_ClientCommandMap.end() )
139+
ClientCommandMap::iterator iter;
140+
if (find_manager<ClientCommandMap, ClientCommandMap::iterator>(g_ClientCommandMap, command.Arg(0), iter))
149141
{
150-
// If the command exists, get the CClientCommandManager instance and call its Dispatch method
151-
CClientCommandManager* pCClientCommandManager = commandMapIter->second;
152-
153-
// Does the command need to be blocked?
154-
if( !pCClientCommandManager->Dispatch(command, iIndex))
142+
if( !iter->second->Dispatch(command, iIndex))
155143
{
156144
// Block the command
157145
return PLUGIN_STOP;
158146
}
159147
}
160-
161148
return PLUGIN_CONTINUE;
162149
}
163150

@@ -239,3 +226,8 @@ CommandReturn CClientCommandManager::Dispatch( const CCommand& command, int iInd
239226

240227
return CONTINUE;
241228
}
229+
230+
const char* CClientCommandManager::GetName()
231+
{
232+
return m_Name;
233+
}

src/core/modules/commands/commands_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class CClientCommandManager
5454

5555
CommandReturn Dispatch(const CCommand& ccommand, int iIndex);
5656

57+
const char* GetName();
58+
5759
private:
5860
CUtlVector<object> m_vecCallables;
5961
const char* m_Name;

src/core/modules/commands/commands_say.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,30 @@ void BaseSayCommand::UnregisterCommands()
9797
//-----------------------------------------------------------------------------
9898
CSayCommandManager* GetSayCommand(const char* szName)
9999
{
100-
// Find if the given name is a registered say command
101-
SayCommandMap::iterator commandMapIter = g_SayCommandMap.find(szName);
102-
if( commandMapIter == g_SayCommandMap.end())
100+
CSayCommandManager* manager = NULL;
101+
SayCommandMap::iterator iter;
102+
if (!find_manager<SayCommandMap, SayCommandMap::iterator>(g_SayCommandMap, szName, iter))
103103
{
104-
// If the command is not already registered, add the name and the CSayCommandManager instance to the mapping
105-
g_SayCommandMap.insert(std::make_pair(szName, new CSayCommandManager(szName)));
106-
107-
// Get the say command in the mapping
108-
commandMapIter = g_SayCommandMap.find(szName);
104+
manager = new CSayCommandManager(szName);
105+
g_SayCommandMap.insert(std::make_pair(szName, manager));
109106
}
110-
111-
// Return the CSayCommandManager instance for the command
112-
return commandMapIter->second;
107+
else
108+
{
109+
manager = iter->second;
110+
}
111+
return manager;
113112
}
114113

115114
//-----------------------------------------------------------------------------
116115
// Removes a CSayCommandManager instance for the given name.
117116
//-----------------------------------------------------------------------------
118117
void RemoveCSayCommandManager(const char* szName)
119118
{
120-
// Find if the given name is a registered say command
121-
SayCommandMap::iterator commandMapIter = g_SayCommandMap.find(szName);
122-
if( commandMapIter != g_SayCommandMap.end() )
119+
SayCommandMap::iterator iter;
120+
if (find_manager<SayCommandMap, SayCommandMap::iterator>(g_SayCommandMap, szName, iter))
123121
{
124-
// If the command is registered, delete the CSayCommandManager instance
125-
// and remove the command from the mapping
126-
delete commandMapIter->second;
127-
g_SayCommandMap.erase(commandMapIter);
122+
delete iter->second;
123+
g_SayCommandMap.erase(iter);
128124
}
129125
}
130126

@@ -268,15 +264,11 @@ void SayConCommand::Dispatch( const CCommand& command )
268264
END_BOOST_PY_NORET()
269265
}
270266

271-
// Find if the command is registered
272-
SayCommandMap::iterator commandMapIter = g_SayCommandMap.find(stripped_command[0]);
273-
if( commandMapIter != g_SayCommandMap.end() )
267+
268+
SayCommandMap::iterator iter;
269+
if (find_manager<SayCommandMap, SayCommandMap::iterator>(g_SayCommandMap, stripped_command[0], iter))
274270
{
275-
// Get the CSayCommandManager instance for the command
276-
CSayCommandManager* pCSayCommandManager = commandMapIter->second;
277-
278-
// Call the command and see it wants to block the command
279-
if( pCSayCommandManager->Dispatch(stripped_command, iIndex, bTeamOnly) == BLOCK)
271+
if(iter->second->Dispatch(stripped_command, iIndex, bTeamOnly) == BLOCK)
280272
{
281273
// Block the command
282274
return;
@@ -370,6 +362,11 @@ CommandReturn CSayCommandManager::Dispatch( const CCommand& command, int iIndex,
370362
return CONTINUE;
371363
}
372364

365+
const char* CSayCommandManager::GetName()
366+
{
367+
return m_Name;
368+
}
369+
373370
//-----------------------------------------------------------------------------
374371
// Registers the say and say_team commands.
375372
//-----------------------------------------------------------------------------

src/core/modules/commands/commands_say.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class CSayCommandManager
8484

8585
CommandReturn Dispatch(const CCommand& ccommand, int iIndex, bool bTeamOnly);
8686

87+
const char* GetName();
88+
8789
private:
8890
const char* m_Name;
8991
CUtlVector<object> m_vecCallables;

src/core/modules/commands/commands_server.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,30 @@ ServerCommandMap g_ServerCommandMap;
8282
CServerCommandManager* GetServerCommand(const char* szName,
8383
const char* szHelpText = 0, int iFlags = 0)
8484
{
85-
// Find if the given name is a registered server command
86-
ServerCommandMap::iterator commandMapIter = g_ServerCommandMap.find(szName);
87-
if( commandMapIter == g_ServerCommandMap.end())
85+
CServerCommandManager* manager = NULL;
86+
ServerCommandMap::iterator iter;
87+
if (!find_manager<ServerCommandMap, ServerCommandMap::iterator>(g_ServerCommandMap, szName, iter))
8888
{
89-
// If the command is not already registered, add the name and the CServerCommandManager instance to the mapping
90-
g_ServerCommandMap.insert(std::make_pair(szName, CServerCommandManager::CreateCommand(szName, szHelpText, iFlags)));
91-
92-
// Get the server command in the mapping
93-
commandMapIter = g_ServerCommandMap.find(szName);
89+
manager = CServerCommandManager::CreateCommand(szName, szHelpText, iFlags);
90+
g_ServerCommandMap.insert(std::make_pair(szName, manager));
9491
}
95-
96-
// Return the CServerCommandManager instance for the command
97-
return commandMapIter->second;
92+
else
93+
{
94+
manager = iter->second;
95+
}
96+
return manager;
9897
}
9998

10099
//-----------------------------------------------------------------------------
101100
// Removes a CServerCommandManager instance for the given name.
102101
//-----------------------------------------------------------------------------
103102
void RemoveCServerCommandManager(const char* szName)
104103
{
105-
// Find if the given name is a registered server command
106-
ServerCommandMap::iterator commandMapIter = g_ServerCommandMap.find(szName);
107-
if( commandMapIter != g_ServerCommandMap.end())
104+
ServerCommandMap::iterator iter;
105+
if (find_manager<ServerCommandMap, ServerCommandMap::iterator>(g_ServerCommandMap, szName, iter))
108106
{
109-
// If the command is registered, delete the CServerCommandManager instance
110-
// and remove the command from the mapping
111-
delete commandMapIter->second;
112-
g_ServerCommandMap.erase(commandMapIter);
107+
delete iter->second;
108+
g_ServerCommandMap.erase(iter);
113109
}
114110
}
115111

0 commit comments

Comments
 (0)