diff options
Diffstat (limited to 'modules')
59 files changed, 354 insertions, 632 deletions
diff --git a/modules/botserv/botserv.cpp b/modules/botserv/botserv.cpp index d2b8df4bb..706865522 100644 --- a/modules/botserv/botserv.cpp +++ b/modules/botserv/botserv.cpp @@ -67,12 +67,8 @@ public: Anope::string Limit; unsigned limit = 0; - try - { - if (c->GetParam("LIMIT", Limit)) - limit = convertTo<unsigned>(Limit); - } - catch (const ConvertException &) { } + if (c->GetParam("LIMIT", Limit)) + limit = Anope::Convert<unsigned>(Limit, limit); /* Should we be invited? */ if (c->HasMode("INVITE") || (limit && c->users.size() >= limit)) diff --git a/modules/botserv/bs_badwords.cpp b/modules/botserv/bs_badwords.cpp index 5dee8ed2c..09e96564b 100644 --- a/modules/botserv/bs_badwords.cpp +++ b/modules/botserv/bs_badwords.cpp @@ -222,7 +222,7 @@ private: const BadWord *b = bw->GetBadWord(Number - 1); ListFormatter::ListEntry entry; - entry["Number"] = stringify(Number); + entry["Number"] = Anope::ToString(Number); entry["Word"] = b->word; entry["Type"] = b->type == BW_SINGLE ? "(SINGLE)" : (b->type == BW_START ? "(START)" : (b->type == BW_END ? "(END)" : "")); this->list.AddEntry(entry); @@ -241,7 +241,7 @@ private: continue; ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); entry["Word"] = b->word; entry["Type"] = b->type == BW_SINGLE ? "(SINGLE)" : (b->type == BW_START ? "(START)" : (b->type == BW_END ? "(END)" : "")); list.AddEntry(entry); diff --git a/modules/botserv/bs_info.cpp b/modules/botserv/bs_info.cpp index c8e05577b..b4a5592b1 100644 --- a/modules/botserv/bs_info.cpp +++ b/modules/botserv/bs_info.cpp @@ -55,7 +55,7 @@ public: info[_("Real name")] = bi->realname; info[_("Created")] = Anope::strftime(bi->created, source.GetAccount()); info[_("Options")] = bi->oper_only ? _("Private") : _("None"); - info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)"; + info[_("Used on")] = Anope::ToString(bi->GetChannelCount()) + " channel(s)"; FOREACH_MOD(OnBotInfo, (source, bi, ci, info)); diff --git a/modules/botserv/bs_kick.cpp b/modules/botserv/bs_kick.cpp index 29c8cb598..9183eae22 100644 --- a/modules/botserv/bs_kick.cpp +++ b/modules/botserv/bs_kick.cpp @@ -106,11 +106,10 @@ struct KickerDataImpl final data["ttb"] >> ttb; spacesepstream sep(ttb); for (int i = 0; sep.GetToken(tok) && i < TTB_SIZE; ++i) - try - { - kd->ttb[i] = convertTo<int16_t>(tok); - } - catch (const ConvertException &) { } + { + if (auto n = Anope::TryConvert<int16_t>(tok)) + kd->ttb[i] = n.value(); + } kd->Check(ci); } @@ -206,21 +205,13 @@ protected: { if (!ttb.empty()) { - int16_t i; - - try - { - i = convertTo<int16_t>(ttb); - if (i < 0) - throw ConvertException(); - } - catch (const ConvertException &) + kd->ttb[ttb_idx] = Anope::Convert<int16_t>(ttb, -1); + if (kd->ttb[ttb_idx] < 0) { + kd->ttb[ttb_idx] = 0; source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); return; } - - kd->ttb[ttb_idx] = i; } else kd->ttb[ttb_idx] = 0; @@ -386,13 +377,8 @@ public: if (!ttb.empty()) { - try - { - kd->ttb[TTB_CAPS] = convertTo<int16_t>(ttb); - if (kd->ttb[TTB_CAPS] < 0) - throw ConvertException(); - } - catch (const ConvertException &) + kd->ttb[TTB_CAPS] = Anope::Convert<int16_t>(ttb, -1); + if (kd->ttb[TTB_CAPS] < 0) { kd->ttb[TTB_CAPS] = 0; source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); @@ -402,21 +388,11 @@ public: else kd->ttb[TTB_CAPS] = 0; - kd->capsmin = 10; - try - { - kd->capsmin = convertTo<int16_t>(min); - } - catch (const ConvertException &) { } + kd->capsmin = Anope::Convert(min, 0); if (kd->capsmin < 1) kd->capsmin = 10; - kd->capspercent = 25; - try - { - kd->capspercent = convertTo<int16_t>(percent); - } - catch (const ConvertException &) { } + kd->capspercent = Anope::Convert(percent, 0); if (kd->capspercent < 1 || kd->capspercent > 100) kd->capspercent = 25; @@ -518,42 +494,25 @@ public: if (!ttb.empty()) { - int16_t i; - - try - { - i = convertTo<int16_t>(ttb); - if (i < 0) - throw ConvertException(); - } - catch (const ConvertException &) + kd->ttb[TTB_FLOOD] = Anope::Convert<int16_t>(ttb, -1); + if (kd->ttb[TTB_FLOOD] < 0) { + kd->ttb[TTB_FLOOD] = 0; source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); return; } - - kd->ttb[TTB_FLOOD] = i; } else kd->ttb[TTB_FLOOD] = 0; - kd->floodlines = 6; - try - { - kd->floodlines = convertTo<int16_t>(lines); - } - catch (const ConvertException &) { } + kd->floodlines = Anope::Convert(lines, -1); if (kd->floodlines < 2) kd->floodlines = 6; - kd->floodsecs = 10; - try - { - kd->floodsecs = convertTo<int16_t>(secs); - } - catch (const ConvertException &) { } + kd->floodsecs = Anope::Convert(secs, -1); if (kd->floodsecs < 1) kd->floodsecs = 10; + if (kd->floodsecs > Config->GetModule(me)->Get<time_t>("keepdata")) kd->floodsecs = Config->GetModule(me)->Get<time_t>("keepdata"); @@ -651,31 +610,18 @@ public: if (!ttb.empty()) { - int16_t i; - - try - { - i = convertTo<int16_t>(ttb); - if (i < 0) - throw ConvertException(); - } - catch (const ConvertException &) + kd->ttb[TTB_REPEAT] = Anope::Convert(ttb, -1); + if (kd->ttb[TTB_REPEAT] < 0) { + kd->ttb[TTB_REPEAT] = 0; source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); return; } - - kd->ttb[TTB_REPEAT] = i; } else kd->ttb[TTB_REPEAT] = 0; - kd->repeattimes = 3; - try - { - kd->repeattimes = convertTo<int16_t>(times); - } - catch (const ConvertException &) { } + kd->repeattimes = Anope::Convert<int16_t>(times, -1); if (kd->repeattimes < 1) kd->repeattimes = 3; diff --git a/modules/chanserv/cs_access.cpp b/modules/chanserv/cs_access.cpp index 3d2c3c8d6..f86d9f5bc 100644 --- a/modules/chanserv/cs_access.cpp +++ b/modules/chanserv/cs_access.cpp @@ -37,18 +37,13 @@ public: Anope::string AccessSerialize() const override { - return stringify(this->level); + return Anope::ToString(this->level); } void AccessUnserialize(const Anope::string &data) override { - try - { - this->level = convertTo<int>(data); - } - catch (const ConvertException &) - { - } + if (auto l = Anope::TryConvert<int>(data)) + this->level = l.value(); } bool operator>(const ChanAccess &other) const override @@ -95,11 +90,9 @@ class CommandCSAccess final Privilege *p = NULL; int level = ACCESS_INVALID; - try - { - level = convertTo<int>(params[3]); - } - catch (const ConvertException &) + if (auto lvl = Anope::TryConvert<int>(params[3])) + level = lvl.value(); + else { p = PrivilegeManager::FindPrivilege(params[3]); if (p != NULL && defaultLevels[p->name]) @@ -402,7 +395,7 @@ class CommandCSAccess final } ListFormatter::ListEntry entry; - entry["Number"] = stringify(number); + entry["Number"] = Anope::ToString(number); entry["Level"] = access->AccessSerialize(); entry["Mask"] = access->Mask(); entry["By"] = access->creator; @@ -442,7 +435,7 @@ class CommandCSAccess final } ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); entry["Level"] = access->AccessSerialize(); entry["Mask"] = access->Mask(); entry["By"] = access->creator; @@ -652,11 +645,9 @@ class CommandCSLevels final level = ACCESS_FOUNDER; else { - try - { - level = convertTo<int>(lev); - } - catch (const ConvertException &) + if (auto lvl = Anope::TryConvert<int>(lev)) + level = lvl.value(); + else { this->OnSyntaxError(source, "SET"); return; @@ -734,7 +725,7 @@ class CommandCSLevels final else if (j == ACCESS_FOUNDER) entry["Level"] = Language::Translate(source.GetAccount(), _("(founder only)")); else - entry["Level"] = stringify(j); + entry["Level"] = Anope::ToString(j); list.AddEntry(entry); } diff --git a/modules/chanserv/cs_akick.cpp b/modules/chanserv/cs_akick.cpp index 6457f2856..35052e63d 100644 --- a/modules/chanserv/cs_akick.cpp +++ b/modules/chanserv/cs_akick.cpp @@ -311,7 +311,7 @@ class CommandCSAKick final lastused = UNKNOWN; ListFormatter::ListEntry entry; - entry["Number"] = stringify(number); + entry["Number"] = Anope::ToString(number); if (akick->nc) entry["Mask"] = akick->nc->display; else @@ -351,7 +351,7 @@ class CommandCSAKick final lastused = UNKNOWN; ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); if (akick->nc) entry["Mask"] = akick->nc->display; else diff --git a/modules/chanserv/cs_enforce.cpp b/modules/chanserv/cs_enforce.cpp index 825301cdd..3c0a464ef 100644 --- a/modules/chanserv/cs_enforce.cpp +++ b/modules/chanserv/cs_enforce.cpp @@ -166,14 +166,8 @@ private: return; } - int l; - try - { - l = convertTo<int>(l_str); - if (l < 0) - throw ConvertException(); - } - catch (const ConvertException &) + auto l = Anope::Convert<int>(l_str, -1); + if (l < 0) { source.Reply(_("The limit on %s is not valid."), ci->name.c_str()); return; diff --git a/modules/chanserv/cs_entrymsg.cpp b/modules/chanserv/cs_entrymsg.cpp index 03e4b22de..efe13d1aa 100644 --- a/modules/chanserv/cs_entrymsg.cpp +++ b/modules/chanserv/cs_entrymsg.cpp @@ -123,7 +123,7 @@ private: EntryMsg *msg = (*messages)->at(i); ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); entry["Creator"] = msg->creator; entry["Created"] = Anope::strftime(msg->when, NULL, true); entry["Message"] = msg->message; @@ -162,21 +162,16 @@ private: source.Reply(_("Entry message list for \002%s\002 is empty."), ci->name.c_str()); else { - try + auto i = Anope::Convert<unsigned>(message, 0); + if (i > 0 && i <= (*messages)->size()) { - unsigned i = convertTo<unsigned>(message); - if (i > 0 && i <= (*messages)->size()) - { - delete (*messages)->at(i - 1); - if ((*messages)->empty()) - ci->Shrink<EntryMessageList>("entrymsg"); - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove a message"; - source.Reply(_("Entry message \002%i\002 for \002%s\002 deleted."), i, ci->name.c_str()); - } - else - throw ConvertException(); + delete (*messages)->at(i - 1); + if ((*messages)->empty()) + ci->Shrink<EntryMessageList>("entrymsg"); + Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove a message"; + source.Reply(_("Entry message \002%i\002 for \002%s\002 deleted."), i, ci->name.c_str()); } - catch (const ConvertException &) + else { source.Reply(_("Entry message \002%s\002 not found on channel \002%s\002."), message.c_str(), ci->name.c_str()); } diff --git a/modules/chanserv/cs_flags.cpp b/modules/chanserv/cs_flags.cpp index feb64aacd..7404aef57 100644 --- a/modules/chanserv/cs_flags.cpp +++ b/modules/chanserv/cs_flags.cpp @@ -331,7 +331,7 @@ class CommandCSFlags final ListFormatter::ListEntry entry; ++count; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); entry["Mask"] = access->Mask(); entry["Flags"] = flags; entry["Creator"] = access->creator; diff --git a/modules/chanserv/cs_info.cpp b/modules/chanserv/cs_info.cpp index 685538284..e02660301 100644 --- a/modules/chanserv/cs_info.cpp +++ b/modules/chanserv/cs_info.cpp @@ -58,7 +58,7 @@ public: if (show_all) { - info[_("Ban type")] = stringify(ci->bantype); + info[_("Ban type")] = Anope::ToString(ci->bantype); } FOREACH_MOD(OnChanInfo, (source, ci, info, show_all)); diff --git a/modules/chanserv/cs_list.cpp b/modules/chanserv/cs_list.cpp index 29add4596..c9589a268 100644 --- a/modules/chanserv/cs_list.cpp +++ b/modules/chanserv/cs_list.cpp @@ -36,12 +36,10 @@ public: sepstream(pattern.substr(1), '-').GetToken(n1, 0); sepstream(pattern, '-').GetToken(n2, 1); - try - { - from = convertTo<int>(n1); - to = convertTo<int>(n2); - } - catch (const ConvertException &) + auto num1 = Anope::TryConvert<int>(n1); + auto num2 = Anope::TryConvert<int>(n2); + + if (!num1.has_value() || !num2.has_value()) { source.Reply(LIST_INCORRECT_RANGE); source.Reply(_("To search for channels starting with #, search for the channel\n" @@ -49,6 +47,8 @@ public: return; } + from = num1.value(); + to = num2.value(); pattern = "*"; } diff --git a/modules/chanserv/cs_log.cpp b/modules/chanserv/cs_log.cpp index 213940a5c..8c1004eeb 100644 --- a/modules/chanserv/cs_log.cpp +++ b/modules/chanserv/cs_log.cpp @@ -135,7 +135,7 @@ public: const LogSetting *log = (*ls)->at(i); ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); entry["Service"] = log->command_service; entry["Command"] = !log->command_name.empty() ? log->command_name : log->service_name; entry["Method"] = log->method; diff --git a/modules/chanserv/cs_mode.cpp b/modules/chanserv/cs_mode.cpp index 8c7c7c1c3..8f462a3cb 100644 --- a/modules/chanserv/cs_mode.cpp +++ b/modules/chanserv/cs_mode.cpp @@ -716,7 +716,7 @@ class CommandCSMode final std::vector<Anope::string> new_params; new_params.push_back(params[0]); new_params.emplace_back("SET"); - new_params.push_back("-" + stringify(cm->mchar)); + new_params.push_back("-" + Anope::ToString(cm->mchar)); new_params.emplace_back("*"); this->DoSet(source, ci, new_params); } diff --git a/modules/chanserv/cs_set.cpp b/modules/chanserv/cs_set.cpp index d5ed4713f..c7952baba 100644 --- a/modules/chanserv/cs_set.cpp +++ b/modules/chanserv/cs_set.cpp @@ -165,19 +165,16 @@ public: return; } - try - { - int16_t new_type = convertTo<int16_t>(params[1]); - if (new_type < 0 || new_type > 3) - throw ConvertException("Invalid range"); - Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to change the ban type to " << new_type; - ci->bantype = new_type; - source.Reply(_("Ban type for channel %s is now #%d."), ci->name.c_str(), ci->bantype); - } - catch (const ConvertException &) + auto new_type = Anope::Convert<int16_t>(params[1], -1); + if (new_type < 0 || new_type > 3) { source.Reply(_("\002%s\002 is not a valid ban type."), params[1].c_str()); + return; } + + Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to change the ban type to " << new_type; + ci->bantype = new_type; + source.Reply(_("Ban type for channel %s is now #%d."), ci->name.c_str(), ci->bantype); } bool OnHelp(CommandSource &source, const Anope::string &) override diff --git a/modules/chanserv/cs_xop.cpp b/modules/chanserv/cs_xop.cpp index b47e1e988..0ec8e8d25 100644 --- a/modules/chanserv/cs_xop.cpp +++ b/modules/chanserv/cs_xop.cpp @@ -420,7 +420,7 @@ private: return; ListFormatter::ListEntry entry; - entry["Number"] = stringify(Number); + entry["Number"] = Anope::ToString(Number); entry["Mask"] = a->Mask(); entry["Description"] = a->description; this->list.AddEntry(entry); @@ -440,7 +440,7 @@ private: continue; ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); + entry["Number"] = Anope::ToString(i + 1); entry["Mask"] = a->Mask(); entry["Description"] = a->description; list.AddEntry(entry); diff --git a/modules/database/db_atheme.cpp b/modules/database/db_atheme.cpp index 3e613562b..3f62c29ca 100644 --- a/modules/database/db_atheme.cpp +++ b/modules/database/db_atheme.cpp @@ -56,16 +56,7 @@ public: template<typename Numeric> std::enable_if_t<std::is_arithmetic_v<Numeric>, Numeric> GetNum() { - try - { - auto token = Get(); - std::stringstream stream(token.str()); - Numeric ntoken = 0; - stream >> ntoken; - return ntoken; - } - catch (const ConvertException &) { } - return 0; + return Anope::Convert<Numeric>(Get(), 0); } // Retrieves the entire row. @@ -869,7 +860,7 @@ private: else if (key == "private:close:reason") data->suspend_reason = value; else if (key == "private:close:timestamp") - data->suspend_ts = convertTo<time_t>(value); + data->suspend_ts = Anope::Convert<time_t>(value, 0); else if (key == "private:entrymsg") { auto *eml = ci->Require<EntryMessageList>("entrymsg"); @@ -891,19 +882,19 @@ private: else if (key == "private:klinechan:reason") data->suspend_reason = value; else if (key == "private:klinechan:timestamp") - data->suspend_ts = convertTo<time_t>(value); + data->suspend_ts = Anope::Convert<time_t>(value, 0); else if (key == "private:mark:reason") data->info_message = value; else if (key == "private:mark:setter") data->info_adder = value; else if (key == "private:mark:timestamp") - data->info_ts = convertTo<time_t>(value); + data->info_ts = Anope::Convert<time_t>(value, 0); else if (key == "private:topic:setter") ci->last_topic_setter = value; else if (key == "private:topic:text") ci->last_topic = value; else if (key == "private:topic:ts") - ci->last_topic_time = convertTo<time_t>(value); + ci->last_topic_time = Anope::Convert<time_t>(value, 0); else Log(this) << "Unknown channel metadata " << key << " = " << value; @@ -953,7 +944,7 @@ private: auto kill = Config->GetModule("nickserv")->Get<time_t>("kill", "60s"); auto killquick = Config->GetModule("nickserv")->Get<time_t>("killquick", "20s"); - auto secs = convertTo<unsigned>(value); + auto secs = Anope::Convert<time_t>(value, kill); if (secs >= kill) nc->Extend<bool>("KILLPROTECT"); else if (secs >= killquick) @@ -966,7 +957,7 @@ private: else if (key == "private:freeze:reason") data- |
