46 #define GETLOG() if (logger) {logger->log("config get: " + key); \
47 if (mIsMain) optionsCount[key] = 1; }
60 "BotCheckerWindowSticky",
62 "BotCheckerWindowVisible",
63 "BotCheckerWindowWinX",
64 "BotCheckerWindowWinY",
68 "screenshotDirectory2",
70 "AttackRangeBorderDelay",
71 "AttackRangeBorderGradient",
73 "AttackRangeGradient",
78 "BotCheckerWindowSkin",
83 "CollisionHighlightDelay",
84 "CollisionHighlightGradient",
89 "ColorExperienceGradient",
91 "ColorPickupGradient",
100 "ExperienceGradient",
110 "Hit CriticalGradient",
111 "Hit Monster Player",
112 "Hit Monster PlayerGradient",
113 "Hit Player Monster",
114 "Hit Player MonsterGradient",
116 "HitCriticalGradient",
117 "HitLocalPlayerCriticalDelay",
118 "HitLocalPlayerCriticalGradient",
119 "HitLocalPlayerMiss",
120 "HitLocalPlayerMissDelay",
121 "HitLocalPlayerMissGradient",
122 "HitLocalPlayerMonster",
123 "HitLocalPlayerMonsterDelay",
124 "HitLocalPlayerMonsterGradient",
126 "HitMonsterPlayerDelay",
127 "HitMonsterPlayerGradient",
129 "HitPlayerMonsterDelay",
130 "HitPlayerMonsterGradient",
133 "HomePlaceBorderDelay",
134 "HomePlaceBorderGradient",
147 "MonsterAttackRange",
148 "MonsterAttackRangeDelay",
149 "MonsterAttackRangeGradient",
171 "PortalHighlightDelay",
172 "PortalHighlightGradient",
186 "SocialCreatePopupSkin",
195 "TextCommandEditorSkin",
213 "keyAutoCompleteChat",
224 "screenshotDirectory",
229 const std::string &value)
240 const std::string &value)
251 (*i)->optionChanged(key);
258 const Options::const_iterator iter =
mOptions.find(key);
260 ? atoi(iter->second.c_str()) + 1 : 1);
264 const std::string &value)
270 const std::string &deflt)
const
273 const Options::const_iterator iter =
mOptions.find(key);
274 return ((iter !=
mOptions.end()) ? iter->second : deflt);
278 const int deflt)
const
281 const Options::const_iterator iter =
mOptions.find(key);
282 return (iter !=
mOptions.end()) ? atoi(iter->second.c_str()) : deflt;
286 const int deflt)
const
289 const Options::const_iterator iter =
mOptions.find(key);
290 return (iter !=
mOptions.end()) ? atoi(iter->second.c_str()) : deflt;
294 const bool deflt)
const
297 const Options::const_iterator iter =
mOptions.find(key);
299 return atoi(iter->second.c_str()) != 0 ? true :
false;
304 const unsigned deflt)
const
307 const Options::const_iterator iter =
mOptions.find(key);
309 atol(iter->second.c_str())) : deflt;
313 const double deflt)
const
316 const Options::const_iterator iter =
mOptions.find(key);
317 return (iter !=
mOptions.end()) ? atof(iter->second.c_str()) : deflt;
322 for (ConfigurationList::const_iterator
334 for (std::map<std::string, ConfigurationList>::const_iterator
380 for (DefaultsData::const_iterator iter =
mDefaultsData.begin();
407 int defaultValue = 0;
408 const Options::const_iterator iter =
mOptions.find(key);
411 const DefaultsData::const_iterator itdef
414 if (itdef !=
mDefaultsData.end() && (itdef->second !=
nullptr))
421 defaultValue = (
static_cast<const IntData*
>(
426 defaultValue = atoi((
static_cast<const StringData*
>(
427 data))->getData().c_str());
445 "%s: No integer value in registry for key %s",
452 defaultValue = atoi(iter->second.c_str());
460 int defaultValue = 0;
461 const DefaultsData::const_iterator itdef =
mDefaultsData.find(key);
464 reportAlways(
"%s: No integer value in registry for key %s",
471 if (
data !=
nullptr &&
474 defaultValue = (
static_cast<const IntData*
>(
479 reportAlways(
"%s: No integer value in registry for key %s",
491 std::string defaultValue;
492 const Options::const_iterator iter =
mOptions.find(key);
495 const DefaultsData::const_iterator
499 (itdef->second !=
nullptr))
506 defaultValue = (
static_cast<const StringData*
>(
529 reportAlways(
"%s: No string value in registry for key %s",
536 defaultValue = iter->second;
545 float defaultValue = 0.0F;
546 const Options::const_iterator iter =
mOptions.find(key);
549 const DefaultsData::const_iterator itdef
553 (itdef->second !=
nullptr))
560 defaultValue =
static_cast<float>(
565 defaultValue =
static_cast<float>(atof((
567 data))->getData().c_str()));
578 defaultValue =
static_cast<float>((
585 reportAlways(
"%s: No float value in registry for key %s",
592 defaultValue =
static_cast<float>(atof(iter->second.c_str()));
600 bool defaultValue =
false;
601 const Options::const_iterator iter =
mOptions.find(key);
604 const DefaultsData::const_iterator itdef
608 (itdef->second !=
nullptr))
615 defaultValue = (
static_cast<const BoolData*
>(
620 if ((
static_cast<const IntData*
>(
data))->getData() != 0)
623 defaultValue =
false;
628 data))->getData() !=
"0")
634 defaultValue =
false;
640 data))->getData()) != 0)
646 defaultValue =
false;
653 "%s: No boolean value in registry for key %s",
669 bool defaultValue =
false;
670 const DefaultsData::const_iterator itdef =
mDefaultsData.find(key);
674 reportAlways(
"%s: No boolean value in registry for key %s",
681 if (
data !=
nullptr &&
684 defaultValue = (
static_cast<const BoolData*
>(
data))->getData();
688 reportAlways(
"%s: No boolean value in registry for key %s",
703 if (parentNode ==
nullptr)
708 if (xmlNameEqual(node,
"list"))
712 "name", std::string());
716 if (xmlNameEqual(subnode, name.c_str()) &&
717 xmlTypeEqual(subnode, XML_ELEMENT_NODE))
725 else if (xmlNameEqual(node,
"option"))
729 "name", std::string());
733 "value", std::string());
754 logger->
log(
"Warning: No configuration file (%s)",
766 logger->
log(
"Warning: No configuration file (%s)",
778 logger->
log(
"Couldn't open configuration file: %s", filename.c_str());
782 XmlNodeConstPtrConst rootNode = doc.
rootNode();
784 if ((rootNode ==
nullptr) || !xmlNameEqual(rootNode,
"configuration"))
786 logger->
log(
"Warning: No configuration file (%s)", filename.c_str());
802 XmlNodeConstPtrConst rootNode = doc.
rootNode();
804 if ((rootNode ==
nullptr) || !xmlNameEqual(rootNode,
"configuration"))
820 if (optionsCount.find(i->first) == optionsCount.end())
821 logger->
log(
"unused configuration option: " + i->first);
825 XmlTextWriterStartElement(writer,
"option");
826 XmlTextWriterWriteAttribute(writer,
"name", i->first.c_str());
827 XmlTextWriterWriteAttribute(writer,
"value", i->second.c_str());
828 XmlTextWriterEndElement(writer);
831 for (std::map<std::string, ConfigurationList>::const_iterator
833 it != it_fend; ++ it)
835 const char *
const name = it->first.c_str();
837 XmlTextWriterStartElement(writer,
"list");
838 XmlTextWriterWriteAttribute(writer,
"name", name);
841 FOR_EACH (ConfigurationList::const_iterator, elt_it, it->second)
843 XmlTextWriterStartElement(writer, name);
844 if (*elt_it !=
nullptr)
845 (*elt_it)->writeToXML(writer);
846 XmlTextWriterEndElement(writer);
849 XmlTextWriterEndElement(writer);
870 FILE *
const testFile = fopen(
mConfigPath.c_str(),
"w");
871 if (testFile ==
nullptr)
873 reportAlways(
"Configuration::write() couldn't open %s for writing",
880 XmlTextWriterPtr writer = XmlNewTextWriterFilename(
883 if (writer ==
nullptr)
885 logger->
log1(
"Configuration::write() error while creating writer");
890 logger->
log1(
"Configuration::write() writing configuration...");
892 XmlTextWriterSetIndent(writer, 1);
893 XmlTextWriterStartDocument(writer,
nullptr,
nullptr,
nullptr);
895 XmlTextWriterStartRootElement(writer,
"configuration");
899 XmlTextWriterEndDocument(writer);
900 XmlSaveTextWriterFilename(writer,
902 XmlFreeTextWriter(writer);
920 const char *
const file,
930 logger->
log(
"detected not cleaned listener: %p, %s:%u",
931 static_cast<void*
>(
listener), file, line);
958 for (f = 0; f < 80; f ++)
960 const std::string str =
toString(f);
965 deleteKey(
"commandShortcutSymbol" + str);
#define reportAlways(...)
virtual void initFromXML(const xmlNode *const parentNode)
int getValueInt(const std::string &key, const int deflt) const
std::string getValue(const std::string &key, const std::string &deflt) const
virtual ~ConfigurationObject()
bool getValueBool(const std::string &key, const bool deflt) const
void deleteList(const std::string &name)
virtual void writeToXML(const xmlTextWriterPtr writer)
void deleteKey(const std::string &key)
virtual void setValue(const std::string &key, const std::string &value)
std::map< std::string, ConfigurationList > mContainerOptions
bool getBoolValue(const std::string &key) const
std::string getStringValue(const std::string &key) const
float getFloatValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void setValue(const std::string &key, const std::string &value)
bool resetBoolValue(const std::string &key)
void incValue(const std::string &key)
Listeners::iterator ListenerIterator
ListenerMap::iterator ListenerMapIterator
void removeListener(const std::string &key, ConfigListener *const listener)
int resetIntValue(const std::string &key)
std::list< ConfigListener * > Listeners
void setSilent(const std::string &key, const std::string &value)
void removeListeners(ConfigListener *const listener)
void init(const std::string &filename, const UseVirtFs useResManager, const SkipError skipError)
DefaultsData mDefaultsData
Defaults of value for a given key.
int getIntValue(const std::string &key) const
void log(const char *const log_text,...)
void log1(const char *const log_text)
Configuration serverConfig
const std::string unusedKeys[]
#define FOR_EACH(type, iter, array)
#define for_each_xml_child_node(var, parent)
std::string toString(T const &value)
converts any type to a string
bool existsLocal(const std::string &path)
bool remove(const std::string &filename)
bool exists(std::string name)
int getProperty(const xmlNodePtr node, const char *const name, int def)
ItemOptionDb::OptionInfos mOptions
std::string getRealPath(const std::string &str)
#define BLOCK_START(name)
const bool SkipError_false
std::map< std::string, int > StringIntMap
std::string getFileDir(const std::string &path)
bool getBoolFromString(const std::string &text)
const bool UseVirtFs_false
const bool UseVirtFs_true