command: use const reference

This commit is contained in:
FutureRave 2022-10-25 22:17:39 +01:00
parent 4d51ee436f
commit 13504f312d
No known key found for this signature in database
GPG Key ID: 22F9079C86CFAB31
4 changed files with 13 additions and 11 deletions

View File

@ -33,9 +33,9 @@ namespace command
params params = {};
const auto command = utils::string::to_lower(params[0]);
if (handlers.contains(command))
if (const auto itr = handlers.find(command); itr != handlers.end())
{
handlers[command](params);
itr->second(params);
}
}
@ -50,9 +50,9 @@ namespace command
params_sv params = {};
const auto command = utils::string::to_lower(params[0]);
if (const auto got = handlers_sv.find(command); got != handlers_sv.end())
if (const auto itr = handlers_sv.find(command); itr != handlers_sv.end())
{
got->second(&game::mp::g_entities[client_num], params);
itr->second(&game::mp::g_entities[client_num], params);
}
client_command_hook.invoke<void>(client_num);
@ -219,7 +219,7 @@ namespace command
});
}
void add_sv(const char* name, std::function<void(game::mp::gentity_s*, const params_sv&)> callback)
void add_sv(const char* name, const std::function<void(game::mp::gentity_s*, const params_sv&)>& callback)
{
// doing this so the sv command would show up in the console
add_raw(name, nullptr);
@ -227,7 +227,9 @@ namespace command
const auto command = utils::string::to_lower(name);
if (!handlers_sv.contains(command))
handlers_sv[command] = std::move(callback);
{
handlers_sv[command] = callback;
}
}
bool cheats_ok(const game::mp::gentity_s* ent)

View File

@ -44,7 +44,7 @@ namespace command
void add(const char* name, const std::function<void(const params&)>& callback);
void add(const char* name, const std::function<void()>& callback);
void add_sv(const char* name, std::function<void(game::mp::gentity_s*, const params_sv&)> callback);
void add_sv(const char* name, const std::function<void(game::mp::gentity_s*, const params_sv&)>& callback);
void execute(std::string command, bool sync = false);
}

View File

@ -171,9 +171,9 @@ namespace gsc
void scr_register_function_stub(void* func, int type, unsigned int name)
{
if (const auto got = builtin_funcs_overrides.find(name); got != builtin_funcs_overrides.end())
if (const auto itr = builtin_funcs_overrides.find(name); itr != builtin_funcs_overrides.end())
{
func = got->second;
func = itr->second;
}
scr_register_function_hook.invoke<void>(func, type, name);

View File

@ -81,9 +81,9 @@ namespace gsc
game::ScriptFile* load_custom_script(const char* file_name, const std::string& real_name)
{
if (const auto got = loaded_scripts.find(real_name); got != loaded_scripts.end())
if (const auto itr = loaded_scripts.find(real_name); itr != loaded_scripts.end())
{
return got->second;
return itr->second;
}
std::string source_buffer{};