private static void SaveMeta(string token, UploadMetaData meta)
        {
            var filepath = HostingEnvironment.MapPath("~/tokens/" + token + ".json");

            Directory.CreateDirectory(Path.GetDirectoryName(filepath));
            File.WriteAllText(filepath, meta.ToString());
        }
        public async Task <object> Create(long fileSize, long blockSize = 1024 * 64)
        {
            var token = Path.GetRandomFileName();
            var meta  = UploadMetaData.Create(fileSize, blockSize);


            JObject.FromObject(new
            {
                fileSize,
                blockSize,
                blocks = new bool[fileSize / blockSize + (fileSize % blockSize == 0 ? 0 : 1)]
            });


            var filepath = GetTempPath(token);

            Directory.CreateDirectory(Path.GetDirectoryName(filepath));

            System.IO.File.WriteAllBytes(filepath, new byte[0]);
            await SaveMeta(token, meta);

            return(new
            {
                token
            });
        }
        private async Task SaveMeta(string token, UploadMetaData meta)
        {
            var filepath = GetTokenPath(token);

            Directory.CreateDirectory(Path.GetDirectoryName(filepath));
            await System.IO.File.WriteAllTextAsync(filepath, meta.ToString());
        }
Exemple #4
0
        public void KeyGen_AccountStatus_Upload()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            var client = new HsReplayClient("89c8bbc1-474a-4b1b-91b5-2a116d19df7a", "HSReplay-API-Test/1.0", true);

            var token = client.CreateUploadToken().Result;

            Assert.IsFalse(string.IsNullOrEmpty(token), "string.IsNullOrEmpty(key)");

            var account = client.GetAccountStatus(token).Result;

            Assert.AreEqual(token, account.Key, "Key matches sent token");
            Assert.IsTrue(account.TestData, "account.TestData");
            Assert.IsNull(account.User);

            var metaData = new UploadMetaData()
            {
                TestData         = true,
                HearthstoneBuild = 1,
                MatchStart       = DateTime.Now.ToString("o")
            };
            var uploadEvent = client.CreateUploadRequest(metaData, token).Result;

            Assert.IsFalse(string.IsNullOrEmpty(uploadEvent.PutUrl));
            Assert.IsFalse(string.IsNullOrEmpty(uploadEvent.ShortId));
            Assert.IsFalse(string.IsNullOrEmpty(uploadEvent.ReplayUrl));

            var packUpload = client.UploadPack(
                new PackData
            {
                AccountHi   = 1,
                AccountLo   = 1,
                BoosterType = 1,
                Date        = DateTime.Now.ToString("o"),
                Cards       =
                    new[]
                {
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    }
                }
            }, token).Result;

            string[] log;
            using (var sr = new StreamReader("TestData/Power.log"))
                log = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            client.UploadLog(uploadEvent, log).Wait();
        }
        public async Task <object> Create(long fileSize, long blockSize = 1024 * 64)
        {
            var token = Path.GetRandomFileName();
            var meta  = UploadMetaData.Create(fileSize, blockSize);

            //JObject.FromObject(new
            //{
            //    fileSize,
            //    blockSize,
            //    blocks = new bool[fileSize / blockSize + (fileSize % blockSize == 0 ? 0 : 1)],
            //});

            var filepath = HostingEnvironment.MapPath("~/temp/" + token);

            Directory.CreateDirectory(Path.GetDirectoryName(filepath));

            File.WriteAllBytes(filepath, new byte[0]);
            SaveMeta(token, meta);

            return(new
            {
                //filepath,
                token,
            });
        }
