From 2772c3aabae3262ebbfc03c7fefcc6a52231c53f Mon Sep 17 00:00:00 2001 From: krivoshein Date: Wed, 21 Jan 2026 15:44:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B0=20=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BA-=D0=B2.=20=D0=91=D0=BB=D0=BE=D0=BA=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=B0=D1=8F.=20=D0=9C=D0=BD=D0=BE=D0=B6.=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=83=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../connectorToServer/Core/dataparser.cpp | 3 +- .../connectorToServer/Core/dataparser.h | 2 +- .../Core/recognizesystem.cpp | 4 +- .../connectorToServer/Core/recognizesystem.h | 1 - .../connectorToServer/connectortoserver.cpp | 1 - .../connectorToServer/connectortoserver.h | 3 +- .../connectortoserver_Send.cpp | 4 +- .../instructors/viewerinstructors.cpp | 4 +- .../settings/dialogsettings.cpp | 6 ++- .../settings/dialogversioncontrol.cpp | 23 ++++----- .../settings/dialogversioncontrol.h | 1 - .../trainees/viewertrainees.cpp | 4 +- LibServer/Systems/Parsers/processparser.cpp | 6 ++- LibServer/Systems/commonclienthandler.cpp | 2 +- LibServer/Systems/commonclienthandler.h | 8 ++- LibServer/Systems/processingsystem.cpp | 8 ++- LibServer/Systems/processingsystem.h | 2 +- LibServer/Systems/recognizesystem.cpp | 2 +- LibServer/Systems/updatecontroller.cpp | 19 +++---- LibServer/Systems/updatecontroller.h | 3 ++ .../multithreadserver/multithreadserver.cpp | 51 +++++++++++++++++-- .../multithreadserver/multithreadserver.h | 26 +++++++--- LibServer/providerdblms/providerdblms.cpp | 8 +-- LibServer/providerdblms/providerdblms.h | 2 +- LibServer/serverlmswidget.cpp | 40 ++++++--------- LibServer/serverlmswidget.h | 4 +- 26 files changed, 146 insertions(+), 91 deletions(-) diff --git a/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.cpp b/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.cpp index 0ff30c5..f4c03aa 100644 --- a/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.cpp +++ b/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.cpp @@ -294,7 +294,7 @@ QByteArray DataParser::createDeAuthMessage(ClientDeAutorization *deAuth) return array; } -QByteArray DataParser::createQueryBlockAuth(bool block) +QByteArray DataParser::createQueryBlockAuth(bool block, QString type) { QByteArray array; QXmlStreamWriter xmlWriter(&array); @@ -304,6 +304,7 @@ QByteArray DataParser::createQueryBlockAuth(bool block) xmlWriter.writeStartElement("BlockAuth"); xmlWriter.writeAttribute("Block", block ? "1" : "0"); + xmlWriter.writeAttribute("type", type); xmlWriter.writeEndElement(); xmlWriter.writeEndElement(); diff --git a/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.h b/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.h index 5730424..6e9fe3f 100644 --- a/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.h +++ b/LibInstructorsAndTrainees/connectorToServer/Core/dataparser.h @@ -29,7 +29,7 @@ public: QByteArray createQueryListSubProcMessage(QString dmCode); QByteArray createDeAuthMessage(ClientDeAutorization *deAuth); - QByteArray createQueryBlockAuth(bool block); + QByteArray createQueryBlockAuth(bool block, QString type); void createAuthData(ServerAuthorization *serverAuth); void createAuthDataOffline(QString username,QString pass); diff --git a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp index c8bf2af..ae334ca 100644 --- a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp +++ b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.cpp @@ -260,12 +260,12 @@ void RecognizeSystem::recognize(QTcpSocket *socket) if(packetType == PacketType::BUSY) { - emit sigAnimationActivated(true); + //emit sigAnimationActivated(true); } if(packetType == PacketType::FREE) { - emit sigAnimationActivated(false); + //emit sigAnimationActivated(false); } if(packetType == PacketType::HASH_READY) diff --git a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h index d731718..dfc3351 100644 --- a/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h +++ b/LibInstructorsAndTrainees/connectorToServer/Core/recognizesystem.h @@ -57,7 +57,6 @@ signals: void sigShowServerDataList(QList *versions); void sigSetVersion(StreamingVersionData* serverVersion); void sigNotifyVersionControl(QString text); - void sigAnimationActivated(bool flag); void sigHashReady(); void sigAnswerQuerySubProc(QList listSubProc, QString parentTask_dmCode); diff --git a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp index 7f27b0c..e5aeaf7 100644 --- a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp +++ b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.cpp @@ -168,7 +168,6 @@ void ConnectorToServer::bindConnection() connect(recognizeSystem,&RecognizeSystem::signal_AnswerDocsChanged,this,&ConnectorToServer::slot_AnswerDocsChanged); connect(recognizeSystem, &RecognizeSystem::sigSetVersion, this, &ConnectorToServer::signal_SetVersion); - connect(recognizeSystem, &RecognizeSystem::sigAnimationActivated, this, &ConnectorToServer::signal_AnimationActivated); connect(this, &ConnectorToServer::signal_SendCopyVersion, sendSystem, &SendSystem::sendCopyVersion); connect(this, &ConnectorToServer::signal_SendDeleteVersion, sendSystem, &SendSystem::sendDeleteVersion); diff --git a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h index cace4d2..29202b3 100644 --- a/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h +++ b/LibInstructorsAndTrainees/connectorToServer/connectortoserver.h @@ -47,7 +47,7 @@ public: bool sendQueryTasksXML(QString type); bool sendQueryListSubProc(QString dmCode); - bool sendQueryBlockAuth(bool block); + bool sendQueryBlockAuth(bool block, QString type); void sendShowVersionSelect(); bool sendClientNotify(QString command); @@ -149,7 +149,6 @@ signals: void signal_AnswerDocsChanged(); void signal_SetVersion(StreamingVersionData* serverVersion); - void signal_AnimationActivated(bool flag); void signal_SendDeleteVersion(StreamingVersionData *streaming); void signal_SendSwitchVersion(StreamingVersionData *selectVersion); diff --git a/LibInstructorsAndTrainees/connectorToServer/connectortoserver_Send.cpp b/LibInstructorsAndTrainees/connectorToServer/connectortoserver_Send.cpp index be087ed..f3f93b1 100644 --- a/LibInstructorsAndTrainees/connectorToServer/connectortoserver_Send.cpp +++ b/LibInstructorsAndTrainees/connectorToServer/connectortoserver_Send.cpp @@ -95,14 +95,14 @@ bool ConnectorToServer::sendQueryListSubProc(QString dmCode) return true; } -bool ConnectorToServer::sendQueryBlockAuth(bool block) +bool ConnectorToServer::sendQueryBlockAuth(bool block, QString type) { if (!client->getIsConnected()) { return false; } - QByteArray array = dataParser->createQueryBlockAuth(block); + QByteArray array = dataParser->createQueryBlockAuth(block, type); emit sigSendAnswerToServer(array); return true; diff --git a/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp b/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp index 41e02fb..9491cb1 100644 --- a/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp +++ b/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp @@ -77,7 +77,7 @@ void ViewerInstructors::slot_receiveMessage(ClientMessage clientMessage) void ViewerInstructors::on_btnEditorInstructors_clicked() { - connectorToServer->sendQueryBlockAuth(true); + connectorToServer->sendQueryBlockAuth(true, "EditorInstructors"); dlgRedactor = new DialogRedactorInstructors(connectorToServer, adminMode, this); dlgRedactor->exec(); @@ -91,7 +91,7 @@ void ViewerInstructors::on_btnEditorInstructors_clicked() if(authComplited) loadInstructorsFromDB(); - connectorToServer->sendQueryBlockAuth(false); + connectorToServer->sendQueryBlockAuth(false, "EditorInstructors"); } void ViewerInstructors::on_treeWidgetCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) diff --git a/LibInstructorsAndTrainees/settings/dialogsettings.cpp b/LibInstructorsAndTrainees/settings/dialogsettings.cpp index 07d8d9b..2798cce 100644 --- a/LibInstructorsAndTrainees/settings/dialogsettings.cpp +++ b/LibInstructorsAndTrainees/settings/dialogsettings.cpp @@ -214,6 +214,8 @@ void DialogSettings::on_btnSetVersion_clicked() if(connectorToServer) if(connectorToServer->getIsConnected()) { + connectorToServer->sendQueryBlockAuth(true, "VersionControl"); + dlgVersionControl = new DialogVersionControl(connectorToServer, this); dlgVersionControl->initialize(connectorToServer->getLoginName()); dlgVersionControl->exec(); @@ -222,7 +224,9 @@ void DialogSettings::on_btnSetVersion_clicked() { delete dlgVersionControl; dlgVersionControl = nullptr; - } + } + + connectorToServer->sendQueryBlockAuth(false, "VersionControl"); } } diff --git a/LibInstructorsAndTrainees/settings/dialogversioncontrol.cpp b/LibInstructorsAndTrainees/settings/dialogversioncontrol.cpp index db203b3..3cf58a8 100644 --- a/LibInstructorsAndTrainees/settings/dialogversioncontrol.cpp +++ b/LibInstructorsAndTrainees/settings/dialogversioncontrol.cpp @@ -58,7 +58,6 @@ void DialogVersionControl::initialize(QString authorName) this->authorName = authorName; connect (connectorToServer, &ConnectorToServer::signal_SetVersion, this, &DialogVersionControl::slot_SetVersion); - connect(connectorToServer, &ConnectorToServer::signal_AnimationActivated, this, &DialogVersionControl::slot_activateLoadAnimation); connect(connectorToServer, &ConnectorToServer::signal_showServerList, this, &DialogVersionControl::slot_showServerList); connect(connectorToServer, &ConnectorToServer::signal_NotifyVersionControl, this, &DialogVersionControl::slot_NotifyVersionControl); @@ -69,6 +68,7 @@ void DialogVersionControl::initialize(QString authorName) connect(this, &DialogVersionControl::signal_getVersion, connectorToServer, &ConnectorToServer::slot_getVersion); + waitAnimationWidget->showWithPlay(); emit signal_getVersion(); } @@ -124,6 +124,7 @@ void DialogVersionControl::sendCopyEmit(QString newName) } versionContainer->setLocalVersionData(selectedVersion); + waitAnimationWidget->showWithPlay(); emit sigSendCopyVersion(result); } @@ -144,6 +145,7 @@ void DialogVersionControl::on_createDuplicateButton_clicked() case QDialog::Accepted: { QString newName = dlgNewVersion->getNewName(); + waitAnimationWidget->showWithPlay(); sendCopyEmit(newName); break; } @@ -171,6 +173,7 @@ void DialogVersionControl::on_deleteVersionButton_clicked() if(SpecMsgBox::WarningYesNo(this, tr("The deletion will be irrevocable.\nDelete it anyway?")) == QDialog::Accepted) { + waitAnimationWidget->showWithPlay(); emit sigSendDeleteVersion(selectedVersion); } } @@ -186,24 +189,14 @@ void DialogVersionControl::on_switchServerVersionButton_clicked() //versionContainer->setServerVersionData(selectedVersion); //ui->verValue->setText(selectedVersion->getViewName()); + waitAnimationWidget->showWithPlay(); emit sigSendSwitchVersion(selectedVersion); } -void DialogVersionControl::slot_activateLoadAnimation(bool flag) -{ - if (flag) - { - waitAnimationWidget->showWithPlay(); - } - else - { - waitAnimationWidget->hideWithStop(); - } -} - void DialogVersionControl::slot_showServerList(QList *serverList) { fillView(serverList); + waitAnimationWidget->hideWithStop(); } void DialogVersionControl::slot_SetVersion(StreamingVersionData *serverVersion) @@ -215,11 +208,15 @@ void DialogVersionControl::slot_SetVersion(StreamingVersionData *serverVersion) connectorToServer->sendShowVersionSelect(); flGetVersion = true; + + waitAnimationWidget->hideWithStop(); } void DialogVersionControl::slot_NotifyVersionControl(QString text) { SpecMsgBox::WarningClose(this, text); + + waitAnimationWidget->hideWithStop(); } void DialogVersionControl::resizeEvent(QResizeEvent *event) diff --git a/LibInstructorsAndTrainees/settings/dialogversioncontrol.h b/LibInstructorsAndTrainees/settings/dialogversioncontrol.h index fe697d9..fbf253f 100644 --- a/LibInstructorsAndTrainees/settings/dialogversioncontrol.h +++ b/LibInstructorsAndTrainees/settings/dialogversioncontrol.h @@ -36,7 +36,6 @@ private slots: void on_verListView_itemClicked(QListWidgetItem *item); private slots: - void slot_activateLoadAnimation(bool flag); void slot_showServerList(QList *serverList); void slot_SetVersion(StreamingVersionData* serverVersion); void slot_NotifyVersionControl(QString text); diff --git a/LibInstructorsAndTrainees/trainees/viewertrainees.cpp b/LibInstructorsAndTrainees/trainees/viewertrainees.cpp index e36b748..bb88d01 100644 --- a/LibInstructorsAndTrainees/trainees/viewertrainees.cpp +++ b/LibInstructorsAndTrainees/trainees/viewertrainees.cpp @@ -111,7 +111,7 @@ void ViewerTrainees::slot_receiveMessage(ClientMessage clientMessage) void ViewerTrainees::on_btnEditorTrainees_clicked() { - connectorToServer->sendQueryBlockAuth(true); + connectorToServer->sendQueryBlockAuth(true, "EditorTrainees"); dlgRedactor = new DialogRedactorTrainees(connectorToServer, adminMode, this); dlgRedactor->exec(); @@ -125,7 +125,7 @@ void ViewerTrainees::on_btnEditorTrainees_clicked() if(authComplited) loadTraineesFromDB(); - connectorToServer->sendQueryBlockAuth(false); + connectorToServer->sendQueryBlockAuth(false, "EditorTrainees"); } void ViewerTrainees::on_btnPersonalCard_clicked() diff --git a/LibServer/Systems/Parsers/processparser.cpp b/LibServer/Systems/Parsers/processparser.cpp index bf7540c..f272608 100644 --- a/LibServer/Systems/Parsers/processparser.cpp +++ b/LibServer/Systems/Parsers/processparser.cpp @@ -367,6 +367,7 @@ void ProcessParser::clientDeAuth(QXmlStreamReader &xmlReader,ClientHandler *clie void ProcessParser::clientBlockAuth(QXmlStreamReader &xmlReader, ClientHandler *client) { bool block = false; + QString type = ""; /*Перебираем все атрибуты тега*/ foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()) @@ -377,9 +378,12 @@ void ProcessParser::clientBlockAuth(QXmlStreamReader &xmlReader, ClientHandler * if(name == "Block") block = (value == "1") ? true : false; + + if(name == "type") + type = value; } - processingSystem->processingClientBlockAuth(client, block); + processingSystem->processingClientBlockAuth(client, block, type); } void ProcessParser::queryToDb(QXmlStreamReader &xmlReader,ClientHandler *client, QByteArray array) diff --git a/LibServer/Systems/commonclienthandler.cpp b/LibServer/Systems/commonclienthandler.cpp index 6e20894..edae0f8 100644 --- a/LibServer/Systems/commonclienthandler.cpp +++ b/LibServer/Systems/commonclienthandler.cpp @@ -117,7 +117,7 @@ void CommonClientHandler::slot_sendPacketToAllClients(PacketType packetType) Logger::instance().log("AllSending " + handler->getClient()->getLogin() + " " + enumToString(packetType)); } - emit sigSetServerState(packetType); + //emit sigSetServerState(packetType); } diff --git a/LibServer/Systems/commonclienthandler.h b/LibServer/Systems/commonclienthandler.h index cef1732..763668c 100644 --- a/LibServer/Systems/commonclienthandler.h +++ b/LibServer/Systems/commonclienthandler.h @@ -22,13 +22,17 @@ public: void slot_ListsInstructorsTraineesChanged(); void slot_StatusTasksAMMofTraineeChanged(int trainee_id); void slot_StatusTasksFIMofTraineeChanged(int trainee_id); - void slot_sendPacketToAllClients(PacketType packetType); + bool slotSendMessage(QString loginFrom, QString loginTo, QString text); void slot_sendTaskToClient(QString fullNameClient, QString textTask); void slot_DocsChanged(); + +public slots: + void slot_sendPacketToAllClients(PacketType packetType); + signals: - void sigSetServerState(PacketType packetType); + //void sigSetServerState(PacketType packetType); private: QMap *clientsMap; ProcessingSystem *processingSystem; diff --git a/LibServer/Systems/processingsystem.cpp b/LibServer/Systems/processingsystem.cpp index ef8398f..7474693 100644 --- a/LibServer/Systems/processingsystem.cpp +++ b/LibServer/Systems/processingsystem.cpp @@ -164,6 +164,8 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli else if(providerDBLMS->deAuthorizationInstructor(clientDeAutorization.Login)) {//ДеАвторизуется инструктор + QString fullName = client->getClient()->getFullName(); + client->getClient()->setLogin(""); client->getClient()->setAccessType(UserType::NONE); client->getClient()->setIsLoggedIn(false); @@ -172,6 +174,8 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli arrayAnswer = dataParser->ClientAnswer()->deAuthorization(true, clientDeAutorization.Login); client->sendXmlAnswer(arrayAnswer); + providerDBLMS->signal_BlockAutorization(false, fullName, "DeAuthorizationInstructor"); + //Извещаем об изменениях в авторизации emit sigListsInstructorsTraineesChanged(); } @@ -182,9 +186,9 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli } } -void ProcessingSystem::processingClientBlockAuth(ClientHandler *client, bool block) +void ProcessingSystem::processingClientBlockAuth(ClientHandler *client, bool block, QString type) { - emit providerDBLMS->signal_BlockAutorization(block); + bool res = emit providerDBLMS->signal_BlockAutorization(block, client->getClient()->getFullName(), type); } //упращенная деавторизация при выключении сервера diff --git a/LibServer/Systems/processingsystem.h b/LibServer/Systems/processingsystem.h index 2c50e36..9da41a9 100644 --- a/LibServer/Systems/processingsystem.h +++ b/LibServer/Systems/processingsystem.h @@ -35,7 +35,7 @@ public: void processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization); void processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization); - void processingClientBlockAuth(ClientHandler *client, bool block); + void processingClientBlockAuth(ClientHandler *client, bool block, QString type); void processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB, int id = 0, void* data = nullptr); void processingClientQueryTasksXML(ClientHandler *client, ClientQueryTasksXML clientQueryTasksXML); void processingClientQueryListSubProc(ClientHandler *client, QString dmCode); diff --git a/LibServer/Systems/recognizesystem.cpp b/LibServer/Systems/recognizesystem.cpp index 1b65e5f..0d06400 100644 --- a/LibServer/Systems/recognizesystem.cpp +++ b/LibServer/Systems/recognizesystem.cpp @@ -411,7 +411,7 @@ void RecognizeSystem::recognize() } emit sigCopyVersion(result[0],result[1],result[2]); - sendSystem->sendPacketType(PacketType::BUSY); + //sendSystem->sendPacketType(PacketType::BUSY); //KAV Вроде, это не нужно (дублируется)? } if(packetType == PacketType::DELETE_DATA_VERSION) diff --git a/LibServer/Systems/updatecontroller.cpp b/LibServer/Systems/updatecontroller.cpp index 0a95869..48772bb 100644 --- a/LibServer/Systems/updatecontroller.cpp +++ b/LibServer/Systems/updatecontroller.cpp @@ -44,7 +44,7 @@ void UpdateController::initialize(CommonClientHandler *commonClientHandler,DataP void UpdateController::changeAssetVersion(QString versionName) { - commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); qDebug() << "UpdateController thread ID " << QThread::currentThreadId(); currentStreamingPath = assetManager->setVersion(versionName); setUpCurrentServerHash(); @@ -52,21 +52,21 @@ void UpdateController::changeAssetVersion(QString versionName) commonClientHandler->slot_sendPacketToAllClients(PacketType::HASH_READY); commonClientHandler->sendCurrentVersionToAllClient(); - commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); } void UpdateController::createCopyVersion(QString versionName,QString newVersionName,QString author) { - commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); assetManager->createCopyVersion(versionName,newVersionName,author); - commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); } void UpdateController::deleteAssetVersion(QString versionName) { - commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); assetManager->deleteVersion(versionName); - commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); } void UpdateController::compareFiles(ClientHandler* handler, QByteArray array) @@ -94,7 +94,8 @@ void UpdateController::calculateFullHash() QElapsedTimer timer; timer.start(); qDebug() << "Start calculate... "; - commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); + //commonClientHandler->slot_sendPacketToAllClients(PacketType::BUSY); + bool res = emit signal_BlockAutorization(true, "SERVER", "CalculateFullHash"); //auto *list = calculateHash(buildPath); hashCalculator->calculateHashes(buildPath); @@ -104,8 +105,8 @@ void UpdateController::calculateFullHash() calculateSharedHash(); Logger::instance().log("Calculate hash complete"); qDebug() << "Calculate time " << timer.elapsed(); - commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); - + //commonClientHandler->slot_sendPacketToAllClients(PacketType::FREE); + res = emit signal_BlockAutorization(false, "SERVER", "CalculateFullHash"); } void UpdateController::calculateFullHashWithSetup() diff --git a/LibServer/Systems/updatecontroller.h b/LibServer/Systems/updatecontroller.h index 6231cc6..b8d1ff0 100644 --- a/LibServer/Systems/updatecontroller.h +++ b/LibServer/Systems/updatecontroller.h @@ -71,6 +71,9 @@ signals: void sigInitializeFinished(); + //сигнал о блокировке авторизации + bool signal_BlockAutorization(bool block, QString whoFullName, QString type); + private: QList clientDataList; QList serverDataList; diff --git a/LibServer/multithreadserver/multithreadserver.cpp b/LibServer/multithreadserver/multithreadserver.cpp index 5fa5b78..0e52572 100644 --- a/LibServer/multithreadserver/multithreadserver.cpp +++ b/LibServer/multithreadserver/multithreadserver.cpp @@ -35,15 +35,17 @@ bool MultiThreadServer::startServer() //connect(tcpServer, &QTcpServer::newConnection, this, &ServerLMSWidget::slotNewConnection,Qt::AutoConnection); if(!listen(QHostAddress::Any, hostPort)) - { - Logger::instance().log("SERVER: start ERROR"); + { stateServer = stoped; + Logger::instance().log("SERVER: start ERROR"); return false; } else { - Logger::instance().log("SERVER: start OK"); + stateServer = started; + slot_BlockAutorization(false, "SERVER", "StartServer"); + Logger::instance().log("SERVER: start OK"); return true; } } @@ -59,7 +61,8 @@ bool MultiThreadServer::stopServer() //Закрываем сервер close(); - stateServer = stoped; + stateServer = stoped; + slot_BlockAutorization(true, "SERVER", "StopServer"); Logger::instance().log("SERVER: stop OK"); return true; } @@ -94,8 +97,13 @@ void MultiThreadServer::disableClients() handler->sigSendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER); QString str = QString(arrayAnswer); + + QString fullName = handler->getClient()->getFullName(); + processingSystem->processingClientDeAutorization(handler->getClient()->getLogin()); + slot_BlockAutorization(false, fullName, "DisableClient"); + handler->sigSocketClose(); //clientsMap.remove(idSocket); removeClient(idSocket); @@ -119,8 +127,12 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo ClientDeAutorization clientDeAutorization; clientDeAutorization.Login = login; + + //QString fullName = client->getClient()->getFullName(); + processingSystem->processingClientDeAutorization(client, clientDeAutorization); + //slot_BlockAutorization(false, fullName, "DisconnectClient"); removeClient(idSocket); delete client; continue; @@ -135,6 +147,37 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(login); } +bool MultiThreadServer::slot_BlockAutorization(bool block, QString whoFullName, QString type) +{ + bool res = true; + bool blockRes = false; + + if(block) + { + this->blockAutorization(); + blockersMap.insert(whoFullName, type); + blockRes = true; + } + else + { + blockersMap.take(whoFullName); + if(!blockersMap.count()) + this->unBlockAutorization(); + } + + if(res) + { + if(blockRes) + emit signal_sendPacketToAllClients(PacketType::BUSY); + else + emit signal_sendPacketToAllClients(PacketType::FREE); + + emit signal_BlockAutorizationIndicate(block, whoFullName, type); + } + + return res; +} + void MultiThreadServer::removeClient(int idSocket) { clientsMap->remove(idSocket); diff --git a/LibServer/multithreadserver/multithreadserver.h b/LibServer/multithreadserver/multithreadserver.h index 3636478..a2f5b2c 100644 --- a/LibServer/multithreadserver/multithreadserver.h +++ b/LibServer/multithreadserver/multithreadserver.h @@ -21,14 +21,7 @@ public: bool startServer(); bool stopServer(); - void blockAutorization() - { - stateBlockAutorization = blocked; - } - void unBlockAutorization() - { - stateBlockAutorization = unblocked; - } + EStateBlockAutorization getStateBlockAutorization() const { return stateBlockAutorization; @@ -37,13 +30,29 @@ public: { return stateServer; } + +private: + void blockAutorization() + { + stateBlockAutorization = blocked; + } + void unBlockAutorization() + { + stateBlockAutorization = unblocked; + } + signals: void sigInitClient(int descriptor, ServerLMSWidget *serverWidget, UpdateController *updateController, DataParser *dataParser); void signalStopSendFile(); + void signal_BlockAutorizationIndicate(bool block, QString whoFullName, QString type); + void signal_sendPacketToAllClients(PacketType packetType); + public slots: void slotDisconnectClient(QString peerAddress, QString peerPort); + + bool slot_BlockAutorization(bool block, QString whoFullName, QString type); protected: void incomingConnection(qintptr handle) override; @@ -57,6 +66,7 @@ private: EStateServer stateServer; EStateBlockAutorization stateBlockAutorization; + QMap blockersMap; void removeClient(int idSocket); void addClient(qintptr descriptor, ClientHandler *client); diff --git a/LibServer/providerdblms/providerdblms.cpp b/LibServer/providerdblms/providerdblms.cpp index 8707b58..8353ff4 100644 --- a/LibServer/providerdblms/providerdblms.cpp +++ b/LibServer/providerdblms/providerdblms.cpp @@ -24,7 +24,7 @@ bool ProviderDBLMS::ConnectionToDB() { if(dbLMS->connectionToDB()) { - Q_EMIT signal_BlockAutorization(false); + bool res = Q_EMIT signal_BlockAutorization(false, "SERVER", "DisConnectionDB"); mtxAccess.unlock(); return true; @@ -44,7 +44,7 @@ void ProviderDBLMS::DisConnectionFromDB() mtxAccess.lock(); if(dbLMS->DBisConnected()) { - Q_EMIT signal_BlockAutorization(true); + bool res = Q_EMIT signal_BlockAutorization(true, "SERVER", "DisConnectionDB"); dbLMS->disConnectionFromDB(); } @@ -230,12 +230,12 @@ bool ProviderDBLMS::deAuthorizationAll() return false; } - Q_EMIT signal_BlockAutorization(true); + bool res = Q_EMIT signal_BlockAutorization(true, "SERVER", "DeAuthorizationAll"); bool res1 = dbLMS->deAuthorizationAllTrainees(); bool res2 = dbLMS->deAuthorizationAllInstructors(); - Q_EMIT signal_BlockAutorization(false); + res = Q_EMIT signal_BlockAutorization(false, "SERVER", "DeAuthorizationAll"); mtxAccess.unlock(); return res1 && res2; diff --git a/LibServer/providerdblms/providerdblms.h b/LibServer/providerdblms/providerdblms.h index bda33fb..5e9c298 100644 --- a/LibServer/providerdblms/providerdblms.h +++ b/LibServer/providerdblms/providerdblms.h @@ -72,7 +72,7 @@ public: Q_SIGNALS: //сигнал о блокировке авторизации - void signal_BlockAutorization(bool block); + bool signal_BlockAutorization(bool block, QString whoFullName, QString type); signals: void signal_ErrorPostgreSQL(QString text); diff --git a/LibServer/serverlmswidget.cpp b/LibServer/serverlmswidget.cpp index 72d133b..e97900f 100644 --- a/LibServer/serverlmswidget.cpp +++ b/LibServer/serverlmswidget.cpp @@ -191,17 +191,17 @@ void ServerLMSWidget::start() startInitialization_step0(); } -void ServerLMSWidget::slot_BlockAutorization(bool block) +void ServerLMSWidget::slot_BlockAutorizationIndicate(bool block, QString whoFullName, QString type) { if(block) { - server->blockAutorization(); - Logger::instance().log("Autorization is blocked"); + //server->blockAutorization(); + Logger::instance().log(QString("Server BLOCK from: %1 [type: %2]").arg(whoFullName, type)); } else { - server->unBlockAutorization(); - Logger::instance().log("Autorization is unblocked"); + //server->unBlockAutorization(); + Logger::instance().log(QString("Server UNBLOCK from: %1 [type: %2]").arg(whoFullName, type)); } updateStateOnlyServer(); } @@ -222,9 +222,9 @@ void ServerLMSWidget::on_btnStartServer_clicked() ui->btnStartServer->setEnabled(false); ui->btnStopServer->setEnabled(true); - slot_BlockAutorization(false); + //slot_BlockAutorizationIndicate(false, "SERVER"); - updateStateOnlyServer(); + //updateStateOnlyServer(); emit signal_Tray_ShowMessage(tr("Server is started!")); @@ -240,9 +240,9 @@ void ServerLMSWidget::on_btnStopServer_clicked() ui->btnStopServer->setEnabled(false); ui->btnStartServer->setEnabled(true); - slot_BlockAutorization(true); + //slot_BlockAutorizationIndicate(true, "SERVER"); - updateStateOnlyServer(); + //updateStateOnlyServer(); emit signal_Tray_ShowMessage(tr("Server is stoped!")); @@ -298,20 +298,6 @@ void ServerLMSWidget::on_btnSettings_clicked() } } -void ServerLMSWidget::slot_trySetServerState(PacketType packetType) -{ - if (packetType == PacketType::BUSY) - { - server->blockAutorization(); - updateStateOnlyServer(); - } - else if (packetType == PacketType::FREE) - { - server->unBlockAutorization(); - updateStateOnlyServer(); - } -} - void ServerLMSWidget::setLanguageInterfase() { ServerDBSettings settings; @@ -366,7 +352,7 @@ void ServerLMSWidget::startInitialization_step0() providerDBLMS = new ProviderDBLMS(this); connect(providerDBLMS, &ProviderDBLMS::signal_ErrorPostgreSQL, this, &ServerLMSWidget::slot_ErrorPostgreSQL); - connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, this, &ServerLMSWidget::slot_BlockAutorization); + //connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, this, &ServerLMSWidget::slot_BlockAutorizationIndicate); mutex = new QMutex; @@ -390,9 +376,13 @@ void ServerLMSWidget::startInitialization_step0() commonClientHandler = new CommonClientHandler; connect(this, &ServerLMSWidget::signal_DocsChanged, commonClientHandler, &CommonClientHandler::slot_DocsChanged); - connect(commonClientHandler, &CommonClientHandler::sigSetServerState, this, &ServerLMSWidget::slot_trySetServerState); + //connect(commonClientHandler, &CommonClientHandler::sigSetServerState, this, &ServerLMSWidget::slot_trySetServerState); server = new MultiThreadServer(this, updateController, processingSystem, dataParser, 6000); + connect(server, &MultiThreadServer::signal_BlockAutorizationIndicate, this, &ServerLMSWidget::slot_BlockAutorizationIndicate); + connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, server, &MultiThreadServer::slot_BlockAutorization, Qt::DirectConnection); + connect(updateController, &UpdateController::signal_BlockAutorization, server, &MultiThreadServer::slot_BlockAutorization, Qt::DirectConnection); + connect(server, &MultiThreadServer::signal_sendPacketToAllClients, commonClientHandler, &CommonClientHandler::slot_sendPacketToAllClients); loggerThread->start(); updateThread->start(); diff --git a/LibServer/serverlmswidget.h b/LibServer/serverlmswidget.h index aa5a93f..3d7c3d5 100644 --- a/LibServer/serverlmswidget.h +++ b/LibServer/serverlmswidget.h @@ -91,7 +91,7 @@ signals: public slots: void slot_LanguageChanged(QString language); void slot_UpdateListClients(); - void slot_BlockAutorization(bool block); + void slot_BlockAutorizationIndicate(bool block, QString whoFullName, QString type); void slot_AddMessageToLog(QString message); void slot_ErrorPostgreSQL(QString text); @@ -102,8 +102,6 @@ public slots: void slot_setVersion(QString versionStr); - void slot_trySetServerState(PacketType packetType); - public: QString getLanguage() {