Move RootConsoleMenu into its own header and .cpp file.

This commit is contained in:
David Anderson 2015-08-27 23:46:36 -04:00
parent 9d805ea9fb
commit 2c886943a0
9 changed files with 411 additions and 373 deletions

View File

@ -41,6 +41,7 @@ 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,7 +30,7 @@
*/ */
#include "ConCmdManager.h" #include "ConCmdManager.h"
#include "sm_srvcmds.h" #include "RootConsoleMenu.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "HalfLife2.h" #include "HalfLife2.h"
@ -66,7 +66,7 @@ ConCmdManager::~ConCmdManager()
void ConCmdManager::OnSourceModAllInitialized() void ConCmdManager::OnSourceModAllInitialized()
{ {
scripts->AddPluginsListener(this); 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); SH_ADD_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &ConCmdManager::SetCommandClient), false);
} }
@ -75,7 +75,7 @@ void ConCmdManager::OnSourceModShutdown()
scripts->RemovePluginsListener(this); scripts->RemovePluginsListener(this);
/* All commands should already be removed by the time we're done */ /* All commands should already be removed by the time we're done */
SH_REMOVE_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &ConCmdManager::SetCommandClient), false); 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) 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) if (!pPlugin)
{ {
g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", text); rootmenu->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))
{ {
g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); rootmenu->ConsolePrint("[SM] No commands found for: %s", plname);
return; return;
} }
if (pList->empty()) if (pList->empty())
{ {
g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); rootmenu->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;
g_RootMenu.ConsolePrint("[SM] Listing commands for: %s", plname); rootmenu->ConsolePrint("[SM] Listing commands for: %s", plname);
g_RootMenu.ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]"); rootmenu->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();
g_RootMenu.ConsolePrint(" %-17.16s %-12.11s %s", name, type, help); rootmenu->ConsolePrint(" %-17.16s %-12.11s %s", name, type, help);
} }
return; return;
} }
g_RootMenu.ConsolePrint("[SM] Usage: sm cmds <plugin #>"); rootmenu->ConsolePrint("[SM] Usage: sm cmds <plugin #>");
} }

View File

