Add cvars sm_voice_addr and sm_voice_port

This commit is contained in:
BotoX 2017-08-04 09:20:54 +02:00
parent fed7ab800d
commit 123e8c0889
2 changed files with 30 additions and 8 deletions

View File

@ -45,9 +45,8 @@
#include "extension.h" #include "extension.h"
#define LISTEN_ADDR "127.0.0.1" ConVar g_SmVoiceAddr("sm_voice_addr", "127.0.0.1", FCVAR_PROTECTED, "Voice server listen ip address.");
//#define LISTEN_ADDR "10.0.0.101" ConVar g_SmVoicePort("sm_voice_port", "27020", FCVAR_PROTECTED, "Voice server listen port.", true, 1025.0, true, 65535.0);
#define LISTEN_PORT 27020
/** /**
* @file extension.cpp * @file extension.cpp
@ -266,13 +265,17 @@ bool CVoice::SDK_OnLoad(char *error, size_t maxlength, bool late)
return false; return false;
} }
engine->ServerCommand("exec sourcemod/extension.Voice.cfg\n");
engine->ServerExecute();
sockaddr_in bindAddr; sockaddr_in bindAddr;
memset(&bindAddr, 0, sizeof(bindAddr)); memset(&bindAddr, 0, sizeof(bindAddr));
bindAddr.sin_family = AF_INET; bindAddr.sin_family = AF_INET;
inet_aton(LISTEN_ADDR, &bindAddr.sin_addr); inet_aton(g_SmVoiceAddr.GetString(), &bindAddr.sin_addr);
bindAddr.sin_port = htons(LISTEN_PORT); bindAddr.sin_port = htons(g_SmVoicePort.GetInt());
smutils->LogMessage(myself, "Binding to %s:%d!\n", g_SmVoiceAddr.GetString(), g_SmVoicePort.GetInt());
// Listen on LISTEN_ADDR:LISTEN_PORT
if(bind(m_ListenSocket, (sockaddr *)&bindAddr, sizeof(sockaddr_in)) < 0) if(bind(m_ListenSocket, (sockaddr *)&bindAddr, sizeof(sockaddr_in)) < 0)
{ {
g_SMAPI->Format(error, maxlength, "Failed binding to socket (%d '%s').", errno, strerror(errno)); g_SMAPI->Format(error, maxlength, "Failed binding to socket (%d '%s').", errno, strerror(errno));
@ -336,6 +339,20 @@ bool CVoice::SDK_OnLoad(char *error, size_t maxlength, bool late)
return true; return true;
} }
bool CVoice::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
ConVar_Register(0, this);
return true;
}
bool CVoice::RegisterConCommandBase(ConCommandBase *pVar)
{
/* Always call META_REGCVAR instead of going through the engine. */
return META_REGCVAR(pVar);
}
void CVoice::SDK_OnAllLoaded() void CVoice::SDK_OnAllLoaded()
{ {
SM_GET_LATE_IFACE(SDKTOOLS, g_pSDKTools); SM_GET_LATE_IFACE(SDKTOOLS, g_pSDKTools);

View File

@ -56,7 +56,9 @@ typedef void (*t_SV_BroadcastVoiceData)(IClient *, int, unsigned char *, int64);
* @brief Sample implementation of the SDK Extension. * @brief Sample implementation of the SDK Extension.
* Note: Uncomment one of the pre-defined virtual functions in order to use it. * Note: Uncomment one of the pre-defined virtual functions in order to use it.
*/ */
class CVoice : public SDKExtension class CVoice :
public SDKExtension,
public IConCommandBaseAccessor
{ {
public: public:
/** /**
@ -103,7 +105,7 @@ public:
* @param late Whether or not Metamod considers this a late load. * @param late Whether or not Metamod considers this a late load.
* @return True to succeed, false to fail. * @return True to succeed, false to fail.
*/ */
//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
/** /**
* @brief Called when Metamod is detaching, after the extension version is called. * @brief Called when Metamod is detaching, after the extension version is called.
@ -127,6 +129,9 @@ public:
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); //virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
#endif #endif
public: // IConCommandBaseAccessor
virtual bool RegisterConCommandBase(ConCommandBase *pVar);
public: public:
CVoice(); CVoice();
void OnGameFrame(bool simulating); void OnGameFrame(bool simulating);