Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(voip/mumble): Add MUMBLE_DOES_CHANNEL_EXIST native #2682

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions ext/native-decls/MumbleDoesChannelExist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
ns: CFX
apiset: client
---
## MUMBLE_DOES_CHANNEL_EXIST

```c
BOOL MUMBLE_DOES_CHANNEL_EXIST(int channel);
```

Check whether specified channel exists on the Mumble server.

## Parameters
* **channel**: A game voice channel ID.
niekschoemaker marked this conversation as resolved.
Show resolved Hide resolved

## Return value
True if the specific channel exists. False otherwise.
Loading