]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add ModeHandler* versions of channel mode access
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 15 Nov 2009 18:26:35 +0000 (18:26 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 15 Nov 2009 18:26:35 +0000 (18:26 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12133 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
include/mode.h
src/channels.cpp
src/mode.cpp

index 3ad26cedaa140a048b26461a890022ece609c2e7..59f4d1cf35530b35eb46ab98fbe79a1e717b3739 100644 (file)
 #define __CHANNELS_H__
 
 #include "membership.h"
-
-/** RFC1459 channel modes
- */
-enum ChannelModes {
-       CM_TOPICLOCK = 't'-65,  /* +t: Only operators can change topic */
-       CM_NOEXTERNAL = 'n'-65, /* +n: Only users in the channel can message it */
-       CM_INVITEONLY = 'i'-65, /* +i: Invite only */
-       CM_MODERATED = 'm'-65,  /* +m: Only voices and above can talk */
-       CM_SECRET = 's'-65,     /* +s: Secret channel */
-       CM_PRIVATE = 'p'-65,    /* +p: Private channel */
-       CM_KEY = 'k'-65,        /* +k: Keyed channel */
-       CM_LIMIT = 'l'-65       /* +l: Maximum user limit */
-};
+#include "mode.h"
 
 /** Holds an entry for a ban list, exemption list, or invite list.
  * This class contains a single element in a channel list, such as a banlist.
@@ -127,6 +115,7 @@ class CoreExport Channel : public Extensible
         * @param mode The mode character to set or unset
         * @param mode_on True if you want to set the mode or false if you want to remove it
         */
+       void SetMode(ModeHandler* mode, bool value);
        void SetMode(char mode,bool mode_on);
 
        /** Sets or unsets a custom mode in the channels info
@@ -134,13 +123,15 @@ class CoreExport Channel : public Extensible
         * @param parameter The parameter string to associate with this mode character.
         * If it is empty, the mode is unset; if it is nonempty, the mode is set.
         */
-       void SetModeParam(char mode, std::string parameter);
+       void SetModeParam(ModeHandler* mode, const std::string& parameter);
+       void SetModeParam(char mode, const std::string& parameter);
 
        /** Returns true if a mode is set on a channel
          * @param mode The mode character you wish to query
          * @return True if the custom mode is set, false if otherwise
          */
        inline bool IsModeSet(char mode) { return modes[mode-'A']; }
+       inline bool IsModeSet(ModeHandler* mode) { return modes[mode->GetModeChar()-'A']; }
 
 
        /** Returns the parameter for a custom mode on a channel.
@@ -154,6 +145,7 @@ class CoreExport Channel : public Extensible
          * @return The parameter for this mode is returned, or an empty string
          */
        std::string GetModeParameter(char mode);
+       std::string GetModeParameter(ModeHandler* mode);
 
        /** Sets the channel topic.
         * @param u The user setting the topic
index f4e5e8a60bdd95a2936d6393d23b82a3c84d60a8..f1768f5597589df60a17657d23d0e14220f4cbd4 100644 (file)
 #ifndef __MODE_H
 #define __MODE_H
 
-/* Forward declarations. */
-class User;
-
 #include "ctables.h"
-#include "channels.h"
 
 /**
  * Holds the values for different type of modes
@@ -214,7 +210,7 @@ class CoreExport ModeHandler : public classbase
         * Returns the mode character this handler handles.
         * @return The mode character
         */
-       char GetModeChar();
+       inline char GetModeChar() { return mode; }
 
        /** For user modes, return the current parameter, if any
         */
index 3f0fc4a36271077bc78b15f056b86a109210c6c7..31038484eb14baedf93858253908b0af711295da 100644 (file)
@@ -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,6 +71,14 @@ 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)
@@ -706,30 +724,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 = "<key>";
-                                       }
-                                       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 = "<key>";
+                       }
+                       else
+                       {
+                               extparam = this->GetModeParameter(n + 65);
                        }
                        if (!extparam.empty())
                        {
index 9c3b75101de3809997941bf85506840406e75cf1..fb154d5e2fb2257ae35051b5a12dbf4d6b1e387d 100644 (file)
@@ -99,11 +99,6 @@ int ModeHandler::GetNumParams(bool adding)
        return 0;
 }
 
-char ModeHandler::GetModeChar()
-{
-       return mode;
-}
-
 std::string ModeHandler::GetUserParameter(User* user)
 {
        return "";