public static ushort LoginUser(string aID, ref string aPass, ref WorldMgr.player aPlayer, bool localConnect)
        {
            if (Helpers.Manager.clients.Count >= Helpers.Manager.maxSlots)
            {
                return(0); // crowded
            }
            DB ms = new DB("SELECT * FROM users WHERE id = '" + aID + "'");

            if (ms.Count() == 0)
            {
                ms.Close();
                return(1);
            }
            ms = new DB("SELECT * FROM users WHERE id = '" + aID + "' AND password='******'");
            if (ms.Count() == 0)
            {
                ms.Close();
                return(5);
            }
            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    if (reader.GetString(1).ToLower() == aID.ToLower()) // id
                    {
                        if (reader.GetByte(3) == 1)                     // online
                        {
                            ms.Close();
                            return(2); // already online
                        }

                        if (reader.GetInt32(5) == 1) // banned
                        {
                            aPass = reader.GetString(4);
                            ms.Close();
                            return(3); // banned
                        }

                        if (aPlayer == null && localConnect)
                        {
                            DB.query("UPDATE users SET online=1 WHERE userid='" + reader.GetInt32(0) + "'");
                        }
                        aPlayer             = new WorldMgr.player();
                        aPlayer.AccountName = aID;
                        aPlayer.Password    = aPass; // Nukei: ?? whats the reason for saving password in memory ?
                        aPlayer.ID          = reader.GetInt32(0);
                        aPlayer.pGold       = reader.GetInt64(7);
                        aPlayer.Silk        = reader.GetInt32(6);
                        aPlayer.SilkPrem    = reader.GetInt32(9);
                        aPlayer.wSlots      = reader.GetByte(11);
                        ms.Close();
                        return(4);
                    }
                }
            }
            ms.Close();
            return(6); // Bilinmeyen geri dönüş:Özel bir durum oluşmadı. (Mecburi Gönderim)
        }
Exemple #2
0
        /////////////////////////////////////////////////////////////////////////////////
        // Login user
        /////////////////////////////////////////////////////////////////////////////////
        public static int LoginUser(string aID, ref string aPass, ref DarkEmu_GameServer.player aPlayer, bool localConnect)
        {
            //Console.WriteLine("Login User: {0} - {1}",aID,aPass);

            MsSQL ms = new MsSQL("SELECT * FROM users WHERE password='******'");

            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                if (Systems.clients.Count >= Systems.maxSlots)
                {
                    ms.Close();
                    return(2); // crowded
                }

                while (reader.Read())
                {
                    if (reader.GetString(1).ToLower() == aID.ToLower()) // id
                    {
                        if (reader.GetByte(3) == 1)                     // online
                        {
                            ms.Close();
                            return(3); // already online
                        }

                        if (reader.GetInt32(5) == 1) // banned
                        {
                            aPass = reader.GetString(4);
                            ms.Close();
                            return(4); // banned
                        }

                        if (aPlayer == null && localConnect)
                        {
                            MsSQL.UpdateData("UPDATE users SET online=1 WHERE userid='" + reader.GetInt32(0) + "'");
                        }
                        aPlayer             = new player();
                        aPlayer.AccountName = aID;
                        aPlayer.Password    = aPass; // Nukei: ?? whats the reason for saving password in memory ?
                        aPlayer.ID          = reader.GetInt32(0);
                        aPlayer.pGold       = reader.GetInt64(7);
                        aPlayer.Silk        = reader.GetInt32(6);
                        aPlayer.SilkPrem    = reader.GetInt32(9);
                        aPlayer.wSlots      = reader.GetByte(11);
                        ms.Close();
                        //Console.WriteLine("Login..!!");
                        return(0);
                    }
                }
            }
            ms.Close();
            return(1); // not found
        }
Exemple #3
0
        /////////////////////////////////////////////////////////////////////////////////
        // Get Max Slots
        /////////////////////////////////////////////////////////////////////////////////
        public byte GetFreeSlotMax()
        {
            #region Get Max Slots Available
            List <byte> ListSlot = new List <byte>(Character.Information.Slots);
            DB          ms       = new DB("SELECT * FROM char_items WHERE owner='" + Character.Information.CharacterID + "' AND slot >= '13' AND slot <= '" + Character.Information.Slots + "' AND inavatar='0'");
            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    ListSlot.Add(reader.GetByte(5));
                }
            }
            ms.Close();
            byte add = 0;
            for (byte i = 13; i < Character.Information.Slots; i++)
            {
                if (!GetCheckFreeSlot(ListSlot, i))
                {
                    add++;
                }
            }
            return(add);

            #endregion
        }
Exemple #4
0
        public static byte[] PrivateMessageCheck(WorldMgr.character c)
        {
            DB           ms     = new DB("SELECT * FROM message WHERE receiver='" + c.Information.Name + "'");
            PacketWriter Writer = new PacketWriter();
            int          count  = ms.Count();

            Writer.Create(OperationCode.SERVER_PM_MESSAGE);
            Writer.Byte(1);                     //Static
            Writer.Byte(Convert.ToByte(count)); //Total count
            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    string   pmfrom    = reader.GetString(1);
                    string   pmto      = reader.GetString(2);
                    string   pmmessage = reader.GetString(3);
                    byte     pmstatus  = reader.GetByte(4);
                    DateTime pmdate    = Convert.ToDateTime(reader.GetDateTime(5));

                    Writer.Text(pmfrom);            // Message From
                    Writer.DWord(0x8A070000);       // date
                    Writer.DWord(0xC7058401);       // date
                    Writer.Byte(pmstatus);          // Status (0 = Unread) (1 = Read)
                }
                ms.Close();
            }
            return(Writer.GetBytes());
        }
