Skip to content

Commit 1bdadf7

Browse files
committed
added:heartbeat client module support
1 parent c2fbd91 commit 1bdadf7

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

XEngine_Source/AuthorizeModule_Client/AuthClient_Connector/AuthClient_Connector.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ bool CAuthClient_Connector::AuthClient_Connector_Close()
8686
pSTDThread->join();
8787
}
8888
m_bLogin = false;
89+
m_bAuth = false;
90+
m_bHeart = false;
8991
XClient_TCPSelect_Close(m_hSocket);
9092
#endif
9193
return true;
@@ -246,13 +248,41 @@ bool CAuthClient_Connector::AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR
246248
#endif
247249
return true;
248250
}
251+
/********************************************************************
252+
函数名称:AuthClient_Connector_Heart
253+
函数功能:启用禁用客户端心跳
254+
参数.一:bEnable
255+
In/Out:In
256+
类型:逻辑型
257+
可空:Y
258+
意思:是启用还是禁用
259+
返回值
260+
类型:逻辑型
261+
意思:是否成功
262+
备注:
263+
*********************************************************************/
264+
bool CAuthClient_Connector::AuthClient_Connector_Heart(bool bEnable /* = true */)
265+
{
266+
AuthClient_IsErrorOccur = false;
267+
268+
if (!m_bAuth)
269+
{
270+
AuthClient_IsErrorOccur = true;
271+
AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_NOTAUTH;
272+
return false;
273+
}
274+
m_bHeart = bEnable;
275+
return true;
276+
}
249277
//////////////////////////////////////////////////////////////////////////
250278
// 保护函数
251279
//////////////////////////////////////////////////////////////////////////
252280
XHTHREAD CALLBACK CAuthClient_Connector::AuthClient_Connector_Thread(XPVOID lParam)
253281
{
254282
CAuthClient_Connector* pClass_This = (CAuthClient_Connector*)lParam;
255283

284+
time_t nTimeStart = time(NULL);
285+
256286
#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP)
257287
while (pClass_This->m_bRun)
258288
{
@@ -280,6 +310,22 @@ XHTHREAD CALLBACK CAuthClient_Connector::AuthClient_Connector_Thread(XPVOID lPar
280310
{
281311
pClass_This->m_bAuth = false;
282312
}
313+
//心跳支持
314+
if (pClass_This->m_bHeart)
315+
{
316+
time_t nTimeEnd = time(NULL);
317+
if ((nTimeEnd - nTimeStart) > 2)
318+
{
319+
XENGINE_PROTOCOLHDR st_ProtocolHdr = {};
320+
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
321+
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_HEARTBEAT;
322+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_HB_SYN;
323+
st_ProtocolHdr.byVersion = 1;
324+
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
325+
326+
XClient_TCPSelect_SendMsg(pClass_This->m_hSocket, (LPCXSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
327+
}
328+
}
283329
std::this_thread::sleep_for(std::chrono::seconds(1));
284330
}
285331
#endif

XEngine_Source/AuthorizeModule_Client/AuthClient_Connector/AuthClient_Connector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ class CAuthClient_Connector
2727
bool AuthClient_Connector_Close();
2828
bool AuthClient_Connector_GetAuth(bool* pbAuth = NULL);
2929
bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0);
30+
bool AuthClient_Connector_Heart(bool bEnable = true);
3031
protected:
3132
static XHTHREAD CALLBACK AuthClient_Connector_Thread(XPVOID lParam);
3233
private:
3334
bool m_bRun = false;
3435
bool m_bLogin = false;
3536
bool m_bAuth = false;
37+
bool m_bHeart = false;
3638
XSOCKET m_hSocket = 0;
3739
XCHAR tszPassStr[128] = {};
3840
private:

XEngine_Source/AuthorizeModule_Client/AuthClient_Define.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ extern "C" bool AuthClient_Connector_GetAuth(bool* pbAuth = NULL);
9393
备注:
9494
*********************************************************************/
9595
extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0);
96+
/********************************************************************
97+
函数名称:AuthClient_Connector_Heart
98+
函数功能:启用禁用客户端心跳
99+
参数.一:bEnable
100+
In/Out:In
101+
类型:逻辑型
102+
可空:Y
103+
意思:是启用还是禁用
104+
返回值
105+
类型:逻辑型
106+
意思:是否成功
107+
备注:服务器开启了心跳,那么客户端也需要开启
108+
*********************************************************************/
109+
extern "C" bool AuthClient_Connector_Heart(bool bEnable = true);
96110
/************************************************************************/
97111
/* 临时验证函数 */
98112
/************************************************************************/

XEngine_Source/AuthorizeModule_Client/AuthClient_Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define ERROR_AUTHORIZE_MODULE_CLIENT_RECV 0x0060002 //接受数据失败
2222
#define ERROR_AUTHORIZE_MODULE_CLIENT_LOGIN 0x0060003 //登录失败,请查看错误码
2323
#define ERROR_AUTHORIZE_MODULE_CLIENT_THREAD 0x0060004 //创建线程失败
24+
#define ERROR_AUTHORIZE_MODULE_CLIENT_NOTAUTH 0x0060005 //没有验证无法启用心跳
2425
/************************************************************************/
2526
/* HTTP验证错误 */
2627
/************************************************************************/

XEngine_Source/AuthorizeModule_Client/AuthorizeModule_Client.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ EXPORTS
77
AuthClient_Connector_Close
88
AuthClient_Connector_GetAuth
99
AuthClient_Connector_Login
10+
AuthClient_Connector_Heart
1011

1112
AuthClient_HTTPVer_TryRequest
1213
AuthClient_HTTPVer_GetDCode

XEngine_Source/AuthorizeModule_Client/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, i
4747
{
4848
return m_Connector.AuthClient_Connector_Login(lpszUser, lpszPass, nDYCode, xhToken);
4949
}
50+
extern "C" bool AuthClient_Connector_Heart(bool bEnable)
51+
{
52+
return m_Connector.AuthClient_Connector_Heart(bEnable);
53+
}
5054
/************************************************************************/
5155
/* 临时验证函数 */
5256
/************************************************************************/

0 commit comments

Comments
 (0)