X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=b0de06267ed7c1e81fbdbc5a1b5c16012acfeb04;hb=ce168051e23bf7a33410ad17a4b78f5da478dbbe;hp=6782ffc5bd72f80a5aeb660e02d8d3fc51dc1109;hpb=1fe8085c6dbecc9558e61ea1829dbf3fcb41830e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 6782ffc5b..b0de06267 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -20,7 +20,7 @@ Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : ServerInstance(Instance) { - chan_hash::iterator findchan = ServerInstance->chanlist->find(name); + chan_hash::iterator findchan = ServerInstance->chanlist->find(cname); if (findchan != Instance->chanlist->end()) throw CoreException("Cannot create duplicate channel " + cname); @@ -184,6 +184,7 @@ CUList* Channel::GetVoicedUsers() void Channel::SetDefaultModes() { + ServerInstance->Logs->Log("CHANNELS", DEBUG, "SetDefaultModes %s", ServerInstance->Config->DefaultModes); irc::spacesepstream list(ServerInstance->Config->DefaultModes); std::string modeseq; std::string parameter; @@ -277,7 +278,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool if (IS_LOCAL(user) && override == false) { MOD_RESULT = 0; - FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,NULL,cname,privs)); + FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, NULL, cname, privs, key ? key : "")); if (MOD_RESULT == 1) return NULL; } @@ -297,7 +298,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool if (IS_LOCAL(user) && override == false) { MOD_RESULT = 0; - FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,Ptr,cname,privs)); + FOREACH_RESULT_I(Instance,I_OnUserPreJoin, OnUserPreJoin(user, Ptr, cname, privs, key ? key : "")); if (MOD_RESULT == 1) { return NULL; @@ -357,7 +358,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool } /* As spotted by jilles, dont bother to set this on remote users */ - if (IS_LOCAL(user) && Ptr->GetUserCounter() == 1) + if (IS_LOCAL(user) && Ptr->GetUserCounter() == 0) Ptr->SetDefaultModes(); return Channel::ForceChan(Instance, Ptr, user, privs, bursting); @@ -432,7 +433,10 @@ bool Channel::IsBanned(User* user) char mask[MAXBUF]; int MOD_RESULT = 0; FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, this)); - if (!MOD_RESULT) + + if (MOD_RESULT == -1) + return true; + else if (MOD_RESULT == 0) { snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString()); for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++) @@ -450,6 +454,37 @@ 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 : + + /* 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. @@ -492,7 +527,7 @@ long Channel::PartUser(User *user, const char* reason) return this->GetUserCounter(); } -long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents) +long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername) { bool silent = false; @@ -508,6 +543,9 @@ long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents) } } + if (servername == NULL || *ServerInstance->Config->HideWhoisServer) + servername = ServerInstance->Config->ServerName; + if (triggerevents) { FOREACH_MOD(I_OnUserKick,OnUserKick(NULL, user, this, reason, silent)); @@ -517,7 +555,7 @@ long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents) if (i != user->chans.end()) { if (!silent) - this->WriteChannelWithServ(ServerInstance->Config->ServerName, "KICK %s %s :%s", this->name, user->nick, reason); + this->WriteChannelWithServ(servername, "KICK %s %s :%s", this->name, user->nick, reason); user->chans.erase(i); this->RemoveAllPrefixes(user); @@ -721,25 +759,9 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text) { - CUList *ulist; + CUList *ulist = this->GetUsers(); char tb[MAXBUF]; - switch (status) - { - case '@': - ulist = this->GetOppedUsers(); - break; - case '%': - ulist = this->GetHalfoppedUsers(); - break; - case '+': - ulist = this->GetVoicedUsers(); - break; - default: - ulist = this->GetUsers(); - break; - } - snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str()); std::string out = tb; @@ -747,6 +769,10 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList { if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end())) { + /* User doesnt have the status we're after */ + if (status && !strchr(this->GetAllPrefixChars(i->first), status)) + continue; + if (serversource) i->first->WriteServ(text); else @@ -856,7 +882,7 @@ void Channel::UserList(User *user, CUList *ulist) } } - dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name); + dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name); int numusers = 0; char* ptr = list + dlen; @@ -903,7 +929,7 @@ void Channel::UserList(User *user, CUList *ulist) user->WriteServ(std::string(list)); /* reset our lengths */ - dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name); + dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name); ptr = list + dlen; ptrlen = 0; @@ -921,7 +947,7 @@ void Channel::UserList(User *user, CUList *ulist) /* if whats left in the list isnt empty, send it */ if (numusers) { - user->WriteServ(std::string(list)); + user->WriteNumeric(353,std::string(list)); } user->WriteNumeric(366, "%s %s :End of /NAMES list.", user->nick, this->name);