Add SourceTV_SetClientTVTitle native

Change the stream title for a single client.
Changing tv_title resets this.
This commit is contained in:
Peace-Maker 2016-11-14 03:27:38 -06:00
parent 9f5ef34087
commit aefdc47d0a
3 changed files with 91 additions and 0 deletions

View File

@ -890,6 +890,61 @@ static cell_t Native_PrintToConsole(IPluginContext *pContext, const cell_t *para
return 0;
}
// native SourceTV_SetClientTVTitle(client, const String:format[], any:...);
static cell_t Native_SetClientTVTitle(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;
}
char buffer[1024];
size_t len;
{
DetectExceptions eh(pContext);
len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2);
if (eh.HasException())
return 0;
}
IGameEvent *msg = gameevents->CreateEvent("hltv_title", true);
if (!msg)
return 0;
#if SOURCE_ENGINE == SE_CSGO
wchar_t wBuffer[1024];
V_UTF8ToUnicode(buffer, wBuffer, sizeof(wBuffer));
msg->SetWString("text", wBuffer);
#else
msg->SetString("text", buffer);
#endif
if (g_bHasClientFireGameEventOffset)
{
void *pGameClient = pClient->BaseClient();
// The IClient vtable is +4 from the CBaseClient vtable due to multiple inheritance.
pGameClient = (void *)((intptr_t)pGameClient - 4);
SH_MCALL(pGameClient, CBaseClient_FireGameEvent)(msg);
}
gameevents->FreeEvent(msg);
return 0;
}
const sp_nativeinfo_t sourcetv_natives[] =
{
{ "SourceTV_GetServerInstanceCount", Native_GetServerInstanceCount },
@ -928,5 +983,6 @@ const sp_nativeinfo_t sourcetv_natives[] =
{ "SourceTV_KickClient", Native_KickClient },
{ "SourceTV_PrintToChat", Native_PrintToChat },
{ "SourceTV_PrintToConsole", Native_PrintToConsole },
{ "SourceTV_SetClientTVTitle", Native_SetClientTVTitle },
{ NULL, NULL },
};

View File

@ -36,6 +36,7 @@ public OnPluginStart()
RegConsoleCmd("sm_speckick", Cmd_KickClient);
RegConsoleCmd("sm_specchatone", Cmd_PrintToChat);
RegConsoleCmd("sm_specconsoleone", Cmd_PrintToConsole);
RegConsoleCmd("sm_spectitle", Cmd_SetTVTitle);
}
public SourceTV_OnStartRecording(instance, const String:filename[])
@ -471,4 +472,24 @@ public Action:Cmd_PrintToConsole(client, args)
SourceTV_PrintToConsole(iTarget, "%s", sMsg);
ReplyToCommand(client, "SourceTV sending console message to spectator %d: %s", iTarget, sMsg);
return Plugin_Handled;
}
public Action:Cmd_SetTVTitle(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "Usage: sm_spectitle <index> <title>");
return Plugin_Handled;
}
new String:sIndex[16], String:sMsg[1024];
GetCmdArg(1, sIndex, sizeof(sIndex));
StripQuotes(sIndex);
GetCmdArg(2, sMsg, sizeof(sMsg));
StripQuotes(sMsg);
new iTarget = StringToInt(sIndex);
SourceTV_SetClientTVTitle(iTarget, "%s", sMsg);
ReplyToCommand(client, "SourceTV set stream title of spectator %d to %s", iTarget, sMsg);
return Plugin_Handled;
}

View File

@ -415,6 +415,19 @@ native SourceTV_PrintToChat(client, const String:format[], any:...);
*/
native SourceTV_PrintToConsole(client, const String:format[], any:...);
/**
* Change the stream title only for one spectator.
* This is like tv_title but for a single client.
* Gets overwritten when tv_title gets changed.
*
* @param client The spectator client index.
* @param format The format string.
* @param ... Variable number of format string arguments.
* @noreturn
* @error Invalid client index or not connected.
*/
native SourceTV_SetClientTVTitle(client, const String:format[], any:...);
/**
* Called when a spectator wants to connect to the SourceTV server.
* This is called before any other validation has happened.
@ -543,5 +556,6 @@ public __ext_stvmngr_SetNTVOptional()
MarkNativeAsOptional("SourceTV_KickClient");
MarkNativeAsOptional("SourceTV_PrintToChat");
MarkNativeAsOptional("SourceTV_PrintToConsole");
MarkNativeAsOptional("SourceTV_SetClientTVTitle");
}
#endif