mirror of
https://github.com/anope/anope.git
synced 2026-07-08 00:03:13 +02:00
Rewrote the config reader to better handle invalid configs.
This prevents Anope from exploding when /os reload has errors.
This commit is contained in:
@@ -26,7 +26,7 @@ class BadwordsListCallback : public NumberList
|
||||
~BadwordsListCallback()
|
||||
{
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
@@ -37,7 +37,7 @@ class BadwordsListCallback : public NumberList
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
|
||||
}
|
||||
|
||||
DoList(u, ci, Number - 1, ci->GetBadWord(Number - 1));
|
||||
@@ -45,7 +45,7 @@ class BadwordsListCallback : public NumberList
|
||||
|
||||
static void DoList(User *u, ChannelInfo *ci, unsigned Number, BadWord *bw)
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : "")));
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : "")));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -62,11 +62,11 @@ class BadwordsDelCallback : public NumberList
|
||||
~BadwordsDelCallback()
|
||||
{
|
||||
if (!Deleted)
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
|
||||
else if (Deleted == 1)
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED_ONE, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_DELETED_ONE, ci->name.c_str());
|
||||
else
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED_SEVERAL, Deleted, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_DELETED_SEVERAL, Deleted, ci->name.c_str());
|
||||
}
|
||||
|
||||
void HandleNumber(unsigned Number)
|
||||
@@ -85,7 +85,7 @@ class CommandBSBadwords : public Command
|
||||
CommandReturn DoList(User *u, ChannelInfo *ci, const Anope::string &word)
|
||||
{
|
||||
if (!ci->GetBadWordCount())
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_EMPTY, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_LIST_EMPTY, ci->name.c_str());
|
||||
else if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos)
|
||||
{
|
||||
BadwordsListCallback list(u, ci, word);
|
||||
@@ -105,14 +105,14 @@ class CommandBSBadwords : public Command
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name.c_str());
|
||||
}
|
||||
|
||||
BadwordsListCallback::DoList(u, ci, i, bw);
|
||||
}
|
||||
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_NO_MATCH, ci->name.c_str());
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -139,9 +139,9 @@ class CommandBSBadwords : public Command
|
||||
realword = word.substr(0, pos);
|
||||
}
|
||||
|
||||
if (ci->GetBadWordCount() >= Config.BSBadWordsMax)
|
||||
if (ci->GetBadWordCount() >= Config->BSBadWordsMax)
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_REACHED_LIMIT, Config.BSBadWordsMax);
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_REACHED_LIMIT, Config->BSBadWordsMax);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
@@ -149,16 +149,16 @@ class CommandBSBadwords : public Command
|
||||
{
|
||||
BadWord *bw = ci->GetBadWord(i);
|
||||
|
||||
if (!bw->word.empty() && ((Config.BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config.BSCaseSensitive && realword.equals_ci(bw->word))))
|
||||
if (!bw->word.empty() && ((Config->BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config->BSCaseSensitive && realword.equals_ci(bw->word))))
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_ALREADY_EXISTS, bw->word.c_str(), ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_ALREADY_EXISTS, bw->word.c_str(), ci->name.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
}
|
||||
|
||||
ci->AddBadWord(realword, type);
|
||||
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_ADDED, realword.c_str(), ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_ADDED, realword.c_str(), ci->name.c_str());
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
@@ -186,13 +186,13 @@ class CommandBSBadwords : public Command
|
||||
|
||||
if (i == end)
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_NOT_FOUND, word.c_str(), ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_NOT_FOUND, word.c_str(), ci->name.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
ci->EraseBadWord(i);
|
||||
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DELETED, badword->word.c_str(), ci->name.c_str());
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_DELETED, badword->word.c_str(), ci->name.c_str());
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -201,7 +201,7 @@ class CommandBSBadwords : public Command
|
||||
CommandReturn DoClear(User *u, ChannelInfo *ci)
|
||||
{
|
||||
ci->ClearBadWords();
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_CLEAR);
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_CLEAR);
|
||||
return MOD_CONT;
|
||||
}
|
||||
public:
|
||||
@@ -227,13 +227,13 @@ class CommandBSBadwords : public Command
|
||||
|
||||
if (!check_access(u, ci, CA_BADWORDS) && (!need_args || !u->Account()->HasPriv("botserv/administration")))
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, ACCESS_DENIED);
|
||||
notice_lang(Config->s_BotServ, u, ACCESS_DENIED);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, BOT_BADWORDS_DISABLED);
|
||||
notice_lang(Config->s_BotServ, u, BOT_BADWORDS_DISABLED);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
@@ -253,18 +253,18 @@ class CommandBSBadwords : public Command
|
||||
|
||||
bool OnHelp(User *u, const Anope::string &subcommand)
|
||||
{
|
||||
notice_help(Config.s_BotServ, u, BOT_HELP_BADWORDS);
|
||||
notice_help(Config->s_BotServ, u, BOT_HELP_BADWORDS);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const Anope::string &subcommand)
|
||||
{
|
||||
syntax_error(Config.s_BotServ, u, "BADWORDS", BOT_BADWORDS_SYNTAX);
|
||||
syntax_error(Config->s_BotServ, u, "BADWORDS", BOT_BADWORDS_SYNTAX);
|
||||
}
|
||||
|
||||
void OnServHelp(User *u)
|
||||
{
|
||||
notice_lang(Config.s_BotServ, u, BOT_HELP_CMD_BADWORDS);
|
||||
notice_lang(Config->s_BotServ, u, BOT_HELP_CMD_BADWORDS);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user