core/CoreConfig.cpp
author David Anderson <dvander@alliedmods.net>
Sat Aug 23 19:59:18 2008 +0000 (2008-08-23)
changeset 2236 2afb085d34df
parent 2235 a44942987c81
child 2289 44045ead61cd
permissions -rw-r--r--
Reverted to old cmd functionality for original engine.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#include <ITextParsers.h>
ds@1952
    33
#include "CoreConfig.h"
ds@1952
    34
#include "sourcemod.h"
ds@1952
    35
#include "sourcemm_api.h"
ds@1952
    36
#include "sm_srvcmds.h"
ds@1952
    37
#include "sm_version.h"
ds@1952
    38
#include "sm_stringutil.h"
ds@1952
    39
#include "LibrarySys.h"
ds@1952
    40
#include "Logger.h"
ds@1952
    41
#include "PluginSys.h"
ds@1952
    42
#include "ForwardSys.h"
dvander@2235
    43
#include "frame_hooks.h"
ds@1952
    44
ds@1952
    45
#ifdef PLATFORM_WINDOWS
ds@1952
    46
ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
ds@1952
    47
#elif defined PLATFORM_LINUX
ds@1952
    48
ConVar sm_corecfgfile("sm_corecfgfile", "addons/sourcemod/configs/core.cfg", 0, "SourceMod core configuration file");
ds@1952
    49
#endif
ds@1952
    50
ds@1952
    51
IForward *g_pOnServerCfg = NULL;
ds@1952
    52
IForward *g_pOnConfigsExecuted = NULL;
dvander@2065
    53
IForward *g_pOnAutoConfigsBuffered = NULL;
ds@1952
    54
CoreConfig g_CoreConfig;
ds@1952
    55
bool g_bConfigsExecd = false;
dvander@2166
    56
bool g_bServerExecd = false;
dvander@2166
    57
bool g_bGotServerStart = false;
dvander@2166
    58
bool g_bGotTrigger = false;
dvander@2166
    59
ConCommand *g_pExecPtr = NULL;
dvander@2166
    60
ConVar *g_ServerCfgFile = NULL;
dvander@2166
    61
dvander@2166
    62
void CheckAndFinalizeConfigs();
dvander@2166
    63
dvander@2166
    64
#if defined ORANGEBOX_BUILD
dvander@2166
    65
SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
dvander@2166
    66
void Hook_ExecDispatchPre(const CCommand &cmd)
dvander@2166
    67
#else
dvander@2166
    68
extern bool __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
dvander@2166
    69
extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0<void>);
dvander@2166
    70
void Hook_ExecDispatchPre()
dvander@2166
    71
#endif
dvander@2166
    72
{
dvander@2166
    73
#if !defined ORANGEBOX_BUILD
dvander@2166
    74
	CCommand cmd;
dvander@2166
    75
#endif
dvander@2166
    76
dvander@2166
    77
	const char *arg = cmd.Arg(1);
dvander@2166
    78
dvander@2166
    79
	if (!g_bServerExecd 
dvander@2166
    80
		&& arg != NULL 
dvander@2166
    81
		&& strcmp(arg, g_ServerCfgFile->GetString()) == 0)
dvander@2166
    82
	{
dvander@2166
    83
		g_bGotTrigger = true;
dvander@2166
    84
	}
dvander@2166
    85
}
dvander@2166
    86
dvander@2166
    87
#if defined ORANGEBOX_BUILD
dvander@2166
    88
void Hook_ExecDispatchPost(const CCommand &cmd)
dvander@2166
    89
#else
dvander@2166
    90
void Hook_ExecDispatchPost()
dvander@2166
    91
#endif
dvander@2166
    92
{
dvander@2166
    93
	if (g_bGotTrigger)
dvander@2166
    94
	{
dvander@2166
    95
		g_bGotTrigger = false;
dvander@2166
    96
		g_bServerExecd = true;
dvander@2166
    97
		CheckAndFinalizeConfigs();
dvander@2166
    98
	}
dvander@2166
    99
}
dvander@2166
   100
dvander@2166
   101
