예제 #1
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var corpName  = request.Data.GetOrDefault <string>(k.name).Trim();
                var nick      = request.Data.GetOrDefault <string>(k.nick).Trim();
                var character = request.Session.Character;

                //get corp and role check
                var corporation = character.GetCorporation().CheckAccessAndThrowIfFailed(character, CorporationRole.CEO, CorporationRole.DeputyCEO);

                (corporation is PrivateCorporation).ThrowIfFalse(ErrorCodes.CorporationMustBePrivate);

                //nick check
                nick.Length.ThrowIfGreater(6, ErrorCodes.CorporationNickTooLong);
                nick.Length.ThrowIfLess(2, ErrorCodes.CorporationNickTooShort);
                nick.AllowExtras().ThrowIfFalse(ErrorCodes.CorporationNickNotAllowedCharacters);
                string.IsNullOrEmpty(nick).ThrowIfTrue(ErrorCodes.CorporationNickNotDefined);

                //name check
                corpName.Length.ThrowIfGreater(128, ErrorCodes.CorporationNameTooLong);
                corpName.Length.ThrowIfLessOrEqual(3, ErrorCodes.CorporationNameTooShort);
                corpName.AllowExtras().ThrowIfFalse(ErrorCodes.CorporationNameNotAllowedCharacters);
                string.IsNullOrEmpty(corpName).ThrowIfTrue(ErrorCodes.CorporationNameNotDefined);

                //existence check
                Corporation.IsNameOrNickTaken(corpName, nick).ThrowIfTrue(ErrorCodes.NameTaken);

                //write OLD name to alias history
                Corporation.WriteRenameHistory(corporation.Eid, character, corporation.CorporationName, corporation.CorporationNick);

                var product = _mtProductHelper.GetByAccountTransactionType(AccountTransactionType.CorporationRename);

                var account = _accountManager.Repository.Get(request.Session.AccountId).ThrowIfNull(ErrorCodes.AccountNotFound);
                var wallet  = _accountManager.GetWallet(account, AccountTransactionType.CorporationRename);
                wallet.Balance -= product.price;

                var e = new AccountTransactionLogEvent(account, AccountTransactionType.CorporationRename)
                {
                    Credit = wallet.Balance, CreditChange = -product.price
                };
                _accountManager.LogTransaction(e);

                corporation.SetName(corpName, nick);

                _accountRepository.Update(account);

                Transaction.Current.OnCommited(() =>
                {
                    //force cache reload
                    CorporationData.RemoveFromCache(corporation.Eid);

                    //send to members
                    var corpInfo = corporation.GetInfoDictionaryForMember(character);
                    Message.Builder.SetCommand(Commands.CorporationGetMyInfo).WithData(corpInfo).ToCharacters(corporation.GetCharacterMembers()).Send();
                });

                scope.Complete();
            }
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var account = _accountManager.Repository.Get(request.Session.AccountId).ThrowIfNull(ErrorCodes.AccountNotFound);
                var product = _mtProductHelper.GetByAccountTransactionType(AccountTransactionType.EpBoost);

                var wallet = _accountManager.GetWallet(account, AccountTransactionType.EpBoost);
                wallet.Balance -= product.price;
                var e = new AccountTransactionLogEvent(account, AccountTransactionType.EpBoost)
                {
                    Credit = wallet.Balance, CreditChange = -product.price
                };
                _accountManager.LogTransaction(e);

                var currentValidUntil = account.ValidUntil ?? DateTime.MaxValue;

                if (currentValidUntil == DateTime.MaxValue || currentValidUntil < DateTime.Now)
                {
                    //validuntil is NULL -- never purchased an EP boost
                    //validUntil is in the past

                    var startTime = DateTime.Now;
                    var endTime   = DateTime.Now.AddDays(EP_BOOST_PERIOD_LENGTH_IN_DAYS);
                    _accountManager.ExtensionSubscriptionStart(account, startTime, endTime);
                    account.ValidUntil = endTime;
                }
                else
                {
                    //validUntil > now  -- is in the future

                    //extend validuntil
                    var extendedValidUntil = currentValidUntil.AddDays(EP_BOOST_PERIOD_LENGTH_IN_DAYS);

                    _accountManager.ExtensionSubscriptionExtend(account, extendedValidUntil);
                    account.ValidUntil = extendedValidUntil;
                }

                //for stats and stuff
                account.PayingCustomer = true;

                _accountRepository.Update(account);

                Transaction.Current.OnCommited(() =>
                {
                    var info = new Dictionary <string, object>
                    {
                        { k.validUntil, account.ValidUntil }
                    };

                    Message.Builder.FromRequest(request).WithData(info).Send();
                });

                scope.Complete();
            }
        }
