示例#1
0
int DB_Worker::process_data_block(Block_Buffer *buf) {
	if (! buf || !buf->is_legal()) {
		LOG_ERROR("buf error, buf.read_index = %ld, buf.write_index = %ld", buf->get_read_idx(), buf->get_write_idx());
		return -1;
	}

	int32_t cid = buf->read_int32();
	/*int16_t len*/ buf->read_int16();
	int32_t msg_id = buf->read_int32();
	/*int32_t status*/ buf->read_int32();

	switch (msg_id) {
	case SYNC_GAME_DB_LOAD_PLAYER: {
		MSG_150001 msg;
		msg.deserialize(*buf);
		process_load_player(cid, msg.account);
		break;
	}
	case SYNC_GAME_DB_CREATE_PLAYER: {
		MSG_150002 msg;
		msg.deserialize(*buf);
		process_create_player(cid, msg.player_info);
		break;
	}
	case SYNC_GAME_DB_SAVE_PLAYER: {
		process_save_player(cid, *buf);
		break;
	}
	case SYNC_MASTER_DB_LOAD_PUBLIC_DATA:{
		process_load_public_data(cid);
		break;
	}
	case SYNC_MASTER_DB_DELETE_DATA: {
		std::string msg_type = buf->read_string();
		DB_Manager::DB_Struct_Name_Map::iterator iter = DB_MANAGER->db_struct_name_map().find(msg_type);
		if(iter == DB_MANAGER->db_struct_name_map().end()){
			LOG_ERROR("Can not find the module %s", msg_type.c_str());
			break;
		}
		DB_Struct *def = iter->second;
		def->delete_data(*buf);
		break;
	}
	default: {
		DB_Manager::DB_Struct_Id_Map::iterator iter = DB_MANAGER->db_struct_id_map().find(msg_id);
		if(iter == DB_MANAGER->db_struct_id_map().end()){
			LOG_ERROR("Can not find the msg_id %d", msg_id);
			break;
		}
		DB_Struct *def = iter->second;
		def->save_data_vector(*buf);
		break;
	}
	}

	DB_SERVER->push_block(cid, buf);
	return 0;
}
示例#2
0
int DB_Worker::process_data_block(Block_Buffer *buffer) {
	if (! buffer || !buffer->is_legal()) {
		LOG_ERROR("buffer is not legal, buffer.read_index = %ld, buffer.write_index = %ld",
				buffer->get_read_idx(), buffer->get_write_idx());
		return -1;
	}

	int32_t cid = 0;
	int16_t len = 0;
	int32_t msg_id = 0;
	int32_t status = 0;
	buffer->read_int32(cid);
	buffer->read_int16(len);
	buffer->read_int32(msg_id);
	buffer->read_int32(status);

	switch (msg_id) {
	case SYNC_GAME_DB_LOAD_PLAYER: {
		std::string account;
		buffer->read_string(account);
		process_load_player(cid, account);
		break;
	}
	case SYNC_GAME_DB_CREATE_PLAYER: {
		Create_Role_Info role_info;
		role_info.deserialize(*buffer);
		process_create_player(cid, role_info);
		break;
	}
	case SYNC_GAME_DB_SAVE_PLAYER: {
		process_save_player(cid, status, *buffer);
		break;
	}
	case SYNC_MASTER_DB_CREATE_GUILD:{
		Create_Guild_Info guild_info;
		guild_info.deserialize(*buffer);
		process_create_guild(cid, guild_info);
		break;
	}
	case SYNC_MASTER_DB_LOAD_DATA:{
		process_load_master(cid);
		break;
	}
	case SYNC_MASTER_DB_DELETE_DATA: {
		std::string struct_name;
		buffer->read_string(struct_name);
		Struct_Name_Map::iterator iter = DB_MANAGER->db_struct_name_map().find(struct_name);
		if(iter == DB_MANAGER->db_struct_name_map().end()){
			LOG_ERROR("Can not find the struct_name: %s", struct_name.c_str());
			break;
		}
		Base_Struct *def = iter->second;
		def->delete_data(*buffer);
		break;
	}
	default: {
		Struct_Id_Map::iterator iter = DB_MANAGER->db_struct_id_map().find(msg_id);
		if(iter == DB_MANAGER->db_struct_id_map().end()){
			LOG_ERROR("Can not find the msg_id %d", msg_id);
			break;
		}
		Base_Struct *def = iter->second;
		def->save_data_vector(*buffer);
		break;
	}
	}

	DB_SERVER->push_block(cid, buffer);
	return 0;
}