2007-10-04 22:15:25 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* ======================================================
|
|
|
|
* Metamod:Source
|
|
|
|
* Copyright (C) 2004-2007 AlliedModders LLC and authors.
|
|
|
|
* All rights reserved.
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
* In no event will the authors be held liable for any damages arising from
|
|
|
|
* the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely, subject to the following restrictions:
|
2007-02-10 01:31:34 +01:00
|
|
|
*
|
2007-10-04 22:15:25 +02:00
|
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
* claim that you wrote the original software. If you use this software in a
|
|
|
|
* product, an acknowledgment in the product documentation would be
|
|
|
|
* appreciated but is not required.
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
* misrepresented as being the original software.
|
|
|
|
* 3. This notice may not be removed or altered from any source distribution.
|
2007-02-10 01:31:34 +01:00
|
|
|
*
|
2007-10-04 22:15:25 +02:00
|
|
|
* Version: $Id$
|
2007-02-10 01:31:34 +01:00
|
|
|
*/
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-12-14 05:32:47 +01:00
|
|
|
#include "metamod_oslink.h"
|
2007-10-04 22:15:25 +02:00
|
|
|
#if defined _DEBUG
|
|
|
|
#define DEBUG2
|
|
|
|
#undef _DEBUG
|
|
|
|
#endif
|
2005-05-26 10:06:23 +02:00
|
|
|
#include <ctype.h>
|
2007-10-04 22:15:25 +02:00
|
|
|
#include "metamod.h"
|
|
|
|
#include "metamod_util.h"
|
|
|
|
#include "metamod_console.h"
|
|
|
|
#include "metamod_plugins.h"
|
|
|
|
#if defined DEBUG2
|
|
|
|
#undef DEBUG2
|
|
|
|
#define _DEBUG
|
|
|
|
#endif
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
using namespace SourceMM;
|
|
|
|
using namespace SourceHook;
|
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
/**
|
|
|
|
* @brief Console Command Implementations
|
|
|
|
* @file concommands.cpp
|
|
|
|
*/
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
#define CONMSG g_Metamod.ConPrintf
|
|
|
|
#define CLIENT_CONMSG g_Metamod.ClientConPrintf
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
bool Command_Meta(IMetamodSourceCommandInfo *info)
|
2005-04-16 21:59:26 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
unsigned int args = info->GetArgCount();
|
2005-05-16 22:15:57 +02:00
|
|
|
|
2007-12-14 05:32:47 +01:00
|
|
|
if (provider->IsAlternatelyLoaded() && !g_Metamod.IsAlternateLoadComplete())
|
|
|
|
{
|
|
|
|
CONMSG("You must change the map to activate Metamod:Source.\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
if (args >= 1)
|
2005-09-24 23:10:53 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
const char *command = info->GetArg(1);
|
2005-04-16 21:59:26 +02:00
|
|
|
if (strcmp(command, "credits") == 0)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Metamod:Source was developed by:\n");
|
|
|
|
CONMSG(" SourceHook: Pavol \"PM OnoTo\" Marko\n");
|
|
|
|
CONMSG(" GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
|
|
|
|
CONMSG(" GameDLL: Scott \"Damaged Soul\" Ehlert\n");
|
|
|
|
CONMSG("For more information, see the official website\n");
|
|
|
|
CONMSG("http://www.sourcemm.net/\n");
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "version") == 0)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
|
|
|
|
CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
|
2007-10-08 20:47:31 +02:00
|
|
|
CONMSG("Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
|
2007-10-08 19:22:57 +02:00
|
|
|
CONMSG("SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("http://www.sourcemm.net/\n");
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "game") == 0)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("GameDLL Information\n");
|
2007-10-04 22:15:25 +02:00
|
|
|
CONMSG(" Description: %s\n", provider->GetGameDescription());
|
|
|
|
CONMSG(" Mod Path: %s\n", g_Metamod.GetBaseDir());
|
|
|
|
CONMSG(" DLL Path: %s\n", g_Metamod.GetGameBinaryPath());
|
|
|
|
CONMSG(" Interface: ServerGameDLL%03d\n", g_Metamod.GetGameDLLVersion());
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-10-06 19:01:35 +02:00
|
|
|
int engine = g_Metamod.GetSourceEngineBuild();
|
|
|
|
if (engine == SOURCE_ENGINE_ORIGINAL)
|
|
|
|
{
|
|
|
|
CONMSG(" Engine: Original (pre-Episode 1)\n");
|
|
|
|
}
|
|
|
|
else if (engine == SOURCE_ENGINE_EPISODEONE)
|
|
|
|
{
|
|
|
|
CONMSG(" Engine: Episode 1 (2004)\n");
|
|
|
|
}
|
|
|
|
else if (engine == SOURCE_ENGINE_ORANGEBOX)
|
|
|
|
{
|
|
|
|
CONMSG(" Engine: Episode 2 (Orange Box, 2007)\n");
|
|
|
|
}
|
|
|
|
|
2007-02-21 02:51:54 +01:00
|
|
|
// Display user messages
|
2007-10-04 22:15:25 +02:00
|
|
|
int messages = g_Metamod.GetUserMessageCount();
|
|
|
|
if (messages != -1)
|
2007-02-21 02:51:54 +01:00
|
|
|
{
|
|
|
|
const char *msgname;
|
|
|
|
int msgsize;
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
if (messages > 0)
|
2007-02-21 02:51:54 +01:00
|
|
|
{
|
|
|
|
CONMSG(" User Messages: %-32.31s %-5s %-5s\n", "Name", "Index", "Size");
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
for (int i = 0; i < messages; i++)
|
2007-02-21 02:51:54 +01:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
msgname = g_Metamod.GetUserMessage(i, &msgsize);
|
2007-02-21 02:51:54 +01:00
|
|
|
|
|
|
|
CONMSG(" %-32.31s %-5d %-5d\n", msgname, i, msgsize);
|
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
CONMSG(" %d user message%s in total\n", messages, (messages > 1) ? "s" : "");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-21 02:51:54 +01:00
|
|
|
CONMSG(" User Messages: None\n");
|
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-21 02:51:54 +01:00
|
|
|
CONMSG(" User Messages: Failed to get list of user messages\n");
|
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "refresh") == 0)
|
|
|
|
{
|
2005-04-16 21:59:26 +02:00
|
|
|
char full_path[255];
|
2007-10-04 22:15:25 +02:00
|
|
|
g_Metamod.PathFormat(full_path,
|
|
|
|
sizeof(full_path),
|
|
|
|
"%s/%s",
|
|
|
|
g_Metamod.GetBaseDir(),
|
|
|
|
g_Metamod.GetPluginsFile());
|
2006-04-21 03:58:22 +02:00
|
|
|
|
2005-04-16 21:59:26 +02:00
|
|
|
LoadPluginsFromFile(full_path);
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "list") == 0)
|
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
CPluginManager::CPlugin *pl;
|
|
|
|
ISmmPlugin *plapi;
|
|
|
|
const char *plname;
|
2005-04-16 21:59:26 +02:00
|
|
|
PluginIter i;
|
2007-08-11 01:43:16 +02:00
|
|
|
char buffer[256];
|
|
|
|
int len;
|
|
|
|
int plnum = g_PluginMngr.GetPluginCount();
|
|
|
|
|
|
|
|
if (!plnum)
|
|
|
|
{
|
|
|
|
CONMSG("No plugins loaded.\n");
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2007-08-11 01:43:16 +02:00
|
|
|
} else {
|
|
|
|
CONMSG("Listing %d plugin%s:\n", plnum, (plnum > 1) ? "s" : "");
|
|
|
|
}
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++)
|
2005-04-16 21:59:26 +02:00
|
|
|
{
|
|
|
|
pl = (*i);
|
|
|
|
if (!pl)
|
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
break;
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
2005-04-17 05:37:50 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
len = 0;
|
|
|
|
|
|
|
|
if (pl->m_Status != Pl_Running)
|
2005-04-17 05:37:50 +02:00
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
len += UTIL_Format(buffer, sizeof(buffer), " [%02d] <%s>", pl->m_Id, g_PluginMngr.GetStatusText(pl));
|
2005-04-17 05:37:50 +02:00
|
|
|
} else {
|
2007-08-11 01:43:16 +02:00
|
|
|
len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", pl->m_Id);
|
2005-04-17 05:37:50 +02:00
|
|
|
}
|
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
if ((plapi = pl->m_API))
|
|
|
|
{
|
|
|
|
plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
|
|
|
|
len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
|
2005-04-17 05:37:50 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
if (IS_STR_FILLED(plapi->GetVersion()))
|
|
|
|
{
|
|
|
|
len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
|
|
|
|
}
|
|
|
|
if (IS_STR_FILLED(plapi->GetAuthor()))
|
|
|
|
{
|
|
|
|
UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 05:37:50 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
CONMSG("%s\n", buffer);
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "cmds") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-05-26 10:06:23 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2007-08-11 01:43:16 +02:00
|
|
|
CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
|
2005-05-26 10:06:23 +02:00
|
|
|
|
|
|
|
if (!pl)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d not found.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pl->m_API)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d is not loaded.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Console commands for %s:\n", pl->m_API->GetName());
|
2007-08-11 01:43:16 +02:00
|
|
|
List<ConCommandBase *>::iterator ci;
|
2005-05-26 10:06:23 +02:00
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
|
|
|
|
{
|
|
|
|
count++;
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta cmds <id>\n");
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "cvars") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-05-26 10:06:23 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2007-08-11 01:43:16 +02:00
|
|
|
CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
|
2005-05-26 10:06:23 +02:00
|
|
|
|
|
|
|
if (!pl)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d not found.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pl->m_API)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d is not loaded.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
|
2007-08-11 01:43:16 +02:00
|
|
|
List<ConCommandBase *>::iterator ci;
|
2005-05-26 10:06:23 +02:00
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
|
|
|
|
{
|
|
|
|
count++;
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta cvars <id>\n");
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "info") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-16 21:59:26 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2007-08-11 01:43:16 +02:00
|
|
|
CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
|
2005-04-16 21:59:26 +02:00
|
|
|
if (!pl)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d not found.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!pl->m_API)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d is not loaded.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-16 21:59:26 +02:00
|
|
|
if (pl->m_Status == Pl_Paused)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d is paused.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if (pl->m_Status == Pl_Running)
|
|
|
|
{
|
2005-10-06 23:59:10 +02:00
|
|
|
char run_msg[255];
|
|
|
|
bool run = false;
|
|
|
|
if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
|
2007-10-04 22:15:25 +02:00
|
|
|
{
|
2005-10-06 23:59:10 +02:00
|
|
|
run = true;
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
2005-10-06 23:59:10 +02:00
|
|
|
if (run)
|
|
|
|
{
|
|
|
|
CONMSG("Plugin %d is running.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-06 23:59:10 +02:00
|
|
|
CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
|
|
|
|
}
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG(" Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
|
|
|
|
CONMSG(" Version: %s\n", pl->m_API->GetVersion());
|
|
|
|
CONMSG(" Description: %s\n", pl->m_API->GetDescription());
|
|
|
|
CONMSG(" License: %s\n", pl->m_API->GetLicense());
|
|
|
|
CONMSG(" URL: %s\n", pl->m_API->GetURL());
|
|
|
|
CONMSG(" Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("File: %s\n\n", pl->m_File.c_str());
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta info <id>\n");
|
2005-04-16 21:59:26 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(command, "pause") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2005-04-17 05:37:50 +02:00
|
|
|
char error[255];
|
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
if (!g_PluginMngr.Pause(id, error, sizeof(error)))
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Pause failed: %s\n", error);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
2005-04-17 05:37:50 +02:00
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d has been paused.\n", id);
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta pause <id>\n");
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(command, "unpause") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2005-04-17 05:37:50 +02:00
|
|
|
char error[255];
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Unpause failed: %s\n", error);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d has been unpaused.\n", id);
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta unpause <id>\n");
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(command, "load") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
const char *file = info->GetArg(2);
|
2005-04-17 01:33:39 +02:00
|
|
|
char full_path[255];
|
|
|
|
|
2006-05-25 06:49:47 +02:00
|
|
|
const char *alias = g_PluginMngr.LookupAlias(file);
|
|
|
|
if (alias)
|
|
|
|
{
|
|
|
|
file = alias;
|
|
|
|
}
|
|
|
|
|
2005-04-17 01:33:39 +02:00
|
|
|
if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
|
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
g_Metamod.PathFormat(full_path, sizeof(full_path), "%s", file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-17 01:33:39 +02:00
|
|
|
const char *ext = UTIL_GetExtension(file);
|
|
|
|
#if defined WIN32 || defined _WIN32
|
2005-04-17 05:37:50 +02:00
|
|
|
ext = ext ? "" : ".dll";
|
2005-04-17 01:33:39 +02:00
|
|
|
#else
|
2005-04-17 05:37:50 +02:00
|
|
|
ext = ext ? "" : "_i486.so";
|
2005-04-17 01:33:39 +02:00
|
|
|
#endif
|
2007-10-04 22:15:25 +02:00
|
|
|
g_Metamod.PathFormat(full_path,
|
|
|
|
sizeof(full_path),
|
|
|
|
"%s/%s%s",
|
|
|
|
g_Metamod.GetBaseDir(),
|
|
|
|
file,
|
|
|
|
ext);
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char error[255]={0};
|
|
|
|
bool already;
|
2007-08-11 01:43:16 +02:00
|
|
|
CPluginManager::CPlugin *pl;
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
|
2005-04-17 01:33:39 +02:00
|
|
|
pl = g_PluginMngr.FindById(id);
|
|
|
|
if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Failed to load plugin %s (%s).\n", file, error);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!already)
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
|
2005-04-17 01:33:39 +02:00
|
|
|
} else {
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta load <path>\n");
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if ( (strcmp(command, "alias") == 0) ||
|
|
|
|
(strcmp(command, "aliases") == 0) )
|
|
|
|
{
|
|
|
|
if (args >= 3)
|
2006-05-25 06:49:47 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
const char *alias = info->GetArg(2);
|
|
|
|
const char *value = info->GetArg(3);
|
2006-05-25 06:49:47 +02:00
|
|
|
|
|
|
|
g_PluginMngr.SetAlias(alias, value);
|
2007-10-04 22:15:25 +02:00
|
|
|
if (value == NULL || value[0] == '\0')
|
2006-05-25 06:49:47 +02:00
|
|
|
{
|
|
|
|
CONMSG("Deleted alias: %s.\n", alias);
|
|
|
|
} else {
|
|
|
|
CONMSG("Set alias \"%s\" to: %s\n", alias, value);
|
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if (args >= 2)
|
|
|
|
{
|
|
|
|
const char *alias = info->GetArg(2);
|
2006-05-25 06:49:47 +02:00
|
|
|
const char *value = g_PluginMngr.LookupAlias(alias);
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
|
|
|
|
} else {
|
|
|
|
CONMSG("Alias \"%s\" was not found.\n", alias);
|
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
List<CNameAlias *>::iterator iter, end;
|
|
|
|
CNameAlias *p;
|
2006-05-25 06:49:47 +02:00
|
|
|
|
|
|
|
iter = g_PluginMngr._alias_begin();
|
|
|
|
end = g_PluginMngr._alias_end();
|
|
|
|
size_t total = 0;
|
|
|
|
if (iter != end)
|
|
|
|
{
|
|
|
|
CONMSG("%-10.9s %s\n", "Alias", "File");
|
|
|
|
CONMSG(" --- \n");
|
|
|
|
for (; iter!=end; iter++)
|
|
|
|
{
|
|
|
|
p = (*iter);
|
|
|
|
CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
CONMSG(" --- \n");
|
|
|
|
CONMSG("%d aliases total.\n", total);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-25 06:49:47 +02:00
|
|
|
CONMSG("No aliases found.\n");
|
|
|
|
}
|
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "unload") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
const char *file = info->GetArg(2);
|
2006-05-25 06:49:47 +02:00
|
|
|
int id = atoi(file);
|
2005-04-17 01:33:39 +02:00
|
|
|
char error[255]={0};
|
|
|
|
|
2006-05-25 06:49:47 +02:00
|
|
|
if (id == 0 && isalpha(file[0]))
|
|
|
|
{
|
|
|
|
char full_path[255];
|
|
|
|
const char *alias = g_PluginMngr.LookupAlias(file);
|
|
|
|
|
|
|
|
if (alias)
|
|
|
|
{
|
|
|
|
file = alias;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first check if it's a known filename */
|
|
|
|
if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
|
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
g_Metamod.PathFormat(full_path, sizeof(full_path), "%s", file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-25 06:49:47 +02:00
|
|
|
const char *ext = UTIL_GetExtension(file);
|
|
|
|
#if defined WIN32 || defined _WIN32
|
|
|
|
ext = ext ? "" : ".dll";
|
|
|
|
#else
|
|
|
|
ext = ext ? "" : "_i486.so";
|
|
|
|
#endif
|
2007-10-04 22:15:25 +02:00
|
|
|
g_Metamod.PathFormat(full_path,
|
|
|
|
sizeof(full_path),
|
|
|
|
"%s/%s%s",
|
|
|
|
g_Metamod.GetBaseDir(),
|
|
|
|
file,
|
|
|
|
ext);
|
2006-05-25 06:49:47 +02:00
|
|
|
}
|
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
List<CPluginManager::CPlugin *>::iterator iter, end;
|
|
|
|
CPluginManager::CPlugin *pl;
|
2006-05-25 06:49:47 +02:00
|
|
|
iter = g_PluginMngr._begin();
|
|
|
|
end = g_PluginMngr._end();
|
|
|
|
for (; iter!=end; iter++)
|
|
|
|
{
|
|
|
|
pl = (*iter);
|
|
|
|
if (strcmp(pl->m_File.c_str(), full_path) == 0)
|
|
|
|
{
|
|
|
|
id = pl->m_Id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
CONMSG("Plugin \"%s\" not found.\n", full_path);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2006-05-25 06:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Unload failed: %s\n", error);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d unloaded.\n", id);
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta unload <id>\n");
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "force_unload") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2005-04-17 01:33:39 +02:00
|
|
|
char error[255]={0};
|
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
|
2005-04-17 01:33:39 +02:00
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Force unload failed: %s\n", error);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d force unloaded.\n", id);
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta force_unload <id>\n");
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
2007-10-04 22:15:25 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(command, "clear") == 0)
|
|
|
|
{
|
2005-04-17 01:33:39 +02:00
|
|
|
if (!g_PluginMngr.UnloadAll())
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("All plugins unloaded.\n");
|
2005-04-17 01:33:39 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcmp(command, "retry") == 0)
|
|
|
|
{
|
|
|
|
if (args >= 2)
|
2005-04-17 06:21:02 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
int id = atoi(info->GetArg(2));
|
2005-04-17 06:21:02 +02:00
|
|
|
char error[255];
|
|
|
|
|
2007-03-21 18:45:28 +01:00
|
|
|
if (!g_PluginMngr.Retry(id, error, sizeof(error)))
|
2005-04-17 06:21:02 +02:00
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Error reloading plugin: %s\n", error);
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 06:21:02 +02:00
|
|
|
}
|
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Plugin %d successfully reloaded.\n", id);
|
2005-04-17 06:21:02 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Usage: meta retry <id>\n");
|
2005-04-17 06:21:02 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-04-17 06:21:02 +02:00
|
|
|
}
|
2005-04-16 21:59:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG("Metamod:Source Menu\n");
|
|
|
|
CONMSG("usage: meta <command> [arguments]\n");
|
2006-05-25 07:25:43 +02:00
|
|
|
CONMSG(" alias - List or set an alias\n");
|
2005-06-25 00:26:19 +02:00
|
|
|
CONMSG(" clear - Unload all plugins forcefully\n");
|
|
|
|
CONMSG(" cmds - Show plugin commands\n");
|
|
|
|
CONMSG(" cvars - Show plugin cvars\n");
|
|
|
|
CONMSG(" credits - About Metamod:Source\n");
|
|
|
|
CONMSG(" force_unload - Forcefully unload a plugin\n");
|
|
|
|
CONMSG(" game - Information about GameDLL\n");
|
|
|
|
CONMSG(" info - Information about a plugin\n");
|
|
|
|
CONMSG(" list - List plugins\n");
|
|
|
|
CONMSG(" load - Load a plugin\n");
|
|
|
|
CONMSG(" pause - Pause a running plugin\n");
|
|
|
|
CONMSG(" refresh - Reparse plugins file\n");
|
|
|
|
CONMSG(" retry - Attempt to reload a plugin\n");
|
|
|
|
CONMSG(" unload - Unload a loaded plugin\n");
|
|
|
|
CONMSG(" unpause - Unpause a paused plugin\n");
|
|
|
|
CONMSG(" version - Version information\n");
|
2005-05-26 10:06:23 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2005-05-26 10:06:23 +02:00
|
|
|
}
|
2005-07-07 22:58:05 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info)
|
2006-04-21 08:35:47 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
const char *cmd = info->GetArg(0);
|
2006-04-21 08:35:47 +02:00
|
|
|
|
|
|
|
if (strcmp(cmd, "meta") == 0)
|
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
unsigned int args = info->GetArgCount();
|
|
|
|
if (args == 1)
|
2006-04-21 08:35:47 +02:00
|
|
|
{
|
2007-10-04 22:15:25 +02:00
|
|
|
const char *subcmd = info->GetArg(1);
|
2006-04-21 08:35:47 +02:00
|
|
|
|
|
|
|
if (strcmp(subcmd, "credits") == 0)
|
|
|
|
{
|
|
|
|
CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
|
|
|
|
CLIENT_CONMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\n");
|
|
|
|
CLIENT_CONMSG(client, " GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
|
|
|
|
CLIENT_CONMSG(client, " GameDLL: Scott \"Damaged Soul\" Ehlert\n");
|
|
|
|
CLIENT_CONMSG(client, "For more information, see the official website\n");
|
|
|
|
CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
|
2007-04-05 08:49:23 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(strcmp(subcmd, "version") == 0)
|
|
|
|
{
|
2006-04-21 08:35:47 +02:00
|
|
|
CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
|
|
|
|
CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
|
2007-10-08 20:47:31 +02:00
|
|
|
CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION);
|
2007-10-08 19:22:57 +02:00
|
|
|
CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion());
|
2006-04-21 08:35:47 +02:00
|
|
|
CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
|
2007-04-05 08:49:23 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(strcmp(subcmd, "list") == 0)
|
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
CPluginManager::CPlugin *pl;
|
|
|
|
ISmmPlugin *plapi;
|
|
|
|
const char *plname;
|
2006-04-21 08:35:47 +02:00
|
|
|
PluginIter i;
|
2007-08-11 01:43:16 +02:00
|
|
|
char buffer[256];
|
|
|
|
int len = 0;
|
|
|
|
int plnum = 0;
|
2006-04-21 08:35:47 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
for (i = g_PluginMngr._begin(); i != g_PluginMngr._end(); i++, len=0)
|
2006-04-21 08:35:47 +02:00
|
|
|
{
|
|
|
|
pl = (*i);
|
2007-08-11 01:43:16 +02:00
|
|
|
if (pl && pl->m_Status == Pl_Running)
|
2006-04-21 08:35:47 +02:00
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
plapi = pl->m_API;
|
|
|
|
if (!plapi || !plapi->QueryRunning(NULL, 0))
|
2007-04-05 08:49:23 +02:00
|
|
|
{
|
2007-08-11 01:43:16 +02:00
|
|
|
continue;
|
2007-04-05 08:49:23 +02:00
|
|
|
}
|
2007-08-11 01:43:16 +02:00
|
|
|
plnum++;
|
2007-04-05 08:49:23 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
len += UTIL_Format(buffer, sizeof(buffer), " [%02d]", plnum);
|
2006-04-21 08:35:47 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
plname = IS_STR_FILLED(plapi->GetName()) ? plapi->GetName() : pl->m_File.c_str();
|
|
|
|
len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " %s", plname);
|
|
|
|
|
|
|
|
if (IS_STR_FILLED(plapi->GetVersion()))
|
|
|
|
{
|
|
|
|
len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " (%s)", plapi->GetVersion());
|
|
|
|
}
|
|
|
|
if (IS_STR_FILLED(plapi->GetAuthor()))
|
|
|
|
{
|
|
|
|
UTIL_Format(&buffer[len], sizeof(buffer)-len, " by %s", plapi->GetAuthor());
|
|
|
|
}
|
|
|
|
|
|
|
|
CLIENT_CONMSG(client, "%s\n", buffer);
|
2006-04-21 08:35:47 +02:00
|
|
|
}
|
|
|
|
}
|
2007-04-05 08:49:23 +02:00
|
|
|
|
2007-08-11 01:43:16 +02:00
|
|
|
if (!plnum)
|
|
|
|
{
|
|
|
|
CLIENT_CONMSG(client, "No active plugins loaded.\n");
|
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2006-04-21 08:35:47 +02:00
|
|
|
}
|
|
|
|
}
|
2007-04-05 08:49:23 +02:00
|
|
|
|
|
|
|
CLIENT_CONMSG(client, "Metamod:Source Menu\n");
|
|
|
|
CLIENT_CONMSG(client, "usage: meta <command>\n");
|
|
|
|
CLIENT_CONMSG(client, " credits - About Metamod:Source\n");
|
|
|
|
CLIENT_CONMSG(client, " list - List plugins\n");
|
|
|
|
CLIENT_CONMSG(client, " version - Version information\n");
|
2006-04-21 08:35:47 +02:00
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return true;
|
2006-04-21 08:35:47 +02:00
|
|
|
}
|
|
|
|
|
2007-10-04 22:15:25 +02:00
|
|
|
return false;
|
2005-07-07 22:58:05 +02:00
|
|
|
}
|