feat: complete delay messages

This commit is contained in:
semenov
2025-08-05 16:34:26 +03:00
parent a6022d7ec8
commit c3bd64588a
12 changed files with 51 additions and 61 deletions

View File

@@ -12,7 +12,7 @@ public:
Client(QString name, QString address, QString port,QObject *parent = nullptr):
login(""),
ready(false),
TypeClient(TypeClientAutorization::TYPE_SIMPLE)
typeClient(TypeClientAutorization::TYPE_QT_CLIENT)
{
this->name = name;
this->address = address;
@@ -57,28 +57,31 @@ public:
this->ready = ready;
}
void setUnity(bool flag)
void setUnity(TypeClientAutorization type)
{
isUnity = flag;
typeClient = type;
}
bool getIsUnity()
TypeClientAutorization GETTYPE()
{
return isUnity;
return typeClient;
}
void setTypeClient(TypeClientAutorization TypeClient)
{
this->TypeClient = TypeClient;
this->typeClient = TypeClient;
}
TypeClientAutorization getTypeClient()
{
return TypeClient;
return typeClient;
}
void changePackageResponse()
{
isUnity = !isUnity;
if (typeClient == TypeClientAutorization::TYPE_QT_CLIENT)
typeClient = TypeClientAutorization::TYPE_UNITY_CLIENT;
else if (typeClient == TypeClientAutorization::TYPE_UNITY_CLIENT)
typeClient = TypeClientAutorization::TYPE_QT_CLIENT;
}
bool operator == (Client* right)
@@ -105,8 +108,6 @@ public:
return userType;
}
QString getId()
{
return id;
@@ -127,9 +128,8 @@ private:
QString login;
bool ready;
bool isLoggedIn;
bool isUnity = false;
TypeClientAutorization TypeClient;
TypeClientAutorization typeClient;
UserType userType;
};

View File

@@ -44,7 +44,8 @@ struct SXmlAnswerTag
};
enum TypeClientAutorization{
TYPE_SIMPLE = 0,
TYPE_QT_CLIENT = 0,
TYPE_UNITY_CLIENT = 1,
TYPE_GUI = 10
};

View File

