1 parent
a7ffe73a6c
commit
c1a11ffe29
29 files changed
+433
-123
No files matched your search
@@ -31,8 +31,6 @@ pkg_check_modules(OPUS IMPORTED_TARGET opus)
|
||||
file(GLOB VOID_TEAMSPEAK_SOURCES CONFIGURE_DEPENDS "src/*.cpp")
|
||||
add_library(VoidTeamspeak ${VOID_TEAMSPEAK_SOURCES})
|
||||
add_library(Void::TeamSpeak ALIAS VoidTeamspeak)
|
||||
# One-release source compatibility for Echoion consumers.
|
||||
add_library(Echoion::Protocol ALIAS VoidTeamspeak)
|
||||
|
||||
target_compile_features(VoidTeamspeak PUBLIC cxx_std_26)
|
||||
target_include_directories(VoidTeamspeak PUBLIC
|
||||
|
||||
@@ -6,8 +6,8 @@ official GUI client or depending on its proprietary ClientLib.
|
||||
|
||||
The public API follows the concepts of the original TeamSpeak Client SDK while
|
||||
using RAII, strong IDs, chrono durations, spans, typed events, and
|
||||
`Void::Result`. The compatibility implementation currently lives below the
|
||||
modern facade and will be removed after the Echoion migration release.
|
||||
`Void::Result`. The lower-level implementation lives under
|
||||
`Void::TeamSpeak::Protocol`; application code should use the owning facade.
|
||||
|
||||
## Public API
|
||||
|
||||
|
||||
+3
-3
@@ -17,9 +17,9 @@ does not reproduce the proprietary C ABI.
|
||||
| Independent voice timelines | Implemented | one `Client` per timeline |
|
||||
| Voice receive callback | Implemented | `Events::voice` |
|
||||
| File download | Implemented | `download` |
|
||||
| Typed server/channel/client notifications | Partial | typed command event plus raw request fallback |
|
||||
| Permissions and channel groups | Partial | raw request fallback |
|
||||
| File upload/delete | Planned | raw request fallback |
|
||||
| Typed server/channel/client notifications | Partial | common client/channel/text events typed; batched command 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 |
|
||||
| GUI contacts, hotkeys, overlays | Not applicable | client-local SDK behavior |
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
#include <Void/TeamSpeak/Identity.hpp>
|
||||
#include <Void/TeamSpeak/Command.hpp>
|
||||
#include <Void/TeamSpeak/Types.hpp>
|
||||
|
||||
#include <chrono>
|
||||
@@ -27,10 +28,15 @@ namespace Void::TeamSpeak
|
||||
};
|
||||
|
||||
struct CommandResponse {
|
||||
using Record = std::map<std::string, std::string>;
|
||||
using Record = CommandFields;
|
||||
std::vector<Record> records;
|
||||
};
|
||||
|
||||
struct CommandEvent {
|
||||
std::string name;
|
||||
std::vector<CommandResponse::Record> records;
|
||||
};
|
||||
|
||||
struct Events {
|
||||
std::function<void()> connected;
|
||||
std::function<void()> disconnected;
|
||||
@@ -38,6 +44,12 @@ namespace Void::TeamSpeak
|
||||
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 TextMessage&)> textMessage;
|
||||
std::function<void(const ChannelChanged&)> channelChanged;
|
||||
std::function<void(std::span<const std::uint8_t>)> voice;
|
||||
};
|
||||
|
||||
@@ -69,10 +81,19 @@ namespace Void::TeamSpeak
|
||||
[[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<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>
|
||||
@@ -85,6 +106,14 @@ namespace Void::TeamSpeak
|
||||
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>
|
||||
sendVoice(std::span<const std::uint8_t> opusFrame);
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace Void::TeamSpeak
|
||||
{
|
||||
using CommandFields = std::map<std::string, std::string>;
|
||||
|
||||
// Build a TeamSpeak command with protocol-safe escaping for every value.
|
||||
[[nodiscard]] std::string buildCommand(
|
||||
std::string_view name, const CommandFields& fields = {});
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/protocol/Identity.hpp>
|
||||
#include <Void/TeamSpeak/Protocol/Identity.hpp>
|
||||
|
||||
namespace Void::TeamSpeak
|
||||
{
|
||||
// Modern public name; the implementation remains source-compatible during
|
||||
// the extraction release.
|
||||
using Identity = Echoion::Protocol::Identity;
|
||||
using Identity = Void::TeamSpeak::Protocol::Identity;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
|
||||
// Escape / unescape a single token per the TS3 rules
|
||||
@@ -33,4 +33,4 @@ namespace Echoion::Protocol
|
||||
// Parse a raw command / notify line into name + params (+ pipe groups).
|
||||
ParsedCommand parseCommand(const std::string& raw);
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol::Crypto
|
||||
namespace Void::TeamSpeak::Protocol::Crypto
|
||||
{
|
||||
|
||||
using Bytes = std::vector<uint8_t>;
|
||||
@@ -85,4 +85,4 @@ namespace Echoion::Protocol::Crypto
|
||||
// base64(sha1(utf8(password))); empty string for empty password.
|
||||
std::string hashPassword(const std::string& password);
|
||||
|
||||
} // namespace Echoion::Protocol::Crypto
|
||||
} // namespace Void::TeamSpeak::Protocol::Crypto
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
|
||||
class Identity
|
||||
@@ -62,4 +62,4 @@ namespace Echoion::Protocol
|
||||
uint64_t keyOffset_ = 0;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
|
||||
using Bytes = std::vector<uint8_t>;
|
||||
@@ -42,4 +42,4 @@ namespace Echoion::Protocol
|
||||
std::array<uint8_t, 64>
|
||||
getSharedSecret2(ByteView serverDerivedKey, ByteView tempPrivateKey);
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
|
||||
using Bytes = std::vector<uint8_t>;
|
||||
@@ -20,4 +20,4 @@ namespace Echoion::Protocol
|
||||
// Throws std::runtime_error on malformed input or unsupported level.
|
||||
Bytes qlzDecompress(ByteView data);
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
+10
-5
@@ -8,8 +8,8 @@
|
||||
// send methods are thread-safe (guarded by an internal mutex) so the audio
|
||||
// thread can call sendVoice() directly. Callbacks fire on the loop thread.
|
||||
|
||||
#include "echoion/protocol/Command.hpp"
|
||||
#include "echoion/protocol/Identity.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Command.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Identity.hpp"
|
||||
#include <Void/Net/Socket.hpp>
|
||||
|
||||
#include <atomic>
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
|
||||
enum class PacketType : uint8_t {
|
||||
@@ -53,7 +53,7 @@ namespace Echoion::Protocol
|
||||
std::string host;
|
||||
uint16_t port = 9987;
|
||||
const Identity* identity = nullptr; // not owned
|
||||
std::string nickname = "EchoionBot";
|
||||
std::string nickname = "VoidTeamspeak";
|
||||
std::string serverPassword;
|
||||
std::string defaultChannel; // channel id or name
|
||||
std::string channelPassword;
|
||||
@@ -122,6 +122,11 @@ namespace Echoion::Protocol
|
||||
const std::string& remotePath, const std::string& destination,
|
||||
uint64_t channelId = 0, const std::string& channelPassword = {},
|
||||
std::chrono::milliseconds timeout = std::chrono::seconds{10});
|
||||
CommandResult uploadFile(
|
||||
const std::string& source, const std::string& remotePath,
|
||||
uint64_t channelId = 0, const std::string& channelPassword = {},
|
||||
bool overwrite = false,
|
||||
std::chrono::milliseconds timeout = std::chrono::seconds{10});
|
||||
|
||||
private:
|
||||
|
||||
@@ -227,4 +232,4 @@ namespace Echoion::Protocol
|
||||
std::atomic<uint16_t> transferId_{0};
|
||||
};
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Protocol::Util
|
||||
namespace Void::TeamSpeak::Protocol::Util
|
||||
{
|
||||
|
||||
using Bytes = std::vector<uint8_t>;
|
||||
@@ -21,4 +21,4 @@ namespace Echoion::Protocol::Util
|
||||
std::string toHex(ByteView data);
|
||||
Bytes fromHex(const std::string& hex);
|
||||
|
||||
} // namespace Echoion::Protocol::Util
|
||||
} // namespace Void::TeamSpeak::Protocol::Util
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/TeamSpeak/Client.hpp>
|
||||
#include <Void/TeamSpeak/Command.hpp>
|
||||
#include <Void/TeamSpeak/Identity.hpp>
|
||||
#include <Void/TeamSpeak/Library.hpp>
|
||||
#include <Void/TeamSpeak/Types.hpp>
|
||||
@@ -46,6 +46,17 @@ namespace Void::TeamSpeak
|
||||
std::string uniqueId;
|
||||
};
|
||||
|
||||
struct ClientLeft {
|
||||
ClientId id;
|
||||
int reasonId{};
|
||||
std::string reasonMessage;
|
||||
};
|
||||
|
||||
struct ClientMoved {
|
||||
ClientId id;
|
||||
ChannelId channel;
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
ChannelId id;
|
||||
std::optional<ChannelId> parent;
|
||||
@@ -59,12 +70,37 @@ namespace Void::TeamSpeak
|
||||
int type{};
|
||||
};
|
||||
|
||||
struct ChannelGroup {
|
||||
ChannelGroupId id;
|
||||
std::string name;
|
||||
int type{};
|
||||
};
|
||||
|
||||
struct Permission {
|
||||
PermissionId id;
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
enum class TextTargetKind { Client = 1, Channel = 2, Server = 3 };
|
||||
struct TextTarget {
|
||||
TextTargetKind kind{TextTargetKind::Client};
|
||||
std::uint64_t id{};
|
||||
};
|
||||
|
||||
struct TextMessage {
|
||||
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;
|
||||
};
|
||||
|
||||
struct Error {
|
||||
enum class Code {
|
||||
InvalidArgument,
|
||||
|
||||
+155
-20
@@ -1,8 +1,8 @@
|
||||
#include <Void/TeamSpeak/Client.hpp>
|
||||
#include <Void/TeamSpeak/Identity.hpp>
|
||||
|
||||
#include <echoion/protocol/TsClient.hpp>
|
||||
#include <echoion/protocol/Command.hpp>
|
||||
#include <Void/TeamSpeak/Protocol/TsClient.hpp>
|
||||
#include <Void/TeamSpeak/Protocol/Command.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <charconv>
|
||||
@@ -11,9 +11,14 @@
|
||||
|
||||
namespace Void::TeamSpeak
|
||||
{
|
||||
std::string buildCommand(std::string_view name, const CommandFields& fields)
|
||||
{
|
||||
return Void::TeamSpeak::Protocol::buildCommand(std::string{name}, fields);
|
||||
}
|
||||
|
||||
class Client::Impl {
|
||||
public:
|
||||
Echoion::Protocol::TsClient client;
|
||||
Void::TeamSpeak::Protocol::TsClient client;
|
||||
Events events;
|
||||
};
|
||||
|
||||
@@ -24,9 +29,9 @@ namespace Void::TeamSpeak
|
||||
return Error{Error::Code::Protocol, std::move(message)};
|
||||
}
|
||||
|
||||
ConnectionState convert(Echoion::Protocol::ClientState state)
|
||||
ConnectionState convert(Void::TeamSpeak::Protocol::ClientState state)
|
||||
{
|
||||
using Old = Echoion::Protocol::ClientState;
|
||||
using Old = Void::TeamSpeak::Protocol::ClientState;
|
||||
switch (state) {
|
||||
case Old::Disconnected: return ConnectionState::Disconnected;
|
||||
case Old::Init: return ConnectionState::Initializing;
|
||||
@@ -37,7 +42,7 @@ namespace Void::TeamSpeak
|
||||
return ConnectionState::Disconnected;
|
||||
}
|
||||
|
||||
std::uint64_t number(const Echoion::Protocol::CommandParams& record,
|
||||
std::uint64_t number(const Void::TeamSpeak::Protocol::CommandParams& record,
|
||||
std::string_view key)
|
||||
{
|
||||
const auto iterator = record.find(std::string{key});
|
||||
@@ -49,7 +54,7 @@ namespace Void::TeamSpeak
|
||||
iterator->second.size() ? value : 0;
|
||||
}
|
||||
|
||||
std::string text(const Echoion::Protocol::CommandParams& record,
|
||||
std::string text(const Void::TeamSpeak::Protocol::CommandParams& record,
|
||||
std::string_view key)
|
||||
{
|
||||
const auto iterator = record.find(std::string{key});
|
||||
@@ -66,7 +71,7 @@ namespace Void::TeamSpeak
|
||||
{
|
||||
impl_->events = std::move(events);
|
||||
auto* impl = impl_.get();
|
||||
Echoion::Protocol::TsClientCallbacks callbacks;
|
||||
Void::TeamSpeak::Protocol::TsClientCallbacks callbacks;
|
||||
callbacks.onConnected = [impl] { if (impl->events.connected) impl->events.connected(); };
|
||||
callbacks.onDisconnected = [impl] { if (impl->events.disconnected) impl->events.disconnected(); };
|
||||
callbacks.onError = [impl](const std::string& message) {
|
||||
@@ -75,8 +80,66 @@ namespace Void::TeamSpeak
|
||||
callbacks.onDebug = [impl](const std::string& message) {
|
||||
if (impl->events.debug) impl->events.debug(message);
|
||||
};
|
||||
callbacks.onCommand = [impl](const Echoion::Protocol::ParsedCommand& command) {
|
||||
callbacks.onCommand = [impl](const Void::TeamSpeak::Protocol::ParsedCommand& command) {
|
||||
if (impl->events.command) impl->events.command(command.name, command.params);
|
||||
if (impl->events.commandBatch) {
|
||||
impl->events.commandBatch(CommandEvent{
|
||||
.name = command.name,
|
||||
.records = command.groups.empty()
|
||||
? std::vector<CommandResponse::Record>{command.params}
|
||||
: command.groups});
|
||||
}
|
||||
const auto& records = command.groups.empty()
|
||||
? std::vector<CommandResponse::Record>{command.params}
|
||||
: command.groups;
|
||||
for (const auto& record : records) {
|
||||
if (command.name == "notifycliententerview" &&
|
||||
impl->events.clientEntered) {
|
||||
impl->events.clientEntered(RemoteClient{
|
||||
.id = ClientId{static_cast<std::uint16_t>(number(record, "clid"))},
|
||||
.channel = ChannelId{number(record, "ctid")},
|
||||
.nickname = text(record, "client_nickname"),
|
||||
.uniqueId = text(record, "client_unique_identifier")});
|
||||
} else if (command.name == "notifyclientleftview" &&
|
||||
impl->events.clientLeft) {
|
||||
impl->events.clientLeft(ClientLeft{
|
||||
.id = ClientId{static_cast<std::uint16_t>(number(record, "clid"))},
|
||||
.reasonId = static_cast<int>(number(record, "reasonid")),
|
||||
.reasonMessage = text(record, "reasonmsg")});
|
||||
} else if (command.name == "notifyclientmoved" &&
|
||||
impl->events.clientMoved) {
|
||||
impl->events.clientMoved(ClientMoved{
|
||||
.id = ClientId{static_cast<std::uint16_t>(number(record, "clid"))},
|
||||
.channel = ChannelId{number(record, "ctid")}});
|
||||
} else if (command.name == "notifytextmessage" &&
|
||||
impl->events.textMessage) {
|
||||
impl->events.textMessage(TextMessage{
|
||||
.target = TextTarget{
|
||||
.kind = static_cast<TextTargetKind>(number(record, "targetmode")),
|
||||
.id = number(record, "target")},
|
||||
.invoker = ClientId{static_cast<std::uint16_t>(number(record, "invokerid"))},
|
||||
.invokerName = text(record, "invokername"),
|
||||
.message = text(record, "msg")});
|
||||
} else if (impl->events.channelChanged) {
|
||||
std::optional<ChannelChangeKind> kind;
|
||||
if (command.name == "notifychannelcreated") kind = ChannelChangeKind::Created;
|
||||
else if (command.name == "notifychanneledited") kind = ChannelChangeKind::Updated;
|
||||
else if (command.name == "notifychannelmoved") kind = ChannelChangeKind::Moved;
|
||||
else if (command.name == "notifychanneldeleted") kind = ChannelChangeKind::Deleted;
|
||||
if (kind) {
|
||||
const auto parent = number(record, "pid");
|
||||
impl->events.channelChanged(ChannelChanged{
|
||||
.kind = *kind,
|
||||
.channel = Channel{
|
||||
.id = ChannelId{number(record, "cid")},
|
||||
.parent = parent == 0 ? std::nullopt
|
||||
: std::optional{ChannelId{parent}},
|
||||
.name = text(record, "channel_name"),
|
||||
.passwordProtected = number(record,
|
||||
"channel_flag_password") != 0}});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
callbacks.onVoice = [impl](std::span<const std::uint8_t> voice) {
|
||||
if (impl->events.voice) impl->events.voice(voice);
|
||||
@@ -90,7 +153,7 @@ namespace Void::TeamSpeak
|
||||
return Void::Result::fail(Error{Error::Code::InvalidArgument,
|
||||
"host and identity are required"});
|
||||
}
|
||||
Echoion::Protocol::TsClientOptions old;
|
||||
Void::TeamSpeak::Protocol::TsClientOptions old;
|
||||
old.host = options.host;
|
||||
old.port = options.port;
|
||||
old.identity = options.identity.get();
|
||||
@@ -173,13 +236,46 @@ namespace Void::TeamSpeak
|
||||
return result;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::vector<ChannelGroup>, Error>
|
||||
Client::channelGroups(std::chrono::milliseconds timeout)
|
||||
{
|
||||
auto response = request("channelgrouplist", timeout);
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
std::vector<ChannelGroup> result;
|
||||
result.reserve(response->records.size());
|
||||
for (const auto& record : response->records) {
|
||||
result.push_back(ChannelGroup{
|
||||
.id = ChannelGroupId{number(record, "cgid")},
|
||||
.name = text(record, "name"),
|
||||
.type = static_cast<int>(number(record, "type"))});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::vector<Permission>, Error>
|
||||
Client::permissions(std::chrono::milliseconds timeout)
|
||||
{
|
||||
auto response = request("permissionlist", timeout);
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
std::vector<Permission> result;
|
||||
result.reserve(response->records.size());
|
||||
for (const auto& record : response->records) {
|
||||
result.push_back(Permission{
|
||||
.id = PermissionId{static_cast<std::uint32_t>(
|
||||
number(record, "permid"))},
|
||||
.name = text(record, "permname"),
|
||||
.description = text(record, "permdesc")});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error>
|
||||
Client::addToServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
{
|
||||
Echoion::Protocol::CommandParams params{
|
||||
Void::TeamSpeak::Protocol::CommandParams params{
|
||||
{"sgid", std::to_string(group.value)},
|
||||
{"cldbid", std::to_string(client.value)}};
|
||||
auto response = request(Echoion::Protocol::buildCommand(
|
||||
auto response = request(Void::TeamSpeak::Protocol::buildCommand(
|
||||
"servergroupaddclient", params));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
@@ -188,24 +284,35 @@ Client::addToServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
Void::Result::Result<void, Error>
|
||||
Client::removeFromServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
{
|
||||
Echoion::Protocol::CommandParams params{
|
||||
Void::TeamSpeak::Protocol::CommandParams params{
|
||||
{"sgid", std::to_string(group.value)},
|
||||
{"cldbid", std::to_string(client.value)}};
|
||||
auto response = request(Echoion::Protocol::buildCommand(
|
||||
auto response = request(Void::TeamSpeak::Protocol::buildCommand(
|
||||
"servergroupdelclient", params));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error> Client::setChannelGroup(
|
||||
ChannelGroupId group, ChannelId channel, ClientDatabaseId client)
|
||||
{
|
||||
CommandFields fields{{"cgid", std::to_string(group.value)},
|
||||
{"cid", std::to_string(channel.value)},
|
||||
{"cldbid", std::to_string(client.value)}};
|
||||
auto response = request(buildCommand("setclientchannelgroup", fields));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error>
|
||||
Client::sendText(TextTarget target, std::string_view message)
|
||||
{
|
||||
Echoion::Protocol::CommandParams params;
|
||||
Void::TeamSpeak::Protocol::CommandParams params;
|
||||
params["targetmode"] = std::to_string(static_cast<int>(target.kind));
|
||||
if (target.kind != TextTargetKind::Server)
|
||||
params["target"] = std::to_string(target.id);
|
||||
params["msg"] = std::string{message};
|
||||
auto response = request(Echoion::Protocol::buildCommand(
|
||||
auto response = request(Void::TeamSpeak::Protocol::buildCommand(
|
||||
"sendtextmessage", params));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
@@ -214,10 +321,10 @@ Client::removeFromServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
Void::Result::Result<void, Error>
|
||||
Client::move(ClientId client, ChannelId channel)
|
||||
{
|
||||
Echoion::Protocol::CommandParams params{
|
||||
Void::TeamSpeak::Protocol::CommandParams params{
|
||||
{"clid", std::to_string(client.value)},
|
||||
{"cid", std::to_string(channel.value)}};
|
||||
auto response = request(Echoion::Protocol::buildCommand("clientmove", params));
|
||||
auto response = request(Void::TeamSpeak::Protocol::buildCommand("clientmove", params));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
}
|
||||
@@ -225,10 +332,10 @@ Client::removeFromServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
Void::Result::Result<void, Error>
|
||||
Client::kick(ClientId client, std::string_view reason)
|
||||
{
|
||||
Echoion::Protocol::CommandParams params{
|
||||
Void::TeamSpeak::Protocol::CommandParams params{
|
||||
{"clid", std::to_string(client.value)}, {"reasonid", "5"},
|
||||
{"reasonmsg", std::string{reason}}};
|
||||
auto response = request(Echoion::Protocol::buildCommand("clientkick", params));
|
||||
auto response = request(Void::TeamSpeak::Protocol::buildCommand("clientkick", params));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
}
|
||||
@@ -244,6 +351,34 @@ Client::removeFromServerGroup(ServerGroupId group, ClientDatabaseId client)
|
||||
return destination;
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error> Client::upload(
|
||||
const std::filesystem::path& source, std::string_view remotePath,
|
||||
ChannelId channel, std::string_view password, bool overwrite,
|
||||
std::chrono::milliseconds timeout)
|
||||
{
|
||||
if (remotePath.empty() || !std::filesystem::is_regular_file(source)) {
|
||||
return Void::Result::fail(Error{Error::Code::InvalidArgument,
|
||||
"upload source and remote path are required"});
|
||||
}
|
||||
auto result = impl_->client.uploadFile(source.string(),
|
||||
std::string{remotePath}, channel.value, std::string{password},
|
||||
overwrite, timeout);
|
||||
if (!result.ok()) return Void::Result::fail(protocolError(result.errorMessage));
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error> Client::deleteFile(
|
||||
std::string_view remotePath, ChannelId channel, std::string_view password)
|
||||
{
|
||||
if (remotePath.empty()) return Void::Result::fail(
|
||||
Error{Error::Code::InvalidArgument, "remote path is required"});
|
||||
CommandFields fields{{"cid", std::to_string(channel.value)},
|
||||
{"cpw", std::string{password}}, {"name", std::string{remotePath}}};
|
||||
auto response = request(buildCommand("ftdeletefile", fields));
|
||||
if (!response) return Void::Result::fail(response.error());
|
||||
return {};
|
||||
}
|
||||
|
||||
Void::Result::Result<void, Error>
|
||||
Client::sendVoice(std::span<const std::uint8_t> frame)
|
||||
{
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#include "echoion/protocol/Command.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Command.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
|
||||
std::string tsEscape(const std::string& str)
|
||||
@@ -181,4 +181,4 @@ namespace Echoion::Protocol
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
#include "echoion/protocol/Crypto.hpp"
|
||||
#include "echoion/protocol/Util.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Crypto.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Util.hpp"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/sha.h>
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Echoion::Protocol::Crypto
|
||||
namespace Void::TeamSpeak::Protocol::Crypto
|
||||
{
|
||||
namespace
|
||||
{
|
||||
@@ -250,4 +250,4 @@ namespace Echoion::Protocol::Crypto
|
||||
return Util::base64Encode(ByteView(digest.data(), digest.size()));
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol::Crypto
|
||||
} // namespace Void::TeamSpeak::Protocol::Crypto
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
#include "echoion/protocol/Identity.hpp"
|
||||
#include "echoion/protocol/Crypto.hpp"
|
||||
#include "echoion/protocol/Util.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Identity.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Crypto.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Util.hpp"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/core_names.h>
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
namespace
|
||||
{
|
||||
@@ -672,4 +672,4 @@ namespace Echoion::Protocol
|
||||
return id;
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
#include "echoion/protocol/License.hpp"
|
||||
#include "echoion/protocol/Crypto.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/License.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Crypto.hpp"
|
||||
|
||||
#include <sodium.h>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
namespace
|
||||
{
|
||||
@@ -168,4 +168,4 @@ namespace Echoion::Protocol
|
||||
return Crypto::sha512(ByteView(mul.data(), mul.size()));
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#include "echoion/protocol/QuickLz.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/QuickLz.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
namespace
|
||||
{
|
||||
@@ -155,4 +155,4 @@ namespace Echoion::Protocol
|
||||
return dest;
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
+95
-8
@@ -1,8 +1,8 @@
|
||||
#include "echoion/protocol/TsClient.hpp"
|
||||
#include "echoion/protocol/Crypto.hpp"
|
||||
#include "echoion/protocol/License.hpp"
|
||||
#include "echoion/protocol/QuickLz.hpp"
|
||||
#include "echoion/protocol/Util.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/TsClient.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Crypto.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/License.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/QuickLz.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Util.hpp"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/rand.h>
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Echoion::Protocol
|
||||
namespace Void::TeamSpeak::Protocol
|
||||
{
|
||||
namespace
|
||||
{
|
||||
@@ -344,7 +344,7 @@ namespace Echoion::Protocol
|
||||
// response-bearing command in flight so those records remain unambiguous.
|
||||
std::unique_lock<std::mutex> serialLock(requestSerialMutex_);
|
||||
auto pending = std::make_shared<PendingRequest>();
|
||||
pending->returnCode = "echoion-" + std::to_string(++requestId_);
|
||||
pending->returnCode = "voidteamspeak-" + std::to_string(++requestId_);
|
||||
{
|
||||
// Keep queue insertion and wire send in the same order when callers
|
||||
// issue requests concurrently.
|
||||
@@ -500,6 +500,93 @@ namespace Echoion::Protocol
|
||||
return {};
|
||||
}
|
||||
|
||||
CommandResult TsClient::uploadFile(
|
||||
const std::string& source, const std::string& remotePath,
|
||||
uint64_t channelId, const std::string& channelPassword, bool overwrite,
|
||||
std::chrono::milliseconds timeout)
|
||||
{
|
||||
std::ifstream input(source, std::ios::binary);
|
||||
if (!input) return {{}, -1, "upload source is not readable"};
|
||||
std::error_code sizeError;
|
||||
const auto size = std::filesystem::file_size(source, sizeError);
|
||||
if (sizeError) return {{}, -1, "cannot determine upload size"};
|
||||
|
||||
CommandParams parameters{{"cid", std::to_string(channelId)},
|
||||
{"cpw", channelPassword}, {"name", remotePath},
|
||||
{"clientftfid", std::to_string(++transferId_)},
|
||||
{"size", std::to_string(size)}, {"overwrite", overwrite ? "1" : "0"},
|
||||
{"resume", "0"}};
|
||||
auto result = requestCommand(buildCommand("ftinitupload", parameters), timeout);
|
||||
if (!result.ok() || result.records.empty()) {
|
||||
if (result.ok()) return {{}, -1,
|
||||
"file transfer returned no connection data"};
|
||||
return result;
|
||||
}
|
||||
const auto& record = result.records.front();
|
||||
auto value = [&record](std::string_view name) {
|
||||
const auto entry = record.find(std::string{name});
|
||||
return entry == record.end() ? std::string{} : entry->second;
|
||||
};
|
||||
const auto transferKey = value("ftkey");
|
||||
const auto port = value("port");
|
||||
if (transferKey.empty() || port.empty())
|
||||
return {{}, -1, "file transfer response is incomplete"};
|
||||
|
||||
addrinfo hints{};
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
addrinfo* addresses = nullptr;
|
||||
if (getaddrinfo(opts_.host.c_str(), port.c_str(), &hints, &addresses) != 0 ||
|
||||
!addresses) return {{}, -1, "cannot resolve file-transfer endpoint"};
|
||||
int socket = -1;
|
||||
for (auto* address = addresses; address; address = address->ai_next) {
|
||||
socket = ::socket(address->ai_family, address->ai_socktype,
|
||||
address->ai_protocol);
|
||||
if (socket >= 0 && ::connect(socket, address->ai_addr,
|
||||
address->ai_addrlen) == 0) break;
|
||||
if (socket >= 0) ::close(socket);
|
||||
socket = -1;
|
||||
}
|
||||
freeaddrinfo(addresses);
|
||||
if (socket < 0) return {{}, -1,
|
||||
"cannot connect to file-transfer endpoint"};
|
||||
|
||||
timeval socketTimeout{};
|
||||
socketTimeout.tv_sec = static_cast<long>(
|
||||
std::max<int64_t>(1, timeout.count() / 1000));
|
||||
setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &socketTimeout,
|
||||
sizeof(socketTimeout));
|
||||
auto sendAll = [socket](const char* data, std::size_t length) {
|
||||
std::size_t sent = 0;
|
||||
while (sent < length) {
|
||||
const auto count = ::send(socket, data + sent, length - sent, 0);
|
||||
if (count <= 0) return false;
|
||||
sent += static_cast<std::size_t>(count);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (!sendAll(transferKey.data(), transferKey.size())) {
|
||||
::close(socket);
|
||||
return {{}, -1, "cannot start file upload"};
|
||||
}
|
||||
std::array<char, 81920> buffer{};
|
||||
uint64_t uploaded = 0;
|
||||
while (input) {
|
||||
input.read(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
||||
const auto count = input.gcount();
|
||||
if (count > 0 && !sendAll(buffer.data(), static_cast<std::size_t>(count))) {
|
||||
::close(socket);
|
||||
return {{}, -1, "file upload was interrupted"};
|
||||
}
|
||||
uploaded += static_cast<uint64_t>(count);
|
||||
}
|
||||
::shutdown(socket, SHUT_WR);
|
||||
::close(socket);
|
||||
if (!input.eof() || uploaded != size)
|
||||
return {{}, -1, "file upload size mismatch"};
|
||||
return {};
|
||||
}
|
||||
|
||||
void TsClient::sendVoice(std::span<const uint8_t> opus)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mu_);
|
||||
@@ -1183,4 +1270,4 @@ namespace Echoion::Protocol
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol
|
||||
} // namespace Void::TeamSpeak::Protocol
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#include "echoion/protocol/Util.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Util.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Echoion::Protocol::Util
|
||||
namespace Void::TeamSpeak::Protocol::Util
|
||||
{
|
||||
namespace
|
||||
{
|
||||
@@ -113,4 +113,4 @@ namespace Echoion::Protocol::Util
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace Echoion::Protocol::Util
|
||||
} // namespace Void::TeamSpeak::Protocol::Util
|
||||
@@ -1,12 +1,12 @@
|
||||
# Unit tests for EchoionProtocol. Uses a tiny header-only harness (check.hpp),
|
||||
# Unit tests for VoidTeamspeak. Uses a tiny header-only harness (check.hpp),
|
||||
# no external test framework required.
|
||||
|
||||
file(GLOB ECHOIONPROTOCOL_TEST_SOURCES CONFIGURE_DEPENDS
|
||||
file(GLOB VOID_TEAMSPEAK_TEST_SOURCES CONFIGURE_DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp")
|
||||
|
||||
add_executable(echoion_protocol_tests ${ECHOIONPROTOCOL_TEST_SOURCES})
|
||||
target_link_libraries(echoion_protocol_tests PRIVATE Void::TeamSpeak)
|
||||
target_include_directories(echoion_protocol_tests PRIVATE
|
||||
add_executable(void_teamspeak_tests ${VOID_TEAMSPEAK_TEST_SOURCES})
|
||||
target_link_libraries(void_teamspeak_tests PRIVATE Void::TeamSpeak)
|
||||
target_include_directories(void_teamspeak_tests PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
add_test(NAME echoion_protocol_tests COMMAND echoion_protocol_tests)
|
||||
add_test(NAME void_teamspeak_tests COMMAND void_teamspeak_tests)
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "check.hpp"
|
||||
#include "echoion/protocol/Command.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Command.hpp"
|
||||
|
||||
using namespace Echoion::Protocol;
|
||||
using namespace Void::TeamSpeak::Protocol;
|
||||
|
||||
TEST_CASE(escape_roundtrip)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "check.hpp"
|
||||
#include "echoion/protocol/Crypto.hpp"
|
||||
#include "echoion/protocol/Util.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Crypto.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Util.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace Echoion::Protocol;
|
||||
using namespace Void::TeamSpeak::Protocol;
|
||||
using Crypto::ByteView;
|
||||
|
||||
namespace
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "check.hpp"
|
||||
#include "echoion/protocol/Crypto.hpp"
|
||||
#include "echoion/protocol/Identity.hpp"
|
||||
#include "echoion/protocol/Util.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Crypto.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Identity.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/Util.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
using namespace Echoion::Protocol;
|
||||
using namespace Void::TeamSpeak::Protocol;
|
||||
|
||||
TEST_CASE(identity_generate_uid_and_level)
|
||||
{
|
||||
@@ -44,7 +44,7 @@ TEST_CASE(identity_sign_verifiable_length)
|
||||
TEST_CASE(identity_save_load_roundtrip)
|
||||
{
|
||||
auto id = Identity::generate(0);
|
||||
std::string path = "/tmp/echoion_identity_test.txt";
|
||||
std::string path = "/tmp/void_teamspeak_identity_test.txt";
|
||||
id.save(path);
|
||||
auto loaded = Identity::load(path);
|
||||
CHECK_EQ(loaded.publicKeyString(), id.publicKeyString());
|
||||
@@ -84,8 +84,8 @@ namespace
|
||||
|
||||
TEST_CASE(identity_import_teamspeak_ini)
|
||||
{
|
||||
const std::string exportPath = "/tmp/echoion_ts_identity.ini";
|
||||
const std::string nativePath = "/tmp/echoion_imported_identity.txt";
|
||||
const std::string exportPath = "/tmp/void_teamspeak_identity.ini";
|
||||
const std::string nativePath = "/tmp/void_teamspeak_imported_identity.txt";
|
||||
{
|
||||
std::ofstream output(exportPath);
|
||||
output << "[Identity]\nidentity=\"" << teamSpeakExportForScalarOne(42)
|
||||
@@ -109,7 +109,7 @@ TEST_CASE(identity_import_teamspeak_ini)
|
||||
|
||||
TEST_CASE(identity_import_rejects_malformed_export)
|
||||
{
|
||||
const std::string path = "/tmp/echoion_bad_identity.ini";
|
||||
const std::string path = "/tmp/void_teamspeak_bad_identity.ini";
|
||||
{
|
||||
std::ofstream output(path);
|
||||
output << "[Identity]\nidentity=not-a-private-key\n";
|
||||
|
||||
+30
-25
@@ -2,36 +2,41 @@
|
||||
|
||||
#include <Void/TeamSpeak/TeamSpeak.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
using namespace Void::TeamSpeak;
|
||||
|
||||
TEST_CASE(modern_library_creates_independent_clients)
|
||||
static_assert(!std::is_copy_constructible_v<Client>);
|
||||
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(std::declval<Client&>().deleteFile("x")),
|
||||
Void::Result::Result<void, Error>>);
|
||||
|
||||
TEST_CASE(modern_build_command_escapes_fields)
|
||||
{
|
||||
ClientLibrary library;
|
||||
auto first = library.createClient();
|
||||
auto second = library.createClient();
|
||||
CHECK(first != nullptr);
|
||||
CHECK(second != nullptr);
|
||||
CHECK(first.get() != second.get());
|
||||
CHECK_EQ(first->state(), ConnectionState::Disconnected);
|
||||
CHECK_EQ(second->state(), ConnectionState::Disconnected);
|
||||
const auto command = buildCommand("sendtextmessage", {
|
||||
{"msg", "hello world|all"}, {"target", "7"}});
|
||||
CHECK_EQ(command,
|
||||
std::string("sendtextmessage msg=hello\\sworld\\pall target=7"));
|
||||
}
|
||||
|
||||
TEST_CASE(strong_ids_do_not_erase_target_types)
|
||||
TEST_CASE(strong_ids_do_not_implicitly_convert)
|
||||
{
|
||||
WhisperTargets targets{
|
||||
.channels = {ChannelId{42}},
|
||||
.clients = {ClientId{7}, ClientId{8}},
|
||||
};
|
||||
const ClientId client{42};
|
||||
const ChannelId channel{42};
|
||||
CHECK(client.value == 42);
|
||||
CHECK(channel.value == 42);
|
||||
CHECK(static_cast<bool>(client));
|
||||
CHECK(static_cast<bool>(channel));
|
||||
}
|
||||
|
||||
TEST_CASE(whisper_targets_report_empty_state)
|
||||
{
|
||||
WhisperTargets targets;
|
||||
CHECK(targets.empty());
|
||||
targets.clients.push_back(ClientId{7});
|
||||
CHECK(!targets.empty());
|
||||
CHECK_EQ(targets.channels.front().value, std::uint64_t{42});
|
||||
CHECK_EQ(targets.clients.size(), std::size_t{2});
|
||||
CHECK(ClientId{7} != ClientId{8});
|
||||
}
|
||||
|
||||
TEST_CASE(connect_options_are_validated_before_network_io)
|
||||
{
|
||||
Client client;
|
||||
auto result = client.connect({});
|
||||
CHECK(!result.has_value());
|
||||
CHECK_EQ(result.error().code, Error::Code::InvalidArgument);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "check.hpp"
|
||||
#include "echoion/protocol/QuickLz.hpp"
|
||||
#include "Void/TeamSpeak/Protocol/QuickLz.hpp"
|
||||
|
||||
using namespace Echoion::Protocol;
|
||||
using namespace Void::TeamSpeak::Protocol;
|
||||
|
||||
// QuickLZ level-1 "stored" (uncompressed) block: header byte with level=1
|
||||
// (bits 2-3 = 01 -> 0x04), compressed bit (bit0) = 0, short size form
|
||||
|
||||
Reference in new issue
Block a user