From df7fefa85c7287bf075f1648f124619783f44aa9 Mon Sep 17 00:00:00 2001 From: faumaray Date: Sun, 12 Jul 2026 17:55:24 +0300 Subject: [PATCH] Update Signed-off-by: faumaray --- README.md | 6 --- include/Void/TeamSpeak/Client.hpp | 8 --- include/Void/TeamSpeak/Protocol/TsClient.hpp | 12 +---- include/Void/TeamSpeak/Types.hpp | 1 - src/Client.cpp | 36 ------------- src/TsClient.cpp | 55 +------------------- tests/test_modern_api.cpp | 19 ------- 7 files changed, 3 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index 6556ee3..c0f49fd 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,6 @@ auto connected = client.connect({ }); ``` -Each `Client` owns one connection and encrypted packet sequence. For different -audio programs on that same visible identity, create logical `VoiceStreamId` -handles and call `sendWhisper(stream, frame, targets)`. Each handle keeps an -independent inner voice sequence while the connection retains its one global -outer packet sequence. - ## Build ```sh diff --git a/include/Void/TeamSpeak/Client.hpp b/include/Void/TeamSpeak/Client.hpp index 0ac1f93..27093f7 100644 --- a/include/Void/TeamSpeak/Client.hpp +++ b/include/Void/TeamSpeak/Client.hpp @@ -128,14 +128,6 @@ namespace Void::TeamSpeak [[nodiscard]] Void::Result::Result sendWhisper(std::span opusFrame, const WhisperTargets& targets); - [[nodiscard]] Void::Result::Result - createVoiceStream(); - [[nodiscard]] Void::Result::Result - destroyVoiceStream(VoiceStreamId stream); - [[nodiscard]] Void::Result::Result - sendWhisper(VoiceStreamId stream, - std::span opusFrame, - const WhisperTargets& targets); void stopVoice() noexcept; private: diff --git a/include/Void/TeamSpeak/Protocol/TsClient.hpp b/include/Void/TeamSpeak/Protocol/TsClient.hpp index bc656e2..c7aa308 100644 --- a/include/Void/TeamSpeak/Protocol/TsClient.hpp +++ b/include/Void/TeamSpeak/Protocol/TsClient.hpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -108,12 +107,6 @@ namespace Void::TeamSpeak::Protocol void sendWhisper(std::span opus, const std::vector& channelIds, const std::vector& clientIds); - [[nodiscard]] uint32_t createVoiceStream(); - [[nodiscard]] bool destroyVoiceStream(uint32_t streamId); - [[nodiscard]] bool sendWhisper( - uint32_t streamId, std::span opus, - const std::vector& channelIds, - const std::vector& clientIds); // End-of-voice marker (empty frame). void sendVoiceStop(); @@ -141,8 +134,7 @@ namespace Void::TeamSpeak::Protocol void loopThread(); void handleIncomingPacket(std::span raw); void sendOutgoing(std::span data, PacketType type, - uint8_t extraFlags = 0, - std::optional voiceId = std::nullopt); + uint8_t extraFlags = 0); std::vector buildRawPacket(std::span data, PacketType type, uint16_t packetId, @@ -200,8 +192,6 @@ namespace Void::TeamSpeak::Protocol std::array packetCounter_{}; std::array generationCounter_{}; - uint32_t nextVoiceStreamId_{1}; - std::map voiceStreamCounters_; bool cryptoInitComplete_ = false; std::vector ivStruct_; diff --git a/include/Void/TeamSpeak/Types.hpp b/include/Void/TeamSpeak/Types.hpp index a6b319c..bea4320 100644 --- a/include/Void/TeamSpeak/Types.hpp +++ b/include/Void/TeamSpeak/Types.hpp @@ -16,7 +16,6 @@ namespace Void::TeamSpeak }; using ClientId = Id; - using VoiceStreamId = Id; using ClientDatabaseId = Id; using ChannelId = Id; using ServerConnectionId = Id; diff --git a/src/Client.cpp b/src/Client.cpp index 58a790a..0fe9ed2 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -490,41 +490,5 @@ Client::removeFromServerGroup(ServerGroupId group, ClientDatabaseId client) return {}; } - Void::Result::Result Client::createVoiceStream() - { - return VoiceStreamId{impl_->client.createVoiceStream()}; - } - - Void::Result::Result - 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 Client::sendWhisper( - VoiceStreamId stream, std::span frame, - const WhisperTargets& targets) - { - if (state() != ConnectionState::Connected) return Void::Result::fail( - Error{Error::Code::NotConnected, "not connected"}); - std::vector channels; - std::vector 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(); } } diff --git a/src/TsClient.cpp b/src/TsClient.cpp index df53d4f..4334ccd 100644 --- a/src/TsClient.cpp +++ b/src/TsClient.cpp @@ -270,8 +270,7 @@ namespace Void::TeamSpeak::Protocol } void TsClient::sendOutgoing(std::span dataIn, PacketType type, - uint8_t extraFlags, - std::optional 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 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 lock(mu_); - return voiceStreamCounters_.erase(streamId) != 0; - } - - bool TsClient::sendWhisper(uint32_t streamId, std::span opus, - const std::vector& channelIds, - const std::vector& clientIds) - { - std::lock_guard 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 buf; - buf.resize(5 + channelIds.size() * 8 + clientIds.size() * 2 + - opus.size()); - size_t p = 2; - buf[p++] = 5; - buf[p++] = static_cast(channelIds.size()); - buf[p++] = static_cast(clientIds.size()); - for (uint64_t cid : channelIds) { - for (int shift = 56; shift >= 0; shift -= 8) { - buf[p++] = static_cast((cid >> shift) & 0xff); - } - } - for (uint16_t clientId : clientIds) { - buf[p++] = static_cast((clientId >> 8) & 0xff); - buf[p++] = static_cast(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 TsClient::decryptPacket(std::span raw, diff --git a/tests/test_modern_api.cpp b/tests/test_modern_api.cpp index db1b037..bdb4fd2 100644 --- a/tests/test_modern_api.cpp +++ b/tests/test_modern_api.cpp @@ -48,22 +48,3 @@ TEST_CASE(whisper_targets_report_empty_state) targets.clients.push_back(ClientId{7}); CHECK(!targets.empty()); } - -TEST_CASE(logical_voice_streams_have_strong_independent_handles) -{ - Client client; - auto first = client.createVoiceStream(); - auto second = client.createVoiceStream(); - CHECK(first.has_value()); - CHECK(second.has_value()); - CHECK(first->value != second->value); - WhisperTargets targets; - targets.clients.push_back(ClientId{7}); - const std::uint8_t frame[] = {1, 2, 3}; - auto sent = client.sendWhisper(*first, frame, targets); - CHECK(!sent.has_value()); - CHECK(sent.error().code == Error::Code::NotConnected); - CHECK(client.destroyVoiceStream(*first).has_value()); - CHECK(!client.destroyVoiceStream(*first).has_value()); - CHECK(client.destroyVoiceStream(*second).has_value()); -}