1 parent
6dddf513b3
commit
a7ffe73a6c
14 files changed
+700
-114
No files matched your search
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Functional/Result.hpp>
|
||||
#include <Void/TeamSpeak/Identity.hpp>
|
||||
#include <Void/TeamSpeak/Types.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
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 = std::map<std::string, std::string>;
|
||||
std::vector<Record> records;
|
||||
};
|
||||
|
||||
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(std::span<const std::uint8_t>)> voice;
|
||||
};
|
||||
|
||||
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<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(
|
||||
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>
|
||||
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>
|
||||
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_;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <echoion/protocol/Identity.hpp>
|
||||
|
||||
namespace Void::TeamSpeak
|
||||
{
|
||||
// Modern public name; the implementation remains source-compatible during
|
||||
// the extraction release.
|
||||
using Identity = Echoion::Protocol::Identity;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/TeamSpeak/Client.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace Void::TeamSpeak
|
||||
{
|
||||
/// Process-level entry point corresponding to the original Client SDK
|
||||
/// library lifecycle. It is intentionally cheap and RAII-managed: clients
|
||||
/// own their actual network and callback resources.
|
||||
class ClientLibrary final
|
||||
{
|
||||
public:
|
||||
static constexpr std::string_view version() noexcept { return "0.1.0"; }
|
||||
[[nodiscard]] std::unique_ptr<Client> createClient() const
|
||||
{
|
||||
return std::make_unique<Client>();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/TeamSpeak/Client.hpp>
|
||||
#include <Void/TeamSpeak/Identity.hpp>
|
||||
#include <Void/TeamSpeak/Library.hpp>
|
||||
#include <Void/TeamSpeak/Types.hpp>
|
||||
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#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;
|
||||
};
|
||||
|
||||
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 ServerGroupId = Id<struct ServerGroupIdTag, std::uint64_t>;
|
||||
using ChannelGroupId = Id<struct ChannelGroupIdTag, std::uint64_t>;
|
||||
using PermissionId = Id<struct PermissionIdTag, std::uint32_t>;
|
||||
|
||||
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 RemoteClient {
|
||||
ClientId id;
|
||||
ChannelId channel;
|
||||
std::string nickname;
|
||||
std::string uniqueId;
|
||||
};
|
||||
|
||||
struct Channel {
|
||||
ChannelId id;
|
||||
std::optional<ChannelId> parent;
|
||||
std::string name;
|
||||
bool passwordProtected{false};
|
||||
};
|
||||
|
||||
struct ServerGroup {
|
||||
ServerGroupId id;
|
||||
std::string name;
|
||||
int type{};
|
||||
};
|
||||
|
||||
enum class TextTargetKind { Client = 1, Channel = 2, Server = 3 };
|
||||
struct TextTarget {
|
||||
TextTargetKind kind{TextTargetKind::Client};
|
||||
std::uint64_t id{};
|
||||
};
|
||||
|
||||
struct Error {
|
||||
enum class Code {
|
||||
InvalidArgument,
|
||||
NotConnected,
|
||||
Timeout,
|
||||
Protocol,
|
||||
Io,
|
||||
NotSupported,
|
||||
} code{Code::Protocol};
|
||||
std::string message;
|
||||
};
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "echoion/protocol/Command.hpp"
|
||||
#include "echoion/protocol/Identity.hpp"
|
||||
#include <Void/Net/Socket.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
@@ -173,7 +174,7 @@ namespace Echoion::Protocol
|
||||
TsClientOptions opts_;
|
||||
TsClientCallbacks cb_;
|
||||
|
||||
int sock_ = -1;
|
||||
Void::Net::UdpSocket socket_;
|
||||
std::atomic<ClientState> state_{ClientState::Disconnected};
|
||||
std::atomic<uint16_t> clientId_{0};
|
||||
|
||||
|
||||
Reference in new issue
Block a user