Compare commits
8
Commits
df1ea8d53f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
470ab507e1 | ||
|
|
06379fbd5c | ||
|
|
446416c723 | ||
|
|
ac88cd6eb1 | ||
|
|
a356251c83 | ||
|
|
9a61e01fda | ||
|
|
b313ed7101 | ||
|
|
7c58af92cd |
No files matched your search
+3
-1
@@ -31,13 +31,15 @@ target_compile_definitions(EchoionPlugin PUBLIC PLUGIN=1)
|
|||||||
# - ApiOpaque (OpaqueHandle for type-safe void*)
|
# - ApiOpaque (OpaqueHandle for type-safe void*)
|
||||||
# - ApiPluginInterface (IPluginInterface to implement)
|
# - ApiPluginInterface (IPluginInterface to implement)
|
||||||
# - ApiCoreInterface (ICoreInterface to call Core - decoupled)
|
# - ApiCoreInterface (ICoreInterface to call Core - decoupled)
|
||||||
target_link_libraries(EchoionPlugin PRIVATE
|
target_link_libraries(EchoionPlugin PRIVATE
|
||||||
Echoion::ApiBase
|
Echoion::ApiBase
|
||||||
Echoion::ApiPlugin
|
Echoion::ApiPlugin
|
||||||
Echoion::ApiOpaque
|
Echoion::ApiOpaque
|
||||||
Echoion::ApiPluginInterface
|
Echoion::ApiPluginInterface
|
||||||
Echoion::ApiLogger
|
Echoion::ApiLogger
|
||||||
Echoion::ApiCoreInterface
|
Echoion::ApiCoreInterface
|
||||||
|
Void::Data
|
||||||
|
Void::Stacktrace
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(dylib CONFIG REQUIRED)
|
find_package(dylib CONFIG REQUIRED)
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ namespace Echoion::Plugin
|
|||||||
// Deferred reload - waits for current track to finish
|
// Deferred reload - waits for current track to finish
|
||||||
std::thread deferredReloadThread_;
|
std::thread deferredReloadThread_;
|
||||||
std::atomic<bool> hasPendingReload_{false};
|
std::atomic<bool> hasPendingReload_{false};
|
||||||
|
std::atomic<bool> stopDeferredReload_{false};
|
||||||
|
std::condition_variable deferredReloadCv_;
|
||||||
std::filesystem::path pendingReloadPath_;
|
std::filesystem::path pendingReloadPath_;
|
||||||
std::string pendingTrackId_; // Track ID that was playing when
|
std::string pendingTrackId_; // Track ID that was playing when
|
||||||
// reload scheduled
|
// reload scheduled
|
||||||
|
|||||||
@@ -55,6 +55,15 @@ namespace Echoion::Plugin
|
|||||||
getClients() override;
|
getClients() override;
|
||||||
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>>
|
[[nodiscard]] Api::Result<std::optional<Api::ClientInfo>>
|
||||||
getClient(uint64_t clientId) override;
|
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,
|
Api::Result<void> moveClient(uint64_t clientId,
|
||||||
uint64_t channelId) override;
|
uint64_t channelId) override;
|
||||||
Api::Result<void> kickClient(uint64_t clientId,
|
Api::Result<void> kickClient(uint64_t clientId,
|
||||||
@@ -90,6 +99,7 @@ namespace Echoion::Plugin
|
|||||||
void clearEventCallbacks();
|
void clearEventCallbacks();
|
||||||
|
|
||||||
// TeamSpeak event handlers (called by TeamSpeak SDK)
|
// TeamSpeak event handlers (called by TeamSpeak SDK)
|
||||||
|
void onConnectionEstablished(uint64_t serverConnectionHandlerId);
|
||||||
void onClientConnected(uint64_t serverConnectionHandlerId,
|
void onClientConnected(uint64_t serverConnectionHandlerId,
|
||||||
uint64_t clientId);
|
uint64_t clientId);
|
||||||
void onClientDisconnected(uint64_t serverConnectionHandlerId,
|
void onClientDisconnected(uint64_t serverConnectionHandlerId,
|
||||||
|
|||||||
+76
-57
@@ -1,4 +1,4 @@
|
|||||||
#include "LoggerInterface.hpp"
|
#include <Void/Log/Log.hpp>
|
||||||
#include "dylib.hpp"
|
#include "dylib.hpp"
|
||||||
#include "echoion/plugin/CoreLoader.hpp"
|
#include "echoion/plugin/CoreLoader.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -21,7 +21,7 @@ namespace Echoion::Plugin
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
if (!currentLibraryPath_.empty() &&
|
if (!currentLibraryPath_.empty() &&
|
||||||
std::filesystem::exists(currentLibraryPath_)) {
|
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()));
|
currentLibraryPath_.string()));
|
||||||
|
|
||||||
fileWatcher_.startWatching(currentLibraryPath_,
|
fileWatcher_.startWatching(currentLibraryPath_,
|
||||||
@@ -33,7 +33,7 @@ namespace Echoion::Plugin
|
|||||||
{
|
{
|
||||||
autoReloadEnabled_ = false;
|
autoReloadEnabled_ = false;
|
||||||
fileWatcher_.stopWatching();
|
fileWatcher_.stopWatching();
|
||||||
ECHOION_LOG_INFO("Auto-reload disabled");
|
Void::Log::info("CoreLoader", "{}", "Auto-reload disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoreLoader::isAutoReloadEnabled() const noexcept
|
bool CoreLoader::isAutoReloadEnabled() const noexcept
|
||||||
@@ -47,7 +47,7 @@ namespace Echoion::Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ECHOION_LOG_INFO(
|
Void::Log::info("CoreLoader", "{}",
|
||||||
"Core file changed, scheduling hot reload after current track...");
|
"Core file changed, scheduling hot reload after current track...");
|
||||||
|
|
||||||
// Small delay to ensure file write is complete
|
// 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 "
|
std::format("Playback active (track: {}), deferring reload "
|
||||||
"until track finishes",
|
"until track finishes",
|
||||||
currentTrackId));
|
currentTrackId));
|
||||||
@@ -85,10 +85,10 @@ namespace Echoion::Plugin
|
|||||||
// No playback, reload immediately
|
// No playback, reload immediately
|
||||||
auto result = hotReload(currentLibraryPath_);
|
auto result = hotReload(currentLibraryPath_);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
ECHOION_LOG_ERROR(std::format("Auto hot-reload failed: {}",
|
Void::Log::error("CoreLoader", "{}", std::format("Auto hot-reload failed: {}",
|
||||||
result.error().message));
|
result.error().message));
|
||||||
} else {
|
} else {
|
||||||
ECHOION_LOG_INFO("Auto hot-reload completed successfully");
|
Void::Log::info("CoreLoader", "{}", "Auto hot-reload completed successfully");
|
||||||
// Notify Plugin to re-register callbacks
|
// Notify Plugin to re-register callbacks
|
||||||
if (hotReloadCallback_) {
|
if (hotReloadCallback_) {
|
||||||
hotReloadCallback_();
|
hotReloadCallback_();
|
||||||
@@ -129,17 +129,30 @@ namespace Echoion::Plugin
|
|||||||
void CoreLoader::waitForTrackAndReload(
|
void CoreLoader::waitForTrackAndReload(
|
||||||
const std::filesystem::path& targetPath, const std::string& trackId)
|
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));
|
"Waiting for track {} to finish before reload...", trackId));
|
||||||
|
|
||||||
// Poll every 500ms to check if the specific track finished
|
// Poll every 500ms to check if the specific track finished
|
||||||
// (playback may continue with next track, but we only care about THIS
|
// (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)) {
|
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
|
// Clear pending flag
|
||||||
{
|
{
|
||||||
@@ -151,10 +164,10 @@ namespace Echoion::Plugin
|
|||||||
// Now do the reload
|
// Now do the reload
|
||||||
auto result = hotReload(targetPath);
|
auto result = hotReload(targetPath);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
ECHOION_LOG_ERROR(std::format("Deferred hot-reload failed: {}",
|
Void::Log::error("CoreLoader", "{}", std::format("Deferred hot-reload failed: {}",
|
||||||
result.error().message));
|
result.error().message));
|
||||||
} else {
|
} else {
|
||||||
ECHOION_LOG_INFO("Deferred hot-reload completed successfully");
|
Void::Log::info("CoreLoader", "{}", "Deferred hot-reload completed successfully");
|
||||||
// Notify Plugin to re-register callbacks
|
// Notify Plugin to re-register callbacks
|
||||||
if (hotReloadCallback_) {
|
if (hotReloadCallback_) {
|
||||||
hotReloadCallback_();
|
hotReloadCallback_();
|
||||||
@@ -164,13 +177,18 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
CoreLoader::~CoreLoader()
|
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()) {
|
if (deferredReloadThread_.joinable()) {
|
||||||
// We can't really stop it gracefully, but we can detach it
|
deferredReloadThread_.join();
|
||||||
// to avoid hanging on shutdown
|
}
|
||||||
deferredReloadThread_.detach();
|
if (auto result = unload(); !result) {
|
||||||
|
Void::Log::warn("CoreLoader", "{}",
|
||||||
|
std::format("Unload from destructor failed: {}",
|
||||||
|
result.error().message));
|
||||||
}
|
}
|
||||||
unload();
|
|
||||||
cleanupTempFiles();
|
cleanupTempFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,14 +197,14 @@ namespace Echoion::Plugin
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
if (loaded_) {
|
if (loaded_) {
|
||||||
return std::unexpected(Api::Error(Api::ErrorCode::AlreadyExists,
|
return Api::fail(Api::ErrorCode::AlreadyExists,
|
||||||
"Core already loaded"));
|
"Core already loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!std::filesystem::exists(libraryPath)) {
|
if (!std::filesystem::exists(libraryPath)) {
|
||||||
return std::unexpected(Api::Error(
|
return Api::fail(
|
||||||
Api::ErrorCode::NotFound,
|
Api::ErrorCode::NotFound,
|
||||||
std::format("Library not found: {}", libraryPath.string())));
|
std::format("Library not found: {}", libraryPath.string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
tempLibraryPath_ = getTempLibraryPath(libraryPath);
|
tempLibraryPath_ = getTempLibraryPath(libraryPath);
|
||||||
@@ -196,9 +214,9 @@ namespace Echoion::Plugin
|
|||||||
libraryPath, tempLibraryPath_,
|
libraryPath, tempLibraryPath_,
|
||||||
std::filesystem::copy_options::overwrite_existing);
|
std::filesystem::copy_options::overwrite_existing);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return std::unexpected(Api::Error(
|
return Api::fail(
|
||||||
Api::ErrorCode::UnknownError,
|
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_);
|
auto result = loadLibraryInternal(tempLibraryPath_);
|
||||||
@@ -232,19 +250,19 @@ namespace Echoion::Plugin
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
if (!loaded_) {
|
if (!loaded_) {
|
||||||
return std::unexpected(Api::Error(Api::ErrorCode::NotFound,
|
return Api::fail(Api::ErrorCode::NotFound,
|
||||||
"No core loaded to reload"));
|
"No core loaded to reload");
|
||||||
}
|
}
|
||||||
|
|
||||||
hotReloading_ = true;
|
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)
|
// Step 1: Save state as opaque blob (Plugin doesn't know contents)
|
||||||
Api::StateBlob stateBlob;
|
Api::StateBlob stateBlob;
|
||||||
if (core_) {
|
if (core_) {
|
||||||
stateBlob = core_->saveState();
|
stateBlob = core_->saveState();
|
||||||
ECHOION_LOG_INFO(
|
Void::Log::info("CoreLoader", "{}",
|
||||||
std::format("Saved state: version={}, size={} bytes",
|
std::format("Saved state: version={}, size={} bytes",
|
||||||
stateBlob.version, stateBlob.size()));
|
stateBlob.version, stateBlob.size()));
|
||||||
}
|
}
|
||||||
@@ -254,9 +272,9 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
if (!std::filesystem::exists(targetPath)) {
|
if (!std::filesystem::exists(targetPath)) {
|
||||||
hotReloading_ = false;
|
hotReloading_ = false;
|
||||||
return std::unexpected(Api::Error(
|
return Api::fail(
|
||||||
Api::ErrorCode::NotFound,
|
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);
|
std::filesystem::path newTempPath = getTempLibraryPath(targetPath);
|
||||||
@@ -269,10 +287,9 @@ namespace Echoion::Plugin
|
|||||||
hotReloading_ = false;
|
hotReloading_ = false;
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
std::filesystem::remove(newTempPath, ec);
|
std::filesystem::remove(newTempPath, ec);
|
||||||
return std::unexpected(
|
return Api::fail(Api::ErrorCode::UnknownError,
|
||||||
Api::Error(Api::ErrorCode::UnknownError,
|
|
||||||
std::format("Failed to copy new library to temp: {}",
|
std::format("Failed to copy new library to temp: {}",
|
||||||
e.what())));
|
e.what()));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto unloadResult = unloadLibraryInternal();
|
auto unloadResult = unloadLibraryInternal();
|
||||||
@@ -301,13 +318,13 @@ namespace Echoion::Plugin
|
|||||||
auto coreVersion = core_->getStateFormatVersion();
|
auto coreVersion = core_->getStateFormatVersion();
|
||||||
auto stateVersion = stateBlob.version;
|
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));
|
stateVersion, coreVersion));
|
||||||
|
|
||||||
if (core_->canRestoreStateVersion(stateVersion)) {
|
if (core_->canRestoreStateVersion(stateVersion)) {
|
||||||
auto restoreResult = core_->restoreState(stateBlob);
|
auto restoreResult = core_->restoreState(stateBlob);
|
||||||
if (!restoreResult) {
|
if (!restoreResult) {
|
||||||
ECHOION_LOG_ERROR(
|
Void::Log::error("CoreLoader", "{}",
|
||||||
std::format("Failed to restore state: {}",
|
std::format("Failed to restore state: {}",
|
||||||
restoreResult.error().message));
|
restoreResult.error().message));
|
||||||
|
|
||||||
@@ -315,17 +332,17 @@ namespace Echoion::Plugin
|
|||||||
if (restoreResult.error().code ==
|
if (restoreResult.error().code ==
|
||||||
Api::ErrorCode::IncompatibleVersion) {
|
Api::ErrorCode::IncompatibleVersion) {
|
||||||
// Signal user to update/restart
|
// Signal user to update/restart
|
||||||
ECHOION_LOG_WARNING("State version incompatible. "
|
Void::Log::warn("CoreLoader", "{}", "State version incompatible. "
|
||||||
"User needs to update/restart.");
|
"User needs to update/restart.");
|
||||||
// Optionally: notify through plugin interface
|
// Optionally: notify through plugin interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue with empty state - graceful degradation
|
// Continue with empty state - graceful degradation
|
||||||
} else {
|
} else {
|
||||||
ECHOION_LOG_INFO("State restored successfully");
|
Void::Log::info("CoreLoader", "{}", "State restored successfully");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ECHOION_LOG_WARNING(std::format(
|
Void::Log::warn("CoreLoader", "{}", std::format(
|
||||||
"Cannot restore state v{} in Core v{}. "
|
"Cannot restore state v{} in Core v{}. "
|
||||||
"Version age exceeds maximum supported ({} versions).",
|
"Version age exceeds maximum supported ({} versions).",
|
||||||
stateVersion, coreVersion,
|
stateVersion, coreVersion,
|
||||||
@@ -337,7 +354,7 @@ namespace Echoion::Plugin
|
|||||||
currentLibraryPath_ = targetPath;
|
currentLibraryPath_ = targetPath;
|
||||||
hotReloading_ = false;
|
hotReloading_ = false;
|
||||||
|
|
||||||
ECHOION_LOG_INFO("Hot reload complete");
|
Void::Log::info("CoreLoader", "{}", "Hot reload complete");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,7 +390,7 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
std::cout << std::format("[Echoion] Loading core library: {}",
|
std::cout << std::format("[Echoion] Loading core library: {}",
|
||||||
path.string())
|
path.string())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
// Use no decorations - the path already has the correct extension
|
// Use no decorations - the path already has the correct extension
|
||||||
// (.ts)
|
// (.ts)
|
||||||
library_ = std::make_unique<dylib::library>(
|
library_ = std::make_unique<dylib::library>(
|
||||||
@@ -389,19 +406,18 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
if (!compatibleFunc(Api::VERSION_MAJOR, Api::VERSION_MINOR)) {
|
if (!compatibleFunc(Api::VERSION_MAJOR, Api::VERSION_MINOR)) {
|
||||||
library_.reset();
|
library_.reset();
|
||||||
return std::unexpected(Api::Error(
|
return Api::fail(
|
||||||
Api::ErrorCode::InvalidArgument,
|
Api::ErrorCode::InvalidArgument,
|
||||||
std::format("API version mismatch. Expected {}.{}, got {}",
|
std::format("API version mismatch. Expected {}.{}, got {}",
|
||||||
Api::VERSION_MAJOR, Api::VERSION_MINOR,
|
Api::VERSION_MAJOR, Api::VERSION_MINOR,
|
||||||
versionFunc())));
|
versionFunc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
core_ = createFunc();
|
core_ = createFunc();
|
||||||
if (!core_) {
|
if (!core_) {
|
||||||
library_.reset();
|
library_.reset();
|
||||||
return std::unexpected(
|
return Api::fail(Api::ErrorCode::UnknownError,
|
||||||
Api::Error(Api::ErrorCode::UnknownError,
|
"Failed to create core instance");
|
||||||
"Failed to create core instance"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto initResult = core_->initialize(configPath_);
|
auto initResult = core_->initialize(configPath_);
|
||||||
@@ -413,22 +429,20 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
loaded_ = true;
|
loaded_ = true;
|
||||||
|
|
||||||
ECHOION_LOG_INFO(std::format(
|
Void::Log::info("CoreLoader", "{}", std::format(
|
||||||
"Core library loaded (API version: {})", versionFunc()));
|
"Core library loaded (API version: {})", versionFunc()));
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
} catch (const dylib::load_error& e) {
|
} catch (const dylib::load_error& e) {
|
||||||
return std::unexpected(Api::Error(
|
return Api::fail(
|
||||||
Api::ErrorCode::PluginError,
|
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) {
|
} catch (const dylib::symbol_error& e) {
|
||||||
return std::unexpected(
|
return Api::fail(Api::ErrorCode::PluginError,
|
||||||
Api::Error(Api::ErrorCode::PluginError,
|
std::format("Failed to find symbol: {}", e.what()));
|
||||||
std::format("Failed to find symbol: {}", e.what())));
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
return std::unexpected(
|
return Api::fail(Api::ErrorCode::UnknownError,
|
||||||
Api::Error(Api::ErrorCode::UnknownError,
|
std::format("Unexpected error: {}", e.what()));
|
||||||
std::format("Unexpected error: {}", e.what())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,17 +452,22 @@ namespace Echoion::Plugin
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ECHOION_LOG_INFO("Unloading core library...");
|
Void::Log::info("CoreLoader", "{}", "Unloading core library...");
|
||||||
|
|
||||||
if (core_) {
|
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();
|
core_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
library_.reset();
|
library_.reset();
|
||||||
|
|
||||||
loaded_ = false;
|
loaded_ = false;
|
||||||
std::cout << "[Echoion] Core library unloaded" << std::endl;
|
std::cout << "[Echoion] Core library unloaded" << '\n';
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -85,7 +85,7 @@ namespace Echoion::Plugin
|
|||||||
std::cerr
|
std::cerr
|
||||||
<< std::format("FileWatcher callback error: {}",
|
<< std::format("FileWatcher callback error: {}",
|
||||||
e.what())
|
e.what())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+224
-70
@@ -3,7 +3,10 @@
|
|||||||
#include "echoion/plugin/PluginInterface.hpp"
|
#include "echoion/plugin/PluginInterface.hpp"
|
||||||
#include "teamspeak/public_errors.h"
|
#include "teamspeak/public_errors.h"
|
||||||
#include <CoreInterface.hpp>
|
#include <CoreInterface.hpp>
|
||||||
|
#include <Void/Data/Json.hpp>
|
||||||
|
#include <Void/Stacktrace/Stacktrace.hpp>
|
||||||
#include <PluginTypes.hpp>
|
#include <PluginTypes.hpp>
|
||||||
|
#include <cstdio>
|
||||||
#include <Types.hpp>
|
#include <Types.hpp>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -16,6 +19,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <plugin_definitions.h>
|
#include <plugin_definitions.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <tuple>
|
||||||
#include <ts3_functions.h>
|
#include <ts3_functions.h>
|
||||||
|
|
||||||
namespace Echoion::Plugin
|
namespace Echoion::Plugin
|
||||||
@@ -93,10 +97,10 @@ namespace Echoion::Plugin
|
|||||||
if (g_ts3Functions && g_ts3Functions->getConfigPath &&
|
if (g_ts3Functions && g_ts3Functions->getConfigPath &&
|
||||||
g_ts3Functions->getPluginPath) {
|
g_ts3Functions->getPluginPath) {
|
||||||
g_ts3FunctionsReady.store(true);
|
g_ts3FunctionsReady.store(true);
|
||||||
std::cout << "[Echoion] TS3 function pointers set" << std::endl;
|
std::cout << "[Echoion] TS3 function pointers set" << '\n';
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "[Echoion] TS3 function pointers incomplete"
|
std::cerr << "[Echoion] TS3 function pointers incomplete"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +116,7 @@ namespace Echoion::Plugin
|
|||||||
pluginID = std::make_unique<char[]>(sz);
|
pluginID = std::make_unique<char[]>(sz);
|
||||||
_strcpy(pluginID.get(), sz, id);
|
_strcpy(pluginID.get(), sz, id);
|
||||||
std::cout << std::format("[Echoion] Plugin ID: {}", pluginID.get())
|
std::cout << std::format("[Echoion] Plugin ID: {}", pluginID.get())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forward declarations for helper functions
|
// Forward declarations for helper functions
|
||||||
@@ -133,7 +137,7 @@ namespace Echoion::Plugin
|
|||||||
g_coreLoader->setHotReloadCallback([]() {
|
g_coreLoader->setHotReloadCallback([]() {
|
||||||
std::cout << "[Echoion] Auto-reload callback triggered, "
|
std::cout << "[Echoion] Auto-reload callback triggered, "
|
||||||
"re-registering interface..."
|
"re-registering interface..."
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
reregisterPluginInterface();
|
reregisterPluginInterface();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -142,16 +146,16 @@ namespace Echoion::Plugin
|
|||||||
g_coreLoader->setConfigPath(getConfigPath());
|
g_coreLoader->setConfigPath(getConfigPath());
|
||||||
std::cout << std::format("[Echoion] Config path: {}",
|
std::cout << std::format("[Echoion] Config path: {}",
|
||||||
getConfigPath().string())
|
getConfigPath().string())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
|
|
||||||
std::cout << std::format("[Echoion] Loading Core from: {}",
|
std::cout << std::format("[Echoion] Loading Core from: {}",
|
||||||
getCorePath().string())
|
getCorePath().string())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
auto loadResult = g_coreLoader->load(getCorePath());
|
auto loadResult = g_coreLoader->load(getCorePath());
|
||||||
if (!loadResult) {
|
if (!loadResult) {
|
||||||
std::cerr << std::format("[Echoion] Failed to load core: {}",
|
std::cerr << std::format("[Echoion] Failed to load core: {}",
|
||||||
loadResult.error().message)
|
loadResult.error().message)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,21 +164,20 @@ namespace Echoion::Plugin
|
|||||||
if (core && g_pluginInterface) {
|
if (core && g_pluginInterface) {
|
||||||
core->setPluginInterface(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(
|
g_pluginInterface->registerEventCallback(
|
||||||
[core](const Api::PluginEvent& event) {
|
[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;
|
return true;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << std::format("[Echoion] Exception loading core: {}",
|
std::cerr << std::format("[Echoion] Exception loading core: {}",
|
||||||
e.what())
|
e.what())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,13 +198,13 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
if (!g_ts3FunctionsReady.load()) {
|
if (!g_ts3FunctionsReady.load()) {
|
||||||
std::cerr << "[Echoion] TS3 functions not ready, aborting init"
|
std::cerr << "[Echoion] TS3 functions not ready, aborting init"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
g_deferredInitRunning = false;
|
g_deferredInitRunning = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[Echoion] Starting deferred initialization..."
|
std::cout << "[Echoion] Starting deferred initialization..."
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create plugin interface
|
// Create plugin interface
|
||||||
@@ -213,7 +216,7 @@ namespace Echoion::Plugin
|
|||||||
std::cerr << std::format("[Echoion] Failed to initialize "
|
std::cerr << std::format("[Echoion] Failed to initialize "
|
||||||
"plugin interface: {}",
|
"plugin interface: {}",
|
||||||
result.error().message)
|
result.error().message)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
g_deferredInitRunning = false;
|
g_deferredInitRunning = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -223,29 +226,29 @@ namespace Echoion::Plugin
|
|||||||
if (!deviceResult) {
|
if (!deviceResult) {
|
||||||
std::cout << std::format("[Echoion] Audio device skipped: {}",
|
std::cout << std::format("[Echoion] Audio device skipped: {}",
|
||||||
deviceResult.error().message)
|
deviceResult.error().message)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
} else {
|
} 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
|
// Load Core library (Core will handle config loading and
|
||||||
// auto-connect)
|
// auto-connect)
|
||||||
if (ensureCoreLoaded()) {
|
if (ensureCoreLoaded()) {
|
||||||
std::cout << "[Echoion] Core loaded successfully" << std::endl;
|
std::cout << "[Echoion] Core loaded successfully" << '\n';
|
||||||
if (g_coreLoader) {
|
if (g_coreLoader) {
|
||||||
g_coreLoader->enableAutoReload();
|
g_coreLoader->enableAutoReload();
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
g_deferredInitComplete = true;
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << std::format("[Echoion] Deferred init failed: {}",
|
std::cerr << std::format("[Echoion] Deferred init failed: {}",
|
||||||
e.what())
|
e.what())
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
g_deferredInitRunning = false;
|
g_deferredInitRunning = false;
|
||||||
@@ -253,14 +256,29 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
TS3_PLUGIN_API int ts3plugin_init()
|
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
|
||||||
|
// diagnosing crashes in a hot-reloadable plugin.
|
||||||
|
static std::once_flag terminateOnce;
|
||||||
|
std::call_once(terminateOnce, [] {
|
||||||
|
std::set_terminate([] {
|
||||||
|
std::cerr << "[Echoion] FATAL: std::terminate — stack trace:\n";
|
||||||
|
const auto frames = Void::Stacktrace::capture_stacktrace();
|
||||||
|
std::cerr << Void::Stacktrace::format_stacktrace(frames)
|
||||||
|
<< '\n';
|
||||||
|
std::abort();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
g_deferredInitThread = std::jthread(deferredInitialization);
|
g_deferredInitThread = std::jthread(deferredInitialization);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TS3_PLUGIN_API void ts3plugin_shutdown()
|
TS3_PLUGIN_API void ts3plugin_shutdown()
|
||||||
{
|
{
|
||||||
std::cout << "[Echoion] Shutting down..." << std::endl;
|
std::cout << "[Echoion] Shutting down..." << '\n';
|
||||||
|
|
||||||
g_deferredInitRunning = false;
|
g_deferredInitRunning = false;
|
||||||
|
|
||||||
@@ -281,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) {
|
if (g_pluginInterface) {
|
||||||
g_pluginInterface->disconnectFromServer();
|
std::ignore = g_pluginInterface->disconnectFromServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_coreLoader) {
|
if (g_coreLoader) {
|
||||||
g_coreLoader->disableAutoReload();
|
g_coreLoader->disableAutoReload();
|
||||||
g_coreLoader->unload();
|
std::ignore = g_coreLoader->unload();
|
||||||
g_coreLoader.reset();
|
g_coreLoader.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_pluginInterface) {
|
if (g_pluginInterface) {
|
||||||
g_pluginInterface->shutdown();
|
std::ignore = g_pluginInterface->shutdown();
|
||||||
g_pluginInterface = nullptr;
|
g_pluginInterface = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_ts3Functions = nullptr;
|
g_ts3Functions = nullptr;
|
||||||
g_ts3FunctionsReady = false;
|
g_ts3FunctionsReady = false;
|
||||||
|
|
||||||
std::cout << "[Echoion] Shutdown complete" << std::endl;
|
std::cout << "[Echoion] Shutdown complete" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle incoming text messages
|
// Handle incoming text messages
|
||||||
TS3_PLUGIN_API void ts3plugin_onTextMessageEvent(
|
TS3_PLUGIN_API void ts3plugin_onTextMessageEvent(
|
||||||
uint64 serverConnectionHandlerId, anyID targetMode, anyID toID,
|
uint64 serverConnectionHandlerId, anyID targetMode, anyID /*toID*/,
|
||||||
anyID fromID, const char* fromName, const char* fromUniqueIdentifier,
|
anyID fromID, const char* /*fromName*/,
|
||||||
const char* message, int ffIgnored)
|
const char* /*fromUniqueIdentifier*/, const char* message,
|
||||||
|
int /*ffIgnored*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
anyID myID = 0;
|
anyID myID = 0;
|
||||||
@@ -327,7 +348,7 @@ namespace Echoion::Plugin
|
|||||||
// Handle client connect/disconnect
|
// Handle client connect/disconnect
|
||||||
TS3_PLUGIN_API void ts3plugin_onClientMoveEvent(
|
TS3_PLUGIN_API void ts3plugin_onClientMoveEvent(
|
||||||
uint64 serverConnectionHandlerId, anyID clientID, uint64 oldChannelID,
|
uint64 serverConnectionHandlerId, anyID clientID, uint64 oldChannelID,
|
||||||
uint64 newChannelID, int visibility, const char* moveMessage)
|
uint64 newChannelID, int /*visibility*/, const char* /*moveMessage*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!g_pluginInterface) {
|
if (!g_pluginInterface) {
|
||||||
@@ -346,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 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) {
|
if (g_pluginInterface) {
|
||||||
@@ -364,52 +408,55 @@ namespace Echoion::Plugin
|
|||||||
if (!g_coreLoader) {
|
if (!g_coreLoader) {
|
||||||
std::cerr
|
std::cerr
|
||||||
<< "[Echoion] Cannot re-register: CoreLoader not available"
|
<< "[Echoion] Cannot re-register: CoreLoader not available"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout
|
std::cout
|
||||||
<< "[Echoion] Re-registering plugin interface after hot reload..."
|
<< "[Echoion] Re-registering plugin interface after hot reload..."
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
|
|
||||||
// Get the new core instance
|
// Get the new core instance
|
||||||
auto core = g_coreLoader->getCore();
|
auto core = g_coreLoader->getCore();
|
||||||
if (!core) {
|
if (!core) {
|
||||||
std::cerr << "[Echoion] ERROR: Core is null!" << std::endl;
|
std::cerr << "[Echoion] ERROR: Core is null!" << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_pluginInterface) {
|
if (!g_pluginInterface) {
|
||||||
std::cerr << "[Echoion] ERROR: PluginInterface is null!"
|
std::cerr << "[Echoion] ERROR: PluginInterface is null!"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::format("[Echoion] New Core pointer: {}",
|
std::cout << std::format("[Echoion] New Core pointer: {}",
|
||||||
reinterpret_cast<uintptr_t>(core.get()))
|
reinterpret_cast<uintptr_t>(core.get()))
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
|
|
||||||
// Set the plugin interface first (before registering callbacks)
|
// Set the plugin interface first (before registering callbacks)
|
||||||
core->setPluginInterface(g_pluginInterface);
|
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
|
// Clear old callbacks (they point to destroyed Core) and register new
|
||||||
// one
|
// one
|
||||||
std::cout << "[Echoion] About to clear callbacks..." << std::endl;
|
std::cout << "[Echoion] About to clear callbacks..." << '\n';
|
||||||
g_pluginInterface->clearEventCallbacks();
|
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(
|
g_pluginInterface->registerEventCallback(
|
||||||
[core](const Api::PluginEvent& event) {
|
[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;
|
std::cout << "[Echoion] New event callback registered" << '\n';
|
||||||
core->skip(0);
|
// Best-effort nudge so playback resumes after the reload; failures
|
||||||
core->resume();
|
// only mean nothing was playing.
|
||||||
|
std::ignore = core->skip(0);
|
||||||
|
std::ignore = core->resume();
|
||||||
std::cout << "[Echoion] Re-registration complete - bot should respond "
|
std::cout << "[Echoion] Re-registration complete - bot should respond "
|
||||||
"to commands"
|
"to commands"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,17 +466,17 @@ namespace Echoion::Plugin
|
|||||||
{
|
{
|
||||||
if (!g_coreLoader) {
|
if (!g_coreLoader) {
|
||||||
std::cerr << "[Echoion] Cannot reload: CoreLoader not available"
|
std::cerr << "[Echoion] Cannot reload: CoreLoader not available"
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return false;
|
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());
|
auto result = g_coreLoader->hotReload(getCorePath());
|
||||||
if (!result) {
|
if (!result) {
|
||||||
std::cerr << std::format("[Echoion] Hot reload failed: {}",
|
std::cerr << std::format("[Echoion] Hot reload failed: {}",
|
||||||
result.error().message)
|
result.error().message)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,8 +486,8 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
// Handle plugin commands from TS3
|
// Handle plugin commands from TS3
|
||||||
TS3_PLUGIN_API void
|
TS3_PLUGIN_API void
|
||||||
ts3plugin_onPluginCommandEvent(uint64 serverConnectionHandlerId,
|
ts3plugin_onPluginCommandEvent(uint64 /*serverConnectionHandlerId*/,
|
||||||
const char* pluginName,
|
const char* /*pluginName*/,
|
||||||
const char* command)
|
const char* command)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -451,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
|
// Menu item callbacks
|
||||||
TS3_PLUGIN_API void
|
TS3_PLUGIN_API void
|
||||||
ts3plugin_onMenuItemEvent(uint64 serverConnectionHandlerId,
|
ts3plugin_onMenuItemEvent(uint64 /*serverConnectionHandlerId*/,
|
||||||
enum PluginMenuType type, int menuItemID,
|
enum PluginMenuType /*type*/, int menuItemID,
|
||||||
uint64 selectedItemID)
|
uint64 /*selectedItemID*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!ensureCoreLoaded()) {
|
if (!ensureCoreLoaded()) {
|
||||||
@@ -467,24 +551,26 @@ namespace Echoion::Plugin
|
|||||||
return;
|
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) {
|
switch (menuItemID) {
|
||||||
case 1:
|
case 1:
|
||||||
{ // Play/Pause
|
{ // Play/Pause
|
||||||
auto state = core->getPlaybackSummary();
|
auto state = core->getPlaybackSummary();
|
||||||
if (state) {
|
if (state) {
|
||||||
if (state->isPlaying && !state->isPaused) {
|
if (state->isPlaying && !state->isPaused) {
|
||||||
core->pause();
|
std::ignore = core->pause();
|
||||||
} else if (state->isPaused) {
|
} else if (state->isPaused) {
|
||||||
core->resume();
|
std::ignore = core->resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: // Skip
|
case 2: // Skip
|
||||||
core->skip(1);
|
std::ignore = core->skip(1);
|
||||||
break;
|
break;
|
||||||
case 3: // Stop
|
case 3: // Stop
|
||||||
core->stop();
|
std::ignore = core->stop();
|
||||||
break;
|
break;
|
||||||
case 4: // Hot Reload Core
|
case 4: // Hot Reload Core
|
||||||
reloadCoreWithInterface();
|
reloadCoreWithInterface();
|
||||||
@@ -492,7 +578,8 @@ namespace Echoion::Plugin
|
|||||||
case 5: // Connect/Disconnect
|
case 5: // Connect/Disconnect
|
||||||
if (g_pluginInterface) {
|
if (g_pluginInterface) {
|
||||||
if (g_pluginInterface->isConnected()) {
|
if (g_pluginInterface->isConnected()) {
|
||||||
g_pluginInterface->disconnectFromServer();
|
std::ignore =
|
||||||
|
g_pluginInterface->disconnectFromServer();
|
||||||
} else {
|
} else {
|
||||||
// Core handles connection, just trigger reconnect
|
// Core handles connection, just trigger reconnect
|
||||||
if (auto result = g_pluginInterface->reconnect();
|
if (auto result = g_pluginInterface->reconnect();
|
||||||
@@ -500,7 +587,7 @@ namespace Echoion::Plugin
|
|||||||
std::cerr
|
std::cerr
|
||||||
<< std::format("[Echoion] Reconnect failed: {}",
|
<< std::format("[Echoion] Reconnect failed: {}",
|
||||||
result.error().message)
|
result.error().message)
|
||||||
<< std::endl;
|
<< '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -508,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, ¤tChannel) ==
|
||||||
|
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
|
// Connection status changes
|
||||||
TS3_PLUGIN_API void
|
TS3_PLUGIN_API void
|
||||||
ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerId,
|
ts3plugin_onConnectStatusChangeEvent(uint64 serverConnectionHandlerId,
|
||||||
int newStatus,
|
int newStatus,
|
||||||
unsigned int errorNumber)
|
unsigned int /*errorNumber*/)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (g_pluginInterface) {
|
if (g_pluginInterface) {
|
||||||
@@ -522,22 +668,30 @@ namespace Echoion::Plugin
|
|||||||
|
|
||||||
switch (newStatus) {
|
switch (newStatus) {
|
||||||
case STATUS_CONNECTING:
|
case STATUS_CONNECTING:
|
||||||
std::cout << "[Echoion] Connecting..." << std::endl;
|
std::cout << "[Echoion] Connecting..." << '\n';
|
||||||
break;
|
break;
|
||||||
case STATUS_CONNECTED:
|
case STATUS_CONNECTED:
|
||||||
std::cout << "[Echoion] Connected" << std::endl;
|
std::cout << "[Echoion] Connected" << '\n';
|
||||||
if (g_pluginInterface) {
|
if (g_pluginInterface) {
|
||||||
g_pluginInterface->closeAudioDevice();
|
// Cycle the device best-effort; both calls log errors.
|
||||||
g_pluginInterface->openAudioDevice();
|
std::ignore = g_pluginInterface->closeAudioDevice();
|
||||||
|
std::ignore = g_pluginInterface->openAudioDevice();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case STATUS_CONNECTION_ESTABLISHED:
|
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;
|
break;
|
||||||
case STATUS_DISCONNECTED:
|
case STATUS_DISCONNECTED:
|
||||||
std::cout << "[Echoion] Disconnected" << std::endl;
|
std::cout << "[Echoion] Disconnected" << '\n';
|
||||||
if (g_pluginInterface) {
|
if (g_pluginInterface) {
|
||||||
g_pluginInterface->closeAudioDevice();
|
std::ignore = g_pluginInterface->closeAudioDevice();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+452
-177
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user