From: Manuel Nickschas Date: Sun, 10 Oct 2010 11:54:43 +0000 (+0200) Subject: Event backend porting X-Git-Tag: 0.8-beta1~91 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=3ec6f311bb4fff1540a01c26069300ad17f6d134;ds=sidebyside Event backend porting ERR_ERRONEUSNICKNAME (432), ERR_NICKNAMEINUSE (433), ERR_UNAVAILRESOURCE (437) --- diff --git a/src/core/coresessioneventprocessor.cpp b/src/core/coresessioneventprocessor.cpp index 3b5ad27e..cb116919 100644 --- a/src/core/coresessioneventprocessor.cpp +++ b/src/core/coresessioneventprocessor.cpp @@ -25,6 +25,7 @@ #include "coresession.h" #include "ircevent.h" #include "ircuser.h" +#include "messageevent.h" CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session) : QObject(session), @@ -47,6 +48,28 @@ bool CoreSessionEventProcessor::checkParamCount(IrcEvent *e, int minParams) { 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 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()) { @@ -445,6 +468,54 @@ void CoreSessionEventProcessor::processIrcEvent353(IrcEvent *e) { 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)) @@ -452,3 +523,4 @@ void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) { } */ + diff --git a/src/core/coresessioneventprocessor.h b/src/core/coresessioneventprocessor.h index 7c533e46..59b48793 100644 --- a/src/core/coresessioneventprocessor.h +++ b/src/core/coresessioneventprocessor.h @@ -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 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(e->network()); } + void tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneous = false); private: CoreSession *_coreSession; diff --git a/src/core/eventstringifier.cpp b/src/core/eventstringifier.cpp index 94c967de..a7238b27 100644 --- a/src/core/eventstringifier.cpp +++ b/src/core/eventstringifier.cpp @@ -105,11 +105,11 @@ void EventStringifier::processIrcEventNumeric(IrcEventNumeric *e) { } // Ignore these commands. - case 321: case 366: case 376: + case 321: case 353: case 366: case 376: 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; @@ -424,6 +424,21 @@ void EventStringifier::processIrcEvent369(IrcEvent *e) { 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 /* diff --git a/src/core/eventstringifier.h b/src/core/eventstringifier.h index c31842ee..25733ad4 100644 --- a/src/core/eventstringifier.h +++ b/src/core/eventstringifier.h @@ -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 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); diff --git a/src/core/ircserverhandler.cpp b/src/core/ircserverhandler.cpp index dfb30098..ae7c42b4 100644 --- a/src/core/ircserverhandler.cpp +++ b/src/core/ircserverhandler.cpp @@ -405,60 +405,6 @@ void IrcServerHandler::handle324(const QString &prefix, const QList handleMode(prefix, params); } -/* ERR_ERRONEUSNICKNAME */ -void IrcServerHandler::handle432(const QString &prefix, const QList ¶ms) { - 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 ¶ms) { - 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 ¶ms) { - 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) diff --git a/src/core/ircserverhandler.h b/src/core/ircserverhandler.h index 94416a09..59c470c2 100644 --- a/src/core/ircserverhandler.h +++ b/src/core/ircserverhandler.h @@ -41,9 +41,6 @@ public slots: void handlePrivmsg(const QString &prefix, const QList ¶ms); void handleQuit(const QString &prefix, const QList ¶ms); void handle324(const QString &prefix, const QList ¶ms); // RPL_CHANNELMODEIS - void handle432(const QString &prefix, const QList ¶ms); // ERR_ERRONEUSNICKNAME - void handle433(const QString &prefix, const QList ¶ms); // ERR_NICKNAMEINUSE - void handle437(const QString &prefix, const QList ¶ms); // ERR_UNAVAILRESOURCE void defaultHandler(QString cmd, const QString &prefix, const QList ¶ms);