Ejemplo n.º 1
0
        public GuildMember(Guild Guild, MySqlDataReader reader)
        {
            this.Guild = Guild;

            CharacterID = reader.GetInt32(1);
            Rank        = (GuildRank)reader.GetByte(2);
            Corp        = (ushort)reader.GetInt16(3);
        }
        public static Vehicle Spawn(MySqlDataReader r)
        {
            string numberPlate = "TEST";
            byte   alpha       = 255;
            bool   engine      = r.GetBoolean("engine");
            int    c           = r.GetInt32("c");
            int    s           = r.GetInt32("s");

            Vehicle veh = NAPI.Vehicle.CreateVehicle(
                r.GetUInt32("hash"),
                new Vector3(r.GetFloat("p_x"), r.GetFloat("p_y"), r.GetFloat("p_z")),
                r.GetFloat("r"),
                c,
                s,
                numberPlate,
                alpha,
                r.GetBoolean("locked"),
                engine,
                r.GetUInt32("dim")
                );

            if (c == 0 && s == 0)
            {
                veh.CustomPrimaryColor   = new Color(r.GetByte("c_r"), r.GetByte("c_g"), r.GetByte("c_b"));
                veh.CustomSecondaryColor = new Color(r.GetByte("s_r"), r.GetByte("s_g"), r.GetByte("s_b"));
            }

            veh.SetData("id", r.GetInt32("id"));
            veh.SetData("hp", r.GetFloat("hp"));

            veh.SetData("owner", r.GetInt32("character_id"));

            veh.SetData("multi", r.GetInt32("multi"));

            veh.SetData("km", r.GetFloat("km"));
            veh.SetData("fuel", r.GetFloat("fuel"));
            veh.SetData("fuelTank", r.GetFloat("fuel_tank"));
            veh.SetData("fuelConsumption", r.GetFloat("fuel_consumption"));

            veh.SetData("engine", engine);

            veh.SetData("lastUsed", r.GetDateTime("last_used"));
            veh.SetData("lastDriver", -1);

            return(veh);
        }
Ejemplo n.º 3
0
 public override byte GetByte(int ordinal)
 {
     if (types[ordinal].ClrEquivalentType != reader.GetFieldType(ordinal))
     {
         return((byte)GetValue(ordinal));
     }
     return(reader.GetByte(ordinal));
 }
Ejemplo n.º 4
0
 public Car(MySqlDataReader reader)
 {
     //  `Id`, `model`,  `number`, `color`, `type`
     ID     = reader.GetUInt32(0);
     Model  = reader.GetString(1);
     Number = reader.GetString(2);
     Type   = (TaxiType)reader.GetByte(3);
 }
 private bool ReadCharacter(MySqlDataReader reader, out PlayerCharacterData result)
 {
     if (reader.Read())
     {
         result                 = new PlayerCharacterData();
         result.Id              = reader.GetString(0);
         result.DataId          = reader.GetInt32(1);
         result.EntityId        = reader.GetInt32(2);
         result.FactionId       = reader.GetInt32(3);
         result.CharacterName   = reader.GetString(4);
         result.Level           = reader.GetInt16(5);
         result.Exp             = reader.GetInt32(6);
         result.CurrentHp       = reader.GetInt32(7);
         result.CurrentMp       = reader.GetInt32(8);
         result.CurrentStamina  = reader.GetInt32(9);
         result.CurrentFood     = reader.GetInt32(10);
         result.CurrentWater    = reader.GetInt32(11);
         result.EquipWeaponSet  = reader.GetByte(12);
         result.StatPoint       = reader.GetInt16(13);
         result.SkillPoint      = reader.GetInt16(14);
         result.Gold            = reader.GetInt32(15);
         result.PartyId         = reader.GetInt32(16);
         result.GuildId         = reader.GetInt32(17);
         result.GuildRole       = reader.GetByte(18);
         result.SharedGuildExp  = reader.GetInt32(19);
         result.CurrentMapName  = reader.GetString(20);
         result.CurrentPosition = new Vector3(
             reader.GetFloat(21),
             reader.GetFloat(22),
             reader.GetFloat(23));
         result.CurrentRotation = new Vector3(
             reader.GetFloat(24),
             reader.GetFloat(25),
             reader.GetFloat(26));
         result.RespawnMapName  = reader.GetString(27);
         result.RespawnPosition = new Vector3(
             reader.GetFloat(28),
             reader.GetFloat(29),
             reader.GetFloat(30));
         result.MountDataId = reader.GetInt32(31);
         result.LastUpdate  = (int)(reader.GetDateTime(32).Ticks / System.TimeSpan.TicksPerMillisecond);
         return(true);
     }
     result = null;
     return(false);
 }