Exemple #6
0
        private async void HandleGameEnd(object sender, LogGameEndEventArgs args)
        {
            Exception exception = null;
            string    replayUrl = null;
            var       metaData  = _metaData;

            _metaData = null;
            _deckWatcher.Run();
            var uploadGame = _allowedModes.Contains((BnetGameType)(metaData?.GameType ?? 0)) && !(metaData?.SpectatorMode ?? false);

            Util.DebugLog?.WriteLine($"HearthstoneWatcher.HandleGameEnd: Game ended. Uploading={uploadGame} GameType={metaData?.GameType} Spectator={metaData?.SpectatorMode}");

            if (uploadGame)
            {
                var trimmedLog = new List <string>();
                try
                {
                    for (var i = args.PowerLog.Count - 1; i > 0; i--)
                    {
                        var line = args.PowerLog[i];
                        trimmedLog.Add(line);
                        if (line.Contains("CREATE_GAME"))
                        {
                            break;
                        }
                    }
                    trimmedLog.Reverse();
                }
                catch (Exception)
                {
                    trimmedLog = args.PowerLog;
                }

                for (var i = 0; i < UploadRetries; i++)
                {
                    try
                    {
                        replayUrl = await _client.UploadLog(metaData, trimmedLog);

                        break;
                    }
                    catch (Exception ex)
                    {
                        exception = ex;
                    }

                    var delay = 5 * (i + 1);
                    Util.DebugLog?.WriteLine($"HearthstoneWatcher.HandleGameEnd: Upload try #{i + 1} failed. Retrying in {delay}s. Exception={exception}");
                    await Task.Delay(1000 *delay);
                }
            }
            Util.DebugLog?.WriteLine($"HearthstoneWatcher.HandleGameEnd: Upload Successful={replayUrl != null}, url={replayUrl} Exception={exception}, invokeEnd={uploadGame}");
            if (uploadGame)
            {
                OnGameEnd?.Invoke(this, new GameEndEventArgs(replayUrl != null, metaData?.GameHandle, exception));
            }
        }
