Merge pull request #400 from alliedmodders/mv-srvcmds-x

Remove sm_srvcmds.cpp.
This commit is contained in:
David Anderson 2015-09-20 15:15:43 -07:00
commit d551338510
15 changed files with 184 additions and 191 deletions

View File

@ -35,7 +35,7 @@ namespace SourceMod {
// Add 1 to the RHS of this expression to bump the intercom file
// This is to prevent mismatching core/logic binaries
static const uint32_t SM_LOGIC_MAGIC = 0x0F47C0DE - 50;
static const uint32_t SM_LOGIC_MAGIC = 0x0F47C0DE - 54;
} // namespace SourceMod

View File

@ -30,6 +30,7 @@
#include <stddef.h>
#include <stdint.h>
#include <IAdminSystem.h>
#include <amtl/am-function.h>
namespace SourcePawn {
class ISourcePawnEngine;
@ -64,6 +65,9 @@ class IGameHelpers;
class IMenuManager;
struct DatabaseInfo;
class IPlayerInfoBridge;
class ICommandArgs;
typedef ke::Lambda<bool(int client, const ICommandArgs*)> CommandFunc;
class CoreProvider
{
@ -92,6 +96,9 @@ public:
virtual const char *GetCvarString(ConVar *cvar) = 0;
virtual bool GetCvarBool(ConVar* cvar) = 0;
// Command functions.
virtual void DefineCommand(const char *cmd, const char *help, const CommandFunc &callback) = 0;
// Game description functions.
virtual bool GetGameName(char *buffer, size_t maxlength) = 0;
virtual const char *GetGameDescription() = 0;
@ -105,6 +112,7 @@ public:
virtual bool DescribePlayer(int index, const char **namep, const char **authp, int *useridp) = 0;
virtual void LogToGame(const char *message) = 0;
virtual void ConPrint(const char *message) = 0;
virtual void ConsolePrint(const char *fmt, ...) = 0;
virtual void ConsolePrintVa(const char *fmt, va_list ap) = 0;
// Game engine helper functions.

View File

@ -68,10 +68,7 @@ struct sm_logic_t
IDebugListener *debugger;
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
void (*AddNatives)(sp_nativeinfo_t *natives);
void (*DumpHandles)(void (*dumpfn)(const char *fmt, ...));
bool (*DumpAdminCache)(const char *filename);
void (*RegisterProfiler)(IProfilingTool *tool);
void (*OnRootCommand)(const ICommandArgs *args);
IDataPack * (*CreateDataPack)();
void (*FreeDataPack)(IDataPack *pack);
IScriptManager *scripts;

View File

@ -36,7 +36,6 @@ project.sources += [
'EventManager.cpp',
'MenuStyle_Radio.cpp',
'sm_autonatives.cpp',
'sm_srvcmds.cpp',
'ConsoleDetours.cpp',
'vprof_tool.cpp',
'smn_commandline.cpp',

View File

@ -534,7 +534,7 @@ void SM_ExecuteForPlugin(IPluginContext *ctx)
can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
}
char cmd[255];
ke::SafeSprintf(cmd, sizeof(cmd), "sm internal 2 %d\n", plugin->GetSerial());
ke::SafeSprintf(cmd, sizeof(cmd), "sm_internal 2 %d\n", plugin->GetSerial());
engine->ServerCommand(cmd);
}
}
@ -581,7 +581,24 @@ void SM_InternalCmdTrigger()
{
/* Order is important here. We need to buffer things before we send the command out. */
g_pOnAutoConfigsBuffered->Execute(NULL);
engine->ServerCommand("sm internal 1\n");
engine->ServerCommand("sm_internal 1\n");
g_PendingInternalPush = false;
}
CON_COMMAND(sm_internal, "")
{
#if SOURCE_ENGINE <= SE_DARKMESSIAH
CCommand args;
#endif
if (args.ArgC() < 1)
return;
const char *arg = args.Arg(1);
if (strcmp(arg, "1") == 0) {
SM_ConfigsExecuted_Global();
} else if (strcmp(arg, "2") == 0) {
if (args.ArgC() >= 3)
SM_ConfigsExecuted_Plugin(atoi(args.Arg(2)));
}
}

View File