Ejemplo n.º 6
0
        public override void Load()
        {
            DatabaseQuery query = new DatabaseQuery(Database.Tables.WORKING_DAYS);

            query.Add(Database.Tables.WorkingDays.StaffId);
            query.Add(Database.Tables.WorkingDays.Sunday);
            query.Add(Database.Tables.WorkingDays.Monday);
            query.Add(Database.Tables.WorkingDays.Tuesday);
            query.Add(Database.Tables.WorkingDays.Wednesday);
            query.Add(Database.Tables.WorkingDays.Thursday);
            query.Add(Database.Tables.WorkingDays.Friday);
            query.Add(Database.Tables.WorkingDays.Saturday);

            MySqlDataReader reader = DoLoad(query);

            if (Loaded)
            {
                Owner     = StaffsManager.GetMedicalStaff(reader.GetInt32(0));
                Sunday    = reader.GetByte(1) > 0 ? true : false;
                Monday    = reader.GetByte(2) > 0 ? true : false;
                Tuesday   = reader.GetByte(3) > 0 ? true : false;
                Wednesday = reader.GetByte(4) > 0 ? true : false;
                Thursday  = reader.GetByte(5) > 0 ? true : false;
                Friday    = reader.GetByte(6) > 0 ? true : false;
                Saturday  = reader.GetByte(7) > 0 ? true : false;
                StaffsManager.Add(this);
            }

            reader.Close();
        }
        public bool Load()
        {
            try
            {
                MySqlCommand    cmd    = new MySqlCommand("SELECT id, code, uses, dinarreward FROM coupons", Databases.Game.connection);
                MySqlDataReader Reader = cmd.ExecuteReader();

                if (Reader.HasRows)
                {
                    while (Reader.Read())
                    {
                        byte   _index       = Reader.GetByte("id");
                        string _code        = Reader.GetString("code");
                        byte   _uses        = Reader.GetByte("uses");
                        uint   _dinarReward = Reader.GetUInt32("dinarreward");

                        Objects.Coupon Coupon = new Objects.Coupon(_index, _code, _uses, _dinarReward);
                        UpdateCouponList(Coupon);
                    }
                }

                Reader.Close();

                if (CouponList.Count > 0)
                {
                    byte _activeCoupons = 0;
                    foreach (var Coupon in CouponList)
                    {
                        if (Coupon.Uses > 0)
                        {
                            _activeCoupons++;
                        }
                    }
                    Log.Instance.WriteLine("Coupon manager found " + _activeCoupons.ToString() + " useable coupons");
                }
                else
                {
                    Log.Instance.WriteError("Coupon list is empty");
                }

                return(true);
            }
            catch { }
            return(false);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Read a byte value in the specified field. Field index starts with 0.
 /// </summary>
 /// <param name="i"></param>
 /// <returns></returns>
 public byte GetByte(int i)
 {
     lastUpdate = MySQL.MSTime;
     if (r.FieldCount > i && !r.IsDBNull(i))
     {
         return(r.GetByte(i));
     }
     return(0);
 }
Ejemplo n.º 9
0
        /// <Sql>
        /// SELECT
        ///     *
        /// FROM
        ///     list_maildata
        /// WHERE
        ///     Sender=?Sender
        /// AND
        ///     IsOutbox=1;
        /// </Sql>
        public IEnumerable <Mail> GetOutboxMail(Character target)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlCommand    command    = new MySqlCommand(_query_37, connection);

            command.Parameters.AddWithValue("Sender", target.Name);
            MySqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    // 0 - MailId
                    // 1 - Sender
                    // 2 - Receiptent
                    // 3 - Date
                    // 4 - IsRead
                    // 5 - IsChecked
                    // 6 - Topic
                    // 7 - Message
                    // 8 - Attachment
                    // 9 - Zeny


                    Mail mailsubject = new Mail();
                    mailsubject.MailId  = reader.GetUInt32(0);
                    mailsubject.Sender  = reader.GetString(1);
                    mailsubject.Time    = reader.GetDateTime(3);
                    mailsubject.IsRead  = reader.GetByte(4);
                    mailsubject.Topic   = reader.GetString(6);
                    mailsubject.Message = reader.GetString(7);
                    mailsubject.Zeny    = (int)reader.GetUInt32(9);


                    if (reader.IsDBNull(8) == false)
                    {
                        byte[] buffer = new byte[67];
                        reader.GetBytes(8, 0, buffer, 0, 67);
                        Rag2Item.Deserialize(out mailsubject.Attachment, buffer, 0);
                    }
                    if (mailsubject.IsRead == 0)
                    {
                        mailsubject.Valid = (byte)(30 - Math.Min(30, (int)((DateTime.Now - mailsubject.Time).TotalDays)));
                    }
                    yield return(mailsubject);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                ConnectionPool.Release(connection);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// get list with preview result data
        /// </summary>
        /// <returns>IEnumerable</returns>
        public IEnumerable <ResultView> GetResultView()
        {
            _resultView = new ObservableCollection <ResultView>();
            ResultViews.Clear();
            try
            {
                _connection.Open();
                MySqlCommand command = _connection.CreateCommand();
                command.CommandText = "SELECT * FROM result_table;";
                EncodingProvider ppp = CodePagesEncodingProvider.Instance;
                Encoding.RegisterProvider(ppp);

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ResultView tt = new ResultView
                        {
                            Price                 = reader.GetDecimal("Price"),
                            Duration              = reader.GetInt32("Duration"),
                            OperateCarrierNumber  = reader.GetInt32("OC_Number"),
                            ValidateCarrierNumber = reader.GetInt16("VC_Number"),
                            ValidateCarrierName   = reader.GetString("ValidateCarrier"),
                            RoundtripTime         = reader.GetDateTime("ReturnTime"),
                            RoundtripDate         = reader.GetDateTime("ReturnDate"),
                            Roundtrip             = reader.GetByte("RT"),
                            ArrivalPoint          = reader.GetString("Arrival"),
                            DeparturePoint        = reader.GetString("Departure"),
                            DepartureTime         = reader.GetDateTime("DepartureTime"),
                            DepartureDate         = reader.GetDateTime("DepartureDate").Date
                        };
                        try
                        {
                            tt.OperateCarrierName = reader.GetString("OperateCarrier");
                        }
                        catch (Exception)
                        {
                            tt.OperateCarrierName = "n/a";
                        }

                        if (_templates._resultView.Contains(tt))
                        {
                            continue;
                        }
                        _templates._resultView.Add(tt);
                    }
                }
                _connection.Close();
            }
            catch (MySqlException e)
            {
                _connection.Close();
                Debug.Assert(true, e.Message);
            }
            _connection.Close();
            return(_templates.ResultViews);
        }
