-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 | |||
@@ -271,194 +271,202 @@ void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { | |||
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) { |