예제 #3
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var account = _accountManager.Repository.Get(request.Session.AccountId).ThrowIfNull(ErrorCodes.AccountNotFound);

                var character = Character.Get(request.Data.GetOrDefault <int>(k.characterID));

                if (character == Character.None)
                {
                    throw new PerpetuumException(ErrorCodes.CharacterNotFound);
                }

                //only characters that belong to the issuers account
                if (character.AccountId != account.Id)
                {
                    throw new PerpetuumException(ErrorCodes.AccessDenied);
                }

                (character.IsDocked).ThrowIfFalse(ErrorCodes.CharacterHasToBeDocked);

                var product = _mtProductHelper.GetByAccountTransactionType(AccountTransactionType.ExtensionReset);
                var wallet  = _accountManager.GetWallet(account, AccountTransactionType.ExtensionReset);

                wallet.Balance -= product.price;

                var e = new AccountTransactionLogEvent(account, AccountTransactionType.ExtensionReset)
                {
                    Credit       = wallet.Balance,
                    CreditChange = -product.price
                };

                _accountManager.LogTransaction(e);

                _accountRepository.Update(account);

                //current extensions
                var extensionCollection = character.GetExtensions();

                //default extensions
                var defaultExtensionHandler = new CharacterDefaultExtensionHelper(character);

                foreach (var extension in extensionCollection)
                {
                    //returns 0 if the extension is not starter extension
                    //returns the minimum level if the extension is starter
                    int newLevel;
                    defaultExtensionHandler.IsStartingExtension(extension, out newLevel);

                    var resultExtension = new Extension(extension.id, newLevel);

                    character.SetExtension(resultExtension);
                }

                character.DeleteAllSpentPoints();

                //ezt nem csinalja, csak nyersen reseteli az extensionoket

                /*
                 * ExtensionHelper.DeleteAllNonForeverPenaltyPoints(character);
                 */

                // %%% itt hagytuk abba

                Message.Builder.FromRequest(request).WithOk().Send();

                scope.Complete();
            }
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var account = _accountManager.Repository.Get(request.Session.AccountId).ThrowIfNull(ErrorCodes.AccountNotFound);

                var nick            = request.Data.GetOrDefault <string>(k.nick).Trim();
                var targetCharacter = Character.Get(request.Data.GetOrDefault <int>(k.characterID));

                if (targetCharacter == Character.None)
                {
                    throw new PerpetuumException(ErrorCodes.CharacterNotFound);
                }

                //only characters that belong to the issuers account
                if (targetCharacter.AccountId != account.Id)
                {
                    throw new PerpetuumException(ErrorCodes.AccessDenied);
                }

                //sosem fordulhat elo, de azert megis
                if (!targetCharacter.IsActive)
                {
                    throw new PerpetuumException(ErrorCodes.AccessDenied);
                }

                //check nick and other conditions
                Character.CheckNickAndThrowIfFailed(nick, request.Session.AccessLevel, account);

                //withdrw credit
                var product = _mtProductHelper.GetByAccountTransactionType(AccountTransactionType.CharacterRename);
                var wallet  = _accountManager.GetWallet(account, AccountTransactionType.CharacterRename);
                wallet.Balance -= product.price;

                var e = new AccountTransactionLogEvent(account, AccountTransactionType.CharacterRename)
                {
                    Credit       = wallet.Balance,
                    CreditChange = -product.price
                };

                _accountManager.LogTransaction(e);

                //do the heavy lifting
                var oldNick = targetCharacter.Nick;
                targetCharacter.Nick = nick;

                //log
                Db.Query().CommandText("INSERT dbo.characternickhistory ( characterid, accountid, nick ) VALUES  ( @characterid, @accountid, @nick )")
                .SetParameter("@characterid", targetCharacter.Id)
                .SetParameter("@accountid", account.Id)
                .SetParameter("@nick", oldNick)
                .ExecuteNonQuery();

                _accountRepository.Update(account);

                Transaction.Current.OnCommited(() =>
                {
                    var character = request.Session.Character;

                    if (_characterProfiles is CachedReadOnlyRepository <int, CharacterProfile> cached)
                    {
                        cached.Remove(character.Id);
                    }

                    var profile = character.GetFullProfile();
                    Message.Builder
                    .FromRequest(request)
                    .SetCommand(Commands.CharacterGetMyProfile)
                    .WithData(profile).Send();
                });

                scope.Complete();
            }
        }