Esempio n. 1
0
        private void ProcessEvent(byte[] blob)
        {
            var decompressedBlob = ZlibStream.UncompressBuffer(blob);

            Data.SetData(decompressedBlob);

            var affectedIDs = new List <int>();

            for (int i = 0; i < 30; i++)
            {
                var xuidTag = string.Format("players.{0}.xuid", i);
                var xuid    = Data.Get(xuidTag).Get <string>();

                if (xuid == "")
                {
                    break;
                }

                var userID = 0;
                int.TryParse(xuid.Substring(8), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture.NumberFormat, out userID);

                if (userID == 0)
                {
                    continue;
                }

                affectedIDs.Add(userID);
            }

            var map      = Data.Get("map").Get <string>();
            var gameType = Data.Get("gametype").Get <string>();

            var uniqueID = Guid.NewGuid().ToString().ToLower();

            var filename = string.Format("data/matches/iw5/{0}/{1}/{2}.match", gameType, map, uniqueID);

            Directory.CreateDirectory(Path.GetDirectoryName(filename));
            File.WriteAllBytes(filename, blob);

            var match = new Matches();

            match.MatchGuiD     = uniqueID;
            match.MatchGameType = gameType;
            match.MatchFilename = filename;
            match.MatchMap      = map;
            match.MatchTime     = Data.Get("dateTime").Get <int>();

            Database.Matches.InsertOnSubmit(match);
            Database.SubmitChanges();

            foreach (var affectedID in affectedIDs)
            {
                var matchUser = new MatchUsers();
                matchUser.MatchID   = uniqueID;
                matchUser.MatchUser = affectedID;

                Database.MatchUsers.InsertOnSubmit(matchUser);
            }
        }
Esempio n. 2
0
        private void Handle(UpdateRequest request)
        {
            Log.Debug("Whopla!");

            var matchString = request.Data;
            var document    = XDocument.Parse(matchString.Split(new char[] { '\n' }, 2)[1]);

            var map      = document.Root.Attribute("map").Value;
            var gameType = document.Root.Attribute("gametype").Value;
            var time     = document.Root.Attribute("date").Value;

            var affectedIDs = from gameEvent in document.Descendants()
                              where gameEvent.Attribute("from") != null && !gameEvent.Attribute("from").Value.StartsWith("bot")
                              select(int)(long.Parse(gameEvent.Attribute("from").Value, NumberStyles.AllowHexSpecifier) & 0xFFFFFFFF);

            affectedIDs = affectedIDs.Concat(from gameEvent in document.Descendants()
                                             where gameEvent.Attribute("to") != null && !gameEvent.Attribute("to").Value.StartsWith("bot")
                                             select(int)(long.Parse(gameEvent.Attribute("to").Value, NumberStyles.AllowHexSpecifier) & 0xFFFFFFFF));

            affectedIDs = affectedIDs.Distinct();

            var uniqueID = Guid.NewGuid().ToString().ToLower();

            var filename = string.Format("data/matches/{0}/{1}/{2}.xml", gameType, map, uniqueID);

            Directory.CreateDirectory(Path.GetDirectoryName(filename));
            File.WriteAllText(filename, document.ToString());

            var match = new Matches();

            match.MatchGuiD     = uniqueID;
            match.MatchGameType = gameType;
            match.MatchFilename = filename;
            match.MatchMap      = map;
            match.MatchTime     = int.Parse(time);

            Database.Matches.InsertOnSubmit(match);
            Database.SubmitChanges();

            foreach (var affectedID in affectedIDs)
            {
                var matchUser = new MatchUsers();
                matchUser.MatchID   = uniqueID;
                matchUser.MatchUser = affectedID;

                Database.MatchUsers.InsertOnSubmit(matchUser);
            }

            Database.SubmitChanges();
        }