mirror of
https://github.com/anope/anope.git
synced 2026-06-15 16:54:46 +02:00
try/catch-ified all instances of convertTo to keep from aborting when a user gives too large or too small a number
This commit is contained in:
+109
-63
@@ -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]);
|
||||
|
||||
+21
-10
@@ -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
|
||||
{
|
||||
|
||||
+10
-12
@@ -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
|
||||
{
|
||||
from = convertTo<int>(n1);
|
||||
to = convertTo<int>(n2);
|
||||
}
|
||||
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;
|
||||
}
|
||||
from = convertTo<int>(tmp);
|
||||
tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */
|
||||
if (tmp.empty() || !tmp.is_number_only())
|
||||
{
|
||||
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 = "*";
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 &) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
+10
-20
@@ -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())
|
||||
Anope::string n1 = myStrGetToken(pattern.substr(1), '-', 0), /* Read FROM out */
|
||||
n2 = myStrGetToken(pattern, '-', 1);
|
||||
|
||||
try
|
||||
{
|
||||
from = convertTo<int>(n1);
|
||||
to = convertTo<int>(n2);
|
||||
}
|
||||
catch (const ConvertException &)
|
||||
{
|
||||
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())
|
||||
{
|
||||
source.Reply(LanguageString::LIST_INCORRECT_RANGE);
|
||||
return MOD_CONT;
|
||||
}
|
||||
if (!tmp.is_number_only())
|
||||
{
|
||||
source.Reply(LanguageString::LIST_INCORRECT_RANGE);
|
||||
return MOD_CONT;
|
||||
}
|
||||
to = convertTo<int>(tmp);
|
||||
|
||||
pattern = "*";
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
+12
-7
@@ -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)
|
||||
{
|
||||
debug = convertTo<int>(setting);
|
||||
Log(LOG_ADMIN, u, this) << "DEBUG " << debug;
|
||||
source.Reply(_("Services are now in debug mode (level %d)."), debug);
|
||||
}
|
||||
else
|
||||
source.Reply(_("Setting for DEBUG must be \002\002, \002\002, or a positive number."));
|
||||
{
|
||||
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."));
|
||||
}
|
||||
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user