summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/core/bs_kick.cpp172
-rw-r--r--modules/core/cs_access.cpp31
-rw-r--r--modules/core/cs_list.cpp18
-rw-r--r--modules/core/cs_set_bantype.cpp14
-rw-r--r--modules/core/hs_list.cpp8
-rw-r--r--modules/core/ns_alist.cpp10
-rw-r--r--modules/core/ns_list.cpp26
-rw-r--r--modules/core/os_defcon.cpp11
-rw-r--r--modules/core/os_news.cpp21
-rw-r--r--modules/core/os_session.cpp23
-rw-r--r--modules/core/os_set.cpp17
-rw-r--r--modules/extra/cs_entrymsg.cpp19
12 files changed, 231 insertions, 139 deletions
diff --git a/modules/core/bs_kick.cpp b/modules/core/bs_kick.cpp
index d37a9d990..fbb6924eb 100644
--- a/modules/core/bs_kick.cpp
+++ b/modules/core/bs_kick.cpp
@@ -52,13 +52,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- /* 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;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
@@ -67,6 +68,7 @@ class CommandBSKick : public Command
}
else
ci->ttb[TTB_BADWORDS] = 0;
+
ci->botflags.SetFlag(BS_KICK_BADWORDS);
if (ci->ttb[TTB_BADWORDS])
source.Reply(_("Bot will now kick \002bad words\002, and will place a ban after \n"
@@ -88,11 +90,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BOLDS];
ci->ttb[TTB_BOLDS] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -121,11 +126,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_CAPS];
ci->ttb[TTB_CAPS] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -134,17 +142,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 ConvertException &) { }
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 ConvertException &) { }
if (ci->capspercent < 1 || ci->capspercent > 100)
ci->capspercent = 25;
@@ -169,11 +181,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_COLORS];
ci->ttb[TTB_COLORS] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -181,6 +196,7 @@ class CommandBSKick : public Command
}
else
ci->ttb[TTB_COLORS] = 0;
+
ci->botflags.SetFlag(BS_KICK_COLORS);
if (ci->ttb[TTB_COLORS])
source.Reply(_("Bot will now kick \002colors\002, and will place a ban after %d\nkicks for the same user."), ci->ttb[TTB_COLORS]);
@@ -202,11 +218,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_FLOOD];
ci->ttb[TTB_FLOOD] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -215,19 +234,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 ConvertException &) { }
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 ConvertException &) { }
+ 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])
@@ -249,11 +274,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REPEAT];
ci->ttb[TTB_REPEAT] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -262,10 +290,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 ConvertException &) { }
if (ci->repeattimes < 2)
ci->repeattimes = 3;
@@ -290,11 +320,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REVERSES];
ci->ttb[TTB_REVERSES] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -320,11 +353,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_UNDERLINES];
ci->ttb[TTB_UNDERLINES] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -332,6 +368,7 @@ class CommandBSKick : public Command
}
else
ci->ttb[TTB_UNDERLINES] = 0;
+
ci->botflags.SetFlag(BS_KICK_UNDERLINES);
if (ci->ttb[TTB_UNDERLINES])
source.Reply(_("Bot will now kick \002underlines\002, and will place a ban after %d\nkicks for the same user."), ci->ttb[TTB_UNDERLINES]);
@@ -350,11 +387,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 ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_ITALICS];
ci->ttb[TTB_ITALICS] = 0;
source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
@@ -362,6 +402,7 @@ class CommandBSKick : public Command
}
else
ci->ttb[TTB_ITALICS] = 0;
+
ci->botflags.SetFlag(BS_KICK_ITALICS);
if (ci->ttb[TTB_ITALICS])
source.Reply(_("Bot will now kick \002italics\002, and will place a ban after\n%d kicks for the same user."), ci->ttb[TTB_ITALICS]);
@@ -380,17 +421,22 @@ class CommandBSKick : public Command
{
if (!ttb.empty())
{
- Anope::string error;
- ci->ttb[TTB_AMSGS] = convertTo<int16>(ttb, error, false);
- if (!error.empty() || ci->ttb[TTB_AMSGS] < 0)
+ try
+ {
+ ci->ttb[TTB_AMSGS] = convertTo<int16>(ttb);
+ if (ci->ttb[TTB_AMSGS] < 0)
+ throw ConvertException();
+ }
+ catch (const ConvertException &)
{
- Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_ITALICS];
ci->ttb[TTB_AMSGS] = 0;
+ source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str());
return MOD_CONT;
}
}
else
ci->ttb[TTB_AMSGS] = 0;
+
ci->botflags.SetFlag(BS_KICK_AMSGS);
if (ci->ttb[TTB_AMSGS])
source.Reply(_("Bot will now kick for \002amsgs\002, and will place a ban after %d\nkicks for the same user."), ci->ttb[TTB_AMSGS]);
diff --git a/modules/core/cs_access.cpp b/modules/core/cs_access.cpp
index 3ae5693d3..3811ffbfd 100644
--- a/modules/core/cs_access.cpp
+++ b/modules/core/cs_access.cpp
@@ -169,7 +169,13 @@ class CommandCSAccess : public Command
ChannelInfo *ci = source.ci;
Anope::string mask = params[2];
- int level = params[3].is_number_only() ? convertTo<int>(params[3]) : ACCESS_INVALID;
+ int level = ACCESS_INVALID;
+
+ try
+ {
+ level = convertTo<int>(params[3]);
+ }
+ catch (const ConvertException &) { }
ChanAccess *u_access = ci->GetAccess(u);
int16 u_level = u_access ? u_access->level : 0;
@@ -536,20 +542,25 @@ class CommandCSLevels : public Command
const Anope::string &what = params[2];
const 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;
if (lev.equals_ci("FOUNDER"))
- {
level = ACCESS_FOUNDER;
- error.clear();
+ else
+ {
+ level = 1;
+ try
+ {
+ level = convertTo<int>(lev);
+ }
+ catch (const ConvertException &)
+ {
+ this->OnSyntaxError(source, "SET");
+ return MOD_CONT;
+ }
}
- if (!error.empty())
- this->OnSyntaxError(source, "SET");
- else if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER)
+ if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER)
source.Reply(_("Level must be between %d and %d inclusive."), ACCESS_INVALID + 1, ACCESS_FOUNDER - 1);
else
{
diff --git a/modules/core/cs_list.cpp b/modules/core/cs_list.cpp
index b95bc3144..bc1a8f47a 100644
--- a/modules/core/cs_list.cpp
+++ b/modules/core/cs_list.cpp
@@ -41,24 +41,22 @@ public:
if (pattern[0] == '#')
{
- Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */
- if (tmp.empty() || !tmp.is_number_only())
+ Anope::string n1 = myStrGetToken(pattern.substr(1), '-', 0), /* Read FROM out */
+ n2 = myStrGetTokenRemainder(pattern, '-', 1);
+
+ try
{
- source.Reply(LanguageString::LIST_INCORRECT_RANGE);
- source.Reply(_("To search for channels starting with #, search for the channel\n"
- "name without the #-sign prepended (\002anope\002 instead of \002#anope\002)."));
- return MOD_CONT;
+ from = convertTo<int>(n1);
+ to = convertTo<int>(n2);
}
- from = convertTo<int>(tmp);
- tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */
- if (tmp.empty() || !tmp.is_number_only())
+ catch (const ConvertException &)
{
source.Reply(LanguageString::LIST_INCORRECT_RANGE);
source.Reply(_("To search for channels starting with #, search for the channel\n"
"name without the #-sign prepended (\002anope\002 instead of \002#anope\002)."));
return MOD_CONT;
}
- to = convertTo<int>(tmp);
+
pattern = "*";
}
diff --git a/modules/core/cs_set_bantype.cpp b/modules/core/cs_set_bantype.cpp
index a3c6decb5..01c07148f 100644
--- a/modules/core/cs_set_bantype.cpp
+++ b/modules/core/cs_set_bantype.cpp
@@ -26,17 +26,15 @@ class CommandCSSetBanType : public Command
if (!ci)
throw CoreException("NULL ci in CommandCSSetBanType");
- Anope::string end;
-
- int16 bantype = convertTo<int16>(params[1], end, false);
-
- if (!end.empty() || bantype < 0 || bantype > 3)
- source.Reply(_("\002%s\002 is not a valid ban type."), params[1].c_str());
- else
+ try
{
- ci->bantype = bantype;
+ ci->bantype = convertTo<int16>(params[1]);
source.Reply(_("Ban type for channel %s is now #%d."), ci->name.c_str(), ci->bantype);
}
+ catch (const ConvertException &)
+ {
+ source.Reply(_("\002%s\002 is not a valid ban type."), params[1].c_str());
+ }
return MOD_CONT;
}
diff --git a/modules/core/hs_list.cpp b/modules/core/hs_list.cpp
index 31a201611..585e0d7f9 100644
--- a/modules/core/hs_list.cpp
+++ b/modules/core/hs_list.cpp
@@ -45,8 +45,12 @@ class CommandHSList : public Command
source.Reply(LanguageString::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 ConvertException &) { }
}
}
diff --git a/modules/core/ns_alist.cpp b/modules/core/ns_alist.cpp
index 1777dacb1..4c4fe3eca 100644
--- a/modules/core/ns_alist.cpp
+++ b/modules/core/ns_alist.cpp
@@ -35,7 +35,6 @@ class CommandNSAList : public Command
Anope::string nick;
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 ConvertException &) { }
+ }
}
if (!na)
diff --git a/modules/core/ns_list.cpp b/modules/core/ns_list.cpp
index 4c3db50ed..a97536867 100644
--- a/modules/core/ns_list.cpp
+++ b/modules/core/ns_list.cpp
@@ -57,30 +57,20 @@ class CommandNSList : public Command
if (pattern[0] == '#')
{
- Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */
- if (tmp.empty())
- {
- source.Reply(LanguageString::LIST_INCORRECT_RANGE);
- return MOD_CONT;
- }
- if (!tmp.is_number_only())
- {
- source.Reply(LanguageString::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
{
- source.Reply(LanguageString::LIST_INCORRECT_RANGE);
- return MOD_CONT;
+ from = convertTo<int>(n1);
+ to = convertTo<int>(n2);
}
- if (!tmp.is_number_only())
+ catch (const ConvertException &)
{
source.Reply(LanguageString::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 209fa4231..645f6fc39 100644
--- a/modules/core/os_defcon.cpp
+++ b/modules/core/os_defcon.cpp
@@ -63,7 +63,6 @@ class CommandOSDefcon : public Command
{
User *u = source.u;
const Anope::string &lvl = params[0];
- int newLevel = 0;
if (lvl.empty())
{
@@ -71,12 +70,20 @@ class CommandOSDefcon : public Command
defcon_sendlvls(source);
return MOD_CONT;
}
- newLevel = lvl.is_number_only() ? convertTo<int>(lvl) : 0;
+
+ int newLevel = 0;
+ try
+ {
+ newLevel = convertTo<int>(lvl);
+ }
+ catch (const ConvertException &) { }
+
if (newLevel < 1 || newLevel > 5)
{
this->OnSyntaxError(source, "");
return MOD_CONT;
}
+
Config->DefConLevel = newLevel;
FOREACH_MOD(I_OnDefconLevel, OnDefconLevel(newLevel));
diff --git a/modules/core/os_news.cpp b/modules/core/os_news.cpp
index d8574e5de..b81bb54f4 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
{
- source.Reply(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;
+ unsigned num = convertTo<unsigned>(text);
+ if (num > 0 && del_newsitem(num, type))
+ {
+ source.Reply(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
- source.Reply(msgs[MSG_DEL_NOT_FOUND], num);
+ catch (const ConvertException &) { }
+
+ source.Reply(msgs[MSG_DEL_NOT_FOUND], num);
}
else
{
diff --git a/modules/core/os_session.cpp b/modules/core/os_session.cpp
index dd10c2cae..835607f45 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 ConvertException &) { }
if (mincount <= 1)
source.Reply(_("Invalid threshold value. It must be a valid integer greater than 1."));
@@ -260,7 +265,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 ConvertException &) { }
if (limit < 0 || limit > static_cast<int>(Config->MaxSessionLimit))
{
@@ -334,8 +344,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 ConvertException &) { }
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 954ca636e..e606c0a1d 100644
--- a/modules/core/os_set.cpp
+++ b/modules/core/os_set.cpp
@@ -122,14 +122,19 @@ class CommandOSSet : public Command
debug = 0;
source.Reply(_("Services are now in non-debug mode."));
}
- else if (setting.is_number_only() && convertTo<int>(setting) > 0)
+ else
{
- debug = convertTo<int>(setting);
- Log(LOG_ADMIN, u, this) << "DEBUG " << debug;
- source.Reply(_("Services are now in debug mode (level %d)."), debug);
+ try
+ {
+ debug = convertTo<int>(setting);
+ Log(LOG_ADMIN, u, this) << "DEBUG " << debug;
+ source.Reply(_("Services are now in debug mode (level %d)."), debug);
+ return MOD_CONT;
+ }
+ catch (const ConvertException &) { }
+
+ source.Reply(_("Setting for DEBUG must be \002ON\002, \002OFF\002, or a positive number."));
}
- else
- source.Reply(_("Setting for DEBUG must be \002\002, \002\002, or a positive number."));
return MOD_CONT;
}
diff --git a/modules/extra/cs_entrymsg.cpp b/modules/extra/cs_entrymsg.cpp
index b32937847..25cef4e78 100644
--- a/modules/extra/cs_entrymsg.cpp
+++ b/modules/extra/cs_entrymsg.cpp
@@ -69,15 +69,22 @@ class CommandEntryMessage : public Command
source.Reply(("Entry message \002%s\002 not found on channel \002%s\002."), message.c_str(), ci->name.c_str());
else if (ci->GetExtRegular("cs_entrymsg", messages))
{
- unsigned i = convertTo<unsigned>(message);
- if (i > 0 && i <= messages.size())
+ try
{
- messages.erase(messages.begin() + i - 1);
- ci->Extend("cs_entrymsg", new ExtensibleItemRegular<std::vector<EntryMsg> >(messages));
- source.Reply(_("Entry message \2%i\2 for \2%s\2 deleted."), i, ci->name.c_str());
+ unsigned i = convertTo<unsigned>(message);
+ if (i <= messages.size())
+ {
+ messages.erase(messages.begin() + i - 1);
+ ci->Extend("cs_entrymsg", new ExtensibleItemRegular<std::vector<EntryMsg> >(messages));
+ source.Reply(_("Entry message \2%i\2 for \2%s\2 deleted."), i, ci->name.c_str());
+ }
+ else
+ throw ConvertException();
}
- else
+ catch (const ConvertException &)
+ {
source.Reply(_("Entry message \2%s\2 not found on channel \2%s\2."), message.c_str(), ci->name.c_str());
+ }
}
else
source.Reply(_("Entry message list for \2%s\2 is empty."), ci->name.c_str());