1 parent
7b8dcd9f31
commit
df7fefa85c
7 files changed
+3
-134
No files matched your search
@@ -490,41 +490,5 @@ Client::removeFromServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<VoiceStreamId, Error> Client::createVoiceStream()
|
||||
{
|
||||
return VoiceStreamId{impl_->client.createVoiceStream()};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error>
|
||||
Client::destroyVoiceStream(VoiceStreamId stream)
|
||||
{
|
||||
if (!stream) return Void::Result::fail(
|
||||
Error{Error::Code::InvalidArgument, "invalid voice stream"});
|
||||
if (!impl_->client.destroyVoiceStream(stream.value)) {
|
||||
return Void::Result::fail(
|
||||
Error{Error::Code::InvalidArgument, "voice stream not found"});
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error> Client::sendWhisper(
|
||||
VoiceStreamId stream, std::span<const std::uint8_t> frame,
|
||||
const WhisperTargets& targets)
|
||||
{
|
||||
if (state() != ConnectionState::Connected) return Void::Result::fail(
|
||||
Error{Error::Code::NotConnected, "not connected"});
|
||||
std::vector<std::uint64_t> channels;
|
||||
std::vector<std::uint16_t> clients;
|
||||
channels.reserve(targets.channels.size());
|
||||
clients.reserve(targets.clients.size());
|
||||
for (auto value : targets.channels) channels.push_back(value.value);
|
||||
for (auto value : targets.clients) clients.push_back(value.value);
|
||||
if (!impl_->client.sendWhisper(stream.value, frame, channels, clients)) {
|
||||
return Void::Result::fail(
|
||||
Error{Error::Code::InvalidArgument, "voice stream not found"});
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Client::stopVoice() noexcept { impl_->client.sendVoiceStop(); }
|
||||
}
|
||||
+2
-53
@@ -270,8 +270,7 @@ namespace Void::TeamSpeak::Protocol
|
||||
}
|
||||
|
||||
void TsClient::sendOutgoing(std::span<const uint8_t> dataIn, PacketType type,
|
||||
uint8_t extraFlags,
|
||||
std::optional<uint16_t> voiceId)
|
||||
uint8_t extraFlags)
|
||||
{
|
||||
auto ctr = getCounter(type);
|
||||
incCounter(type);
|
||||
@@ -282,7 +281,7 @@ namespace Void::TeamSpeak::Protocol
|
||||
case PacketType::Voice:
|
||||
case PacketType::VoiceWhisper:
|
||||
if (data.size() >= 2) {
|
||||
putU16BE(data, 0, voiceId.value_or(ctr.id));
|
||||
putU16BE(data, 0, ctr.id);
|
||||
}
|
||||
break;
|
||||
case PacketType::Command:
|
||||
@@ -647,56 +646,6 @@ namespace Void::TeamSpeak::Protocol
|
||||
sendOutgoing(buf, PacketType::VoiceWhisper);
|
||||
}
|
||||
|
||||
uint32_t TsClient::createVoiceStream()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mu_);
|
||||
while (nextVoiceStreamId_ == 0 ||
|
||||
voiceStreamCounters_.contains(nextVoiceStreamId_)) {
|
||||
++nextVoiceStreamId_;
|
||||
}
|
||||
const auto id = nextVoiceStreamId_++;
|
||||
voiceStreamCounters_.emplace(id, 0);
|
||||
return id;
|
||||
}
|
||||
|
||||
bool TsClient::destroyVoiceStream(uint32_t streamId)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mu_);
|
||||
return voiceStreamCounters_.erase(streamId) != 0;
|
||||
}
|
||||
|
||||
bool TsClient::sendWhisper(uint32_t streamId, std::span<const uint8_t> opus,
|
||||
const std::vector<uint64_t>& channelIds,
|
||||
const std::vector<uint16_t>& clientIds)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mu_);
|
||||
if (state_.load() != ClientState::Connected) return false;
|
||||
auto stream = voiceStreamCounters_.find(streamId);
|
||||
if (stream == voiceStreamCounters_.end()) return false;
|
||||
if (channelIds.empty() && clientIds.empty()) return true;
|
||||
|
||||
std::vector<uint8_t> buf;
|
||||
buf.resize(5 + channelIds.size() * 8 + clientIds.size() * 2 +
|
||||
opus.size());
|
||||
size_t p = 2;
|
||||
buf[p++] = 5;
|
||||
buf[p++] = static_cast<uint8_t>(channelIds.size());
|
||||
buf[p++] = static_cast<uint8_t>(clientIds.size());
|
||||
for (uint64_t cid : channelIds) {
|
||||
for (int shift = 56; shift >= 0; shift -= 8) {
|
||||
buf[p++] = static_cast<uint8_t>((cid >> shift) & 0xff);
|
||||
}
|
||||
}
|
||||
for (uint16_t clientId : clientIds) {
|
||||
buf[p++] = static_cast<uint8_t>((clientId >> 8) & 0xff);
|
||||
buf[p++] = static_cast<uint8_t>(clientId & 0xff);
|
||||
}
|
||||
std::memcpy(buf.data() + p, opus.data(), opus.size());
|
||||
const auto voiceId = stream->second++;
|
||||
sendOutgoing(buf, PacketType::VoiceWhisper, 0, voiceId);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- Incoming ----------------------------------------------------------
|
||||
|
||||
std::vector<uint8_t> TsClient::decryptPacket(std::span<const uint8_t> raw,
|
||||
|
||||
Reference in new issue
Block a user