diff --git a/AMBuilder b/AMBuilder index 1f3d327..1a45f1d 100644 --- a/AMBuilder +++ b/AMBuilder @@ -8,6 +8,7 @@ sourceFiles = [ 'extension.cpp', 'natives.cpp', 'forwards.cpp', + 'hltvserverwrapper.cpp', 'hltvdirectorwrapper.cpp', 'hltvclientwrapper.cpp' ] diff --git a/natives.cpp b/natives.cpp index c322f1e..01d3c0c 100644 --- a/natives.cpp +++ b/natives.cpp @@ -623,6 +623,29 @@ static cell_t Native_IsClientConnected(IPluginContext *pContext, const cell_t *p return pClient->IsConnected(); } +// native bool:SourceTV_IsClientProxy(client); +static cell_t Native_IsClientProxy(IPluginContext *pContext, const cell_t *params) +{ + if (hltvserver == nullptr) + return 0; + + cell_t client = params[1]; + if (client < 1 || client > hltvserver->GetBaseServer()->GetClientCount()) + { + pContext->ReportError("Invalid spectator client index %d.", client); + return 0; + } + + HLTVClientWrapper *pClient = hltvserver->GetClient(client); + if (!pClient->IsConnected()) + { + pContext->ReportError("Client %d is not connected.", client); + return 0; + } + + return pClient->BaseClient()->IsHLTV(); +} + // native SourceTV_GetSpectatorName(client, String:name[], maxlen); static cell_t Native_GetSpectatorName(IPluginContext *pContext, const cell_t *params) { @@ -756,6 +779,7 @@ const sp_nativeinfo_t sourcetv_natives[] = { "SourceTV_GetSpectatorName", Native_GetSpectatorName }, { "SourceTV_GetSpectatorIP", Native_GetSpectatorIP }, { "SourceTV_GetSpectatorPassword", Native_GetSpectatorPassword }, + { "SourceTV_IsClientProxy", Native_IsClientProxy }, { "SourceTV_KickClient", Native_KickClient }, { NULL, NULL }, }; diff --git a/sourcetv_test.sp b/sourcetv_test.sp index d56a3da..48ed618 100644 --- a/sourcetv_test.sp +++ b/sourcetv_test.sp @@ -189,7 +189,7 @@ public Action:Cmd_Spectators(client, args) SourceTV_GetSpectatorName(i, sName, sizeof(sName)); SourceTV_GetSpectatorIP(i, sIP, sizeof(sIP)); - ReplyToCommand(client, "Client %d: %s - %s", i, sName, sIP); + ReplyToCommand(client, "Client %d%s: %s - %s", i, (SourceTV_IsClientProxy(i)?" (RELAY)":""), sName, sIP); } return Plugin_Handled; } diff --git a/sourcetvmanager.inc b/sourcetvmanager.inc index c12c6a4..5d8e2a1 100644 --- a/sourcetvmanager.inc +++ b/sourcetvmanager.inc @@ -332,6 +332,15 @@ native SourceTV_GetClientCount(); */ native bool:SourceTV_IsClientConnected(client); +/** + * Returns if the spectator is a relay proxy. + * + * @param client The spectator client index. + * @return True if client is a proxy, false otherwise. + * @error Invalid client index. + */ +native bool:SourceTV_IsClientProxy(client); + /** * Get the name of a SourceTV spectator client. * @@ -479,6 +488,7 @@ public __ext_stvmngr_SetNTVOptional() MarkNativeAsOptional("SourceTV_GetSpectatorName"); MarkNativeAsOptional("SourceTV_GetSpectatorIP"); MarkNativeAsOptional("SourceTV_GetSpectatorPassword"); + MarkNativeAsOptional("SourceTV_IsClientProxy"); MarkNativeAsOptional("SourceTV_KickClient"); } #endif