]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_services.cpp
Probably wont compile yet - purge_empty_channels refactor
[user/henk/code/inspircd.git] / src / modules / m_services.cpp
index a3573137014c0cbb0f1d41c1b40c65ec54f13c71..3253d34dd2defa605b81a44a750e809bedbfe20e 100644 (file)
@@ -29,6 +29,8 @@ using namespace std;
 class ModuleServices : public Module
 {
        Server *Srv; 
+       bool kludgeme;
+
  public:
        ModuleServices(Server* Me)
                : Module::Module(Me)
@@ -40,30 +42,28 @@ class ModuleServices : public Module
                Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0);
                Srv->AddExtendedMode('R',MT_CLIENT,false,0,0);
                Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0);
+
+               kludgeme = false;
+       }
+
+       virtual void On005Numeric(std::string &output)
+       {
+               InsertMode(output, "rRM", 4);
        }
 
-        virtual void On005Numeric(std::string &output)
-        {
-                std::stringstream line(output);
-                std::string temp1, temp2;
-                while (!line.eof())
-                {
-                        line >> temp1;
-                        if (temp1.substr(0,10) == "CHANMODES=")
-                        {
-                                // append the chanmode to the end
-                                temp1 = temp1.substr(10,temp1.length());
-                                temp1 = "CHANMODES=" + temp1 + "rRM";
-                        }
-                        temp2 = temp2 + temp1 + " ";
-                }
-               if (temp2.length())
-                       output = temp2.substr(0,temp2.length()-1);
-        }
+       /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */
+       virtual void OnWhois(userrec* source, userrec* dest)
+       {
+               if (strchr(dest->modes, 'r'))
+               {
+                       /* user is registered */
+                       WriteServ(source->fd, "307 %s %s :is a registered nick", source->nick, dest->nick);
+               }
+       }
 
        void Implements(char* List)
        {
-               List[I_OnUserPostNick] = List[I_OnUserPreMessage] = List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
+               List[I_OnWhois] = List[I_OnUserPostNick] = List[I_OnUserPreMessage] = List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreNotice] = List[I_OnUserPreJoin] = 1;
        }
 
        virtual void OnUserPostNick(userrec* user, std::string oldnick)
@@ -74,7 +74,9 @@ class ModuleServices : public Module
                        char* modechange[2];
                        modechange[0] = user->nick;
                        modechange[1] = "-r";
+                       kludgeme = true;
                        Srv->SendMode(modechange,2,user);
+                       kludgeme = false;
                }
        }
        
@@ -99,7 +101,7 @@ class ModuleServices : public Module
                        }
                        else
                        {
-                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
+                               if ((kludgeme) || (Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
                                {
                                        log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
                                        return 1;
@@ -126,7 +128,7 @@ class ModuleServices : public Module
                return 0;
        }
 
-       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
+       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
                if (target_type == TYPE_CHANNEL)
                {
@@ -161,39 +163,9 @@ class ModuleServices : public Module
                return 0;
        }
        
-       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
+       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
-               if (target_type == TYPE_CHANNEL)
-               {
-                       chanrec* c = (chanrec*)dest;
-                       if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
-                       {
-                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
-                               {
-                                       // user is ulined, can speak regardless
-                                       return 0;
-                               }
-                               // user noticing a +M channel and is not registered
-                               Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel");
-                               return 1;
-                       }
-               }
-               if (target_type == TYPE_USER)
-               {
-                       userrec* u = (userrec*)dest;
-                       if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
-                       {
-                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
-                               {
-                                       // user is ulined, can speak regardless
-                                       return 0;
-                               }
-                               // user noticing a +R user and is not registered
-                               Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user");
-                               return 1;
-                       }
-               }
-               return 0;
+               return OnUserPreMessage(user,dest,target_type,text,status);
        }
        
        virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)