Migrate to VoidLibrary (toolchain + API groundwork)

This commit is contained in:
faumaray committed 2026-06-22 15:53:18 +03:00
1 parent 5e1e3d66c4
commit e17cfed56f
38 files changed
+3077 -2505

No files matched your search

@@ -0,0 +1,111 @@
#pragma once
#ifndef PLUGIN
#include "ConfigTypes.hpp"
#include <atomic>
#include <filesystem>
#include <functional>
#include <mutex>
#include <optional>
#include <shared_mutex>
namespace Echoion::Api
{
class ConfigManager
{
public:
using ConfigChangedCallback = std::function<void(const AppConfig&)>;
// Get singleton instance
static ConfigManager& instance();
// Delete copy/move
ConfigManager(const ConfigManager&) = delete;
ConfigManager& operator=(const ConfigManager&) = delete;
// Initialize with config file path (call once at startup)
[[nodiscard]] bool
initialize(const std::filesystem::path& configPath);
// Initialize with default path (~/.config/echoion/config.json)
[[nodiscard]] bool initialize();
// Get current config (thread-safe)
[[nodiscard]] AppConfig getConfig() const;
// Get config by reference (faster, but hold lock briefly)
template <typename Func>
auto withConfig(Func&& func) const
-> decltype(func(std::declval<const AppConfig&>()))
{
std::shared_lock lock(mutex_);
return func(config_);
}
// Direct accessors for config sections (convenience methods)
[[nodiscard]] const BotConfig& getBot() const;
[[nodiscard]] const YouTubeConfig& getYouTube() const;
[[nodiscard]] const NetworkConfig& getNetwork() const;
[[nodiscard]] const TeamSpeakConfig& getTeamSpeak() const;
[[nodiscard]] const SecurityConfig& getSecurity() const;
[[nodiscard]] const FeaturesConfig& getFeatures() const;
[[nodiscard]] const AdvancedConfig& getAdvanced() const;
// Reload configuration from file
[[nodiscard]] bool reload();
// Save current configuration to file
[[nodiscard]] bool save();
// Update config (and optionally save)
void updateConfig(const AppConfig& config, bool saveToFile = true);
// Check if initialized
[[nodiscard]] bool isInitialized() const;
// Get config file path
[[nodiscard]] std::filesystem::path getConfigPath() const;
// Get default config path (~/.config/echoion/config.json)
[[nodiscard]] static std::filesystem::path getDefaultConfigPath();
// Subscribe to config changes
void onConfigChanged(ConfigChangedCallback callback);
// Create default config file if it doesn't exist
[[nodiscard]] bool createDefaultConfigIfNeeded();
private:
ConfigManager() = default;
~ConfigManager() = default;
mutable std::shared_mutex mutex_;
AppConfig config_;
std::filesystem::path configPath_;
std::atomic<bool> initialized_{false};
std::vector<ConfigChangedCallback> callbacks_;
mutable std::shared_mutex callbackMutex_;
void notifyCallbacks();
[[nodiscard]] bool loadFromFileInternal();
[[nodiscard]] bool saveToFileInternal();
};
} // namespace Echoion::Api
// Convenience macros for accessing config
#define ECHOION_CONFIG (::Echoion::Api::ConfigManager::instance().getConfig())
#define ECHOION_BOT (::Echoion::Api::ConfigManager::instance().getBot())
#define ECHOION_YOUTUBE (::Echoion::Api::ConfigManager::instance().getYouTube())
#define ECHOION_NETWORK (::Echoion::Api::ConfigManager::instance().getNetwork())
#define ECHOION_TEAMSPEAK \
(::Echoion::Api::ConfigManager::instance().getTeamSpeak())
#define ECHOION_SECURITY \
(::Echoion::Api::ConfigManager::instance().getSecurity())
#define ECHOION_FEATURES \
(::Echoion::Api::ConfigManager::instance().getFeatures())
#define ECHOION_ADVANCED \
(::Echoion::Api::ConfigManager::instance().getAdvanced())
#endif
+165
View File
@@ -0,0 +1,165 @@
#pragma once
#ifndef PLUGIN
#include "AudioTypes.hpp"
#include "NetworkTypes.hpp"
#include "Types.hpp"
#include <chrono>
#include <map>
#include <optional>
#include <string>
#include <variant>
#include <vector>
namespace Echoion::Api
{
using ConfigValue = std::variant<std::monostate, bool, int64_t, double,
std::string, std::vector<std::string>>;
struct ConfigEntry {
std::string key;
ConfigValue value;
std::string description;
bool isSecret;
std::optional<ConfigValue> defaultValue;
std::optional<std::string> category;
};
// Core Bot Settings
struct BotConfig {
std::string botName = "Echoion";
std::string commandPrefix = "!";
float defaultVolume = 0.5f;
uint32_t maxQueueSize = 100;
std::chrono::milliseconds trackTimeout =
std::chrono::milliseconds(30000);
// Reconnection settings
bool autoReconnect = true;
std::chrono::milliseconds reconnectDelay =
std::chrono::milliseconds(5000);
uint32_t maxReconnectAttempts = 5;
// Audio quality settings
AudioQuality preferredQuality = AudioQuality::High;
bool allowPlaylistImports = true;
};
// YouTube Integration Settings
struct YouTubeConfig {
std::optional<std::string> youtubeApiKey;
std::optional<std::string> youtubeCookiesPath;
std::optional<std::string> cookiesFromBrowser;
size_t ytDlpMaxConcurrent = 4;
bool ytDlpAsyncEnabled = true;
bool enableUrlShortening = true;
};
// Network & Proxy Settings
struct NetworkConfig {
std::optional<ProxyConfig> proxy;
bool rpcEnabled = true;
uint16_t rpcPort = 8765;
std::string rpcBindAddress = "127.0.0.1";
};
// TeamSpeak Server Connection
struct TeamSpeakConfig {
std::string address = "localhost";
uint16_t port = 9987;
std::string serverPassword;
std::string nickname = "EchoionBot";
std::optional<std::string> defaultChannelId;
std::optional<std::string> channelPassword;
std::vector<uint64_t> adminGroups;
std::vector<uint64_t> djGroups;
std::vector<uint64_t> bannedGroups;
};
// Security & Authentication
struct SecurityConfig {
bool requireAuthForAdmin = true;
uint32_t maxLoginAttempts = 5;
std::chrono::milliseconds lockoutDuration =
std::chrono::milliseconds(300000);
std::chrono::milliseconds sessionTimeout =
std::chrono::milliseconds(3600000);
bool enableAuditLog = true;
std::optional<std::string> apiKey;
bool allowCors = false;
std::vector<std::string> corsOrigins;
};
// Feature Toggles
struct FeaturesConfig {
bool enableHotReload = true;
bool enableAutoReload = false;
bool enableAutoUpdateCheck = true;
// Playback behavior
bool autoStartOnSubscribe = true;
bool pauseOnEmptySubscribers = true;
bool resumeOnSubscriberReturn = true;
// Queue management
std::string shuffleMode = "random";
std::string repeatMode = "off";
uint32_t maxHistorySize = 50;
};
// Advanced Settings
struct AdvancedConfig {
// Audio configuration
uint32_t sampleRate = 192000;
uint32_t channels = 2;
uint32_t bufferSize = 7680;
// Thread pool configuration
uint32_t commandThreadPoolSize = 4;
uint32_t networkThreadPoolSize = 4;
uint32_t decoderThreads = 2;
// Cache settings
bool cacheEnabled = true;
std::string cacheMaxSize = "1GB";
uint32_t cacheTTL = 86400;
uint32_t tempCleanupInterval = 3600;
};
// ServerConfig for Plugin interface (mirrors PluginTypes.hpp version)
struct ServerConfig {
std::string address;
uint16_t port = 0;
std::string serverPassword;
std::string nickname;
std::optional<std::string> defaultChannelId;
std::optional<std::string> channelPassword;
std::vector<uint64_t> adminGroups;
std::vector<uint64_t> djGroups;
std::vector<uint64_t> bannedGroups;
};
struct AdminCredentials {
std::string username;
std::string passwordHash;
std::optional<std::string> salt;
std::vector<std::string> permissions;
std::chrono::system_clock::time_point createdAt;
std::optional<std::chrono::system_clock::time_point> lastLogin;
bool isActive;
};
struct AppConfig {
BotConfig bot;
YouTubeConfig youtube;
NetworkConfig network;
TeamSpeakConfig teamspeak;
SecurityConfig security;
FeaturesConfig features;
AdvancedConfig advanced;
AdminCredentials admin;
std::map<std::string, ConfigEntry> custom;
};
} // namespace Echoion::Api
#endif