1 parent
c1a11ffe29
commit
09a3a4fee3
6 files changed
+177
-29
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ 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 | common client/channel/text events typed; batched command fallback |
|
||||
| Typed server/channel/client notifications | Implemented | client lifecycle/update/talk, channel, 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 |
|
||||
|
||||
@@ -48,8 +48,16 @@ namespace Void::TeamSpeak
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
@@ -57,6 +58,23 @@ namespace Void::TeamSpeak
|
||||
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;
|
||||
};
|
||||
|
||||
struct TalkStatusChanged {
|
||||
ClientId id;
|
||||
bool talking{false};
|
||||
bool whisper{false};
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
ChannelId id;
|
||||
std::optional<ChannelId> parent;
|
||||
@@ -101,6 +119,33 @@ namespace Void::TeamSpeak
|
||||
Channel channel;
|
||||
};
|
||||
|
||||
struct ServerUpdated {
|
||||
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;
|
||||
};
|
||||
|
||||
struct ChannelGroupMembershipChanged {
|
||||
ChannelGroupId group;
|
||||
ChannelId channel;
|
||||
ClientDatabaseId client;
|
||||
ClientId invoker;
|
||||
};
|
||||
|
||||
struct FileTransferStatus {
|
||||
std::uint64_t id{};
|
||||
int status{};
|
||||
std::string message;
|
||||
};
|
||||
|
||||
struct Error {
|
||||
enum class Code {
|
||||
InvalidArgument,
|
||||
|
||||
+109
-23
@@ -5,6 +5,7 @@
|
||||
#include <Void/TeamSpeak/Protocol/Command.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <atomic>
|
||||
#include <charconv>
|
||||
#include <system_error>
|
||||
#include <utility>
|
||||
@@ -18,8 +19,10 @@ namespace Void::TeamSpeak
|
||||
|
||||
class Client::Impl {
|
||||
public:
|
||||
Void::TeamSpeak::Protocol::TsClient client;
|
||||
Events events;
|
||||
std::atomic<std::shared_ptr<const Events>> events{
|
||||
std::make_shared<const Events>()};
|
||||
std::atomic<bool> callbacksInstalled{false};
|
||||
Void::TeamSpeak::Protocol::TsClient client;
|
||||
};
|
||||
|
||||
namespace
|
||||
@@ -60,30 +63,60 @@ namespace Void::TeamSpeak
|
||||
const auto iterator = record.find(std::string{key});
|
||||
return iterator == record.end() ? std::string{} : iterator->second;
|
||||
}
|
||||
|
||||
std::optional<std::string> optionalText(
|
||||
const Void::TeamSpeak::Protocol::CommandParams& record,
|
||||
std::string_view key)
|
||||
{
|
||||
const auto iterator = record.find(std::string{key});
|
||||
if (iterator == record.end()) return std::nullopt;
|
||||
return iterator->second;
|
||||
}
|
||||
|
||||
std::optional<bool> optionalBool(
|
||||
const Void::TeamSpeak::Protocol::CommandParams& record,
|
||||
std::string_view key)
|
||||
{
|
||||
if (!record.contains(std::string{key})) return std::nullopt;
|
||||
return number(record, key) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
Client::Client() : impl_(std::make_unique<Impl>()) {}
|
||||
Client::Client() : impl_(std::make_unique<Impl>()) { setEvents({}); }
|
||||
Client::~Client() = default;
|
||||
Client::Client(Client&&) noexcept = default;
|
||||
Client& Client::operator=(Client&&) noexcept = default;
|
||||
|
||||
void Client::setEvents(Events events)
|
||||
void Client::setEvents(Events handlers)
|
||||
{
|
||||
impl_->events = std::move(events);
|
||||
impl_->events.store(std::make_shared<const Events>(std::move(handlers)),
|
||||
std::memory_order_release);
|
||||
if (impl_->callbacksInstalled.exchange(true, std::memory_order_acq_rel)) {
|
||||
return;
|
||||
}
|
||||
auto* impl = impl_.get();
|
||||
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.onConnected = [impl] {
|
||||
auto events = impl->events.load(std::memory_order_acquire);
|
||||
if (events->connected) events->connected();
|
||||
};
|
||||
callbacks.onDisconnected = [impl] {
|
||||
auto events = impl->events.load(std::memory_order_acquire);
|
||||
if (events->disconnected) events->disconnected();
|
||||
};
|
||||
callbacks.onError = [impl](const std::string& message) {
|
||||
if (impl->events.error) impl->events.error(protocolError(message));
|
||||
auto events = impl->events.load(std::memory_order_acquire);
|
||||
if (events->error) events->error(protocolError(message));
|
||||
};
|
||||
callbacks.onDebug = [impl](const std::string& message) {
|
||||
if (impl->events.debug) impl->events.debug(message);
|
||||
auto events = impl->events.load(std::memory_order_acquire);
|
||||
if (events->debug) events->debug(message);
|
||||
};
|
||||
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{
|
||||
auto events = impl->events.load(std::memory_order_acquire);
|
||||
if (events->command) events->command(command.name, command.params);
|
||||
if (events->commandBatch) {
|
||||
events->commandBatch(CommandEvent{
|
||||
.name = command.name,
|
||||
.records = command.groups.empty()
|
||||
? std::vector<CommandResponse::Record>{command.params}
|
||||
@@ -94,33 +127,85 @@ namespace Void::TeamSpeak
|
||||
: command.groups;
|
||||
for (const auto& record : records) {
|
||||
if (command.name == "notifycliententerview" &&
|
||||
impl->events.clientEntered) {
|
||||
impl->events.clientEntered(RemoteClient{
|
||||
events->clientEntered) {
|
||||
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{
|
||||
events->clientLeft) {
|
||||
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{
|
||||
events->clientMoved) {
|
||||
events->clientMoved(ClientMoved{
|
||||
.id = ClientId{static_cast<std::uint16_t>(number(record, "clid"))},
|
||||
.channel = ChannelId{number(record, "ctid")}});
|
||||
} else if (command.name == "notifyclientupdated" &&
|
||||
events->clientUpdated) {
|
||||
events->clientUpdated(ClientUpdated{
|
||||
.id = ClientId{static_cast<std::uint16_t>(number(record, "clid"))},
|
||||
.nickname = optionalText(record, "client_nickname"),
|
||||
.uniqueId = optionalText(record, "client_unique_identifier"),
|
||||
.inputMuted = optionalBool(record, "client_input_muted"),
|
||||
.outputMuted = optionalBool(record, "client_output_muted"),
|
||||
.away = optionalBool(record, "client_away"),
|
||||
.recording = optionalBool(record, "client_is_recording"),
|
||||
.properties = record});
|
||||
} else if (command.name == "notifytalkstatuschange" &&
|
||||
events->talkStatusChanged) {
|
||||
events->talkStatusChanged(TalkStatusChanged{
|
||||
.id = ClientId{static_cast<std::uint16_t>(number(record, "clid"))},
|
||||
.talking = number(record, "status") != 0,
|
||||
.whisper = number(record, "isreceivedwhisper") != 0});
|
||||
} else if (command.name == "notifytextmessage" &&
|
||||
impl->events.textMessage) {
|
||||
impl->events.textMessage(TextMessage{
|
||||
events->textMessage) {
|
||||
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) {
|
||||
} else if ((command.name == "notifyserveredited" ||
|
||||
command.name == "notifyserverupdated") &&
|
||||
events->serverUpdated) {
|
||||
events->serverUpdated(ServerUpdated{
|
||||
.name = optionalText(record, "virtualserver_name"),
|
||||
.welcomeMessage = optionalText(record,
|
||||
"virtualserver_welcomemessage"),
|
||||
.invoker = ClientId{static_cast<std::uint16_t>(number(record,
|
||||
"invokerid"))},
|
||||
.properties = record});
|
||||
} else if ((command.name == "notifyservergroupclientadded" ||
|
||||
command.name == "notifyservergroupclientdeleted") &&
|
||||
events->serverGroupMembershipChanged) {
|
||||
events->serverGroupMembershipChanged(
|
||||
ServerGroupMembershipChanged{
|
||||
.added = command.name == "notifyservergroupclientadded",
|
||||
.group = ServerGroupId{number(record, "sgid")},
|
||||
.client = ClientDatabaseId{number(record, "cldbid")},
|
||||
.invoker = ClientId{static_cast<std::uint16_t>(number(record,
|
||||
"invokerid"))}});
|
||||
} else if (command.name == "notifyclientchannelgroupchanged" &&
|
||||
events->channelGroupMembershipChanged) {
|
||||
events->channelGroupMembershipChanged(
|
||||
ChannelGroupMembershipChanged{
|
||||
.group = ChannelGroupId{number(record, "cgid")},
|
||||
.channel = ChannelId{number(record, "cid")},
|
||||
.client = ClientDatabaseId{number(record, "cldbid")},
|
||||
.invoker = ClientId{static_cast<std::uint16_t>(number(record,
|
||||
"invokerid"))}});
|
||||
} else if (command.name == "notifyfiletransferstatus" &&
|
||||
events->fileTransferStatus) {
|
||||
events->fileTransferStatus(FileTransferStatus{
|
||||
.id = number(record, "ftid"),
|
||||
.status = static_cast<int>(number(record, "status")),
|
||||
.message = text(record, "msg")});
|
||||
} else if (events->channelChanged) {
|
||||
std::optional<ChannelChangeKind> kind;
|
||||
if (command.name == "notifychannelcreated") kind = ChannelChangeKind::Created;
|
||||
else if (command.name == "notifychanneledited") kind = ChannelChangeKind::Updated;
|
||||
@@ -128,7 +213,7 @@ namespace Void::TeamSpeak
|
||||
else if (command.name == "notifychanneldeleted") kind = ChannelChangeKind::Deleted;
|
||||
if (kind) {
|
||||
const auto parent = number(record, "pid");
|
||||
impl->events.channelChanged(ChannelChanged{
|
||||
events->channelChanged(ChannelChanged{
|
||||
.kind = *kind,
|
||||
.channel = Channel{
|
||||
.id = ChannelId{number(record, "cid")},
|
||||
@@ -142,7 +227,8 @@ namespace Void::TeamSpeak
|
||||
}
|
||||
};
|
||||
callbacks.onVoice = [impl](std::span<const std::uint8_t> voice) {
|
||||
if (impl->events.voice) impl->events.voice(voice);
|
||||
auto events = impl->events.load(std::memory_order_acquire);
|
||||
if (events->voice) events->voice(voice);
|
||||
};
|
||||
impl_->client.setCallbacks(std::move(callbacks));
|
||||
}
|
||||
|
||||
+6
-5
@@ -203,7 +203,7 @@ namespace Void::TeamSpeak::Protocol
|
||||
std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
buf[5] = (ts >> 24) & 0xff;
|
||||
buf[5] = static_cast<std::uint8_t>((ts >> 24) & 0xffU);
|
||||
buf[6] = (ts >> 16) & 0xff;
|
||||
buf[7] = (ts >> 8) & 0xff;
|
||||
buf[8] = ts & 0xff;
|
||||
@@ -827,10 +827,11 @@ namespace Void::TeamSpeak::Protocol
|
||||
init4[4] = 0x04;
|
||||
std::memcpy(init4.data() + 5, x.data(), 64);
|
||||
std::memcpy(init4.data() + 69, n.data(), 64);
|
||||
init4[133] = (level >> 24) & 0xff;
|
||||
init4[134] = (level >> 16) & 0xff;
|
||||
init4[135] = (level >> 8) & 0xff;
|
||||
init4[136] = level & 0xff;
|
||||
const auto unsignedLevel = static_cast<std::uint32_t>(level);
|
||||
init4[133] = static_cast<std::uint8_t>((unsignedLevel >> 24) & 0xffU);
|
||||
init4[134] = static_cast<std::uint8_t>((unsignedLevel >> 16) & 0xffU);
|
||||
init4[135] = static_cast<std::uint8_t>((unsignedLevel >> 8) & 0xffU);
|
||||
init4[136] = static_cast<std::uint8_t>(unsignedLevel & 0xffU);
|
||||
std::memcpy(init4.data() + 137, serverData.data(), 100);
|
||||
std::memcpy(init4.data() + 237, y.data(), 64);
|
||||
std::memcpy(init4.data() + 301, textBytes.data(), textBytes.size());
|
||||
|
||||
@@ -12,6 +12,14 @@ 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(Events{}.clientUpdated),
|
||||
std::function<void(const ClientUpdated&)>>);
|
||||
static_assert(std::is_same_v<decltype(Events{}.talkStatusChanged),
|
||||
std::function<void(const TalkStatusChanged&)>>);
|
||||
static_assert(std::is_same_v<decltype(Events{}.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>>);
|
||||
|
||||
|
||||
Reference in new issue
Block a user