synced config changes from 1.0.3

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402367
This commit is contained in:
David Anderson 2008-07-06 03:35:58 +00:00
parent 6a834ffef7
commit 43c085eea3

View File

@ -52,6 +52,61 @@ IForward *g_pOnConfigsExecuted = NULL;
IForward *g_pOnAutoConfigsBuffered = NULL;
CoreConfig g_CoreConfig;
bool g_bConfigsExecd = false;
bool g_bServerExecd = false;
bool g_bGotServerStart = false;
bool g_bGotTrigger = false;
ConCommand *g_pExecPtr = NULL;
ConVar *g_ServerCfgFile = NULL;
void CheckAndFinalizeConfigs();
#if defined ORANGEBOX_BUILD
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
void Hook_ExecDispatchPre(const CCommand &cmd)
#else
extern bool __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
void Hook_ExecDispatchPre()
#endif
{
#if !defined ORANGEBOX_BUILD
CCommand cmd;
#endif
const char *arg = cmd.Arg(1);
if (!g_bServerExecd
&& arg != NULL
&& strcmp(arg, g_ServerCfgFile->GetString()) == 0)
{
g_bGotTrigger = true;
}
}
#if defined ORANGEBOX_BUILD
void Hook_ExecDispatchPost(const CCommand &cmd)
#else
void Hook_ExecDispatchPost()
#endif
{
if (g_bGotTrigger)
{
g_bGotTrigger = false;
g_bServerExecd = true;
CheckAndFinalizeConfigs();
}
}
void CheckAndFinalizeConfigs()
{
if ((g_bServerExecd || g_ServerCfgFile == NULL)
&& g_bGotServerStart)
{
/* 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");
}
}
void CoreConfig::OnSourceModAllInitialized()
{
@ -67,11 +122,52 @@ void CoreConfig::OnSourceModShutdown()
g_Forwards.ReleaseForward(g_pOnServerCfg);
g_Forwards.ReleaseForward(g_pOnConfigsExecuted);
g_Forwards.ReleaseForward(g_pOnAutoConfigsBuffered);
if (g_pExecPtr != NULL)
{
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false);
SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true);
g_pExecPtr = NULL;
}
}
void CoreConfig::OnSourceModLevelChange(const char *mapName)
{
static bool already_checked = false;
if (!already_checked)
{
g_ServerCfgFile = icvar->FindVar("servercfgfile");
if (g_ServerCfgFile != NULL)
{
ConCommandBase *pBase = icvar->GetCommands();
while (pBase != NULL)
{
if (pBase->IsCommand() && strcmp(pBase->GetName(), "exec") == 0)
{
break;
}
pBase = const_cast<ConCommandBase *>(pBase->GetNext());
}
g_pExecPtr = (ConCommand *)pBase;
if (g_pExecPtr != NULL)
{
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false);
SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true);
}
else
{
g_ServerCfgFile = NULL;
}
}
already_checked = true;
}
g_bConfigsExecd = false;
g_bServerExecd = false;
g_bGotServerStart = false;
g_bGotTrigger = false;
}
void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
@ -385,7 +481,7 @@ void SM_ExecuteForPlugin(IPluginContext *ctx)
void SM_ExecuteAllConfigs()
{
if (g_bConfigsExecd)
if (g_bGotServerStart)
{
return;
}
@ -406,9 +502,12 @@ void SM_ExecuteAllConfigs()
}
iter->Release();
g_pOnAutoConfigsBuffered->Execute(NULL);
#if defined ORANGEBOX_BUILD
engine->ServerExecute();
#endif
engine->ServerCommand("sm internal 1\n");
g_bGotServerStart = true;
CheckAndFinalizeConfigs();
}
void SM_ConfigsExecuted_Global()