X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=0b9eb1cc478d1681ecfcb1a8fd59b6915f046844;hb=d1f2a430501aec8bc893647dc1049b8499e1caf6;hp=fd9861279e15258972b5086b10cdce92c3c1c0ed;hpb=b16e16ac1bae4ac5494778b4b8a7009febb58137;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index fd9861279..0b9eb1cc4 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see @@ -36,7 +36,12 @@ void Channel::SetMode(char mode,bool mode_on) modes[mode-65] = mode_on; } -void Channel::SetModeParam(char mode, std::string parameter) +void Channel::SetMode(ModeHandler* mh, bool on) +{ + modes[mh->GetModeChar() - 65] = on; +} + +void Channel::SetModeParam(char mode, const std::string& parameter) { CustomModeList::iterator n = custom_mode_params.find(mode); // always erase, even if changing, so that the map gets the new value @@ -53,6 +58,11 @@ void Channel::SetModeParam(char mode, std::string parameter) } } +void Channel::SetModeParam(ModeHandler* mode, const std::string& parameter) +{ + SetModeParam(mode->GetModeChar(), parameter); +} + std::string Channel::GetModeParameter(char mode) { CustomModeList::iterator n = custom_mode_params.find(mode); @@ -61,31 +71,36 @@ std::string Channel::GetModeParameter(char mode) return ""; } +std::string Channel::GetModeParameter(ModeHandler* mode) +{ + CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar()); + if (n != custom_mode_params.end()) + return n->second; + return ""; +} + int Channel::SetTopic(User *u, std::string &ntopic, bool forceset) { - if (u) + if (!u) + u = ServerInstance->FakeClient; + if (IS_LOCAL(u) && !forceset) { - if(!forceset) - { - ModResult res; - /* 0: check status, 1: don't, -1: disallow change silently */ - - FIRST_MOD_RESULT(OnPreTopicChange, res, (u,this,ntopic)); + ModResult res; + FIRST_MOD_RESULT(OnPreTopicChange, res, (u,this,ntopic)); - if (res == MOD_RES_DENY) + if (res == MOD_RES_DENY) + return CMD_FAILURE; + if (res != MOD_RES_ALLOW) + { + if (!this->HasUser(u)) + { + u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str()); return CMD_FAILURE; - if (res != MOD_RES_ALLOW) + } + if ((this->IsModeSet('t')) && (this->GetPrefixValue(u) < HALFOP_VALUE)) { - if (!this->HasUser(u)) - { - u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str()); - return CMD_FAILURE; - } - if ((this->IsModeSet('t')) && (this->GetPrefixValue(u) < HALFOP_VALUE)) - { - u->WriteNumeric(482, "%s %s :You must be at least a half-operator to change the topic on this channel", u->nick.c_str(), this->name.c_str()); - return CMD_FAILURE; - } + u->WriteNumeric(482, "%s %s :You do not have access to change the topic on this channel", u->nick.c_str(), this->name.c_str()); + return CMD_FAILURE; } } } @@ -104,11 +119,7 @@ int Channel::SetTopic(User *u, std::string &ntopic, bool forceset) this->topicset = ServerInstance->Time(); - // XXX: this check for 'u' is probably pre-fake-user, and it fucking sucks anyway. we need to change this. - if (u) - { - FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic)); - } + FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic)); return CMD_SUCCESS; } @@ -377,7 +388,9 @@ Channel* Channel::ForceChan(Channel* Ptr, User* user, const std::string &privs, Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str()); /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */ - std::string ms = ServerInstance->Modes->ModeString(user, Ptr); + std::string ms = memb->modes; + for(unsigned int i=0; i < memb->modes.length(); i++) + ms.append(" ").append(user->nick); if ((Ptr->GetUserCounter() > 1) && (ms.length())) Ptr->WriteAllExceptSender(user, true, 0, "MODE %s +%s", Ptr->name.c_str(), ms.c_str()); @@ -644,19 +657,19 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out) { - char statmode = 0; + unsigned int minrank = 0; if (status) { ModeHandler* mh = ServerInstance->Modes->FindPrefix(status); if (mh) - statmode = mh->GetModeChar(); + minrank = mh->GetPrefixRank(); } for (UserMembIter i = userlist.begin(); i != userlist.end(); i++) { - if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end())) + if (IS_LOCAL(i->first) && (except_list.find(i->first) == except_list.end())) { - /* User doesnt have the status we're after */ - if (statmode && !i->second->hasMode(statmode)) + /* User doesn't have the status we're after */ + if (minrank && i->second->getRank() < minrank) continue; i->first->Write(out); @@ -704,30 +717,13 @@ char* Channel::ChanModes(bool showkey) { *offset++ = n + 65; extparam.clear(); - switch (n) + if (n == 'k' - 65 && !showkey) { - case CM_KEY: - // Unfortunately this must be special-cased, as we definitely don't want to always display key. - if (showkey) - { - extparam = this->GetModeParameter('k'); - } - else - { - extparam = ""; - } - break; - case CM_NOEXTERNAL: - case CM_TOPICLOCK: - case CM_INVITEONLY: - case CM_MODERATED: - case CM_SECRET: - case CM_PRIVATE: - /* We know these have no parameters */ - break; - default: - extparam = this->GetModeParameter(n + 65); - break; + extparam = ""; + } + else + { + extparam = this->GetModeParameter(n + 65); } if (!extparam.empty()) { @@ -926,14 +922,14 @@ unsigned int Channel::GetPrefixValue(User* user) return m->second->getRank(); } -void Channel::SetPrefix(User* user, char prefix, bool adding) +bool Channel::SetPrefix(User* user, char prefix, bool adding) { ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL); if (!delta_mh) - return; + return false; UserMembIter m = userlist.find(user); if (m == userlist.end()) - return; + return false; for(unsigned int i=0; i < m->second->modes.length(); i++) { char mchar = m->second->modes[i]; @@ -944,11 +940,12 @@ void Channel::SetPrefix(User* user, char prefix, bool adding) m->second->modes.substr(0,i) + (adding ? std::string(1, prefix) : "") + m->second->modes.substr(mchar == prefix ? i+1 : i); - return; + return adding != (mchar == prefix); } } if (adding) m->second->modes += std::string(1, prefix); + return adding; } void Channel::RemoveAllPrefixes(User* user)