]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Did some renaming so that the methods for modes in chanrec and userrec are identical.
[user/henk/code/inspircd.git] / src / channels.cpp
index 4eba586ab6a9cd8f6c09e87f7e3c74b83482d6c5..a25b2927c7ea0a3b7f196496adf00cde04ecba2d 100644 (file)
 
 using namespace std;
 
-#include "configreader.h"
-#include "inspircd.h"
-#include "inspircd_io.h"
-#include <unistd.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/utsname.h>
-#include <time.h>
 #include <string>
-#ifdef GCC3
-#include <ext/hash_map>
-#else
-#include <hash_map>
-#endif
 #include <map>
 #include <sstream>
 #include <vector>
 #include <deque>
+#include "configreader.h"
+#include "inspircd.h"
+#include "hash_map.h"
 #include "users.h"
 #include "ctables.h"
 #include "globals.h"
@@ -48,19 +38,11 @@ using namespace std;
 #include "helperfuncs.h"
 #include "typedefs.h"
 
-#ifdef GCC3
-#define nspace __gnu_cxx
-#else
-#define nspace std
-#endif
-
 extern ServerConfig* Config;
 
 extern int MODCOUNT;
 extern std::vector<Module*> modules;
 extern std::vector<ircd_module*> factory;
-extern int WHOWAS_STALE;
-extern int WHOWAS_MAX;
 extern time_t TIME;
 extern chan_hash chanlist;
 
@@ -75,26 +57,30 @@ chanrec::chanrec()
        memset(&modes,0,64);
 }
 
-void chanrec::SetCustomMode(char mode,bool mode_on)
+void chanrec::SetMode(char mode,bool mode_on)
 {
        modes[mode-65] = mode_on;
        if (!mode_on)
-               this->SetCustomModeParam(mode,"",false);
+               this->SetModeParam(mode,"",false);
 }
 
 
