Example #1
0
        public int res_role_list(Bit_Buffer buffer)
        {
            int length = (int)buffer.read_uint(3);

            for (int i = 0; i < length; ++i)
            {
                Role_Info role_info;
                role_info.role_id   = buffer.read_int64();
                role_info.role_name = buffer.read_string();
                role_info.gender    = (byte)buffer.read_uint(1);
                role_info.career    = (byte)buffer.read_uint(2);
                role_info.level     = (byte)buffer.read_uint(8);
                role_info.combat    = buffer.read_uint(32);
                role_list_.Add(role_info);
            }

            if (length > 0)
            {
                Log.debug_log("账号名:" + account_ + "角色数量:" + length.ToString());
                Random random  = new Random();
                int    index   = random.Next(0, length - 1);
                long   role_id = role_list_[index].role_id;
                req_enter_game(role_id);
            }
            else
            {
                req_create_role();
            }
            return(0);
        }
Example #2
0
        public int res_error_code(Bit_Buffer buffer)
        {
            uint   code    = buffer.read_uint(16);
            string err_msg = Error_Code.message(code);

            if (err_msg != "")
            {
                player_log("服务器返回错误消息:" + err_msg);
            }
            else
            {
                player_log("服务器返回错误代码:" + code.ToString());
            }
            return(0);
        }
Example #3
0
        private string get_print_msg(List <Field_Info> info_list, Bit_Buffer buffer)
        {
            string ret = "";

            foreach (Field_Info info in info_list)
            {
                if (info.field_label == "arg")
                {
                    string value = get_arg_string(info, buffer);
                    ret += value;
                }
                else if (info.field_label == "vector")
                {
                    string value = get_vector_string(info, buffer);
                    ret += value;
                }
                else if (info.field_label == "struct")
                {
                    string value = get_struct_string(info, buffer);
                    ret += value;
                }
                else if (info.field_label == "if")
                {
                    if (buffer.read_bits_available() >= 1 && buffer.read_bool())
                    {
                        ret += get_print_msg(info.field_list, buffer);
                    }
                }
                else if (info.field_label == "switch")
                {
                    if (buffer.read_bits_available() >= info.field_bit)
                    {
                        uint case_val = buffer.read_uint(info.field_bit);
                        foreach (Field_Info swinfo in info.field_list)
                        {
                            if (swinfo.field_label == "case" && swinfo.case_val == case_val)
                            {
                                //找到对应的case标签,对case标签内的child数组进行build
                                ret += get_print_msg(swinfo.field_list, buffer);
                                break;
                            }
                        }
                    }
                }
            }
            return(ret);
        }
Example #4
0
        public int res_select_gate(Bit_Buffer buffer)
        {
            string gate_ip   = buffer.read_string();
            uint   gate_port = buffer.read_uint(16);

            token_ = buffer.read_string();
            player_log("\r\n" +
                       "{" + "\r\n" +
                       "  gate_ip:" + gate_ip + "\r\n" +
                       "  gate_port:" + gate_port.ToString() + "\r\n" +
                       "  token:" + token_ + "\r\n" +
                       "}");
            robot_status_ = 1;//准备连接gate服务器
            end_point_.disconnect();
            end_point_.connect(gate_ip, (int)gate_port);
            return(1);
        }
Example #5
0
        private string get_arg_string(Field_Info info, Bit_Buffer buffer, bool from_vector = false)
        {
            string ret = "";

            if (!from_vector)
            {
                ret = (info.field_name + ":");
            }

            if (info.field_type == "int")
            {
                int val = buffer.read_int(info.field_bit);
                ret += val.ToString();
            }
            else if (info.field_type == "uint")
            {
                uint val = buffer.read_uint(info.field_bit);
                ret += val.ToString();
            }
            else if (info.field_type == "int64")
            {
                long val = buffer.read_int64();
                ret += val.ToString();
            }
            else if (info.field_type == "uint64")
            {
                ulong val = buffer.read_uint64();
                ret += val.ToString();
            }
            else if (info.field_type == "float")
            {
                float val = buffer.read_decimal(32);
                ret += val.ToString();
            }
            else if (info.field_type == "bool")
            {
                bool val = buffer.read_bool();
                ret += val.ToString();
            }
            else if (info.field_type == "string")
            {
                string val = buffer.read_string();
                ret += "\"" + val + "\"";
            }
            return(ret + ", ");
        }
Example #6
0
        private string get_vector_string(Field_Info info, Bit_Buffer buffer)
        {
            string ret    = info.field_name + ":[";
            uint   length = buffer.read_uint(info.field_vbit);

            for (uint i = 0; i < length; ++i)
            {
                if (is_struct(info.field_type))
                {
                    ret += get_struct_string(info, buffer, true);
                }
                else
                {
                    ret += get_arg_string(info, buffer, true);
                }
            }
            if (length > 0)
            {
                ret = ret.Substring(0, ret.Length - 2);
            }
            return(ret + "], ");
        }