Exemplo n.º 1
0
        public bool LogMatchScore(LogMatch logMatch)
        {
            bool isSuccessful = true;

            string SQL_LogMatchScore = @"Insert into users_matches(matchId, score) values(@matchId,@score)";

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(SQL_LogMatchScore, conn);

                    cmd.Parameters.Add(new SqlParameter("@matchId", logMatch.match.ID));
                    cmd.Parameters.Add(new SqlParameter("@score", logMatch.score));
                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
                isSuccessful = false;
            }
            return(isSuccessful);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to match the log line against all predefined regex patterns. If there was a match, the action
        /// associated with the pattern will be called.
        /// </summary>
        private void LogAction(string line)
        {
            // Match log line against all regular expressions
            foreach (var logRegExp in LogRegExps.RegExpList)
            {
                foreach (var regExp in logRegExp.RegExps)
                {
                    var match = regExp.Match(line);
                    if (!match.Success)
                    {
                        continue;
                    }

                    var logMatch = new LogMatch {
                        Type  = logRegExp.Type,
                        Match = match,
                        Msg   = line
                    };

                    _lastMatch = logMatch;
                    if (logRegExp.Type == LogType.AreaChange)
                    {
                        _lastAreaMatch = logMatch;
                    }

                    // EOF is not yet reached
                    if (!_logParser.IsEof)
                    {
                        return;
                    }

                    // If there was a match, invoke an action
                    switch (logRegExp.Type)
                    {
                    case LogType.AreaChange:
                        ActionAreaChange(logMatch);
                        break;

                    case LogType.StatusChange:
                        ActionStatusChange(logMatch);
                        break;

                    case LogType.CharacterSelect:
                        ActionCharacterSelect(logMatch);
                        break;

                    case LogType.LoginScreen:
                        ActionLoginScreen(logMatch);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    return;
                }
            }
        }
 public void Add(LogMatch match)
 {
     List<LogLineMatch> lineMatches;
     if (!_matches.TryGetValue(match.Index, out lineMatches))
     {
         lineMatches = new List<LogLineMatch>();
         _matches.Add(match.Index, lineMatches);
     }
     lineMatches.Add(match.Match);
 }
Exemplo n.º 4
0
        /// <summary>
        /// User is in the game and changed areas
        /// </summary>
        private void ActionAreaChange(LogMatch logMatch)
        {
            if (logMatch == null || logMatch.Type != LogType.AreaChange)
            {
                throw new ArgumentException("Invalid match passed");
            }

            var areaName = logMatch.Match.Groups[2].Value;

            _rpcClient.PresenceUpdateArea(areaName);
            Console.WriteLine($@"[EVENT] Player switched areas to {areaName}");
        }
Exemplo n.º 5
0
        /// <summary>
        /// User is in the game and turned DND/AFK ON/OFF
        /// </summary>
        private void ActionStatusChange(LogMatch logMatch)
        {
            if (logMatch == null || logMatch.Type != LogType.StatusChange)
            {
                throw new ArgumentException("Invalid match passed");
            }

            var mode = logMatch.Match.Groups[2].Value;              // DND or AFK
            var on   = logMatch.Match.Groups[3].Value.Equals("ON"); // ON or OFF
            var msg  = on ? logMatch.Match.Groups[5].Value : null;  // Status message or null

            _rpcClient.PresenceUpdateStatus(mode, on, msg);
            Console.WriteLine($@"[EVENT] Player switched {mode} {on} with message '{msg}'");
        }
Exemplo n.º 6
0
        public ActionResult LogMatchScore(LogMatch logMatch)
        {
            bool isSuccessful = dal.LogMatchScore(logMatch);

            if (isSuccessful)
            {
                SetMessage("Score has been successfully logged!", MessageType.Success);
            }
            else
            {
                SetMessage("There was an error logging your score!", MessageType.Error);
            }
            return(RedirectToAction("Index", "Home"));
        }
 private static string BuildMessage(LogMatch log)
 {
     return(string.Format("Expected log did not appear: {0}", log));
 }
 public UnexpectedLogMessageException(LogMatch log)
     : base(BuildMessage(log))
 {
     LogEvent = log;
 }
Exemplo n.º 9
0
 public void Add(LogMatch match)
 {
     _matchesByLine.Add(match);
     _matches.Add(match);
 }
Exemplo n.º 10
0
        private void AppendMatches(LogFileSection section)
        {
            try
            {
                // We've instructed the logfile to give us exactly up to
                // _logLinesBuffer.Length amount of entries in the ctor, hence the following
                // is correct:
                _logFile.GetSection(section, _logLinesBuffer);

                bool added = false;
                for (int i = 0; i < section.Count; ++i)
                {
                    var line = _logLinesBuffer[i];

                    _filter.Match(line, _matchesBuffer);
                    if (_matchesBuffer.Count > 0)
                    {
                        lock (_syncRoot)
                        {
                            foreach (LogLineMatch logLineMatch in _matchesBuffer)
                            {
                                var match = new LogMatch(line.LineIndex, logLineMatch);
                                _matches.Add(match);
                            }
                        }

                        _matchesBuffer.Clear();
                        added = true;
                    }
                }

                if (added)
                {
                    _listeners.EmitSearchChanged(_matches);
                }
            }
            catch (IndexOutOfRangeException e)
            {
                // This exception is usually thrown when we access a portion of the
                // log file that has already been reset. This means that a reset event is
                // either pending or soon to be. So not doing anything else to handle
                // this exception is fine.
                Log.DebugFormat("Caught exception while searching log file: {0}", e);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// User is in character select
 /// </summary>
 private void ActionCharacterSelect(LogMatch logMatch)
 {
     _rpcClient.PresenceUpdateCharacterSelect();
     Console.WriteLine(@"[EVENT] Player is in character select");
 }
Exemplo n.º 12
0
 /// <summary>
 /// User is on login screen
 /// </summary>
 private void ActionLoginScreen(LogMatch logMatch)
 {
     _rpcClient.PresenceUpdateLoginScreen();
     Console.WriteLine(@"[EVENT] Player is on login screen");
 }