Event backend porting
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 10 Oct 2010 11:54:43 +0000 (13:54 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:33 +0000 (01:06 +0200)
ERR_ERRONEUSNICKNAME (432), ERR_NICKNAMEINUSE (433), ERR_UNAVAILRESOURCE (437)

src/core/coresessioneventprocessor.cpp
src/core/coresessioneventprocessor.h
src/core/eventstringifier.cpp
src/core/eventstringifier.h
src/core/ircserverhandler.cpp
src/core/ircserverhandler.h

index 3b5ad27..cb11691 100644 (file)
@@ -25,6 +25,7 @@
 #include "coresession.h"
 #include "ircevent.h"
 #include "ircuser.h"
 #include "coresession.h"
 #include "ircevent.h"
 #include "ircuser.h"
+#include "messageevent.h"
 
 CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
   : QObject(session),
 
 CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
   : QObject(session),
@@ -47,6 +48,28 @@ bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams) {
   return true;
 }
 
   return true;
 }
 
+void CoreSessionEventProcessor::tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneus) {
+  QStringList desiredNicks = coreSession()->identity(e->network()->identity())->nicks();
+  int nextNickIdx = desiredNicks.indexOf(errnick) + 1;
+  QString nextNick;
+  if(nextNickIdx > 0 && desiredNicks.size() > nextNickIdx) {
+    nextNick = desiredNicks[nextNickIdx];
+  } else {
+    if(erroneus) {
+      // FIXME Make this an ErrorEvent or something like that, so it's translated in the client
+      MessageEvent *msgEvent = new MessageEvent(Message::Error, e->network(),
+                                                tr("No free and valid nicks in nicklist found. use: /nick <othernick> to continue"),
+                                                QString(), QString(), Message::None, e->timestamp());
+      coreSession()->eventManager()->sendEvent(msgEvent);
+      return;
+    } else {
+      nextNick = errnick + "_";
+    }
+  }
+  // FIXME Use a proper output event for this
+  coreNetwork(e)->putRawLine("NICK " + coreNetwork(e)->encodeServerString(nextNick));
+}
+
 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
   switch(e->number()) {
 
 void CoreSessionEventProcessor::processIrcEventNumeric(IrcEventNumeric *e) {
   switch(e->number()) {
 
@@ -445,6 +468,54 @@ void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e) {
   channel->joinIrcUsers(nicks, modes);
 }
 
   channel->joinIrcUsers(nicks, modes);
 }
 
+/* ERR_ERRONEUSNICKNAME */
+void CoreSessionEventProcessor::processIrcEvent432(IrcEventNumeric *e) {
+  QString errnick;
+  if(e->params().count() < 2) {
+    // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
+    // nick @@@
+    // :irc.scortum.moep.net 432  @@@ :Erroneous Nickname: Illegal characters
+    // correct server reply:
+    // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
+    e->params().prepend(e->target());
+    e->setTarget("*");
+  }
+  errnick = e->params()[0];
+
+  tryNextNick(e, errnick, true /* erroneus */);
+}
+
+/* ERR_NICKNAMEINUSE */
+void CoreSessionEventProcessor::processIrcEvent433(IrcEventNumeric *e) {
+  if(!checkParamCount(e, 1))
+    return;
+
+  QString errnick = e->params().first();
+
+  // if there is a problem while connecting to the server -> we handle it
+  // but only if our connection has not been finished yet...
+  if(!e->network()->currentServer().isEmpty())
+    return;
+
+  tryNextNick(e, errnick);
+}
+
+/* ERR_UNAVAILRESOURCE */
+void CoreSessionEventProcessor::processIrcEvent437(IrcEventNumeric *e) {
+  if(!checkParamCount(e, 1))
+    return;
+
+  QString errnick = e->params().first();
+
+  // if there is a problem while connecting to the server -> we handle it
+  // but only if our connection has not been finished yet...
+  if(!e->network()->currentServer().isEmpty())
+    return;
+
+  if(!e->network()->isChannelName(errnick))
+    tryNextNick(e, errnick);
+}
+
 /* template
 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
   if(!checkParamCount(e, 1))
 /* template
 void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
   if(!checkParamCount(e, 1))
@@ -452,3 +523,4 @@ void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
 
 }
 */
 
 }
 */
