Esempio n. 1
0
int DB_Worker::process_create_player(int cid, Create_Role_Info &role_info) {
	int64_t role_id = 0;
	Block_Buffer buf;
	if ((role_id = DB_MANAGER->create_player(role_info)) > 0) {
		buf.make_server_message(SYNC_DB_GAME_CREATE_PLAYER, ROLE_SUCCESS_CREATE);
		buf.write_string(role_info.account);
		//创建所有玩家表,构建登录消息buf
		create_player_data(role_id, buf);
	} else {
		buf.make_server_message(SYNC_DB_GAME_CREATE_PLAYER, ROLE_HAS_EXIST);
		buf.write_string(role_info.account);
	}
	buf.finish_message();
	DB_MANAGER->send_data_block(cid, buf);
	return 0;
}
Esempio n. 2
0
int DB_Worker::process_create_guild(int cid, Create_Guild_Info &guild_info) {
	Block_Buffer buf;
	buf.make_server_message(SYNC_DB_MASTER_CREATE_GUILD, 0);
	guild_info.guild_id = DB_MANAGER->create_guild(guild_info);
	guild_info.serialize(buf);
	buf.finish_message();
	DB_MANAGER->send_data_block(cid, buf);
	return 0;
}
Esempio n. 3
0
int DB_Worker::process_load_master(int cid) {
	Base_Struct *master_struct = DB_MANAGER->get_master_data_struct();
	for(std::vector<Field_Info>::const_iterator iter = master_struct->field_vec().begin();
				iter != master_struct->field_vec().end(); iter++){
		Struct_Name_Map::iterator it = DB_MANAGER->db_struct_name_map().find(iter->field_type);
		if(it == DB_MANAGER->db_struct_name_map().end()){
			LOG_ERROR("Can not find the struct_name:%s", iter->field_type.c_str());
			return -1;
		}

		Block_Buffer buf;
		buf.make_server_message(it->second->msg_id() + 400000, 0);
		it->second->load_data(0, buf);
		buf.finish_message();
		DB_MANAGER->send_data_block(cid, buf);
	}

	return 0;
}
Esempio n. 4
0
int DB_Worker::process_save_player(int cid, int status, Block_Buffer &buffer) {
	//先把两个额外字段读出来,再保存玩家数据,防止buffer错乱
	bool logout = false;
	std::string account = "";
	buffer.read_bool(logout);
	buffer.read_string(account);
	if (logout) {
		//离线保存
		save_player_data(buffer);

		Block_Buffer buf;
		buf.make_server_message(SYNC_DB_GAME_SAVE_PLAYER, 0);
		buf.write_string(account);
		buf.finish_message();
		DB_MANAGER->send_data_block(cid, buf);
	} else {
		//在线定时保存
		save_player_data(buffer);
	}
	return 0;
}
Esempio n. 5
0
int DB_Worker::process_load_player(int cid, std::string &account) {
	int32_t status = 0;
	int64_t role_id = 0;
	DB_Manager::DB_Cache_Account_Map::iterator iter = DB_MANAGER->db_cache_account_map().find(account);
	if (iter != DB_MANAGER->db_cache_account_map().end())	{
		//角色存在,加载数据
		status = ROLE_SUCCESS_LOAD;
		role_id = iter->second.role_id;
	} else {
		//角色不存在,直接返回
		status = ROLE_NOT_EXIST;
	}

	Block_Buffer buf;
	buf.make_server_message(SYNC_DB_GAME_LOAD_PLAYER, status);
	buf.write_string(account);
	if (role_id > 0) {
		load_player_data(role_id, buf);
	}
	buf.finish_message();
	DB_MANAGER->send_data_block(cid, buf);
	return 0;
}