コード例 #1
0
        private async Task GetPlayerSteamData(Player player)
        {
            var steamData = (await _steamService.GetPlayerSummary(player.SteamId)).ToSteamPlayerDataResponse();

            player.SteamName       = steamData.SteamName;
            player.SteamProfileUrl = new Uri(steamData.ProfileUrl);
            player.SteamAvatarUri  = new Uri(steamData.Avatar);
        }
コード例 #2
0
        private async Task UpdatePlayerSteamData(Player player)
        {
            var playerSteamData = (await _steamService.GetPlayerSummary(player.SteamId)).ToSteamPlayerDataResponse();

            player.SteamName       = playerSteamData.SteamName;
            player.SteamProfileUrl = new Uri(playerSteamData.ProfileUrl);
            player.SteamAvatarUri  = new Uri(playerSteamData.Avatar);
            player.Country         = playerSteamData.LocCountryCode;
        }
コード例 #3
0
        public async Task <SteamStatusPlayerDataResponse> Handle(GetPlayerSteamStatusQuery request, CancellationToken cancellationToken)
        {
            var playerSteamId = (await _statisticsDbContext.Players.FindAsync(request.Id)).SteamId;

            return((await _steamService.GetPlayerSummary(playerSteamId)).ToSteamStatusPlayerDataResponse());
        }
コード例 #4
0
        public async Task <AuthenticationResult> Authenticate(Dictionary <string, string> authenticationCtx, IUserService userService)
        {
            if (authenticationCtx["provider"] != PROVIDER_NAME)
            {
                return(null);
            }

            string ticket;
            var    pId = new PlatformId {
                Platform = PROVIDER_NAME
            };

            if (!authenticationCtx.TryGetValue("ticket", out ticket) || string.IsNullOrWhiteSpace(ticket))
            {
                return(AuthenticationResult.CreateFailure("Steam session ticket must not be empty.", pId, authenticationCtx));
            }
            try
            {
                var steamId = await _authenticator.AuthenticateUserTicket(ticket);

                if (!steamId.HasValue)
                {
                    return(AuthenticationResult.CreateFailure("Invalid steam session ticket.", pId, authenticationCtx));
                }
                pId.OnlineId = steamId.ToString();

                if (_vacEnabled)
                {
                    AuthenticationResult result = null;
                    string vacSessionId         = null;
                    try
                    {
                        vacSessionId = await _steamService.OpenVACSession(steamId.Value.ToString());

                        _vacSessions[steamId.Value] = vacSessionId;
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(LogLevel.Error, "authenticator.steam", $"Failed to start VAC session for {steamId}", ex);
                        result = AuthenticationResult.CreateFailure($"Failed to start VAC session.", pId, authenticationCtx);
                    }

                    try
                    {
                        if (!await _steamService.RequestVACStatusForUser(steamId.Value.ToString(), vacSessionId))
                        {
                            result = AuthenticationResult.CreateFailure($"Connection refused by VAC.", pId, authenticationCtx);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(LogLevel.Error, "authenticator.steam", $"Failed to check VAC status for  {steamId}", ex);
                        result = AuthenticationResult.CreateFailure($"Failed to check VAC status for user.", pId, authenticationCtx);
                    }

                    if (result != null)//Failed
                    {
                        if (_vacSessions.TryRemove(steamId.Value, out vacSessionId))
                        {
                            try
                            {
                                await _steamService.CloseVACSession(steamId.ToString(), vacSessionId);
                            }
                            catch (Exception ex)
                            {
                                _logger.Log(LogLevel.Error, $"authenticator.steam", $"Failed to close vac session for user '{steamId}'", ex);
                            }
                        }
                        return(result);
                    }
                }
                var steamIdString = steamId.GetValueOrDefault().ToString();
                var user          = await userService.GetUserByClaim(PROVIDER_NAME, ClaimPath, steamIdString);

                var playerSummary = await _steamService.GetPlayerSummary(steamId.Value);

                if (user == null)
                {
                    var uid = Guid.NewGuid().ToString("N");

                    user = await userService.CreateUser(uid, JObject.FromObject(new { steamid = steamIdString, pseudo = playerSummary.personaname, avatar = playerSummary.avatarfull }));

                    var claim = new JObject();
                    claim[ClaimPath] = steamIdString;
                    user             = await userService.AddAuthentication(user, PROVIDER_NAME, claim, steamIdString);
                }
                else
                {
                    user.UserData["pseudo"] = playerSummary.personaname;
                    user.UserData["avatar"] = playerSummary.avatarfull;
                    await userService.UpdateUserData(user.Id, user.UserData);
                }

                return(AuthenticationResult.CreateSuccess(user, pId, authenticationCtx));
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Debug, "authenticator.steam", $"Steam authentication failed. Ticket : {ticket}", ex);
                return(AuthenticationResult.CreateFailure($"Invalid steam session ticket.", pId, authenticationCtx));
            }
        }