Exemple #5
0
        public static void PrivateItemPacket(PacketWriter Writer, int id, byte max, byte avatar, bool mspawn)
        {
            try
            {
                List <byte> slots = new List <byte>();
                DB          ms    = new DB("SELECT * FROM char_items WHERE owner='" + id + "' AND slot >= '0' AND slot <= '" + max + "' AND inavatar='" + avatar + "' AND storagetype='0' AND quantity='1'");
                using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                {
                    int count = ms.Count();

                    Writer.Byte(count);

                    while (reader.Read())
                    {
                        byte slot      = reader.GetByte(5);
                        byte plusvalue = reader.GetByte(4);
                        int  itemid    = reader.GetInt32(2);

                        if (itemid != 0)
                        {
                            if (!slots.Exists(delegate(byte bk)
                            {
                                return(bk == slot);
                            }))
                            {
                                slots.Add(slot);
                            }
                            Writer.DWord(itemid);
                            Writer.Byte(plusvalue);
                        }
                    }
                }
                ms.Close();
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
Exemple #6
0
        /////////////////////////////////////////////////////////////////////////////////
        // Get Slot Item Information
        /////////////////////////////////////////////////////////////////////////////////
        static Global.slotItem GetItem(uint id, byte slot, int type)
        {
            #region Slot item info

            try
            {
                if (id != 0)
                {
                    Global.slotItem slotItem = new Global.slotItem();
                    int             row      = type;

                    MsSQL ms;
                    if (row == 1)
                    {
                        ms = new MsSQL("SELECT * FROM char_items WHERE itemnumber='item" + slot + "' AND storageacc='" + id + "' AND storagetype='" + row + "' AND slot='" + slot + "'");
                    }
                    else if (row == 3)
                    {
                        ms = new MsSQL("SELECT * FROM char_items WHERE itemnumber='item" + slot + "' AND storagetype='" + row + "' AND slot='" + slot + "'");
                    }
                    else
                    {
                        ms = new MsSQL("SELECT * FROM char_items WHERE itemnumber='item" + slot + "' AND owner='" + id + "' AND storagetype='" + row + "' AND slot='" + slot + "'");
                    }

                    using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                    {
                        while (reader.Read())
                        {
                            slotItem.dbID       = reader.GetInt32(0);
                            slotItem.ID         = reader.GetInt32(2);
                            slotItem.PlusValue  = reader.GetByte(4);
                            slotItem.Amount     = reader.GetInt16(6);
                            slotItem.Durability = reader.GetInt32(7);
                            slotItem.Slot       = slot;
                            LoadBluesid(slotItem.dbID);
                        }
                    }
                    ms.Close();
                    return(slotItem);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Data item load error {0}", ex);
                Systems.Debugger.Write(ex);
            }
            return(null);

            #endregion
        }
        ///////////////////////////////////////////////////////////////////////////
        // Grab pet information packet
        ///////////////////////////////////////////////////////////////////////////
        public static byte[] Pet_Information_grab(CLGameServer.WorldMgr.pet_obj o, byte slot)
        {
            PacketWriter Writer = new PacketWriter();

            Writer.Create(OperationCode.SERVER_PET_INFORMATION);
            try
            {
                //////////////////////////////////////////////////////////////////////////////////////
                // Grabpet structure
                //////////////////////////////////////////////////////////////////////////////////////
                Writer.DWord(o.UniqueID);                   //Unique ID
                Writer.DWord(o.Model);                      //Pet Model
                Writer.DWord(0x00006D);                     //Settings
                Writer.DWord(0x00006D);                     //Settings
                Writer.DWord(0x000047);                     //Settings 0x47 grab pet active 0 disabled
                if (o.Petname != "No name")                 //###############
                {
                    Writer.Text(o.Petname);                 // Name region
                }
                else                                        //
                {
                    Writer.Word(0);                         //###############
                }
                Writer.Byte(o.Slots);                       //Slots count inventory pet
                //////////////////////////////////////////////////////////////////////////////////////
                // Grabpet item inventory
                //////////////////////////////////////////////////////////////////////////////////////
                DB ms = new DB("SELECT * FROM char_items WHERE owner='" + o.OwnerID + "' AND pet_storage_id='" + o.UniqueID + "'");
                Writer.Byte(ms.Count());
                using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                {
                    while (reader.Read())
                    {
                        Item.AddItemPacket(Writer, reader.GetByte(5), reader.GetInt32(2), reader.GetByte(4), reader.GetInt16(6), reader.GetInt32(7), reader.GetInt32(0), reader.GetInt32(9), reader.GetInt32(30));
                    }
                }
                ms.Close();
                //////////////////////////////////////////////////////////////////////////////////////
                // Other
                //////////////////////////////////////////////////////////////////////////////////////
                Writer.DWord(o.OwnerID);                    //Character ID
                Writer.Byte(slot);                          //Slot location of the pet
                //////////////////////////////////////////////////////////////////////////////////////
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            return(Writer.GetBytes());
        }
Exemple #8
0
        public static byte GetAmmoSlot(WorldMgr.character ch)
        {
            DB   ms   = new DB("SELECT * FROM char_items WHERE owner='" + ch.Information.CharacterID + "' AND (itemid='62' OR itemid='3655' OR itemid='10376' OR itemid='10727')");
            byte ammo = 0;

            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    ammo = reader.GetByte(5);
                }
                ms.Close();
                return(Convert.ToByte(ammo));
            }
        }
Exemple #9
0
        /////////////////////////////////////////////////////////////////////////////////
        // Get player inventory items (We will use this for stacking and checking).
        // So herer's the simple one ive made we can use to check player inventory
        /////////////////////////////////////////////////////////////////////////////////
        public static List <byte> GetPlayerItems(WorldMgr.character c)
        {
            List <byte> items = new List <byte>();
            DB          ms    = new DB("SELECT * FROM char_items WHERE owner='" + c.Information.CharacterID + "'");

            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    items.Add(reader.GetByte(5));
                }
            }
            ms.Close();
            return(items);
        }
        public static byte[] OpenWarehouse2(byte storageslots, WorldMgr.player c)
        {
            PacketWriter Writer = new PacketWriter();

            Writer.Create(OperationCode.SERVER_OPEN_WAREPROB);
            Writer.Byte(storageslots);

            DB ms = new DB("SELECT * FROM char_items WHERE storageacc='" + c.ID + "' AND storagetype='1'");

            Writer.Byte(ms.Count());
            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    Item.AddItemPacket(Writer, reader.GetByte(5), reader.GetInt32(2), reader.GetByte(4), reader.GetInt16(6), reader.GetInt32(7), reader.GetInt32(0), reader.GetInt32(9), reader.GetInt32(30));
                }
            }
            ms.Close();
            return(Writer.GetBytes());
        }
