Skip to content

Commit 15ce3ed

Browse files
committed
added:logout protocol support for verification module with xauthorize
1 parent da4c1c3 commit 15ce3ed

File tree

5 files changed

+152
-3
lines changed

5 files changed

+152
-3
lines changed

XEngine_Module/XEngine_Verification/Verification_Define.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,4 +854,28 @@ extern "C" bool Verification_XAuthNet_GetAuth();
854854
意思:是否成功
855855
备注:
856856
*********************************************************************/
857-
extern "C" bool Verification_XAuthNet_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, LPCXSTR lpszHWCode = NULL, XSHOT nDYCode = 0, XNETHANDLE xhToken = 0, XLONG dwCryption = 0);
857+
extern "C" bool Verification_XAuthNet_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, LPCXSTR lpszHWCode = NULL, XSHOT nDYCode = 0, XNETHANDLE xhToken = 0, XLONG dwCryption = 0);
858+
/********************************************************************
859+
函数名称:Verification_XAuthNet_Logout
860+
函数功能:用户登出协议
861+
参数.一:lpszUser
862+
In/Out:In
863+
类型:常量字符指针
864+
可空:N
865+
意思:输入用户名
866+
参数.二:lpszPass
867+
In/Out:In
868+
类型:常量字符指针
869+
可空:N
870+
意思:输入密码
871+
参数.三:dwCryption
872+
In/Out:In
873+
类型:整数型
874+
可空:Y
875+
意思:密码加密方法
876+
返回值
877+
类型:逻辑型
878+
意思:是否成功
879+
备注:
880+
*********************************************************************/
881+
extern "C" bool Verification_XAuthNet_Logout(LPCXSTR lpszUser, LPCXSTR lpszPass, XLONG dwCryption = 0);

XEngine_Module/XEngine_Verification/Verification_XAuth/Verification_XAuthNet.cpp

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ bool CVerification_XAuthNet::Verification_XAuthNet_Login(LPCXSTR lpszUser, LPCXS
370370
//协议头
371371
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
372372
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
373-
st_ProtocolHdr.unOperatorCode = 0x2005;
373+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN;
374374
st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERAUTHEX);
375375
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
376376

