public override void Execute(Level level)
        {
            var targetAccount = ResourcesManager.GetPlayer(m_vAvatarId, true);

            if (targetAccount != null)
            {
                var targetAvatar        = targetAccount.GetPlayerAvatar();
                var targetAllianceId    = targetAvatar.GetAllianceId();
                var requesterAvatar     = level.GetPlayerAvatar();
                var requesterAllianceId = requesterAvatar.GetAllianceId();
                if (requesterAllianceId > 0 && targetAllianceId == requesterAllianceId)
                {
                    var alliance        = ObjectManager.GetAlliance(requesterAllianceId);
                    var requesterMember = alliance.GetAllianceMember(requesterAvatar.GetId());
                    var targetMember    = alliance.GetAllianceMember(m_vAvatarId);
                    if (targetMember.HasLowerRoleThan(requesterMember.GetRole()))
                    {
                        targetAvatar.SetAllianceId(0);
                        alliance.RemoveMember(m_vAvatarId);
                        if (ResourcesManager.IsPlayerOnline(targetAccount))
                        {
                            var leaveAllianceCommand = new LeaveAllianceCommand();
                            leaveAllianceCommand.SetAlliance(alliance);
                            leaveAllianceCommand.SetReason(2); //Kick
                            var availableServerCommandMessage =
                                new AvailableServerCommandMessage(targetAccount.GetClient());
                            availableServerCommandMessage.SetCommandId(2);
                            availableServerCommandMessage.SetCommand(leaveAllianceCommand);
                            PacketManager.ProcessOutgoingPacket(availableServerCommandMessage);

                            var kickOutStreamEntry = new AllianceKickOutStreamEntry();
                            kickOutStreamEntry.SetId(
                                (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                            kickOutStreamEntry.SetAvatar(requesterAvatar);
                            kickOutStreamEntry.SetIsNew(0);
                            kickOutStreamEntry.SetAllianceId(alliance.GetAllianceId());
                            kickOutStreamEntry.SetAllianceBadgeData(alliance.GetAllianceBadgeData());
                            kickOutStreamEntry.SetAllianceName(alliance.GetAllianceName());
                            kickOutStreamEntry.SetMessage(m_vMessage);
                            var p = new AvatarStreamEntryMessage(targetAccount.GetClient());
                            p.SetAvatarStreamEntry(kickOutStreamEntry);
                            PacketManager.ProcessOutgoingPacket(p);
                        }

                        var eventStreamEntry = new AllianceEventStreamEntry();
                        eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                        eventStreamEntry.SetAvatar(targetAvatar);
                        eventStreamEntry.SetEventType(1);
                        eventStreamEntry.SetAvatarId(requesterAvatar.GetId());
                        eventStreamEntry.SetAvatarName(requesterAvatar.GetAvatarName());
                        alliance.AddChatMessage(eventStreamEntry);

                        foreach (var onlinePlayer in ResourcesManager.GetOnlinePlayers())
                        {
                            if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == requesterAllianceId)
                            {
                                var p = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                                p.SetStreamEntry(eventStreamEntry);
                                PacketManager.ProcessOutgoingPacket(p);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal override async void Process()
        {
            try
            {
                var targetAccount = await ResourcesManager.GetPlayer(m_vAvatarId);

                if (targetAccount != null)
                {
                    var targetAvatar        = targetAccount.Avatar;
                    var targetAllianceId    = targetAvatar.AllianceId;
                    var requesterAvatar     = this.Device.Player.Avatar;
                    var requesterAllianceId = requesterAvatar.AllianceId;
                    if (requesterAllianceId > 0 && targetAllianceId == requesterAllianceId)
                    {
                        var alliance        = ObjectManager.GetAlliance(requesterAllianceId);
                        var requesterMember = alliance.m_vAllianceMembers[requesterAvatar.UserId];
                        var targetMember    = alliance.m_vAllianceMembers[m_vAvatarId];
                        if (targetMember.HasLowerRoleThan(requesterMember.Role))
                        {
                            targetAvatar.AllianceId = 0;
                            alliance.RemoveMember(m_vAvatarId);
                            if (ResourcesManager.IsPlayerOnline(targetAccount))
                            {
                                var leaveAllianceCommand = new LeavedAllianceCommand(this.Device);
                                leaveAllianceCommand.SetAlliance(alliance);
                                leaveAllianceCommand.SetReason(2); //Kick
                                new AvailableServerCommandMessage(targetAccount.Client, leaveAllianceCommand.Handle()).Send();

                                var kickOutStreamEntry = new AllianceKickOutStreamEntry();
                                kickOutStreamEntry.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                                kickOutStreamEntry.SetSender(requesterAvatar);
                                kickOutStreamEntry.IsNew = 2;
                                kickOutStreamEntry.SetAllianceId(alliance.m_vAllianceId);
                                kickOutStreamEntry.SetAllianceBadgeData(alliance.m_vAllianceBadgeData);
                                kickOutStreamEntry.SetAllianceName(alliance.m_vAllianceName);
                                kickOutStreamEntry.SetMessage(m_vMessage);

                                var p = new AvatarStreamEntryMessage(targetAccount.Client);
                                p.SetAvatarStreamEntry(kickOutStreamEntry);
                                p.Send();
                            }

                            var eventStreamEntry = new AllianceEventStreamEntry();
                            eventStreamEntry.ID = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                            eventStreamEntry.SetSender(targetAvatar);
                            eventStreamEntry.m_vAvatarName = this.Device.Player.Avatar.AvatarName;
                            eventStreamEntry.EventType     = 1;
                            alliance.AddChatMessage(eventStreamEntry);

                            foreach (AllianceMemberEntry op in alliance.GetAllianceMembers())
                            {
                                Level alliancemembers = await ResourcesManager.GetPlayer(op.AvatarId);

                                if (alliancemembers.Client != null)
                                {
                                    new AllianceStreamEntryMessage(alliancemembers.Client)
                                    {
                                        StreamEntry = eventStreamEntry
                                    }.Send();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }