mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
Merge branch 'insp3' into master.
This commit is contained in:
commit
b045f49afb
@ -116,12 +116,12 @@ public:
|
||||
* @param args A variable number of context parameters and a human readable description of this reply.
|
||||
*/
|
||||
template<typename... Args>
|
||||
void SendIfCap(LocalUser* user, const Cap::Capability& cap, Command* command, const std::string& code,
|
||||
void SendIfCap(LocalUser* user, Cap::Capability* cap, Command* command, const std::string& code,
|
||||
Args&&... args)
|
||||
{
|
||||
static_assert(sizeof...(Args) >= 1);
|
||||
|
||||
if (cap.IsEnabled(user))
|
||||
if (cap && cap->IsEnabled(user))
|
||||
Send(user, command, code, std::forward<Args>(args)...);
|
||||
else
|
||||
SendNoticeInternal(user, command, std::get<sizeof...(Args) - 1>(std::forward_as_tuple(args...)));
|
||||
|
@ -68,9 +68,9 @@ bool irc::sockets::MatchCIDR(const std::string& address, const std::string& cidr
|
||||
}
|
||||
|
||||
const std::string::size_type per_pos = cidr_copy.rfind('/');
|
||||
if ((per_pos == std::string::npos) || (per_pos == cidr_copy.length()-1)
|
||||
if ((per_pos != std::string::npos) && ((per_pos == cidr_copy.length()-1)
|
||||
|| (cidr_copy.find_first_not_of("0123456789", per_pos+1) != std::string::npos)
|
||||
|| (cidr_copy.find_first_not_of("0123456789abcdefABCDEF.:") < per_pos))
|
||||
|| (cidr_copy.find_first_not_of("0123456789abcdefABCDEF.:") < per_pos)))
|
||||
{
|
||||
// The CIDR mask is invalid
|
||||
return false;
|
||||
|
@ -50,13 +50,13 @@ public:
|
||||
{
|
||||
if (parameters[0].size() > ServerInstance->Config->Limits.MaxReal)
|
||||
{
|
||||
fail.SendIfCap(user, cap, this, "INVALID_REALNAME", "Real name is too long");
|
||||
fail.SendIfCap(user, &cap, this, "INVALID_REALNAME", "Real name is too long");
|
||||
return CmdResult::FAILURE;
|
||||
}
|
||||
|
||||
if (!user->ChangeRealName(parameters[0]))
|
||||
{
|
||||
fail.SendIfCap(user, cap, this, "CANNOT_CHANGE_REALNAME", "Unable to change your real name");
|
||||
fail.SendIfCap(user, &cap, this, "CANNOT_CHANGE_REALNAME", "Unable to change your real name");
|
||||
return CmdResult::FAILURE;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
}
|
||||
|
||||
// Converts a flag list to a bitmask.
|
||||
static bool FlagsToBits(const std::string& flags, uint32_t& out)
|
||||
static bool FlagsToBits(const std::string& flags, uint32_t& out, bool strict)
|
||||
{
|
||||
out = SF_NONE;
|
||||
for (const auto& flag : flags)
|
||||
@ -147,6 +147,8 @@ public:
|
||||
out |= SF_EXEMPT;
|
||||
break;
|
||||
default:
|
||||
if (!strict)
|
||||
continue;
|
||||
out = SF_NONE;
|
||||
return false;
|
||||
}
|
||||
@ -233,7 +235,7 @@ public:
|
||||
|
||||
// Try to parse the flags.
|
||||
uint32_t flags;
|
||||
if (!SilenceEntry::FlagsToBits(flagstr, flags))
|
||||
if (!SilenceEntry::FlagsToBits(flagstr, flags, false))
|
||||
{
|
||||
ServerInstance->Logs.Debug(MODNAME, "Malformed silence flags received for %s: %s",
|
||||
user->uuid.c_str(), flagstr.c_str());
|
||||
@ -377,7 +379,7 @@ public:
|
||||
uint32_t flags = SilenceEntry::SF_DEFAULT;
|
||||
if (parameters.size() > 1)
|
||||
{
|
||||
if (!SilenceEntry::FlagsToBits(parameters[1], flags))
|
||||
if (!SilenceEntry::FlagsToBits(parameters[1], flags, true))
|
||||
{
|
||||
user->WriteNumeric(ERR_SILENCE, mask, parameters[1], "You specified one or more invalid SILENCE flags");
|
||||
return CmdResult::FAILURE;
|
||||
|
@ -406,16 +406,19 @@ std::string irc::sockets::cidr_mask::str() const
|
||||
|
||||
unsigned char* base;
|
||||
size_t len;
|
||||
unsigned char maxlen;
|
||||
switch (type)
|
||||
{
|
||||
case AF_INET:
|
||||
base = reinterpret_cast<unsigned char*>(&sa.in4.sin_addr);
|
||||
len = 4;
|
||||
maxlen = 32;
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
base = reinterpret_cast<unsigned char*>(&sa.in6.sin6_addr);
|
||||
len = 16;
|
||||
maxlen = 128;
|
||||
break;
|
||||
|
||||
case AF_UNIX:
|
||||
@ -429,7 +432,14 @@ std::string irc::sockets::cidr_mask::str() const
|
||||
}
|
||||
|
||||
memcpy(base, bits, len);
|
||||
return sa.addr() + "/" + ConvToStr(length);
|
||||
|
||||
std::string value = sa.addr();
|
||||
if (length < maxlen)
|
||||
{
|
||||
value.push_back('/');
|
||||
value.append(ConvToStr(static_cast<uint16_t>(length)));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool irc::sockets::cidr_mask::operator==(const cidr_mask& other) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user