1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
11 private struct LogMessage
20 text = $
"[{DateTime.Now}]\n {text}";
24 text = $
"[{DateTime.Now}]\n {TextManager.GetServerMessage(text)}";
49 private readonly Dictionary<MessageType, Color> messageColor =
new Dictionary<MessageType, Color>
52 {
MessageType.ItemInteraction,
new Color(205, 205, 180) },
57 {
MessageType.ServerMessage,
new Color(157, 225, 160) },
58 {
MessageType.ConsoleUsage,
new Color(0, 162, 232) },
67 private readonly Dictionary<MessageType, string> messageTypeName =
new Dictionary<MessageType, string>
85 private int linesPerFile = 800;
89 private readonly Queue<LogMessage> lines;
90 private readonly Queue<LogMessage> unsavedLines;
92 private readonly
bool[] msgTypeHidden =
new bool[Enum.GetValues(typeof(
MessageType)).Length];
96 get {
return linesPerFile; }
97 set { linesPerFile = Math.Max(value, 10); }
105 lines =
new Queue<LogMessage>();
106 unsavedLines =
new Queue<LogMessage>();
110 System.Diagnostics.Debug.Assert(messageColor.ContainsKey(messageType));
111 System.Diagnostics.Debug.Assert(messageTypeName.ContainsKey(messageType));
119 var newText =
new LogMessage(line, messageType);
124 DebugConsole.NewMessage(newText.Text.SanitizedValue, messageColor[messageType]);
128 lines.Enqueue(newText);
129 unsavedLines.Enqueue(newText);
135 listBox.UpdateScrollBarSize();
141 unsavedLines.Clear();
150 while (listBox !=
null && listBox.Content.CountChildren >
LinesPerFile)
152 listBox.Content.RemoveChild(!reverseOrder ? listBox.Content.Children.First() : listBox.Content.Children.Last());
163 Directory.CreateDirectory(
SavePath, catchUnauthorizedAccessExceptions:
false);
167 DebugConsole.ThrowError(
"Failed to create a folder for server logs", e);
172 string fileName =
ServerName +
"_" + DateTime.Now.ToString(
"yyyy-MM-dd_HH:mm");
173 fileName = ToolBox.RemoveInvalidFileNameChars(fileName);
175 string filePath = Path.Combine(
SavePath, fileName +
".txt");
177 while (File.Exists(filePath))
179 filePath = Path.Combine(
SavePath, fileName +
" (" + i +
").txt");
185 File.WriteAllLines(filePath, unsavedLines.Select(l => l.Text.SanitizedValue), catchUnauthorizedAccessExceptions:
false);
189 DebugConsole.ThrowError(
"Saving the server log to " + filePath +
" failed", e);
Attacks are used to deal damage to characters, structures and items. They can be defined in the weapo...
void WriteLine(string line, MessageType messageType, bool logToConsole=true)
ServerLog(string serverName)
static RichString Rich(LocalizedString str, Func< string, string >? postProcess=null)