~ubuntu-branches/ubuntu/lucid/konversation/lucid-updates

« back to all changes in this revision

Viewing changes to src/irc/inputfilter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-02-11 14:52:14 UTC
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20100211145214-xsbd3hmrnu5fmb8f
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "server.h"
16
16
#include "replycodes.h"
17
17
#include "application.h"
18
 
#include "commit.h"
19
18
#include "version.h"
20
19
#include "query.h"
21
20
#include "channel.h"
153
152
    }
154
153
}
155
154
 
156
 
#define trailing (parameterList.isEmpty() ? QString() : parameterList.last())
 
155
#define trailing parameterList.last()
157
156
#define plHas(x) _plHas(parameterList.count(), (x))
158
157
 
159
158
bool _plHad=false;
209
208
                ctcpArgument = konv_app->doAutoreplace(ctcpArgument, false);
210
209
 
211
210
            // If it was a ctcp action, build an action string
212
 
            if (ctcpCommand == "action" && isChan)
 
211
            if (ctcpCommand == "action" && isChan && hasArg)
213
212
            {
214
 
                if (!isIgnore(prefix, Ignore::Channel))
 
213
                if (!isIgnore(prefix,Ignore::Channel))
215
214
                {
216
215
                    Channel* channel = server->getChannelByName( parameterList.value(0) );
217
216
 
224
223
 
225
224
                    if (sourceNick != server->getNickname())
226
225
                    {
227
 
                        if (hasArg && ctcpArgument.toLower().contains(QRegExp("(^|[^\\d\\w])"
 
226
                        if (ctcpArgument.toLower().contains(QRegExp("(^|[^\\d\\w])"
228
227
                            + QRegExp::escape(server->loweredNickname())
229
228
                            + "([^\\d\\w]|$)")))
230
229
                        {
238
237
                }
239
238
            }
240
239
            // If it was a ctcp action, build an action string
241
 
            else if (ctcpCommand == "action" && !isChan)
 
240
            else if (ctcpCommand == "action" && !isChan && hasArg)
242
241
            {
243
242
                // Check if we ignore queries from this nick
244
 
                if (!isIgnore(prefix, Ignore::Query))
 
243
                if (!isIgnore(prefix,Ignore::Query))
245
244
                {
246
245
                    NickInfoPtr nickinfo = server->obtainNickInfo(sourceNick);
247
246
                    nickinfo->setHostmask(sourceHostmask);
250
249
                    query = server->addQuery(nickinfo, false /* we didn't initiate this*/ );
251
250
 
252
251
                    // send action to query
253
 
                    query->appendAction(sourceNick, ctcpArgument);
 
252
                    query->appendAction(sourceNick,ctcpArgument);
254
253
 
255
 
                    if (sourceNick != server->getNickname() && query)
 
254
                    if(sourceNick != server->getNickname() && query)
 
255
                    {
256
256
                        konv_app->notificationHandler()->queryMessage(query, sourceNick, ctcpArgument);
 
257
                    }
257
258
                }
258
259
            }
259
260
 
308
309
                    else
309
310
                    {
310
311
                        // Do not internationalize the below version string
311
 
                        reply = QString("Konversation %1 Build %2 (C) 2002-2010 by the Konversation team")
312
 
                            .arg(QString(KONVI_VERSION))
313
 
                            .arg(QString::number(COMMIT));
 
312
                        reply = QString("Konversation %1 (C) 2002-2010 by the Konversation team")
 
313
                            .arg(QString(KONVI_VERSION));
314
314
 
315
315
                    }
316
316
                    server->ctcpReply(sourceNick,"VERSION "+reply);
440
440
            }
441
441
            else if (ctcpCommand=="clientinfo" && !isChan)
442
442
            {
443
 
                if (!isIgnore(prefix, Ignore::CTCP))
444
 
                {
445
 
                    server->appendMessageToFrontmost(i18n("CTCP"),
446
 
                        i18n("Received CTCP-%1 request from %2, sending answer.",
447
 
                            QString::fromLatin1("CLIENTINFO"), sourceNick)
448
 
                        );
449
 
                    server->ctcpReply(sourceNick,QString("CLIENTINFO ACTION CLIENTINFO DCC PING TIME VERSION"));
450
 
                }
 
443
                server->appendMessageToFrontmost(i18n("CTCP"),
 
444
                    i18n("Received CTCP-%1 request from %2, sending answer.",
 
445
                         QString::fromLatin1("CLIENTINFO"), sourceNick)
 
446
                    );
 
447
                server->ctcpReply(sourceNick,QString("CLIENTINFO ACTION CLIENTINFO DCC PING TIME VERSION"));
451
448
            }
452
449
            else if (ctcpCommand=="time" && !isChan)
453
450
            {
454
 
                if (!isIgnore(prefix, Ignore::CTCP))
455
 
                {
456
 
                    server->appendMessageToFrontmost(i18n("CTCP"),
457
 
                        i18n("Received CTCP-%1 request from %2, sending answer.",
458
 
                            QString::fromLatin1("TIME"), sourceNick)
459
 
                        );
460
 
                    server->ctcpReply(sourceNick,QString("TIME ")+QDateTime::currentDateTime().toString());
461
 
                }
 
451
                server->appendMessageToFrontmost(i18n("CTCP"),
 
452
                    i18n("Received CTCP-%1 request from %2, sending answer.",
 
453
                         QString::fromLatin1("TIME"), sourceNick)
 
454
                    );
 
455
                server->ctcpReply(sourceNick,QString("TIME ")+QDateTime::currentDateTime().toString());
462
456
            }
463
457
 
464
458
            // No known CTCP request, give a general message
520
514
                        int dateArrived=QDateTime::currentDateTime().toTime_t();
521
515
                        int dateSent=reply.toInt();
522
516
                        int time = dateArrived-dateSent;
523
 
                        QString unit = i18np("second", "seconds", time);
 
517
                        QString unit = "seconds";
 
518
 
 
519
                        if (time==1)
 
520
                            unit = "second";
524
521
 
525
522
                        server->appendMessageToFrontmost(i18n("CTCP"),
526
523
                            i18n("Received CTCP-PING reply from %1: %2 %3.",
623
620
            // Join the channel
624
621
            server->joinChannel(channelName, sourceHostmask);
625
622
 
 
623
            server->resetNickList(channelName);
 
624
 
626
625
            // Upon JOIN we're going to receive some NAMES input from the server which
627
626
            // we need to be able to tell apart from manual invocations of /names
628
627
            setAutomaticRequest("NAMES",channelName,true);
1092
1091
            {
1093
1092
                if (plHas(3))
1094
1093
                {
1095
 
                    QString topic(trailing);
 
1094
                    QString topic = Konversation::removeIrcMarkup(trailing);
1096
1095
 
1097
1096
                    // FIXME: This is an abuse of the automaticRequest system: We're
1098
1097
                    // using it in an inverted manner, i.e. the automaticRequest is
1124
1123
                        server->appendCommandMessageToChannel(parameterList.value(1), i18n("Topic"),
1125
1124
                            i18n("The topic was set by %1 on %2.",
1126
1125
                            parameterList.value(2), KGlobal::locale()->formatDateTime(when, KLocale::ShortDate)),
1127
 
                            false,
1128
1126
                            false);
1129
1127
                    }
1130
1128
                    else
1132
1130
                        server->appendMessageToFrontmost(i18n("Topic"),i18n("The topic for %1 was set by %2 on %3.",
1133
1131
                            parameterList.value(1),
1134
1132
                            parameterList.value(2),
1135
 
                            KGlobal::locale()->formatDateTime(when, KLocale::ShortDate)),
1136
 
                            false);
 
1133
                            KGlobal::locale()->formatDateTime(when, KLocale::ShortDate))
 
1134
                            );
1137
1135
                        setAutomaticRequest("TOPIC",parameterList.value(1), false);
1138
1136
                    }
1139
1137
                    emit topicAuthor(parameterList.value(1), parameterList.value(2), when);
1200
1198
                        // The user chose to disconnect
1201
1199
                        if (newNick.isNull())
1202
1200
                        {
1203
 
                            server->disconnectServer();
 
1201
                            server->disconnect();
1204
1202
                        }
1205
1203
                        else
1206
1204
                        {
1231
1229
                        // The user chose to disconnect
1232
1230
                        if (newNick.isNull())
1233
1231
                        {
1234
 
                            server->disconnectServer();
 
1232
                            server->disconnect();
1235
1233
                        }
1236
1234
                        else
1237
1235
                        {
1297
1295
                }
1298
1296
                break;
1299
1297
            }
1300
 
            case ERR_CHANOPRIVSNEEDED:
1301
 
            {
1302
 
                if (plHas(2))
1303
 
                {
1304
 
                    server->appendMessageToFrontmost(i18n("Error"), i18n("You need to be a channel operator in %1 to do that.", parameterList.value(1)));
1305
 
                }
1306
 
                break;
1307
 
            }
1308
1298
            case RPL_YOUREOPER:
1309
1299
            {
1310
1300
                if (plHas(1))
1471
1461
                }
1472
1462
                break;
1473
1463
            }
1474
 
            case RPL_WHOISSECURE:
1475
 
            {
1476
 
                if (plHas(2))
1477
 
                {
1478
 
                    if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 0)
1479
 
                        server->appendMessageToFrontmost(i18n("Whois"), i18n("%1 is using a secure connection.", parameterList.value(1)));
1480
 
                }
1481
 
                break;
1482
 
            }
1483
1464
            // Sample WHO response
1484
1465
            //"/WHO #lounge"
1485
1466
            //[21:39] [352] #lounge jasmine bots.worldforge.org irc.worldforge.org jasmine H 0 jasmine
1943
1924
            }
1944
1925
            case RPL_BANLIST:
1945
1926
            {
1946
 
                //:calvino.freenode.net 367 argonel #konversation fooish!~a@example.com argonel!argkde4@konversation/developer/argonel 1269464382
1947
 
                if (plHas(3))
 
1927
                if (plHas(5))
1948
1928
                {
1949
1929
                    if (getAutomaticRequest("BANLIST", parameterList.value(1)))
1950
1930
                    {
1951
 
                        server->addBan(parameterList.value(1), parameterList.join(" ").section(' ', 2, 4)); //<-- QString::Section handles out of bounds end parameter
 
1931
                        server->addBan(parameterList.value(1), parameterList.join(" ").section(' ', 2, 4));
1952
1932
                    }
1953
1933
                    else
1954
1934
                    {
1955
1935
                        QDateTime when;
1956
 
                        if (plHas(5))
1957
 
                            when.setTime_t(parameterList.value(4).toUInt());
1958
 
                        else
1959
 
                            when = QDateTime::currentDateTime(); //use todays date instead of Jan 1 1970
1960
 
 
1961
 
                        QString setter(parameterList.value(3, i18nc("The server didn't respond with the identity of the ban creator, so we say unknown (in brackets to avoid confusion with a real nickname)", "(unknown)")).section('!', 0, 0));
 
1936
                        when.setTime_t(parameterList.value(4).toUInt());
1962
1937
 
1963
1938
                        server->appendMessageToFrontmost(i18n("BanList:%1", parameterList.value(1)),
1964
1939
                                    i18nc("BanList message: e.g. *!*@aol.com set by MrGrim on <date>", "%1 set by %2 on %3",
1965
 
                                        parameterList.value(2), setter, KGlobal::locale()->formatDateTime(when, KLocale::ShortDate))
 
1940
                                        parameterList.value(2), parameterList.value(3).section('!', 0, 0), KGlobal::locale()->formatDateTime(when, KLocale::ShortDate))
1966
1941
                                    );
1967
1942
                    }
1968
1943
                }
2008
1983
                    {
2009
1984
                        server->pongReceived();
2010
1985
                    }
2011
 
                    else if (getAutomaticRequest("WHOIS", parameterList.value(1)) == 1) //Inhibit message if this was an automatic request
2012
 
                    {
2013
 
                        setAutomaticRequest("WHOIS", parameterList.value(1), false);
2014
 
                    }
2015
 
                    else
2016
 
                    {
2017
 
                        server->appendMessageToFrontmost(i18n("Error"), i18n("No such server: %1.", parameterList.value(1)));
2018
 
                    }
2019
1986
                }
2020
1987
                break;
2021
1988
            }
2080
2047
                }
2081
2048
                break;
2082
2049
            }
2083
 
            case ERR_BADCHANNELKEY:
2084
 
            {
2085
 
                if (plHas(2))
2086
 
                {
2087
 
                    server->appendMessageToFrontmost(i18n("Error"), i18n("Cannot join %1: The channel is password-protected and either a wrong or no password was given.", parameterList.value(1)));
2088
 
                }
2089
 
                break;
2090
 
            }
2091
2050
            default:
2092
2051
            {
2093
2052
                // All yet unknown messages go into the frontmost window without the