fix: first initialize

This commit is contained in:
semenov
2025-09-18 12:55:26 +03:00
parent a2375700b1
commit ced8a5cc64
3 changed files with 45 additions and 34 deletions

View File

@@ -48,19 +48,6 @@ void RecognizeSystem::recognize()
{ {
stream.startTransaction(); stream.startTransaction();
if(!isPackageTypeInited) //первичная инициализация для типа клиента
{
char *read = new char[4];
stream.readRawData(read,4);
int numPackage = *((int*)read);
packetType = static_cast<PacketType>(numPackage);
packetTypeInit(packetType,client);
if(!stream.commitTransaction()) continue;
continue;
}
if(client->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT) if(client->getClientType() == TypeClientAutorization::TYPE_UNITY_CLIENT)
{ {
char *read = new char[4]; char *read = new char[4];
@@ -466,25 +453,6 @@ void RecognizeSystem::recognize()
//mutex->unlock(); //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() bool RecognizeSystem::checkIsChangeable()
{ {
return updateController->getCurrentVersion()->getIsChangeable(); return updateController->getCurrentVersion()->getIsChangeable();

View File

@@ -56,12 +56,13 @@ void ClientHandler::initialize(int descriptor,ServerLMSWidget *serverWidget,
connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection); connect(this,&ClientHandler::sigSendPacketType,sendSystem,&SendSystem::sendPacketType,Qt::AutoConnection);
connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::sendStop,Qt::DirectConnection); connect(this,&ClientHandler::sigSendStop,sendSystem,&SendSystem::sendStop,Qt::DirectConnection);
connect(socket,&QTcpSocket::readyRead,recognizeSystem,&RecognizeSystem::recognize,Qt::AutoConnection); connect(socket,&QTcpSocket::readyRead,this,&ClientHandler::initClientType,Qt::AutoConnection);
connect(socket, &QTcpSocket::disconnected, this, &ClientHandler::sendDisable,Qt::AutoConnection); initClientType();
recognizeSystem->initialize(updateController,dataParser,serverWidget,sendSystem, this); recognizeSystem->initialize(updateController,dataParser,serverWidget,sendSystem, this);
sendSystem->setClient(client,socket); sendSystem->setClient(client,socket);
emit sigInitSender(dataParser,serverWidget->getMutex()); emit sigInitSender(dataParser,serverWidget->getMutex());
} }
void ClientHandler::setClient(Client *value) void ClientHandler::setClient(Client *value)
@@ -69,6 +70,30 @@ void ClientHandler::setClient(Client *value)
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<PacketType>(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() void ClientHandler::sendHash()
{ {
QString path = "\\" + hashFileName; QString path = "\\" + hashFileName;
@@ -145,6 +170,21 @@ void ClientHandler::sendDisable()
emit sigClientDisconnected(client->getAddress(),client->getPort()); 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 Client *ClientHandler::getClient() const
{ {
return client; return client;

View File

@@ -85,6 +85,9 @@ private:
SendSystem *sendSystem; SendSystem *sendSystem;
ServerLMSWidget *server; ServerLMSWidget *server;
void initClientType();
void packetTypeInit(PacketType packet, Client *client);
}; };
#endif // CLIENTHANDLER_H #endif // CLIENTHANDLER_H