public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character      = request.Session.Character;
                var corporationEID = character.CorporationEid;
                var resultRole     = CorporationRole.NotDefined;

                var corporation = Corporation.GetOrThrow(corporationEID);

                var role = corporation.GetMemberRole(character);

                if (role.IsAnyRole(CorporationRole.CEO))
                {
                    resultRole = resultRole | CorporationRole.CEO; //force add ceo role
                }


                //not ceo, not boardmember -> drop role is permitted
                corporation.SetMemberRole(character, resultRole);
                corporation.WriteRoleHistory(character, character, resultRole, role);
                CorporationData.RemoveFromCache(corporation.Eid);

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

                scope.Complete();
            }
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character = request.Session.Character;

                var corporationeid = character.CorporationEid;
                DefaultCorporationDataCache.IsCorporationDefault(corporationeid).ThrowIfTrue(ErrorCodes.CharacterMustBeInPrivateCorporation);

                var role = Corporation.GetRoleFromSql(character);
                role.IsAnyRole(CorporationRole.CEO, CorporationRole.DeputyCEO, CorporationRole.HRManager, CorporationRole.PRManager).ThrowIfFalse(ErrorCodes.InsufficientPrivileges);

                //do the work
                _corporationManager.DeleteYellowPages(corporationeid);

                var entry  = _corporationManager.GetYellowPages(corporationeid);
                var result = new Dictionary <string, object> {
                    { k.data, entry }
                };
                Message.Builder.FromRequest(request).WithData(result).Send();
                CorporationData.RemoveFromCache(corporationeid);

                scope.Complete();
            }
        }
