Move RootConsoleMenu into core/logic.

This commit is contained in:
David Anderson 2015-08-28 14:08:25 -04:00
parent 23d55dd9d5
commit 28346c99f2
12 changed files with 52 additions and 47 deletions

View File

@ -41,7 +41,6 @@ project.sources += [
'ConsoleDetours.cpp', 'ConsoleDetours.cpp',
'vprof_tool.cpp', 'vprof_tool.cpp',
'smn_commandline.cpp', 'smn_commandline.cpp',
'RootConsoleMenu.cpp',
] ]
for sdk_name in SM.sdks: for sdk_name in SM.sdks:

View File

@ -30,12 +30,12 @@
*/ */
#include "ConCmdManager.h" #include "ConCmdManager.h"
#include "RootConsoleMenu.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "HalfLife2.h" #include "HalfLife2.h"
#include "ChatTriggers.h" #include "ChatTriggers.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "sourcemod.h"
using namespace ke; using namespace ke;
@ -644,7 +644,7 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
if (!pPlugin) if (!pPlugin)
{ {
rootmenu->ConsolePrint("[SM] Plugin \"%s\" was not found.", text); UTIL_ConsolePrint("[SM] Plugin \"%s\" was not found.", text);
return; return;
} }
@ -654,20 +654,20 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
PluginHookList *pList; PluginHookList *pList;
if (!pPlugin->GetProperty("CommandList", (void **)&pList)) if (!pPlugin->GetProperty("CommandList", (void **)&pList))
{ {
rootmenu->ConsolePrint("[SM] No commands found for: %s", plname); UTIL_ConsolePrint("[SM] No commands found for: %s", plname);
return; return;
} }
if (pList->empty()) if (pList->empty())
{ {
rootmenu->ConsolePrint("[SM] No commands found for: %s", plname); UTIL_ConsolePrint("[SM] No commands found for: %s", plname);
return; return;
} }
const char *type = NULL; const char *type = NULL;
const char *name; const char *name;
const char *help; const char *help;
rootmenu->ConsolePrint("[SM] Listing commands for: %s", plname); UTIL_ConsolePrint("[SM] Listing commands for: %s", plname);
rootmenu->ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]"); UTIL_ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]");
for (PluginHookList::iterator iter = pList->begin(); iter != pList->end(); iter++) for (PluginHookList::iterator iter = pList->begin(); iter != pList->end(); iter++)
{ {
CmdHook *hook = *iter; CmdHook *hook = *iter;
@ -681,11 +681,11 @@ void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
help = hook->helptext.chars(); help = hook->helptext.chars();
else else
help = hook->info->pCmd->GetHelpText(); help = hook->info->pCmd->GetHelpText();
rootmenu->ConsolePrint(" %-17.16s %-12.11s %s", name, type, help); UTIL_ConsolePrint(" %-17.16s %-12.11s %s", name, type, help);
} }
return; return;
} }
rootmenu->ConsolePrint("[SM] Usage: sm cmds <plugin #>"); UTIL_ConsolePrint("[SM] Usage: sm cmds <plugin #>");
} }

View File

@ -33,7 +33,7 @@
#include <sh_vector.h> #include <sh_vector.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
#include "logic_bridge.h" #include "logic_bridge.h"
#include "RootConsoleMenu.h" #include "sourcemod.h"
ConVarManager g_ConVarManager; ConVarManager g_ConVarManager;
@ -360,7 +360,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
if (!plugin) if (!plugin)
{ {
rootmenu->ConsolePrint("[SM] Plugin \"%s\" was not found.", arg); UTIL_ConsolePrint("[SM] Plugin \"%s\" was not found.", arg);
return; return;
} }
@ -374,14 +374,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
/* If no convar list... */ /* If no convar list... */
if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
{ {
rootmenu->ConsolePrint("[SM] No convars found for: %s", plname); UTIL_ConsolePrint("[SM] No convars found for: %s", plname);
return; return;
} }
if (!wantReset) if (!wantReset)
{ {
rootmenu->ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); UTIL_ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname);
rootmenu->ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); UTIL_ConsolePrint(" %-32.31s %s", "[Name]", "[Value]");
} }
/* Iterate convar list and display/reset each one */ /* 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<ConVar *>(*iter); /*const */ConVar *pConVar = const_cast<ConVar *>(*iter);
if (!wantReset) if (!wantReset)
{ {
rootmenu->ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); UTIL_ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString());
} else { } else {
pConVar->Revert(); pConVar->Revert();
} }
@ -398,14 +398,14 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
if (wantReset) if (wantReset)
{ {
rootmenu->ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname); UTIL_ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname);
} }
return; return;
} }
/* Display usage of subcommand */ /* Display usage of subcommand */
rootmenu->ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>"); UTIL_ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>");
} }
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) 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)

