X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=83aff70cf56400a4e64d29d89dc26cc196f65948;hb=3f971b447fae258a92f2cc6645497cce93f1c04e;hp=5a0cdbf1ee0a460c5766d1e5ef0005e55fc4a1e1;hpb=dd36852a52e8541306b76c5b88bce8ab9b36654c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 5a0cdbf1e..83aff70cf 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -91,7 +91,7 @@ unsigned int ModeHandler::GetCount() void ModeHandler::ChangeCount(int modifier) { count += modifier; - ServerInstance->Log(DEBUG,"Change count for mode %c is now %d", mode, count); + ServerInstance->Logs->Log("MODE", DEBUG,"Change count for mode %c is now %d", mode, count); } ModeType ModeHandler::GetModeType() @@ -186,7 +186,7 @@ User* ModeParser::SanityChecks(User *user, const char *dest, Channel *chan, int) d = ServerInstance->FindNick(dest); if (!d) { - user->WriteServ("401 %s %s :No such nick/channel",user->nick, dest); + user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, dest); return NULL; } return d; @@ -257,35 +257,35 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ if (targetchannel) { /* Display channel's current mode string */ - user->WriteServ("324 %s %s +%s",user->nick, targetchannel->name, targetchannel->ChanModes(targetchannel->HasUser(user))); - user->WriteServ("329 %s %s %lu", user->nick, targetchannel->name, (unsigned long)targetchannel->age); + user->WriteNumeric(324, "%s %s +%s",user->nick, targetchannel->name, targetchannel->ChanModes(targetchannel->HasUser(user))); + user->WriteNumeric(329, "%s %s %lu", user->nick, targetchannel->name, (unsigned long)targetchannel->age); return; } else if (targetuser) { if (targetuser->Visibility && !targetuser->Visibility->VisibleTo(user)) { - user->WriteServ("401 %s %s :No such nick/channel",user->nick, text); + user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, text); return; } if ((targetuser == user) || (IS_OPER(user))) { /* Display user's current mode string */ - user->WriteServ("221 %s :+%s",targetuser->nick,targetuser->FormatModes()); + user->WriteNumeric(221, "%s :+%s",targetuser->nick,targetuser->FormatModes()); if (IS_OPER(targetuser)) - user->WriteServ("008 %s +%s :Server notice mask", targetuser->nick, targetuser->FormatNoticeMasks()); + user->WriteNumeric(8, "%s +%s :Server notice mask", targetuser->nick, targetuser->FormatNoticeMasks()); return; } else { - user->WriteServ("502 %s :Can't change mode for other users", user->nick); + user->WriteNumeric(502, "%s :Can't change mode for other users", user->nick); return; } } /* No such nick/channel */ - user->WriteServ("401 %s %s :No such nick/channel",user->nick, text); + user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, text); return; } @@ -350,7 +350,7 @@ void ModeParser::Process(const char* const* parameters, int pcnt, User *user, bo if (ServerInstance->Config->HideModeLists[mletter] && (targetchannel->GetStatus(user) < STATUS_HOP)) { - user->WriteServ("482 %s %s :Only half-operators and above may view the +%c list",user->nick, targetchannel->name, *mode++); + user->WriteNumeric(482, "%s %s :Only half-operators and above may view the +%c list",user->nick, targetchannel->name, *mode++); mh->DisplayEmptyList(user, targetchannel); continue; } @@ -414,14 +414,14 @@ void ModeParser::Process(const char* const* parameters, int pcnt, User *user, bo mask = MASK_USER; if ((user != targetuser) && (!ServerInstance->ULine(user->server))) { - user->WriteServ("502 %s :Can't change mode for other users", user->nick); + user->WriteNumeric(502, "%s :Can't change mode for other users", user->nick); return; } } else { /* No such nick/channel */ - user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]); + user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, parameters[0]); return; } @@ -521,13 +521,11 @@ void ModeParser::Process(const char* const* parameters, int pcnt, User *user, bo if (!SkipAccessChecks && IS_LOCAL(user) && (MOD_RESULT != ACR_ALLOW)) { - ServerInstance->Log(DEBUG,"Enter minimum prefix check"); /* Check access to this mode character */ if ((type == MODETYPE_CHANNEL) && (modehandlers[handler_id]->GetNeededPrefix())) { char needed = modehandlers[handler_id]->GetNeededPrefix(); ModeHandler* prefixmode = FindPrefix(needed); - ServerInstance->Log(DEBUG,"Needed prefix: %c", needed); /* If the mode defined by the handler is not '\0', but the handler for it * cannot be found, they probably dont have the right module loaded to implement @@ -549,7 +547,7 @@ void ModeParser::Process(const char* const* parameters, int pcnt, User *user, bo if (!ourmode || ourmode->GetPrefixRank() < neededrank) { /* Bog off */ - user->WriteServ("482 %s %s :You must have channel privilege %c or above to %sset channel mode %c", + user->WriteNumeric(482, "%s %s :You must have channel privilege %c or above to %sset channel mode %c", user->nick, targetchannel->name, needed, adding ? "" : "un", modechar); continue; } @@ -579,10 +577,13 @@ void ModeParser::Process(const char* const* parameters, int pcnt, User *user, bo /* It's an oper only mode, check if theyre an oper. If they arent, * eat any parameter that came with the mode, and continue to next */ - if ((IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!IS_OPER(user))) + if ((IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!user->HasModePermission(modehandlers[handler_id]->GetModeChar(), type))) { - user->WriteServ("481 %s :Permission Denied - Only IRC operators may %sset %s mode %c", user->nick, - adding ? "" : "un", type == MODETYPE_CHANNEL ? "channel" : "user", + user->WriteNumeric(481, "%s :Permission Denied - Oper type %s does not have access to %sset %s mode %c", + user->nick, + user->oper, + adding ? "" : "un", + type == MODETYPE_CHANNEL ? "channel" : "user", modehandlers[handler_id]->GetModeChar()); continue; } @@ -775,6 +776,9 @@ bool ModeParser::DelMode(ModeHandler* mh) if (!modehandlers[pos]) return false; + /* Note: We can't stack here, as we have modes potentially being removed across many different channels. + * To stack here we have to make the algorithm slower. Discuss. + */ switch (mh->GetModeType()) { case MODETYPE_USER: @@ -878,7 +882,7 @@ ModeHandler* ModeParser::FindPrefix(unsigned const char pfxletter) return NULL; } -std::string ModeParser::ModeString(User* user, Channel* channel) +std::string ModeParser::ModeString(User* user, Channel* channel, bool nick_suffix) { std::string types; std::string pars; @@ -896,14 +900,20 @@ std::string ModeParser::ModeString(User* user, Channel* channel) ret = mh->ModeSet(NULL, user, channel, user->nick); if ((ret.first) && (ret.second == user->nick)) { - pars.append(" "); - pars.append(user->nick); + if (nick_suffix) + { + pars.append(" "); + pars.append(user->nick); + } types.push_back(mh->GetModeChar()); } } } - return types+pars; + if (nick_suffix) + return types+pars; + else + return types; } std::string ModeParser::ChanModes() @@ -1041,30 +1051,44 @@ bool ModeParser::DelModeWatcher(ModeWatcher* mw) /** This default implementation can remove simple user modes */ -void ModeHandler::RemoveMode(User* user) +void ModeHandler::RemoveMode(User* user, irc::modestacker* stack) { char moderemove[MAXBUF]; const char* parameters[] = { user->nick, moderemove }; if (user->IsModeSet(this->GetModeChar())) { - sprintf(moderemove,"-%c",this->GetModeChar()); - ServerInstance->Parser->CallHandler("MODE", parameters, 2, user); + if (stack) + { + stack->Push(this->GetModeChar()); + } + else + { + sprintf(moderemove,"-%c",this->GetModeChar()); + ServerInstance->Parser->CallHandler("MODE", parameters, 2, user); + } } } /** This default implementation can remove simple channel modes * (no parameters) */ -void ModeHandler::RemoveMode(Channel* channel) +void ModeHandler::RemoveMode(Channel* channel, irc::modestacker* stack) { char moderemove[MAXBUF]; const char* parameters[] = { channel->name, moderemove }; if (channel->IsModeSet(this->GetModeChar())) { - sprintf(moderemove,"-%c",this->GetModeChar()); - ServerInstance->SendMode(parameters, 2, ServerInstance->FakeClient); + if (stack) + { + stack->Push(this->GetModeChar()); + } + else + { + sprintf(moderemove,"-%c",this->GetModeChar()); + ServerInstance->SendMode(parameters, 2, ServerInstance->FakeClient); + } } }