Compare commits

...
7 Commits
Author SHA1 Message Date
faumaray 470ab507e1 making WEB
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-11 00:46:06 +03:00
faumaray 06379fbd5c Release 1.0.0
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-04 01:49:55 +03:00
faumarayandClaude Opus 4.8 446416c723 Plugin: keep <details> blocks intact when chunking replies
A reply is split into <=900-byte TeamSpeak messages; never split inside a
<details>…</details> block (each top-level block starts a fresh message and is
kept whole), otherwise a collapsible section spanning two messages would not
render.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 03:15:40 +03:00
faumarayandClaude Opus 4.8 ac88cd6eb1 Plugin: log sendTextMessage size + chunk count (debug)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 02:39:10 +03:00
faumarayandClaude Opus 4.8 a356251c83 Plugin: chunk long text replies so search/queue results arrive
requestSendPrivateTextMsg rejects over-long messages, and sendTextMessage
ignored its error return — so long replies (e.g. a 5-result search list) were
silently dropped while short ones (!help, error messages) worked. Split
messages into UTF-8-safe <=900-byte chunks on line boundaries and send each;
log the TeamSpeak error code on failure instead of swallowing it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 21:49:52 +03:00
faumarayandClaude Opus 4.8 9a61e01fda Route plugin logging through the Void::Log facade
Rewrite the ~80 ECHOION_LOG_* sites in PluginInterface/CoreLoader to
Void::Log::<level>("<Subsystem>", "{}", <expr>); add <iostream> where the
deleted LoggerInterface.hpp previously pulled it in. The plugin shares the
process-wide Void::Log sink installed by Core.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 14:10:06 +03:00
faumarayandClaude Opus 4.8 b313ed7101 Use Api::fail() for error returns
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 22:07:18 +03:00
7 changed files with 751 additions and 306 deletions

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ target_link_libraries(EchoionPlugin PRIVATE
Echoion::ApiPluginInterface
Echoion::ApiLogger
Echoion::ApiCoreInterface
Void::Data
Void::Stacktrace
)
+2
View File
@@ -74,6 +74,8 @@ namespace Echoion::Plugin
// Deferred reload - waits for current track to finish
std::thread deferredReloadThread_;
std::atomic<bool> hasPendingReload_{false};
std::atomic<bool> stopDeferredReload_{false};
std::condition_variable deferredReloadCv_;
std::filesystem::path pendingReloadPath_;
std::string pendingTrackId_; // Track ID that was playing when
// reload scheduled
@@ -55,6 +55,15 @@ namespace Echoion::Plugin
getClients() override;
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>>
getClient(uint64_t clientId) override;
[[nodiscard]] Api::Result<std::optional<std::string>>
getClientIp(uint64_t clientId) override;
[[nodiscard]] Api::Result<std::optional<std::string>>
getClientAvatarPath(uint64_t clientId) override;
[[nodiscard]] Api::Result<std::optional<std::string>>
getClientAvatarUrl(uint64_t clientId) override;
[[nodiscard]] Api::Result<std::optional<std::string>>
requestClientAvatar(uint64_t clientId,
const std::string& destDir) override;
Api::Result<void> moveClient(uint64_t clientId,
uint64_t channelId) override;
Api::Result<void> kickClient(uint64_t clientId,
@@ -90,6 +99,7 @@ namespace Echoion::Plugin
void clearEventCallbacks();
// TeamSpeak event handlers (called by TeamSpeak SDK)
void onConnectionEstablished(uint64_t serverConnectionHandlerId);
void onClientConnected(uint64_t serverConnectionHandlerId,
uint64_t clientId);
void onClientDisconnected(uint64_t serverConnectionHandlerId,
+76 -57
View File
@@ -1,4 +1,4 @@
#include "LoggerInterface.hpp"
#include <Void/Log/Log.hpp>
#include "dylib.hpp"
#include "echoion/plugin/CoreLoader.hpp"
#include <chrono>
@@ -21,7 +21,7 @@ namespace Echoion::Plugin
std::lock_guard<std::mutex> lock(mutex_);
if (!currentLibraryPath_.empty() &&
std::filesystem::exists(currentLibraryPath_)) {
ECHOION_LOG_INFO(std::format("Enabling auto-reload for: {}",
Void::Log::info("CoreLoader", "{}", std::format("Enabling auto-reload for: {}",
currentLibraryPath_.string()));
fileWatcher_.startWatching(currentLibraryPath_,
@@ -33,7 +33,7 @@ namespace Echoion::Plugin
{
autoReloadEnabled_ = false;
fileWatcher_.stopWatching();
ECHOION_LOG_INFO("Auto-reload disabled");
Void::Log::info("CoreLoader", "{}", "Auto-reload disabled");
}
bool CoreLoader::isAutoReloadEnabled() const noexcept
@@ -47,7 +47,7 @@ namespace Echoion::Plugin
return;
}
ECHOION_LOG_INFO(
Void::Log::info("CoreLoader", "{}",
"Core file changed, scheduling hot reload after current track...");
// Small delay to ensure file write is complete
@@ -69,7 +69,7 @@ namespace Echoion::Plugin
}
}
ECHOION_LOG_INFO(
Void::Log::info("CoreLoader", "{}",
std::format("Playback active (track: {}), deferring reload "
"until track finishes",
currentTrackId));
@@ -85,10 +85,10 @@ namespace Echoion::Plugin
// No playback, reload immediately
auto result = hotReload(currentLibraryPath_);
if (!result) {
ECHOION_LOG_ERROR(std::format("Auto hot-reload failed: {}",
Void::Log::error("CoreLoader", "{}", std::format("Auto hot-reload failed: {}",
result.error().message));
} else {
ECHOION_LOG_INFO("Auto hot-reload completed successfully");
Void::Log::info("CoreLoader", "{}", "Auto hot-reload completed successfully");
// Notify Plugin to re-register callbacks
if (hotReloadCallback_) {
hotReloadCallback_();
@@ -129,17 +129,30 @@ namespace Echoion::Plugin
void CoreLoader::waitForTrackAndReload(
const std::filesystem::path& targetPath, const std::string& trackId)
{
ECHOION_LOG_INFO(std::format(
Void::Log::info("CoreLoader", "{}", std::format(
"Waiting for track {} to finish before reload...", trackId));
// Poll every 500ms to check if the specific track finished
// (playback may continue with next track, but we only care about THIS
// track)
// track). The wait is interruptible so the destructor can join this
// thread instead of detaching it (detaching risks use-after-free when
// the plugin unloads mid-wait).
while (isSameTrackPlaying(trackId)) {
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::unique_lock<std::mutex> lock(pendingReloadMutex_);
if (deferredReloadCv_.wait_for(
lock, std::chrono::milliseconds(500),
[this] { return stopDeferredReload_.load(); })) {
Void::Log::info("CoreLoader", "{}",
"Deferred hot-reload cancelled (loader shutting down)");
return;
}
}
ECHOION_LOG_INFO("Track finished, starting hot reload");
if (stopDeferredReload_.load()) {
return;
}
Void::Log::info("CoreLoader", "{}", "Track finished, starting hot reload");
// Clear pending flag
{
@@ -151,10 +164,10 @@ namespace Echoion::Plugin
// Now do the reload
auto result = hotReload(targetPath);
if (!result) {
ECHOION_LOG_ERROR(std::format("Deferred hot-reload failed: {}",
Void::Log::error("CoreLoader", "{}", std::format("Deferred hot-reload failed: {}",
result.error().message));
} else {
ECHOION_LOG_INFO("Deferred hot-reload completed successfully");
Void::Log::info("CoreLoader", "{}", "Deferred hot-reload completed successfully");
// Notify Plugin to re-register callbacks
if (hotReloadCallback_) {
hotReloadCallback_();
@@ -164,13 +177,18 @@ namespace Echoion::Plugin
CoreLoader::~CoreLoader()
{
// Stop any deferred reload thread
// Signal the deferred reload thread to stop and wait for it. It must
// never outlive this object: it dereferences core_ and this.
stopDeferredReload_ = true;
deferredReloadCv_.notify_all();
if (deferredReloadThread_.joinable()) {
// We can't really stop it gracefully, but we can detach it
// to avoid hanging on shutdown
deferredReloadThread_.detach();
deferredReloadThread_.join();
}
if (auto result = unload(); !result) {
Void::Log::warn("CoreLoader", "{}",
std::format("Unload from destructor failed: {}",
result.error().message));
}
unload();
cleanupTempFiles();
}
@@ -179,14 +197,14 @@ namespace Echoion::Plugin
std::lock_guard<std::mutex> lock(mutex_);
if (loaded_) {
return std::unexpected(Api::Error(Api::ErrorCode::AlreadyExists,
"Core already loaded"));
return Api::fail(Api::ErrorCode::AlreadyExists,
"Core already loaded");
}
if (!std::filesystem::exists(libraryPath)) {
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::NotFound,
std::format("Library not found: {}", libraryPath.string())));
std::format("Library not found: {}", libraryPath.string()));
}
tempLibraryPath_ = getTempLibraryPath(libraryPath);
@@ -196,9 +214,9 @@ namespace Echoion::Plugin
libraryPath, tempLibraryPath_,
std::filesystem::copy_options::overwrite_existing);
} catch (const std::exception& e) {
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::UnknownError,
std::format("Failed to copy library to temp: {}", e.what())));
std::format("Failed to copy library to temp: {}", e.what()));
}
auto result = loadLibraryInternal(tempLibraryPath_);
@@ -232,19 +250,19 @@ namespace Echoion::Plugin
std::lock_guard<std::mutex> lock(mutex_);
if (!loaded_) {
return std::unexpected(Api::Error(Api::ErrorCode::NotFound,
"No core loaded to reload"));
return Api::fail(Api::ErrorCode::NotFound,
"No core loaded to reload");
}
hotReloading_ = true;
ECHOION_LOG_INFO("Starting hot reload with temp file...");
Void::Log::info("CoreLoader", "{}", "Starting hot reload with temp file...");
// Step 1: Save state as opaque blob (Plugin doesn't know contents)
Api::StateBlob stateBlob;
if (core_) {
stateBlob = core_->saveState();
ECHOION_LOG_INFO(
Void::Log::info("CoreLoader", "{}",
std::format("Saved state: version={}, size={} bytes",
stateBlob.version, stateBlob.size()));
}
@@ -254,9 +272,9 @@ namespace Echoion::Plugin
if (!std::filesystem::exists(targetPath)) {
hotReloading_ = false;
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::NotFound,
std::format("New library not found: {}", targetPath.string())));
std::format("New library not found: {}", targetPath.string()));
}
std::filesystem::path newTempPath = getTempLibraryPath(targetPath);
@@ -269,10 +287,9 @@ namespace Echoion::Plugin
hotReloading_ = false;
std::error_code ec;
std::filesystem::remove(newTempPath, ec);
return std::unexpected(
Api::Error(Api::ErrorCode::UnknownError,
return Api::fail(Api::ErrorCode::UnknownError,
std::format("Failed to copy new library to temp: {}",
e.what())));
e.what()));
}
auto unloadResult = unloadLibraryInternal();
@@ -301,13 +318,13 @@ namespace Echoion::Plugin
auto coreVersion = core_->getStateFormatVersion();
auto stateVersion = stateBlob.version;
ECHOION_LOG_INFO(std::format("Restoring state v{} to Core v{}",
Void::Log::info("CoreLoader", "{}", std::format("Restoring state v{} to Core v{}",
stateVersion, coreVersion));
if (core_->canRestoreStateVersion(stateVersion)) {
auto restoreResult = core_->restoreState(stateBlob);
if (!restoreResult) {
ECHOION_LOG_ERROR(
Void::Log::error("CoreLoader", "{}",
std::format("Failed to restore state: {}",
restoreResult.error().message));
@@ -315,17 +332,17 @@ namespace Echoion::Plugin
if (restoreResult.error().code ==
Api::ErrorCode::IncompatibleVersion) {
// Signal user to update/restart
ECHOION_LOG_WARNING("State version incompatible. "
Void::Log::warn("CoreLoader", "{}", "State version incompatible. "
"User needs to update/restart.");
// Optionally: notify through plugin interface
}
// Continue with empty state - graceful degradation
} else {
ECHOION_LOG_INFO("State restored successfully");
Void::Log::info("CoreLoader", "{}", "State restored successfully");
}
} else {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("CoreLoader", "{}", std::format(
"Cannot restore state v{} in Core v{}. "
"Version age exceeds maximum supported ({} versions).",
stateVersion, coreVersion,
@@ -337,7 +354,7 @@ namespace Echoion::Plugin
currentLibraryPath_ = targetPath;
hotReloading_ = false;
ECHOION_LOG_INFO("Hot reload complete");
Void::Log::info("CoreLoader", "{}", "Hot reload complete");
return {};
}
@@ -373,7 +390,7 @@ namespace Echoion::Plugin
std::cout << std::format("[Echoion] Loading core library: {}",
path.string())
<< std::endl;
<< '\n';
// Use no decorations - the path already has the correct extension
// (.ts)
library_ = std::make_unique<dylib::library>(
@@ -389,19 +406,18 @@ namespace Echoion::Plugin
if (!compatibleFunc(Api::VERSION_MAJOR, Api::VERSION_MINOR)) {
library_.reset();
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::InvalidArgument,
std::format("API version mismatch. Expected {}.{}, got {}",
Api::VERSION_MAJOR, Api::VERSION_MINOR,
versionFunc())));
versionFunc()));
}
core_ = createFunc();
if (!core_) {
library_.reset();
return std::unexpected(
Api::Error(Api::ErrorCode::UnknownError,
"Failed to create core instance"));
return Api::fail(Api::ErrorCode::UnknownError,
"Failed to create core instance");
}
auto initResult = core_->initialize(configPath_);
@@ -413,22 +429,20 @@ namespace Echoion::Plugin
loaded_ = true;
ECHOION_LOG_INFO(std::format(
Void::Log::info("CoreLoader", "{}", std::format(
"Core library loaded (API version: {})", versionFunc()));
return {};
} catch (const dylib::load_error& e) {
return std::unexpected(Api::Error(
return Api::fail(
Api::ErrorCode::PluginError,
std::format("Failed to load library: {}", e.what())));
std::format("Failed to load library: {}", e.what()));
} catch (const dylib::symbol_error& e) {
return std::unexpected(
Api::Error(Api::ErrorCode::PluginError,
std::format("Failed to find symbol: {}", e.what())));
return Api::fail(Api::ErrorCode::PluginError,
std::format("Failed to find symbol: {}", e.what()));
} catch (const std::exception& e) {
return std::unexpected(
Api::Error(Api::ErrorCode::UnknownError,
std::format("Unexpected error: {}", e.what())));
return Api::fail(Api::ErrorCode::UnknownError,
std::format("Unexpected error: {}", e.what()));
}
}
@@ -438,17 +452,22 @@ namespace Echoion::Plugin
return {};
}
ECHOION_LOG_INFO("Unloading core library...");
Void::Log::info("CoreLoader", "{}", "Unloading core library...");
if (core_) {
core_->shutdown();
if (auto result = core_->shutdown(); !result) {
Void::Log::warn(
"CoreLoader", "{}",
std::format("Core shutdown reported failure: {}",
result.error().message));
}
core_.reset();
}
library_.reset();
loaded_ = false;
std::cout << "[Echoion] Core library unloaded" << std::endl;
std::cout << "[Echoion] Core library unloaded" << '\n';
return {};
}
+1 -1
View File
@@ -85,7 +85,7 @@ namespace Echoion::Plugin
std::cerr
<< std::format("FileWatcher callback error: {}",
e.what())
<< std::endl;
<< '\n';
}
}
}
+209 -71
View File
@@ -3,8 +3,10 @@
#include "echoion/plugin/PluginInterface.hpp"
#include "teamspeak/public_errors.h"
#include <CoreInterface.hpp>
#include <Void/Data/Json.hpp>
#include <Void/Stacktrace/Stacktrace.hpp>
#include <PluginTypes.hpp>
#include <cstdio>
#include <Types.hpp>
#include <atomic>
#include <chrono>
@@ -17,6 +19,7 @@
#include <mutex>
#include <plugin_definitions.h>
#include <thread>
#include <tuple>
#include <ts3_functions.h>
namespace Echoion::Plugin
@@ -94,10 +97,10 @@ namespace Echoion::Plugin
if (g_ts3Functions && g_ts3Functions->getConfigPath &&
g_ts3Functions->getPluginPath) {
g_ts3FunctionsReady.store(true);
std::cout << "[Echoion] TS3 function pointers set" << std::endl;
std::cout << "[Echoion] TS3 function pointers set" << '\n';
} else {
std::cerr << "[Echoion] TS3 function pointers incomplete"
<< std::endl;
<< '\n';
}
}
@@ -113,7 +116,7 @@ namespace Echoion::Plugin
pluginID = std::make_unique<char[]>(sz);
_strcpy(pluginID.get(), sz, id);
std::cout << std::format("[Echoion] Plugin ID: {}", pluginID.get())
<< std::endl;
<< '\n';
}
// Forward declarations for helper functions
@@ -134,7 +137,7 @@ namespace Echoion::Plugin
g_coreLoader->setHotReloadCallback([]() {
std::cout << "[Echoion] Auto-reload callback triggered, "
"re-registering interface..."
<< std::endl;
<< '\n';
reregisterPluginInterface();
});
}
@@ -143,16 +146,16 @@ namespace Echoion::Plugin
g_coreLoader->setConfigPath(getConfigPath());
std::cout << std::format("[Echoion] Config path: {}",
getConfigPath().string())
<< std::endl;
<< '\n';
std::cout << std::format("[Echoion] Loading Core from: {}",
getCorePath().string())
<< std::endl;
<< '\n';
auto loadResult = g_coreLoader->load(getCorePath());
if (!loadResult) {
std::cerr << std::format("[Echoion] Failed to load core: {}",
loadResult.error().message)
<< std::endl;
<< '\n';
return false;
}
@@ -161,21 +164,20 @@ namespace Echoion::Plugin
if (core && g_pluginInterface) {
core->setPluginInterface(g_pluginInterface);
// Register for plugin events from Core
// Register for plugin events from Core. Auto-connect is
// already triggered inside setPluginInterface() above.
g_pluginInterface->registerEventCallback(
[core](const Api::PluginEvent& event) {
core->onPluginEvent(event);
// Core logs dispatch failures itself.
std::ignore = core->onPluginEvent(event);
});
// Trigger auto-connect now that plugin interface is set
core->triggerAutoConnect();
}
return true;
} catch (const std::exception& e) {
std::cerr << std::format("[Echoion] Exception loading core: {}",
e.what())
<< std::endl;
<< '\n';
return false;
}
}
@@ -196,13 +198,13 @@ namespace Echoion::Plugin
if (!g_ts3FunctionsReady.load()) {
std::cerr << "[Echoion] TS3 functions not ready, aborting init"
<< std::endl;
<< '\n';
g_deferredInitRunning = false;
return;
}
std::cout << "[Echoion] Starting deferred initialization..."
<< std::endl;
<< '\n';
try {
// Create plugin interface
@@ -214,7 +216,7 @@ namespace Echoion::Plugin
std::cerr << std::format("[Echoion] Failed to initialize "
"plugin interface: {}",
result.error().message)
<< std::endl;
<< '\n';
g_deferredInitRunning = false;
return;
}
@@ -224,29 +226,29 @@ namespace Echoion::Plugin
if (!deviceResult) {
std::cout << std::format("[Echoion] Audio device skipped: {}",
deviceResult.error().message)
<< std::endl;
<< '\n';
} else {
std::cout << "[Echoion] Audio device registered" << std::endl;
std::cout << "[Echoion] Audio device registered" << '\n';
}
// Load Core library (Core will handle config loading and
// auto-connect)
if (ensureCoreLoaded()) {
std::cout << "[Echoion] Core loaded successfully" << std::endl;
std::cout << "[Echoion] Core loaded successfully" << '\n';
if (g_coreLoader) {
g_coreLoader->enableAutoReload();
}
} else {
std::cout << "[Echoion] Core failed to load" << std::endl;
std::cout << "[Echoion] Core failed to load" << '\n';
}
std::cout << "[Echoion] Initialization complete" << std::endl;
std::cout << "[Echoion] Initialization complete" << '\n';
g_deferredInitComplete = true;
} catch (const std::exception& e) {
std::cerr << std::format("[Echoion] Deferred init failed: {}",
e.what())
<< std::endl;
<< '\n';
}
g_deferredInitRunning = false;
@@ -254,7 +256,7 @@ namespace Echoion::Plugin
TS3_PLUGIN_API int ts3plugin_init()
{
std::cout << "[Echoion] Plugin init started" << std::endl;
std::cout << "[Echoion] Plugin init started" << '\n';
// Install a terminate handler that dumps a symbolized stack trace
// (with source snippets) before the process dies — invaluable for
@@ -265,7 +267,7 @@ namespace Echoion::Plugin
std::cerr << "[Echoion] FATAL: std::terminate — stack trace:\n";
const auto frames = Void::Stacktrace::capture_stacktrace();
std::cerr << Void::Stacktrace::format_stacktrace(frames)
<< std::endl;
<< '\n';
std::abort();
});
});
@@ -276,7 +278,7 @@ namespace Echoion::Plugin
TS3_PLUGIN_API void ts3plugin_shutdown()
{
std::cout << "[Echoion] Shutting down..." << std::endl;
std::cout << "[Echoion] Shutting down..." << '\n';
g_deferredInitRunning = false;
@@ -297,32 +299,35 @@ namespace Echoion::Plugin
}
}
// Teardown is best-effort: failures here can't be acted on and the
// individual calls log their own errors.
if (g_pluginInterface) {
g_pluginInterface->disconnectFromServer();
std::ignore = g_pluginInterface->disconnectFromServer();
}
if (g_coreLoader) {
g_coreLoader->disableAutoReload();
g_coreLoader->unload();
std::ignore = g_coreLoader->unload();
g_coreLoader.reset();
}
if (g_pluginInterface) {
g_pluginInterface->shutdown();
std::ignore = g_pluginInterface->shutdown();
g_pluginInterface = nullptr;
}
g_ts3Functions = nullptr;
g_ts3FunctionsReady = false;
std::cout << "[Echoion] Shutdown complete" << std::endl;
std::cout << "[Echoion] Shutdown complete" << '\n';
}
// Handle incoming text messages
TS3_PLUGIN_API void ts3plugin_onTextMessageEvent(
uint64 serverConnectionHandlerId, anyID targetMode, anyID toID,
anyID fromID, const char* fromName, const char* fromUniqueIdentifier,
const char* message, int ffIgnored)
uint64 serverConnectionHandlerId, anyID targetMode, anyID /*toID*/,
anyID fromID, const char* /*fromName*/,
const char* /*fromUniqueIdentifier*/, const char* message,
int /*ffIgnored*/)
{
anyID myID = 0;
@@ -343,7 +348,7 @@ namespace Echoion::Plugin
// Handle client connect/disconnect
TS3_PLUGIN_API void ts3plugin_onClientMoveEvent(
uint64 serverConnectionHandlerId, anyID clientID, uint64 oldChannelID,
uint64 newChannelID, int visibility, const char* moveMessage)
uint64 newChannelID, int /*visibility*/, const char* /*moveMessage*/)
{
if (!g_pluginInterface) {
@@ -362,9 +367,32 @@ namespace Echoion::Plugin
}
}
TS3_PLUGIN_API void ts3plugin_onClientMoveTimeoutEvent(
// Clients that become visible without moving — e.g. everyone already
// online when the bot itself connects, or channel-subscription changes.
// Without this, subscribers present before a restart never produce a
// ClientConnected event and restored playback stays paused.
TS3_PLUGIN_API void ts3plugin_onClientMoveSubscriptionEvent(
uint64 serverConnectionHandlerId, anyID clientID, uint64 oldChannelID,
uint64 newChannelID, int visibility, const char* timeoutMessage)
uint64 newChannelID, int /*visibility*/)
{
if (!g_pluginInterface) {
return;
}
if (oldChannelID == 0) {
g_pluginInterface->onClientConnected(serverConnectionHandlerId,
clientID);
} else if (newChannelID == 0) {
g_pluginInterface->onClientDisconnected(serverConnectionHandlerId,
clientID);
}
}
TS3_PLUGIN_API void ts3plugin_onClientMoveTimeoutEvent(
uint64 serverConnectionHandlerId, anyID clientID,
uint64 /*oldChannelID*/, uint64 /*newChannelID*/, int /*visibility*/,
const char* /*timeoutMessage*/)
{
if (g_pluginInterface) {
@@ -380,52 +408,55 @@ namespace Echoion::Plugin
if (!g_coreLoader) {
std::cerr
<< "[Echoion] Cannot re-register: CoreLoader not available"
<< std::endl;
<< '\n';
return false;
}
std::cout
<< "[Echoion] Re-registering plugin interface after hot reload..."
<< std::endl;
<< '\n';
// Get the new core instance
auto core = g_coreLoader->getCore();
if (!core) {
std::cerr << "[Echoion] ERROR: Core is null!" << std::endl;
std::cerr << "[Echoion] ERROR: Core is null!" << '\n';
return false;
}
if (!g_pluginInterface) {
std::cerr << "[Echoion] ERROR: PluginInterface is null!"
<< std::endl;
<< '\n';
return false;
}
std::cout << std::format("[Echoion] New Core pointer: {}",
reinterpret_cast<uintptr_t>(core.get()))
<< std::endl;
<< '\n';
// Set the plugin interface first (before registering callbacks)
core->setPluginInterface(g_pluginInterface);
std::cout << "[Echoion] Plugin interface set on new Core" << std::endl;
std::cout << "[Echoion] Plugin interface set on new Core" << '\n';
// Clear old callbacks (they point to destroyed Core) and register new
// one
std::cout << "[Echoion] About to clear callbacks..." << std::endl;
std::cout << "[Echoion] About to clear callbacks..." << '\n';
g_pluginInterface->clearEventCallbacks();
std::cout << "[Echoion] Old event callbacks cleared" << std::endl;
std::cout << "[Echoion] Old event callbacks cleared" << '\n';
std::cout << "[Echoion] About to register new callback..." << std::endl;
std::cout << "[Echoion] About to register new callback..." << '\n';
g_pluginInterface->registerEventCallback(
[core](const Api::PluginEvent& event) {
core->onPluginEvent(event);
// Core logs dispatch failures itself.
std::ignore = core->onPluginEvent(event);
});
std::cout << "[Echoion] New event callback registered" << std::endl;
core->skip(0);
core->resume();
std::cout << "[Echoion] New event callback registered" << '\n';
// Best-effort nudge so playback resumes after the reload; failures
// only mean nothing was playing.
std::ignore = core->skip(0);
std::ignore = core->resume();
std::cout << "[Echoion] Re-registration complete - bot should respond "
"to commands"
<< std::endl;
<< '\n';
return true;
}
@@ -435,17 +466,17 @@ namespace Echoion::Plugin
{
if (!g_coreLoader) {
std::cerr << "[Echoion] Cannot reload: CoreLoader not available"
<< std::endl;
<< '\n';
return false;
}
std::cout << "[Echoion] Starting hot reload (Plugin)..." << std::endl;
std::cout << "[Echoion] Starting hot reload (Plugin)..." << '\n';
auto result = g_coreLoader->hotReload(getCorePath());
if (!result) {
std::cerr << std::format("[Echoion] Hot reload failed: {}",
result.error().message)
<< std::endl;
<< '\n';
return false;
}
@@ -455,8 +486,8 @@ namespace Echoion::Plugin
// Handle plugin commands from TS3
TS3_PLUGIN_API void
ts3plugin_onPluginCommandEvent(uint64 serverConnectionHandlerId,
const char* pluginName,
ts3plugin_onPluginCommandEvent(uint64 /*serverConnectionHandlerId*/,
const char* /*pluginName*/,
const char* command)
{
@@ -467,11 +498,48 @@ namespace Echoion::Plugin
}
}
// Global plugin menu. Item ids match the existing
// ts3plugin_onMenuItemEvent handler below (1..5).
TS3_PLUGIN_API void ts3plugin_initMenus(struct PluginMenuItem*** menuItems,
char** menuIcon)
{
struct Entry {
int id;
const char* text;
};
static constexpr Entry entries[] = {
{1, "Play / Pause"}, {2, "Skip Track"},
{3, "Stop Playback"}, {4, "Hot Reload Core"},
{5, "Connect / Disconnect"},
};
constexpr size_t count = std::size(entries);
// The client frees each item, the array and the icon string via
// ts3plugin_freeMemory, so everything must come from malloc.
auto** items = static_cast<PluginMenuItem**>(
std::malloc((count + 1) * sizeof(PluginMenuItem*)));
for (size_t i = 0; i < count; ++i) {
auto* item = static_cast<PluginMenuItem*>(
std::malloc(sizeof(PluginMenuItem)));
item->type = PLUGIN_MENU_TYPE_GLOBAL;
item->id = entries[i].id;
std::snprintf(item->text, PLUGIN_MENU_BUFSZ, "%s",
entries[i].text);
item->icon[0] = '\0';
items[i] = item;
}
items[count] = nullptr;
*menuItems = items;
*menuIcon = nullptr;
}
TS3_PLUGIN_API void ts3plugin_freeMemory(void* data) { std::free(data); }
// Menu item callbacks
TS3_PLUGIN_API void
ts3plugin_onMenuItemEvent(uint64 serverConnectionHandlerId,
enum PluginMenuType type, int menuItemID,
uint64 selectedItemID)
ts3plugin_onMenuItemEvent(uint64 /*serverConnectionHandlerId*/,
enum PluginMenuType /*type*/, int menuItemID,
uint64 /*selectedItemID*/)
{
if (!ensureCoreLoaded()) {
@@ -483,24 +551,26 @@ namespace Echoion::Plugin
return;
}
// Menu actions are fire-and-forget: Core logs failures and there is
// no channel to report them back through the TS3 menu.
switch (menuItemID) {
case 1:
{ // Play/Pause
auto state = core->getPlaybackSummary();
if (state) {
if (state->isPlaying && !state->isPaused) {
core->pause();
std::ignore = core->pause();
} else if (state->isPaused) {
core->resume();
std::ignore = core->resume();
}
}
break;
}
case 2: // Skip
core->skip(1);
std::ignore = core->skip(1);
break;
case 3: // Stop
core->stop();
std::ignore = core->stop();
break;
case 4: // Hot Reload Core
reloadCoreWithInterface();
@@ -508,7 +578,8 @@ namespace Echoion::Plugin
case 5: // Connect/Disconnect
if (g_pluginInterface) {
if (g_pluginInterface->isConnected()) {
g_pluginInterface->disconnectFromServer();
std::ignore =
g_pluginInterface->disconnectFromServer();
} else {
// Core handles connection, just trigger reconnect
if (auto result = g_pluginInterface->reconnect();
@@ -516,7 +587,7 @@ namespace Echoion::Plugin
std::cerr
<< std::format("[Echoion] Reconnect failed: {}",
result.error().message)
<< std::endl;
<< '\n';
}
}
}
@@ -524,11 +595,70 @@ namespace Echoion::Plugin
}
}
// Move the bot into teamspeak.defaultChannelId (config) once fully
// connected. No-op when the option is absent/non-numeric or the bot is
// already there.
static void joinDefaultChannel(uint64 serverConnectionHandlerId)
{
if (!g_ts3Functions || !ensureCoreLoaded()) {
return;
}
auto core = g_coreLoader->getCore();
if (!core) {
return;
}
auto configJson = core->getConfigJson();
if (!configJson) {
return;
}
auto parsed = Void::Json::parse(*configJson);
if (!parsed) {
return;
}
const auto* teamspeak = parsed->find("teamspeak");
const auto* channel =
teamspeak ? teamspeak->find("defaultChannelId") : nullptr;
if (!channel || !channel->is_string()) {
return;
}
uint64 targetChannel = 0;
try {
targetChannel = std::stoull(channel->as_string());
} catch (const std::exception&) {
std::cerr << "[Echoion] defaultChannelId is not numeric, "
"skipping auto-join"
<< '\n';
return;
}
if (targetChannel == 0) {
return;
}
anyID myId = 0;
if (g_ts3Functions->getClientID(serverConnectionHandlerId, &myId) !=
ERROR_ok) {
return;
}
uint64 currentChannel = 0;
if (g_ts3Functions->getChannelOfClient(serverConnectionHandlerId,
myId, &currentChannel) ==
ERROR_ok &&
currentChannel == targetChannel) {
return; // already there
}
std::cout << std::format("[Echoion] Auto-joining channel {}",
targetChannel)
<< '\n';
g_ts3Functions->requestClientMove(serverConnectionHandlerId, myId,
targetChannel, "", nullptr);
}
// Connection status changes
TS3_PLUGIN_API void
ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerId,
int newStatus,
unsigned int errorNumber)
unsigned int /*errorNumber*/)
{
if (g_pluginInterface) {
@@ -538,22 +668,30 @@ namespace Echoion::Plugin
switch (newStatus) {
case STATUS_CONNECTING:
std::cout << "[Echoion] Connecting..." << std::endl;
std::cout << "[Echoion] Connecting..." << '\n';
break;
case STATUS_CONNECTED:
std::cout << "[Echoion] Connected" << std::endl;
std::cout << "[Echoion] Connected" << '\n';
if (g_pluginInterface) {
g_pluginInterface->closeAudioDevice();
g_pluginInterface->openAudioDevice();
// Cycle the device best-effort; both calls log errors.
std::ignore = g_pluginInterface->closeAudioDevice();
std::ignore = g_pluginInterface->openAudioDevice();
}
break;
case STATUS_CONNECTION_ESTABLISHED:
std::cout << "[Echoion] Connection established" << std::endl;
std::cout << "[Echoion] Connection established" << '\n';
joinDefaultChannel(serverConnectionHandlerId);
// Tell the core the client list is now available so it can
// resolve online subscribers and resume a restored session.
if (g_pluginInterface) {
g_pluginInterface->onConnectionEstablished(
serverConnectionHandlerId);
}
break;
case STATUS_DISCONNECTED:
std::cout << "[Echoion] Disconnected" << std::endl;
std::cout << "[Echoion] Disconnected" << '\n';
if (g_pluginInterface) {
g_pluginInterface->closeAudioDevice();
std::ignore = g_pluginInterface->closeAudioDevice();
}
break;
}
+452 -177
View File
File diff suppressed because it is too large. Load diff