]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Change the syntax of FOREACH macros to be less dumb.
[user/henk/code/inspircd.git] / src / channels.cpp
index 4b701cc3c04df9fbaa727394e0065d2ff5a5d5c4..d82ad6c233b4345d838d61b41113df96c72c503d 100644 (file)
 #include <cstdarg>
 #include "mode.h"
 
-static ModeReference ban(NULL, "ban");
+namespace
+{
+       ChanModeReference ban(NULL, "ban");
+       ChanModeReference inviteonlymode(NULL, "inviteonly");
+       ChanModeReference keymode(NULL, "key");
+       ChanModeReference limitmode(NULL, "limit");
+       ChanModeReference secretmode(NULL, "secret");
+       ChanModeReference privatemode(NULL, "private");
+       UserModeReference invisiblemode(NULL, "invisible");
+}
 
 Channel::Channel(const std::string &cname, time_t ts)
 {
@@ -47,8 +56,9 @@ void Channel::SetMode(ModeHandler* mh, bool on)
        modes[mh->GetModeChar() - 65] = on;
 }
 
-void Channel::SetModeParam(char mode, const std::string& parameter)
+void Channel::SetModeParam(ModeHandler* mh, const std::string& parameter)
 {
+       char mode = mh->GetModeChar();
        if (parameter.empty())
        {
                custom_mode_params.erase(mode);
@@ -61,19 +71,6 @@ void Channel::SetModeParam(char mode, const 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);
-       if (n != custom_mode_params.end())
-               return n->second;
-       return "";
-}
-
 std::string Channel::GetModeParameter(ModeHandler* mode)
 {
        CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar());
@@ -89,7 +86,7 @@ void Channel::SetTopic(User* u, const std::string& ntopic)
        this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
        this->topicset = ServerInstance->Time();
 
-       FOREACH_MOD(I_OnPostTopicChange,OnPostTopicChange(u, this, this->topic));
+       FOREACH_MOD(OnPostTopicChange, (u, this, this->topic));
 }
 
 Membership* Channel::AddUser(User* user)
@@ -123,7 +120,7 @@ void Channel::CheckDestroy()
        /* kill the record */
        if (iter != ServerInstance->chanlist->end())
        {
-               FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
+               FOREACH_MOD(OnChannelDelete, (this));
                ServerInstance->chanlist->erase(iter);
        }
 
@@ -264,7 +261,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                        // then this entire section is skipped
                        if (MOD_RESULT == MOD_RES_PASSTHRU)
                        {
-                               std::string ckey = chan->GetModeParameter('k');
+                               std::string ckey = chan->GetModeParameter(keymode);
                                bool invited = user->IsInvited(chan);
                                bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
 
@@ -279,7 +276,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                                        }
                                }
 
-                               if (chan->IsModeSet('i'))
+                               if (chan->IsModeSet(inviteonlymode))
                                {
                                        FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
                                        if (!MOD_RESULT.check(invited))
@@ -289,7 +286,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                                        }
                                }
 
-                               std::string limit = chan->GetModeParameter('l');
+                               std::string limit = chan->GetModeParameter(limitmode);
                                if (!limit.empty())
                                {
                                        FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
@@ -358,7 +355,7 @@ void Channel::ForceJoin(User* user, const std::string* privs, bool bursting, boo
 
        // Tell modules about this join, they have the chance now to populate except_list with users we won't send the JOIN (and possibly MODE) to
        CUList except_list;
-       FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created_by_local, except_list));
+       FOREACH_MOD(OnUserJoin, (memb, bursting, created_by_local, except_list));
 
        this->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", this->name.c_str());
 
@@ -383,7 +380,7 @@ void Channel::ForceJoin(User* user, const std::string* privs, bool bursting, boo
                this->UserList(user);
        }
 
-       FOREACH_MOD(I_OnPostJoin,OnPostJoin(memb));
+       FOREACH_MOD(OnPostJoin, (memb));
 }
 
 bool Channel::IsBanned(User* user)
@@ -468,7 +465,7 @@ void Channel::PartUser(User *user, std::string &reason)
        {
                Membership* memb = membiter->second;
                CUList except_list;
-               FOREACH_MOD(I_OnUserPart,OnUserPart(memb, reason, except_list));
+               FOREACH_MOD(OnUserPart, (memb, reason, except_list));
 
                WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
 
@@ -523,7 +520,7 @@ void Channel::KickUser(User* src, User* victim, const std::string& reason, Membe
        }
 
        CUList except_list;
-       FOREACH_MOD(I_OnUserKick,OnUserKick(src, memb, reason, except_list));
+       FOREACH_MOD(OnUserKick, (src, memb, reason, except_list));
 
        WriteAllExcept(src, false, 0, except_list, "KICK %s %s :%s", name.c_str(), victim->nick.c_str(), reason.c_str());
 
@@ -632,13 +629,17 @@ const char* Channel::ChanModes(bool showkey)
                if(this->modes[n])
                {
                        scratch.push_back(n + 65);
+                       ModeHandler* mh = ServerInstance->Modes->FindMode(n+'A', MODETYPE_CHANNEL);
+                       if (!mh)
+                               continue;
+
                        if (n == 'k' - 65 && !showkey)
                        {
                                sparam += " <key>";
                        }
                        else
                        {
-                               const std::string param = this->GetModeParameter(n + 65);
+                               const std::string param = this->GetModeParameter(mh);
                                if (!param.empty())
                                {
                                        sparam += ' ';
@@ -657,7 +658,7 @@ const char* Channel::ChanModes(bool showkey)
  */
 void Channel::UserList(User *user)
 {
-       if (this->IsModeSet('s') && !this->HasUser(user) && !user->HasPrivPermission("channels/auspex"))
+       if (this->IsModeSet(secretmode) && !this->HasUser(user) && !user->HasPrivPermission("channels/auspex"))
        {
                user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
                return;
@@ -665,7 +666,7 @@ void Channel::UserList(User *user)
 
        std::string list = user->nick;
        list.push_back(' ');
-       list.push_back(this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=');
+       list.push_back(this->IsModeSet(secretmode) ? '@' : this->IsModeSet(privatemode) ? '*' : '=');
        list.push_back(' ');
        list.append(this->name).append(" :");
        std::string::size_type pos = list.size();
@@ -683,7 +684,7 @@ void Channel::UserList(User *user)
        {
                if (i->first->quitting)
                        continue;
-               if ((!has_user) && (i->first->IsModeSet('i')))
+               if ((!has_user) && (i->first->IsModeSet(invisiblemode)))
                {
                        /*
                         * user is +i, and source not on the channel, does not show
@@ -695,7 +696,7 @@ void Channel::UserList(User *user)
                prefixlist = this->GetPrefixChar(i->first);
                nick = i->first->nick;
 
-               FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->second, prefixlist, nick));
+               FOREACH_MOD(OnNamesListItem, (user, i->second, prefixlist, nick));
 
                /* Nick was nuked, a module wants us to skip it */
                if (nick.empty())