Exemple #11
0
        /////////////////////////////////////////////////////////////////////////////////
        // Arrow Item Check
        /////////////////////////////////////////////////////////////////////////////////
        bool ItemCheckArrow()
        {
            #region Check Arrow
            DB ms = new DB("SELECT * FROM char_items WHERE owner='" + Character.Information.CharacterID + "' AND slot >= '13' AND slot <= '" + Character.Information.Slots + "' AND inavatar='0' AND itemid='62' AND storagetype='0'");
            if (ms.Count() == 0)
            {
                ms = new DB("SELECT * FROM char_items WHERE owner='" + Character.Information.CharacterID + "' AND slot >= '13' AND slot <= '" + Character.Information.Slots + "' AND inavatar='0' AND itemid='3823' AND storagetype='0'");
            }
            else if (ms.Count() == 0)
            {
                ms = new DB("SELECT * FROM char_items WHERE owner='" + Character.Information.CharacterID + "' AND slot >= '13' AND slot <= '" + Character.Information.Slots + "' AND inavatar='0' AND itemid='10302' AND storagetype='0'");
            }
            else if (ms.Count() == 0)
            {
                ms = new DB("SELECT * FROM char_items WHERE owner='" + Character.Information.CharacterID + "' AND slot >= '13' AND slot <= '" + Character.Information.Slots + "' AND inavatar='0' AND itemid='10487' AND storagetype='0'");
            }
            if (ms.Count() == 0)
            {
                return(false);
            }
            else
            {
                ObjData.slotItem items = null;
                using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                {
                    while (reader.Read())
                    {
                        items = ConvertToItem(reader.GetInt32(2), reader.GetByte(5), reader.GetInt16(6), 1);
                    }
                }
                ms.Close();
                DB.query("UPDATE char_items SET itemnumber='item" + 7 + "',slot='" + 7 + "' WHERE itemnumber='" + "item" + items.Slot + "' AND owner='" + Character.Information.CharacterID + "' AND itemid='" + items.ID + "'");
                client.Send(Packet.MoveItem(0, items.Slot, 7, items.Amount, 0, "MOVE_INSIDE_INVENTORY"));

                Character.Information.Item.sAmount = items.Amount;
                Character.Information.Item.sID     = items.ID;
                ;
                return(true);
            }
            #endregion
        }
Exemple #12
0
        public static byte[] GuildStorageData(WorldMgr.character c)
        {
            DB           getstorage = new DB("SELECT * FROM char_items WHERE guild_storage_id='" + c.Network.Guild.Guildid + "' AND storagetype='3'");
            int          itemcount  = getstorage.Count();
            PacketWriter Writer     = new PacketWriter();

            Writer.Create(OperationCode.SERVER_GUILD_STORAGE3);
            Writer.Byte(c.Network.Guild.StorageSlots);
            Writer.Byte(itemcount);
            if (itemcount != 0)
            {
                using (System.Data.SqlClient.SqlDataReader reader = getstorage.Read())
                {
                    while (reader.Read())
                    {
                        Item.AddItemPacket(Writer, reader.GetByte(5), reader.GetInt32(2), reader.GetByte(4), reader.GetInt16(6), reader.GetInt32(7), reader.GetInt32(0), reader.GetInt32(9), reader.GetInt32(30));
                    }
                }
            }
            getstorage.Close();
            return(Writer.GetBytes());
        }
