Ejemplo n.º 1
0
        public async Task <IActionResult> GetCharacterGuildList([NotNull][FromServices] IGuildCharacterMembershipRepository guildCharacterMembershipRepository,
                                                                [FromServices] ISocialServiceToGameServiceClient socialToGameClient)
        {
            if (guildCharacterMembershipRepository == null)
            {
                throw new ArgumentNullException(nameof(guildCharacterMembershipRepository));
            }

            CharacterSessionDataResponse session = await socialToGameClient.GetCharacterSessionDataByAccount(ClaimsReader.GetAccountIdInt(User));

            if (!session.isSuccessful)
            {
                return(BuildFailedResponseModel(CharacterGuildMembershipStatusResponseCode.GeneralServerError));
            }

            //No guild check
            if (!await guildCharacterMembershipRepository.ContainsAsync(session.CharacterId))
            {
                return(BuildFailedResponseModel(CharacterGuildMembershipStatusResponseCode.NoGuild));
            }

            var playerGuildMembership = await guildCharacterMembershipRepository.RetrieveAsync(session.CharacterId);

            int[] roster = await guildCharacterMembershipRepository.GetEntireGuildRosterAsync(playerGuildMembership.GuildId);

            return(BuildSuccessfulResponseModel(new CharacterGuildListResponseModel(roster)));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <HubOnConnectionState> OnConnected([JetBrains.Annotations.NotNull] Hub hubConnectedTo)
        {
            if (hubConnectedTo == null)
            {
                throw new ArgumentNullException(nameof(hubConnectedTo));
            }

            //We should never be here unless auth worked
            //so we can assume that and just try to request character session data
            //for the account.
            CharacterSessionDataResponse characterSessionDataResponse = await SocialToGameClient.GetCharacterSessionDataByAccount(ClaimsReader.GetAccountIdInt(hubConnectedTo.Context.User))
                                                                        .ConfigureAwaitFalse();

            //TODO: To support website chat we shouldn't disconnect just because they don't have a zone session.
            //If the session data request fails we should just abort
            //and disconnect, the user shouldn't be connecting
            if (!characterSessionDataResponse.isSuccessful)
            {
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning($"Failed to Query SessionData for AccountId: {ClaimsReader.GetAccountId(hubConnectedTo.Context.User)} Reason: {characterSessionDataResponse.ResultCode}");
                }

                //TODO: Eventually we don't want to do this.
                return(HubOnConnectionState.Abort);
            }

            //This is ABSOLUTELY CRITICAL we need to validate that the character header they sent actually
            //is the character they have a session as
            //NOT CHECKING THIS IS EQUIVALENT TO LETTING USERS PRETEND THEY ARE ANYONE!
            if (hubConnectedTo.Context.UserIdentifier != characterSessionDataResponse.CharacterId.ToString())
            {
                //We can log account name and id here, because they were successfully authed.
                if (Logger.IsEnabled(LogLevel.Warning))
                {
                    Logger.LogWarning($"User with AccountId: {ClaimsReader.GetAccountName(hubConnectedTo.Context.User)}:{ClaimsReader.GetAccountId(hubConnectedTo.Context.User)} attempted to spoof as CharacterId: {hubConnectedTo.Context.UserIdentifier} but had session for CharacterID: {characterSessionDataResponse.CharacterId}.");
                }

                return(HubOnConnectionState.Abort);
            }

            if (Logger.IsEnabled(LogLevel.Information))
            {
                Logger.LogInformation($"Recieved SessionData: Id: {characterSessionDataResponse.CharacterId} ZoneId: {characterSessionDataResponse.ZoneId}");
            }

            //TODO: We should have group name builders. Not hardcoded
            //Join the zoneserver's chat channel group
            await hubConnectedTo.Groups.AddToGroupAsync(hubConnectedTo.Context.ConnectionId, $"zone:{characterSessionDataResponse.ZoneId}", hubConnectedTo.Context.ConnectionAborted)
            .ConfigureAwaitFalseVoid();

            return(HubOnConnectionState.Success);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetCharacterFriends([FromServices][JetBrains.Annotations.NotNull] ICharacterFriendRepository friendsRepository,
                                                              [FromServices][JetBrains.Annotations.NotNull] ISocialServiceToGameServiceClient socialServiceClient)
        {
            if (friendsRepository == null)
            {
                throw new ArgumentNullException(nameof(friendsRepository));
            }
            if (socialServiceClient == null)
            {
                throw new ArgumentNullException(nameof(socialServiceClient));
            }

            //Find the character
            CharacterSessionDataResponse response = await socialServiceClient.GetCharacterSessionDataByAccount(ClaimsReader.GetAccountIdInt(User));

            if (response.ResultCode == CharacterSessionDataResponseCode.NoSessionAvailable)
            {
                return(Json(new CharacterFriendListResponseModel(Array.Empty <int>())));
            }

            int[] friendsCharacterIds = await friendsRepository.GetCharactersFriendsList(response.CharacterId);

            return(Json(new CharacterFriendListResponseModel(friendsCharacterIds)));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> TryAddFriend([FromRoute(Name = "name")][JetBrains.Annotations.NotNull] string characterFriendName,
                                                       [FromServices][JetBrains.Annotations.NotNull] ICharacterFriendRepository friendsRepository,
                                                       [FromServices][JetBrains.Annotations.NotNull] ISocialServiceToGameServiceClient socialServiceClient,
                                                       [FromServices] INameQueryService nameQueryService)
        {
            if (friendsRepository == null)
            {
                throw new ArgumentNullException(nameof(friendsRepository));
            }
            if (socialServiceClient == null)
            {
                throw new ArgumentNullException(nameof(socialServiceClient));
            }
            if (string.IsNullOrEmpty(characterFriendName))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(characterFriendName));
            }

            //Find the character
            CharacterSessionDataResponse response = await socialServiceClient.GetCharacterSessionDataByAccount(ClaimsReader.GetAccountIdInt(User));

            if (response.ResultCode == CharacterSessionDataResponseCode.NoSessionAvailable)
            {
                return(BadRequest());
            }

            var nameReverseQueryResponse = await nameQueryService.RetrievePlayerGuidAsync(characterFriendName);

            //Handle known failure cases first.
            switch (nameReverseQueryResponse.ResultCode)
            {
            case NameQueryResponseCode.UnknownIdError:
                return(BuildFailedResponseModel(CharacterFriendAddResponseCode.CharacterNotFound));

            case NameQueryResponseCode.GeneralServerError:
                return(BuildFailedResponseModel(CharacterFriendAddResponseCode.GeneralServerError));
            }

            //If the player is trying to add himself, just say not found
            if (nameReverseQueryResponse.Result.EntityId == response.CharacterId)
            {
                return(BuildFailedResponseModel(CharacterFriendAddResponseCode.CharacterNotFound));
            }

            //Ok, reverse namequery is a success
            //now we must check some stuff

            //Already friends check
            if (await friendsRepository.IsFriendshipPresentAsync(response.CharacterId, nameReverseQueryResponse.Result.EntityId))
            {
                return(BuildFailedResponseModel(CharacterFriendAddResponseCode.AlreadyFriends));
            }

            if (await friendsRepository.TryCreateAsync(new CharacterFriendModel(response.CharacterId, nameReverseQueryResponse.Result.EntityId)))
            {
                //This is a success, let's tell them about who they added.
                return(BuildSuccessfulResponseModel(new CharacterFriendAddResponseModel(nameReverseQueryResponse.Result)));
            }
            else
            {
                return(BuildFailedResponseModel(CharacterFriendAddResponseCode.GeneralServerError));
            }
        }