mirror of
https://github.com/srcdslab/sm-ext-voice.git
synced 2025-12-07 10:38:22 +00:00
Add sm_voice_logging, Fix sourcetv bot index
This commit is contained in:
parent
dd63f8a035
commit
c24d24a75a
@ -43,8 +43,12 @@
|
|||||||
#include <iserver.h>
|
#include <iserver.h>
|
||||||
#include <ISDKTools.h>
|
#include <ISDKTools.h>
|
||||||
|
|
||||||
|
#include <ihltvdirector.h>
|
||||||
|
#include <ihltv.h>
|
||||||
|
|
||||||
#include "CDetour/detours.h"
|
#include "CDetour/detours.h"
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
|
#include "extensionHelper.h"
|
||||||
|
|
||||||
// voice packets are sent over unreliable netchannel
|
// voice packets are sent over unreliable netchannel
|
||||||
//#define NET_MAX_DATAGRAM_PAYLOAD 4000 // = maximum unreliable payload size
|
//#define NET_MAX_DATAGRAM_PAYLOAD 4000 // = maximum unreliable payload size
|
||||||
@ -54,8 +58,9 @@
|
|||||||
// sensible limit of 8 packets per frame = 552 bytes -> 185.76ms of voice data per frame
|
// sensible limit of 8 packets per frame = 552 bytes -> 185.76ms of voice data per frame
|
||||||
#define NET_MAX_VOICE_BYTES_FRAME (8 * (5 + 64))
|
#define NET_MAX_VOICE_BYTES_FRAME (8 * (5 + 64))
|
||||||
|
|
||||||
ConVar g_SmVoiceAddr("sm_voice_addr", "127.0.0.1", FCVAR_PROTECTED, "Voice server listen ip address.");
|
ConVar *g_SmVoiceAddr = CreateConVar("sm_voice_addr", "127.0.0.1", FCVAR_PROTECTED, "Voice server listen ip address.");
|
||||||
ConVar g_SmVoicePort("sm_voice_port", "27020", FCVAR_PROTECTED, "Voice server listen port.", true, 1025.0, true, 65535.0);
|
ConVar *g_SmVoicePort = CreateConVar("sm_voice_port", "27020", FCVAR_PROTECTED, "Voice server listen port.", true, 1025.0, true, 65535.0);
|
||||||
|
ConVar *g_SvLogging = CreateConVar("sm_voice_logging", "0", FCVAR_NOTIFY, "Log client connections");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file extension.cpp
|
* @file extension.cpp
|
||||||
@ -71,12 +76,15 @@ CGlobalVars *gpGlobals = NULL;
|
|||||||
ISDKTools *g_pSDKTools = NULL;
|
ISDKTools *g_pSDKTools = NULL;
|
||||||
IServer *iserver = NULL;
|
IServer *iserver = NULL;
|
||||||
|
|
||||||
double g_fLastVoiceData[SM_MAXPLAYERS + 1];
|
IHLTVDirector *hltvdirector = NULL;
|
||||||
|
IHLTVServer *hltv = NULL;
|
||||||
|
|
||||||
int g_aFrameVoiceBytes[SM_MAXPLAYERS + 1];
|
int g_aFrameVoiceBytes[SM_MAXPLAYERS + 1];
|
||||||
|
double g_fLastVoiceData[SM_MAXPLAYERS + 1];
|
||||||
|
|
||||||
DETOUR_DECL_STATIC4(SV_BroadcastVoiceData, void, IClient *, pClient, int, nBytes, char *, data, int64, xuid)
|
DETOUR_DECL_STATIC4(SV_BroadcastVoiceData, void, IClient *, pClient, int, nBytes, char *, data, int64, xuid)
|
||||||
{
|
{
|
||||||
if(g_Interface.OnBroadcastVoiceData(pClient, nBytes, data))
|
if (g_Interface.OnBroadcastVoiceData(pClient, nBytes, data))
|
||||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData)(pClient, nBytes, data, xuid);
|
DETOUR_STATIC_CALL(SV_BroadcastVoiceData)(pClient, nBytes, data, xuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +102,7 @@ DETOUR_DECL_STATIC2(SV_BroadcastVoiceData_LTCG, void, char *, data, int64, xuid)
|
|||||||
__asm mov ecx, pClient;
|
__asm mov ecx, pClient;
|
||||||
__asm mov edx, nBytes;
|
__asm mov edx, nBytes;
|
||||||
|
|
||||||
if(ret)
|
if (ret)
|
||||||
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)(data, xuid);
|
DETOUR_STATIC_CALL(SV_BroadcastVoiceData_LTCG)(data, xuid);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -268,12 +276,15 @@ bool CVoice::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
|||||||
celt_encoder_ctl(m_pCodec, CELT_SET_BITRATE(m_EncoderSettings.TargetBitRate_Kbps * 1000));
|
celt_encoder_ctl(m_pCodec, CELT_SET_BITRATE(m_EncoderSettings.TargetBitRate_Kbps * 1000));
|
||||||
celt_encoder_ctl(m_pCodec, CELT_SET_COMPLEXITY(m_EncoderSettings.Complexity));
|
celt_encoder_ctl(m_pCodec, CELT_SET_COMPLEXITY(m_EncoderSettings.Complexity));
|
||||||
|
|
||||||
|
AutoExecConfig(g_pCVar, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVoice::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
bool CVoice::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
||||||
{
|
{
|
||||||
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
|
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
|
||||||
|
GET_V_IFACE_CURRENT(GetServerFactory, hltvdirector, IHLTVDirector, INTERFACEVERSION_HLTVDIRECTOR);
|
||||||
gpGlobals = ismm->GetCGlobals();
|
gpGlobals = ismm->GetCGlobals();
|
||||||
ConVar_Register(0, this);
|
ConVar_Register(0, this);
|
||||||
|
|
||||||
@ -356,10 +367,6 @@ void CVoice::SDK_OnAllLoaded()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This doesn't seem to work right away ...
|
|
||||||
engine->ServerCommand("exec sourcemod/extension.Voice.cfg\n");
|
|
||||||
engine->ServerExecute();
|
|
||||||
|
|
||||||
// ... delay starting listen server to next frame
|
// ... delay starting listen server to next frame
|
||||||
smutils->AddFrameAction(ListenSocketAction, this);
|
smutils->AddFrameAction(ListenSocketAction, this);
|
||||||
}
|
}
|
||||||
@ -372,10 +379,10 @@ void CVoice::ListenSocket()
|
|||||||
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(g_SmVoiceAddr.GetString(), &bindAddr.sin_addr);
|
inet_aton(g_SmVoiceAddr->GetString(), &bindAddr.sin_addr);
|
||||||
bindAddr.sin_port = htons(g_SmVoicePort.GetInt());
|
bindAddr.sin_port = htons(g_SmVoicePort->GetInt());
|
||||||
|
|
||||||
smutils->LogMessage(myself, "Binding to %s:%d!\n", g_SmVoiceAddr.GetString(), g_SmVoicePort.GetInt());
|
smutils->LogMessage(myself, "Binding to %s:%d!\n", g_SmVoiceAddr->GetString(), g_SmVoicePort->GetInt());
|
||||||
|
|
||||||
if(bind(m_ListenSocket, (sockaddr *)&bindAddr, sizeof(sockaddr_in)) < 0)
|
if(bind(m_ListenSocket, (sockaddr *)&bindAddr, sizeof(sockaddr_in)) < 0)
|
||||||
{
|
{
|
||||||
@ -498,7 +505,8 @@ void CVoice::HandleNetwork()
|
|||||||
m_aPollFds[m_PollFds].revents = 0;
|
m_aPollFds[m_PollFds].revents = 0;
|
||||||
m_PollFds++;
|
m_PollFds++;
|
||||||
|
|
||||||
//smutils->LogMessage(myself, "Client %d connected!\n", Client);
|
if (g_SvLogging->GetInt())
|
||||||
|
smutils->LogMessage(myself, "Client %d connected!\n", Client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,7 +532,8 @@ void CVoice::HandleNetwork()
|
|||||||
pClient->m_Socket = -1;
|
pClient->m_Socket = -1;
|
||||||
m_aPollFds[PollFds].fd = -1;
|
m_aPollFds[PollFds].fd = -1;
|
||||||
CompressPollFds = true;
|
CompressPollFds = true;
|
||||||
//smutils->LogMessage(myself, "Client %d disconnected!(2)\n", Client);
|
if (g_SvLogging->GetInt())
|
||||||
|
smutils->LogMessage(myself, "Client %d disconnected!(2)\n", Client);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,7 +575,8 @@ void CVoice::HandleNetwork()
|
|||||||
pClient->m_Socket = -1;
|
pClient->m_Socket = -1;
|
||||||
m_aPollFds[PollFds].fd = -1;
|
m_aPollFds[PollFds].fd = -1;
|
||||||
CompressPollFds = true;
|
CompressPollFds = true;
|
||||||
//smutils->LogMessage(myself, "Client %d disconnected!(1)\n", Client);
|
if (g_SvLogging->GetInt())
|
||||||
|
smutils->LogMessage(myself, "Client %d disconnected!(1)\n", Client);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,10 +669,20 @@ void CVoice::HandleVoiceData()
|
|||||||
// 5 = max frames per packet
|
// 5 = max frames per packet
|
||||||
FramesAvailable = min(FramesAvailable, 5);
|
FramesAvailable = min(FramesAvailable, 5);
|
||||||
|
|
||||||
// 0 = SourceTV
|
// Get SourceTV Index
|
||||||
IClient *pClient = iserver->GetClient(0);
|
if (!hltv)
|
||||||
|
hltv = hltvdirector->GetHLTVServer();
|
||||||
|
|
||||||
|
int iSourceTVIndex = 0;
|
||||||
|
if (hltv)
|
||||||
|
iSourceTVIndex = hltv->GetHLTVSlot();
|
||||||
|
|
||||||
|
IClient *pClient = iserver->GetClient(iSourceTVIndex);
|
||||||
if(!pClient)
|
if(!pClient)
|
||||||
|
{
|
||||||
|
smutils->LogError(myself, "Couldnt get client with id %d (SourceTV)\n", iSourceTVIndex);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(int Frame = 0; Frame < FramesAvailable; Frame++)
|
for(int Frame = 0; Frame < FramesAvailable; Frame++)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user