public void CharacterRequest()
        {
            try
            {
                //Open packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);

                //Get targeted player information
                PlayerMgr sys = Helpers.GetInformation.GetPlayer(Character.Network.TargetID);

                if (this.Character.State.UnionApply && sys.Character.State.UnionApply)
                {
                    if (Reader.Byte() == 1 && Reader.Byte() == 0)
                    {
                        //Need to sniff decline packet info
                        Character.State.UnionApply     = false;
                        sys.Character.State.UnionApply = false;
                    }
                    else
                    {
                        //Check for null and set unique id for union and insert our own guild.
                        if (sys.Character.Network.Guild.Unions == null)
                        {
                            int uniqueid = DB.GetRowsCount("SELECT * FROM guild_unions");
                            sys.Character.Network.Guild.UniqueUnion = uniqueid + 1;
                            DB.query("INSERT INTO guild_unions (union_leader, union_guildid, union_unique_id) VALUES ('" + sys.Character.Network.Guild.Guildid + "','" + sys.Character.Network.Guild.Guildid + "','" + sys.Character.Network.Guild.UniqueUnion + "')");
                        }
                        //Update database
                        DB.query("INSERT INTO guild_unions (union_leader, union_guildid, union_unique_id) VALUES ('" + sys.Character.Network.Guild.Guildid + "','" + Character.Network.Guild.Guildid + "','" + sys.Character.Network.Guild.UniqueUnion + "')");

                        //Send union packet to newly joined player
                        client.Send(Packet.UnionInfo(this));

                        //Send update packet to all guilds in union
                        foreach (int member in Character.Network.Guild.Members)
                        {
                            //Make sure the member is there
                            if (member != 0)
                            {
                                //If the user is not the newly invited member get player info
                                PlayerMgr tomember = Helpers.GetInformation.GetPlayerMainid(member);
                                //Send guild update packet
                                if (tomember != null)
                                {
                                    if (!tomember.Character.Network.Guild.SingleSend)
                                    {
                                        if (Character.Information.CharacterID != tomember.Character.Information.CharacterID)
                                        {
                                            tomember.Character.Network.Guild.SingleSend = true;
                                            tomember.client.Send(Packet.GuildUpdate(Character, 14, 0, 0, 0));
                                        }
                                    }
                                }
                            }
                        }
                        foreach (int member in Character.Network.Guild.UnionMembers)
                        {
                            //Make sure the member is there
                            if (member != 0)
                            {
                                //If the user is not the newly invited member get player info
                                PlayerMgr tomember = Helpers.GetInformation.GetPlayerMainid(member);
                                //Send guild update packet
                                if (tomember != null)
                                {
                                    if (!tomember.Character.Network.Guild.SingleSend)
                                    {
                                        tomember.Character.Network.Guild.SingleSend = true;
                                        tomember.client.Send(Packet.GuildUpdate(Character, 14, 0, 0, 0));
                                    }
                                }
                            }
                        }
                        //Disable the bool again
                        foreach (int member in Character.Network.Guild.Members)
                        {
                            //Make sure member isnt null
                            if (member != 0)
                            {
                                //Get guildmember details
                                PlayerMgr guildmember = Helpers.GetInformation.GetPlayerMainid(member);
                                //Make sure guildmember isnt null
                                if (guildmember != null)
                                {
                                    //Disable bool to allow resend new packets.
                                    guildmember.Character.Network.Guild.SingleSend = false;
                                }
                            }
                        }
                        //Disable the bool again
                        foreach (int member in Character.Network.Guild.UnionMembers)
                        {
                            //Make sure member isnt null
                            if (member != 0)
                            {
                                //Get guildmember details
                                PlayerMgr guildmember = Helpers.GetInformation.GetPlayerMainid(member);
                                //Make sure guildmember isnt null
                                if (guildmember != null)
                                {
                                    //Disable bool to allow resend new packets.
                                    guildmember.Character.Network.Guild.SingleSend = false;
                                }
                            }
                        }
                        //Reset bools
                        Character.State.UnionApply     = false;
                        sys.Character.State.UnionApply = false;
                    }
                }
                //------------------------------------- [ Exchange invite ] -------------------------------------//
                else if (this.Character.State.Exchanging && sys.Character.State.Exchanging)
                {
                    if (Reader.Byte() == 1 && Reader.Byte() == 0)
                    {
                        sys.client.Send(Packet.Exchange_Cancel());
                        Character.State.Exchanging     = false;
                        sys.Character.State.Exchanging = false;
                    }
                    else
                    {
                        sys.client.Send(Packet.OpenExhangeWindow(1, this.Character.Information.UniqueID));
                        client.Send(Packet.OpenExhangeWindow(sys.Character.Information.UniqueID));

                        Character.Network.Exchange.Window       = true;
                        Character.Network.Exchange.ItemList     = new List <ObjData.slotItem>();
                        sys.Character.Network.Exchange.Window   = true;
                        sys.Character.Network.Exchange.ItemList = new List <ObjData.slotItem>();
                    }
                }
                //------------------------------------- [ Guild invite ] -------------------------------------//
                else if (this.Character.State.GuildInvite && sys.Character.State.GuildInvite)
                {
                    //If byte equals 2 the type is denied
                    if (Reader.Byte() == 2)
                    {
                        //Denied request
                        Character.State.GuildInvite     = false;
                        sys.Character.State.GuildInvite = false;
                        //Send refused packet to sender
                        sys.client.Send(Packet.Message(OperationCode.SERVER_GUILD, Messages.UIIT_MSG_GUILDERR_JOIN_GUILD_REFUSED));
                    }
                    //If not denied we start adding the new member
                    else
                    {
                        //Invite guild member (Add member count + 1).
                        int guildmemberadd = sys.Character.Network.Guild.Members.Count + 1;
                        //Update database
                        DB.query("INSERT INTO guild_members (guild_id, guild_member_id, guild_rank, guild_points, guild_fortress, guild_grant, guild_perm_join, guild_perm_withdraw, guild_perm_union, guild_perm_storage, guild_perm_notice) VALUES ('" + sys.Character.Network.Guild.Guildid + "','" + Character.Information.CharacterID + "','10','0','1','" + "" + "','0','0','0','0','0')");
                        DB.query("UPDATE guild SET guild_members_t='" + guildmemberadd + "' WHERE guild_name='" + sys.Character.Network.Guild.Name + "'");
                        //Reload new member and load character data for guildinfo
                        LoadPlayerGuildInfo(true);
                        //Send packets to network and spawned players
                        foreach (int member in Character.Network.Guild.Members)
                        {
                            //Make sure the member is there
                            if (member != 0)
                            {
                                //We dont send this info to the invited user.
                                if (member != Character.Information.CharacterID)
                                {
                                    //If the user is not the newly invited member get player info
                                    PlayerMgr tomember = Helpers.GetInformation.GetPlayerMainid(member);
                                    //Send guild update packet
                                    tomember.LoadPlayerGuildInfo(true);
                                    tomember.client.Send(Packet.GuildUpdate(Character, 1, Character.Information.CharacterID, 0, 0));
                                    tomember.client.Send(Packet.GuildSetOnline(Character.Network.Guild, Character.Information.UniqueID));
                                    tomember.client.Send(Packet.GuildUpdate(Character, 6, Character.Information.CharacterID, 0, 0));
                                }
                                //Send information to the invited player
                                else
                                {
                                    //Send guild data packets to invited
                                    client.Send(Packet.SendGuildStart());
                                    client.Send(Packet.SendGuildInfo(Character.Network.Guild));
                                    client.Send(Packet.SendGuildEnd());
                                    //Load union data for new invited player
                                    LoadUnions();
                                }
                            }
                        }
                        //Set bools to false for new invite
                        Character.State.GuildInvite     = false;
                        sys.Character.State.GuildInvite = false;
                    }
                }

                //------------------------------------- [ Party invite ] -------------------------------------//
                else
                {
                    //If invitation is accepted
                    if (Reader.Byte() == 1 && Reader.Byte() == 1)
                    {
                        //First we set our main checks (Check if player is in party or not).
                        if (Character.Network.Party != null)
                        {
                            return;
                        }
                        //Set bools for check
                        Character.Information.CheckParty     = true;
                        sys.Character.Information.CheckParty = true;

                        //Set main party information
                        WorldMgr.party JoiningParty = sys.Character.Network.Party;

                        //Check party type members allowed need message if full
                        if (JoiningParty.Type == 4 && JoiningParty.Members.Count > 3)
                        {
                            //Send party is full message to player
                            client.Send(Packet.Message(OperationCode.SERVER_PARTY_MESSAGES, Messages.UIIT_MSG_PARTYERR_ALREADY_FULL));
                            return;
                        }
                        if (JoiningParty.Type == 5 && JoiningParty.Members.Count > 7)
                        {
                            //Send party is full message to player
                            client.Send(Packet.Message(OperationCode.SERVER_PARTY_MESSAGES, Messages.UIIT_MSG_PARTYERR_ALREADY_FULL));
                            return;
                        }
                        //If the current count == 0 then add party and add me
                        if (JoiningParty.Members.Count == 0)
                        {
                            //Add ourselfs to the party list
                            JoiningParty.Members.Add(sys.Character.Information.UniqueID);
                            //Add our client to the party list
                            JoiningParty.MembersClient.Add(sys.client);
                            //Set party id
                            JoiningParty.ptid = Helpers.Manager.Party.Count + 1;
                            //Set party network info
                            sys.Character.Network.Party = JoiningParty;
                            //Send permissions
                            sys.client.Send(Packet.Party_Member(sys.Character.Information.UniqueID));
                            //Send party data to leader
                            sys.client.Send(Packet.Party_DataMember(JoiningParty));
                            //Send party data packet to leader (Other player that joined).
                            sys.client.Send(Packet.Party_Data(2, Character.Information.UniqueID));
                            //Add invited member to the list
                            JoiningParty.Members.Add(Character.Information.UniqueID);
                            JoiningParty.MembersClient.Add(client);
                            //Set party info for invited member
                            Character.Network.Party = JoiningParty;
                            //Send permissions
                            client.Send(Packet.PartyOwnerInformation(Character.Information.UniqueID));
                            //Send party data
                            client.Send(Packet.Party_DataMember(JoiningParty));
                            //return
                            return;
                        }
                        //If there are more members in the current party
                        else
                        {
                            //Repeat for each member using count
                            for (byte b = 0; b <= JoiningParty.Members.Count - 1; b++)
                            {
                                //Get player information from [b]
                                PlayerMgr others = Helpers.GetInformation.GetPlayer(JoiningParty.Members[b]);
                                //Send party data to member
                                others.client.Send(Packet.Party_Data(2, Character.Information.UniqueID));
                            }
                            //Add the invited member to list
                            JoiningParty.Members.Add(Character.Information.UniqueID);
                            //Add the invited client to the list
                            JoiningParty.MembersClient.Add(client);
                            //Set party
                            Character.Network.Party = JoiningParty;
                            //Send permissions
                            client.Send(Packet.PartyOwnerInformation(Character.Information.UniqueID));
                            //Send party data
                            client.Send(Packet.Party_DataMember(JoiningParty));
                            return;
                        }
                    }
                    //If denied request
                    else
                    {
                        //Send denied message to the player joining
                        client.Send(Packet.Message(OperationCode.SERVER_PARTY_MEMBER, Messages.UIIT_MSG_PARTYERR_JOIN_PARTY_REFUSED));
                        //Set both bools to false so inviting can be done again
                        sys.Character.Information.CheckParty = false;
                        Character.Information.CheckParty     = false;
                    }
                }
            }
            //Catch bad exception errors
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        public void GuildPromote()
        {
            try
            {
                //Read client information int32 id
                PacketReader reader  = new PacketReader(PacketInformation.buffer);
                int          guildid = reader.Int32();
                reader.Close();

                //When a guild has reached its max level
                if (Character.Network.Guild.Level == 5)
                {
                    //Send packet to client and return (Message level up max).
                    client.Send(Packet.Message(OperationCode.SERVER_GUILD_WAIT, Messages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_FULL));
                    return;
                }
                //Definition for gold needed
                int GoldRequired;
                //Definition for guild points needed
                int GuildPointRequired;
                //Check if player is allready in process of upgrading
                if (!IsUpgrading)
                {
                    //Set bool to true, so we cant dupe
                    IsUpgrading = true;
                    //Load player guild information before we continue (Check last info).
                    LoadPlayerGuildInfo(false);
                    //Create switch on guildl evel
                    switch (Character.Network.Guild.Level)
                    {
                    case 1:
                        GoldRequired       = 3000000;
                        GuildPointRequired = 5400;
                        break;

                    case 2:
                        GoldRequired       = 9000000;
                        GuildPointRequired = 50400;
                        break;

                    case 3:
                        GoldRequired       = 15000000;
                        GuildPointRequired = 135000;
                        break;

                    case 4:
                        GoldRequired       = 21000000;
                        GuildPointRequired = 378000;
                        break;

                    default:
                        return;
                    }
                    //Set new guild level definition + 1
                    int NewLevel = Character.Network.Guild.Level + 1;
                    //Set new guild storage slot  amount
                    int NewStorageSlots = Character.Network.Guild.StorageSlots + 30;
                    //If character's gold is not enough
                    if (Character.Information.Gold < GoldRequired)
                    {
                        //Send message to client
                        client.Send(Packet.Message(OperationCode.SERVER_GUILD_PROMOTE_MSG, Messages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_GOLD_DEFICIT));
                        return;
                    }
                    //Not enough guildpoints
                    if (Character.Network.Guild.PointsTotal < GuildPointRequired)
                    {
                        //Send client message
                        client.Send(Packet.Message(OperationCode.SERVER_GUILD_PROMOTE_MSG, Messages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_GP_DEFICIT));
                        return;
                    }
                    //Max level
                    if (Character.Network.Guild.Level == 5)
                    {
                        //Send client message
                        client.Send(Packet.Message(OperationCode.SERVER_GUILD_PROMOTE_MSG, Messages.UIIT_MSG_ERROR_GUILD_LEVEL_UP_FULL));
                        return;
                    }
                    //If everything else is fine
                    else
                    //Upgrade guild initiate
                    {
                        //If max level return just incase.
                        if (Character.Network.Guild.Level == 5)
                        {
                            return;
                        }
                        //Reduct guildpoints
                        Character.Network.Guild.PointsTotal -= GuildPointRequired;
                        //If the upgrade is final upgrade set points to 0
                        if (Character.Network.Guild.Level == 4)
                        {
                            Character.Network.Guild.PointsTotal = 0;
                        }
                        //Reduct gold
                        Character.Information.Gold -= GoldRequired;
                        //Send update information to client
                        client.Send(Packet.InfoUpdate(1, Character.Network.Guild.PointsTotal, 0));
                        //Send success message to client
                        client.Send(Packet.PromoteOrDisband(2));
                        //Update guild in database
                        DB.query("UPDATE guild SET guild_level='" + NewLevel + "',guild_points='" + Character.Network.Guild.PointsTotal + "',guild_storage_slots='" + NewStorageSlots + "' WHERE guild_name='" + Character.Network.Guild.Name + "'");
                        //Repeat for each member in our guild
                        foreach (int member in Character.Network.Guild.Members)
                        {
                            //Check if memeber is not null
                            if (member != 0)
                            {
                                //Get detailed member information
                                PlayerMgr memberinfo = Helpers.GetInformation.GetPlayerMainid(member);
                                //Make sure the member is not null
                                if (memberinfo != null)
                                {
                                    //Reload information for the current guild member
                                    memberinfo.LoadPlayerGuildInfo(false);
                                    //Send guild update packet for current guild member
                                    memberinfo.client.Send(Packet.GuildUpdate(Character, 5, 0, 0, 0));
                                }
                            }
                        }
                        //Save player's gold
                        SaveGold();
                        //Send update gold packet to client
                        client.Send(Packet.UpdateGold(Character.Information.Gold));
                    }
                }
                //Disable the bool so we can upgrade again
                IsUpgrading = false;
            }
            //If any error accures
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }