Move RootConsoleMenu into its own header and .cpp file.
This commit is contained in:
parent
9d805ea9fb
commit
2c886943a0
@ -41,6 +41,7 @@ project.sources += [
|
||||
'ConsoleDetours.cpp',
|
||||
'vprof_tool.cpp',
|
||||
'smn_commandline.cpp',
|
||||
'RootConsoleMenu.cpp',
|
||||
]
|
||||
|
||||
for sdk_name in SM.sdks:
|
||||
|
@ -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 <plugin #>");
|
||||
rootmenu->ConsolePrint("[SM] Usage: sm cmds <plugin #>");
|
||||
}
|
||||
|
@ -29,11 +29,11 @@
|
||||
|
||||
#include "ConVarManager.h"
|
||||
#include "HalfLife2.h"
|
||||
#include "sm_srvcmds.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include <sh_vector.h>
|
||||
#include <sm_namehashset.h>
|
||||
#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<ConVar *>(*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] <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)
|
||||
|
@ -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 <option> [value]");
|
||||
rootmenu->ConsolePrint("[SM] Usage: sm config <option> [value]");
|
||||
}
|
||||
|
||||
void CoreConfig::Initialize()
|
||||
|
@ -35,8 +35,8 @@
|
||||
#include "sourcemm_api.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "sourcehook.h"
|
||||
#include "sm_srvcmds.h"
|
||||
#include "logic_bridge.h"
|
||||
#include "compat_wrappers.h"
|
||||
|
||||
NextMapManager g_NextMap;
|
||||
|
||||
|
250
core/RootConsoleMenu.cpp
Normal file
250
core/RootConsoleMenu.cpp
Normal 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/");
|
||||
}
|
||||
}
|
@ -1,36 +1,31 @@
|
||||
/**
|
||||
* 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>.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_
|
||||
#define _INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_
|
||||
// vim: set ts=4 sw=4 tw=99 noet :
|
||||
// =============================================================================
|
||||
// SourceMod
|
||||
// Copyright (C) 2004-2015 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>.
|
||||
#ifndef _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
|
||||
#define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
|
||||
|
||||
#include "sourcemod.h"
|
||||
#include <IRootConsoleMenu.h>
|
||||
@ -91,5 +86,6 @@ private:
|
||||
};
|
||||
|
||||
extern RootConsoleMenu g_RootMenu;
|
||||
extern IRootConsole *rootmenu;
|
||||
|
||||
#endif //_INCLUDE_SOURCEMOD_SERVERCOMMANDS_H_
|
||||
#endif // _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
|
@ -37,7 +37,7 @@
|
||||
#include "logic/intercom.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "Logger.h"
|
||||
#include "sm_srvcmds.h"
|
||||
#include "RootConsoleMenu.h"
|
||||
#include "TimerSys.h"
|
||||
#include "logic_bridge.h"
|
||||
#include "PlayerManager.h"
|
||||
|
@ -28,166 +28,15 @@
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include "sm_srvcmds.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include "CoreConfig.h"
|
||||
#include "ConVarManager.h"
|
||||
#include "sourcemod.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include "logic_bridge.h"
|
||||
#include <sourcemod_version.h>
|
||||
|
||||
RootConsoleMenu 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;
|
||||
}
|
||||
#include "sm_globals.h"
|
||||
#include "RootConsoleMenu.h"
|
||||
#include "CoreConfig.h"
|
||||
#include <compat_wrappers.h>
|
||||
#include <ITranslator.h>
|
||||
#include <amtl/am-string.h>
|
||||
|
||||
#if SOURCE_ENGINE==SE_EPISODEONE || SOURCE_ENGINE==SE_DARKMESSIAH
|
||||
class CCommandArgs : public ICommandArgs
|
||||
@ -232,95 +81,37 @@ public:
|
||||
};
|
||||
#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")
|
||||
{
|
||||
#if SOURCE_ENGINE <= SE_DARKMESSIAH
|
||||
CCommand args;
|
||||
#endif
|
||||
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);
|
||||
}
|
||||
|
||||
@ -343,7 +134,7 @@ void write_handles_to_game(const char *fmt, ...)
|
||||
char buffer[1024];
|
||||
|
||||
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);
|
||||
|
||||
buffer[len] = '\n';
|
||||
@ -359,7 +150,7 @@ CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle le
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
|
||||
@ -372,7 +163,7 @@ CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle le
|
||||
FILE *fp = fopen(filename, "wt");
|
||||
if (!fp)
|
||||
{
|
||||
g_RootMenu.ConsolePrint("Failed to open \"%s\" for writing", filename);
|
||||
rootmenu->ConsolePrint("Failed to open \"%s\" for writing", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -400,10 +191,10 @@ CON_COMMAND(sm_dump_admcache, "Dumps the admin cache for debugging")
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
g_RootMenu.ConsolePrint("Admin cache dumped to: %s", buffer);
|
||||
rootmenu->ConsolePrint("Admin cache dumped to: %s", buffer);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user