[Voice]: Check who sent packet (#973)
This commit is contained in:
parent
b5ed99a2f9
commit
4dd88de3a0
@ -5,6 +5,7 @@ namespace Components
|
||||
Utils::Signal<Network::CallbackRaw> Network::StartupSignal;
|
||||
// Packet interception
|
||||
std::unordered_map<std::string, Network::networkCallback> Network::CL_Callbacks;
|
||||
std::unordered_map<std::string, Network::networkRawCallback> Network::CL_RawCallbacks;
|
||||
|
||||
Network::Address::Address()
|
||||
{
|
||||
@ -274,17 +275,34 @@ namespace Components
|
||||
CL_Callbacks[Utils::String::ToLower(command)] = callback;
|
||||
}
|
||||
|
||||
bool Network::CL_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message)
|
||||
void Network::OnClientPacketRaw(const std::string& command, const networkRawCallback& callback)
|
||||
{
|
||||
CL_RawCallbacks[Utils::String::ToLower(command)] = callback;
|
||||
}
|
||||
|
||||
bool Network::CL_HandleCommand(Game::netadr_t* address, const char* command, Game::msg_t* message)
|
||||
{
|
||||
const auto command_ = Utils::String::ToLower(command);
|
||||
const auto handler = CL_Callbacks.find(command_);
|
||||
|
||||
const auto offset = command_.size() + 5;
|
||||
if (static_cast<std::size_t>(message->cursize) < offset || handler == CL_Callbacks.end())
|
||||
if (static_cast<std::size_t>(message->cursize) < offset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (const auto rawHandler = CL_RawCallbacks.find(command_); rawHandler != CL_RawCallbacks.end())
|
||||
{
|
||||
rawHandler->second(address, message);
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto handler = CL_Callbacks.find(command_);
|
||||
if (handler == CL_Callbacks.end())
|
||||
{
|
||||
// Normal handler was not found, return
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string data(reinterpret_cast<char*>(message->data) + offset, message->cursize - offset);
|
||||
|
||||
auto target = Address{ address };
|
||||
|
@ -49,6 +49,7 @@ namespace Components
|
||||
typedef void(CallbackRaw)();
|
||||
|
||||
using networkCallback = std::function<void(Address&, const std::string&)>;
|
||||
using networkRawCallback = std::function<void(Game::netadr_t*, Game::msg_t* msg)>;
|
||||
|
||||
Network();
|
||||
|
||||
@ -73,17 +74,19 @@ namespace Components
|
||||
static void BroadcastAll(const std::string& data);
|
||||
|
||||
static void OnClientPacket(const std::string& command, const networkCallback& callback);
|
||||
static void OnClientPacketRaw(const std::string& command, const networkRawCallback& callback);
|
||||
|
||||
private:
|
||||
static Utils::Signal<CallbackRaw> StartupSignal;
|
||||
static std::unordered_map<std::string, networkCallback> CL_Callbacks;
|
||||
static std::unordered_map<std::string, networkRawCallback> CL_RawCallbacks;
|
||||
|
||||
static void NetworkStart();
|
||||
static void NetworkStartStub();
|
||||
|
||||
static void PacketErrorCheck();
|
||||
|
||||
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message);
|
||||
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, Game::msg_t* message);
|
||||
|
||||
static void CL_HandleCommandStub();
|
||||
};
|
||||
|
@ -241,7 +241,7 @@ namespace Components
|
||||
void Voice::CL_WriteVoicePacket_Hk(const int localClientNum)
|
||||
{
|
||||
const auto connstate = Game::CL_GetLocalClientConnectionState(localClientNum);
|
||||
const auto clc = Game::CL_GetLocalClientConnection(localClientNum);
|
||||
const auto* clc = Game::CL_GetLocalClientConnection(localClientNum);
|
||||
const auto* vc = Game::CL_GetLocalClientVoiceCommunication(localClientNum);
|
||||
if (clc->demoplaying || (connstate < Game::CA_LOADING))
|
||||
{
|
||||
@ -315,8 +315,14 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
void Voice::CL_VoicePacket_Hk(const int localClientNum, Game::msg_t* msg)
|
||||
void Voice::CL_VoicePacket(Game::netadr_t* address, Game::msg_t* msg)
|
||||
{
|
||||
auto* clc = Game::CL_GetLocalClientConnection(0);
|
||||
if (!Game::NET_CompareBaseAdr(clc->serverAddress, *address))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const auto numPackets = Game::MSG_ReadByte(msg);
|
||||
if (numPackets < 0 || numPackets > MAX_SERVER_QUEUED_VOICE_PACKETS)
|
||||
{
|
||||
@ -342,7 +348,7 @@ namespace Components
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CL_IsPlayerMuted_Hk(nullptr, localClientNum, voicePacket.talker))
|
||||
if (!CL_IsPlayerMuted_Hk(nullptr, 0, voicePacket.talker))
|
||||
{
|
||||
if ((*Game::cl_voice)->current.enabled)
|
||||
{
|
||||
@ -395,7 +401,10 @@ namespace Components
|
||||
// Write voice packets to the server instead of other clients
|
||||
Utils::Hook(0x487935, CL_WriteVoicePacket_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x5AD945, CL_WriteVoicePacket_Hk, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x5A9E06, CL_VoicePacket_Hk, HOOK_CALL).install()->quick();
|
||||
|
||||
// Disable 'v' OOB handler and use our own
|
||||
Utils::Hook::Set<std::uint8_t>(0x5A9E02, 0xEB);
|
||||
Network::OnClientPacketRaw("v", CL_VoicePacket);
|
||||
|
||||
Utils::Hook(0x4AE740, CL_IsPlayerTalking_Hk, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x4B6250, CL_IsPlayerMuted_Hk, HOOK_JUMP).install()->quick();
|
||||
|
@ -46,7 +46,7 @@ namespace Components
|
||||
static void CL_TogglePlayerMute(int localClientNum, int muteClientIndex);
|
||||
|
||||
static void CL_WriteVoicePacket_Hk(int localClientNum);
|
||||
static void CL_VoicePacket_Hk(int localClientNum, Game::msg_t* msg);
|
||||
static void CL_VoicePacket(Game::netadr_t* address, Game::msg_t* msg);
|
||||
|
||||
static void UI_Mute_player(int clientNum, int localClientNum);
|
||||
static void UI_Mute_Player_Stub();
|
||||
|
Loading…
Reference in New Issue
Block a user