diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-04-04 21:43:21 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-04-04 21:43:21 +0000 |
commit | f00094febf62beb74fb45a765a9fccd1ba4c8b8b (patch) | |
tree | d532bc5147fc104a75bf75427240dc5056395c97 | |
parent | ccea6c12cd10e26c3ccacc91fdc16897d00582de (diff) |
The start of extended bans infrastructure: syntax is e.g. +b n:w00tdiff@*, bans of any type can be applied and checked against, but there's more to come with this.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9337 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/channels.h | 7 | ||||
-rw-r--r-- | src/channels.cpp | 32 | ||||
-rw-r--r-- | src/mode.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_foobar.cpp | 11 |
4 files changed, 51 insertions, 5 deletions
diff --git a/include/channels.h b/include/channels.h index 693f429f4..bf025ec56 100644 --- a/include/channels.h +++ b/include/channels.h @@ -528,6 +528,13 @@ class CoreExport Channel : public Extensible */ bool IsBanned(User* user); + /** Check whether an extban of a given type matches + * a given user for this channel. + * @param u The user to match bans against + * @param type The type of extban to check + */ + bool IsExtBanned(User *u, char type); + /** Clears the cached max bans value */ void ResetMaxBans(); diff --git a/src/channels.cpp b/src/channels.cpp index c03a69ace..5dde87117 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -450,6 +450,38 @@ bool Channel::IsBanned(User* user) return false; } +bool Channel::IsExtBanned(User *user, char type) +{ + // XXX. do we need events? + char mask[MAXBUF]; + char *maskptr; + + snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString()); + + for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++) + { + if (i->data[0] != type || i->data[1] != ':') + continue; + + // Iterate past char and : to get to the mask without doing a data copy(!) + maskptr = i->data; + maskptr++; // past the char + maskptr++; // past the : +printf("realmask: %s\n", maskptr); + + /* This allows CIDR ban matching + * + * Full masked host Full unmasked host IP with/without CIDR + */ + if ((match(user->GetFullHost(), maskptr)) || (match(user->GetFullRealHost(), maskptr)) || (match(mask, maskptr, true))) + { + return true; + } + } + + return false; +} + /* Channel::PartUser * remove a channel from a users record, and return the number of users left. * Therefore, if this function returns 0 the caller should delete the Channel. diff --git a/src/mode.cpp b/src/mode.cpp index 83aff70cf..6805c348c 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -705,12 +705,12 @@ void ModeParser::CleanMask(std::string &mask) std::string::size_type pos_of_pling = mask.find_first_of('!'); std::string::size_type pos_of_at = mask.find_first_of('@'); std::string::size_type pos_of_dot = mask.find_first_of('.'); - std::string::size_type pos_of_colon = mask.find_first_of(':'); /* Because ipv6 addresses are colon delimited */ + std::string::size_type pos_of_colons = mask.find("::"); /* Because ipv6 addresses are colon delimited -- double so it treats extban as nick */ if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos)) { - /* Just a nick, or just a host */ - if ((pos_of_dot == std::string::npos) && (pos_of_colon == std::string::npos)) + /* Just a nick, or just a host - or clearly ipv6 (starting with :) */ + if ((pos_of_dot == std::string::npos) && (pos_of_colons == std::string::npos) && mask[0] != ':') { /* It has no '.' in it, it must be a nick. */ mask.append("!*@*"); diff --git a/src/modules/m_foobar.cpp b/src/modules/m_foobar.cpp index 4917dd501..d9254c435 100644 --- a/src/modules/m_foobar.cpp +++ b/src/modules/m_foobar.cpp @@ -35,8 +35,8 @@ class ModuleFoobar : public Module // The constructor just makes a copy of the server class - Implementation eventlist[] = { I_OnUserConnect, I_OnUserQuit, I_OnUserJoin, I_OnUserPart }; - ServerInstance->Modules->Attach(eventlist, this, 4); + Implementation eventlist[] = { I_OnUserConnect, I_OnUserQuit, I_OnUserJoin, I_OnUserPart, I_OnUserPreJoin }; + ServerInstance->Modules->Attach(eventlist, this, 5); } virtual ~ModuleFoobar() @@ -86,6 +86,13 @@ class ModuleFoobar : public Module ServerInstance->Logs->Log("m_foobar",DEBUG,"Foobar: User "+b+" parted "+c); } + virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs) + { + if (chan->IsExtBanned(user, 'n')) + return 1; + + return 0; + } }; |