summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircmessageparser.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp
index 939cdae..32e1011 100644
--- a/noncore/net/opieirc/ircmessageparser.cpp
+++ b/noncore/net/opieirc/ircmessageparser.cpp
@@ -1,667 +1,668 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include <opie2/ofiledialog.h> 4#include <opie2/ofiledialog.h>
5#include <opie2/ofileselector.h> 5#include <opie2/ofileselector.h>
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7 7
8#include "ircmessageparser.h" 8#include "ircmessageparser.h"
9#include "ircversion.h" 9#include "ircversion.h"
10#include "ircchannelperson.h" 10#include "ircchannelperson.h"
11#include "dcctransfertab.h" 11#include "dcctransfertab.h"
12#include "ircservertab.h" 12#include "ircservertab.h"
13 13
14/* Lookup table for literal commands */ 14/* Lookup table for literal commands */
15IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { 15IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = {
16 { "PING", FUNC(parseLiteralPing) }, 16 { "PING", FUNC(parseLiteralPing) },
17 { "NOTICE", FUNC(parseLiteralNotice) }, 17 { "NOTICE", FUNC(parseLiteralNotice) },
18 { "JOIN", FUNC(parseLiteralJoin) }, 18 { "JOIN", FUNC(parseLiteralJoin) },
19 { "PRIVMSG", FUNC(parseLiteralPrivMsg) }, 19 { "PRIVMSG", FUNC(parseLiteralPrivMsg) },
20 { "NICK", FUNC(parseLiteralNick) }, 20 { "NICK", FUNC(parseLiteralNick) },
21 { "PART", FUNC(parseLiteralPart) }, 21 { "PART", FUNC(parseLiteralPart) },
22 { "QUIT", FUNC(parseLiteralQuit) }, 22 { "QUIT", FUNC(parseLiteralQuit) },
23 { "ERROR", FUNC(parseLiteralError) }, 23 { "ERROR", FUNC(parseLiteralError) },
24 { "ERROR:", FUNC(parseLiteralError) }, 24 { "ERROR:", FUNC(parseLiteralError) },
25 { "MODE", FUNC(parseLiteralMode) }, 25 { "MODE", FUNC(parseLiteralMode) },
26 { "KICK", FUNC(parseLiteralKick) }, 26 { "KICK", FUNC(parseLiteralKick) },
27 { "TOPIC", FUNC(parseLiteralTopic) }, 27 { "TOPIC", FUNC(parseLiteralTopic) },
28 { 0 , 0 } 28 { 0 , 0 }
29}; 29};
30 30
31/* Lookup table for literal commands */ 31/* Lookup table for literal commands */
32IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { 32IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = {
33 { "PING", FUNC(parseCTCPPing) }, 33 { "PING", FUNC(parseCTCPPing) },
34 { "VERSION", FUNC(parseCTCPVersion) }, 34 { "VERSION", FUNC(parseCTCPVersion) },
35 { "ACTION", FUNC(parseCTCPAction) }, 35 { "ACTION", FUNC(parseCTCPAction) },
36 { "DCC", FUNC(parseCTCPDCC) }, 36 { "DCC", FUNC(parseCTCPDCC) },
37 { 0 , 0 } 37 { 0 , 0 }
38}; 38};
39 39
40/* Lookup table for numerical commands 40/* Lookup table for numerical commands
41 * According to: 41 * According to:
42 * http://www.faqs.org/rfcs/rfc1459.html 42 * http://www.faqs.org/rfcs/rfc1459.html
43 * http://www.faqs.org/rfcs/rfc2812.html 43 * http://www.faqs.org/rfcs/rfc2812.html
44*/ 44*/
45 45
46IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { 46IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = {
47 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME 47 { 1, "%1", "1", FUNC(parseNumericalServerName) }, // RPL_WELCOME
48 { 2, "%1", "1", 0 }, // RPL_YOURHOST 48 { 2, "%1", "1", 0 }, // RPL_YOURHOST
49 { 3, "%1", "1", 0 }, // RPL_CREATED 49 { 3, "%1", "1", 0 }, // RPL_CREATED
50 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO 50 { 4, QT_TR_NOOP("Server %1 version %2 supports usermodes '%3' and channelmodes '%4'"), "1:4", FUNC(parseNumericalServerFeatures) }, // RPL_MYINFO
51 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL 51 { 5, 0, 0, FUNC(parseNumericalServerProtocol) }, // RPL_BOUNCE, RPL_PROTOCTL
52 { 250, "%1", "1", 0 }, // RPL_STATSCONN 52 { 250, "%1", "1", 0 }, // RPL_STATSCONN
53 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT 53 { 251, "%1", "1", 0 }, // RPL_LUSERCLIENT
54 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP 54 { 252, QT_TR_NOOP("There are %1 operators connected"), "1", 0 }, // RPL_LUSEROP
55 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN 55 { 253, QT_TR_NOOP("There are %1 unknown connection(s)"), "1", 0 }, // RPL_LUSERUNKNOWN
56 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS 56 { 254, QT_TR_NOOP("There are %1 channels formed"), "1", 0 }, // RPL_LUSERCHANNELS
57 { 255, "%1", "1", 0 }, // RPL_LUSERME 57 { 255, "%1", "1", 0 }, // RPL_LUSERME
58 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN 58 { 263, QT_TR_NOOP("Please wait a while and try again"), 0, 0 }, // RPL_TRYAGAIN
59 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS 59 { 265, "%1", "1", 0 }, // RPL_LOCALUSERS
60 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS 60 { 266, "%1", "1", 0 }, // RPL_GLOBALUSERS
61 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER 61 { 311, QT_TR_NOOP("Whois %1 (%2@%3)\nReal name: %4"), "1:3,5", 0 }, // RPL_WHOISUSER
62 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER 62 { 312, QT_TR_NOOP("%1 is using server %2"), "1,2", 0 }, // RPL_WHOISSERVER
63 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE 63 { 317, 0, 0, FUNC(parseNumericalWhoisIdle) }, // RPL_WHOISIDLE
64 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS 64 { 318, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOIS
65 { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS 65 { 319, QT_TR_NOOP("%1 is on channels: %2"), "1,2", 0 }, // RPL_WHOISCHANNELS
66 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT 66 { 320, "%1 %2", "1,2", 0}, // RPL_WHOISVIRT
67 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC 67 { 332, 0, 0, FUNC(parseNumericalTopic) }, // RPL_TOPIC
68 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/ 68 { 333, 0, 0, FUNC(parseNumericalTopicWhoTime) }, // RPL_TOPICWHOTIME*/
69 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY 69 { 353, QT_TR_NOOP("Names for %1: %2"), "2,3", FUNC(parseNumericalNames) }, // RPL_NAMREPLY
70 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES 70 { 366, "%1 :%2", "1,2", FUNC(parseNumericalEndOfNames) }, // RPL_ENDOFNAMES
71 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS 71 { 369, "%1 :%2", "1,2", 0 }, // RPL_ENDOFWHOWAS
72 { 372, "%1", "1", 0 }, // RPL_MOTD 72 { 372, "%1", "1", 0 }, // RPL_MOTD
73 { 375, "%1", "1", 0 }, // RPL_MOTDSTART 73 { 375, "%1", "1", 0 }, // RPL_MOTDSTART
74 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD 74 { 376, "%1", "1", 0 }, // RPL_ENDOFMOTD
75 { 377, "%1", "1", 0 }, // RPL_MOTD2 75 { 377, "%1", "1", 0 }, // RPL_MOTD2
76 { 378, "%1", "1", 0 }, // RPL_MOTD3 76 { 378, "%1", "1", 0 }, // RPL_MOTD3
77 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME 77 { 391, QT_TR_NOOP("Time on server %1 is %2"), "1,2", 0 }, // RPL_TIME
78 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK 78 { 401, QT_TR_NOOP("Channel or nick %1 doesn't exists"), "1", 0 }, // ERR_NOSUCHNICK
79 { 403, QT_TR_NOOP("Channel %1 doesn't exists"), "1", 0 }, // ERR_ERR_NOSUCHCHANNEL
79 { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK 80 { 406, QT_TR_NOOP("There is no history information for %1"), "1", 0 }, // ERR_WASNOSUCHNICK
80 { 409, "%1", "1", 0 }, // ERR_NOORIGIN 81 { 409, "%1", "1", 0 }, // ERR_NOORIGIN
81 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT 82 { 411, "%1", "1", 0 }, // ERR_NORECIPIENT
82 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND 83 { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND
83 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND 84 { 421, QT_TR_NOOP("Unknown command: %1"), "1", 0 }, // ERR_ERR_UNKNOWNCOMMAND
84 { 422, "%1", "1", 0 }, // ERR_NOMOTD 85 { 422, "%1", "1", 0 }, // ERR_NOMOTD
85 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE 86 { 433, QT_TR_NOOP("Can't change nick to %1: %2"), "1,2", FUNC(parseNumericalNicknameInUse) }, // ERR_NICKNAMEINUSE
86 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL 87 { 442, QT_TR_NOOP("You're not on channel %1"), "1", 0}, // ERR_NOTONCHANNEL
87 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK 88 { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK
88 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED 89 { 482, QT_TR_NOOP("[%1] Operation not permitted, you don't have enough channel privileges"), "1", 0 }, //ERR_CHANOPRIVSNEEDED
89 { 0, 0, 0, 0 } 90 { 0, 0, 0, 0 }
90}; 91};
91 92
92 93
93IRCMessageParser::IRCMessageParser(IRCSession *session) { 94IRCMessageParser::IRCMessageParser(IRCSession *session) {
94 m_session = session; 95 m_session = session;
95} 96}
96 97
97void IRCMessageParser::parse(IRCMessage *message) { 98void IRCMessageParser::parse(IRCMessage *message) {
98 /* Find out what kind of message we have here and call the appropriate handler using 99 /* Find out what kind of message we have here and call the appropriate handler using
99 the parser tables. If no handler can be found, print out an error message */ 100 the parser tables. If no handler can be found, print out an error message */
100 if (message->isNumerical()) { 101 if (message->isNumerical()) {
101 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { 102 for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) {
102 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { 103 if (message->commandNumber() == numericalParserProcTable[i].commandNumber) {
103 parseNumerical(message, i); 104 parseNumerical(message, i);
104 return; 105 return;
105 } 106 }
106 } 107 }
107 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) ))); 108 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled numeric command: %1").arg( QString::number(message->commandNumber()) )));
108 } else if (message->isCTCP()) { 109 } else if (message->isCTCP()) {
109 for (int i=0; ctcpParserProcTable[i].commandName; i++) { 110 for (int i=0; ctcpParserProcTable[i].commandName; i++) {
110 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { 111 if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) {
111 parseCTCP(message, i); 112 parseCTCP(message, i);
112 return; 113 return;
113 } 114 }
114 } 115 }
115 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) ); 116 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled ctcp command: %1").arg( message->ctcpCommand())) );
116 } else { 117 } else {
117 for (int i=0; literalParserProcTable[i].commandName; i++) { 118 for (int i=0; literalParserProcTable[i].commandName; i++) {
118 if (message->command() == literalParserProcTable[i].commandName) { 119 if (message->command() == literalParserProcTable[i].commandName) {
119 (this->*(literalParserProcTable[i].proc))(message); 120 (this->*(literalParserProcTable[i].proc))(message);
120 return; 121 return;
121 } 122 }
122 } 123 }
123 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) )); 124 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received unhandled literal command: %1").arg( message->command()) ));
124 } 125 }
125} 126}
126 127
127void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { 128void IRCMessageParser::parseNumerical(IRCMessage *message, int position) {
128 QString out = tr(numericalParserProcTable[position].message); 129 QString out = tr(numericalParserProcTable[position].message);
129 QString paramString = numericalParserProcTable[position].params; 130 QString paramString = numericalParserProcTable[position].params;
130 131
131 if(!out.isEmpty() && !paramString.isEmpty()) { 132 if(!out.isEmpty() && !paramString.isEmpty()) {
132 QStringList params = message->params(numericalParserProcTable[position].params); 133 QStringList params = message->params(numericalParserProcTable[position].params);
133 134
134 QStringList::Iterator end = params.end(); 135 QStringList::Iterator end = params.end();
135 for (QStringList::Iterator it = params.begin(); it != end; ++it) { 136 for (QStringList::Iterator it = params.begin(); it != end; ++it) {
136 out = out.arg(*it); 137 out = out.arg(*it);
137 } 138 }
138 139
139 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 140 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
140 } 141 }
141 142
142 if(numericalParserProcTable[position].proc) 143 if(numericalParserProcTable[position].proc)
143 (this->*(numericalParserProcTable[position].proc))(message); 144 (this->*(numericalParserProcTable[position].proc))(message);
144} 145}
145 146
146void IRCMessageParser::parseCTCP(IRCMessage *message, int position) { 147void IRCMessageParser::parseCTCP(IRCMessage *message, int position) {
147 if(ctcpParserProcTable[position].proc) 148 if(ctcpParserProcTable[position].proc)
148 (this->*(ctcpParserProcTable[position].proc))(message); 149 (this->*(ctcpParserProcTable[position].proc))(message);
149} 150}
150 151
151 152
152 153
153void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { 154void IRCMessageParser::parseNumericalServerName(IRCMessage *message) {
154 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>")); 155 emit outputReady(IRCOutput(OUTPUT_TITLE, tr("Connected to")+" <b>" + message->prefix() + "</b>"));
155 /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password 156 /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password
156 * for authentication and the parser gets confused */ 157 * for authentication and the parser gets confused */
157 m_session->m_server->setNick(message->param(0)); 158 m_session->m_server->setNick(message->param(0));
158 159
159} 160}
160 161
161void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { 162void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) {
162 m_session->setValidUsermodes(message->param(2)); 163 m_session->setValidUsermodes(message->param(2));
163 m_session->setValidChannelmodes(message->param(3)); 164 m_session->setValidChannelmodes(message->param(3));
164 165
165} 166}
166 167
167void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { 168void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) {
168 /* XXX: Add some usefull features here */ 169 /* XXX: Add some usefull features here */
169 QString out = message->allParameters(); 170 QString out = message->allParameters();
170 out = out.mid(out.find(' ')+1); 171 out = out.mid(out.find(' ')+1);
171 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); 172 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out));
172} 173}
173void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { 174void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) {
174 QDateTime dt; 175 QDateTime dt;
175 QTime t; 176 QTime t;
176 t = t.addSecs(message->param(2).toInt()); 177 t = t.addSecs(message->param(2).toInt());
177 dt.setTime_t(message->param(3).toInt()); 178 dt.setTime_t(message->param(3).toInt());
178 179
179 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString()))); 180 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 has been idle for %2").arg(message->param(1)).arg(t.toString())));
180 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString()))); 181 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, tr("%1 signed on %2").arg(message->param(1)).arg(dt.toString())));
181 182
182} 183}
183 184
184void IRCMessageParser::parseLiteralPing(IRCMessage *message) { 185void IRCMessageParser::parseLiteralPing(IRCMessage *message) {
185 m_session->m_connection->sendLine("PONG " + message->allParameters()); 186 m_session->m_connection->sendLine("PONG " + message->allParameters());
186} 187}
187 188
188void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { 189void IRCMessageParser::parseLiteralNotice(IRCMessage *message) {
189 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); 190 emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters()));
190} 191}
191 192
192void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { 193void IRCMessageParser::parseLiteralJoin(IRCMessage *message) {
193 QString channelName = message->param(0).lower(); 194 QString channelName = message->param(0).lower();
194 IRCPerson mask(message->prefix()); 195 IRCPerson mask(message->prefix());
195 IRCChannel *channel = m_session->getChannel(channelName); 196 IRCChannel *channel = m_session->getChannel(channelName);
196 if (!channel) { 197 if (!channel) {
197 /* We joined */ 198 /* We joined */
198 if (mask.nick() == m_session->m_server->nick()) { 199 if (mask.nick() == m_session->m_server->nick()) {
199 channel = new IRCChannel(channelName); 200 channel = new IRCChannel(channelName);
200 m_session->addChannel(channel); 201 m_session->addChannel(channel);
201 } else { 202 } else {
202 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); 203 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?")));
203 } 204 }
204 } else { 205 } else {
205 /* Someone else joined */ 206 /* Someone else joined */
206 if (mask.nick() != m_session->m_server->nick()) { 207 if (mask.nick() != m_session->m_server->nick()) {
207 if (!channel->getPerson(mask.nick())) { 208 if (!channel->getPerson(mask.nick())) {
208 IRCPerson *person = m_session->getPerson(mask.nick()); 209 IRCPerson *person = m_session->getPerson(mask.nick());
209 if (!person) { 210 if (!person) {
210 person = new IRCPerson(message->prefix()); 211 person = new IRCPerson(message->prefix());
211 m_session->addPerson(person); 212 m_session->addPerson(person);
212 } 213 }
213 IRCChannelPerson *chanperson = new IRCChannelPerson(person); 214 IRCChannelPerson *chanperson = new IRCChannelPerson(person);
214 channel->addPerson(chanperson); 215 channel->addPerson(chanperson);
215 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); 216 IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName ));
216 output.addParam(channel); 217 output.addParam(channel);
217 output.addParam(chanperson); 218 output.addParam(chanperson);
218 emit outputReady(output); 219 emit outputReady(output);
219 } else { 220 } else {
220 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); 221 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?")));
221 } 222 }
222 } else { 223 } else {
223 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); 224 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?")));
224 } 225 }
225 } 226 }
226} 227}
227 228
228void IRCMessageParser::parseLiteralPart(IRCMessage *message) { 229void IRCMessageParser::parseLiteralPart(IRCMessage *message) {
229 QString channelName = message->param(0).lower(); 230 QString channelName = message->param(0).lower();
230 IRCChannel *channel = m_session->getChannel(channelName); 231 IRCChannel *channel = m_session->getChannel(channelName);
231 IRCPerson mask(message->prefix()); 232 IRCPerson mask(message->prefix());
232 if (channel) { 233 if (channel) {
233 if (mask.nick() == m_session->m_server->nick()) { 234 if (mask.nick() == m_session->m_server->nick()) {
234 m_session->removeChannel(channel); 235 m_session->removeChannel(channel);
235 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); 236 IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName ));
236 output.addParam(channel); 237 output.addParam(channel);
237 emit outputReady(output); 238 emit outputReady(output);
238 delete channel; 239 delete channel;
239 } else { 240 } else {
240 IRCChannelPerson *person = channel->getPerson(mask.nick()); 241 IRCChannelPerson *person = channel->getPerson(mask.nick());
241 if (person) { 242 if (person) {
242 channel->removePerson(person); 243 channel->removePerson(person);
243 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) ); 244 IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) );
244 output.addParam(channel); 245 output.addParam(channel);
245 output.addParam(person); 246 output.addParam(person);
246 emit outputReady(output); 247 emit outputReady(output);
247 delete person; 248 delete person;
248 } else { 249 } else {
249 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); 250 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?")));
250 } 251 }
251 } 252 }
252 } else { 253 } else {
253 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); 254 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?")));
254 } 255 }
255} 256}
256 257
257void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { 258void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) {
258 if (m_session->m_server->nick().lower() == message->param(0).lower() ) { 259 if (m_session->m_server->nick().lower() == message->param(0).lower() ) {
259 /* IRC Query message detected, verify sender and display it */ 260 /* IRC Query message detected, verify sender and display it */
260 IRCPerson mask(message->prefix()); 261 IRCPerson mask(message->prefix());
261 IRCPerson *person = m_session->getPerson(mask.nick()); 262 IRCPerson *person = m_session->getPerson(mask.nick());
262 if (!person) { 263 if (!person) {
263 /* Person not yet known, create and add to the current session */ 264 /* Person not yet known, create and add to the current session */
264 person = new IRCPerson(message->prefix()); 265 person = new IRCPerson(message->prefix());
265 m_session->addPerson(person); 266 m_session->addPerson(person);
266 } 267 }
267 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); 268 IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1));
268 output.addParam(person); 269 output.addParam(person);
269 emit outputReady(output); 270 emit outputReady(output);
270 } 271 }
271 else 272 else
272 if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { 273 if (IRCChannel::isValid(message->param(0))) {
273 /* IRC Channel message detected, verify sender, channel and display it */ 274 /* IRC Channel message detected, verify sender, channel and display it */
274 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 275 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
275 if (channel) { 276 if (channel) {
276 IRCPerson mask(message->prefix()); 277 IRCPerson mask(message->prefix());
277 IRCChannelPerson *person = channel->getPerson(mask.nick()); 278 IRCChannelPerson *person = channel->getPerson(mask.nick());
278 if (person) { 279 if (person) {
279 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); 280 IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1));
280 output.addParam(channel); 281 output.addParam(channel);
281 output.addParam(person); 282 output.addParam(person);
282 emit outputReady(output); 283 emit outputReady(output);
283 } 284 }
284 else { 285 else {
285 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); 286 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender")));
286 } 287 }
287 } 288 }
288 else { 289 else {
289 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); 290 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) ));
290 } 291 }
291 } 292 }
292 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); 293 else {emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type")));
293 } 294 }
294} 295}
295 296
296void IRCMessageParser::parseLiteralNick(IRCMessage *message) { 297void IRCMessageParser::parseLiteralNick(IRCMessage *message) {
297 IRCPerson mask(message->prefix()); 298 IRCPerson mask(message->prefix());
298 m_session->updateNickname(mask.nick(), message->param(0)); 299 m_session->updateNickname(mask.nick(), message->param(0));
299 /* this way of handling nick changes really sucks 300 /* this way of handling nick changes really sucks
300 if (mask.nick() == m_session->m_server->nick()) { 301 if (mask.nick() == m_session->m_server->nick()) {
301 We are changing our nickname 302 We are changing our nickname
302 m_session->m_server->setNick(message->param(0)); 303 m_session->m_server->setNick(message->param(0));
303 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); 304 IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0)));
304 output.addParam(0); 305 output.addParam(0);
305 emit outputReady(output); 306 emit outputReady(output);
306 } else { 307 } else {
307 Someone else is 308 Someone else is
308 RCPerson *person = m_session->getPerson(mask.nick()); 309 RCPerson *person = m_session->getPerson(mask.nick());
309 if (person) { 310 if (person) {
310 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 311 //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
311 312
312 new code starts here -- this removes the person from all channels 313 new code starts here -- this removes the person from all channels
313 QList<IRCChannel> channels; 314 QList<IRCChannel> channels;
314 m_session->getChannelsByPerson(person, channels); 315 m_session->getChannelsByPerson(person, channels);
315 QListIterator<IRCChannel> it(channels); 316 QListIterator<IRCChannel> it(channels);
316 for (;it.current(); ++it) { 317 for (;it.current(); ++it) {
317 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 318 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
318 it.current()->removePerson(chanperson); 319 it.current()->removePerson(chanperson);
319 chanperson->person->setNick(message->param(0)); 320 chanperson->person->setNick(message->param(0));
320 it.current()->addPerson(chanperson); 321 it.current()->addPerson(chanperson);
321 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); 322 IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0)));
322 output.addParam(person); 323 output.addParam(person);
323 emit outputReady(output); 324 emit outputReady(output);
324 } 325 }
325 new code ends here 326 new code ends here
326 } else { 327 } else {
327 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); 328 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person")));
328 } 329 }
329 }*/ 330 }*/
330} 331}
331 332
332void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { 333void IRCMessageParser::parseLiteralQuit(IRCMessage *message) {
333 IRCPerson mask(message->prefix()); 334 IRCPerson mask(message->prefix());
334 IRCPerson *person = m_session->getPerson(mask.nick()); 335 IRCPerson *person = m_session->getPerson(mask.nick());
335 if (person) { 336 if (person) {
336 QList<IRCChannel> channels; 337 QList<IRCChannel> channels;
337 m_session->getChannelsByPerson(person, channels); 338 m_session->getChannelsByPerson(person, channels);
338 QListIterator<IRCChannel> it(channels); 339 QListIterator<IRCChannel> it(channels);
339 for (;it.current(); ++it) { 340 for (;it.current(); ++it) {
340 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); 341 IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick());
341 it.current()->removePerson(chanperson); 342 it.current()->removePerson(chanperson);
342 delete chanperson; 343 delete chanperson;
343 } 344 }
344 m_session->removePerson(person); 345 m_session->removePerson(person);
345 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); 346 IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) ));
346 output.addParam(person); 347 output.addParam(person);
347 emit outputReady(output); 348 emit outputReady(output);
348 delete person; 349 delete person;
349 } else { 350 } else {
350 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); 351 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?")));
351 } 352 }
352} 353}
353 354
354void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { 355void IRCMessageParser::parseLiteralTopic(IRCMessage *message) {
355 IRCPerson mask(message->prefix()); 356 IRCPerson mask(message->prefix());
356 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 357 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
357 if (channel) { 358 if (channel) {
358 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); 359 IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\"");
359 output.addParam(channel); 360 output.addParam(channel);
360 emit outputReady(output); 361 emit outputReady(output);
361 } else { 362 } else {
362 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); 363 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?")));
363 } 364 }
364} 365}
365 366
366void IRCMessageParser::parseLiteralError(IRCMessage *message) { 367void IRCMessageParser::parseLiteralError(IRCMessage *message) {
367 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); 368 emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters()));
368} 369}
369 370
370void IRCMessageParser::parseCTCPPing(IRCMessage *message) { 371void IRCMessageParser::parseCTCPPing(IRCMessage *message) {
371 IRCPerson mask(message->prefix()); 372 IRCPerson mask(message->prefix());
372 if(message->isCTCPReply()) { 373 if(message->isCTCPReply()) {
373 unsigned int sentTime = message->param(0).toUInt(); 374 unsigned int sentTime = message->param(0).toUInt();
374 QDateTime tm; 375 QDateTime tm;
375 tm.setTime_t(0); 376 tm.setTime_t(0);
376 unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime()); 377 unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime());
377 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING reply from %1: %2 seconds").arg(mask.nick()).arg(receivedTime-sentTime))); 378 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING reply from %1: %2 seconds").arg(mask.nick()).arg(receivedTime-sentTime)));
378 return; 379 return;
379 } 380 }
380 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters()); 381 m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters());
381 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING request from %1").arg(mask.nick()))); 382 emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING request from %1").arg(mask.nick())));
382 383
383 //IRCPerson mask(message->prefix()); 384 //IRCPerson mask(message->prefix());
384 QString dest = message->ctcpDestination(); 385 QString dest = message->ctcpDestination();
385 if (dest.startsWith("#")) { 386 if (dest.startsWith("#")) {
386 IRCChannel *channel = m_session->getChannel(dest.lower()); 387 IRCChannel *channel = m_session->getChannel(dest.lower());
387 if (channel) { 388 if (channel) {
388 IRCChannelPerson *person = channel->getPerson(mask.nick()); 389 IRCChannelPerson *person = channel->getPerson(mask.nick());
389 if (person) { 390 if (person) {
390 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; 391 IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ;
391 output.addParam(channel); 392 output.addParam(channel);
392 output.addParam(person); 393 output.addParam(person);
393 emit outputReady(output); 394 emit outputReady(output);
394 } else { 395 } else {
395 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); 396 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?")));
396 } 397 }
397 } else { 398 } else {
398 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?"))); 399 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?")));
399 } 400 }
400 } else { 401 } else {
401 if (message->ctcpDestination() == m_session->m_server->nick()) { 402 if (message->ctcpDestination() == m_session->m_server->nick()) {
402 IRCPerson *person = m_session->getPerson(mask.nick()); 403 IRCPerson *person = m_session->getPerson(mask.nick());
403 if (!person) { 404 if (!person) {
404 /* Person not yet known, create and add to the current session */ 405 /* Person not yet known, create and add to the current session */
405 person = new IRCPerson(message->prefix()); 406 person = new IRCPerson(message->prefix());
406 m_session->addPerson(person); 407 m_session->addPerson(person);
407 } 408 }
408 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() ); 409 IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() );
409 output.addParam(person); 410 output.addParam(person);
410 emit outputReady(output); 411 emit outputReady(output);
411 } else { 412 } else {
412 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); 413 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient")));
413 } 414 }
414 } 415 }
415 416
416} 417}
417 418
418void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { 419void IRCMessageParser::parseCTCPVersion(IRCMessage *message) {
419 IRCPerson mask(message->prefix()); 420 IRCPerson mask(message->prefix());
420 IRCOutput output(OUTPUT_CTCP); 421 IRCOutput output(OUTPUT_CTCP);
421 if(message->isCTCPRequest()) { 422 if(message->isCTCPRequest()) {
422 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR); 423 m_session->m_connection->sendCTCPReply(mask.nick(), "VERSION", APP_VERSION " " APP_COPYSTR);
423 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); 424 output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick());
424 } 425 }
425 426
426 else { 427 else {
427 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0)); 428 output.setMessage("Received CTCP VERSION reply from " + mask.nick() + ":" + message->param(0));
428 } 429 }
429 emit outputReady(output); 430 emit outputReady(output);
430} 431}
431 432
432void IRCMessageParser::parseCTCPAction(IRCMessage *message) { 433void IRCMessageParser::parseCTCPAction(IRCMessage *message) {
433 IRCPerson mask(message->prefix()); 434 IRCPerson mask(message->prefix());
434 QString dest = message->ctcpDestination(); 435 QString dest = message->ctcpDestination();
435 if (dest.startsWith("#")) { 436 if (dest.startsWith("#")) {
436 IRCChannel *channel = m_session->getChannel(dest.lower()); 437 IRCChannel *channel = m_session->getChannel(dest.lower());
437 if (channel) { 438 if (channel) {
438 IRCChannelPerson *person = channel->getPerson(mask.nick()); 439 IRCChannelPerson *person = channel->getPerson(mask.nick());
439 if (person) { 440 if (person) {
440 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); 441 IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0));
441 output.addParam(channel); 442 output.addParam(channel);
442 output.addParam(person); 443 output.addParam(person);
443 emit outputReady(output); 444 emit outputReady(output);
444 } else { 445 } else {
445 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); 446 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?")));
446 } 447 }
447 } else { 448 } else {
448 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); 449 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?")));
449 } 450 }
450 } else { 451 } else {
451 if (message->ctcpDestination() == m_session->m_server->nick()) { 452 if (message->ctcpDestination() == m_session->m_server->nick()) {
452 IRCPerson *person = m_session->getPerson(mask.nick()); 453 IRCPerson *person = m_session->getPerson(mask.nick());
453 if (!person) { 454 if (!person) {
454 /* Person not yet known, create and add to the current session */ 455 /* Person not yet known, create and add to the current session */
455 person = new IRCPerson(message->prefix()); 456 person = new IRCPerson(message->prefix());
456 m_session->addPerson(person); 457 m_session->addPerson(person);
457 } 458 }
458 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); 459 IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0));
459 output.addParam(person); 460 output.addParam(person);
460 emit outputReady(output); 461 emit outputReady(output);
461 } else { 462 } else {
462 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); 463 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient")));
463 } 464 }
464 } 465 }
465} 466}
466 467
467void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { 468void IRCMessageParser::parseCTCPDCC(IRCMessage *message) {
468 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); 469 QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace());
469 470
470 if(params[0] == "SEND") { 471 if(params[0] == "SEND") {
471 QString nickname = IRCPerson(message->prefix()).nick(); 472 QString nickname = IRCPerson(message->prefix()).nick();
472 if( params.count() != 5) { 473 if( params.count() != 5) {
473 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname))); 474 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Malformed DCC request from %1").arg(nickname)));
474 return; 475 return;
475 } 476 }
476 bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt()); 477 bool accepted = DCCTransferTab::confirm(static_cast<QWidget*>(m_session->parent()), nickname, params[1], params[4].toUInt());
477 if(!accepted) 478 if(!accepted)
478 return; 479 return;
479 QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL, 480 QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL,
480 QString::null, params[1], MimeTypes(), 0, tr("Save As")); 481 QString::null, params[1], MimeTypes(), 0, tr("Save As"));
481 if(filename.isEmpty()) 482 if(filename.isEmpty())
482 return; 483 return;
483 484
484 odebug << "Receiving file " << filename << " from " << nickname << oendl; 485 odebug << "Receiving file " << filename << " from " << nickname << oendl;
485 static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(), 486 static_cast<IRCServerTab*>(m_session->parent())->mainwindow()->addDCC(DCCTransfer::Recv, params[2].toUInt(), params[3].toUInt(),
486 filename, nickname, params[4].toUInt()); 487 filename, nickname, params[4].toUInt());
487 } 488 }
488} 489}
489 490
490void IRCMessageParser::parseLiteralMode(IRCMessage *message) { 491void IRCMessageParser::parseLiteralMode(IRCMessage *message) {
491 IRCPerson mask(message->prefix()); 492 IRCPerson mask(message->prefix());
492 493
493 if (message->param(0).startsWith("#")) { 494 if (IRCChannel::isValid(message->param(0))) {
494 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 495 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
495 if (channel) { 496 if (channel) {
496 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); 497 QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1);
497 QTextIStream stream(&parameters); 498 QTextIStream stream(&parameters);
498 bool set = FALSE; 499 bool set = FALSE;
499 while (!stream.atEnd()) { 500 while (!stream.atEnd()) {
500 stream >> temp; 501 stream >> temp;
501 if (temp.startsWith("+")) { 502 if (temp.startsWith("+")) {
502 set = TRUE; 503 set = TRUE;
503 temp = temp.right(1); 504 temp = temp.right(1);
504 } 505 }
505 else 506 else
506 if (temp.startsWith("-")) { 507 if (temp.startsWith("-")) {
507 set = FALSE; 508 set = FALSE;
508 temp = temp.right(1); 509 temp = temp.right(1);
509 } 510 }
510 else { 511 else {
511 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); 512 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type")));
512 return; 513 return;
513 } 514 }
514 if (temp == "o") { 515 if (temp == "o") {
515 stream >> temp; 516 stream >> temp;
516 IRCChannelPerson *person = channel->getPerson(temp); 517 IRCChannelPerson *person = channel->getPerson(temp);
517 if (person) { 518 if (person) {
518 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); 519 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set));
519 output.addParam(channel); 520 output.addParam(channel);
520 output.addParam(person); 521 output.addParam(person);
521 emit outputReady(output); 522 emit outputReady(output);
522 } 523 }
523 else { 524 else {
524 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 525 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
525 } 526 }
526 } 527 }
527 else 528 else
528 if (temp == "v") { 529 if (temp == "v") {
529 stream >> temp; 530 stream >> temp;
530 IRCChannelPerson *person = channel->getPerson(temp); 531 IRCChannelPerson *person = channel->getPerson(temp);
531 if (person) { 532 if (person) {
532 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); 533 IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set));
533 output.addParam(channel); 534 output.addParam(channel);
534 output.addParam(person); 535 output.addParam(person);
535 emit outputReady(output); 536 emit outputReady(output);
536 } 537 }
537 else { 538 else {
538 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); 539 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?")));
539 } 540 }
540 } 541 }
541 else { 542 else {
542 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); 543 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag")));
543 } 544 }
544 } 545 }
545 } else { 546 } else {
546 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); 547 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?")));
547 } 548 }
548 } else { 549 } else {
549 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); 550 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet")));
550 } 551 }
551} 552}
552 553
553void IRCMessageParser::parseLiteralKick(IRCMessage *message) { 554void IRCMessageParser::parseLiteralKick(IRCMessage *message) {
554 IRCPerson mask(message->prefix()); 555 IRCPerson mask(message->prefix());
555 IRCChannel *channel = m_session->getChannel(message->param(0).lower()); 556 IRCChannel *channel = m_session->getChannel(message->param(0).lower());
556 if (channel) { 557 if (channel) {
557 IRCChannelPerson *person = channel->getPerson(message->param(1)); 558 IRCChannelPerson *person = channel->getPerson(message->param(1));
558 if (person) { 559 if (person) {
559 if (person->nick() == m_session->m_server->nick()) { 560 if (person->nick() == m_session->m_server->nick()) {
560 m_session->removeChannel(channel); 561 m_session->removeChannel(channel);
561 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); 562 IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")");
562 output.addParam(channel); 563 output.addParam(channel);
563 emit outputReady(output); 564 emit outputReady(output);
564 } else { 565 } else {
565 /* someone else got kicked */ 566 /* someone else got kicked */
566 channel->removePerson(person); 567 channel->removePerson(person);
567 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); 568 IRCOutput output(OUTPUT_OTHERKICK, person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")");
568 output.addParam(channel); 569 output.addParam(channel);
569 output.addParam(person); 570 output.addParam(person);
570 emit outputReady(output); 571 emit outputReady(output);
571 } 572 }
572 } else { 573 } else {
573 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); 574 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?")));
574 } 575 }
575 } else { 576 } else {
576 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); 577 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?")));
577 } 578 }
578} 579}
579 580
580void IRCMessageParser::parseNumericalNames(IRCMessage *message) { 581void IRCMessageParser::parseNumericalNames(IRCMessage *message) {
581 /* Name list sent when joining a channel */ 582 /* Name list sent when joining a channel */
582 IRCChannel *channel = m_session->getChannel(message->param(2).lower()); 583 IRCChannel *channel = m_session->getChannel(message->param(2).lower());
583 if (channel != 0) { 584 if (channel != 0) {
584 QString people = message->param(3); 585 QString people = message->param(3);
585 QTextIStream stream(&people); 586 QTextIStream stream(&people);
586 QString temp; 587 QString temp;
587 588
588 while (!stream.atEnd()) { 589 while (!stream.atEnd()) {
589 stream >> temp; 590 stream >> temp;
590 591
591 char flagch = temp.at(0).latin1(); 592 char flagch = temp.at(0).latin1();
592 int flag = 0; 593 int flag = 0;
593 QString nick; 594 QString nick;
594 /* Parse person flags */ 595 /* Parse person flags */
595 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { 596 if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') {
596 597
597 nick = temp.right(temp.length()-1); 598 nick = temp.right(temp.length()-1);
598 switch (flagch) { 599 switch (flagch) {
599 case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break; 600 case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break;
600 case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break; 601 case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break;
601 case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break; 602 case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break;
602 default : flag = 0; break; 603 default : flag = 0; break;
603 } 604 }
604 } else { 605 } else {
605 nick = temp; 606 nick = temp;
606 } 607 }
607 608
608 IRCPerson *person = m_session->getPerson(nick); 609 IRCPerson *person = m_session->getPerson(nick);
609 if (person == 0) { 610 if (person == 0) {
610 person = new IRCPerson(); 611 person = new IRCPerson();
611 person->setNick(nick); 612 person->setNick(nick);
612 m_session->addPerson(person); 613 m_session->addPerson(person);
613 } 614 }
614 IRCChannelPerson *chan_person = new IRCChannelPerson(person); 615 IRCChannelPerson *chan_person = new IRCChannelPerson(person);
615 chan_person->setFlags(flag); 616 chan_person->setFlags(flag);
616 channel->addPerson(chan_person); 617 channel->addPerson(chan_person);
617 } 618 }
618 } else { 619 } else {
619 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 620 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
620 } 621 }
621} 622}
622 623
623void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { 624void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) {
624 /* Done syncing to channel */ 625 /* Done syncing to channel */
625 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 626 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
626 if (channel) { 627 if (channel) {
627 channel->setHasPeople(TRUE); 628 channel->setHasPeople(TRUE);
628 /* Yes, we want the names before anything happens inside the GUI */ 629 /* Yes, we want the names before anything happens inside the GUI */
629 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); 630 IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname());
630 output.addParam(channel); 631 output.addParam(channel);
631 emit outputReady(output); 632 emit outputReady(output);
632 } else { 633 } else {
633 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); 634 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel")));
634 } 635 }
635} 636}
636 637
637 638
638void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { 639void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) {
639 /* If we are connnected this error is not critical */ 640 /* If we are connnected this error is not critical */
640 if(m_session->isLoggedIn()) 641 if(m_session->isLoggedIn())
641 return; 642 return;
642 643
643 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); 644 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname")));
644 m_session->endSession(); 645 m_session->endSession();
645} 646}
646 647
647void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { 648void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) {
648 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); 649 emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname")));
649} 650}
650 651
651void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { 652void IRCMessageParser::parseNumericalTopic(IRCMessage *message) {
652 IRCChannel *channel = m_session->getChannel(message->param(1).lower()); 653 IRCChannel *channel = m_session->getChannel(message->param(1).lower());
653 if (channel) { 654 if (channel) {
654 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); 655 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\""));
655 output.addParam(channel); 656 output.addParam(channel);
656 emit outputReady(output); 657 emit outputReady(output);
657 } else { 658 } else {
658 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); 659 IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\""));
659 output.addParam(0); 660 output.addParam(0);
660 emit outputReady(output); 661 emit outputReady(output);
661 } 662 }
662} 663}
663 664
664void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { 665void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) {
665} 666}
666 667
667 668