diff options
author | Adam <Adam@anope.org> | 2011-02-04 22:10:39 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-02-04 22:10:39 -0500 |
commit | b2e52553a722e3d26606490b81097c82e36ecf57 (patch) | |
tree | fdd405aa3e05cac72a1fbacff651ed980adf34b0 | |
parent | 032c30dd5dc43e61939905ab62f1d6ca21741cf6 (diff) |
Merge 83556667fd7c
-rw-r--r-- | modules/core/bs_kick.cpp | 159 | ||||
-rw-r--r-- | modules/core/cs_access.cpp | 30 | ||||
-rw-r--r-- | modules/core/cs_list.cpp | 29 | ||||
-rw-r--r-- | modules/core/hs_list.cpp | 8 | ||||
-rw-r--r-- | modules/core/ns_alist.cpp | 10 | ||||
-rw-r--r-- | modules/core/ns_list.cpp | 26 | ||||
-rw-r--r-- | modules/core/os_defcon.cpp | 7 | ||||
-rw-r--r-- | modules/core/os_news.cpp | 21 | ||||
-rw-r--r-- | modules/core/os_session.cpp | 23 | ||||
-rw-r--r-- | modules/core/os_set.cpp | 12 |
10 files changed, 196 insertions, 129 deletions
diff --git a/modules/core/bs_kick.cpp b/modules/core/bs_kick.cpp index 380236a43..c2065fc47 100644 --- a/modules/core/bs_kick.cpp +++ b/modules/core/bs_kick.cpp @@ -51,13 +51,14 @@ class CommandBSKick : public Command { if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_BADWORDS] = convertTo<int16>(ttb, error, false); - /* Only error if errno returns ERANGE or EINVAL or we are less then 0 - TSL */ - if (!error.empty() || ci->ttb[TTB_BADWORDS] < 0) + try + { + ci->ttb[TTB_BADWORDS] = convertTo<int16>(ttb); + if (ci->ttb[TTB_BADWORDS] < 0) + throw CoreException(); + } + catch (const CoreException &) { - /* leaving the debug behind since we might want to know what these are */ - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BADWORDS]; /* reset the value back to 0 - TSL */ ci->ttb[TTB_BADWORDS] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); @@ -66,6 +67,7 @@ class CommandBSKick : public Command } else ci->ttb[TTB_BADWORDS] = 0; + ci->botflags.SetFlag(BS_KICK_BADWORDS); if (ci->ttb[TTB_BADWORDS]) u->SendMessage(BotServ, BOT_KICK_BADWORDS_ON_BAN, ci->ttb[TTB_BADWORDS]); @@ -84,11 +86,14 @@ class CommandBSKick : public Command { if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_BOLDS] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_BOLDS] < 0) + try + { + ci->ttb[TTB_BOLDS] = convertTo<int16>(ttb); + if (ci->ttb[TTB_BOLDS] < 0) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BOLDS]; ci->ttb[TTB_BOLDS] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -117,11 +122,14 @@ class CommandBSKick : public Command if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_CAPS] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_CAPS] < 0) + try + { + ci->ttb[TTB_CAPS] = convertTo<int16>(ttb); + if (ci->ttb[TTB_CAPS] < 0) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_CAPS]; ci->ttb[TTB_CAPS] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -130,17 +138,21 @@ class CommandBSKick : public Command else ci->ttb[TTB_CAPS] = 0; - if (min.empty()) - ci->capsmin = 10; - else - ci->capsmin = min.is_number_only() ? convertTo<int16>(min) : 10; + ci->capsmin = 10; + try + { + ci->capsmin = convertTo<int16>(min); + } + catch (const CoreException &) { } if (ci->capsmin < 1) ci->capsmin = 10; - if (percent.empty()) - ci->capspercent = 25; - else - ci->capspercent = percent.is_number_only() ? convertTo<int16>(percent) : 25; + ci->capspercent = 25; + try + { + ci->capspercent = convertTo<int16>(percent); + } + catch (const CoreException &) { } if (ci->capspercent < 1 || ci->capspercent > 100) ci->capspercent = 25; @@ -162,11 +174,14 @@ class CommandBSKick : public Command { if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_COLORS] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_COLORS] < 0) + try + { + ci->ttb[TTB_COLORS] = convertTo<int16>(ttb); + if (ci->ttb[TTB_COLORS] < 1) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_COLORS]; ci->ttb[TTB_COLORS] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -174,6 +189,7 @@ class CommandBSKick : public Command } else ci->ttb[TTB_COLORS] = 0; + ci->botflags.SetFlag(BS_KICK_COLORS); if (ci->ttb[TTB_COLORS]) u->SendMessage(BotServ, BOT_KICK_COLORS_ON_BAN, ci->ttb[TTB_COLORS]); @@ -195,11 +211,14 @@ class CommandBSKick : public Command if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_FLOOD] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_FLOOD] < 0) + try + { + ci->ttb[TTB_FLOOD] = convertTo<int16>(ttb); + if (ci->ttb[TTB_FLOOD] < 1) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_FLOOD]; ci->ttb[TTB_FLOOD] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -208,19 +227,25 @@ class CommandBSKick : public Command else ci->ttb[TTB_FLOOD] = 0; - if (lines.empty()) - ci->floodlines = 6; - else - ci->floodlines = lines.is_number_only() ? convertTo<int16>(lines) : 6; + ci->floodlines = 6; + try + { + ci->floodlines = convertTo<int16>(lines); + } + catch (const CoreException &) { } if (ci->floodlines < 2) ci->floodlines = 6; - if (secs.empty()) - ci->floodsecs = 10; - else - ci->floodsecs = secs.is_number_only() ? convertTo<int16>(secs) : 10; - if (ci->floodsecs < 1 || ci->floodsecs > Config->BSKeepData) + ci->floodsecs = 10; + try + { + ci->floodsecs = convertTo<int16>(secs); + } + catch (const CoreException &) { } + if (ci->floodsecs < 1) ci->floodsecs = 10; + if (ci->floodsecs > Config->BSKeepData) + ci->floodsecs = Config->BSKeepData; ci->botflags.SetFlag(BS_KICK_FLOOD); if (ci->ttb[TTB_FLOOD]) @@ -242,11 +267,14 @@ class CommandBSKick : public Command if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_REPEAT] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_REPEAT] < 0) + try + { + ci->ttb[TTB_REPEAT] = convertTo<int16>(ttb); + if (ci->ttb[TTB_REPEAT]) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REPEAT]; ci->ttb[TTB_REPEAT] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -255,10 +283,12 @@ class CommandBSKick : public Command else ci->ttb[TTB_REPEAT] = 0; - if (times.empty()) - ci->repeattimes = 3; - else - ci->repeattimes = times.is_number_only() ? convertTo<int16>(times) : 3; + ci->repeattimes = 3; + try + { + ci->repeattimes = convertTo<int16>(times); + } + catch (const CoreException &) { } if (ci->repeattimes < 2) ci->repeattimes = 3; @@ -280,11 +310,14 @@ class CommandBSKick : public Command { if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_REVERSES] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_REVERSES] < 0) + try + { + ci->ttb[TTB_REVERSES] = convertTo<int16>(ttb); + if (ci->ttb[TTB_REVERSES] < 0) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REVERSES]; ci->ttb[TTB_REVERSES] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -310,11 +343,14 @@ class CommandBSKick : public Command { if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_UNDERLINES] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_UNDERLINES] < 0) + try + { + ci->ttb[TTB_UNDERLINES] = convertTo<int16>(ttb); + if (ci->ttb[TTB_REVERSES] < 0) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_UNDERLINES]; ci->ttb[TTB_UNDERLINES] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -322,6 +358,7 @@ class CommandBSKick : public Command } else ci->ttb[TTB_UNDERLINES] = 0; + ci->botflags.SetFlag(BS_KICK_UNDERLINES); if (ci->ttb[TTB_UNDERLINES]) u->SendMessage(BotServ, BOT_KICK_UNDERLINES_ON_BAN, ci->ttb[TTB_UNDERLINES]); @@ -340,11 +377,14 @@ class CommandBSKick : public Command { if (!ttb.empty()) { - Anope::string error; - ci->ttb[TTB_ITALICS] = convertTo<int16>(ttb, error, false); - if (!error.empty() || ci->ttb[TTB_ITALICS] < 0) + try + { + ci->ttb[TTB_ITALICS] = convertTo<int16>(ttb); + if (ci->ttb[TTB_ITALICS] < 0) + throw CoreException(); + } + catch (const CoreException &) { - Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_ITALICS]; ci->ttb[TTB_ITALICS] = 0; u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; @@ -352,6 +392,7 @@ class CommandBSKick : public Command } else ci->ttb[TTB_ITALICS] = 0; + ci->botflags.SetFlag(BS_KICK_ITALICS); if (ci->ttb[TTB_ITALICS]) u->SendMessage(BotServ, BOT_KICK_ITALICS_ON_BAN, ci->ttb[TTB_ITALICS]); diff --git a/modules/core/cs_access.cpp b/modules/core/cs_access.cpp index 9f77baead..9c180fbd1 100644 --- a/modules/core/cs_access.cpp +++ b/modules/core/cs_access.cpp @@ -162,9 +162,15 @@ class CommandCSAccess : public Command CommandReturn DoAdd(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { Anope::string nick = params[2]; - int level = params[3].is_number_only() ? convertTo<int>(params[3]) : ACCESS_INVALID; int ulev = get_access(u, ci); + int level = ACCESS_INVALID; + try + { + level = convertTo<int>(params[3]); + } + catch (const CoreException &) { } + if (level >= ulev && !u->Account()->HasPriv("chanserv/access/modify")) { u->SendMessage(ChanServ, ACCESS_DENIED); @@ -456,20 +462,24 @@ class CommandCSLevels : public Command Anope::string what = params[2]; Anope::string lev = params[3]; - Anope::string error; - int level = (lev.is_number_only() ? convertTo<int>(lev, error, false) : 0); - if (!lev.is_number_only()) - error = "1"; + int level = 0; if (lev.equals_ci("FOUNDER")) - { level = ACCESS_FOUNDER; - error.clear(); + else + { + try + { + level = convertTo<int>(lev); + } + catch (const CoreException &) + { + this->OnSyntaxError(u, "SET"); + return MOD_CONT; + } } - if (!error.empty()) - this->OnSyntaxError(u, "SET"); - else if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER) + if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER) u->SendMessage(ChanServ, CHAN_LEVELS_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); else { diff --git a/modules/core/cs_list.cpp b/modules/core/cs_list.cpp index 8654647fe..76b1717d3 100644 --- a/modules/core/cs_list.cpp +++ b/modules/core/cs_list.cpp @@ -39,34 +39,21 @@ public: if (pattern[0] == '#') { - Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */ - if (tmp.empty()) - { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); - return MOD_CONT; - } - if (!tmp.is_number_only()) - { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); - return MOD_CONT; - } - from = convertTo<int>(tmp); - tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */ - if (tmp.empty()) + Anope::string n1 = myStrGetToken(pattern.substr(1), '-', 0), /* Read FROM out */ + n2 = myStrGetToken(pattern, '-', 1); + + try { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); - return MOD_CONT; + from = convertTo<int>(n1); + to = convertTo<int>(n2); } - if (!tmp.is_number_only()) + catch (const CoreException &) { u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); return MOD_CONT; } - to = convertTo<int>(tmp); + pattern = "*"; } diff --git a/modules/core/hs_list.cpp b/modules/core/hs_list.cpp index c0408844d..755914813 100644 --- a/modules/core/hs_list.cpp +++ b/modules/core/hs_list.cpp @@ -45,8 +45,12 @@ class CommandHSList : public Command u->SendMessage(HostServ, LIST_INCORRECT_RANGE); return MOD_CONT; } - from = convertTo<int>(key.substr(1, tmp - 1)); - to = convertTo<int>(key.substr(tmp + 1)); + try + { + from = convertTo<int>(key.substr(1, tmp - 1)); + to = convertTo<int>(key.substr(tmp + 1)); + } + catch (const CoreException &) { } } } diff --git a/modules/core/ns_alist.cpp b/modules/core/ns_alist.cpp index 16a30726d..3f1351e81 100644 --- a/modules/core/ns_alist.cpp +++ b/modules/core/ns_alist.cpp @@ -35,7 +35,6 @@ class CommandNSAList : public Command NickAlias *na; - int min_level = 0; int is_servadmin = u->Account()->IsServicesOper(); unsigned lev_param = 0; @@ -60,6 +59,7 @@ class CommandNSAList : public Command Anope::string lev = params.size() > lev_param ? params[lev_param] : ""; /* if a level was given, make sure it's an int for later */ + int min_level = ACCESS_INVALID; if (!lev.empty()) { if (lev.equals_ci("FOUNDER")) @@ -73,7 +73,13 @@ class CommandNSAList : public Command else if (lev.equals_ci("VOP")) min_level = ACCESS_VOP; else - min_level = lev.is_number_only() ? convertTo<int>(lev) : ACCESS_INVALID; + { + try + { + min_level = convertTo<int>(lev); + } + catch (const CoreException &) { } + } } if (!na) diff --git a/modules/core/ns_list.cpp b/modules/core/ns_list.cpp index 347d21b9a..39b84de64 100644 --- a/modules/core/ns_list.cpp +++ b/modules/core/ns_list.cpp @@ -55,30 +55,20 @@ class CommandNSList : public Command if (pattern[0] == '#') { - Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */ - if (tmp.empty()) - { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - if (!tmp.is_number_only()) - { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - from = convertTo<int>(tmp); - tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */ - if (tmp.empty()) + Anope::string n1 = myStrGetToken(pattern.substr(1), '-', 0), /* Read FROM out */ + n2 = myStrGetToken(pattern, '-', 1); + + try { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); - return MOD_CONT; + from = convertTo<int>(n1); + to = convertTo<int>(n2); } - if (!tmp.is_number_only()) + catch (const CoreException &) { u->SendMessage(NickServ, LIST_INCORRECT_RANGE); return MOD_CONT; } - to = convertTo<int>(tmp); + pattern = "*"; } diff --git a/modules/core/os_defcon.cpp b/modules/core/os_defcon.cpp index 89bc2b6f0..a90cc0111 100644 --- a/modules/core/os_defcon.cpp +++ b/modules/core/os_defcon.cpp @@ -70,7 +70,12 @@ class CommandOSDefcon : public Command defcon_sendlvls(u); return MOD_CONT; } - newLevel = lvl.is_number_only() ? convertTo<int>(lvl) : 0; + + try + { + newLevel = convertTo<int>(lvl); + } + catch (const CoreException &) { } if (newLevel < 1 || newLevel > 5) { this->OnSyntaxError(u, ""); diff --git a/modules/core/os_news.cpp b/modules/core/os_news.cpp index 237d5c66b..0edb61cca 100644 --- a/modules/core/os_news.cpp +++ b/modules/core/os_news.cpp @@ -226,16 +226,21 @@ class NewsBase : public Command } if (!text.equals_ci("ALL")) { - num = text.is_pos_number_only() ? convertTo<unsigned>(text) : 0; - if (num > 0 && del_newsitem(num, type)) + try { - u->SendMessage(OperServ, msgs[MSG_DELETED], num); - for (unsigned i = 0, end = News.size(); i < end; ++i) - if (News[i]->type == type && News[i]->num > num) - --News[i]->num; + num = convertTo<unsigned>(text); + if (del_newsitem(num, type)) + { + u->SendMessage(OperServ, msgs[MSG_DELETED], num); + for (unsigned i = 0, end = News.size(); i < end; ++i) + if (News[i]->type == type && News[i]->num > num) + --News[i]->num; + return MOD_CONT; + } } - else - u->SendMessage(OperServ, msgs[MSG_DEL_NOT_FOUND], num); + catch (const CoreException &) { } + + u->SendMessage(OperServ, msgs[MSG_DEL_NOT_FOUND], num); } else { diff --git a/modules/core/os_session.cpp b/modules/core/os_session.cpp index 41d703acd..e8190ce60 100644 --- a/modules/core/os_session.cpp +++ b/modules/core/os_session.cpp @@ -125,7 +125,12 @@ class CommandOSSession : public Command { Anope::string param = params[1]; - unsigned mincount = param.is_pos_number_only() ? convertTo<unsigned>(param) : 0; + unsigned mincount = 0; + try + { + mincount = convertTo<unsigned>(param); + } + catch (const CoreException &) { } if (mincount <= 1) u->SendMessage(OperServ, OPER_SESSION_INVALID_THRESHOLD); @@ -245,7 +250,12 @@ class CommandOSException : public Command else if (expires > 0) expires += Anope::CurTime; - int limit = !limitstr.empty() && limitstr.is_number_only() ? convertTo<int>(limitstr) : -1; + int limit = -1; + try + { + limit = convertTo<int>(limitstr); + } + catch (const CoreException &) { } if (limit < 0 || limit > static_cast<int>(Config->MaxSessionLimit)) { @@ -319,8 +329,13 @@ class CommandOSException : public Command return MOD_CONT; } - n1 = n1str.is_pos_number_only() ? convertTo<int>(n1str) - 1 : -1; - n2 = n2str.is_pos_number_only() ? convertTo<int>(n2str) - 1 : -1; + n1 = n2 = -1; + try + { + n1 = convertTo<int>(n1str); + n2 = convertTo<int>(n2str); + } + catch (const CoreException &) { } if (n1 >= 0 && n1 < exceptions.size() && n2 >= 0 && n2 < exceptions.size() && n1 != n2) { diff --git a/modules/core/os_set.cpp b/modules/core/os_set.cpp index db216b410..a225e9db1 100644 --- a/modules/core/os_set.cpp +++ b/modules/core/os_set.cpp @@ -143,16 +143,20 @@ class CommandOSSet : public Command Log(LOG_ADMIN, u, this) << "DEBUG ON"; u->SendMessage(OperServ, OPER_SET_DEBUG_ON); } - else if (setting.equals_ci("OFF") || (setting[0] == '0' && setting.is_number_only() && !convertTo<int>(setting))) + else if (setting.equals_ci("OFF")) { Log(LOG_ADMIN, u, this) << "DEBUG OFF"; debug = 0; u->SendMessage(OperServ, OPER_SET_DEBUG_OFF); } - else if (setting.is_number_only() && convertTo<int>(setting) > 0) + else if (setting.is_number_only()) { - debug = convertTo<int>(setting); - Log(LOG_ADMIN, u, this) << "DEBUG " << debug; + try + { + debug = convertTo<int>(setting); + Log(LOG_ADMIN, u, this) << "DEBUG " << debug; + } + catch (const CoreException &) { } u->SendMessage(OperServ, OPER_SET_DEBUG_LEVEL, debug); } else |