public void HandleRequest(IRequest request)
        {
            var character = request.Session.Character;
            var member    = Character.Get(request.Data.GetOrDefault <int>(k.memberID));

            var currentGang = _gangManager.GetGangByMember(member);

            if (currentGang != null)
            {
                throw new PerpetuumException(ErrorCodes.CharacterAlreadyInGang);
            }

            var gang = _gangManager.GetGangByMember(character);

            if (gang == null)
            {
                throw new PerpetuumException(ErrorCodes.CharacterNotInGang);
            }

            gang.CanInvite(character).ThrowIfFalse(ErrorCodes.OnlyGangLeaderOrAssistantCanDoThis);

            _gangInviteService.GetInvite(member).ThrowIfNotNull(ErrorCodes.CharacterAlreadyHasPendingGangInvitation);
            _gangInviteService.AddInvite(new GangInviteInfo(gang.Id, character, member));

            var data = new Dictionary <string, object>
            {
                { k.name, gang.Name }, { k.characterID, character.Id }
            };

            Message.Builder.SetCommand(Commands.GangInvite).WithData(data).ToCharacter(member).Send();
            Message.Builder.FromRequest(request).WithOk().Send();
        }
Пример #2
0
        public void HandleRequest(IRequest request)
        {
            using (var scope = Db.CreateTransaction())
            {
                var character = request.Session.Character;
                var answer    = request.Data.GetOrDefault <int>(k.answer);

                var currentGang = _gangManager.GetGangByMember(character);
                if (currentGang != null)
                {
                    throw new PerpetuumException(ErrorCodes.CharacterAlreadyInGang);
                }

                var gangInvite = _gangInviteService.GetInvite(character).ThrowIfNull(ErrorCodes.NoSuchGangInvite);
                var gang       = _gangManager.GetGang(gangInvite.gangGuid).ThrowIfNull(ErrorCodes.GangNotFound);

                _gangInviteService.RemoveInvite(gangInvite);

                if (answer > 0)
                {
                    _gangManager.JoinMember(gang, character, true);
                }

                Transaction.Current.OnCommited(() =>
                {
                    var data = new Dictionary <string, object>
                    {
                        { k.characterID, gangInvite.member.Id },
                        { k.answer, answer }
                    };

                    // feladonak
                    Message.Builder.SetCommand(Commands.GangInviteReply)
                    .WithData(data)
                    .ToCharacter(gangInvite.sender)
                    .Send();

                    data = new Dictionary <string, object> {
                        { k.answer, answer }
                    };

                    if (answer > 0)
                    {
                        data.Add(k.gang, gang.ToDictionary());
                    }

                    // membernek
                    Message.Builder.FromRequest(request).WithData(data).Send();
                });

                scope.Complete();
            }
        }