X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=878fdc1a28dc1e30478e49ff56edd6cebe6f7822;hb=2d4a319d961e3f9e6aa9f7926f9ed320d72de8da;hp=219979dc93cdf96ebc3f24b15a25520eee5b433b;hpb=5ca2a6ffdb4dbb7f7d8f120df5f99d85d484b3ab;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 219979dc9..878fdc1a2 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -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); + + if (match(str, maskptr)) + return true; + } + } + + return false; +} - snprintf(mask, MAXBUF, "%s!%s@%s", user->nick.c_str(), user->ident.c_str(), user->GetIPString()); +bool Channel::IsExtBanned(User *user, char type) +{ + int MOD_RESULT = 0; + FOREACH_RESULT(I_OnCheckExtBan, OnCheckExtBan(user, this, type)); - for (BanList::iterator i = this->bans.begin(); i != this->bans.end(); i++) + 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; @@ -482,8 +506,10 @@ bool Channel::IsExtBanned(User *user, char type) /* Channel::PartUser * remove a channel from a users record, and return the number of users left. * Therefore, if this function returns 0 the caller should delete the Channel. + * + * 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; @@ -493,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, reason ? reason : "", 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); @@ -585,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; @@ -615,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(); } } @@ -871,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; } } @@ -941,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()