Exemplo 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)));
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 public CharacterZoneOnHubConnectionEventListener(
     [JetBrains.Annotations.NotNull] ILogger <CharacterZoneOnHubConnectionEventListener> logger,
     [JetBrains.Annotations.NotNull] ISocialServiceToGameServiceClient socialToGameClient,
     [JetBrains.Annotations.NotNull] IClaimsPrincipalReader claimsReader)
 {
     Logger             = logger ?? throw new ArgumentNullException(nameof(logger));
     SocialToGameClient = socialToGameClient ?? throw new ArgumentNullException(nameof(socialToGameClient));
     ClaimsReader       = claimsReader ?? throw new ArgumentNullException(nameof(claimsReader));
 }
Exemplo n.º 3
0
 /// <inheritdoc />
 public TextChatHub(IClaimsPrincipalReader claimsReader,
                    ILogger <TextChatHub> logger,
                    [JetBrains.Annotations.NotNull] ISocialServiceToGameServiceClient socialToGameClient,
                    [JetBrains.Annotations.NotNull] IConnectionToZoneMappable zoneLookupService,
                    [JetBrains.Annotations.NotNull] IEnumerable <IOnHubConnectionEventListener> onConnectionHubListeners,
                    [JetBrains.Annotations.NotNull] IServiceProvider serviceProvider,
                    [JetBrains.Annotations.NotNull] IEntityDataLockingService entityLockService,
                    [JetBrains.Annotations.NotNull] IEnumerable <IEntityCollectionRemovable> entityRemovable)
     : base(claimsReader, logger)
 {
     SocialToGameClient       = socialToGameClient ?? throw new ArgumentNullException(nameof(socialToGameClient));
     ZoneLookupService        = zoneLookupService ?? throw new ArgumentNullException(nameof(zoneLookupService));
     OnConnectionHubListeners = onConnectionHubListeners ?? throw new ArgumentNullException(nameof(onConnectionHubListeners));
     ServiceProvider          = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     EntityLockService        = entityLockService ?? throw new ArgumentNullException(nameof(entityLockService));
     EntityRemovable          = entityRemovable ?? throw new ArgumentNullException(nameof(entityRemovable));
 }
Exemplo n.º 4
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)));
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
0
 /// <inheritdoc />
 public CharacterGuildOnHubConnectionEventListener([JetBrains.Annotations.NotNull] ILogger <CharacterGuildOnHubConnectionEventListener> logger, [JetBrains.Annotations.NotNull] ISocialServiceToGameServiceClient socialToGameClient, [JetBrains.Annotations.NotNull] IClaimsPrincipalReader claimsReader, IEntityGuidMappable <CharacterGuildMembershipStatusResponse> guildStatusMappable)
 {
     Logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     SocialToGameClient  = socialToGameClient ?? throw new ArgumentNullException(nameof(socialToGameClient));
     ClaimsReader        = claimsReader ?? throw new ArgumentNullException(nameof(claimsReader));
     GuildStatusMappable = guildStatusMappable;
 }