Add a method to ConfigTag to help with retrieving a single character.

This commit is contained in:
Sadie Powell 2022-04-10 23:43:43 +01:00
parent a3864dabc7
commit 79b1c44721
4 changed files with 14 additions and 2 deletions

View File

@ -54,6 +54,8 @@ class CoreExport ConfigTag : public refcountbase
double getFloat(const std::string& key, double def, double min = DBL_MIN, double max = DBL_MAX);
/** Get the value of an option, using def if it does not exist */
bool getBool(const std::string& key, bool def = false);
/** Get the value of an option, using def if it does not exist */
unsigned char getCharacter(const std::string& key, unsigned char def = '\0');
/** Get the value in seconds of a duration that is in the user-friendly "1h2m3s" format,
* using a default value if it does not exist or is out of bounds.

View File

@ -755,6 +755,16 @@ bool ConfigTag::getBool(const std::string &key, bool def)
return def;
}
unsigned char ConfigTag::getCharacter(const std::string &key, unsigned char def)
{
std::string result;
if (!readString(key, result) || result.size() != 1)
return def;
return result[0];
}
std::string ConfigTag::getTagLocation()
{
return src_name + ":" + ConvToStr(src_line);

View File

@ -113,7 +113,7 @@ class ModuleOjoin : public Module
public:
ModuleOjoin()
: np(this, ServerInstance->Config->ConfValue("ojoin")->getString("prefix").c_str()[0])
: np(this, ServerInstance->Config->ConfValue("ojoin")->getCharacter("prefix"))
, mycommand(this, np)
{
}

View File

@ -37,7 +37,7 @@ class OperPrefixMode : public PrefixMode
OperPrefixMode(Module* Creator)
: PrefixMode(Creator, "operprefix", 'y', OPERPREFIX_VALUE)
{
prefix = ServerInstance->Config->ConfValue("operprefix")->getString("prefix", "!", 1, 1)[0];
prefix = ServerInstance->Config->ConfValue("operprefix")->getCharacter("prefix", '!');
ranktoset = ranktounset = UINT_MAX;
}
};