+
index 7c533e4..59b4879 100644 (file)
@@ -69,12 +69,16 @@ public:
   Q_INVOKABLE void processIrcEvent332(IrcEvent *event);            // RPL_TOPIC
   Q_INVOKABLE void processIrcEvent352(IrcEvent *event);            // RPL_WHOREPLY
   Q_INVOKABLE void processIrcEvent353(IrcEvent *event);            // RPL_NAMREPLY
   Q_INVOKABLE void processIrcEvent332(IrcEvent *event);            // RPL_TOPIC
   Q_INVOKABLE void processIrcEvent352(IrcEvent *event);            // RPL_WHOREPLY
   Q_INVOKABLE void processIrcEvent353(IrcEvent *event);            // RPL_NAMREPLY
+  Q_INVOKABLE void processIrcEvent432(IrcEventNumeric *event);            // ERR_ERRONEUSNICKNAME
+  Q_INVOKABLE void processIrcEvent433(IrcEventNumeric *event);            // ERR_NICKNAMEINUSE
+  Q_INVOKABLE void processIrcEvent437(IrcEventNumeric *event);            // ERR_UNAVAILRESOURCE
 
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
 protected:
   bool checkParamCount(IrcEvent *event, int minParams);
   inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
 
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
 protected:
   bool checkParamCount(IrcEvent *event, int minParams);
   inline CoreNetwork *coreNetwork(NetworkEvent *e) const { return qobject_cast<CoreNetwork *>(e->network()); }
+  void tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneous = false);
 
 private:
   CoreSession *_coreSession;
 
 private:
   CoreSession *_coreSession;
index 94c967d..a7238b2 100644 (file)
@@ -105,11 +105,11 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) {
   }
 
   // Ignore these commands.
   }
 
   // Ignore these commands.
-  case 321: case 366: case 376:
+  case 321: case 353: case 366: case 376:
     break;
 
   // CAP stuff
     break;
 
   // CAP stuff
