Example #1
0
        public async Task <IActionResult> JoinGuildChat([FromServices] ICharacterSessionRepository characterSessionRepository,
                                                        [FromServices] IFactoryCreatable <VivoxTokenClaims, VivoxTokenClaimsCreationContext> claimsFactory,
                                                        [FromServices] IGuildCharacterMembershipRepository guildMembershipRepository,
                                                        [FromServices] IVivoxTokenSignService signService)
        {
            int accountId = this.ClaimsReader.GetAccountIdInt(User);

            //If the user doesn't actually have a claimed session in the game
            //then we shouldn't log them into Vivox.
            if (!await characterSessionRepository.AccountHasActiveSession(accountId))
            {
                return(BuildFailedResponseModel(VivoxLoginResponseCode.NoActiveCharacterSession));
            }

            int characterId = await RetrieveSessionCharacterIdAsync(characterSessionRepository, accountId);

            if (!await guildMembershipRepository.ContainsAsync(characterId))
            {
                return(BuildFailedResponseModel(VivoxLoginResponseCode.ChannelUnavailable));
            }

            int guildId = (await guildMembershipRepository.RetrieveAsync(characterId)).GuildId;

            //TODO: Use a factory for channel name generation maybe?
            VivoxTokenClaims claims = claimsFactory.Create(new VivoxTokenClaimsCreationContext(characterId, VivoxAction.JoinChannel, new VivoxChannelData(false, $"Guild-{guildId}")));

            //We don't send it back in a JSON form even though it's technically a JSON object
            //because the client just needs it as a raw string anyway to put through the Vivox client API.
            return(BuildSuccessfulResponseModel(new VivoxChannelJoinResponse(signService.CreateSignature(claims), claims.DestinationSIPURI)));
        }
Example #2
0
        public async Task <IActionResult> JoinZoneProximityChat([FromServices] ICharacterSessionRepository characterSessionRepository,
                                                                [FromServices] IFactoryCreatable <VivoxTokenClaims, VivoxTokenClaimsCreationContext> claimsFactory,
                                                                [FromServices] IVivoxTokenSignService signService)
        {
            int accountId = this.ClaimsReader.GetAccountIdInt(User);

            //If the user doesn't actually have a claimed session in the game
            //then we shouldn't log them into Vivox.
            if (!await characterSessionRepository.AccountHasActiveSession(accountId))
            {
                return(BuildFailedResponseModel(VivoxLoginResponseCode.NoActiveCharacterSession));
            }

            int characterId = await RetrieveSessionCharacterIdAsync(characterSessionRepository, accountId);

            CharacterSessionModel session = await characterSessionRepository.RetrieveAsync(characterId);

            //Players in the same zone will all join the same proximity channel such as Prox-1.
            //They can use this for proximity text and voice chat.
            //TODO: Use a factory for channel name generation maybe?
            VivoxTokenClaims claims = claimsFactory.Create(new VivoxTokenClaimsCreationContext(characterId, VivoxAction.JoinChannel, new VivoxChannelData(true, $"Prox-{session.ZoneId}")));

            //We don't send it back in a JSON form even though it's technically a JSON object
            //because the client just needs it as a raw string anyway to put through the Vivox client API.
            return(BuildSuccessfulResponseModel(new VivoxChannelJoinResponse(signService.CreateSignature(claims), claims.DestinationSIPURI)));
        }
Example #3
0
        public async Task <IActionResult> LoginVivox([FromServices] ICharacterSessionRepository characterSessionRepository,
                                                     [FromServices] IFactoryCreatable <VivoxTokenClaims, VivoxTokenClaimsCreationContext> claimsFactory,
                                                     [FromServices] IVivoxTokenSignService signService)
        {
            int accountId = this.ClaimsReader.GetAccountIdInt(User);

            //If the user doesn't actually have a claimed session in the game
            //then we shouldn't log them into Vivox.
            if (!await characterSessionRepository.AccountHasActiveSession(accountId))
            {
                return(BuildFailedResponseModel(VivoxLoginResponseCode.NoActiveCharacterSession));
            }

            int characterId = await RetrieveSessionCharacterIdAsync(characterSessionRepository, accountId);

            VivoxTokenClaims claims = claimsFactory.Create(new VivoxTokenClaimsCreationContext(characterId, VivoxAction.Login));

            //We don't send it back in a JSON form even though it's technically a JSON object
            //because the client just needs it as a raw string anyway to put through the Vivox client API.
            return(BuildSuccessfulResponseModel(signService.CreateSignature(claims)));
        }