コード例 #1
0
        /// <summary>
        /// 加载邮件列表
        /// </summary>
        /// <param name="receiver_idx">收件人</param>
        /// <param name="callback"></param>
        public static void LoadMailList(long receiver_idx, ushort spid, Action <List <MailInfo> > callback)
        {
            string sql = "call SP_MAIL_LIST(" + receiver_idx + ", " + spid + ", " + Time.second_time + ")";

            DBManager.Instance.GetDB(eDBType.Game).Query(sql, (reader) =>
            {
                List <MailInfo> list = new List <MailInfo>();
                while (reader.HasRows && reader.Read())
                {
                    int idx          = 0;
                    MailInfo data    = CommonObjectPools.Spawn <MailInfo>();
                    data.mail_idx    = reader.GetInt64(idx++);
                    data.mail_type   = (eMailType)reader.GetByte(idx++);
                    data.spid        = reader.GetUInt16(idx++);
                    data.sender_idx  = reader.GetInt64(idx++);
                    data.sender_name = reader.GetString(idx++);
                    data.send_time   = reader.GetInt64(idx++);
                    data.expire_time = reader.GetInt32(idx++);
                    data.flags       = reader.GetUInt32(idx++);
                    data.subject     = reader.GetString(idx++);
                    //内容
                    long len     = reader.GetBytes(idx, 0, null, 0, int.MaxValue);
                    ByteArray by = DBUtils.AllocDBArray();
                    reader.GetBytes(idx, 0, by.Buffer, 0, (int)len);
                    by.WriteEmpty((int)len);//直接修改m_tail
                    data.bin_mail_content.Read(by);
                    list.Add(data);
                }
                callback(list);
            });
        }
コード例 #2
0
        /// <summary>
        /// 执行查询
        /// </summary>
        private void ProcessQuery(QueryInfo query_info, Action <ByteArray> callback)
        {
            string sql = "select `" + query_info.field_name + "` from `" + query_info.table_name + "` where `" + query_info.sql_key_name + "` = ";

            if (query_info.sql_key_type == 0)
            {//数字
                sql += long.Parse(query_info.sql_key_value) + ";";
            }
            else if (query_info.sql_key_type == 1)
            {//字符串
                sql += "'" + query_info.sql_key_value + "';";
            }
            else
            {
                return;
            }
            DatabaseManager.Instance.GetDB(query_info.db_type).Query(sql, (reader) =>
            {
                ByteArray by = new ByteArray(1024 * 8, int.MaxValue);
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {//内容
                        long len = reader.GetBytes(0, 0, null, 0, int.MaxValue);
                        reader.GetBytes(0, 0, by.Buffer, 0, (int)len);
                        by.WriteEmpty((int)len);
                    }
                }
                callback(by);
            });
        }
コード例 #3
0
        /// <summary>
        /// 玩家所有物品
        /// </summary>
        public static void LoadItem(long char_idx, DBID db_id, Action <List <ItemInfo> > callback)
        {
            string sql = "call SP_ITEM_LIST(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Query(sql, (reader) =>
            {
                List <ItemInfo> list = new List <ItemInfo>();
                while (reader.HasRows && reader.Read())
                {
                    int idx          = 0;
                    ItemInfo data    = CommonObjectPools.Spawn <ItemInfo>();
                    data.item_idx    = reader.GetInt64(idx++);
                    data.char_idx    = reader.GetInt64(idx++);
                    data.type        = (eItemSubType)reader.GetUInt32(idx++);
                    data.bag_type    = (eBagType)reader.GetUInt16(idx++);
                    data.ui_pos      = reader.GetUInt32(idx++);
                    data.number      = reader.GetUInt32(idx++);
                    data.create_time = reader.GetInt64(idx++);
                    //内容
                    long len     = reader.GetBytes(idx, 0, null, 0, int.MaxValue);
                    ByteArray by = DBUtils.AllocDBArray();
                    reader.GetBytes(idx, 0, by.Buffer, 0, (int)len);
                    by.WriteEmpty((int)len);
                    data.bin_content.Read(by);
                    list.Add(data);
                }
                callback(list);
            });
        }
コード例 #4
0
        /// <summary>
        /// 查询信息
        /// </summary>
        public static void QueryDBEvent(long char_idx, DBID db_id, Action <List <DBEventInfo> > callback)
        {
            List <DBEventInfo> list = new List <DBEventInfo>();
            ByteArray          by   = DBUtils.AllocDBArray();
            string             sql  = "call SP_DB_EVENT_LOAD(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Query(sql, (reader) =>
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        DBEventInfo info     = new DBEventInfo();
                        info.event_idx       = reader.GetInt64(0);
                        info.target_char_idx = reader.GetInt64(1);
                        info.source_char_idx = reader.GetInt64(2);
                        info.event_type      = (eDBEventType)reader.GetByte(3);
                        //内容
                        by.Clear();
                        long len = reader.GetBytes(4, 0, null, 0, int.MaxValue);
                        reader.GetBytes(4, 0, by.Buffer, 0, (int)len);
                        by.WriteEmpty((int)len);
                        info.bin_content.Read(by);

                        list.Add(info);
                    }
                }
                callback(list);
            });
        }
