X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=bd8a9719c5f8e17dbb2291342232191530dff718;hb=cf4439ac5c5e5f57aba2c998ee63b9b27ec17d69;hp=2793843c7f5e1a47c15a6ad6824af99e0af74c4e;hpb=e6fa614ad27cd68aa61605ca0884eee9c44384eb;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 2793843c7..bd8a9719c 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -11,9 +11,9 @@ * --------------------------------------------------- */ +#include "inspircd.h" #include #include "configreader.h" -#include "inspircd.h" #include "users.h" #include "modules.h" #include "wildcard.h" @@ -172,6 +172,31 @@ CUList* chanrec::GetVoicedUsers() return &internal_voice_userlist; } +void chanrec::SetDefaultModes() +{ + irc::spacesepstream list(ServerInstance->Config->DefaultModes); + std::string modeseq = list.GetToken(); + std::string parameter; + userrec* dummyuser = new userrec(ServerInstance); + dummyuser->SetFd(FD_MAGIC_NUMBER); + + for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n) + { + ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL); + if (mode) + { + if (mode->GetNumParams(true)) + parameter = list.GetToken().c_str(); + else + parameter.clear(); + + mode->OnModeChange(dummyuser, dummyuser, this, parameter, true); + } + } + + delete dummyuser; +} + /* * add a channel to a user, creating the record for it if needed and linking * it to the user record @@ -181,21 +206,65 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo if (!user || !cn) return NULL; - bool new_channel = false; char cname[MAXBUF]; int MOD_RESULT = 0; - strlcpy(cname,cn,CHANMAX); - std::string privs; + chanrec *Ptr; + + /* + * We don't restrict the number of channels that remote users or users that are override-joining may be in. + * We restrict local users to MaxChans channels. + * We restrict local operators to OperMaxChans channels. + * This is a lot more logical than how it was formerly. -- w00t + */ + if (IS_LOCAL(user) && !override) + { + if (user->GetMaxChans()) + { + if (user->chans.size() >= user->GetMaxChans()) + { + user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn); + return NULL; + } + } + else + { + if (IS_OPER(user)) + { + if (user->chans.size() >= Instance->Config->OperMaxChans) + { + user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn); + return NULL; + } + } + else + { + if (user->chans.size() >= Instance->Config->MaxChans) + { + user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn); + return NULL; + } + } + } + } - chanrec* Ptr = Instance->FindChan(cname); + strlcpy(cname, cn, CHANMAX); + Ptr = Instance->FindChan(cname); if (!Ptr) { - if ((!IS_LOCAL(user)) && (!TS)) - Instance->Log(DEBUG,"*** BUG *** chanrec::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn); - - privs = "@"; + /* + * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t + */ + if (!IS_LOCAL(user)) + { + if (!TS) + Instance->Log(DEBUG,"*** BUG *** chanrec::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn); + } + else + { + privs = "@"; + } if (IS_LOCAL(user) && override == false) { @@ -213,14 +282,13 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo /* As spotted by jilles, dont bother to set this on remote users */ if (IS_LOCAL(user)) - Ptr->modes[CM_TOPICLOCK] = Ptr->modes[CM_NOEXTERNAL] = 1; + Ptr->SetDefaultModes(); Ptr->created = TS ? TS : Instance->Time(); Ptr->age = Ptr->created; *Ptr->topic = 0; *Ptr->setby = 0; Ptr->topicset = 0; - new_channel = true; } else { @@ -255,18 +323,13 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo } } } - if (Ptr->modes[CM_INVITEONLY]) + if (Ptr->IsModeSet('i')) { MOD_RESULT = 0; FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr)); if (!MOD_RESULT) { - if (user->IsInvited(Ptr->name)) - { - /* user was invited to channel */ - /* there may be an optional channel NOTICE here */ - } - else + if (!user->IsInvited(Ptr->name)) { user->WriteServ("473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name); return NULL; @@ -299,43 +362,7 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo } } - /* NOTE: If the user is an oper here, we can extend their user->chans by up to - * OperMaxchans. For remote users which are not bound by the channel limits, - * we can extend infinitely. Otherwise, nope, youre restricted to MaxChans. - */ - if (!IS_LOCAL(user) || override == true) - { - return chanrec::ForceChan(Instance, Ptr, user, privs); - } - else if (IS_OPER(user)) - { - /* Oper allows extension up to the OperMaxchans value */ - if (user->chans.size() < Instance->Config->OperMaxChans) - { - return chanrec::ForceChan(Instance, Ptr, user, privs); - } - } - else if (user->chans.size() < Instance->Config->MaxChans) - { - return chanrec::ForceChan(Instance, Ptr, user, privs); - } - - - user->WriteServ("405 %s %s :You are on too many channels",user->nick, cname); - - if (new_channel) - { - /* Things went seriously pear shaped, so take this away. bwahaha. */ - chan_hash::iterator n = Instance->chanlist->find(cname); - if (n != Instance->chanlist->end()) - { - Ptr->DelUser(user); - DELETE(Ptr); - Instance->chanlist->erase(n); - } - } - - return NULL; + return chanrec::ForceChan(Instance, Ptr, user, privs); } chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, const std::string &privs) @@ -765,7 +792,7 @@ char* chanrec::ChanModes(bool showkey) if(this->modes[n]) { *offset++ = n + 65; - extparam = ""; + extparam.clear(); switch (n) { case CM_KEY: @@ -786,7 +813,7 @@ char* chanrec::ChanModes(bool showkey) extparam = this->GetModeParameter(n + 65); break; } - if (extparam != "") + if (!extparam.empty()) { charlcat(sparam,' ',MAXBUF); strlcat(sparam,extparam.c_str(),MAXBUF); @@ -831,7 +858,7 @@ void chanrec::UserList(userrec *user, CUList *ulist) for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if ((!has_user) && (i->first->modes[UM_INVISIBLE])) + if ((!has_user) && (i->first->IsModeSet('i'))) { /* * user is +i, and source not on the channel, does not show