Exemple #13
0
        /////////////////////////////////////////////////////////////////////////////////
        // List free slots in inventory
        /////////////////////////////////////////////////////////////////////////////////
        public byte GetFreeSlot()
        {
            #region List free slots
            List <byte> ListSlot = new List <byte>(Character.Information.Slots);
            MsSQL       ms       = new MsSQL("SELECT * FROM char_items WHERE owner='" + Character.Information.CharacterID + "' AND slot >= '13' AND slot <= '" + Character.Information.Slots + "' AND inavatar='0'");
            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    ListSlot.Add(reader.GetByte(5));
                }
            }
            ms.Close();
            for (byte i = 13; i < Character.Information.Slots; i++)
            {
                if (!GetCheckFreeSlot(ListSlot, i))
                {
                    return(i);
                }
            }
            return(0);

            #endregion
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Character listening packet
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static byte[] CharacterListing(string name)
        {
            DB           ms     = new DB("SELECT TOP 4 * FROM character WHERE account='" + name + "'");
            PacketWriter Writer = new PacketWriter();

            Writer.Create(OperationCode.SERVER_CHARACTERSCREEN); // Select opcode
            Writer.Byte(2);                                      // Static byte 2
            Writer.Byte(1);                                      // Static byte 1
            Writer.Byte(ms.Count());                             // Byte WorldMgr.character count

            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                while (reader.Read())
                {
                    Writer.DWord(reader.GetInt32(3));           // DWord Skin Model
                    Writer.Text(reader.GetString(2));           // String Name

                    Writer.Byte(reader.GetByte(4));             // Byte Skin Volume
                    Writer.Byte(reader.GetByte(5));             // Byte Level

                    Writer.LWord(reader.GetInt64(12));          // Long Experience

                    Writer.Word(reader.GetInt16(6));            // Word STR
                    Writer.Word(reader.GetInt16(7));            // Word INT
                    Writer.Word(reader.GetInt16(8));            // Attribute points

                    Writer.DWord(reader.GetInt32(9));           // HP
                    Writer.DWord(reader.GetInt32(10));          // MP

                    TimeSpan ts   = Convert.ToDateTime(reader.GetDateTime(43)) - DateTime.Now;
                    double   time = ts.TotalMinutes;

                    if (Math.Round(time) > 0)
                    {
                        Writer.Byte(1);
                        Writer.DWord(Math.Round(time));
                    }
                    else
                    {
                        Writer.Byte(0);
                    }

                    if (Math.Round(time) < 0 && DateTime.Now != reader.GetDateTime(43))
                    {
                        DB.query("UPDATE character SET deleted='1' Where id='" + reader.GetInt32(0) + "'");
                    }

                    Writer.Word(0);
                    Writer.Byte(0);

                    Function.Items.PrivateItemPacket(Writer, reader.GetInt32(0), 8, 0, false);
                    Function.Items.PrivateItemPacket(Writer, reader.GetInt32(0), 5, 1, false);
                }
                //Jobtype information
                byte jobinfo = Convert.ToByte(DB.GetData("SELECT * FROM users WHERE id='" + name + "'", "jobtype"));
                Writer.Byte(jobinfo);
            }
            ms.Close();

            return(Writer.GetBytes());
        }
        public void LoadPlayerGuildInfo(bool logon)
        {
            try
            {
                DB ms = new DB("SELECT * FROM guild_members WHERE guild_member_id='" + Character.Information.CharacterID + "'");
                using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                {
                    while (reader.Read())
                    {
                        Character.Network.Guild.Guildid           = reader.GetInt32(1);
                        Character.Network.Guild.GrantName         = reader.GetString(5);
                        Character.Network.Guild.FWrank            = reader.GetByte(6);
                        Character.Network.Guild.DonateGP          = reader.GetInt32(4);
                        Character.Network.Guild.LastDonate        = Character.Network.Guild.DonateGP;
                        Character.Network.Guild.joinRight         = (reader.GetByte(7) == 1);
                        Character.Network.Guild.withdrawRight     = (reader.GetByte(8) == 1);
                        Character.Network.Guild.unionRight        = (reader.GetByte(9) == 1);
                        Character.Network.Guild.guildstorageRight = (reader.GetByte(10) == 1);
                        Character.Network.Guild.noticeeditRight   = (reader.GetByte(11) == 1);
                    }
                }

                ms = new DB("SELECT * FROM guild WHERE id='" + Character.Network.Guild.Guildid + "'");
                using (System.Data.SqlClient.SqlDataReader reader2 = ms.Read())
                {
                    while (reader2.Read())
                    {
                        Character.Network.Guild.Name         = reader2.GetString(1);
                        Character.Network.Guild.Level        = reader2.GetByte(2);
                        Character.Network.Guild.PointsTotal  = reader2.GetInt32(3);
                        Character.Network.Guild.NewsTitle    = reader2.GetString(4);
                        Character.Network.Guild.NewsMessage  = reader2.GetString(5);
                        Character.Network.Guild.StorageSlots = reader2.GetInt32(7);
                        Character.Network.Guild.Wargold      = reader2.GetInt32(8);
                        Character.Network.Guild.StorageGold  = reader2.GetInt64(11);
                        Character.Network.Guild.GuildOwner   = reader2.GetInt32(9);
                    }
                }

                ms = new DB("SELECT * FROM guild_members WHERE guild_id='" + Character.Network.Guild.Guildid + "'");
                Character.Network.Guild.TotalMembers = Convert.ToByte(ms.Count());

                ms.Close();
                //Set max players allowed in guild
                switch (Character.Network.Guild.Level)
                {
                case 1:
                    Character.Network.Guild.MaxMembers = 20;
                    break;

                case 2:
                    Character.Network.Guild.MaxMembers = 25;
                    break;

                case 3:
                    Character.Network.Guild.MaxMembers = 30;
                    break;

                case 4:
                    Character.Network.Guild.MaxMembers = 35;
                    break;

                case 5:
                    Character.Network.Guild.MaxMembers = 50;
                    break;
                }

                //Only load on player login
                if (logon)
                {
                    LoadGuildMembers();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("LoadPlayerGuildInfo error {0}", ex);
            }
        }
Exemple #16
0
        public TList_Colunasbd Select(TpBusca[] vBusca, Int32 vTop, string vNM_Campo, string vOrder)
        {
            TList_Colunasbd lista = new TList_Colunasbd();

            System.Data.SqlClient.SqlDataReader reader = null;
            bool   podeFecharBco = false;
            string pk = string.Empty, fk = string.Empty, lgm = string.Empty, lgr = string.Empty;
            int    tamanho = 0;

            if (Banco_Dados == null)
            {
                podeFecharBco = this.CriarBanco_Dados(false);
            }
            try
            {
                reader = this.ExecutarBusca(this.SqlCodeBusca(vBusca, Convert.ToInt16(vTop), vNM_Campo, vOrder));

                while (reader.Read())
                {
                    TRegistro_Columnsbd reg = new TRegistro_Columnsbd();
                    if (!(reader.IsDBNull(reader.GetOrdinal("COLUMN_NAME"))))
                    {
                        reg.nome_coluna = reader.GetString(reader.GetOrdinal("COLUMN_NAME"));
                    }
                    if (!(reader.IsDBNull(reader.GetOrdinal("PK"))) || !(reader.IsDBNull(reader.GetOrdinal("FK"))))
                    {
                        pk = reader.GetString(reader.GetOrdinal("PK"));
                        fk = reader.GetString(reader.GetOrdinal("FK"));
                        if (pk == fk && !pk.Equals("0") && !fk.Equals("0"))
                        {
                            reg.chave = "PFK";
                        }
                        else if (!pk.Equals("0"))
                        {
                            reg.chave = "PK";
                        }
                        else if (!fk.Equals("0"))
                        {
                            reg.chave = "FK";
                        }
                    }
                    if (!(reader.IsDBNull(reader.GetOrdinal("data_type"))))
                    {
                        reg.tipo = reader.GetString(reader.GetOrdinal("data_type"));
                    }
                    if (!(reader.IsDBNull(reader.GetOrdinal("length"))) || !(reader.IsDBNull(reader.GetOrdinal("numeric_precision"))) ||
                        !(reader.IsDBNull(reader.GetOrdinal("numeric_scale"))))
                    {
                        tamanho = reader.GetInt32(reader.GetOrdinal("length"));
                        lgm     = reader.GetByte(reader.GetOrdinal("numeric_precision")).ToString();
                        lgr     = reader.GetInt32(reader.GetOrdinal("numeric_scale")).ToString();
                        if (!string.IsNullOrEmpty(lgm.ToString()) && !lgm.Equals("0") && !string.IsNullOrEmpty(lgr.ToString()))
                        {
                            reg.tamanho = "(" + lgm + "," + lgr + ")";
                        }
                        else if (!string.IsNullOrEmpty(tamanho.ToString()) && !tamanho.Equals("0"))
                        {
                            reg.tamanho = "(" + tamanho + ")";
                        }
                    }
                    if (reg.tipo.Equals("varchar") || reg.tipo.Equals("char") || reg.tipo.Equals("image") || reg.tipo.Equals("numeric") || reg.tipo.Equals("decimal") || reg.tipo.Equals("datetime") || reg.tipo.Equals("int"))
                    {
                        lista.Add(reg);
                    }
                }
            }
            finally
            {
                reader.Close();
                reader.Dispose();
                if (podeFecharBco)
                {
                    this.deletarBanco_Dados();
                }
            }
            return(lista);
        }
 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
     }
 }
