Files
RRJServer/ServerLMS/Systems/commonclienthandler.cpp

191 lines
6.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "commonclienthandler.h"
CommonClientHandler::CommonClientHandler(QObject *parent) : QObject(parent)
{
}
void CommonClientHandler::initialize(QMap<int, ClientHandler *> *clientsMap, ProcessingSystem *processingSystem, DataParser *dataParser, Logger *logger)
{
this->clientsMap = clientsMap;
this->processingSystem = processingSystem;
this->dataParser = dataParser;
this->logger = logger;
connect(this,&CommonClientHandler::sigSendToLogger,logger,&Logger::addTextToLogger,Qt::AutoConnection);
}
void CommonClientHandler::sendNewVersionListToAllClient()
{
foreach(int idSocket,clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
if (!handler->getClient()->getIsLoggedIn()) continue;
handler->sendVersionList();
}
}
void CommonClientHandler::sendCurrentVersionToAllClient()
{
foreach(int idSocket,clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
if (!handler->getClient()->getIsLoggedIn()) continue;
handler->sendVersion();
}
}
void CommonClientHandler::slot_ListsInstructorsTraineesChanged()
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
//Проверяем, есть ли клиенты TYPE_GUI
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту обновление списков
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_ALL_LISTS;
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
}
}
void CommonClientHandler::slot_StatusTasksAMMofTraineeChanged(int trainee_id)
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
//Проверяем, есть ли клиенты TYPE_GUI
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту задачи AMM для Обучаемого (с измененным статусом)
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_TASKS_AMM_FOR_TRAINEE;
processingSystem->processingClientQueryToDB(handler, queryToDB, trainee_id);
}
}
/*
//Отправка списка задач AMM клиенту Юнити
if(ClientHandler* clientUnity = processingSystem->getUnityClientById(trainee_id))
{//Есть такой
//processingSystem->sendListTasksAMMofTraineetoClient(clientUnity, trainee_id);
}*/
}
void CommonClientHandler::slot_StatusTasksFIMofTraineeChanged(int trainee_id)
{
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
//Проверяем, есть ли клиенты TYPE_GUI
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем этому клиенту задачи FIM для Обучаемого (с измененным статусом)
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_TASKS_FIM_FOR_TRAINEE;
processingSystem->processingClientQueryToDB(handler, queryToDB, trainee_id);
}
}
/*
//Отправка списка задач FIM клиенту Юнити
if(ClientHandler* clientUnity = processingSystem->getUnityClientById(trainee_id))
{//Есть такой
//processingSystem->sendListTasksFIMofTraineetoClient(clientUnity, trainee_id);
}*/
}
void CommonClientHandler::slot_sendPacketToAllClients(PacketType packetType)
{
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
if (!handler->getClient()->getIsLoggedIn()) continue;
handler->sendPacketType(packetType);
}
}
void CommonClientHandler::slot_msgToClientFromGUI(QString login, QString text)
{
QString textMsg = text;
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(textMsg);
//Проходим все открытые сокеты, ищем нужный
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
if(handler->getClient()->getLogin() == login)
{//Отправляем ему
handler->sendXmlAnswer(byteArrayMsg);
QString peerAddress = handler->getSocket()->peerAddress().toString();
QString peerPort = QString::number(handler->getSocket()->peerPort());
QString str = "Msg To Client [" + peerAddress + ":" + peerPort + "] : " + textMsg;
emit sigSendToLogger(str);
break;
}
}
}
void CommonClientHandler::slot_msgToGUIfromClient(QString login, QString text)
{
QString textMsg = text;
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(textMsg, login);
//Проходим все открытые сокеты, ищем нужный
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);;
if(handler->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
{//Отправляем GUI-клиенту для отображения в Мессенджере
handler->sendXmlAnswer(byteArrayMsg, PacketType::TYPE_XMLANSWER);
QString peerAddress = handler->getSocket()->peerAddress().toString();
QString peerPort = QString::number(handler->getSocket()->peerPort());
QString str = "Msg From Client [" + peerAddress + ":" + peerPort + "] : " + textMsg;
emit sigSendToLogger(str);
break;
}
}
}
void CommonClientHandler::slot_sendTaskToClient(QString fullNameClient,QString textTask)
{
QByteArray byteArrayTask = dataParser->ClientAnswer()->task(textTask);
//Проходим все открытые сокеты
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
if(handler->getClient()->getFullName() == fullNameClient)
{//Отправляем ему
handler->getSocket()->write(byteArrayTask);
QString peerAddress = handler->getSocket()->peerAddress().toString();
QString peerPort = QString::number(handler->getSocket()->peerPort());
QString str = "Task To Client [" + peerAddress + ":" + peerPort + "] : " + textTask;
emit sigSendToLogger(str);
}
}
}