// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1 #include "core/fsd/servererror.h" #include #include "misc/logmessage.h" namespace swift::core::fsd { ServerError::ServerError(const QString &sender, const QString &receiver, ServerErrorCode errorCode, const QString &causingParameter, const QString &description) : MessageBase(sender, receiver), m_errorNumber(errorCode), m_causingParameter(causingParameter), m_description(description) {} bool ServerError::isFatalError() const { static const QVector fatalErrors { ServerErrorCode::CallsignInUse, ServerErrorCode::InvalidCallsign, ServerErrorCode::AlreadyRegistered, ServerErrorCode::InvalidCidPassword, ServerErrorCode::InvalidRevision, ServerErrorCode::RequestedLevelTooHigh, ServerErrorCode::ServerFull, ServerErrorCode::CidSuspended, ServerErrorCode::RatingTooLow, ServerErrorCode::InvalidClient, ServerErrorCode::AuthTimeout, }; return fatalErrors.contains(m_errorNumber); } QStringList ServerError::toTokens() const { auto tokens = QStringList {}; tokens.push_back(m_sender); tokens.push_back(m_receiver); tokens.push_back(QString::number(static_cast(m_errorNumber))); tokens.push_back(m_causingParameter); tokens.push_back(m_description); return tokens; } ServerError ServerError::fromTokens(const QStringList &tokens) { if (tokens.size() < 5) { swift::misc::CLogMessage(static_cast(nullptr)).debug(u"Wrong number of arguments."); return {}; } return { tokens[0], tokens[1], static_cast(tokens[2].toInt()), tokens[3], tokens[4] }; } } // namespace swift::core::fsd