This commit is contained in:
erik 2025-06-22 21:32:00 +02:00
parent c174c143c6
commit e9925096f0
3 changed files with 137 additions and 25 deletions

View file

@ -392,39 +392,70 @@ namespace MosswartMassacre
{ {
try try
{ {
// Stream high priority quest data via WebSocket // Debug: Log when timer fires
if (WebSocketEnabled && questManager?.QuestList != null && questManager.QuestList.Count > 0) if (PluginSettings.Instance?.VerboseLogging == true)
{ {
var currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); WriteToChat("[QUEST-STREAM] Timer fired, checking conditions...");
}
// Find and stream priority quests (deduplicated by quest ID) // Stream high priority quest data via WebSocket
var priorityQuests = questManager.QuestList if (!WebSocketEnabled)
.Where(q => IsHighPriorityQuest(q.Id)) {
.GroupBy(q => q.Id) if (PluginSettings.Instance?.VerboseLogging == true)
.Select(g => g.First()) // Take first occurrence of each quest ID
.ToList();
foreach (var quest in priorityQuests)
{ {
try WriteToChat("[QUEST-STREAM] WebSocket not enabled, skipping");
{ }
string questName = questManager.GetFriendlyQuestName(quest.Id); return;
long timeRemaining = quest.ExpireTime - currentTime; }
string countdown = FormatCountdown(timeRemaining);
// Stream quest data if (questManager?.QuestList == null || questManager.QuestList.Count == 0)
System.Threading.Tasks.Task.Run(() => WebSocket.SendQuestDataAsync(questName, countdown)); {
} if (PluginSettings.Instance?.VerboseLogging == true)
catch (Exception) {
WriteToChat($"[QUEST-STREAM] No quest data available (null: {questManager?.QuestList == null}, count: {questManager?.QuestList?.Count ?? 0})");
}
return;
}
var currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
// Find and stream priority quests (deduplicated by quest ID)
var priorityQuests = questManager.QuestList
.Where(q => IsHighPriorityQuest(q.Id))
.GroupBy(q => q.Id)
.Select(g => g.First()) // Take first occurrence of each quest ID
.ToList();
if (PluginSettings.Instance?.VerboseLogging == true)
{
WriteToChat($"[QUEST-STREAM] Found {priorityQuests.Count} priority quests to stream");
}
foreach (var quest in priorityQuests)
{
try
{
string questName = questManager.GetFriendlyQuestName(quest.Id);
long timeRemaining = quest.ExpireTime - currentTime;
string countdown = FormatCountdown(timeRemaining);
if (PluginSettings.Instance?.VerboseLogging == true)
{ {
// Silently handle individual quest streaming errors WriteToChat($"[QUEST-STREAM] Sending: {questName} - {countdown}");
} }
// Stream quest data
System.Threading.Tasks.Task.Run(() => WebSocket.SendQuestDataAsync(questName, countdown));
}
catch (Exception ex)
{
WriteToChat($"[QUEST-STREAM] Error streaming quest {quest.Id}: {ex.Message}");
} }
} }
} }
catch (Exception) catch (Exception ex)
{ {
// Silently handle quest streaming errors to avoid spam WriteToChat($"[QUEST-STREAM] Error in timer handler: {ex.Message}");
} }
} }
@ -541,6 +572,31 @@ namespace MosswartMassacre
WriteToChat($"[ERROR] Quest manager hot reload failed: {ex.Message}"); WriteToChat($"[ERROR] Quest manager hot reload failed: {ex.Message}");
} }
// 9. Reinitialize quest streaming timer for hot reload
try
{
// Stop existing timer if any
if (questStreamingTimer != null)
{
questStreamingTimer.Stop();
questStreamingTimer.Elapsed -= OnQuestStreamingUpdate;
questStreamingTimer.Dispose();
questStreamingTimer = null;
}
// Create new timer
questStreamingTimer = new Timer(30000); // 30 seconds
questStreamingTimer.Elapsed += OnQuestStreamingUpdate;
questStreamingTimer.AutoReset = true;
questStreamingTimer.Start();
WriteToChat("[OK] Quest streaming timer reinitialized (30s interval)");
}
catch (Exception ex)
{
WriteToChat($"[ERROR] Quest streaming timer hot reload failed: {ex.Message}");
}
WriteToChat("Hot reload initialization completed!"); WriteToChat("Hot reload initialization completed!");
} }
@ -1314,6 +1370,8 @@ namespace MosswartMassacre
WriteToChat("/mm debugupdate - Debug update UI controls"); WriteToChat("/mm debugupdate - Debug update UI controls");
WriteToChat("/mm sendinventory - Force inventory upload with ID requests"); WriteToChat("/mm sendinventory - Force inventory upload with ID requests");
WriteToChat("/mm refreshquests - Force quest data refresh for Flag Tracker"); WriteToChat("/mm refreshquests - Force quest data refresh for Flag Tracker");
WriteToChat("/mm queststatus - Show quest streaming status and diagnostics");
WriteToChat("/mm verbose - Toggle verbose debug logging");
break; break;
case "report": case "report":
TimeSpan elapsed = DateTime.Now - statsStartTime; TimeSpan elapsed = DateTime.Now - statsStartTime;
@ -1745,6 +1803,53 @@ namespace MosswartMassacre
} }
break; break;
case "queststatus":
// Show quest streaming status
try
{
WriteToChat("=== Quest Streaming Status ===");
WriteToChat($"Timer Active: {questStreamingTimer != null && questStreamingTimer.Enabled}");
WriteToChat($"WebSocket Enabled: {WebSocketEnabled}");
WriteToChat($"Quest Manager: {(questManager != null ? "Active" : "Not Active")}");
WriteToChat($"Quest Count: {questManager?.QuestList?.Count ?? 0}");
if (questManager?.QuestList != null)
{
var priorityQuests = questManager.QuestList
.Where(q => IsHighPriorityQuest(q.Id))
.GroupBy(q => q.Id)
.Select(g => g.First())
.ToList();
WriteToChat($"Priority Quests Found: {priorityQuests.Count}");
foreach (var quest in priorityQuests)
{
string questName = questManager.GetFriendlyQuestName(quest.Id);
WriteToChat($" - {questName} ({quest.Id})");
}
}
WriteToChat($"Verbose Logging: {PluginSettings.Instance?.VerboseLogging ?? false}");
WriteToChat("Use '/mm verbose' to toggle debug logging");
}
catch (Exception ex)
{
WriteToChat($"[QUEST] Status check failed: {ex.Message}");
}
break;
case "verbose":
// Toggle verbose logging
if (PluginSettings.Instance != null)
{
PluginSettings.Instance.VerboseLogging = !PluginSettings.Instance.VerboseLogging;
WriteToChat($"Verbose logging: {(PluginSettings.Instance.VerboseLogging ? "ENABLED" : "DISABLED")}");
}
else
{
WriteToChat("Settings not initialized");
}
break;
default: default:
WriteToChat($"Unknown /mm command: {subCommand}. Try /mm help"); WriteToChat($"Unknown /mm command: {subCommand}. Try /mm help");
break; break;

View file

@ -24,6 +24,7 @@ namespace MosswartMassacre
private int _mainWindowY = 100; private int _mainWindowY = 100;
private bool _useTabbedInterface = true; private bool _useTabbedInterface = true;
private string _vtankProfilesPath = ""; private string _vtankProfilesPath = "";
private bool _verboseLogging = false;
public static PluginSettings Instance => _instance public static PluginSettings Instance => _instance
?? throw new InvalidOperationException("PluginSettings not initialized"); ?? throw new InvalidOperationException("PluginSettings not initialized");
@ -197,5 +198,11 @@ namespace MosswartMassacre
get => _vtankProfilesPath; get => _vtankProfilesPath;
set { _vtankProfilesPath = value; Save(); } set { _vtankProfilesPath = value; Save(); }
} }
public bool VerboseLogging
{
get => _verboseLogging;
set { _verboseLogging = value; Save(); }
}
} }
} }