diff --git a/code/components/gta-net-five/src/MumbleVoice.cpp b/code/components/gta-net-five/src/MumbleVoice.cpp index 0a68444929..6c83d13abc 100644 --- a/code/components/gta-net-five/src/MumbleVoice.cpp +++ b/code/components/gta-net-five/src/MumbleVoice.cpp @@ -1151,6 +1151,20 @@ static HookFunction hookFunction([]() } }); + fx::ScriptEngine::RegisterNativeHandler("MUMBLE_DOES_CHANNEL_EXIST", [](fx::ScriptContext& context) { + auto channel = context.GetArgument(0); + + if (g_mumble.connected) + { + auto channelName = fmt::sprintf("Game Channel %d", channel); + context.SetResult(g_mumbleClient->DoesChannelExist(channelName)); + } + else + { + context.SetResult(false); + } + }); + fx::ScriptEngine::RegisterNativeHandler("MUMBLE_ADD_VOICE_TARGET_PLAYER", [](fx::ScriptContext& context) { auto id = context.GetArgument(0); diff --git a/code/components/voip-mumble/include/MumbleClient.h b/code/components/voip-mumble/include/MumbleClient.h index 9fada0214a..f0bbda637c 100644 --- a/code/components/voip-mumble/include/MumbleClient.h +++ b/code/components/voip-mumble/include/MumbleClient.h @@ -121,6 +121,8 @@ class IMumbleClient : public fwRefCountable virtual void RemoveListenChannel(const std::string& channelName) = 0; + virtual bool DoesChannelExist(const std::string& channelName) = 0; + virtual std::shared_ptr GetAudioContext(const std::string& name) = 0; // settings diff --git a/code/components/voip-mumble/include/MumbleClientImpl.h b/code/components/voip-mumble/include/MumbleClientImpl.h index de17f8acb9..8523501caa 100644 --- a/code/components/voip-mumble/include/MumbleClientImpl.h +++ b/code/components/voip-mumble/include/MumbleClientImpl.h @@ -104,6 +104,8 @@ class MumbleClient : public IMumbleClient, public Botan::TLS::Callbacks virtual void RemoveListenChannel(const std::string& channelName) override; + virtual bool DoesChannelExist(const std::string& channelName) override; + virtual std::shared_ptr GetAudioContext(const std::string& name) override; virtual void SetClientVolumeOverride(const std::wstring& clientName, float volume) override; diff --git a/code/components/voip-mumble/src/MumbleClient.cpp b/code/components/voip-mumble/src/MumbleClient.cpp index 91ac9880f0..965ca1836e 100644 --- a/code/components/voip-mumble/src/MumbleClient.cpp +++ b/code/components/voip-mumble/src/MumbleClient.cpp @@ -349,9 +349,10 @@ void MumbleClient::Initialize() if (!t.channel.empty()) { + std::wstring wname = ToWide(t.channel); for (auto& channelPair : m_state.GetChannels()) { - if (channelPair.second.GetName() == ToWide(t.channel)) + if (channelPair.second.GetName() == wname) { vt->set_channel_id(channelPair.first); } @@ -690,6 +691,21 @@ std::string MumbleClient::GetVoiceChannelFromServerId(uint32_t serverId) return retString; } +bool MumbleClient::DoesChannelExist(const std::string& channelName) +{ + std::wstring wname = ToWide(channelName); + + for (const auto& channel : m_state.GetChannels()) + { + if (channel.second.GetName() == wname) + { + return true; + } + } + + return false; +} + void MumbleClient::GetTalkers(std::vector* referenceIds) { referenceIds->clear(); diff --git a/code/components/voip-mumble/src/MumbleClientState_Channel.cpp b/code/components/voip-mumble/src/MumbleClientState_Channel.cpp index a2a986d2a3..7bd4010baa 100644 --- a/code/components/voip-mumble/src/MumbleClientState_Channel.cpp +++ b/code/components/voip-mumble/src/MumbleClientState_Channel.cpp @@ -62,8 +62,7 @@ void MumbleClientState::ProcessChannelState(MumbleProto::ChannelState& channelSt if (channelIt == m_channels.end()) { auto channel = MumbleChannel(m_client, channelState); - - m_channels.insert(std::make_pair(id, channel)); + m_channels.emplace(id, channel); auto name = channel.GetName(); diff --git a/ext/native-decls/MumbleDoesChannelExist.md b/ext/native-decls/MumbleDoesChannelExist.md new file mode 100644 index 0000000000..6ee15a941d --- /dev/null +++ b/ext/native-decls/MumbleDoesChannelExist.md @@ -0,0 +1,14 @@ +--- +ns: CFX +apiset: client +--- +## MUMBLE_DOES_CHANNEL_EXIST + +```c +void MUMBLE_DOES_CHANNEL_EXIST(int channel); +``` + +Check whether specified channel exists on the Mumble server. + +## Parameters +* **channel**: A game voice channel ID.