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