@@ -60,14 +60,14 @@ void ProcessParser::slot_read(ClientHandler *client, QByteArray array)
}
else if(xmlReader.name() == "ListTasksAMM")
{
if(client->getClient()->getIsUnity())
if(client->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{//Отчет по задаче АММ от Юнити-клиента
clientUnityTaskAMMreport(xmlReader,client, array);
}
}
else if(xmlReader.name() == "ListTasksFIM")
{
if(client->getClient()->getIsUnity())
if(client->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{//Отчет по задаче FIM от Юнити-клиента
clientUnityTaskFIMreport(xmlReader,client, array);
}
@@ -518,8 +518,6 @@ void ProcessParser::clientNotify(QXmlStreamReader &xmlReader,ClientHandler *clie
clientNotify.Code = value;
}
processingSystem->processingClientNotify(client, clientNotify);
}

View File

@@ -10,15 +10,7 @@ void ChatSystem::initialize(CommonClientHandler *commonClientHandler, DataParser
this->commonClientHandler = commonClientHandler;
this->dataParser = dataParser;
this->clientsMap = clientsMap;
clientNotSendedMessage = new QMap<QString,QStack<ClientMessage>*>;
auto stack = new QStack<ClientMessage>;
auto clientMessage1 = ClientMessage("1-0","102-0","Сообщение 1");
stack->append(clientMessage1);
auto clientMessage2 = ClientMessage("1-0","102-0","Сообщение 2");
stack->append(clientMessage2);
clientNotSendedMessage->insert("102", stack);
clientNotSendedMessage = new QMap<QString,QQueue<ClientMessage>*>;
}
bool ChatSystem::sendTo(ClientMessage message)
@@ -26,16 +18,14 @@ bool ChatSystem::sendTo(ClientMessage message)
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(message.From,message.To,message.Text);
auto result = message.To.split("-");
//qt - инструктор
//qt - клиент нельзя
//unity - можно
foreach(int idSocket, clientsMap->keys())
{
ClientHandler *handler = clientsMap->value(idSocket);
QString userType = QString::number(static_cast<int>(handler->getClient()->getAccessType()));
if(handler->getClient()->getId() == result[0] &&
userType == result[1])
userType == result[1] &&
handler->getClient()->getTypeClient() != TypeClientAutorization::TYPE_QT_CLIENT)
{
handler->sendXmlAnswer(byteArrayMsg, PacketType::TYPE_XMLANSWER);
QString str = "Msg From Client [" + message.From + " to " + message.To + "] : " + message.Text;
@@ -60,8 +50,8 @@ bool ChatSystem::sendMessage(ClientMessage message)
}
else
{
auto stack = new QStack<ClientMessage>;
stack->append(message);
auto stack = new QQueue<ClientMessage>;
stack->enqueue(message);
clientNotSendedMessage->insert(message.To, stack);
}
@@ -76,11 +66,11 @@ void ChatSystem::sendOldMessages(QString id)
qDebug() << id;
if (clientNotSendedMessage->contains(id))
{
auto stack = clientNotSendedMessage->find(id).value();
auto queue = clientNotSendedMessage->find(id).value();
while (!stack->isEmpty())
while (!queue->isEmpty())
{
auto message = stack->pop();
auto message = queue->dequeue();
sendTo(message);
}
}

View File

@@ -20,7 +20,7 @@ private:
CommonClientHandler *commonClientHandler;
DataParser *dataParser;
QMap<int, ClientHandler*> *clientsMap;
QMap<QString,QStack<ClientMessage>*> *clientNotSendedMessage;
QMap<QString,QQueue<ClientMessage>*> *clientNotSendedMessage;
bool sendTo(ClientMessage message);
};

View File

@@ -53,7 +53,7 @@ void CommonClientHandler::slot_ListsInstructorsTraineesChanged()
processingSystem->processingClientQueryToDB(handler, queryToDB);
}
if(handler->getClient()->getIsUnity())
if(handler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
ClientQueryToDB queryToDB;
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_CONTACT_LIST;

View File

@@ -528,7 +528,7 @@ void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotif
else if(clientNotify.Code == commandStartTimerClient)
{
//Фиксируем время входа Юнити-клиента
if (client->getClient()->getIsUnity())
if (client->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
processingEntryUnityClient(client);
}
@@ -538,7 +538,7 @@ void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotif
qDebug() << "processing thread: " << QThread::currentThreadId();
//Фиксируем время выхода Юнити-клиента
if (client->getClient()->getIsUnity())
if (client->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
processingExitUnityClient(client);
}
@@ -670,7 +670,7 @@ void ProcessingSystem::sendTaskFIMToClient(ClientHandler *client, int id_trainee
void ProcessingSystem::sendTaskListToUnity(ClientHandler *client)
{
//Отправка списков задач клиенту Юнити
if(client->getClient()->getIsUnity())
if(client->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
QString login = client->getClient()->getLogin();
int id_trainee = providerDBLMS->getIdTraineeByLogin(login);
@@ -697,7 +697,7 @@ ClientHandler *ProcessingSystem::getUnityClientById(int id)
ClientHandler *handler = server->getClientsMap().value(idSocket);
if(handler->getClient()->getLogin() == login)
{
if(handler->getClient()->getIsUnity())
if(handler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
return handler;
}

View File

@@ -61,7 +61,7 @@ void RecognizeSystem::recognize()
continue;
}
if(client->getIsUnity())
if(client->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
char *read = new char[4];
stream.readRawData(read,4);
@@ -110,7 +110,7 @@ void RecognizeSystem::recognize()
if (packetType == PacketType::TYPE_XMLANSWER)
{
if(clientHandler->getClient()->getIsUnity())
if(clientHandler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
data = socket->readAll();
}
@@ -130,7 +130,7 @@ void RecognizeSystem::recognize()
if(packetType == PacketType::TYPE_BIGXML)
{
if (clientHandler->getClient()->getIsUnity())
if (clientHandler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
char *readBuffer = new char[4];
socket->read(readBuffer,4);
@@ -183,7 +183,7 @@ void RecognizeSystem::recognize()
if(packetType == PacketType::TYPE_FOLDER) //создание папок
{
if(client->getIsUnity())
if(client->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
filePath = socket->readAll();
filePath = Tools::createSharedPath(filePath);
@@ -215,7 +215,7 @@ void RecognizeSystem::recognize()
if (packetType == PacketType::TYPE_FILE) //выгрузка одного файла
{
if(client->getIsUnity())
if(client->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
DataInfo *currentFileData = updateController->getCurrentDataInfo();
filePath = currentFileData->path;
@@ -443,13 +443,13 @@ void RecognizeSystem::packetTypeInit(PacketType packet,Client *client)
{
if(packet == PacketType::TYPE_QT)
{
client->setUnity(false);
client->setUnity(TypeClientAutorization::TYPE_QT_CLIENT);
qDebug() << "ConnectionType isUnity: " << client->getIsUnity();
qDebug() << "ConnectionType isUnity: " << client->GETTYPE();
}
else if (packet == PacketType::TYPE_UNITY)
{
client->setUnity(true);
client->setUnity(TypeClientAutorization::TYPE_UNITY_CLIENT);
//Фиксируем время входа Юнити-клиента
}

View File

@@ -22,7 +22,7 @@ void SendSystem::initialize(DataParser *dataParser,Logger *logger)
void SendSystem::setClient(Client *client,QTcpSocket *socket)
{
this->socket = socket;
this->isUnity = client->getIsUnity();
this->type = client->GETTYPE();
this->client = client;
isSendStopped = false;
}
@@ -85,7 +85,8 @@ void SendSystem::sendFileBlockByteArray(QByteArray array, PacketType packetType)
{
qDebug() << "sendFileBlockByteArray thread: " << QThread::currentThreadId();
if(!client->getIsUnity())
if(client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
@@ -193,7 +194,8 @@ void SendSystem::sendDeleteBlock(QString path)
void SendSystem::sendPacketType(PacketType packetType)
{
if(!client->getIsUnity())
if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{
QDataStream stream(socket);
@@ -225,7 +227,8 @@ void SendSystem::sendNotify(QString notify)
void SendSystem::sendXmlAnswer(QByteArray array, PacketType packetType)
{
qDebug() << "SendSystemThread: " << QThread::currentThreadId();
if(!client->getIsUnity())
if (client->GETTYPE() == TypeClientAutorization::TYPE_QT_CLIENT ||
client->GETTYPE() == TypeClientAutorization::TYPE_GUI)
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);

View File

@@ -63,9 +63,7 @@ private:
quint64 fileSize;
int countSend;
bool isSendStopped;
bool isUnity;
TypeClientAutorization type;
};
#endif // SENDSYSTEM_H

View File

@@ -136,7 +136,7 @@ bool ServerLMSWidget::stopServer()
ClientHandler* clientHandlerOpen = clientsMap[idSocket];
//Фиксируем время выхода Юнити-клиента
if(clientHandlerOpen->getClient()->getIsUnity())
if(clientHandlerOpen->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{
processingSystem->processingExitUnityClient(clientHandlerOpen);
}