Example #3
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 character = request.Session.Character;
                var color     = request.Data.GetOrDefault <int>(k.color);

                var corporation = character.GetPrivateCorporationOrThrow().CheckAccessAndThrowIfFailed(character, CorporationRole.CEO, CorporationRole.DeputyCEO);

                corporation.SetColor(color);

                var corpInfo = corporation.GetInfoDictionaryForMember(character);
                Message.Builder.FromRequest(request).WithData(corpInfo).Send();

                CorporationData.RemoveFromCache(corporation.Eid);

                scope.Complete();
            }
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character = request.Session.Character;
                character.IsInTraining().ThrowIfTrue(ErrorCodes.TrainingCharacterInvolved);
                var corporation = character.GetCorporation();

                //deal with taxrate
                if (request.Data.TryGetValue(k.taxRate, out int taxRate))
                {
                    corporation.CanSetTaxRate(character).ThrowIfFalse(ErrorCodes.AccessDenied);
                    corporation.TaxRate = taxRate;
                }


                //deal with private profile
                if (request.Data.TryGetValue(k.privateProfile, out Dictionary <string, object> privateProfile))
                {
                    corporation.IsAnyRole(character, CorporationRole.PRManager, CorporationRole.CEO, CorporationRole.DeputyCEO).ThrowIfFalse(ErrorCodes.AccessDenied);
                    corporation.SetPrivateProfile(privateProfile);
                }

                //public profile
                if (request.Data.TryGetValue(k.publicProfile, out Dictionary <string, object> publicProfile))
                {
                    corporation.IsAnyRole(character, CorporationRole.PRManager, CorporationRole.CEO, CorporationRole.DeputyCEO).ThrowIfFalse(ErrorCodes.AccessDenied);
                    corporation.SetPublicProfile(publicProfile);
                }

                CorporationData.RemoveFromCache(corporation.Eid);

                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 character = request.Session.Character;

                var primaryactivity   = request.Data.GetOrDefault(k.primaryActivity, -1);
                var primaryzone       = request.Data.GetOrDefault(k.zoneID, -1);
                var primarybase       = request.Data.GetOrDefault(k.baseEID, (long)-1);
                var orientation       = request.Data.GetOrDefault(k.orientation, -1);
                var lookingfor        = request.Data.GetOrDefault(k.lookingFor, -1);
                var preferredfaction  = request.Data.GetOrDefault(k.preferredFaction, -1);
                var providesinsurance = request.Data.GetOrDefault(k.providesInsurance, -1);
                var timezone          = request.Data.GetOrDefault(k.timeZone, -1);
                var requiredactivity  = request.Data.GetOrDefault(k.requiredActivity, -1);
                var communication     = request.Data.GetOrDefault(k.communication, -1);
                var services          = request.Data.GetOrDefault(k.services, -1);

                var updateList = new List <string>();
                var insertDict = new Dictionary <string, object>();

                var corporationeid = character.CorporationEid;

                DefaultCorporationDataCache.IsCorporationDefault(corporationeid).ThrowIfTrue(ErrorCodes.CharacterMustBeInPrivateCorporation);

                var role = Corporation.GetRoleFromSql(character);
                role.IsAnyRole(CorporationRole.CEO, CorporationRole.DeputyCEO, CorporationRole.HRManager, CorporationRole.PRManager).ThrowIfFalse(ErrorCodes.InsufficientPrivileges);

                var update = false;

                var query = Db.Query();

                var id = query.CommandText("select id from yellowpages where corporationeid=@corporationeid")
                         .SetParameter("@corporationeid", corporationeid)
                         .ExecuteScalar <int>();

                if (id > 0)
                {
                    update = true;
                }

                insertDict.Add("corporationeid", corporationeid);

                if (primaryactivity >= 0)
                {
                    insertDict.Add("primaryactivity", primaryactivity);
                    updateList.Add("primaryactivity=@primaryactivity ");
                    query.SetParameter("@primaryactivity", primaryactivity);
                }

                if (primaryzone >= 0)
                {
                    _zoneManager.ContainsZone(primaryzone).ThrowIfFalse(ErrorCodes.ZoneNotFound);
                    insertDict.Add("zoneID", primaryzone);
                    updateList.Add("zoneID = @primaryzone ");
                    query.SetParameter("@primaryzone", primaryzone);
                }

                //set explicitely on the client
                if (request.Data.ContainsKey(k.zoneID) && primaryzone == -1)
                {
                    updateList.Add("zoneID = NULL ");
                }

                //na ezert nem lehet pbs base-t a yellow pagesbe beallitani
                if (primarybase > 0)
                {
                    var dockingBase = _dockingBaseHelper.GetDockingBase(primarybase);
                    insertDict.Add("baseEID", dockingBase.Eid);
                    updateList.Add("baseEID = @primarybase ");
                    query.SetParameter("@primarybase", primarybase);
                }

                if (request.Data.ContainsKey(k.baseEID) && primarybase == -1)
                {
                    updateList.Add("baseEID = NULL ");
                }

                if (orientation >= 0)
                {
                    insertDict.Add("orientation", orientation);
                    updateList.Add("orientation=@orientation ");
                    query.SetParameter("@orientation", orientation);
                }

                if (lookingfor >= 0)
                {
                    insertDict.Add("lookingfor", lookingfor);
                    updateList.Add("lookingfor=@lookingfor ");
                    query.SetParameter("@lookingfor", lookingfor);
                }

                if (preferredfaction >= 0)
                {
                    insertDict.Add("preferredfaction", preferredfaction);
                    updateList.Add("preferredfaction = @preferredfaction ");
                    query.SetParameter("@preferredfaction", preferredfaction);
                }

                if (request.Data.ContainsKey(k.preferredFaction) && preferredfaction == -1)
                {
                    updateList.Add("preferredfaction = NULL ");
                }

                if (providesinsurance >= 0)
                {
                    insertDict.Add("providesinsurance", providesinsurance);
                    updateList.Add("providesinsurance=@providesinsurance ");
                    query.SetParameter("@providesinsurance", providesinsurance);
                }

                if (timezone >= 0)
                {
                    insertDict.Add("timezone", timezone);
                    updateList.Add("timezone=@timezone ");
                    query.SetParameter("@timezone", timezone);
                }

                if (requiredactivity >= 0)
                {
                    insertDict.Add("requiredactivity", requiredactivity);
                    updateList.Add("requiredactivity=@requiredactivity ");
                    query.SetParameter("@requiredactivity", requiredactivity);
                }

                if (communication >= 0)
                {
                    insertDict.Add("communication", communication);
                    updateList.Add("communication=@communication ");
                    query.SetParameter("@communication", communication);
                }

                if (services >= 0)
                {
                    insertDict.Add("services", services);
                    updateList.Add("services=@services");
                    query.SetParameter("@services", services);
                }

                updateList.Count.ThrowIfEqual(0, ErrorCodes.NothingDefined);

                string cmdStr;

                if (update)
                {
                    cmdStr = "update yellowpages set " + updateList.ArrayToString() + " where id=@id";
                    query.CommandText(cmdStr).SetParameter("@id", id);
                }
                else
                {
                    cmdStr = insertDict.ToInsertString("yellowpages", "nothing");
                    query.CommandText(cmdStr);
                }

                query.ExecuteNonQuery().ThrowIfNotEqual(1, ErrorCodes.SQLExecutionError);

                var entry  = _corporationManager.GetYellowPages(corporationeid);
                var result = new Dictionary <string, object> {
                    { k.data, entry }
                };
                Message.Builder.FromRequest(request).WithData(result).Send();
                CorporationData.RemoveFromCache(corporationeid);

                scope.Complete();
            }
        }
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character = request.Session.Character;
                var member    = Character.Get(request.Data.GetOrDefault <int>(k.memberID));
                var role      = request.Data.GetOrDefault <CorporationRole>(k.role);

                character.IsInTraining().ThrowIfTrue(ErrorCodes.TrainingCharacterInvolved);


                var corporation = character.GetCorporation().CheckAccessAndThrowIfFailed(character, CorporationRole.CEO, CorporationRole.DeputyCEO);

                var isIssuerCEO = corporation.HasAllRoles(character, CorporationRole.CEO);

                //check target
                corporation.IsMember(member).ThrowIfFalse(ErrorCodes.NotMemberOfCorporation);

                _corporationManager.IsInLeavePeriod(member).ThrowIfTrue(ErrorCodes.RoleChangeOnLeavingMember);

                var CEOBitSet = ((int)role & (int)CorporationRole.CEO) > 0;

                if (!isIssuerCEO)
                {
                    //only CEO can set a roles of a CEO
                    corporation.HasAllRoles(member, CorporationRole.CEO).ThrowIfTrue(ErrorCodes.InsufficientPrivileges);
                }

                (CEOBitSet && !isIssuerCEO).ThrowIfTrue(ErrorCodes.InsufficientPrivileges);

                //issuer is ceo and he/she wants to clear his/her own CEO role
                if (isIssuerCEO && (member == character))
                {
                    CEOBitSet.ThrowIfFalse(ErrorCodes.CharacterIsCEOOperationFailed);
                }

                //if the CEO wants to resign
                if (isIssuerCEO && (member != character))
                {
                    //ceo bit set
                    if (CEOBitSet)
                    {
                        //target member VS current corpmember amount check
                        corporation.CheckMaxMemberCountAndThrowIfFailed(member);

                        //resign as CEO -----------

                        //old roles
                        var currentRole = corporation.GetMemberRole(character);
                        currentRole = currentRole.ClearRole(CorporationRole.CEO);
                        currentRole = currentRole.SetRole(CorporationRole.DeputyCEO);

                        //clear the current CEO's CEO role
                        corporation.SetMemberRole(character, currentRole);

                        //new roles
                        var newRole = corporation.GetMemberRole(character);

                        corporation.WriteRoleHistory(character, character, newRole, currentRole);
                        //%%% remove alliance board nem kene?
                    }
                }

                role = role.CleanUpHangarAccess();
                role = role.CleanUpCharacterPBSRoles();

                //target member's role
                var oldRole = corporation.GetMemberRole(member);

                const int deputyMask = (int)CorporationRole.DeputyCEO;

                var targetDeputyStatus    = (int)oldRole & deputyMask;
                var targetNewDeputyStatus = (int)role & deputyMask;

                (targetNewDeputyStatus != targetDeputyStatus && !isIssuerCEO).ThrowIfTrue(ErrorCodes.InsufficientPrivileges);

                //set the actual target member's role
                corporation.SetMemberRole(member, role);
                corporation.WriteRoleHistory(character, member, role, oldRole);
                //            corporation.GetLogger().SetMemberRole(character,member);
                corporation.Save();

                _channelManager.SetMemberRole(corporation.ChannelName, member, role);

                if (member.IsDocked)
                {
                    var dockingBase = _dockingBaseHelper.GetDockingBase(member.CurrentDockingBaseEid);
                    if (dockingBase is PBSDockingBase pbsDockingBase)
                    {
                        _channelManager.SetMemberRole(pbsDockingBase.ChannelName, member, role);
                    }
                }

                CorporationData.RemoveFromCache(corporation.Eid);

                scope.Complete();
            }
        }