void CheckAndFinalizeConfigs()
dvander@2166
   102
{
dvander@2166
   103
	if ((g_bServerExecd || g_ServerCfgFile == NULL) 
dvander@2166
   104
		&& g_bGotServerStart)
dvander@2166
   105
	{
dvander@2236
   106
#if defined ORANGEBOX_BUILD
dvander@2235
   107
        g_PendingInternalPush = true;
dvander@2236
   108
#else
dvander@2236
   109
        SM_InternalCmdTrigger();
dvander@2236
   110
#endif
dvander@2166
   111
	}
dvander@2166
   112
}
ds@1952
   113
ds@1952
   114
void CoreConfig::OnSourceModAllInitialized()
ds@1952
   115
{
ds@1952
   116
	g_RootMenu.AddRootConsoleCommand("config", "Set core configuration options", this);
ds@1952
   117
	g_pOnServerCfg = g_Forwards.CreateForward("OnServerCfg", ET_Ignore, 0, NULL);
ds@1952
   118
	g_pOnConfigsExecuted = g_Forwards.CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL);
dvander@2065
   119
	g_pOnAutoConfigsBuffered = g_Forwards.CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL);
ds@1952
   120
}
ds@1952
   121
ds@1952
   122
void CoreConfig::OnSourceModShutdown()
ds@1952
   123
{
ds@1952
   124
	g_RootMenu.RemoveRootConsoleCommand("config", this);
ds@1952
   125
	g_Forwards.ReleaseForward(g_pOnServerCfg);
ds@1952
   126
	g_Forwards.ReleaseForward(g_pOnConfigsExecuted);
dvander@2065
   127
	g_Forwards.ReleaseForward(g_pOnAutoConfigsBuffered);
dvander@2166
   128
dvander@2166
   129
	if (g_pExecPtr != NULL)
dvander@2166
   130
	{
dvander@2166
   131
		SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false);
dvander@2166
   132
		SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true);
dvander@2166
   133
		g_pExecPtr = NULL;
dvander@2166
   134
	}
ds@1952
   135
}
ds@1952
   136
ds@1952
   137
void CoreConfig::OnSourceModLevelChange(const char *mapName)
ds@1952
   138
{
dvander@2166
   139
	static bool already_checked = false;
dvander@2166
   140
dvander@2166
   141
	if (!already_checked)
dvander@2166
   142
	{
dvander@2166
   143
		g_ServerCfgFile = icvar->FindVar("servercfgfile");
dvander@2166
   144
		if (g_ServerCfgFile != NULL)
dvander@2166
   145
		{
dvander@2166
   146
			ConCommandBase *pBase = icvar->GetCommands();
dvander@2166
   147
			while (pBase != NULL)
dvander@2166
   148
			{
dvander@2166
   149
				if (pBase->IsCommand() && strcmp(pBase->GetName(), "exec") == 0)
dvander@2166
   150
				{
dvander@2166
   151
					break;
dvander@2166
   152
				}
dvander@2166
   153
				pBase = const_cast<ConCommandBase *>(pBase->GetNext());
dvander@2166
   154
			}
dvander@2166
   155
dvander@2166
   156
			g_pExecPtr = (ConCommand *)pBase;
dvander@2166
   157
			if (g_pExecPtr != NULL)
dvander@2166
   158
			{
dvander@2166
   159
				SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false);
dvander@2166
   160
				SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true);
dvander@2166
   161
			}
dvander@2166
   162
			else
dvander@2166
   163
			{
dvander@2166
   164
				g_ServerCfgFile = NULL;
dvander@2166
   165
			}
dvander@2166
   166
		}
dvander@2166
   167
		already_checked = true;
dvander@2166
   168
	}
dvander@2166
   169
ds@1952
   170
	g_bConfigsExecd = false;
dvander@2166
   171
	g_bServerExecd = false;
dvander@2166
   172
	g_bGotServerStart = false;
dvander@2166
   173
	g_bGotTrigger = false;
ds@1952
   174
}
ds@1952
   175
ds@1952
   176
void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command)
ds@1952
   177
{
ds@1952
   178
	int argcount = command.ArgC();
ds@1952
   179
	if (argcount >= 4)
ds@1952
   180
	{
ds@1952
   181
		const char *option = command.Arg(2);
ds@1952
   182
		const char *value = command.Arg(3);
ds@1952
   183
ds@1952
   184
		char error[255];
ds@1952
   185
ds@1952
   186
		ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error));
ds@1952
   187
