public Hashtable getWantedKit(string playerName, int index)
        {
            BattlelogClient bclient = new BattlelogClient();
            Hashtable loadout = bclient.getStats(playerName, index);
            if (loadout != null)
            {
                personaID = bclient.personaID;
                activeKit = index;
                active_Kit = (kits)index;

                return (loadout);
            }
            else
                return (null);
        }
Exemple #2
0
        public IActionResult GetNumPlayersOnServer(string platform, string guid, SlotResponseType type = SlotResponseType.Battlelog)
        {
            try
            {
                var cacheKey = guid;
                var gameId   = GetGameIdFromCache(cacheKey);
                ServerDetailsViewModel model = null;

fetchNewGameId:
                if (!string.IsNullOrEmpty(gameId))
                {
                    _logger?.LogInformation("GameId {gameId} fetched from cache for Guid {guid}", gameId, guid);

                    _logger?.LogInformation("Retrieving server slots for gameId {gameId}", gameId);
                    model = _companionService?.GetServerDetails(gameId);

                    // Check if guid matches (in other words whether the gameId was correct or not)
                    if (!guid.Equals(model?.Guid, StringComparison.OrdinalIgnoreCase))
                    {
                        gameId = null;
                        goto fetchNewGameId;
                    }
                }
                else
                {
                    var serverInfo = BattlelogClient.GetServerShow(guid, platform);
                    gameId = serverInfo.gameId;

                    _distributedCache.SetStringAsync(cacheKey, gameId).ConfigureAwait(false);
                    _logger?.LogInformation("GameId {gameId} added to cache for Guid {guid}", gameId, guid);

                    _logger?.LogInformation("Retrieving server slots for gameId {gameId}", gameId);
                    model = _companionService?.GetServerDetails(gameId);
                }

                if (model?.Slots == null)
                {
                    return(BadRequestBattlelogResponse <SlotTypesViewModel>(null, "Couldn't retrieve server slots"));
                }

                return(type switch {
                    SlotResponseType.Companion => SuccessBattlelogResponse(model.Slots),
                    _ => Ok(model.CompanionPlayerCountsToBattlelog()),
                });
            }
        public Hashtable getActiveKit(string playerName)
        {
            BattlelogClient bclient = new BattlelogClient();
            Hashtable loadout = null;
            for (int i = 0; i < 5; i++)
            {
                if (i == 5)
                    return null;

                loadout = bclient.getStats(playerName, i);
                if(loadout != null)
                {
                    activeKit = i;
                    active_Kit = (kits)i;
                    if ((bool)loadout["isActive"])
                        break;
                }
            }
            personaID = bclient.personaID;
            return (loadout);
        }