IrcServerParseError,
IrcEvent = 0x00030000,
+ IrcEventAuthenticate,
IrcEventCap,
- IrcEventCapAuthenticate,
IrcEventInvite,
IrcEventJoin,
IrcEventKick,
}
}
+void CoreSessionEventProcessor::processIrcEventAuthenticate(IrcEvent *e) {
+ if(!checkParamCount(e, 1))
+ return;
+
+ if(e->params().at(0) != "+") {
+ qWarning() << "Invalid AUTHENTICATE" << e;
+ return;
+ }
+
+ CoreNetwork *net = coreNetwork(e);
+
+ QString construct = net->saslAccount();
+ construct.append(QChar(QChar::Null));
+ construct.append(net->saslAccount());
+ construct.append(QChar(QChar::Null));
+ construct.append(net->saslPassword());
+ QByteArray saslData = QByteArray(construct.toAscii().toBase64());
+ saslData.prepend("AUTHENTICATE ");
+ net->putRawLine(saslData);
+}
+
+void CoreSessionEventProcessor::processIrcEventCap(IrcEvent *e) {
+ // for SASL, there will only be a single param of 'sasl', however you can check here for
+ // additional CAP messages (ls, multi-prefix, et cetera).
+
+ if(e->params().count() == 3) {
+ if(e->params().at(2) == "sasl") {
+ // FIXME use event
+ coreNetwork(e)->putRawLine(coreNetwork(e)->serverEncode("AUTHENTICATE PLAIN")); // Only working with PLAIN atm, blowfish later
+ }
+ }
+}
+
void CoreSessionEventProcessor::processIrcEventInvite(IrcEvent *e) {
if(checkParamCount(e, 2)) {
e->network()->updateNickFromMask(e->prefix());
qobject_cast<CoreNetwork *>(e->network())->setChannelParted(channel);
}
}
+
+void CoreSessionEventProcessor::processIrcEventPong(IrcEvent *e) {
+ // the server is supposed to send back what we passed as param. and we send a timestamp
+ // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
+ if(checkParamCount(e, 2)) {
+ QString timestamp = e->params().at(1);
+ QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
+ if(sendTime.isValid())
+ e->network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
+ }
+}
+
+void CoreSessionEventProcessor::processIrcEventTopic(IrcEvent *e) {
+ if(checkParamCount(e, 2)) {
+ e->network()->updateNickFromMask(e->prefix());
+ IrcChannel *channel = e->network()->ircChannel(e->params().at(0));
+ if(channel)
+ channel->setTopic(e->params().at(1));
+ }
+}
+
+/* RPL_WELCOME */
+void CoreSessionEventProcessor::processIrcEvent001(IrcEvent *e) {
+ if(!checkParamCount(e, 1))
+ return;
+
+ QString myhostmask = e->params().at(0).section(' ', -1, -1);
+ e->network()->setCurrentServer(e->prefix());
+ e->network()->setMyNick(nickFromMask(myhostmask));
+}
+
+/* template
+void CoreSessionEventProcessor::processIrcEvent(IrcEvent *e) {
+ if(!checkParamCount(e, 1))
+ return;
+
+}
+*/
#ifndef CORESESSIONEVENTPROCESSOR_H
#define CORESESSIONEVENTPROCESSOR_H
-#include <QObject>
+#include "corenetwork.h"
+#include "networkevent.h"
class CoreSession;
class IrcEvent;
Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric *event);
+ Q_INVOKABLE void processIrcEventAuthenticate(IrcEvent *event); // SASL auth
+ Q_INVOKABLE void processIrcEventCap(IrcEvent *event); // CAP framework
Q_INVOKABLE void processIrcEventInvite(IrcEvent *event);
Q_INVOKABLE void processIrcEventKick(IrcEvent *event);
Q_INVOKABLE void processIrcEventNick(IrcEvent *event);
Q_INVOKABLE void processIrcEventPart(IrcEvent *event);
+ Q_INVOKABLE void processIrcEventPong(IrcEvent *event);
+ Q_INVOKABLE void processIrcEventTopic(IrcEvent *event);
+
+ Q_INVOKABLE void processIrcEvent001(IrcEvent *event); // RPL_WELCOME
+
+ // 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()); }
private:
CoreSession *_coreSession;
//qDebug() << e->number();
switch(e->number()) {
// Welcome, status, info messages. Just display these.
- case 2: case 3: case 4: case 5: case 251: case 252: case 253: case 254: case 255: case 372: case 375:
- displayMsg(e, Message::Server, e->params().join(" "), e->prefix());
+ case 1: case 2: case 3: case 4: case 5: case 251: case 252: case 253: case 254: case 255: case 372: case 375:
+ displayMsg(e, Message::Server, e->params().join(" "), e->prefix()); qDebug () << e;
break;
// Server error messages without param, just display them
displayMsg(e, Message::Part, msg, e->prefix(), channel);
}
+
+void EventStringifier::processIrcEventPong(IrcEvent *e) {
+ QString timestamp = e->params().at(1);
+ QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
+ if(!sendTime.isValid())
+ displayMsg(e, Message::Server, "PONG " + e->params().join(" "), e->prefix());
+}
+
+void EventStringifier::processIrcEventTopic(IrcEvent *e) {
+ displayMsg(e, Message::Topic, tr("%1 has changed topic for %2 to: \"%3\"")
+ .arg(e->nick(), e->params().at(0), e->params().at(1)), QString(), e->params().at(0));
+}
Q_INVOKABLE void earlyProcessIrcEventKick(IrcEvent *event);
Q_INVOKABLE void earlyProcessIrcEventNick(IrcEvent *event);
Q_INVOKABLE void earlyProcessIrcEventPart(IrcEvent *event);
+ Q_INVOKABLE void processIrcEventPong(IrcEvent *event);
+ Q_INVOKABLE void processIrcEventTopic(IrcEvent *event);
+
+ // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
public slots:
//! Creates and sends a MessageEvent
QString foo = serverDecode(params.takeFirst());
// with SASL, the command is 'AUTHENTICATE +' and we should check for this here.
+ /* obsolete because of events
if(foo == QString("AUTHENTICATE +")) {
handleAuthenticate();
return;
}
-
+ */
// a colon as the first chars indicates the existence of a prefix
if(foo[0] == ':') {
foo.remove(0, 1);
putCmd("PONG", params);
}
-void IrcServerHandler::handlePong(const QString &prefix, const QList<QByteArray> ¶ms) {
- Q_UNUSED(prefix);
- // the server is supposed to send back what we passed as param. and we send a timestamp
- // but using quote and whatnought one can send arbitrary pings, so we have to do some sanity checks
- if(params.count() < 2)
- return;
-
- QString timestamp = serverDecode(params[1]);
- QTime sendTime = QTime::fromString(timestamp, "hh:mm:ss.zzz");
- if(!sendTime.isValid()) {
- emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", "PONG " + serverDecode(params).join(" "), prefix);
- return;
- }
-
- network()->setLatency(sendTime.msecsTo(QTime::currentTime()) / 2);
-}
-
void IrcServerHandler::handlePrivmsg(const QString &prefix, const QList<QByteArray> ¶ms) {
if(!checkParamCount("IrcServerHandler::handlePrivmsg()", params, 1))
return;
}
}
-void IrcServerHandler::handleTopic(const QString &prefix, const QList<QByteArray> ¶ms) {
- if(!checkParamCount("IrcServerHandler::handleTopic()", params, 1))
- return;
-
- IrcUser *ircuser = network()->updateNickFromMask(prefix);
- if(!ircuser)
- return;
-
- IrcChannel *channel = network()->ircChannel(serverDecode(params[0]));
- if(!channel)
- return;
-
- QString topic;
- if(params.count() > 1) {
- QByteArray rawTopic = params[1];
-#ifdef HAVE_QCA2
- rawTopic = decrypt(channel->name(), rawTopic, true);
-#endif
- topic = channelDecode(channel->name(), rawTopic);
- }
-
- channel->setTopic(topic);
-
- emit displayMsg(Message::Topic, BufferInfo::ChannelBuffer, channel->name(), tr("%1 has changed topic for %2 to: \"%3\"").arg(ircuser->nick()).arg(channel->name()).arg(topic));
-}
-
-void IrcServerHandler::handleCap(const QString &prefix, const QList<QByteArray> ¶ms) {
- // for SASL, there will only be a single param of 'sasl', however you can check here for
- // additional CAP messages (ls, multi-prefix, et cetera).
-
- Q_UNUSED(prefix);
-
- if(params.size() == 3) {
- QString param = serverDecode(params[2]);
- if(param == QString("sasl")) { // SASL Ready
- network()->putRawLine(serverEncode("AUTHENTICATE PLAIN")); // Only working with PLAIN atm, blowfish later
- }
- }
-}
-
-void IrcServerHandler::handleAuthenticate() {
- QString construct = network()->saslAccount();
- construct.append(QChar(QChar::Null));
- construct.append(network()->saslAccount());
- construct.append(QChar(QChar::Null));
- construct.append(network()->saslPassword());
- QByteArray saslData = QByteArray(construct.toAscii().toBase64());
- saslData.prepend(QString("AUTHENTICATE ").toAscii());
- network()->putRawLine(saslData);
-}
-
-/* RPL_WELCOME */
-void IrcServerHandler::handle001(const QString &prefix, const QList<QByteArray> ¶ms) {
- network()->setCurrentServer(prefix);
-
- if(params.isEmpty()) {
- emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("%1 didn't supply a valid welcome message... expect some serious issues..."));
- }
- // there should be only one param: "Welcome to the Internet Relay Network <nick>!<user>@<host>"
- QString param = serverDecode(params[0]);
- QString myhostmask = param.section(' ', -1, -1);
-
- network()->setMyNick(nickFromMask(myhostmask));
-
- emit displayMsg(Message::Server, BufferInfo::StatusBuffer, "", param, prefix);
-}
-
/* RPL_ISUPPORT */
// TODO Complete 005 handling, also use sensible defaults for non-sent stuff
void IrcServerHandler::handle005(const QString &prefix, const QList<QByteArray> ¶ms) {
void handleMode(const QString &prefix, const QList<QByteArray> ¶ms);
void handleNotice(const QString &prefix, const QList<QByteArray> ¶ms);
void handlePing(const QString &prefix, const QList<QByteArray> ¶ms);
- void handlePong(const QString &prefix, const QList<QByteArray> ¶ms);
void handlePrivmsg(const QString &prefix, const QList<QByteArray> ¶ms);
void handleQuit(const QString &prefix, const QList<QByteArray> ¶ms);
- void handleTopic(const QString &prefix, const QList<QByteArray> ¶ms);
- void handleCap(const QString &prefix, const QList<QByteArray> ¶ms); // CAP framework
- void handleAuthenticate(); // SASL auth - no params
- void handle001(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_WELCOME
void handle005(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_ISUPPORT
void handle221(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_UMODEIS
void handle250(const QString &prefix, const QList<QByteArray> ¶ms); // RPL_STATSDLINE