X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoreuserinputhandler.cpp;h=e80751bb83ead8d9bea206d5ea6baa1704ff850f;hp=930be966eac16278e9bd0073916f7a9b50ab294a;hb=ba9e218feccbf16895f08ae4ec63aaa77de447d0;hpb=5b686746c880e5cda6d5de3e08180ea4332ff222 diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index 930be966..e80751bb 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -226,34 +226,62 @@ void CoreUserInputHandler::handleDelkey(const BufferInfo &bufferInfo, const QStr #endif } +void CoreUserInputHandler::doMode(const BufferInfo &bufferInfo, const QChar& addOrRemove, const QChar& mode, const QString &nicks) +{ + QString m; + bool isNumber; + int maxModes = network()->support("MODES").toInt(&isNumber); + if (!isNumber || maxModes == 0) maxModes = 1; + + QStringList nickList; + if (nicks == "*") { // All users in channel + const QList users = network()->ircChannel(bufferInfo.bufferName())->ircUsers(); + foreach(IrcUser *user, users) { + if ((addOrRemove == '+' && !network()->ircChannel(bufferInfo.bufferName())->userModes(user).contains(mode)) + || (addOrRemove == '-' && network()->ircChannel(bufferInfo.bufferName())->userModes(user).contains(mode))) + nickList.append(user->nick()); + } + } else { + nickList = nicks.split(' ', QString::SkipEmptyParts); + } + + if (nickList.count() == 0) return; + + while (!nickList.isEmpty()) { + int amount = qMin(nickList.count(), maxModes); + QString m = addOrRemove; for(int i = 0; i < amount; i++) m += mode; + QStringList params; + params << bufferInfo.bufferName() << m; + for(int i = 0; i < amount; i++) params << nickList.takeFirst(); + emit putCmd("MODE", serverEncode(params)); + } +} + -void CoreUserInputHandler::handleDeop(const BufferInfo &bufferInfo, const QString &msg) +void CoreUserInputHandler::handleDeop(const BufferInfo &bufferInfo, const QString &nicks) { - QStringList nicks = msg.split(' ', QString::SkipEmptyParts); - QString m = "-"; for (int i = 0; i < nicks.count(); i++) m += 'o'; - QStringList params; - params << bufferInfo.bufferName() << m << nicks; - emit putCmd("MODE", serverEncode(params)); + doMode(bufferInfo, '-', 'o', nicks); } -void CoreUserInputHandler::handleDehalfop(const BufferInfo &bufferInfo, const QString &msg) +void CoreUserInputHandler::handleDehalfop(const BufferInfo &bufferInfo, const QString &nicks) { - QStringList nicks = msg.split(' ', QString::SkipEmptyParts); - QString m = "-"; for (int i = 0; i < nicks.count(); i++) m += 'h'; - QStringList params; - params << bufferInfo.bufferName() << m << nicks; - emit putCmd("MODE", serverEncode(params)); + doMode(bufferInfo, '-', 'h', nicks); } -void CoreUserInputHandler::handleDevoice(const BufferInfo &bufferInfo, const QString &msg) +void CoreUserInputHandler::handleDevoice(const BufferInfo &bufferInfo, const QString &nicks) { - QStringList nicks = msg.split(' ', QString::SkipEmptyParts); - QString m = "-"; for (int i = 0; i < nicks.count(); i++) m += 'v'; - QStringList params; - params << bufferInfo.bufferName() << m << nicks; - emit putCmd("MODE", serverEncode(params)); + doMode(bufferInfo, '-', 'v', nicks); +} + +void CoreUserInputHandler::handleHalfop(const BufferInfo &bufferInfo, const QString &nicks) +{ + doMode(bufferInfo, '+', 'h', nicks); +} + +void CoreUserInputHandler::handleOp(const BufferInfo &bufferInfo, const QString &nicks) { + doMode(bufferInfo, '+', 'o', nicks); } @@ -427,25 +455,6 @@ void CoreUserInputHandler::handleNotice(const BufferInfo &bufferInfo, const QStr } -void CoreUserInputHandler::handleHalfop(const BufferInfo &bufferInfo, const QString &msg) -{ - QStringList nicks = msg.split(' ', QString::SkipEmptyParts); - QString m = "+"; for (int i = 0; i < nicks.count(); i++) m += 'h'; - QStringList params; - params << bufferInfo.bufferName() << m << nicks; - emit putCmd("MODE", serverEncode(params)); -} - - -void CoreUserInputHandler::handleOp(const BufferInfo &bufferInfo, const QString &msg) -{ - QStringList nicks = msg.split(' ', QString::SkipEmptyParts); - QString m = "+"; for (int i = 0; i < nicks.count(); i++) m += 'o'; - QStringList params; - params << bufferInfo.bufferName() << m << nicks; - emit putCmd("MODE", serverEncode(params)); -} - void CoreUserInputHandler::handleOper(const BufferInfo &bufferInfo, const QString &msg) {