Kind of hacky solution to not break protocol.
Introduces new "type" in settingspage that causes the "Rule"
line to be interpreted as:
hostmask [CTCPCMD CTCPCMD]
for example:
* VERSION
blocks any version _request_ globally or on any configured network.
If no CTCPCMD is given, all CTCP requests will be ignored.
_ignoreList[idx].isActive = !_ignoreList[idx].isActive;
SYNC(ARG(ignoreRule))
}
+
+bool IgnoreListManager::ctcpMatch(const QString sender, const QString &network, const QString &type) {
+ foreach(IgnoreListItem item, _ignoreList) {
+ if(!item.isActive)
+ continue;
+ if(item.scope == GlobalScope || (item.scope == NetworkScope && scopeMatch(item.scopeRule, network))) {
+ QString sender_;
+ QStringList types = item.ignoreRule.split(QRegExp("\\s+"), QString::SkipEmptyParts);
+
+ sender_ = types.takeAt(0);
+
+ QRegExp ruleRx = QRegExp(sender_);
+ ruleRx.setCaseSensitivity(Qt::CaseInsensitive);
+ if(!item.isRegEx)
+ ruleRx.setPatternSyntax(QRegExp::Wildcard);
+ if((!item.isRegEx && ruleRx.exactMatch(sender)) ||
+ (item.isRegEx && ruleRx.indexIn(sender) != -1)) {
+
+ if(types.isEmpty() || types.contains(type, Qt::CaseInsensitive))
+ return true;
+ }
+ }
+ }
+ return false;
+}
enum IgnoreType {
SenderIgnore,
- MessageIgnore
+ MessageIgnore,
+ CtcpIgnore
};
enum StrictnessType {
*/
StrictnessType match(const Message &msg, const QString &network = QString());
+ bool ctcpMatch(const QString sender, const QString &network, const QString &type = QString());
// virtual void addIgnoreListItem(const IgnoreListItem &item);
class IrcServerHandler;
class CoreUserInputHandler;
class CtcpHandler;
+class CoreIgnoreListManager;
class CoreNetwork : public Network {
SYNCABLE_OBJECT
inline IrcServerHandler *ircServerHandler() const { return _ircServerHandler; }
inline CoreUserInputHandler *userInputHandler() const { return _userInputHandler; }
inline CtcpHandler *ctcpHandler() const { return _ctcpHandler; }
+ inline CoreIgnoreListManager *ignoreListManager() { return coreSession()->ignoreListManager(); }
//! Decode a string using the server (network) decoding.
inline QString serverDecode(const QByteArray &string) const { return decodeServerString(string); }
inline CoreIrcListHelper *ircListHelper() const { return _ircListHelper; }
+ inline CoreIgnoreListManager *ignoreListManager() { return &_ignoreListManager; }
// void attachNetworkConnection(NetworkConnection *conn);
//! Return necessary data for restoring the session after restarting the core
#include "network.h"
#include "quassel.h"
#include "util.h"
+#include "coreignorelistmanager.h"
CtcpHandler::CtcpHandler(CoreNetwork *parent)
: BasicHandler(parent),
- XDELIM("\001")
+ XDELIM("\001"),
+ _ignoreListManager(parent->ignoreListManager())
{
QByteArray MQUOTE = QByteArray("\020");
void CtcpHandler::handlePing(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- reply(nickFromMask(prefix), "PING", param);
- emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "PING")) {
+ reply(nickFromMask(prefix), "PING", param);
+ emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP PING request from %1").arg(prefix));
+ }
} else {
// display ping answer
uint now = QDateTime::currentDateTime().toTime_t();
void CtcpHandler::handleVersion(CtcpType ctcptype, const QString &prefix, const QString &target, const QString ¶m) {
Q_UNUSED(target)
if(ctcptype == CtcpQuery) {
- reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
- .arg(Quassel::buildInfo().plainVersionString)
- .arg(Quassel::buildInfo().buildDate));
- emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName(), "VERSION")) {
+ reply(nickFromMask(prefix), "VERSION", QString("Quassel IRC %1 (built on %2) -- http://www.quassel-irc.org")
+ .arg(Quassel::buildInfo().plainVersionString)
+ .arg(Quassel::buildInfo().buildDate));
+ emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION request by %1").arg(prefix));
+ }
} else {
// display Version answer
emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Received CTCP VERSION answer from %1: %2").arg(prefix).arg(param));
Q_UNUSED(ctcptype);
Q_UNUSED(target);
Q_UNUSED(param);
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix));
+ if(!_ignoreListManager->ctcpMatch(prefix, network()->networkName())) {
+ emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Received unknown CTCP %1 by %2").arg(cmd).arg(prefix));
+ }
}
#include "basichandler.h"
+class CoreListIgnoreListManager;
+
class CtcpHandler : public BasicHandler {
Q_OBJECT
QByteArray XDELIM;
QHash<QByteArray, QByteArray> ctcpMDequoteHash;
QHash<QByteArray, QByteArray> ctcpXDelimDequoteHash;
+ CoreIgnoreListManager *_ignoreListManager;
};
</property>
</widget>
</item>
+ <item>
+ <widget class="QRadioButton" name="ctcpTypeButton">
+ <property name="text">
+ <string>CTCP</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
</item>
// this could be moved to .ui file with qt4.5
_typeButtonGroup.addButton(ui.senderTypeButton, 0);
_typeButtonGroup.addButton(ui.messageTypeButton, 1);
+ _typeButtonGroup.addButton(ui.ctcpTypeButton, 2);
_strictnessButtonGroup.addButton(ui.dynamicStrictnessButton, 0);
_strictnessButtonGroup.addButton(ui.permanentStrictnessButton, 1);
_scopeButtonGroup.addButton(ui.globalScopeButton, 0);
if(item.type == IgnoreListManager::MessageIgnore)
ui.messageTypeButton->setChecked(true);
+ else if(item.type == IgnoreListManager::CtcpIgnore)
+ ui.ctcpTypeButton->setChecked(true);
else
ui.senderTypeButton->setChecked(true);
void IgnoreListEditDlg::widgetHasChanged() {
if(ui.messageTypeButton->isChecked())
_clonedIgnoreListItem.type = IgnoreListManager::MessageIgnore;
+ else if(ui.ctcpTypeButton->isChecked())
+ _clonedIgnoreListItem.type = IgnoreListManager::CtcpIgnore;
else
_clonedIgnoreListItem.type = IgnoreListManager::SenderIgnore;