Exemplo n.º 1
0
void verify_and_set_global_variable(const vconfig &pcfg)
{
	bool valid = true;
	if (!pcfg.has_attribute("to_global")) {
		LOG_PERSIST << "Error: [set_global_variable] missing required attribute \"from_global\"";
		valid = false;
	}
	if (!pcfg.has_attribute("from_local")) {
		LOG_PERSIST << "Warning: [set_global_variable] missing attribute \"to_local\", global variable will be cleared";
	}
	// TODO: allow for global namespace.
	if (!pcfg.has_attribute("namespace")) {
		LOG_PERSIST << "Error: [set_global_variable] missing attribute \"namespace\" and no global namespace provided.";
		valid = false;
	}
	if (network::nconnections() != 0) {
		if (!pcfg.has_attribute("side")) {
			LOG_PERSIST << "Error: [set_global_variable] missing attribute \"side\" required in multiplayer context.";
			valid = false;
		} else {
			config::attribute_value pcfg_side = pcfg["side"];
			int side = pcfg_side;
			//Check side matching only if the side is not "global".
			if (pcfg_side.str() != "global") {
				//Ensure that the side is valid.
				if (unsigned(side-1) > resources::teams->size()) {
					LOG_PERSIST << "Error: [set_global_variable] attribute \"side\" specifies invalid side number.";
					valid = false;
				} else {
					//Set the variable only if it is meant for a side we control
					valid = (*resources::teams)[side - 1].is_local();
				}
			}
		}
	}
	if (valid)
	{
		persist_context &ctx = resources::persist->get_context((pcfg["namespace"]));
		if (ctx.valid()) {
			set_global_variable(ctx,pcfg);
		} else {
			LOG_PERSIST << "Error: [set_global_variable] attribute \"namespace\" is not valid.";
		}
	}
}
Exemplo n.º 2
0
void verify_and_set_global_variable(const vconfig &pcfg)
{
	bool valid = true;
	if (!pcfg.has_attribute("to_global")) {
		ERR_PERSIST << "[set_global_variable] missing required attribute \"to_global\"";
		valid = false;
	}
	if (!pcfg.has_attribute("from_local")) {
		LOG_PERSIST << "Warning: [set_global_variable] missing attribute \"from_local\", global variable will be cleared";
	}
	// TODO: allow for global namespace.
	if (!pcfg.has_attribute("namespace")) {
		ERR_PERSIST << "[set_global_variable] missing attribute \"namespace\" and no global namespace provided.";
		valid = false;
	}
	if (resources::controller->is_networked_mp()) {
		config::attribute_value pcfg_side = pcfg["side"];
		int side = pcfg_side;
		//Check side matching only if the side is not "global" or empty.
		if (pcfg_side.str() != "global" && !pcfg_side.empty()) {
			//Ensure that the side is valid.
			if (unsigned(side-1) > resources::gameboard->teams().size()) {
				ERR_PERSIST << "[set_global_variable] attribute \"side\" specifies invalid side number.";
				valid = false;
			} else if (resources::gameboard->teams()[side - 1].is_empty()) {
				LOG_PERSIST << "[set_global_variable] attribute \"side\" specifies a null-controlled side number.";
				valid = false;
			} else {
				//Set the variable only if it is meant for a side we control
				valid = resources::gameboard->teams()[side - 1].is_local();
			}
		}
	}
	if (valid)
	{
		persist_context &ctx = resources::persist->get_context((pcfg["namespace"]));
		if (ctx.valid()) {
			set_global_variable(ctx,pcfg);
		} else {
			LOG_PERSIST << "Error: [set_global_variable] attribute \"namespace\" is not valid.";
		}
	}
}