карта блок-в. Блокировка правильная. Множ. доступ

This commit is contained in:
2026-01-21 15:44:01 +03:00
parent fe75f2c6ca
commit 2772c3aaba
26 changed files with 146 additions and 91 deletions

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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<int, ClientHandler*> *clientsMap;
ProcessingSystem *processingSystem;

View File

@@ -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);
}
//упращенная деавторизация при выключении сервера

View File

@@ -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);

View File

@@ -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)

View File

@@ -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()

View File

@@ -71,6 +71,9 @@ signals:
void sigInitializeFinished();
//сигнал о блокировке авторизации
bool signal_BlockAutorization(bool block, QString whoFullName, QString type);
private:
QList<FileData> clientDataList;
QList<FileData> serverDataList;

View File

@@ -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);

View File

@@ -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<QString, QString> blockersMap;
void removeClient(int idSocket);
void addClient(qintptr descriptor, ClientHandler *client);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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();

View File

@@ -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()
{