示例#1
0
void LogAction(Handle_t hndl, int type, int client, int target, const char *message)
{
	if (g_OnLogAction->GetFunctionCount())
	{
		cell_t result = 0;
		g_OnLogAction->PushCell(hndl);
		g_OnLogAction->PushCell(type);
		g_OnLogAction->PushCell(client);
		g_OnLogAction->PushCell(target);
		g_OnLogAction->PushString(message);
		g_OnLogAction->Execute(&result);

		if (result >= (ResultType)Pl_Handled)
		{
			return;
		}
	}

	const char *logtag = "SM";
	if (type == 2)
	{
		HandleError err;
		IPlugin *pPlugin = scripts->FindPluginByHandle(hndl, &err);
		if (pPlugin)
		{
			logtag = pPlugin->GetFilename();
		}
	}

	g_Logger.LogMessage("[%s] %s", logtag, message);
}
示例#2
0
static cell_t LogToFile(IPluginContext *pContext, const cell_t *params)
{
	char *file;
	pContext->LocalToString(params[1], &file);

	char path[PLATFORM_MAX_PATH];
	g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file);

	FILE *fp = fopen(path, "at");
	if (!fp)
	{
		return pContext->ThrowNativeError("Could not open file \"%s\"", path);
	}

	char buffer[2048];
	{
		DetectExceptions eh(pContext);
		g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
		g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
		if (eh.HasException()) {
			fclose(fp);
			return 0;
		}
	}

	IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());

	g_Logger.LogToOpenFile(fp, "[%s] %s", pPlugin->GetFilename(), buffer);

	fclose(fp);

	return 1;
}
示例#3
0
static cell_t sm_RegConsoleCmd(IPluginContext *pContext, const cell_t *params)
{
	char *name,*help;
	IPluginFunction *pFunction;

	pContext->LocalToString(params[1], &name);

	if (strcasecmp(name, "sm") == 0)
	{
		return pContext->ThrowNativeError("Cannot register \"sm\" command");
	}

	pContext->LocalToString(params[3], &help);
	pFunction = pContext->GetFunctionById(params[2]);

	if (!pFunction)
	{
		return pContext->ThrowNativeError("Invalid function id (%X)", params[2]);
	}

	IPlugin *pPlugin = scripts->FindPluginByContext(pContext->GetContext());
	const char *group = pPlugin->GetFilename();
	if (!g_ConCmds.AddAdminCommand(pFunction, name, group, 0, help, params[4]))
	{
		return pContext->ThrowNativeError("Command \"%s\" could not be created. A convar with the same name already exists.", name);
	}

	return 1;
}
示例#4
0
void ProfileReport::SaveAtom(const prof_atom_t &atom)
{
	double atom_time;
	char full_name[256];
	prof_atom_report_t **pReport, *report;

	if (atom.atom_type == SP_PROF_NATIVES)
	{
		smcore.strncopy(full_name, atom.name, sizeof(full_name));
	}
	else
	{
		IPlugin *pl;
		const char *file;

		file = "unknown";
		if ((pl = pluginsys->FindPluginByContext(atom.ctx)) != NULL)
		{
			file = pl->GetFilename();
		}

		smcore.Format(full_name, sizeof(full_name), "%s!%s", file, atom.name);
	}

	atom_time = CalcAtomTime(atom);

	if ((pReport = m_ReportLookup.retrieve(full_name)) == NULL)
	{
		report = new prof_atom_report_t;

		smcore.strncopy(report->atom_name, full_name, sizeof(report->atom_name));
		report->max_time = atom_time;
		report->min_time = atom_time;
		report->num_calls = 1;
		report->total_time = atom_time;
		
		m_ReportLookup.insert(full_name, report);
		m_Reports.push_back(report);
	}
	else
	{
		report = *pReport;

		if (atom_time > report->max_time)
		{
			report->max_time = atom_time;
		}
		if (atom_time < report->min_time)
		{
			report->min_time = atom_time;
		}
		report->num_calls++;
		report->total_time += atom_time;
	}
}
示例#5
0
static cell_t GetPluginFilename(IPluginContext *pContext, const cell_t *params)
{
	IPlugin *pPlugin = GetPluginFromHandle(pContext, params[1]);
	if (!pPlugin)
	{
		return 0;
	}

	pContext->StringToLocalUTF8(params[2], params[3], pPlugin->GetFilename(), NULL);

	return 1;
}
示例#6
0
void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs *command)
{
	int argcount = command->ArgC();
	if (argcount >= 3)
	{
		bool wantReset = false;
		
		/* Get plugin index that was passed */
		const char *arg = command->Arg(2);
		if (argcount >= 4 && strcmp(arg, "reset") == 0)
		{
			wantReset = true;
			arg = command->Arg(3);
		}
		
		/* Get plugin object */
		IPlugin *plugin = scripts->FindPluginByConsoleArg(arg);

		if (!plugin)
		{
			UTIL_ConsolePrint("[SM] Plugin \"%s\" was not found.", arg);
			return;
		}

		/* Get plugin name */
		const sm_plugininfo_t *plinfo = plugin->GetPublicInfo();
		const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename();

		ConVarList *pConVarList;
		ConVarList::iterator iter;

		/* If no convar list... */
		if (!plugin->GetProperty("ConVarList", (void **)&pConVarList))
		{
			UTIL_ConsolePrint("[SM] No convars found for: %s", plname);
			return;
		}

		if (!wantReset)
		{
			UTIL_ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname);
			UTIL_ConsolePrint("  %-32.31s %s", "[Name]", "[Value]");
		}
		
		/* Iterate convar list and display/reset each one */
		for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++)
		{
			/*const */ConVar *pConVar = const_cast<ConVar *>(*iter);
			if (!wantReset)
			{
				UTIL_ConsolePrint("  %-32.31s %s", pConVar->GetName(), pConVar->GetString()); 
			} else {
				pConVar->Revert();
			}
		}
		
		if (wantReset)
		{
			UTIL_ConsolePrint("[SM] Reset %d convars for: %s", pConVarList->size(), plname);
		}

		return;
	}

	/* Display usage of subcommand */
	UTIL_ConsolePrint("[SM] Usage: sm cvars [reset] <plugin #>");
}