From 2c886943a07073fb24d1aebef1efd6c36b76da41 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 27 Aug 2015 23:46:36 -0400 Subject: [PATCH] Move RootConsoleMenu into its own header and .cpp file. --- core/AMBuilder | 1 + core/ConCmdManager.cpp | 20 +- core/ConVarManager.cpp | 20 +- core/CoreConfig.cpp | 18 +- core/NextMap.cpp | 2 +- core/RootConsoleMenu.cpp | 250 ++++++++++++++++++++ core/{sm_srvcmds.h => RootConsoleMenu.h} | 186 ++++++++------- core/logic_bridge.cpp | 2 +- core/sm_srvcmds.cpp | 285 +++-------------------- 9 files changed, 411 insertions(+), 373 deletions(-) create mode 100644 core/RootConsoleMenu.cpp rename core/{sm_srvcmds.h => RootConsoleMenu.h} (55%) diff --git a/core/AMBuilder b/core/AMBuilder index 183cd10d..edf83535 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -41,6 +41,7 @@ project.sources += [ 'ConsoleDetours.cpp', 'vprof_tool.cpp', 'smn_commandline.cpp', + 'RootConsoleMenu.cpp', ] for sdk_name in SM.sdks: diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 83576b68..fe223856 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -30,7 +30,7 @@ */ #include "ConCmdManager.h" -#include "sm_srvcmds.h" +#include "RootConsoleMenu.h" #include "sm_stringutil.h" #include "PlayerManager.h" #include "HalfLife2.h" @@ -66,7 +66,7 @@ ConCmdManager::~ConCmdManager() void ConCmdManager::OnSourceModAllInitialized() { scripts->AddPluginsListener(this); - g_RootMenu.AddRootConsoleCommand3("cmds", "List console commands", this); + rootmenu->AddRootConsoleCommand3("cmds", "List console commands", this); SH_ADD_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &ConCmdManager::SetCommandClient), false); } @@ -75,7 +75,7 @@ void ConCmdManager::OnSourceModShutdown() scripts->RemovePluginsListener(this); /* All commands should already be removed by the time we're done */ SH_REMOVE_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &ConCmdManager::SetCommandClient), false); - g_RootMenu.RemoveRootConsoleCommand("cmds", this); + rootmenu->RemoveRootConsoleCommand("cmds", this); } void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) @@ -644,7 +644,7 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs if (!pPlugin) { - g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", text); + rootmenu->ConsolePrint("[SM] Plugin \"%s\" was not found.", text); return; } @@ -654,20 +654,20 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs PluginHookList *pList; if (!pPlugin->GetProperty("CommandList", (void **)&pList)) { - g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); + rootmenu->ConsolePrint("[SM] No commands found for: %s", plname); return; } if (pList->empty()) { - g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); + rootmenu->ConsolePrint("[SM] No commands found for: %s", plname); return; } const char *type = NULL; const char *name; const char *help; - g_RootMenu.ConsolePrint("[SM] Listing commands for: %s", plname); - g_RootMenu.ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]"); + rootmenu->ConsolePrint("[SM] Listing commands for: %s", plname); + rootmenu->ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]"); for (PluginHookList::iterator iter = pList->begin(); iter != pList->end(); iter++) { CmdHook *hook = *iter; @@ -681,11 +681,11 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs help = hook->helptext.chars(); else help = hook->info->pCmd->GetHelpText(); - g_RootMenu.ConsolePrint(" %-17.16s %-12.11s %s", name, type, help); + rootmenu->ConsolePrint(" %-17.16s %-12.11s %s", name, type, help); } return; } - g_RootMenu.ConsolePrint("[SM] Usage: sm cmds "); + rootmenu->ConsolePrint("[SM] Usage: sm cmds "); } diff --git a/core/ConVarManager.cpp b/core/ConVarManager.cpp index 6514784b..6ea14fb8 100644 --- a/core/ConVarManager.cpp +++ b/core/ConVarManager.cpp @@ -29,11 +29,11 @@ #include "ConVarManager.h" #include "HalfLife2.h" -#include "sm_srvcmds.h" #include "sm_stringutil.h" #include #include #include "logic_bridge.h" +#include "RootConsoleMenu.h" ConVarManager g_ConVarManager; @@ -134,7 +134,7 @@ void ConVarManager::OnSourceModAllInitialized() scripts->AddPluginsListener(this); /* Add the 'convars' option to the 'sm' console command */ - g_RootMenu.AddRootConsoleCommand3("cvars", "View convars created by a plugin", this); + rootmenu->AddRootConsoleCommand3("cvars", "View convars created by a plugin", this); } void ConVarManager::OnSourceModShutdown() @@ -205,7 +205,7 @@ void ConVarManager::OnSourceModShutdown() #endif /* Remove the 'convars' option from the 'sm' console command */ - g_RootMenu.RemoveRootConsoleCommand("cvars", this); + rootmenu->RemoveRootConsoleCommand("cvars", this); scripts->RemovePluginsListener(this); @@ -360,7 +360,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs if (!plugin) { - g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", arg); + rootmenu->ConsolePrint("[SM] Plugin \"%s\" was not found.", arg); return; } @@ -374,14 +374,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs /* If no convar list... */ if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) { - g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); + rootmenu->ConsolePrint("[SM] No convars found for: %s", plname); return; } if (!wantReset) { - g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); - g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); + rootmenu->ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); + rootmenu->ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); } /* Iterate convar list and display/reset each one */ @@ -390,7 +390,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs /*const */ConVar *pConVar = const_cast(*iter); if (!wantReset) { - g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); + rootmenu->ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); } else { pConVar->Revert(); } @@ -398,14 +398,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs if (wantReset) { - g_RootMenu.ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname); + rootmenu->ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname); } return; } /* Display usage of subcommand */ - g_RootMenu.ConsolePrint("[SM] Usage: sm cvars [reset] "); + rootmenu->ConsolePrint("[SM] Usage: sm cvars [reset] "); } Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *description, int flags, bool hasMin, float min, bool hasMax, float max) diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index 25f5a524..9c7f0bde 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -33,7 +33,7 @@ #include "CoreConfig.h" #include "sourcemod.h" #include "sourcemm_api.h" -#include "sm_srvcmds.h" +#include "RootConsoleMenu.h" #include "sm_stringutil.h" #include "Logger.h" #include "frame_hooks.h" @@ -118,7 +118,7 @@ void CheckAndFinalizeConfigs() void CoreConfig::OnSourceModAllInitialized() { - g_RootMenu.AddRootConsoleCommand3("config", "Set core configuration options", this); + rootmenu->AddRootConsoleCommand3("config", "Set core configuration options", this); g_pOnServerCfg = forwardsys->CreateForward("OnServerCfg", ET_Ignore, 0, NULL); g_pOnConfigsExecuted = forwardsys->CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL); g_pOnAutoConfigsBuffered = forwardsys->CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL); @@ -134,7 +134,7 @@ CoreConfig::~CoreConfig() void CoreConfig::OnSourceModShutdown() { - g_RootMenu.RemoveRootConsoleCommand("config", this); + rootmenu->RemoveRootConsoleCommand("config", this); forwardsys->ReleaseForward(g_pOnServerCfg); forwardsys->ReleaseForward(g_pOnConfigsExecuted); forwardsys->ReleaseForward(g_pOnAutoConfigsBuffered); @@ -198,11 +198,11 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *c if (res == ConfigResult_Reject) { - g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error); + rootmenu->ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error); } else if (res == ConfigResult_Ignore) { - g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); + rootmenu->ConsolePrint("[SM] No such config option \"%s\" exists.", option); } else { - g_RootMenu.ConsolePrint("[SM] Config option \"%s\" successfully set to \"%s\".", option, value); + rootmenu->ConsolePrint("[SM] Config option \"%s\" successfully set to \"%s\".", option, value); } return; @@ -213,15 +213,15 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *c if (value == NULL) { - g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); + rootmenu->ConsolePrint("[SM] No such config option \"%s\" exists.", option); } else { - g_RootMenu.ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value); + rootmenu->ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value); } return; } - g_RootMenu.ConsolePrint("[SM] Usage: sm config