Пример #1
0
        internal override void Process()
        {
            if (m_vAllianceName == null)
            {
                m_vAllianceName = "Clan";
            }

            if (m_vAllianceName.Length < 16 || m_vAllianceName.Length < 1)
            {
                if (m_vAllianceDescription.Length < 259 || m_vAllianceDescription.Length < 0)
                {
                    Alliance alliance = ObjectManager.CreateAlliance(0);
                    alliance.m_vAllianceName        = m_vAllianceName;
                    alliance.m_vAllianceDescription = m_vAllianceDescription;
                    alliance.m_vAllianceType        = m_vAllianceType;
                    alliance.m_vRequiredScore       = m_vRequiredScore;
                    alliance.m_vAllianceBadgeData   = m_vAllianceBadgeData;
                    alliance.m_vAllianceOrigin      = m_vAllianceOrigin;
                    alliance.m_vWarFrequency        = m_vWarFrequency;
                    alliance.SetWarAndFriendlytStatus(m_vWarAndFriendlyStatus);
                    this.Device.Player.Avatar.AllianceId = alliance.m_vAllianceId;

                    AllianceMemberEntry member = new AllianceMemberEntry(this.Device.Player.Avatar.UserId)
                    {
                        Role = 2
                    };
                    alliance.AddAllianceMember(member);

                    JoinedAllianceCommand b = new JoinedAllianceCommand(this.Device);
                    b.SetAlliance(alliance);

                    AllianceRoleUpdateCommand d = new AllianceRoleUpdateCommand(this.Device);
                    d.SetAlliance(alliance);
                    d.SetRole(2);
                    d.Tick(this.Device.Player);

                    new AvailableServerCommandMessage(this.Device, b.Handle()).Send();

                    new AvailableServerCommandMessage(this.Device, d.Handle()).Send();
                }
                else
                {
                    ResourcesManager.DisconnectClient(Device);
                }
            }
            else
            {
                ResourcesManager.DisconnectClient(Device);
            }
        }
Пример #2
0
        internal override async void Process()
        {
            try
            {
                Alliance alliance = ObjectManager.GetAlliance(m_vAllianceId);
                if (alliance != null)
                {
                    if (!alliance.IsAllianceFull())
                    {
                        this.Device.Player.Avatar.AllianceId = alliance.m_vAllianceId;
                        AllianceMemberEntry member = new AllianceMemberEntry(this.Device.Player.Avatar.UserId);
                        member.Role = 1;
                        alliance.AddAllianceMember(member);

                        JoinedAllianceCommand b = new JoinedAllianceCommand(this.Device);
                        b.SetAlliance(alliance);

                        AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand(this.Device);
                        c.SetAlliance(alliance);
                        c.SetRole(1);
                        c.Tick(this.Device.Player);

                        AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                        eventStreamEntry.ID = alliance.m_vChatMessages.Count + 1;
                        eventStreamEntry.SetSender(this.Device.Player.Avatar);
                        eventStreamEntry.EventType = 3;
                        alliance.AddChatMessage(eventStreamEntry);

                        new AvailableServerCommandMessage(this.Device, b.Handle()).Send();

                        new AvailableServerCommandMessage(this.Device, c.Handle()).Send();

                        new AllianceStreamMessage(Device, alliance).Send();

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

                            new AllianceStreamEntryMessage(l.Client)
                            {
                                StreamEntry = eventStreamEntry
                            }.Send();
                        }
                    }
                }
            } catch (Exception) { }
        }
