Example #1
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) { }
        }
Example #2
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) { }
        }