diff -r ddefc8bfb9fa -r 1753f7a9b2f2 sourcemm/concommands.cpp --- a/sourcemm/concommands.cpp Sun May 22 04:33:58 2005 +0000 +++ b/sourcemm/concommands.cpp Thu May 26 08:06:23 2005 +0000 @@ -8,6 +8,8 @@ * ============================ */ +#include +#include #include "concommands.h" #include "CPlugin.h" @@ -16,6 +18,7 @@ * @file concommands.cpp */ +CAlwaysRegisterableCommand g_EternalCommand; SMConVarAccessor g_SMConVarAccessor; bool SMConVarAccessor::RegisterConCommandBase(ConCommandBase *pCommand) @@ -34,6 +37,15 @@ return true; } +bool SMConVarAccessor::Register(ConCommandBase *pCommand) +{ + //simple, don't mark as part of sourcemm! + pCommand->SetNext( NULL ); + g_Engine.icvar->RegisterConCommandBase(pCommand); + + return true; +} + void SMConVarAccessor::MarkCommandsAsGameDLL() { for (std::list::iterator iter = m_RegisteredCommands.begin(); @@ -43,37 +55,34 @@ } } -void SMConVarAccessor::Unregister(ConCommandBase *pCvar) +void SMConVarAccessor::Unregister(ConCommandBase *pCommand) { ICvar *cv = g_Engine.icvar; - ConCommandBase *ptr = cv->GetCommands(); - if (ptr == pCvar && ptr->GetNext()) - { - //we're at the beginning of the list - *ptr = *(ptr->GetNext()); - return; - } - - while (ptr) + if (ptr == pCommand) { - ConCommandBase *pNext = const_cast(ptr->GetNext()); - if (pNext == pCvar) - break; - ptr = pNext; + //first in list + g_EternalCommand.BringToFront(); + g_EternalCommand.SetNext(const_cast(pCommand->GetNext())); + } else { + //find us and unregister us + ConCommandBase *pPrev = NULL; + while (ptr) + { + if (ptr == pCommand) + break; + pPrev = ptr; + ptr = const_cast(ptr->GetNext()); + } + if (pPrev && ptr == pCommand) + { + pPrev->SetNext(const_cast(pCommand->GetNext())); + } } - - if (ptr) - { - ptr->SetNext(const_cast(pCvar->GetNext())); - pCvar->SetNext(NULL); - } - - m_RegisteredCommands.remove(pCvar); } -ConVar metamod_version("metamod_version", SOURCEMM_VERSION, FCVAR_REPLICATED | FCVAR_SPONLY, "Metamod:Source Version"); +ConVar metamod_version("metamod_version", SOURCEMM_VERSION, FCVAR_REPLICATED | FCVAR_SPONLY | FCVAR_NOTIFY, "Metamod:Source Version"); CON_COMMAND(meta, "Metamod:Source Menu") { @@ -111,9 +120,9 @@ } else if (strcmp(command, "refresh") == 0) { char full_path[255]; #if defined WIN32 || defined _WIN32 - snprintf(full_path, sizeof(full_path)-1, "%s\\%s", g_ModPath.c_str(), "metaplugins.ini"); + snprintf(full_path, sizeof(full_path)-1, "%s\\addons\\metamod\\%s", g_ModPath.c_str(), "metaplugins.ini"); #else - snprintf(full_path, sizeof(full_path)-1, "%s/%s", g_ModPath.c_str(), "metaplugins.ini"); + snprintf(full_path, sizeof(full_path)-1, "%s/addons/metamod/%s", g_ModPath.c_str(), "metaplugins.ini"); #endif LoadPluginsFromFile(full_path); @@ -170,6 +179,68 @@ Msg("\n"); return; + } else if (strcmp(command, "cmds") == 0) { + if (args >= 3) + { + int id = atoi(e->Cmd_Argv(2)); + SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); + + if (!pl) + { + Msg("Plugin %d not found.\n", id); + return; + } + + if (!pl->m_API) + { + Msg("Plugin %d is not loaded.\n", id); + } else { + Msg("Console commands for %s:\n", pl->m_API->GetName()); + std::list::iterator ci; + size_t count = 0; + + for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++) + { + count++; + Msg(" [%5d] %-s\n", count, (*ci)->GetName()); + } + } + } else { + Msg("Usage: meta cmds \n"); + } + + return; + } else if (strcmp(command, "cvars") == 0) { + if (args >= 3) + { + int id = atoi(e->Cmd_Argv(2)); + SourceMM::CPluginManager::CPlugin *pl = g_PluginMngr.FindById(id); + + if (!pl) + { + Msg("Plugin %d not found.\n", id); + return; + } + + if (!pl->m_API) + { + Msg("Plugin %d is not loaded.\n", id); + } else { + Msg("Registered cvars for %s:\n", pl->m_API->GetName()); + std::list::iterator ci; + size_t count = 0; + + for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++) + { + count++; + Msg(" [%5d] %-s\n", count, (*ci)->GetName()); + } + } + } else { + Msg("Usage: meta cvars \n"); + } + + return; } else if (strcmp(command, "info") == 0) { if (args >= 3) { @@ -368,6 +439,8 @@ Msg("Metamod:Source Menu\n"); Msg("usage: meta [arguments]\n"); Msg(" clear - Unload all plugins forcefully\n"); + Msg(" cmds - Show plugin commands\n"); + Msg(" cvars - Show plugin cvars\n"); Msg(" credits - About Metamod:Source\n"); Msg(" force_unload - Forcefully unload a plugin\n"); Msg(" game - Information about GameDLL\n"); @@ -382,3 +455,65 @@ Msg(" version - Version information\n"); Msg("\n"); } + +int UTIL_CmpNocase(const std::string &s1, const std::string &s2) +{ + std::string::const_iterator p1 = s1.begin(); + std::string::const_iterator p2 = s2.begin(); + + while (p1 != s1.end() && p2 != s2.end()) + { + if(toupper(*p1) != toupper(*p2)) + return (toupper(*p1)GetCommands(); + + if (pPtr == this) + { + // We are already at the beginning; Nothing to do + return; + } + + while (pPtr) + { + if (pPtr == this && pPtr->IsCommand() && UTIL_CmpNocase(GetName(), pPtr->GetName()) == 0) + break; + ConCommandBase *pPrev = NULL; + while (pPtr) + { + if (pPtr == this) + break; + pPrev = pPtr; + pPtr = const_cast(pPtr->GetNext()); + } + if (pPrev && pPtr == this) + { + pPrev->SetNext(m_pNext); // Remove us from the list + } + // Now, register us + m_pICvar->RegisterConCommandBase(this); + } +}