Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-15 19:49:57 +03:00
1 parent 01362d2e51
commit 39aff68d8d
29 files changed
+2061 -1818

No files matched your search

+5
View File
@@ -120,6 +120,9 @@ namespace Echoion::Core
getCommand(std::string_view name) const;
[[nodiscard]] std::vector<std::pair<std::string, CommandPtr>>
getAllCommands() const;
[[nodiscard]] bool registerExternalCommand(
std::string owner, std::string primaryName, CommandPtr command);
void unregisterExternalCommands(std::string_view owner);
// Get commands visible to a specific client (for help)
[[nodiscard]] std::vector<std::pair<std::string, CommandPtr>>
@@ -202,6 +205,8 @@ namespace Echoion::Core
// List for generating help: {"play", PlayCommand}
std::vector<CommandEntry> uniqueCommands_;
std::map<std::string, std::vector<CommandPtr>, std::less<>>
externalCommands_;
mutable std::mutex mutex_;
+20 -22
View File
@@ -12,12 +12,12 @@
#include <ConfigManager.hpp>
#include <ConfigTypes.hpp>
#include <CoreInterface.hpp>
#include <Void/Async/EventBus.hpp>
#include <Database.hpp>
#include <RpcTypes.hpp>
#include <StateBlob.hpp>
#include <TrackTypes.hpp>
#include <Types.hpp>
#include <Void/Async/EventBus.hpp>
#include <Void/Service/Registry.hpp>
#include <atomic>
#include <map>
@@ -35,7 +35,8 @@ namespace Void::Logging
namespace Echoion::Core
{
class ListeningRoomManager;
class PluginHost;
class TeamSpeakDirectoryService;
// Main Core implementation of ICoreInterface
class Core : public Api::ICoreInterface
@@ -169,10 +170,10 @@ namespace Echoion::Core
void setupEventBusSubscriptions() noexcept;
// Fetch an online client's avatar bytes (TS local cache, then the
// myTeamSpeak URL, then a legacy file-transfer download) and persist
// them — and the myTS URL — to the database keyed by uid. Returns
// {contentType, bytes} on success. Web-agnostic; used by both the
// avatar HTTP provider and the background warmer.
// myTeamSpeak URL, then a legacy file-transfer download) and
// persist them — and the myTS URL — to the database keyed by uid.
// Returns {contentType, bytes} on success. Web-agnostic; used by
// both the avatar HTTP provider and the background warmer.
[[nodiscard]] std::optional<std::pair<std::string, std::string>>
fetchClientAvatarBytes(const std::string& uid,
uint64_t clientId);
@@ -192,9 +193,9 @@ namespace Echoion::Core
std::shared_ptr<NetworkClient> networkClient_;
std::shared_ptr<LyricsService> lyricsService_;
std::shared_ptr<MusicManager> musicManager_;
std::shared_ptr<ListeningRoomManager> listeningRooms_;
std::string pendingListeningRoomState_;
std::unique_ptr<CommandManager> commandManager_;
std::shared_ptr<PluginHost> extensionPlugins_;
std::shared_ptr<TeamSpeakDirectoryService> directoryService_;
Api::PluginInterfacePtr pluginInterface_;
// State
@@ -210,12 +211,6 @@ namespace Echoion::Core
std::vector<Api::EventCallback> eventCallbacks_;
mutable std::mutex eventMutex_;
// Admin / DJ tracking (RPC clients whose TeamSpeak identity is in
// a configured teamspeak.adminGroups / djGroups server group).
std::vector<uint64_t> adminClients_;
std::vector<uint64_t> djClients_;
mutable std::mutex adminMutex_;
// Authenticated RPC client -> stable TS uid + nickname, resolved
// at token auth. Keys per-user features (favorites, vote-skip).
struct RpcIdentity {
@@ -226,10 +221,12 @@ namespace Echoion::Core
mutable std::mutex rpcIdentityMutex_;
[[nodiscard]] std::optional<RpcIdentity>
rpcIdentity(uint64_t clientId) const;
[[nodiscard]] bool hasLiveTeamSpeakRole(
uint64_t clientId,
const std::vector<uint64_t>& configuredGroups) const;
// Full identity behind an RPC token: uid, display nickname and
// admin standing. Shared by token auth, IP autologin and the
// watch-together identity resolver.
// admin standing. Shared by token auth and IP autologin.
struct TokenIdentity {
std::string uid;
std::string nickname;
@@ -238,8 +235,9 @@ namespace Echoion::Core
};
[[nodiscard]] std::optional<TokenIdentity>
identityForToken(const std::string& token);
// Mark an RPC connection authenticated as `identity` (auth set,
// admin list, per-client identity map).
// Mark an RPC connection authenticated as `identity` and retain its
// stable TeamSpeak identity. Roles are checked live for each
// request.
void registerRpcAuth(uint64_t clientId,
const TokenIdentity& identity);
// Guards RestartWebInterface against overlapping restarts.
@@ -249,7 +247,8 @@ namespace Echoion::Core
std::shared_ptr<Api::Database> database_;
// Background avatar cache warmer + the uids already cached this
// session (so we don't re-download an unchanged avatar every cycle).
// session (so we don't re-download an unchanged avatar every
// cycle).
std::jthread avatarWarmer_;
std::unordered_set<std::string> warmedUids_;
@@ -257,9 +256,8 @@ namespace Echoion::Core
std::shared_ptr<RpcServer> rpcServer_;
#ifdef ECHOION_WITH_WEB
// Browser web interface: serves the static UI and hosts the
// independent sync-watch WebSocket. Bot control from the browser
// goes straight to the RPC server, so this holds no bot handles.
// Browser web interface: serves the static dashboard and same-origin
// RPC bridge. Bot control still terminates at the RPC server.
std::shared_ptr<Web::HttpServer> webServer_;
#endif
@@ -1,106 +0,0 @@
#pragma once
#include "echoion/core/MusicManager.hpp"
#include <PluginInterface.hpp>
#include <Void/Async/EventBus.hpp>
#include <map>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <vector>
namespace Echoion::Core
{
class NetworkClient;
class ListeningRoomManager final
{
public:
struct RoomSummary {
std::string name;
uint64_t ownerId{};
std::vector<uint64_t> members;
bool isPlaying{};
bool isPaused{};
std::size_t queueSize{};
};
struct PersistedRoom {
std::string name;
uint64_t ownerId{};
std::vector<uint64_t> members;
Api::HotReloadState state;
};
ListeningRoomManager(std::shared_ptr<NetworkClient> network,
Api::ConfigManager& config, Void::EventBus::EventBus& events);
~ListeningRoomManager();
ListeningRoomManager(const ListeningRoomManager&) = delete;
ListeningRoomManager& operator=(const ListeningRoomManager&) = delete;
void setPluginInterface(Api::PluginInterfacePtr plugin);
void setChangeCallback(std::function<void()> callback);
[[nodiscard]] Api::Result<void>
create(std::string name, uint64_t ownerId);
[[nodiscard]] Api::Result<void> remove(const std::string& name,
uint64_t requesterId);
[[nodiscard]] Api::Result<void> join(const std::string& name,
uint64_t clientId);
[[nodiscard]] Api::Result<void> leave(uint64_t clientId);
[[nodiscard]] Api::Result<std::string> play(const std::string& name,
std::string query, uint64_t clientId);
[[nodiscard]] Api::Result<void> pause(const std::string& name,
uint64_t requesterId);
[[nodiscard]] Api::Result<void> resume(const std::string& name,
uint64_t requesterId);
[[nodiscard]] Api::Result<void> stop(const std::string& name,
uint64_t requesterId);
[[nodiscard]] Api::Result<void> skip(const std::string& name,
uint64_t requesterId);
[[nodiscard]] Api::Result<void> removeQueueEntry(const std::string& name,
uint64_t queueId, uint64_t requesterId);
[[nodiscard]] Api::Result<void> moveQueueEntry(const std::string& name,
uint64_t queueId, uint32_t newPosition, uint64_t requesterId);
[[nodiscard]] Api::Result<void> clearQueue(const std::string& name,
uint64_t requesterId);
[[nodiscard]] Api::Result<std::vector<Api::QueueEntry>>
queue(const std::string& name) const;
[[nodiscard]] std::vector<RoomSummary> list() const;
[[nodiscard]] std::optional<std::string>
roomForClient(uint64_t clientId) const;
[[nodiscard]] std::vector<PersistedRoom> snapshot() const;
[[nodiscard]] Api::Result<void>
restore(const std::vector<PersistedRoom>& rooms);
void shutdown();
private:
struct Room {
std::string name;
uint64_t ownerId{};
Api::IPluginInterface::AudioStreamId streamId{};
std::set<uint64_t> members;
std::unique_ptr<MusicManager> music;
};
[[nodiscard]] Api::ServerConfig serverConfigFor(
const std::string& roomName) const;
[[nodiscard]] Api::Result<void> refreshRecipients(Room& room);
[[nodiscard]] Room* findLocked(const std::string& name);
[[nodiscard]] const Room* findLocked(const std::string& name) const;
std::shared_ptr<NetworkClient> network_;
Api::ConfigManager& config_;
Void::EventBus::EventBus& events_;
Api::PluginInterfacePtr plugin_;
std::map<std::string, std::unique_ptr<Room>> rooms_;
std::map<uint64_t, std::string> membership_;
mutable std::mutex mutex_;
std::function<void()> changeCallback_;
void notifyChanged() const;
};
}
@@ -1,37 +0,0 @@
#pragma once
#include <Types.hpp>
#include <algorithm>
#include <cctype>
#include <string>
#include <string_view>
namespace Echoion::Core
{
[[nodiscard]] inline Api::Result<std::string>
validateListeningRoomName(std::string name)
{
const auto first = name.find_first_not_of(" \t\r\n");
if (first == std::string::npos) return Api::fail(
Api::ErrorCode::InvalidArgument, "room name is required");
const auto last = name.find_last_not_of(" \t\r\n");
name = name.substr(first, last - first + 1);
if (name.size() > 48 || std::ranges::any_of(name,
[](unsigned char value) { return std::iscntrl(value) != 0; })) {
return Api::fail(Api::ErrorCode::InvalidArgument,
"room name must be 1-48 printable characters");
}
return name;
}
[[nodiscard]] inline std::string
canonicalListeningRoomName(std::string_view name)
{
std::string key{name};
std::ranges::transform(key, key.begin(), [](unsigned char value) {
return static_cast<char>(std::tolower(value));
});
return key;
}
}
+9 -1
View File
@@ -80,7 +80,15 @@ namespace Echoion::Core
// Re-apply the source-chain settings (order, cooldown, instance
// lists) after a config reload.
void applySourcesConfig(const Api::SourcesConfig& sources);
void addTrackSource(std::shared_ptr<ITrackSource> source);
void setSharedYouTubeClient(std::shared_ptr<YouTubeClient> client)
{
youTubeClient_ = std::move(client);
}
[[nodiscard]] std::shared_ptr<YouTubeClient> sharedYouTubeClient() const
{
return youTubeClient_;
}
// Re-apply bot settings (queue size, track timeout, playlist
// import gate) after a config reload. Does not touch the live
// volume.
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include <ExtensionPlugin.hpp>
#include <Void/Plugin/Manager.hpp>
#include <filesystem>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <string_view>
#include <vector>
namespace Echoion::Core
{
class CommandManager;
class MusicManager;
class ITrackSource;
class PluginHost final : public std::enable_shared_from_this<PluginHost>
{
public:
PluginHost(CommandManager& commands, std::shared_ptr<MusicManager> music,
std::function<bool(uint64_t)> isAdmin,
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink = {});
~PluginHost();
void loadDirectory(const std::filesystem::path& directory);
void setChangeCallback(std::function<void()> callback);
void dispatch(const Api::PluginEvent& event) const;
[[nodiscard]] Api::Result<std::string> call(
std::string_view plugin, std::string_view method,
std::string params, uint64_t clientId) const;
[[nodiscard]] std::vector<Api::ExtensionWebAsset> webAssets() const;
[[nodiscard]] std::vector<std::string> names() const;
struct State {
std::string name;
std::string json;
std::uint32_t version{};
};
[[nodiscard]] std::vector<State> snapshotStates() const;
void restoreStates(const std::vector<State>& states);
private:
void publish(std::string_view name);
void unpublish(std::string_view name);
void notifyChanged() const;
CommandManager& commands_;
std::shared_ptr<MusicManager> music_;
std::function<bool(uint64_t)> isAdmin_;
std::function<void(std::shared_ptr<ITrackSource>)> mediaSink_;
Void::Plugin::PluginManager plugins_;
Void::Plugin::ReloadCallbackId reloadCallback_{};
mutable std::mutex mutex_;
std::vector<std::shared_ptr<class PluginTrackSource>> sources_;
std::function<void()> changeCallback_;
};
}
+12 -51
View File
@@ -1,6 +1,7 @@
#pragma once
#include <TrackTypes.hpp>
#include <ExtensionPlugin.hpp>
#include <Void/Data/Json.hpp>
#include <Void/Data/Reflect.hpp>
#include <cstdint>
@@ -85,26 +86,6 @@ namespace Echoion::Core::Dto
std::string text;
};
struct ListeningRoomRequest {
std::string room;
};
struct ListeningRoomPlayRequest {
std::string room;
std::string query;
};
struct ListeningRoomQueueRequest {
std::string room;
std::uint64_t queueId = 0;
};
struct ListeningRoomMoveRequest {
std::string room;
std::uint64_t queueId = 0;
std::uint32_t newPosition = 0;
};
// ── RPC handler responses ───────────────────────────────────────────────
struct Track {
@@ -201,19 +182,19 @@ namespace Echoion::Core::Dto
float volume = 0.0f;
};
struct ListeningRoom {
std::string name;
std::uint64_t ownerId = 0;
std::vector<std::uint64_t> members;
bool isPlaying = false;
bool isPaused = false;
std::uint64_t queueSize = 0;
bool isOwner = false;
struct Capabilities {
bool plugins = false;
bool webExtensions = false;
};
struct ListeningRoomList {
std::vector<ListeningRoom> rooms;
std::optional<std::string> currentRoom;
struct PluginCallRequest {
std::string plugin;
std::string method;
std::string params;
};
struct PluginExtensions {
std::vector<Api::ExtensionWebAsset> assets;
};
struct Autoplay {
@@ -227,26 +208,6 @@ namespace Echoion::Core::Dto
std::string language;
};
// Custom emoji metadata (name + mime); the image itself is served at
// GET /emoji/<name>, not inlined here.
struct CustomEmojiDto {
std::string name;
std::string mime;
std::string addedBy;
};
struct CustomEmojiList {
std::vector<CustomEmojiDto> emojis;
};
// AddCustomEmoji request: name + mime + base64-encoded image bytes.
struct AddEmojiRequest {
std::string name;
std::string mime;
std::string dataBase64;
};
struct EmojiNameRequest {
std::string name;
};
struct QueuedResponse {
bool success = true;
std::uint64_t queueId = 0;
@@ -0,0 +1,54 @@
#pragma once
#include <PluginInterface.hpp>
#include <PluginTypes.hpp>
#include <Types.hpp>
#include <Void/Data/Json.hpp>
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace Echoion::Core
{
// One authoritative, event-refreshed TeamSpeak topology cache. The public
// serializer is deliberately structural: it has no fields for UIDs, groups,
// database IDs, addresses, or query clients, so private data cannot leak by
// accidentally toggling a flag at the HTTP boundary.
class TeamSpeakDirectoryService
{
public:
struct Snapshot {
Api::ServerInfo server;
std::vector<Api::ChannelInfo> channels;
std::vector<Api::ClientInfo> clients;
bool connected = false;
std::uint64_t revision = 0;
};
void setPluginInterface(Api::PluginInterfacePtr plugin);
[[nodiscard]] Api::Result<void> refresh();
void handleEvent(Api::PluginEventType type);
[[nodiscard]] Snapshot snapshot() const;
[[nodiscard]] Void::Json::Value publicJson() const;
[[nodiscard]] Void::Json::Value adminJson() const;
// TeamSpeak stores a sibling's predecessor id in channel_order.
// This helper turns that linked-list representation into display
// order and deterministically appends malformed/orphaned entries.
[[nodiscard]] static std::vector<Api::ChannelInfo>
orderChannels(std::vector<Api::ChannelInfo> channels);
private:
mutable std::mutex mutex_;
Api::PluginInterfacePtr plugin_;
Snapshot snapshot_;
};
} // namespace Echoion::Core
-1
View File
@@ -119,7 +119,6 @@ namespace Echoion::Core
// Get best audio stream URL using yt-dlp
[[nodiscard]] Api::Result<std::string>
getAudioStreamUrl(std::string_view videoId);
// Resolve a stream URL for any yt-dlp-supported page URL
// (SoundCloud, Bandcamp, VK, radio pages, ...). When useProxy is
// false the configured proxy is explicitly bypassed with a
@@ -19,7 +19,6 @@
#include "ReloadConfigCommand.hpp"
#include "RemoveCommand.hpp"
#include "RepeatCommand.hpp"
#include "RoomCommand.hpp"
#include "ResumeCommand.hpp"
#include "RpcInfoCommand.hpp"
#include "SearchCommand.hpp"
@@ -1,218 +0,0 @@
#pragma once
#include "Command.hpp"
#include "echoion/core/ListeningRoomManager.hpp"
#include <algorithm>
#include <charconv>
#include <cctype>
#include <format>
#include <sstream>
#include <string>
#include <string_view>
namespace Echoion::Core
{
class RoomCommand final : public Command
{
public:
void execute(const CommandContext& ctx) override
{
auto rooms = ctx.service<ListeningRoomManager>();
if (!rooms) {
ctx.reply(ctx.tr("Listening rooms are currently unavailable."));
return;
}
auto [action, argument] = split(ctx.args);
if (action.empty() || action == "list") {
list(ctx, *rooms);
return;
}
if (action == "help") {
help(ctx);
return;
}
if (action == "create") {
reply(ctx, rooms->create(argument, ctx.clientId),
ctx.trf("Created and joined room '{}'.", argument));
return;
}
if (action == "join") {
reply(ctx, rooms->join(argument, ctx.clientId),
ctx.trf("Joined room '{}'.", argument));
return;
}
if (action == "leave") {
reply(ctx, rooms->leave(ctx.clientId),
ctx.tr("Left the listening room."));
return;
}
const auto current = rooms->roomForClient(ctx.clientId);
if (!current) {
ctx.reply(ctx.trf(
"Join a room first with {}room join <name>.", ctx.prefix));
return;
}
if (action == "delete") {
reply(ctx, rooms->remove(*current, ctx.clientId),
ctx.trf("Deleted room '{}'.", *current));
} else if (action == "play") {
if (argument.empty()) {
help(ctx);
return;
}
auto result = rooms->play(*current, argument, ctx.clientId);
if (!result) {
ctx.reply(ctx.trf("Room action failed: {}",
result.error().message));
} else {
ctx.reply(ctx.trf("Added to '{}': {}", *current, *result));
}
} else if (action == "pause") {
reply(ctx, rooms->pause(*current, ctx.clientId),
ctx.trf("Paused room '{}'.", *current));
} else if (action == "resume") {
reply(ctx, rooms->resume(*current, ctx.clientId),
ctx.trf("Resumed room '{}'.", *current));
} else if (action == "stop") {
reply(ctx, rooms->stop(*current, ctx.clientId),
ctx.trf("Stopped room '{}'.", *current));
} else if (action == "skip") {
reply(ctx, rooms->skip(*current, ctx.clientId),
ctx.trf("Skipped in room '{}'.", *current));
} else if (action == "clear") {
reply(ctx, rooms->clearQueue(*current, ctx.clientId),
ctx.trf("Cleared queue for '{}'.", *current));
} else if (action == "remove") {
const auto queueId = number(argument);
if (!queueId) {
help(ctx);
return;
}
reply(ctx, rooms->removeQueueEntry(
*current, *queueId, ctx.clientId),
ctx.trf("Removed queue entry {}.", *queueId));
} else if (action == "move") {
auto [queueIdText, positionText] = split(argument);
const auto queueId = number(queueIdText);
const auto position = number(positionText);
if (!queueId || !position || *position == 0) {
help(ctx);
return;
}
reply(ctx, rooms->moveQueueEntry(*current, *queueId,
static_cast<uint32_t>(*position - 1), ctx.clientId),
ctx.trf("Moved queue entry {} to position {}.",
*queueId, *position));
} else if (action == "queue") {
queue(ctx, *rooms, *current);
} else {
help(ctx);
}
}
[[nodiscard]] std::string_view getDescription() const override
{
return "Creates, joins and controls independent listening rooms.";
}
[[nodiscard]] std::string_view getUsage() const override
{
return "<list|create|join|leave|delete|play|pause|resume|stop|skip|queue|remove|move|clear>";
}
[[nodiscard]] CommandCategory getCategory() const override
{
return CommandCategory::Music;
}
private:
static std::pair<std::string, std::string> split(std::string_view input)
{
const auto first = input.find_first_not_of(" \t");
if (first == std::string_view::npos) return {};
const auto separator = input.find_first_of(" \t", first);
std::string action(input.substr(first, separator - first));
std::ranges::transform(action, action.begin(),
[](unsigned char value) { return std::tolower(value); });
if (separator == std::string_view::npos) return {action, {}};
const auto argumentStart = input.find_first_not_of(" \t", separator);
return {action, argumentStart == std::string_view::npos
? std::string{} : std::string(input.substr(argumentStart))};
}
static std::optional<uint64_t> number(std::string_view text)
{
uint64_t value = 0;
const auto [end, error] = std::from_chars(
text.data(), text.data() + text.size(), value);
return error == std::errc{} && end == text.data() + text.size()
? std::optional<uint64_t>{value} : std::nullopt;
}
static void list(const CommandContext& ctx, ListeningRoomManager& rooms)
{
const auto all = rooms.list();
if (all.empty()) {
ctx.reply(ctx.trf("No listening rooms. Create one with {}room create <name>.",
ctx.prefix));
return;
}
const auto current = rooms.roomForClient(ctx.clientId);
std::stringstream output;
output << ctx.tr("Listening rooms:") << '\n';
for (const auto& room : all) {
const bool selected = current == room.name;
output << (selected ? "**> " : "- ")
<< escapeMarkdown(room.name) << (selected ? "** " : " ")
<< ctx.trf("({} listeners, {} queued{})", room.members.size(),
room.queueSize, room.isPlaying ? ", playing" : "") << '\n';
}
ctx.reply(output.str());
}
static void queue(const CommandContext& ctx, ListeningRoomManager& rooms,
const std::string& name)
{
auto entries = rooms.queue(name);
if (!entries) {
ctx.reply(ctx.trf("Room action failed: {}", entries.error().message));
return;
}
std::stringstream output;
output << ctx.trf("Queue for '{}' ({} tracks):", name, entries->size());
for (std::size_t index = 0; index < entries->size(); ++index) {
output << '\n' << index + 1 << ". "
<< trackLink((*entries)[index].track) << " `#"
<< (*entries)[index].queueId << '`';
}
ctx.reply(output.str());
}
static void reply(const CommandContext& ctx, const Api::Result<void>& result,
std::string_view success)
{
if (result) {
ctx.reply(success);
} else {
ctx.reply(ctx.trf("Room action failed: {}", result.error().message));
}
}
static void help(const CommandContext& ctx)
{
ctx.reply(ctx.trf(
"Room commands:\n"
"`{}room list`\n`{}room create <name>`\n"
"`{}room join <name>`\n`{}room leave`\n"
"`{}room play <song>`\n`{}room pause|resume|stop|skip`\n"
"`{}room queue`\n`{}room remove <queue-id>`\n"
"`{}room move <queue-id> <position>`\n"
"`{}room clear`\n`{}room delete`",
ctx.prefix, ctx.prefix, ctx.prefix, ctx.prefix, ctx.prefix,
ctx.prefix, ctx.prefix, ctx.prefix, ctx.prefix, ctx.prefix,
ctx.prefix));
}
};
}
@@ -0,0 +1,31 @@
#pragma once
#include <Void/Data/Json.hpp>
#include <cmath>
#include <cstdint>
#include <optional>
#include <string_view>
namespace Echoion::Core::Detail
{
[[nodiscard]] inline std::optional<std::uint64_t>
uintField(const Void::Json::Value& object, std::string_view key)
{
const auto* value = object.find(key);
if (!value || !value->is_number()) {
return std::nullopt;
}
const auto number = value->as_number();
// A double equal to 2^64 is what uint64_t::max() rounds to, so use
// an exclusive 2^64 bound before converting. Floating-to-integer
// conversion outside the destination range is undefined behavior.
constexpr double kUint64Limit = 18446744073709551616.0;
if (!std::isfinite(number) || number < 0.0 ||
std::trunc(number) != number || number >= kUint64Limit) {
return std::nullopt;
}
return static_cast<std::uint64_t>(number);
}
} // namespace Echoion::Core::Detail
@@ -21,6 +21,7 @@ namespace Echoion::Core
public:
void setSources(std::vector<std::shared_ptr<ITrackSource>> sources);
void addSource(std::shared_ptr<ITrackSource> source);
// Reorder/enable per config; names not found are ignored, sources
// not named are dropped from the chain.
@@ -59,9 +60,9 @@ namespace Echoion::Core
std::chrono::steady_clock::time_point cooldownUntil{};
};
[[nodiscard]] std::vector<SourceState*>
[[nodiscard]] std::vector<std::shared_ptr<ITrackSource>>
candidatesFor(const std::string& query, bool needSearch);
void reportFailure(SourceState& state);
void reportFailure(const std::shared_ptr<ITrackSource>& source);
mutable std::mutex mutex_;
std::vector<std::shared_ptr<ITrackSource>> allSources_;
+4 -10
View File
@@ -46,16 +46,10 @@ namespace Echoion::Core
std::string lastActivity; // ISO 8601
};
struct ListeningRoomState {
struct ExtensionPluginState {
std::string name;
uint64_t ownerId = 0;
std::vector<uint64_t> members;
Echoion::Api::PlaybackState playback;
std::vector<QueueEntry> queue;
std::optional<std::string> currentStreamUrl;
int64_t playbackPositionMs = 0;
BotConfig config;
bool autoplay = false;
std::string json;
std::uint32_t version = 0;
};
// Main state
@@ -65,7 +59,7 @@ namespace Echoion::Core
bool autoplay = false; // Radio mode on/off (persisted for restart)
std::vector<QueueEntryState> queue;
std::vector<SessionState> sessions;
std::vector<ListeningRoomState> listeningRooms;
std::vector<ExtensionPluginState> extensionPlugins;
// Version info
uint32_t version = 1;