static cell_t sm_CallFinish(IPluginContext *pContext, const cell_t *params)
{
	int err = SP_ERROR_NOT_RUNNABLE;
	cell_t *result;

	if (!s_CallStarted)
	{
		return pContext->ThrowNativeError("Cannot finish call when there is no call in progress");
	}

	pContext->LocalToPhysAddr(params[1], &result);

	if (s_pFunction)
	{
		IPluginFunction *pFunction = s_pFunction;
		ResetCall();
		err = pFunction->Execute(result);
	} else if (s_pForward) {
		IForward *pForward = s_pForward;
		ResetCall();
		err = pForward->Execute(result, NULL);
	}

	return err;
}
static cell_t sm_CallStartFunction(IPluginContext *pContext, const cell_t *params)
{
	Handle_t hndl;
	HandleError err;
	IPlugin *pPlugin;

	ResetCall();

	hndl = static_cast<Handle_t>(params[1]);

	if (hndl == 0)
	{
		pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext());
	} else {
		pPlugin = g_PluginSys.PluginFromHandle(hndl, &err);

		if (!pPlugin)
		{
			return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err);
		}
	}

	s_pFunction = pPlugin->GetBaseContext()->GetFunctionById(params[2]);

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

	s_pCallable = static_cast<ICallable *>(s_pFunction);

	s_CallStarted = true;

	return 1;
}
Esempio n. 3
0
static cell_t sm_CallStartForward(IPluginContext *pContext, const cell_t *params)
{
	Handle_t hndl;
	HandleError err;
	IForward *pForward;
	HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);

	ResetCall();

	hndl = static_cast<Handle_t>(params[1]);

	if ((err=handlesys->ReadHandle(hndl, g_GlobalFwdType, &sec, (void **)&pForward))
		!= HandleError_None)
	{
		return pContext->ThrowNativeError("Invalid forward handle %x (error %d)", hndl, err);
	}

	s_pForward = pForward;

	s_pCallable = static_cast<ICallable *>(pForward);

	s_CallStarted = true;

	return 1;
}
static cell_t sm_CallCancel(IPluginContext *pContext, const cell_t *params)
{
	if (!s_CallStarted)
	{
		return pContext->ThrowNativeError("Cannot cancel call when there is no call in progress");
	}

	s_pCallable->Cancel();
	ResetCall();

	return 1;
}
static cell_t sm_CallPushFloat(IPluginContext *pContext, const cell_t *params)
{
	int err;

	if (!s_CallStarted)
	{
		return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress");
	}

	err = s_pCallable->PushFloat(sp_ctof(params[1]));

	if (err)
	{
		s_pCallable->Cancel();
		ResetCall();
		return pContext->ThrowNativeErrorEx(err, NULL);
	}

	return 1;
}
static cell_t sm_CallPushStringEx(IPluginContext *pContext, const cell_t *params)
{
	int err;
	char *value;

	if (!s_CallStarted)
	{
		return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress");
	}

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

	err = s_pCallable->PushStringEx(value, params[2], params[3], params[4]);

	if (err)
	{
		s_pCallable->Cancel();
		ResetCall();
		return pContext->ThrowNativeErrorEx(err, NULL);
	}

	return 1;
}
static cell_t sm_CallPushArrayEx(IPluginContext *pContext, const cell_t *params)
{
	int err;
	cell_t *addr;

	if (!s_CallStarted)
	{
		return pContext->ThrowNativeError("Cannot push parameters when there is no call in progress");
	}

	pContext->LocalToPhysAddr(params[1], &addr);

	err = s_pCallable->PushArray(addr, params[2], params[3]);

	if (err)
	{
		s_pCallable->Cancel();
		ResetCall();
		return pContext->ThrowNativeErrorEx(err, NULL);
	}

	return 1;
}