feat(logs): add logging for CStaticStorage

This commit is contained in:
NanderTGA 2023-08-23 23:17:39 +02:00
parent cf991aa798
commit b8f137d53b
No known key found for this signature in database
GPG Key ID: 387081A6AADB0C8D
4 changed files with 84 additions and 0 deletions

View File

@ -64,6 +64,8 @@ namespace OpenFK
this.NetworkPostLogs = new System.Windows.Forms.RichTextBox();
this.NetworkCommandTab = new System.Windows.Forms.TabPage();
this.NetworkCommandLogs = new System.Windows.Forms.RichTextBox();
this.staticStorageTab = new System.Windows.Forms.TabPage();
this.staticStorageLogs = new System.Windows.Forms.RichTextBox();
this.tabControl1.SuspendLayout();
this.logTab.SuspendLayout();
this.FileLogsTab.SuspendLayout();
@ -84,6 +86,7 @@ namespace OpenFK
this.NetworkGetTab.SuspendLayout();
this.NetworkPostTab.SuspendLayout();
this.NetworkCommandTab.SuspendLayout();
this.staticStorageTab.SuspendLayout();
this.SuspendLayout();
//
// generalLogs
@ -104,6 +107,7 @@ namespace OpenFK
this.tabControl1.Controls.Add(this.outgoing);
this.tabControl1.Controls.Add(this.CLogger);
this.tabControl1.Controls.Add(this.network);
this.tabControl1.Controls.Add(this.staticStorageTab);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
@ -460,6 +464,26 @@ namespace OpenFK
this.NetworkCommandLogs.TabIndex = 2;
this.NetworkCommandLogs.Text = "";
//
// staticStorageTab
//
this.staticStorageTab.Controls.Add(this.staticStorageLogs);
this.staticStorageTab.Location = new System.Drawing.Point(4, 22);
this.staticStorageTab.Name = "staticStorageTab";
this.staticStorageTab.Size = new System.Drawing.Size(599, 429);
this.staticStorageTab.TabIndex = 7;
this.staticStorageTab.Text = "CStaticStorage";
this.staticStorageTab.UseVisualStyleBackColor = true;
//
// staticStorageLogs
//
this.staticStorageLogs.Dock = System.Windows.Forms.DockStyle.Fill;
this.staticStorageLogs.Location = new System.Drawing.Point(0, 0);
this.staticStorageLogs.Name = "staticStorageLogs";
this.staticStorageLogs.ReadOnly = true;
this.staticStorageLogs.Size = new System.Drawing.Size(599, 429);
this.staticStorageLogs.TabIndex = 0;
this.staticStorageLogs.Text = "";
//
// DebugWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -488,6 +512,7 @@ namespace OpenFK
this.NetworkGetTab.ResumeLayout(false);
this.NetworkPostTab.ResumeLayout(false);
this.NetworkCommandTab.ResumeLayout(false);
this.staticStorageTab.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -529,5 +554,7 @@ namespace OpenFK
private System.Windows.Forms.RichTextBox NetworkPostLogs;
private System.Windows.Forms.TabPage NetworkCommandTab;
private System.Windows.Forms.RichTextBox NetworkCommandLogs;
private System.Windows.Forms.TabPage staticStorageTab;
private System.Windows.Forms.RichTextBox staticStorageLogs;
}
}

View File

@ -40,6 +40,8 @@ namespace OpenFK
{ "POST", NetworkPostLogs },
{ "NetCommand", NetworkCommandLogs }
};
LogManager.staticStorageLogs = staticStorageLogs;
}
}
}

View File

@ -285,6 +285,9 @@ namespace OpenFK
void flashPlayer_FSCommand(object sender, _IShockwaveFlashEvents_FSCommandEvent e) //FSCommand Handler
{
// We put these here because these use a different xml scheme and to prevent clutter in the general logs.
// It is also important to return, since only we call this and know to not put anything else in it to prevent bugs due to bad code below.
if (e.args.Contains("<log")) // logs from modified CLogger
{
var log = new XmlDocument();
@ -294,6 +297,38 @@ namespace OpenFK
string level = node.Attributes["type"].Value;
string message = node.InnerText;
LogManager.LogLog(message, level);
return;
}
else if (e.args.Contains("<staticstorage"))
{
var log = new XmlDocument();
log.LoadXml(e.args);
var node = log.SelectSingleNode("/commands/staticstorage");
string type = node.Attributes["type"].Value;
string key = WebUtility.UrlDecode(node.Attributes["key"].Value);
switch (type)
{
case "get":
string value = WebUtility.UrlDecode(node.Attributes["value"].Value);
string defaultValue = WebUtility.UrlDecode(node.Attributes["defaultvalue"].Value);
LogManager.LogStaticStorageGet(key, value, defaultValue);
break;
case "set":
string oldValue = WebUtility.UrlDecode(node.Attributes["original"].Value);
string newValue = WebUtility.UrlDecode(node.Attributes["value"].Value); ;
LogManager.LogStaticStorageSet(key, oldValue, newValue);
break;
case "delete":
string original = WebUtility.UrlDecode(node.Attributes["original"].Value);
LogManager.LogStaticStorageDelete(key, original);
break;
}
return;
}
else
{ // Don't log incoming message that are logs to prevent clutter.

View File

@ -16,6 +16,7 @@ namespace OpenFK.OFK.Common
public static RichTextBox outgoingLogs;
public static Dictionary<string, RichTextBox> CLogger;
public static Dictionary<string, RichTextBox> networkLogs;
public static RichTextBox staticStorageLogs;
private static void AppendLine(RichTextBox richTextBox, string message)
{
@ -66,5 +67,24 @@ namespace OpenFK.OFK.Common
AppendLine(networkLogs["All"], message);
LogGeneral($"[Network] {message}");
}
//TODO: implement table view to keep track of values like the localstorage viewer in devtools
public static void LogStaticStorageSet(string key, string oldValue, string newValue)
{
string message = $"[Set] {key} = {oldValue} --> {newValue}";
AppendLine(staticStorageLogs, message);
}
public static void LogStaticStorageGet(string key, string value, string defaultValue)
{
string message = $"[Get] {key} = {value} || {defaultValue}";
AppendLine(staticStorageLogs, message);
}
public static void LogStaticStorageDelete(string key, string oldValue)
{
string message = $"[Delete] {key} = {oldValue}";
AppendLine(staticStorageLogs, message);
}
}
}