Пример #3
0
        public override void Process(Level level)
        {
            if (m_vAllianceName == null)
            {
                m_vAllianceName = "Clan";
            }

            var alliance = ObjectManager.CreateAlliance(0);

            alliance.SetAllianceName(m_vAllianceName);
            alliance.SetAllianceDescription(m_vAllianceDescription);
            alliance.SetAllianceType(m_vAllianceType);
            alliance.SetRequiredScore(m_vRequiredScore);
            alliance.SetAllianceBadgeData(m_vAllianceBadgeData);
            alliance.SetAllianceOrigin(m_vAllianceOrigin);
            alliance.SetWarFrequency(m_vWarFrequency);
            alliance.SetWarAndFriendlytStatus(m_vWarAndFriendlyStatus);
            level.GetPlayerAvatar().SetAllianceId(alliance.GetAllianceId());

            var member = new AllianceMemberEntry(level.GetPlayerAvatar().GetId());

            member.SetRole(2);
            alliance.AddAllianceMember(member);

            var b = new JoinedAllianceCommand();

            b.SetAlliance(alliance);

            var d = new AllianceRoleUpdateCommand();

            d.SetAlliance(alliance);
            d.SetRole(2);
            d.Tick(level);

            var a = new AvailableServerCommandMessage(Client);

            a.SetCommandId(1);
            a.SetCommand(b);

            var c = new AvailableServerCommandMessage(Client);

            c.SetCommandId(8);
            c.SetCommand(d);

            a.Send();
            c.Send();
        }
        public override void Process(Level level)
        {
            var alliance = ObjectManager.GetAlliance(m_vAllianceId);

            if (alliance == null || alliance.IsAllianceFull())
            {
                return;
            }

            level.GetPlayerAvatar().SetAllianceId(alliance.GetAllianceId());
            var entry = new AllianceMemberEntry(level.GetPlayerAvatar().GetId());

            entry.SetRole(1);
            alliance.AddAllianceMember(entry);

            var jaCommand = new JoinedAllianceCommand();

            jaCommand.SetAlliance(alliance);

            var aruCommand = new AllianceRoleUpdateCommand();

            aruCommand.SetAlliance(alliance);
            aruCommand.SetRole(1);
            aruCommand.Tick(level);

            var asCommand1 = new AvailableServerCommandMessage(Client);

            asCommand1.SetCommandId(1);
            asCommand1.SetCommand(jaCommand);

            var asCommand2 = new AvailableServerCommandMessage(Client);

            asCommand2.SetCommandId(8);
            asCommand2.SetCommand(aruCommand);

            asCommand1.Send();
            asCommand2.Send();

            new AllianceStreamMessage(Client, alliance).Send();
        }
        public override async void Process(Level level)
        {
            try
            {
                Alliance alliance = await ObjectManager.GetAlliance(m_vAllianceId);

                if (alliance != null)
                {
                    if (!alliance.IsAllianceFull())
                    {
                        level.GetPlayerAvatar().SetAllianceId(alliance.GetAllianceId());
                        AllianceMemberEntry member = new AllianceMemberEntry(level.GetPlayerAvatar().GetId());
                        member.SetRole(1);
                        alliance.AddAllianceMember(member);

                        JoinedAllianceCommand b = new JoinedAllianceCommand();
                        b.SetAlliance(alliance);

                        AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand();
                        c.SetAlliance(alliance);
                        c.SetRole(1);
                        c.Tick(level);

                        AvailableServerCommandMessage a = new AvailableServerCommandMessage(Client);
                        a.SetCommandId(1);
                        a.SetCommand(b);

                        AvailableServerCommandMessage d = new AvailableServerCommandMessage(Client);
                        d.SetCommandId(8);
                        d.SetCommand(c);

                        PacketProcessor.Send(a);
                        PacketProcessor.Send(d);

                        PacketProcessor.Send(new AllianceStreamMessage(Client, alliance));
                    }
                }
            } catch (Exception) { }
        }
Пример #6
0
        public override void Process(Level level)
        {
            var alliance = ObjectManager.GetAlliance(m_vAllianceId);

            if (alliance != null)
            {
                if (!alliance.IsAllianceFull())
                {
                    level.GetPlayerAvatar().SetAllianceId(alliance.GetAllianceId());
                    var member = new AllianceMemberEntry(level.GetPlayerAvatar().GetId());
                    member.SetRole(1);
                    alliance.AddAllianceMember(member);

                    var b = new JoinedAllianceCommand();
                    b.SetAlliance(alliance);

                    var c = new AllianceRoleUpdateCommand();
                    c.SetAlliance(alliance);
                    c.SetRole(1);
                    c.Tick(level);

                    var a = new AvailableServerCommandMessage(Client);
                    a.SetCommandId(1);
                    a.SetCommand(b);

                    var d = new AvailableServerCommandMessage(Client);
                    d.SetCommandId(8);
                    d.SetCommand(c);

                    a.Send();
                    d.Send();

                    new AllianceStreamMessage(Client, alliance).Send();
                }
            }
        }