ds@1952
   188
		if (res == ConfigResult_Reject)
ds@1952
   189
		{
ds@1952
   190
			g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error);
ds@1952
   191
		} else if (res == ConfigResult_Ignore) {
ds@1952
   192
			g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option);
ds@1952
   193
		} else {
ds@1952
   194
			g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value);
ds@1952
   195
		}
ds@1952
   196
ds@1952
   197
		return;
ds@1952
   198
	}
ds@1952
   199
ds@1952
   200
	g_RootMenu.ConsolePrint("[SM] Usage: sm config <option> <value>");
ds@1952
   201
}
ds@1952
   202
ds@1952
   203
void CoreConfig::Initialize()
ds@1952
   204
{
ds@1952
   205
	SMCError err;
ds@1952
   206
	char filePath[PLATFORM_MAX_PATH];
ds@1952
   207
ds@1952
   208
	/* Try to get command line value of core config convar */
ds@1952
   209
	const char *corecfg = icvar->GetCommandLineValue("sm_corecfgfile");
ds@1952
   210
ds@1952
   211
	/* If sm_corecfgfile not specified on command line, use default value */
ds@1952
   212
	if (!corecfg)
ds@1952
   213
	{
ds@1952
   214
		corecfg = sm_corecfgfile.GetDefault();
ds@1952
   215
	}
ds@1952
   216
ds@1952
   217
	/* Format path to config file */
ds@1952
   218
	g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg);
ds@1952
   219
ds@1952
   220
	/* Parse config file */
ds@1952
   221
	if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay)
ds@1952
   222
	{
ds@1952
   223
 		/* :TODO: This won't actually log or print anything :( - So fix that somehow */
ds@1952
   224
		const char *error = textparsers->GetSMCErrorString(err);
ds@1952
   225
		g_Logger.LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : "");
ds@1952
   226
	}
ds@1952
   227
}
ds@1952
   228
ds@1952
   229
SMCResult CoreConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
ds@1952
   230
{
ds@1952
   231
	char error[255];
ds@1952
   232
	ConfigResult err = SetConfigOption(key, value, ConfigSource_File, error, sizeof(error));
ds@1952
   233
ds@1952
   234
	if (err == ConfigResult_Reject)
ds@1952
   235
	{
ds@1952
   236
		/* This is a fatal error */
ds@1952
   237
		g_Logger.LogFatal("Config error (key: %s) (value: %s) %s", key, value, error);
ds@1952
   238
	}
ds@1952
   239
ds@1952
   240
	return SMCResult_Continue;
ds@1952
   241
}
ds@1952
   242
ds@1952
   243
ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value, ConfigSource source, char *error, size_t maxlength)
ds@1952
   244
{
ds@1952
   245
	ConfigResult result;
ds@1952
   246
ds@1952
   247
	/* Notify! */
ds@1952
   248
	SMGlobalClass *pBase = SMGlobalClass::head;
ds@1952
   249
	while (pBase)
ds@1952
   250
	{
ds@1952
   251
		if ((result = pBase->OnSourceModConfigChanged(option, value, source, error, maxlength)) != ConfigResult_Ignore)
ds@1952
   252
		{
ds@1952
   253
			return result;
ds@1952
   254
		}
ds@1952
   255
		pBase = pBase->m_pGlobalClassNext;
ds@1952
   256
	}
ds@1952
   257
ds@1952
   258
	return ConfigResult_Ignore;
ds@1952
   259
}
ds@1952
   260
ds@1952
   261
bool SM_AreConfigsExecuted()
ds@1952
   262
{
ds@1952
   263
	return g_bConfigsExecd;
ds@1952
   264
}
ds@1952
   265
ds@1952
   266
inline bool IsPathSepChar(char c)
ds@1952
   267
{
ds@1952
   268
#if defined PLATFORM_WINDOWS
ds@1952
   269
	return (c == '\\' || c == '/');
ds@1952
   270
#elif defined PLATFORM_LINUX
ds@1952
   271
	return (c == '/');
ds@1952
   272
#endif
ds@1952
   273
}
ds@1952
   274
ds@1952
   275
