211 lines
5.9 KiB
C++
Executable File
211 lines
5.9 KiB
C++
Executable File
|
|
|
|
|
|
#include "messages.h"
|
|
|
|
#include <QJsonArray>
|
|
#include <QDebug>
|
|
|
|
namespace LtsProjectionWorkstation
|
|
{
|
|
|
|
|
|
STC::LoginRequestReply::LoginRequestReply(const QString &uuid, Reason reason, int reasonUserId, const QVector<VncScreen> &screens)
|
|
: Message(nullptr, nullptr, JsonKeys::LOGIN_REPLY(), uuid, QJsonValue())
|
|
, m_screens(screens)
|
|
, m_reasonUserId(reasonUserId)
|
|
, m_reason(reason)
|
|
{
|
|
QJsonObject result;
|
|
QJsonArray arr;
|
|
for (const VncScreen &vncScreen : screens)
|
|
{
|
|
QJsonObject screen;
|
|
screen.insert(JsonKeys::NAME(), vncScreen.name);
|
|
screen.insert(JsonKeys::PORT(), vncScreen.port);
|
|
screen.insert(JsonKeys::WIDTH(), vncScreen.geometry.width());
|
|
screen.insert(JsonKeys::HEIGHT(), vncScreen.geometry.height());
|
|
arr.append(screen);
|
|
}
|
|
result.insert(JsonKeys::REASON(), reason);
|
|
result.insert(JsonKeys::USER_ID(), reasonUserId);
|
|
result.insert(JsonKeys::SCREENS(), arr);
|
|
m_replyData = QJsonValue(result);
|
|
}
|
|
|
|
|
|
void STC::LoginRequestReply::process()
|
|
{
|
|
if (!m_handler || !m_client) return;
|
|
QJsonObject dataObj = m_data.toObject();
|
|
m_reason = Reason(dataObj.value(JsonKeys::REASON()).toInt());
|
|
m_reasonUserId = dataObj.value(JsonKeys::USER_ID()).toInt();
|
|
const auto arr = dataObj.value(JsonKeys::SCREENS()).toArray();
|
|
for (const QJsonValue &val : arr)
|
|
{
|
|
const QJsonObject obj(val.toObject());
|
|
VncScreen screen;
|
|
screen.name = obj.value(JsonKeys::NAME()).toString(QStringLiteral("err"));
|
|
screen.port = obj.value(JsonKeys::PORT()).toInt(-1);
|
|
screen.geometry = QRect(0, 0,
|
|
obj.value(JsonKeys::WIDTH()).toInt(-1),
|
|
obj.value(JsonKeys::HEIGHT()).toInt(-1));
|
|
m_screens.append(std::move(screen));
|
|
}
|
|
m_handler->handleMessage(this);
|
|
}
|
|
|
|
|
|
bool STC::LoginRequestReply::hasValidData() const
|
|
{
|
|
if (!m_handler || !m_client) return false;
|
|
QJsonObject obj = m_data.toObject();
|
|
if (obj.value(JsonKeys::REASON()).isUndefined()) return false;
|
|
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
|
if (obj.value(JsonKeys::SCREENS()).isUndefined()) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
STC::DedicatedDisconnect::DedicatedDisconnect(const QString &uuid, int userId)
|
|
: Message(nullptr, nullptr, JsonKeys::DEDICAED_DISCONNECT(), uuid, QJsonValue())
|
|
, m_userId(userId)
|
|
{
|
|
QJsonObject result;
|
|
result.insert(JsonKeys::USER_ID(), m_userId);
|
|
m_replyData = result;
|
|
}
|
|
|
|
|
|
void STC::DedicatedDisconnect::process()
|
|
{
|
|
if (!m_handler || !m_client) return;
|
|
QJsonObject obj = m_data.toObject();
|
|
m_userId = obj.value(JsonKeys::USER_ID()).toInt(-1);
|
|
m_handler->handleMessage(this);
|
|
}
|
|
|
|
|
|
bool STC::DedicatedDisconnect::hasValidData() const
|
|
{
|
|
if (!m_handler || !m_client) return false;
|
|
QJsonObject obj = m_data.toObject();
|
|
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
CTS::LoginRequest::LoginRequest(const QString &uuid, int userId, int priority, int exerciseId, const QByteArray &settingsData)
|
|
: Message(nullptr, nullptr, JsonKeys::LOGIN_REQUEST(), uuid, QJsonValue())
|
|
, m_settingsData(settingsData), m_userId(userId), m_priority(priority), m_exerciseId(exerciseId)
|
|
{
|
|
QJsonObject result;
|
|
result.insert(JsonKeys::USER_ID(), m_userId);
|
|
result.insert(JsonKeys::USER_PRIORITY(), m_priority);
|
|
result.insert(JsonKeys::EXERCISE_ID(), m_exerciseId);
|
|
result.insert(JsonKeys::SETTINGS_DATA(), QString::fromLatin1(m_settingsData.toBase64()));
|
|
m_replyData = result;
|
|
}
|
|
|
|
|
|
void CTS::LoginRequest::process()
|
|
{
|
|
if (!m_handler || !m_client) return;
|
|
QJsonObject obj = m_data.toObject();
|
|
m_userId = obj.value(JsonKeys::USER_ID()).toInt(-1);
|
|
m_priority = obj.value(JsonKeys::USER_PRIORITY()).toInt(-1);
|
|
m_exerciseId = obj.value(JsonKeys::EXERCISE_ID()).toInt(-1);
|
|
m_settingsData = QByteArray::fromBase64(obj.value(JsonKeys::SETTINGS_DATA()).toString().toLatin1());
|
|
m_handler->handleMessage(this);
|
|
}
|
|
|
|
|
|
bool CTS::LoginRequest::hasValidData() const
|
|
{
|
|
if (!m_handler || !m_client) return false;
|
|
QJsonObject obj = m_data.toObject();
|
|
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
|
if (obj.value(JsonKeys::EXERCISE_ID()).isUndefined()) return false;
|
|
if (obj.value(JsonKeys::USER_PRIORITY()).isUndefined()) return false;
|
|
if (obj.value(JsonKeys::SETTINGS_DATA()).isUndefined()) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void CTS::LogoutRequest::process()
|
|
{
|
|
if (!m_handler || !m_client) return;
|
|
m_handler->handleMessage(this);
|
|
}
|
|
|
|
|
|
bool CTS::LogoutRequest::hasValidData() const
|
|
{
|
|
if (!m_handler || !m_client) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
CTS::DisconnectRequest::DisconnectRequest(const QString &uuid, int userId)
|
|
: Message(nullptr, nullptr, JsonKeys::DISCONNECT_REQUEST(), uuid, QJsonValue())
|
|
, m_userId(userId)
|
|
{
|
|
qDebug() << " 1 m_userId = " << m_userId;
|
|
QJsonObject result;
|
|
result.insert(JsonKeys::USER_ID(), m_userId);
|
|
m_replyData = result;
|
|
}
|
|
|
|
void CTS::DisconnectRequest::process()
|
|
{
|
|
if (!m_handler || !m_client) return;
|
|
QJsonObject obj = m_data.toObject();
|
|
m_userId = obj.value(JsonKeys::USER_ID()).toInt(-1);
|
|
qDebug() << " 2 m_userId = " << m_userId;
|
|
m_handler->handleMessage(this);
|
|
}
|
|
|
|
bool CTS::DisconnectRequest::hasValidData() const
|
|
{
|
|
if (!m_handler || !m_client) return false;
|
|
QJsonObject obj = m_data.toObject();
|
|
if (obj.value(JsonKeys::USER_ID()).isUndefined()) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
ErrorMessage::ErrorMessage(const QString &uuid, const QString &reason)
|
|
: Message(nullptr, nullptr, JsonKeys::ERROR_MESSAGE(), uuid, QJsonValue())
|
|
, m_reason(reason)
|
|
{
|
|
QJsonObject result;
|
|
result.insert(JsonKeys::REASON(), m_reason);
|
|
m_replyData = result;
|
|
}
|
|
|
|
|
|
void ErrorMessage::process()
|
|
{
|
|
if (!m_handler || !m_client) return;
|
|
QJsonObject obj = m_data.toObject();
|
|
m_reason = obj.value(JsonKeys::REASON()).toString(QStringLiteral("err"));
|
|
m_handler->handleMessage(this);
|
|
}
|
|
|
|
|
|
bool ErrorMessage::hasValidData() const
|
|
{
|
|
if (!m_handler || !m_client) return false;
|
|
QJsonObject obj = m_data.toObject();
|
|
if (obj.value(JsonKeys::REASON()).isUndefined()) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|