Exemple #7
0
        internal async Task <string> UploadLog(UploadMetaData metaData, List <string> log)
        {
            if (_testData)
            {
                metaData.TestData = true;
            }
            var request = await _client.CreateUploadRequest(metaData, UploadToken);

            await _client.UploadLog(request, log);

            return(request.ReplayUrl);
        }
            public static UploadMetaData Create(long fileSize, long blockSize)
            {
                var instance = new UploadMetaData();

                instance.FileSize  = fileSize;
                instance.BlockSize = blockSize;

                var maxBlocks = fileSize / blockSize + (fileSize % blockSize == 0 ? 0 : 1);

                instance.Blocks = new bool[maxBlocks];
                return(instance);
            }
            public static UploadMetaData FromJson(string json)
            {
                var data = JObject.Parse(json);

                var instance = new UploadMetaData();

                instance.FileSize  = (long)data["FileSize"];
                instance.BlockSize = (long)data["BlockSize"];

                instance.Blocks = ((JArray)data["Blocks"]).ToObject <bool[]>();

                return(instance);
            }
        private async Task <UploadMetaData> LoadMeta(string token)
        {
            var filepath = GetTokenPath(token);

            if (System.IO.File.Exists(filepath) == false)
            {
                return(null);
            }

            using (var stream = System.IO.File.OpenRead(filepath))
            {
                return(UploadMetaData.FromJson(await new StreamReader(stream).ReadToEndAsync()));
            }
        }
        private async Task <UploadMetaData> LoadMeta(string token)
        {
            var filepath = HostingEnvironment.MapPath("~/tokens/" + token + ".json");

            if (File.Exists(filepath) == false)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "invalid token"));
            }

            using (var stream = File.OpenRead(filepath))
            {
                return(UploadMetaData.FromJson(await new StreamReader(stream).ReadToEndAsync()));
            }
        }
		public static UploadMetaData Generate(string[] log, GameMetaData gameMetaData, GameStats game)
		{
			var metaData = new UploadMetaData();
			var playerInfo = GetPlayerInfo(log, game);
			if(playerInfo != null)
			{
				metaData.Player1 = playerInfo.Player1;
				metaData.Player2 = playerInfo.Player2;
			}
			if(!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
				metaData.ServerIp = gameMetaData.ServerInfo.Address;
			if(gameMetaData?.ServerInfo?.Port > 0)
				metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
			if(gameMetaData?.ServerInfo?.GameHandle > 0)
				metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
			if(gameMetaData?.ServerInfo?.ClientHandle > 0)
				metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
			if(!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
				metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
			if(!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
				metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
			if(!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
				metaData.ServerVersion = gameMetaData.ServerInfo.Version;
			if(game?.StartTime > DateTime.MinValue)
				metaData.MatchStart = game.StartTime.ToString("o");
			if(game != null)
				metaData.GameType = game.GameType != GameType.GT_UNKNOWN ? (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format) : (int)HearthDbConverter.GetGameType(game.GameMode, game.Format);
			if(game?.Format != null)
				metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
			metaData.SpectatorMode = game?.GameMode == GameMode.Spectator;
			metaData.Reconnected = gameMetaData?.Reconnected ?? false;
			metaData.Resumable = gameMetaData?.ServerInfo?.Resumable ?? false;
			metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (playerInfo?.FriendlyPlayerId > 0 ? playerInfo?.FriendlyPlayerId : null);
			var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;
			if(scenarioId > 0)
				metaData.ScenarioId = scenarioId;
			var build = gameMetaData?.HearthstoneBuild ?? game?.HearthstoneBuild ?? (game != null ? BuildDates.GetByDate(game.StartTime) : null);
			if(build > 0)
				metaData.HearthstoneBuild = build;
			if(game?.BrawlSeasonId > 0)
				metaData.BrawlSeason = game.BrawlSeasonId;
			if(game?.RankedSeasonId > 0)
				metaData.LadderSeason = game.RankedSeasonId;
			return metaData;
		}
Exemple #13
0
        private async void HandleGameStart(object sender, LogGameStartEventArgs args)
        {
            var deck = _deckWatcher.SelectedDeck;

            _deckWatcher.Stop();
            var build = Util.GetHearthstoneBuild(_logManager.HearthstoneDir);

            Util.DebugLog?.WriteLine($"HearthstoneWatcher.HandleGameStart: foundDeck={deck != null}, build={build}");
            _metaData = await UploadMetaDataGenerator.Generate(deck, build);

            var accInfo     = Reflection.GetAccountId();
            var invokeStart = _metaData.GameType.HasValue && _allowedModes.Contains((BnetGameType)_metaData.GameType);

            if (invokeStart)
            {
                OnGameStart?.Invoke(this, new GameStartEventArgs((BnetGameType)(_metaData.GameType ?? 0), _metaData.GameHandle, accInfo?.Hi ?? 0, accInfo?.Lo ?? 0));
            }
            Util.DebugLog?.WriteLine($"HearthstoneWatcher.HandleGameStart: Game Started. GameType={_metaData.GameType}, GameHandle={_metaData.GameHandle}, invokeStart={invokeStart}, accHi={accInfo?.Hi}, accLo={accInfo?.Lo}");
        }
Exemple #14
0
        public async Task <UploadStatus> Upload(string[] logLines, UploadMetaData data)
        {
            var result = LogValidator.Validate(logLines);

            if (!result.IsValid)
            {
                UploadError?.Invoke(new UploadErrorEventArgs(0, data, result.Reason));
                return(new UploadStatus(new InvalidLogException(result.Reason)));
            }

            var log  = string.Join(Environment.NewLine, logLines);
            var item = new UploaderItem(log.GetHashCode());

            if (_inProgress.Contains(item))
            {
                Log.Debug($"{item.Hash} already in progress. Waiting for it to complete...");
                _inProgress.Add(item);
                return(await item.Status);
            }
            _inProgress.Add(item);
            Log.Debug($"Uploading {item.Hash}...");
            UploadStatus status;

            UploadInitiated?.Invoke(new UploadStatusChangedEventArgs(item.Hash, data));
            try
            {
                status = await TryUpload(logLines, data);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                status = new UploadStatus(ex);
            }
            Log.Debug($"{item.Hash} complete. Success={status.Success}");
            UploadComplete?.Invoke(new UploadCompleteEventArgs(item.Hash, data, status));
            foreach (var waiting in _inProgress.Where(x => x.Hash == item.Hash))
            {
                waiting.Complete(status);
            }
            _inProgress.RemoveAll(x => x.Hash == item.Hash);
            return(status);
        }
Exemple #15
0
        private async Task <UploadStatus> TryUpload(IEnumerable <string> logLines, UploadMetaData data)
        {
            try
            {
                var lines = logLines.SkipWhile(x => !x.Contains("CREATE_GAME")).ToArray();
                Log.Debug("Creating upload request...");
                var uploadRequest = await _api.CreateUploadRequest(data);

                Log.Debug("Upload Id: " + uploadRequest.ShortId);
                await _api.UploadLog(uploadRequest, lines);

                Log.Debug("Upload complete");
                return(new UploadStatus(uploadRequest.ShortId, uploadRequest.ReplayUrl));
            }
            catch (WebException ex)
            {
                Log.Error(ex);
                return(new UploadStatus(ex));
            }
        }
        public static UploadMetaData Generate(int?build, IGameState game, int wins, int losses)
        {
            var metaData   = new UploadMetaData();
            var playerInfo = GetPlayerInfo(game, wins, losses);

            if (playerInfo != null)
            {
                metaData.Player1 = playerInfo.Player1;
                metaData.Player2 = playerInfo.Player2;
            }
            if (game?.ServerInfo != null)
            {
                metaData.ServerIp         = game.ServerInfo.Address;
                metaData.ServerPort       = game.ServerInfo.Port.ToString();
                metaData.GameHandle       = game.ServerInfo.GameHandle.ToString();
                metaData.ClientHandle     = game.ServerInfo.ClientHandle.ToString();
                metaData.SpectatePassword = game.ServerInfo.SpectatorPassword;
                metaData.AuroraPassword   = game.ServerInfo.AuroraPassword;
                metaData.ServerVersion    = game.ServerInfo.Version;
                metaData.Resumable        = game.ServerInfo.Resumable;
                if (game.ServerInfo.Mission > 0)
                {
                    metaData.ScenarioId = game.ServerInfo.Mission;
                }
            }
            if (game?.CreatedAt > DateTime.MinValue)
            {
                metaData.MatchStart = game.CreatedAt.ToString("o");
            }
            if (game?.MatchInfo != null)
            {
                metaData.GameType      = (int?)Converters.GetBnetGameType((GameType)game.MatchInfo.GameType, (FormatType)game.MatchInfo.FormatType);
                metaData.Format        = game.MatchInfo.FormatType;
                metaData.SpectatorMode = game.MatchInfo.Spectator;
                metaData.BrawlSeason   = game.MatchInfo.BrawlSeasonId;
                metaData.LadderSeason  = game.MatchInfo.RankedSeasonId;
            }
            metaData.FriendlyPlayerId = game?.LocalPlayer?.PlayerId;
            metaData.HearthstoneBuild = build;
            return(metaData);
        }
Exemple #17
0
 internal async Task <LogUploadRequest> CreateUploadRequest(UploadMetaData metaData)
 => await _client.CreateUploadRequest(metaData, await GetUploadToken());
 public UploadErrorEventArgs(int uploadId, UploadMetaData data, string reason)
     : base(uploadId, data)
 {
     Reason = reason;
 }
Exemple #19
0
        public static UploadMetaData Generate(GameMetaData gameMetaData, GameStats game)
        {
            var metaData = new UploadMetaData();
            var players  = GetPlayerInfo(game);

            if (players != null)
            {
                if (game.GameType == GameType.GT_BATTLEGROUNDS)
                {
                    metaData.Players = players;
                }
                else
                {
                    metaData.Player1 = players.FirstOrDefault(x => x.Id == 1);
                    metaData.Player2 = players.FirstOrDefault(x => x.Id == 2);
                }
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
            {
                metaData.ServerIp = gameMetaData.ServerInfo.Address;
            }
            if (gameMetaData?.ServerInfo?.Port > 0)
            {
                metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
            }
            if (gameMetaData?.ServerInfo?.GameHandle > 0)
            {
                metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
            }
            if (gameMetaData?.ServerInfo?.ClientHandle > 0)
            {
                metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
            {
                metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
            {
                metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
            {
                metaData.ServerVersion = gameMetaData.ServerInfo.Version;
            }
            if (game?.StartTime > DateTime.MinValue)
            {
                metaData.MatchStart = game.StartTime.ToString("o");
            }
            if (game != null)
            {
                metaData.GameType = game.GameType != GameType.GT_UNKNOWN ? (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format) : (int)HearthDbConverter.GetGameType(game.GameMode, game.Format);
            }
            if (game?.Format != null)
            {
                metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
            }
            metaData.SpectatorMode    = game?.GameMode == GameMode.Spectator;
            metaData.Reconnected      = gameMetaData?.Reconnected ?? false;
            metaData.Resumable        = gameMetaData?.ServerInfo?.Resumable ?? false;
            metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (int?)null;
            var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;

            if (scenarioId > 0)
            {
                metaData.ScenarioId = scenarioId;
            }
            var build = gameMetaData?.HearthstoneBuild;

            if (build == null || build == 0)
            {
                build = game?.HearthstoneBuild;
            }
            if ((build == null || build == 0) && game != null)
            {
                build = BuildDates.GetByDate(game.StartTime);
            }
            if (build > 0)
            {
                metaData.HearthstoneBuild = build;
            }
            if (game?.BrawlSeasonId > 0)
            {
                metaData.BrawlSeason = game.BrawlSeasonId;
            }
            if (game?.RankedSeasonId > 0)
            {
                metaData.LadderSeason = game.RankedSeasonId;
            }
            if (gameMetaData?.TwitchVodData != null)
            {
                metaData.TwitchVod = gameMetaData.TwitchVodData;
            }
            if (game?.LeagueId > 0)
            {
                metaData.LeagueId = game.LeagueId;
            }
            return(metaData);
        }
Exemple #20
0
        public static UploadMetaData Generate(GameMetaData gameMetaData, GameStats game)
        {
            var metaData = new UploadMetaData();
            var players  = GetPlayerInfo(game);

            if (players != null)
            {
                if (game.GameMode == GameMode.Battlegrounds || game.GameMode == GameMode.Mercenaries)
                {
                    metaData.Players = players;
                }
                else
                {
                    metaData.Player1 = players.FirstOrDefault(x => x.Id == 1);
                    metaData.Player2 = players.FirstOrDefault(x => x.Id == 2);
                }
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
            {
                metaData.ServerIp = gameMetaData.ServerInfo.Address;
            }
            if (gameMetaData?.ServerInfo?.Port > 0)
            {
                metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
            }
            if (gameMetaData?.ServerInfo?.GameHandle > 0)
            {
                metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
            }
            if (gameMetaData?.ServerInfo?.ClientHandle > 0)
            {
                metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
            {
                metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
            {
                metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
            {
                metaData.ServerVersion = gameMetaData.ServerInfo.Version;
            }
            if (game?.StartTime > DateTime.MinValue)
            {
                metaData.MatchStart = game.StartTime.ToString("o");
            }
            if (game != null)
            {
                metaData.GameType = (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format);
            }
            if (game?.Format != null)
            {
                metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
            }
            metaData.SpectatorMode    = game?.GameMode == GameMode.Spectator;
            metaData.Reconnected      = gameMetaData?.Reconnected ?? false;
            metaData.Resumable        = gameMetaData?.ServerInfo?.Resumable ?? false;
            metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (int?)null;
            var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;

            if (scenarioId > 0)
            {
                metaData.ScenarioId = scenarioId;
            }
            var build = gameMetaData?.HearthstoneBuild;

            if (build == null || build == 0)
            {
                build = game?.HearthstoneBuild;
            }
            if ((build == null || build == 0) && game != null)
            {
                build = BuildDates.GetByDate(game.StartTime);
            }
            if (build > 0)
            {
                metaData.HearthstoneBuild = build;
            }
            if (game?.BrawlSeasonId > 0)
            {
                metaData.BrawlSeason = game.BrawlSeasonId;
            }
            if (game?.RankedSeasonId > 0)
            {
                metaData.LadderSeason = game.RankedSeasonId;
            }
            if (gameMetaData?.TwitchVodData != null)
            {
                metaData.TwitchVod = gameMetaData.TwitchVodData;
            }
            if (game?.LeagueId > 0)
            {
                metaData.LeagueId = game.LeagueId;
            }
            if (game?.GameMode == GameMode.Battlegrounds)
            {
                metaData.BattlegroundsRaces = game.BattlegroundsRaces?.Cast <int>().OrderBy(x => x).ToArray();
            }
            if (game?.GameMode == GameMode.Mercenaries)
            {
                if (game?.MercenariesBountyRunRewards?.Count > 0)
                {
                    metaData.MercenariesRewards = game.MercenariesBountyRunRewards
                                                  .Select(x => new UploadMetaData.MercenaryReward()
                    {
                        Id = x.Id, Coins = x.Coins
                    })
                                                  .ToList();
                }
                if (!string.IsNullOrEmpty(game?.MercenariesBountyRunId))
                {
                    metaData.MercenariesBountyRunId             = game.MercenariesBountyRunId;
                    metaData.MercenariesBountyRunTurnsTaken     = game.MercenariesBountyRunTurnsTaken;
                    metaData.MercenariesBountyRunCompletedNodes = game.MercenariesBountyRunCompletedNodes;
                }
            }
            return(metaData);
        }
Exemple #21
0
 public UploadCompleteEventArgs(int uploadId, UploadMetaData data, LogUploader.UploadStatus status)
     : base(uploadId, data)
 {
     Status = status;
 }
		public static async Task<LogUploadRequest> CreateUploadRequest(UploadMetaData metaData) 
			=> await Client.CreateUploadRequest(metaData, await GetUploadToken());
Exemple #23
0
        public static async Task <UploadMetaData> Generate(Deck deck, int?hearthstoneBuild)
        {
            var metaData = new UploadMetaData();

            var serverInfoResult = await TryGetReflection(Reflection.GetServerInfo);

            if (serverInfoResult.Successful)
            {
                var serverInfo = serverInfoResult.Result;
                metaData.AuroraPassword   = serverInfo.AuroraPassword;
                metaData.ServerIp         = serverInfo.Address;
                metaData.ClientHandle     = serverInfo.ClientHandle.ToString();
                metaData.GameHandle       = serverInfo.GameHandle.ToString();
                metaData.SpectatePassword = serverInfo.SpectatorPassword;
                metaData.SpectatorMode    = serverInfo.SpectatorMode;
                metaData.Resumable        = serverInfo.Resumable;
                metaData.ServerPort       = serverInfo.Port.ToString();
                metaData.ServerVersion    = serverInfo.Version;
            }

            var formatResult = await TryGetReflection(Reflection.GetFormat);

            if (formatResult.Successful)
            {
                metaData.Format = formatResult.Result;
                var gameTypeResult = await TryGetReflection(Reflection.GetGameType);

                if (gameTypeResult.Successful)
                {
                    metaData.GameType = Util.GetBnetGameType(gameTypeResult.Result, formatResult.Result);
                }
            }


            var friendly = new UploadMetaData.Player()
            {
                DeckId   = deck?.Id,
                DeckList = deck?.Cards?.Where(x => x != null).SelectMany(x => Enumerable.Repeat(x.Id, x.Count)).ToArray()
            };
            var opposing = new UploadMetaData.Player();

            var matchInfoResult = await TryGetReflection(Reflection.GetMatchInfo);

            if (matchInfoResult.Successful)
            {
                var matchInfo = matchInfoResult.Result;
                metaData.FriendlyPlayerId = matchInfo.LocalPlayer.Id;
                metaData.LadderSeason     = matchInfo.RankedSeasonId;
                metaData.ScenarioId       = matchInfo.MissionId;

                if (matchInfo.LocalPlayer.CardBackId > 0)
                {
                    friendly.Cardback = matchInfo.LocalPlayer.CardBackId;
                }

                if (matchInfo.OpposingPlayer.CardBackId > 0)
                {
                    opposing.Cardback = matchInfo.OpposingPlayer.CardBackId;
                }

                metaData.Player1 = matchInfo.LocalPlayer.Id == 1 ? friendly : opposing;
                metaData.Player2 = matchInfo.LocalPlayer.Id == 2 ? friendly : opposing;
            }


            metaData.HearthstoneBuild = hearthstoneBuild;
            metaData.MatchStart       = DateTime.Now.ToString("o");

            return(metaData);
        }
Exemple #24
0
        public static UploadMetaData Generate(string[] log, GameMetaData gameMetaData, GameStats game)
        {
            var metaData   = new UploadMetaData();
            var playerInfo = GetPlayerInfo(log, game);

            if (playerInfo != null)
            {
                metaData.Player1 = playerInfo.Player1;
                metaData.Player2 = playerInfo.Player2;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
            {
                metaData.ServerIp = gameMetaData.ServerInfo.Address;
            }
            if (gameMetaData?.ServerInfo?.Port > 0)
            {
                metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
            }
            if (gameMetaData?.ServerInfo?.GameHandle > 0)
            {
                metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
            }
            if (gameMetaData?.ServerInfo?.ClientHandle > 0)
            {
                metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
            {
                metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
            {
                metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
            {
                metaData.ServerVersion = gameMetaData.ServerInfo.Version;
            }
            if (game?.StartTime > DateTime.MinValue)
            {
                metaData.MatchStart = game.StartTime.ToString("o");
            }
            if (game != null)
            {
                metaData.GameType = game.GameType != GameType.GT_UNKNOWN ? (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format) : (int)HearthDbConverter.GetGameType(game.GameMode, game.Format);
            }
            if (game?.Format != null)
            {
                metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
            }
            metaData.SpectatorMode    = game?.GameMode == GameMode.Spectator;
            metaData.Reconnected      = gameMetaData?.Reconnected ?? false;
            metaData.Resumable        = gameMetaData?.ServerInfo?.Resumable ?? false;
            metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (playerInfo?.FriendlyPlayerId > 0 ? playerInfo?.FriendlyPlayerId : null);
            var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;

            if (scenarioId > 0)
            {
                metaData.ScenarioId = scenarioId;
            }
            var build = gameMetaData?.HearthstoneBuild ?? game?.HearthstoneBuild ?? (game != null ? BuildDates.GetByDate(game.StartTime) : null);

            if (build > 0)
            {
                metaData.HearthstoneBuild = build;
            }
            if (game?.BrawlSeasonId > 0)
            {
                metaData.BrawlSeason = game.BrawlSeasonId;
            }
            if (game?.RankedSeasonId > 0)
            {
                metaData.LadderSeason = game.RankedSeasonId;
            }
            return(metaData);
        }
Exemple #25
0
 public UploadStatusChangedEventArgs(int uploadId, UploadMetaData data)
 {
     UploadId = uploadId;
     Data     = data;
 }
 public static async Task <LogUploadRequest> CreateUploadRequest(UploadMetaData metaData)
 => await Client.CreateUploadRequest(metaData, await GetUploadToken());
		public PlayerInfo(UploadMetaData.Player player1, UploadMetaData.Player player2, int friendlyPlayerId = -1)
		{
			Player1 = player1;
			Player2 = player2;
			FriendlyPlayerId = friendlyPlayerId;
		}