View File

@ -33,14 +33,17 @@
#include "CoreConfig.h" #include "CoreConfig.h"
#include "sourcemod.h" #include "sourcemod.h"
#include "sourcemm_api.h" #include "sourcemm_api.h"
#include "RootConsoleMenu.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "Logger.h" #include "Logger.h"
#include "frame_hooks.h" #include "frame_hooks.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "compat_wrappers.h"
#include <sourcemod_version.h> #include <sourcemod_version.h>
#include <amtl/os/am-path.h> #include <amtl/os/am-path.h>
#include <amtl/os/am-fsutil.h> #include <amtl/os/am-fsutil.h>
#include <sh_list.h>
using namespace SourceHook;
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file"); ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
@ -198,11 +201,11 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *c
if (res == ConfigResult_Reject) if (res == ConfigResult_Reject)
{ {
rootmenu->ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error); UTIL_ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\". (%s)", option, value, error);
} else if (res == ConfigResult_Ignore) { } else if (res == ConfigResult_Ignore) {
rootmenu->ConsolePrint("[SM] No such config option \"%s\" exists.", option); UTIL_ConsolePrint("[SM] No such config option \"%s\" exists.", option);
} else { } else {
rootmenu->ConsolePrint("[SM] Config option \"%s\" successfully set to \"%s\".", option, value); UTIL_ConsolePrint("[SM] Config option \"%s\" successfully set to \"%s\".", option, value);
} }
return; return;
@ -213,15 +216,15 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *c
if (value == NULL) if (value == NULL)
{ {
rootmenu->ConsolePrint("[SM] No such config option \"%s\" exists.", option); UTIL_ConsolePrint("[SM] No such config option \"%s\" exists.", option);
} else { } else {
rootmenu->ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value); UTIL_ConsolePrint("[SM] Config option \"%s\" is set to \"%s\".", option, value);
} }
return; return;
} }
rootmenu->ConsolePrint("[SM] Usage: sm config <option> [value]"); UTIL_ConsolePrint("[SM] Usage: sm config <option> [value]");
} }
void CoreConfig::Initialize() void CoreConfig::Initialize()

View File

@ -77,6 +77,7 @@ binary.sources += [
'smn_menus.cpp', 'smn_menus.cpp',
'sprintf.cpp', 'sprintf.cpp',
'LibrarySys.cpp', 'LibrarySys.cpp',
'RootConsoleMenu.cpp',
] ]
if builder.target_platform == 'windows': if builder.target_platform == 'windows':
binary.sources += ['thread/WinThreads.cpp'] binary.sources += ['thread/WinThreads.cpp']

View File

@ -25,14 +25,10 @@
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), // exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
// or <http://www.sourcemod.net/license.php>. // or <http://www.sourcemod.net/license.php>.
#include "RootConsoleMenu.h" #include "RootConsoleMenu.h"
#include "sm_stringutil.h" #include <amtl/am-string.h>
#include "CoreConfig.h"
#include "ConVarManager.h"
#include "logic_bridge.h"
#include <sourcemod_version.h> #include <sourcemod_version.h>
RootConsoleMenu g_RootMenu; RootConsoleMenu g_RootMenu;
IRootConsole *rootmenu = &g_RootMenu;
RootConsoleMenu::RootConsoleMenu() RootConsoleMenu::RootConsoleMenu()
{ {
@ -69,7 +65,7 @@ void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
UTIL_ConsolePrintVa(fmt, ap); smcore.ConsolePrintVa(fmt, ap);
va_end(ap); va_end(ap);
} }
@ -149,7 +145,7 @@ void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
char buffer[255]; char buffer[255];
size_t len, cmdlen = strlen(cmd); size_t len, cmdlen = strlen(cmd);
len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd); len = ke::SafeSprintf(buffer, sizeof(buffer), " %s", cmd);
if (cmdlen < 16) if (cmdlen < 16)
{ {
size_t num = 16 - cmdlen; size_t num = 16 - cmdlen;

View File

@ -27,12 +27,10 @@
#ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_ #ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
#define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_ #define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
#include "sourcemod.h" #include "common_logic.h"
#include <IRootConsoleMenu.h> #include <IRootConsoleMenu.h>
#include "sourcemm_api.h"
#include <sh_list.h> #include <sh_list.h>
#include <sh_string.h> #include <sh_string.h>
#include <compat_wrappers.h>
#include <sm_namehashset.h> #include <sm_namehashset.h>
using namespace SourceMod; using namespace SourceMod;
@ -86,6 +84,5 @@ private:
}; };
extern RootConsoleMenu g_RootMenu; extern RootConsoleMenu g_RootMenu;
extern IRootConsole *rootmenu;
#endif // _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_ #endif // _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_