Exemple #18
0
        public static void ExecuteCommand(string aCommand, Socket aSocket)
        {
            try
            {
                if (aCommand != null)
                {
                    string[] command = aCommand.Split(' ');
                    if (command[0] == "/help")
                    {
                        if (aSocket == null)
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.WriteLine("                     Ingame notice: Type 1 space then message.");
                            Console.WriteLine("                     //clear");
                            Console.WriteLine("                     //repairitems");
                            Console.WriteLine("                     //respawn_unique");
                            Console.WriteLine("                     //event");
                            Console.WriteLine("                     //shutdown");
                            Console.WriteLine("                     //manager");

                            Console.ForegroundColor = ConsoleColor.Yellow;
                        }
                        else
                        {
                            sendSocket(aSocket, "Ingame notice: Type 1 space then message." + Environment.NewLine);
                            sendSocket(aSocket, "  //clear = cleanup unused memory" + Environment.NewLine);
                            sendSocket(aSocket, "  //repairitems" + Environment.NewLine);
                            sendSocket(aSocket, "  //respawn_unique" + Environment.NewLine);
                            sendSocket(aSocket, "  //event" + Environment.NewLine);
                            sendSocket(aSocket, "  //shutdown" + Environment.NewLine);
                        }
                    }
                    else if (command[0] == "//clear")
                    {
                        System.GC.Collect();
                        GC.Collect(0, GCCollectionMode.Forced);
                        sendSocket(aSocket, "done memory cleanup" + Environment.NewLine);
                    }
                    else if (command[0] == "//shutdown")
                    {
                        byte waitTime = 5;
                        if (command.Length > 1)
                        {
                            waitTime = System.Convert.ToByte(command[1]);
                        }
                        if (aSocket != null)
                        {
                            aSocket.Send(Encoding.ASCII.GetBytes("SHUTDOWN_START" + Environment.NewLine));
                        }

                        lock (Systems.clients)
                        {
                            Console.WriteLine("{0}stopping server and sending notice to clients ...", DarkEmu_GameServer.Global.Product.Prefix);
                            sendSocket(aSocket, "SHUTDOWN: stopping server and sending notice to clients ..." + Environment.NewLine);
                            net.ServerCheck(true);
                            net.Stop();  // disable any new connection
                            try
                            {
                                Systems.SendAll(Packet.ChatPacket(7, 0, "The server is stopping, your information will be saved.", ""));
                                Systems.SendAll(Packet.StartingLeaveGame(waitTime, 0));
                            }
                            catch { }
                            Thread.Sleep(waitTime);
                            Console.WriteLine("@SHUTDOWN: logoff clients ...");
                            sendSocket(aSocket, "@SHUTDOWN: logoff clients ..." + Environment.NewLine);
                            while (Systems.clients.Count > 0)
                            {
                                try
                                {
                                    try
                                    {
                                        Systems.clients[0].Send(Packet.EndLeaveGame());
                                    }
                                    catch { }
                                    //Ignore new character case (used for disconnect kick).
                                    Systems c = new Systems();
                                    Systems.clients[0].Disconnect("normal");
                                }
                                catch { }
                            }
                        }
                        sendSocket(aSocket, "SHUTDOWN_END" + Environment.NewLine);
                        cancelServer = true;
                        Systems.UpdateServerInfo(0);
                        //Environment.Exit(0);
                    }
                    else if (command[0] == "//repairitems")
                    {
                        int           fixeditem = 0;
                        Systems.MsSQL ms        = new Systems.MsSQL("SELECT * FROM char_items");
                        using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
                        {
                            while (reader.Read())
                            {
                                short amount = reader.GetInt16(7);
                                if (amount < 1)
                                {
                                    fixeditem++;
                                    amount = 1;
                                    Systems.MsSQL.InsertData("UPDATE char_items SET quantity='" + amount + "' WHERE itemnumber='" + "item" + reader.GetByte(5) + "' AND owner='" + reader.GetInt32(3) + "' AND itemid='" + reader.GetInt32(2) + "'");
                                }
                            }
                        }
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("@Gameserver:         Items Repaired:           {0}", fixeditem);
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        sendSocket(aSocket, String.Format("@Gameserver: Items Repaired: {0}", fixeditem) + Environment.NewLine);
                    }
                    else if (command[0] == "//respawn_unique")
                    {
                        DarkEmu_GameServer.GlobalUnique.StartTGUnique(6000 * 10, 6000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartUriUnique(7000 * 10, 7000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartIsyUnique(8000 * 10, 8000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartLordUnique(9000 * 10, 9000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartDemonUnique(10000 * 10, 10000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartCerbUnique(11000 * 10, 11000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartIvyUnique(11000 * 10, 11000 * 10);
                        //Game.GlobalUnique.StartRoc(11000 * 10, 11000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartMedusa(11000 * 10, 11000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartNeith(11000 * 10, 11000 * 10);
                        //Game.GlobalUnique.StartSphinx(11000 * 10, 11000 * 10);
                        DarkEmu_GameServer.GlobalUnique.StartIsis(11000 * 10, 11000 * 10);
                        sendSocket(aSocket, "done respawn" + Environment.NewLine);
                    }
                    else if (command[0] == "//event")
                    {
                        EventMain eventnew = new EventMain(System.IO.Directory.GetCurrentDirectory() + "/data/event.txt");
                        eventnew.Start();
                        sendSocket(aSocket, "Event Started" + Environment.NewLine);
                    }
                    else if (command[0] == "")
                    {
                        string information           = aCommand;
                        DarkEmu_GameServer.Systems c = new DarkEmu_GameServer.Systems();
                        DarkEmu_GameServer.Systems.SendAll(c.sendnoticecon(7, 0, information, ""));

                        Console.WriteLine("Notice: " + information);
                        sendSocket(aSocket, "Sent Notice: " + information + Environment.NewLine);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Program.Main {0}", ex);
            }
        }
Exemple #19
0
        public static byte[] UnionInfo(PlayerMgr c)
        {
            PacketWriter Writer = new PacketWriter();

            Writer.Create(OperationCode.SERVER_GUILD_UNIONS);
            Writer.DWord(c.Character.Information.CharacterID);                // Union owner id
            Writer.DWord(7);                                                  // ??Need to check
            Writer.DWord(c.Character.Network.Guild.Guildid);                  // Union leader guild id
            Writer.Byte(c.Character.Network.Guild.Unions.Count);              // Count guilds in union
            //Get all guilds details
            foreach (int guild in c.Character.Network.Guild.Unions)
            {
                //Load other guild data
                DB guild_data = new DB("SELECT * FROM guild WHERE id='" + guild + "'");

                using (System.Data.SqlClient.SqlDataReader reader = guild_data.Read())
                {
                    while (reader.Read())
                    {
                        string Guildname        = reader.GetString(1);
                        byte   Guildlevel       = reader.GetByte(2);
                        byte   Guildmembercount = reader.GetByte(6);
                        int    Ownerid          = reader.GetInt32(9);

                        string Charname  = DB.GetData("SELECT name FROM character WHERE id='" + Ownerid + "'", "name").ToString();
                        int    Charmodel = Convert.ToInt32(DB.GetData("SELECT chartype FROM character WHERE id='" + Ownerid + "'", "chartype"));

                        Writer.DWord(guild);                        //Guild ID
                        Writer.Text(reader.GetString(1));           //Guildname
                        Writer.Byte(reader.GetByte(2));             //Guildlevel
                        Writer.Text(Charname);                      //Ownername
                        Writer.DWord(Charmodel);                    //Owner model
                        Writer.Byte(reader.GetByte(6));             //Guild member count

                        //Get guild details
                        PlayerMgr Guildmembers = Helpers.GetInformation.GetGuildPlayer(guild);
                        //Add clients that are online to union list
                        //Null check
                        if (Guildmembers != null)
                        {
                            foreach (int member in Guildmembers.Character.Network.Guild.Members)
                            {
                                //make sure member isnt 0
                                if (member != 0)
                                {
                                    //Get player details
                                    PlayerMgr getmember = Helpers.GetInformation.GetPlayerMainid(member);
                                    //Make sure that the player is there
                                    if (getmember != null)
                                    {
                                        //Add client to union list
                                        c.Character.Network.Guild.UnionMembers.Add(getmember.Character.Information.CharacterID);
                                        //Add to member
                                        if (c.Character.Information.CharacterID != getmember.Character.Information.CharacterID)
                                        {
                                            getmember.Character.Network.Guild.UnionMembers.Add(c.Character.Information.CharacterID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(Writer.GetBytes());
        }
        public static byte[] CharacterDataLoad(WorldMgr.character c)
        {
            PacketWriter Writer = new PacketWriter();

            Writer.Create(OperationCode.SERVER_PLAYERDATA);
            /////////////////////////////////////////////////////// Character basic info
            #region Basic info
            Writer.DWord(c.Ids.GetLoginID);
            Writer.DWord(c.Information.Model);
            Writer.Byte(c.Information.Volume);
            Writer.Byte(c.Information.Level);
            Writer.Byte(c.Information.Level);
            Writer.LWord(c.Information.XP);
            Writer.DWord(c.Information.SpBar);
            Writer.LWord(c.Information.Gold);
            Writer.DWord(c.Information.SkillPoint);
            Writer.Word(c.Information.Attributes);
            Writer.Byte(c.Information.BerserkBar);
            Writer.DWord(988);
            Writer.DWord(c.Stat.SecondHp);
            Writer.DWord(c.Stat.SecondMP);
            Writer.Bool(c.Information.Level < 20 ? true : false);
            #endregion
            /////////////////////////////////////////////////////// Character Player Kill Info
            #region Pk information
            //DB perfection reading with multiple data adapters... while this one is open i can still read anything else from the database
            //With no speed reduction...
            DB checkpk = new DB("SELECT * FROM character WHERE name ='" + c.Information.Name + "'");
            using (System.Data.SqlClient.SqlDataReader getinfo = checkpk.Read())
            {
                while (getinfo.Read())
                {
                    byte dailypk     = getinfo.GetByte(48);
                    byte pklevel     = getinfo.GetByte(49);
                    byte murderlevel = getinfo.GetByte(50);

                    Writer.Byte(dailypk);
                    Writer.Word(pklevel);
                    Writer.DWord(murderlevel);
                    if (murderlevel != 0)
                    {
                        c.Information.Murderer = true;
                    }
                }
            }
            #endregion
            /////////////////////////////////////////////////////// Character Title
            #region Title
            Writer.Byte(c.Information.Title);
            #endregion
            /////////////////////////////////////////////////////// Character Pvpstate
            #region Pvp
            Writer.Byte(c.Information.Pvpstate);
            if (c.Information.Pvpstate > 0)
            {
                c.Information.PvP = true;
            }
            #endregion
            /////////////////////////////////////////////////////// Character Items
            #region Item

            Writer.Byte(c.Information.Slots);

            DB ms = new DB("SELECT * FROM char_items WHERE owner='" + c.Information.CharacterID + "' AND slot >= '0' AND slot <= '" + c.Information.Slots + "' AND inavatar='0' AND storagetype='0'");
            Writer.Byte(ms.Count());
            using (System.Data.SqlClient.SqlDataReader msreader = ms.Read())
            {
                while (msreader.Read())
                {
                    short amount = msreader.GetInt16(6);

                    if (amount < 1)
                    {
                        amount = 1;
                    }
                    DB.query("UPDATE char_items SET quantity='" + amount + "' WHERE owner='" + c.Information.CharacterID + "' AND itemid='" + msreader.GetInt32(2) + "' AND id='" + msreader.GetInt32(0) + "' AND storagetype='0'");

                    if (msreader.GetByte(5) == 6)
                    {
                        c.Information.Item.wID = Convert.ToInt32(msreader.GetInt32(2));
                    }
                    if (msreader.GetByte(5) == 7)
                    {
                        c.Information.Item.sID     = msreader.GetInt32(2);
                        c.Information.Item.sAmount = msreader.GetInt16(6);
                    }

                    Item.AddItemPacket(Writer, msreader.GetByte(5), msreader.GetInt32(2), msreader.GetByte(4), amount, msreader.GetInt32(7), msreader.GetInt32(0), msreader.GetInt32(9), msreader.GetInt32(30));
                }
            }
            ms.Close();

            //Avatar
            Writer.Byte(5);

            ms = new DB("SELECT * FROM char_items WHERE owner='" + c.Information.CharacterID + "' AND slot >= '0' AND slot <= '" + c.Information.Slots + "' AND inavatar='1' AND storagetype='0'");

            Writer.Byte(ms.Count());
            using (System.Data.SqlClient.SqlDataReader msreader = ms.Read())
            {
                while (msreader.Read())
                {
                    Item.AddItemPacket(Writer, msreader.GetByte(5), msreader.GetInt32(2), msreader.GetByte(4), msreader.GetInt16(6), msreader.GetInt32(7), msreader.GetInt32(0), msreader.GetInt32(9), msreader.GetInt32(30));
                }
            }
            ms.Close();

            Writer.Byte(0);

            // job mastery
            Writer.Byte(0x0B);
            Writer.Byte(0);
            Writer.Byte(0);

            #endregion
            ///////////////////////////////////////////////////////  Mastery
            #region Mastery
            if (c.Information.Model <= 12000)
            {
                for (byte i = 1; i <= 7; i++)
                {
                    Writer.Byte(1);
                    Writer.DWord(c.Stat.Skill.Mastery[i]);
                    Writer.Byte(c.Stat.Skill.Mastery_Level[i]);
                }
            }
            else
            {
                if (c.Information.Model >= 14000)
                {
                    for (byte i = 1; i < 7; i++)
                    {
                        Writer.Byte(1);
                        Writer.DWord(c.Stat.Skill.Mastery[i]);
                        Writer.Byte(c.Stat.Skill.Mastery_Level[i]);
                    }
                }
            }
            #endregion
            /////////////////////////////////////////////////////// Skills
            #region Skill
            Writer.Byte(2);
            Writer.Byte(0);
            for (int i = 1; i <= c.Stat.Skill.AmountSkill; i++)
            {
                Writer.Byte(1);
                Writer.DWord(c.Stat.Skill.Skill[i]);
                Writer.Byte(1);
            }
            Writer.Byte(2);
            #endregion
            /////////////////////////////////////////////////////// Quests
            #region Quest
            Writer.Word(1);  // how many Quest ids completed/aborted
            Writer.DWord(1); // Quest id
            Writer.Byte(0);  //number of Quests that are live
            #endregion
            Writer.Byte(0);  //? for now
            /////////////////////////////////////////////////////// Talisman
            #region Talisman
            Writer.DWord(1);    //new
            Writer.DWord(1);    //new
            Writer.DWord(0);    //? for now
            Writer.DWord(0x0C); //new
            #endregion
            /////////////////////////////////////////////////////// Position + id + speed
            #region Character id / Position / Speed
            Writer.DWord(c.Information.UniqueID);
            Writer.Byte(c.Position.xSec);
            Writer.Byte(c.Position.ySec);
            if (!FileDB.CheckCave(c.Position.xSec, c.Position.ySec))
            {
                Writer.Float(Formule.packetx(c.Position.x, c.Position.xSec));
                Writer.Float(c.Position.z);
                Writer.Float(Formule.packety(c.Position.y, c.Position.ySec));
            }
            else
            {
                Writer.Float(Formule.cavepacketx(c.Position.x)); // Added for cave Coords
                Writer.Float(c.Position.z);
                Writer.Float(Formule.cavepackety(c.Position.y)); // Added for cave Coords
            }
            Writer.Word(0);                                      // Angle
            Writer.Byte(0);
            Writer.Byte(1);
            Writer.Byte(0);
            Writer.Word(0);                                                     // Angle
            Writer.Word(0);
            Writer.Byte(0);
            Writer.Bool(false); //berserk

            Writer.Byte(0);     //new ?

            Writer.Float(c.Speed.WalkSpeed);
            Writer.Float(c.Speed.RunSpeed);
            Writer.Float(c.Speed.BerserkSpeed);
            #endregion
            /////////////////////////////////////////////////////// Premium Tickets
            #region Premium ticket
            Writer.Byte(0); //ITEM_MALL_GOLD_TIME_SERVICE_TICKET_4W
            #endregion
            /////////////////////////////////////////////////////// GM Check + Name
            #region GM Check + Name
            Writer.Text(c.Information.Name);
            #endregion
            /////////////////////////////////////////////////////// Character jobs
            #region Character Job / hunter thief trader ( old job things )
            //Writer info with job name when on job

            /*if (c.Job.state == 1 && c.Job.Jobname != "0")
             * {
             *  Writer.Text(c.Job.Jobname);
             *  Writer.Byte(3);
             *  Writer.Byte(1);
             *  Writer.DWord(0);
             *  Writer.DWord(0);
             *  Writer.DWord(0);
             *  Writer.Byte(0);
             *  Writer.Byte(0);
             *  Writer.Byte(0);
             * }
             * //Write basic info noname
             * if (c.Job.Jobname == "0")
             * {
             *  Writer.Word(0);
             *  Writer.Byte(3);
             *  Writer.Byte(1);
             *  Writer.DWord(0);
             *  Writer.DWord(0);
             *  Writer.DWord(0);
             *  Writer.Byte(0);
             *  Writer.Byte(0);
             *  Writer.Byte(0);
             * }
             * //Write no info
             * else
             * {
             *  Writer.Word(0);
             *  Writer.Byte(0);
             *  Writer.Byte(1);
             *  Writer.DWord(0);
             *  Writer.DWord(0);
             *  Writer.DWord(0);
             *  Writer.Byte(0);
             *  Writer.Byte(0);
             *  Writer.Byte(0);
             * }*/
            #endregion
            #region New job system
            if (c.Job.state == 1)
            {
                Writer.Text(c.Job.Jobname);
                Writer.Byte(1);
                Writer.Byte(c.Job.level);         //Level job
                Writer.Byte(c.Information.Level); //Level char
                Writer.Byte(1);                   // job level? myb
                Writer.LWord(0);                  // job exp probably y
                Writer.Byte(0);
                Writer.Byte(0);
                Writer.Byte(0);
                Writer.Byte(0);
            }
            else
            {
                Writer.Word(0);
                Writer.Byte(0);
                Writer.Byte(0);
                Writer.Byte(2);  // job type
                Writer.Byte(1);  // job level? myb
                Writer.LWord(0); // job exp probably y
                Writer.Byte(0);
                Writer.Byte(0);
                Writer.Byte(0);
                Writer.Byte(0);
            }

            #endregion
            /////////////////////////////////////////////////////// Pvp / Pk State
            #region Pvp / Pk State
            if (c.Information.Pvpstate == 1 || c.Information.Murderer)
            {
                Writer.Byte(0x22);
            }
            else if (c.Information.Pvpstate == 0 || !c.Information.Murderer)
            {
                Writer.Byte(0xFF);
            }
            #endregion
            /////////////////////////////////////////////////////// Guide Data
            #region Guide Data this data stacks on itself so if guide id is 0400000000000000 and next guide is 0300000000000000 the data to send is 0700000000000000

            for (int i = 0; i < 8; ++i)         //Main Guide Packet Info
            {
                Writer.Byte(c.Guideinfo.G1[i]); //Reads From Int Array
            }
            #endregion
            /////////////////////////////////////////////////////// Account / Gm Check
            #region Account ID + Gm Check
            Writer.DWord(c.Account.ID);
            Writer.Byte(c.Information.GM);
            #endregion
            /////////////////////////////////////////////////////// Quickbar + Autopotion
            #region Bar information
            Writer.Byte(7);
            PlayerQuickBar(Writer, c.Information.CharacterID);
            PlayerAutoPot(Writer, c.Information.CharacterID);
            #endregion
            /////////////////////////////////////////////////////// Academy
            #region Academy
            Writer.Byte(0); // number of player in academy

            /* // if we have players there
             * Writer.Byte(1);
             * Writer.Text("asd");
             */
            Writer.Byte(0);//added byte today for 1.310
            Writer.Byte(0);
            Writer.Word(1);
            Writer.Word(1);
            Writer.Byte(0);
            Writer.Byte(1);
            #endregion
            return(Writer.GetBytes());
        }
Exemple #21
0
        //Listening main uses a single packet only so we write our packet here
        public static byte[] CharacterListing(player p)
        {
            //Create new sql query to get all characters except fully deleted
            Systems.MsSQL ms = new Systems.MsSQL("SELECT TOP 4 * FROM character WHERE account='" + p.AccountName + "' AND deleted='0' OR account='" + p.AccountName + "' AND deleted ='1'");
            //Create new packet writer
            PacketWriter Writer = new PacketWriter();

            Writer.Create(Systems.SERVER_CHARACTERSCREEN);      // Select opcode
            Writer.Byte(2);                                     // Static byte 2
            Writer.Byte(1);                                     // Static byte 1
            Writer.Byte(ms.Count());                            // Byte Character Count
            //Create new sql data reader
            using (System.Data.SqlClient.SqlDataReader reader = ms.Read())
            {
                //While the reader is reading data from the database
                while (reader.Read())
                {
                    Writer.DWord(reader.GetInt32(3));           // DWord Skin Model
                    Writer.Text(reader.GetString(2));           // String Name
                    Writer.Byte(reader.GetByte(4));             // Byte Skin Volume
                    Writer.Byte(reader.GetByte(5));             // Byte Level
                    Writer.LWord(reader.GetInt64(12));          // Long Experience
                    Writer.Word(reader.GetInt16(6));            // Word STR
                    Writer.Word(reader.GetInt16(7));            // Word INT
                    Writer.Word(reader.GetInt16(8));            // Attribute points
                    Writer.DWord(reader.GetInt32(9));           // HP
                    Writer.DWord(reader.GetInt32(10));          // MP
                    //Set defnition for current time
                    DateTime CurrentTime = DateTime.Now;
                    //Subtract the current time with deletion time information
                    TimeSpan TIMESPAN = reader.GetDateTime(43) - DateTime.Now;
                    //If the character has been deleted but still sitting
                    if (reader.GetByte(42) == 1)
                    {
                        //Write state byte 1 for sitting
                        Writer.Byte(1);
                        //Display deletion time reamining
                        Writer.DWord((double)TIMESPAN.TotalMinutes);
                        //If time has expired delete the character
                        if (TIMESPAN.TotalMinutes <= 0)
                        {
                            //Note: There are more ways like full delete but if someone got deleted by someone else's action
                            //It will be easy to recover the character by changing the deletion byte in the database
                            //0 = Not deleted , 1 = Deletion in progress, 2 = Deleted

                            //Set deletion state so it wont be listed again.
                            Systems.MsSQL.UpdateData("UPDATE character SET deleted='2' Where id='" + reader.GetInt32(0) + "'");
                        }
                    }
                    //If not deleted
                    else
                    {
                        //State byte = 0 Standing
                        Writer.Byte(0);
                    }
                    //Static
                    Writer.Word(0);
                    Writer.Byte(0);
                    //Get normal equipped items upto slot 8 not in avatar slots
                    Function.Items.PrivateItemPacket(Writer, reader.GetInt32(0), 8, 0, false);
                    //Get avatar type items
                    Function.Items.PrivateItemPacket(Writer, reader.GetInt32(0), 5, 1, false);
                }
                //Jobtype information
                int jobinfo = Systems.MsSQL.GetDataInt("SELECT * FROM users WHERE id='" + p.AccountName + "'", "jobtype");
                Writer.Byte(Convert.ToByte(jobinfo));
            }
            ms.Close();
            //Return all bytes to the client
            return(Writer.GetBytes());
        }