예제 #1
0
static bool read_config(config& src, config& dst)
{
	assert(dst.empty());
	if(!src.empty())
	{
		src.swap(dst);
		return true;
	}
	else
	{
		return false;
	}
}
예제 #2
0
/**
 * Updates our command to @a new_command.
 */
void wml_menu_item::update_command(const config & new_command)
{
	// If there is an old command, remove it from the event handlers.
	if ( !command_.empty() ) {
		manager::iteration iter(event_name_);
		while ( handler_ptr hand = *iter ) {
			if ( hand->is_menu_item() ) {
				LOG_NG << "Removing command for " << event_name_ << ".\n";
				remove_event_handler(command_["id"].str());
			}
			++iter;
		}
	}

	// Update our stored command.
	if ( new_command.empty() )
		command_.clear();
	else {
		command_ = new_command;

		// Set some fields required by event processing.
		config::attribute_value & event_id = command_["id"];
		if ( event_id.empty() && !item_id_.empty() ) {
			event_id = item_id_;
		}
		command_["name"] = event_name_;
		command_["first_time_only"] = false;

		// Register the event.
		LOG_NG << "Setting command for " << event_name_ << " to:\n" << command_;
		add_event_handler(command_, true);
	}
}
예제 #3
0
void add_wml_hotkey(const std::string& id, const t_string& description, const config& default_hotkey)
{
	if(id == "null")
	{
		LOG_G << "Couldn't add wml hotkey with null id and description = '" << description << "'.\n";
		return;
	}
	else
	{
		if(has_hotkey_command(id))
		{
			LOG_G << "Hotkey with id '" << id << "' already exists. Deleting the old hotkey_command.\n";
			remove_wml_hotkey(id);
		}
		DBG_G << "Added wml hotkey with id = '" << id << "' and description = '" << description << "'.\n";
		known_hotkeys.push_back(new hotkey_command(hotkey::HOTKEY_WML, id, description, false, hotkey::SCOPE_GAME, t_string("")));

		command_map_[id] = known_hotkeys.size() - 1;

		if(!default_hotkey.empty() && !has_hotkey_item(id))
		{
			hotkey_item new_item(default_hotkey, true);
			new_item.set_command(id);
			if(new_item.valid())
			{
				DBG_G << "added default description for the wml hotkey with id=" + id;
				add_hotkey(new_item);
			}
			else
			{
				ERR_CF << "failed to add default hotkey with id=" + id;
			}
		}
	}
}
bool ignored_checkup::networked_checkup(const config& /*expected_data*/, config& real_data)
{
    assert(real_data.empty());

    LOG_REPLAY << "ignored_checkup::networked_checkup called\n";
    return true;
}
예제 #5
0
void reset_default_hotkeys()
{
	hotkeys_.clear();

	if (!default_hotkey_cfg_.empty()) {
		load_hotkeys(default_hotkey_cfg_, true);
	} else {
		ERR_G<< "no default hotkeys set yet; all hotkeys are now unassigned!" << std::endl;
	}
}
예제 #6
0
    size_t send_data(const config&                cfg,
                     connection                   connection_num,
                     const std::string&           /*packet_type*/)
    {
        if(cfg.empty())
            return 0;

        if( connection_num == 0 )
            return ana_manager.send_all( cfg );
        else
            return ana_manager.send( connection_num, cfg );
    }
예제 #7
0
bool playturn_network_adapter::read(config& dst)
{
	assert(dst.empty());
	if(is_at_end())
	{
		read_from_network();
	}
	if(is_at_end())
	{
		//that means we couldn't read anything from the network.
		return false;
	}
	//skip empty data.
	while(next_ == data_.begin()->ordered_end())
	{
		data_.pop_front();
		next_ = data_.front().ordered_begin();
		assert(!is_at_end());
	}
	config& child = dst.add_child(next_->key);
	//TODO: implement a non const version of ordered children
	config& child_old = const_cast<config&>(next_->cfg);
	if(next_->key == "turn")
	{
		//split [turn] indo different [turn] for each child.
		assert(next_->cfg.all_children_count() > next_command_num_);
		config::all_children_iterator itor = child_old.ordered_begin();
		//TODO: implement operator + (all_children_iterator, int ) properly
		std::advance(itor, next_command_num_);
		//TODO: implement a non const version of ordered children
		config& childchild_old = const_cast<config&>(itor->cfg);
		config& childchild = child.add_child(itor->key);
		childchild.swap(childchild_old);
		
		++next_command_num_;
		if(next_->cfg.all_children_count() == next_command_num_)
		{
			next_command_num_ = 0;
			++next_;
		}
		return true;
	}
	else
	{
		child.swap(child_old);
		++next_;
		return true;
	}
}
예제 #8
0
bool synced_checkup::local_checkup(const config& expected_data, config& real_data)
{
	assert(real_data.empty());
	if(buffer_.child_count("result") > pos_)
	{
		//copying objects :o
		real_data = buffer_.child("result",pos_);
		pos_ ++;
		return real_data == expected_data;
	}
	else
	{
		assert(buffer_.child_count("result") == pos_);
		buffer_.add_child("result", expected_data);
		pos_++;
		return true;
	}
}
예제 #9
0
void manager::read_save_file(const std::string& name, config& cfg, std::string* error_log)
{
	std::string modified_name = name;
	replace_space2underbar(modified_name);

	// Try reading the file both with and without underscores, if needed append .gz as well
	scoped_istream file_stream = istream_file(get_saves_dir() + "/" + modified_name);
	if (file_stream->fail()) {
		file_stream = istream_file(get_saves_dir() + "/" + name);
	}
	if(file_stream->fail() && !is_gzip_file(modified_name)) {
		file_stream = istream_file(get_saves_dir() + "/" + modified_name + ".gz");
		if (file_stream->fail()) {
			file_stream = istream_file(get_saves_dir() + "/" + name + ".gz");
		}
		modified_name += ".gz";
	}

	cfg.clear();
	try{
		/*
		 * Test the modified name, since it might use a .gz
		 * file even when not requested.
		 */
		if(is_gzip_file(modified_name)) {
			read_gz(cfg, *file_stream);
		} else {
			read(cfg, *file_stream);
		}
	} catch (config::error &err)
	{
		LOG_SAVE << err.message;
		if (error_log) *error_log += err.message;
		throw game::load_game_failed();
	}

	if(cfg.empty()) {
		LOG_SAVE << "Could not parse file data into config\n";
		throw game::load_game_failed();
	}
}
bool synced_checkup::networked_checkup(const config& /*expected_data*/, config& real_data)
{
    assert(real_data.empty());
    throw "not implemented";
    //TODO: something with get_user_choice :).
}
예제 #11
0
bool mp_debug_checkup::local_checkup(const config& expected_data, config& real_data)
{
	assert(real_data.empty());
	real_data = get_user_choice("mp_checkup", checkup_choice(expected_data));
	return real_data == expected_data;
}