]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Tidyup op/halfop/voice list on part/quit
[user/henk/code/inspircd.git] / src / channels.cpp
index 19cf14d550a8de4fb8ee417332fb64007f28ba0d..f067646d3358656ff94647e8846d1bf2ee7058e5 100644 (file)
@@ -173,7 +173,61 @@ void chanrec::DelUser(char* castuser)
                internal_userlist.erase(a);
                return;
        }
-       log(DEBUG,"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!",name);
+       /* Tidy up any others */
+       DelOppedUser(castuser);
+       DelHalfoppedUser(castuser);
+       DelVoicedUser(castuser);
+}
+
+void chanrec::AddOppedUser(char* castuser)
+{
+        internal_op_userlist[castuser] = castuser;
+        log(DEBUG,"Added casted user to channel's internal list");
+}
+
+void chanrec::DelOppedUser(char* castuser)
+{
+        std::map<char*,char*>::iterator a = internal_op_userlist.find(castuser);
+        if (a != internal_op_userlist.end())
+        {
+                log(DEBUG,"Removed casted user from channel's internal list");
+                internal_op_userlist.erase(a);
+                return;
+        }
+}
+
+void chanrec::AddHalfoppedUser(char* castuser)
+{
+        internal_halfop_userlist[castuser] = castuser;
+        log(DEBUG,"Added casted user to channel's internal list");
+}
+
+void chanrec::DelHalfoppedUser(char* castuser)
+{
+        std::map<char*,char*>::iterator a = internal_halfop_userlist.find(castuser);
+        if (a != internal_halfop_userlist.end())
+        {       
+                log(DEBUG,"Removed casted user from channel's internal list");
+                internal_halfop_userlist.erase(a);
+                return; 
+        }       
+}
+
+void chanrec::AddVoicedUser(char* castuser)
+{
+        internal_voice_userlist[castuser] = castuser;
+        log(DEBUG,"Added casted user to channel's internal list");
+}
+
+void chanrec::DelVoicedUser(char* castuser)
+{
+        std::map<char*,char*>::iterator a = internal_voice_userlist.find(castuser);
+        if (a != internal_voice_userlist.end())
+        {       
+                log(DEBUG,"Removed casted user from channel's internal list");
+                internal_voice_userlist.erase(a);
+                return; 
+        }       
 }
 
 std::map<char*,char*> *chanrec::GetUsers()
@@ -181,6 +235,21 @@ std::map<char*,char*> *chanrec::GetUsers()
        return &internal_userlist;
 }
 
+std::map<char*,char*> *chanrec::GetOppedUsers()
+{
+               return &internal_op_userlist;
+}
+
+std::map<char*,char*> *chanrec::GetHalfoppedUsers()
+{
+               return &internal_halfop_userlist;
+}
+
+std::map<char*,char*> *chanrec::GetVoicedUsers()
+{
+               return &internal_voice_userlist;
+}
+
 /* add a channel to a user, creating the record for it if needed and linking
  * it to the user record */
 
@@ -369,6 +438,7 @@ chanrec* ForceChan(chanrec* Ptr,ucrec &a,userrec* user, int created)
         {
                 /* first user in is given ops */
                 a.uc_modes = UCMODE_OP;
+               Ptr->AddOppedUser((char*)user);
         }
         else
         {
@@ -458,12 +528,15 @@ void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool trigger
                return;
        }
 
-       if (!has_channel(user,Ptr))
+       if (IS_LOCAL(user))
        {
-               /* Not on channel */
-               return;
+               if (!has_channel(user,Ptr))
+               {
+                       /* Not on channel */
+                       return;
+               }
        }
-
+       
        if (triggerevents)
        {
                FOREACH_MOD(I_OnUserKick,OnUserKick(NULL,user,Ptr,reason));
@@ -508,41 +581,42 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
 
         log(DEBUG,"kick_channel: removing: %s %s %s",user->nick,Ptr->name,src->nick);
 
-        if (!has_channel(user,Ptr))
-        {
-                WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
-                return;
-        }
-
-        int MOD_RESULT = 0;
-        FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,Ptr,AC_KICK));
-        if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server)))
-                return;
-
-        if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
-        {
-                if ((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr)))
-                {
-                        if (cstatus(src,Ptr) == STATUS_HOP)
-                        {
-                                WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, Ptr->name);
-                        }
-                        else
-                        {
-                                WriteServ(src->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",src->nick, Ptr->name);
-                        }
-
-                        return;
-                }
-        }
-
-        if (!is_uline(src->server))
-        {
-                MOD_RESULT = 0;
-                FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,Ptr,reason));
-                if (MOD_RESULT)
-                        return;
-        }
+       if (IS_LOCAL(user))
+       {
+               if (!has_channel(user,Ptr))
+               {
+                       WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
+                       return;
+               }
+               int MOD_RESULT = 0;
+               FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,Ptr,AC_KICK));
+               if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server)))
+                       return;
+       
+               if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
+               {
+                       if ((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr)))
+                       {
+                               if (cstatus(src,Ptr) == STATUS_HOP)
+                               {
+                                       WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, Ptr->name);
+                               }
+                               else
+                               {
+                                       WriteServ(src->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",src->nick, Ptr->name);
+                               }
+       
+                               return;
+                       }
+               }
+               if (!is_uline(src->server))
+               {
+                       MOD_RESULT = 0;
+                       FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,Ptr,reason));
+                       if (MOD_RESULT)
+                               return;
+               }
+       }
 
         FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,Ptr,reason));