Skip to content

Commit b825024

Browse files
committed
added:get online user list for http restful
1 parent 05e7243 commit b825024

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

XEngine_Source/MQCore_ProtocolModule/MQCore_ProtocolModule.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EXPORTS
1010
ProtocolModule_Packet_Http
1111
ProtocolModule_Packet_UserList
1212
ProtocolModule_Packet_TopicList
13+
ProtocolModule_Packet_OnlineList
1314
ProtocolModule_Packet_UNReadCreate
1415
ProtocolModule_Packet_UNReadInsert
1516
ProtocolModule_Packet_UNReadDelete

XEngine_Source/MQCore_ProtocolModule/ProtocolModule_Packet/ProtocolModule_Packet.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,57 @@ bool CProtocolModule_Packet::ProtocolModule_Packet_TopicList(XCHAR* ptszMsgBuffe
429429
return true;
430430
}
431431
/********************************************************************
432+
函数名称:ProtocolModule_Packet_OnlineList
433+
函数功能:在线用户打包
434+
参数.一:ptszMsgBuffer
435+
In/Out:Out
436+
类型:字符指针
437+
可空:N
438+
意思:输出打包的内容
439+
参数.二:pInt_MsgLen
440+
In/Out:Out
441+
类型:整数型指针
442+
可空:N
443+
意思:输出打包大小
444+
参数.三:ppptszListUser
445+
In/Out:In
446+
类型:三级指针
447+
可空:N
448+
意思:输入要打包的数据
449+
参数.四:nListCount
450+
In/Out:In
451+
类型:整数型
452+
可空:N
453+
意思:输入要打包的数据的个数
454+
返回值
455+
类型:逻辑型
456+
意思:是否成功
457+
备注:
458+
*********************************************************************/
459+
bool CProtocolModule_Packet::ProtocolModule_Packet_OnlineList(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListUser, int nListCount)
460+
{
461+
Protocol_IsErrorOccur = false;
462+
463+
Json::Value st_JsonRoot;
464+
Json::Value st_JsonArray;
465+
Json::StreamWriterBuilder st_JsonBuilder;
466+
467+
for (int i = 0; i < nListCount; i++)
468+
{
469+
Json::Value st_JsonObject;
470+
st_JsonObject["tszUserAddr"] = (*ppptszListUser)[i];
471+
st_JsonArray.append(st_JsonObject);
472+
}
473+
st_JsonRoot["code"] = 0;
474+
st_JsonRoot["Array"] = st_JsonArray;
475+
st_JsonRoot["Count"] = st_JsonArray.size();
476+
477+
st_JsonBuilder["emitUTF8"] = true;
478+
*pInt_MsgLen = Json::writeString(st_JsonBuilder, st_JsonRoot).length();
479+
memcpy(ptszMsgBuffer, Json::writeString(st_JsonBuilder, st_JsonRoot).c_str(), *pInt_MsgLen);
480+
return true;
481+
}
482+
/********************************************************************
432483
函数名称:ProtocolModule_Packet_UNReadCreate
433484
函数功能:未读消息打包创建函数
434485
参数.一:pSt_ProtocolHdr

XEngine_Source/MQCore_ProtocolModule/ProtocolModule_Packet/ProtocolModule_Packet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CProtocolModule_Packet
3232
bool ProtocolModule_Packet_Http(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, int nCode = 0, LPCXSTR lpszMsgBuffer = NULL);
3333
bool ProtocolModule_Packet_UserList(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XENGINE_PROTOCOL_USERINFO*** pppSt_UserInfo, int nListCount);
3434
bool ProtocolModule_Packet_TopicList(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** pppszTableName, int nListCount);
35+
bool ProtocolModule_Packet_OnlineList(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListUser, int nListCount);
3536
public:
3637
XHANDLE ProtocolModule_Packet_UNReadCreate(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType);
3738
bool ProtocolModule_Packet_UNReadInsert(XHANDLE xhToken, XENGINE_DBMESSAGEQUEUE*** pppSt_DBMessage, int nListCount, LPCXSTR lpszUserName);

XEngine_Source/MQCore_ProtocolModule/Protocol_Define.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,35 @@ extern "C" bool ProtocolModule_Packet_UserList(XCHAR* ptszMsgBuffer, int* pInt_M
241241
*********************************************************************/
242242
extern "C" bool ProtocolModule_Packet_TopicList(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** pppszTableName, int nListCount);
243243
/********************************************************************
244+
函数名称:ProtocolModule_Packet_OnlineList
245+
函数功能:在线用户打包
246+
参数.一:ptszMsgBuffer
247+
In/Out:Out
248+
类型:字符指针
249+
可空:N
250+
意思:输出打包的内容
251+
参数.二:pInt_MsgLen
252+
In/Out:Out
253+
类型:整数型指针
254+
可空:N
255+
意思:输出打包大小
256+
参数.三:ppptszListUser
257+
In/Out:In
258+
类型:三级指针
259+
可空:N
260+
意思:输入要打包的数据
261+
参数.四:nListCount
262+
In/Out:In
263+
类型:整数型
264+
可空:N
265+
意思:输入要打包的数据的个数
266+
返回值
267+
类型:逻辑型
268+
意思:是否成功
269+
备注:
270+
*********************************************************************/
271+
extern "C" bool ProtocolModule_Packet_OnlineList(XCHAR* ptszMsgBuffer, int* pInt_MsgLen, XCHAR*** ppptszListUser, int nListCount);
272+
/********************************************************************
244273
函数名称:ProtocolModule_Packet_UNReadCreate
245274
函数功能:未读消息打包创建函数
246275
参数.一:pSt_ProtocolHdr

XEngine_Source/MQCore_ProtocolModule/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ extern "C" bool ProtocolModule_Packet_TopicList(XCHAR * ptszMsgBuffer, int* pInt
5959
{
6060
return m_ProtocolPacket.ProtocolModule_Packet_TopicList(ptszMsgBuffer, pInt_MsgLen, pppszTableName, nListCount);
6161
}
62+
extern "C" bool ProtocolModule_Packet_OnlineList(XCHAR * ptszMsgBuffer, int* pInt_MsgLen, XCHAR * **ppptszListUser, int nListCount)
63+
{
64+
return m_ProtocolPacket.ProtocolModule_Packet_OnlineList(ptszMsgBuffer, pInt_MsgLen, ppptszListUser, nListCount);
65+
}
6266
extern "C" XHANDLE ProtocolModule_Packet_UNReadCreate(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, ENUM_XENGINE_PROTOCOLHDR_PAYLOAD_TYPE enPayType)
6367
{
6468
return m_ProtocolPacket.ProtocolModule_Packet_UNReadCreate(pSt_ProtocolHdr, enPayType);

XEngine_Source/XEngine_MQServiceApp/MQService_HttpTask.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ bool MessageQueue_Http_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXST
5454
LPCXSTR lpszAPIGet = _X("get");
5555
LPCXSTR lpszAPIUser = _X("user");
5656
LPCXSTR lpszAPITopic = _X("topic");
57+
LPCXSTR lpszAPIOnline = _X("online");
5758

5859
if (0 == _tcsxnicmp(lpszPostMethod, pSt_HTTPParam->tszHttpMethod, _tcsxlen(lpszPostMethod)))
5960
{
@@ -87,6 +88,19 @@ bool MessageQueue_Http_Handle(RFCCOMPONENTS_HTTP_REQPARAM* pSt_HTTPParam, LPCXST
8788
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
8889
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取用户列表请求成功,获取到的用户列表个数:%d"), lpszClientAddr, nListCount);
8990
}
91+
else if (0 == _tcsxnicmp(lpszAPIOnline, tszValue, _tcsxlen(lpszAPIOnline)))
92+
{
93+
//获取在线用户 http://127.0.0.1:5202/api?function=get&method=online&type=0
94+
int nListCount = 0;
95+
XCHAR** pptszListAddr;
96+
97+
BaseLib_OperatorString_GetKeyValue(ppSt_ListUrl[2], _X("="), tszKey, tszValue);
98+
SessionModule_Client_GetListAddr(&pptszListAddr, &nListCount, _ttxoi(tszValue));
99+
ProtocolModule_Packet_OnlineList(tszPKTBuffer, &nPKTLen, &pptszListAddr, nListCount);
100+
BaseLib_OperatorMemory_Free((XPPPMEM)&pptszListAddr, nListCount);
101+
XEngine_MQXService_Send(lpszClientAddr, tszPKTBuffer, nPKTLen, XENGINE_MQAPP_NETTYPE_HTTP);
102+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,发送的获取在线用户列表请求成功,获取到的列表个数:%d"), lpszClientAddr, nListCount);
103+
}
90104
else if (0 == _tcsxnicmp(lpszAPITopic, tszValue, _tcsxlen(lpszAPITopic)))
91105
{
92106
//主题 http://127.0.0.1:5202/api?function=get&method=topic

0 commit comments

Comments
 (0)