Skip to content

Commit e8f77ed

Browse files
committed
added:cdkey example ver for service
1 parent 8b7c933 commit e8f77ed

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

XEngine_Source/AuthorizeModule_Configure/Config_Define.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ typedef struct
3333
}st_XMax;
3434
struct
3535
{
36+
struct
37+
{
38+
XCHAR tszKeyFile[MAX_PATH]; //本地CDKEY文件地址
39+
XCHAR tszKeyPass[MAX_PATH]; //本地CDKEY密码
40+
}st_XCDKey;
3641
int nTokenTimeout; //TOKEN登录超时时间
3742
int nDynamicTimeout; //动态码超时时间
3843
int nVerTime; //验证时间

XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
101101
pSt_ServerConfig->st_XMax.nWSThread = st_JsonXMax["nWSThread"].asInt();
102102
pSt_ServerConfig->st_XMax.nHTTPThread = st_JsonXMax["nHTTPThread"].asInt();
103103
//验证配置
104-
if (st_JsonRoot["XVerification"].empty() || (6 != st_JsonRoot["XVerification"].size()))
104+
if (st_JsonRoot["XVerification"].empty() || (7 != st_JsonRoot["XVerification"].size()))
105105
{
106106
Config_IsErrorOccur = true;
107107
Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_XVER;
@@ -114,6 +114,9 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE
114114
pSt_ServerConfig->st_XVerification.nVerMode = st_JsonXVerification["nVerMode"].asInt();
115115
pSt_ServerConfig->st_XVerification.nTryTime = st_JsonXVerification["nTryTime"].asInt();
116116
pSt_ServerConfig->st_XVerification.nTryMode = st_JsonXVerification["nTryMode"].asInt();
117+
118+
_tcsxcpy(pSt_ServerConfig->st_XVerification.st_XCDKey.tszKeyFile, st_JsonXVerification["st_XCDKey"]["tszKeyFile"].asCString());
119+
_tcsxcpy(pSt_ServerConfig->st_XVerification.st_XCDKey.tszKeyPass, st_JsonXVerification["st_XCDKey"]["tszKeyPass"].asCString());
117120
//登录配置
118121
if (st_JsonRoot["XLogin"].empty() || (5 != st_JsonRoot["XLogin"].size()))
119122
{

XEngine_Source/XAuth_Protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
static LPCXSTR lpszXSerialType[5] = { "UNKNOW","SECOND","DAY","TIME","CUSTOM" };
4242
static LPCXSTR lpszXRegType[6] = { "UNKNOW","TEMP","TRY","OFFICIAL","UNLIMIT","EXPIRED" };
4343
static LPCXSTR lpszXHDType[6] = { "UNKNOW","CPU","DISK","BOARD","MAC","BIOS" };
44-
static LPCXSTR lpszXVerType[6] = { "UNKNOW","LOCAL","LAN","NETWORK" };
44+
static LPCXSTR lpszXVerType[6] = { "UNKNOW","LOCAL","NETWORK" };
4545
#ifndef _MSC_BUILD
4646
#pragma GCC diagnostic pop
4747
#endif

XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/Authorize_Dialog/Dialog_CDKey.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ BOOL CDialog_CDKey::OnInitDialog()
8888
{
8989
m_ComboRegHard.InsertString(i, lpszXHDType[i]);
9090
}
91-
for (int i = 0; i < 4; i++)
91+
for (int i = 0; i < 3; i++)
9292
{
9393
m_ComboRegVer.InsertString(i, lpszXVerType[i]);
9494
}
@@ -108,10 +108,10 @@ bool CDialog_CDKey::Dialog_CDKey_Init()
108108
m_ComboRegHard.SetCurSel(4);
109109
m_ComboRegVer.SetCurSel(1);
110110

111-
m_EditIPAddr.SetWindowText(_T("127.0.0.1"));
112-
m_EditPort.SetWindowText(_T("5300"));
111+
m_EditIPAddr.SetWindowText(_T("http://app.xyry.org"));
112+
m_EditPort.SetWindowText(_T("5302"));
113113

114-
m_EditSoftName.SetWindowText(_T("XEngine_Authorze"));
114+
m_EditSoftName.SetWindowText(_T("XEngine_AuthorzeApp"));
115115
m_EditSoftVer.SetWindowText(_T("V1.0.0.1001"));
116116
m_EditSoftTime.SetWindowText(_T("0"));
117117

@@ -262,12 +262,12 @@ bool CDialog_CDKey::Dialog_CDKey_Write(XENGINE_AUTHORIZE_LOCAL* pSt_AuthorizeCDK
262262
void CDialog_CDKey::OnBnClickedButton1()
263263
{
264264
// TODO: 在此添加控件通知处理程序代码
265-
if (0 == m_ComboRegHard.GetCurSel() || 0 == m_ComboRegSerial.GetCurSel() || 0 == m_ComboRegType.GetCurSel() || 0 == m_ComboRegVer.GetCurSel())
265+
if (0 == m_ComboRegSerial.GetCurSel() || 0 == m_ComboRegType.GetCurSel() || 0 == m_ComboRegVer.GetCurSel())
266266
{
267267
AfxMessageBox(_T("创建失败,注册验证类型没选择"));
268268
return;
269269
}
270-
if (3 != m_ComboRegSerial.GetCurSel() || 4 != m_ComboRegSerial.GetCurSel())
270+
if (3 != m_ComboRegSerial.GetCurSel() && 4 != m_ComboRegSerial.GetCurSel())
271271
{
272272
AfxMessageBox(_T("创建失败,注册类型仅支持次数卡和自定义时间卡"));
273273
return;

XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/XEngine_AuthorizeService.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ int main(int argc, char** argv)
9999
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
100100
#endif
101101
bIsRun = true;
102+
FILE* pSt_File = NULL;
102103
HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig;
103104
THREADPOOL_PARAMENT** ppSt_ListTCPThread;
104105
THREADPOOL_PARAMENT** ppSt_ListWSThread;
@@ -315,6 +316,51 @@ int main(int argc, char** argv)
315316
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,信息报告给API服务器没有启用"));
316317
}
317318
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,功能开关选项,删除功能:%d,登录功能:%d,找回密码:%d,充值功能:%d,注册功能:%d,CDKey功能:%d,公告系统:%d,动态验证:%d,多端登录:%d,临时试用:%d,黑名单功能:%d"), st_FunSwitch.bSwitchDelete, st_FunSwitch.bSwitchLogin, st_FunSwitch.bSwitchPass, st_FunSwitch.bSwitchPay, st_FunSwitch.bSwitchRegister, st_FunSwitch.bSwitchCDKey, st_FunSwitch.bSwitchNotice, st_FunSwitch.bSwitchDCode, st_FunSwitch.bSwitchMulti, st_FunSwitch.bSwitchTry, st_FunSwitch.bSwitchBlack);
319+
320+
pSt_File = _xtfopen(st_AuthConfig.st_XVerification.st_XCDKey.tszKeyFile, _X("rb"));
321+
if (NULL == pSt_File)
322+
{
323+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,授权文件验证失败,授权文件没有找到"));
324+
}
325+
else
326+
{
327+
//一个简单的示例,没有验证硬件码
328+
XCHAR tszENCodecBuffer[4096] = {};
329+
XCHAR tszDECodecBuffer[4096] = {};
330+
XENGINE_AUTHORIZE_LOCAL st_AuthLocal = {};
331+
332+
int nRet = fread(tszENCodecBuffer, 1, sizeof(tszENCodecBuffer), pSt_File);
333+
fclose(pSt_File);
334+
335+
if (OPenSsl_XCrypto_Decoder(tszENCodecBuffer, &nRet, tszDECodecBuffer, st_AuthConfig.st_XVerification.st_XCDKey.tszKeyPass))
336+
{
337+
Authorize_CDKey_ReadMemory(tszDECodecBuffer, nRet, &st_AuthLocal);
338+
bool bRet = Authorize_CDKey_GetLeftTimer(&st_AuthLocal);
339+
//无论成功失败需要重写CDKEY
340+
memset(tszENCodecBuffer, '\0', sizeof(tszENCodecBuffer));
341+
memset(tszDECodecBuffer, '\0', sizeof(tszDECodecBuffer));
342+
Authorize_CDKey_WriteMemory(tszDECodecBuffer, &nRet, &st_AuthLocal);
343+
OPenSsl_XCrypto_Encoder(tszDECodecBuffer, &nRet, (XBYTE*)tszENCodecBuffer, st_AuthConfig.st_XVerification.st_XCDKey.tszKeyPass);
344+
pSt_File = _xtfopen(st_AuthConfig.st_XVerification.st_XCDKey.tszKeyFile, _X("wb"));
345+
fwrite(tszENCodecBuffer, 1, nRet, pSt_File);
346+
fclose(pSt_File);
347+
if (bRet)
348+
{
349+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,授权文件验证成功,总可运行次数:%s,剩余可运行次数:%lld"), st_AuthLocal.st_AuthRegInfo.tszLeftTime, st_AuthLocal.st_AuthRegInfo.nHasTime);
350+
}
351+
else
352+
{
353+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,授权文件验证失败,总可运行次数:%s,剩余可运行次数:%lld,错误码:%lX"), st_AuthLocal.st_AuthRegInfo.tszLeftTime, st_AuthLocal.st_AuthRegInfo.nHasTime, Authorize_GetLastError());
354+
}
355+
}
356+
else
357+
{
358+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("启动服务中,授权文件失败,解密失败,数据不正确"));
359+
}
360+
361+
fclose(pSt_File);
362+
}
363+
318364
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("所有服务成功启动,网络验证服务运行中,XEngien版本:%s%s,发行版本次数:%d,当前运行版本:%s。。。"), BaseLib_OperatorVer_XNumberStr(), BaseLib_OperatorVer_XTypeStr(), st_AuthConfig.st_XVer.pStl_ListVer->size(), st_AuthConfig.st_XVer.pStl_ListVer->front().c_str());
319365
while (true)
320366
{

0 commit comments

Comments
 (0)