Add checkParamCount() which stops the event if something's wrong
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 30 Sep 2010 15:55:11 +0000 (17:55 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:32 +0000 (01:06 +0200)
src/common/ircevent.h
src/core/coresessioneventprocessor.cpp
src/core/coresessioneventprocessor.h

index 0f4336d..e8e21ac 100644 (file)
@@ -22,6 +22,7 @@
 #define IRCEVENT_H
 
 #include "networkevent.h"
+#include "util.h"
 
 class IrcEvent : public NetworkEvent {
 public:
@@ -34,6 +35,8 @@ public:
   inline QString prefix() const { return _prefix; }
   inline void setPrefix(const QString &prefix) { _prefix = prefix; }
 
+  inline QString nick() const { return nickFromMask(prefix()); }
+
   inline QStringList params() const { return _params; }
   inline void setParams(const QStringList &params) { _params = params; }
 
index ebfb007..8599524 100644 (file)
@@ -31,6 +31,20 @@ CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
 
 }
 
+bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams) {
+  if(e->params().count() < minParams) {
+    if(e->type() == EventManager::IrcEventNumeric) {
+      qWarning() << "Command " << static_cast<IrcEventNumeric *>(e)->number() << " requires " << minParams << "params, got: " << e->params();
+    } else {
+      QString name = coreSession()->eventManager()->enumName(e->type());
+      qWarning() << qPrintable(name) << "requires" << minParams << "params, got:" << e->params();
+    }
+    e->stop();
+    return false;
+  }
+  return true;
+}
+
 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
   switch(e->number()) {
 
index fa647d0..4d7559d 100644 (file)
@@ -24,6 +24,7 @@
 #include <QObject>
 
 class CoreSession;
+class IrcEvent;
 class IrcEventNumeric;
 
 class CoreSessionEventProcessor : public QObject {
@@ -37,6 +38,7 @@ public:
   Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event);
 
 protected:
+  bool checkParamCount(IrcEvent *event, int minParams);
 
 private:
   CoreSession *_coreSession;