Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-15 21:08:28 +03:00
1 parent df7fefa85c
commit 89911ff107
6 files changed
+1915 -523

No files matched your search

+8 -5
View File
@@ -9,15 +9,18 @@ does not reproduce the proprietary C ABI.
| Identity generation/import/security level | Implemented | `Identity` |
| Connect/disconnect/state/client ID | Implemented | `Client` |
| Raw requests and typed responses | Implemented | `Client::request` |
| Client and channel lists | Implemented | `clients`, `channels` |
| Text messaging | Implemented | `sendText` |
| Client move and kick | Implemented | `move`, `kick` |
| Server groups | Implemented | `serverGroups`, add/remove client |
| Client, channel, and server directory | Implemented | rich `clients`, sensitive `clientDetails`, `channels`, `serverInfo` records |
| Channel event subscription | Implemented | `subscribeAllChannels` plus typed callbacks |
| Text messaging | Implemented | `sendText`, plus private/channel/server typed scopes |
| Client move and kick | Implemented | `move`, typed channel/server `kick` |
| Ban administration | Implemented | permanent/timed `ban`, `bans`, `unban` |
| Channel administration | Implemented | `createChannel`, `editChannel`, `reorderChannel`, `deleteChannel` |
| Server groups | Implemented | `serverGroups`, typed membership add/remove |
| Voice and whisper transmission | Implemented | `sendVoice`, `sendWhisper` |
| Independent voice timelines | Implemented | one `Client` per timeline |
| Voice receive callback | Implemented | `Events::voice` |
| File download | Implemented | `download` |
| Typed server/channel/client notifications | Implemented | client lifecycle/update/talk, channel, server, group, text, file-transfer events; batched fallback |
| Typed server/channel/client notifications | Implemented | client lifecycle/update/talk, sparse-safe `ChannelPatch`, server, group, text, file-transfer events; batched fallback |
| Permissions and channel groups | Implemented | typed lists and channel-group assignment |
| File upload/delete | Implemented | `upload`, `deleteFile` |
| Audio preprocessing/device GUI | Not applicable | client-local SDK behavior |
+155 -106
View File
@@ -1,8 +1,8 @@
#pragma once
#include <Void/Functional/Result.hpp>
#include <Void/TeamSpeak/Identity.hpp>
#include <Void/TeamSpeak/Command.hpp>
#include <Void/TeamSpeak/Identity.hpp>
#include <Void/TeamSpeak/Types.hpp>
#include <chrono>
@@ -10,6 +10,7 @@
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <span>
#include <string>
#include <string_view>
@@ -17,121 +18,169 @@
namespace Void::TeamSpeak
{
struct ConnectOptions {
std::string host;
std::uint16_t port{9987};
std::shared_ptr<Identity> identity;
std::string nickname{"VoidTeamspeak"};
std::string serverPassword;
std::string defaultChannel;
std::string channelPassword;
};
struct CommandResponse {
using Record = CommandFields;
std::vector<Record> records;
};
struct CommandEvent {
std::string name;
std::vector<CommandResponse::Record> records;
struct ConnectOptions {
std::string host;
std::uint16_t port{9987};
std::shared_ptr<Identity> identity;
std::string nickname{"VoidTeamspeak"};
std::string serverPassword;
std::string defaultChannel;
std::string channelPassword;
};
struct Events {
std::function<void()> connected;
std::function<void()> disconnected;
std::function<void(const Error&)> error;
std::function<void(std::string_view)> debug;
std::function<void(std::string_view,
const std::map<std::string, std::string>&)> command;
std::function<void(const CommandEvent&)> commandBatch;
std::function<void(const RemoteClient&)> clientEntered;
std::function<void(const ClientLeft&)> clientLeft;
std::function<void(const ClientMoved&)> clientMoved;
std::function<void(const ClientUpdated&)> clientUpdated;
std::function<void(const TalkStatusChanged&)> talkStatusChanged;
std::function<void(const TextMessage&)> textMessage;
std::function<void(const ChannelChanged&)> channelChanged;
std::function<void(const ServerUpdated&)> serverUpdated;
std::function<void(const ServerGroupMembershipChanged&)>
serverGroupMembershipChanged;
std::function<void(const ChannelGroupMembershipChanged&)>
channelGroupMembershipChanged;
std::function<void(const FileTransferStatus&)> fileTransferStatus;
std::function<void(std::span<const std::uint8_t>)> voice;
};
struct CommandResponse {
using Record = CommandFields;
std::vector<Record> records;
};
class Client final
{
public:
Client();
~Client();
Client(Client&&) noexcept;
Client& operator=(Client&&) noexcept;
Client(const Client&) = delete;
Client& operator=(const Client&) = delete;
struct CommandEvent {
std::string name;
std::vector<CommandResponse::Record> records;
};
void setEvents(Events events);
[[nodiscard]] Void::Result::Result<void, Error>
connect(const ConnectOptions& options);
void disconnect() noexcept;
void close() noexcept;
[[nodiscard]] ConnectionState state() const noexcept;
[[nodiscard]] ClientId id() const noexcept;
struct Events {
std::function<void()> connected;
std::function<void()> disconnected;
std::function<void(const Error &)> error;
std::function<void(std::string_view)> debug;
std::function<void(std::string_view,
const std::map<std::string, std::string> &)>
command;
std::function<void(const CommandEvent &)> commandBatch;
std::function<void(const RemoteClient &)> clientEntered;
std::function<void(const ClientLeft &)> clientLeft;
std::function<void(const ClientMoved &)> clientMoved;
std::function<void(const ClientUpdated &)> clientUpdated;
std::function<void(const TalkStatusChanged &)> talkStatusChanged;
std::function<void(const TextMessage &)> textMessage;
std::function<void(const ChannelChanged &)> channelChanged;
std::function<void(const ServerUpdated &)> serverUpdated;
std::function<void(const ServerGroupMembershipChanged &)>
serverGroupMembershipChanged;
std::function<void(const ChannelGroupMembershipChanged &)>
channelGroupMembershipChanged;
std::function<void(const FileTransferStatus &)> fileTransferStatus;
std::function<void(std::span<const std::uint8_t>)> voice;
};
[[nodiscard]] Void::Result::Result<CommandResponse, Error>
request(std::string_view command,
std::chrono::milliseconds timeout = std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<RemoteClient>, Error>
clients(std::chrono::milliseconds timeout = std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<Channel>, Error>
channels(std::chrono::milliseconds timeout = std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<ServerGroup>, Error>
serverGroups(
class Client final
{
public:
Client();
~Client();
Client(Client &&) noexcept;
Client &operator=(Client &&) noexcept;
Client(const Client &) = delete;
Client &operator=(const Client &) = delete;
void setEvents(Events events);
[[nodiscard]] Void::Result::Result<void, Error>
connect(const ConnectOptions &options);
void disconnect() noexcept;
void close() noexcept;
[[nodiscard]] ConnectionState state() const noexcept;
[[nodiscard]] ClientId id() const noexcept;
[[nodiscard]] Void::Result::Result<CommandResponse, Error> request(
std::string_view command,
std::chrono::milliseconds timeout = std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<ChannelGroup>, Error>
channelGroups(
[[nodiscard]] Void::Result::Result<std::vector<RemoteClient>, Error>
clients(std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<ClientDetails, Error>
clientDetails(ClientId client,
std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<Channel>, Error>
channels(std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<void, Error>
subscribeAllChannels(std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<ServerGroup>, Error>
serverGroups(std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<ChannelGroup>, Error>
channelGroups(std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<Permission>, Error>
permissions(std::chrono::milliseconds timeout =
std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<ServerInfo, Error> serverInfo(
std::chrono::milliseconds timeout = std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<std::vector<Permission>, Error>
permissions(
[[nodiscard]] Void::Result::Result<std::vector<Ban>, Error> bans(
std::chrono::milliseconds timeout = std::chrono::seconds{3});
[[nodiscard]] Void::Result::Result<void, Error>
addToServerGroup(ServerGroupId group, ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
removeFromServerGroup(ServerGroupId group, ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
setChannelGroup(ChannelGroupId group, ChannelId channel,
ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
sendText(TextTarget target, std::string_view message);
[[nodiscard]] Void::Result::Result<void, Error>
move(ClientId client, ChannelId channel);
[[nodiscard]] Void::Result::Result<void, Error>
kick(ClientId client, std::string_view reason);
[[nodiscard]] Void::Result::Result<std::filesystem::path, Error>
download(std::string_view remotePath,
const std::filesystem::path& destination,
ChannelId channel = {},
std::string_view channelPassword = {},
std::chrono::milliseconds timeout = std::chrono::seconds{10});
[[nodiscard]] Void::Result::Result<void, Error>
upload(const std::filesystem::path& source,
[[nodiscard]] Void::Result::Result<BanId, Error>
ban(ClientId client, const BanOptions &options = {});
[[nodiscard]] Void::Result::Result<void, Error> unban(BanId ban);
[[nodiscard]] Void::Result::Result<ChannelId, Error>
createChannel(const ChannelCreateOptions &options);
[[nodiscard]] Void::Result::Result<void, Error>
editChannel(ChannelId channel,
const ChannelEditOptions &options);
[[nodiscard]] Void::Result::Result<void, Error> reorderChannel(
ChannelId channel, std::optional<ChannelId> parent,
std::optional<ChannelId> orderAfter = std::nullopt);
[[nodiscard]] Void::Result::Result<void, Error>
deleteChannel(ChannelId channel, bool force = false);
[[nodiscard]] Void::Result::Result<void, Error>
addServerGroupMember(ServerGroupId group,
ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
removeServerGroupMember(ServerGroupId group,
ClientDatabaseId client);
// Compatibility names retained for existing consumers.
[[nodiscard]] Void::Result::Result<void, Error>
addToServerGroup(ServerGroupId group, ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
removeFromServerGroup(ServerGroupId group,
ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
setChannelGroup(ChannelGroupId group, ChannelId channel,
ClientDatabaseId client);
[[nodiscard]] Void::Result::Result<void, Error>
sendText(TextTarget target, std::string_view message);
[[nodiscard]] Void::Result::Result<void, Error>
sendPrivateMessage(ClientId client, std::string_view message);
[[nodiscard]] Void::Result::Result<void, Error>
sendChannelMessage(ChannelId channel, std::string_view message);
[[nodiscard]] Void::Result::Result<void, Error>
sendServerMessage(std::string_view message);
[[nodiscard]] Void::Result::Result<void, Error>
move(ClientId client, ChannelId channel);
[[nodiscard]] Void::Result::Result<void, Error>
kick(ClientId client, KickScope scope, std::string_view reason);
[[nodiscard]] Void::Result::Result<void, Error>
kick(ClientId client, std::string_view reason);
[[nodiscard]] Void::Result::Result<std::filesystem::path, Error>
download(std::string_view remotePath,
const std::filesystem::path &destination,
ChannelId channel = {},
std::string_view channelPassword = {},
std::chrono::milliseconds timeout =
std::chrono::seconds{10});
[[nodiscard]] Void::Result::Result<void, Error> upload(
const std::filesystem::path &source,
std::string_view remotePath, ChannelId channel = {},
std::string_view channelPassword = {}, bool overwrite = false,
std::chrono::milliseconds timeout = std::chrono::seconds{10});
[[nodiscard]] Void::Result::Result<void, Error>
deleteFile(std::string_view remotePath, ChannelId channel = {},
std::string_view channelPassword = {});
[[nodiscard]] Void::Result::Result<void, Error>
deleteFile(std::string_view remotePath, ChannelId channel = {},
std::string_view channelPassword = {});
[[nodiscard]] Void::Result::Result<void, Error>
sendVoice(std::span<const std::uint8_t> opusFrame);
[[nodiscard]] Void::Result::Result<void, Error>
sendWhisper(std::span<const std::uint8_t> opusFrame,
const WhisperTargets& targets);
void stopVoice() noexcept;
[[nodiscard]] Void::Result::Result<void, Error>
sendVoice(std::span<const std::uint8_t> opusFrame);
[[nodiscard]] Void::Result::Result<void, Error>
sendWhisper(std::span<const std::uint8_t> opusFrame,
const WhisperTargets &targets);
void stopVoice() noexcept;
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
}
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace Void::TeamSpeak
+349 -93
View File
@@ -1,160 +1,416 @@
#pragma once
#include <chrono>
#include <compare>
#include <cstdint>
#include <map>
#include <string>
#include <optional>
#include <string>
#include <vector>
namespace Void::TeamSpeak
{
template <typename Tag, typename Value>
struct Id {
Value value{};
explicit constexpr operator bool() const noexcept { return value != 0; }
auto operator<=>(const Id&) const = default;
};
template <typename Tag, typename Value> struct Id {
Value value{};
explicit constexpr operator bool() const noexcept
{
return value != 0;
}
auto operator<=>(const Id &) const = default;
};
using ClientId = Id<struct ClientIdTag, std::uint16_t>;
using ClientId = Id<struct ClientIdTag, std::uint16_t>;
using ClientDatabaseId = Id<struct ClientDatabaseIdTag, std::uint64_t>;
using ChannelId = Id<struct ChannelIdTag, std::uint64_t>;
using ServerConnectionId = Id<struct ServerConnectionIdTag, std::uint64_t>;
using ChannelId = Id<struct ChannelIdTag, std::uint64_t>;
using ServerConnectionId = Id<struct ServerConnectionIdTag, std::uint64_t>;
using ServerGroupId = Id<struct ServerGroupIdTag, std::uint64_t>;
using ChannelGroupId = Id<struct ChannelGroupIdTag, std::uint64_t>;
using PermissionId = Id<struct PermissionIdTag, std::uint32_t>;
using BanId = Id<struct BanIdTag, std::uint64_t>;
enum class ConnectionState {
Disconnected,
Initializing,
Handshaking,
Connected,
Disconnecting,
};
enum class ConnectionState {
Disconnected,
Initializing,
Handshaking,
Connected,
Disconnecting,
};
struct WhisperTargets {
std::vector<ChannelId> channels;
std::vector<ClientId> clients;
[[nodiscard]] bool empty() const noexcept
{
return channels.empty() && clients.empty();
}
};
struct WhisperTargets {
std::vector<ChannelId> channels;
std::vector<ClientId> clients;
[[nodiscard]] bool empty() const noexcept
{
return channels.empty() && clients.empty();
}
};
struct RemoteClient {
ClientId id;
ChannelId channel;
std::string nickname;
std::string uniqueId;
ClientId id;
ClientDatabaseId databaseId;
ChannelId channel;
std::string nickname;
std::string uniqueId;
std::vector<ServerGroupId> serverGroups;
int type{};
int talkPower{};
bool inputMuted{false};
bool outputMuted{false};
bool inputHardware{true};
bool outputHardware{true};
bool away{false};
bool talking{false};
bool recording{false};
bool channelCommander{false};
bool prioritySpeaker{false};
std::string awayMessage;
std::string country;
[[nodiscard]] bool isQuery() const noexcept { return type != 0; }
[[nodiscard]] bool muted() const noexcept
{
return inputMuted || !inputHardware;
}
[[nodiscard]] bool deafened() const noexcept
{
return outputMuted || !outputHardware;
}
};
struct ClientDetails {
RemoteClient client;
// Sensitive connection data is intentionally kept out of
// RemoteClient so directory snapshots cannot expose it
// accidentally.
std::optional<std::string> connectionIp;
std::optional<std::string> avatarHash;
std::optional<std::string> avatarUrl;
};
struct ClientLeft {
ClientId id;
int reasonId{};
std::string reasonMessage;
ClientId id;
int reasonId{};
std::string reasonMessage;
};
struct ClientMoved {
ClientId id;
ChannelId channel;
ClientId id;
ChannelId channel;
};
struct ClientUpdated {
ClientId id;
std::optional<std::string> nickname;
std::optional<std::string> uniqueId;
std::optional<bool> inputMuted;
std::optional<bool> outputMuted;
std::optional<bool> away;
std::optional<bool> recording;
std::map<std::string, std::string> properties;
ClientId id;
std::optional<std::string> nickname;
std::optional<std::string> uniqueId;
std::optional<bool> inputMuted;
std::optional<bool> outputMuted;
std::optional<bool> inputHardware;
std::optional<bool> outputHardware;
std::optional<bool> away;
std::optional<bool> talking;
std::optional<bool> recording;
std::optional<bool> channelCommander;
std::optional<bool> prioritySpeaker;
std::optional<std::string> avatarHash;
std::optional<std::string> avatarUrl;
std::map<std::string, std::string> properties;
};
struct TalkStatusChanged {
ClientId id;
bool talking{false};
bool whisper{false};
ClientId id;
bool talking{false};
bool whisper{false};
};
struct Channel {
ChannelId id;
std::optional<ChannelId> parent;
std::string name;
bool passwordProtected{false};
ChannelId id;
std::optional<ChannelId> parent;
ChannelId orderAfter;
std::string name;
std::string topic;
std::string description;
int codec{};
int codecQuality{};
int maxClients{};
int maxFamilyClients{};
int neededTalkPower{};
std::uint64_t iconId{};
bool passwordProtected{false};
bool permanent{false};
bool semiPermanent{false};
bool defaultChannel{false};
bool unlimitedClients{false};
bool unlimitedFamilyClients{false};
};
// TeamSpeak channel notifications are sparse: only fields that changed are
// guaranteed to be present. Keeping that distinction in the public type
// prevents an omitted value from resetting a cached channel to its default.
struct ChannelPatch {
// The outer optional means "present in the notification". The
// inner optional is empty when the channel was explicitly moved to
// the root.
std::optional<std::optional<ChannelId>> parent;
std::optional<ChannelId> orderAfter;
std::optional<std::string> name;
std::optional<std::string> topic;
std::optional<std::string> description;
std::optional<int> codec;
std::optional<int> codecQuality;
std::optional<int> maxClients;
std::optional<int> maxFamilyClients;
std::optional<int> neededTalkPower;
std::optional<std::uint64_t> iconId;
std::optional<bool> passwordProtected;
std::optional<bool> permanent;
std::optional<bool> semiPermanent;
std::optional<bool> defaultChannel;
std::optional<bool> unlimitedClients;
std::optional<bool> unlimitedFamilyClients;
std::map<std::string, std::string> properties;
[[nodiscard]] bool empty() const noexcept
{
return !parent && !orderAfter && !name && !topic &&
!description && !codec && !codecQuality && !maxClients &&
!maxFamilyClients && !neededTalkPower && !iconId &&
!passwordProtected && !permanent && !semiPermanent &&
!defaultChannel && !unlimitedClients &&
!unlimitedFamilyClients;
}
void applyTo(Channel &channel) const
{
if (parent) {
channel.parent = *parent;
}
if (orderAfter) {
channel.orderAfter = *orderAfter;
}
if (name) {
channel.name = *name;
}
if (topic) {
channel.topic = *topic;
}
if (description) {
channel.description = *description;
}
if (codec) {
channel.codec = *codec;
}
if (codecQuality) {
channel.codecQuality = *codecQuality;
}
if (maxClients) {
channel.maxClients = *maxClients;
}
if (maxFamilyClients) {
channel.maxFamilyClients = *maxFamilyClients;
}
if (neededTalkPower) {
channel.neededTalkPower = *neededTalkPower;
}
if (iconId) {
channel.iconId = *iconId;
}
if (passwordProtected) {
channel.passwordProtected = *passwordProtected;
}
if (permanent) {
channel.permanent = *permanent;
}
if (semiPermanent) {
channel.semiPermanent = *semiPermanent;
}
if (defaultChannel) {
channel.defaultChannel = *defaultChannel;
}
if (unlimitedClients) {
channel.unlimitedClients = *unlimitedClients;
}
if (unlimitedFamilyClients) {
channel.unlimitedFamilyClients = *unlimitedFamilyClients;
}
}
};
enum class ChannelLifetime { Temporary, SemiPermanent, Permanent };
struct ChannelCreateOptions {
std::string name;
std::optional<ChannelId> parent;
std::optional<ChannelId> orderAfter;
std::string topic;
std::string description;
std::string password;
std::optional<int> codec;
std::optional<int> codecQuality;
std::optional<int> maxClients;
std::optional<int> maxFamilyClients;
std::optional<int> neededTalkPower;
ChannelLifetime lifetime{ChannelLifetime::Permanent};
bool defaultChannel{false};
bool unlimitedClients{false};
bool unlimitedFamilyClients{false};
};
struct ChannelEditOptions {
std::optional<std::string> name;
std::optional<std::string> topic;
std::optional<std::string> description;
std::optional<std::string> password;
std::optional<int> codec;
std::optional<int> codecQuality;
std::optional<int> maxClients;
std::optional<int> maxFamilyClients;
std::optional<int> neededTalkPower;
std::optional<ChannelLifetime> lifetime;
std::optional<bool> defaultChannel;
std::optional<bool> unlimitedClients;
std::optional<bool> unlimitedFamilyClients;
[[nodiscard]] bool empty() const noexcept
{
return !name && !topic && !description && !password && !codec &&
!codecQuality && !maxClients && !maxFamilyClients &&
!neededTalkPower && !lifetime && !defaultChannel &&
!unlimitedClients && !unlimitedFamilyClients;
}
};
struct ServerGroup {
ServerGroupId id;
std::string name;
int type{};
ServerGroupId id;
std::string name;
int type{};
int nameMode{};
int sortId{};
int modifyPower{};
int memberAddPower{};
int memberRemovePower{};
std::uint64_t iconId{};
bool savedToDatabase{false};
};
struct ChannelGroup {
ChannelGroupId id;
std::string name;
int type{};
ChannelGroupId id;
std::string name;
int type{};
};
struct Permission {
PermissionId id;
std::string name;
std::string description;
PermissionId id;
std::string name;
std::string description;
};
struct ServerInfo {
ServerConnectionId id;
std::string uniqueIdentifier;
std::string name;
std::string welcomeMessage;
std::string platform;
std::string version;
std::string hostMessage;
int hostMessageMode{};
std::uint64_t uptimeSeconds{};
std::uint64_t maxClients{};
std::uint64_t clientCount{};
std::uint64_t queryClientCount{};
std::uint64_t channelCount{};
std::uint64_t reservedSlots{};
ServerGroupId defaultServerGroup;
ChannelGroupId defaultChannelGroup;
ChannelGroupId defaultChannelAdminGroup;
bool passwordProtected{false};
};
struct Ban {
BanId id;
std::string ip;
std::string name;
std::string uniqueId;
std::string lastNickname;
std::uint64_t createdAtUnixSeconds{};
std::chrono::seconds duration{};
ClientDatabaseId invokerDatabaseId;
std::string invokerName;
std::string invokerUniqueId;
std::string reason;
std::uint64_t enforcements{};
[[nodiscard]] bool permanent() const noexcept
{
return duration == std::chrono::seconds::zero();
}
};
struct BanOptions {
// No duration means a permanent ban. Timed bans must be positive.
std::optional<std::chrono::seconds> duration;
std::string reason;
};
enum class KickScope { Channel = 4, Server = 5 };
enum class TextTargetKind { Client = 1, Channel = 2, Server = 3 };
struct TextTarget {
TextTargetKind kind{TextTargetKind::Client};
std::uint64_t id{};
TextTargetKind kind{TextTargetKind::Client};
std::uint64_t id{};
};
struct TextMessage {
TextTarget target;
ClientId invoker;
std::string invokerName;
std::string message;
TextTarget target;
ClientId invoker;
std::string invokerName;
std::string message;
};
enum class ChannelChangeKind { Created, Updated, Moved, Deleted };
struct ChannelChanged {
ChannelChangeKind kind{ChannelChangeKind::Updated};
Channel channel;
ChannelChangeKind kind{ChannelChangeKind::Updated};
ChannelId id;
ChannelPatch patch;
ClientId invoker;
int reasonId{};
};
struct ServerUpdated {
std::optional<std::string> name;
std::optional<std::string> welcomeMessage;
ClientId invoker;
std::map<std::string, std::string> properties;
std::optional<std::string> name;
std::optional<std::string> welcomeMessage;
ClientId invoker;
std::map<std::string, std::string> properties;
};
struct ServerGroupMembershipChanged {
bool added{false};
ServerGroupId group;
ClientDatabaseId client;
ClientId invoker;
bool added{false};
ServerGroupId group;
ClientDatabaseId client;
ClientId invoker;
};
struct ChannelGroupMembershipChanged {
ChannelGroupId group;
ChannelId channel;
ClientDatabaseId client;
ClientId invoker;
ChannelGroupId group;
ChannelId channel;
ClientDatabaseId client;
ClientId invoker;
};
struct FileTransferStatus {
std::uint64_t id{};
int status{};
std::string message;
std::uint64_t id{};
int status{};
std::string message;
};
struct Error {
enum class Code {
InvalidArgument,
NotConnected,
Timeout,
Protocol,
Io,
NotSupported,
} code{Code::Protocol};
std::string message;
};
}
struct Error {
enum class Code {
InvalidArgument,
NotConnected,
Timeout,
Protocol,
Io,
NotSupported,
} code{Code::Protocol};
std::string message;
};
} // namespace Void::TeamSpeak
+1143 -310
View File
File diff suppressed because it is too large. Load diff
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <Void/TeamSpeak/Command.hpp>
#include <Void/TeamSpeak/Types.hpp>
#include <optional>
#include <string_view>
namespace Void::TeamSpeak::Detail
{
[[nodiscard]] std::optional<ChannelChanged>
parseChannelChanged(std::string_view eventName,
const CommandFields &record);
} // namespace Void::TeamSpeak::Detail
+246 -9
View File
@@ -2,6 +2,9 @@
#include <Void/TeamSpeak/TeamSpeak.hpp>
#include "../src/EventParser.hpp"
#include <chrono>
#include <type_traits>
#include <utility>
@@ -12,23 +15,47 @@ static_assert(std::is_move_constructible_v<Client>);
static_assert(std::is_same_v<decltype(Client{}.id()), ClientId>);
static_assert(std::is_same_v<decltype(ChannelGroup{}.id), ChannelGroupId>);
static_assert(std::is_same_v<decltype(Permission{}.id), PermissionId>);
static_assert(std::is_same_v<decltype(Ban{}.id), BanId>);
static_assert(
std::is_same_v<decltype(RemoteClient{}.databaseId), ClientDatabaseId>);
static_assert(
std::is_same_v<decltype(ServerInfo{}.defaultServerGroup), ServerGroupId>);
static_assert(std::is_same_v<decltype(Events{}.clientUpdated),
std::function<void(const ClientUpdated&)>>);
std::function<void(const ClientUpdated &)>>);
static_assert(std::is_same_v<decltype(Events{}.talkStatusChanged),
std::function<void(const TalkStatusChanged&)>>);
std::function<void(const TalkStatusChanged &)>>);
static_assert(std::is_same_v<decltype(Events{}.channelChanged),
std::function<void(const ChannelChanged &)>>);
static_assert(std::is_same_v<decltype(ChannelChanged{}.patch), ChannelPatch>);
static_assert(std::is_same_v<decltype(Events{}.serverUpdated),
std::function<void(const ServerUpdated&)>>);
std::function<void(const ServerUpdated &)>>);
static_assert(std::is_same_v<decltype(Events{}.fileTransferStatus),
std::function<void(const FileTransferStatus&)>>);
static_assert(std::is_same_v<decltype(std::declval<Client&>().deleteFile("x")),
Void::Result::Result<void, Error>>);
std::function<void(const FileTransferStatus &)>>);
static_assert(std::is_same_v<decltype(std::declval<Client &>().deleteFile("x")),
Void::Result::Result<void, Error>>);
static_assert(
std::is_same_v<decltype(std::declval<Client &>().ban(ClientId{1})),
Void::Result::Result<BanId, Error>>);
static_assert(std::is_same_v<decltype(std::declval<Client &>().createChannel(
std::declval<const ChannelCreateOptions &>())),
Void::Result::Result<ChannelId, Error>>);
static_assert(std::is_same_v<decltype(std::declval<Client &>().serverInfo()),
Void::Result::Result<ServerInfo, Error>>);
static_assert(std::is_same_v<decltype(std::declval<Client &>().bans()),
Void::Result::Result<std::vector<Ban>, Error>>);
static_assert(std::is_same_v<
decltype(std::declval<Client &>().clientDetails(ClientId{1})),
Void::Result::Result<ClientDetails, Error>>);
static_assert(
std::is_same_v<decltype(std::declval<Client &>().subscribeAllChannels()),
Void::Result::Result<void, Error>>);
TEST_CASE(modern_build_command_escapes_fields)
{
const auto command = buildCommand("sendtextmessage", {
{"msg", "hello world|all"}, {"target", "7"}});
const auto command = buildCommand(
"sendtextmessage", {{"msg", "hello world|all"}, {"target", "7"}});
CHECK_EQ(command,
std::string("sendtextmessage msg=hello\\sworld\\pall target=7"));
std::string("sendtextmessage msg=hello\\sworld\\pall target=7"));
}
TEST_CASE(strong_ids_do_not_implicitly_convert)
@@ -48,3 +75,213 @@ TEST_CASE(whisper_targets_report_empty_state)
targets.clients.push_back(ClientId{7});
CHECK(!targets.empty());
}
TEST_CASE(channel_edit_options_preserve_explicit_false)
{
ChannelEditOptions options;
CHECK(options.empty());
options.defaultChannel = false;
CHECK(!options.empty());
}
TEST_CASE(channel_patch_preserves_fields_omitted_by_sparse_events)
{
Channel cached{.id = ChannelId{7},
.parent = ChannelId{2},
.orderAfter = ChannelId{6},
.name = "Original",
.topic = "Keep topic",
.description = "Keep description",
.codec = 4,
.codecQuality = 8,
.maxClients = 32,
.maxFamilyClients = 64,
.neededTalkPower = 25,
.iconId = 99,
.passwordProtected = true,
.permanent = true,
.defaultChannel = true,
.unlimitedClients = true};
const ChannelPatch patch{.name = "Renamed"};
patch.applyTo(cached);
CHECK_EQ(cached.name, std::string{"Renamed"});
CHECK_EQ(cached.topic, std::string{"Keep topic"});
CHECK_EQ(cached.description, std::string{"Keep description"});
CHECK(cached.parent == std::optional{ChannelId{2}});
CHECK(cached.orderAfter == ChannelId{6});
CHECK(cached.codec == 4);
CHECK(cached.codecQuality == 8);
CHECK(cached.maxClients == 32);
CHECK(cached.maxFamilyClients == 64);
CHECK(cached.neededTalkPower == 25);
CHECK(cached.iconId == 99);
CHECK(cached.passwordProtected);
CHECK(cached.permanent);
CHECK(cached.defaultChannel);
CHECK(cached.unlimitedClients);
}
TEST_CASE(channel_patch_applies_explicit_empty_zero_false_and_root_values)
{
Channel cached{.id = ChannelId{7},
.parent = ChannelId{2},
.orderAfter = ChannelId{6},
.topic = "Topic",
.description = "Description",
.maxClients = 32,
.iconId = 99,
.passwordProtected = true,
.defaultChannel = true};
const ChannelPatch patch{.parent = std::optional<ChannelId>{},
.orderAfter = ChannelId{},
.topic = "",
.description = "",
.maxClients = 0,
.iconId = 0,
.passwordProtected = false,
.defaultChannel = false};
CHECK(!patch.empty());
patch.applyTo(cached);
CHECK(!cached.parent);
CHECK(!static_cast<bool>(cached.orderAfter));
CHECK(cached.topic.empty());
CHECK(cached.description.empty());
CHECK(cached.maxClients == 0);
CHECK(cached.iconId == 0);
CHECK(!cached.passwordProtected);
CHECK(!cached.defaultChannel);
}
TEST_CASE(channel_events_decode_only_fields_present_in_the_notification)
{
const CommandFields record{{"cid", "42"},
{"channel_name", "Renamed"},
{"channel_flag_default", "0"},
{"reasonid", "10"},
{"invokerid", "7"}};
const auto event =
Detail::parseChannelChanged("notifychanneledited", record);
CHECK(event.has_value());
CHECK(event->kind == ChannelChangeKind::Updated);
CHECK(event->id == ChannelId{42});
CHECK(event->invoker == ClientId{7});
CHECK(event->reasonId == 10);
CHECK(event->patch.name == std::optional<std::string>{"Renamed"});
CHECK(event->patch.defaultChannel == std::optional<bool>{false});
CHECK(!event->patch.topic);
CHECK(!event->patch.description);
CHECK(!event->patch.codec);
CHECK(!event->patch.parent);
CHECK(!event->patch.orderAfter);
}
TEST_CASE(channel_move_events_preserve_explicit_root_and_zero_order)
{
const CommandFields record{{"cid", "42"}, {"cpid", "0"}, {"order", "0"}};
const auto event =
Detail::parseChannelChanged("notifychannelmoved", record);
CHECK(event.has_value());
CHECK(event->patch.parent.has_value());
CHECK(!*event->patch.parent);
CHECK(event->patch.orderAfter == std::optional{ChannelId{}});
Channel cached{.id = ChannelId{42},
.parent = ChannelId{2},
.orderAfter = ChannelId{6},
.name = "Keep"};
event->patch.applyTo(cached);
CHECK(!cached.parent);
CHECK(!static_cast<bool>(cached.orderAfter));
CHECK_EQ(cached.name, std::string{"Keep"});
}
TEST_CASE(channel_events_reject_invalid_identity_and_ignore_invalid_fields)
{
CHECK(!Detail::parseChannelChanged("notifychannelmoved", {{"cpid", "2"}}));
CHECK(!Detail::parseChannelChanged("unrelated", {{"cid", "42"}}));
const auto event = Detail::parseChannelChanged(
"notifychanneledited",
{{"cid", "42"}, {"channel_codec", "not-a-number"}});
CHECK(event.has_value());
CHECK(!event->patch.codec);
}
TEST_CASE(ban_models_permanent_and_timed_duration)
{
const Ban permanent{.duration = std::chrono::seconds::zero()};
const Ban timed{.duration = std::chrono::minutes{10}};
CHECK(permanent.permanent());
CHECK(!timed.permanent());
}
TEST_CASE(remote_client_derives_public_status_flags)
{
const RemoteClient query{
.type = 1, .inputHardware = false, .outputHardware = false};
CHECK(query.isQuery());
CHECK(query.muted());
CHECK(query.deafened());
const RemoteClient voice;
CHECK(!voice.isQuery());
CHECK(!voice.muted());
CHECK(!voice.deafened());
}
TEST_CASE(administration_operations_reject_invalid_identifiers)
{
Client client;
const auto ban = client.ban(ClientId{});
const auto unban = client.unban(BanId{});
const auto edit =
client.editChannel(ChannelId{}, ChannelEditOptions{.name = "name"});
const auto reorder = client.reorderChannel(ChannelId{}, std::nullopt);
const auto remove = client.deleteChannel(ChannelId{});
const auto addGroup =
client.addServerGroupMember(ServerGroupId{}, ClientDatabaseId{1});
const auto move = client.move(ClientId{1}, ChannelId{});
const auto kick = client.kick(ClientId{}, KickScope::Channel, "reason");
const auto details = client.clientDetails(ClientId{});
CHECK(!ban && ban.error().code == Error::Code::InvalidArgument);
CHECK(!unban && unban.error().code == Error::Code::InvalidArgument);
CHECK(!edit && edit.error().code == Error::Code::InvalidArgument);
CHECK(!reorder && reorder.error().code == Error::Code::InvalidArgument);
CHECK(!remove && remove.error().code == Error::Code::InvalidArgument);
CHECK(!addGroup && addGroup.error().code == Error::Code::InvalidArgument);
CHECK(!move && move.error().code == Error::Code::InvalidArgument);
CHECK(!kick && kick.error().code == Error::Code::InvalidArgument);
CHECK(!details && details.error().code == Error::Code::InvalidArgument);
}
TEST_CASE(administration_operations_validate_payloads_before_transport)
{
Client client;
const auto missingName = client.createChannel(ChannelCreateOptions{});
const auto emptyEdit = client.editChannel(ChannelId{1}, {});
const auto invalidQuality = client.createChannel(
ChannelCreateOptions{.name = "Talk", .codecQuality = 11});
const auto invalidDuration = client.ban(
ClientId{1}, BanOptions{.duration = std::chrono::seconds::zero()});
const auto emptyMessage = client.sendServerMessage("");
const auto missingTarget = client.sendPrivateMessage(ClientId{}, "hello");
CHECK(!missingName &&
missingName.error().code == Error::Code::InvalidArgument);
CHECK(!emptyEdit && emptyEdit.error().code == Error::Code::InvalidArgument);
CHECK(!invalidQuality &&
invalidQuality.error().code == Error::Code::InvalidArgument);
CHECK(!invalidDuration &&
invalidDuration.error().code == Error::Code::InvalidArgument);
CHECK(!emptyMessage &&
emptyMessage.error().code == Error::Code::InvalidArgument);
CHECK(!missingTarget &&
missingTarget.error().code == Error::Code::InvalidArgument);
}