Пример #7
0
        public override void Process(Level level)
        {
            if (m_vAllianceName == null)
            {
                m_vAllianceName = "Clan";
            }

            if (m_vAllianceName.Length < 16 || m_vAllianceName.Length < 1)
            {
                if (m_vAllianceDescription.Length < 259 || m_vAllianceDescription.Length < 0)
                {
                    if (m_vAllianceBadgeData < 1 || (long)m_vAllianceBadgeData < 10000000000L)
                    {
                        if (m_vAllianceType < 0 || m_vAllianceType < 10)
                        {
                            if (m_vRequiredScore < 0 || m_vRequiredScore < 4201)
                            {
                                if (m_vWarFrequency < 0 || m_vWarFrequency < 10)
                                {
                                    if (m_vAllianceOrigin < 0 || m_vAllianceOrigin < 42000000)
                                    {
                                        if ((int)m_vWarAndFriendlyStatus < 0 || (int)m_vWarAndFriendlyStatus < 5)
                                        {
                                            Alliance alliance = ObjectManager.CreateAlliance();
                                            alliance.SetAllianceName(m_vAllianceName);
                                            alliance.SetAllianceDescription(m_vAllianceDescription);
                                            alliance.SetAllianceType(m_vAllianceType);
                                            alliance.SetRequiredScore(m_vRequiredScore);
                                            alliance.SetAllianceBadgeData(m_vAllianceBadgeData);
                                            alliance.SetAllianceOrigin(m_vAllianceOrigin);
                                            alliance.SetWarFrequency(m_vWarFrequency);
                                            alliance.SetWarAndFriendlytStatus(m_vWarAndFriendlyStatus);
                                            level.GetPlayerAvatar().SetAllianceId(alliance.GetAllianceId());
                                            AllianceMemberEntry entry = new AllianceMemberEntry(level.GetPlayerAvatar().GetId());
                                            entry.SetRole(2);
                                            alliance.AddAllianceMember(entry);
                                            JoinedAllianceCommand Command1 = new JoinedAllianceCommand();
                                            Command1.SetAlliance(alliance);
                                            AllianceRoleUpdateCommand Command2 = new AllianceRoleUpdateCommand();
                                            Command2.SetAlliance(alliance);
                                            Command2.SetRole(2);
                                            Command2.Tick(level);
                                            var a = new AvailableServerCommandMessage(Client);
                                            a.SetCommandId(1);
                                            a.SetCommand(Command1);
                                            var c = new AvailableServerCommandMessage(Client);
                                            c.SetCommandId(8);
                                            c.SetCommand(Command2);
                                            a.Send();
                                            c.Send();
                                        }
                                        else
                                        {
                                            ResourcesManager.DisconnectClient(Client);
                                        }
                                    }
                                    else
                                    {
                                        ResourcesManager.DisconnectClient(Client);
                                    }
                                }
                                else
                                {
                                    ResourcesManager.DisconnectClient(Client);
                                }
                            }
                            else
                            {
                                ResourcesManager.DisconnectClient(Client);
                            }
                        }
                        else
                        {
                            ResourcesManager.DisconnectClient(Client);
                        }
                    }
                    else
                    {
                        ResourcesManager.DisconnectClient(Client);
                    }
                }
                else
                {
                    ResourcesManager.DisconnectClient(Client);
                }
            }
            else
            {
                ResourcesManager.DisconnectClient(Client);
            }
        }
        public override async void Process(Level level)
        {
            try
            {
                ClientAvatar avatar = level.GetPlayerAvatar();
                Alliance alliance = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

                if (await avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1)
                {
                    List<AllianceMemberEntry> members = alliance.GetAllianceMembers();
                    foreach (AllianceMemberEntry player in members.Where(player => player.GetRole() >= 3))
                    {
                        player.SetRole(2);

                        if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.GetAvatarId())))
                        {
                            AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand();
                            c.SetAlliance(alliance);
                            c.SetRole(2);
                            c.Tick(level);

                            Level l = await ResourcesManager.GetPlayer(player.GetAvatarId());
                            AvailableServerCommandMessage d = new AvailableServerCommandMessage(l.GetClient());
                            d.SetCommandId(8);
                            d.SetCommand(c);
                            PacketProcessor.Send(d);
                        }
                        done = true;
                        break;
                    }
                    if (!done)
                    {
                        int count = alliance.GetAllianceMembers().Count;
                        Random rnd = new Random();
                        int id = rnd.Next(1, count);
                        while (id != level.GetPlayerAvatar().GetId())
                            id = rnd.Next(1, count);
                        int loop = 0;
                        foreach (AllianceMemberEntry player in members)
                        {
                            loop++;
                            if (loop == id)
                            {
                                player.SetRole(2);
                                if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.GetAvatarId())))
                                {
                                    AllianceRoleUpdateCommand e = new AllianceRoleUpdateCommand();
                                    e.SetAlliance(alliance);
                                    e.SetRole(2);
                                    e.Tick(level);

                                    Level l2 = await ResourcesManager.GetPlayer(player.GetAvatarId());
                                    AvailableServerCommandMessage f = new AvailableServerCommandMessage(l2.GetClient());
                                    f.SetCommandId(8);
                                    f.SetCommand(e);
                                    PacketProcessor.Send(f);
                                }
                                break;
                            }
                        }
                    }
                }
                LeavedAllianceCommand a = new LeavedAllianceCommand();
                a.SetAlliance(alliance);
                a.SetReason(1);

                AvailableServerCommandMessage b = new AvailableServerCommandMessage(Client);
                b.SetCommandId(2);
                b.SetCommand(a);
                PacketProcessor.Send(b);

                alliance.RemoveMember(avatar.GetId());
                avatar.SetAllianceId(0);

                if (alliance.GetAllianceMembers().Count > 0)
                {
                    AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                    eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                    eventStreamEntry.SetSender(avatar);
                    eventStreamEntry.SetEventType(4);
                    eventStreamEntry.SetAvatarId(avatar.GetId());
                    eventStreamEntry.SetAvatarName(avatar.GetAvatarName());
                    alliance.AddChatMessage(eventStreamEntry);
                    foreach (Level onlinePlayer in ResourcesManager.GetOnlinePlayers())
                        if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == alliance.GetAllianceId())
                        {
                            AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                            p.SetStreamEntry(eventStreamEntry);
                            PacketProcessor.Send(p);
                        }
                }
                else
                {
                    DatabaseManager.Single().RemoveAlliance(alliance);
                }
                PacketProcessor.Send(new LeaveAllianceOkMessage(Client, alliance));
            } catch (Exception) { }
        }
