diff options
author | Sadie Powell <sadie@witchery.services> | 2024-03-11 13:53:05 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-03-11 19:17:29 +0000 |
commit | 29e7674e56bf2b829bba22def2760d034a76e788 (patch) | |
tree | f40049ba995b03dd7c510d88f9f19db2d2e65a2e /src/modes.cpp | |
parent | e2df7d4d01f8fdb41c49ce8efc462cab005e7d5c (diff) |
Replace convertTo/stringify with non-throwing alternatives.
Having these throw is terrible for ergonomics and there are loads
of places where the exception was either silently ignored or not
handled at all. Having a function which returns an optional and
another that returns a default works a lot better imo.
Diffstat (limited to 'src/modes.cpp')
-rw-r--r-- | src/modes.cpp | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/modes.cpp b/src/modes.cpp index 9d344e153..8b2534268 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -398,7 +398,7 @@ bool ModeManager::AddUserMode(UserMode *um) if (um->name.empty()) { - um->name = stringify(++GenericUserModes); + um->name = Anope::ToString(++GenericUserModes); Log() << "ModeManager: Added generic support for user mode " << um->mchar; } @@ -425,7 +425,7 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) if (cm->name.empty()) { - cm->name = stringify(++GenericChannelModes); + cm->name = Anope::ToString(++GenericChannelModes); Log() << "ModeManager: Added generic support for channel mode " << cm->mchar; } @@ -783,22 +783,15 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh &cidr_range = this->host.substr(sl + 1); sockaddrs addr(cidr_ip); - - try + auto range = Anope::TryConvert<unsigned short>(cidr_range); + if (addr.valid() && range.has_value()) { - if (addr.valid() && cidr_range.is_pos_number_only()) - { - this->cidr_len = convertTo<unsigned short>(cidr_range); - - /* If we got here, cidr_len is a valid number. */ - - this->host = cidr_ip; - this->family = addr.family(); + this->cidr_len = range.value(); + this->host = cidr_ip; + this->family = addr.family(); - Log(LOG_DEBUG) << "Ban " << mask << " has cidr " << this->cidr_len; - } + Log(LOG_DEBUG) << "Ban " << mask << " has cidr " << this->cidr_len; } - catch (const ConvertException &) { } } } @@ -822,11 +815,11 @@ Anope::string Entry::GetNUHMask() const { case AF_INET: if (cidr_len <= 32) - c = "/" + stringify(cidr_len); + c = "/" + Anope::ToString(cidr_len); break; case AF_INET6: if (cidr_len <= 128) - c = "/" + stringify(cidr_len); + c = "/" + Anope::ToString(cidr_len); break; } |