Add natives to get SourceTV ip and port
This commit is contained in:
parent
5399c79d97
commit
fb03d5f2d5
@ -47,6 +47,7 @@
|
||||
#include "ihltvdemorecorder.h"
|
||||
#include "igameevents.h"
|
||||
#include "inetmessage.h"
|
||||
#include "netadr.h"
|
||||
#include "hltvdirectorwrapper.h"
|
||||
#include "hltvclientwrapper.h"
|
||||
|
||||
|
@ -33,7 +33,6 @@
|
||||
#define _INCLUDE_SOURCEMOD_EXTENSION_FORWARDS_H_
|
||||
|
||||
#include "extension.h"
|
||||
#include "netadr.h"
|
||||
|
||||
#if SOURCE_ENGINE == SE_CSGO
|
||||
#include "netmessages.pb.h"
|
||||
|
36
natives.cpp
36
natives.cpp
@ -110,6 +110,39 @@ static cell_t Native_GetSelectedServerInstance(IPluginContext *pContext, const c
|
||||
#endif
|
||||
}
|
||||
|
||||
// native SourceTV_IsMasterProxy();
|
||||
static cell_t Native_IsMasterProxy(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
if (hltvserver == nullptr)
|
||||
return 0;
|
||||
|
||||
return hltvserver->IsMasterProxy();
|
||||
}
|
||||
|
||||
// native bool:SourceTV_GetServerIP(String:ip[], maxlen);
|
||||
static cell_t Native_GetServerIP(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
if (hltvserver == nullptr)
|
||||
return 0;
|
||||
|
||||
const netadr_t *adr = hltvserver->GetRelayAddress();
|
||||
|
||||
char buf[16];
|
||||
V_snprintf(buf, sizeof(buf), "%d.%d.%d.%d", adr->ip[0], adr->ip[1], adr->ip[2], adr->ip[3]);
|
||||
pContext->StringToLocalUTF8(params[1], static_cast<size_t>(params[2]), buf, NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// native SourceTV_GetServerPort();
|
||||
static cell_t Native_GetServerPort(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
if (hltvserver == nullptr)
|
||||
return 0;
|
||||
|
||||
return hltvserver->GetBaseServer()->GetUDPPort();
|
||||
}
|
||||
|
||||
// native SourceTV_GetBotIndex();
|
||||
static cell_t Native_GetBotIndex(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
@ -709,6 +742,9 @@ const sp_nativeinfo_t sourcetv_natives[] =
|
||||
{ "SourceTV_GetServerInstanceCount", Native_GetServerInstanceCount },
|
||||
{ "SourceTV_SelectServerInstance", Native_SelectServerInstance },
|
||||
{ "SourceTV_GetSelectedServerInstance", Native_GetSelectedServerInstance },
|
||||
{ "SourceTV_IsMasterProxy", Native_IsMasterProxy },
|
||||
{ "SourceTV_GetServerIP", Native_GetServerIP },
|
||||
{ "SourceTV_GetServerPort", Native_GetServerPort },
|
||||
{ "SourceTV_GetBotIndex", Native_GetBotIndex },
|
||||
{ "SourceTV_GetLocalStats", Native_GetLocalStats },
|
||||
{ "SourceTV_GetGlobalStats", Native_GetGlobalStats },
|
||||
|
@ -8,6 +8,9 @@ public OnPluginStart()
|
||||
RegConsoleCmd("sm_servercount", Cmd_GetServerCount);
|
||||
RegConsoleCmd("sm_selectserver", Cmd_SelectServer);
|
||||
RegConsoleCmd("sm_selectedserver", Cmd_GetSelectedServer);
|
||||
RegConsoleCmd("sm_ismaster", Cmd_IsMasterProxy);
|
||||
RegConsoleCmd("sm_serverip", Cmd_GetServerIP);
|
||||
RegConsoleCmd("sm_serverport", Cmd_GetServerPort);
|
||||
RegConsoleCmd("sm_botindex", Cmd_GetBotIndex);
|
||||
RegConsoleCmd("sm_broadcasttick", Cmd_GetBroadcastTick);
|
||||
RegConsoleCmd("sm_localstats", Cmd_Localstats);
|
||||
@ -103,6 +106,26 @@ public Action:Cmd_GetSelectedServer(client, args)
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Cmd_IsMasterProxy(client, args)
|
||||
{
|
||||
ReplyToCommand(client, "SourceTV is master proxy: %d", SourceTV_IsMasterProxy());
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Cmd_GetServerIP(client, args)
|
||||
{
|
||||
new String:sIP[32];
|
||||
new bool:bSuccess = SourceTV_GetServerIP(sIP, sizeof(sIP));
|
||||
ReplyToCommand(client, "SourceTV server ip (ret %d): %s", bSuccess, sIP);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Cmd_GetServerPort(client, args)
|
||||
{
|
||||
ReplyToCommand(client, "SourceTV server port: %d", SourceTV_GetServerPort());
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action:Cmd_GetBotIndex(client, args)
|
||||
{
|
||||
ReplyToCommand(client, "SourceTV bot index: %d", SourceTV_GetBotIndex());
|
||||
|
@ -35,6 +35,30 @@ native SourceTV_SelectServerInstance(instance);
|
||||
*/
|
||||
native SourceTV_GetSelectedServerInstance();
|
||||
|
||||
/**
|
||||
* Returns whether this SourceTV instance is a master proxy or relay.
|
||||
*
|
||||
* @return True if SourceTV instance is master proxy, false otherwise.
|
||||
*/
|
||||
native SourceTV_IsMasterProxy();
|
||||
|
||||
/**
|
||||
* Get the local ip of the SourceTV server.
|
||||
*
|
||||
* @param ip Buffer to save IP in.
|
||||
* @param maxlen Maximum length of the buffer.
|
||||
* @return True if IP written, false otherwise.
|
||||
*/
|
||||
native bool:SourceTV_GetServerIP(String:ip[], maxlen);
|
||||
|
||||
/**
|
||||
* Get the UDP port of the SourceTV server.
|
||||
* This is the port clients use to connect.
|
||||
*
|
||||
* @return SourceTV server UDP port.
|
||||
*/
|
||||
native SourceTV_GetServerPort();
|
||||
|
||||
/**
|
||||
* Get the client index of the SourceTV bot.
|
||||
*
|
||||
@ -403,6 +427,7 @@ public __ext_stvmngr_SetNTVOptional()
|
||||
MarkNativeAsOptional("SourceTV_GetServerInstanceCount");
|
||||
MarkNativeAsOptional("SourceTV_SelectServerInstance");
|
||||
MarkNativeAsOptional("SourceTV_GetSelectedServerInstance");
|
||||
MarkNativeAsOptional("SourceTV_IsMasterProxy");
|
||||
MarkNativeAsOptional("SourceTV_GetBotIndex");
|
||||
MarkNativeAsOptional("SourceTV_GetLocalStats");
|
||||
MarkNativeAsOptional("SourceTV_GetGlobalStats");
|
||||
|
Loading…
Reference in New Issue
Block a user