Skip to content

Commit

Permalink
Merge pull request #24 from libxengine/develop
Browse files Browse the repository at this point in the history
V3.11.0.1001 Merge
  • Loading branch information
xengine-qyt authored Feb 23, 2024
2 parents ce73426 + 3876a56 commit 7316761
Show file tree
Hide file tree
Showing 44 changed files with 294 additions and 143 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
XEngine_Authorize V3.11.0.1001

增加:客户端模块的http版本支持获取动态码
更新:对XEngine V8.25的编译支持
修改:客户端编译开关选项名称
修改:动态码被禁用的时候不允许访问
修正:某些时候websocket服务无法访问的问题
修正:http发送数据丢失
修正:某些加解密API缓冲区没有使用正确的问题
删除:客户端模块导出函数构建编译选项删除
删除:websocket的text协议验证

added:get dynamic code for http ver
update:xengine v8.25 build supported
modify:client build switch name
modify:dynamiccode is disable then not allow access
fixed:sometime does not visit websocket service
fixed:http sendmsg lost datas
fixed:Some crypto api buffers are used incorrectly
delete:export functions build switch for client module
delete:text protocol ver for websocket
================================================================
XEngine_Authorize V3.10.0.1001

增加:临时验证超时时间字段支持
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ V3版本为全新版本,为了适应过多环境要求开发
数据库更新使用Navicat等数据库软件打开判断表和字段不同的地方进行修改
修改完毕后直接把数据库拷贝到新的版本进行覆盖,修改你的配置文件即可

## 视频教程
你也可以观看视频教程来了解我们的代码框架情况:https://www.bilibili.com/video/BV1iF4m177aG

## 授权说明
使用此软件必须开源并且注明出处,如果想闭源商用,那么需要经过作者授权.

Expand Down
Binary file modified XEngine_Apps/Authorize_APPClient.e
Binary file not shown.
115 changes: 57 additions & 58 deletions XEngine_Apps/Authorize_APPClient/Authorize_APPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,35 @@
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
#pragma comment(lib,"XEngine_Core/XEngine_OPenSsl")
#pragma comment(lib,"XEngine_Client/XClient_Socket")
#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient")
#pragma comment(lib,"../../XEngine_Source/Debug/jsoncpp")
#pragma comment(lib,"XEngine_Client/XClient_APIHelp")
#ifdef _WIN64
#pragma comment(lib,"../../XEngine_Source/x64/Debug/jsoncpp")
#else
#pragma comment(lib,"../../XEngine_Source/Debug/jsoncpp")
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
#include <thread>
#include <json/json.h>
using namespace std;
#include <XEngine_Include/XEngine_CommHdr.h>
#include <XEngine_Include/XEngine_Types.h>
#include <XEngine_Include/XEngine_ProtocolHdr.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
#include <XEngine_Include/XEngine_Core/OPenSsl_Define.h>
#include <XEngine_Include/XEngine_Core/OPenSsl_Error.h>
#include <XEngine_Include/XEngine_Client/XClient_Define.h>
#include <XEngine_Include/XEngine_Client/XClient_Error.h>
#include <XEngine_Include/XEngine_NetHelp/APIClient_Define.h>
#include <XEngine_Include/XEngine_NetHelp/APIClient_Error.h>
#include <XEngine_Include/XEngine_Client/APIClient_Define.h>
#include <XEngine_Include/XEngine_Client/APIClient_Error.h>
#include <XEngine_Include/XEngine_HelpComponents/Authorize_Define.h>
#include "../../XEngine_Source/XAuth_Protocol.h"

//Windows::vs2022 x86 debug 编译即可
//Linux::g++ -std=c++17 -Wall -g Auth_APPClient.cpp -o Auth_APPClient.exe -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Core -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Client -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp -lXEngine_BaseLib -lXEngine_OPenSsl -lXClient_Socket -lNetHelp_APIClient -lpthread -ljsoncpp -Wl,-rpath=../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Core:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Client:../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp,--disable-new-dtags
//Macos::g++ -std=c++17 -Wall -g Auth_APPClient.cpp -o Auth_APPClient.exe -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_BaseLib -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Core -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_Client -L ../../../XEngine/XEngine_Release/XEngine_Linux/Ubuntu/XEngine_NetHelp -lXEngine_BaseLib -lXEngine_OPenSsl -lXClient_Socket -lNetHelp_APIClient -lpthread -ljsoncpp
//Linux::g++ -std=c++17 -Wall -g Authorize_APPClient.cpp -o Authorize_APPClient.exe -I ../../XEngine_Source/XEngine_ThirdPart/jsoncpp -lXEngine_BaseLib -L ../../XEngine_Release -lXEngine_OPenSsl -lXClient_Socket -lXClient_APIHelp -lpthread -ljsoncpp

//#define _DYNAMIC_CODE
bool bRun = true;
Expand All @@ -41,10 +44,10 @@ XNETHANDLE xhToken = 0;
int nDYCode = 0;

