예제 #1
0
파일: rulesys.cpp 프로젝트: Corysia/Server
void RuleManager::SaveRules(Database *db, const char *ruleset) {

	if(ruleset != nullptr) {
		//saving to a specific name
		if(m_activeName != ruleset) {
			//a new name...

			m_activeRuleset = _FindOrCreateRuleset(db, ruleset);
			if(m_activeRuleset == -1) {
				_log(RULES__ERROR, "Unable to find or create rule set %s", ruleset);
				return;
			}
			m_activeName = ruleset;
		}
		_log(RULES__CHANGE, "Saving running rules into rule set %s (%d)", ruleset, m_activeRuleset);
	} else {
		_log(RULES__CHANGE, "Saving running rules into running rule set %s", m_activeName.c_str(), m_activeRuleset);
	}

	int r;
	for(r = 0; r < _IntRuleCount; r++) {
		_SaveRule(db, IntRule, r);
	}
	for(r = 0; r < _RealRuleCount; r++) {
		_SaveRule(db, RealRule, r);
	}
	for(r = 0; r < _BoolRuleCount; r++) {
		_SaveRule(db, BoolRule, r);
	}
}
예제 #2
0
void RuleManager::SaveRules(Database *database, const char *ruleset_name) {

	if (ruleset_name != nullptr) {
		//saving to a specific name
		if (m_activeName != ruleset_name) {
			//a new name...

			m_activeRuleset = _FindOrCreateRuleset(database, ruleset_name);
			if (m_activeRuleset == -1) {
				Log.Out(Logs::Detail, Logs::Rules, "Unable to find or create rule set %s", ruleset_name);
				return;
			}
			m_activeName = ruleset_name;
		}
		Log.Out(Logs::Detail, Logs::Rules, "Saving running rules into rule set %s (%d)", ruleset_name, m_activeRuleset);
	}
	else {
		Log.Out(Logs::Detail, Logs::Rules, "Saving running rules into running rule set %s", m_activeName.c_str(), m_activeRuleset);
	}

	int i;
	for (i = 0; i < _IntRuleCount; i++) {
		_SaveRule(database, IntRule, i);
	}
	for (i = 0; i < _RealRuleCount; i++) {
		_SaveRule(database, RealRule, i);
	}
	for (i = 0; i < _BoolRuleCount; i++) {
		_SaveRule(database, BoolRule, i);
	}
}
예제 #3
0
파일: rulesys.cpp 프로젝트: Corysia/Server
bool RuleManager::SetRule(const char *rule_name, const char *rule_value, Database *db, bool db_save) {
	if(rule_name == nullptr || rule_value == nullptr)
		return(false);

	RuleType type;
	uint16 index;
	if(!_FindRule(rule_name, type, index))
		return(false);

	switch(type) {
	case IntRule:
		m_RuleIntValues [index] = atoi(rule_value);
		_log(RULES__CHANGE, "Set rule %s to value %d", rule_name, m_RuleIntValues[index]);
		break;
	case RealRule:
		m_RuleRealValues[index] = atof(rule_value);
		_log(RULES__CHANGE, "Set rule %s to value %.13f", rule_name, m_RuleRealValues[index]);
		break;
	case BoolRule:
		uint32 val = 0;
		if(!strcasecmp(rule_value, "on") || !strcasecmp(rule_value, "true") || !strcasecmp(rule_value, "yes") || !strcasecmp(rule_value, "enabled") || !strcmp(rule_value, "1"))
			val = 1;
		m_RuleBoolValues[index] = val;
		_log(RULES__CHANGE, "Set rule %s to value %s", rule_name, m_RuleBoolValues[index] == 1 ?"true":"false");
		break;
	}

	if(db_save)
		_SaveRule(db, type, index);

	return(true);
}