feat: wire up character stats timer, ServerDispatch, and login send

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
erik 2026-02-26 15:43:01 +00:00
parent 655bfd5163
commit 1fdae96262

View file

@ -64,6 +64,7 @@ namespace MosswartMassacre
internal static Timer updateTimer; internal static Timer updateTimer;
private static Timer vitalsTimer; private static Timer vitalsTimer;
private static System.Windows.Forms.Timer commandTimer; private static System.Windows.Forms.Timer commandTimer;
private static Timer characterStatsTimer;
private static readonly Queue<string> pendingCommands = new Queue<string>(); private static readonly Queue<string> pendingCommands = new Queue<string>();
public static bool RareMetaEnabled { get; set; } = true; public static bool RareMetaEnabled { get; set; } = true;
@ -182,6 +183,8 @@ namespace MosswartMassacre
CoreManager.Current.WorldFilter.CreateObject += OnInventoryCreate; CoreManager.Current.WorldFilter.CreateObject += OnInventoryCreate;
CoreManager.Current.WorldFilter.ReleaseObject += OnInventoryRelease; CoreManager.Current.WorldFilter.ReleaseObject += OnInventoryRelease;
CoreManager.Current.WorldFilter.ChangeObject += OnInventoryChange; CoreManager.Current.WorldFilter.ChangeObject += OnInventoryChange;
// Subscribe to server messages for allegiance/luminance/title data
CoreManager.Current.EchoFilter.ServerDispatch += EchoFilter_ServerDispatch;
// Initialize VVS view after character login // Initialize VVS view after character login
ViewManager.ViewInit(); ViewManager.ViewInit();
@ -251,7 +254,8 @@ namespace MosswartMassacre
CoreManager.Current.WorldFilter.CreateObject -= OnInventoryCreate; CoreManager.Current.WorldFilter.CreateObject -= OnInventoryCreate;
CoreManager.Current.WorldFilter.ReleaseObject -= OnInventoryRelease; CoreManager.Current.WorldFilter.ReleaseObject -= OnInventoryRelease;
CoreManager.Current.WorldFilter.ChangeObject -= OnInventoryChange; CoreManager.Current.WorldFilter.ChangeObject -= OnInventoryChange;
// Unsubscribe from server dispatch
CoreManager.Current.EchoFilter.ServerDispatch -= EchoFilter_ServerDispatch;
// Stop and dispose of the timers // Stop and dispose of the timers
if (updateTimer != null) if (updateTimer != null)
@ -284,6 +288,15 @@ namespace MosswartMassacre
questStreamingTimer = null; questStreamingTimer = null;
} }
// Stop and dispose character stats timer
if (characterStatsTimer != null)
{
characterStatsTimer.Stop();
characterStatsTimer.Elapsed -= OnCharacterStatsUpdate;
characterStatsTimer.Dispose();
characterStatsTimer = null;
}
// Dispose quest manager // Dispose quest manager
if (questManager != null) if (questManager != null)
{ {
@ -403,6 +416,34 @@ namespace MosswartMassacre
WriteToChat($"[ERROR] Quest streaming initialization failed: {ex.Message}"); WriteToChat($"[ERROR] Quest streaming initialization failed: {ex.Message}");
} }
// Initialize character stats streaming
try
{
CharacterStats.Init();
// Start 10-minute character stats timer
characterStatsTimer = new Timer(600000); // 10 minutes
characterStatsTimer.Elapsed += OnCharacterStatsUpdate;
characterStatsTimer.AutoReset = true;
characterStatsTimer.Start();
// Send initial stats after 5-second delay (let CharacterFilter populate)
var initialDelay = new Timer(5000);
initialDelay.AutoReset = false;
initialDelay.Elapsed += (s, args) =>
{
CharacterStats.CollectAndSend();
((Timer)s).Dispose();
};
initialDelay.Start();
WriteToChat("[OK] Character stats streaming initialized (10-min interval)");
}
catch (Exception ex)
{
WriteToChat($"[ERROR] Character stats initialization failed: {ex.Message}");
}
} }
#region Quest Streaming Methods #region Quest Streaming Methods
@ -1161,6 +1202,50 @@ namespace MosswartMassacre
} }
} }
private static void OnCharacterStatsUpdate(object sender, ElapsedEventArgs e)
{
try
{
CharacterStats.CollectAndSend();
}
catch (Exception ex)
{
WriteToChat($"[CharStats] Timer error: {ex.Message}");
}
}
private void EchoFilter_ServerDispatch(object sender, NetworkMessageEventArgs e)
{
try
{
if (e.Message.Type == 0xF7B0) // Game Event
{
int eventId = (int)e.Message["event"];
if (eventId == 0x0020) // Allegiance info
{
CharacterStats.ProcessAllegianceInfoMessage(e);
}
else if (eventId == 0x0013) // Login Character (properties)
{
CharacterStats.ProcessCharacterPropertyData(e);
}
else if (eventId == 0x0029) // Titles list
{
CharacterStats.ProcessTitlesMessage(e);
}
else if (eventId == 0x002b) // Set title
{
CharacterStats.ProcessSetTitleMessage(e);
}
}
}
catch (Exception ex)
{
WriteToChat($"[CharStats] ServerDispatch error: {ex.Message}");
}
}
private void CalculateKillsPerInterval() private void CalculateKillsPerInterval()
{ {
double minutesElapsed = (DateTime.Now - statsStartTime).TotalMinutes; double minutesElapsed = (DateTime.Now - statsStartTime).TotalMinutes;