summaryrefslogtreecommitdiff
authorskyhusker <skyhusker>2005-01-16 02:14:38 (UTC)
committer skyhusker <skyhusker>2005-01-16 02:14:38 (UTC)
commit986280fcb93a2c9550aa83a3109deb885ce50e8f (patch) (unidiff)
treed507028d909e7e7f1703aa80b3b2d7201573bd93
parente420e24bb1506e313cc38174111d424ba7274e33 (diff)
downloadopie-986280fcb93a2c9550aa83a3109deb885ce50e8f.zip
opie-986280fcb93a2c9550aa83a3109deb885ce50e8f.tar.gz
opie-986280fcb93a2c9550aa83a3109deb885ce50e8f.tar.bz2
Fixed a bug in nickname handling with networks using nickname:password for auth
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index fde156c..cfad2c1 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,366 +1,374 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include "ircmessageparser.h" 4#include "ircmessageparser.h"
5#include "ircversion.h" 5#include "ircversion.h"
6 6
7/* Lookup table for literal commands */ 7/* Lookup table for literal commands */
8IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 8IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
9 { "PING", FUNC(parseLiteralPing) }, 9 { "PING", FUNC(parseLiteralPing) },
10 { "NOTICE", FUNC(parseLiteralNotice) }, 10 { "NOTICE", FUNC(parseLiteralNotice) },
11 { "JOIN", FUNC(parseLiteralJoin) }, 11 { "JOIN", FUNC(parseLiteralJoin) },
12 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 12 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
13 { "NICK", FUNC(parseLiteralNick) }, 13 { "NICK", FUNC(parseLiteralNick) },
14 { "PART", FUNC(parseLiteralPart) }, 14 { "PART", FUNC(parseLiteralPart) },
15 { "QUIT", FUNC(parseLiteralQuit) }, 15 { "QUIT", FUNC(parseLiteralQuit) },
16 { "ERROR", FUNC(parseLiteralError) }, 16 { "ERROR", FUNC(parseLiteralError) },
17 { "ERROR:", FUNC(parseLiteralError) }, 17 { "ERROR:", FUNC(parseLiteralError) },
18 { "MODE", FUNC(parseLiteralMode) }, 18 { "MODE", FUNC(parseLiteralMode) },
19 { "KICK", FUNC(parseLiteralKick) }, 19 { "KICK", FUNC(parseLiteralKick) },
20 { "TOPIC", FUNC(parseLiteralTopic) }, 20 { "TOPIC", FUNC(parseLiteralTopic) },
21 { 0 , 0 } 21 { 0 , 0 }
22}; 22};
23 23
24/* Lookup table for literal commands */ 24/* Lookup table for literal commands */
25IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 25IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
26 { "PING", FUNC(parseCTCPPing) }, 26 { "PING", FUNC(parseCTCPPing) },
27 { "VERSION", FUNC(parseCTCPVersion) }, 27 { "VERSION", FUNC(parseCTCPVersion) },
28 { "ACTION", FUNC(parseCTCPAction) }, 28 { "ACTION", FUNC(parseCTCPAction) },
29 { 0 , 0 } 29 { 0 , 0 }
30}; 30};
31 31
32/* Lookup table for numerical commands 32/* Lookup table for numerical commands
33 * According to: 33 * According to:
34 * http://www.faqs.org/rfcs/rfc1459.html 34 * http://www.faqs.org/rfcs/rfc1459.html
35 * http://www.faqs.org/rfcs/rfc2812.html 35 * http://www.faqs.org/rfcs/rfc2812.html
36*/ 36*/
37 37
38IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { 38IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
39 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME 39 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME
40 { 2, "%1", "1", 0 }, // RPL_YOURHOST 40 { 2, "%1", "1", 0 }, // RPL_YOURHOST
41 { 3, "%1", "1", 0 }, // RPL_CREATED 41 { 3, "%1", "1", 0 }, // RPL_CREATED
42 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO 42 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO
43 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL 43 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL
44 { 250, "%1", "1", 0 }, // RPL_STATSCONN 44 { 250, "%1", "1", 0 }, // RPL_STATSCONN
45 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT 45 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT
46 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP 46 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP
47 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN 47 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN
48 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS 48 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS
49 { 255, "%1", "1", 0 }, // RPL_LUSERME 49 { 255, "%1", "1", 0 }, // RPL_LUSERME
50 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN 50 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
51 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS 51 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
52 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS 52 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
53 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER 53 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5" }, // RPL_WHOISUSER
54 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER 54 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
55 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE 55 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
56 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS 56 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
57 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT 57 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
58 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC 58 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
59 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ 59 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
60 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY 60 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
61 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 61 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
62 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS 62 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
63 { 372, "%1", "1", 0 }, // RPL_MOTD 63 { 372, "%1", "1", 0 }, // RPL_MOTD
64 { 375, "%1", "1", 0 }, // RPL_MOTDSTART 64 { 375, "%1", "1", 0 }, // RPL_MOTDSTART
65 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD 65 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
66 { 377, "%1", "1", 0 }, // RPL_MOTD2 66 { 377, "%1", "1", 0 }, // RPL_MOTD2
67 { 378, "%1", "1", 0 }, // RPL_MOTD3 67 { 378, "%1", "1", 0 }, // RPL_MOTD3
68 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME 68 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME
69 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK 69 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK
70 { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK 70 { 406, QT_TR_NOOP("There is no history information for %1"), "1" }, // ERR_WASNOSUCHNICK
71 { 409, "%1", "1", 0 }, // ERR_NOORIGIN 71 { 409, "%1", "1", 0 }, // ERR_NOORIGIN
72 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT 72 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
73 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND 73 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
74 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_NOMOTD 74 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND
75 { 422, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
76 { 422, "%1", "1", 0 }, // ERR_NOMOTD 75 { 422, "%1", "1", 0 }, // ERR_NOMOTD
77 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 76 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
77 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
78 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK 78 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
79 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED 79 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED
80 { 0, 0, 0, 0 } 80 { 0, 0, 0, 0 }
81}; 81};
82 82
83 83
84IRCMessageParser::IRCMessageParser(IRCSession *session) { 84IRCMessageParser::IRCMessageParser(IRCSession *session) {
85 m_session = session; 85 m_session = session;
86} 86}
87 87
88void IRCMessageParser::parse(IRCMessage *message) { 88void IRCMessageParser::parse(IRCMessage *message) {
89 /* Find out what kind of message we have here and call the appropriate handler using 89 /* Find out what kind of message we have here and call the appropriate handler using
90 the parser tables. If no handler can be found, print out an error message */ 90 the parser tables. If no handler can be found, print out an error message */
91 if (message->isNumerical()) { 91 if (message->isNumerical()) {
92 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 92 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
93 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 93 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
94 parseNumerical(message, i); 94 parseNumerical(message, i);
95 return; 95 return;
96 } 96 }
97 } 97 }
98 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 98 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
99 } else if (message->isCTCP()) { 99 } else if (message->isCTCP()) {
100 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 100 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
101 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 101 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
102 (this->*(ctcpParserProcTable[i].proc))(message); 102 (this->*(ctcpParserProcTable[i].proc))(message);
103 return; 103 return;
104 } 104 }
105 } 105 }
106 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) ); 106 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) );
107 } else { 107 } else {
108 for (int i=0; literalParserProcTable[i].commandName; i++) { 108 for (int i=0; literalParserProcTable[i].commandName; i++) {
109 if (message->command() == literalParserProcTable[i].commandName) { 109 if (message->command() == literalParserProcTable[i].commandName) {
110 (this->*(literalParserProcTable[i].proc))(message); 110 (this->*(literalParserProcTable[i].proc))(message);
111 return; 111 return;
112 } 112 }
113 } 113 }
114 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) )); 114 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) ));
115 } 115 }
116} 116}
117 117
118void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { 118void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
119 QString out = tr(numericalParserProcTable[position].message); 119 QString out = tr(numericalParserProcTable[position].message);
120 QString paramString = numericalParserProcTable[position].params; 120 QString paramString = numericalParserProcTable[position].params;
121 121
122 if(!out.isEmpty() && !paramString.isEmpty()) { 122 if(!out.isEmpty() && !paramString.isEmpty()) {
123 QStringList params = message->params(numericalParserProcTable[position].params); 123 QStringList params = message->params(numericalParserProcTable[position].params);
124 124
125 QStringList::Iterator end = params.end(); 125 QStringList::Iterator end = params.end();
126 for (QStringList::Iterator it = params.begin(); it != end; ++it) { 126 for (QStringList::Iterator it = params.begin(); it != end; ++it) {
127 out = out.arg(*it); 127 out = out.arg(*it);
128 } 128 }
129 129
130 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 130 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
131 } 131 }
132 132
133 if(numericalParserProcTable[position].proc) 133 if(numericalParserProcTable[position].proc)
134 (this->*(numericalParserProcTable[position].proc))(message); 134 (this->*(numericalParserProcTable[position].proc))(message);
135} 135}
136 136
137void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { 137void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
138 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); 138 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
139 /* Register EFFECTIVE nickname, some networks (as irc-hispano) uses nick:password
140 * for authentication and the parser gets confused */
141 m_session->m_server->setNick(message->param(0));
142
139} 143}
140 144
141void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { 145void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
142 m_session->setValidUsermodes(message->param(2)); 146 m_session->setValidUsermodes(message->param(2));
143 m_session->setValidChannelmodes(message->param(3)); 147 m_session->setValidChannelmodes(message->param(3));
144 148
145} 149}
146 150
147void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { 151void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) {
148 /* XXX: Add some usefull features here */ 152 /* XXX: Add some usefull features here */
149 QString out = message->allParameters(); 153 QString out = message->allParameters();
150 out = out.mid(out.find(' ')+1); 154 out = out.mid(out.find(' ')+1);
151 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 155 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
152} 156}
153void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { 157void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) {
154 QDateTime dt; 158 QDateTime dt;
155 QTime t; 159 QTime t;
156 t = t.addSecs(message->param(2).toInt()); 160 t = t.addSecs(message->param(2).toInt());
157 dt.setTime_t(message->param(3).toInt()); 161 dt.setTime_t(message->param(3).toInt());
158 162
159 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString()))); 163 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString())));
160 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString()))); 164 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString())));
161 165
162} 166}
163 167
164void IRCMessageParser::parseLiteralPing(IRCMessage *message) { 168void IRCMessageParser::parseLiteralPing(IRCMessage *message) {
165 m_session->m_connection->sendLine("PONG " + message->allParameters()); 169 m_session->m_connection->sendLine("PONG " + message->allParameters());
166} 170}
167 171
168void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { 172void IRCMessageParser::parseLiteralNotice(IRCMessage *message) {
169 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); 173 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
170} 174}
171 175
172void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { 176void IRCMessageParser::parseLiteralJoin(IRCMessage *message) {
173 QString channelName = message->param(0).lower(); 177 QString channelName = message->param(0).lower();
174 IRCPerson mask(message->prefix()); 178 IRCPerson mask(message->prefix());
175 IRCChannel *channel = m_session->getChannel(channelName); 179 IRCChannel *channel = m_session->getChannel(channelName);
176 if (!channel) { 180 if (!channel) {
177 /* We joined */ 181 /* We joined */
178 if (mask.nick() == m_session->m_server->nick()) { 182 if (mask.nick() == m_session->m_server->nick()) {
179 channel = new IRCChannel(channelName); 183 channel = new IRCChannel(channelName);
180 m_session->addChannel(channel); 184 m_session->addChannel(channel);
181 } else { 185 } else {
182 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); 186 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?")));
183 } 187 }
184 } else { 188 } else {
185 /* Someone else joined */ 189 /* Someone else joined */
186 if (mask.nick() != m_session->m_server->nick()) { 190 if (mask.nick() != m_session->m_server->nick()) {
187 if (!channel->getPerson(mask.nick())) { 191 if (!channel->getPerson(mask.nick())) {
188 IRCChannelPerson *chanperson = new IRCChannelPerson(); 192 IRCChannelPerson *chanperson = new IRCChannelPerson();
189 IRCPerson *person = m_session->getPerson(mask.nick()); 193 IRCPerson *person = m_session->getPerson(mask.nick());
190 if (!person) { 194 if (!person) {
191 person = new IRCPerson(message->prefix()); 195 person = new IRCPerson(message->prefix());
192 m_session->addPerson(person); 196 m_session->addPerson(person);
193 } 197 }
194 chanperson->flags = 0; 198 chanperson->flags = 0;
195 chanperson->person = person; 199 chanperson->person = person;
196 channel->addPerson(chanperson); 200 channel->addPerson(chanperson);
197 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); 201 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName ));
198 output.addParam(channel); 202 output.addParam(channel);
199 output.addParam(chanperson); 203 output.addParam(chanperson);
200 emit outputReady(output); 204 emit outputReady(output);
201 } else { 205 } else {
202 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); 206 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?")));
203 } 207 }
204 } else { 208 } else {
205 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); 209 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?")));
206 } 210 }
207 } 211 }
208} 212}
209 213
210void IRCMessageParser::parseLiteralPart(IRCMessage *message) { 214void IRCMessageParser::parseLiteralPart(IRCMessage *message) {
211 QString channelName = message->param(0).lower(); 215 QString channelName = message->param(0).lower();
212 IRCChannel *channel = m_session->getChannel(channelName); 216 IRCChannel *channel = m_session->getChannel(channelName);
213 IRCPerson mask(message->prefix()); 217 IRCPerson mask(message->prefix());
214 if (channel) { 218 if (channel) {
215 if (mask.nick() == m_session->m_server->nick()) { 219 if (mask.nick() == m_session->m_server->nick()) {
216 m_session->removeChannel(channel); 220 m_session->removeChannel(channel);
217 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); 221 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName ));
218 output.addParam(channel); 222 output.addParam(channel);
219 emit outputReady(output); 223 emit outputReady(output);
220 delete channel; 224 delete channel;
221 } else { 225 } else {
222 IRCChannelPerson *person = channel->getPerson(mask.nick()); 226 IRCChannelPerson *person = channel->getPerson(mask.nick());
223 if (person) { 227 if (person) {
224 channel->removePerson(person); 228 channel->removePerson(person);
225 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) ); 229 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) );
226 output.addParam(channel); 230 output.addParam(channel);
227 output.addParam(person); 231 output.addParam(person);
228 emit outputReady(output); 232 emit outputReady(output);
229 delete person; 233 delete person;
230 } else { 234 } else {
231 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); 235 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?")));
232 } 236 }
233 } 237 }
234 } else { 238 } else {
235 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); 239 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?")));
236 } 240 }
237} 241}
238 242
239void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { 243void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
240 if (m_session->m_server->nick().lower() == message->param(0).lower() ) { 244 if (m_session->m_server->nick().lower() == message->param(0).lower() ) {
241 /* IRC Query message detected, verify sender and display it */ 245 /* IRC Query message detected, verify sender and display it */
242 IRCPerson mask(message->prefix()); 246 IRCPerson mask(message->prefix());
243 IRCPerson *person = m_session->getPerson(mask.nick()); 247 IRCPerson *person = m_session->getPerson(mask.nick());
244 if (!person) { 248 if (!person) {
245 /* Person not yet known, create and add to the current session */ 249 /* Person not yet known, create and add to the current session */
246 person = new IRCPerson(message->prefix()); 250 person = new IRCPerson(message->prefix());
247 m_session->addPerson(person); 251 m_session->addPerson(person);
248 } 252 }
249 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 253 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
250 output.addParam(person); 254 output.addParam(person);
251 emit outputReady(output); 255 emit outputReady(output);
252 } else if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { 256 }
253 /* IRC Channel message detected, verify sender, channel and display it */ 257 else
254 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 258 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') {
255 if (channel) { 259 /* IRC Channel message detected, verify sender, channel and display it */
256 IRCPerson mask(message->prefix()); 260 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
257 IRCChannelPerson *person = channel->getPerson(mask.nick()); 261 if (channel) {
258 if (person) { 262 IRCPerson mask(message->prefix());
259 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 263 IRCChannelPerson *person = channel->getPerson(mask.nick());
260 output.addParam(channel); 264 if (person) {
261 output.addParam(person); 265 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
262 emit outputReady(output); 266 output.addParam(channel);
263 } else { 267 output.addParam(person);
264 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 268 emit outputReady(output);
269 }
270 else {
271 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
272 }
273 }
274 else {
275 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
265 } 276 }
266 } else { 277 }
267 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 278 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
268 }
269 } else {
270 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
271 } 279 }
272} 280}
273 281
274void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 282void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
275 IRCPerson mask(message->prefix()); 283 IRCPerson mask(message->prefix());
276 m_session->updateNickname(mask.nick(), message->param(0)); 284 m_session->updateNickname(mask.nick(), message->param(0));
277 /* this way of handling nick changes really sucks 285 /* this way of handling nick changes really sucks
278 if (mask.nick() == m_session->m_server->nick()) { 286 if (mask.nick() == m_session->m_server->nick()) {
279 We are changing our nickname 287 We are changing our nickname
280 m_session->m_server->setNick(message->param(0)); 288 m_session->m_server->setNick(message->param(0));
281 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 289 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
282 output.addParam(0); 290 output.addParam(0);
283 emit outputReady(output); 291 emit outputReady(output);
284 } else { 292 } else {
285 Someone else is 293 Someone else is
286 RCPerson *person = m_session->getPerson(mask.nick()); 294 RCPerson *person = m_session->getPerson(mask.nick());
287 if (person) { 295 if (person) {
288 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 296 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
289 297
290 new code starts here -- this removes the person from all channels 298 new code starts here -- this removes the person from all channels
291 QList<IRCChannel> channels; 299 QList<IRCChannel> channels;
292 m_session->getChannelsByPerson(person, channels); 300 m_session->getChannelsByPerson(person, channels);
293 QListIterator<IRCChannel> it(channels); 301 QListIterator<IRCChannel> it(channels);
294 for (;it.current(); ++it) { 302 for (;it.current(); ++it) {
295 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 303 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
296 it.current()->removePerson(chanperson); 304 it.current()->removePerson(chanperson);
297 chanperson->person->setNick(message->param(0)); 305 chanperson->person->setNick(message->param(0));
298 it.current()->addPerson(chanperson); 306 it.current()->addPerson(chanperson);
299 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 307 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
300 output.addParam(person); 308 output.addParam(person);
301 emit outputReady(output); 309 emit outputReady(output);
302 } 310 }
303 new code ends here 311 new code ends here
304 } else { 312 } else {
305 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 313 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
306 } 314 }
307 }*/ 315 }*/
308} 316}
309 317
310void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 318void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
311 IRCPerson mask(message->prefix()); 319 IRCPerson mask(message->prefix());
312 IRCPerson *person = m_session->getPerson(mask.nick()); 320 IRCPerson *person = m_session->getPerson(mask.nick());
313 if (person) { 321 if (person) {
314 QList<IRCChannel> channels; 322 QList<IRCChannel> channels;
315 m_session->getChannelsByPerson(person, channels); 323 m_session->getChannelsByPerson(person, channels);
316 QListIterator<IRCChannel> it(channels); 324 QListIterator<IRCChannel> it(channels);
317 for (;it.current(); ++it) { 325 for (;it.current(); ++it) {
318 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 326 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
319 it.current()->removePerson(chanperson); 327 it.current()->removePerson(chanperson);
320 delete chanperson; 328 delete chanperson;
321 } 329 }
322 m_session->removePerson(person); 330 m_session->removePerson(person);
323 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); 331 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) ));
324 output.addParam(person); 332 output.addParam(person);
325 emit outputReady(output); 333 emit outputReady(output);
326 delete person; 334 delete person;
327 } else { 335 } else {
328 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 336 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
329 } 337 }
330} 338}
331 339
332void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { 340void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
333 IRCPerson mask(message->prefix()); 341 IRCPerson mask(message->prefix());
334 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 342 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
335 if (channel) { 343 if (channel) {
336 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); 344 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
337 output.addParam(channel); 345 output.addParam(channel);
338 emit outputReady(output); 346 emit outputReady(output);
339 } else { 347 } else {
340 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); 348 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
341 } 349 }
342} 350}
343 351
344void IRCMessageParser::parseLiteralError(IRCMessage *message) { 352void IRCMessageParser::parseLiteralError(IRCMessage *message) {
345 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 353 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
346} 354}
347 355
348void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 356void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
349 IRCPerson mask(message->prefix()); 357 IRCPerson mask(message->prefix());
350 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); 358 m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters());
351 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); 359 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick()));
352 360
353 //IRCPerson mask(message->prefix()); 361 //IRCPerson mask(message->prefix());
354 QString dest = message->ctcpDestination(); 362 QString dest = message->ctcpDestination();
355 if (dest.startsWith("#")) { 363 if (dest.startsWith("#")) {
356 IRCChannel *channel = m_session->getChannel(dest.lower()); 364 IRCChannel *channel = m_session->getChannel(dest.lower());
357 if (channel) { 365 if (channel) {
358 IRCChannelPerson *person = channel->getPerson(mask.nick()); 366 IRCChannelPerson *person = channel->getPerson(mask.nick());
359 if (person) { 367 if (person) {
360 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; 368 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ;
361 output.addParam(channel); 369 output.addParam(channel);
362 output.addParam(person); 370 output.addParam(person);
363 emit outputReady(output); 371 emit outputReady(output);
364 } else { 372 } else {
365 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); 373 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?")));
366 } 374 }