@ -271,6 +271,21 @@ void AdminCache::OnSourceModStartup(bool late)
NameFlag("custom4", Admin_Custom4);
NameFlag("custom5", Admin_Custom5);
NameFlag("custom6", Admin_Custom6);
auto sm_dump_admcache = [this] (int client, const ICommandArgs *args) -> bool {
char buffer[PLATFORM_MAX_PATH];
g_pSM->BuildPath(Path_SM, buffer, sizeof(buffer), "data/admin_cache_dump.txt");
if (!DumpCache(buffer)) {
bridge->ConsolePrint("Could not open file for writing: %s", buffer);
return true;
}
bridge->ConsolePrint("Admin cache dumped to: %s", buffer);
return true;
};
bridge->DefineCommand("sm_dump_admcache", "Dumps the admin cache for debugging", sm_dump_admcache);
}
void AdminCache::OnSourceModAllInitialized()

View File

@ -1066,11 +1066,23 @@ bool HandleSystem::TryAndFreeSomeHandles()
return scripts->UnloadPlugin(highest_owner);
}
void HandleSystem::Dump(HANDLE_REPORTER rep)
static void rep(const HandleReporter &fn, const char *fmt, ...)
{
va_list ap;
char buffer[1024];
va_start(ap, fmt);
ke::SafeVsprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
fn(buffer);
}
void HandleSystem::Dump(const HandleReporter &fn)
{
unsigned int total_size = 0;
rep("%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
rep("--------------------------------------------------------------------------");
rep(fn, "%-10.10s\t%-20.20s\t%-20.20s\t%-10.10s", "Handle", "Owner", "Type", "Memory");
rep(fn, "--------------------------------------------------------------------------");
for (unsigned int i = 1; i <= m_HandleTail; i++)
{
if (m_Handles[i].set != HandleSet_Used)
@ -1141,16 +1153,16 @@ void HandleSystem::Dump(HANDLE_REPORTER rep)
if (pType->dispatch->GetDispatchVersion() < HANDLESYS_MEMUSAGE_MIN_VERSION
|| !bresult)
{
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
rep(fn, "0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, "-1");
}
else
{
char buffer[32];
ke::SafeSprintf(buffer, sizeof(buffer), "%d", size);
rep("0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
rep(fn, "0x%08x\t%-20.20s\t%-20.20s\t%-10.10s", index, owner, type, buffer);
total_size += size;
}
}
rep("-- Approximately %d bytes of memory are in use by Handles.\n", total_size);
rep(fn, "-- Approximately %d bytes of memory are in use by Handles.\n", total_size);
}

View File

@ -35,7 +35,8 @@
#include <IHandleSys.h>
#include <stdio.h>
#include <sm_namehashset.h>
#include <am-string.h>
#include <amtl/am-string.h>
#include <amtl/am-function.h>
#include "common_logic.h"
#define HANDLESYS_MAX_HANDLES (1<<15)
@ -111,7 +112,7 @@ struct QHandleType
}
};
typedef void (HANDLE_REPORTER)(const char *str, ...);
typedef ke::Lambda<void(const char *)> HandleReporter;
class HandleSystem :
public IHandleSys
@ -163,7 +164,7 @@ public: //IHandleSystem
const HandleAccess *pAccess,
HandleError *err);
void Dump(HANDLE_REPORTER rep);
void Dump(const HandleReporter &reporter);
/* Bypasses security checks. */
Handle_t FastCloneHandle(Handle_t hndl);

View File

@ -27,10 +27,15 @@
#include "RootConsoleMenu.h"
#include <amtl/am-string.h>
#include <sourcemod_version.h>
#include <ISourceMod.h>
#include <bridge/include/CoreProvider.h>
#include "HandleSys.h"
RootConsoleMenu g_RootMenu;
// Some top-level commands that are just thrown in here.
static bool sm_dump_handles(int client, const ICommandArgs *args);
RootConsoleMenu::RootConsoleMenu()
{
}
@ -49,6 +54,13 @@ void RootConsoleMenu::OnSourceModStartup(bool late)
{
AddRootConsoleCommand3("version", "Display version information", this);
AddRootConsoleCommand3("credits", "Display credits listing", this);
bridge->DefineCommand("sm_dump_handles", "Dumps Handle usage to a file for finding Handle leaks",
sm_dump_handles);
bridge->DefineCommand("sm", "SourceMod Menu", [this] (int client, const ICommandArgs *args) -> bool {
GotRootCmd(args);
return true;
});
}
void RootConsoleMenu::OnSourceModAllInitialized()
@ -232,3 +244,46 @@ void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const ICommandAr
ConsolePrint(" http://www.sourcemod.net/");
}
}
static bool sm_dump_handles(int client, const ICommandArgs *args)
{
if (args->ArgC() < 2) {
bridge->ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
return true;
}
if (strcmp(args->Arg(1), "log") == 0) {
auto write_handles_to_game = [] (const char *str) -> void
{
char buffer[1024];
size_t len = ke::SafeSprintf(buffer, sizeof(buffer)-2, "%s", str);
buffer[len] = '\n';
buffer[len+1] = '\0';
bridge->LogToGame(buffer);
};
g_HandleSys.Dump(write_handles_to_game);
return true;
}
FILE *fp = nullptr;
auto write_handles_to_log = [&fp] (const char *str) -> void
{
fprintf(fp, "%s\n", str);
};
char filename[PLATFORM_MAX_PATH];
const char *arg = args->Arg(1);
g_pSM->BuildPath(Path_Game, filename, sizeof(filename), "%s", arg);
fp = fopen(filename, "wt");
if (!fp) {
bridge->ConsolePrint("Failed to open \"%s\" for writing", filename);
return true;
}
g_HandleSys.Dump(write_handles_to_log);
fclose(fp);
return true;
}

