X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoresessioneventprocessor.cpp;h=cb116919b735e546b6fda1b854c476e5a1ce78bc;hp=3b5ad27e5469e3a157d3b5fef56a668438c37227;hb=3ec6f311bb4fff1540a01c26069300ad17f6d134;hpb=5ff4265bbd3a682a6d6542480760eaf4a2b85d77 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) { } */ +