public void Handle(GameClient Session, ClientMessage Event)
        {
            int           guildId = Event.PopWiredInt32();
            GroupsManager guild   = Groups.GetGroupById(guildId);

            if (guild != null && guild.UserWithRanks.Contains((int)Session.GetHabbo().Id))
            {
                int        num2  = Event.PopWiredInt32();
                GameClient gc    = Essential.GetGame().GetClientManager().GetClientByHabbo(Essential.GetGame().GetClientManager().GetNameById((uint)num2));
                Habbo      habbo = gc.GetHabbo();
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    if (guild.UserWithRanks.Contains(num2))
                    {
                        dbClient.ExecuteQuery("UPDATE group_memberships SET hasRights='0' WHERE userid=" + num2 + " AND groupid=" + guild.Id);
                        guild.UserWithRanks.Remove(num2);
                    }
                    else
                    {
                        dbClient.ExecuteQuery("UPDATE group_memberships SET hasRights='1' WHERE userid=" + num2 + " AND groupid=" + guild.Id);
                        guild.UserWithRanks.Add(num2);
                    }
                }

                if (gc != null && habbo != null)
                {
                    RoomData data = Essential.GetGame().GetRoomManager().method_11((uint)guild.RoomId);
                    try
                    {
                        ServerMessage message = new ServerMessage(Outgoing.SendHtmlColors);
                        message.AppendInt32(habbo.dataTable_0.Rows.Count);
                        foreach (DataRow num3 in habbo.dataTable_0.Rows)
                        {
                            GroupsManager guild2 = Groups.GetGroupById((int)num3["groupid"]);
                            message.AppendInt32(guild2.Id);
                            message.AppendString(guild2.Name);
                            message.AppendString(guild2.Badge);
                            message.AppendString(guild2.ColorOne);
                            message.AppendString(guild2.ColorTwo);
                            message.AppendBoolean(guild2.Id == habbo.FavouriteGroup);
                        }

                        gc.SendMessage(message);
                        ServerMessage message1;

                        message1 = new ServerMessage(Outgoing.SendAdvGroupInit);
                        message1.AppendInt32(guild.Id);
                        message1.AppendBoolean(true);
                        message1.AppendInt32(guild.Type);
                        message1.AppendString(guild.Name);
                        message1.AppendString(guild.Description);
                        message1.AppendString(guild.Badge);
                        message1.AppendInt32(data.Id);
                        message1.AppendString(data.Name);
                        if (guild.Petitions.Contains((int)habbo.Id))
                        {
                            message1.AppendInt32(2);
                        }
                        else if (!habbo.InGuild(guild.Id))
                        {
                            message1.AppendInt32(0);
                        }
                        else if (habbo.InGuild(guild.Id))
                        {
                            message1.AppendInt32(1);
                        }
                        message1.AppendInt32(guild.Members.Count);
                        message1.AppendBoolean(false);
                        message1.AppendString(guild.Created);
                        message1.AppendBoolean(guild.UserWithRanks.Contains((int)Session.GetHabbo().Id));//habbo.Id == guild.OwnerId);

                        if (Session.GetHabbo().InGuild(guild.Id))
                        {
                            if (guild.UserWithRanks.Contains((int)habbo.Id))
                            {
                                message1.AppendBoolean(true);
                            }
                            else
                            {
                                message1.AppendBoolean(false);
                            }
                        }
                        else
                        {
                            message1.AppendBoolean(false);
                        }
                        message1.AppendString(guild.OwnerName);
                        message1.AppendBoolean(true);
                        message1.AppendBoolean(true);
                        message1.AppendInt32(guild.Members.Contains((int)habbo.Id) ? guild.Petitions.Count : 0);
                        gc.SendMessage(message);
                    }
                    catch
                    {
                    }
                    Session.GetClientMessageHandler().LoadMembersPetitions(0, guildId, 0, "", Session);
                }
            }
        }
        public void Handle(GameClient Session, ClientMessage Event)
        {
            int           guildId = Event.PopWiredInt32();
            GroupsManager guild   = Groups.GetGroupById(guildId);

            if (guild != null && guild.UserWithRanks.Contains((int)Session.GetHabbo().Id))
            {
                int userId = Event.PopWiredInt32();
                guild.JoinGroup(userId);
                guild.Petitions.Remove(userId);
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.ExecuteQuery("DELETE FROM group_requests WHERE userid=" + userId + " AND groupid=" + guildId);
                    dbClient.ExecuteQuery("UPDATE user_stats SET groupid=" + guildId + " WHERE id=" + userId);
                    dbClient.ExecuteQuery("INSERT INTO group_memberships (`groupid`,`userid`) VALUES (" + guildId + "," + userId + ")");
                }
                GameClient gc    = Essential.GetGame().GetClientManager().GetClientById((uint)userId);
                Habbo      habbo = null;
                if (gc != null)
                {
                    habbo = gc.GetHabbo();
                }
                if (habbo != null)
                {
                    Room room = Essential.GetGame().GetRoomManager().GetRoom((uint)guild.RoomId);
                    if (habbo.FavouriteGroup == 0)
                    {
                        habbo.FavouriteGroup = guild.Id;
                        habbo.RefreshGuilds();
                        if (habbo.CurrentRoomId > 0)
                        {
                            if (room == null)
                            {
                                return;
                            }
                            ServerMessage message = new ServerMessage(Outgoing.SendGroup); //Rootkit
                            message.AppendInt32(1);
                            message.AppendInt32(guild.Id);
                            message.AppendString(guild.Badge);
                            gc.SendMessage(message);
                            ServerMessage message2 = new ServerMessage(Outgoing.SetRoomUser); //Rootkit
                            message2.AppendInt32(1);
                            RoomUser ru = gc.GetHabbo().CurrentRoom.GetRoomUserByHabbo(habbo.Id);
                            if (ru != null)
                            {
                                ru.method_14(message2);
                            }
                            gc.GetHabbo().CurrentRoom.SendMessage(message2, null);
                        }
                    }
                    ServerMessage message3 = new ServerMessage(Outgoing.AddNewMember); //Rootkit
                    message3.AppendInt32(guildId);
                    message3.AppendInt32(guild.getRank(userId));
                    message3.AppendInt32(habbo.Id);
                    message3.AppendString(habbo.Username);
                    message3.AppendString(habbo.Figure);
                    message3.AppendString(string.Concat(new object[] { DateTime.Now.Month, " ", DateTime.Now.Day, ", ", DateTime.Now.Year }));
                    Session.SendMessage(message3);

                    ServerMessage message4 = new ServerMessage(Outgoing.UpdatePetitionsGuild); //Rootkit
                    message4.AppendInt32(1);
                    message4.AppendInt32(guild.Id);
                    message4.AppendInt32(3);
                    message4.AppendString(guild.Name);
                    Session.SendMessage(message4);
                    gc.SendMessage(message4);
                    ServerMessage message5 = new ServerMessage(Outgoing.SetRoomUser); //Rootkit
                    message5.AppendInt32(1);
                    RoomUser ru2 = gc.GetHabbo().CurrentRoom.GetRoomUserByHabbo(habbo.Id);
                    if (ru2 != null)
                    {
                        ru2.method_14(message5);
                    }
                    gc.GetHabbo().CurrentRoom.SendMessage(message5, null);
                }
                ServerMessage message6 = new ServerMessage(Outgoing.SendHtmlColors);
                message6.AppendInt32(Session.GetHabbo().dataTable_0.Rows.Count);
                foreach (DataRow num4 in Session.GetHabbo().dataTable_0.Rows)
                {
                    GroupsManager guild2 = Groups.GetGroupById((int)num4["groupid"]);
                    message6.AppendInt32(guild2.Id);
                    message6.AppendString(guild2.Name);
                    message6.AppendString(guild2.Badge);
                    message6.AppendString(guild2.ColorOne);
                    message6.AppendString(guild2.ColorTwo);
                    message6.AppendBoolean(guild2.Id == Session.GetHabbo().FavouriteGroup);
                }
                Session.SendMessage(message6);
                Session.GetClientMessageHandler().LoadMembersPetitions(2, guildId, 0, "", Session);
                RoomData data = Essential.GetGame().GetRoomManager().method_11((uint)guild.RoomId);
                if (gc != null)
                {
                    ServerMessage message7 = new ServerMessage(Outgoing.SendAdvGroupInit);
                    message7.AppendInt32(guild.Id);
                    message7.AppendBoolean(true);
                    message7.AppendInt32(guild.Type);
                    message7.AppendString(guild.Name);
                    message7.AppendString(guild.Description);
                    message7.AppendString(guild.Badge);
                    message7.AppendInt32(data.Id);
                    message7.AppendString(data.Name);
                    if (guild.Petitions.Contains((int)habbo.Id))
                    {
                        message7.AppendInt32(2);
                    }
                    else if (!habbo.InGuild(guild.Id))
                    {
                        message7.AppendInt32(0);
                    }
                    else if (habbo.InGuild(guild.Id))
                    {
                        message7.AppendInt32(1);
                    }
                    message7.AppendInt32(guild.Members.Count);
                    message7.AppendBoolean(false);
                    message7.AppendString(guild.Created);

                    message7.AppendBoolean(guild.UserWithRanks.Contains((int)Session.GetHabbo().Id));    //habbo.Id == guild.OwnerId);

                    if (habbo.InGuild(guild.Id))
                    {
                        if (guild.UserWithRanks.Contains((int)habbo.Id))
                        {
                            message7.AppendBoolean(true);
                        }
                        else
                        {
                            message7.AppendBoolean(false);
                        }
                    }
                    else
                    {
                        message7.AppendBoolean(false);
                    }
                    message7.AppendString(guild.OwnerName);
                    message7.AppendBoolean(true);
                    message7.AppendBoolean(true);
                    message7.AppendInt32(guild.Members.Contains((int)habbo.Id) ? guild.Petitions.Count : 0);
                    gc.SendMessage(message7);
                }
            }
        }
        public void Handle(GameClient Session, ClientMessage Event)
        {
            int           guildId = Event.PopWiredInt32();
            GroupsManager guild   = Groups.GetGroupById(guildId);

            if (guild != null && guild.UserWithRanks.Contains((int)Session.GetHabbo().Id))
            {
                int      num2 = Event.PopWiredInt32();
                RoomData data = Essential.GetGame().GetRoomManager().method_11((uint)guild.RoomId);
                if (guild.Petitions.Contains(num2))
                {
                    guild.Petitions.Remove(num2);
                }
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.ExecuteQuery("DELETE FROM group_requests WHERE userid=" + num2 + " AND groupid=" + guildId);
                    dbClient.ExecuteQuery("UPDATE user_stats WHERE id=" + num2 + " AND groupid=" + guildId);
                }
                GameClient gc    = Essential.GetGame().GetClientManager().GetClientById((uint)num2);
                Habbo      habbo = null;
                if (gc != null)
                {
                    habbo = gc.GetHabbo();
                }
                if (gc != null && habbo != null)
                {
                    Room room = Essential.GetGame().GetRoomManager().GetRoom((uint)guild.RoomId);
                    if (room != null)
                    {
                        ServerMessage message;
                        message = new ServerMessage(Outgoing.SendAdvGroupInit);
                        message.AppendInt32(guild.Id);
                        message.AppendBoolean(true);
                        message.AppendInt32(guild.Type);
                        message.AppendString(guild.Name);
                        message.AppendString(guild.Description);
                        message.AppendString(guild.Badge);
                        message.AppendInt32(data.Id);
                        message.AppendString(data.Name);
                        if (guild.Petitions.Contains((int)habbo.Id))
                        {
                            message.AppendInt32(2);
                        }
                        else if (!habbo.InGuild(guild.Id))
                        {
                            message.AppendInt32(0);
                        }
                        else if (habbo.InGuild(guild.Id))
                        {
                            message.AppendInt32(1);
                        }
                        message.AppendInt32(guild.Members.Count);
                        message.AppendBoolean(false);
                        message.AppendString(guild.Created);
                        message.AppendBoolean(guild.UserWithRanks.Contains((int)Session.GetHabbo().Id));//habbo.Id == guild.OwnerId);

                        if (habbo.InGuild(guild.Id))
                        {
                            if (guild.UserWithRanks.Contains((int)habbo.Id))
                            {
                                message.AppendBoolean(true);
                            }
                            else
                            {
                                message.AppendBoolean(false);
                            }
                        }
                        else
                        {
                            message.AppendBoolean(false);
                        }
                        message.AppendString(guild.OwnerName);
                        message.AppendBoolean(true);
                        message.AppendBoolean(true);
                        message.AppendInt32(guild.Members.Contains((int)habbo.Id) ? guild.Petitions.Count : 0);
                        gc.SendMessage(message);
                    }
                }
            }
            Session.GetClientMessageHandler().LoadMembersPetitions(2, guild.Id, 0, "", Session);
        }