1.1 --- a/core/ConCmdManager.cpp Wed May 02 20:30:29 2007 +0000
1.2 +++ b/core/ConCmdManager.cpp Wed May 02 20:44:35 2007 +0000
1.3 @@ -31,12 +31,17 @@
1.4 CmdType type;
1.5 };
1.6 typedef List<PlCmdInfo> CmdList;
1.7 +
1.8 void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info);
1.9
1.10 ConCmdManager::ConCmdManager() : m_Strings(1024)
1.11 {
1.12 m_pCmds = sm_trie_create();
1.13 m_pCmdGrps = sm_trie_create();
1.14 + m_bServerCfgDone = true;
1.15 + m_pExecCmd = NULL;
1.16 + m_pServerCfgFile = NULL;
1.17 + m_pServerCfgFwd = NULL;
1.18 }
1.19
1.20 ConCmdManager::~ConCmdManager()
1.21 @@ -50,15 +55,73 @@
1.22 g_PluginSys.AddPluginsListener(this);
1.23 g_RootMenu.AddRootConsoleCommand("cmds", "List console commands", this);
1.24 SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
1.25 +
1.26 + ConCommandBase *pCmd = icvar->GetCommands();
1.27 + while (pCmd)
1.28 + {
1.29 + if (pCmd->IsCommand()
1.30 + && strcmp(pCmd->GetName(), "exec") == 0)
1.31 + {
1.32 + m_pExecCmd = (ConCommand *)pCmd;
1.33 + break;
1.34 + }
1.35 + pCmd = const_cast<ConCommandBase *>(pCmd->GetNext());
1.36 + }
1.37 +
1.38 + if (m_pExecCmd)
1.39 + {
1.40 + m_pServerCfgFile = (ConVar *)icvar->FindVar("servercfgfile");
1.41 + SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pExecCmd, this, &ConCmdManager::OnExecCmd, true);
1.42 + m_pServerCfgFwd = g_Forwards.CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
1.43 + }
1.44 }
1.45
1.46 void ConCmdManager::OnSourceModShutdown()
1.47 {
1.48 + if (m_pExecCmd)
1.49 + {
1.50 + SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pExecCmd, this, &ConCmdManager::OnExecCmd, true);
1.51 + g_Forwards.ReleaseForward(m_pServerCfgFwd);
1.52 + m_pServerCfgFwd = NULL;
1.53 + m_pExecCmd = NULL;
1.54 + }
1.55 +
1.56 /* All commands should already be removed by the time we're done */
1.57 SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false);
1.58 g_RootMenu.RemoveRootConsoleCommand("cmds", this);
1.59 }
1.60
1.61 +void ConCmdManager::OnSourceModPluginsLoaded()
1.62 +{
1.63 + m_bServerCfgDone = false;
1.64 +}
1.65 +
1.66 +void ConCmdManager::OnExecCmd()
1.67 +{
1.68 + const char *arg = engine->Cmd_Argv(1);
1.69 + const char *cfgfile = "server.cfg";
1.70 +
1.71 + if (m_pServerCfgFile)
1.72 + {
1.73 + cfgfile = m_pServerCfgFile->GetString();
1.74 + }
1.75 +
1.76 + if (strcmp(arg, cfgfile) == 0)
1.77 + {
1.78 + engine->ServerCommand("sm cmds internal 1\n");
1.79 + }
1.80 +}
1.81 +
1.82 +void ConCmdManager::NotifyExecDone(const char *file)
1.83 +{
1.84 + if (file == NULL && !m_bServerCfgDone)
1.85 + {
1.86 + /* Server-cfg file */
1.87 + m_bServerCfgDone = true;
1.88 + m_pServerCfgFwd->Execute(NULL);
1.89 + }
1.90 +}
1.91 +
1.92 void ConCmdManager::RemoveConCmds(List<CmdHook *> &cmdlist, IPluginContext *pContext)
1.93 {
1.94 List<CmdHook *>::iterator iter = cmdlist.begin();
1.95 @@ -732,6 +795,16 @@
1.96 if (argcount >= 3)
1.97 {
1.98 const char *text = engine->Cmd_Argv(2);
1.99 +
1.100 + if (strcmp(text, "internal") == 0)
1.101 + {
1.102 + const char *num = engine->Cmd_Argv(3);
1.103 + if (atoi(num) == 1)
1.104 + {
1.105 + g_ConCmds.NotifyExecDone(NULL);
1.106 + }
1.107 + }
1.108 +
1.109 int id = atoi(text);
1.110 CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id);
1.111