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