Skip to content

Commit 465c231

Browse files
committed
modify:Message notifications now support additional notifications and not send single user
1 parent 2025909 commit 465c231

File tree

5 files changed

+48
-25
lines changed

5 files changed

+48
-25
lines changed

XEngine_Source/XEngine_MQServiceApp/MQService_Hdr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ using namespace std;
3131
#include <XEngine_Include/XEngine_Core/ManagePool_Error.h>
3232
#include <XEngine_Include/XEngine_Client/APIClient_Define.h>
3333
#include <XEngine_Include/XEngine_Client/APIClient_Error.h>
34+
#include <XEngine_Include/XEngine_NetHelp/APIAddr_Define.h>
35+
#include <XEngine_Include/XEngine_NetHelp/APIAddr_Error.h>
3436
#include <XEngine_Include/XEngine_HelpComponents/XLog_Define.h>
3537
#include <XEngine_Include/XEngine_HelpComponents/XLog_Error.h>
3638
#include <XEngine_Include/XEngine_HelpComponents/Packets_Define.h>
@@ -102,6 +104,7 @@ extern MESSAGEQUEUE_DBCONFIG st_DBConfig;
102104
#pragma comment(lib,"XEngine_Core/XEngine_Core.lib")
103105
#pragma comment(lib,"XEngine_Core/XEngine_ManagePool.lib")
104106
#pragma comment(lib,"XEngine_Client/XClient_APIHelp.lib")
107+
#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIAddr.lib")
105108
#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib")
106109
#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib")
107110
#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_HttpProtocol.lib")

XEngine_Source/XEngine_MQServiceApp/MQService_Net.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void XEngine_MQXService_Close(LPCXSTR lpszClientAddr, int nIPProto, bool bHeart)
165165
SessionModule_Client_Delete(lpszClientAddr);
166166
}
167167
//////////////////////////////////////////////////////////////////////////
168-
bool XEngine_MQXService_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nIPProto)
168+
bool XEngine_MQXService_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nIPProto, XENGINE_PROTOCOL_MSGATTR* pSt_MSGAttr, LPCXSTR lpszUserName)
169169
{
170170
if (XENGINE_MQAPP_NETTYPE_TCP == nIPProto)
171171
{
@@ -210,13 +210,32 @@ bool XEngine_MQXService_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int
210210
return false;
211211
}
212212
}
213-
else if (XENGINE_MQAPP_NETTYPE_EMAIL == nIPProto)
213+
214+
if (NULL != pSt_MSGAttr)
214215
{
215-
if (!MSGNotify_EMail_Send(st_ServiceCfg.st_XNotify.st_EMailNotify.tszServiceAddr, st_ServiceCfg.st_XNotify.st_EMailNotify.tszUser, st_ServiceCfg.st_XNotify.st_EMailNotify.tszPass, lpszClientAddr, st_ServiceCfg.st_XNotify.st_EMailNotify.tszEMailSubject, lpszMsgBuffer))
216+
XENGINE_PROTOCOL_USERINFO st_UserInfo = {};
217+
_tcsxcpy(st_UserInfo.tszUserName, lpszUserName);
218+
219+
if (!DBModule_MQUser_UserQuery(&st_UserInfo))
216220
{
217-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("发送数据给EMail地址:%s 失败,错误码:%lX"), lpszClientAddr, MSGNotify_GetLastError());
221+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("客户端:%s,用户名:%s 请求消息通知失败,因为没有找到指定的用户信息,错误码:%lX"), lpszClientAddr,lpszUserName, DBModule_GetLastError());
218222
return false;
219223
}
224+
//是否需要邮件通知
225+
if (pSt_MSGAttr->byAttrEMail)
226+
{
227+
if (!APIAddr_EMail_IsEMailAddr(st_UserInfo.tszEMailAddr))
228+
{
229+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("客户端:%s,用户名:%s 请求消息通知失败,通知邮件地址不正确,错误码:%lX"), lpszClientAddr, lpszUserName, APIAddr_GetLastError());
230+
return false;
231+
}
232+
if (!MSGNotify_EMail_Send(st_ServiceCfg.st_XNotify.st_EMailNotify.tszServiceAddr, st_ServiceCfg.st_XNotify.st_EMailNotify.tszUser, st_ServiceCfg.st_XNotify.st_EMailNotify.tszPass, lpszClientAddr, st_ServiceCfg.st_XNotify.st_EMailNotify.tszEMailSubject, lpszMsgBuffer))
233+
{
234+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("发送数据给EMail地址:%s 失败,错误码:%lX"), lpszClientAddr, MSGNotify_GetLastError());
235+
return false;
236+
}
237+
}
220238
}
239+
221240
return true;
222241
}

XEngine_Source/XEngine_MQServiceApp/MQService_Net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ void XCALLBACK MessageQueue_Callback_WSRecv(LPCXSTR lpszClientAddr, XSOCKET hSoc
1717
void XCALLBACK MessageQueue_Callback_WSLeave(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam);
1818

1919
void XEngine_MQXService_Close(LPCXSTR lpszClientAddr, int nIPProto, bool bHeart);
20-
bool XEngine_MQXService_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nIPProto);
20+
bool XEngine_MQXService_Send(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, int nIPProto, XENGINE_PROTOCOL_MSGATTR* pSt_MSGAttr = NULL, LPCXSTR lpszUserName = NULL);