View File

@ -749,6 +749,13 @@ void Translator::OnSourceModAllInitialized()
g_pCorePhrases->AddPhraseFile("core.phrases");
sharesys->AddInterface(NULL, this);
auto sm_reload_translations = [this] (int client, const ICommandArgs *args) -> bool {
RebuildLanguageDatabase();
return true;
};
bridge->DefineCommand("sm_reload_translations", "Reparses all loaded translation files",
sm_reload_translations);
}
void Translator::OnSourceModShutdown()

View File

@ -109,26 +109,11 @@ static void AddNatives(sp_nativeinfo_t *natives)
g_CoreNatives.AddNatives(natives);
}
static void DumpHandles(void (*dumpfn)(const char *fmt, ...))
{
g_HandleSys.Dump(dumpfn);
}
static bool DumpAdminCache(const char *filename)
{
return g_Admins.DumpCache(filename);
}
static void RegisterProfiler(IProfilingTool *tool)
{
g_ProfileToolManager.RegisterTool(tool);
}
static void OnRootCommand(const ICommandArgs *args)
{
g_RootMenu.GotRootCmd(args);
}
// Defined in smn_filesystem.cpp.
extern bool OnLogPrint(const char *msg);
@ -159,10 +144,7 @@ static sm_logic_t logic =
&g_DbgReporter,
GenerateError,
AddNatives,
DumpHandles,
DumpAdminCache,
RegisterProfiler,
OnRootCommand,
CDataPack::New,
CDataPack::Free,
&g_PluginSys,

View File