bool SM_ExecuteConfig(CPlugin *pl, AutoConfig *cfg, bool can_create)
ds@1952
   276
{
ds@1952
   277
	bool will_create = false;
ds@1952
   278
	
ds@1952
   279
	/* See if we should be creating */
ds@1952
   280
	if (can_create && cfg->create)
ds@1952
   281
	{
ds@1952
   282
		will_create = true;
ds@1952
   283
		
ds@1952
   284
		/* If the folder does not exist, attempt to create it.  
ds@1952
   285
		 * We're awfully nice.
ds@1952
   286
		 */
ds@1952
   287
		const char *folder = cfg->folder.c_str();
ds@1952
   288
		char path[PLATFORM_MAX_PATH];
ds@1952
   289
		char build[PLATFORM_MAX_PATH];
ds@1952
   290
ds@1952
   291
		g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "cfg/%s", folder);
ds@1952
   292
ds@1952
   293
		if (!g_LibSys.IsPathDirectory(path))
ds@1952
   294
		{
ds@1952
   295
			char *cur_ptr = path;
ds@1952
   296
			size_t len;
ds@1952
   297
			
ds@1952
   298
			g_LibSys.PathFormat(path, sizeof(path), "%s", folder);
ds@1952
   299
			len = g_SourceMod.BuildPath(Path_Game, build, sizeof(build), "cfg");
ds@1952
   300
ds@1952
   301
			do
ds@1952
   302
			{
ds@1952
   303
				/* Find next suitable path */
ds@1952
   304
				char *next_ptr = cur_ptr;
ds@1952
   305
				while (*next_ptr != '\0')
ds@1952
   306
				{
ds@1952
   307
					if (IsPathSepChar(*next_ptr))
ds@1952
   308
					{
ds@1952
   309
						*next_ptr = '\0';
ds@1952
   310
						next_ptr++;
ds@1952
   311
						break;
ds@1952
   312
					}
ds@1952
   313
					next_ptr++;
ds@1952
   314
				}
ds@1952
   315
				if (*next_ptr == '\0')
ds@1952
   316
				{
ds@1952
   317
					next_ptr = NULL;
ds@1952
   318
				}
ds@1952
   319
				len += g_LibSys.PathFormat(&build[len], 
ds@1952
   320
					sizeof(build)-len,
ds@1952
   321
					"/%s",
ds@1952
   322
					cur_ptr);
ds@1952
   323
				if (!g_LibSys.CreateFolder(build))
ds@1952
   324
				{
ds@1952
   325
					break;
ds@1952
   326
				}
ds@1952
   327
				cur_ptr = next_ptr;
ds@1952
   328
			} while (cur_ptr);
ds@1952
   329
		}
ds@1952
   330
	}
ds@1952
   331
ds@1952
   332
	/* Check if the file exists. */
ds@1952
   333
	char file[PLATFORM_MAX_PATH];
ds@1952
   334
	char local[PLATFORM_MAX_PATH];
ds@1952
   335
ds@1952
   336
	if (cfg->folder.size())
ds@1952
   337
	{
ds@1952
   338
		g_LibSys.PathFormat(local, 
ds@1952
   339
			sizeof(local), 
ds@1952
   340
			"%s/%s.cfg",
ds@1952
   341
			cfg->folder.c_str(),
ds@1952
   342
			cfg->autocfg.c_str());
ds@1952
   343
	} else {
ds@1952
   344
		g_LibSys.PathFormat(local,
ds@1952
   345
			sizeof(local),
ds@1952
   346
			"%s.cfg",
ds@1952
   347
			cfg->autocfg.c_str());
ds@1952
   348
	}
ds@1952
   349
	
ds@1952
   350
	g_SourceMod.BuildPath(Path_Game, file, sizeof(file), "cfg/%s", local);
ds@1952
   351
ds@1952
   352
	bool file_exists = g_LibSys.IsPathFile(file);
ds@1952
   353
	if (!file_exists && will_create)