@ -29,11 +29,11 @@
#include "ConVarManager.h" #include "ConVarManager.h"
#include "HalfLife2.h" #include "HalfLife2.h"
#include "sm_srvcmds.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#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"
ConVarManager g_ConVarManager; ConVarManager g_ConVarManager;
@ -134,7 +134,7 @@ void ConVarManager::OnSourceModAllInitialized()
scripts->AddPluginsListener(this); scripts->AddPluginsListener(this);
/* Add the 'convars' option to the 'sm' console command */ /* 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() void ConVarManager::OnSourceModShutdown()
@ -205,7 +205,7 @@ void ConVarManager::OnSourceModShutdown()
#endif #endif
/* Remove the 'convars' option from the 'sm' console command */ /* Remove the 'convars' option from the 'sm' console command */
g_RootMenu.RemoveRootConsoleCommand("cvars", this); rootmenu->RemoveRootConsoleCommand("cvars", this);
scripts->RemovePluginsListener(this); scripts->RemovePluginsListener(this);
@ -360,7 +360,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs
if (!plugin) if (!plugin)
{ {
g_RootMenu.ConsolePrint("[SM] Plugin \"%s\" was not found.", arg); rootmenu->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))
{ {
g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); rootmenu->ConsolePrint("[SM] No convars found for: %s", plname);
return; return;
} }
if (!wantReset) if (!wantReset)
{ {
g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); rootmenu->ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname);
g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); rootmenu->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)
{ {
g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); rootmenu->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)
{ {
g_RootMenu.ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname); rootmenu->ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname);
} }
return; return;
} }
/* Display usage of subcommand */ /* Display usage of subcommand */
g_RootMenu.ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>"); rootmenu->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,7 +33,7 @@
#include "CoreConfig.h" #include "CoreConfig.h"
#include "sourcemod.h" #include "sourcemod.h"
#include "sourcemm_api.h" #include "sourcemm_api.h"
#include "sm_srvcmds.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"
@ -118,7 +118,7 @@ void CheckAndFinalizeConfigs()
void CoreConfig::OnSourceModAllInitialized() 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_pOnServerCfg = forwardsys->CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
g_pOnConfigsExecuted = forwardsys->CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL); g_pOnConfigsExecuted = forwardsys->CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL);
g_pOnAutoConfigsBuffered = forwardsys->CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL); g_pOnAutoConfigsBuffered = forwardsys->CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL);
@ -134,7 +134,7 @@ CoreConfig::~CoreConfig()
void CoreConfig::OnSourceModShutdown() void CoreConfig::OnSourceModShutdown()
{ {
g_RootMenu.RemoveRootConsoleCommand("config", this); rootmenu->RemoveRootConsoleCommand("config", this);
forwardsys->ReleaseForward(g_pOnServerCfg); forwardsys->ReleaseForward(g_pOnServerCfg);
forwardsys->ReleaseForward(g_pOnConfigsExecuted); forwardsys->ReleaseForward(g_pOnConfigsExecuted);
forwardsys->ReleaseForward(g_pOnAutoConfigsBuffered); forwardsys->ReleaseForward(g_pOnAutoConfigsBuffered);
@ -198,11 +198,11 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *c
if (res == ConfigResult_Reject) 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) { } 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 { } 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; return;
@ -213,15 +213,15 @@ void CoreConfig::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *c
if (value == NULL) 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 { } 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; return;
} }
g_RootMenu.ConsolePrint("[SM] Usage: sm config <option> [value]"); rootmenu->ConsolePrint("[SM] Usage: sm config <option> [value]");
} }
void CoreConfig::Initialize() void CoreConfig::Initialize()

View File

@ -35,8 +35,8 @@
#include "sourcemm_api.h" #include "sourcemm_api.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "sourcehook.h" #include "sourcehook.h"
#include "sm_srvcmds.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "compat_wrappers.h"
NextMapManager g_NextMap; NextMapManager g_NextMap;

250
core/RootConsoleMenu.cpp Normal file
View File