XEngine_Source/XEngine_MQServiceApp/MQService_TCPTask.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,36 +328,34 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC
328328
}
329329
nSDLen = 0;
330330
int nClientType = 0;
331+
XCHAR tszTmpUser[XPATH_MID] = {};
331332
memset(tszSDBuffer, '\0', sizeof(tszSDBuffer));
332333

333334
SessionModule_Client_GetType(pptszListAddr[i], &nClientType);
335+
SessionModule_Client_GetUser(pptszListAddr[i], tszTmpUser);
334336
ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ));
335-
XEngine_MQXService_Send(pptszListAddr[i], tszSDBuffer, nSDLen, nClientType);
337+
XEngine_MQXService_Send(pptszListAddr[i], tszSDBuffer, nSDLen, nClientType, &st_MQProtocol.st_MSGAttr, tszTmpUser);
336338
BaseLib_Memory_Free((XPPPMEM)&pptszListAddr, nListCount);
337339
}
338340
}
339341
else
340342
{
341343
if (_tcsxlen(st_MQProtocol.tszMQUsr) > 0)
342344
{
343-
if (1 == st_MQProtocol.st_MSGAttr.byAttrEMail)
345+
//如果发送指定用户被指定.
346+
if (SessionModule_Client_GetExist(NULL, st_MQProtocol.tszMQUsr))
344347
{
345-
XEngine_MQXService_Send(st_MQProtocol.tszMQUsr, st_DBQueue.tszMsgBuffer, st_DBQueue.nMsgLen, XENGINE_MQAPP_NETTYPE_EMAIL);
346-
}
347-
else
348-
{
349-
//如果发送指定用户被指定.
350-
if (SessionModule_Client_GetExist(NULL, st_MQProtocol.tszMQUsr))
351-
{
352-
int nClientType = 0;
353-
XCHAR tszUserAddr[128] = {};
354-
355-
SessionModule_Client_GetAddr(st_MQProtocol.tszMQUsr, tszUserAddr);
356-
SessionModule_Client_GetType(tszUserAddr, &nClientType);
357-
ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ));
358-
XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType);
359-
}
348+
int nClientType = 0;
349+
XCHAR tszUserAddr[128] = {};
350+
XCHAR tszTmpUser[XPATH_MID] = {};
351+
352+
SessionModule_Client_GetAddr(st_MQProtocol.tszMQUsr, tszUserAddr);
353+
SessionModule_Client_GetType(tszUserAddr, &nClientType);
354+
SessionModule_Client_GetUser(tszUserAddr, tszTmpUser);
355+
ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ));
356+
XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType, &st_MQProtocol.st_MSGAttr, tszTmpUser);
360357
}
358+
361359
}
362360
else
363361
{
@@ -380,10 +378,13 @@ bool MessageQueue_TCP_Handle(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, LPCXSTR lpszC
380378
//只有在线用户才需要即时通知
381379
if (SessionModule_Client_GetExist(NULL, ppSt_ListUser[i]->tszUserName))
382380
{
381+
XCHAR tszTmpUser[XPATH_MID] = {};
382+
383383
SessionModule_Client_GetAddr(ppSt_ListUser[i]->tszUserName, tszUserAddr);
384384
SessionModule_Client_GetType(tszUserAddr, &nClientType);
385+
SessionModule_Client_GetUser(tszUserAddr, tszTmpUser);
385386
ProtocolModule_Packet_Common(nClientType, pSt_ProtocolHdr, &st_MQProtocol, tszSDBuffer, &nSDLen, lpszMsgBuffer + sizeof(XENGINE_PROTOCOL_XMQ), nMsgLen - sizeof(XENGINE_PROTOCOL_XMQ));
386-
XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType);
387+
XEngine_MQXService_Send(tszUserAddr, tszSDBuffer, nSDLen, nClientType, &st_MQProtocol.st_MSGAttr, tszTmpUser);
387388
}
388389
}
389390
BaseLib_Memory_Free((XPPPMEM)&ppSt_ListUser, nListCount);

XEngine_Source/XQueue_ProtocolHdr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ typedef struct
100100
XBYTE byAttrSelf : 1; //自己也能接受
101101
XBYTE byAttrReply : 1; //对方必须回复
102102
XBYTE byAttrActive : 1; //主动获取不受限制,比如超时的,不是自己发给自己的
103-
XBYTE byAttrEMail : 1; //此消息需要邮件通知
104-
XBYTE byAttrPhone : 1; //此消息需要短信通知
103+
XBYTE byAttrEMail : 1; //此消息需要邮件通知,仅限即时消息
104+
XBYTE byAttrPhone : 1; //此消息需要短信通知,仅限即时消息
105105
XBYTE byAttrResver6 : 1;
106106
XBYTE byAttrResver7 : 1;
107107
XBYTE byAttrResver;

0 commit comments

Comments
 (0)