Project

General

Profile

userinputhandler.patch

admin, 08/18/2008 02:41 PM

View differences:

src/core/userinputhandler.cpp
153 153

  
154 154
void UserInputHandler::handleJoin(const BufferInfo &bufferInfo, const QString &msg) {
155 155
  Q_UNUSED(bufferInfo)
156
  QStringList params = msg.trimmed().split(" ");
157
  QStringList chans = params[0].split(",");
158
  QStringList keys;
156
  // Sometimes channels can be prepended with whitespaces so the
157
  // strategy is the following:
158
  // First split msg after , and trim the results
159
  // Secondly check if we can split the last element with ' '. If yes,
160
  // we have our keys
161

  
162
  QStringList chans = msg.trimmed().split(",");
159 163
  int i;
160 164
  for(i = 0; i < chans.count(); i++) {
165
    chans[i] = chans.at(i).trimmed();
166
  }
167
  int lastElement = chans.count() - 1;
168
  QStringList tempList = chans.at(lastElement).split(" ");
169
  QStringList keys;
170
  QStringList params;
171
  if (tempList.count() > 1) {
172
    keys = tempList.at(1).split(",");
173
    // Strip the keys from the last channel
174
    chans[lastElement] = tempList.at(0);
175
  }
176
  // Add missing # to the channel names
177
  for(i = 0; i < chans.count(); i++) {
161 178
    if (chans.at(i)[0].isLetterOrNumber())
162 179
      chans[i].prepend(QChar('#'));
163 180
  }
164
  params[0] = chans.join(",");
165
  if(params.count() > 1) keys = params[1].split(",");
181
  params.append(chans.join(","));
182
  if (keys.count() > 0)
183
    params.append(keys.join(","));
166 184
  emit putCmd("JOIN", serverEncode(params)); // FIXME handle messages longer than 512 bytes!
167 185
  i = 0;
168 186
  for(; i < keys.count(); i++) {