]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Fix total mess of makefile dependency macros (all depending on stuff they dont NEED...
[user/henk/code/inspircd.git] / src / channels.cpp
index fbec272b37623b826ac5bd42206b695e22c084b9..878fdc1a28dc1e30478e49ff56edd6cebe6f7822 100644 (file)
@@ -229,7 +229,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                {
                        if (user->chans.size() >= user->GetMaxChans())
                        {
-                               user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick.c_str(), cn);
+                               user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
                                return NULL;
                        }
                }
@@ -239,7 +239,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                        {
                                if (user->chans.size() >= Instance->Config->OperMaxChans)
                                {
-                                       user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick.c_str(), cn);
+                                       user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
                                        return NULL;
                                }
                        }
@@ -247,7 +247,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                        {
                                if (user->chans.size() >= Instance->Config->MaxChans)
                                {
-                                       user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick.c_str(), cn);
+                                       user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s %s :You are on too many channels",user->nick.c_str(), cn);
                                        return NULL;
                                }
                        }
@@ -310,7 +310,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                                        {
                                                if ((!key) || Ptr->key == key)
                                                {
-                                                       user->WriteNumeric(475, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
+                                                       user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
                                                        return NULL;
                                                }
                                        }
@@ -323,7 +323,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                                        {
                                                if (!user->IsInvited(Ptr->name.c_str()))
                                                {
-                                                       user->WriteNumeric(473, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
+                                                       user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
                                                        return NULL;
                                                }
                                        }
@@ -337,7 +337,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                                        {
                                                if (Ptr->GetUserCounter() >= Ptr->limit)
                                                {
-                                                       user->WriteNumeric(471, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
+                                                       user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
                                                        return NULL;
                                                }
                                        }
@@ -346,7 +346,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                                {
                                        if (Ptr->IsBanned(user))
                                        {
-                                               user->WriteNumeric(474, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
                                                return NULL;
                                        }
                                }
@@ -416,8 +416,8 @@ Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const
        {
                if (Ptr->topicset)
                {
-                       user->WriteNumeric(332, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
-                       user->WriteNumeric(333, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
+                       user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
+                       user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
                }
                Ptr->UserList(user);
        }
@@ -451,29 +451,53 @@ bool Channel::IsBanned(User* user)
        return false;
 }
 
-bool Channel::IsExtBanned(User *user, char type)
+bool Channel::IsExtBanned(const std::string &str, char type)
 {
-       // XXX. do we need events?
-       char mask[MAXBUF];
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnCheckStringExtBan, OnCheckStringExtBan(str, this, type));
+
+       if (MOD_RESULT == -1)
+               return true;
+       else if (MOD_RESULT == 0)
+       {
+               for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+               {
+                       if (i->data[0] != type || i->data[1] != ':')
+                               continue;
+
+                       // Iterate past char and : to get to the mask without doing a data copy(!)
+                       std::string maskptr = i->data.substr(2);
+                       ServerInstance->Logs->Log("EXTBANS", DEBUG, "Checking %s against %s, type is %c", str.c_str(), maskptr.c_str(), type);
 
-       snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
+                       if (match(str, maskptr))
+                               return true;
+               }
+       }
+
+       return false;
+}
 
-       for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++)
+bool Channel::IsExtBanned(User *user, char type)
+{
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type));
+
+       if (MOD_RESULT == -1)
+               return true;
+       else if (MOD_RESULT == 0)
        {
-               if (i->data[0] != type || i->data[1] != ':')
-                       continue;
+               char mask[MAXBUF];
+               snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString());
 
-               // Iterate past char and : to get to the mask without doing a data copy(!)
-               std::string maskptr = i->data.substr(2);
+               // XXX: we should probably hook cloaked hosts in here somehow too..
+               if (this->IsExtBanned(mask, type))
+                       return true;
 
-               /* This allows CIDR ban matching
-                *
-                *        Full masked host                             Full unmasked host                     IP with/without CIDR
-                */
-               if ((match(user->GetFullHost(), maskptr)) || (match(user->GetFullRealHost(), maskptr)) || (match(mask, maskptr, true)))
-               {
+               if (this->IsExtBanned(user->GetFullHost(), type))
+                       return true;
+
+               if (this->IsExtBanned(user->GetFullRealHost(), type))
                        return true;
-               }
        }
 
        return false;
@@ -485,15 +509,9 @@ bool Channel::IsExtBanned(User *user, char type)
  *
  * XXX: bleh, string copy of reason, fixme! -- w00t
  */
-long Channel::PartUser(User *user, const char* reason)
+long Channel::PartUser(User *user, std::string &reason)
 {
        bool silent = false;
-       std::string freason;
-
-       if (reason)
-               freason = reason;
-       else
-               freason = "";
 
        if (!user)
                return this->GetUserCounter();
@@ -501,10 +519,10 @@ long Channel::PartUser(User *user, const char* reason)
        UCListIter i = user->chans.find(this);
        if (i != user->chans.end())
        {
-               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, freason, silent));
+               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason, silent));
 
                if (!silent)
-                       this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason ? " :" : "", reason ? reason : "");
+                       this->WriteChannel(user, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
 
                user->chans.erase(i);
                this->RemoveAllPrefixes(user);
@@ -593,12 +611,12 @@ long Channel::KickUser(User *src, User *user, const char* reason)
        {
                if (!this->HasUser(user))
                {
-                       src->WriteNumeric(441, "%s %s %s :They are not on that channel",src->nick.c_str(), user->nick.c_str(), this->name.c_str());
+                       src->WriteNumeric(ERR_USERNOTINCHANNEL, "%s %s %s :They are not on that channel",src->nick.c_str(), user->nick.c_str(), this->name.c_str());
                        return this->GetUserCounter();
                }
                if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
                {
-                       src->WriteNumeric(482, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick.c_str(), this->name.c_str());
+                       src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick.c_str(), this->name.c_str());
                        return this->GetUserCounter();
                }
                int MOD_RESULT = 0;
@@ -623,7 +641,7 @@ long Channel::KickUser(User *src, User *user, const char* reason)
                                int us = this->GetStatus(user);
                                if ((them < STATUS_HOP) || (them < us))
                                {
-                                       src->WriteNumeric(482, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
+                                       src->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must be a channel %soperator",src->nick.c_str(), this->name.c_str(), them == STATUS_HOP ? "" : "half-");
                                        return this->GetUserCounter();
                                }
                        }
@@ -879,7 +897,7 @@ void Channel::UserList(User *user, CUList *ulist)
        {
                if ((this->IsModeSet('s')) && (!this->HasUser(user)))
                {
-                       user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
+                       user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), this->name.c_str());
                        return;
                }
        }
@@ -949,10 +967,10 @@ void Channel::UserList(User *user, CUList *ulist)
        /* if whats left in the list isnt empty, send it */
        if (numusers)
        {
-               user->WriteNumeric(353,std::string(list));
+               user->WriteNumeric(RPL_NAMREPLY, std::string(list));
        }
 
-       user->WriteNumeric(366, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
+       user->WriteNumeric(RPL_ENDOFNAMES, "%s %s :End of /NAMES list.", user->nick.c_str(), this->name.c_str());
 }
 
 long Channel::GetMaxBans()