コード例 #5
0
        public void Write(ByteArray by)
        {
            int start_pos = by.Tail;

            by.WriteLong(char_idx);
            by.WriteUShort(spid);
            by.WriteString(char_name);
            by.WriteByte(char_type);
            by.WriteUShort(ws_id);
            by.WriteByte((byte)flags);
            by.WriteUInt(model_idx);
            by.WriteByte(job);
            by.WriteUShort(level);
            by.WriteUInt(exp);
            by.WriteUInt(gold);
            by.WriteUInt(coin);
            by.WriteUInt(vip_grade);
            by.WriteEmpty(200 - (by.Tail - start_pos));
        }
コード例 #6
0
        /// <summary>
        /// 查询关系信息
        /// </summary>
        public static void QueryRelationInfo(long char_idx, Action <bool, ByteArray> callback)
        {
            bool      ret = false;
            ByteArray by  = DBUtils.AllocDBArray();
            string    sql = "call SP_RELATION_GET(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Center).Query(sql, (reader) =>
            {
                if (reader.HasRows && reader.Read())
                {
                    //内容
                    long len = reader.GetBytes(0, 0, null, 0, int.MaxValue);
                    reader.GetBytes(0, 0, by.Buffer, 0, (int)len);
                    by.WriteEmpty((int)len);
                    ret = true;
                }
                callback(ret, by);
            });
        }
コード例 #7
0
        /// <summary>
        /// 查询信息
        /// </summary>
        public static void QueryCounterList(long char_idx, DBID db_id, Action <bool, ByteArray> callback)
        {
            bool      ret = false;
            ByteArray by  = DBUtils.AllocDBArray();
            string    sql = "call SP_COUNTER_LIST(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Query(sql, (reader) =>
            {
                if (reader.HasRows && reader.Read())
                {
                    //内容
                    long len = reader.GetBytes(0, 0, null, 0, int.MaxValue);
                    reader.GetBytes(0, 0, by.Buffer, 0, (int)len);
                    by.WriteEmpty((int)len);
                    ret = true;
                }
                callback(ret, by);
            });
        }
コード例 #8
0
        /// <summary>
        /// 加载玩家已经领取过的邮件列表
        /// </summary>
        /// <param name="char_idx">收件人</param>
        /// <param name="callback"></param>
        public static void LoadCharRecvs(long char_idx, Action <MailCharRecvs> callback)
        {
            string sql = "call SP_MAIL_GET_CHAR_RECV(" + char_idx + ")";

            DBManager.Instance.GetDB(eDBType.Game).Query(sql, (reader) =>
            {
                MailCharRecvs info = new MailCharRecvs();
                if (reader.HasRows && reader.Read())
                {
                    long len = reader.GetBytes(0, 0, null, 0, int.MaxValue);
                    if (len > 0)
                    {
                        ByteArray by = DBUtils.AllocDBArray();
                        reader.GetBytes(0, 0, by.Buffer, 0, (int)len);
                        by.WriteEmpty((int)len);//直接修改m_tail
                        info.Read(by);
                    }
                }
                callback(info);
            });
        }
コード例 #9
0
        private void ProcessSave(QueryInfo query_info)
        {
            //先收集数据
            List <List <string> > list_result = new List <List <string> >();

            for (int row = 0; row < m_find_result.Rows.Count; ++row)
            {
                List <string> list = new List <string>();
                for (int col = 0; col < m_find_result.Columns.Count; col++)
                {
                    string value = m_find_result.Rows[row].Cells[col].Value as string;
                    list.Add(value);
                }
                list_result.Add(list);
            }

            //序列化
            ByteArray by = new ByteArray(1024 * 8, int.MaxValue);

            for (int row = 0; row < list_result.Count; ++row)
            {
                int           start_pos       = by.Tail;
                List <string> list_row_result = list_result[row];
                for (int col = 0; col < m_list_bin_header.Count; ++col)
                {
                    BinHeader header_info = m_list_bin_header[col];
                    string    value       = list_row_result[col];
                    switch (header_info.type)
                    {
                    case "int":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        long   l = long.Parse(value);
                        byte[] b = BitConverter.GetBytes(l);
                        by.Write(b, header_info.length);
                        break;

                    case "uint":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        ulong ul = ulong.Parse(value);
                        b = BitConverter.GetBytes(ul);
                        by.Write(b, header_info.length);
                        break;

                    case "float":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        float f = float.Parse(value);
                        b = BitConverter.GetBytes(f);
                        by.Write(b, header_info.length);
                        break;

                    case "double":
                        if (value.Length == 0)
                        {
                            value = "0";
                        }
                        double d = double.Parse(value);
                        b = BitConverter.GetBytes(d);
                        by.Write(b, header_info.length);
                        break;

                    case "string":
                        by.WriteString(value);
                        break;

                    default: continue;
                    }
                }
                if (query_info.fixed_length > 0)
                {
                    by.WriteEmpty(query_info.fixed_length - (by.Tail - start_pos));
                }
            }

            //保存到db
            string key_sql = query_info.sql_key_value;

            if (query_info.sql_key_type == 1)
            {
                key_sql = "'" + key_sql + "'";
            }

            string sql = "replace into `" + query_info.table_name + "`" +
                         "(`" + query_info.sql_key_name + "`,`" + query_info.field_name + "`) " +
                         "values (" +
                         key_sql + "," +
                         "@bin_data)";

            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_data", query_info.bin_type, by.GetBuffer(), by.Available);

            param.Add(p);
            DatabaseManager.Instance.GetDB(query_info.db_type).Execute(sql, param);
        }