Example #1
0
        public void Handle(GameClient Session, ClientMessage Event)
        {
            int           GuildId = Event.PopWiredInt32();
            int           UserId  = Event.PopWiredInt32();
            string        OwnerName;
            GroupsManager Guild = Groups.GetGroupById(GuildId);

            if (Guild == null || Session.GetHabbo().Id != UserId)
            {
                return;
            }

            using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
            {
                dbClient.ExecuteQuery("DELETE FROM `group_memberships` WHERE (`groupid`='" + GuildId + "') AND (`userid`='" + UserId + "') LIMIT 1");
            }

            using (DatabaseClient class2 = Essential.GetDatabase().GetClient())
            {
                Session.GetHabbo().method_0(class2);
            }

            Guild.Leave((int)Session.GetHabbo().Id);

            ServerMessage Message = new ServerMessage(Outgoing.GroupInfo); // Updated

            Message.AppendInt32(Guild.Id);
            Message.AppendBoolean(true);
            Message.AppendInt32(Guild.Locked == "open" ? 0 : 1);
            Message.AppendStringWithBreak(Guild.Name);
            Message.AppendStringWithBreak(Guild.Description);
            Message.AppendStringWithBreak(Guild.Badge);
            using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
            {
                OwnerName = dbClient.ReadString("SELECT username FROM users WHERE id = '" + Guild.OwnerId + "' LIMIT 1");
            }
            if (Guild.RoomId > 0u)
            {
                Message.AppendUInt(Guild.RoomId);
                if (Essential.GetGame().GetRoomManager().GetRoom(Guild.RoomId) != null)
                {
                    Message.AppendStringWithBreak(Essential.GetGame().GetRoomManager().GetRoom(Guild.RoomId).Name);
                    goto IL_15A;
                }
                using (DatabaseClient class2 = Essential.GetDatabase().GetClient())
                {
                    try
                    {
                        DataRow dataRow_ = class2.ReadDataRow("SELECT * FROM rooms WHERE Id = " + Guild.RoomId + " LIMIT 1;");
                        string  string_  = Essential.GetGame().GetRoomManager().method_17(Guild.RoomId, dataRow_).Name;
                        Message.AppendStringWithBreak(string_);
                    }
                    catch
                    {
                        if (Session.GetHabbo().CurrentRoomId > 0)
                        {
                            Message.AppendInt32((int)Session.GetHabbo().CurrentRoomId);
                            Message.AppendStringWithBreak("");
                        }
                        else
                        {
                            Message.AppendInt32(-1);
                            Message.AppendStringWithBreak("");
                        }
                    }
                    goto IL_15A;
                }
            }
            if (Session.GetHabbo().CurrentRoomId > 0)
            {
                Message.AppendInt32((int)Session.GetHabbo().CurrentRoomId);
                Message.AppendStringWithBreak("");
            }
            else
            {
                Message.AppendInt32(-1);
                Message.AppendStringWithBreak("");
            }

IL_15A:
            bool flag = false;

            foreach (DataRow dataRow in Session.GetHabbo().dataTable_0.Rows)
            {
                if ((int)dataRow["groupid"] == Guild.Id)
                {
                    flag = true;
                }
            }
            if (Session.GetHabbo().list_0.Contains(Guild.Id))
            {
                Message.AppendInt32(2);
            }
            else
            {
                if (flag)
                {
                    Message.AppendInt32(1);
                }
                else
                {
                    if (Guild.Members.Contains((int)Session.GetHabbo().Id))
                    {
                        Message.AppendInt32(1);
                    }
                    else
                    {
                        Message.AppendInt32(0);
                    }
                }
            }
            Message.AppendInt32(Guild.Members.Count);
            if (Session.GetHabbo().FavouriteGroup == Guild.Id)
            {
                Message.AppendBoolean(true);
            }
            else
            {
                Message.AppendBoolean(false);
            }
            Message.AppendString(Guild.Created);
            Message.AppendBoolean(false);
            Message.AppendBoolean(false);
            Message.AppendString(OwnerName);
            Message.AppendBoolean(true);
            Message.AppendBoolean(false);
            Message.AppendInt32(0); // Pending
            Session.SendMessage(Message);

            ServerMessage InitGroupData = new ServerMessage(Outgoing.OwnGuilds);

            InitGroupData.AppendInt32(Session.GetHabbo().dataTable_0.Rows.Count);
            foreach (DataRow dataRow in Session.GetHabbo().dataTable_0.Rows)
            {
                GroupsManager current = Groups.GetGroupById((int)dataRow["groupId"]);
                InitGroupData.AppendInt32(current.Id);
                InitGroupData.AppendString(current.Name);
                InitGroupData.AppendString(current.Badge);
                InitGroupData.AppendString(current.ColorOne);
                InitGroupData.AppendString(current.ColorTwo);
                InitGroupData.AppendBoolean((Session.GetHabbo().FavouriteGroup == current.Id));
            }


            Session.SendMessage(InitGroupData);


            if (Session.GetHabbo().FavouriteGroup == Guild.Id)
            {
                Session.GetHabbo().FavouriteGroup = 0;
                using (DatabaseClient class2 = Essential.GetDatabase().GetClient())
                {
                    class2.ExecuteQuery("UPDATE user_stats SET groupid = 0 WHERE Id = " + Session.GetHabbo().Id + " LIMIT 1;");
                }
            }
        }
        public void Handle(GameClient Session, ClientMessage Event)
        {
            int           guildId = Event.PopWiredInt32();
            GroupsManager guild   = Groups.GetGroupById(guildId);
            int           UserId  = Event.PopWiredInt32();

            if (UserId != Session.GetHabbo().Id&& !guild.UserWithRanks.Contains((int)Session.GetHabbo().Id))
            {
                return;
            }
            if (guild != null)
            {
                using (DatabaseClient dbClient = Essential.GetDatabase().GetClient())
                {
                    dbClient.ExecuteQuery("DELETE FROM `group_memberships` WHERE (`groupid`='" + guildId + "') AND (`userid`='" + UserId + "') LIMIT 1");
                    dbClient.ExecuteQuery("UPDATE user_stats SET groupid=0 WHERE (groupid=" + guildId + ") AND (id=" + UserId + ") LIMIT 1");
                }
                guild.Leave(UserId);
                if (guild.UserWithRanks.Contains((int)UserId))
                {
                    guild.UserWithRanks.Remove((int)UserId);
                }
                if ((uint)UserId != Session.GetHabbo().Id)
                {
                    LoadMembersPetitions(0, guildId, 0, "", Session);
                }
                GameClient habbo = Essential.GetGame().GetClientManager().GetClientById((uint)UserId);
                if (habbo != null)
                {
                    if (habbo.GetHabbo().FavouriteGroup == guild.Id)
                    {
                        habbo.GetHabbo().FavouriteGroup = 0;
                        if (habbo.GetHabbo().CurrentRoom != null)
                        {
                            List <RoomUser> list    = new List <RoomUser>(habbo.GetHabbo().CurrentRoom.RoomUsers);
                            ServerMessage   message = new ServerMessage(Outgoing.SendGroup);
                            message.AppendInt32(0);
                            Session.SendMessage(message);
                            ServerMessage message2 = new ServerMessage(Outgoing.SetRoomUser);
                            message2.AppendInt32(1);
                            foreach (RoomUser user in list)
                            {
                                if (user.UId == habbo.GetHabbo().Id)
                                {
                                    user.method_14(message2);
                                    user.RemoveStatus("flatctrl 1");
                                    user.AddStatus("flatctrl 0", "");
                                    user.UpdateNeeded = true;
                                }
                            }
                            habbo.GetHabbo().CurrentRoom.SendMessage(message2, null);
                        }

                        habbo.GetHabbo().RefreshGuilds();
                    }
                    if ((int)Session.GetHabbo().Id == UserId)
                    {
                        RoomData      data = Essential.GetGame().GetRoomManager().method_11((uint)guild.RoomId);
                        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)Session.GetHabbo().Id))
                        {
                            message.AppendInt32(2);
                        }
                        else if (!Session.GetHabbo().InGuild(guild.Id))
                        {
                            message.AppendInt32(0);
                        }
                        else if (Session.GetHabbo().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));//(int)Session.GetHabbo().Id == guild.OwnerId);

                        if (Session.GetHabbo().InGuild(guild.Id))
                        {
                            if (guild.getRank((int)Session.GetHabbo().Id) < 2)
                            {
                                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)Session.GetHabbo().Id) ? guild.Petitions.Count : 0);
                        Session.SendMessage(message);
                    }
                }
            }
        }