Ejemplo n.º 11
0
 public static void Initialize()
 {
     if (a)
     {
         Global.Channels.Clear();
     }
     using (MySqlDataReader r = Database.RunQuery("SELECT * FROM channels;"))
     {
         while (r.Read())
         {
             Channel c = new Channel(r.GetString("name"), r.GetString("topic"));
             c.Write = r.GetByte("public_write") == 1;
             c.Read  = r.GetByte("public_read") == 1;
             Global.Channels.Add(c.Name, c);
         }
     }
     a = true;
 }
Ejemplo n.º 12
0
        public static bool SelectAllNPCs(out Dictionary <int, DB_NPC> data)
        {
            var locked = false;

            data = new Dictionary <int, DB_NPC>();
            if (!IsConnected)
            {
                return(false);
            }
            try
            {
                using (MySqlCommand _cmd = _connection.CreateCommand())
                {
                    _cmd.CommandText = $"SELECT a.*, b.item, c.* FROM {tb_05} a LEFT JOIN {tb_05_02} b ON a.id = b.id LEFT JOIN {tb_05_01} c ON a.id = c.id;";
                    Monitor.Enter(s_lock, ref locked);
                    using (MySqlDataReader _result = _cmd.ExecuteReader())
                    {
                        DB_NPC entry; int id;
                        if (_result.HasRows)
                        {
                            while (_result.Read())
                            {
                                id = _result.GetInt32(0);
                                if (data.ContainsKey(id))
                                {
                                    data[id].Items.Add(_result.GetInt32(24));
                                }
                                else
                                {
                                    entry = new DB_NPC(id, _result.GetByte(1), _result.GetInt16(2), _result.GetUInt16(3), _result.GetByte(4), _result.GetUInt16(5),
                                                       _result.GetPonyOld(6));
                                    if ((entry.Flags & NPCFlags.Trader) > 0)
                                    {
                                        entry.Items.Add(_result.GetInt32(24));
                                    }
                                    if ((entry.Flags & NPCFlags.Wears) > 0)
                                    {
                                        for (int i = 26; i <= 33; i++)
                                        {
                                            entry.Wears.Add(_result.GetInt32(i));
                                        }
                                    }
                                    data[id] = entry;
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            catch { return(false); }
            finally { if (locked)
                      {
                          Monitor.Exit(s_lock);
                      }
            }
        }
Ejemplo n.º 13
0
        private void InternalBytesAndBooleans(bool prepare)
        {
            execSQL("DROP TABLE IF EXISTS Test");
            execSQL("CREATE TABLE Test (id TINYINT, idu TINYINT UNSIGNED, i INT UNSIGNED)");
            execSQL("INSERT INTO Test VALUES (-98, 140, 20)");
            execSQL("INSERT INTO Test VALUES (0, 0, 0)");

            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);

            if (prepare)
            {
                cmd.Prepare();
            }
            MySqlDataReader reader = null;

            try
            {
                reader = cmd.ExecuteReader();
                Assert.IsTrue(reader.Read());
                Assert.AreEqual(-98, (sbyte)reader.GetByte(0));
                Assert.AreEqual(140, reader.GetByte(1));
                Assert.IsTrue(reader.GetBoolean(1));
                Assert.AreEqual(20, reader.GetUInt32(2));
                Assert.AreEqual(20, reader.GetInt32(2));

                Assert.IsTrue(reader.Read());
                Assert.AreEqual(0, reader.GetByte(0));
                Assert.AreEqual(0, reader.GetByte(1));
                Assert.IsFalse(reader.GetBoolean(1));

                Assert.IsFalse(reader.Read());
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Ejemplo n.º 14
0
        private bool LoadGuilds()
        {
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    return(false);
                }
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "select * from u_guild;";
                MySqlDataReader reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    reader.Close(); return(false);
                }

                while (reader.Read())
                {
                    GameData.XGuild Temp = new GameData.XGuild();
                    Temp.GuildIdx      = reader.GetUInt16(0);
                    Temp.Name          = reader.GetString(1);
                    Temp.Info          = reader.GetString(2);
                    Temp.Cert          = reader.GetString(3);
                    Temp.EstablishDate = reader.GetDateTime(4);
                    Temp.LimitCount    = reader.GetUInt16(5);
                    Temp.Status        = reader.GetByte(6);
                    Temp.MarkRegDate   = reader.GetDateTime(7);
                    Temp.MarkRegCnt    = reader.GetByte(8);
                    Temp.gold          = reader.GetUInt32(10);
                    Temp.HiringIdx     = reader.GetUInt16(11);
                    Temp.CertDate      = reader.GetDateTime(12);
                    Temp.InfoDate      = reader.GetDateTime(13);

                    Init.game.gamedata.guild.Add(Temp);
                }
                reader.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 15
0
        //从数据库载入军团配置
        public void DB_Load()
        {
            LegionInfo   info    = null;
            String       sql     = string.Format("select * from cq_legion");
            MySqlCommand command = new MySqlCommand(sql, MysqlConn.GetConn());

            MysqlConn.Conn_Open();
            MySqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                if (!reader.HasRows)
                {
                    break;
                }
                info              = new LegionInfo();
                info.id           = reader.GetUInt32("id");
                info.name         = reader.GetString("name");
                info.name         = Coding.Latin1ToGB2312(info.name);
                info.title        = reader.GetByte("member_title");
                info.leader_id    = reader.GetInt32("leader_id");
                info.leader_name  = reader.GetString("leader_name");
                info.leader_name  = Coding.Latin1ToGB2312(info.leader_name);
                info.money        = reader.GetInt64("money");
                info.notice       = reader.GetString("notice");
                info.notice       = Coding.Latin1ToGB2312(info.notice);
                mDicInfo[info.id] = info;
            }

            MysqlConn.Conn_Close();
            command.Dispose();
            //载入行会成员信息

            foreach (LegionInfo obj in mDicInfo.Values)
            {
                sql     = string.Format("select * from cq_legion_members where legion_id={0}", obj.id);
                command = new MySqlCommand(sql, MysqlConn.GetConn());
                MysqlConn.Conn_Open();
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    if (!reader.HasRows)
                    {
                        break;
                    }
                    LegionMember member = new LegionMember();
                    member.rank         = reader.GetInt16("rank");
                    member.members_name = reader.GetString("members_name");
                    member.members_name = Coding.Latin1ToGB2312(member.members_name);
                    member.money        = reader.GetInt64("money");
                    obj.list_member.Add(member);
                }
                MysqlConn.Conn_Close();
                command.Dispose();
            }
        }
Ejemplo n.º 16
0
        // Data Gathering Section
        // Grabs the stored data for the Container.
        internal object[] GetContainerData(CSteamID steamID, string containerName)
        {
            object[]        tmp    = null;
            MySqlDataReader reader = null;

            try
            {
                if (!Initialized)
                {
                    Logger.LogError("Error: Cant load player info from DB, plugin hasn't initialized properly.");
                    return(tmp);
                }
                MySqlCommand command = Connection.CreateCommand();
                command.Parameters.AddWithValue("@steamid", steamID);
                command.Parameters.AddWithValue("@cname", containerName);
                command.CommandText = "SELECT * FROM `" + TableData + "` WHERE SteamID = @steamid AND ContainerName = @cname";
                reader = command.ExecuteReader();
                if (reader.Read())
                {
                    tmp = new object[]
                    {
                        reader.GetUInt16("AssetID"),
                        reader.GetValue(reader.GetOrdinal("ContainerData")) as byte[],
                        reader.GetString("ContainerName"),
                        reader.GetByte("ItemCount"),
                        reader.GetByte("ContainerVersion"),
                    };
                }
            }
            catch (MySqlException ex)
            {
                HandleException(ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
            return(tmp);
        }
Ejemplo n.º 17
0
        public static PonyData GetPony(this MySqlDataReader reader, int i)
        {
            var ret = new PonyData();

            ret.Race   = reader.GetByte(i);
            ret.Gender = reader.GetByte(++i);
            ret.Name   = reader.GetString(++i);
            if (reader.IsDBNull(++i))
            {
                return(ret);
            }
            using (var mem = new MemoryStream())
            {
                var data = (byte[])reader.GetValue(i);
                mem.Write(data, 0, data.Length); mem.Position = 0;
                using (var zip = new DeflateStream(mem, CompressionMode.Decompress))
                    return(ProtoBuf.Serializer.Merge(zip, ret));
            }
        }
Ejemplo n.º 18
0
        public static bool SelectAllSpells(out Dictionary <int, DB_Spell> data)
        {
            var locked = false;

            data = new Dictionary <int, DB_Spell>();
            if (!IsConnected)
            {
                return(false);
            }
            try
            {
                using (MySqlCommand _cmd = _connection.CreateCommand())
                {
                    _cmd.CommandText = $"SELECT * FROM {tb_11};";
                    Monitor.Enter(_connection, ref locked);
                    using (MySqlDataReader _result = _cmd.ExecuteReader())
                    {
                        int id; byte index; DB_Spell spell;
                        if (_result.HasRows)
                        {
                            while (_result.Read())
                            {
                                id    = _result.GetInt32(0);
                                index = _result.GetByte(1);
                                if (!data.TryGetValue(id, out spell))
                                {
                                    data[id] = spell = new DB_Spell(id);
                                }
                                spell.Effects.Add(index, new DB_SpellEffect(_result.GetByte(2), _result.GetByte(3), _result.GetFloat(4), _result.GetFloat(5),
                                                                            _result.GetFloat(6), _result.GetFloat(7), _result.GetFloat(8), _result.GetFloat(9)));
                            }
                        }
                    }
                }
                return(true);
            }
            catch { return(false); }
            finally { if (locked)
                      {
                          Monitor.Exit(_connection);
                      }
            }
        }
 private ActionItem ReadItem(MySqlDataReader reader)
 {
     return(new ActionItem
     {
         Id = reader.GetGuid(0),
         Content = reader.GetString(1),
         Completed = Convert.ToBoolean(reader.GetByte(2)),
         CreatedAt = reader.GetDateTime(3)
     });
 }
Ejemplo n.º 20
0
 public static Watch FromReader(MySqlDataReader reader) =>
 new Watch()
 {
     WatchId    = reader.GetInt32("watchId"),
     MetricId   = reader.GetInt32("metricId"),
     Name       = reader.GetString("name"),
     Expression = reader.GetString("expression"),
     Message    = reader.GetString("message"),
     Sent       = reader.GetByte("sent")
 };
Ejemplo n.º 21
0
        public List <Usuario> ListaColaborador()
        {
            string sql = "SELECT * FROM Usuario WHERE tipoUsuario=1";

            conexao.Open();
            MySqlCommand    command       = new MySqlCommand(sql, conexao);
            MySqlDataReader reader        = command.ExecuteReader();
            List <Usuario>  listaUsuarios = new List <Usuario>();

            while (reader.Read())
            {
                Usuario usuario = new Usuario();
                usuario.id = reader.GetInt32("idUsuario");
                if (!reader.IsDBNull(reader.GetOrdinal("nome")))
                {
                    usuario.nome = reader.GetString("nome");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("nomeUsuario")))
                {
                    usuario.nomeUsuario = reader.GetString("nomeUsuario");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("cpf")))
                {
                    usuario.cpf = reader.GetString("cpf");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("email")))
                {
                    usuario.email = reader.GetString("email");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("telefone")))
                {
                    usuario.telefone = reader.GetString("telefone");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("cep")))
                {
                    usuario.cep = reader.GetString("cep");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("tipoUsuario")))
                {
                    usuario.tipoUsuario = reader.GetByte("tipoUsuario");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("dataCriacao")))
                {
                    usuario.criacaoConta = reader.GetDateTime("dataCriacao");
                }
                if (!reader.IsDBNull(reader.GetOrdinal("dataUltimoAcesso")))
                {
                    usuario.ultimoAcesso = reader.GetDateTime("dataUltimoAcesso");
                }
                listaUsuarios.Add(usuario);
            }
            reader.Close();
            conexao.Close();
            return(listaUsuarios);
        }