Пример #9
0
        public override async void Process(Level level)
        {
            try
            {
                Alliance a = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

                StreamEntry message   = a.GetChatMessages().Find(c => c.GetId() == MessageID);
                Level       requester = await ResourcesManager.GetPlayer(message.GetSenderId());

                if (Choice == 1)
                {
                    if (!a.IsAllianceFull())
                    {
                        requester.GetPlayerAvatar().SetAllianceId(a.GetAllianceId());

                        AllianceMemberEntry member = new AllianceMemberEntry(requester.GetPlayerAvatar().GetId());
                        member.SetRole(1);
                        a.AddAllianceMember(member);

                        StreamEntry e = a.GetChatMessages().Find(c => c.GetId() == MessageID);
                        e.SetJudgeName(level.GetPlayerAvatar().GetAvatarName());
                        e.SetState(2);

                        AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                        eventStreamEntry.SetId(a.GetChatMessages().Count + 1);
                        eventStreamEntry.SetSender(requester.GetPlayerAvatar());
                        eventStreamEntry.SetAvatarName(level.GetPlayerAvatar().GetAvatarName());
                        eventStreamEntry.SetAvatarId(level.GetPlayerAvatar().GetId());
                        eventStreamEntry.SetEventType(2);

                        a.AddChatMessage(eventStreamEntry);

                        foreach (AllianceMemberEntry op in a.GetAllianceMembers())
                        {
                            Level player = await ResourcesManager.GetPlayer(op.GetAvatarId());

                            if (player.GetClient() != null)
                            {
                                AllianceStreamEntryMessage c = new AllianceStreamEntryMessage(player.GetClient());
                                AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(player.GetClient());
                                p.SetStreamEntry(eventStreamEntry);
                                c.SetStreamEntry(e);

                                PacketProcessor.Send(p);
                                PacketProcessor.Send(c);
                            }
                        }
                        if (ResourcesManager.IsPlayerOnline(requester))
                        {
                            JoinedAllianceCommand joinAllianceCommand = new JoinedAllianceCommand();
                            joinAllianceCommand.SetAlliance(a);

                            AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(requester.GetClient());
                            availableServerCommandMessage.SetCommandId(1);
                            availableServerCommandMessage.SetCommand(joinAllianceCommand);

                            AllianceRoleUpdateCommand d = new AllianceRoleUpdateCommand();
                            d.SetAlliance(a);
                            d.SetRole(4);
                            d.Tick(level);

                            AvailableServerCommandMessage c = new AvailableServerCommandMessage(Client);
                            c.SetCommandId(8);
                            c.SetCommand(d);

                            PacketProcessor.Send(new AnswerJoinRequestAllianceMessage(Client));
                            PacketProcessor.Send(availableServerCommandMessage);
                            PacketProcessor.Send(c);
                            PacketProcessor.Send(new AllianceStreamMessage(requester.GetClient(), a));
                        }
                    }
                }
                else
                {
                    StreamEntry e = a.GetChatMessages().Find(c => c.GetId() == MessageID);
                    e.SetJudgeName(level.GetPlayerAvatar().GetAvatarName());
                    e.SetState(3);

                    foreach (AllianceMemberEntry op in a.GetAllianceMembers())
                    {
                        Level player = await ResourcesManager.GetPlayer(op.GetAvatarId());

                        if (player.GetClient() != null)
                        {
                            AllianceStreamEntryMessage c = new AllianceStreamEntryMessage(player.GetClient());
                            c.SetStreamEntry(e);
                            PacketProcessor.Send(c);
                        }
                    }
                }
            } catch (Exception) { }
        }
