コード例 #1
0
ファイル: hall.cpp プロジェクト: wentao/chatty
bool HallAction::execute(const QString &input, QStringList* output) {
  QString head = Command::ParseHead(input);
  if (head == kActionRooms) {
    for (auto it : hall_->opens_) {
      *output << " * ";
      output->last().append(it.first);
      if (!it.second->pin().isEmpty()) {
        output->last().append(" (** pin required)");
      }
    }
  } else if (head == kActionCreate) {
    if (Hall::opens_.size() >= kMaxRoomCount) {
      *output << QString("Maximum room count reached: %1").arg(kMaxRoomCount);
    } else {
      Create* create = new Create;
      if (!create->execute(input, output)) {
        client_->registerProtocol(create);
      } else {
        delete create;
      }
    }
  } else if (head == kActionQuit) {
    emit client_->closeConnection();
    *output << "BYE!";
  } else if (head == kActionJoin) {
    Join* join = new Join(hall_, client_);
    if (!join->execute(input, output)) {
      client_->registerProtocol(join);
    } else {
      delete join;
    }
  } else {
    *output << actionList_;
  }
  return false;
}