Example #1
0
        public async Task <bool> TransferCharacter(int sourceCharacterId, int targetCharacterId)
        {
            var user = await userService.GetUserWithCharacters(httpContextReader.CurrentUserId) ??
                       throw new EntityNotFoundException("User not found");

            var(sourceCharacter, targetCharacter) =
                (user.Characters.FirstOrDefault(c => c.Id == sourceCharacterId) ??
                 throw new EntityNotFoundException("Character not found"),
                 user.Characters.FirstOrDefault(c => c.Id == targetCharacterId) ??
                 throw new EntityNotFoundException("Character not found"));

            using (var transaction = database.BeginTransaction().Transaction)
            {
                await ExecuteTransferCharacter(sourceCharacter, targetCharacter);

                transaction.Complete();
            }

            try
            {
                await emailSender.Send(EmailMessages.TransferCharacterEmail(user.Email));

                mtaManager.CallFunction(MtaResources.WebsiteHttpFunctions, MtaFunctions.TransferCharacter);
            }
            catch (MTARequestException)
            {
            }

            return(true);
        }
Example #2
0
        public async Task <GetHomepageStatsResponse> Handle(GetHomepageStatsRequest request,
                                                            CancellationToken cancellationToken)
        {
            HomepageStatsResult homepageStats = default;

            await Task.Run(() => homepageStats = mtaManager
                           .CallFunction(MtaResources.WebsiteHttpFunctions, MtaFunctions.GetOnlinePlayers)
                           .Replace("[", string.Empty)
                           .Replace("]", string.Empty)
                           .FromJSON <HomepageStatsResult>(JsonSettings.JsonSerializerOptions));

            homepageStats = homepageStats with
            {
                ServerAddress = $"{mtaManager.MtaServerSettings.Host}:{homepageStats.ServerPort}"
            };

            return(new GetHomepageStatsResponse {
                HomepageStats = homepageStats
            });
        }
    }