Пример #10
0
        public override void Process(Level level)
        {
            var avatar   = level.GetPlayerAvatar();
            var alliance = ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

            if (avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1)
            {
                var members = alliance.GetAllianceMembers();
                foreach (AllianceMemberEntry player in members.Where(player => player.GetRole() >= 3))
                {
                    player.SetRole(2);

                    if (ResourcesManager.IsPlayerOnline(ResourcesManager.GetPlayer(player.GetAvatarId())))
                    {
                        var c = new AllianceRoleUpdateCommand();
                        c.SetAlliance(alliance);
                        c.SetRole(2);
                        c.Tick(level);

                        var d = new AvailableServerCommandMessage(ResourcesManager.GetPlayer(player.GetAvatarId()).GetClient());
                        d.SetCommandId(8);
                        d.SetCommand(c);
                        d.Send();
                    }
                    done = true;
                    break;
                }
                if (!done)
                {
                    var count = alliance.GetAllianceMembers().Count;
                    var rnd   = new Random();
                    var id    = rnd.Next(1, count);
                    while (id != level.GetPlayerAvatar().GetId())
                    {
                        id = rnd.Next(1, count);
                    }
                    var loop = 0;
                    foreach (AllianceMemberEntry player in members)
                    {
                        loop++;
                        if (loop == id)
                        {
                            player.SetRole(2);
                            if (ResourcesManager.IsPlayerOnline(ResourcesManager.GetPlayer(player.GetAvatarId())))
                            {
                                var e = new AllianceRoleUpdateCommand();
                                e.SetAlliance(alliance);
                                e.SetRole(2);
                                e.Tick(level);

                                var f = new AvailableServerCommandMessage(ResourcesManager.GetPlayer(player.GetAvatarId()).GetClient());
                                f.SetCommandId(8);
                                f.SetCommand(e);
                                f.Send();
                            }
                            break;
                        }
                    }
                }
            }
            var a = new LeavedAllianceCommand();

            a.SetAlliance(alliance);
            a.SetReason(1);

            var b = new AvailableServerCommandMessage(Client);

            b.SetCommandId(2);
            b.SetCommand(a);
            b.Send();

            alliance.RemoveMember(avatar.GetId());
            avatar.SetAllianceId(0);

            if (alliance.GetAllianceMembers().Count > 0)
            {
                var eventStreamEntry = new AllianceEventStreamEntry();
                eventStreamEntry.SetId((int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
                eventStreamEntry.SetSender(avatar);
                eventStreamEntry.SetEventType(4);
                eventStreamEntry.SetAvatarId(avatar.GetId());
                eventStreamEntry.SetAvatarName(avatar.GetAvatarName());
                alliance.AddChatMessage(eventStreamEntry);
                foreach (Level onlinePlayer in ResourcesManager.GetOnlinePlayers())
                {
                    if (onlinePlayer.GetPlayerAvatar().GetAllianceId() == alliance.GetAllianceId())
                    {
                        AllianceStreamEntryMessage p = new AllianceStreamEntryMessage(onlinePlayer.GetClient());
                        p.SetStreamEntry(eventStreamEntry);
                        p.Send();
                    }
                }
            }
            else
            {
                DatabaseManager.Single().RemoveAlliance(alliance);
            }
            new LeaveAllianceOkMessage(Client, alliance).Send();
        }
Пример #11
0
        public override void Process(Level level)
        {
            var target   = ResourcesManager.GetPlayer(m_vId);
            var player   = level.GetPlayerAvatar();
            var alliance = ObjectManager.GetAlliance(player.GetAllianceId());

            if (player.GetAllianceRole() == 2 || player.GetAllianceRole() == 4)
            {
                if (player.GetAllianceId() == target.GetPlayerAvatar().GetAllianceId())
                {
                    int oldrole = target.GetPlayerAvatar().GetAllianceRole();
                    target.GetPlayerAvatar().SetAllianceRole(m_vRole);
                    if (m_vRole == 2)
                    {
                        player.SetAllianceRole(4);

                        AllianceEventStreamEntry demote = new AllianceEventStreamEntry();
                        demote.SetId(alliance.GetChatMessages().Count + 1);
                        demote.SetSender(player);
                        demote.SetEventType(6);
                        demote.SetAvatarId(player.GetId());
                        demote.SetAvatarName(player.GetAvatarName());

                        alliance.AddChatMessage(demote);

                        AllianceEventStreamEntry promote = new AllianceEventStreamEntry();
                        promote.SetId(alliance.GetChatMessages().Count + 1);
                        promote.SetSender(target.GetPlayerAvatar());
                        promote.SetEventType(5);
                        promote.SetAvatarId(player.GetId());
                        promote.SetAvatarName(player.GetAvatarName());

                        alliance.AddChatMessage(promote);

                        PromoteAllianceMemberOkMessage rup = new PromoteAllianceMemberOkMessage(Client);
                        PromoteAllianceMemberOkMessage rub = new PromoteAllianceMemberOkMessage(target.GetClient());

                        AllianceRoleUpdateCommand     p  = new AllianceRoleUpdateCommand();
                        AvailableServerCommandMessage pa = new AvailableServerCommandMessage(Client);

                        AllianceRoleUpdateCommand     t  = new AllianceRoleUpdateCommand();
                        AvailableServerCommandMessage ta = new AvailableServerCommandMessage(target.GetClient());

                        rup.SetID(level.GetPlayerAvatar().GetId());
                        rup.SetRole(4);
                        rub.SetID(target.GetPlayerAvatar().GetId());
                        rub.SetRole(2);

                        t.SetAlliance(alliance);
                        p.SetAlliance(alliance);
                        t.SetRole(2);
                        p.SetRole(4);
                        t.Tick(target);
                        p.Tick(level);

                        ta.SetCommandId(8);
                        pa.SetCommandId(8);
                        ta.SetCommand(t);
                        pa.SetCommand(p);
                        if (ResourcesManager.IsPlayerOnline(target))
                        {
                            ta.Send();
                            rub.Send();
                        }
                        rup.Send();
                        pa.Send();


                        // New function for send a message
                        foreach (AllianceMemberEntry op in alliance.GetAllianceMembers())
                        {
                            Level aplayer = ResourcesManager.GetPlayer(op.GetAvatarId());
                            if (aplayer.GetClient() != null)
                            {
                                AllianceStreamEntryMessage a = new AllianceStreamEntryMessage(aplayer.GetClient());
                                AllianceStreamEntryMessage b = new AllianceStreamEntryMessage(aplayer.GetClient());

                                a.SetStreamEntry(demote);
                                b.SetStreamEntry(promote);

                                a.Send();
                                b.Send();
                            }
                        }
                    }
                    else
                    {
                        AllianceRoleUpdateCommand      t      = new AllianceRoleUpdateCommand();
                        AvailableServerCommandMessage  ta     = new AvailableServerCommandMessage(target.GetClient());
                        PromoteAllianceMemberOkMessage ru     = new PromoteAllianceMemberOkMessage(target.GetClient());
                        AllianceEventStreamEntry       stream = new AllianceEventStreamEntry();

                        stream.SetId(alliance.GetChatMessages().Count + 1);
                        stream.SetSender(target.GetPlayerAvatar());
                        stream.SetAvatarId(player.GetId());
                        stream.SetAvatarName(player.GetAvatarName());
                        if (m_vRole > oldrole)
                        {
                            stream.SetEventType(5);
                        }
                        else
                        {
                            stream.SetEventType(6);
                        }

                        t.SetAlliance(alliance);
                        t.SetRole(m_vRole);
                        t.Tick(target);

                        ta.SetCommandId(8);
                        ta.SetCommand(t);

                        ru.SetID(target.GetPlayerAvatar().GetId());
                        ru.SetRole(m_vRole);

                        alliance.AddChatMessage(stream);

                        if (ResourcesManager.IsPlayerOnline(target))
                        {
                            ta.Send();
                            ru.Send();
                        }
                        // New function for send a message
                        foreach (AllianceMemberEntry op in alliance.GetAllianceMembers())
                        {
                            Level aplayer = ResourcesManager.GetPlayer(op.GetAvatarId());
                            if (aplayer.GetClient() != null)
                            {
                                AllianceStreamEntryMessage b = new AllianceStreamEntryMessage(aplayer.GetClient());
                                b.SetStreamEntry(stream);
                                PacketManager.Send(b);
                            }
                        }
                    }
                }
            }
        }
Пример #12
0
        internal override async void Process()
        {
            try
            {
                Level target = await ResourcesManager.GetPlayer(m_vId);

                ClientAvatar player   = this.Device.Player.Avatar;
                Alliance     alliance = ObjectManager.GetAlliance(player.AllianceId);
                if (await player.GetAllianceRole() == 2 || await player.GetAllianceRole() == 4)
                {
                    if (player.AllianceId == target.Avatar.AllianceId)
                    {
                        int oldrole = await target.Avatar.GetAllianceRole();

                        target.Avatar.SetAllianceRole(m_vRole);
                        if (m_vRole == 2)
                        {
                            player.SetAllianceRole(4);

                            AllianceEventStreamEntry demote = new AllianceEventStreamEntry();
                            demote.ID = alliance.m_vChatMessages.Count + 1;
                            demote.SetSender(player);
                            demote.EventType = 6;

                            alliance.AddChatMessage(demote);

                            AllianceEventStreamEntry promote = new AllianceEventStreamEntry();
                            promote.ID = alliance.m_vChatMessages.Count + 1;
                            promote.SetSender(target.Avatar);
                            promote.EventType = 5;

                            alliance.AddChatMessage(promote);

                            AllianceRoleUpdateCommand     p  = new AllianceRoleUpdateCommand(this.Device);
                            AvailableServerCommandMessage pa = new AvailableServerCommandMessage(Device, p.Handle());

                            AllianceRoleUpdateCommand     t  = new AllianceRoleUpdateCommand(target.Client);
                            AvailableServerCommandMessage ta = new AvailableServerCommandMessage(target.Client, t.Handle());

                            PromoteAllianceMemberOkMessage rup = new PromoteAllianceMemberOkMessage(Device)
                            {
                                Id   = this.Device.Player.Avatar.UserId,
                                Role = 4
                            };
                            PromoteAllianceMemberOkMessage rub = new PromoteAllianceMemberOkMessage(target.Client)
                            {
                                Id   = target.Avatar.UserId,
                                Role = 2
                            };

                            t.SetAlliance(alliance);
                            p.SetAlliance(alliance);
                            t.SetRole(2);
                            p.SetRole(4);
                            t.Tick(target);
                            p.Tick(this.Device.Player);

                            if (ResourcesManager.IsPlayerOnline(target))
                            {
                                ta.Send();
                                rub.Send();
                            }
                            rup.Send();
                            pa.Send();

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

                                if (aplayer.Client != null)
                                {
                                    new AllianceStreamEntryMessage(aplayer.Client)
                                    {
                                        StreamEntry = demote
                                    }.Send();
                                    new AllianceStreamEntryMessage(aplayer.Client)
                                    {
                                        StreamEntry = promote
                                    }.Send();
                                }
                            }
                        }
                        else
                        {
                            AllianceRoleUpdateCommand     t  = new AllianceRoleUpdateCommand(target.Client);
                            AvailableServerCommandMessage ta = new AvailableServerCommandMessage(target.Client, t.Handle());

                            t.SetAlliance(alliance);
                            t.SetRole(m_vRole);
                            t.Tick(target);

                            PromoteAllianceMemberOkMessage ru = new PromoteAllianceMemberOkMessage(target.Client)
                            {
                                Id   = target.Avatar.UserId,
                                Role = m_vRole
                            };

                            if (ResourcesManager.IsPlayerOnline(target))
                            {
                                ta.Send();
                                ru.Send();
                            }

                            AllianceEventStreamEntry stream = new AllianceEventStreamEntry();

                            stream.ID = alliance.m_vChatMessages.Count + 1;
                            stream.SetSender(target.Avatar);
                            stream.EventType = m_vRole > oldrole ? 5 : 6;
                            alliance.AddChatMessage(stream);

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

                                if (aplayer.Client != null)
                                {
                                    new AllianceStreamEntryMessage(aplayer.Client)
                                    {
                                        StreamEntry = stream
                                    }.Send();
                                }
                            }
                        }
                    }
                }
            } catch (Exception) { }
        }
