author | erik <erik> | 2007-02-09 21:10:30 (UTC) |
---|---|---|
committer | erik <erik> | 2007-02-09 21:10:30 (UTC) |
commit | 9abe862308081155837512dd5e6c581752c9ddb2 (patch) (unidiff) | |
tree | 0ba021365dab067f9783bdcf2fbc01d910c6802b | |
parent | b3cde0d17f52f996c04a55de90583ca60a7e0210 (diff) | |
download | opie-9abe862308081155837512dd5e6c581752c9ddb2.zip opie-9abe862308081155837512dd5e6c581752c9ddb2.tar.gz opie-9abe862308081155837512dd5e6c581752c9ddb2.tar.bz2 |
This commit is based on the patch attached to Opie bug 1735:
http://opie-bugs.oszine.de/view.php?id=1735
It changes the opie-irc app to be able to support the additional user
characters that the unrealircd irc daemon provides.
Thanks goes to andrewy for reporting and providing a patch.
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index 32e1011..c449a65 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp | |||
@@ -1,668 +1,683 @@ | |||
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 */ |
15 | IRCLiteralMessageParserStruct IRCMessageParser::literalParserProcTable[] = { | 15 | IRCLiteralMessageParserStruct 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 */ |
32 | IRCCTCPMessageParserStruct IRCMessageParser::ctcpParserProcTable[] = { | 32 | IRCCTCPMessageParserStruct 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 | ||
46 | IRCNumericalMessageParserStruct IRCMessageParser::numericalParserProcTable[] = { | 46 | IRCNumericalMessageParserStruct 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 | { 403, QT_TR_NOOP("Channel %1 doesn't exists"), "1", 0 }, // ERR_ERR_NOSUCHCHANNEL |
80 | { 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 |
81 | { 409, "%1", "1", 0 }, // ERR_NOORIGIN | 81 | { 409, "%1", "1", 0 }, // ERR_NOORIGIN |
82 | { 411, "%1", "1", 0 }, // ERR_NORECIPIENT | 82 | { 411, "%1", "1", 0 }, // ERR_NORECIPIENT |
83 | { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND | 83 | { 412, "%1", "1", 0 }, // ERR_NOTEXTTOSEND |
84 | { 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 |
85 | { 422, "%1", "1", 0 }, // ERR_NOMOTD | 85 | { 422, "%1", "1", 0 }, // ERR_NOMOTD |
86 | { 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 |
87 | { 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 |
88 | { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK | 88 | { 477, "%1", "1", 0 }, // ERR_NOCHANMODES || ERR_NEEDREGGEDNICK |
89 | { 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 |
90 | { 0, 0, 0, 0 } | 90 | { 0, 0, 0, 0 } |
91 | }; | 91 | }; |
92 | 92 | ||
93 | 93 | ||
94 | IRCMessageParser::IRCMessageParser(IRCSession *session) { | 94 | IRCMessageParser::IRCMessageParser(IRCSession *session) { |
95 | m_session = session; | 95 | m_session = session; |
96 | } | 96 | } |
97 | 97 | ||
98 | void IRCMessageParser::parse(IRCMessage *message) { | 98 | void IRCMessageParser::parse(IRCMessage *message) { |
99 | /* 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 |
100 | 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 */ |
101 | if (message->isNumerical()) { | 101 | if (message->isNumerical()) { |
102 | for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { | 102 | for (int i=0; i<numericalParserProcTable[i].commandNumber; i++) { |
103 | if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { | 103 | if (message->commandNumber() == numericalParserProcTable[i].commandNumber) { |
104 | parseNumerical(message, i); | 104 | parseNumerical(message, i); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | 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()) ))); |
109 | } else if (message->isCTCP()) { | 109 | } else if (message->isCTCP()) { |
110 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { | 110 | for (int i=0; ctcpParserProcTable[i].commandName; i++) { |
111 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { | 111 | if (message->ctcpCommand() == ctcpParserProcTable[i].commandName) { |
112 | parseCTCP(message, i); | 112 | parseCTCP(message, i); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 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())) ); |
117 | } else { | 117 | } else { |
118 | for (int i=0; literalParserProcTable[i].commandName; i++) { | 118 | for (int i=0; literalParserProcTable[i].commandName; i++) { |
119 | if (message->command() == literalParserProcTable[i].commandName) { | 119 | if (message->command() == literalParserProcTable[i].commandName) { |
120 | (this->*(literalParserProcTable[i].proc))(message); | 120 | (this->*(literalParserProcTable[i].proc))(message); |
121 | return; | 121 | return; |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 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()) )); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { | 128 | void IRCMessageParser::parseNumerical(IRCMessage *message, int position) { |
129 | QString out = tr(numericalParserProcTable[position].message); | 129 | QString out = tr(numericalParserProcTable[position].message); |
130 | QString paramString = numericalParserProcTable[position].params; | 130 | QString paramString = numericalParserProcTable[position].params; |
131 | 131 | ||
132 | if(!out.isEmpty() && !paramString.isEmpty()) { | 132 | if(!out.isEmpty() && !paramString.isEmpty()) { |
133 | QStringList params = message->params(numericalParserProcTable[position].params); | 133 | QStringList params = message->params(numericalParserProcTable[position].params); |
134 | 134 | ||
135 | QStringList::Iterator end = params.end(); | 135 | QStringList::Iterator end = params.end(); |
136 | for (QStringList::Iterator it = params.begin(); it != end; ++it) { | 136 | for (QStringList::Iterator it = params.begin(); it != end; ++it) { |
137 | out = out.arg(*it); | 137 | out = out.arg(*it); |
138 | } | 138 | } |
139 | 139 | ||
140 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); | 140 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); |
141 | } | 141 | } |
142 | 142 | ||
143 | if(numericalParserProcTable[position].proc) | 143 | if(numericalParserProcTable[position].proc) |
144 | (this->*(numericalParserProcTable[position].proc))(message); | 144 | (this->*(numericalParserProcTable[position].proc))(message); |
145 | } | 145 | } |
146 | 146 | ||
147 | void IRCMessageParser::parseCTCP(IRCMessage *message, int position) { | 147 | void IRCMessageParser::parseCTCP(IRCMessage *message, int position) { |
148 | if(ctcpParserProcTable[position].proc) | 148 | if(ctcpParserProcTable[position].proc) |
149 | (this->*(ctcpParserProcTable[position].proc))(message); | 149 | (this->*(ctcpParserProcTable[position].proc))(message); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | 153 | ||
154 | void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { | 154 | void IRCMessageParser::parseNumericalServerName(IRCMessage *message) { |
155 | 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>")); |
156 | /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password | 156 | /* Register EFFECTIVE nickname, some networks (as irc-hispano) use nick:password |
157 | * for authentication and the parser gets confused */ | 157 | * for authentication and the parser gets confused */ |
158 | m_session->m_server->setNick(message->param(0)); | 158 | m_session->m_server->setNick(message->param(0)); |
159 | 159 | ||
160 | } | 160 | } |
161 | 161 | ||
162 | void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { | 162 | void IRCMessageParser::parseNumericalServerFeatures(IRCMessage *message) { |
163 | m_session->setValidUsermodes(message->param(2)); | 163 | m_session->setValidUsermodes(message->param(2)); |
164 | m_session->setValidChannelmodes(message->param(3)); | 164 | m_session->setValidChannelmodes(message->param(3)); |
165 | 165 | ||
166 | } | 166 | } |
167 | 167 | ||
168 | void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { | 168 | void IRCMessageParser::parseNumericalServerProtocol(IRCMessage *message) { |
169 | /* XXX: Add some usefull features here */ | 169 | /* XXX: Add some usefull features here */ |
170 | QString out = message->allParameters(); | 170 | QString out = message->allParameters(); |
171 | out = out.mid(out.find(' ')+1); | 171 | out = out.mid(out.find(' ')+1); |
172 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); | 172 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, out)); |
173 | } | 173 | } |
174 | void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { | 174 | void IRCMessageParser::parseNumericalWhoisIdle(IRCMessage *message) { |
175 | QDateTime dt; | 175 | QDateTime dt; |
176 | QTime t; | 176 | QTime t; |
177 | t = t.addSecs(message->param(2).toInt()); | 177 | t = t.addSecs(message->param(2).toInt()); |
178 | dt.setTime_t(message->param(3).toInt()); | 178 | dt.setTime_t(message->param(3).toInt()); |
179 | 179 | ||
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 has been idle for %2").arg(message->param(1)).arg(t.toString()))); |
181 | 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()))); |
182 | 182 | ||
183 | } | 183 | } |
184 | 184 | ||
185 | void IRCMessageParser::parseLiteralPing(IRCMessage *message) { | 185 | void IRCMessageParser::parseLiteralPing(IRCMessage *message) { |
186 | m_session->m_connection->sendLine("PONG " + message->allParameters()); | 186 | m_session->m_connection->sendLine("PONG " + message->allParameters()); |
187 | } | 187 | } |
188 | 188 | ||
189 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { | 189 | void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { |
190 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); | 190 | emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); |
191 | } | 191 | } |
192 | 192 | ||
193 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { | 193 | void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { |
194 | QString channelName = message->param(0).lower(); | 194 | QString channelName = message->param(0).lower(); |
195 | IRCPerson mask(message->prefix()); | 195 | IRCPerson mask(message->prefix()); |
196 | IRCChannel *channel = m_session->getChannel(channelName); | 196 | IRCChannel *channel = m_session->getChannel(channelName); |
197 | if (!channel) { | 197 | if (!channel) { |
198 | /* We joined */ | 198 | /* We joined */ |
199 | if (mask.nick() == m_session->m_server->nick()) { | 199 | if (mask.nick() == m_session->m_server->nick()) { |
200 | channel = new IRCChannel(channelName); | 200 | channel = new IRCChannel(channelName); |
201 | m_session->addChannel(channel); | 201 | m_session->addChannel(channel); |
202 | } else { | 202 | } else { |
203 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); | 203 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); |
204 | } | 204 | } |
205 | } else { | 205 | } else { |
206 | /* Someone else joined */ | 206 | /* Someone else joined */ |
207 | if (mask.nick() != m_session->m_server->nick()) { | 207 | if (mask.nick() != m_session->m_server->nick()) { |
208 | if (!channel->getPerson(mask.nick())) { | 208 | if (!channel->getPerson(mask.nick())) { |
209 | IRCPerson *person = m_session->getPerson(mask.nick()); | 209 | IRCPerson *person = m_session->getPerson(mask.nick()); |
210 | if (!person) { | 210 | if (!person) { |
211 | person = new IRCPerson(message->prefix()); | 211 | person = new IRCPerson(message->prefix()); |
212 | m_session->addPerson(person); | 212 | m_session->addPerson(person); |
213 | } | 213 | } |
214 | IRCChannelPerson *chanperson = new IRCChannelPerson(person); | 214 | IRCChannelPerson *chanperson = new IRCChannelPerson(person); |
215 | channel->addPerson(chanperson); | 215 | channel->addPerson(chanperson); |
216 | 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 )); |
217 | output.addParam(channel); | 217 | output.addParam(channel); |
218 | output.addParam(chanperson); | 218 | output.addParam(chanperson); |
219 | emit outputReady(output); | 219 | emit outputReady(output); |
220 | } else { | 220 | } else { |
221 | 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?"))); |
222 | } | 222 | } |
223 | } else { | 223 | } else { |
224 | 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?"))); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | void IRCMessageParser::parseLiteralPart(IRCMessage *message) { | 229 | void IRCMessageParser::parseLiteralPart(IRCMessage *message) { |
230 | QString channelName = message->param(0).lower(); | 230 | QString channelName = message->param(0).lower(); |
231 | IRCChannel *channel = m_session->getChannel(channelName); | 231 | IRCChannel *channel = m_session->getChannel(channelName); |
232 | IRCPerson mask(message->prefix()); | 232 | IRCPerson mask(message->prefix()); |
233 | if (channel) { | 233 | if (channel) { |
234 | if (mask.nick() == m_session->m_server->nick()) { | 234 | if (mask.nick() == m_session->m_server->nick()) { |
235 | m_session->removeChannel(channel); | 235 | m_session->removeChannel(channel); |
236 | IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); | 236 | IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); |
237 | output.addParam(channel); | 237 | output.addParam(channel); |
238 | emit outputReady(output); | 238 | emit outputReady(output); |
239 | delete channel; | 239 | delete channel; |
240 | } else { | 240 | } else { |
241 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 241 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
242 | if (person) { | 242 | if (person) { |
243 | channel->removePerson(person); | 243 | channel->removePerson(person); |
244 | 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) ); |
245 | output.addParam(channel); | 245 | output.addParam(channel); |
246 | output.addParam(person); | 246 | output.addParam(person); |
247 | emit outputReady(output); | 247 | emit outputReady(output); |
248 | delete person; | 248 | delete person; |
249 | } else { | 249 | } else { |
250 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); | 250 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | } else { | 253 | } else { |
254 | 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?"))); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { | 258 | void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { |
259 | if (m_session->m_server->nick().lower() == message->param(0).lower() ) { | 259 | if (m_session->m_server->nick().lower() == message->param(0).lower() ) { |
260 | /* IRC Query message detected, verify sender and display it */ | 260 | /* IRC Query message detected, verify sender and display it */ |
261 | IRCPerson mask(message->prefix()); | 261 | IRCPerson mask(message->prefix()); |
262 | IRCPerson *person = m_session->getPerson(mask.nick()); | 262 | IRCPerson *person = m_session->getPerson(mask.nick()); |
263 | if (!person) { | 263 | if (!person) { |
264 | /* Person not yet known, create and add to the current session */ | 264 | /* Person not yet known, create and add to the current session */ |
265 | person = new IRCPerson(message->prefix()); | 265 | person = new IRCPerson(message->prefix()); |
266 | m_session->addPerson(person); | 266 | m_session->addPerson(person); |
267 | } | 267 | } |
268 | IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); | 268 | IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); |
269 | output.addParam(person); | 269 | output.addParam(person); |
270 | emit outputReady(output); | 270 | emit outputReady(output); |
271 | } | 271 | } |
272 | else | 272 | else |
273 | if (IRCChannel::isValid(message->param(0))) { | 273 | if (IRCChannel::isValid(message->param(0))) { |
274 | /* IRC Channel message detected, verify sender, channel and display it */ | 274 | /* IRC Channel message detected, verify sender, channel and display it */ |
275 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); | 275 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); |
276 | if (channel) { | 276 | if (channel) { |
277 | IRCPerson mask(message->prefix()); | 277 | IRCPerson mask(message->prefix()); |
278 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 278 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
279 | if (person) { | 279 | if (person) { |
280 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); | 280 | IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); |
281 | output.addParam(channel); | 281 | output.addParam(channel); |
282 | output.addParam(person); | 282 | output.addParam(person); |
283 | emit outputReady(output); | 283 | emit outputReady(output); |
284 | } | 284 | } |
285 | else { | 285 | else { |
286 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); | 286 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); |
287 | } | 287 | } |
288 | } | 288 | } |
289 | else { | 289 | else { |
290 | 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()) )); |
291 | } | 291 | } |
292 | } | 292 | } |
293 | 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"))); |
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | void IRCMessageParser::parseLiteralNick(IRCMessage *message) { | 297 | void IRCMessageParser::parseLiteralNick(IRCMessage *message) { |
298 | IRCPerson mask(message->prefix()); | 298 | IRCPerson mask(message->prefix()); |
299 | m_session->updateNickname(mask.nick(), message->param(0)); | 299 | m_session->updateNickname(mask.nick(), message->param(0)); |
300 | /* this way of handling nick changes really sucks | 300 | /* this way of handling nick changes really sucks |
301 | if (mask.nick() == m_session->m_server->nick()) { | 301 | if (mask.nick() == m_session->m_server->nick()) { |
302 | We are changing our nickname | 302 | We are changing our nickname |
303 | m_session->m_server->setNick(message->param(0)); | 303 | m_session->m_server->setNick(message->param(0)); |
304 | 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))); |
305 | output.addParam(0); | 305 | output.addParam(0); |
306 | emit outputReady(output); | 306 | emit outputReady(output); |
307 | } else { | 307 | } else { |
308 | Someone else is | 308 | Someone else is |
309 | RCPerson *person = m_session->getPerson(mask.nick()); | 309 | RCPerson *person = m_session->getPerson(mask.nick()); |
310 | if (person) { | 310 | if (person) { |
311 | //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))); |
312 | 312 | ||
313 | new code starts here -- this removes the person from all channels | 313 | new code starts here -- this removes the person from all channels |
314 | QList<IRCChannel> channels; | 314 | QList<IRCChannel> channels; |
315 | m_session->getChannelsByPerson(person, channels); | 315 | m_session->getChannelsByPerson(person, channels); |
316 | QListIterator<IRCChannel> it(channels); | 316 | QListIterator<IRCChannel> it(channels); |
317 | for (;it.current(); ++it) { | 317 | for (;it.current(); ++it) { |
318 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); | 318 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); |
319 | it.current()->removePerson(chanperson); | 319 | it.current()->removePerson(chanperson); |
320 | chanperson->person->setNick(message->param(0)); | 320 | chanperson->person->setNick(message->param(0)); |
321 | it.current()->addPerson(chanperson); | 321 | it.current()->addPerson(chanperson); |
322 | 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))); |
323 | output.addParam(person); | 323 | output.addParam(person); |
324 | emit outputReady(output); | 324 | emit outputReady(output); |
325 | } | 325 | } |
326 | new code ends here | 326 | new code ends here |
327 | } else { | 327 | } else { |
328 | 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"))); |
329 | } | 329 | } |
330 | }*/ | 330 | }*/ |
331 | } | 331 | } |
332 | 332 | ||
333 | void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { | 333 | void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { |
334 | IRCPerson mask(message->prefix()); | 334 | IRCPerson mask(message->prefix()); |
335 | IRCPerson *person = m_session->getPerson(mask.nick()); | 335 | IRCPerson *person = m_session->getPerson(mask.nick()); |
336 | if (person) { | 336 | if (person) { |
337 | QList<IRCChannel> channels; | 337 | QList<IRCChannel> channels; |
338 | m_session->getChannelsByPerson(person, channels); | 338 | m_session->getChannelsByPerson(person, channels); |
339 | QListIterator<IRCChannel> it(channels); | 339 | QListIterator<IRCChannel> it(channels); |
340 | for (;it.current(); ++it) { | 340 | for (;it.current(); ++it) { |
341 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); | 341 | IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); |
342 | it.current()->removePerson(chanperson); | 342 | it.current()->removePerson(chanperson); |
343 | delete chanperson; | 343 | delete chanperson; |
344 | } | 344 | } |
345 | m_session->removePerson(person); | 345 | m_session->removePerson(person); |
346 | 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) )); |
347 | output.addParam(person); | 347 | output.addParam(person); |
348 | emit outputReady(output); | 348 | emit outputReady(output); |
349 | delete person; | 349 | delete person; |
350 | } else { | 350 | } else { |
351 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); | 351 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); |
352 | } | 352 | } |
353 | } | 353 | } |
354 | 354 | ||
355 | void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { | 355 | void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { |
356 | IRCPerson mask(message->prefix()); | 356 | IRCPerson mask(message->prefix()); |
357 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); | 357 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); |
358 | if (channel) { | 358 | if (channel) { |
359 | 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) + "\""); |
360 | output.addParam(channel); | 360 | output.addParam(channel); |
361 | emit outputReady(output); | 361 | emit outputReady(output); |
362 | } else { | 362 | } else { |
363 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); | 363 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); |
364 | } | 364 | } |
365 | } | 365 | } |
366 | 366 | ||
367 | void IRCMessageParser::parseLiteralError(IRCMessage *message) { | 367 | void IRCMessageParser::parseLiteralError(IRCMessage *message) { |
368 | emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); | 368 | emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); |
369 | } | 369 | } |
370 | 370 | ||
371 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { | 371 | void IRCMessageParser::parseCTCPPing(IRCMessage *message) { |
372 | IRCPerson mask(message->prefix()); | 372 | IRCPerson mask(message->prefix()); |
373 | if(message->isCTCPReply()) { | 373 | if(message->isCTCPReply()) { |
374 | unsigned int sentTime = message->param(0).toUInt(); | 374 | unsigned int sentTime = message->param(0).toUInt(); |
375 | QDateTime tm; | 375 | QDateTime tm; |
376 | tm.setTime_t(0); | 376 | tm.setTime_t(0); |
377 | unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime()); | 377 | unsigned int receivedTime = tm.secsTo(QDateTime::currentDateTime()); |
378 | 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))); |
379 | return; | 379 | return; |
380 | } | 380 | } |
381 | m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters()); | 381 | m_session->m_connection->sendCTCPReply(mask.nick(), "PING", message->allParameters()); |
382 | 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()))); |
383 | 383 | ||
384 | //IRCPerson mask(message->prefix()); | 384 | //IRCPerson mask(message->prefix()); |
385 | QString dest = message->ctcpDestination(); | 385 | QString dest = message->ctcpDestination(); |
386 | if (dest.startsWith("#")) { | 386 | if (dest.startsWith("#")) { |
387 | IRCChannel *channel = m_session->getChannel(dest.lower()); | 387 | IRCChannel *channel = m_session->getChannel(dest.lower()); |
388 | if (channel) { | 388 | if (channel) { |
389 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 389 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
390 | if (person) { | 390 | if (person) { |
391 | 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()) ; |
392 | output.addParam(channel); | 392 | output.addParam(channel); |
393 | output.addParam(person); | 393 | output.addParam(person); |
394 | emit outputReady(output); | 394 | emit outputReady(output); |
395 | } else { | 395 | } else { |
396 | 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?"))); |
397 | } | 397 | } |
398 | } else { | 398 | } else { |
399 | 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?"))); |
400 | } | 400 | } |
401 | } else { | 401 | } else { |
402 | if (message->ctcpDestination() == m_session->m_server->nick()) { | 402 | if (message->ctcpDestination() == m_session->m_server->nick()) { |
403 | IRCPerson *person = m_session->getPerson(mask.nick()); | 403 | IRCPerson *person = m_session->getPerson(mask.nick()); |
404 | if (!person) { | 404 | if (!person) { |
405 | /* Person not yet known, create and add to the current session */ | 405 | /* Person not yet known, create and add to the current session */ |
406 | person = new IRCPerson(message->prefix()); | 406 | person = new IRCPerson(message->prefix()); |
407 | m_session->addPerson(person); | 407 | m_session->addPerson(person); |
408 | } | 408 | } |
409 | 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() ); |
410 | output.addParam(person); | 410 | output.addParam(person); |
411 | emit outputReady(output); | 411 | emit outputReady(output); |
412 | } else { | 412 | } else { |
413 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); | 413 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | } | 417 | } |
418 | 418 | ||
419 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { | 419 | void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { |
420 | IRCPerson mask(message->prefix()); | 420 | IRCPerson mask(message->prefix()); |
421 | IRCOutput output(OUTPUT_CTCP); | 421 | IRCOutput output(OUTPUT_CTCP); |
422 | if(message->isCTCPRequest()) { | 422 | if(message->isCTCPRequest()) { |
423 | 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); |
424 | output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); | 424 | output.setMessage(tr("Received a CTCP VERSION request from ") + mask.nick()); |
425 | } | 425 | } |
426 | 426 | ||
427 | else { | 427 | else { |
428 | 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)); |
429 | } | 429 | } |
430 | emit outputReady(output); | 430 | emit outputReady(output); |
431 | } | 431 | } |
432 | 432 | ||
433 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { | 433 | void IRCMessageParser::parseCTCPAction(IRCMessage *message) { |
434 | IRCPerson mask(message->prefix()); | 434 | IRCPerson mask(message->prefix()); |
435 | QString dest = message->ctcpDestination(); | 435 | QString dest = message->ctcpDestination(); |
436 | if (dest.startsWith("#")) { | 436 | if (dest.startsWith("#")) { |
437 | IRCChannel *channel = m_session->getChannel(dest.lower()); | 437 | IRCChannel *channel = m_session->getChannel(dest.lower()); |
438 | if (channel) { | 438 | if (channel) { |
439 | IRCChannelPerson *person = channel->getPerson(mask.nick()); | 439 | IRCChannelPerson *person = channel->getPerson(mask.nick()); |
440 | if (person) { | 440 | if (person) { |
441 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); | 441 | IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); |
442 | output.addParam(channel); | 442 | output.addParam(channel); |
443 | output.addParam(person); | 443 | output.addParam(person); |
444 | emit outputReady(output); | 444 | emit outputReady(output); |
445 | } else { | 445 | } else { |
446 | 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?"))); |
447 | } | 447 | } |
448 | } else { | 448 | } else { |
449 | 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?"))); |
450 | } | 450 | } |
451 | } else { | 451 | } else { |
452 | if (message->ctcpDestination() == m_session->m_server->nick()) { | 452 | if (message->ctcpDestination() == m_session->m_server->nick()) { |
453 | IRCPerson *person = m_session->getPerson(mask.nick()); | 453 | IRCPerson *person = m_session->getPerson(mask.nick()); |
454 | if (!person) { | 454 | if (!person) { |
455 | /* Person not yet known, create and add to the current session */ | 455 | /* Person not yet known, create and add to the current session */ |
456 | person = new IRCPerson(message->prefix()); | 456 | person = new IRCPerson(message->prefix()); |
457 | m_session->addPerson(person); | 457 | m_session->addPerson(person); |
458 | } | 458 | } |
459 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); | 459 | IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); |
460 | output.addParam(person); | 460 | output.addParam(person); |
461 | emit outputReady(output); | 461 | emit outputReady(output); |
462 | } else { | 462 | } else { |
463 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); | 463 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); |
464 | } | 464 | } |
465 | } | 465 | } |
466 | } | 466 | } |
467 | 467 | ||
468 | void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { | 468 | void IRCMessageParser::parseCTCPDCC(IRCMessage *message) { |
469 | QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); | 469 | QStringList params = QStringList::split(' ', message->param(0).stripWhiteSpace()); |
470 | 470 | ||
471 | if(params[0] == "SEND") { | 471 | if(params[0] == "SEND") { |
472 | QString nickname = IRCPerson(message->prefix()).nick(); | 472 | QString nickname = IRCPerson(message->prefix()).nick(); |
473 | if( params.count() != 5) { | 473 | if( params.count() != 5) { |
474 | 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))); |
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | 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()); |
478 | if(!accepted) | 478 | if(!accepted) |
479 | return; | 479 | return; |
480 | QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL, | 480 | QString filename = Opie::Ui::OFileDialog::getSaveFileName(Opie::Ui::OFileSelector::EXTENDED_ALL, |
481 | QString::null, params[1], MimeTypes(), 0, tr("Save As")); | 481 | QString::null, params[1], MimeTypes(), 0, tr("Save As")); |
482 | if(filename.isEmpty()) | 482 | if(filename.isEmpty()) |
483 | return; | 483 | return; |
484 | 484 | ||
485 | odebug << "Receiving file " << filename << " from " << nickname << oendl; | 485 | odebug << "Receiving file " << filename << " from " << nickname << oendl; |
486 | 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(), |
487 | filename, nickname, params[4].toUInt()); | 487 | filename, nickname, params[4].toUInt()); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { | 491 | void IRCMessageParser::parseLiteralMode(IRCMessage *message) { |
492 | IRCPerson mask(message->prefix()); | 492 | IRCPerson mask(message->prefix()); |
493 | 493 | ||
494 | if (IRCChannel::isValid(message->param(0))) { | 494 | if (IRCChannel::isValid(message->param(0))) { |
495 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); | 495 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); |
496 | if (channel) { | 496 | if (channel) { |
497 | 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); |
498 | QTextIStream stream(¶meters); | 498 | QTextIStream stream(¶meters); |
499 | bool set = FALSE; | 499 | bool set = FALSE; |
500 | while (!stream.atEnd()) { | 500 | while (!stream.atEnd()) { |
501 | stream >> temp; | 501 | stream >> temp; |
502 | if (temp.startsWith("+")) { | 502 | if (temp.startsWith("+")) { |
503 | set = TRUE; | 503 | set = TRUE; |
504 | temp = temp.right(1); | 504 | temp = temp.right(1); |
505 | } | 505 | } |
506 | else | 506 | else |
507 | if (temp.startsWith("-")) { | 507 | if (temp.startsWith("-")) { |
508 | set = FALSE; | 508 | set = FALSE; |
509 | temp = temp.right(1); | 509 | temp = temp.right(1); |
510 | } | 510 | } |
511 | else { | 511 | else { |
512 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); | 512 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); |
513 | return; | 513 | return; |
514 | } | 514 | } |
515 | if (temp == "o") { | 515 | if (temp == "o") { |
516 | stream >> temp; | 516 | stream >> temp; |
517 | IRCChannelPerson *person = channel->getPerson(temp); | 517 | IRCChannelPerson *person = channel->getPerson(temp); |
518 | if (person) { | 518 | if (person) { |
519 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); | 519 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setOp(mask.nick(), set)); |
520 | output.addParam(channel); | 520 | output.addParam(channel); |
521 | output.addParam(person); | 521 | output.addParam(person); |
522 | emit outputReady(output); | 522 | emit outputReady(output); |
523 | } | 523 | } |
524 | else { | 524 | else { |
525 | 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?"))); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | else | 528 | else |
529 | if (temp == "v") { | 529 | if (temp == "v") { |
530 | stream >> temp; | 530 | stream >> temp; |
531 | IRCChannelPerson *person = channel->getPerson(temp); | 531 | IRCChannelPerson *person = channel->getPerson(temp); |
532 | if (person) { | 532 | if (person) { |
533 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); | 533 | IRCOutput output(OUTPUT_CHANPERSONMODE, person->setVoice(mask.nick(), set)); |
534 | output.addParam(channel); | 534 | output.addParam(channel); |
535 | output.addParam(person); | 535 | output.addParam(person); |
536 | emit outputReady(output); | 536 | emit outputReady(output); |
537 | } | 537 | } |
538 | else { | 538 | else { |
539 | 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?"))); |
540 | } | 540 | } |
541 | } | 541 | } |
542 | else { | 542 | else { |
543 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); | 543 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); |
544 | } | 544 | } |
545 | } | 545 | } |
546 | } else { | 546 | } else { |
547 | 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?"))); |
548 | } | 548 | } |
549 | } else { | 549 | } else { |
550 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); | 550 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); |
551 | } | 551 | } |
552 | } | 552 | } |
553 | 553 | ||
554 | void IRCMessageParser::parseLiteralKick(IRCMessage *message) { | 554 | void IRCMessageParser::parseLiteralKick(IRCMessage *message) { |
555 | IRCPerson mask(message->prefix()); | 555 | IRCPerson mask(message->prefix()); |
556 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); | 556 | IRCChannel *channel = m_session->getChannel(message->param(0).lower()); |
557 | if (channel) { | 557 | if (channel) { |
558 | IRCChannelPerson *person = channel->getPerson(message->param(1)); | 558 | IRCChannelPerson *person = channel->getPerson(message->param(1)); |
559 | if (person) { | 559 | if (person) { |
560 | if (person->nick() == m_session->m_server->nick()) { | 560 | if (person->nick() == m_session->m_server->nick()) { |
561 | m_session->removeChannel(channel); | 561 | m_session->removeChannel(channel); |
562 | 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) + ")"); |
563 | output.addParam(channel); | 563 | output.addParam(channel); |
564 | emit outputReady(output); | 564 | emit outputReady(output); |
565 | } else { | 565 | } else { |
566 | /* someone else got kicked */ | 566 | /* someone else got kicked */ |
567 | channel->removePerson(person); | 567 | channel->removePerson(person); |
568 | 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) + ")"); |
569 | output.addParam(channel); | 569 | output.addParam(channel); |
570 | output.addParam(person); | 570 | output.addParam(person); |
571 | emit outputReady(output); | 571 | emit outputReady(output); |
572 | } | 572 | } |
573 | } else { | 573 | } else { |
574 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); | 574 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); |
575 | } | 575 | } |
576 | } else { | 576 | } else { |
577 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); | 577 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); |
578 | } | 578 | } |
579 | } | 579 | } |
580 | 580 | ||
581 | void IRCMessageParser::parseNumericalNames(IRCMessage *message) { | 581 | void IRCMessageParser::parseNumericalNames(IRCMessage *message) { |
582 | /* Name list sent when joining a channel */ | 582 | /* Name list sent when joining a channel */ |
583 | IRCChannel *channel = m_session->getChannel(message->param(2).lower()); | 583 | IRCChannel *channel = m_session->getChannel(message->param(2).lower()); |
584 | if (channel != 0) { | 584 | if (channel != 0) { |
585 | QString people = message->param(3); | 585 | QString people = message->param(3); |
586 | QTextIStream stream(&people); | 586 | QTextIStream stream(&people); |
587 | QString temp; | 587 | QString temp; |
588 | 588 | ||
589 | while (!stream.atEnd()) { | 589 | while (!stream.atEnd()) { |
590 | stream >> temp; | 590 | stream >> temp; |
591 | 591 | ||
592 | char flagch = temp.at(0).latin1(); | 592 | char flagch = temp.at(0).latin1(); |
593 | int flag = 0; | 593 | int flag = 0; |
594 | QString nick; | 594 | QString nick; |
595 | /* Parse person flags */ | 595 | /* Parse person flags */ |
596 | if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { | 596 | if (flagch == '~' || flagch == '&' || flagch == '@' || flagch == '+' || |
597 | flagch=='%' || flagch == '*') { | ||
597 | 598 | ||
598 | nick = temp.right(temp.length()-1); | 599 | nick = temp.right(temp.length()-1); |
599 | switch (flagch) { | 600 | switch (flagch) { |
600 | case '@': flag = IRCChannelPerson::PERSON_FLAG_OP; break; | 601 | /** |
601 | case '+': flag = IRCChannelPerson::PERSON_FLAG_VOICE; break; | 602 | * @note '~' and `&' are extensions of the unrealircd irc |
602 | case '%': flag = IRCChannelPerson::PERSON_FLAG_HALFOP; break; | 603 | * daemon. This app can't see users w/out checking for these |
603 | default : flag = 0; break; | 604 | * chars. |
605 | */ | ||
606 | case '~': | ||
607 | case '&': | ||
608 | case '@': | ||
609 | flag = IRCChannelPerson::PERSON_FLAG_OP; | ||
610 | break; | ||
611 | case '+': | ||
612 | flag = IRCChannelPerson::PERSON_FLAG_VOICE; | ||
613 | break; | ||
614 | case '%': | ||
615 | flag = IRCChannelPerson::PERSON_FLAG_HALFOP; | ||
616 | break; | ||
617 | default : | ||
618 | flag = 0; | ||
619 | break; | ||
604 | } | 620 | } |
605 | } else { | 621 | } else |
606 | nick = temp; | 622 | nick = temp; |
607 | } | ||
608 | 623 | ||
609 | IRCPerson *person = m_session->getPerson(nick); | 624 | IRCPerson *person = m_session->getPerson(nick); |
610 | if (person == 0) { | 625 | if (person == 0) { |
611 | person = new IRCPerson(); | 626 | person = new IRCPerson(); |
612 | person->setNick(nick); | 627 | person->setNick(nick); |
613 | m_session->addPerson(person); | 628 | m_session->addPerson(person); |
614 | } | 629 | } |
615 | IRCChannelPerson *chan_person = new IRCChannelPerson(person); | 630 | IRCChannelPerson *chan_person = new IRCChannelPerson(person); |
616 | chan_person->setFlags(flag); | 631 | chan_person->setFlags(flag); |
617 | channel->addPerson(chan_person); | 632 | channel->addPerson(chan_person); |
618 | } | 633 | } |
619 | } else { | 634 | } else |
620 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); | 635 | emit outputReady(IRCOutput(OUTPUT_ERROR, |
621 | } | 636 | tr("Server message with unknown channel"))); |
622 | } | 637 | } |
623 | 638 | ||
624 | void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { | 639 | void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { |
625 | /* Done syncing to channel */ | 640 | /* Done syncing to channel */ |
626 | IRCChannel *channel = m_session->getChannel(message->param(1).lower()); | 641 | IRCChannel *channel = m_session->getChannel(message->param(1).lower()); |
627 | if (channel) { | 642 | if (channel) { |
628 | channel->setHasPeople(TRUE); | 643 | channel->setHasPeople(TRUE); |
629 | /* Yes, we want the names before anything happens inside the GUI */ | 644 | /* Yes, we want the names before anything happens inside the GUI */ |
630 | IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); | 645 | IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); |
631 | output.addParam(channel); | 646 | output.addParam(channel); |
632 | emit outputReady(output); | 647 | emit outputReady(output); |
633 | } else { | 648 | } else { |
634 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); | 649 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); |
635 | } | 650 | } |
636 | } | 651 | } |
637 | 652 | ||
638 | 653 | ||
639 | void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { | 654 | void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { |
640 | /* If we are connnected this error is not critical */ | 655 | /* If we are connnected this error is not critical */ |
641 | if(m_session->isLoggedIn()) | 656 | if(m_session->isLoggedIn()) |
642 | return; | 657 | return; |
643 | 658 | ||
644 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); | 659 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); |
645 | m_session->endSession(); | 660 | m_session->endSession(); |
646 | } | 661 | } |
647 | 662 | ||
648 | void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { | 663 | void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { |
649 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); | 664 | emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); |
650 | } | 665 | } |
651 | 666 | ||
652 | void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { | 667 | void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { |
653 | IRCChannel *channel = m_session->getChannel(message->param(1).lower()); | 668 | IRCChannel *channel = m_session->getChannel(message->param(1).lower()); |
654 | if (channel) { | 669 | if (channel) { |
655 | IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); | 670 | IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); |
656 | output.addParam(channel); | 671 | output.addParam(channel); |
657 | emit outputReady(output); | 672 | emit outputReady(output); |
658 | } else { | 673 | } else { |
659 | IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); | 674 | IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); |
660 | output.addParam(0); | 675 | output.addParam(0); |
661 | emit outputReady(output); | 676 | emit outputReady(output); |
662 | } | 677 | } |
663 | } | 678 | } |
664 | 679 | ||
665 | void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { | 680 | void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { |
666 | } | 681 | } |
667 | 682 | ||
668 | 683 | ||