Skip to content

Commit

Permalink
feature(voip/mumble): Add MUMBLE_DOES_CHANNEL_EXIST native
Browse files Browse the repository at this point in the history
  • Loading branch information
niekschoemaker committed Jul 29, 2024
1 parent e8e1554 commit 6db3bcd
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
14 changes: 14 additions & 0 deletions code/components/gta-net-five/src/MumbleVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,20 @@ static HookFunction hookFunction([]()
}
});

fx::ScriptEngine::RegisterNativeHandler("MUMBLE_DOES_CHANNEL_EXIST", [](fx::ScriptContext& context) {
auto channel = context.GetArgument<int>(0);

if (g_mumble.connected)
{
auto channelName = fmt::sprintf("Game Channel %d", channel);
context.SetResult<bool>(g_mumbleClient->DoesChannelExist(channelName));
}
else
{
context.SetResult<bool>(false);
}
});

fx::ScriptEngine::RegisterNativeHandler("MUMBLE_ADD_VOICE_TARGET_PLAYER", [](fx::ScriptContext& context)
{
auto id = context.GetArgument<int>(0);
Expand Down
2 changes: 2 additions & 0 deletions code/components/voip-mumble/include/MumbleClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<lab::AudioContext> GetAudioContext(const std::string& name) = 0;

// settings
Expand Down
2 changes: 2 additions & 0 deletions code/components/voip-mumble/include/MumbleClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<lab::AudioContext> GetAudioContext(const std::string& name) override;

virtual void SetClientVolumeOverride(const std::wstring& clientName, float volume) override;
Expand Down
18 changes: 17 additions & 1 deletion code/components/voip-mumble/src/MumbleClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<std::string>* referenceIds)
{
referenceIds->clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
14 changes: 14 additions & 0 deletions ext/native-decls/MumbleDoesChannelExist.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 6db3bcd

Please sign in to comment.