X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=d917edb84b6bfd03f4a301594ba56ccd19091eb2;hb=0a45c56f10efb2af30835652b75317f2969a0b06;hp=f0cd66dbf29af66d53ec09facde8dd2c2c1c48ab;hpb=31f1e7ad092f8bf16ee653cc105eea4a769650ca;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index f0cd66dbf..d917edb84 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -14,7 +14,7 @@ /* $Core: libIRCDchannels */ #include "inspircd.h" -#include +#include #include "wildcard.h" #include "mode.h" @@ -25,7 +25,7 @@ Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : Serv throw CoreException("Cannot create duplicate channel " + cname); (*(ServerInstance->chanlist))[cname.c_str()] = this; - this->name.assign(cname, 0, CHANMAX); + this->name.assign(cname, 0, ServerInstance->Config->Limits.ChanMax); this->created = ts ? ts : ServerInstance->Time(); this->age = this->created; @@ -44,7 +44,7 @@ void Channel::SetMode(char mode,bool mode_on) void Channel::SetModeParam(char mode,const char* parameter,bool mode_on) { - CustomModeList::iterator n = custom_mode_params.find(mode); + CustomModeList::iterator n = custom_mode_params.find(mode); if (mode_on) { @@ -96,7 +96,7 @@ void Channel::AddUser(User* user) unsigned long Channel::DelUser(User* user) { CUListIter a = internal_userlist.find(user); - + if (a != internal_userlist.end()) { internal_userlist.erase(a); @@ -105,7 +105,7 @@ unsigned long Channel::DelUser(User* user) DelHalfoppedUser(user); DelVoicedUser(user); } - + return internal_userlist.size(); } @@ -139,7 +139,7 @@ void Channel::DelHalfoppedUser(User* user) CUListIter a = internal_halfop_userlist.find(user); if (a != internal_halfop_userlist.end()) - { + { internal_halfop_userlist.erase(a); } } @@ -152,7 +152,7 @@ void Channel::AddVoicedUser(User* user) void Channel::DelVoicedUser(User* user) { CUListIter a = internal_voice_userlist.find(user); - + if (a != internal_voice_userlist.end()) { internal_voice_userlist.erase(a); @@ -203,9 +203,9 @@ void Channel::SetDefaultModes() } } -/* +/* * add a channel to a user, creating the record for it if needed and linking - * it to the user record + * it to the user record */ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS) { @@ -254,7 +254,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool } } - strlcpy(cname, cn, CHANMAX); + strlcpy(cname, cn, Instance->Config->Limits.ChanMax); Ptr = Instance->FindChan(cname); if (!Ptr) @@ -439,7 +439,7 @@ bool Channel::IsBanned(User* user) for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++) { /* This allows CIDR ban matching - * + * * Full masked host Full unmasked host IP with/without CIDR */ if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true))) @@ -453,26 +453,32 @@ bool Channel::IsBanned(User* user) bool Channel::IsExtBanned(User *user, char type) { - // XXX. do we need events? char mask[MAXBUF]; + int MOD_RESULT = 0; + FOREACH_RESULT(I_OnCheckExtBan,OnCheckExtBan(user, this, type)); - snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString()); - - for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++) + if (MOD_RESULT == -1) + return true; + else if (MOD_RESULT == 0) { - if (i->data[0] != type || i->data[1] != ':') - continue; - - // Iterate past char and : to get to the mask without doing a data copy(!) - std::string maskptr = i->data.substr(2); + snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString()); - /* 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))) + for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++) { - return true; + if (i->data[0] != type || i->data[1] != ':') + continue; + + // Iterate past char and : to get to the mask without doing a data copy(!) + std::string maskptr = i->data.substr(2); + + /* 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; + } } } @@ -482,8 +488,10 @@ bool Channel::IsExtBanned(User *user, char type) /* 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. + * + * XXX: bleh, string copy of reason, fixme! -- w00t */ -long Channel::PartUser(User *user, const char* reason) +long Channel::PartUser(User *user, std::string &reason) { bool silent = false; @@ -493,10 +501,10 @@ long Channel::PartUser(User *user, const char* reason) UCListIter i = user->chans.find(this); if (i != user->chans.end()) { - FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason ? reason : "", silent)); + FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent)); if (!silent) - this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason ? " :" : "", reason ? reason : ""); + this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : ":", reason.c_str()); user->chans.erase(i); this->RemoveAllPrefixes(user); @@ -608,7 +616,7 @@ long Channel::KickUser(User *src, User *user, const char* reason) FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK)); if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server))) return this->GetUserCounter(); - + if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server))) { int them = this->GetStatus(src); @@ -909,15 +917,15 @@ void Channel::UserList(User *user, CUList *ulist) if (call_modules) { FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick)); - + /* Nick was nuked, a module wants us to skip it */ if (nick.empty()) continue; } - + size_t ptrlen = 0; - if (curlen > (480-NICKMAX)) + if (curlen + prefixlist.length() + nick.length() + 1 > 480) { /* list overflowed into multiple numerics */ user->WriteServ(std::string(list)); @@ -980,7 +988,7 @@ void Channel::ResetMaxBans() const char* Channel::GetPrefixChar(User *user) { static char pf[2] = {0, 0}; - + prefixlist::iterator n = prefixes.find(user); if (n != prefixes.end()) {