public void SelectObject()
        {
            try
            {

                if (Character.Information.Scroll) return;
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                int objectid = Reader.Int32();
                if (objectid == 0) return;
                //Character.Action.Target = objectid;
                //if (Character.Position.Walking) StopPlayerMovementO(objectid);
                if (objectid == Character.Information.UniqueID) return;
                WorldMgr.Monsters o = Helpers.GetInformation.GetObject(objectid);
                if (o != null)
                {
                    byte[] bb = Packet.SelectObject(objectid, o.ID, o.LocalType, o.HP);
                    if (bb == null) return;
                    client.Send(bb);
                    //Character.Action.Object = o;
                    return;
                }
                PlayerMgr sys = Helpers.GetInformation.GetPlayers(objectid);
                if (o == null && sys != null)
                {
                    client.Send(Packet.SelectObject(objectid, 0, 5, sys.Character.Stat.Hp));
                    Character.Action.Object = sys;
                    return;
                }
                Reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Selectobject error: {0}", ex);
            }
        }
        public void Mastery_Skill_Up()
        {
            PacketReader Reader = new PacketReader(PacketInformation.buffer);
            int SkillID = Reader.Int32();
            /*if (Array.Exists(ObjData.Manager.SkillBase, GetSkill => GetSkill.ID == SkillID) == false)
            {
                Console.WriteLine("SkillID bulunamadı:{0}", Character.Information.Name);
            }
            */
            if (Character.Information.SkillPoint < ObjData.Manager.SkillBase[SkillID].SkillPoint) { Console.WriteLine("SP LAZIM"); return; }
            int check = DB.GetRowsCount("SELECT * FROM saved_skills WHERE skillid = " + SkillID + " AND owner=" + Character.Information.CharacterID);
            if (check == 1)
            {
                client.Send(Packet.Message(OperationCode.SERVER_SKILL_UPDATE, Messages.UIIT_STT_SKILL_LEARN_MASTERY_LIMIT));
                return;
            }
            else
            {
                Character.Stat.Skill.AmountSkill++;
                Character.Stat.Skill.Skill[Character.Stat.Skill.AmountSkill] = SkillID;
            }
            if (SkillGetOpened(SkillID))
            {
                Character.Information.SkillPoint -= ObjData.Manager.SkillBase[SkillID].SkillPoint;
                client.Send(Packet.InfoUpdate(2, Character.Information.SkillPoint, 0));
                client.Send(Packet.SkillUpdate(SkillID));
                client.Send(Packet.PlayerStat(Character));

                SaveSkill(SkillID);
            }
            else
            {
               return;
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        // Open Npc
        /////////////////////////////////////////////////////////////////////////////////
        public void Open_NPC()
        {
            #region Open Npc
            try
            {
                Character.State.Busy = true;
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                Reader.UInt32();
                byte type = Reader.Byte();

                if (type == 1)
                {
                    client.Send(Packet.OpenNPC(type));
                }
                else
                {
                    client.Send(Packet.OpenNPC(type));
                }
                Reader.Close();
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            #endregion
        }
        void CharacterJobPick(byte[] buff)
        {
            //Wrap our function inside a catcher
            try
            {
                //Open packet reader
                PacketReader Reader = new PacketReader(buff);
                Reader.Skip(1);
                short namel = Reader.Int16();
                string name = Reader.String(namel);
                byte job = Reader.Byte();
                Reader.Close();

                //Anti hack check
                string namecheck = DB.GetData("SELECT name FROM character WHERE account='" + Player.AccountName + "'", "name");
                int jobcheck = Convert.ToInt32(DB.GetData("SELECT jobtype FROM users WHERE id='" + Player.AccountName + "'", "jobtype"));

                //If the name check is succesfull and account has no job set.
                if (jobcheck == 0 && namecheck.Length > 0)
                {
                    //Write new job info
                    DB.query("UPDATE users SET jobtype='" + job + "' WHERE id='" + Player.AccountName + "'");
                }
                //Send visual confirmation
                client.Send(Packet.CharacterJobSelection());
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        // Friend add response
        /////////////////////////////////////////////////////////////////////////////////
        public void FriendAddResponse()
        {
            try
            {
                PacketReader reader = new PacketReader(PacketInformation.buffer);
                int Inviterid = reader.Int32();
                int Myid = reader.Int32();
                byte State = reader.Byte();
                reader.Close();

                PlayerMgr sys = Helpers.GetInformation.GetPlayer(Inviterid);
                if (sys != null)
                {
                    if (State == 0)
                    {
                        //Declined
                        client.Send(Packet.FriendDecline(Character.Information.Name));
                        sys.client.Send(Packet.FriendDecline(Character.Information.Name));
                    }
                    else
                    {
                        //Accepted
                        sys.client.Send(Packet.FriendData(Myid, 2, Character.Information.Name, Character, false));
                        client.Send(Packet.FriendData(Inviterid, 2, sys.Character.Information.Name, sys.Character, false));
                        DB.query("INSERT INTO friends (owner,friend_name,model_info) VALUES ('" + Character.Information.CharacterID + "','" + sys.Character.Information.CharacterID + "','" + sys.Character.Information.Model + "')");
                        DB.query("INSERT INTO friends (owner,friend_name,model_info) VALUES ('" + sys.Character.Information.CharacterID + "','" + Character.Information.CharacterID + "','" + Character.Information.Model + "')");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Friend Add Response Error {0}", ex);
                Log.Exception(ex);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Private Message Open
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void PrivateMessageOpen()
        {
            try
            {
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                /////////////////////////////////////////////////////////////////////////////////////
                byte type = Reader.Byte();
                short typeget = (short)type;
                Reader.Close();
                DB ms = new DB("SELECT * FROM message WHERE receiver='" + Character.Information.Name + "' AND idinfo ='" + typeget + "'");

                using (SqlDataReader reader = ms.Read())
                {
                    while (reader.Read())
                    {
                        string messageinfo = reader.GetString(3);
                        client.Send(Packet.PrivateMessageOpen(type, messageinfo));
                        DB.query("UPDATE message SET status='1' WHERE receiver='" + Character.Information.Name + "' AND idinfo ='" + type + "'");
                    }
                }
                ms.Close();
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
 public void Connect()
 {
     //Wrap our function inside a catcher
     try
     {
         //Open our packet reader
         PacketReader Reader = new PacketReader(PacketInformation.buffer);
         byte type = Reader.Byte();
         Reader.Skip(3);
         string ID = Reader.Text();
         string PW = Reader.Text();
         Reader.Close();
         //Set login result information
         int LoginResult = LoginUser(ID, ref PW, ref Player, true);
         //If the login is succesfull
         if (LoginResult == 4)
         {
             //Send succes packet
             client.Send(Packet.ConnectSuccess());
         }
         //If the login is wrong
         else
         {
             //Disconnect the user
             client.Disconnect(PacketInformation.Client);
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        public void PartyAddmembers()
        {
            try
            {
                //Create new packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                //Read target id
                int targetid = Reader.Int32();
                //Close packet reader
                Reader.Close();
                //Get detailed information from target
                PlayerMgr InvitedPlayer = Helpers.GetInformation.GetPlayer(targetid);
                //Check if the targeted player allready is in a party.
                if (InvitedPlayer.Character.Network.Party == null)
                {
                    //Set target id of target player to our id
                    InvitedPlayer.Character.Network.TargetID = this.Character.Information.UniqueID;
                    //Send request
                    InvitedPlayer.client.Send(Packet.PartyRequest(2, Character.Information.UniqueID, Character.Network.Party.Type));
                }
            }
            //Write bad exception errors
            catch (Exception ex)
            {
                //Write error to the console.
                Console.WriteLine(ex);
                //Write error to the debug log

            }
        }
 /////////////////////////////////////////////////////////////////////////////////
 // Add new friend
 /////////////////////////////////////////////////////////////////////////////////
 public void FriendAdd()
 {
     try
     {
         PacketReader reader = new PacketReader(PacketInformation.buffer);
         short namelenght = reader.Int16();
         string name = reader.String(namelenght);
         reader.Close();
         if (name == Character.Information.Name) return;
         PlayerMgr sys = Helpers.GetInformation.GetPlayerName(name);
         if (sys != null)
         {
             sys.client.Send(Packet.FriendInviteTarget(sys.Character));
         }
         else
         {
             //Packet cannot find user
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("Friend Add error {0}", ex);
         Log.Exception(ex);
     }
 }
 public void MakeAlias()
 {
     try
     {
         ///////////////////////////////////////////////////////////////////////////////////////////////////
         PacketReader Reader = new PacketReader(PacketInformation.buffer);
         int id = Reader.Int32();
         byte type = Reader.Byte();
         short nLenght = Reader.Int16();
         string name = Reader.String(nLenght);
         ///////////////////////////////////////////////////////////////////////////////////////////////////
         Console.WriteLine(name);
         DB ms = new DB("SELECT * FROM character_jobs WHERE job_alias='" + name + "'");
         int checkjob = ms.Count();
         ///////////////////////////////////////////////////////////////////////////////////////////////////
         client.Send(Packet.MakeAlias(name, type));
         if (checkjob == 0)
         {
             client.Send(Packet.MakeAlias(name, type));
             DB.query("UPDATE character_jobs SET job_alias='" + name + "' WHERE character_name='" + Character.Information.Name + "'");
         }
         else if (checkjob >= 0)
         {
             client.Send(Packet.MakeAliasError(name, type));
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        public void JoinMerc()
        {
            try
            {
                DB ms = new DB("SELECT * FROM character_jobs WHERE character_name='" + Character.Information.Name + "'");
                int checkjob = ms.Count();

                if (checkjob == 0)
                {
                    /////////////////////////////////////////////////////////////////////////////////////
                    PacketReader Reader = new PacketReader(PacketInformation.buffer);
                    int id = Reader.Int32();
                    byte type = Reader.Byte();
                    /////////////////////////////////////////////////////////////////////////////////////
                    client.Send(Packet.InfoUpdate(1, Character.Information.CharacterID, 0));
                    client.Send(Packet.JoinMerchant(id, type));
                    /////////////////////////////////////////////////////////////////////////////////////
                    DB.query("INSERT INTO character_jobs (character_name, job_type) VALUES ('" + Character.Information.Name + "','2')");
                    ms.Close();
                }
                else
                {
                    // Not needed cant join job because excist
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        /////////////////////////////////////////////////////////////////////////
        // Union Apply
        /////////////////////////////////////////////////////////////////////////
        public void unionapply()
        {
            try
            {
                //Open our packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                //Get target id (Targeted).
                int Target = Reader.Int32();
                //Close reader
                Reader.Close();

                //Get target details
                PlayerMgr targetplayer = Helpers.GetInformation.GetPlayer(Target);
                //Make sure the target is still there
                if (targetplayer != null)
                {
                    //If allready in union
                    if (targetplayer.Character.Network.Guild.UnionActive) return;
                    //Set bools for both players
                    targetplayer.Character.State.UnionApply = true;
                    Character.State.UnionApply = true;
                    //Set target player to us
                    targetplayer.Character.Network.TargetID = Character.Information.UniqueID;
                    //Send request to targeted player
                    targetplayer.client.Send(Packet.PartyRequest(6, Character.Information.UniqueID, 0));
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
 /////////////////////////////////////////////////////////////////////////////////
 // Movement angle
 /////////////////////////////////////////////////////////////////////////////////
 public void Angle()
 {
     PacketReader Reader = new PacketReader(PacketInformation.buffer);
     ushort angle = Reader.UInt16();
     client.Send(Packet.Angle(Character.Information.UniqueID, angle));
     client.Send(Packet.ChatPacket(7, 0, string.Format("ANGLE:{0}", angle), ""));
 }
        ///////////////////////////////////////////////////////////////////////////
        // Grabpet settings
        ///////////////////////////////////////////////////////////////////////////
        public void GrabPetSettings()
        {
            //Not worked on yet.
            PacketReader Reader         = new PacketReader(PacketInformation.buffer);
            int petid                   = Reader.Int32();
            byte type                   = Reader.Byte();
            int settingsinfo            = Reader.Int32();

            client.Send(Packet.ChangePetSettings(1, petid, type, settingsinfo));
        }
 public void GuildInvite()
 {
     //Wrap our code into a catcher
     try
     {
         //Create new packet reader
         PacketReader Reader = new PacketReader(PacketInformation.buffer);
         //Read lenght of invited character name
         Int16 InvitedCharacterLEN = Reader.Int16();
         //Read invited character name
         string InvitedCharacter = Reader.String(InvitedCharacterLEN);
         //Close packet reader
         Reader.Close();
         //Get information for target
         PlayerMgr sys = Helpers.GetInformation.GetPlayerName(InvitedCharacter);
         //Set targetid information
         Character.Network.TargetID = sys.Character.Information.UniqueID;
         //If player allready has a guild
         if (sys.Character.Network.Guild.Guildid != 0)
         {
             client.Send(Packet.Message(OperationCode.SERVER_GUILD_WAIT, Messages.UIIT_MSG_GUILDERR_MEMBER_OF_ANOTHER_GUILD));
             return;
         }
         //If player has to wait before the player can join another guild
         if (sys.Character.Information.GuildPenalty)
         {
             client.Send(Packet.Message(OperationCode.SERVER_GUILD_WAIT, Messages.UIIT_MSG_GUILD_PENALTY));
             return;
         }
         //If the guild has max members
         if (Character.Network.Guild.TotalMembers >= Character.Network.Guild.MaxMembers)
         {
             client.Send(Packet.Message(OperationCode.SERVER_GUILD_WAIT, Messages.UIIT_MSG_GUILDERR_MEMBER_FULL));
         }
         //If the character doesnt have join rights
         if (!Character.Network.Guild.joinRight)
         {
             //This should not happen unless hack attempt, because button should be grayed out
             return;
         }
         //Set targetid to the invited player
         sys.Character.Network.TargetID = this.Character.Information.UniqueID;
         //Send guild request packet
         sys.client.Send(Packet.PartyRequest(5, this.Character.Information.UniqueID, 0));
         //Set bools active
         Character.State.GuildInvite = true;
         sys.Character.State.GuildInvite = true;
     }
     //Catch bad exception errors
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        //##############################################################################
        // Start timers voids
        //##############################################################################
        public void StartPvpTimer(int time)
        {
            //Need to add checks
            PacketReader reader = new PacketReader(PacketInformation.buffer);
            byte pvptype = reader.Byte();

            if (Timer.Pvp != null) Timer.Pvp.Dispose();
            Timer.Pvp = new Timer(new TimerCallback(Player_Pvp_CallBack), 0, time, 0);
            Send(Packet.PvpSystemWait(Character.Information.UniqueID));
            Character.Information.PvpWait = true;
            Character.Information.Pvptype = pvptype;
        }
        public void StallBuy()
        {
            try
            {
                if (!Character.Network.Stall.isOpened) return;
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                byte stallslot = Reader.Byte();

                WorldMgr.stall currentStall = Character.Network.Stall;
                WorldMgr.stall.stallItem sitem = currentStall.ItemList.Find(i => (i.stallSlot == stallslot));

                // stall buyer update
                byte slot = GetFreeSlot();
                if (slot <= 12) return;
                if (Character.Information.Gold >= (long)sitem.price)
                {
                    Character.Information.Gold -= (long)sitem.price;
                    client.Send(Packet.UpdateGold(Character.Information.Gold));
                    SaveGold();
                }
                else return; //insufficent gold

                // staller update
                if (currentStall.ItemList.Contains(sitem))
                {
                    PlayerMgr staller = Helpers.GetInformation.GetPlayer(currentStall.ownerID);
                    staller.Character.Information.Gold += (long)sitem.price;
                    staller.client.Send(Packet.UpdateGold(staller.Character.Information.Gold));

                    DB.query("update character set gold='" + staller.Character.Information.Gold + "' where id='" + staller.Character.Information.CharacterID + "'");
                    //DB.query("delete from char_items where itemnumber='item" + sitem.Item.Slot + "' AND owner='" + staller.Character.Information.CharacterID + "'");
                    DB.query("UPDATE char_items SET owner='" + Character.Information.CharacterID + "',slot='" + slot + "',itemnumber='item" + slot + "' WHERE owner='" + staller.Character.Information.CharacterID + "' AND itemid='" + sitem.Item.ID + "' AND id='" + sitem.Item.dbID + "' AND storagetype='0'");
                    //take item out from stall
                    if (currentStall.ItemList.Count == 1)
                    {
                        staller.Character.Stall.Stallactive = false;
                        Character.Stall.Stallactive = false;
                    }
                    currentStall.ItemList.Remove(sitem);
                    client.Send(Packet.StallBuyItem(stallslot, 1));
                    currentStall.Send(Packet.StallBuyItem2(Character.Information.Name, stallslot, currentStall.ItemList));
                }
                else
                {
                    Disconnect("ban");
                    Console.WriteLine("Autobanned user: "******" Due to hacking");
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
 public void CharacterScreen()
 {
     //Wrap our function inside a catcher
     try
     {
         //Open our packet reader
         PacketReader Reader = new PacketReader(PacketInformation.buffer);
         byte type = Reader.Byte();
         //Switch on byte type
         switch (type)
         {
             case 1:
                 //WorldMgr.character creation
                 CharacterCreate();
                 break;
             case 2:
                 //Character listening
                 CharacterListing();
                 break;
             case 3:
                 //Character deletion
                 CharacterDelete();
                 break;
             case 4:
                 //WorldMgr.character checking
                 CharacterCheck(PacketInformation.buffer);
                 break;
             case 5:
                 //Character restoring
                 CharacterRestore();
                 break;
             case 9:
                 //Character job information
                 CharacterJobInfo();
                 break;
             case 16:
                 //Select job
                 CharacterJobPick(PacketInformation.buffer);
                 break;
             default:
                 //We use this if we get a new case.
                 Console.WriteLine("Character Screen Type: " + type);
                 Disconnect("normal");
                 break;
         }
         //Close packet reader
         Reader.Close();
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        public void RenameParty()
        {
            try
            {
                //Create new packet reader
                PacketReader reader = new PacketReader(PacketInformation.buffer);
                //First integer is party id
                int partyid = reader.Int32();
                //Second integer is not needed
                int NotNeeded = reader.Int32();
                //Byte party type
                byte ptype = reader.Byte();
                //Byte party purpose
                byte purpose = reader.Byte();
                //Byte minimum level
                byte minlevel = reader.Byte();
                //Byte max level to enter party
                byte maxlevel = reader.Byte();
                //Party name lenght
                short namel = reader.Int16();
                //Party name each character is a word value using text3
                string pname = reader.Text3();
                //Create new packet writer
                PacketWriter Writer = new PacketWriter();
                //Add opcode to server packet
                Writer.Create(OperationCode.SERVER_PARTY_CHANGENAME);
                //Write static byte 1
                Writer.Byte(1);
                //Write party id
                Writer.DWord(partyid);
                //Write dword 0
                Writer.DWord(0);
                //Write party type
                Writer.Byte(ptype);
                //Write party purpose
                Writer.Byte(purpose);
                //Write party minimum level
                Writer.Byte(minlevel);
                //Write party max level
                Writer.Byte(maxlevel);
                //Write party name
                Writer.Text3(pname);
                //Send bytes to client
                client.Send(Writer.GetBytes());
            }
            //If a error happens
            catch (Exception ex)
            {
                //Write the exception to the log

            }
        }
        public void Save()
        {
            //Wrap our function inside a catcher
            try
            {
                //Open our packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                string player_path;
                byte[] file;
                //Switch on byte
                switch (Reader.Byte())
                {
                    case 1:
                        //Save quickbar information
                        player_path = Environment.CurrentDirectory + @"\PlayerData\Hotkey\" + Character.Information.CharacterID + ".ClientSettings";
                        file = System.IO.File.ReadAllBytes(player_path);

                        byte Slot = Reader.Byte();
                        byte sType = Reader.Byte();

                        Slot *= 5;

                        file[Slot] = sType;
                        file[Slot + 1] = Reader.Byte();
                        file[Slot + 2] = Reader.Byte();
                        file[Slot + 3] = Reader.Byte();
                        file[Slot + 4] = Reader.Byte();
                        System.IO.File.WriteAllBytes(player_path, file);
                        break;
                    case 2:
                        //Save autopotion information
                        player_path = Environment.CurrentDirectory + @"\PlayerData\AutoPotion\" + Character.Information.CharacterID + ".ClientSettings";
                        file = System.IO.File.ReadAllBytes(player_path);
                        file[0] = Reader.Byte();
                        file[1] = Reader.Byte();
                        file[2] = Reader.Byte();
                        file[3] = Reader.Byte();
                        file[4] = Reader.Byte();
                        file[5] = Reader.Byte();
                        file[6] = Reader.Byte();
                        System.IO.File.WriteAllBytes(player_path, file);
                        UpdateHp();
                        UpdateMp();
                        break;
                }
                Reader.Close();
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        public void GuildTransferLeaderShip()
        {
            try
            {
                //Create new packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                //Read guild id
                int Guildid = Reader.Int32();
                //Read guild member id to transfer to
                int GuildMemberID = Reader.Int32();
                //Close reader
                Reader.Close();

                //Get detailed player information
                PlayerMgr NewLeader = Helpers.GetInformation.GetPlayerid(GuildMemberID);

                //Update database
                DB.query("UPDATE guild_members SET guild_rank='10',guild_perm_join='0',guild_perm_withdraw='0',guild_perm_union='0',guild_perm_storage='0',guild_perm_notice='0' WHERE guild_member_id='" + Character.Information.CharacterID + "'");
                DB.query("UPDATE guild_members SET guild_rank='0',guild_perm_join='1',guild_perm_withdraw='1',guild_perm_union='1',guild_perm_storage='1',guild_perm_notice='1' WHERE guild_member_id='" + GuildMemberID + "'");

                //Repeat for each member in our guild
                foreach (int member in Character.Network.Guild.Members)
                {
                    //Make sure member is not null
                    if (member != 0)
                    {
                        //Get information for the guildmember
                        PlayerMgr guildmember = Helpers.GetInformation.GetPlayerMainid(member);
                        //Make sure the guildmember isnt null
                        if (guildmember != null)
                        {
                            //Send update packet of new leader
                            guildmember.client.Send(Packet.GuildUpdate(Character, 3, GuildMemberID, 0, 0));
                        }
                    }
                }
                //Send message to old owner
                PacketWriter Writer = new PacketWriter();
                //Add opcode
                Writer.Create(OperationCode.SERVER_GUILD_TRANSFER_MSG);
                //Static byte 1
                Writer.Byte(1);
                //Send bytes to client
                client.Send(Writer.GetBytes());
            }
            //If a bad exception error happens
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        //Will need to read this byte by byte to get the id for the server to record for the chardata
        public void Gameguide()
        {
            try
            {
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                bool Guideok = false;
                int[] b1 = new int[8];
                for (int b = 0; b < 8; ++b)//Reads Guide Data
                {
                    b1[b] = Reader.Byte();//Puts into a int Array
                }

                for (int gc = 0; gc < 8; ++gc)//This Checks The Last Send Guide Paket To Make Sure The Same Packet Is Not Read Twice
                {
                    if (b1[gc] == Character.Guideinfo.Gchk[gc])
                    {
                        Guideok = false;//If Guide Packet Has Been Sent Will Return False
                    }
                    else
                    {
                        Guideok = true;//If Guide Packet Is New Will Retun True And Break
                        break;
                    }
                }

                if (Guideok)
                {
                    for (int gc = 0; gc < 8; ++gc)// Guide Packet Check
                    {
                        Character.Guideinfo.Gchk[gc] = b1[gc];//Adds Packet To Int Array
                    }

                    for (int gi = 0; gi < 8; ++gi)//Guide Packet Update For Save And Teleport,Return,Etc
                    {
                        Character.Guideinfo.G1[gi] = Character.Guideinfo.G1[gi] + b1[gi];//Adds The Packet And Updates The Data
                    }
                    PacketWriter Writer = new PacketWriter();//Writes the Packet Responce For Guide Window
                    Writer.Create(OperationCode.SERVER_SEND_GUIDE);
                    Writer.Byte(1);
                    for (int b = 0; b < 8; ++b)
                    {
                        Writer.Byte(b1[b]);
                    }
                    client.Send(Writer.GetBytes());
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Private Message Delete
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public void PrivateMessageDelete()
 {
     try
     {
         PacketReader Reader = new PacketReader(PacketInformation.buffer);
         byte messageid = Reader.Byte();
         client.Send(Packet.DeletePrivateMessage(messageid));
         DB.query("delete FROM message WHERE idinfo='" + messageid + "' AND receiver='" + Character.Information.Name + "'");
         return;
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        public void GuildWarGold()
        {
            PacketReader Reader = new PacketReader(PacketInformation.buffer);
            int guildid = Reader.Int32();
            Reader.Close();

            if (Character.Guild.GuildWarGold == 0)
            {
                //Send Packet Message No War Gold Received
                client.Send(Packet.GuildWarMsg(2));
            }
            else
            {
                //Sniff packet for war gold
            }
        }
        public void GuildMessage()
        {
            //Wrap our function inside a catcher
            try
            {
                //Create new packet reader
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                //Read short int16 for title lenght
                short TitleL = Reader.Int16();
                //Read string for title
                string Title = Reader.String(TitleL);
                //Read short Message lenght
                short MessageL = Reader.Int16();
                //Read message
                string Message = Reader.String(MessageL);
                //Close reader
                Reader.Close();

                //Update database guild message title and message
                DB.query("UPDATE guild SET guild_news_t='" + Title + "',guild_news_m='" + Message + "' WHERE guild_name='" + Character.Network.Guild.Name + "'");

                //Set new message info to current member for sending packet update.
                Character.Network.Guild.NewsTitle = Title;
                Character.Network.Guild.NewsMessage = Message;
                //Repeat for each member in our guild
                foreach (int member in Character.Network.Guild.Members)
                {
                    //Make sure the member is there
                    if (member != 0)
                    {
                        //Get detailed information from member main id
                        PlayerMgr characterinformation = Helpers.GetInformation.GetPlayerid(member);
                        //Set the current member news title and message information
                        characterinformation.Character.Network.Guild.NewsMessage = Message;
                        characterinformation.Character.Network.Guild.NewsTitle = Title;
                        //Send packet to the member to update guild message.
                        characterinformation.client.Send(Packet.GuildUpdate(characterinformation.Character, 11, 0, 0, 0));
                    }
                }
            }
            //Catch any bad exception error
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        void HandleRegisterIcon()
        {
            try
            {
                PacketReader reader = new PacketReader(PacketInformation.buffer);
                byte type = reader.Byte();
                int iconlenght = reader.Int32();
                string icon = reader.Text();
                reader.Close();

                string convertedicon = ConvertToHex(icon);
                //Save output to .dat file in hex formatting.
            }
            catch (Exception ex)
            {
                Console.WriteLine("Guild icon register error {0}", ex);
            }
        }
 void CharacterDelete()
 {
     //Wrap our function in a catcher
     try
     {
         //Open our reader
         PacketReader Reader = new PacketReader(PacketInformation.buffer);
         byte unused = Reader.Byte();
         string name = Reader.Text();
         Reader.Close();
         //Update character deletion information
         DB.query("UPDATE character SET deletedtime=dateadd(dd,7,getdate()) WHERE name='" + name + "'");
         //Update character visual screen
         client.Send(Packet.ScreenSuccess(3));
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
        public void CharacterCheck(byte[] buff)
        {
            //Wrap our function into a catcher
            try
            {
                //Open our reader
                PacketReader Reader = new PacketReader(buff);
                byte ignored = Reader.Byte();
                string name = Reader.Text();
                Reader.Close();

                if (CharacterCheck(name))
                    client.Send(Packet.CharacterName(4));
                else
                    client.Send(Packet.ScreenSuccess(4));
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
        public void HandleClosePet()
        {
            try
            {
                PacketReader Reader = new PacketReader(PacketInformation.buffer);
                int petid = Reader.Int32();

                if (petid == Character.Transport.Horse.UniqueID)
                {
                    Send(Packet.Player_UpToHorse(Character.Information.UniqueID, false, petid));
                    client.Send(Packet.PetSpawn(petid, 1, Character.Transport.Horse));
                    Character.Transport.Horse.DeSpawnMe();
                    Character.Transport.Right = false;
                    if (Character.Position.Walking) Timer.Movement.Dispose();
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
 //Public void select opcode
 public static void Opcode_List(Decode information)
 {
     //Set definition for detailed information
     Definitions.Clientdefinition Control = (Definitions.Clientdefinition)information.Packet;
     //Set Packetinformation as information (short).
     Control.PacketInformation = information;
     //Create a new packet reader to view incoming packet data
     PacketReader R = new PacketReader(Control.PacketInformation.buffer);
     //Create switch code based on the opcode the client sends.
     switch (information.opcode)
     {
         case Opcodes.CLIENT.CLIENT_PING_CHECK:
             break;
         case Opcodes.CLIENT.CLIENT_INFO:
             //If the client connecting is silkroad
             if (R.Text() == "SR_Client")
                 Control.client.Send(Connect.GateWayPacket());
             break;
         case Opcodes.CLIENT.CLIENT_GATEWAY_PATCH_REQUEST:
             Functions.Connect.ClientCheck(Control);
             break;
         case Opcodes.CLIENT.CLIENT_GATEWAY_SERVERLIST_REQUEST:
             Control.client.Send(Serverlist.ServerListPacket(0));
             break;
         case Opcodes.CLIENT.CLIENT_GATEWAY_LOGIN_REQUEST:
             Functions.Auth.Connect(Control);
             break;
         case Opcodes.CLIENT.CLIENT_GATEWAY_NOTICE_REQUEST:
             Control.client.Send(Connect._6());
             Control.client.Send(News.NewsPacket());
             break;
         case 1905:
             byte[] buffer = information.buffer;
             Definitions.Clientdefinition.Connected_Users = BitConverter.ToInt16(buffer, 0);
             break;
         default:
             break;
     }
 }