Ejemplo n.º 22
0
        // 往 dr 填充 r 于 i 索引的值
        public static void FillValue(DbRow dr, MySqlDataReader r, int i)
        {
            switch (dr.parent.columns[i].dataType)
            {
            case DbDataTypes.Boolean:
                dr[i].Assign(r.GetBoolean(i)); break;

            case DbDataTypes.Int8:
                dr[i].Assign(r.GetSByte(i)); break;

            case DbDataTypes.Int16:
                dr[i].Assign(r.GetInt16(i)); break;

            case DbDataTypes.Int32:
                dr[i].Assign(r.GetInt32(i)); break;

            case DbDataTypes.Int64:
                dr[i].Assign(r.GetInt64(i)); break;

            case DbDataTypes.UInt8:
                dr[i].Assign(r.GetByte(i)); break;

            case DbDataTypes.UInt16:
                dr[i].Assign(r.GetUInt16(i)); break;

            case DbDataTypes.UInt32:
                dr[i].Assign(r.GetUInt32(i)); break;

            case DbDataTypes.UInt64:
                dr[i].Assign(r.GetUInt64(i)); break;

            case DbDataTypes.Float:
                dr[i].Assign(r.GetFloat(i)); break;

            case DbDataTypes.Double:
                dr[i].Assign(r.GetDouble(i)); break;

            case DbDataTypes.DateTime:
                dr[i].Assign(r.GetDateTime(i)); break;

            case DbDataTypes.String:
                dr[i].Assign(r.GetString(i)); break;

            case DbDataTypes.Bytes:
                var len = (int)r.GetBytes(i, 0, null, 0, 0);
                var buf = new byte[len];
                r.GetBytes(i, 0, buf, 0, len);
                dr[i].Assign(buf);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 23
0
        public static AccountEntry Read(MySqlDataReader reader)
        {
            if (!reader.Read())
            {
                return(null);
            }

            return(new AccountEntry
            {
                Id = reader.GetUInt32("id"),
                //Email = reader.GetString("email"), // Not needed by the server currently
                Username = reader.GetString("username"),
                Password = reader.GetString("password"),
                Salt = reader.GetString("salt"),
                Level = reader.GetByte("level"),
                LastServerId = reader.GetByte("last_server_id"),
                Locked = reader.GetBoolean("locked"),
                Validated = reader.GetBoolean("validated")
            });
        }
Ejemplo n.º 24
0
        private bool LoadNPC()
        {
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    return(false);
                }
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "select * from s_npc;";
                MySqlDataReader reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    reader.Close(); return(false);
                }

                while (reader.Read())
                {
                    SData.Npc Temp = new SData.Npc();
                    Temp.idx                = reader.GetInt16(0);
                    Temp.name               = reader.GetString(1);
                    Temp.type               = reader.GetByte(2);
                    Temp.birth_zone_idx     = reader.GetInt16(3);
                    Temp.birth_zone_x       = reader.GetByte(4);
                    Temp.birth_zone_y       = reader.GetByte(5);
                    Temp.move_zone_layernum = reader.GetInt16(6);
                    Temp.sell_type          = reader.GetByte(7);
                    Temp.sell_ratio         = reader.GetByte(8);
                    Temp.barter_item_idx    = reader.GetInt16(9);

                    Init.game.sdata.npc.Add(Temp);
                }
                reader.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 25
0
        public Account LoadAccount(string name)
        {
            Account         account    = null;
            MySqlConnection connection = DAO.GetConnection();

            try
            {
                connection.Open();
                string       cmdText      = "SELECT * FROM account_data WHERE name = ?name";
                MySqlCommand mySqlCommand = new MySqlCommand(cmdText, connection);
                mySqlCommand.Parameters.AddWithValue("?name", name);
                MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader();
                if (mySqlDataReader.Read())
                {
                    int @int = mySqlDataReader.GetInt32("id");
                    account               = new Account(@int, name);
                    account.Password      = mySqlDataReader.GetString("password");
                    account.Activated     = mySqlDataReader.GetByte("activated");
                    account.AccessLevel   = mySqlDataReader.GetByte("access_level");
                    account.MemberShipExp = mySqlDataReader.GetInt64("membership_exp");
                    account.LastServer    = mySqlDataReader.GetByte("last_server");
                    account.LastIp        = mySqlDataReader.GetString("last_ip");
                    account.Toll          = mySqlDataReader.GetInt64("toll");
                }
                mySqlDataReader.Close();
                return(account);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception ex2 = ex;
                log.Error((object)ex2);
                Account result = null;
                ProjectData.ClearProjectError();
                return(result);
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 26
0
        // 取 dr 中某字段的数据并返回
        public static object GetValue(DbColumn col, MySqlDataReader r, int idx)
        {
            switch (col.dataType)
            {
            case DbDataTypes.Boolean:
                return(r.GetBoolean(idx));

            case DbDataTypes.Int8:
                return(r.GetSByte(idx));

            case DbDataTypes.Int16:
                return(r.GetInt16(idx));

            case DbDataTypes.Int32:
                return(r.GetInt32(idx));

            case DbDataTypes.Int64:
                return(r.GetInt64(idx));

            case DbDataTypes.UInt8:
                return(r.GetByte(idx));

            case DbDataTypes.UInt16:
                return(r.GetUInt16(idx));

            case DbDataTypes.UInt32:
                return(r.GetUInt32(idx));

            case DbDataTypes.UInt64:
                return(r.GetUInt64(idx));

            case DbDataTypes.Float:
                return(r.GetFloat(idx));

            case DbDataTypes.Double:
                return(r.GetDouble(idx));

            case DbDataTypes.DateTime:
                return(r.GetDateTime(idx));

            case DbDataTypes.String:
                return(r.GetString(idx));

            case DbDataTypes.Bytes:
                var len = (int)r.GetBytes(idx, 0, null, 0, 0);
                var buf = new byte[len];
                r.GetBytes(idx, 0, buf, 0, len);
                return(buf);

            default:
                throw new Exception("unsupported DbType");
            }
        }
Ejemplo n.º 27
0
 private bool ReadCharacterSkillUsage(MySqlDataReader reader, out CharacterSkillUsage result)
 {
     if (reader.Read())
     {
         result        = new CharacterSkillUsage();
         result.type   = (SkillUsageType)reader.GetByte(0);
         result.dataId = reader.GetInt32(1);
         result.coolDownRemainsDuration = reader.GetFloat(2);
         return(true);
     }
     result = CharacterSkillUsage.Empty;
     return(false);
 }
Ejemplo n.º 28
0
 private bool ReadCharacterHotkey(MySqlDataReader reader, out CharacterHotkey result)
 {
     if (reader.Read())
     {
         result          = new CharacterHotkey();
         result.hotkeyId = reader.GetString(0);
         result.type     = (HotkeyType)reader.GetByte(1);
         result.relateId = reader.GetString(2);
         return(true);
     }
     result = CharacterHotkey.Empty;
     return(false);
 }
Ejemplo n.º 29
0
        private bool LoadMixSkill()
        {
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    return(false);
                }
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "select * from s_mixskill;";
                MySqlDataReader reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    reader.Close(); return(false);
                }

                while (reader.Read())
                {
                    SData.MixSkill Temp = new SData.MixSkill();
                    Temp.MixSkillLelvel  = reader.GetByte(0);
                    Temp.StartHenchLevel = reader.GetInt16(1);
                    Temp.EndHenchLevel   = reader.GetInt16(2);
                    Temp.MixSkillBasis   = reader.GetInt16(3);
                    Temp.MixSkillStart   = reader.GetInt16(4);
                    Temp.MixSkillMaster  = reader.GetInt16(5);
                    Temp.MixSkillBonus   = reader.GetInt16(6);
                    Temp.MixSkillMaxRate = reader.GetByte(7);

                    Init.game.sdata.mixSkill.Add(Temp);
                }
                reader.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 30
0
        private bool LoadSkillData()
        {
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    return(false);
                }
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "select * from s_skilldata;";
                MySqlDataReader reader = cmd.ExecuteReader();
                if (!reader.HasRows)
                {
                    reader.Close(); return(false);
                }

                while (reader.Read())
                {
                    SData.SkillData Temp = new SData.SkillData();
                    Temp.skill_index       = reader.GetByte(0);
                    Temp.level             = reader.GetByte(1);
                    Temp.consumedMp        = reader.GetByte(2);
                    Temp.maxTargetDistance = reader.GetByte(3);
                    Temp.targetRange       = reader.GetByte(4);
                    Temp.requireSP         = reader.GetInt16(5);
                    Temp.continuityTime    = reader.GetInt32(6);
                    Temp.coolTime          = reader.GetInt32(7);

                    Init.game.sdata.skillData.Add(Temp);
                }
                reader.Close();
                return(true);
            }
            catch
            {
                return(false);
            }
        }