public void GuildPermissions()
        {
            try
            {
                //Create new packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                //Skip first
                Reader.Skip(1);
                //Read member id
                int memberid = Reader.Int32();
                //Read permission byte
                byte permissions = (byte)Reader.Int32();
                //Set new char bits 8
                char[] bits = new char[8];
                //Repeat for each 8 bits
                for (int i = 0; i < 8; ++i)
                {
                    bits[i] = (char)0;
                }
                //Convert bits to string / to char array
                bits = Convert.ToString(permissions, 2).ToCharArray();
                //Close reader
                Reader.Close();
                //Set amount to player targetindex
                int targetindex = this.Character.Network.Guild.MembersInfo.FindIndex(i => i.MemberID == memberid);
                //If character is online
                if (this.Character.Network.Guild.MembersInfo[targetindex].Online)
                {
                    //Get detailed player information
                    PlayerMgr member = Helpers.GetInformation.GetPlayerMainid(memberid);
                    //Set bits
                    member.Character.Network.Guild.joinRight         = bits[4] == '1' ? true : false;
                    member.Character.Network.Guild.withdrawRight     = bits[3] == '1' ? true : false;
                    member.Character.Network.Guild.unionRight        = bits[2] == '1' ? true : false;
                    member.Character.Network.Guild.guildstorageRight = bits[0] == '1' ? true : false;
                    member.Character.Network.Guild.noticeeditRight   = bits[1] == '1' ? true : false;
                }
                // set new amount to every guild members guild class
                foreach (int m in Character.Network.Guild.Members)
                {
                    //Set int index (Find member id)
                    int index = Character.Network.Guild.MembersInfo.FindIndex(i => i.MemberID == m);
                    //If the character is online
                    if (Character.Network.Guild.MembersInfo[index].Online)
                    {
                        //Get detailed information of the player
                        PlayerMgr sys = Helpers.GetInformation.GetPlayerMainid(m);

                        //Set new guild player
                        ObjData.guild_player mygp = new ObjData.guild_player();
                        int myindex = 0;
                        //Repeat for each player
                        foreach (ObjData.guild_player gp in sys.Character.Network.Guild.MembersInfo)
                        {
                            //if the member id equals the player
                            if (gp.MemberID == memberid)
                            {
                                //Set my gp
                                mygp = gp;
                                //Set bits
                                mygp.joinRight         = bits[4] == '1' ? true : false;
                                mygp.withdrawRight     = bits[3] == '1' ? true : false;
                                mygp.unionRight        = bits[2] == '1' ? true : false;
                                mygp.guildstorageRight = bits[0] == '1' ? true : false;
                                mygp.noticeeditRight   = bits[1] == '1' ? true : false;
                                break;
                            }
                            //Index ++
                            myindex++;
                        }
                        //Set membersinfo index as mygp
                        sys.Character.Network.Guild.MembersInfo[myindex] = mygp;
                    }
                }
                //Update guild database information rights
                DB.query("UPDATE guild_members SET guild_perm_join='" + bits[4] + "',guild_perm_withdraw='" + bits[3] + "',guild_perm_union='" + bits[2] + "',guild_perm_storage='" + bits[0] + "',guild_perm_notice='" + bits[1] + "' WHERE guild_member_id='" + memberid + "'");
                //Send to everyone in guild update of permissions
                Character.Network.Guild.Send(Packet.GuildUpdate(Character, 4, 0, permissions, 0));
            }
            //If an error happens
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        public void LoadGuildMembers()
        {
            //Wrap our code in a try to catch bad exception errors
            try
            {
                //Load guild member id's
                LoadGuildMemberIds(Character.Network.Guild.Guildid, ref Character.Network.Guild.Members);
                //Repeat for each member in the guild member list
                foreach (int Guildmember in Character.Network.Guild.Members)
                {
                    //Set new guild player information
                    ObjData.guild_player PlayerGuild = new ObjData.guild_player();
                    //Set guildmember id
                    PlayerGuild.MemberID = Guildmember;
                    //Create new DB query to get player information
                    DB ms = new DB("SELECT * FROM character WHERE id='" + Guildmember + "'");
                    //Create DB data reader
                    using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                    {
                        //While the reader is reading
                        while (reader.Read())
                        {
                            //Get player model
                            PlayerGuild.Model = reader.GetInt32(3);
                            //Get player xsector
                            PlayerGuild.Xsector = reader.GetByte(16);
                            //Get player ysector
                            PlayerGuild.Ysector = reader.GetByte(17);
                            //Get player level
                            PlayerGuild.Level = reader.GetByte(5);
                            //Get player name
                            PlayerGuild.Name = reader.GetString(2);
                            //Get player online state
                            PlayerGuild.Online = (reader.GetInt32(47) == 1);
                            //If player is online
                            if (PlayerGuild.Online)
                            {
                                //Get detailed player information
                                PlayerMgr sys = Helpers.GetInformation.GetPlayerMainid(Guildmember);
                                //Make sure sys is not null
                                if (sys != null)
                                    //Add the character client to the client list
                                    if (!this.Character.Network.Guild.MembersClient.Contains(sys.client))
                                        Character.Network.Guild.MembersClient.Add(sys.client);
                            }
                        }
                    }
                    //Create new query to select from table guild_members
                    ms = new DB("SELECT * FROM guild_members WHERE guild_member_id='" + Guildmember + "'");
                    //Create new sql data reader
                    using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                    {
                        //While the sql data reader is reading
                        while (reader.Read())
                        {
                            //Get player rights
                            PlayerGuild.joinRight = (reader.GetByte(7) == 1);
                            PlayerGuild.withdrawRight = (reader.GetByte(8) == 1);
                            PlayerGuild.unionRight = (reader.GetByte(9) == 1);
                            PlayerGuild.guildstorageRight = (reader.GetByte(10) == 1);
                            PlayerGuild.noticeeditRight = (reader.GetByte(11) == 1);
                            PlayerGuild.FWrank = reader.GetByte(6);
                            //Get player donated gp
                            PlayerGuild.DonateGP = reader.GetInt32(4);
                            //Get player rank
                            PlayerGuild.Rank = reader.GetByte(3);
                        }
                    }
                    //Close DB
                    ms.Close();
                    //Add our character to the guild member info
                    Character.Network.Guild.MembersInfo.Add(PlayerGuild);
                }
            }
            //Catch bad exceptions
            catch (Exception ex)
            {
                //Write error to the console
                Console.WriteLine(ex);
                //Write error to the debug log file

            }
        }
 public void LoadGuildMembers()
 {
     //Wrap our code in a try to catch bad exception errors
     try
     {
         //Load guild member id's
         LoadGuildMemberIds(Character.Network.Guild.Guildid, ref Character.Network.Guild.Members);
         //Repeat for each member in the guild member list
         foreach (int Guildmember in Character.Network.Guild.Members)
         {
             //Set new guild player information
             ObjData.guild_player PlayerGuild = new ObjData.guild_player();
             //Set guildmember id
             PlayerGuild.MemberID = Guildmember;
             //Create new DB query to get player information
             DB ms = new DB("SELECT * FROM character WHERE id='" + Guildmember + "'");
             //Create DB data reader
             using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
             {
                 //While the reader is reading
                 while (reader.Read())
                 {
                     //Get player model
                     PlayerGuild.Model = reader.GetInt32(3);
                     //Get player xsector
                     PlayerGuild.Xsector = reader.GetByte(16);
                     //Get player ysector
                     PlayerGuild.Ysector = reader.GetByte(17);
                     //Get player level
                     PlayerGuild.Level = reader.GetByte(5);
                     //Get player name
                     PlayerGuild.Name = reader.GetString(2);
                     //Get player online state
                     PlayerGuild.Online = (reader.GetInt32(47) == 1);
                     //If player is online
                     if (PlayerGuild.Online)
                     {
                         //Get detailed player information
                         PlayerMgr sys = Helpers.GetInformation.GetPlayerMainid(Guildmember);
                         //Make sure sys is not null
                         if (sys != null)
                         {
                             //Add the character client to the client list
                             if (!this.Character.Network.Guild.MembersClient.Contains(sys.client))
                             {
                                 Character.Network.Guild.MembersClient.Add(sys.client);
                             }
                         }
                     }
                 }
             }
             //Create new query to select from table guild_members
             ms = new DB("SELECT * FROM guild_members WHERE guild_member_id='" + Guildmember + "'");
             //Create new sql data reader
             using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
             {
                 //While the sql data reader is reading
                 while (reader.Read())
                 {
                     //Get player rights
                     PlayerGuild.joinRight         = (reader.GetByte(7) == 1);
                     PlayerGuild.withdrawRight     = (reader.GetByte(8) == 1);
                     PlayerGuild.unionRight        = (reader.GetByte(9) == 1);
                     PlayerGuild.guildstorageRight = (reader.GetByte(10) == 1);
                     PlayerGuild.noticeeditRight   = (reader.GetByte(11) == 1);
                     PlayerGuild.FWrank            = reader.GetByte(6);
                     //Get player donated gp
                     PlayerGuild.DonateGP = reader.GetInt32(4);
                     //Get player rank
                     PlayerGuild.Rank = reader.GetByte(3);
                 }
             }
             //Close DB
             ms.Close();
             //Add our character to the guild member info
             Character.Network.Guild.MembersInfo.Add(PlayerGuild);
         }
     }
     //Catch bad exceptions
     catch (Exception ex)
     {
         //Write error to the console
         Console.WriteLine(ex);
         //Write error to the debug log file
     }
 }
        public void GuildPermissions()
        {
            try
            {
                //Create new packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                //Skip first
                Reader.Skip(1);
                //Read member id
                int memberid = Reader.Int32();
                //Read permission byte
                byte permissions = (byte)Reader.Int32();
                //Set new char bits 8
                char[] bits = new char[8];
                //Repeat for each 8 bits
                for (int i = 0; i < 8; ++i) bits[i] = (char)0;
                //Convert bits to string / to char array
                bits = Convert.ToString(permissions, 2).ToCharArray();
                //Close reader
                Reader.Close();
                //Set amount to player targetindex
                int targetindex = this.Character.Network.Guild.MembersInfo.FindIndex(i => i.MemberID == memberid);
                //If character is online
                if (this.Character.Network.Guild.MembersInfo[targetindex].Online)
                {
                    //Get detailed player information
                    PlayerMgr member = Helpers.GetInformation.GetPlayerMainid(memberid);
                    //Set bits
                    member.Character.Network.Guild.joinRight = bits[4] == '1' ? true : false;
                    member.Character.Network.Guild.withdrawRight = bits[3] == '1' ? true : false;
                    member.Character.Network.Guild.unionRight = bits[2] == '1' ? true : false;
                    member.Character.Network.Guild.guildstorageRight = bits[0] == '1' ? true : false;
                    member.Character.Network.Guild.noticeeditRight = bits[1] == '1' ? true : false;
                }
                // set new amount to every guild members guild class
                foreach (int m in Character.Network.Guild.Members)
                {
                    //Set int index (Find member id)
                    int index = Character.Network.Guild.MembersInfo.FindIndex(i => i.MemberID == m);
                    //If the character is online
                    if (Character.Network.Guild.MembersInfo[index].Online)
                    {
                        //Get detailed information of the player
                        PlayerMgr sys = Helpers.GetInformation.GetPlayerMainid(m);

                        //Set new guild player
                        ObjData.guild_player mygp = new ObjData.guild_player();
                        int myindex = 0;
                        //Repeat for each player
                        foreach (ObjData.guild_player gp in sys.Character.Network.Guild.MembersInfo)
                        {
                            //if the member id equals the player
                            if (gp.MemberID == memberid)
                            {
                                //Set my gp
                                mygp = gp;
                                //Set bits
                                mygp.joinRight = bits[4] == '1' ? true : false;
                                mygp.withdrawRight = bits[3] == '1' ? true : false;
                                mygp.unionRight = bits[2] == '1' ? true : false;
                                mygp.guildstorageRight = bits[0] == '1' ? true : false;
                                mygp.noticeeditRight = bits[1] == '1' ? true : false;
                                break;
                            }
                            //Index ++
                            myindex++;
                        }
                        //Set membersinfo index as mygp
                        sys.Character.Network.Guild.MembersInfo[myindex] = mygp;
                    }
                }
                //Update guild database information rights
                DB.query("UPDATE guild_members SET guild_perm_join='" + bits[4] + "',guild_perm_withdraw='" + bits[3] + "',guild_perm_union='" + bits[2] + "',guild_perm_storage='" + bits[0] + "',guild_perm_notice='" + bits[1] + "' WHERE guild_member_id='" + memberid + "'");
                //Send to everyone in guild update of permissions
                Character.Network.Guild.Send(Packet.GuildUpdate(Character, 4, 0, permissions, 0));
            }
            //If an error happens
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }