]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/u_listmode.h
More comments
[user/henk/code/inspircd.git] / include / u_listmode.h
index 8315dbcd1e7e795bc38b5ade6544edc916aeca50..a2a3940451ff3fd99216dce2000d299c5a9a2b31 100644 (file)
@@ -1,3 +1,16 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
 #ifndef INSPIRCD_LISTMODE_PROVIDER
 #define INSPIRCD_LISTMODE_PROVIDER
 
@@ -8,7 +21,6 @@
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-
 #include "wildcard.h"
 #include "inspircd.h"
 
@@ -27,14 +39,18 @@ inline std::string stringtime()
        return TIME.str();
 }
 
+/** An item in a listmode's list
+ */
 class ListItem : public classbase
 {
 public:
        std::string nick;
-       std::string mask;
+       irc::string mask;
        std::string time;
 };
 
+/** The number of items a listmode's list may contain
+ */
 class ListLimit : public classbase
 {
 public:
@@ -46,6 +62,23 @@ public:
 typedef std::vector<ListItem> modelist;
 typedef std::vector<ListLimit> limitlist;
 
+class ListModeRequest : public Request
+{
+ public:
+       userrec* user;
+       chanrec* chan;
+
+       ListModeRequest(Module* sender, Module* target, userrec* u, chanrec* c) : Request(sender, target, "LM_CHECKLIST"), user(u), chan(c)
+       {
+       }
+
+       ~ListModeRequest()
+       {
+       }
+};
+
+/** The base class for listmodes defined by u_listmode.h
+ */
 class ListModeBase : public ModeHandler
 {
  protected:
@@ -62,7 +95,7 @@ class ListModeBase : public ModeHandler
        : ModeHandler(Instance, modechar, 1, 1, true, MODETYPE_CHANNEL, false), listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy), configtag(ctag)
        {
                this->DoRehash();
-               infokey = "exceptionbase_mode_" + std::string(1, mode) + "_list";
+               infokey = "listbase_mode_" + std::string(1, mode) + "_list";
        }
 
        std::pair<bool,std::string> ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
@@ -88,38 +121,39 @@ class ListModeBase : public ModeHandler
                channel->GetExt(infokey, el);
                if (el)
                {
-                       for(modelist::iterator it = el->begin(); it != el->end(); it++)
+                       for (modelist::reverse_iterator it = el->rbegin(); it != el->rend(); ++it)
                        {
                                user->WriteServ("%s %s %s %s %s %s", listnumeric.c_str(), user->nick, channel->name, it->mask.c_str(), it->nick.c_str(), it->time.c_str());
                        }
                }
-               user->WriteServ("%s %s %s %s", endoflistnumeric.c_str(), user->nick, channel->name, endofliststring.c_str());
+               user->WriteServ("%s %s %s :%s", endoflistnumeric.c_str(), user->nick, channel->name, endofliststring.c_str());
        }
 
        virtual void RemoveMode(chanrec* channel)
        {
-               ServerInstance->Log(DEBUG,"Removing listmode base from %s %s",channel->name,infokey.c_str());
                modelist* el;
                channel->GetExt(infokey, el);
                if (el)
                {
-                       ServerInstance->Log(DEBUG,"Channel is extended with a list");
-                       char moderemove[MAXBUF];
+                       irc::modestacker modestack(false);
+                       std::deque<std::string> stackresult;
+                       const char* mode_junk[MAXMODES+2];
+                       mode_junk[0] = channel->name;
                        userrec* n = new userrec(ServerInstance);
                        n->SetFd(FD_MAGIC_NUMBER);
-                       modelist copy;
-                       /* Make a copy of it, because we cant change the list whilst iterating over it */
-                       for(modelist::iterator it = el->begin(); it != el->end(); it++)
+                       for (modelist::iterator it = el->begin(); it != el->end(); it++)
                        {
-                               copy.push_back(*it);
+                               modestack.Push(this->GetModeChar(), assign(it->mask));
                        }
-                       for(modelist::iterator it = copy.begin(); it != copy.end(); it++)
+                       while (modestack.GetStackedLine(stackresult))
                        {
-                               ServerInstance->Log(DEBUG,"Remove item %s",it->mask.c_str());
-                               sprintf(moderemove,"-%c",this->GetModeChar());
-                               const char* parameters[] = { channel->name, moderemove, it->mask.c_str() };
-                               ServerInstance->SendMode(parameters, 3, n);
+                               for (size_t j = 0; j < stackresult.size(); j++)
+                               {
+                                       mode_junk[j+1] = stackresult[j].c_str();
+                               }
+                               ServerInstance->SendMode(mode_junk, stackresult.size() + 1, n);         
                        }
+
                        delete n;
                }
        }
