public static void Main(string[] args) { // LogMiner.MineStatusLogs(); return; // LogMiner.MineAttackLogs(); return; var cts = new CancellationTokenSource(); var csvLogFileProducer = new CsvLogFileProducer(); if (ReadFromLogFile) { csvLogFileProducer.LoopOnNewThread(LogFilename, cts.Token); } var connectionClientProducer = new ConnectionClientProducer(); var rawInputToDevTextConverter = new RawInputToDevTextConverter(); var parsedOutputConverter = new ParsedOutputConverter(); CsvLogFileWriter csvWriter = null; if (!ReadFromLogFile) { csvWriter = new CsvLogFileWriter(); } using (var form = new MudClientForm(cts.Token, connectionClientProducer)) { var parsedOutputWriter = new ParsedOutputWriter(form); var statusWriter = new StatusWriter(form.StatusForm); var devOutputWriter = new DevOutputWriter(form.DevViewForm); var roomFinder = new RoomFinder(form.MapWindow); var doorsCommands = new DoorsCommands(form.MapWindow); var miscCommands = new MiscCommands(); var narrsWriter = new NarrsWriter(form); /*List<string> data = new(); * Store.ParsedOutput.Subscribe(o => { * data.AddRange( * o.Where(x => x.Type == ParsedOutputType.Raw) * .SelectMany(x => x.Lines.Zip(x.LineMetadata, (l, m) => new { l, m })) * .Where(line => line.m.Type == LineMetadataType.None) * .Select(l => l.l) * ); * }); * Task.Run(() => { * Thread.Sleep(60000); * File.WriteAllLines("unparsedLinesGrouped4.txt", data.GroupBy(d => d).OrderByDescending(g => g.Count()).Select(g => $"{g.Count()} {g.Key}")); * });*/ form.ShowDialog(); } cts.Cancel(); csvWriter?.CloseFile(); }
public static void Flash(MudClientForm window) { if (!window.IsShown) { return; } Action Flash = () => { FLASHWINFO fw = new FLASHWINFO(); fw.cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO))); fw.hwnd = window.Handle; fw.dwFlags = (int)(FlashType.FLASHW_TRAY | FlashType.FLASHW_TIMERNOFG); fw.uCount = UInt32.MaxValue; FlashWindowEx(ref fw); }; window.Invoke(Flash); }
public NarrsWriter(MudClientForm form) { _form = form; Store.ParsedOutput.Subscribe((outputs) => { foreach (var output in outputs) { if (output.Type != ParsedOutputType.Raw) { continue; } foreach (var line in output.Lines) { // todo: also include my narrates in here // todo: should match on colour and also with a regex instead of doing this if (line.Contains(" narrates '") || line.Contains(" tells you '") || line.Contains(" says '") || line.Contains(" speaks from the ") || line.Contains(" bellows '") || line.Contains(" hisses '") || line.Contains(" chats '") || line == "You are hungry." || line == "You are thirsty.") { if (line == "You are hungry." || line == "You are thirsty.") { SystemSounds.Beep.Play(); } // todo: decoding & then converting to rich text will be needlessly wasteful _form.WriteToNarrs(FormatDecodedText.Format(ControlCharacterEncoder.Decode(line + "\n"))); } } } }); }
public ParsedOutputWriter(MudClientForm form) { Store.TcpSend.Subscribe((message) => { // output = output + "\n"; // seems to be the most like zMud form.WriteToOutput(" " + message + " ", MudColors.CommandColor); }); Store.ClientInfo.Subscribe((message) => { form.WriteToOutput("\n" + message + "\n", MudColors.ClientInfoColor); }); Store.ParsedOutput.Subscribe((parsedOutputs) => { foreach (var p in parsedOutputs) { switch (p.Type) { case ParsedOutputType.Raw: // todo: dont unsplit things, dont decode things ~ waste of time & effort // probably copy paste a custom version of .FormatOutput /*var lines = p.Lines; * for (int i = 0; i < p.Lines.Length; i++) { * if (!string.IsNullOrWhiteSpace(p.Lines[i])) { * lines[i] = p.LineMetadata[i].Type.ToString().PadRight(15)[..15] + " " + p.Lines[i]; * } * }*/ var formattedOutput = FormatDecodedText.Format(ControlCharacterEncoder.Decode(string.Join("\n", p.Lines) + "\n")); form.WriteToOutput(formattedOutput); if (!form.ContainsFocus) { WindowFlasher.Flash(form); } break; case ParsedOutputType.Room: // todo: there's a break between rooms even if it was a dline form.WriteToOutput("\n" + p.Title, MudColors.RoomTitle); // form.WriteToOutput(string.Join("\n", p.Description) + "\n", MudColors.ForegroundColor); form.WriteToOutput(p.Exits + "\n", MudColors.RoomExits); if (p.Tracks.Length > 0) { form.WriteToOutput(string.Join("\n", p.Tracks) + "\n", MudColors.Tracks); } if (p.Items.Length > 0) { form.WriteToOutput(string.Join("\n", p.Items) + "\n", MudColors.ItemsOnFloor); } if (p.Creatures.Length > 0) { // Todo: does this work correctly? also it's inefficient form.WriteToOutput(FormatDecodedText.Format(ControlCharacterEncoder.Decode("\\x1B[33m" + string.Join("\n", p.Creatures) + "\n"))); } break; case ParsedOutputType.Status: form.WriteToOutput(p.Lines[0] + " ", MudColors.ForegroundColor); break; default: throw new Exception("Unhandled parsed output type"); } } }); }