Skip to content

Commit 1b801b9

Browse files
committed
fixed:Doesn't handle whether the client is online or not when a message notification is made
1 parent e3c33be commit 1b801b9

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

XEngine_Source/MQCore_SessionModule/MQCore_SessionModule.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ EXPORTS
1212
SessionModule_Client_GetAddr
1313
SessionModule_Client_GetInfoByUser
1414
SessionModule_Client_GetType
15+
SessionModule_Client_GetExist
1516
SessionModule_Client_GetListAddr

XEngine_Source/MQCore_SessionModule/SessionModule_Client/SessionModule_Client.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,70 @@ bool CSessionModule_Client::SessionModule_Client_GetType(LPCXSTR lpszSessionStr,
341341
return true;
342342
}
343343
/********************************************************************
344+
函数名称:SessionModule_Client_GetExist
345+
函数功能:指定客户端是否存在
346+
参数.一:lpszClientAddr
347+
In/Out:In
348+
类型:常量字符指针
349+
可空:Y
350+
意思:输入客户端地址
351+
参数.二:lpszClientUser
352+
In/Out:In
353+
类型:常量字符指针
354+
可空:Y
355+
意思:输入客户端用户
356+
返回值
357+
类型:逻辑型
358+
意思:是否成功
359+
备注:不能同时为NULL,可以使用一个参数
360+
*********************************************************************/
361+
bool CSessionModule_Client::SessionModule_Client_GetExist(LPCXSTR lpszClientAddr, LPCXSTR lpszClientUser)
362+
{
363+
Session_IsErrorOccur = false;
364+
365+
if (NULL == lpszClientUser && NULL == lpszClientAddr)
366+
{
367+
Session_IsErrorOccur = true;
368+
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_PARAMENT;
369+
return false;
370+
}
371+
372+
st_Locker.lock_shared();
373+
if (NULL == lpszClientAddr)
374+
{
375+
bool bFound = false;
376+
unordered_map<tstring, XENGINE_SESSIONINFO>::iterator stl_MapIterator = stl_MapSession.begin();
377+
for (int i = 0; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++, i++)
378+
{
379+
if (0 == _tcsxnicmp(lpszClientUser, stl_MapIterator->second.st_UserInfo.tszUserName, _tcsxlen(stl_MapIterator->second.st_UserInfo.tszUserName)))
380+
{
381+
bFound = true;
382+
break;
383+
}
384+
}
385+
if (!bFound)
386+
{
387+
Session_IsErrorOccur = true;
388+
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_NOTFOUND;
389+
st_Locker.unlock_shared();
390+
return false;
391+
}
392+
}
393+
else
394+
{
395+
unordered_map<tstring, XENGINE_SESSIONINFO>::iterator stl_MapIterator = stl_MapSession.find(lpszClientAddr);
396+
if (stl_MapIterator == stl_MapSession.end())
397+
{
398+
Session_IsErrorOccur = true;
399+
Session_dwErrorCode = ERROR_MQ_MODULE_SESSION_NOTFOUND;
400+
st_Locker.unlock_shared();
401+
return false;
402+
}
403+
}
404+
st_Locker.unlock_shared();
405+
return true;
406+
}
407+
/********************************************************************
344408
函数名称:SessionModule_Client_GetList
345409
函数功能:获取客户端地址列表
346410
参数.一:ppptszClientList

XEngine_Source/MQCore_SessionModule/SessionModule_Client/SessionModule_Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CSessionModule_Client
3333
bool SessionModule_Client_GetAddr(LPCXSTR lpszUserName, XCHAR* ptszUserAddr = NULL);
3434
bool SessionModule_Client_GetInfoByUser(LPCXSTR lpszUserName, XENGINE_PROTOCOL_USERINFO* pSt_UserInfo);
3535
bool SessionModule_Client_GetType(LPCXSTR lpszSessionStr, int* pInt_NetType);
36+
bool SessionModule_Client_GetExist(LPCXSTR lpszClientAddr = NULL, LPCXSTR lpszClientUser = NULL);
3637
bool SessionModule_Client_GetListAddr(XCHAR*** ppptszClientList, int* pInt_ListCount);
3738
private:
3839
shared_mutex st_Locker;

XEngine_Source/MQCore_SessionModule/Session_Define.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,25 @@ extern "C" bool SessionModule_Client_GetInfoByUser(LPCXSTR lpszUserName, XENGINE
174174
*********************************************************************/
175175
extern "C" bool SessionModule_Client_GetType(LPCXSTR lpszSessionStr, int* pInt_NetType);
176176
/********************************************************************
177+
函数名称:SessionModule_Client_GetExist
178+
函数功能:指定客户端是否存在
179+
参数.一:lpszClientAddr
180+
In/Out:In
181+
类型:常量字符指针
182+
可空:Y
183+
意思:输入客户端地址
184+
参数.二:lpszClientUser
185+
In/Out:In
186+
类型:常量字符指针
187+
可空:Y
188+
意思:输入客户端用户
189+
返回值
190+
类型:逻辑型
191+
意思:是否成功
192+
备注:不能同时为NULL,可以使用一个参数
193+
*********************************************************************/
194+
extern "C" bool SessionModule_Client_GetExist(LPCXSTR lpszClientAddr = NULL, LPCXSTR lpszClientUser = NULL);
195+
/********************************************************************
177196
函数名称:SessionModule_Client_GetList
178197
函数功能:获取客户端地址列表
179198
参数.一:ppptszClientList

XEngine_Source/MQCore_SessionModule/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ extern "C" bool SessionModule_Client_GetType(LPCXSTR lpszSessionStr, int* pInt_N
6565
{
6666
return m_SessionClient.SessionModule_Client_GetType(lpszSessionStr, pInt_NetType);
6767
}
68+
extern "C" bool SessionModule_Client_GetExist(LPCXSTR lpszClientAddr, LPCXSTR lpszClientUser)
69+
{
70+
return m_SessionClient.SessionModule_Client_GetExist(lpszClientAddr, lpszClientUser);
71+
}
6872
extern "C" bool SessionModule_Client_GetListAddr(XCHAR * **ppptszClientList, int* pInt_ListCount)
6973
{
7074
return m_SessionClient.SessionModule_Client_GetListAddr(ppptszClientList, pInt_ListCount);

XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,14 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC
463463
memset(tszSDBuffer, '\0', sizeof(tszSDBuffer));
464464

465465
pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_MQ_MSGNOTIFY;
466-
467-
SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr);
468-
SessionModule_Client_GetType(tszUserAddr, &nClientType);
469-
ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ));
470-
XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType);
466+
//只有在线用户才需要即时通知
467+
if (SessionModule_Client_GetExist(NULL, tszUserName))
468+
{
469+
SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr);
470+
SessionModule_Client_GetType(tszUserAddr, &nClientType);
471+
ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ));
472+
XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType);
473+
}
471474
}
472475
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount);
473476
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("%s消息端:%s,主题:%s,序列:%lld,投递数据到消息队列成功,通知客户端个数:%d"), lpszClientType, lpszClientAddr, st_DBQueue.tszQueueName, st_DBQueue.nQueueSerial, nListCount);

0 commit comments

Comments
 (0)