changed the two init/unload forwards to have easier names
authorDavid Anderson <dvander@alliedmods.net>
Thu Jan 25 02:10:43 2007 +0000 (2007-01-25)
changeset 340c39c68f4874c
parent 339 5c9d28dacfc4
child 341 94f9b674ecd6
changed the two init/unload forwards to have easier names
added text parsing natives
core/msvc8/sourcemod_mm.vcproj
core/smn_textparse.cpp
core/sourcemod.cpp
core/systems/PluginSys.cpp
     1.1 --- a/core/msvc8/sourcemod_mm.vcproj	Thu Jan 25 01:59:37 2007 +0000
     1.2 +++ b/core/msvc8/sourcemod_mm.vcproj	Thu Jan 25 02:10:43 2007 +0000
     1.3 @@ -252,6 +252,10 @@
     1.4  				>
     1.5  			</File>
     1.6  			<File
     1.7 +				RelativePath="..\smn_textparse.cpp"
     1.8 +				>
     1.9 +			</File>
    1.10 +			<File
    1.11  				RelativePath="..\sourcemm_api.cpp"
    1.12  				>
    1.13  			</File>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/core/smn_textparse.cpp	Thu Jan 25 02:10:43 2007 +0000
     2.3 @@ -0,0 +1,285 @@
     2.4 +#include "sm_globals.h"
     2.5 +#include "CTextParsers.h"
     2.6 +#include "HandleSys.h"
     2.7 +
     2.8 +HandleType_t g_TypeSMC = 0;
     2.9 +
    2.10 +class ParseInfo : public ITextListener_SMC
    2.11 +{
    2.12 +public:
    2.13 +	ParseInfo()
    2.14 +	{
    2.15 +		parse_start = NULL;
    2.16 +		parse_end = NULL;
    2.17 +		new_section = NULL;
    2.18 +		key_value = NULL;
    2.19 +		end_section = NULL;
    2.20 +		raw_line = NULL;
    2.21 +		handle = 0;
    2.22 +	}
    2.23 +public:
    2.24 +	void ReadSMC_ParseStart()
    2.25 +	{
    2.26 +		if (parse_start)
    2.27 +		{
    2.28 +			cell_t result;
    2.29 +			parse_start->PushCell(handle);
    2.30 +			parse_start->Execute(&result);
    2.31 +		}
    2.32 +	}
    2.33 +
    2.34 +	void ReadSMC_ParseEnd(bool halted, bool failed)
    2.35 +	{
    2.36 +		if (parse_end)
    2.37 +		{
    2.38 +			cell_t result;
    2.39 +			parse_start->PushCell(handle);
    2.40 +			parse_end->PushCell(halted ? 1 : 0);
    2.41 +			parse_end->PushCell(failed ? 1 : 0);
    2.42 +			parse_end->Execute(&result);
    2.43 +		}
    2.44 +	}
    2.45 +
    2.46 +	SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes)
    2.47 +	{
    2.48 +		cell_t result = SMCParse_Continue;
    2.49 +
    2.50 +		if (new_section)
    2.51 +		{
    2.52 +			new_section->PushCell(handle);
    2.53 +			new_section->PushString(name);
    2.54 +			new_section->PushCell(opt_quotes ? 1 : 0);
    2.55 +			new_section->Execute(&result);
    2.56 +		}
    2.57 +
    2.58 +		return (SMCParseResult)result;
    2.59 +	}
    2.60 +
    2.61 +	SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
    2.62 +	{
    2.63 +		cell_t result = SMCParse_Continue;
    2.64 +
    2.65 +		if (key_value)
    2.66 +		{
    2.67 +			key_value->PushCell(handle);
    2.68 +			key_value->PushString(key);
    2.69 +			key_value->PushString(value);
    2.70 +			key_value->PushCell(key_quotes ? 1 : 0);
    2.71 +			key_value->PushCell(value_quotes ? 1 : 0);
    2.72 +			key_value->Execute(&result);
    2.73 +		}
    2.74 +
    2.75 +		return (SMCParseResult)result;
    2.76 +	}
    2.77 +
    2.78 +	SMCParseResult ReadSMC_LeavingSection()
    2.79 +	{
    2.80 +		cell_t result = SMCParse_Continue;
    2.81 +
    2.82 +		if (end_section)
    2.83 +		{
    2.84 +			end_section->PushCell(handle);
    2.85 +			end_section->Execute(&result);
    2.86 +		}
    2.87 +
    2.88 +		return (SMCParseResult)result;
    2.89 +	}
    2.90 +
    2.91 +	SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline)
    2.92 +	{
    2.93 +		cell_t result = SMCParse_Continue;
    2.94 +
    2.95 +		if (raw_line)
    2.96 +		{
    2.97 +			raw_line->PushCell(handle);
    2.98 +			raw_line->PushString(line);
    2.99 +			raw_line->PushCell(curline);
   2.100 +			raw_line->Execute(&result);
   2.101 +		}
   2.102 +
   2.103 +		return (SMCParseResult)result;
   2.104 +	}
   2.105 +public:
   2.106 +	IPluginFunction *parse_start;
   2.107 +	IPluginFunction *parse_end;
   2.108 +	IPluginFunction *new_section;
   2.109 +	IPluginFunction *key_value;
   2.110 +	IPluginFunction *end_section;
   2.111 +	IPluginFunction *raw_line;
   2.112 +	Handle_t handle;
   2.113 +};
   2.114 +
   2.115 +class TextParseGlobals : 
   2.116 +	public SMGlobalClass,
   2.117 +	public IHandleTypeDispatch
   2.118 +{
   2.119 +public:
   2.120 +	void OnSourceModAllInitialized()
   2.121 +	{
   2.122 +		HandleAccess sec;
   2.123 +
   2.124 +		/* These cannot be cloned, because they are locked to a specific plugin.
   2.125 +		 * However, we let anyone read them because we don't care.
   2.126 +		 */
   2.127 +		g_HandleSys.InitAccessDefaults(NULL, &sec);
   2.128 +		sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY;
   2.129 +		sec.access[HandleAccess_Read] = 0;
   2.130 +
   2.131 +		g_TypeSMC = g_HandleSys.CreateType("SMCParser", this, 0, NULL, &sec, g_pCoreIdent, NULL);
   2.132 +	}
   2.133 +
   2.134 +	void OnSourceModShutdown()
   2.135 +	{
   2.136 +		g_HandleSys.RemoveType(g_TypeSMC, g_pCoreIdent);
   2.137 +	}
   2.138 +
   2.139 +	void OnHandleDestroy(HandleType_t type, void *object)
   2.140 +	{
   2.141 +		ParseInfo *parse = (ParseInfo *)object;
   2.142 +		delete parse;
   2.143 +	}
   2.144 +};
   2.145 +
   2.146 +TextParseGlobals g_TextParseGlobals;
   2.147 +
   2.148 +static cell_t SMC_CreateParse(IPluginContext *pContext, const cell_t *params)
   2.149 +{
   2.150 +	ParseInfo *pInfo = new ParseInfo();
   2.151 +
   2.152 +	Handle_t hndl = g_HandleSys.CreateHandle(g_TypeSMC, pInfo, pContext->GetIdentity(), g_pCoreIdent, NULL);
   2.153 +
   2.154 +	/* Should never happen */
   2.155 +	if (!hndl)
   2.156 +	{
   2.157 +		delete pInfo;
   2.158 +		return 0;
   2.159 +	}
   2.160 +
   2.161 +	pInfo->handle = hndl;
   2.162 +
   2.163 +	return hndl;
   2.164 +}
   2.165 +
   2.166 +static cell_t SMC_SetParseStart(IPluginContext *pContext, const cell_t *params)
   2.167 +{
   2.168 +	Handle_t hndl = (Handle_t)params[1];
   2.169 +	HandleError err;
   2.170 +	ParseInfo *parse;
   2.171 +
   2.172 +	if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
   2.173 +		!= HandleError_None)
   2.174 +	{
   2.175 +		return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
   2.176 +	}
   2.177 +
   2.178 +	parse->parse_start = pContext->GetFunctionById((funcid_t)params[2]);
   2.179 +
   2.180 +	return 1;
   2.181 +}
   2.182 +
   2.183 +static cell_t SMC_SetParseEnd(IPluginContext *pContext, const cell_t *params)
   2.184 +{
   2.185 +	Handle_t hndl = (Handle_t)params[1];
   2.186 +	HandleError err;
   2.187 +	ParseInfo *parse;
   2.188 +
   2.189 +	if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
   2.190 +		!= HandleError_None)
   2.191 +	{
   2.192 +		return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
   2.193 +	}
   2.194 +
   2.195 +	parse->parse_end = pContext->GetFunctionById((funcid_t)params[2]);
   2.196 +
   2.197 +	return 1;
   2.198 +}
   2.199 +
   2.200 +static cell_t SMC_SetReaders(IPluginContext *pContext, const cell_t *params)
   2.201 +{
   2.202 +	Handle_t hndl = (Handle_t)params[1];
   2.203 +	HandleError err;
   2.204 +	ParseInfo *parse;
   2.205 +
   2.206 +	if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
   2.207 +		!= HandleError_None)
   2.208 +	{
   2.209 +		return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
   2.210 +	}
   2.211 +
   2.212 +	parse->new_section = pContext->GetFunctionById((funcid_t)params[2]);
   2.213 +	parse->key_value = pContext->GetFunctionById((funcid_t)params[3]);
   2.214 +	parse->end_section = pContext->GetFunctionById((funcid_t)params[4]);
   2.215 +
   2.216 +	return 1;
   2.217 +}
   2.218 +
   2.219 +static cell_t SMC_SetRawLine(IPluginContext *pContext, const cell_t *params)
   2.220 +{
   2.221 +	Handle_t hndl = (Handle_t)params[1];
   2.222 +	HandleError err;
   2.223 +	ParseInfo *parse;
   2.224 +
   2.225 +	if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
   2.226 +		!= HandleError_None)
   2.227 +	{
   2.228 +		return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
   2.229 +	}
   2.230 +
   2.231 +	parse->raw_line = pContext->GetFunctionById((funcid_t)params[2]);
   2.232 +
   2.233 +	return 1;
   2.234 +}
   2.235 +
   2.236 +static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params)
   2.237 +{
   2.238 +	Handle_t hndl = (Handle_t)params[1];
   2.239 +	HandleError err;
   2.240 +	ParseInfo *parse;
   2.241 +
   2.242 +	if ((err=g_HandleSys.ReadHandle(hndl, g_TypeSMC, NULL, (void **)&parse))
   2.243 +		!= HandleError_None)
   2.244 +	{
   2.245 +		return pContext->ThrowNativeError("Invalid SMC Parse Handle %x (error %d)", hndl, err);
   2.246 +	}
   2.247 +
   2.248 +	char *file;
   2.249 +	pContext->LocalToString(params[2], &file);
   2.250 +
   2.251 +	char path[PLATFORM_MAX_PATH];
   2.252 +	g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "%s", file);
   2.253 +
   2.254 +	unsigned int line = 0, col = 0;
   2.255 +	SMCParseError p_err = g_TextParser.ParseFile_SMC(path, parse, &line, &col);
   2.256 +
   2.257 +	cell_t *c_line, *c_col;
   2.258 +	pContext->LocalToPhysAddr(params[3], &c_line);
   2.259 +	pContext->LocalToPhysAddr(params[4], &c_col);
   2.260 +
   2.261 +	return (cell_t)p_err;
   2.262 +}
   2.263 +
   2.264 +static cell_t SMC_GetErrorString(IPluginContext *pContext, const cell_t *params)
   2.265 +{
   2.266 +	const char *str = g_TextParser.GetSMCErrorString((SMCParseError)params[1]);
   2.267 +
   2.268 +	if (!str)
   2.269 +	{
   2.270 +		return 0;
   2.271 +	}
   2.272 +
   2.273 +	pContext->StringToLocal(params[2], params[3], str);
   2.274 +
   2.275 +	return 1;
   2.276 +}
   2.277 +
   2.278 +REGISTER_NATIVES(textNatives)
   2.279 +{
   2.280 +	{"SMC_CreateParse",				SMC_CreateParse},
   2.281 +	{"SMC_ParseFile",				SMC_ParseFile},
   2.282 +	{"SMC_GetErrorString",			SMC_GetErrorString},
   2.283 +	{"SMC_SetParseStart",			SMC_SetParseStart},
   2.284 +	{"SMC_SetParseEnd",				SMC_SetParseEnd},
   2.285 +	{"SMC_SetReaders",				SMC_SetReaders},
   2.286 +	{"SMC_SetRawLine",				SMC_SetRawLine},
   2.287 +	{NULL,							NULL},
   2.288 +};
     3.1 --- a/core/sourcemod.cpp	Thu Jan 25 01:59:37 2007 +0000
     3.2 +++ b/core/sourcemod.cpp	Thu Jan 25 02:10:43 2007 +0000
     3.3 @@ -8,6 +8,7 @@
     3.4  #include "ShareSys.h"
     3.5  #include "CLogger.h"
     3.6  #include "ExtensionSys.h"
     3.7 +#include "AdminCache.h"
     3.8  
     3.9  SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
    3.10  SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    3.11 @@ -169,6 +170,8 @@
    3.12  
    3.13  	m_IsMapLoading = false;
    3.14  
    3.15 +	g_Admins.DumpAdminCache(ADMIN_CACHE_GROUPS|ADMIN_CACHE_ADMINS|ADMIN_CACHE_OVERRIDES, true);
    3.16 +
    3.17  	RETURN_META_VALUE(MRES_IGNORED, true);
    3.18  }
    3.19  
     4.1 --- a/core/systems/PluginSys.cpp	Thu Jan 25 01:59:37 2007 +0000
     4.2 +++ b/core/systems/PluginSys.cpp	Thu Jan 25 02:10:43 2007 +0000
     4.3 @@ -238,7 +238,7 @@
     4.4  	m_status = Plugin_Running;
     4.5  
     4.6  	cell_t result;
     4.7 -	IPluginFunction *pFunction = m_ctx.base->GetFunctionByName("OnPluginInit");
     4.8 +	IPluginFunction *pFunction = m_ctx.base->GetFunctionByName("OnPluginStart");
     4.9  	if (!pFunction)
    4.10  	{
    4.11  		return;
    4.12 @@ -256,7 +256,7 @@
    4.13  	}
    4.14  
    4.15  	cell_t result;
    4.16 -	IPluginFunction *pFunction = m_ctx.base->GetFunctionByName("OnPluginUnload");
    4.17 +	IPluginFunction *pFunction = m_ctx.base->GetFunctionByName("OnPluginEnd");
    4.18  	if (!pFunction)
    4.19  	{
    4.20  		return;
    4.21 @@ -1369,8 +1369,12 @@
    4.22  				assert(pl->GetStatus() != Plugin_Created);
    4.23  				int len = 0;
    4.24  				const sm_plugininfo_t *info = pl->GetPublicInfo();
    4.25 -
    4.26 -				len += UTIL_Format(buffer, sizeof(buffer), "  %02d <%s>", id, GetStatusText(pl->GetStatus()));
    4.27 +				if (pl->GetStatus() != Pl_Running)
    4.28 +				{
    4.29 +					len += UTIL_Format(buffer, sizeof(buffer), "  %02d <%s>", id, GetStatusText(pl->GetStatus()));
    4.30 +				} else {
    4.31 +					len += UTIL_Format(buffer, sizeof(buffer), "  %02d", id);
    4.32 +				}
    4.33  				len += UTIL_Format(&buffer[len], sizeof(buffer)-len, " \"%s\"", (IS_STR_FILLED(info->name)) ? info->name : pl->GetFilename());
    4.34  				if (IS_STR_FILLED(info->version))
    4.35  				{