-
-
Notifications
You must be signed in to change notification settings - Fork 420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for sending gameevent to specific client. #505
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
#include "sm_globals.h" | ||
#include "sourcemm_api.h" | ||
#include "EventManager.h" | ||
#include "PlayerManager.h" | ||
#include "logic_bridge.h" | ||
|
||
static cell_t sm_HookEvent(IPluginContext *pContext, const cell_t *params) | ||
|
@@ -146,6 +147,54 @@ static cell_t sm_FireEvent(IPluginContext *pContext, const cell_t *params) | |
return 1; | ||
} | ||
|
||
static cell_t sm_FireEventToClient(IPluginContext *pContext, const cell_t *params) | ||
{ | ||
Handle_t hndl = static_cast<Handle_t>(params[1]); | ||
HandleError err; | ||
EventInfo *pInfo; | ||
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); | ||
|
||
if ((err = handlesys->ReadHandle(hndl, g_EventManager.GetHandleType(), &sec, (void **)&pInfo)) | ||
!= HandleError_None) | ||
{ | ||
return pContext->ThrowNativeError("Invalid game event handle %x (error %d)", hndl, err); | ||
} | ||
|
||
/* If identities do not match, don't fire event */ | ||
if (pContext->GetIdentity() != pInfo->pOwner) | ||
{ | ||
return pContext->ThrowNativeError("Game event \"%s\" could not be fired because it was not created by this plugin", pInfo->pEvent->GetName()); | ||
} | ||
|
||
if (pInfo->bDontBroadcast) | ||
{ | ||
return pContext->ThrowNativeError("Game event \"%s\" is set to not be broadcasted to clients", pInfo->pEvent->GetName()); | ||
} | ||
|
||
int client = params[2]; | ||
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); | ||
|
||
if (!pPlayer) | ||
{ | ||
return pContext->ThrowNativeError("Client index %d is invalid", client); | ||
} | ||
|
||
if (!pPlayer->IsConnected()) | ||
{ | ||
return pContext->ThrowNativeError("Client %d is not connected", client); | ||
} | ||
|
||
IClient *pClient = pPlayer->GetIClient(); | ||
if (!pClient) | ||
{ | ||
return pContext->ThrowNativeError("Sending events to fakeclients is not supported on this game (client %d)", client); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are super rare cases where a client can be connected but still have an invalid net channel (KAC/SMAC used to cause crashes in convar queries). Despite this, everything looks fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pics or it didn't happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ironically it was part of the code you refactored 😄 https://hg.alliedmods.net/releases/sourcemod-1.3/rev/82cfdef347cc |
||
} | ||
|
||
g_EventManager.FireEventToClient(pInfo, pClient); | ||
|
||
return 1; | ||
} | ||
|
||
static cell_t sm_CancelCreatedEvent(IPluginContext *pContext, const cell_t *params) | ||
{ | ||
Handle_t hndl = static_cast<Handle_t>(params[1]); | ||
|
@@ -421,6 +470,7 @@ REGISTER_NATIVES(gameEventNatives) | |
|
||
// Transitional syntax support. | ||
{"Event.Fire", sm_FireEvent}, | ||
{"Event.FireToClient", sm_FireEventToClient}, | ||
{"Event.Cancel", sm_CancelCreatedEvent}, | ||
{"Event.GetName", sm_GetEventName}, | ||
{"Event.GetBool", sm_GetEventBool}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So is this blank line needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...