-  case 903: case 904: case 905: case 906: case 907:
+  case 900: case 903: case 904: case 905: case 906: case 907:
   {
     displayMsg(e, Message::Info, "CAP: " + e->params().join(""));
     break;
   {
     displayMsg(e, Message::Info, "CAP: " + e->params().join(""));
     break;
@@ -424,6 +424,21 @@ void EventStringifier::processIrcEvent369(IrcEvent *e) {
   displayMsg(e, Message::Server, tr("End of /WHOWAS"));
 }
 
   displayMsg(e, Message::Server, tr("End of /WHOWAS"));
 }
 
+/* ERR_ERRONEUSNICKNAME */
+void EventStringifier::processIrcEvent432(IrcEvent *e) {
+  displayMsg(e, Message::Error, tr("Nick %1 contains illegal characters").arg(e->params()[0]));
+}
+
+/* ERR_NICKNAMEINUSE */
+void EventStringifier::processIrcEvent433(IrcEvent *e) {
+  displayMsg(e, Message::Error, tr("Nick already in use: %1").arg(e->params()[0]));
+}
+
+/* ERR_UNAVAILRESOURCE */
+void EventStringifier::processIrcEvent437(IrcEvent *e) {
+  displayMsg(e, Message::Error, tr("Nick/channel is temporarily unavailable: %1").arg(e->params()[0]));
+}
+
 // template
 /*
 
 // template
 /*
 
index c31842e..25733ad 100644 (file)
@@ -79,7 +79,9 @@ public:
   Q_INVOKABLE void processIrcEvent341(IrcEvent *event);      // RPL_INVITING
   Q_INVOKABLE void processIrcEvent352(IrcEvent *event);      // RPL_WHOREPLY
   Q_INVOKABLE void processIrcEvent369(IrcEvent *event);      // RPL_ENDOFWHOWAS
   Q_INVOKABLE void processIrcEvent341(IrcEvent *event);      // RPL_INVITING
   Q_INVOKABLE void processIrcEvent352(IrcEvent *event);      // RPL_WHOREPLY
   Q_INVOKABLE void processIrcEvent369(IrcEvent *event);      // RPL_ENDOFWHOWAS
-
+  Q_INVOKABLE void processIrcEvent432(IrcEvent *event);      // ERR_ERRONEUSNICKNAME
+  Q_INVOKABLE void processIrcEvent433(IrcEvent *event);      // ERR_NICKNAMEINUSE
+  Q_INVOKABLE void processIrcEvent437(IrcEvent *event);      // ERR_UNAVAILRESOURCE
 
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
 
   // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
 
index dfb3009..ae7c42b 100644 (file)
@@ -405,60 +405,6 @@ void IrcServerHandler::handle324(const QString &prefix, const QList<QByteArray>
   handleMode(prefix, params);
 }
 
   handleMode(prefix, params);
 }
 
-/* ERR_ERRONEUSNICKNAME */
-void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-
-  QString errnick;
-  if(params.size() < 2) {
-    // handle unreal-ircd bug, where unreal ircd doesnt supply a TARGET in ERR_ERRONEUSNICKNAME during registration phase:
-    // nick @@@
-    // :irc.scortum.moep.net 432  @@@ :Erroneous Nickname: Illegal characters
-    // correct server reply:
-    // :irc.scortum.moep.net 432 * @@@ :Erroneous Nickname: Illegal characters
-    errnick = target();
-  } else {
-    errnick = params[0];
-  }
-  emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Nick %1 contains illegal characters").arg(errnick));
-  tryNextNick(errnick, true /* erroneus */);
-}
-
-/* ERR_NICKNAMEINUSE */
-void IrcServerHandler::handle433(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle433()", params, 1))
-    return;
-
-  QString errnick = serverDecode(params[0]);
-  emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Nick already in use: %1").arg(errnick));
-
-  // if there is a problem while connecting to the server -> we handle it
-  // but only if our connection has not been finished yet...
-  if(!network()->currentServer().isEmpty())
-    return;
-
-  tryNextNick(errnick);
-}
-
-/* ERR_UNAVAILRESOURCE */
-void IrcServerHandler::handle437(const QString &prefix, const QList<QByteArray> &params) {
-  Q_UNUSED(prefix);
-  if(!checkParamCount("IrcServerHandler::handle437()", params, 1))
-    return;
-
-  QString errnick = serverDecode(params[0]);
-  emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Nick/channel is temporarily unavailable: %1").arg(errnick));
-
-  // if there is a problem while connecting to the server -> we handle it
-  // but only if our connection has not been finished yet...
-  if(!network()->currentServer().isEmpty())
-    return;
-
-  if(!network()->isChannelName(errnick))
-    tryNextNick(errnick);
-}
-
 /* Handle signals from Netsplit objects  */
 
 void IrcServerHandler::handleNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes, const QString& quitMessage)
 /* Handle signals from Netsplit objects  */
 
 void IrcServerHandler::handleNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes, const QString& quitMessage)
index 94416a0..59c470c 100644 (file)
@@ -41,9 +41,6 @@ public slots:
   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
   void handle324(const QString &prefix, const QList<QByteArray> &params);   // RPL_CHANNELMODEIS
   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
   void handle324(const QString &prefix, const QList<QByteArray> &params);   // RPL_CHANNELMODEIS
-  void handle432(const QString &prefix, const QList<QByteArray> &params);   // ERR_ERRONEUSNICKNAME
-  void handle433(const QString &prefix, const QList<QByteArray> &params);   // ERR_NICKNAMEINUSE
-  void handle437(const QString &prefix, const QList<QByteArray> &params);   // ERR_UNAVAILRESOURCE
 
   void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &params);
 
 
   void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &params);