@ -0,0 +1,250 @@
// vim: set ts=4 sw=4 tw=99 noet :
// =============================================================================
// SourceMod
// Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
// =============================================================================
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License, version 3.0, as published by the
// Free Software Foundation.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, AlliedModders LLC gives you permission to link the
// code of this program (as well as its derivative works) to "Half-Life 2," the
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
// by the Valve Corporation. You must obey the GNU General Public License in
// all respects for all other code used. Additionally, AlliedModders LLC grants
// this exception to all derivative works. AlliedModders LLC defines further
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
// or <http://www.sourcemod.net/license.php>.
#include "RootConsoleMenu.h"
#include "sm_stringutil.h"
#include "CoreConfig.h"
#include "ConVarManager.h"
#include "logic_bridge.h"
#include <sourcemod_version.h>
RootConsoleMenu g_RootMenu;
IRootConsole *rootmenu = &g_RootMenu;
RootConsoleMenu::RootConsoleMenu()
{
}
RootConsoleMenu::~RootConsoleMenu()
{
List<ConsoleEntry *>::iterator iter;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{
delete (*iter);
}
m_Menu.clear();
}
void RootConsoleMenu::OnSourceModStartup(bool late)
{
AddRootConsoleCommand3("version", "Display version information", this);
AddRootConsoleCommand3("credits", "Display credits listing", this);
}
void RootConsoleMenu::OnSourceModAllInitialized()
{
sharesys->AddInterface(NULL, this);
}
void RootConsoleMenu::OnSourceModShutdown()
{
RemoveRootConsoleCommand("credits", this);
RemoveRootConsoleCommand("version", this);
}
void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
{
char buffer[512];
va_list ap;
va_start(ap, fmt);
size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
if (len >= sizeof(buffer) - 1)
{
buffer[510] = '\n';
buffer[511] = '\0';
} else {
buffer[len++] = '\n';
buffer[len] = '\0';
}
META_CONPRINT(buffer);
}
bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{
return false;
}
bool RootConsoleMenu::AddRootConsoleCommand2(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{
return false;
}
bool RootConsoleMenu::AddRootConsoleCommand3(const char *cmd,
const char *text,
IRootConsoleCommand *pHandler)
{
if (m_Commands.contains(cmd))
return false;
/* Sort this into the menu */
List<ConsoleEntry *>::iterator iter = m_Menu.begin();
ConsoleEntry *pEntry;
bool inserted = false;
while (iter != m_Menu.end())
{
pEntry = (*iter);
if (strcmp(cmd, pEntry->command.c_str()) < 0)
{
ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd);
pNew->description.assign(text);
pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew);
m_Menu.insert(iter, pNew);
inserted = true;
break;
}
iter++;
}
if (!inserted)
{
ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd);
pNew->description.assign(text);
pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew);
m_Menu.push_back(pNew);
}
return true;
}
bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
{
m_Commands.remove(cmd);
List<ConsoleEntry *>::iterator iter;
ConsoleEntry *pEntry;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{
pEntry = (*iter);
if (pEntry->command.compare(cmd) == 0)
{
delete pEntry;
m_Menu.erase(iter);
break;
}
}
return true;
}
void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
{
char buffer[255];
size_t len, cmdlen = strlen(cmd);
len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd);
if (cmdlen < 16)
{
size_t num = 16 - cmdlen;
for (size_t i = 0; i < num; i++)
{
buffer[len++] = ' ';
}
len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
ConsolePrint("%s", buffer);
}
}
const char *RootConsoleMenu::GetInterfaceName()
{
return SMINTERFACE_ROOTCONSOLE_NAME;
}
unsigned int RootConsoleMenu::GetInterfaceVersion()
{
return SMINTERFACE_ROOTCONSOLE_VERSION;
}
void RootConsoleMenu::GotRootCmd(const ICommandArgs *cmd)
{
unsigned int argnum = cmd->ArgC();
if (argnum >= 2)
{
const char *cmdname = cmd->Arg(1);
ConsoleEntry *entry;
if (m_Commands.retrieve(cmdname, &entry))
{
entry->cmd->OnRootConsoleCommand(cmdname, cmd);
return;
}
}
ConsolePrint("SourceMod Menu:");
ConsolePrint("Usage: sm <command> [arguments]");
List<ConsoleEntry *>::iterator iter;
ConsoleEntry *pEntry;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{
pEntry = (*iter);
DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
}
}
void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{
if (strcmp(cmdname, "credits") == 0)
{
ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
ConsolePrint(" Development would not have been possible without the following people:");
ConsolePrint(" David \"BAILOPAN\" Anderson");
ConsolePrint(" Matt \"pRED\" Woodrow");
ConsolePrint(" Scott \"DS\" Ehlert");
ConsolePrint(" Fyren");
ConsolePrint(" Nicholas \"psychonic\" Hastings");
ConsolePrint(" Asher \"asherkin\" Baker");
ConsolePrint(" Borja \"faluco\" Ferrer");
ConsolePrint(" Pavol \"PM OnoTo\" Marko");
ConsolePrint(" Special thanks to Liam, ferret, and Mani");
ConsolePrint(" Special thanks to Viper and SteamFriends");
ConsolePrint(" http://www.sourcemod.net/");
}
else if (strcmp(cmdname, "version") == 0)
{
ConsolePrint(" SourceMod Version Information:");
ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION);
if (g_pSourcePawn2->IsJitEnabled())
ConsolePrint(" SourcePawn Engine: %s (build %s)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
else
ConsolePrint(" SourcePawn Engine: %s (build %s NO JIT)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
ConsolePrint(" SourcePawn API: v1 = %d, v2 = %d", g_pSourcePawn->GetEngineAPIVersion(), g_pSourcePawn2->GetAPIVersion());
ConsolePrint(" Compiled on: %s", SOURCEMOD_BUILD_TIME);
#if defined(SM_GENERATED_BUILD)
ConsolePrint(" Built from: https://github.com/alliedmodders/sourcemod/commit/%s", SOURCEMOD_SHA);
ConsolePrint(" Build ID: %s:%s", SOURCEMOD_LOCAL_REV, SOURCEMOD_SHA);
#endif
ConsolePrint(" http://www.sourcemod.net/");
}
}

View File

@ -1,95 +1,91 @@
/** // vim: set ts=4 sw=4 tw=99 noet :
* vim: set ts=4 sw=4 tw=99 noet : // =============================================================================
* ============================================================================= // SourceMod
* SourceMod // Copyright (C) 2004-2015 AlliedModders LLC. All rights reserved.
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved. // =============================================================================
* ============================================================================= //
* // This program is free software; you can redistribute it and/or modify it under
* This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License, version 3.0, as published by the
* the terms of the GNU General Public License, version 3.0, as published by the // Free Software Foundation.
* Free Software Foundation. //
* // This program is distributed in the hope that it will be useful, but WITHOUT
* This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // details.
* details. //
* // You should have received a copy of the GNU General Public License along with
* You should have received a copy of the GNU General Public License along with // this program. If not, see <http://www.gnu.org/licenses/>.
* this program. If not, see <http://www.gnu.org/licenses/>. //
* // As a special exception, AlliedModders LLC gives you permission to link the
* As a special exception, AlliedModders LLC gives you permission to link the // code of this program (as well as its derivative works) to "Half-Life 2," the
* code of this program (as well as its derivative works) to "Half-Life 2," the // "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software // by the Valve Corporation. You must obey the GNU General Public License in
* by the Valve Corporation. You must obey the GNU General Public License in // all respects for all other code used. Additionally, AlliedModders LLC grants
* all respects for all other code used. Additionally, AlliedModders LLC grants // this exception to all derivative works. AlliedModders LLC defines further
* this exception to all derivative works. AlliedModders LLC defines further // 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>. #ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
* #define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
* Version: $Id$
*/ #include "sourcemod.h"
#include <IRootConsoleMenu.h>
#ifndef _INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_ #include "sourcemm_api.h"
#define _INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_ #include <sh_list.h>
#include <sh_string.h>
#include "sourcemod.h" #include <compat_wrappers.h>
#include <IRootConsoleMenu.h> #include <sm_namehashset.h>
#include "sourcemm_api.h"
#include <sh_list.h> using namespace SourceMod;
#include <sh_string.h> using namespace SourceHook;
#include <compat_wrappers.h>
#include <sm_namehashset.h> struct ConsoleEntry
{
using namespace SourceMod; String command;
using namespace SourceHook; String description;
IRootConsoleCommand *cmd;
struct ConsoleEntry
{ static inline bool matches(const char *name, const ConsoleEntry *entry)
String command; {
String description; return strcmp(name, entry->command.c_str()) == 0;
IRootConsoleCommand *cmd; }
};
static inline bool matches(const char *name, const ConsoleEntry *entry)
{ class RootConsoleMenu :
return strcmp(name, entry->command.c_str()) == 0; public SMGlobalClass,
} public IRootConsoleCommand,
}; public IRootConsole
{
class RootConsoleMenu : public:
public SMGlobalClass, RootConsoleMenu();
public IRootConsoleCommand, ~RootConsoleMenu();
public IRootConsole public:
{ const char *GetInterfaceName();
public: unsigned int GetInterfaceVersion();
RootConsoleMenu(); public: //SMGlobalClass
~RootConsoleMenu(); void OnSourceModStartup(bool late);
public: void OnSourceModAllInitialized();
const char *GetInterfaceName(); void OnSourceModShutdown();
unsigned int GetInterfaceVersion(); public: //IRootConsoleCommand
public: //SMGlobalClass void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command);
void OnSourceModStartup(bool late); public: //IRootConsole
void OnSourceModAllInitialized(); bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler);
void OnSourceModShutdown(); bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler);
public: //IRootConsoleCommand void ConsolePrint(const char *fmt, ...);
void OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command); void DrawGenericOption(const char *cmd, const char *text);
public: //IRootConsole bool AddRootConsoleCommand2(const char *cmd,
bool AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler); const char *text,
bool RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler); IRootConsoleCommand *pHandler);
void ConsolePrint(const char *fmt, ...); bool AddRootConsoleCommand3(const char *cmd,
void DrawGenericOption(const char *cmd, const char *text); const char *text,
bool AddRootConsoleCommand2(const char *cmd, IRootConsoleCommand *pHandler);
const char *text, public:
IRootConsoleCommand *pHandler); void GotRootCmd(const ICommandArgs *cmd);
bool AddRootConsoleCommand3(const char *cmd, private:
const char *text, NameHashSet<ConsoleEntry *> m_Commands;
IRootConsoleCommand *pHandler); List<ConsoleEntry *> m_Menu;
public: };
void GotRootCmd(const ICommandArgs *cmd);
private: extern RootConsoleMenu g_RootMenu;
NameHashSet<ConsoleEntry *> m_Commands; extern IRootConsole *rootmenu;
List<ConsoleEntry *> m_Menu;
}; #endif // _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
extern RootConsoleMenu g_RootMenu;
#endif //_INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_

