MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / AddOrFindCommand

Method AddOrFindCommand

core/ConCmdManager.cpp:539–580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

537}
538
539ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags, IPlugin *pPlugin)
540{
541 ConCmdInfo *pInfo;
542 if (!m_Cmds.retrieve(name, &pInfo))
543 {
544 pInfo = new ConCmdInfo();
545 /* Find the commandopan */
546 ConCommand *pCmd = FindCommand(name);
547
548 if (!pCmd)
549 {
550 /* Note that we have to duplicate because the source might not be
551 * a static string, and these expect static memory.
552 */
553 if (!description)
554 {
555 description = "";
556 }
557 char *new_name = sm_strdup(name);
558 char *new_help = sm_strdup(description);
559 pCmd = new ConCommand(new_name, CommandCallback, new_help, flags);
560 pInfo->pPlugin = pPlugin;
561 pInfo->sourceMod = true;
562 }
563 else
564 {
565 TrackConCommandBase(pCmd, this);
566 CommandHook::Callback callback = [this] (int client, const ICommandArgs *args) -> bool {
567 AutoEnterCommand autoEnterCommand(args);
568 return this->InternalDispatch(client, args);
569 };
570 pInfo->sh_hook = sCoreProviderImpl.AddCommandHook(pCmd, callback);
571 }
572
573 pInfo->pCmd = pCmd;
574
575 m_Cmds.insert(name, pInfo);
576 AddToCmdList(pInfo);
577 }
578
579 return pInfo;
580}
581
582void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
583{

Callers

nothing calls this directly

Calls 7

InternalDispatchMethod · 0.95
FindCommandFunction · 0.85
sm_strdupFunction · 0.85
TrackConCommandBaseFunction · 0.85
retrieveMethod · 0.45
AddCommandHookMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected