Exemple #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)));
        }
Exemple #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)));
        }
Exemple #3
0
        public string CreateSignature([JetBrains.Annotations.NotNull] VivoxTokenClaims claims)
        {
            if (claims == null)
            {
                throw new ArgumentNullException(nameof(claims));
            }

            string claimsString = JsonConvert.SerializeObject(claims);

            //Base64URLEncoding from: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/master/src/Microsoft.IdentityModel.Tokens/Base64UrlEncoder.cs
            claimsString = Base64UrlEncoder.Encode(claimsString);

            //e30 is {} header
            string signable = $"e30.{claimsString}";

            return($"{signable}.{SHA256Hash(VIVOX_API_KEY, signable)}");
        }
Exemple #4
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)));
        }