View File

@ -37,7 +37,7 @@
#include "logic/intercom.h" #include "logic/intercom.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "Logger.h" #include "Logger.h"
#include "sm_srvcmds.h" #include "RootConsoleMenu.h"
#include "TimerSys.h" #include "TimerSys.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "PlayerManager.h" #include "PlayerManager.h"

View File

@ -28,166 +28,15 @@
* *
* Version: $Id$ * Version: $Id$
*/ */
#include "sourcemod.h"
#include "sm_srvcmds.h" #include "sourcemm_api.h"
#include "sm_stringutil.h"
#include "CoreConfig.h"
#include "ConVarManager.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include <sourcemod_version.h> #include "sm_globals.h"
#include "RootConsoleMenu.h"
RootConsoleMenu g_RootMenu; #include "CoreConfig.h"
#include <compat_wrappers.h>
RootConsoleMenu::RootConsoleMenu() #include <ITranslator.h>
{ #include <amtl/am-string.h>
}
RootConsoleMenu::~RootConsoleMenu()
{
List<ConsoleEntry *>::iterator iter;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{
delete (*iter);
}
m_Menu.clear();
}
void RootConsoleMenu::OnSourceModStartup(bool late)
{
AddRootConsoleCommand3("version", "Display version information", this);
AddRootConsoleCommand3("credits", "Display credits listing", this);
}
void RootConsoleMenu::OnSourceModAllInitialized()
{
sharesys->AddInterface(NULL, this);
}
void RootConsoleMenu::OnSourceModShutdown()
{
RemoveRootConsoleCommand("credits", this);
RemoveRootConsoleCommand("version", this);
}
void RootConsoleMenu::ConsolePrint(const char *fmt, ...)
{
char buffer[512];
va_list ap;
va_start(ap, fmt);
size_t len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
if (len >= sizeof(buffer) - 1)
{
buffer[510] = '\n';
buffer[511] = '\0';
} else {
buffer[len++] = '\n';
buffer[len] = '\0';
}
META_CONPRINT(buffer);
}
bool RootConsoleMenu::AddRootConsoleCommand(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{
return false;
}
bool RootConsoleMenu::AddRootConsoleCommand2(const char *cmd, const char *text, IRootConsoleCommand *pHandler)
{
return false;
}
bool RootConsoleMenu::AddRootConsoleCommand3(const char *cmd,
const char *text,
IRootConsoleCommand *pHandler)
{
if (m_Commands.contains(cmd))
return false;
/* Sort this into the menu */
List<ConsoleEntry *>::iterator iter = m_Menu.begin();
ConsoleEntry *pEntry;
bool inserted = false;
while (iter != m_Menu.end())
{
pEntry = (*iter);
if (strcmp(cmd, pEntry->command.c_str()) < 0)
{
ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd);
pNew->description.assign(text);
pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew);
m_Menu.insert(iter, pNew);
inserted = true;
break;
}
iter++;
}
if (!inserted)
{
ConsoleEntry *pNew = new ConsoleEntry;
pNew->command.assign(cmd);
pNew->description.assign(text);
pNew->cmd = pHandler;
m_Commands.insert(cmd, pNew);
m_Menu.push_back(pNew);
}
return true;
}
bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
{
m_Commands.remove(cmd);
List<ConsoleEntry *>::iterator iter;
ConsoleEntry *pEntry;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{
pEntry = (*iter);
if (pEntry->command.compare(cmd) == 0)
{
delete pEntry;
m_Menu.erase(iter);
break;
}
}
return true;
}
void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
{
char buffer[255];
size_t len, cmdlen = strlen(cmd);
len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd);
if (cmdlen < 16)
{
size_t num = 16 - cmdlen;
for (size_t i = 0; i < num; i++)
{
buffer[len++] = ' ';
}
len += snprintf(&buffer[len], sizeof(buffer) - len, " - %s", text);
ConsolePrint("%s", buffer);
}
}
const char *RootConsoleMenu::GetInterfaceName()
{
return SMINTERFACE_ROOTCONSOLE_NAME;
}
unsigned int RootConsoleMenu::GetInterfaceVersion()
{
return SMINTERFACE_ROOTCONSOLE_VERSION;
}
#if SOURCE_ENGINE==SE_EPISODEONE || SOURCE_ENGINE==SE_DARKMESSIAH #if SOURCE_ENGINE==SE_EPISODEONE || SOURCE_ENGINE==SE_DARKMESSIAH
class CCommandArgs : public ICommandArgs class CCommandArgs : public ICommandArgs
@ -232,95 +81,37 @@ public:
}; };
#endif #endif
void RootConsoleMenu::GotRootCmd(const ICommandArgs *cmd)
{
unsigned int argnum = cmd->ArgC();
if (argnum >= 2)
{
const char *cmdname = cmd->Arg(1);
if (strcmp(cmdname, "internal") == 0)
{
if (argnum >= 3)
{
const char *arg = cmd->Arg(2);
if (strcmp(arg, "1") == 0)
{
SM_ConfigsExecuted_Global();
}
else if (strcmp(arg, "2") == 0)
{
if (argnum >= 4)
{
SM_ConfigsExecuted_Plugin(atoi(cmd->Arg(3)));
}
}
}
return;
}
ConsoleEntry *entry;
if (m_Commands.retrieve(cmdname, &entry))
{
entry->cmd->OnRootConsoleCommand(cmdname, cmd);
return;
}
}
ConsolePrint("SourceMod Menu:");
ConsolePrint("Usage: sm <command> [arguments]");
List<ConsoleEntry *>::iterator iter;
ConsoleEntry *pEntry;
for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
{
pEntry = (*iter);
DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str());
}
}
void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{
if (strcmp(cmdname, "credits") == 0)
{
ConsolePrint(" SourceMod was developed by AlliedModders, LLC.");
ConsolePrint(" Development would not have been possible without the following people:");
ConsolePrint(" David \"BAILOPAN\" Anderson");
ConsolePrint(" Matt \"pRED\" Woodrow");
ConsolePrint(" Scott \"DS\" Ehlert");
ConsolePrint(" Fyren");
ConsolePrint(" Nicholas \"psychonic\" Hastings");
ConsolePrint(" Asher \"asherkin\" Baker");
ConsolePrint(" Borja \"faluco\" Ferrer");
ConsolePrint(" Pavol \"PM OnoTo\" Marko");
ConsolePrint(" Special thanks to Liam, ferret, and Mani");
ConsolePrint(" Special thanks to Viper and SteamFriends");
ConsolePrint(" http://www.sourcemod.net/");
}
else if (strcmp(cmdname, "version") == 0)
{
ConsolePrint(" SourceMod Version Information:");
ConsolePrint(" SourceMod Version: %s", SOURCEMOD_VERSION);
if (g_pSourcePawn2->IsJitEnabled())
ConsolePrint(" SourcePawn Engine: %s (build %s)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
else
ConsolePrint(" SourcePawn Engine: %s (build %s NO JIT)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString());
ConsolePrint(" SourcePawn API: v1 = %d, v2 = %d", g_pSourcePawn->GetEngineAPIVersion(), g_pSourcePawn2->GetAPIVersion());
ConsolePrint(" Compiled on: %s", SOURCEMOD_BUILD_TIME);
#if defined(SM_GENERATED_BUILD)
ConsolePrint(" Built from: https://github.com/alliedmodders/sourcemod/commit/%s", SOURCEMOD_SHA);
ConsolePrint(" Build ID: %s:%s", SOURCEMOD_LOCAL_REV, SOURCEMOD_SHA);
#endif
ConsolePrint(" http://www.sourcemod.net/");
}
}
CON_COMMAND(sm, "SourceMod Menu") CON_COMMAND(sm, "SourceMod Menu")
{ {
#if SOURCE_ENGINE <= SE_DARKMESSIAH #if SOURCE_ENGINE <= SE_DARKMESSIAH
CCommand args; CCommand args;
#endif #endif
CCommandArgs cargs(args); CCommandArgs cargs(args);
if (cargs.ArgC() >= 2) {
const char *cmdname = cargs.Arg(1);
if (strcmp(cmdname, "internal") == 0)
{
if (cargs.ArgC() >= 3)
{
const char *arg = cargs.Arg(2);
if (strcmp(arg, "1") == 0)
{
SM_ConfigsExecuted_Global();
}
else if (strcmp(arg, "2") == 0)
{
if (cargs.ArgC() >= 4)
{
SM_ConfigsExecuted_Plugin(atoi(cargs.Arg(3)));
}
}
}
return;
}
}
g_RootMenu.GotRootCmd(&cargs); g_RootMenu.GotRootCmd(&cargs);
} }
@ -343,7 +134,7 @@ void write_handles_to_game(const char *fmt, ...)
char buffer[1024]; char buffer[1024];
va_start(ap, fmt); va_start(ap, fmt);
len = UTIL_FormatArgs(buffer, sizeof(buffer)-2, fmt, ap); len = ke::SafeSprintf(buffer, sizeof(buffer)-2, fmt, ap);
va_end(ap); va_end(ap);
buffer[len] = '\n'; buffer[len] = '\n';
@ -359,7 +150,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)
{ {
g_RootMenu.ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs"); rootmenu->ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
return; return;
} }
@ -372,7 +163,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)
{ {
g_RootMenu.ConsolePrint("Failed to open \"%s\" for writing", filename); rootmenu->ConsolePrint("Failed to open \"%s\" for writing", filename);
return; return;
} }
@ -400,10 +191,10 @@ CON_COMMAND(sm_dump_admcache, "Dumps the admin cache for debugging")
if (!logicore.DumpAdminCache(buffer)) if (!logicore.DumpAdminCache(buffer))
{ {
g_RootMenu.ConsolePrint("Could not open file for writing: %s", buffer); rootmenu->ConsolePrint("Could not open file for writing: %s", buffer);
return; return;
} }
g_RootMenu.ConsolePrint("Admin cache dumped to: %s", buffer); rootmenu->ConsolePrint("Admin cache dumped to: %s", buffer);
} }