]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
ModeParser::InsertMode is no longer required -- this is auto-generated by the ModePar...
[user/henk/code/inspircd.git] / src / channels.cpp
index fff2769701a12a5689bdf59ff612922605591e8c..e7564c3ea6ceddac42aa347dbf7edd47675039fa 100644 (file)
@@ -35,7 +35,7 @@ using namespace std;
 #include "mode.h"
 #include "xline.h"
 #include "inspstring.h"
-#include "helperfuncs.h"
+
 #include "typedefs.h"
 
 chanrec::chanrec(InspIRCd* Instance) : ServerInstance(Instance)
@@ -222,7 +222,7 @@ chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bo
 
        if (!Ptr)
        {
-               if (user->fd > -1)
+               if (IS_LOCAL(user))
                {
                        MOD_RESULT = 0;
                        FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,NULL,cname));
@@ -430,6 +430,7 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* u
                /* first user in is given ops */
                a->uc_modes = UCMODE_OP;
                Ptr->AddOppedUser(user);
+               Ptr->SetPrefix(user, '@', OP_VALUE, true);
        }
        else
        {
@@ -481,6 +482,7 @@ long chanrec::PartUser(userrec *user, const char* reason)
                        }
                        user->chans[i]->uc_modes = 0;
                        user->chans[i]->channel = NULL;
+                       this->RemoveAllPrefixes(user);
                        break;
                }
        }
@@ -527,6 +529,7 @@ long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggereven
                        this->WriteChannelWithServ(ServerInstance->Config->ServerName, "KICK %s %s :%s", this->name, user->nick, reason);
                        user->chans[i]->uc_modes = 0;
                        user->chans[i]->channel = NULL;
+                       this->RemoveAllPrefixes(user);
                        break;
                }
        }
@@ -609,6 +612,7 @@ long chanrec::KickUser(userrec *src, userrec *user, const char* reason)
                        this->WriteChannel(src, "KICK %s %s :%s", this->name, user->nick, reason);
                        (*i)->uc_modes = 0;
                        (*i)->channel = NULL;
+                       this->RemoveAllPrefixes(user);
                        break;
                }
        }
@@ -654,7 +658,7 @@ void chanrec::WriteChannel(userrec* user, const std::string &text)
 
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if (i->second->fd != FD_MAGIC_NUMBER)
+               if (IS_LOCAL(i->second))
                        user->WriteTo(i->second,text);
        }
 }
@@ -831,7 +835,7 @@ void chanrec::UserList(userrec *user)
                        continue;
                }
 
-               size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetStatusChar(i->second), i->second->nick);
+               size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->second), i->second->nick);
 
                curlen += ptrlen;
                ptr += ptrlen;
@@ -876,30 +880,67 @@ long chanrec::GetMaxBans()
 
 /* returns the status character for a given user on a channel, e.g. @ for op,
  * % for halfop etc. If the user has several modes set, the highest mode
- * the user has must be returned. */
-
-const char* chanrec::GetStatusChar(userrec *user)
+ * the user has must be returned.
+ */
+const char* chanrec::GetPrefixChar(userrec *user)
 {
-       for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+       static char px[2];
+       unsigned int mx = 0;
+
+       *px = 0;
+       *(px+1) = 0;
+
+       prefixlist::iterator n = prefixes.find(user);
+       if (n != prefixes.end())
        {
-               if ((*i)->channel == this)
+               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
                {
-                       if (((*i)->uc_modes & UCMODE_OP) > 0)
-                       {
-                               return "@";
-                       }
-                       if (((*i)->uc_modes & UCMODE_HOP) > 0)
-                       {
-                               return "%";
-                       }
-                       if (((*i)->uc_modes & UCMODE_VOICE) > 0)
+                       if (x->second > mx)
                        {
-                               return "+";
+                               *px = x->first;
+                               mx  = x->second;
                        }
-                       return "";
                }
        }
-       return "";
+
+       return px;
+}
+
+const char* chanrec::GetAllPrefixChars(userrec* user)
+{
+       static char prefix[MAXBUF];
+       int ctr = 0;
+       *prefix = 0;
+
+       prefixlist::iterator n = prefixes.find(user);
+       if (n != prefixes.end())
+       {
+               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
+               {
+                       prefix[ctr++] = x->first;
+               }
+       }
+
+       prefix[ctr] = 0;
+
+       return prefix;
+}
+
+unsigned int chanrec::GetPrefixValue(userrec* user)
+{
+       unsigned int mx = 0;
+
+       prefixlist::iterator n = prefixes.find(user);
+       if (n != prefixes.end())
+       {
+               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
+               {
+                       if (x->second > mx)
+                               mx  = x->second;
+               }
+       }
+
+       return mx;
 }
 
 
@@ -916,7 +957,6 @@ int chanrec::GetStatusFlags(userrec *user)
 }
 
 
-
 int chanrec::GetStatus(userrec *user)
 {
        if (ServerInstance->ULine(user->server))
@@ -944,4 +984,41 @@ int chanrec::GetStatus(userrec *user)
        return STATUS_NORMAL;
 }
 
+void chanrec::SetPrefix(userrec* user, char prefix, unsigned int prefix_value, bool adding)
+{
+       prefixlist::iterator n = prefixes.find(user);
+       prefixtype pfx = std::make_pair(prefix,prefix_value);
+       if (adding)
+       {
+               if (n != prefixes.end())
+               {
+                       if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
+                       {
+                               n->second.push_back(pfx);
+                       }
+               }
+               else
+               {
+                       pfxcontainer one;
+                       one.push_back(pfx);
+                       prefixes.insert(std::make_pair<userrec*,pfxcontainer>(user, one));
+               }
+       }
+       else
+       {
+               if (n != prefixes.end())
+               {
+                       pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
+                       if (x != n->second.end())
+                               n->second.erase(x);
+               }
+       }
+}
+
+void chanrec::RemoveAllPrefixes(userrec* user)
+{
+       prefixlist::iterator n = prefixes.find(user);
+       if (n != prefixes.end())
+               prefixes.erase(n);
+}