@ -564,6 +564,14 @@ void CoreProviderImpl::ConPrint(const char *message)
META_CONPRINT(message);
}
void CoreProviderImpl::ConsolePrint(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
UTIL_ConsolePrintVa(fmt, ap);
va_end(ap);
}
void CoreProviderImpl::ConsolePrintVa(const char *message, va_list ap)
{
UTIL_ConsolePrintVa(message, ap);
@ -754,6 +762,39 @@ CoreProviderImpl::AddPostCommandHook(ConCommand *cmd, const CommandHook::Callbac
return hooks_.AddPostCommandHook(cmd, callback);
}
CoreProviderImpl::CommandImpl::CommandImpl(ConCommand *cmd, CommandHook *hook)
: cmd_(cmd),
hook_(hook)
{
}
CoreProviderImpl::CommandImpl::~CommandImpl()
{
hook_ = nullptr;
g_SMAPI->UnregisterConCommandBase(g_PLAPI, cmd_);
delete [] const_cast<char *>(cmd_->GetHelpText());
delete [] const_cast<char *>(cmd_->GetName());
delete cmd_;
}
void
CoreProviderImpl::DefineCommand(const char *name, const char *help, const CommandFunc &callback)
{
char *new_name = sm_strdup(name);
char *new_help = sm_strdup(help);
int flags = 0;
auto ignore_callback = [] (DISPATCH_ARGS) -> void {
};
ConCommand *cmd = new ConCommand(new_name, ignore_callback, new_help, flags);
ke::Ref<CommandHook> hook = AddCommandHook(cmd, callback);
ke::Ref<CommandImpl> impl = new CommandImpl(cmd, hook);
commands_.append(impl);
}
void CoreProviderImpl::InitializeHooks()
{
hooks_.Start();
@ -766,6 +807,7 @@ void CoreProviderImpl::OnVSPReceived()
void CoreProviderImpl::ShutdownHooks()
{
commands_.clear();
hooks_.Shutdown();
}

View File

@ -59,11 +59,13 @@ public:
bool DescribePlayer(int index, const char **namep, const char **authp, int *useridp) override;
void LogToGame(const char *message) override;
void ConPrint(const char *message) override;
void ConsolePrint(const char *fmt, ...) override;
void ConsolePrintVa(const char *fmt, va_list ap) override;
int LoadMMSPlugin(const char *file, bool *ok, char *error, size_t maxlength) override;
void UnloadMMSPlugin(int id) override;
int QueryClientConVar(int client, const char *cvar) override;
bool IsClientConVarQueryingSupported() override;
void DefineCommand(const char *cmd, const char *help, const SourceMod::CommandFunc &callback) override;
ke::PassRef<CommandHook> AddCommandHook(ConCommand *cmd, const CommandHook::Callback &callback);
ke::PassRef<CommandHook> AddPostCommandHook(ConCommand *cmd, const CommandHook::Callback &callback);
@ -76,6 +78,18 @@ private:
ke::Ref<ke::SharedLib> logic_;
LogicInitFunction logic_init_;
GameHooks hooks_;
struct CommandImpl : public ke::Refcounted<CommandImpl>
{
public:
CommandImpl(ConCommand *cmd, CommandHook *hook);
~CommandImpl();
private:
ConCommand *cmd_;
ke::Ref<CommandHook> hook_;
};
ke::Vector<ke::Ref<CommandImpl>> commands_;
};
extern CoreProviderImpl sCoreProviderImpl;

View File

@ -1,156 +0,0 @@
/**
* 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$
*/
#include "sourcemod.h"
#include "sourcemm_api.h"
#include "logic_bridge.h"
#include "sm_globals.h"
#include "CoreConfig.h"
#include "command_args.h"
#include <ITranslator.h>
#include <amtl/am-string.h>
CON_COMMAND(sm, "SourceMod Menu")
{
#if SOURCE_ENGINE <= SE_DARKMESSIAH
CCommand args;
#endif
EngineArgs 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;
}
}
logicore.OnRootCommand(&cargs);
}
FILE *g_pHndlLog = NULL;
void write_handles_to_log(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(g_pHndlLog, fmt, ap);
fprintf(g_pHndlLog, "\n");
va_end(ap);
}
void write_handles_to_game(const char *fmt, ...)
{
size_t len;
va_list ap;
char buffer[1024];
va_start(ap, fmt);
len = ke::SafeSprintf(buffer, sizeof(buffer)-2, fmt, ap);
va_end(ap);
buffer[len] = '\n';
buffer[len+1] = '\0';
engine->LogPrint(buffer);
}
CON_COMMAND(sm_dump_handles, "Dumps Handle usage to a file for finding Handle leaks")
{
#if SOURCE_ENGINE <= SE_DARKMESSIAH
CCommand args;
#endif
if (args.ArgC() < 2)
{
UTIL_ConsolePrint("Usage: sm_dump_handles <file> or <log> for game logs");
return;
}
if (strcmp(args.Arg(1), "log") != 0)
{
char filename[PLATFORM_MAX_PATH];
const char *arg = args.Arg(1);
g_SourceMod.BuildPath(Path_Game, filename, sizeof(filename), "%s", arg);
FILE *fp = fopen(filename, "wt");
if (!fp)
{
UTIL_ConsolePrint("Failed to open \"%s\" for writing", filename);
return;
}
g_pHndlLog = fp;
logicore.DumpHandles(write_handles_to_log);
g_pHndlLog = NULL;
fclose(fp);
}
else
{
logicore.DumpHandles(write_handles_to_game);
}
}
CON_COMMAND(sm_reload_translations, "Reparses all loaded translation files")
{
translator->RebuildLanguageDatabase();
}
CON_COMMAND(sm_dump_admcache, "Dumps the admin cache for debugging")
{
char buffer[PLATFORM_MAX_PATH];
g_SourceMod.BuildPath(Path_SM, buffer, sizeof(buffer), "data/admin_cache_dump.txt");
if (!logicore.DumpAdminCache(buffer))
{
UTIL_ConsolePrint("Could not open file for writing: %s", buffer);
return;
}
UTIL_ConsolePrint("Admin cache dumped to: %s", buffer);
}

@ -1 +1 @@
Subproject commit c4c2aa3e97157407c3832b40fed43ba9cd24a2c1
Subproject commit 298217cbbfac16851bb58574bc6744f58b260b15