]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_chanprotect.cpp
Changed so that when the first in the channel gets founder, the +q mode change is...
[user/henk/code/inspircd.git] / src / modules / m_chanprotect.cpp
index 65a7b0e84c55fad5b307ee00dc191aff69eaae3a..8cf91d45cda6e1fcd5c527e27a480bb1633ba1a9 100644 (file)
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include <stdio.h>
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "helperfuncs.h"
 
 /* $ModDesc: Provides channel modes +a and +q */
 
-char dummyvalue[] = "on";
+char fakevalue[] = "on";
 
 class ModuleChanProtect : public Module
 {
@@ -69,6 +72,13 @@ class ModuleChanProtect : public Module
                        output = temp2.substr(0,temp2.length()-1);
         }
 
+       virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason)
+       {
+               // FIX: when someone gets kicked from a channel we must remove their Extensibles!
+               user->Shrink("cm_founder_"+std::string(chan->name));
+               user->Shrink("cm_protect_"+std::string(chan->name));
+       }
+
        virtual void OnUserPart(userrec* user, chanrec* channel)
        {
                // FIX: when someone parts a channel we must remove their Extensibles!
@@ -97,7 +107,12 @@ class ModuleChanProtect : public Module
                                // this way is best as it adds data thats accessible to other modules
                                // (so long as you document your code properly) without breaking anything
                                // because its encapsulated neatly in a map.
-                               if (user->Extend("cm_founder_"+std::string(channel->name),dummyvalue))
+
+                               // Change requested by katsklaw... when the first in is set to get founder,
+                               // to make it clearer that +q has been given, send that one user the +q notice
+                               // so that their client's syncronization and their sanity are left intact.
+                               WriteServ(user->fd,"MODE %s +q %s",channel->name,user->nick);
+                               if (user->Extend("cm_founder_"+std::string(channel->name),fakevalue))
                                {
                                        Srv->Log(DEBUG,"Marked user "+std::string(user->nick)+" as founder for "+std::string(channel->name));
                                }
@@ -212,7 +227,7 @@ class ModuleChanProtect : public Module
                                {
                                        if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
                                        {
-                                               theuser->Extend("cm_founder_"+std::string(chan->name),dummyvalue);
+                                               theuser->Extend("cm_founder_"+std::string(chan->name),fakevalue);
                                                return 1;
                                        }
                                }
@@ -255,7 +270,7 @@ class ModuleChanProtect : public Module
                                {
                                        if (!theuser->GetExt("cm_protect_"+std::string(chan->name)))
                                        {
-                                               theuser->Extend("cm_protect_"+std::string(chan->name),dummyvalue);
+                                               theuser->Extend("cm_protect_"+std::string(chan->name),fakevalue);
                                                return 1;
                                        }
                                }
@@ -279,6 +294,35 @@ class ModuleChanProtect : public Module
                }
                return 0;
        }
+
+       virtual void OnSendList(userrec* user, chanrec* channel, char mode)
+       {
+               if (mode == 'q')
+               {
+                       chanuserlist cl = Srv->GetUsers(channel);
+                       for (int i = 0; i < cl.size(); i++)
+                       {
+                               if (cl[i]->GetExt("cm_founder_"+std::string(channel->name)))
+                               {
+                                       WriteServ(user->fd,"386 %s %s %s",user->nick, channel->name,cl[i]->nick);
+                               }
+                       }
+                       WriteServ(user->fd,"387 %s %s :End of channel founder list",user->nick, channel->name);
+               }
+                if (mode == 'a')
+                {
+                        chanuserlist cl = Srv->GetUsers(channel);
+                        for (int i = 0; i < cl.size(); i++)
+                        {
+                                if (cl[i]->GetExt("cm_protect_"+std::string(channel->name)))
+                                {
+                                        WriteServ(user->fd,"388 %s %s %s",user->nick, channel->name,cl[i]->nick);
+                                }
+                        }
+                       WriteServ(user->fd,"389 %s %s :End of channel protected user list",user->nick, channel->name);
+                }
+
+       }
        
        virtual ~ModuleChanProtect()
        {