X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=14b1ea54534b3559750e1e2594db4858ff338575;hb=b25070bf5e9447533bf1a0555c6954740ca12340;hp=f79b5b89f56c37e221e7aee01f24862d64f660cb;hpb=8320bcc9df1ea89a47257c9f9c70aa6d476beaa8;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index f79b5b89f..14b1ea545 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -90,7 +90,6 @@ void Channel::CheckDestroy() FOREACH_MOD(OnChannelDelete, (this)); ServerInstance->chanlist.erase(iter); - ClearInvites(); ServerInstance->GlobalCulls.AddItem(this); } @@ -181,7 +180,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co } if (user->chans.size() >= maxchans) { - user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s :You are on too many channels", cname.c_str()); + user->WriteNumeric(ERR_TOOMANYCHANNELS, cname, "You are on too many channels"); return NULL; } } @@ -235,16 +234,13 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (MOD_RESULT == MOD_RES_PASSTHRU) { std::string ckey = chan->GetModeParameter(keymode); - bool invited = user->IsInvited(chan); - bool can_bypass = ServerInstance->Config->InvBypassModes && invited; - if (!ckey.empty()) { FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key)); - if (!MOD_RESULT.check((ckey == key) || can_bypass)) + if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, key))) { // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled) - user->WriteNumeric(ERR_BADCHANNELKEY, "%s :Cannot join channel (Incorrect channel key)", chan->name.c_str()); + user->WriteNumeric(ERR_BADCHANNELKEY, chan->name, "Cannot join channel (Incorrect channel key)"); return NULL; } } @@ -252,9 +248,9 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (chan->IsModeSet(inviteonlymode)) { FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan)); - if (!MOD_RESULT.check(invited)) + if (MOD_RESULT != MOD_RES_ALLOW) { - user->WriteNumeric(ERR_INVITEONLYCHAN, "%s :Cannot join channel (Invite only)", chan->name.c_str()); + user->WriteNumeric(ERR_INVITEONLYCHAN, chan->name, "Cannot join channel (Invite only)"); return NULL; } } @@ -263,27 +259,18 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (!limit.empty()) { FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan)); - if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass))) + if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str())))) { - user->WriteNumeric(ERR_CHANNELISFULL, "%s :Cannot join channel (Channel is full)", chan->name.c_str()); + user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)"); return NULL; } } - if (chan->IsBanned(user) && !can_bypass) + if (chan->IsBanned(user)) { - user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s :Cannot join channel (You're banned)", chan->name.c_str()); + user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (You're banned)"); return NULL; } - - /* - * If the user has invites for this channel, remove them now - * after a successful join so they don't build up. - */ - if (invited) - { - user->RemoveInvite(chan); - } } } } @@ -418,23 +405,25 @@ ModResult Channel::GetExtBanStatus(User *user, char type) * Remove a channel from a users record, remove the reference to the Membership object * from the channel and destroy it. */ -void Channel::PartUser(User *user, std::string &reason) +bool Channel::PartUser(User* user, std::string& reason) { MemberMap::iterator membiter = userlist.find(user); - if (membiter != userlist.end()) - { - Membership* memb = membiter->second; - CUList except_list; - FOREACH_MOD(OnUserPart, (memb, reason, except_list)); + if (membiter == userlist.end()) + return false; - WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str()); + Membership* memb = membiter->second; + CUList except_list; + FOREACH_MOD(OnUserPart, (memb, reason, except_list)); - // Remove this channel from the user's chanlist - user->chans.erase(memb); - // Remove the Membership from this channel's userlist and destroy it - this->DelUser(membiter); - } + WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str()); + + // Remove this channel from the user's chanlist + user->chans.erase(memb); + // Remove the Membership from this channel's userlist and destroy it + this->DelUser(membiter); + + return true; } void Channel::KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason) @@ -573,6 +562,13 @@ const char* Channel::ChanModes(bool showkey) return scratch.c_str(); } +void Channel::WriteNotice(const std::string& text) +{ + std::string rawmsg = "NOTICE "; + rawmsg.append(this->name).append(" :").append(text); + WriteChannelWithServ(ServerInstance->Config->ServerName, rawmsg); +} + /* 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. @@ -650,68 +646,3 @@ bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding) modes.push_back(prefix); return adding; } - -void Invitation::Create(Channel* c, LocalUser* u, time_t timeout) -{ - if ((timeout != 0) && (ServerInstance->Time() >= timeout)) - // Expired, don't bother - return; - - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str()); - - Invitation* inv = Invitation::Find(c, u, false); - if (inv) - { - if ((inv->expiry == 0) || (inv->expiry > timeout)) - return; - inv->expiry = timeout; - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv); - } - else - { - inv = new Invitation(c, u, timeout); - c->invites.push_front(inv); - u->invites.push_front(inv); - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv); - } -} - -Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired) -{ - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired); - - Invitation* result = NULL; - for (InviteList::iterator i = u->invites.begin(); i != u->invites.end(); ) - { - Invitation* inv = *i; - ++i; - - if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time())) - { - /* Expired invite, remove it. */ - std::string expiration = InspIRCd::TimeString(inv->expiry); - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str()); - delete inv; - } - else - { - /* Is it what we're searching for? */ - if (inv->chan == c) - { - result = inv; - break; - } - } - } - - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result); - return result; -} - -Invitation::~Invitation() -{ - // Remove this entry from both lists - chan->invites.erase(this); - user->invites.erase(this); - ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "Invitation::~ %p", (void*) this); -}