Example #1
0
static cell AMX_NATIVE_CALL set_native_filter(AMX *amx, cell *params)
{
    Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];

    if (!pHandler)
    {
        Debugger::GenericMessage(amx, AMX_ERR_NOTFOUND);
        AMXXLOG_Error("[AMXX] Plugin not initialized correctly.");
        return 0;
    }

    if (!pHandler->IsNativeFiltering())
    {
        //we can only initialize this during PRENIT
        if (! (amx->flags & AMX_FLAG_PRENIT) )
            return 0;
    }

    int len;
    char *func = get_amxstring(amx, params[1], 0, len);

    int err = pHandler->SetNativeFilter(func);

    if (err != AMX_ERR_NONE)
    {
        Debugger::GenericMessage(amx, AMX_ERR_NOTFOUND);
        AMXXLOG_Error("[AMXX] Function not found: %s", function);
        return 0;
    }

    return 1;
}
Example #2
0
static cell AMX_NATIVE_CALL invalid_native(AMX *amx, cell *params)
{
	//A script has accidentally called an invalid native! give them a
	// first chance to block the resulting error.

	Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];

	//this should never happen
	if (!pHandler)
	{
		LogError(amx, AMX_ERR_INVNATIVE, "Invalid native attempt");
		return 0;
	}

	//this should never happen because this native won't be called
	// if the plugin isn't filtering.
	if (!pHandler->IsNativeFiltering())
	{
		LogError(amx, AMX_ERR_INVNATIVE, "Invalid native attempt");
		return 0;
	}

	char name[sNAMEMAX + 1];
	int native = (int)(_INT_PTR)(amx->usertags[UT_NATIVE]);
	int err = amx_GetNative(amx, native, name);

	if (err != AMX_ERR_NONE)
		name[0] = '\0';

	//1 - because we're trapping usage
	if (!pHandler->HandleNative(name, native, 1))
	{
		amx->usertags[UT_NATIVE] = (void *)native;
		LogError(amx, AMX_ERR_INVNATIVE, NULL);
		return 0;
	}

	//Someday maybe allow native filters to write their own return value?
	return 0;
}
Example #3
0
void CPluginMngr::CPlugin::Finalize()
{
	char buffer[128];
	int old_status = status;

	if (CheckModules(&amx, buffer))
	{
		if (amx_Register(&amx, core_Natives, -1) != AMX_ERR_NONE)
		{
			Handler *pHandler = (Handler *)amx.userdata[UD_HANDLER];
			int res = 0;

			if (pHandler->IsNativeFiltering())
				res = amx_CheckNatives(&amx, native_handler);

			if (!res)
			{
				status = ps_bad_load;
				sprintf(buffer, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function);
				errorMsg = buffer;
				amx.error = AMX_ERR_NOTFOUND;
			} else {
				amx_RegisterToAny(&amx, invalid_native);
			}
		}
	} else {
		status = ps_bad_load;
		errorMsg = buffer;
		amx.error = AMX_ERR_NOTFOUND;
	}

	if (old_status != status)
	{
		AMXXLOG_Log("[AMXX] Plugin \"%s\" failed to load: %s", name.chars(), errorMsg.chars());
	}
}