/// <summary> /// Processes a log message /// </summary> private void ProcessLogMessage() { // Figure out where the end of the string is int trimLength = _rawMessage.IndexOfAny(new char[] {'\0', '\n'}); // Get a clean version of the log message _cleanMessage = _rawMessage.Substring(0, trimLength > 0 ? trimLength : _rawMessage.Length ); // Get the pure log message (without the timestamp) _pureMessage = _cleanMessage.Remove(0, 25); // Get a MySQL timestamp from the log line _mysqlTimestamp = DateTime.Parse (_cleanMessage.Substring(2, 21).Remove(10, 2)). ToString("yyyy-MM-dd HH:mm:ss"); // Check for user info MatchCollection mc = TypePlayerInfo.Matches(_pureMessage); // This is a user message of some kind if (mc.Count == 1 && mc[0].Groups.Count == 2) { // Get the user info _userInfo = GetPlayerInfo(mc[0].Groups[1].Value); // Did we get valid user info? if (_userInfo != PlayerInfo.Null) { // Check for target info mc = TypeA.Matches(_pureMessage); // Is there target info? if (mc.Count == 1 && mc[0].Groups.Count > 3) { // Yes _targetInfo = GetPlayerInfo(mc[0].Groups[3].Value); // Did we get valid target information? if (_targetInfo != PlayerInfo.Null) // Yes, targeted event _currentMessageType = MessageType.Targeted; else // No _currentMessageType = MessageType.User; } else { // User event _currentMessageType = MessageType.User; // No target info _targetInfo = PlayerInfo.Null; } } else { // Invalid user info // No player info _userInfo = PlayerInfo.Null; // No target info _targetInfo = PlayerInfo.Null; // Default message type _currentMessageType = MessageType.Generic; } } else { // Not a user event // No player info _userInfo = PlayerInfo.Null; // No target info _targetInfo = PlayerInfo.Null; // Default message type _currentMessageType = MessageType.Generic; } }
/// <summary> /// Static constructor /// </summary> static PlayerInfo() { // Create the null value Null = new PlayerInfo(); Null.Name = null; Null.SteamID = null; Null.Team = null; Null.UID = null; }
/// <summary> /// Gets a player's information from a string part /// </summary> /// <param name="playerInfoPart"> /// The string part to get the player's info from /// </param> /// <returns> /// The player's info, or null if the string part /// didn't parse into valid info /// </returns> private PlayerInfo GetPlayerInfo(string playerInfoPart) { // Get the player info parts MatchCollection mc = TypePlayerInfoParts.Matches(playerInfoPart); if (mc.Count == 1 && mc[0].Groups.Count > 4) { // Player info PlayerInfo pi = new PlayerInfo(); // Get the player info pi.Name = mc[0].Groups[1].Value; pi.UID = mc[0].Groups[2].Value; pi.SteamID = mc[0].Groups[3].Value; // Is this player on a team? if (mc[0].Groups.Count > 5) pi.Team = mc[0].Groups[5].Value; // Return the player info return pi; } else return PlayerInfo.Null; }