View File

@ -53,6 +53,7 @@
#include "Logger.h" #include "Logger.h"
#include "sprintf.h" #include "sprintf.h"
#include "LibrarySys.h" #include "LibrarySys.h"
#include "RootConsoleMenu.h"
sm_core_t smcore; sm_core_t smcore;
IHandleSys *handlesys = &g_HandleSys; IHandleSys *handlesys = &g_HandleSys;
@ -63,7 +64,7 @@ ILibrarySys *libsys = &g_LibSys;
ITextParsers *textparser = &g_TextParser; ITextParsers *textparser = &g_TextParser;
IVEngineServer *engine; IVEngineServer *engine;
IShareSys *sharesys = &g_ShareSys; IShareSys *sharesys = &g_ShareSys;
IRootConsole *rootmenu; IRootConsole *rootmenu = &g_RootMenu;
IPluginManager *pluginsys = g_PluginSys.GetOldAPI(); IPluginManager *pluginsys = g_PluginSys.GetOldAPI();
IForwardManager *forwardsys = &g_Forwards; IForwardManager *forwardsys = &g_Forwards;
ITimerSystem *timersys; ITimerSystem *timersys;
@ -120,6 +121,11 @@ static void RegisterProfiler(IProfilingTool *tool)
g_ProfileToolManager.RegisterTool(tool); g_ProfileToolManager.RegisterTool(tool);
} }
static void OnRootCommand(const ICommandArgs *args)
{
g_RootMenu.GotRootCmd(args);
}
static sm_logic_t logic = static sm_logic_t logic =
{ {
NULL, NULL,
@ -140,6 +146,7 @@ static sm_logic_t logic =
DumpHandles, DumpHandles,
DumpAdminCache, DumpAdminCache,
RegisterProfiler, RegisterProfiler,
OnRootCommand,
&g_PluginSys, &g_PluginSys,
&g_ShareSys, &g_ShareSys,
&g_Extensions, &g_Extensions,
@ -148,6 +155,7 @@ static sm_logic_t logic =
&g_Admins, &g_Admins,
NULL, NULL,
&g_Logger, &g_Logger,
&g_RootMenu,
-1.0f -1.0f
}; };
@ -161,7 +169,6 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
engine = core->engine; engine = core->engine;
g_pSM = core->sm; g_pSM = core->sm;
rootmenu = core->rootmenu;
timersys = core->timersys; timersys = core->timersys;
playerhelpers = core->playerhelpers; playerhelpers = core->playerhelpers;
gamehelpers = core->gamehelpers; gamehelpers = core->gamehelpers;

View File

@ -52,7 +52,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 37) #define SM_LOGIC_MAGIC (0x0F47C0DE - 38)
#if defined SM_LOGIC #if defined SM_LOGIC
class IVEngineServer class IVEngineServer
@ -120,6 +120,7 @@ namespace SourceMod
class ITranslator; class ITranslator;
class IGameConfig; class IGameConfig;
class IMenuManager; class IMenuManager;
class ICommandArgs;
} }
class IVEngineServer; class IVEngineServer;
@ -283,7 +284,6 @@ struct sm_core_t
IVEngineServer *engine; IVEngineServer *engine;
IFileSystem *filesystem; IFileSystem *filesystem;
IPlayerInfo_Logic *playerInfo; IPlayerInfo_Logic *playerInfo;
IRootConsole *rootmenu;
ITimerSystem *timersys; ITimerSystem *timersys;
IPlayerManager *playerhelpers; IPlayerManager *playerhelpers;
IGameHelpers *gamehelpers; IGameHelpers *gamehelpers;
@ -348,6 +348,7 @@ struct sm_logic_t
void (*DumpHandles)(void (*dumpfn)(const char *fmt, ...)); void (*DumpHandles)(void (*dumpfn)(const char *fmt, ...));
bool (*DumpAdminCache)(const char *filename); bool (*DumpAdminCache)(const char *filename);
void (*RegisterProfiler)(IProfilingTool *tool); void (*RegisterProfiler)(IProfilingTool *tool);
void (*OnRootCommand)(const ICommandArgs *args);
IScriptManager *scripts; IScriptManager *scripts;
IShareSys *sharesys; IShareSys *sharesys;
IExtensionSys *extsys; IExtensionSys *extsys;
@ -356,6 +357,7 @@ struct sm_logic_t
IAdminSystem *adminsys; IAdminSystem *adminsys;
IdentityToken_t *core_ident; IdentityToken_t *core_ident;
ILogger *logger; ILogger *logger;
IRootConsole *rootmenu;
float sentinel; float sentinel;
}; };

