]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_services.cpp
Gah, im forgetting to SetMode!
[user/henk/code/inspircd.git] / src / modules / m_services.cpp
index 8787241680af15262b38bd68df7735b93762ada3..c868eefef6d687bf348ff03ae5d80449d4713d25 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include <stdio.h>
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
 #include <string>
-
+#include "helperfuncs.h"
+#include "hashcomp.h"
 
 /* $ModDesc: Povides support for services +r user/chan modes and more */
 
 class ModuleServices : public Module
 {
        Server *Srv; 
+       bool kludgeme;
+
  public:
-       ModuleServices()
+       ModuleServices(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
+               Srv = Me;
 
                Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0);
                Srv->AddExtendedMode('r',MT_CLIENT,false,0,0);
                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);
+       }
+
+       /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */
+       virtual void OnWhois(userrec* source, userrec* dest)
+       {
+               if (dest->modes['r'-65])
+               {
+                       /* user is registered */
+                       WriteServ(source->fd, "307 %s %s :is a registered nick", source->nick, dest->nick);
+               }
+       }
+
+       void Implements(char* List)
+       {
+               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, const std::string &oldnick)
+       {
+               /* On nickchange, if they have +r, remove it */
+               if (user->modes['r'-65])
+               {
+                       char* modechange[2];
+                       modechange[0] = user->nick;
+                       modechange[1] = "-r";
+                       kludgeme = true;
+                       Srv->SendMode(modechange,2,user);
+                       kludgeme = false;
+               }
        }
        
        virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
@@ -46,40 +88,34 @@ class ModuleServices : public Module
                        if (type == MT_CHANNEL)
                        {
                                // only a u-lined server may add or remove the +r mode.
-                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
+                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"") || (strchr(user->nick,'.'))))
                                {
-                                       // FCS - BugFix for #27 :)
-                                       if ((!strchr(user->modes,'r')) && (mode_on == false)) {
-                                               return 1;
-                                       } else if ((strchr(user->modes,'r')) && (mode_on == true)) {
-                                               return 1;
-                                       } else { 
-                                               return 0;
-                                       }
+                                       log(DEBUG,"Allowing umode +r, server and nick are: '%s','%s'",user->nick,user->server);
+                                       return 1;
                                }
                                else
                                {
-                                       Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode");
+                                       log(DEBUG,"Only a server can set chanmode +r, server and nick are: '%s','%s'",user->nick,user->server);
+                                       Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r channel mode");
                                }
                        }
                        else
                        {
-                               if (!strcmp(user->server,""))
+                               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;
                                }
                                else
                                {
+                                       log(DEBUG,"Only a server can set umode +r, server and nick are: '%s','%s'",user->nick,user->server);
                                        Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a server may modify the +r user mode");
                                }
                        }
                }
                else if (modechar == 'R')
                {
-                       if (type == MT_CHANNEL)
-                       {
-                               return 1;
-                       }
+                       return 1;
                }
                else if (modechar == 'M')
                {
@@ -92,14 +128,14 @@ 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)
                {
                        chanrec* c = (chanrec*)dest;
-                       if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r')))
+                       if ((c->IsModeSet('M')) && (!user->modes['r'-65]))
                        {
-                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
+                               if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
                                {
                                        // user is ulined, can speak regardless
                                        return 0;
@@ -112,7 +148,7 @@ class ModuleServices : public Module
                if (target_type == TYPE_USER)
                {
                        userrec* u = (userrec*)dest;
-                       if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r')))
+                       if ((u->modes['R'-65]) && (user->modes['r'-65]))
                        {
                                if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
                                {
@@ -127,48 +163,18 @@ 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)
        {
                if (chan)
                {
-                       if (chan->IsCustomModeSet('R'))
+                       if (chan->IsModeSet('R'))
                        {
-                               if (!strchr(user->modes,'r'))
+                               if (user->modes['r'-65])
                                {
                                        if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)))
                                        {
@@ -186,18 +192,12 @@ class ModuleServices : public Module
 
        virtual ~ModuleServices()
        {
-               delete Srv;
        }
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,0);
+               return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
        }
-       
-       virtual void OnUserConnect(userrec* user)
-       {
-       }
-
 };
 
 
@@ -212,9 +212,9 @@ class ModuleServicesFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleServices;
+               return new ModuleServices(Me);
        }
        
 };