Exemplo n.º 1
0
        public static void CollectFeed(string hostFilePath)
        {
            if (!File.Exists(hostFilePath))
            {
                return;
            }

            string newFile       = mRootPath + @"\copy";
            string lineCountFile = mRootPath + @"\linesread";

            // Copy file
            if (File.Exists(newFile))
            {
                File.Delete(newFile);
            }
            File.Copy(hostFilePath, newFile);

            // Get last read line
            UInt32 linesRead = 0;

            if (File.Exists(lineCountFile))
            {
                try
                {
                    linesRead = BitConverter.ToUInt32(File.ReadAllBytes(lineCountFile), 0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Could not read linesread file.");
                }
            }

            StreamReader sr = new StreamReader(newFile);

            // Skip read lines
            SkipLines(sr, linesRead);

            // Read new feed
            string feed = sr.ReadLine();

            while (feed != null)
            {
                linesRead++;
                if (feed.Trim() == string.Empty)
                {
                    continue;
                }

                // Get the data from the feed and put it in the database
                Debug.WriteLine("Feed(" + linesRead + "):" + feed);
                MW2Event mw2Event = new MW2Event(feed);
                MW2EventHandler.HandleMW2Event(mw2Event);

                feed = sr.ReadLine();
            }

            // Close the reader
            sr.Close();

            // Save the new value of lines read
            File.WriteAllBytes(lineCountFile, BitConverter.GetBytes(linesRead));
        }
Exemplo n.º 2
0
        private static bool mWaitingforEndMatch = false;    // When exitlevel: executed appears we need to wait with ending the match and to wait till the line ------------- appears, because we need to handle events between those lines

        public static void HandleMW2Event(MW2Event e)
        {
            //if (mMatchId == -1 && e.Type != "initgame")     // If we start become host after hostmigration
            //    return;

            // When you leave game as host:
            //  0:26 ShutdownGame:
            //  0:26------------------------------------------------------------

            switch (e.Type)
            {
            case "initgame":
                if (e.Timestamp == "0:00")        // New match began
                {
                    if (MatchId != -1)
                    {
                        DataBase.EndMatch(MatchId);     // When you are host and you leave, the match won't be ended by this application. Can't read that from the "games_mp.log" file.
                    }
                }
                if (MatchId == -1)
                {
                    DataBase.RegisterNewMatch();
                }
                break;

            case "exitlevel: executed":             // Match has finished
                mWaitingforEndMatch = true;
                break;

            case "------------------------------------------------------------":
                if (mWaitingforEndMatch)
                {
                    mWaitingforEndMatch = false;
                    DataBase.EndMatch(MatchId);
                }
                break;

            case "j":
            case "q":
            case "say":
            case "sayteam":
                UpdatePlayer(e.Victim);             // With these types there's only a victim, no attacker
                break;

            case "weapon":
                UpdatePlayer(e.Victim);
                UpdateWeapon(e.Weapon);
                break;

            case "k":
            case "d":
                long vicPlayerId = UpdatePlayer(e.Victim);
                long attPlayerId = UpdatePlayer(e.Attacker);
                int  wepId       = UpdateWeapon(e.Weapon);

                if (attPlayerId == -1)                  // Player damaged himself
                {
                    attPlayerId = vicPlayerId;
                }
                DataBase.RegisterHit(vicPlayerId, attPlayerId, MatchId, wepId, e.Damage, e.HitLocation, e.MeansOfDeath, e.Type == "k" ? true : false);
                break;
            }
        }