ds@1952
   354
	{
ds@1952
   355
		List<const ConVar *> *convars = NULL;
ds@1952
   356
		if (pl->GetProperty("ConVarList", (void **)&convars, false) && convars)
ds@1952
   357
		{
ds@1952
   358
			/* Attempt to create it */
ds@1952
   359
			FILE *fp = fopen(file, "wt");
ds@1952
   360
			if (fp)
ds@1952
   361
			{
ds@1952
   362
				fprintf(fp, "// This file was auto-generated by SourceMod (v%s)\n", SVN_FULL_VERSION);
ds@1952
   363
				fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename());
ds@1952
   364
				fprintf(fp, "\n\n");
ds@1952
   365
ds@1952
   366
				List<const ConVar *>::iterator iter;
ds@1952
   367
				float x;
ds@1952
   368
				for (iter = convars->begin(); iter != convars->end(); iter++)
ds@1952
   369
				{
ds@1952
   370
					const ConVar *cvar = (*iter);
ds@1952
   371
ds@1952
   372
					if ((cvar->GetFlags() & FCVAR_DONTRECORD) == FCVAR_DONTRECORD)
ds@1952
   373
					{
ds@1952
   374
						continue;
ds@1952
   375
					}
ds@1952
   376
ds@1952
   377
					char descr[255];
ds@1952
   378
					char *dptr = descr;
ds@1952
   379
ds@1952
   380
					/* Print comments until there is no more */
ds@1952
   381
					strncopy(descr, cvar->GetHelpText(), sizeof(descr));
ds@1952
   382
					while (*dptr != '\0')
ds@1952
   383
					{
ds@1952
   384
						/* Find the next line */
ds@1952
   385
						char *next_ptr = dptr;
ds@1952
   386
						while (*next_ptr != '\0')
ds@1952
   387
						{
ds@1952
   388
							if (*next_ptr == '\n')
ds@1952
   389
							{
ds@1952
   390
								*next_ptr = '\0';
ds@1952
   391
								next_ptr++;
ds@1952
   392
								break;
ds@1952
   393
							}
ds@1952
   394
							next_ptr++;
ds@1952
   395
						}
ds@1952
   396
						fprintf(fp, "// %s\n", dptr);
ds@1952
   397
						dptr = next_ptr;
ds@1952
   398
					}
ds@1952
   399
ds@1952
   400
					fprintf(fp, "// -\n");
ds@1952
   401
					fprintf(fp, "// Default: \"%s\"\n", cvar->GetDefault());
ds@1952
   402
					if (cvar->GetMin(x))
ds@1952
   403
					{
ds@1952
   404
						fprintf(fp, "// Minimum: \"%02f\"\n", x);
ds@1952
   405
					}
ds@1952
   406
					if (cvar->GetMax(x))
ds@1952
   407
					{
ds@1952
   408
						fprintf(fp, "// Maximum: \"%02f\"\n", x);
ds@1952
   409
					}
ds@1952
   410
					fprintf(fp, "%s \"%s\"\n", cvar->GetName(), cvar->GetDefault());
ds@1952
   411
					fprintf(fp, "\n");
ds@1952
   412
				}
ds@1952
   413
				fprintf(fp, "\n");
ds@1952
   414
ds@1952
   415
				file_exists = true;
ds@1952
   416
				can_create = false;
ds@1952
   417
				fclose(fp);
ds@1952
   418
			}
ds@1952
   419
		}
ds@1952
   420
	}
ds@1952
   421
ds@1952
   422
	if (file_exists)
ds@1952
   423
	{
ds@1952
   424
		char cmd[255];
ds@1952
   425
		UTIL_Format(cmd, sizeof(cmd), "exec %s\n", local);
ds@1952
   426
		engine->ServerCommand(cmd);
ds@1952
   427
	}
ds@1952
   428
ds@1952
   429
	return can_create;
ds@1952
   430
}
ds@1952
   431
ds@1952
   432
void SM_DoSingleExecFwds(IPluginContext *ctx)
ds@1952
   433
{
ds@1952
   434
	IPluginFunction *pf;
ds@1952
   435
ds@1952
   436
	if ((pf = ctx->GetFunctionByName("OnServerCfg")) != NULL)
ds@1952
   437
	{
ds@1952
   438
		pf->Execute(NULL);
ds@1952
   439
	}
ds@1952
   440
ds@1952
   441
	if ((pf = ctx->GetFunctionByName("OnConfigsExecuted")) != NULL)
ds@1952
   442
	{
ds@1952
   443
		pf->Execute(NULL);
ds@1952
   444
	}
ds@1952
   445
}
ds@1952
   446
ds@1952
   447
