diff --git a/ServerLMS/Systems/recognizesystem.cpp b/ServerLMS/Systems/recognizesystem.cpp index d8d096b..a7e8826 100644 --- a/ServerLMS/Systems/recognizesystem.cpp +++ b/ServerLMS/Systems/recognizesystem.cpp @@ -48,19 +48,6 @@ void RecognizeSystem::recognize() { stream.startTransaction(); - if(!isPackageTypeInited) //первичная инициализация для типа клиента - { - char *read = new char[4]; - stream.readRawData(read,4); - - int numPackage = *((int*)read); - packetType = static_cast(numPackage); - packetTypeInit(packetType,client); - - if(!stream.commitTransaction()) continue; - continue; - } - if(client->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT) { char *read = new char[4]; @@ -466,25 +453,6 @@ void RecognizeSystem::recognize() //mutex->unlock(); } -void RecognizeSystem::packetTypeInit(PacketType packet,Client *client) -{ - if(packet == PacketType::TYPE_QT) - { - client->setUnity(TypeClientAutorization::TYPE_QT_CLIENT); - - qDebug() << "ConnectionType isUnity: " << client->getClientType(); - } - else if (packet == PacketType::TYPE_UNITY) - { - client->setUnity(TypeClientAutorization::TYPE_UNITY_CLIENT); - //Фиксируем время входа Юнити-клиента - } - - isPackageTypeInited = true; - Logger::instance().log("C: " + client->getLogin() + " send pack " + enumToString(packetType)); - packetType = PacketType::TYPE_NONE; -} - bool RecognizeSystem::checkIsChangeable() { return updateController->getCurrentVersion()->getIsChangeable(); diff --git a/ServerLMS/clienthandler.cpp b/ServerLMS/clienthandler.cpp index d9636b5..42382fa 100644 --- a/ServerLMS/clienthandler.cpp +++ b/ServerLMS/clienthandler.cpp @@ -56,12 +56,13 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget, connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection); connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::sendStop,Qt::DirectConnection); - connect(socket,&QTcpSocket::readyRead,recognizeSystem,&RecognizeSystem::recognize,Qt::AutoConnection); - connect(socket, &QTcpSocket::disconnected, this, &ClientHandler::sendDisable,Qt::AutoConnection); + connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection); + initClientType(); recognizeSystem->initialize(updateController,dataParser,serverWidget,sendSystem, this); sendSystem->setClient(client,socket); emit sigInitSender(dataParser,serverWidget->getMutex()); + } void ClientHandler::setClient(Client *value) @@ -69,6 +70,30 @@ void ClientHandler::setClient(Client *value) client = value; } +void ClientHandler::initClientType() +{ + QDataStream stream(socket); + stream.setVersion(QDataStream::Qt_DefaultCompiledVersion); + + while (socket->bytesAvailable() > 0) + { + stream.startTransaction(); + char *read = new char[4]; + stream.readRawData(read,4); + + int numPackage = *((int*)read); + PacketType packetType = static_cast(numPackage); + + if(!stream.commitTransaction()) continue; + + packetTypeInit(packetType,client); + + disconnect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType); + connect(socket,&QTcpSocket::readyRead,recognizeSystem,&RecognizeSystem::recognize,Qt::AutoConnection); + connect(socket, &QTcpSocket::disconnected, this, &ClientHandler::sendDisable,Qt::AutoConnection); + } +} + void ClientHandler::sendHash() { QString path = "\\" + hashFileName; @@ -145,6 +170,21 @@ void ClientHandler::sendDisable() emit sigClientDisconnected(client->getAddress(),client->getPort()); } +void ClientHandler::packetTypeInit(PacketType packet,Client *client) +{ + if(packet == PacketType::TYPE_QT) + { + client->setUnity(TypeClientAutorization::TYPE_QT_CLIENT); + } + else if (packet == PacketType::TYPE_UNITY) + { + client->setUnity(TypeClientAutorization::TYPE_UNITY_CLIENT); + } + + Logger::instance().log("C: " + client->getLogin() + " send pack " + enumToString(packet)); +} + + Client *ClientHandler::getClient() const { return client; diff --git a/ServerLMS/clienthandler.h b/ServerLMS/clienthandler.h index b9189af..69dbae4 100644 --- a/ServerLMS/clienthandler.h +++ b/ServerLMS/clienthandler.h @@ -85,6 +85,9 @@ private: SendSystem *sendSystem; ServerLMSWidget *server; + + void initClientType(); + void packetTypeInit(PacketType packet, Client *client); }; #endif // CLIENTHANDLER_H