Exemplo n.º 1
0
        public static string HashReplay(ReplayMatch replay, IEnumerable <Player> players)
        {
            StringBuilder sb = new StringBuilder(replay.RandomValue.ToString());

            sb.Append(replay.MapName);
            sb.Append(replay.ReplayBuild);
            sb.Append(replay.GameMode);

            foreach (Player player in players)
            {
                if (player == null || string.IsNullOrWhiteSpace(player.Character))
                {
                    continue;
                }

                sb.Append(player.Character);
            }

            using (SHA1Managed sha1 = new SHA1Managed())
            {
                byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString()));

                return(string.Join(string.Empty, hash.Select(b => b.ToString("x2")).ToArray()));
            }
        }
Exemplo n.º 2
0
        public static string HashReplayOld(ReplayMatch replay)
        {
            string input = replay.RandomValue + replay.MapName + replay.ReplayBuild + replay.GameMode;

            using (SHA1Managed sha1 = new SHA1Managed())
            {
                byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input));

                return(string.Join(string.Empty, hash.Select(b => b.ToString("x2")).ToArray()));
            }
        }
        public MatchHistoryMatch(IInternalService internalService, IWebsiteService website, ReplayMatch replayMatch)
        {
            InternalService = internalService;
            HeroesIcons     = internalService.HeroesIcons;
            UserProfile     = internalService.UserProfile;
            Website         = website;

            ReplayMatch = replayMatch;

            SetMatch();
        }
Exemplo n.º 4
0
        // returns true if replay already exists in database
        private bool BasicData(string fileName)
        {
            string mapName = Replay.MapAlternativeName;

            if (string.IsNullOrEmpty(mapName))
            {
                mapName = Replay.Map;
            }

            Battleground battleground = HeroesIcons.Battlegrounds(Replay.ReplayBuild).Battleground(mapName);

            if (battleground == null)
            {
                throw new TranslationException(RetrieveAllMapAndHeroNames());
            }

            mapName = battleground.Name;
            mapName = MapVerification(mapName);

            ReplayMatch replayMatch = new ReplayMatch
            {
                Frames             = Replay.Frames,
                GameMode           = (Heroes.Helpers.GameMode)Replay.GameMode,
                GameSpeed          = Replay.GameSpeed.ToString(),
                IsGameEventsParsed = Replay.IsGameEventsParsedSuccessfully,
                MapName            = mapName,
                RandomValue        = Replay.RandomValue,
                ReplayBuild        = Replay.ReplayBuild,
                ReplayLength       = Replay.ReplayLength,
                ReplayVersion      = Replay.ReplayVersion,
                TeamSize           = Replay.TeamSize,
                TimeStamp          = Replay.Timestamp,
                FileName           = fileName,
            };

            replayMatch.Hash = ReplayHasher.HashReplay(replayMatch, GetPlayers());
            ReplayTimeStamp  = replayMatch.TimeStamp.Value;

            // check if replay was added to database already
            if (ReplaysDb.MatchReplay.IsExistingRecord(ReplaysContext, replayMatch))
            {
                ReplayId = ReplaysDb.MatchReplay.ReadReplayIdByHash(replayMatch);
                return(true);
            }
            else
            {
                ReplayId = ReplaysDb.MatchReplay.CreateRecord(ReplaysContext, replayMatch);
                return(false);
            }
        }
        // returns true if replay already exists in database
        private bool BasicData(string fileName)
        {
            if (!HeroesIcons.MapBackgrounds().MapNameTranslation(Replay.Map, out string mapName))
            {
                if (!AutoTranslateMapNameByMapObjectives(out mapName))
                {
                    throw new TranslationException(RetrieveAllMapAndHeroNames());
                }
            }

            ReplayMatch replayMatch = new ReplayMatch
            {
                Frames             = Replay.Frames,
                GameMode           = Replay.GameMode,
                GameSpeed          = Replay.GameSpeed.ToString(),
                IsGameEventsParsed = Replay.IsGameEventsParsedSuccessfully,
                MapName            = mapName,
                RandomValue        = Replay.RandomValue,
                ReplayBuild        = Replay.ReplayBuild,
                ReplayLength       = Replay.ReplayLength,
                ReplayVersion      = Replay.ReplayVersion,
                TeamSize           = Replay.TeamSize,
                TimeStamp          = Replay.Timestamp,
                FileName           = fileName,
            };

            replayMatch.Hash = ReplayHasher.HashReplay(replayMatch);
            ReplayTimeStamp  = replayMatch.TimeStamp.Value;

            // check if replay was added to database already
            if (ReplaysDb.MatchReplay.IsExistingRecord(ReplaysContext, replayMatch))
            {
                ReplayId = ReplaysDb.MatchReplay.ReadReplayIdByHash(replayMatch);
                return(true);
            }
            else
            {
                ReplayId = ReplaysDb.MatchReplay.CreateRecord(ReplaysContext, replayMatch);
                return(false);
            }
        }