#include "coresession.h"
#include "ircevent.h"
#include "ircuser.h"
+#include "messageevent.h"
CoreSessionEventProcessor::CoreSessionEventProcessor(CoreSession *session)
: QObject(session),
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()) {
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))
}
*/
+
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()); }
+ void tryNextNick(NetworkEvent *e, const QString &errnick, bool erroneous = false);
private:
CoreSession *_coreSession;
}
// 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;
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
/*
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);
handleMode(prefix, params);
}
-/* ERR_ERRONEUSNICKNAME */
-void IrcServerHandler::handle432(const QString &prefix, const QList<QByteArray> ¶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<QByteArray> ¶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<QByteArray> ¶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)
void handlePrivmsg(const QString &prefix, const QList<QByteArray> ¶ms);
void handleQuit(const QString &prefix, const QList<QByteArray> ¶ms);
void handle324(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_CHANNELMODEIS
- void handle432(const QString &prefix, const QList<QByteArray> ¶ms); // ERR_ERRONEUSNICKNAME
- void handle433(const QString &prefix, const QList<QByteArray> ¶ms); // ERR_NICKNAMEINUSE
- void handle437(const QString &prefix, const QList<QByteArray> ¶ms); // ERR_UNAVAILRESOURCE
void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> ¶ms);