mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
ref: clientMap to MultithreadServer
This commit is contained in:
@@ -11,8 +11,7 @@ ProcessingSystem::ProcessingSystem(ProviderDBLMS* providerDBLMS, UpdateControlle
|
|||||||
this->updateController = updateController;
|
this->updateController = updateController;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessingSystem::initialize(ServerLMSWidget *server,
|
void ProcessingSystem::initialize(MultiThreadServer *server, DataParser *dataParser,
|
||||||
DataParser *dataParser,
|
|
||||||
CommonClientHandler *commonClientHandler,
|
CommonClientHandler *commonClientHandler,
|
||||||
Logger *logger,
|
Logger *logger,
|
||||||
UpdateController *updateController,
|
UpdateController *updateController,
|
||||||
@@ -29,7 +28,6 @@ void ProcessingSystem::initialize(ServerLMSWidget *server,
|
|||||||
connect(this,&ProcessingSystem::sigStatusTasksAMMofTraineeChanged,commonClientHandler, &CommonClientHandler::slot_StatusTasksAMMofTraineeChanged,Qt::AutoConnection);
|
connect(this,&ProcessingSystem::sigStatusTasksAMMofTraineeChanged,commonClientHandler, &CommonClientHandler::slot_StatusTasksAMMofTraineeChanged,Qt::AutoConnection);
|
||||||
connect(this,&ProcessingSystem::sigStatusTasksFIMofTraineeChanged,commonClientHandler, &CommonClientHandler::slot_StatusTasksFIMofTraineeChanged,Qt::AutoConnection);
|
connect(this,&ProcessingSystem::sigStatusTasksFIMofTraineeChanged,commonClientHandler, &CommonClientHandler::slot_StatusTasksFIMofTraineeChanged,Qt::AutoConnection);
|
||||||
|
|
||||||
connect(this,&ProcessingSystem::sigUpdateListClients,server, &ServerLMSWidget::slotUpdateListClients,Qt::AutoConnection);
|
|
||||||
connect(this,&ProcessingSystem::sigSetData,updateController,&UpdateController::setDataInfo,Qt::AutoConnection);
|
connect(this,&ProcessingSystem::sigSetData,updateController,&UpdateController::setDataInfo,Qt::AutoConnection);
|
||||||
connect(this,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger,Qt::QueuedConnection);
|
connect(this,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger,Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
@@ -692,9 +690,9 @@ ClientHandler *ProcessingSystem::getUnityClientById(int id)
|
|||||||
QString login = providerDBLMS->getLoginTraineeById(id);
|
QString login = providerDBLMS->getLoginTraineeById(id);
|
||||||
|
|
||||||
//Проходим все открытые сокеты, ищем нужный
|
//Проходим все открытые сокеты, ищем нужный
|
||||||
foreach(int idSocket, server->getClientsMap().keys())
|
foreach(int idSocket, server->getClientsMap()->keys())
|
||||||
{
|
{
|
||||||
ClientHandler *handler = server->getClientsMap().value(idSocket);
|
ClientHandler *handler = server->getClientsMap()->value(idSocket);
|
||||||
if(handler->getClient()->getLogin() == login)
|
if(handler->getClient()->getLogin() == login)
|
||||||
{
|
{
|
||||||
if(handler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
|
if(handler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <clienthandler.h>
|
#include <clienthandler.h>
|
||||||
#include <serverlmswidget.h>
|
#include <serverlmswidget.h>
|
||||||
|
#include "multithreadserver.h"
|
||||||
//#include "instructorsandtraineeswidget.h"
|
//#include "instructorsandtraineeswidget.h"
|
||||||
#include "chatsystem.h"
|
#include "chatsystem.h"
|
||||||
#include "providerdblms.h"
|
#include "providerdblms.h"
|
||||||
@@ -17,6 +18,7 @@ class Logger;
|
|||||||
class DataParser;
|
class DataParser;
|
||||||
class ClientHandler;
|
class ClientHandler;
|
||||||
class CommonClientHandler;
|
class CommonClientHandler;
|
||||||
|
class MultiThreadServer;
|
||||||
|
|
||||||
class ProcessingSystem : public QObject
|
class ProcessingSystem : public QObject
|
||||||
{
|
{
|
||||||
@@ -24,7 +26,7 @@ class ProcessingSystem : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit ProcessingSystem(ProviderDBLMS* providerDBLMS, UpdateController* updateController, QObject *parent = nullptr);
|
explicit ProcessingSystem(ProviderDBLMS* providerDBLMS, UpdateController* updateController, QObject *parent = nullptr);
|
||||||
|
|
||||||
void initialize(ServerLMSWidget *server,
|
void initialize(MultiThreadServer *server,
|
||||||
DataParser* dataParser,
|
DataParser* dataParser,
|
||||||
CommonClientHandler *commonClientServer,
|
CommonClientHandler *commonClientServer,
|
||||||
Logger *logger,
|
Logger *logger,
|
||||||
@@ -66,7 +68,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CommonClientHandler *commonClientServer;
|
CommonClientHandler *commonClientServer;
|
||||||
ServerLMSWidget *server;
|
MultiThreadServer *server;
|
||||||
DataParser *dataParser;
|
DataParser *dataParser;
|
||||||
UpdateController *updateController;
|
UpdateController *updateController;
|
||||||
ProviderDBLMS* providerDBLMS;
|
ProviderDBLMS* providerDBLMS;
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
|
|||||||
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigFolderBlock,sendSystem,&SendSystem::sendFolderBlock,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigGetIsSendStopped,sendSystem,&SendSystem::getIsSendStopped,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigSendDeleteBlock,sendSystem,&SendSystem::sendDeleteBlock,Qt::AutoConnection);
|
||||||
//connect(this,&ClientHandler::sigSendFinish,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection);
|
|
||||||
connect(this,&ClientHandler::sigSendMessageBlock,sendSystem,&SendSystem::sendMessageBlock,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigSendMessageBlock,sendSystem,&SendSystem::sendMessageBlock,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::sendNeedUpdate,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigNeedUpdate,sendSystem,&SendSystem::sendNeedUpdate,Qt::AutoConnection);
|
||||||
connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::sendNotify,Qt::AutoConnection);
|
connect(this,&ClientHandler::sigSendNotify,sendSystem,&SendSystem::sendNotify,Qt::AutoConnection);
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
#include "multithreadserver.h"
|
#include "multithreadserver.h"
|
||||||
|
|
||||||
MultiThreadServer::MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,
|
MultiThreadServer::MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,ProcessingSystem *processingSystem,
|
||||||
DataParser *dataParser,Logger *logger,QObject *parent):
|
DataParser *dataParser,Logger *logger,qint16 hostPort, QObject *parent ):
|
||||||
QTcpServer(parent),
|
QTcpServer(parent),
|
||||||
serverLmsWidget(widget),
|
serverLmsWidget(widget),
|
||||||
|
hostPort(hostPort),
|
||||||
|
processingSystem(processingSystem),
|
||||||
updateController(updateController),
|
updateController(updateController),
|
||||||
dataParser(dataParser),
|
dataParser(dataParser),
|
||||||
logger(logger)
|
logger(logger),
|
||||||
|
stateServer(stoped),
|
||||||
|
stateBlockAutorization(unblocked)
|
||||||
{
|
{
|
||||||
connect(this,&MultiThreadServer::sigSendToLogger,logger,&Logger::addTextToLogger);
|
connect(this,&MultiThreadServer::sigSendToLogger,logger,&Logger::addTextToLogger);
|
||||||
|
clientsMap = new QMap<int,ClientHandler*>;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
||||||
@@ -21,21 +26,94 @@ void MultiThreadServer::incomingConnection(qintptr socketDesriptor)
|
|||||||
emit sigInitClient(socketDesriptor,serverLmsWidget,updateController,dataParser,logger);
|
emit sigInitClient(socketDesriptor,serverLmsWidget,updateController,dataParser,logger);
|
||||||
disconnect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize);
|
disconnect(this,&MultiThreadServer::sigInitClient,newClient,&ClientHandler::initialize);
|
||||||
|
|
||||||
serverLmsWidget->addClient(socketDesriptor,newClient);
|
addClient(socketDesriptor,newClient);
|
||||||
|
|
||||||
emit sigSendToLogger("To Client: " + QString(SERVER_HELLO));
|
emit sigSendToLogger("To Client: " + QString(SERVER_HELLO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MultiThreadServer::startServer()
|
||||||
|
{
|
||||||
|
if(stateServer == stoped)
|
||||||
|
{
|
||||||
|
//connect(tcpServer, &QTcpServer::newConnection, this, &ServerLMSWidget::slotNewConnection,Qt::AutoConnection);
|
||||||
|
|
||||||
|
if(!listen(QHostAddress::Any, hostPort))
|
||||||
|
{
|
||||||
|
logger->addTextToLogger("SERVER: start ERROR");
|
||||||
|
stateServer = stoped;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger->addTextToLogger("SERVER: start OK");
|
||||||
|
stateServer = started;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MultiThreadServer::stopServer()
|
||||||
|
{
|
||||||
|
if(stateServer == started)
|
||||||
|
{
|
||||||
|
disableClients();
|
||||||
|
|
||||||
|
//Закрываем сервер
|
||||||
|
close();
|
||||||
|
stateServer = stoped;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<int, ClientHandler *> *MultiThreadServer::getClientsMap() const
|
||||||
|
{
|
||||||
|
return clientsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiThreadServer::updateClientList()
|
||||||
|
{
|
||||||
|
serverLmsWidget->slotUpdateListClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiThreadServer::disableClients()
|
||||||
|
{
|
||||||
|
QByteArray arrayAnswer = dataParser->ClientAnswer()->notify(NOTIFY_SERVER_END);
|
||||||
|
|
||||||
|
//Закрываем все открытые сокеты
|
||||||
|
foreach(int idSocket, clientsMap->keys())
|
||||||
|
{
|
||||||
|
ClientHandler* handler = (*clientsMap)[idSocket];
|
||||||
|
|
||||||
|
//Фиксируем время выхода Юнити-клиента
|
||||||
|
if(handler->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
|
||||||
|
{
|
||||||
|
processingSystem->processingExitUnityClient(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
handler->sigSendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER);
|
||||||
|
QString str = QString(arrayAnswer);
|
||||||
|
processingSystem->processingClientDeAutorization(handler->getClient()->getLogin());
|
||||||
|
|
||||||
|
handler->sigSocketClose();
|
||||||
|
//clientsMap.remove(idSocket);
|
||||||
|
removeClient(idSocket);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPort)
|
void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPort)
|
||||||
{
|
{
|
||||||
auto clientsMap = serverLmsWidget->getClientsMap();
|
|
||||||
QString login = "";
|
QString login = "";
|
||||||
qDebug() << peerAddress << " " << peerPort << " " << "disconnect";
|
qDebug() << peerAddress << " " << peerPort << " " << "disconnect";
|
||||||
|
|
||||||
//Проходим все открытые сокеты, ищем нужный
|
//Проходим все открытые сокеты, ищем нужный
|
||||||
foreach(int idSocket, clientsMap.keys())
|
foreach(int idSocket, clientsMap->keys())
|
||||||
{
|
{
|
||||||
ClientHandler *client = clientsMap[idSocket];
|
ClientHandler *client = (*clientsMap)[idSocket];
|
||||||
|
|
||||||
if(client->getClient()->getAddress() == peerAddress && client->getClient()->getPort() == peerPort)
|
if(client->getClient()->getAddress() == peerAddress && client->getClient()->getPort() == peerPort)
|
||||||
{
|
{
|
||||||
@@ -43,9 +121,9 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo
|
|||||||
|
|
||||||
ClientDeAutorization clientDeAutorization;
|
ClientDeAutorization clientDeAutorization;
|
||||||
clientDeAutorization.Login = login;
|
clientDeAutorization.Login = login;
|
||||||
serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(client, clientDeAutorization);
|
processingSystem->processingClientDeAutorization(client, clientDeAutorization);
|
||||||
|
|
||||||
serverLmsWidget->removeClient(idSocket);
|
removeClient(idSocket);
|
||||||
delete client;
|
delete client;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -59,3 +137,15 @@ void MultiThreadServer::slotDisconnectClient(QString peerAddress, QString peerPo
|
|||||||
serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(login);
|
serverLmsWidget->getProcessingSystem()->processingClientDeAutorization(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MultiThreadServer::removeClient(int idSocket)
|
||||||
|
{
|
||||||
|
clientsMap->remove(idSocket);
|
||||||
|
serverLmsWidget->slotUpdateListClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiThreadServer::addClient(qintptr descriptor, ClientHandler *client)
|
||||||
|
{
|
||||||
|
(*clientsMap)[descriptor] = client;
|
||||||
|
serverLmsWidget->slotUpdateListClients();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,40 @@
|
|||||||
#define MULTITHREADSERVER_H
|
#define MULTITHREADSERVER_H
|
||||||
|
|
||||||
#include "serverlmswidget.h"
|
#include "serverlmswidget.h"
|
||||||
|
#include "Systems/processingsystem.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class ProcessingSystem;
|
||||||
class MultiThreadServer : public QTcpServer
|
class MultiThreadServer : public QTcpServer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MultiThreadServer( ServerLMSWidget *widget,UpdateController *updateController,
|
MultiThreadServer(ServerLMSWidget *widget,UpdateController *updateController,ProcessingSystem *processingSystem,
|
||||||
DataParser *dataParser,Logger *logger,QObject *parent = nullptr);
|
DataParser *dataParser,Logger *logger, qint16 hostPort, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
||||||
|
QMap<int, ClientHandler *> *getClientsMap() const;
|
||||||
|
void updateClientList();
|
||||||
|
void disableClients();
|
||||||
|
|
||||||
|
bool startServer();
|
||||||
|
bool stopServer();
|
||||||
|
void blockAutorization()
|
||||||
|
{
|
||||||
|
stateBlockAutorization = blocked;
|
||||||
|
}
|
||||||
|
void unBlockAutorization()
|
||||||
|
{
|
||||||
|
stateBlockAutorization = unblocked;
|
||||||
|
}
|
||||||
|
EStateBlockAutorization getStateBlockAutorization() const
|
||||||
|
{
|
||||||
|
return stateBlockAutorization;
|
||||||
|
}
|
||||||
signals:
|
signals:
|
||||||
void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
void sigInitClient(int descriptor, ServerLMSWidget *serverWidget,
|
||||||
UpdateController *updateController, DataParser *dataParser,Logger *logger);
|
UpdateController *updateController, DataParser *dataParser,Logger *logger);
|
||||||
void signalStopSendFile();
|
void signalStopSendFile();
|
||||||
void sigSendToLogger(QString text);
|
void sigSendToLogger(QString text);
|
||||||
|
|
||||||
@@ -27,9 +46,18 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ServerLMSWidget *serverLmsWidget;
|
ServerLMSWidget *serverLmsWidget;
|
||||||
|
QMap<int, ClientHandler*> *clientsMap;
|
||||||
|
qint16 hostPort;
|
||||||
|
ProcessingSystem *processingSystem;
|
||||||
UpdateController *updateController;
|
UpdateController *updateController;
|
||||||
DataParser *dataParser;
|
DataParser *dataParser;
|
||||||
Logger *logger;
|
Logger *logger;
|
||||||
|
|
||||||
|
EStateServer stateServer;
|
||||||
|
EStateBlockAutorization stateBlockAutorization;
|
||||||
|
|
||||||
|
void removeClient(int idSocket);
|
||||||
|
void addClient(qintptr descriptor, ClientHandler *client);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MULTITHREADSERVER_H
|
#endif // MULTITHREADSERVER_H
|
||||||
|
|||||||
@@ -11,10 +11,7 @@
|
|||||||
ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::ServerLMSWidget),
|
ui(new Ui::ServerLMSWidget),
|
||||||
tcpServer(nullptr),
|
server(nullptr),
|
||||||
hostPort(6000),
|
|
||||||
stateServer(stoped),
|
|
||||||
stateBlockAutorization(unblocked),
|
|
||||||
updateThread(nullptr),
|
updateThread(nullptr),
|
||||||
loggerThread(nullptr),
|
loggerThread(nullptr),
|
||||||
dataParser(nullptr),
|
dataParser(nullptr),
|
||||||
@@ -63,13 +60,14 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
|||||||
dataParser = new DataParser(assetsManager,processingSystem);
|
dataParser = new DataParser(assetsManager,processingSystem);
|
||||||
|
|
||||||
commonClientHandler = new CommonClientHandler;
|
commonClientHandler = new CommonClientHandler;
|
||||||
|
server = new MultiThreadServer(this,updateController,processingSystem,dataParser,logger,6000);
|
||||||
|
|
||||||
loggerThread->start();
|
loggerThread->start();
|
||||||
updateThread->start();
|
updateThread->start();
|
||||||
|
|
||||||
commonClientHandler->initialize(&clientsMap,processingSystem,dataParser,logger);
|
commonClientHandler->initialize(server->getClientsMap(),processingSystem,dataParser,logger);
|
||||||
processingSystem->initialize(this,dataParser,commonClientHandler,logger,updateController,chatSystem);
|
processingSystem->initialize(server,dataParser,commonClientHandler,logger,updateController,chatSystem);
|
||||||
chatSystem->initialize(commonClientHandler,dataParser,&clientsMap);
|
chatSystem->initialize(commonClientHandler,dataParser,server->getClientsMap());
|
||||||
|
|
||||||
logger->setTypeLog("widget");
|
logger->setTypeLog("widget");
|
||||||
connect(dataParser,&DataParser::sigLogMessage,logger,&Logger::addTextToLogger);
|
connect(dataParser,&DataParser::sigLogMessage,logger,&Logger::addTextToLogger);
|
||||||
@@ -93,127 +91,43 @@ void ServerLMSWidget::setError(int code)
|
|||||||
|
|
||||||
ServerLMSWidget::~ServerLMSWidget()
|
ServerLMSWidget::~ServerLMSWidget()
|
||||||
{
|
{
|
||||||
stopServer();
|
server->stopServer();
|
||||||
updateThread->exit();
|
updateThread->exit();
|
||||||
loggerThread->exit();
|
loggerThread->exit();
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerLMSWidget::startServer()
|
|
||||||
{
|
|
||||||
if(stateServer == stoped)
|
|
||||||
{
|
|
||||||
tcpServer = new MultiThreadServer(this,updateController,dataParser,logger);
|
|
||||||
|
|
||||||
//connect(tcpServer, &QTcpServer::newConnection, this, &ServerLMSWidget::slotNewConnection,Qt::AutoConnection);
|
|
||||||
|
|
||||||
if(!tcpServer->listen(QHostAddress::Any, hostPort))
|
|
||||||
{
|
|
||||||
logger->addTextToLogger("SERVER: start ERROR");
|
|
||||||
stateServer = stoped;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger->addTextToLogger("SERVER: start OK");
|
|
||||||
stateServer = started;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ServerLMSWidget::stopServer()
|
|
||||||
{
|
|
||||||
if(stateServer == started)
|
|
||||||
{
|
|
||||||
QByteArray arrayAnswer = dataParser->ClientAnswer()->notify(NOTIFY_SERVER_END);
|
|
||||||
|
|
||||||
//Закрываем все открытые сокеты
|
|
||||||
foreach(int idSocket, clientsMap.keys())
|
|
||||||
{
|
|
||||||
ClientHandler* clientHandlerOpen = clientsMap[idSocket];
|
|
||||||
|
|
||||||
//Фиксируем время выхода Юнити-клиента
|
|
||||||
if(clientHandlerOpen->getClient()->GETTYPE() == TypeClientAutorization::TYPE_UNITY_CLIENT)
|
|
||||||
{
|
|
||||||
processingSystem->processingExitUnityClient(clientHandlerOpen);
|
|
||||||
}
|
|
||||||
|
|
||||||
clientHandlerOpen->sigSendXmlAnswer(arrayAnswer, PacketType::TYPE_XMLANSWER);
|
|
||||||
//while (!clientsMap[idSocket]->sigSocketFlush()) {}
|
|
||||||
|
|
||||||
QString str = QString(arrayAnswer);
|
|
||||||
emit sigLog("To Client: " + str);
|
|
||||||
|
|
||||||
//slotDisconnectClient(clientsMap[idSocket]->get, QString peerPort)
|
|
||||||
processingSystem->processingClientDeAutorization(clientHandlerOpen->getClient()->getLogin());
|
|
||||||
|
|
||||||
clientHandlerOpen->sigSocketClose();
|
|
||||||
//clientsMap.remove(idSocket);
|
|
||||||
removeClient(idSocket);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Закрываем сервер
|
|
||||||
tcpServer->close();
|
|
||||||
stateServer = stoped;
|
|
||||||
delete tcpServer;
|
|
||||||
emit sigLog("Server is stopped");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger *ServerLMSWidget::getLogger() const
|
Logger *ServerLMSWidget::getLogger() const
|
||||||
{
|
{
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, ClientHandler *> ServerLMSWidget::getClientsMap() const
|
|
||||||
{
|
|
||||||
return clientsMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerLMSWidget::slotUpdateListClients()
|
void ServerLMSWidget::slotUpdateListClients()
|
||||||
{
|
{
|
||||||
//Очищаем список
|
//Очищаем список
|
||||||
ui->listWidget_Clients->clear();
|
ui->listWidget_Clients->clear();
|
||||||
|
|
||||||
//Проходим все открытые сокеты
|
for (const ClientHandler *handler : server->getClientsMap()->values())
|
||||||
foreach(int idSocket, clientsMap.keys())
|
|
||||||
{
|
{
|
||||||
//Добавляем в список Клиентов
|
QString strClient = handler->getClient()->getFullName();
|
||||||
QString strClient = clientsMap[idSocket]->getClient()->getFullName();
|
|
||||||
|
|
||||||
ui->listWidget_Clients->addItem(strClient);
|
ui->listWidget_Clients->addItem(strClient);
|
||||||
ui->listWidget_Clients->scrollToBottom();
|
ui->listWidget_Clients->scrollToBottom();
|
||||||
ui->listWidget_Clients->setCurrentRow(ui->listWidget_Clients->count() - 1);
|
ui->listWidget_Clients->setCurrentRow(ui->listWidget_Clients->count() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int countClients = clientsMap.count();
|
int countClients = (*server->getClientsMap()).count();
|
||||||
emit sigLog("SERVER: countClients = " + QString::number(countClients));
|
emit sigLog("SERVER: countClients = " + QString::number(countClients));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLMSWidget::slot_BlockAutorization(bool block)
|
void ServerLMSWidget::slot_BlockAutorization(bool block)
|
||||||
{
|
{
|
||||||
if(block)
|
if(block)
|
||||||
blockAutorization();
|
server->blockAutorization();
|
||||||
else
|
else
|
||||||
unBlockAutorization();
|
server->unBlockAutorization();
|
||||||
}
|
|
||||||
|
|
||||||
void ServerLMSWidget::removeClient(int idSocket)
|
|
||||||
{
|
|
||||||
clientsMap.remove(idSocket);
|
|
||||||
slotUpdateListClients();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerLMSWidget::addClient(qintptr descriptor, ClientHandler *client)
|
|
||||||
{
|
|
||||||
clientsMap[descriptor] = client;
|
|
||||||
slotUpdateListClients();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLMSWidget::slot_LanguageChanged(QString language)
|
void ServerLMSWidget::slot_LanguageChanged(QString language)
|
||||||
@@ -230,7 +144,7 @@ void ServerLMSWidget::slotAddToLog(QString msg)
|
|||||||
|
|
||||||
void ServerLMSWidget::on_btnStartServer_clicked()
|
void ServerLMSWidget::on_btnStartServer_clicked()
|
||||||
{
|
{
|
||||||
if(startServer())
|
if(server->startServer())
|
||||||
{
|
{
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
@@ -243,7 +157,7 @@ void ServerLMSWidget::on_btnStartServer_clicked()
|
|||||||
|
|
||||||
void ServerLMSWidget::on_btnStopServer_clicked()
|
void ServerLMSWidget::on_btnStopServer_clicked()
|
||||||
{
|
{
|
||||||
if(stopServer())
|
if(server->stopServer())
|
||||||
{
|
{
|
||||||
ui->btnStopServer->setEnabled(false);
|
ui->btnStopServer->setEnabled(false);
|
||||||
ui->btnStartServer->setEnabled(true);
|
ui->btnStartServer->setEnabled(true);
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_LanguageChanged(QString language);
|
void slot_LanguageChanged(QString language);
|
||||||
void addClient(qintptr descriptor, ClientHandler *client);
|
|
||||||
void slotUpdateListClients();
|
void slotUpdateListClients();
|
||||||
void slot_BlockAutorization(bool block);
|
void slot_BlockAutorization(bool block);
|
||||||
void slotAddToLog(QString msg);
|
void slotAddToLog(QString msg);
|
||||||
@@ -74,50 +73,27 @@ public slots:
|
|||||||
public:
|
public:
|
||||||
void removeClient(int socketId);
|
void removeClient(int socketId);
|
||||||
|
|
||||||
void blockAutorization()
|
|
||||||
{
|
|
||||||
stateBlockAutorization = blocked;
|
|
||||||
}
|
|
||||||
void unBlockAutorization()
|
|
||||||
{
|
|
||||||
stateBlockAutorization = unblocked;
|
|
||||||
}
|
|
||||||
int hasError() const
|
int hasError() const
|
||||||
{
|
{
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
EStateBlockAutorization getStateBlockAutorization() const
|
|
||||||
{
|
|
||||||
return stateBlockAutorization;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessingSystem* getProcessingSystem()
|
ProcessingSystem* getProcessingSystem()
|
||||||
{
|
{
|
||||||
return processingSystem;
|
return processingSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, ClientHandler *> getClientsMap() const;
|
|
||||||
|
|
||||||
Logger *getLogger() const;
|
Logger *getLogger() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_btnStartServer_clicked();
|
void on_btnStartServer_clicked();
|
||||||
void on_btnStopServer_clicked();
|
void on_btnStopServer_clicked();
|
||||||
|
|
||||||
private:
|
|
||||||
bool startServer();
|
|
||||||
bool stopServer();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ServerLMSWidget *ui;
|
Ui::ServerLMSWidget *ui;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MultiThreadServer * tcpServer;
|
MultiThreadServer *server;
|
||||||
qint16 hostPort;
|
|
||||||
QMap<int, ClientHandler*> clientsMap;
|
|
||||||
EStateServer stateServer;
|
|
||||||
EStateBlockAutorization stateBlockAutorization;
|
|
||||||
|
|
||||||
QThread *updateThread;
|
QThread *updateThread;
|
||||||
QThread *loggerThread;
|
QThread *loggerThread;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user