Пример #13
0
        internal async void Process()
        {
            try
            {
                Alliance    a         = ObjectManager.GetAlliance(this.Device.Player.Avatar.AllianceId);
                StreamEntry message   = a.m_vChatMessages.Find(c => c.ID == MessageID);
                Level       requester = await ResourcesManager.GetPlayer(message.SenderID);

                if (Choice == 1)
                {
                    if (!a.IsAllianceFull())
                    {
                        requester.Avatar.AllianceId = a.m_vAllianceId;

                        AllianceMemberEntry member = new AllianceMemberEntry(requester.Avatar.UserId);
                        member.Role = 1;
                        a.AddAllianceMember(member);

                        StreamEntry e = a.m_vChatMessages.Find(c => c.ID == MessageID);
                        e.SetJudgeName(this.Device.Player.Avatar.AvatarName);
                        e.SetState(2);

                        AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                        eventStreamEntry.ID = a.m_vChatMessages.Count + 1;
                        eventStreamEntry.SetSender(requester.Avatar);
                        eventStreamEntry.EventType = 2;

                        a.AddChatMessage(eventStreamEntry);

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

                            if (player.Client != null)
                            {
                                new AllianceStreamEntryMessage(player.Client)
                                {
                                    StreamEntry = eventStreamEntry
                                }.Send();
                                new AllianceStreamEntryMessage(player.Client)
                                {
                                    StreamEntry = e
                                }.Send();
                            }
                        }
                        if (ResourcesManager.IsPlayerOnline(requester))
                        {
                            JoinedAllianceCommand joinAllianceCommand = new JoinedAllianceCommand(requester.Client);
                            joinAllianceCommand.SetAlliance(a);

                            new AvailableServerCommandMessage(requester.Client, joinAllianceCommand.Handle()).Send();

                            AllianceRoleUpdateCommand d = new AllianceRoleUpdateCommand(requester.Client);
                            d.SetAlliance(a);
                            d.SetRole(4);
                            d.Tick(requester);

                            new AvailableServerCommandMessage(requester.Client, d.Handle()).Send();

                            new AllianceStreamMessage(requester.Client, a).Send();
                        }
                    }
                }
                else
                {
                    StreamEntry e = a.m_vChatMessages.Find(c => c.ID == MessageID);
                    e.SetJudgeName(this.Device.Player.Avatar.AvatarName);
                    e.SetState(3);

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

                        if (player.Client != null)
                        {
                            new AllianceStreamEntryMessage(player.Client)
                            {
                                StreamEntry = e
                            }.Send();
                        }
                    }
                }
            } catch (Exception) { }
        }
