bool RuleManager::LoadRules(Database *db, const char *ruleset) { int rsid = GetRulesetID(db, ruleset); if(rsid < 0) { _log(RULES__ERROR, "Failed to find ruleset '%s' for load operation. Canceling.", ruleset); return(false); } _log(RULES__CHANGE, "Loading rule set '%s' (%d)", ruleset, rsid); m_activeRuleset = rsid; m_activeName = ruleset; std::string query = StringFormat("SELECT rule_name, rule_value FROM rule_values WHERE ruleset_id=%d", rsid); auto results = db->QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error in LoadRules query %s: %s", query.c_str(), results.ErrorMessage().c_str()); return false; } for(auto row = results.begin(); row != results.end(); ++row) if(!SetRule(row[0], row[1], nullptr, false)) _log(RULES__ERROR, "Unable to interpret rule record for %s", row[0]); return true; }
int RuleManager::_FindOrCreateRuleset(Database *db, const char *ruleset) { int res; res = GetRulesetID(db, ruleset); if(res >= 0) return(res); //found and existing one... uint32 len = strlen(ruleset); char* rst = new char[2*len+1]; db->DoEscapeString(rst, ruleset, len); uint32 new_id; char errbuf[MYSQL_ERRMSG_SIZE]; char* query = 0; if (!db->RunQuery(query, MakeAnyLenString(&query, "INSERT INTO rule_sets (ruleset_id, name) " " VALUES(0, '%s')", rst),errbuf,nullptr,nullptr,&new_id)) { _log(RULES__ERROR, "Fauled to create rule set in the database: %s: %s", query,errbuf); res = -1; } else { res = new_id; } safe_delete_array(query); return(res); }
bool RuleManager::LoadRules(Database *db, const char *ruleset) { int rsid = GetRulesetID(db, ruleset); if(rsid < 0) { Log.Out(Logs::Detail, Logs::Rules, "Failed to find ruleset '%s' for load operation. Canceling.", ruleset); return(false); } Log.Out(Logs::Detail, Logs::Rules, "Loading rule set '%s' (%d)", ruleset, rsid); m_activeRuleset = rsid; m_activeName = ruleset; std::string query = StringFormat("SELECT rule_name, rule_value FROM rule_values WHERE ruleset_id=%d", rsid); auto results = db->QueryDatabase(query); if (!results.Success()) { return false; } for(auto row = results.begin(); row != results.end(); ++row) if(!SetRule(row[0], row[1], nullptr, false)) Log.Out(Logs::Detail, Logs::Rules, "Unable to interpret rule record for %s", row[0]); return true; }
bool RuleManager::LoadRules(Database *database, const char *ruleset_name) { int ruleset_id = GetRulesetID(database, ruleset_name); if (ruleset_id < 0) { Log.Out(Logs::Detail, Logs::Rules, "Failed to find ruleset '%s' for load operation. Canceling.", ruleset_name); return(false); } Log.Out(Logs::Detail, Logs::Rules, "Loading rule set '%s' (%d)", ruleset_name, ruleset_id); m_activeRuleset = ruleset_id; m_activeName = ruleset_name; /* Load default ruleset values first if we're loading something other than default */ if (strcasecmp(ruleset_name, "default") != 0){ std::string default_ruleset_name = "default"; int default_ruleset_id = GetRulesetID(database, default_ruleset_name.c_str()); if (default_ruleset_id < 0) { Log.Out(Logs::Detail, Logs::Rules, "Failed to find default ruleset '%s' for load operation. Canceling.", default_ruleset_name.c_str()); return(false); } Log.Out(Logs::Detail, Logs::Rules, "Loading rule set '%s' (%d)", default_ruleset_name.c_str(), default_ruleset_id); std::string query = StringFormat("SELECT rule_name, rule_value FROM rule_values WHERE ruleset_id = %d", default_ruleset_id); auto results = database->QueryDatabase(query); if (!results.Success()) return false; for (auto row = results.begin(); row != results.end(); ++row) if (!SetRule(row[0], row[1], nullptr, false)) Log.Out(Logs::Detail, Logs::Rules, "Unable to interpret rule record for %s", row[0]); } std::string query = StringFormat("SELECT rule_name, rule_value FROM rule_values WHERE ruleset_id=%d", ruleset_id); auto results = database->QueryDatabase(query); if (!results.Success()) return false; for (auto row = results.begin(); row != results.end(); ++row) if (!SetRule(row[0], row[1], nullptr, false)) Log.Out(Logs::Detail, Logs::Rules, "Unable to interpret rule record for %s", row[0]); return true; }
int RuleManager::_FindOrCreateRuleset(Database *database, const char *in_ruleset_name) { int ruleset_id = GetRulesetID(database, in_ruleset_name); if (ruleset_id >= 0) return ruleset_id; //found and existing one... uint32 len = strlen(in_ruleset_name); auto ruleset_name = new char[2 * len + 1]; database->DoEscapeString(ruleset_name, in_ruleset_name, len); std::string query = StringFormat("INSERT INTO rule_sets (ruleset_id, name) VALUES(0, '%s')", ruleset_name); safe_delete_array(ruleset_name); auto results = database->QueryDatabase(query); if (!results.Success()) return -1; return results.LastInsertedID(); }
int RuleManager::_FindOrCreateRuleset(Database *db, const char *ruleset) { int res = GetRulesetID(db, ruleset); if(res >= 0) return res; //found and existing one... uint32 len = strlen(ruleset); char* rst = new char[2*len+1]; db->DoEscapeString(rst, ruleset, len); std::string query = StringFormat("INSERT INTO rule_sets (ruleset_id, name) VALUES(0, '%s')", rst); safe_delete_array(rst); auto results = db->QueryDatabase(query); if (!results.Success()) { return -1; } return results.LastInsertedID(); }
bool RuleManager::LoadRules(Database *db, const char *ruleset) { char errbuf[MYSQL_ERRMSG_SIZE]; char *query = 0; MYSQL_RES *result; MYSQL_ROW row; int rsid = GetRulesetID(db, ruleset); if(rsid < 0) { _log(RULES__ERROR, "Failed to find ruleset '%s' for load operation. Canceling.", ruleset); return(false); } _log(RULES__CHANGE, "Loading rule set '%s' (%d)", ruleset, rsid); m_activeRuleset = rsid; m_activeName = ruleset; if (db->RunQuery(query, MakeAnyLenString(&query, "SELECT rule_name, rule_value" " FROM rule_values" " WHERE ruleset_id=%d", rsid), errbuf, &result)) { safe_delete_array(query); while((row = mysql_fetch_row(result))) { if(!SetRule(row[0], row[1], nullptr, false)) _log(RULES__ERROR, "Unable to interpret rule record for %s", row[0]); } mysql_free_result(result); } else { safe_delete_array(query); LogFile->write(EQEMuLog::Error, "Error in LoadRules query %s: %s", query, errbuf); return(false); } return(true); }