XSOCKET m_Socket = 0;
LPCXSTR lpszUser = _T("123123aa");
LPCXSTR lpszPass = _T("123123");
LPCXSTR lpszSerial = _T("XAUTH-XYRYM-ZAA10-59NKW-KOFLP-35838-ZXC36-ZOVTH");
LPCXSTR lpszEmail = _T("[email protected]");
LPCXSTR lpszUser = _X("123123aa");
LPCXSTR lpszPass = _X("123123");
LPCXSTR lpszSerial = _X("XAUTH-XYRYM-ZAA10-59NKW-KOFLP-35838-ZXC36-ZOVTH");
LPCXSTR lpszEmail = _X("[email protected]");
__int64x nPhoneNumber = 1366666666;
__int64x nIDNumber = 511025111111111111;

Expand Down Expand Up @@ -77,21 +80,21 @@ XHTHREAD AuthClient_Thread()
bLogin = false;
if (0 == st_ProtocolHdr.wReserve)
{
printf(_T("登录成功\n"));
printf(_X("登录成功\n"));
}
else
{
printf(_T("登录失败,错误:%d\n"), st_ProtocolHdr.wReserve);
printf(_X("登录失败,错误:%d\n"), st_ProtocolHdr.wReserve);
}
}
else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_TIMEDOUT == st_ProtocolHdr.unOperatorCode)
{
bTimeOut = false;
printf(_T("用户过期\n"));
printf(_X("用户过期\n"));
}
else
{
printf(_T("不明白的类型\n"));
printf(_X("不明白的类型\n"));
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
Expand All @@ -101,17 +104,16 @@ XHTHREAD AuthClient_Thread()

int AuthClient_Register()
{
int nHTTPCode = 0;
Json::Value st_JsonRoot;
Json::Value st_JsonUserInfo;
Json::Value st_JsonUserTable;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/auth/user/register");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/auth/user/register");

st_JsonUserInfo["tszUserName"] = lpszUser;
st_JsonUserInfo["tszUserPass"] = lpszPass;
st_JsonUserInfo["tszEMailAddr"] = lpszEmail;
st_JsonUserInfo["nPhoneNumber"] = nPhoneNumber;
st_JsonUserInfo["nIDNumber"] = nIDNumber;
st_JsonUserInfo["nPhoneNumber"] = (Json::Value::Int64)nPhoneNumber;
st_JsonUserInfo["nIDNumber"] = (Json::Value::Int64)nIDNumber;
st_JsonUserInfo["nUserLevel"] = 5;

st_JsonUserTable["tszHardCode"] = "2FDWAD02JD2091";
Expand All @@ -120,41 +122,39 @@ int AuthClient_Register()
st_JsonRoot["st_UserTable"] = st_JsonUserTable;

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_Register:\n%s\n", ptszMsgBuffer);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);

return 0;
}
int AuthClient_Pay()
{
int nHTTPCode = 0;
Json::Value st_JsonRoot;
Json::Value st_JsonObject;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/auth/user/pay");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/auth/user/pay");

st_JsonObject["tszSerialNumber"] = lpszSerial;
st_JsonObject["tszUserName"] = lpszUser;

st_JsonRoot["st_UserPay"] = st_JsonObject;

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_Pay:\n%s\n", ptszMsgBuffer);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);

return 0;
}
int AuthClient_DynamicCode()
{
int nHTTPCode = 0;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/api?function=dcode&user=get");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/api?function=dcode&user=get");

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_DynamicCode:\n%s\n", ptszMsgBuffer);

Json::Value st_JsonRoot;
Expand Down Expand Up @@ -200,7 +200,7 @@ int AuthClient_Login()
if (nDYCode > 0)
{
st_ProtocolHdr.xhToken = xhToken;
_stprintf(st_AuthUser.tszDCode, _T("%d"), nDYCode);
_xstprintf(st_AuthUser.tszDCode, _X("%d"), nDYCode);
}

int nMsgLen = 0;
Expand All @@ -210,7 +210,7 @@ int AuthClient_Login()
memset(tszCodecBuffer, '\0', sizeof(tszCodecBuffer));

st_ProtocolHdr.wCrypto = ENUM_XENGINE_PROTOCOLHDR_CRYPTO_TYPE_XCRYPT;
OPenSsl_XCrypto_Encoder((LPCXSTR)&st_AuthUser, (int*)&st_ProtocolHdr.unPacketSize, (UCHAR*)tszCodecBuffer, lpszPass);
OPenSsl_XCrypto_Encoder((LPCXSTR)&st_AuthUser, (int*)&st_ProtocolHdr.unPacketSize, (XBYTE*)tszCodecBuffer, lpszPass);

memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), tszCodecBuffer, st_ProtocolHdr.unPacketSize);
Expand All @@ -227,7 +227,7 @@ int AuthClient_Login()