void SM_ConfigsExecuted_Plugin(unsigned int serial)
ds@1952
   448
{
ds@1952
   449
	IPluginIterator *iter = g_PluginSys.GetPluginIterator();
ds@1952
   450
	while (iter->MorePlugins())
ds@1952
   451
	{
ds@1952
   452
		CPlugin *plugin = (CPlugin *)(iter->GetPlugin());
ds@1952
   453
		if (plugin->GetSerial() == serial)
ds@1952
   454
		{
ds@1952
   455
			SM_DoSingleExecFwds(plugin->GetBaseContext());
ds@1952
   456
			break;
ds@1952
   457
		}
ds@1952
   458
		iter->NextPlugin();
ds@1952
   459
	}
ds@1952
   460
	iter->Release();
ds@1952
   461
}
ds@1952
   462
ds@1952
   463
void SM_ExecuteForPlugin(IPluginContext *ctx)
ds@1952
   464
{
ds@1952
   465
	CPlugin *plugin = (CPlugin *)g_PluginSys.GetPluginByCtx(ctx->GetContext());
ds@1952
   466
ds@1952
   467
	unsigned int num = plugin->GetConfigCount();
ds@1952
   468
	if (!num)
ds@1952
   469
	{
ds@1952
   470
		SM_DoSingleExecFwds(ctx);
ds@1952
   471
	}
ds@1952
   472
	else
ds@1952
   473
	{
ds@1952
   474
		bool can_create = true;
ds@1952
   475
		for (unsigned int i=0; i<num; i++)
ds@1952
   476
		{
ds@1952
   477
			can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
ds@1952
   478
		}
ds@1952
   479
		char cmd[255];
ds@1952
   480
		UTIL_Format(cmd, sizeof(cmd), "sm internal 2 %d\n", plugin->GetSerial());
ds@1952
   481
		engine->ServerCommand(cmd);
ds@1952
   482
	}
ds@1952
   483
}
ds@1952
   484
ds@1952
   485
void SM_ExecuteAllConfigs()
ds@1952
   486
{
dvander@2166
   487
	if (g_bGotServerStart)
ds@1952
   488
	{
ds@1952
   489
		return;
ds@1952
   490
	}
ds@1952
   491
ds@1952
   492
	engine->ServerCommand("exec sourcemod/sourcemod.cfg\n");
ds@1952
   493
ds@1952
   494
	IPluginIterator *iter = g_PluginSys.GetPluginIterator();
ds@1952
   495
	while (iter->MorePlugins())
ds@1952
   496
	{
ds@1952
   497
		CPlugin *plugin = (CPlugin *)(iter->GetPlugin());
ds@1952
   498
		unsigned int num = plugin->GetConfigCount();
ds@1952
   499
		bool can_create = true;
ds@1952
   500
		for (unsigned int i=0; i<num; i++)
ds@1952
   501
		{
ds@1952
   502
			can_create = SM_ExecuteConfig(plugin, plugin->GetConfig(i), can_create);
ds@1952
   503
		}
ds@1952
   504
		iter->NextPlugin();
ds@1952
   505
	}
ds@1952
   506
	iter->Release();
ds@1952
   507
dvander@2166
   508
	g_bGotServerStart = true;
dvander@2166
   509
	CheckAndFinalizeConfigs();
ds@1952
   510
}
ds@1952
   511
ds@1952
   512
void SM_ConfigsExecuted_Global()
ds@1952
   513
{
ds@1952
   514
	if (g_bConfigsExecd)
ds@1952
   515
	{
ds@1952
   516
		return;
ds@1952
   517
	}
ds@1952
   518
ds@1952
   519
	g_bConfigsExecd = true;
ds@1952
   520
ds@1952
   521
	g_pOnServerCfg->Execute(NULL);
ds@1952
   522
	g_pOnConfigsExecuted->Execute(NULL);
ds@1952
   523
}
dvander@2235
   524
dvander@2235
   525
void SM_InternalCmdTrigger()
dvander@2235
   526
{
dvander@2235
   527
	/* Order is important here.  We need to buffer things before we send the command out. */
dvander@2235
   528
	g_pOnAutoConfigsBuffered->Execute(NULL);
dvander@2235
   529
	engine->ServerCommand("sm internal 1\n");
dvander@2235
   530
    g_PendingInternalPush = false;
dvander@2235
   531
}
dvander@2235
   532