Skip to content

Commit 062cdff

Browse files
author
G_Moris
committed
Refactoring changes
1 parent b98217d commit 062cdff

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

Client/core/CCommands.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ bool CCommands::Execute(const char* szCommandLine)
8484
bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool bHandleRemotely, bool bIsScriptedBind)
8585
{
8686
// Copy szParametersIn so the contents can be changed
87-
std::string strParameters;
88-
if (szParametersIn)
89-
{
90-
strParameters = std::string(szParametersIn, strlen(szParametersIn));
91-
}
87+
std::string strParameters = szParametersIn ? std::string(szParametersIn, strlen(szParametersIn)) : "";
9288

9389
// HACK: if its a 'chatboxsay' command, use the next parameter
9490
// Is the command "say" and the arguments start with /? (command comes from the chatbox)
@@ -101,15 +97,15 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
10197
{
10298
// Copy the characters after the slash to the 0 terminator to a seperate buffer
10399
std::array<char, 256> szBuffer = {};
104-
strncpy(szBuffer.data(), strParameters.c_str() + 1, szBuffer.size() - 1);
100+
std::strncpy(szBuffer.data(), strParameters.c_str() + 1, szBuffer.size() - 1);
105101
szBuffer.back() = '\0';
106102

107103
// Split it into command and arguments
108-
szCommand = strtok(szBuffer.data(), " ");
104+
szCommand = std::strtok(szBuffer.data(), " ");
109105
if (!szCommand)
110106
return false;
111107

112-
if (char* szNewParameters = strtok(nullptr, "\0"))
108+
if (char* szNewParameters = std::strtok(nullptr, "\0"))
113109
{
114110
strParameters = std::string(szNewParameters, strlen(szNewParameters));
115111
}
@@ -126,21 +122,19 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
126122
// Grab the command
127123
tagCOMMANDENTRY* pEntry = Get(szCommand);
128124
bool wasHandled = false;
129-
if (pEntry)
125+
126+
// If its a core command, or if its enabled
127+
if (pEntry && (!pEntry->bModCommand || pEntry->bEnabled))
130128
{
131-
// If its a core command, or if its enabled
132-
if (!pEntry->bModCommand || pEntry->bEnabled)
133-
{
134-
// Execute it
135-
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
136-
ExecuteHandler(pEntry->pfnCmdFunc, strParameters.c_str());
137-
138-
wasHandled = true;
139-
}
129+
// Execute it
130+
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
131+
ExecuteHandler(pEntry->pfnCmdFunc, strParameters.c_str());
132+
133+
wasHandled = true;
140134
}
141135

142136
// Recompose the original command text
143-
std::string val = std::string(szCommand) + " " + std::string(!strParameters.empty() ? strParameters : "");
137+
std::string val = std::string(szCommand) + " " + strParameters;
144138

145139
// Is it a cvar? (syntax: cvar[ = value])
146140
if (!wasHandled)
@@ -221,8 +215,9 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
221215

222216
// Unknown command
223217
val = _("Unknown command or cvar: ") + szCommand;
224-
if (!bIsScriptedBind && !bIsNickCommand && pEntry == nullptr)
218+
if (!bIsScriptedBind && !bIsNickCommand && !pEntry)
225219
CCore::GetSingleton().GetConsole()->Print(val.c_str());
220+
226221
return false;
227222
}
228223

0 commit comments

Comments
 (0)