mirror of
https://github.com/anope/anope.git
synced 2026-06-29 15:36:38 +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:
+41
-41
@@ -26,11 +26,11 @@ class ExceptionDelCallback : public NumberList
|
||||
~ExceptionDelCallback()
|
||||
{
|
||||
if (!Deleted)
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NO_MATCH);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_NO_MATCH);
|
||||
else if (Deleted == 1)
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_DELETED_ONE);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_DELETED_ONE);
|
||||
else
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_DELETED_SEVERAL, Deleted);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_DELETED_SEVERAL, Deleted);
|
||||
}
|
||||
|
||||
virtual void HandleNumber(unsigned Number)
|
||||
@@ -70,8 +70,8 @@ class ExceptionListCallback : public NumberList
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_COLHEAD);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_COLHEAD);
|
||||
}
|
||||
|
||||
DoList(u, Number - 1);
|
||||
@@ -82,7 +82,7 @@ class ExceptionListCallback : public NumberList
|
||||
if (index >= exceptions.size())
|
||||
return;
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_FORMAT, index + 1, exceptions[index]->limit, exceptions[index]->mask.c_str());
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_FORMAT, index + 1, exceptions[index]->limit, exceptions[index]->mask.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -101,7 +101,7 @@ class ExceptionViewCallback : public ExceptionListCallback
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
}
|
||||
|
||||
DoList(u, Number - 1);
|
||||
@@ -121,7 +121,7 @@ class ExceptionViewCallback : public ExceptionListCallback
|
||||
|
||||
Anope::string expirebuf = expire_left(u->Account(), exceptions[index]->expires);
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_VIEW_FORMAT, index + 1, exceptions[index]->mask.c_str(), !exceptions[index]->who.empty() ? exceptions[index]->who.c_str() : "<unknown>", timebuf, expirebuf.c_str(), exceptions[index]->limit, exceptions[index]->reason.c_str());
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_VIEW_FORMAT, index + 1, exceptions[index]->mask.c_str(), !exceptions[index]->who.empty() ? exceptions[index]->who.c_str() : "<unknown>", timebuf, expirebuf.c_str(), exceptions[index]->limit, exceptions[index]->reason.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -134,18 +134,18 @@ class CommandOSSession : public Command
|
||||
Anope::string param = params[1];
|
||||
|
||||
if ((mincount = (param.is_number_only() ? convertTo<int>(param) : 0)) <= 1)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_INVALID_THRESHOLD);
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_INVALID_THRESHOLD);
|
||||
else
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_HEADER, mincount);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_COLHEAD);
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_LIST_HEADER, mincount);
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_LIST_COLHEAD);
|
||||
|
||||
for (session_map::const_iterator it = SessionList.begin(), it_end = SessionList.end(); it != it_end; ++it)
|
||||
{
|
||||
Session *session = it->second;
|
||||
|
||||
if (session->count >= mincount)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_LIST_FORMAT, session->count, session->host.c_str());
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_LIST_FORMAT, session->count, session->host.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,11 +158,11 @@ class CommandOSSession : public Command
|
||||
Session *session = findsession(param);
|
||||
|
||||
if (!session)
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_NOT_FOUND, param.c_str());
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_NOT_FOUND, param.c_str());
|
||||
else
|
||||
{
|
||||
Exception *exception = find_host_exception(param);
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_VIEW_FORMAT, param.c_str(), session->count, exception ? exception-> limit : Config.DefSessionLimit);
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_VIEW_FORMAT, param.c_str(), session->count, exception ? exception-> limit : Config->DefSessionLimit);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -176,9 +176,9 @@ class CommandOSSession : public Command
|
||||
{
|
||||
Anope::string cmd = params[0];
|
||||
|
||||
if (!Config.LimitSessions)
|
||||
if (!Config->LimitSessions)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_SESSION_DISABLED);
|
||||
notice_lang(Config->s_OperServ, u, OPER_SESSION_DISABLED);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
@@ -193,18 +193,18 @@ class CommandOSSession : public Command
|
||||
|
||||
bool OnHelp(User *u, const Anope::string &subcommand)
|
||||
{
|
||||
notice_help(Config.s_OperServ, u, OPER_HELP_SESSION);
|
||||
notice_help(Config->s_OperServ, u, OPER_HELP_SESSION);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const Anope::string &subcommand)
|
||||
{
|
||||
syntax_error(Config.s_OperServ, u, "SESSION", OPER_SESSION_LIST_SYNTAX);
|
||||
syntax_error(Config->s_OperServ, u, "SESSION", OPER_SESSION_LIST_SYNTAX);
|
||||
}
|
||||
|
||||
void OnServHelp(User *u)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SESSION);
|
||||
notice_lang(Config->s_OperServ, u, OPER_HELP_CMD_SESSION);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -242,10 +242,10 @@ class CommandOSException : public Command
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
time_t expires = !expiry.empty() ? dotime(expiry) : Config.ExceptionExpiry;
|
||||
time_t expires = !expiry.empty() ? dotime(expiry) : Config->ExceptionExpiry;
|
||||
if (expires < 0)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, BAD_EXPIRY_TIME);
|
||||
notice_lang(Config->s_OperServ, u, BAD_EXPIRY_TIME);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else if (expires > 0)
|
||||
@@ -253,26 +253,26 @@ class CommandOSException : public Command
|
||||
|
||||
int limit = !limitstr.empty() && limitstr.is_number_only() ? convertTo<int>(limitstr) : -1;
|
||||
|
||||
if (limit < 0 || limit > static_cast<int>(Config.MaxSessionLimit))
|
||||
if (limit < 0 || limit > static_cast<int>(Config->MaxSessionLimit))
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_INVALID_LIMIT, Config.MaxSessionLimit);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_INVALID_LIMIT, Config->MaxSessionLimit);
|
||||
return MOD_CONT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mask.find('!') == Anope::string::npos || mask.find('@') == Anope::string::npos)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_INVALID_HOSTMASK);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_INVALID_HOSTMASK);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
x = exception_add(u, mask, limit, reason, u->nick, expires);
|
||||
|
||||
if (x == 1)
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_ADDED, mask.c_str(), limit);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_ADDED, mask.c_str(), limit);
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
notice_lang(Config->s_OperServ, u, READ_ONLY_MODE);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -300,15 +300,15 @@ class CommandOSException : public Command
|
||||
if (mask.equals_ci(exceptions[i]->mask))
|
||||
{
|
||||
ExceptionDelCallback::DoDel(u, i);
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_DELETED, mask.c_str());
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_DELETED, mask.c_str());
|
||||
break;
|
||||
}
|
||||
if (i == end)
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NOT_FOUND, mask.c_str());
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_NOT_FOUND, mask.c_str());
|
||||
}
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
notice_lang(Config->s_OperServ, u, READ_ONLY_MODE);
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
@@ -334,10 +334,10 @@ class CommandOSException : public Command
|
||||
exceptions[n1] = exceptions[n2];
|
||||
exceptions[n2] = temp;
|
||||
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_MOVED, exceptions[n1]->mask.c_str(), n1 + 1, n2 + 1);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_MOVED, exceptions[n1]->mask.c_str(), n1 + 1, n2 + 1);
|
||||
|
||||
if (readonly)
|
||||
notice_lang(Config.s_OperServ, u, READ_ONLY_MODE);
|
||||
notice_lang(Config->s_OperServ, u, READ_ONLY_MODE);
|
||||
}
|
||||
else
|
||||
this->OnSyntaxError(u, "MOVE");
|
||||
@@ -365,15 +365,15 @@ class CommandOSException : public Command
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_COLHEAD);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_COLHEAD);
|
||||
}
|
||||
|
||||
ExceptionListCallback::DoList(u, i);
|
||||
}
|
||||
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NO_MATCH);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_NO_MATCH);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -399,14 +399,14 @@ class CommandOSException : public Command
|
||||
if (!SentHeader)
|
||||
{
|
||||
SentHeader = true;
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_LIST_HEADER);
|
||||
}
|
||||
|
||||
ExceptionViewCallback::DoList(u, i);
|
||||
}
|
||||
|
||||
if (!SentHeader)
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_NO_MATCH);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_NO_MATCH);
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
@@ -420,9 +420,9 @@ class CommandOSException : public Command
|
||||
{
|
||||
Anope::string cmd = params[0];
|
||||
|
||||
if (!Config.LimitSessions)
|
||||
if (!Config->LimitSessions)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_EXCEPTION_DISABLED);
|
||||
notice_lang(Config->s_OperServ, u, OPER_EXCEPTION_DISABLED);
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
@@ -443,18 +443,18 @@ class CommandOSException : public Command
|
||||
|
||||
bool OnHelp(User *u, const Anope::string &subcommand)
|
||||
{
|
||||
notice_help(Config.s_OperServ, u, OPER_HELP_EXCEPTION);
|
||||
notice_help(Config->s_OperServ, u, OPER_HELP_EXCEPTION);
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(User *u, const Anope::string &subcommand)
|
||||
{
|
||||
syntax_error(Config.s_OperServ, u, "EXCEPTION", OPER_EXCEPTION_SYNTAX);
|
||||
syntax_error(Config->s_OperServ, u, "EXCEPTION", OPER_EXCEPTION_SYNTAX);
|
||||
}
|
||||
|
||||
void OnServHelp(User *u)
|
||||
{
|
||||
notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_EXCEPTION);
|
||||
notice_lang(Config->s_OperServ, u, OPER_HELP_CMD_EXCEPTION);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user