View File

@ -37,7 +37,6 @@
#include "logic/intercom.h" #include "logic/intercom.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "Logger.h" #include "Logger.h"
#include "RootConsoleMenu.h"
#include "TimerSys.h" #include "TimerSys.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "PlayerManager.h" #include "PlayerManager.h"
@ -89,6 +88,7 @@ IHandleSys *handlesys;
IForwardManager *forwardsys; IForwardManager *forwardsys;
IAdminSystem *adminsys; IAdminSystem *adminsys;
ILogger *logger; ILogger *logger;
IRootConsole *rootmenu;
class VEngineServer_Logic : public IVEngineServer_Logic class VEngineServer_Logic : public IVEngineServer_Logic
{ {
@ -625,7 +625,6 @@ static sm_core_t core_bridge =
reinterpret_cast<IVEngineServer*>(&logic_engine), reinterpret_cast<IVEngineServer*>(&logic_engine),
reinterpret_cast<IFileSystem*>(&logic_filesystem), reinterpret_cast<IFileSystem*>(&logic_filesystem),
&logic_playerinfo, &logic_playerinfo,
&g_RootMenu,
&g_Timers, &g_Timers,
&g_Players, &g_Players,
&g_HL2, &g_HL2,
@ -706,6 +705,7 @@ void InitLogicBridge()
forwardsys = logicore.forwardsys; forwardsys = logicore.forwardsys;
adminsys = logicore.adminsys; adminsys = logicore.adminsys;
logger = logicore.logger; logger = logicore.logger;
rootmenu = logicore.rootmenu;
} }
bool StartLogicBridge(char *error, size_t maxlength) bool StartLogicBridge(char *error, size_t maxlength)

View File

@ -49,5 +49,6 @@ extern IHandleSys *handlesys;
extern IForwardManager *forwardsys; extern IForwardManager *forwardsys;
extern IAdminSystem *adminsys; extern IAdminSystem *adminsys;
extern ILogger *logger; extern ILogger *logger;
extern IRootConsole *rootmenu;
#endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */ #endif /* _INCLUDE_SOURCEMOD_LOGIC_BRIDGE_H_ */

View File

@ -32,7 +32,6 @@
#include "sourcemm_api.h" #include "sourcemm_api.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "sm_globals.h" #include "sm_globals.h"
#include "RootConsoleMenu.h"
#include "CoreConfig.h" #include "CoreConfig.h"
#include <compat_wrappers.h> #include <compat_wrappers.h>
#include <ITranslator.h> #include <ITranslator.h>
@ -112,7 +111,7 @@ CON_COMMAND(sm, "SourceMod Menu")
} }
g_RootMenu.GotRootCmd(&cargs); logicore.OnRootCommand(&cargs);
} }
FILE *g_pHndlLog = NULL; FILE *g_pHndlLog = NULL;
@ -150,7 +149,7 @@ CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle le
#endif #endif
if (args.ArgC() < 2) if (args.ArgC() < 2)
{ {
rootmenu->ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs"); UTIL_ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
return; return;
} }
@ -163,7 +162,7 @@ CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle le
FILE *fp = fopen(filename, "wt"); FILE *fp = fopen(filename, "wt");
if (!fp) if (!fp)
{ {
rootmenu->ConsolePrint("Failed to open \"%s\" for writing", filename); UTIL_ConsolePrint("Failed to open \"%s\" for writing", filename);
return; return;
} }
@ -191,10 +190,10 @@ CON_COMMAND(sm_dump_admcache, "Dumps the admin cache for debugging")
if (!logicore.DumpAdminCache(buffer)) if (!logicore.DumpAdminCache(buffer))
{ {
rootmenu->ConsolePrint("Could not open file for writing: %s", buffer); UTIL_ConsolePrint("Could not open file for writing: %s", buffer);
return; return;
} }
rootmenu->ConsolePrint("Admin cache dumped to: %s", buffer); UTIL_ConsolePrint("Admin cache dumped to: %s", buffer);
} }