1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcemm/concommands.cpp Tue Sep 18 20:03:47 2007 +0000
1.3 @@ -0,0 +1,764 @@
1.4 +/* ======== SourceMM ========
1.5 + * Copyright (C) 2004-2007 Metamod:Source Development Team
1.6 + * No warranties of any kind
1.7 + *
1.8 + * License: zlib/libpng
1.9 + *
1.10 + * Author(s): David "BAILOPAN" Anderson
1.11 + * ============================
1.12 + */
1.13 +
1.14 +#include <ctype.h>
1.15 +#include "CSmmAPI.h"
1.16 +#include "concommands.h"
1.17 +#include "CPlugin.h"
1.18 +#include "sh_string.h"
1.19 +#include "sh_list.h"
1.20 +
1.21 +/**
1.22 + * @brief Console Command Implementations
1.23 + * @file concommands.cpp
1.24 + */
1.25 +
1.26 +CAlwaysRegisterableCommand g_EternalCommand;
1.27 +SMConVarAccessor g_SMConVarAccessor;
1.28 +
1.29 +bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand)
1.30 +{
1.31 + // Add the FCVAR_GAMEDLL flag
1.32 + // => No crash on exit!
1.33 + // UPDATE: Do _not_ add the FCVAR_GAMEDLL flag here, as it
1.34 + // causes the command to be unusable on listenservers until you load a map
1.35 + // We will set the FCVAR_GAMEDLL flag on all commands we have registered once we are being unloaded
1.36 + //pCommand->AddFlags(FCVAR_GAMEDLL);
1.37 + m_RegisteredCommands.push_back(pCommand);
1.38 +
1.39 + pCommand->SetNext( NULL );
1.40 + g_Engine.icvar->RegisterConCommandBase(pCommand);
1.41 +
1.42 + return true;
1.43 +}
1.44 +
1.45 +bool SMConVarAccessor::Register(ConCommandBase *pCommand)
1.46 +{
1.47 + //simple, don't mark as part of sourcemm!
1.48 + pCommand->SetNext( NULL );
1.49 + g_Engine.icvar->RegisterConCommandBase(pCommand);
1.50 +
1.51 + return true;
1.52 +}
1.53 +
1.54 +void SMConVarAccessor::MarkCommandsAsGameDLL()
1.55 +{
1.56 + for (SourceHook::List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
1.57 + iter != m_RegisteredCommands.end(); ++iter)
1.58 + {
1.59 + (*iter)->AddFlags(FCVAR_GAMEDLL);
1.60 + }
1.61 +}
1.62 +
1.63 +void SMConVarAccessor::Unregister(ConCommandBase *pCommand)
1.64 +{
1.65 + ICvar *cv = g_Engine.icvar;
1.66 + ConCommandBase *ptr = cv->GetCommands();
1.67 +
1.68 + if (ptr == pCommand)
1.69 + {
1.70 + //first in list
1.71 + g_EternalCommand.BringToFront();
1.72 + g_EternalCommand.SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
1.73 + } else {
1.74 + //find us and unregister us
1.75 + ConCommandBase *pPrev = NULL;
1.76 + while (ptr)
1.77 + {
1.78 + if (ptr == pCommand)
1.79 + break;
1.80 + pPrev = ptr;
1.81 + ptr = const_cast<ConCommandBase *>(ptr->GetNext());
1.82 + }
1.83 + if (pPrev && ptr == pCommand)
1.84 + {
1.85 + pPrev->SetNext(const_cast<ConCommandBase *>(pCommand->GetNext()));
1.86 + }
1.87 + }
1.88 +}
1.89 +
1.90 +void SMConVarAccessor::UnregisterGameDLLCommands()
1.91 +{
1.92 + ConCommandBase *begin = g_Engine.icvar->GetCommands();
1.93 + ConCommandBase *iter = begin;
1.94 + ConCommandBase *prev = NULL;
1.95 + while (iter)
1.96 + {
1.97 + // watch out for the ETERNAL COMMAND!
1.98 + if (iter != &g_EternalCommand && iter->IsBitSet(FCVAR_GAMEDLL))
1.99 + {
1.100 + // Remove it!
1.101 + if (iter == begin)
1.102 + {
1.103 + g_EternalCommand.BringToFront();
1.104 + iter = const_cast<ConCommandBase*>(iter->GetNext());
1.105 + g_EternalCommand.SetNext(iter);
1.106 + prev = &g_EternalCommand;
1.107 + continue;
1.108 + }
1.109 + else
1.110 + {
1.111 + iter = const_cast<ConCommandBase*>(iter->GetNext());
1.112 + prev->SetNext(iter);
1.113 + continue;
1.114 + }
1.115 + }
1.116 + prev = iter;
1.117 + iter = const_cast<ConCommandBase*>(iter->GetNext());
1.118 + }
1.119 +}
1.120 +
1.121 +ConVar metamod_version("metamod_version", SOURCEMM_VERSION, FCVAR_REPLICATED | FCVAR_SPONLY | FCVAR_NOTIFY, "Metamod:Source Version");
1.122 +#if defined WIN32 || defined _WIN32
1.123 +ConVar mm_pluginsfile("mm_pluginsfile", "addons\\metamod\\metaplugins.ini", FCVAR_SPONLY, "Metamod:Source Plugins File");
1.124 +#else
1.125 +ConVar mm_pluginsfile("mm_pluginsfile", "addons/metamod/metaplugins.ini", FCVAR_SPONLY, "Metamod:Source Plugins File");
1.126 +#endif
1.127 +
1.128 +CON_COMMAND(meta, "Metamod:Source Menu")
1.129 +{
1.130 + IVEngineServer *e = g_Engine.engine;
1.131 +
1.132 + int args = e->Cmd_Argc();
1.133 +
1.134 + if (args >= 2)
1.135 + {
1.136 + const char *command = e->Cmd_Argv(1);
1.137 + if (strcmp(command, "credits") == 0)
1.138 + {
1.139 + CONMSG("Metamod:Source was developed by:\n");
1.140 + CONMSG(" SourceHook: Pavol \"PM OnoTo\" Marko\n");
1.141 + CONMSG(" GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
1.142 + CONMSG(" GameDLL: Scott \"Damaged Soul\" Ehlert\n");
1.143 + CONMSG("For more information, see the official website\n");
1.144 + CONMSG("http://www.sourcemm.net/\n");
1.145 +
1.146 + return;
1.147 + } else if (strcmp(command, "version") == 0) {
1.148 + CONMSG("Metamod:Source version %s\n", SOURCEMM_VERSION);
1.149 + CONMSG("Compiled on: %s\n", SOURCEMM_DATE);
1.150 + CONMSG("Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
1.151 + CONMSG("SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
1.152 + CONMSG("http://www.sourcemm.net/\n");
1.153 +
1.154 + return;
1.155 + } else if (strcmp(command, "game") == 0) {
1.156 + CONMSG("GameDLL Information\n");
1.157 + CONMSG(" Description: %s\n", g_GameDll.pGameDLL->GetGameDescription());
1.158 + CONMSG(" Mod Path: %s\n", g_ModPath.c_str());
1.159 + CONMSG(" DLL Path: %s\n", g_BinPath.c_str());
1.160 + CONMSG(" Interface: ServerGameDLL%03d\n", g_GameDllVersion);
1.161 +
1.162 + // Display user messages
1.163 + if (g_SmmAPI.MsgCacheSuccessful())
1.164 + {
1.165 + const char *msgname;
1.166 + int msgsize;
1.167 + int msgcount = g_SmmAPI.GetUserMessageCount();
1.168 +
1.169 + if (msgcount > 0)
1.170 + {
1.171 + CONMSG(" User Messages: %-32.31s %-5s %-5s\n", "Name", "Index", "Size");
1.172 +
1.173 + for (int i = 0; i < msgcount; i++)
1.174 + {
1.175 + msgname = g_SmmAPI.GetUserMessage(i, &msgsize);
1.176 +
1.177 + CONMSG(" %-32.31s %-5d %-5d\n", msgname, i, msgsize);
1.178 + }
1.179 +
1.180 + CONMSG(" %d user message%s in total\n", msgcount, (msgcount > 1) ? "s" : "");
1.181 + } else {
1.182 + CONMSG(" User Messages: None\n");
1.183 + }
1.184 + } else {
1.185 + CONMSG(" User Messages: Failed to get list of user messages\n");
1.186 + }
1.187 +
1.188 + return;
1.189 + } else if (strcmp(command, "refresh") == 0) {
1.190 + char full_path[255];
1.191 + g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s", g_ModPath.c_str(), GetPluginsFile());
1.192 +
1.193 + LoadPluginsFromFile(full_path);
1.194 +
1.195 + return;
1.196 + } else if (strcmp(command, "list") == 0) {
1.197 + SourceMM::CPluginManager::CPlugin *pl;
1.198 + PluginIter i;
1.199 + const char *status="";
1.200 + const char *version=NULL;
1.201 + const char *name=NULL;
1.202 + const char *author=NULL;
1.203 +
1.204 + CONMSG("-Id- %-20.19s %-10.9s %-20.19s %-8.7s\n", "Name", "Version", "Author", "Status");
1.205 + for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
1.206 + {
1.207 + pl = (*i);
1.208 + if (!pl)
1.209 + break;
1.210 + if (pl->m_Status == Pl_Paused)
1.211 + {
1.212 + status = "PAUSE";
1.213 + } else if (pl->m_Status == Pl_Running) {
1.214 + if (pl->m_API && pl->m_API->QueryRunning(NULL, 0))
1.215 + status = "RUN";
1.216 + else
1.217 + status = "STOPPED";
1.218 + } else if (pl->m_Status == Pl_Refused) {
1.219 + status = "FAIL";
1.220 + } else if (pl->m_Status == Pl_Error) {
1.221 + status = "ERROR";
1.222 + } else if (pl->m_Status == Pl_NotFound) {
1.223 + status = "NOFILE";
1.224 + }
1.225 +
1.226 + if (pl->m_API)
1.227 + {
1.228 + version = pl->m_API->GetVersion();
1.229 + author = pl->m_API->GetAuthor();
1.230 + name = pl->m_API->GetName();
1.231 + } else {
1.232 + version = "-";
1.233 + author = "-";
1.234 + name = "-";
1.235 + }
1.236 +
1.237 + if (!version)
1.238 + version = "-";
1.239 + if (!author)
1.240 + author = "-";
1.241 + if (!name)
1.242 + name = pl->m_File.c_str();
1.243 +
1.244 +
1.245 + CONMSG("[%02d] %-20.19s %-10.9s %-20.19s %-8.7s\n", pl->m_Id, name, version, author, status);
1.246 + }
1.247 +
1.248 + //CONMSG("\n");
1.249 +
1.250 + return;
1.251 + } else if (strcmp(command, "cmds") == 0) {
1.252 + if (args >= 3)
1.253 + {
1.254 + int id = atoi(e->Cmd_Argv(2));
1.255 + SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
1.256 +
1.257 + if (!pl)
1.258 + {
1.259 + CONMSG("Plugin %d not found.\n", id);
1.260 + return;
1.261 + }
1.262 +
1.263 + if (!pl->m_API)
1.264 + {
1.265 + CONMSG("Plugin %d is not loaded.\n", id);
1.266 + } else {
1.267 + CONMSG("Console commands for %s:\n", pl->m_API->GetName());
1.268 + SourceHook::List<ConCommandBase *>::iterator ci;
1.269 + size_t count = 0;
1.270 +
1.271 + for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
1.272 + {
1.273 + count++;
1.274 + CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
1.275 + }
1.276 + }
1.277 + } else {
1.278 + CONMSG("Usage: meta cmds <id>\n");
1.279 + }
1.280 +
1.281 + return;
1.282 + } else if (strcmp(command, "cvars") == 0) {
1.283 + if (args >= 3)
1.284 + {
1.285 + int id = atoi(e->Cmd_Argv(2));
1.286 + SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
1.287 +
1.288 + if (!pl)
1.289 + {
1.290 + CONMSG("Plugin %d not found.\n", id);
1.291 + return;
1.292 + }
1.293 +
1.294 + if (!pl->m_API)
1.295 + {
1.296 + CONMSG("Plugin %d is not loaded.\n", id);
1.297 + } else {
1.298 + CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
1.299 + SourceHook::List<ConCommandBase *>::iterator ci;
1.300 + size_t count = 0;
1.301 +
1.302 + for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
1.303 + {
1.304 + count++;
1.305 + CONMSG(" [%5d] %-s\n", count, (*ci)->GetName());
1.306 + }
1.307 + }
1.308 + } else {
1.309 + CONMSG("Usage: meta cvars <id>\n");
1.310 + }
1.311 +
1.312 + return;
1.313 + } else if (strcmp(command, "info") == 0) {
1.314 + if (args >= 3)
1.315 + {
1.316 + int id = atoi(e->Cmd_Argv(2));
1.317 + SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id);
1.318 + if (!pl)
1.319 + {
1.320 + CONMSG("Plugin %d not found.\n", id);
1.321 + return;
1.322 + }
1.323 +
1.324 + if (!pl->m_API)
1.325 + {
1.326 + CONMSG("Plugin %d is not loaded.\n", id);
1.327 + } else {
1.328 + if (pl->m_Status == Pl_Paused)
1.329 + {
1.330 + CONMSG("Plugin %d is paused.\n", id);
1.331 + } else if (pl->m_Status == Pl_Running) {
1.332 + char run_msg[255];
1.333 + bool run = false;
1.334 + if (pl->m_API && pl->m_API->QueryRunning(run_msg, sizeof(run_msg)-1))
1.335 + run = true;
1.336 + if (run)
1.337 + {
1.338 + CONMSG("Plugin %d is running.\n", id);
1.339 + } else {
1.340 + CONMSG("Plugin %d is stopped: %s\n", id, run_msg);
1.341 + }
1.342 + }
1.343 + CONMSG(" Name: \"%s\" by %s\n", pl->m_API->GetName(), pl->m_API->GetAuthor());
1.344 + CONMSG(" Version: %s\n", pl->m_API->GetVersion());
1.345 + CONMSG(" Description: %s\n", pl->m_API->GetDescription());
1.346 + CONMSG(" License: %s\n", pl->m_API->GetLicense());
1.347 + CONMSG(" URL: %s\n", pl->m_API->GetURL());
1.348 + CONMSG(" Details: API %03d, Date: %s\n", pl->m_API->GetApiVersion(), pl->m_API->GetDate());
1.349 + }
1.350 + CONMSG("File: %s\n\n", pl->m_File.c_str());
1.351 +
1.352 + return;
1.353 + } else {
1.354 + CONMSG("Usage: meta info <id>\n");
1.355 +
1.356 + return;
1.357 + }
1.358 + } else if (strcmp(command, "pause") == 0) {
1.359 + if (args >= 3)
1.360 + {
1.361 + int id = atoi(e->Cmd_Argv(2));
1.362 +
1.363 + char error[255];
1.364 +
1.365 + if (!g_PluginMngr.Pause(id, error, sizeof(error)))
1.366 + {
1.367 + CONMSG("Pause failed: %s\n", error);
1.368 + return;
1.369 + }
1.370 +
1.371 + CONMSG("Plugin %d has been paused.\n", id);
1.372 +
1.373 + return;
1.374 + } else {
1.375 + CONMSG("Usage: meta pause <id>\n");
1.376 +
1.377 + return;
1.378 + }
1.379 + } else if (strcmp(command, "unpause") == 0) {
1.380 + if (args >= 3)
1.381 + {
1.382 + int id = atoi(e->Cmd_Argv(2));
1.383 + char error[255];
1.384 +
1.385 + if (!g_PluginMngr.Unpause(id, error, sizeof(error)))
1.386 + {
1.387 + CONMSG("Unpause failed: %s\n", error);
1.388 + return;
1.389 + }
1.390 +
1.391 + CONMSG("Plugin %d has been unpaused.\n", id);
1.392 +
1.393 + return;
1.394 + } else {
1.395 + CONMSG("Usage: meta unpause <id>\n");
1.396 +
1.397 + return;
1.398 + }
1.399 + } else if (strcmp(command, "load") == 0) {
1.400 + if (args >= 3)
1.401 + {
1.402 + const char *file = e->Cmd_Argv(2);
1.403 + char full_path[255];
1.404 +
1.405 + const char *alias = g_PluginMngr.LookupAlias(file);
1.406 + if (alias)
1.407 + {
1.408 + file = alias;
1.409 + }
1.410 +
1.411 + if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
1.412 + {
1.413 + g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s", file);
1.414 + } else {
1.415 + const char *ext = UTIL_GetExtension(file);
1.416 +#if defined WIN32 || defined _WIN32
1.417 + ext = ext ? "" : ".dll";
1.418 +#else
1.419 + ext = ext ? "" : "_i486.so";
1.420 +#endif
1.421 + g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext);
1.422 + }
1.423 +
1.424 + char error[255]={0};
1.425 + bool already;
1.426 + SourceMM::CPluginManager::CPlugin *pl;
1.427 +
1.428 + PluginId id = g_PluginMngr.Load(full_path, Pl_Console, already, error, sizeof(error));
1.429 + pl = g_PluginMngr.FindById(id);
1.430 + if (!pl || id < Pl_MinId || (pl->m_Status < Pl_Paused))
1.431 + {
1.432 + CONMSG("Failed to load plugin %s (%s).\n", file, error);
1.433 + return;
1.434 + }
1.435 +
1.436 + if (!already)
1.437 + {
1.438 + CONMSG("Plugin \"%s\" loaded with id %d.\n", pl->m_API->GetName(), pl->m_Id);
1.439 + } else {
1.440 + CONMSG("Plugin \"%s\" is already loaded as %d.\n", pl->m_API->GetName(), pl->m_Id);
1.441 + }
1.442 +
1.443 + return;
1.444 + } else {
1.445 + CONMSG("Usage: meta load <path>\n");
1.446 +
1.447 + return;
1.448 + }
1.449 + } else if ( (strcmp(command, "alias") == 0) ||
1.450 + (strcmp(command, "aliases") == 0) ) {
1.451 + if (args >= 4)
1.452 + {
1.453 + const char *alias = e->Cmd_Argv(2);
1.454 + const char *value = e->Cmd_Argv(3);
1.455 +
1.456 + g_PluginMngr.SetAlias(alias, value);
1.457 + if (value[0] == '\0')
1.458 + {
1.459 + CONMSG("Deleted alias: %s.\n", alias);
1.460 + } else {
1.461 + CONMSG("Set alias \"%s\" to: %s\n", alias, value);
1.462 + }
1.463 + } else if (args >= 3) {
1.464 + const char *alias = e->Cmd_Argv(2);
1.465 + const char *value = g_PluginMngr.LookupAlias(alias);
1.466 + if (value)
1.467 + {
1.468 + CONMSG("Alias \"%s\" is set to: %s\n", alias, value);
1.469 + } else {
1.470 + CONMSG("Alias \"%s\" was not found.\n", alias);
1.471 + }
1.472 + } else {
1.473 + SourceHook::List<SourceMM::CNameAlias *>::iterator iter, end;
1.474 + SourceMM::CNameAlias *p;
1.475 +
1.476 + iter = g_PluginMngr._alias_begin();
1.477 + end = g_PluginMngr._alias_end();
1.478 + size_t total = 0;
1.479 + if (iter != end)
1.480 + {
1.481 + CONMSG("%-10.9s %s\n", "Alias", "File");
1.482 + CONMSG(" --- \n");
1.483 + for (; iter!=end; iter++)
1.484 + {
1.485 + p = (*iter);
1.486 + CONMSG("%-10.9s %s\n", p->alias.c_str(), p->value.c_str());
1.487 + total++;
1.488 + }
1.489 + CONMSG(" --- \n");
1.490 + CONMSG("%d aliases total.\n", total);
1.491 + } else {
1.492 + CONMSG("No aliases found.\n");
1.493 + }
1.494 + }
1.495 + return;
1.496 + } else if (strcmp(command, "unload") == 0) {
1.497 + if (args >= 3)
1.498 + {
1.499 + const char *file = e->Cmd_Argv(2);
1.500 + int id = atoi(file);
1.501 + char error[255]={0};
1.502 +
1.503 + if (id == 0 && isalpha(file[0]))
1.504 + {
1.505 + char full_path[255];
1.506 + const char *alias = g_PluginMngr.LookupAlias(file);
1.507 +
1.508 + if (alias)
1.509 + {
1.510 + file = alias;
1.511 + }
1.512 +
1.513 + /* first check if it's a known filename */
1.514 + if (file[0] == '/' || strcmp(&(file[1]), ":\\") == 0)
1.515 + {
1.516 + g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s", file);
1.517 + } else {
1.518 + const char *ext = UTIL_GetExtension(file);
1.519 +#if defined WIN32 || defined _WIN32
1.520 + ext = ext ? "" : ".dll";
1.521 +#else
1.522 + ext = ext ? "" : "_i486.so";
1.523 +#endif
1.524 + g_SmmAPI.PathFormat(full_path, sizeof(full_path), "%s/%s%s", g_ModPath.c_str(), file, ext);
1.525 + }
1.526 +
1.527 + SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator iter, end;
1.528 + SourceMM::CPluginManager::CPlugin *pl;
1.529 + iter = g_PluginMngr._begin();
1.530 + end = g_PluginMngr._end();
1.531 + for (; iter!=end; iter++)
1.532 + {
1.533 + pl = (*iter);
1.534 + if (strcmp(pl->m_File.c_str(), full_path) == 0)
1.535 + {
1.536 + id = pl->m_Id;
1.537 + break;
1.538 + }
1.539 + }
1.540 + if (id == 0)
1.541 + {
1.542 + CONMSG("Plugin \"%s\" not found.\n", full_path);
1.543 + return;
1.544 + }
1.545 + }
1.546 +
1.547 + if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
1.548 + {
1.549 + CONMSG("Unload failed: %s\n", error);
1.550 + return;
1.551 + }
1.552 +
1.553 + CONMSG("Plugin %d unloaded.\n", id);
1.554 + } else {
1.555 + CONMSG("Usage: meta unload <id>\n");
1.556 + }
1.557 + return;
1.558 + } else if (strcmp(command, "force_unload") == 0) {
1.559 + if (args >= 3)
1.560 + {
1.561 + int id = atoi(e->Cmd_Argv(2));
1.562 + char error[255]={0};
1.563 +
1.564 + if (!g_PluginMngr.Unload(id, false, error, sizeof(error)))
1.565 + {
1.566 + CONMSG("Force unload failed: %s\n", error);
1.567 + return;
1.568 + }
1.569 +
1.570 + CONMSG("Plugin %d force unloaded.\n", id);
1.571 +
1.572 + return;
1.573 + } else {
1.574 + CONMSG("Usage: meta force_unload <id>\n");
1.575 +
1.576 + return;
1.577 + }
1.578 + } else if (strcmp(command, "clear") == 0) {
1.579 + if (!g_PluginMngr.UnloadAll())
1.580 + {
1.581 + CONMSG("One or more plugins resisted removal (cleaned anyway).\n");
1.582 + return;
1.583 + }
1.584 +
1.585 + CONMSG("All plugins unloaded.\n");
1.586 +
1.587 + return;
1.588 + } else if (strcmp(command, "retry") == 0) {
1.589 + if (args >= 3)
1.590 + {
1.591 + int id = atoi(e->Cmd_Argv(2));
1.592 + char error[255];
1.593 +
1.594 + if (!g_PluginMngr.Retry(id, error, sizeof(error)))
1.595 + {
1.596 + CONMSG("Error reloading plugin: %s\n", error);
1.597 + return;
1.598 + }
1.599 +
1.600 + CONMSG("Plugin %d successfully reloaded.\n", id);
1.601 +
1.602 + return;
1.603 + } else {
1.604 + CONMSG("Usage: meta retry <id>\n");
1.605 +
1.606 + return;
1.607 + }
1.608 + }
1.609 + }
1.610 +
1.611 + CONMSG("Metamod:Source Menu\n");
1.612 + CONMSG("usage: meta <command> [arguments]\n");
1.613 + CONMSG(" alias - List or set an alias\n");
1.614 + CONMSG(" clear - Unload all plugins forcefully\n");
1.615 + CONMSG(" cmds - Show plugin commands\n");
1.616 + CONMSG(" cvars - Show plugin cvars\n");
1.617 + CONMSG(" credits - About Metamod:Source\n");
1.618 + CONMSG(" force_unload - Forcefully unload a plugin\n");
1.619 + CONMSG(" game - Information about GameDLL\n");
1.620 + CONMSG(" info - Information about a plugin\n");
1.621 + CONMSG(" list - List plugins\n");
1.622 + CONMSG(" load - Load a plugin\n");
1.623 + CONMSG(" pause - Pause a running plugin\n");
1.624 + CONMSG(" refresh - Reparse plugins file\n");
1.625 + CONMSG(" retry - Attempt to reload a plugin\n");
1.626 + CONMSG(" unload - Unload a loaded plugin\n");
1.627 + CONMSG(" unpause - Unpause a paused plugin\n");
1.628 + CONMSG(" version - Version information\n");
1.629 +}
1.630 +
1.631 +CAlwaysRegisterableCommand::CAlwaysRegisterableCommand()
1.632 +{
1.633 + Create("", NULL, FCVAR_UNREGISTERED|FCVAR_GAMEDLL);
1.634 + m_pICvar = NULL;
1.635 +}
1.636 +
1.637 +bool CAlwaysRegisterableCommand::IsRegistered( void ) const
1.638 +{
1.639 + return false;
1.640 +}
1.641 +
1.642 +void CAlwaysRegisterableCommand::BringToFront()
1.643 +{
1.644 + if (!m_pICvar)
1.645 + m_pICvar = g_Engine.icvar;
1.646 +
1.647 + // First, let's try to find us!
1.648 + ConCommandBase *pPtr = m_pICvar->GetCommands();
1.649 +
1.650 + if (pPtr == this)
1.651 + {
1.652 + // We are already at the beginning; Nothing to do
1.653 + return;
1.654 + }
1.655 +
1.656 + while (pPtr)
1.657 + {
1.658 + if (pPtr == this && pPtr->IsCommand() && stricmp(GetName(), pPtr->GetName()) == 0)
1.659 + break;
1.660 + ConCommandBase *pPrev = NULL;
1.661 + while (pPtr)
1.662 + {
1.663 + if (pPtr == this)
1.664 + break;
1.665 + pPrev = pPtr;
1.666 + pPtr = const_cast<ConCommandBase*>(pPtr->GetNext());
1.667 + }
1.668 + if (pPrev && pPtr == this)
1.669 + {
1.670 + pPrev->SetNext(m_pNext); // Remove us from the list
1.671 + }
1.672 + // Now, register us
1.673 + SetNext(NULL);
1.674 + m_pICvar->RegisterConCommandBase(this);
1.675 + }
1.676 +}
1.677 +
1.678 +void ClientCommand_handler(edict_t *client)
1.679 +{
1.680 + IVEngineServer *e = g_Engine.engine;
1.681 + const char *cmd = e->Cmd_Argv(0);
1.682 +
1.683 + if (strcmp(cmd, "meta") == 0)
1.684 + {
1.685 + int args = e->Cmd_Argc();
1.686 + if (args == 2)
1.687 + {
1.688 + const char *subcmd = e->Cmd_Argv(1);
1.689 +
1.690 + if (strcmp(subcmd, "credits") == 0)
1.691 + {
1.692 + CLIENT_CONMSG(client, "Metamod:Source was developed by:\n");
1.693 + CLIENT_CONMSG(client, " SourceHook: Pavol \"PM OnoTo\" Marko\n");
1.694 + CLIENT_CONMSG(client, " GameDLL/Plugins: David \"BAILOPAN\" Anderson\n");
1.695 + CLIENT_CONMSG(client, " GameDLL: Scott \"Damaged Soul\" Ehlert\n");
1.696 + CLIENT_CONMSG(client, "For more information, see the official website\n");
1.697 + CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
1.698 +
1.699 + RETURN_META(MRES_SUPERCEDE);
1.700 + } else if(strcmp(subcmd, "version") == 0) {
1.701 + CLIENT_CONMSG(client, "Metamod:Source version %s\n", SOURCEMM_VERSION);
1.702 + CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE);
1.703 + CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION);
1.704 + CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion());
1.705 + CLIENT_CONMSG(client, "http://www.sourcemm.net/\n");
1.706 +
1.707 + RETURN_META(MRES_SUPERCEDE);
1.708 + } else if(strcmp(subcmd, "list") == 0) {
1.709 + SourceMM::CPluginManager::CPlugin *pl;
1.710 + Pl_Status st;
1.711 + PluginIter i;
1.712 + const char *version = NULL;
1.713 + const char *name = NULL;
1.714 + const char *author = NULL;
1.715 + const char *status = NULL;
1.716 +
1.717 + CLIENT_CONMSG(client, "-Id- %-20.19s %-10.9s %-20.19s %6s\n", "Name", "Version", "Author", "Status");
1.718 +
1.719 + for (i=g_PluginMngr._begin(); i!=g_PluginMngr._end(); i++)
1.720 + {
1.721 + pl = (*i);
1.722 + if (!pl)
1.723 + break;
1.724 +
1.725 + st = pl->m_Status;
1.726 +
1.727 + /* Only show plugins that are running or paused */
1.728 + if (pl->m_API && (st == Pl_Running || st == Pl_Paused))
1.729 + {
1.730 + version = pl->m_API->GetVersion();
1.731 + author = pl->m_API->GetAuthor();
1.732 + name = pl->m_API->GetName();
1.733 +
1.734 + if (st == Pl_Running && pl->m_API->QueryRunning(NULL, 0))
1.735 + {
1.736 + status = "RUN";
1.737 + } else {
1.738 + status = "PAUSE";
1.739 + }
1.740 +
1.741 + if (!version || !author || !name)
1.742 + break;
1.743 +
1.744 + CLIENT_CONMSG(client, "[%02d] %-20.19s %-10.9s %-20.19s %6s\n", pl->m_Id, name, version, author, status);
1.745 + }
1.746 + }
1.747 +
1.748 + RETURN_META(MRES_SUPERCEDE);
1.749 + }
1.750 + }
1.751 +
1.752 + CLIENT_CONMSG(client, "Metamod:Source Menu\n");
1.753 + CLIENT_CONMSG(client, "usage: meta <command>\n");
1.754 + CLIENT_CONMSG(client, " credits - About Metamod:Source\n");
1.755 + CLIENT_CONMSG(client, " list - List plugins\n");
1.756 + CLIENT_CONMSG(client, " version - Version information\n");
1.757 +
1.758 + RETURN_META(MRES_SUPERCEDE);
1.759 + }
1.760 +
1.761 + RETURN_META(MRES_IGNORED);
1.762 +}
1.763 +
1.764 +const char *GetPluginsFile()
1.765 +{
1.766 + return mm_pluginsfile.GetString();
1.767 +}