~ubuntu-branches/ubuntu/saucy/quassel/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/coreuserinputhandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-02-17 12:49:50 UTC
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20100217124950-v9hajw5d2xa6fszn
Tags: upstream-0.6~beta1
ImportĀ upstreamĀ versionĀ 0.6~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright (C) 2005-09 by the Quassel Project                          *
 
2
 *   Copyright (C) 2005-10 by the Quassel Project                          *
3
3
 *   devel@quassel-irc.org                                                 *
4
4
 *                                                                         *
5
5
 *   This program is free software; you can redistribute it and/or modify  *
29
29
#include <QRegExp>
30
30
 
31
31
CoreUserInputHandler::CoreUserInputHandler(CoreNetwork *parent)
32
 
  : BasicHandler(parent)
 
32
  : CoreBasicHandler(parent)
33
33
{
34
34
}
35
35
 
128
128
  if(ctcpTag.isEmpty())
129
129
    return;
130
130
 
131
 
  QString message = "";
132
 
  QString verboseMessage = tr("sending CTCP-%1 request").arg(ctcpTag);
 
131
  QString message = msg.section(' ', 2);
 
132
  QString verboseMessage = tr("sending CTCP-%1 request to %2").arg(ctcpTag).arg(nick);
133
133
 
134
134
  if(ctcpTag == "PING") {
135
135
    uint now = QDateTime::currentDateTime().toTime_t();
169
169
  QString sane_msg = msg;
170
170
  sane_msg.replace(QRegExp(", +"), ",");
171
171
  QStringList params = sane_msg.trimmed().split(" ");
 
172
 
172
173
  QStringList chans = params[0].split(",", QString::SkipEmptyParts);
173
174
  QStringList keys;
 
175
  if(params.count() > 1)
 
176
    keys = params[1].split(",");
 
177
 
174
178
  int i;
175
179
  for(i = 0; i < chans.count(); i++) {
176
180
    if(!network()->isChannelName(chans[i]))
177
181
      chans[i].prepend('#');
 
182
 
 
183
    if(i < keys.count()) {
 
184
      network()->addChannelKey(chans[i], keys[i]);
 
185
    } else {
 
186
      network()->removeChannelKey(chans[i]);
 
187
    }
178
188
  }
179
 
  params[0] = chans.join(",");
180
 
  if(params.count() > 1) keys = params[1].split(",");
181
 
  emit putCmd("JOIN", serverEncode(params)); // FIXME handle messages longer than 512 bytes!
 
189
 
 
190
  static const char *cmd = "JOIN";
182
191
  i = 0;
183
 
  for(; i < keys.count(); i++) {
184
 
    if(i >= chans.count()) break;
185
 
    network()->addChannelKey(chans[i], keys[i]);
186
 
  }
187
 
  for(; i < chans.count(); i++) {
188
 
    network()->removeChannelKey(chans[i]);
 
192
  QStringList joinChans, joinKeys;
 
193
  int slicesize = chans.count();
 
194
  QList<QByteArray> encodedParams;
 
195
 
 
196
  // go through all to-be-joined channels and (re)build the join list
 
197
  while(i < chans.count()) {
 
198
    joinChans.append(chans.at(i));
 
199
    if(i < keys.count())
 
200
      joinKeys.append(keys.at(i));
 
201
 
 
202
    // if the channel list we built so far either contains all requested channels or exceeds
 
203
    // the desired amount of channels in this slice, try to send what we have so far
 
204
    if(++i == chans.count() || joinChans.count() >= slicesize) {
 
205
      params.clear();
 
206
      params.append(joinChans.join(","));
 
207
      params.append(joinKeys.join(","));
 
208
      encodedParams = serverEncode(params);
 
209
      // check if it fits in one command
 
210
      if(lastParamOverrun(cmd, encodedParams) == 0) {
 
211
        emit putCmd(cmd, encodedParams);
 
212
      } else if(slicesize > 1) {
 
213
        // back to start of slice, try again with half the amount of channels
 
214
        i -= slicesize;
 
215
        slicesize /= 2;
 
216
      }
 
217
      joinChans.clear();
 
218
      joinKeys.clear();
 
219
    }
189
220
  }
190
221
}
191
222
 
387
418
 
388
419
void CoreUserInputHandler::defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &msg) {
389
420
  Q_UNUSED(bufferInfo);
390
 
  emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", QString("Error: %1 %2").arg(cmd, msg));
 
421
  emit putCmd(serverEncode(cmd.toUpper()), serverEncode(msg.split(" ")));
391
422
}
392
423
 
393
424
void CoreUserInputHandler::putPrivmsg(const QByteArray &target, const QByteArray &message) {
413
444
 
414
445
// returns 0 if the message will not be chopped by the irc server or number of chopped bytes if message is too long
415
446
int CoreUserInputHandler::lastParamOverrun(const QString &cmd, const QList<QByteArray> &params) {
416
 
  // the server will pass our message trunkated to 512 bytes including CRLF with the following format:
 
447
  // the server will pass our message truncated to 512 bytes including CRLF with the following format:
417
448
  // ":prefix COMMAND param0 param1 :lastparam"
418
449
  // where prefix = "nickname!user@host"
419
450
  // that means that the last message can be as long as: