X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=c0055bf1d015a37f0b2b54a2dad78b3cf5d767d3;hb=2b51585f8be4fe954b07416f75787ca48f1f1a27;hp=00f8dbce6f466a502676e33cdbaf78669ab13251;hpb=3759fe0ba2420bd564abb4b034582ea0866907aa;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 00f8dbce6..c0055bf1d 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" @@ -83,7 +83,7 @@ long chanrec::GetUserCounter() void chanrec::AddUser(userrec* user) { - internal_userlist[user] = user; + internal_userlist[user] = user->nick; } unsigned long chanrec::DelUser(userrec* user) @@ -109,7 +109,7 @@ bool chanrec::HasUser(userrec* user) void chanrec::AddOppedUser(userrec* user) { - internal_op_userlist[user] = user; + internal_op_userlist[user] = user->nick; } void chanrec::DelOppedUser(userrec* user) @@ -124,7 +124,7 @@ void chanrec::DelOppedUser(userrec* user) void chanrec::AddHalfoppedUser(userrec* user) { - internal_halfop_userlist[user] = user; + internal_halfop_userlist[user] = user->nick; } void chanrec::DelHalfoppedUser(userrec* user) @@ -139,7 +139,7 @@ void chanrec::DelHalfoppedUser(userrec* user) void chanrec::AddVoicedUser(userrec* user) { - internal_voice_userlist[user] = user; + internal_voice_userlist[user] = user->nick; } void chanrec::DelVoicedUser(userrec* user) @@ -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 @@ -192,10 +217,18 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo 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,9 +246,10 @@ 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; @@ -254,18 +288,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; @@ -302,23 +331,29 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo * 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) + + + + /* + * We place no restrictions on remote users, users that are override-joining, or users that are + * currently in under MaxChans channels. For all others, they won't get in here. -- w00t + */ + if (!IS_LOCAL(user) || override == true || user->chans.size() < Instance->Config->MaxChans) { return chanrec::ForceChan(Instance, Ptr, user, privs); } - else if (*user->oper) + + /* + * If the above fails, and the user is an oper -- we let them in if they are under OperMaxChans. + * Otherwise, they're stuck, and need to override to get in, etc. -- w00t + */ + 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); @@ -621,8 +656,8 @@ void chanrec::WriteChannel(userrec* user, const std::string &text) for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if (IS_LOCAL(i->second)) - i->second->Write(out); + if (IS_LOCAL(i->first)) + i->first->Write(out); } } @@ -651,8 +686,8 @@ void chanrec::WriteChannelWithServ(const char* ServName, const std::string &text for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if (IS_LOCAL(i->second)) - i->second->Write(out); + if (IS_LOCAL(i->first)) + i->first->Write(out); } } @@ -714,12 +749,12 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if ((IS_LOCAL(i->second)) && (except_list.find(i->second) == except_list.end())) + if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end())) { if (serversource) - i->second->WriteServ(text); + i->first->WriteServ(text); else - i->second->Write(out); + i->first->Write(out); } } } @@ -727,7 +762,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi void chanrec::WriteAllExceptSender(userrec* user, bool serversource, char status, const std::string& text) { CUList except_list; - except_list[user] = user; + except_list[user] = user->nick; this->WriteAllExcept(user, serversource, status, except_list, std::string(text)); } @@ -741,7 +776,7 @@ int chanrec::CountInvisible() CUList *ulist= this->GetUsers(); for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if (!(i->second->modes[UM_INVISIBLE])) + if (!(i->first->IsModeSet('i'))) count++; } @@ -764,7 +799,7 @@ char* chanrec::ChanModes(bool showkey) if(this->modes[n]) { *offset++ = n + 65; - extparam = ""; + extparam.clear(); switch (n) { case CM_KEY: @@ -785,7 +820,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); @@ -802,7 +837,7 @@ char* chanrec::ChanModes(bool showkey) /* compile a userlist of a channel into a string, each nick seperated by * spaces and op, voice etc status shown as @ and +, and send it to 'user' */ -void chanrec::UserList(userrec *user) +void chanrec::UserList(userrec *user, CUList *ulist) { char list[MAXBUF]; size_t dlen, curlen; @@ -811,7 +846,7 @@ void chanrec::UserList(userrec *user) if (!IS_LOCAL(user)) return; - FOREACH_RESULT(I_OnUserList,OnUserList(user, this)); + FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist)); if (MOD_RESULT == 1) return; @@ -820,7 +855,8 @@ void chanrec::UserList(userrec *user) int numusers = 0; char* ptr = list + dlen; - CUList *ulist= this->GetUsers(); + if (!ulist) + ulist = this->GetUsers(); /* Improvement by Brain - this doesnt change in value, so why was it inside * the loop? @@ -829,7 +865,7 @@ void chanrec::UserList(userrec *user) for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) { - if ((!has_user) && (i->second->modes[UM_INVISIBLE])) + if ((!has_user) && (i->first->IsModeSet('i'))) { /* * user is +i, and source not on the channel, does not show @@ -838,10 +874,12 @@ void chanrec::UserList(userrec *user) continue; } - if (i->second->Visibility && !i->second->Visibility->VisibleTo(user)) + if (i->first->Visibility && !i->first->Visibility->VisibleTo(user)) continue; - size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->second), i->second->nick); + size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->first), i->second.c_str()); + /* OnUserList can change this - reset it back to normal */ + i->second = i->first->nick; curlen += ptrlen; ptr += ptrlen;