mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
ref: segregate chat sytem
This commit is contained in:
@@ -39,6 +39,8 @@ add_library(ServerLMS SHARED
|
||||
Systems/sendsystem.h
|
||||
Systems/tools.cpp
|
||||
Systems/tools.h
|
||||
Systems/chatsystem.cpp
|
||||
Systems/chatsystem.h
|
||||
providerdblms.cpp
|
||||
providerdblms.h
|
||||
resources.qrc
|
||||
|
||||
@@ -101,6 +101,14 @@ public:
|
||||
QString From;
|
||||
QString To;
|
||||
QString Text;
|
||||
|
||||
ClientMessage(){}
|
||||
ClientMessage(QString from,QString to,QString text)
|
||||
{
|
||||
From = from;
|
||||
To = to;
|
||||
Text = text;
|
||||
}
|
||||
};
|
||||
|
||||
class ServerTask
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "processparser.h"
|
||||
#include "tasksAmmFim.h"
|
||||
|
||||
ProcessParser::ProcessParser(QObject *parent) : QObject(parent)
|
||||
ProcessParser::ProcessParser(QObject *parent) : QObject(parent) //TODO: переименовать в XMLProcessParser?
|
||||
{
|
||||
|
||||
}
|
||||
@@ -500,7 +500,7 @@ void ProcessParser::clientMessage(QXmlStreamReader &xmlReader,ClientHandler *cli
|
||||
clientMessage.To = value;
|
||||
}
|
||||
|
||||
processingSystem->processingSendMessage(client, clientMessage);
|
||||
processingSystem->processingSendMessage(clientMessage);
|
||||
|
||||
}
|
||||
|
||||
|
||||
83
ServerLMS/Systems/chatsystem.cpp
Normal file
83
ServerLMS/Systems/chatsystem.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "chatsystem.h"
|
||||
|
||||
ChatSystem::ChatSystem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChatSystem::initialize(CommonClientHandler *commonClientHandler, DataParser *dataParser, QMap<int, ClientHandler*> *clientsMap)
|
||||
{
|
||||
this->commonClientHandler = commonClientHandler;
|
||||
this->dataParser = dataParser;
|
||||
this->clientsMap = clientsMap;
|
||||
clientNotSendedMessage = new QMap<QString,QStack<ClientMessage>*>;
|
||||
|
||||
auto stack = new QStack<ClientMessage>;
|
||||
auto clientMessage1 = ClientMessage("1","102","Сообщение 1");
|
||||
stack->append(clientMessage1);
|
||||
auto clientMessage2 = ClientMessage("1","102","Сообщение 2");
|
||||
stack->append(clientMessage2);
|
||||
|
||||
clientNotSendedMessage->insert("102", stack);
|
||||
}
|
||||
|
||||
bool ChatSystem::sendTo(ClientMessage message)
|
||||
{
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(message.From,message.To,message.Text);
|
||||
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
if(handler->getClient()->getId() == message.To)
|
||||
{
|
||||
handler->sendXmlAnswer(byteArrayMsg, PacketType::TYPE_XMLANSWER);
|
||||
QString str = "Msg From Client [" + message.From + " to " + message.To + "] : " + message.Text;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChatSystem::sendMessage(ClientMessage message)
|
||||
{
|
||||
bool isSended = false;
|
||||
isSended = sendTo(message);
|
||||
|
||||
if (!isSended)
|
||||
{
|
||||
if (clientNotSendedMessage->contains(message.To))
|
||||
{
|
||||
clientNotSendedMessage->find(message.To).value()->append(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto stack = new QStack<ClientMessage>;
|
||||
stack->append(message);
|
||||
clientNotSendedMessage->insert(message.To, stack);
|
||||
}
|
||||
|
||||
qDebug() << "Message stack count: " + QString::number(clientNotSendedMessage->count());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatSystem::sendOldMessages(QString id)
|
||||
{
|
||||
if (clientNotSendedMessage->contains(id))
|
||||
{
|
||||
auto stack = clientNotSendedMessage->find(id).value();
|
||||
|
||||
while (!stack->isEmpty())
|
||||
{
|
||||
auto message = stack->pop();
|
||||
sendTo(message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "client empty";
|
||||
}
|
||||
}
|
||||
27
ServerLMS/Systems/chatsystem.h
Normal file
27
ServerLMS/Systems/chatsystem.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef CHATSYSTEM_H
|
||||
#define CHATSYSTEM_H
|
||||
|
||||
#include "commonclienthandler.h"
|
||||
#include <QObject>
|
||||
#include <Data/typesDataServerClient.h>
|
||||
|
||||
class ChatSystem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChatSystem();
|
||||
void initialize(CommonClientHandler *commonClientHandler, DataParser *dataParser, QMap<int, ClientHandler*> *clientsMap);
|
||||
bool sendMessage(ClientMessage message);
|
||||
//логика хранения отложенных сообщений
|
||||
//хендлеры для отправки и приема
|
||||
|
||||
void sendOldMessages(QString id);
|
||||
private:
|
||||
CommonClientHandler *commonClientHandler;
|
||||
DataParser *dataParser;
|
||||
QMap<int, ClientHandler*> *clientsMap;
|
||||
QMap<QString,QStack<ClientMessage>*> *clientNotSendedMessage;
|
||||
bool sendTo(ClientMessage message);
|
||||
};
|
||||
|
||||
#endif // CHATSYSTEM_H
|
||||
@@ -120,26 +120,7 @@ void CommonClientHandler::slot_sendPacketToAllClients(PacketType packetType)
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slotSendMessage(QString idFrom, QString idTo, QString text)
|
||||
{
|
||||
QString textMsg = text;
|
||||
|
||||
QByteArray byteArrayMsg = dataParser->ClientAnswer()->message(idFrom,idTo,text);
|
||||
|
||||
//Проходим все открытые сокеты, ищем нужный
|
||||
foreach(int idSocket, clientsMap->keys())
|
||||
{
|
||||
ClientHandler *handler = clientsMap->value(idSocket);
|
||||
if(handler->getClient()->getId() == idTo)
|
||||
{
|
||||
handler->sendXmlAnswer(byteArrayMsg, PacketType::TYPE_XMLANSWER);
|
||||
QString str = "Msg From Client [" + idFrom + " to " + idTo + "] : " + textMsg;
|
||||
|
||||
emit sigSendToLogger(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommonClientHandler::slot_sendTaskToClient(QString fullNameClient,QString textTask)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
void slot_StatusTasksAMMofTraineeChanged(int trainee_id);
|
||||
void slot_StatusTasksFIMofTraineeChanged(int trainee_id);
|
||||
void slot_sendPacketToAllClients(PacketType packetType);
|
||||
void slotSendMessage(QString loginFrom, QString loginTo, QString text);
|
||||
bool slotSendMessage(QString loginFrom, QString loginTo, QString text);
|
||||
void slot_sendTaskToClient(QString fullNameClient, QString textTask);
|
||||
signals:
|
||||
void sigSendToLogger(QString text);
|
||||
|
||||
@@ -15,12 +15,14 @@ void ProcessingSystem::initialize(ServerLMSWidget *server,
|
||||
DataParser *dataParser,
|
||||
CommonClientHandler *commonClientHandler,
|
||||
Logger *logger,
|
||||
UpdateController *updateController)
|
||||
UpdateController *updateController,
|
||||
ChatSystem *chatSystem)
|
||||
{
|
||||
this->commonClientServer = commonClientHandler;
|
||||
this->dataParser = dataParser;
|
||||
this->server = server;
|
||||
this->updateController = updateController;
|
||||
this->chatSystem = chatSystem;
|
||||
|
||||
connect(this,&ProcessingSystem::sigListsInstructorsTraineesChanged,commonClientHandler, &CommonClientHandler::slot_ListsInstructorsTraineesChanged,Qt::AutoConnection);
|
||||
|
||||
@@ -29,7 +31,6 @@ void ProcessingSystem::initialize(ServerLMSWidget *server,
|
||||
|
||||
connect(this,&ProcessingSystem::sigUpdateListClients,server, &ServerLMSWidget::slotUpdateListClients,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::sigSetData,updateController,&UpdateController::setDataInfo,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::sigSendMessage,commonClientHandler, &CommonClientHandler::slotSendMessage,Qt::AutoConnection);
|
||||
connect(this,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger,Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
@@ -95,7 +96,6 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
|
||||
|
||||
QString str = QString(arrayAnswer);
|
||||
//logger->addTextToLogger("To Client: " + str);
|
||||
|
||||
//Извещаем об изменениях в авторизации
|
||||
emit sigListsInstructorsTraineesChanged();
|
||||
}
|
||||
@@ -474,9 +474,9 @@ void ProcessingSystem::processingClientQueryTasksXML(ClientHandler *client, Clie
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingSendMessage(ClientHandler *client, ClientMessage clientMessage)
|
||||
void ProcessingSystem::processingSendMessage(ClientMessage clientMessage)
|
||||
{
|
||||
emit sigSendMessage(clientMessage.From, clientMessage.To, clientMessage.Text);
|
||||
chatSystem->sendMessage(clientMessage);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientNotify(ClientHandler *client, ClientNotify clientNotify)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <clienthandler.h>
|
||||
#include <serverlmswidget.h>
|
||||
//#include "instructorsandtraineeswidget.h"
|
||||
#include "chatsystem.h"
|
||||
#include "providerdblms.h"
|
||||
|
||||
class SendSystem;
|
||||
@@ -27,14 +28,15 @@ public:
|
||||
DataParser* dataParser,
|
||||
CommonClientHandler *commonClientServer,
|
||||
Logger *logger,
|
||||
UpdateController *updateComtroller);
|
||||
UpdateController *updateComtroller,
|
||||
ChatSystem *chatSystem);
|
||||
|
||||
void processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization);
|
||||
void processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization);
|
||||
void processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB, int id = 0, void* data = nullptr);
|
||||
void processingClientQueryTasksXML(ClientHandler *client, ClientQueryTasksXML clientQueryTasksXML);
|
||||
|
||||
void processingSendMessage(ClientHandler *client, ClientMessage clientMessage);
|
||||
void processingSendMessage(ClientMessage clientMessage);
|
||||
void processingClientNotify(ClientHandler *client, ClientNotify clientNotify);
|
||||
|
||||
void setCurrentDataInfo(DataInfo *dataInfo);
|
||||
@@ -57,7 +59,6 @@ signals:
|
||||
void sigStatusTasksFIMofTraineeChanged(int trainee_id);
|
||||
void sigLogMessage(QString log);
|
||||
void sigAddToMessanger(QString login,QString text);
|
||||
void sigSendMessage(QString loginFrom, QString loginTo, QString text);
|
||||
void sigSetData(DataInfo *dataInfo);
|
||||
|
||||
private:
|
||||
@@ -66,6 +67,7 @@ private:
|
||||
DataParser *dataParser;
|
||||
UpdateController *updateController;
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
ChatSystem *chatSystem;
|
||||
void sendTaskListToUnity(ClientHandler *client);
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ void RecognizeSystem::initialize(UpdateController *updateController,DataParser*
|
||||
socket = handler->getSocket();
|
||||
|
||||
connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::calculateFullHashWithSetup,Qt::AutoConnection);
|
||||
//connect(this,&RecognizeSystem::sigCalculateHash,updateController,&UpdateController::setUpCurrentServerHash,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigChangeVersion,updateController,&UpdateController::changeAssetVersion,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigDeleteVersion,updateController,&UpdateController::deleteAssetVersion,Qt::AutoConnection);
|
||||
connect(this,&RecognizeSystem::sigCopyVersion,updateController,&UpdateController::createCopyVersion,Qt::AutoConnection);
|
||||
@@ -51,10 +50,6 @@ void RecognizeSystem::recognize()
|
||||
|
||||
if(!isPackageTypeInited) //первичная инициализация для типа клиента
|
||||
{
|
||||
// char *read = new char[0];
|
||||
// stream.readRawData(read,1);
|
||||
// packetType = static_cast<PacketType>(QString(read[0]).toInt());
|
||||
|
||||
char *read = new char[4];
|
||||
stream.readRawData(read,4);
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
||||
providerDBLMS->deAuthorizationAll();
|
||||
|
||||
logger = new Logger();
|
||||
chatSystem = new ChatSystem();
|
||||
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_BlockAutorization, this, &ServerLMSWidget::slot_BlockAutorization);
|
||||
connect(logger,&Logger::sigSendTextToLogger,this,&ServerLMSWidget::slotAddToLog,Qt::AutoConnection);
|
||||
@@ -66,7 +67,8 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
||||
updateThread->start();
|
||||
|
||||
commonClientHandler->initialize(&clientsMap,processingSystem,dataParser,logger);
|
||||
processingSystem->initialize(this,dataParser,commonClientHandler,logger,updateController);
|
||||
processingSystem->initialize(this,dataParser,commonClientHandler,logger,updateController,chatSystem);
|
||||
chatSystem->initialize(commonClientHandler,dataParser,&clientsMap);
|
||||
|
||||
logger->setTypeLog("widget");
|
||||
connect(dataParser,&DataParser::sigLogMessage,logger,&Logger::addTextToLogger);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <Systems/recognizesystem.h>
|
||||
#include <Systems/logger.h>
|
||||
#include <Systems/commonclienthandler.h>
|
||||
#include <Systems/assetsmanager.h>
|
||||
|
||||
#include <Data/typesDataServerClient.h>
|
||||
#include <Data/Client.h>
|
||||
@@ -38,6 +39,7 @@ class RecognizeSystem;
|
||||
class ClientHandler;
|
||||
class MultiThreadServer;
|
||||
class AssetsManager;
|
||||
class ChatSystem;
|
||||
|
||||
class SERVERLMS_EXPORT ServerLMSWidget : public QWidget
|
||||
{
|
||||
@@ -125,6 +127,7 @@ private:
|
||||
AssetsManager *assetsManager;
|
||||
Logger *logger;
|
||||
CommonClientHandler *commonClientHandler;
|
||||
ChatSystem *chatSystem;
|
||||
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user