public override int Send(long conn_idx, ByteArray by)
        {
            base.Send(conn_idx, by);

            if (m_socket == null)
            {
                return(0);
            }

            if (by.Available >= NetID.SendPacketMaxSize)
            {
                by.Skip(NetID.PacketHeadSize);
                ushort header = by.ReadUShort();
                Log.Error("发送数据量过大:" + header);
                return(0);
            }
            int data_len = by.Available - NetID.PacketHeadSize;

            by.ModifyUShort((ushort)data_len, 0);
            m_send_stream.SetLength(0);
            m_send_stream.Write(by.GetBuffer(), 0, (int)by.Available);//数据内容

            m_socket.Send(m_send_stream.ToArray());
            return((int)m_send_stream.Length);
        }
Esempio n. 2
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);
        }
        /// <summary>
        /// 创建邮件
        /// </summary>
        /// <param name="info"></param>
        /// <param name="callback"></param>
        public static void CreateMail(MailInfo info)
        {
            string sql = "insert into `mail_box` " +
                         "(mail_type,spid,receiver_idx,sender_idx,sender_name,send_time,expire_time,delivery_time,flags,`subject`,bin_mail_content,last_update_time) " +
                         "values (" +
                         (byte)info.mail_type + "," +
                         info.spid + "," +
                         info.receiver_idx + "," +
                         info.sender_idx + ",'" +
                         info.sender_name + "'," +
                         info.send_time + "," +
                         info.expire_time + "," +
                         info.delivery_time + "," +
                         info.flags + ",'" +
                         info.subject + "'," +
                         "@bin_content,now())";

            ByteArray by = DBUtils.AllocDBArray();

            info.bin_mail_content.Write(by);
            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_content", MySqlDbType.Blob, by.GetBuffer(), by.Available);

            param.Add(p);
            DBManager.Instance.GetDB(eDBType.Game).Execute(sql, param);
        }
        /// <summary>
        /// 修改已经领取过的邮件
        /// </summary>
        /// <param name="info"></param>
        /// <param name="callback"></param>
        public static void UpdateCharRecvs(long char_idx, MailCharRecvs info)
        {
            string sql = "replace into `mail_char_recv`" +
                         "(`char_idx`,`bin_mails`) " +
                         "values (" +
                         char_idx + "," +
                         "@bin_mails)";

            ByteArray by = DBUtils.AllocDBArray();

            info.Write(by);
            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_mails", MySqlDbType.Blob, by.GetBuffer(), by.Available);

            param.Add(p);
            DBManager.Instance.GetDB(eDBType.Game).Execute(sql, param);
        }
Esempio n. 5
0
        /// <summary>
        /// 创建物品
        /// </summary>
        public static void CreateItem(ItemInfo info, DBID db_id)
        {
            string sql = "insert into `character_all_item` " +
                         "(item_idx, char_idx,type,bag_type,ui_pos,number,create_time,bin_content) " +
                         "values (" +
                         info.item_idx + "," +
                         info.char_idx + "," +
                         (uint)info.type + "," +
                         (ushort)info.bag_type + "," +
                         info.ui_pos + "," +
                         info.number + "," +
                         info.create_time + "," +
                         "@bin_content)";

            ByteArray by = DBUtils.AllocDBArray();

            info.bin_content.Write(by);
            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_content", MySqlDbType.Blob, by.GetBuffer(), by.Available);

            param.Add(p);
            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Execute(sql, param);
        }
        /// <summary>
        /// 添加事件
        /// </summary>
        public static void InsertDBEvent(DBEventInfo info, DBID db_id)
        {
            string sql = "call SP_DB_EVENT_CREATE(" +
                         info.target_char_idx + "," +
                         info.source_char_idx + "," +
                         (byte)info.event_type + "," +
                         "@i_bin_content);";

            ByteArray by = DBUtils.AllocDBArray();

            info.bin_content.Write(by);

            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@i_bin_content", MySqlDbType.Blob, by.GetBuffer(), by.Available);

            param.Add(p);
            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Execute(sql, param);
        }
Esempio n. 7
0
        /// <summary>
        /// 修改关系信息
        /// </summary>
        public static void UpdateCharRelation(long char_idx, ByteArray by)
        {
            //TODO:没有关系成员,删除
            if (by.Available == 0)
            {
                string sql = "delete from `relation` where char_idx = " + char_idx + ";";
                DBManager.Instance.GetDB(eDBType.Center).Execute(sql);
            }
            else
            {
                string sql = "replace into `relation`" +
                             "(`char_idx`,`bin_relation`) " +
                             "values (" +
                             char_idx + "," +
                             "@bin_relation)";

                List <MySqlParameter> param = new List <MySqlParameter>();
                MySqlParameter        p     = Database.MakeMysqlParam("@bin_relation", MySqlDbType.Blob, by.GetBuffer(), by.Available);
                param.Add(p);
                DBManager.Instance.GetDB(eDBType.Center).Execute(sql, param);
            }
        }
Esempio n. 8
0
 public override void Write(ByteArray by)
 {
     base.Write(by);
     by.Write(data.GetBuffer(), data.Available);
 }
        /// <summary>
        /// 修改或插入信息
        /// </summary>
        public static void UpdateCounter(long char_idx, DBID db_id, ByteArray by)
        {
            string sql = "replace into `character_counter`" +
                         "(`char_idx`,`bin_use_count`) " +
                         "values (" +
                         char_idx + "," +
                         "@bin_use_count)";

            List <MySqlParameter> param = new List <MySqlParameter>();
            MySqlParameter        p     = Database.MakeMysqlParam("@bin_use_count", MySqlDbType.Blob, by.GetBuffer(), by.Available);

            param.Add(p);
            DBManager.Instance.GetDB(eDBType.Game, db_id.game_id).Execute(sql, param);
        }