diff --git a/ConsoleLogReaderCSGO/Base/Interfaces/IMessage.cs b/ConsoleLogReaderCSGO/Base/Interfaces/IMessage.cs new file mode 100644 index 0000000..168fc40 --- /dev/null +++ b/ConsoleLogReaderCSGO/Base/Interfaces/IMessage.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleLogReaderCSGO.Base.Interfaces +{ + public interface IMessage + { + #region Fields + public int ID { get; set; } + public string User { get; set; } + public string Text { get; set; } + + #endregion + } +} diff --git a/ConsoleLogReaderCSGO/Base/MessageConsole.cs b/ConsoleLogReaderCSGO/Base/MessageConsole.cs new file mode 100644 index 0000000..e1084f1 --- /dev/null +++ b/ConsoleLogReaderCSGO/Base/MessageConsole.cs @@ -0,0 +1,30 @@ +using ConsoleLogReaderCSGO.Base.Roots; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleLogReaderCSGO.Base +{ + public class MessageConsole : Message + { + #region Fields + public bool IsDead { get; set; } + public ChatType MessageType { get; set; } + public string Location { get; set; } + + #endregion + + #region Constructors + + public MessageConsole() { } + public MessageConsole(int id, string user, string text, bool isDead, ChatType type, string location = null) : base(id, user, text) + { + IsDead = isDead; + MessageType = type; + Location = location; + } + + #endregion + } + +} diff --git a/ConsoleLogReaderCSGO/Base/Roots/Message.cs b/ConsoleLogReaderCSGO/Base/Roots/Message.cs new file mode 100644 index 0000000..9585726 --- /dev/null +++ b/ConsoleLogReaderCSGO/Base/Roots/Message.cs @@ -0,0 +1,27 @@ +using ConsoleLogReaderCSGO.Base.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleLogReaderCSGO.Base.Roots +{ + public abstract class Message : IMessage + { + #region Fields + public int ID { get; set; } + public string User { get; set; } + public string Text { get; set; } + + #endregion + + #region Constructors + internal Message() { } + internal Message(int id, string user, string text) + { + ID = id; + User = user; + Text = text; + } + #endregion + } +} diff --git a/ConsoleLogReaderCSGO/ConsoleLogReaderCSGO.csproj b/ConsoleLogReaderCSGO/ConsoleLogReaderCSGO.csproj index 4925d42..dd7105e 100644 --- a/ConsoleLogReaderCSGO/ConsoleLogReaderCSGO.csproj +++ b/ConsoleLogReaderCSGO/ConsoleLogReaderCSGO.csproj @@ -22,7 +22,6 @@ - diff --git a/ConsoleLogReaderCSGO/Data/LogRegex.cs b/ConsoleLogReaderCSGO/Data/LogRegex.cs index 7e86ae0..53e6081 100644 --- a/ConsoleLogReaderCSGO/Data/LogRegex.cs +++ b/ConsoleLogReaderCSGO/Data/LogRegex.cs @@ -8,13 +8,14 @@ namespace ConsoleLogReaderCSGO.Data { internal static class LogRegex { - public static Regex LogChat = new Regex(@"[ ][:][ ]"); - public static Regex LogDamage = new Regex(@"^((Damage Given to)|(Damage Taken from)|(-------------------------)|(Player:(.*)- Damage Given)|(Player: (.*)- Damage Taken))"); + public static Regex LogChat = new Regex($@"({Variables.MessageUserTextSeparator})"); - public static Regex LogMatchInfo = new Regex(@"^((Steamworks Stats: CSteamWorksGameStatsClient Received CLIENT session id:)|(Steamworks Stats: CSteamWorksGameStatsClient Ending CLIENT session id:))"); + public static Regex LogDamage = new Regex($@"^(({Variables.MessageDmg1})|({Variables.MessageDmg2})|({Variables.MessageDmg3})|({Variables.MessageDmg4})|({Variables.MessageDmg5}))"); - public static (Regex, LogFlags)[] regexLog { get; private set; } = + public static Regex LogMatchInfo = new Regex($@"^(({Variables.MessageStartGame})|({Variables.MessageEndGame}))"); + public static Regex LogChatTeam { get; private set; } = new Regex($@" ?({Variables.MessageDead}|)(({Variables.MessageCT}|{Variables.MessageTT})(.*))"); + public static (Regex, LogFlags)[] RegexLog { get; private set; } = { (LogChat, LogFlags.Chat), (LogDamage, LogFlags.Damage), diff --git a/ConsoleLogReaderCSGO/Data/Variables.cs b/ConsoleLogReaderCSGO/Data/Variables.cs index 2eb7875..a6254b6 100644 --- a/ConsoleLogReaderCSGO/Data/Variables.cs +++ b/ConsoleLogReaderCSGO/Data/Variables.cs @@ -8,8 +8,45 @@ namespace ConsoleLogReaderCSGO.Data { internal static class Variables { + #region logs + public static List ConsoleLines { get; set; } public static LogSorted[] ConsoleLinesArray { get; set; } + + #endregion + + #region chat + + public static int LastIndexChat { get; set; } + + #endregion + + #region Console Log Lines + + public const string MessageStartGame = "Steamworks Stats: CSteamWorksGameStatsClient Received CLIENT session id:"; + public const string MessageEndGame = "Steamworks Stats: CSteamWorksGameStatsClient Ending CLIENT session id:"; + public const string MessageDisconnectFromGame = "ChangeGameUIState: CSGO_GAME_UI_STATE_MAINMENU -> CSGO_GAME_UI_STATE_MAINMENU"; + public const string MessageGameStartConfirm = "LoadingScreen::OnNetMsgSetConVar"; + public const string MessageGameEndConfirmPNG = "PNG load error Interlace handling should be turned on when using png_read_image"; + + public const string MessageTT = "(Terrorist) "; + public const string MessageCT = "(Counter-Terrorist) "; + public const string MessageDead = "*DEAD*"; + public const string MessageUserTextSeparator = " : "; + public const string MessageMapSpotSeparator = " @ "; + + public const string MessageDamageTaken = "Damage Taken from"; + public const string MessageDamageGiven = "Damage Given to "; + + public const string MessageDmg1 = "Damage Given to"; + public const string MessageDmg2 = "Damage Taken from"; + public const string MessageDmg3 = "-------------------------"; + public const string MessageDmg4 = "Player: (.*)- Damage Given"; + public const string MessageDmg5 = "Player: (.*)- Damage Taken"; + + + + #endregion } } diff --git a/ConsoleLogReaderCSGO/Flags.cs b/ConsoleLogReaderCSGO/Flags.cs index ab47d5a..3ab033d 100644 --- a/ConsoleLogReaderCSGO/Flags.cs +++ b/ConsoleLogReaderCSGO/Flags.cs @@ -4,6 +4,9 @@ namespace ConsoleLogReaderCSGO { + + #region Enumerator Log Flag + /// /// Enumerator of Log Flags /// @@ -30,4 +33,31 @@ public enum LogFlags /// All = 20, } + + #endregion + + #region Enumerator Chat Type + + /// + /// Enumerator for Type of console chat + /// + public enum ChatType + { + /// + /// Counter Terrorist chat, only readable for counter terrorist team + /// + CT = 1, + /// + /// Terrorist chat, only readable for terrorist team + /// + TT = 2, + /// + /// Global chat, readable for everyone + /// + GLOBAL = 3, + } + + #endregion + + } \ No newline at end of file diff --git a/ConsoleLogReaderCSGO/LogReader.cs b/ConsoleLogReaderCSGO/LogReader.cs index 51495ff..d3cc648 100644 --- a/ConsoleLogReaderCSGO/LogReader.cs +++ b/ConsoleLogReaderCSGO/LogReader.cs @@ -88,6 +88,35 @@ public void UpdateLogNewFile(T newLog) // old.txt + newlogs.txt UpdateLog(newLog, false); } + /// + ///
Method returns a List that contains chats in provided logs.
+ ///
Depend on provided parameter bool it return all chat logs or only chat logs that was not given from last time method executed.
+ /// returns List of MessageConsole + ///
+ /// + ///
A boolean if true returns all chat message from log file.
+ ///
A boolean if false returns only chat message from log file that was not given from last time method executed.
+ /// + /// + /// Object List where every object cointains: + ///
1) (int) ID- index of line in console logs
+ ///
2) (string) User - username of message
+ ///
3) (string) Text - a message
+ ///
4) (bool) IsDead - if username when wrote message was dead
+ ///
5) (ChatTypr) MessageType - enumerator that indicates if message is global, counter-terrorist team or terrorist team
+ ///
6) (string) Location - if message was on team chat, showing map spot where message was wroten
+ ///
+ public List GetChat(bool getAllChat) + { + var result = getAllChat ? Operations.Chat.GetChat.GetChats(Data.Variables.ConsoleLines) + : Operations.Chat.GetChat.GetChats(Data.Variables.ConsoleLines, Data.Variables.LastIndexChat); + if (result != null) + { + return result.Cast().ToList(); + } + return new List { }; + } + /// /// Method that remove all logs from instance. /// diff --git a/ConsoleLogReaderCSGO/Operations/Chat/GetChat.cs b/ConsoleLogReaderCSGO/Operations/Chat/GetChat.cs new file mode 100644 index 0000000..7f4c120 --- /dev/null +++ b/ConsoleLogReaderCSGO/Operations/Chat/GetChat.cs @@ -0,0 +1,125 @@ +using ConsoleLogReaderCSGO.Base; +using ConsoleLogReaderCSGO.Data; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ConsoleLogReaderCSGO.Operations.Chat +{ + /// + /// Class that contains public and private methods of getting and sorting chat message + /// + internal class GetChat + { + #region Methods + + /// + ///
Method to iterate all provided logs or from indicated index
+ ///
Returns List of MessageConsole.
+ ///
+ /// Console logs + /// An index that indicated a line number where iteration starts + public static List GetChats(List logs, int startIndex = 0) + { + var chatMessages = new List(); + + for (int i = startIndex; i < logs.Count; i++) + { + if (logs[i].LogTypeFlag == LogFlags.Chat) + { + string line = logs[i].Line; + string user = GetUserFullName(line); + + var messageCSGO = new MessageConsole() + { + ID = i, + Text = GetOnlyMessage(line), + IsDead = IsDead(line), + MessageType = GetChatType(user), + Location = GetLocation(ref user), + User = GetOnlyNickname(ref user), + }; + chatMessages.Add(messageCSGO); + } + } + Variables.LastIndexChat = logs.Count; + return chatMessages; + } + #endregion + + #region Methods private + + /// + /// Returns true if user in chat line was dead when wrote a message. + /// + /// + /// + private static bool IsDead(string line) + { + return line.StartsWith(Variables.MessageDead); + } + + /// + /// Returns string that only contains username (and if is the case, string that contains game side with map spot too). + /// + /// + /// + private static string GetUserFullName(string line) + { + return line.Substring(0, line.IndexOf(Variables.MessageUserTextSeparator)).Replace(Variables.MessageDead, string.Empty); + } + + /// + /// Returns reference string that is substring for game side. + /// + /// + /// + private static string GetOnlyNickname(ref string line) + { + return line.Replace(Variables.MessageTT, string.Empty).Replace(Variables.MessageCT, string.Empty); + } + + /// + ///
Returns string that contains user message.
+ ///
Message is finding after first occurrence of " : " chars
+ ///
+ /// + /// + private static string GetOnlyMessage(string line) + { + return line[(line.IndexOf(Variables.MessageUserTextSeparator) + 3)..]; + } + + /// + /// Returns Chat Type from provided line + /// + /// + /// + private static ChatType GetChatType(string line) + { + return !Data.LogRegex.LogChatTeam.IsMatch(line) ? ChatType.GLOBAL + : line.Contains(Variables.MessageTT) ? ChatType.TT + : line.Contains(Variables.MessageCT) ? ChatType.CT + : ChatType.GLOBAL; + } + + /// + ///
Returns string that contains user spot map
+ ///
And return reference parameter that is truncated by spot map
+ ///
+ /// + /// + private static string GetLocation(ref string line) + { + try + { + string result = line[line.IndexOf(Variables.MessageMapSpotSeparator)..]; + line = line.Replace(result, string.Empty); + return result.Replace(Variables.MessageMapSpotSeparator, string.Empty); + } + catch(ArgumentOutOfRangeException) { return null; } + } + + #endregion + } +} diff --git a/ConsoleLogReaderCSGO/Operations/Flag/SetFlagToLogLine.cs b/ConsoleLogReaderCSGO/Operations/Flag/SetFlagToLogLine.cs index dd26010..ac621ee 100644 --- a/ConsoleLogReaderCSGO/Operations/Flag/SetFlagToLogLine.cs +++ b/ConsoleLogReaderCSGO/Operations/Flag/SetFlagToLogLine.cs @@ -20,7 +20,7 @@ public static LogFlags DetermineFlag(string line) //Every Logflag has Regular Expression pattern and Exceptions list. //Iterate patterns of RegularExpression looking for a match with 'line'. - foreach (var patternRegex in Data.LogRegex.regexLog) + foreach (var patternRegex in Data.LogRegex.RegexLog) { if (patternRegex.Item1.IsMatch(line)) { diff --git a/ConsoleLogReaderCSGO/Operations/ReadConsoleLogFile.cs b/ConsoleLogReaderCSGO/Operations/ReadConsoleLogFile.cs index dbd737b..6f9bddf 100644 --- a/ConsoleLogReaderCSGO/Operations/ReadConsoleLogFile.cs +++ b/ConsoleLogReaderCSGO/Operations/ReadConsoleLogFile.cs @@ -22,7 +22,7 @@ internal static (LogSorted[], int) ReadConsoleFile(IEnumerable logs) return ((LogSorted[])logs.Select(x => new LogSorted(x, Flag.SetFlagToLogLine.DetermineFlag(x), counter++)).ToArray(), logs.ToArray().Length); } return (null, 0); - + } #endregion }