@@ -135,17 +169,17 @@ class ListModeBase : public ModeHandler
 
                chanlimits.clear();
 
-               for(int i = 0; i < Conf.Enumerate(configtag); i++)
+               for (int i = 0; i < Conf.Enumerate(configtag); i++)
                {
                        // For each <banlist> tag
                        ListLimit limit;
                        limit.mask = Conf.ReadValue(configtag, "chan", i);
                        limit.limit = Conf.ReadInteger(configtag, "limit", i, true);
 
-                       if(limit.mask.size() && limit.limit > 0)
+                       if (limit.mask.size() && limit.limit > 0)
                                chanlimits.push_back(limit);
                }
-               if(chanlimits.size() == 0)
+               if (chanlimits.size() == 0)
                {
                        ListLimit limit;
                        limit.mask = "*";
@@ -182,7 +216,7 @@ class ListModeBase : public ModeHandler
                        // Check if the item already exists in the list
                        for (modelist::iterator it = el->begin(); it != el->end(); it++)
                        {
-                               if(parameter == it->mask)
+                               if (parameter == it->mask)
                                {
                                        /* Give a subclass a chance to error about this */
                                        TellAlreadyOnList(source, channel, parameter);
@@ -212,11 +246,11 @@ class ListModeBase : public ModeHandler
                                                 * 2) 'fix' parameter and then allow
                                                 * 3) deny
                                                 */
-                                               if(ValidateParam(source, channel, parameter))
+                                               if (ValidateParam(source, channel, parameter))
                                                {
                                                        // And now add the mask onto the list...
                                                        ListItem e;
-                                                       e.mask = parameter;
+                                                       e.mask = assign(parameter);
                                                        e.nick = source->nick;
                                                        e.time = stringtime();
 
@@ -233,7 +267,7 @@ class ListModeBase : public ModeHandler
                        }
 
                        /* List is full, give subclass a chance to send a custom message */
-                       if(!TellListTooLong(source, channel, parameter))
+                       if (!TellListTooLong(source, channel, parameter))
                        {
                                source->WriteServ("478 %s %s %s :Channel ban/ignore list is full", source->nick, channel->name, parameter.c_str());
                        }
@@ -248,10 +282,10 @@ class ListModeBase : public ModeHandler
                        {
                                for (modelist::iterator it = el->begin(); it != el->end(); it++)
                                {
-                                       if(parameter == it->mask)
+                                       if (parameter == it->mask)
                                        {
                                                el->erase(it);
-                                               if(el->size() == 0)
+                                               if (el->size() == 0)
                                                {
                                                        channel->Shrink(infokey);
                                                        delete el;
@@ -296,13 +330,21 @@ class ListModeBase : public ModeHandler
        {
                modelist* list;
                chan->GetExt(infokey, list);
+               irc::modestacker modestack(true);
+               std::deque<std::string> stackresult;
                if (list)
                {
                        for (modelist::iterator it = list->begin(); it != list->end(); it++)
                        {
-                               proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, "+" + std::string(1, mode) + " " + it->mask);
+                               modestack.Push(std::string(1, mode)[0], assign(it->mask));
                        }
                }
+               while (modestack.GetStackedLine(stackresult))
+               {
+                       irc::stringjoiner mode_join(" ", stackresult, 0, stackresult.size() - 1);
+                       std::string line = mode_join.GetJoined();
+                       proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, line);
+               }
        }
 
        virtual void DoCleanup(int target_type, void* item)
@@ -330,3 +372,4 @@ class ListModeBase : public ModeHandler
 };
 
 #endif
+