- 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));
+ bool isNumber;
+ int maxModes = network()->support("MODES").toInt(&isNumber);
+ if (!isNumber || maxModes == 0)
+ maxModes = 1;
+
+ QStringList nickList;
+ if (nicks == "*" && bufferInfo.type() == BufferInfo::ChannelBuffer) { // All users in channel
+ const QList<IrcUser*> users = network()->ircChannel(bufferInfo.bufferName())->ircUsers();
+ for (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));
+ }