コード例 #1
0
ファイル: Gate_Manager.cpp プロジェクト: firehot/server
int Gate_Manager::self_close_process(void) {
	server_status_ = STATUS_CLOSING;

	Block_Buffer buf;
	buf.make_inner_message(ACTIVE_DISCONNECT, ERROR_DISCONNECT_SELF);
	buf.finish_message();
	for (Gate_Player_Cid_Map::iterator iter = player_cid_map_.begin(); iter != player_cid_map_.end(); ++iter) {
		GATE_MANAGER->send_to_client(iter->first, buf);
	}
	//等待服务器通知客户端完毕
	sleep(2);

	//关闭客户端连接
	for (Gate_Player_Cid_Map::iterator iter = player_cid_map_.begin(); iter != player_cid_map_.end(); ++iter) {
		iter->second->link_close();
	}

	int i = 0;
	while (++i < 60) {
		sleep(1);
		LOG_DEBUG("gate server has user:%d", player_cid_map_.size());
		if (player_cid_map_.size() == 0)
			break;
	}

	return 0;
}
コード例 #2
0
ファイル: DB_Worker.cpp プロジェクト: ACEZLY/server
int DB_Worker::process_create_player(int cid, Game_Player_Info &player_info) {
	Block_Buffer buf;
	buf.make_inner_message(SYNC_DB_GAME_CREATE_PLAYER);
	int32_t status = 0;
	if (DB_MANAGER->create_player(player_info) < 0) {
		status = ROLE_HAS_EXIST;
	} else {
		status = SUCCESS_CREATED;
		//创建所有玩家表
		create_player_data(player_info.role_id);
	}
	buf.write_string(player_info.account);
	buf.write_int32(status);
	load_player_data(player_info.role_id, buf);
	buf.finish_message();
	DB_MANAGER->send_data_block(cid, buf);
	return 0;
}
コード例 #3
0
ファイル: DB_Worker.cpp プロジェクト: ACEZLY/server
int DB_Worker::process_load_player(int cid, std::string &account) {
	Block_Buffer buf;
	buf.make_inner_message(SYNC_DB_GAME_LOAD_PLAYER);
	buf.write_string(account);
	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())	{
		//角色存在,开始加载数据
		buf.write_int32(SUCCESS_LOADED);
		int64_t role_id = iter->second.role_id;
		load_player_data(role_id, buf);
	} else {
		//角色不存在,直接返回
		buf.write_int32(ROLE_NOT_EXIST);
	}
	buf.finish_message();
	DB_MANAGER->send_data_block(cid, buf);
	return 0;
}
コード例 #4
0
ファイル: DB_Worker.cpp プロジェクト: ACEZLY/server
int DB_Worker::process_load_public_data(int cid) {
	DB_Struct *public_data = DB_MANAGER->get_public_data_struct();
	for(std::vector<Field_Info>::iterator iter = public_data->field_vec().begin();
				iter != public_data->field_vec().end(); iter++){
		std::string type_name = (*iter).field_type;
		DB_Manager::DB_Struct_Name_Map::iterator it = DB_MANAGER->db_struct_name_map().find(type_name);
		if(it == DB_MANAGER->db_struct_name_map().end()){
			LOG_ERROR("Can not find the module %s", type_name.c_str());
			return -1;
		}

		DB_Struct *def = it->second;
		Block_Buffer buf;
		buf.make_inner_message(def->msg_id() + 400000);
		def->load_data(0, buf);
		buf.finish_message();
		DB_MANAGER->send_data_block(cid, buf);
	}

	return 0;
}
コード例 #5
0
ファイル: DB_Worker.cpp プロジェクト: ACEZLY/server
int DB_Worker::process_save_player(int cid, Block_Buffer &buffer) {
	int32_t status = buffer.read_int32();
	if (status == 1) {
		int rdx = buffer.get_read_idx();
		buffer.read_int32();
		int64_t role_id = buffer.read_int64();
		buffer.set_read_idx(rdx);

		save_player_data(buffer);

		Block_Buffer buf;
		buf.make_inner_message(SYNC_DB_GAME_SAVE_PLAYER);
		MSG_550003 msg;
		msg.role_id = role_id;
		msg.serialize(buf);
		buf.finish_message();
		DB_MANAGER->send_data_block(cid, buf);
	} else {
		save_player_data(buffer);
	}
	return 0;
}