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

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

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