-void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
+void chanrec::SetModeParam(char mode,char* parameter,bool mode_on)
 {
-       log(DEBUG,"SetCustomModeParam called");
+       log(DEBUG,"SetModeParam called");
        
-       std::map<char,char*>::iterator n = custom_mode_params.find(mode);       
+       CustomModeList::iterator n = custom_mode_params.find(mode);     
 
        if (mode_on)
        {
-               log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
                if (n == custom_mode_params.end())
                {
                        custom_mode_params[mode] = strdup(parameter);
+                       log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
+               }
+               else
+               {
+                       log(DEBUG, "Tried to set custom mode parameter for %c '%s' when it was already '%s'", mode, parameter, n->second);
                }
        }
        else
@@ -124,7 +110,7 @@ std::string chanrec::GetModeParameter(char mode)
        }
        else
        {
-               std::map<char,char*>::iterator n = custom_mode_params.find(mode);
+               CustomModeList::iterator n = custom_mode_params.find(mode);
                if (n != custom_mode_params.end())
                {
                        return n->second;
@@ -145,7 +131,8 @@ void chanrec::AddUser(userrec* user)
 
 unsigned long chanrec::DelUser(userrec* user)
 {
-       CUList::iterator a = internal_userlist.find(user);
+       CUListIter a = internal_userlist.find(user);
+       
        if (a != internal_userlist.end())
        {
                internal_userlist.erase(a);
@@ -153,8 +140,8 @@ unsigned long chanrec::DelUser(userrec* user)
                DelOppedUser(user);
                DelHalfoppedUser(user);
                DelVoicedUser(user);
-               return internal_userlist.size();
        }
+       
        return internal_userlist.size();
 }
 
@@ -170,7 +157,7 @@ void chanrec::AddOppedUser(userrec* user)
 
 void chanrec::DelOppedUser(userrec* user)
 {
-       CUList::iterator a = internal_op_userlist.find(user);
+       CUListIter a = internal_op_userlist.find(user);
        if (a != internal_op_userlist.end())
        {
                internal_op_userlist.erase(a);
@@ -185,11 +172,11 @@ void chanrec::AddHalfoppedUser(userrec* user)
 
 void chanrec::DelHalfoppedUser(userrec* user)
 {
-       CUList::iterator a = internal_halfop_userlist.find(user);
+       CUListIter a = internal_halfop_userlist.find(user);
+
        if (a != internal_halfop_userlist.end())
        {   
                internal_halfop_userlist.erase(a);
-               return; 
        }
 }
 
@@ -200,11 +187,11 @@ void chanrec::AddVoicedUser(userrec* user)
 
 void chanrec::DelVoicedUser(userrec* user)
 {
-       CUList::iterator a = internal_voice_userlist.find(user);
+       CUListIter a = internal_voice_userlist.find(user);
+       
        if (a != internal_voice_userlist.end())
        {
                internal_voice_userlist.erase(a);
-               return; 
        }
 }
 
@@ -384,11 +371,11 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
 
        log(DEBUG,"Passed channel checks");
 
-       for (std::vector<ucrec*>::const_iterator index = user->chans.begin(); index != user->chans.end(); index++)
+       for (UserChanList::const_iterator index = user->chans.begin(); index != user->chans.end(); index++)
        {
-               if ((ucrec*)(*index)->channel == NULL)
+               if ((*index)->channel == NULL)
                {
-                       return ForceChan(Ptr,(ucrec*)(*index),user,created);
+                       return ForceChan(Ptr, *index, user, created);
                }
        }
 
@@ -427,7 +414,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
                if (n != chanlist.end())
                {
                        Ptr->DelUser(user);
-                       delete Ptr;
+                       DELETE(Ptr);
                        chanlist.erase(n);
                        for (unsigned int index =0; index < user->chans.size(); index++)
                        {
@@ -439,6 +426,17 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
                        }
                }
        }
+       else
+       {
+               for (unsigned int index =0; index < user->chans.size(); index++)
+               {
+                       if (user->chans[index]->channel == Ptr)
+                       {
+                               user->chans[index]->channel = NULL;
+                               user->chans[index]->uc_modes = 0;
+                       }
+               }
+       }
        return NULL;
 }
 
@@ -531,7 +529,7 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool
                {
                        log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
                        FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
-                       delete Ptr;
+                       DELETE(Ptr);
                        chanlist.erase(iter);
                }
        }
@@ -581,8 +579,8 @@ void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool trigger
                if (iter != chanlist.end())
                {
                        log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
-                       delete Ptr;
+                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
+                       DELETE(Ptr);
                        chanlist.erase(iter);
                }
        }
@@ -605,6 +603,11 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
                        WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
                        return;
                }
+                if ((is_uline(user->server)) && (!is_uline(src->server)))
+               {
+                       WriteServ(src->fd,"482 %s %s :Only a u-line may kick a u-line from a channel.",src->nick, Ptr->name);
+                       return;
+               }
                int MOD_RESULT = 0;
 
                if (!is_uline(src->server))
@@ -642,14 +645,14 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
 
        FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,Ptr,reason));
                        
-       for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+       for (UserChanList::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
        {
                /* zap it from the channel list of the user */
-               if ((((ucrec*)(*i))->channel) && (((ucrec*)(*i))->channel == Ptr))
+               if ((*i)->channel && ((*i)->channel == Ptr))
                {
                        WriteChannel(Ptr,src,"KICK %s %s :%s",Ptr->name, user->nick, reason);
-                       ((ucrec*)(*i))->uc_modes = 0;
-                       ((ucrec*)(*i))->channel = NULL;
+                       (*i)->uc_modes = 0;
+                       (*i)->channel = NULL;
                        log(DEBUG,"del_channel: unlinked: %s %s",user->nick,Ptr->name);
                        break;
                }
@@ -667,7 +670,7 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
                {
                        log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
                        FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
-                       delete Ptr;
+                       DELETE(Ptr);
                        chanlist.erase(iter);
                }
        }