Skip to content

Commit

Permalink
Correct some more conversions.
Browse files Browse the repository at this point in the history
I tend to forget the try/catch on conversions with my Anope stuff.
Added them where needed and bumped the versions for a patch release.
  • Loading branch information
genius3000 committed Jul 6, 2021
1 parent c8c8165 commit 763963e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
20 changes: 14 additions & 6 deletions cs_set_joinflood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,19 @@ class CommandCSSetJoinFlood : public Command
time_t duration = 60;
if (params.size() >= 3)
{
joins = convertTo<unsigned int>(params[2]);
if (params.size() >= 4)
secs = convertTo<time_t>(params[3]);
if (params.size() == 5)
duration = convertTo<time_t>(params[4]);
try
{
joins = convertTo<unsigned int>(params[2]);
if (params.size() >= 4)
secs = convertTo<time_t>(params[3]);
if (params.size() == 5)
duration = convertTo<time_t>(params[4]);
}
catch (const ConvertException &)
{
source.Reply("Invalid value given for joins, secs, and/or duration.");
return;
}
}

Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to enable join flood protection";
Expand Down Expand Up @@ -256,7 +264,7 @@ class CSSetJoinFlood : public Module
throw ModuleException("Requires version 2.0.x of Anope.");

this->SetAuthor("genius3000");
this->SetVersion("1.0.2");
this->SetVersion("1.0.3");

if (Me && Me->IsSynced())
this->Init();
Expand Down
16 changes: 13 additions & 3 deletions hs_offer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,18 @@ class CommandHSOfferList : public Command

if (match.find_first_not_of("1234567890") == Anope::string::npos)
{
const unsigned number = convertTo<unsigned>(match);
ho = HostOffersList.Get(number - 1);
try
{
const unsigned number = convertTo<unsigned>(match);
if (number > 0)
ho = HostOffersList.Get(number - 1);
}
catch (const ConvertException &)
{
source.Reply("'%s' is an invalid entry number", match.c_str());
return;
}

if (!ho)
{
source.Reply("%d is an invalid entry number", number);
Expand Down Expand Up @@ -909,7 +919,7 @@ class HSOffer : public Module
throw ModuleException("Requires version 2.0.x of Anope.");

this->SetAuthor("genius3000");
this->SetVersion("1.0.1");
this->SetVersion("1.0.2");
}

void OnReload(Configuration::Conf *conf) anope_override
Expand Down
15 changes: 12 additions & 3 deletions m_xlinetoakill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class XLineToAkill : public Module
throw ModuleException("This module requires both OperServ and OS_AKILL to function.");

this->SetAuthor("genius3000");
this->SetVersion("1.0.1");
this->SetVersion("1.0.2");
}

void OnReload(Configuration::Conf *conf) anope_override
Expand Down Expand Up @@ -82,10 +82,19 @@ class XLineToAkill : public Module
return EVENT_CONTINUE;

const Anope::string setby = params[2];
time_t settime = convertTo<time_t>(params[3]);
time_t duration = convertTo<time_t>(params[4]);
const Anope::string reason = params[5];

try
{
time_t settime = convertTo<time_t>(params[3]);
time_t duration = convertTo<time_t>(params[4]);
}
catch (const ConvertException &)
{
Log(OperServ, "akill/sync") << "X-Line (" << linetype << ") sync received with malformed set time and/or duration for: " << mask << " (" << reason << ") [set by " << setby << "]: set time: '" << params[3] << "' duration: '" << params[4] << "'";
return EVENT_CONTINUE;
}

time_t expires = (duration == 0) ? duration : settime + duration;

XLine *x = new XLine(mask, setby, expires, reason, XLineManager::GenerateUID());
Expand Down
13 changes: 11 additions & 2 deletions os_chantrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,21 @@ class CommandOSChanTrap : public Command
}

mask = params[1];
bots = convertTo<unsigned>(params[2]);
saction = params[3];
sduration = params[4];
modes = params[5];
reason = params[6];

try
{
bots = convertTo<unsigned>(params[2]);
}
catch (const ConvertException &)
{
source.Reply("Invalid number of bots: '%s' is not valid for number of bots.", params[2].c_str());
return;
}

if (bots == 0 && mask.replace_all_cs("?*", "").empty())

{
Expand Down Expand Up @@ -1049,7 +1058,7 @@ class OSChanTrap : public Module
throw ModuleException("Requires version 2.0.x of Anope.");

this->SetAuthor("genius3000");
this->SetVersion("1.0.1");
this->SetVersion("1.0.2");

if (Me && Me->IsSynced())
this->Init();
Expand Down

0 comments on commit 763963e

Please sign in to comment.