@@ -470,6 +470,125 @@ bool CVerification_XAuthNet::Verification_XAuthNet_Login(LPCXSTR lpszUser, LPCXS
470470
}
471471
return true;
472472
}
473+
/********************************************************************
474+
函数名称:Verification_XAuthNet_Logout
475+
函数功能:用户登出协议
476+
参数.一:lpszUser
477+
In/Out:In
478+
类型:常量字符指针
479+
可空:N
480+
意思:输入用户名
481+
参数.二:lpszPass
482+
In/Out:In
483+
类型:常量字符指针
484+
可空:N
485+
意思:输入密码
486+
参数.三:dwCryption
487+
In/Out:In
488+
类型:整数型
489+
可空:Y
490+
意思:密码加密方法
491+
返回值
492+
类型:逻辑型
493+
意思:是否成功
494+
备注:
495+
*********************************************************************/
496+
bool CVerification_XAuthNet::Verification_XAuthNet_Logout(LPCXSTR lpszUser, LPCXSTR lpszPass, XLONG dwCryption /* = 0 */)
497+
{
498+
Verification_IsErrorOccur = false;
499+
500+
if ((NULL == lpszUser) || (NULL == lpszPass))
501+
{
502+
Verification_IsErrorOccur = true;
503+
Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_PARAMENT;
504+
return false;
505+
}
506+
XCHAR tszMsgBuffer[2048] = {};
507+
XENGINE_PROTOCOLHDR st_ProtocolHdr = {};
508+
XENGINE_PROTOCOL_USERAUTHEX st_AuthUser = {};
509+
//协议头
510+
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
511+
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH;
512+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGOUT;
513+
st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERAUTHEX);
514+
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
515+
516+
#ifdef _MSC_BUILD
517+
st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_WINDOWS;
518+
#elif __linux__
519+
st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_LINUX;
520+
#else
521+
st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_MACOS;
522+
#endif
523+
_tcsxcpy(st_AuthUser.tszUserName, lpszUser);
524+
525+
if (dwCryption > 0)
526+
{
527+
int nPLen = _tcsxlen(lpszPass);
528+
XBYTE byMD5Buffer[XPATH_MAX] = {};
529+
Cryption_Api_Digest(lpszPass, byMD5Buffer, &nPLen, false, dwCryption);
530+
BaseLib_String_StrToHex((LPCXSTR)byMD5Buffer, nPLen, st_AuthUser.tszUserPass);
531+
}
532+
else
533+
{
534+
_tcsxcpy(st_AuthUser.tszUserPass, lpszPass);
535+
}
536+
//是否加密
537+
int nMsgLen = 0;
538+
if (_tcsxlen(tszPassStr) > 0)
539+
{
540+
XCHAR tszCodecBuffer[2048] = {};
541+
542+
st_ProtocolHdr.wCrypto = ENUM_XENGINE_PROTOCOLHDR_CRYPTO_TYPE_XCRYPT;
543+
Cryption_XCrypto_Encoder((LPCXSTR)&st_AuthUser, (int*)&st_ProtocolHdr.unPacketSize, (XBYTE*)tszCodecBuffer, tszPassStr);
544+
545+
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
546+
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), tszCodecBuffer, st_ProtocolHdr.unPacketSize);
547+
548+
nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
549+
}
550+
else
551+
{
552+
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
553+
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), &st_AuthUser, st_ProtocolHdr.unPacketSize);
554+
555+
nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + sizeof(XENGINE_PROTOCOL_USERAUTHEX);
556+
}
557+
//发送数据
558+
if (!XClient_TCPSelect_SendMsg(m_hSocket, tszMsgBuffer, nMsgLen))
559+
{
560+
Verification_IsErrorOccur = true;
561+
Verification_dwErrorCode = XClient_GetLastError();
562+
return false;
563+
}
564+
565+
nMsgLen = 0;
566+
XCHAR* ptszMsgBuffer;
567+
st_ProtocolHdr = {};
568+
//接受数据
569+
if (!XClient_TCPSelect_RecvPkt(m_hSocket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr))
570+
{
571+
Verification_IsErrorOccur = true;
572+
Verification_dwErrorCode = XClient_GetLastError();
573+
return false;
574+
}
575+
//判断是否登录协议
576+
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGOUT != st_ProtocolHdr.unOperatorCode)
577+
{
578+
Verification_IsErrorOccur = true;
579+
Verification_dwErrorCode = ERROR_XENGINE_MODULE_VERIFICATION_XAUTH_CODE;
580+
return false;
581+
}
582+
//登录失败,错误码
583+
if (0 != st_ProtocolHdr.wReserve)
584+
{
585+
Verification_IsErrorOccur = true;
586+
Verification_dwErrorCode = st_ProtocolHdr.wReserve;
587+
return false;
588+
}
589+
Verification_XAuthNet_Close();
590+
return true;
591+
}
473592
//////////////////////////////////////////////////////////////////////////
474593
// 保护函数
475594
//////////////////////////////////////////////////////////////////////////

XEngine_Module/XEngine_Verification/Verification_XAuth/Verification_XAuthNet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CVerification_XAuthNet
3030
bool Verification_XAuthNet_Close();
3131
bool Verification_XAuthNet_GetAuth();
3232
bool Verification_XAuthNet_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, LPCXSTR lpszHWCode = NULL, XSHOT nDYCode = 0, XNETHANDLE xhToken = 0, XLONG dwCryption = 0);
33+
bool Verification_XAuthNet_Logout(LPCXSTR lpszUser, LPCXSTR lpszPass, XLONG dwCryption = 0);
3334
protected:
3435
static XHTHREAD XCALLBACK Verification_XAuthNet_Thread(XPVOID lParam);
3536
private:

XEngine_Module/XEngine_Verification/XEngine_Verification.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ EXPORTS
3232
Verification_XAuthNet_Connect
3333
Verification_XAuthNet_Close
3434
Verification_XAuthNet_GetAuth
35-
Verification_XAuthNet_Login
35+
Verification_XAuthNet_Login
36+
Verification_XAuthNet_Logout

XEngine_Module/XEngine_Verification/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,8 @@ extern "C" bool Verification_XAuthNet_GetAuth()
152152
extern "C" bool Verification_XAuthNet_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, LPCXSTR lpszHWCode, XSHOT nDYCode, XNETHANDLE xhToken, XLONG dwCryption)
153153
{
154154
return m_XAuthNetVerification.Verification_XAuthNet_Login(lpszUser, lpszPass, lpszHWCode, nDYCode, xhToken, dwCryption);
155+
}
156+
extern "C" bool Verification_XAuthNet_Logout(LPCXSTR lpszUser, LPCXSTR lpszPass, XLONG dwCryption)
157+
{
158+
return m_XAuthNetVerification.Verification_XAuthNet_Logout(lpszUser, lpszPass, dwCryption);
155159
}

0 commit comments

Comments
 (0)