예제 #1
0
int Player_Monster::battle_appear_info(Block_Buffer &buf) {
    // size_t rd_idx = buf.get_read_idx();
    size_t wr_begin_idx = buf.get_write_idx();
    size_t wr_end_idx = 0;
    uint32_t len = 0;

    // fill head
    buf.make_message(ACTIVE_FIGHTER_APPEAR);

    MSG_81000008 msg;
    msg.fighter_info.role_id = role_id();
    msg.fighter_info.role_name = role_name();
    msg.fighter_info.career = career_;
    msg.fighter_info.gender = gender_;
    msg.fighter_info.position.val_1 = mover_detail().battle_position.pos;
    msg.fighter_info.position.val_2 = mover_detail().battle_position.idx;
    msg.fighter_info.hp_curr = blood_current();
    msg.fighter_info.hp_max = blood_max();
    msg.fighter_info.avatar = avatar_vec;
    boost::unordered_set<Property_Type> property_set;
    property_set.insert(PT_MORALE_CAPS);
    property_set.insert(PT_MORALE_CURRENT);

    for (boost::unordered_set<Property_Type>::iterator it = property_set.begin(); it != property_set.end(); ++it) {
        msg.fighter_info.init_props.push_back(Prop_Change(*it));
    }

    for (std::vector<Prop_Change>::iterator pc_it = msg.fighter_info.init_props.begin();
            pc_it != msg.fighter_info.init_props.end(); ++pc_it) {
        (*pc_it).current_val = fighter_detail().fetch_fight_property(Property_Type((*pc_it).prop_type));
    }

    msg.serialize(buf);

    // refill len in head
    wr_end_idx = buf.get_write_idx();
    len = wr_end_idx - wr_begin_idx - sizeof(uint32_t);
    buf.set_write_idx(wr_begin_idx);
    buf.write_uint32(len);
    buf.set_write_idx(wr_end_idx);

    return 0;
}
예제 #2
0
int Gate_Manager::process_list(void) {
	int32_t cid = 0;
	Block_Buffer *buf = 0;

	while (1) {
		bool all_empty = true;

		/// 掉线玩家列表
		if (! drop_cid_list_.empty()) {
			all_empty = false;
			cid = drop_cid_list_.pop_front();
			process_drop_cid(cid);
		}
		/// client-->gate  消息队列
		if ((buf = gate_client_data_list_.pop_front()) != 0) {
			all_empty = false;
			if (buf->is_legal()) {
				cid = buf->peek_int32();
				GATE_CLIENT_MESSAGER->process_block(*buf);
			} else {
				LOG_ERROR("buf.read_index = %ld, buf.write_index = %ld", buf->get_read_idx(), buf->get_write_idx());
				buf->reset();
			}
			GATE_CLIENT_SERVER->push_block(cid, buf);
		}
		/// 游戏服内部循环消息队列
		if (! self_loop_block_list_.empty()) {
			all_empty = false;
			buf = self_loop_block_list_.front();
			self_loop_block_list_.pop_front();
			GATE_INNER_MESSAGER->process_self_loop_block(*buf);
			block_pool_.push(buf);
		}
		/// login-->gate  消息队列
		if ((buf = gate_login_data_list_.pop_front()) != 0) {
			all_empty = false;
			if (buf->is_legal()) {
				cid = buf->peek_int32();
				GATE_INNER_MESSAGER->process_login_block(*buf);
			} else {
				LOG_ERROR("buf.read_index = %ld, buf.write_index = %ld", buf->get_read_idx(), buf->get_write_idx());
				buf->reset();
			}
			GATE_LOGIN_CONNECTOR->push_block(cid, buf);
		}
		/// game-->gate  消息队列
		if ((buf = gate_game_data_list_.pop_front()) != 0) {
			all_empty = false;
			if (buf->is_legal()) {
				cid = buf->peek_int32();
				GATE_INNER_MESSAGER->process_game_block(*buf);
			} else {
				LOG_ERROR("buf.read_index = %ld, buf.write_index = %ld", buf->get_read_idx(), buf->get_write_idx());
				buf->reset();
			}
			GATE_GAME_CONNECTOR->push_block(cid, buf);
		}
		/// master-->gate  消息队列
		if ((buf = gate_master_data_list_.pop_front()) != 0) {
			all_empty = false;
			if (buf->is_legal()) {
				cid = buf->peek_int32();
				GATE_INNER_MESSAGER->process_master_block(*buf);
			} else {
				LOG_ERROR("buf.read_index = %ld, buf.write_index = %ld", buf->get_read_idx(), buf->get_write_idx());
				buf->reset();
			}
			GATE_MASTER_CONNECTOR->push_block(cid, buf);
		}

		if (all_empty)
			Time_Value::sleep(Time_Value(0,100));
	}
	return 0;
}