コード例 #1
0
void lobby_info::process_gamelist(const config &data)
{
	SCOPE_LB;
	gamelist_ = data;
	gamelist_initialized_ = true;
	delete_games();
	games_by_id_.clear();
	FOREACH(const AUTO& c, gamelist_.child("gamelist").child_range("game")) {
		game_info* game = new game_info(c, game_config_);
		games_by_id_[game->id] = game;
	}
	DBG_LB << dump_games_map(games_by_id_);
	DBG_LB << dump_games_config(gamelist_.child("gamelist"));
	process_userlist();
}
コード例 #2
0
ファイル: lobby_info.cpp プロジェクト: Martin9295/wesnoth
bool lobby_info::process_gamelist_diff(const config& data)
{
	SCOPE_LB;
	if(!gamelist_initialized_)
		return false;
	DBG_LB << "prediff " << dump_games_config(gamelist_.child("gamelist"));
	try
	{
		gamelist_.apply_diff(data, true);
	}
	catch(config::error& e)
	{
		ERR_LB << "Error while applying the gamelist diff: '" << e.message
			   << "' Getting a new gamelist.\n";
		network::send_data(config("refresh_lobby"), 0);
		return false;
	}
	DBG_LB << "postdiff " << dump_games_config(gamelist_.child("gamelist"));
	DBG_LB << dump_games_map(games_by_id_);
	config::child_itors range = gamelist_.child("gamelist").child_range("game");
	for(config::child_iterator i = range.first; i != range.second; ++i) {
		config& c = *i;
		DBG_LB << "data process: " << c["id"] << " ("
			   << c[config::diff_track_attribute] << ")\n";
		int game_id = c["id"];
		if(game_id == 0) {
			ERR_LB << "game with id 0 in gamelist config" << std::endl;
			network::send_data(config("refresh_lobby"), 0);
			return false;
		}
		game_info_map::iterator current_i = games_by_id_.find(game_id);
		const std::string& diff_result = c[config::diff_track_attribute];
		if(diff_result == "new" || diff_result == "modified") {
			if(current_i == games_by_id_.end()) {
				games_by_id_.insert(std::make_pair(
						game_id, new game_info(c, game_config_)));
			} else {
				// had a game with that id, so update it and mark it as such
				*(current_i->second) = game_info(c, game_config_);
				current_i->second->display_status = game_info::UPDATED;
			}
		} else if(diff_result == "deleted") {
			if(current_i == games_by_id_.end()) {
				WRN_LB << "Would have to delete a game that I don't have: "
					   << game_id << "\n";
			} else {
				if(current_i->second->display_status == game_info::NEW) {
					// this means the game never made it through to the user
					// interface
					// so just deleting it is fine
					games_by_id_.erase(current_i);
				} else {
					current_i->second->display_status = game_info::DELETED;
				}
			}
		}
	}
	DBG_LB << dump_games_map(games_by_id_);
	try
	{
		gamelist_.clear_diff_track(data);
	}
	catch(config::error& e)
	{
		ERR_LB << "Error while applying the gamelist diff (2): '" << e.message
			   << "' Getting a new gamelist.\n";
		network::send_data(config("refresh_lobby"), 0);
		return false;
	}
	DBG_LB << "postclean " << dump_games_config(gamelist_.child("gamelist"));
	process_userlist();
	return true;
}