Пример #14
0
        internal override async void Process()
        {
            try
            {
                ClientAvatar avatar   = this.Device.Player.Avatar;
                Alliance     alliance = ObjectManager.GetAlliance(avatar.AllianceId);

                if (await avatar.GetAllianceRole() == 2 && alliance.GetAllianceMembers().Count > 1)
                {
                    List <AllianceMemberEntry> members = alliance.GetAllianceMembers();
                    foreach (AllianceMemberEntry player in members.Where(player => player.Role >= 3))
                    {
                        player.Role = 2;

                        if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.AvatarId)))
                        {
                            Level l = await ResourcesManager.GetPlayer(player.AvatarId);

                            AllianceRoleUpdateCommand c = new AllianceRoleUpdateCommand(l.Client);
                            c.SetAlliance(alliance);
                            c.SetRole(2);
                            c.Tick(l);

                            new AvailableServerCommandMessage(l.Client, c.Handle()).Send();
                        }
                        done = true;
                        break;
                    }
                    if (!done)
                    {
                        int    count = alliance.GetAllianceMembers().Count;
                        Random rnd   = new Random();
                        int    id    = rnd.Next(1, count);
                        while (id != this.Device.Player.Avatar.UserId)
                        {
                            id = rnd.Next(1, count);
                        }
                        int loop = 0;
                        foreach (AllianceMemberEntry player in members)
                        {
                            loop++;
                            if (loop == id)
                            {
                                player.Role = 2;
                                if (ResourcesManager.IsPlayerOnline(await ResourcesManager.GetPlayer(player.AvatarId)))
                                {
                                    Level l2 = await ResourcesManager.GetPlayer(player.AvatarId);

                                    AllianceRoleUpdateCommand e = new AllianceRoleUpdateCommand(l2.Client);
                                    e.SetAlliance(alliance);
                                    e.SetRole(2);
                                    e.Tick(l2);

                                    new AvailableServerCommandMessage(l2.Client, e.Handle()).Send();
                                }
                                break;
                            }
                        }
                    }
                }
                LeavedAllianceCommand a = new LeavedAllianceCommand(this.Device);
                a.SetAlliance(alliance);
                a.SetReason(1);

                new AvailableServerCommandMessage(Device, a.Handle()).Send();

                alliance.RemoveMember(avatar.UserId);
                avatar.AllianceId = 0;

                if (alliance.GetAllianceMembers().Count > 0)
                {
                    AllianceEventStreamEntry eventStreamEntry = new AllianceEventStreamEntry();
                    eventStreamEntry.ID = alliance.m_vChatMessages.Count + 1;
                    eventStreamEntry.SetSender(avatar);
                    eventStreamEntry.EventType = 4;
                    alliance.AddChatMessage(eventStreamEntry);
                    foreach (Level onlinePlayer in ResourcesManager.m_vOnlinePlayers)
                    {
                        if (onlinePlayer.Avatar.AllianceId == alliance.m_vAllianceId)
                        {
                            new AllianceStreamEntryMessage(onlinePlayer.Client)
                            {
                                StreamEntry = eventStreamEntry
                            }.Send();
                        }
                    }
                }
                else
                {
                    Resources.DatabaseManager.RemoveAlliance(alliance);
                }
                new LeaveAllianceOkMessage(Device, alliance).Send();
            } catch (Exception) { }
        }