if (!XClient_TCPSelect_SendMsg(m_Socket, tszMsgBuffer, nMsgLen))
{
printf(_T("登录协议发送失败!\n"));
printf(_X("登录协议发送失败!\n"));
return -1;
}
while (bLogin)
Expand All @@ -238,12 +238,11 @@ int AuthClient_Login()
}
int AuthClient_Notice()
{
int nHTTPCode = 0;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/api?function=notice");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/api?function=notice");

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("GET"), lpszUrl, NULL, &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nMsgLen);

Json::Value st_JsonRoot;
Json::Value st_JsonObject;
Expand All @@ -263,89 +262,89 @@ int AuthClient_Notice()
int nMsgLen = st_JsonArray["tszContext"].asString().length();
BaseLib_OperatorCharset_UTFToAnsi(st_JsonArray["tszContext"].asCString(), tszMsgBuffer, &nMsgLen);

#ifdef _MSC_BUILD
printf("AuthClient_Notice:\nID:%lld:%s\n", st_JsonArray["nID"].asInt64(), tszMsgBuffer);
#else
printf("AuthClient_Notice:\nID:%ld:%s\n", st_JsonArray["nID"].asInt64(), tszMsgBuffer);
#endif
}
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);
return 0;
}
int AuthClient_GetPass()
{
int nHTTPCode = 0;
Json::Value st_JsonRoot;
Json::Value st_JsonObject;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/auth/user/pass");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/auth/user/pass");

st_JsonObject["tszUserName"] = lpszUser;
st_JsonObject["tszEMailAddr"] = lpszEmail;
st_JsonObject["nPhoneNumber"] = nPhoneNumber;
st_JsonObject["nIDNumber"] = nIDNumber;
st_JsonObject["nPhoneNumber"] = (Json::Value::Int64)nPhoneNumber;
st_JsonObject["nIDNumber"] = (Json::Value::Int64)nIDNumber;

st_JsonRoot["st_UserInfo"] = st_JsonObject;

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_GetPass:\n%s\n", ptszMsgBuffer);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);

return 0;
}
int AuthClient_GetTime()
{
int nHTTPCode = 0;
Json::Value st_JsonRoot;
Json::Value st_JsonObject;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/auth/user/time");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/auth/user/time");

st_JsonObject["tszUserName"] = lpszUser;
st_JsonObject["tszUserPass"] = lpszPass;
st_JsonRoot["st_UserAuth"] = st_JsonObject;

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_GetTime:\n%s\n", ptszMsgBuffer);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);

return 0;
}
int AuthClient_Delete()
{
int nHTTPCode = 0;
Json::Value st_JsonRoot;
Json::Value st_JsonObject;
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/auth/user/delete");
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/auth/user/delete");

st_JsonObject["tszUserName"] = lpszUser;
st_JsonObject["tszUserPass"] = lpszPass;
st_JsonObject["tszEMailAddr"] = lpszEmail;
st_JsonObject["nPhoneNumber"] = nPhoneNumber;
st_JsonObject["nIDNumber"] = nIDNumber;
st_JsonObject["nPhoneNumber"] = (Json::Value::Int64)nPhoneNumber;
st_JsonObject["nIDNumber"] = (Json::Value::Int64)nIDNumber;

st_JsonRoot["st_UserInfo"] = st_JsonObject;

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_Delete:\n%s\n", ptszMsgBuffer);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);

return 0;
}
int AuthClient_Try()
{
int nHTTPCode = 0;
Json::Value st_JsonRoot;
Json::Value st_JsonObject;
LPCXSTR lpszSerialNet = _T("cpuid:112233"); //通过此可以做临时网络验证,安全性比本地临时验证高
LPCXSTR lpszUrl = _T("http://127.0.0.1:5302/auth/user/try");
LPCXSTR lpszSerialNet = _X("cpuid:112233"); //通过此可以做临时网络验证,安全性比本地临时验证高
LPCXSTR lpszUrl = _X("http://127.0.0.1:5302/auth/user/try");

st_JsonObject["tszSerial"] = lpszSerialNet;
st_JsonRoot["st_UserTry"] = st_JsonObject;

int nMsgLen = 0;
CHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_T("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen);
XCHAR* ptszMsgBuffer = NULL;
APIClient_Http_Request(_X("POST"), lpszUrl, st_JsonRoot.toStyledString().c_str(), NULL, &ptszMsgBuffer, &nMsgLen);
printf("AuthClient_Try:\n%s\n", ptszMsgBuffer);
BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer);

Expand All @@ -358,7 +357,7 @@ int main()
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
#endif
int nPort = 5300;
LPCXSTR lpszAddr = _T("127.0.0.1");
LPCXSTR lpszAddr = _X("127.0.0.1");

if (!XClient_TCPSelect_Create(&m_Socket, lpszAddr, nPort))
{
Expand Down
4 changes: 3 additions & 1 deletion XEngine_Apps/Authorize_APPClient/Authorize_APPClient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(XEngine_Include);../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(IncludePath)</IncludePath>
<LibraryPath>$(XEngine_Lib64);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
Expand Down Expand Up @@ -116,7 +118,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
Expand Down
Loading

0 comments on commit 7316761

Please sign in to comment.