diff --git a/README.en.md b/README.en.md index 3ac2be389b64e9f51748fe7d453045f5b280b425..32076aaffb010b0e18cd29bea2a03f9396b6414e 100644 --- a/README.en.md +++ b/README.en.md @@ -19,17 +19,12 @@ Stable and reliable: based on C/C++, the core framework has been verified for 10 Flexible authentication: supports third-party authentication and authorization, supports distributed authentication and authorization, and can use its own user password system more functions: support various types of authorization -#### Choose the Right One -Most products on the market either charge fees, update slowly, or lack complete functionality. They also lack technical support. With our product, you don't need to worry about these issues at all. -Our product is completely free and offers both free and paid technical support. It is rich in features and allows for custom development. You can start using our product now and experience the best and open-source time service available. - #### Version difference V3 version, the protocol is basically reimplemented. It is no longer compatible with the V2 protocol. V3 is basically changed to the HTTP interface for management. The compatibility is better. Please check the documentation for more. V2 Version can be update to V3,V3 DB Compatible with V2 Databse ## Software feature -Our feature list not only includes the following but also has many features in development. -You can refer to this webpage to learn about the features we plan to support in the future: https://github.com/libxengine/XEngine_Authorize/issues +A simple and high-performance cross-platform network authentication and authorization server developed and implemented based on XEngine feature list: 1. support http.websocket protocols 2. Support Encrypto communication @@ -132,6 +127,9 @@ Database update Use Navicat and other database software to open the judgment tab After modification, directly copy the database to the new version to overwrite, and modify your configuration file 3.11->3.12 A new time field has been added to the user table, please refer to the SQL file +## Authorization instructions +Use this software must be open source and indicate the source,If you want closed source and commercial,Then need to be authorized by the author. + ## Follow us If you think this software is helpful to you, please give us a START and wechat qr scan to follow us diff --git a/README.md b/README.md index 01258e5902961999236542522e9e34b5b260edb4..042a95eb6763f91c36cc873488493ce347a5c93f 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,12 @@ c c++network Authorize service 灵活验证:支持第三方验证授权,支持分布式验证授权,可以使用自己的用户密码系统 功能丰富:支持各种类型授权,支持时间和次数等等模式 -#### 选择对的 -目前市面上的大多数产品不是收费就是产品更新慢,或者功能不全。没有技术支持。使用我们的产品你完全不需要有这方便的担心。 -我们的产品完全免费,提供免费技术支持和收费技术支持。功能丰富多样,还可以自主开发。现在,你就可以使用我们的产品并且体验目前最好的并且开源的授时服务. - #### 版本区别 V3版本后协议基本重新实现,不在兼容V2协议,V3基本改为HTTP接口进行管理.兼容性更好.请查看文档获取更多. V2可以直接升级到V3版本,因为数据库并没有修改,直接替换程序即可.数据库兼容V2版本 -## 软件特性 -我们的功能列表不仅包括下面的,还有很多待开发的功能正在计划中。 -你可以参考这个网页了解我们未来支持的功能列表:https://github.com/libxengine/XEngine_Authorize/issues +## 软件特性 +基于XEngine开发并实现的一套简洁高性能跨平台网络验证授权服务器 软件特性: 1. 支持TCP,WEBSOCKET协议 2. 支持加密通信 @@ -146,6 +141,9 @@ V3版本为全新版本,为了适应过多环境要求开发 ## 视频教程 你也可以观看视频教程来了解我们的代码框架情况:https://www.bilibili.com/video/BV1iF4m177aG +## 授权说明 +使用此软件必须开源并且注明出处,如果想闭源商用,那么需要经过作者授权. + ## 关注我们 如果你觉得这个软件对你有帮助,请你给我们一个START吧 也可以通过微信关注我们 diff --git a/XEngine_Apps/Authorize_APPClient/Authorize_APPClient.cpp b/XEngine_Apps/Authorize_APPClient/Authorize_APPClient.cpp index 9017d17978a499b66783a8ec075a927e23e93dc8..841966bd673dc83ee584d61fd064396abb2b718b 100644 --- a/XEngine_Apps/Authorize_APPClient/Authorize_APPClient.cpp +++ b/XEngine_Apps/Authorize_APPClient/Authorize_APPClient.cpp @@ -39,7 +39,7 @@ using namespace std; bool bRun = true; bool bLogin = true; bool bTimeOut = true; -bool bEncrypto = true; +bool bEncrypto = false; XNETHANDLE xhToken = 0; int nDYCode = 0; @@ -123,27 +123,10 @@ int AuthClient_Register() int nMsgLen = 0; 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); - if (bEncrypto) - { - XCHAR tszENBuffer[2048] = {}; - XCHAR tszDEBuffer[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENBuffer, lpszPass); - APIClient_Http_Request(_X("POST"), lpszUrl, tszENBuffer, NULL, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - printf("AuthClient_Register:\n%s\n", tszDEBuffer); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - } - else - { - 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() @@ -159,26 +142,10 @@ int AuthClient_Pay() int nMsgLen = 0; 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); - if (bEncrypto) - { - XCHAR tszENBuffer[2048] = {}; - XCHAR tszDEBuffer[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENBuffer, lpszPass); - APIClient_Http_Request(_X("POST"), lpszUrl, tszENBuffer, NULL, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - printf("AuthClient_Pay:\n%s\n", tszDEBuffer); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - } - else - { - 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() @@ -188,29 +155,15 @@ int AuthClient_DynamicCode() int nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; APIClient_Http_Request(_X("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nMsgLen); + printf("AuthClient_DynamicCode:\n%s\n", ptszMsgBuffer); Json::Value st_JsonRoot; JSONCPP_STRING st_JsonError; Json::CharReaderBuilder st_ReaderBuilder; std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); - if (bEncrypto) + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) { - XCHAR tszDEBuffer[2048] = {}; - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - if (!pSt_JsonReader->parse(tszDEBuffer, tszDEBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - return 0; - } - printf("AuthClient_DynamicCode:\n%s\n", tszDEBuffer); - } - else - { - if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - return 0; - } - printf("AuthClient_DynamicCode:\n%s\n", ptszMsgBuffer); + return 0; } XCHAR tszDCodeStr[64]; XCHAR tszTokenStr[64]; @@ -289,31 +242,17 @@ int AuthClient_Notice() int nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; + APIClient_Http_Request(_X("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nMsgLen); + Json::Value st_JsonRoot; Json::Value st_JsonObject; JSONCPP_STRING st_JsonError; Json::CharReaderBuilder st_ReaderBuilder; std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); - - APIClient_Http_Request(_X("GET"), lpszUrl, NULL, NULL, &ptszMsgBuffer, &nMsgLen); - if (bEncrypto) - { - XCHAR tszDEBuffer[2048] = {}; - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - if (!pSt_JsonReader->parse(tszDEBuffer, tszDEBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - return 0; - } - } - else + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) { - if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - return 0; - } + return 0; } - for (unsigned int i = 0; i < st_JsonRoot["Array"].size(); i++) { XCHAR tszMsgBuffer[2048]; @@ -347,26 +286,9 @@ int AuthClient_GetPass() int nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; - - if (bEncrypto) - { - XCHAR tszENBuffer[2048] = {}; - XCHAR tszDEBuffer[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENBuffer, lpszPass); - APIClient_Http_Request(_X("POST"), lpszUrl, tszENBuffer, NULL, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - printf("AuthClient_GetPass:\n%s\n", tszDEBuffer); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - } - else - { - 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); - } + 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; } @@ -382,26 +304,9 @@ int AuthClient_GetTime() int nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; - - if (bEncrypto) - { - XCHAR tszENBuffer[2048] = {}; - XCHAR tszDEBuffer[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENBuffer, lpszPass); - APIClient_Http_Request(_X("POST"), lpszUrl, tszENBuffer, NULL, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - printf("AuthClient_GetTime:\n%s\n", tszDEBuffer); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - } - else - { - 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); - } + 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; } @@ -421,26 +326,10 @@ int AuthClient_Delete() int nMsgLen = 0; 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); - if (bEncrypto) - { - XCHAR tszENBuffer[2048] = {}; - XCHAR tszDEBuffer[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENBuffer, lpszPass); - APIClient_Http_Request(_X("POST"), lpszUrl, tszENBuffer, NULL, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - printf("AuthClient_Delete:\n%s\n", tszDEBuffer); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - } - else - { - 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() @@ -455,26 +344,10 @@ int AuthClient_Try() int nMsgLen = 0; 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); - if (bEncrypto) - { - XCHAR tszENBuffer[2048] = {}; - XCHAR tszDEBuffer[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENBuffer, lpszPass); - APIClient_Http_Request(_X("POST"), lpszUrl, tszENBuffer, NULL, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDEBuffer, lpszPass); - printf("AuthClient_Try:\n%s\n", tszDEBuffer); - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - } - else - { - 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); - } return 0; } int main() diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 92fa662855c02eadb5124ef218e3e99ab79939e3..e5e5cb272438a8932715aa2963504848eee61122 100644 Binary files a/XEngine_Docment/Docment_en.docx and b/XEngine_Docment/Docment_en.docx differ diff --git a/XEngine_Docment/Docment_zh.docx b/XEngine_Docment/Docment_zh.docx index 8d7ed81e917de81dfe8411547091436f63c3dfb1..3d688c4f0cc7705610ba192f970b89394b5e7089 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_SQL/xengine_authorize.sql b/XEngine_SQL/xengine_authorize.sql new file mode 100644 index 0000000000000000000000000000000000000000..7925a398771f5a29917c5778c8fcb2b73c94c04f --- /dev/null +++ b/XEngine_SQL/xengine_authorize.sql @@ -0,0 +1,197 @@ +/* + Navicat Premium Data Transfer + + Source Server : 本地mysql + Source Server Type : MySQL + Source Server Version : 50726 + Source Host : localhost:3306 + Source Schema : xengine_authorize + + Target Server Type : MySQL + Target Server Version : 50726 + File Encoding : 65001 + + Date: 04/07/2024 20:51:48 +*/ + +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for authorize_announcement +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_announcement`; +CREATE TABLE `authorize_announcement` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `tszContext` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, + `tszCreateTime` date NULL DEFAULT NULL, + PRIMARY KEY (`ID`) USING BTREE +) ENGINE = MyISAM AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_announcement +-- ---------------------------- +INSERT INTO `authorize_announcement` VALUES (5, 'test0003', '2024-06-20'); + +-- ---------------------------- +-- Table structure for authorize_bannedaddr +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_bannedaddr`; +CREATE TABLE `authorize_bannedaddr` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `bEnable` tinyint(4) NOT NULL, + `tszIPAddr` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `tszLeftTime` date NULL DEFAULT NULL, + `tszCreateTime` date NOT NULL, + PRIMARY KEY (`ID`) USING BTREE +) ENGINE = MyISAM AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_bannedaddr +-- ---------------------------- + +-- ---------------------------- +-- Table structure for authorize_banneduser +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_banneduser`; +CREATE TABLE `authorize_banneduser` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `bEnable` tinyint(1) NOT NULL, + `tszUserName` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `tszLeftTime` date NULL DEFAULT NULL, + `tszCreateTime` date NOT NULL, + PRIMARY KEY (`ID`) USING BTREE +) ENGINE = MyISAM AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_banneduser +-- ---------------------------- +INSERT INTO `authorize_banneduser` VALUES (3, 0, '123123aa', '2023-11-01', '2024-06-26'); + +-- ---------------------------- +-- Table structure for authorize_coin +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_coin`; +CREATE TABLE `authorize_coin` ( + `coin_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '币种id', + `platform` int(11) NOT NULL COMMENT '所属平台', + `currency_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '币种名称', + `network` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '网络', + `contract_address` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '合约地址', + `Docking_platform` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '对接平台', + `remarks` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注', + `Official_website` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '官方网站', + `delisted` int(11) NULL DEFAULT NULL COMMENT '是否下架(0代表未下架 1代表已暂停 2代表已下架 3代币已删除)', + `Block_Browser` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '区块浏览器', + `Slip_point_and_combustion` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '滑点与燃烧', + `Withdrawal_time` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '提现功能开启时间', + `del_flag` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '删除标志(0代表存在 1代表正常 2代表删除)', + `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建者', + `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新者', + `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`coin_id`) USING BTREE, + INDEX `ix_sys_coin_coin_id`(`coin_id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 6678 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_coin +-- ---------------------------- +INSERT INTO `authorize_coin` VALUES (1, 1, 'FNF', 'BEP20', '0xacf8d5e515ed005655dfefa09c22673a37a7cdee', 'Mexc Gate', '抹茶叫FUNFI', 'https://www.funfi.org/', 1, 'https://etherscan.io/token/0xacf8d5e515ed005655dfefa09c22673a37a7cdee', '', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (2, 1, 'FNF', 'ERC20', '0xe803178b48A0e560C2b19F3b3d4e504f79D229ce', 'Bitmart Lbank', '-', 'https//www.bobcoin.eco', 0, 'https://etherscan.io/token/0xe803178b48A0e560C2b19F3b3d4e504f79D229ce', '', '2023-01-01 00:00:00', '1', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (32, 1, 'QANX', 'ERC20', '0xAAA9214F675316182Eaa21C85f0Ca99160CC3AAA', 'Bitmart Gate', '某茶确认充值', 'https//www.qanplatform.com/', 0, '0xAAA9214F675316182Eaa21C85f0Ca99160CC3AAA', '', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (33, 1, 'QANX', 'BEP20', '0xAAA9214F675316182Eaa21C85f0Ca99160CC3AAA', 'Wallet Bitmart Gate', '芝麻到钱包确认充值', 'https//www.qanplatform.com/', 0, 'https://bscscan.com/token/0xAAA9214F675316182Eaa21C85f0Ca99160CC3AAA', '买卖不用滑点', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (34, 1, 'MISA', 'BEP20', '0x934b0633f4874ca9340341ad66ff2f6ce3124b4c', 'Wallet Bitmart Lbank', '', 'https://www.misatoken.com/zh-cn', 1, 'https://bscscan.com/token/0x934b0633f4874ca9340341ad66ff2f6ce3124b4c', '钱包没有流动性', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (508, 1, 'FORM', 'ERC20', '0x21381e026ad6d8266244f2a583b35f9e4413fa2a', 'Bitmart Mexc Kucoin Gate', '库币确认充值', 'https://formation.fi', 0, 'https://etherscan.io/token/0x21381e026ad6d8266244f2a583b35f9e4413fa2a', '', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (509, 1, 'STORJ', 'ERC20', '0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac', 'Bitmart Mexc Kucoin Lbank Gate Bkex Ok Huobi Binance', '', 'https://storj.io/', 0, 'https://etherscan.io/token/0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac', '', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (510, 1, 'FXS', 'ERC20', '0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0', 'Bitmart Mexc Kucoin Lbank Binance Gate Bkex Xt', '', 'https://frax.finance/', 0, 'https://etherscan.io/token/0x3432b6a60d23ca0dfca7761b7ab56459d9c964d0', '', '2023-01-01 00:00:00', '0', 'admin', 'admin', '2023-12-12 17:34:28', '2023-12-12 17:34:28'); +INSERT INTO `authorize_coin` VALUES (6677, 1, 'QANX3333', 'BEP202', '0xAAA9214F675316182Eaa21C85f033444444', 'bitmart mexc', 'beizhu33333', 'guanwang332211', 2, 'qukaui333', 'huadian33', '2024-07-02 17:00:00', '1', 'admin', 'test01', '2024-07-03 04:27:16', '2024-07-03 04:52:16'); + +-- ---------------------------- +-- Table structure for authorize_serial +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_serial`; +CREATE TABLE `authorize_serial` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `UserName` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, + `SerialNumber` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, + `MaxTime` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL, + `CardSerialType` int(11) NULL DEFAULT NULL, + `bIsUsed` tinyint(1) NULL DEFAULT NULL, + `CreateTime` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`ID`) USING BTREE +) ENGINE = MyISAM AUTO_INCREMENT = 17 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_serial +-- ---------------------------- +INSERT INTO `authorize_serial` VALUES (1, 'NOT', 'XAUTH-XYRYS-MAR60-54RRO-FZRUA-26014-HLL22', '60', 1, 0, '2024-06-18 23:22:35'); +INSERT INTO `authorize_serial` VALUES (2, 'NOT', 'XAUTH-XYRYS-SGL60-44NHI-IGFGX-40652-MRH79', '60', 1, 0, '2024-06-18 23:22:35'); +INSERT INTO `authorize_serial` VALUES (3, 'NOT', 'XAUTH-XYRYS-WGP60-49HLJ-JDACQ-33453-OUZ13', '60', 1, 0, '2024-06-18 23:22:35'); +INSERT INTO `authorize_serial` VALUES (5, 'NOT', 'XAUTH-XYRYS-QIV60-75CBB-ERYVY-29360-ODF41', '60', 1, 0, '2024-06-18 23:22:35'); +INSERT INTO `authorize_serial` VALUES (6, 'NOT', 'XAUTH-XYRYS-JDF60-92JNY-OGPWV-37503-IBN97', '60', 1, 0, '2024-06-18 23:22:35'); + +-- ---------------------------- +-- Table structure for authorize_tempver +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_tempver`; +CREATE TABLE `authorize_tempver` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `tszVSerial` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `nVMode` int(11) NOT NULL, + `nVTime` int(11) NOT NULL, + `nLTime` int(11) NOT NULL, + `CreateTime` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`ID`) USING BTREE +) ENGINE = MyISAM AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_tempver +-- ---------------------------- + +-- ---------------------------- +-- Table structure for authorize_user +-- ---------------------------- +DROP TABLE IF EXISTS `authorize_user`; +CREATE TABLE `authorize_user` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `UserName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户名', + `Password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '密码', + `LeftTime` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '剩余时间', + `EmailAddr` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '电子邮件', + `HardCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '设备SN', + `CardSerialType` int(11) NOT NULL, + `PhoneNumber` bigint(20) NOT NULL COMMENT '电话号码', + `IDCard` bigint(20) NOT NULL COMMENT '身份证', + `nUserLevel` int(11) NOT NULL COMMENT '用户等级,数字越小越高', + `UPTime` datetime NULL DEFAULT NULL COMMENT '登录时间', + `CreateTime` datetime NOT NULL COMMENT '注册时间', + PRIMARY KEY (`ID`) USING BTREE +) ENGINE = MyISAM AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of authorize_user +-- ---------------------------- +INSERT INTO `authorize_user` VALUES (1, 'admin', '123123aa', '0', '486179@qq.com', 'DAFD2A2DAD', 1, 13699430000, 511025198881118888, 0, '2022-09-21 15:06:45', '2022-09-21 15:06:45'); +INSERT INTO `authorize_user` VALUES (2, 'test001', '123123', '600', '123@qq.com', 'FD52FD2TYH7', 1, 13444444444, 5111222333, 5, '2024-06-26 02:48:37', '2024-06-19 03:05:50'); +INSERT INTO `authorize_user` VALUES (4, '123123aa', '123123', '59884582', '486179@qq.com', '2FDWAD02JD2091', 1, 1366666666, 511025111111111111, 10, '2024-06-27 23:31:11', '2024-06-19 03:23:51'); + +-- ---------------------------- +-- Table structure for sqlite_sequence +-- ---------------------------- +DROP TABLE IF EXISTS `sqlite_sequence`; +CREATE TABLE `sqlite_sequence` ( + `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, + `seq` int(11) NULL DEFAULT NULL +) ENGINE = MyISAM CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of sqlite_sequence +-- ---------------------------- +INSERT INTO `sqlite_sequence` VALUES ('Authorize_BannedUser', 6); +INSERT INTO `sqlite_sequence` VALUES ('Authorize_BannedAddr', 5); +INSERT INTO `sqlite_sequence` VALUES ('Authorize_TempVer', 1); +INSERT INTO `sqlite_sequence` VALUES ('Authorize_Serial', 10); +INSERT INTO `sqlite_sequence` VALUES ('Authorize_User', 5); + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/XEngine_Source/AuthClient_Connector/AuthClient_Connector.cpp b/XEngine_Source/AuthClient_Connector/AuthClient_Connector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..401bdc0ea0ec93e76ce5b01ae61f1e7f2dbf8a8f --- /dev/null +++ b/XEngine_Source/AuthClient_Connector/AuthClient_Connector.cpp @@ -0,0 +1,287 @@ +#include "pch.h" +#include "AuthClient_Connector.h" +/******************************************************************** +// Created: 2023/11/15 10:36:04 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_Connector\AuthClient_Connector.cpp +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_Connector +// File Base: AuthClient_Connector +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 验证客户端示例模块 +// History: +*********************************************************************/ +CAuthClient_Connector::CAuthClient_Connector() +{ +} +CAuthClient_Connector::~CAuthClient_Connector() +{ +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:AuthClient_Connector_Connect +函数功能:链接到服务器 + 参数.一:lpszClientAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器地址 + 参数.二:nPort + In/Out:In + 类型:整数型 + 可空:N + 意思:服务器端口 + 参数.三:lpszPass + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器密码,如果没有填空 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAuthClient_Connector::AuthClient_Connector_Connect(LPCXSTR lpszClientAddr, int nPort, LPCXSTR lpszPass /* = NULL */) +{ + AuthClient_IsErrorOccur = true; + + if (NULL == lpszClientAddr) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_PARAMENT; + return false; + } +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP) + if (!XClient_TCPSelect_Create(&m_hSocket, lpszClientAddr, nPort, 2)) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = XClient_GetLastError(); + return false; + } + if (NULL != lpszPass) + { + _tcsxcpy(tszPassStr, lpszPass); + } +#endif + return true; +} +/******************************************************************** +函数名称:AuthClient_Connector_Close +函数功能:销毁关闭客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAuthClient_Connector::AuthClient_Connector_Close() +{ + AuthClient_IsErrorOccur = false; + +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP) + if (NULL != pSTDThread) + { + m_bRun = false; + pSTDThread->join(); + } + m_bLogin = false; + XClient_TCPSelect_Close(m_hSocket); +#endif + return true; +} +/******************************************************************** +函数名称:AuthClient_Connector_GetAuth +函数功能:验证用户是否登录或者超时 + 参数.一:pbAuth + In/Out:Out + 类型:逻辑型指针 + 可空:Y + 意思:输出是否验证,如果登录成功但是参数为假.说明没有剩余时间了 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAuthClient_Connector::AuthClient_Connector_GetAuth(bool* pbAuth /* = NULL */) +{ + AuthClient_IsErrorOccur = false; + +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP) + if (NULL != pbAuth) + { + *pbAuth = m_bAuth; + } +#endif + return m_bLogin; +} +/******************************************************************** +函数名称:AuthClient_Connector_Login +函数功能:登录到服务器 + 参数.一:lpszUser + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入用户名 + 参数.二:lpszPass + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入密码 + 参数.三:nDYCode + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入动态码 + 参数.四:xhToken + In/Out:In + 类型:句柄型 + 可空:Y + 意思:输入动态码绑定的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAuthClient_Connector::AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode /* = 0 */, XNETHANDLE xhToken /* = 0 */) +{ + AuthClient_IsErrorOccur = false; + + if ((NULL == lpszUser) || (NULL == lpszPass)) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_PARAMENT; + return false; + } +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP) + XCHAR tszMsgBuffer[2048] = {}; + XENGINE_PROTOCOLHDR st_ProtocolHdr = {}; + XENGINE_PROTOCOL_USERAUTH st_AuthUser = {}; + //协议头 + st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; + st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH; + st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN; + st_ProtocolHdr.unPacketSize = sizeof(XENGINE_PROTOCOL_USERAUTH); + st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; + +#ifdef _MSC_BUILD + st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_WINDOWS; +#elif __linux__ + st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_LINUX; +#else + st_AuthUser.enDeviceType = ENUM_PROTOCOL_FOR_DEVICE_TYPE_PC_MACOS; +#endif + _tcsxcpy(st_AuthUser.tszUserName, lpszUser); + _tcsxcpy(st_AuthUser.tszUserPass, lpszPass); + //是否有动态码 + if (nDYCode > 0) + { + st_ProtocolHdr.xhToken = xhToken; + _xstprintf(st_AuthUser.tszDCode, _X("%d"), nDYCode); + } + //是否加密 + int nMsgLen = 0; + if (_tcsxlen(tszPassStr) > 0) + { + XCHAR tszCodecBuffer[2048] = {}; + + st_ProtocolHdr.wCrypto = ENUM_XENGINE_PROTOCOLHDR_CRYPTO_TYPE_XCRYPT; + OPenSsl_XCrypto_Encoder((LPCXSTR)&st_AuthUser, (int*)&st_ProtocolHdr.unPacketSize, (XBYTE*)tszCodecBuffer, tszPassStr); + + memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR)); + memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), tszCodecBuffer, st_ProtocolHdr.unPacketSize); + + nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize; + } + else + { + memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR)); + memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), &st_AuthUser, st_ProtocolHdr.unPacketSize); + + nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + sizeof(XENGINE_PROTOCOL_USERAUTH); + } + //发送数据 + if (!XClient_TCPSelect_SendMsg(m_hSocket, tszMsgBuffer, nMsgLen)) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_SEND; + return false; + } + + nMsgLen = 0; + XCHAR* ptszMsgBuffer; + st_ProtocolHdr = {}; + //接受数据 + if (!XClient_TCPSelect_RecvPkt(m_hSocket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_RECV; + return false; + } + //判断是否登录协议 + if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REPLOGIN != st_ProtocolHdr.unOperatorCode) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_LOGIN; + return false; + } + //登录失败,错误码 + if (0 != st_ProtocolHdr.wReserve) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = st_ProtocolHdr.wReserve; + return false; + } + m_bRun = true; + m_bLogin = true; + m_bAuth = true; + //登录成功,创建线程 + pSTDThread = make_shared(AuthClient_Connector_Thread, this); + if (NULL == pSTDThread) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_CLIENT_THREAD; + return false; + } +#endif + return true; +} +////////////////////////////////////////////////////////////////////////// +// 保护函数 +////////////////////////////////////////////////////////////////////////// +XHTHREAD CALLBACK CAuthClient_Connector::AuthClient_Connector_Thread(XPVOID lParam) +{ + CAuthClient_Connector* pClass_This = (CAuthClient_Connector*)lParam; + +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP) + while (pClass_This->m_bRun) + { + int nMsgLen = 0; + XCHAR* ptszMsgBuffer; + XENGINE_PROTOCOLHDR st_ProtocolHdr = {}; + + if (!XClient_TCPSelect_RecvPkt(pClass_This->m_hSocket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + pClass_This->m_bLogin = false; + break; + } + XCHAR tszMsgBuffer[4096] = {}; + if (nMsgLen > 0 && _tcsxlen(pClass_This->tszPassStr) > 0) + { + //只有有后续数据的情况才需要解密 + OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszMsgBuffer, pClass_This->tszPassStr); + } + else + { + memcpy(tszMsgBuffer, ptszMsgBuffer, nMsgLen); + } + + if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_TIMEDOUT == st_ProtocolHdr.unOperatorCode) + { + pClass_This->m_bAuth = false; + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_Source/AuthClient_Connector/AuthClient_Connector.h b/XEngine_Source/AuthClient_Connector/AuthClient_Connector.h new file mode 100644 index 0000000000000000000000000000000000000000..2d0514707c02d5023c659b80eab6b73dd920d783 --- /dev/null +++ b/XEngine_Source/AuthClient_Connector/AuthClient_Connector.h @@ -0,0 +1,40 @@ +#pragma once +/******************************************************************** +// Created: 2023/11/15 10:34:36 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_Connector\AuthClient_Connector.h +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_Connector +// File Base: AuthClient_Connector +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 验证客户端示例模块 +// History: +*********************************************************************/ +typedef struct +{ + XNETHANDLE xhToken; + int nDynamicCode; + time_t nTimeStart; +}AUTHHELP_DYNAMICCODE; + +class CAuthClient_Connector +{ +public: + CAuthClient_Connector(); + ~CAuthClient_Connector(); +public: + bool AuthClient_Connector_Connect(LPCXSTR lpszClientAddr, int nPort, LPCXSTR lpszPass = NULL); + bool AuthClient_Connector_Close(); + bool AuthClient_Connector_GetAuth(bool* pbAuth = NULL); + bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0); +protected: + static XHTHREAD CALLBACK AuthClient_Connector_Thread(XPVOID lParam); +private: + bool m_bRun = false; + bool m_bLogin = false; + bool m_bAuth = false; + XSOCKET m_hSocket = 0; + XCHAR tszPassStr[128] = {}; +private: + shared_ptr pSTDThread; +}; \ No newline at end of file diff --git a/XEngine_Source/AuthClient_Define.h b/XEngine_Source/AuthClient_Define.h new file mode 100644 index 0000000000000000000000000000000000000000..60ae0157d0efef65017ee627f858a86c666b7d0e --- /dev/null +++ b/XEngine_Source/AuthClient_Define.h @@ -0,0 +1,141 @@ +#pragma once +/******************************************************************** +// Created: 2023/11/15 11:29:49 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_Define.h +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client +// File Base: AuthClient_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 为了方便使用,封装了验证客户端,可以通过c/c++ e 等语言使用 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出的函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG AuthClient_GetLastError(int *pInt_SysError = NULL); +/************************************************************************/ +/* 验证客户端导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:AuthClient_Connector_Connect +函数功能:链接到服务器 + 参数.一:lpszClientAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器地址 + 参数.二:nPort + In/Out:In + 类型:整数型 + 可空:N + 意思:服务器端口 + 参数.三:lpszPass + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器密码,如果没有填空 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool AuthClient_Connector_Connect(LPCXSTR lpszClientAddr, int nPort, LPCXSTR lpszPass = NULL); +/******************************************************************** +函数名称:AuthClient_Connector_Close +函数功能:销毁关闭客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool AuthClient_Connector_Close(); +/******************************************************************** +函数名称:AuthClient_Connector_GetAuth +函数功能:验证用户是否登录或者超时 + 参数.一:pbAuth + In/Out:Out + 类型:逻辑型指针 + 可空:Y + 意思:输出是否验证,如果登录成功但是参数为假.说明没有剩余时间了 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool AuthClient_Connector_GetAuth(bool* pbAuth = NULL); +/******************************************************************** +函数名称:AuthClient_Connector_Login +函数功能:登录到服务器 + 参数.一:lpszUser + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入用户名 + 参数.二:lpszPass + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入密码 + 参数.三:nDYCode + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入动态码 + 参数.四:xhToken + In/Out:In + 类型:句柄型 + 可空:Y + 意思:输入动态码绑定的句柄 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode = 0, XNETHANDLE xhToken = 0); +/************************************************************************/ +/* 临时验证函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:AuthClient_HTTPVer_TryRequest +函数功能:试用版请求 + 参数.一:lpszURLAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr); +/******************************************************************** +函数名称:AuthClient_HTTPVer_GetDCode +函数功能:获取动态码 + 参数.一:lpszURLAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器地址,完成的API地址,比如:http://127.0.0.1:5302/api?function=dcode&user=get + 参数.二:pInt_DYCode + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出动态码 + 参数.二:pxhToken + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出绑定的句柄 + 参数.三:pInt_Timeout + In/Out:Out + 类型:整数型指针 + 可空:Y + 意思:输出动态码超时时间 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout = NULL); \ No newline at end of file diff --git a/XEngine_Source/AuthClient_Error.h b/XEngine_Source/AuthClient_Error.h new file mode 100644 index 0000000000000000000000000000000000000000..61c2a54bebe42f1b0edb964e82b913d9de603240 --- /dev/null +++ b/XEngine_Source/AuthClient_Error.h @@ -0,0 +1,29 @@ +#pragma once +/******************************************************************** +// Created: 2023/11/15 11:32:27 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_Error.h +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client +// File Base: AuthClient_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 错误表 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出的错误表 +////////////////////////////////////////////////////////////////////////// +/************************************************************************/ +/* 网络协议错误 */ +/************************************************************************/ +#define ERROR_AUTHORIZE_MODULE_CLIENT_PARAMENT 0x0060000 //参数错误,无法继续 +#define ERROR_AUTHORIZE_MODULE_CLIENT_SEND 0x0060001 //发送数据失败 +#define ERROR_AUTHORIZE_MODULE_CLIENT_RECV 0x0060002 //接受数据失败 +#define ERROR_AUTHORIZE_MODULE_CLIENT_LOGIN 0x0060003 //登录失败,请查看错误码 +#define ERROR_AUTHORIZE_MODULE_CLIENT_THREAD 0x0060004 //创建线程失败 +/************************************************************************/ +/* HTTP验证错误 */ +/************************************************************************/ +#define ERROR_AUTHORIZE_MODULE_HTTPVER_PARAMENT 0x0060010 +#define ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE 0x0060011 +#define ERROR_AUTHORIZE_MODULE_HTTPVER_VERFAILED 0x0060012 \ No newline at end of file diff --git a/XEngine_Source/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp b/XEngine_Source/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d571e2191dc82f8e019cb9c7e2d833c990abf00d --- /dev/null +++ b/XEngine_Source/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp @@ -0,0 +1,160 @@ +#include "pch.h" +#include "AuthClient_HTTPVer.h" +/******************************************************************** +// Created: 2024/01/04 09:44:04 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_HTTPVer\AuthClient_HTTPVer.cpp +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_HTTPVer +// File Base: AuthClient_HTTPVer +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 临时授权客户端 +// History: +*********************************************************************/ +CAuthClient_HTTPVer::CAuthClient_HTTPVer() +{ +} +CAuthClient_HTTPVer::~CAuthClient_HTTPVer() +{ +} +////////////////////////////////////////////////////////////////////////// +// 公有函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:AuthClient_HTTPVer_TryRequest +函数功能:试用版请求 + 参数.一:lpszURLAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:函数的API地址,需要输入完整的URL +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr) +{ + AuthClient_IsErrorOccur = true; + + if (NULL == lpszURLAddr) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARAMENT; + return false; + } +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_HTTP) + int nHTTPCode = 0; + XCHAR tszJsonStr[MAX_PATH] = {}; + Json::Value st_JsonRoot; + Json::Value st_JsonObject; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_ReaderBuilder; + SYSTEMAPI_SERIAL_INFOMATION st_SDKSerial = {}; + + SystemApi_HardWare_GetSerial(&st_SDKSerial); + + _xstprintf(tszJsonStr, _X("%s"), st_SDKSerial.tszBoardSerial); + + st_JsonObject["tszVSerial"] = tszJsonStr; + st_JsonRoot["st_VERTemp"] = st_JsonObject; + //请求 + int nMsgLen = 0; + XCHAR* ptszMsgBuffer = NULL; + APIClient_Http_Request(_X("POST"), lpszURLAddr, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen); + st_JsonRoot.clear(); + st_JsonObject.clear(); + //解析回复 + std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + return false; + } + if (0 != st_JsonRoot["code"].asInt()) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_VERFAILED; + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + return false; + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +#endif + return true; +} +/******************************************************************** +函数名称:AuthClient_HTTPVer_GetDCode +函数功能:获取动态码 + 参数.一:lpszURLAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:服务器地址,完成的API地址,比如:http://127.0.0.1:5302/api?function=dcode&user=get + 参数.二:pInt_DYCode + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出动态码 + 参数.二:pxhToken + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出绑定的句柄 + 参数.三:pInt_Timeout + In/Out:Out + 类型:整数型指针 + 可空:Y + 意思:输出动态码超时时间 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CAuthClient_HTTPVer::AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout /* = NULL */) +{ + AuthClient_IsErrorOccur = true; + + if (NULL == lpszURLAddr) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARAMENT; + return false; + } +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_HTTP) + int nHTTPCode = 0; + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_ReaderBuilder; + //请求 + int nMsgLen = 0; + XCHAR* ptszMsgBuffer = NULL; + APIClient_Http_Request(_X("GET"), lpszURLAddr, NULL, &nHTTPCode, &ptszMsgBuffer, &nMsgLen); + //解析回复 + std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + return false; + } + if (0 != st_JsonRoot["code"].asInt()) + { + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_VERFAILED; + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + return false; + } + + *pInt_DYCode = st_JsonRoot["nDynamicCode"].asInt(); + *pxhToken = st_JsonRoot["xhToken"].asUInt64(); + if (NULL != pInt_Timeout) + { + *pInt_Timeout = st_JsonRoot["nTimeout"].asInt(); + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); +#endif + return true; +} \ No newline at end of file diff --git a/XEngine_Source/AuthClient_HTTPVer/AuthClient_HTTPVer.h b/XEngine_Source/AuthClient_HTTPVer/AuthClient_HTTPVer.h new file mode 100644 index 0000000000000000000000000000000000000000..626b0dbf7da914b0f8400d532f2368460518c4f7 --- /dev/null +++ b/XEngine_Source/AuthClient_HTTPVer/AuthClient_HTTPVer.h @@ -0,0 +1,24 @@ +#pragma once +/******************************************************************** +// Created: 2024/01/04 09:42:55 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_HTTPVer\AuthClient_HTTPVer.h +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\AuthClient_HTTPVer +// File Base: AuthClient_HTTPVer +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 临时授权客户端 +// History: +*********************************************************************/ + +class CAuthClient_HTTPVer +{ +public: + CAuthClient_HTTPVer(); + ~CAuthClient_HTTPVer(); +public: + bool AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr); + bool AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout = NULL); +protected: +private: +}; \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Client.def b/XEngine_Source/AuthorizeModule_Client.def new file mode 100644 index 0000000000000000000000000000000000000000..405148316214b596e37e793df5ba541f1aa0ba66 --- /dev/null +++ b/XEngine_Source/AuthorizeModule_Client.def @@ -0,0 +1,12 @@ +LIBRARY + +EXPORTS + AuthClient_GetLastError + + AuthClient_Connector_Connect + AuthClient_Connector_Close + AuthClient_Connector_GetAuth + AuthClient_Connector_Login + + AuthClient_HTTPVer_TryRequest + AuthClient_HTTPVer_GetDCode \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Client.vcxproj b/XEngine_Source/AuthorizeModule_Client.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..2f3fe3bbf5939ad96817b51c4a5fb4198ffb8b14 --- /dev/null +++ b/XEngine_Source/AuthorizeModule_Client.vcxproj @@ -0,0 +1,186 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {dd8cb5f1-980f-48c3-ba2f-3cf534903b14} + AuthorizeModuleClient + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);../XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);..\AuthorizeModule_Client;../XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);../XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + $(XEngine_Include);../XEngine_Depend/XEngine_Module/jsoncpp;$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;AUTHORIZEMODULECLIENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + AuthorizeModule_Client.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;AUTHORIZEMODULECLIENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + AuthorizeModule_Client.def + + + + + Level3 + true + _DEBUG;AUTHORIZEMODULECLIENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + AuthorizeModule_Client.def + + + + + Level3 + true + true + true + NDEBUG;AUTHORIZEMODULECLIENT_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + AuthorizeModule_Client.def + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Client.vcxproj.filters b/XEngine_Source/AuthorizeModule_Client.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..94729c044f149793bff6f282d0c6bdc03b687a48 --- /dev/null +++ b/XEngine_Source/AuthorizeModule_Client.vcxproj.filters @@ -0,0 +1,68 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {8e7e2cf3-2b0b-423c-ac1e-1397e7a6b105} + + + {af74d4d4-f721-4060-b98b-6f9d5eda9354} + + + {4a9a85f2-55f9-47e4-9049-14245fc56628} + + + {a5434c6b-9493-4a10-ae83-7dc2f1f6d489} + + + + + 头文件 + + + 头文件 + + + 头文件\AuthClient_Connector + + + 头文件 + + + 头文件 + + + 头文件\AuthClient_HTTPVer + + + + + 源文件 + + + 源文件 + + + 源文件\AuthClient_Connector + + + 源文件\AuthClient_HTTPVer + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Client.vcxproj.user b/XEngine_Source/AuthorizeModule_Client.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_Source/AuthorizeModule_Client.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Client/AuthClient_Define.h b/XEngine_Source/AuthorizeModule_Client/AuthClient_Define.h index 04a3515af1716e226ca084974474c21382351ca9..60ae0157d0efef65017ee627f858a86c666b7d0e 100644 --- a/XEngine_Source/AuthorizeModule_Client/AuthClient_Define.h +++ b/XEngine_Source/AuthorizeModule_Client/AuthClient_Define.h @@ -104,11 +104,6 @@ extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, i 类型:常量字符指针 可空:N 意思:服务器地址 - 参数.二:lpszPass - In/Out:In - 类型:常量字符指针 - 可空:Y - 意思:输入密码,如果服务端设置了密码客户端也必须使用加密通信 返回值 类型:逻辑型 意思:是否成功 @@ -128,21 +123,16 @@ extern "C" bool AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr); 类型:整数型指针 可空:N 意思:输出动态码 - 参数.三:pxhToken + 参数.二:pxhToken In/Out:Out 类型:整数型指针 可空:N 意思:输出绑定的句柄 - 参数.四:pInt_Timeout + 参数.三:pInt_Timeout In/Out:Out 类型:整数型指针 可空:Y 意思:输出动态码超时时间 - 参数.五:lpszPass - In/Out:In - 类型:常量字符指针 - 可空:Y - 意思:输入密码,如果服务端设置了密码客户端也必须使用加密通信 返回值 类型:逻辑型 意思:是否成功 diff --git a/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp b/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp index 5e8caed9fda6d9a4f82d2164a4f769bdf295bcc0..d571e2191dc82f8e019cb9c7e2d833c990abf00d 100644 --- a/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp +++ b/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.cpp @@ -28,17 +28,12 @@ CAuthClient_HTTPVer::~CAuthClient_HTTPVer() 类型:常量字符指针 可空:N 意思:函数的API地址,需要输入完整的URL - 参数.二:lpszPass - In/Out:In - 类型:常量字符指针 - 可空:Y - 意思:输入密码,如果服务端设置了密码客户端也必须使用加密通信 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr, LPCXSTR lpszPass /* = NULL */) +bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr) { AuthClient_IsErrorOccur = true; @@ -49,7 +44,6 @@ bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr, LPC return false; } #if (1 == _XAUTH_BUILD_SWITCH_CLIENT_HTTP) - int nHTTPCode = 0; XCHAR tszJsonStr[MAX_PATH] = {}; Json::Value st_JsonRoot; @@ -67,45 +61,18 @@ bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr, LPC //请求 int nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; - - if (NULL != lpszPass) - { - XCHAR tszENCodec[2048] = {}; - XCHAR tszDECodec[2048] = {}; - - nMsgLen = st_JsonRoot.toStyledString().length(); - OPenSsl_XCrypto_Encoder(st_JsonRoot.toStyledString().c_str(), &nMsgLen, (XBYTE*)tszENCodec, lpszPass); - APIClient_Http_Request(_X("POST"), lpszURLAddr, tszENCodec, &nHTTPCode, &ptszMsgBuffer, &nMsgLen); - - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDECodec, lpszPass); - st_JsonRoot.clear(); - st_JsonObject.clear(); - //解析回复 - std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); - if (!pSt_JsonReader->parse(tszDECodec, tszDECodec + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - AuthClient_IsErrorOccur = true; - AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - return false; - } - } - else + APIClient_Http_Request(_X("POST"), lpszURLAddr, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen); + st_JsonRoot.clear(); + st_JsonObject.clear(); + //解析回复 + std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) { - APIClient_Http_Request(_X("POST"), lpszURLAddr, st_JsonRoot.toStyledString().c_str(), &nHTTPCode, &ptszMsgBuffer, &nMsgLen); - st_JsonRoot.clear(); - st_JsonObject.clear(); - //解析回复 - std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); - if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - AuthClient_IsErrorOccur = true; - AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - return false; - } + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + return false; } - if (0 != st_JsonRoot["code"].asInt()) { AuthClient_IsErrorOccur = true; @@ -130,27 +97,22 @@ bool CAuthClient_HTTPVer::AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr, LPC 类型:整数型指针 可空:N 意思:输出动态码 - 参数.三:pxhToken + 参数.二:pxhToken In/Out:Out 类型:整数型指针 可空:N 意思:输出绑定的句柄 - 参数.四:pInt_Timeout + 参数.三:pInt_Timeout In/Out:Out 类型:整数型指针 可空:Y 意思:输出动态码超时时间 - 参数.五:lpszPass - In/Out:In - 类型:常量字符指针 - 可空:Y - 意思:输入密码,如果服务端设置了密码客户端也必须使用加密通信 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CAuthClient_HTTPVer::AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout /* = NULL */, LPCXSTR lpszPass /* = NULL */) +bool CAuthClient_HTTPVer::AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout /* = NULL */) { AuthClient_IsErrorOccur = true; @@ -168,35 +130,16 @@ bool CAuthClient_HTTPVer::AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* //请求 int nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; - APIClient_Http_Request(_X("GET"), lpszURLAddr, NULL, &nHTTPCode, &ptszMsgBuffer, &nMsgLen); - if (NULL != lpszPass) + //解析回复 + std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) { - XCHAR tszDECodec[2048] = {}; - OPenSsl_XCrypto_Decoder(ptszMsgBuffer, &nMsgLen, tszDECodec, lpszPass); - - std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); - if (!pSt_JsonReader->parse(tszDECodec, tszDECodec + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - AuthClient_IsErrorOccur = true; - AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - return false; - } - } - else - { - //解析回复 - std::unique_ptr const pSt_JsonReader(st_ReaderBuilder.newCharReader()); - if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) - { - AuthClient_IsErrorOccur = true; - AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; - BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); - return false; - } + AuthClient_IsErrorOccur = true; + AuthClient_dwErrorCode = ERROR_AUTHORIZE_MODULE_HTTPVER_PARSE; + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + return false; } - if (0 != st_JsonRoot["code"].asInt()) { AuthClient_IsErrorOccur = true; diff --git a/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.h b/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.h index aff8887bb6fccb1238e3d251551a5a1fff68bc2a..626b0dbf7da914b0f8400d532f2368460518c4f7 100644 --- a/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.h +++ b/XEngine_Source/AuthorizeModule_Client/AuthClient_HTTPVer/AuthClient_HTTPVer.h @@ -17,8 +17,8 @@ public: CAuthClient_HTTPVer(); ~CAuthClient_HTTPVer(); public: - bool AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr, LPCXSTR lpszPass = NULL); - bool AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout = NULL, LPCXSTR lpszPass = NULL); + bool AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr); + bool AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE* pxhToken, int* pInt_Timeout = NULL); protected: private: }; \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Configure/Config_Define.h b/XEngine_Source/AuthorizeModule_Configure/Config_Define.h index fa980f62f2ded12f8bcb5d3a4157a6be71dfe35d..a54553ce5893a5ac779022dbeeabe40a52d2c203 100644 --- a/XEngine_Source/AuthorizeModule_Configure/Config_Define.h +++ b/XEngine_Source/AuthorizeModule_Configure/Config_Define.h @@ -15,6 +15,10 @@ ////////////////////////////////////////////////////////////////////////// typedef struct { + XCHAR tszIPAddr[128]; + XCHAR tszTopic[128]; + int nMQTTPort; + bool bDB; int nTCPPort; //TCP端口 int nWSPort; //WEBSOCKET端口 int nHTTPPort; //HTTP管理端口 @@ -65,6 +69,12 @@ typedef struct }st_XCrypto; struct { + // mysql + XCHAR tszSQLAddr[128]; //数据库地址 + XCHAR tszSQLUser[128]; //数据库账号 + XCHAR tszSQLPass[128]; //数据库密码 + XCHAR tszDBName[128]; //数据库名 + int nSQLPort; //数据库端口 XCHAR tszSQLite[MAX_PATH]; //数据库文件位置 }st_XSql; struct diff --git a/XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp b/XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp index 9eff1c2825665a2c95962c216df2e8eb54bb61d9..ecdc9a03a81b35c7748320425c6ef54c2656e8ea 100644 --- a/XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/AuthorizeModule_Configure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -147,11 +147,29 @@ bool CModuleConfigure_Json::ModuleConfigure_Json_File(LPCXSTR lpszConfigFile, XE pSt_ServerConfig->st_XCrypto.bEnable = st_JsonXCrypto["bEnable"].asBool(); pSt_ServerConfig->st_XCrypto.nPassword = st_JsonXCrypto["nPass"].asInt(); //数据库配置 - if (st_JsonRoot["XSQL"].empty() || (1 != st_JsonRoot["XSQL"].size())) + if (pSt_ServerConfig->bDB) { + if (st_JsonRoot["XSQL"].empty() || (1 != st_JsonRoot["XSQL"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_XSQL; + return false; + } + Json::Value st_JsonXSQL = st_JsonRoot["XSQL"]; + _tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLite, st_JsonXSQL["tszSQLFile"].asCString()); //数据库文件位置 + } + else { - Config_IsErrorOccur = true; - Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_XSQL; - return false; + if (st_JsonRoot["XSql"].empty() || (4 != st_JsonRoot["XSql"].size())) + { + Config_IsErrorOccur = true; + Config_dwErrorCode = ERROR_AUTHORIZE_MODULE_CONFIGURE_XSQL; + return false; + } + Json::Value st_JsonXSql = st_JsonRoot["XSql"]; + pSt_ServerConfig->st_XSql.nSQLPort = st_JsonXSql["SQLPort"].asInt(); + _tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLAddr, st_JsonXSql["SQLAddr"].asCString()); + _tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLUser, st_JsonXSql["SQLUser"].asCString()); + _tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLPass, st_JsonXSql["SQLPass"].asCString()); } Json::Value st_JsonXSQL = st_JsonRoot["XSQL"]; _tcsxcpy(pSt_ServerConfig->st_XSql.tszSQLite, st_JsonXSQL["tszSQLFile"].asCString()); diff --git a/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.def b/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.def index eed0328fcc53520348dc74e3e4d284f0781d68cb..609f0b7a4040b2dc56b7f7acffe0641191ef3d1b 100644 --- a/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.def +++ b/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.def @@ -35,4 +35,39 @@ EXPORTS Database_SQLite_AnnouncementInsert Database_SQLite_AnnouncementDelete - Database_SQLite_AnnouncementList \ No newline at end of file + Database_SQLite_AnnouncementList + + + Database_MYSQL_Init + Database_MYSQL_Destroy + + Database_MYSQL_UserDelete + Database_MYSQL_UserRegister + Database_MYSQL_UserQuery + Database_MYSQL_UserPay + Database_MYSQL_UserLeave + Database_MYSQL_UserSet + Database_MYSQL_UserList + + Database_MYSQL_SerialInsert + Database_MYSQL_SerialDelete + Database_MYSQL_SerialQuery + Database_MYSQL_SerialQueryAll + Database_MYSQL_SerialPush + + Database_MYSQL_TryInsert + Database_MYSQL_TryQuery + Database_MYSQL_TryDelete + Database_MYSQL_TryClear + Database_MYSQL_TrySet + Database_MYSQL_TryList + + Database_MYSQL_BannedInsert + Database_MYSQL_BannedDelete + Database_MYSQL_BannedList + Database_MYSQL_BannedExist + Database_MYSQL_BannedUPDate + + Database_MYSQL_AnnouncementInsert + Database_MYSQL_AnnouncementDelete + Database_MYSQL_AnnouncementList \ No newline at end of file diff --git a/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj b/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj index d5e921813a5c2121c12ec23c04542b130a534f1f..82f9f63df79b89a37546152fbf04b2e4c758ea84 100644 --- a/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj +++ b/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj @@ -161,11 +161,13 @@ + + diff --git a/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj.filters b/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj.filters index 6cbd88b5afbe74bc87e3b05716325736e257c29b..b3c01925ef450965b421133446d464d5197d14a8 100644 --- a/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj.filters +++ b/XEngine_Source/AuthorizeModule_Database/AuthorizeModule_Database.vcxproj.filters @@ -19,6 +19,12 @@ {be64df35-6ef0-4c8c-b95a-444977d7d1c4} + + {b1fc88cc-dfc6-483e-b4e7-41bb469b29cc} + + + {4a258342-2326-48f1-8c8b-3a925feffa70} + @@ -36,6 +42,9 @@ 头文件 + + 头文件\Database_MySQL + @@ -47,6 +56,9 @@ 源文件\Database_SQLite + + 源文件\Database_MySQL + diff --git a/XEngine_Source/AuthorizeModule_Database/Database_Define.h b/XEngine_Source/AuthorizeModule_Database/Database_Define.h index dd02840759a5cb55b6e5215f7c3f1dc5b5a4a8e3..5d6fc82c621c96cc5d7a2ed0efd5ff9429a38663 100644 --- a/XEngine_Source/AuthorizeModule_Database/Database_Define.h +++ b/XEngine_Source/AuthorizeModule_Database/Database_Define.h @@ -503,4 +503,494 @@ extern "C" bool Database_SQLite_AnnouncementDelete(AUTHREG_ANNOUNCEMENT* pSt_Ann 意思:是否成功 备注: *********************************************************************/ -extern "C" bool Database_SQLite_AnnouncementList(AUTHREG_ANNOUNCEMENT*** ppppSt_Announcement, int* pInt_ListCount); \ No newline at end of file +extern "C" bool Database_SQLite_AnnouncementList(AUTHREG_ANNOUNCEMENT*** ppppSt_Announcement, int* pInt_ListCount); + + +/************************************************************************/ +/* MYSQL数据库服务导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:Database_MYSQL_Init +函数功能:初始化数据库管理器 + 参数.一:pSt_DBConnector + In/Out:In + 类型:数据结构指针 + 参数.二:bIsChange + In/Out:In + 类型:逻辑型 + 可空:Y + 意思:是否允许更改用户充值类型 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注:先初始化数据库服务,在初始化网络服务,才可以使用本验证服务器! +*********************************************************************/ +extern "C" bool Database_MYSQL_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bIsChange = true); +/******************************************************************** +函数名称:Database_MYSQL_Destroy +函数功能:销毁数据库服务 +返回值 + 类型:逻辑型 + 意思:是否销毁成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_Destroy(); +/******************************************************************** +函数名称:Database_MYSQL_UserDelete +函数功能:删除一个用户从数据库中 + 参数.一:lpszUserName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要删除的用户 +返回值 + 类型:逻辑型 + 意思:是否删除成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserDelete(LPCXSTR lpszUserName); +/******************************************************************** +函数名称:Database_MYSQL_UserRegister +函数功能:用户注册处理数据库语句函数 + 参数.一:pSt_UserInfo + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要插入的用户数据 +返回值 + 类型:逻辑型 + 意思:是否插入成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserRegister(AUTHREG_USERTABLE* pSt_UserInfo); +/******************************************************************** +函数名称:Database_MYSQL_UserQuery +函数功能:查询用户相对应的值 + 参数.一:lpszUserName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的指定用户 + 参数.二:pSt_UserInfo + In/Out:Out + 类型:数据结构指针 + 可空:Y + 意思:如果为空NULL,那么将只判断此用户是否存在 +返回值 + 类型:逻辑型 + 意思:是否查询成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserQuery(LPCXSTR lpszUserName, AUTHREG_USERTABLE* pSt_UserInfo); +/******************************************************************** +函数名称:Database_MYSQL_UserPay +函数功能:用户充值函数 + 参数.一:lpszUserName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要充值的用户名 + 参数.二:lpszSerialName + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:充值使用的序列号 +返回值 + 类型:逻辑型 + 意思:是否成功充值 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserPay(LPCXSTR lpszUserName, LPCXSTR lpszSerialName); +/******************************************************************** +函数名称:Database_MYSQL_UserLeave +函数功能:用户离开处理事件 + 参数.一:pSt_TimeProtocol + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:离开的用户信息 +返回值 + 类型:逻辑型 + 意思:是否处理成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserLeave(AUTHREG_PROTOCOL_TIME* pSt_TimeProtocol); +/******************************************************************** +函数名称:Database_MYSQL_UserSet +函数功能:设置用户信息 + 参数.一:pSt_UserTable + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要设置的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserSet(AUTHREG_USERTABLE* pSt_UserTable); +/******************************************************************** +函数名称:Database_MYSQL_UserList +函数功能:获取用户列表 + 参数.一:pppSt_UserInfo + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出用户列表,内存由用户释放 + 参数.二:pInt_ListCount + In/Out:Out + 类型:整数型 + 可空:N + 意思:输出列表个数 + 参数.三:nPosStart + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入起始位置 + 参数.四:nPosEnd + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入结束位置 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_UserList(AUTHREG_USERTABLE*** pppSt_UserInfo, int* pInt_ListCount, int nPosStart, int nPosEnd); +/******************************************************************** +函数名称:Database_MYSQL_SerialInsert +函数功能:插入一个序列号到数据库 + 参数.一:lpszSerialNumber + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要插入的序列号 +返回值 + 类型:逻辑型 + 意思:是否插入成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_SerialInsert(LPCXSTR lpszSerialNumber); +/******************************************************************** +函数名称:Database_MYSQL_SerialDelete +函数功能:从数据库删除指定序列号 + 参数.一:lpszSerialNumber + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要删除的序列号 +返回值 + 类型:逻辑型 + 意思:是否删除成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_SerialDelete(LPCXSTR lpszSerialNumber); +/******************************************************************** +函数名称:Database_MYSQL_SerialQuery +函数功能:查询一个指定的序列号信息 + 参数.一:lpszSerialNumber + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:要查询的序列号 + 参数.二:pSt_SerialTable + In/Out:Out + 类型:数据结构指针 + 可空:Y + 意思:导出查询到的信息,如果为NULL,此参数将不起作用 +返回值 + 类型:逻辑型 + 意思:是否查询成功,如果第二个参数为NULL,那么将只返回是否有这个序列号 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_SerialQuery(LPCXSTR lpszSerialNumber, LPAUTHREG_SERIALTABLE pSt_SerialTable); +/******************************************************************** +函数名称:Database_MYSQL_SerialQueryAll +函数功能:查询序列卡表中的所有序列号 + 参数.一:pppSt_SerialTable + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出序列卡列表 + 参数.二:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:Y + 意思:输出多少张卡 + 参数.三:nPosStart + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入起始位置 + 参数.四:nPosEnd + In/Out:In + 类型:整数型 + 可空:Y + 意思:输入结束位置 +返回值 + 类型:逻辑型 + 意思:是否查询成功 +备注:参数一需要调用基础库的释放内存函数进行内存释放 +*********************************************************************/ +extern "C" bool Database_MYSQL_SerialQueryAll(AUTHREG_SERIALTABLE*** pppSt_SerialTable, int* pInt_ListCount, int nPosStart, int nPosEnd); +/******************************************************************** +函数名称:Database_MYSQL_SerialPush +函数功能:插入一条指定的序列号信息到服务器 + 参数.一:pSt_SerialTable + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_SerialPush(AUTHREG_SERIALTABLE* pSt_SerialTable); +/******************************************************************** +函数名称:Database_MYSQL_TryInsert +函数功能:网络使用模式插入一条数据 + 参数.一:pSt_AuthVer + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_TryInsert(AUTHREG_TEMPVER* pSt_AuthVer); +/******************************************************************** +函数名称:Database_MYSQL_TryQuery +函数功能:试用序列号查询函数 + 参数.一:pSt_AuthVer + In/Out:In/Out + 类型:数据结构指针 + 可空:N + 意思:输入序列号,输出获取到的内容 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_TryQuery(AUTHREG_TEMPVER* pSt_AuthVer); +/******************************************************************** +函数名称:Database_MYSQL_TryDelete +函数功能:删除一条指定的试用数据 + 参数.一:lpszSerial + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要删除的序列号 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_TryDelete(LPCXSTR lpszSerial); +/******************************************************************** +函数名称:Database_MYSQL_TryClear +函数功能:清理函数,自动清理过期数据 + 参数.一:nThanValue + In/Out:In + 类型:整数型 + 可空:N + 意思:清理用于判断需要大于此的值 + 参数.二:enVerMode + In/Out:In + 类型:枚举型 + 可空:Y + 意思:判断注册类型,默认不判断全部执行 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_TryClear(int nThanValue, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE enVerMode = ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_UNKNOW); +/******************************************************************** +函数名称:Database_MYSQL_TrySet +函数功能:设置用户信息函数 + 参数.一:pSt_AuthVer + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要更新的用户信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_TrySet(AUTHREG_TEMPVER* pSt_AuthVer); +/******************************************************************** +函数名称:Database_MYSQL_TryList +函数功能:请求试用期列表 + 参数.一:pppSt_AuthVer + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出获取到的列表 + 参数.二:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 + 参数.三:nPosStart + In/Out:In + 类型:整数型 + 可空:N + 意思:输入查询起始编号 + 参数.四:nPosEnd + In/Out:In + 类型:整数型 + 可空:N + 意思:输入查询结束编号 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_TryList(AUTHREG_TEMPVER*** pppSt_AuthVer, int* pInt_ListCount, int nPosStart = 0, int nPosEnd = 1000); +/******************************************************************** +函数名称:Database_MYSQL_BannedInsert +函数功能:黑名单列表插入 + 参数.一:pSt_Banned + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要操作的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_BannedInsert(AUTHREG_BANNED* pSt_Banned); +/******************************************************************** +函数名称:Database_MYSQL_BannedDelete +函数功能:黑名单列表删除 + 参数.一:pSt_Banned + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要操作的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_BannedDelete(AUTHREG_BANNED* pSt_Banned); +/******************************************************************** +函数名称:Database_MYSQL_BannedList +函数功能:黑名单列表查询 + 参数.一:pppSt_BannedUser + In/Out:Out + 类型:三级指针 + 可空:N + 意思:禁用的用户名列表 + 参数.二:pInt_UserCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出用户禁用列表个数 + 参数.三:pppSt_BannedAddr + In/Out:Out + 类型:三级指针 + 可空:N + 意思:禁用的IP地址列表 + 参数.四:pInt_AddrCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出地址禁用列表个数 + 参数.五:nPosStart + In/Out:In + 类型:整数型 + 可空:N + 意思:输入查找起始位置 + 参数.六:nPosEnd + In/Out:In + 类型:整数型 + 可空:N + 意思:输入查找结束位置 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_BannedList(AUTHREG_BANNED*** pppSt_BannedUser, int* pInt_UserCount, AUTHREG_BANNED*** pppSt_BannedAddr, int* pInt_AddrCount, int nPosStart, int nPosEnd); +/******************************************************************** +函数名称:Database_MYSQL_BannedExist +函数功能:名单是否存在黑名单列表 + 参数.一:pSt_Banned + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要操作的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_BannedExist(AUTHREG_BANNED* pSt_Banned); +/******************************************************************** +函数名称:Database_MYSQL_BannedUPDate +函数功能:更新名单列表信息 + 参数.一:pSt_Banned + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:要操作的数据 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_BannedUPDate(AUTHREG_BANNED* pSt_Banned); +/******************************************************************** +函数名称:Database_MYSQL_AnnouncementInsert +函数功能:公告插入 + 参数.一:pSt_Announcement + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要插入的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_AnnouncementInsert(AUTHREG_ANNOUNCEMENT* pSt_Announcement); +/******************************************************************** +函数名称:Database_MYSQL_AnnouncementDelete +函数功能:公告删除 + 参数.一:pSt_Announcement + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要删除的信息 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_AnnouncementDelete(AUTHREG_ANNOUNCEMENT* pSt_Announcement); +/******************************************************************** +函数名称:Database_MYSQL_AnnouncementList +函数功能:列举所有公告 + 参数.一:ppppSt_Announcement + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出列举数据 + 参数.二:pInt_ListCount + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:导出数据个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool Database_MYSQL_AnnouncementList(AUTHREG_ANNOUNCEMENT*** ppppSt_Announcement, int* pInt_ListCount); diff --git a/XEngine_Source/AuthorizeModule_Database/Database_MySQL/Database_MySQL.cpp b/XEngine_Source/AuthorizeModule_Database/Database_MySQL/Database_MySQL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b66552e3d4b44177e06b2eae1187401d6cb908e --- /dev/null +++ b/XEngine_Source/AuthorizeModule_Database/Database_MySQL/Database_MySQL.cpp @@ -0,0 +1,2008 @@ +#include "pch.h" +#include "Database_MySQL.h" + +/******************************************************************** +// Created: 2022/05/26 11:01:13 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Database\Database_MySQL\Database_MySQL.cpp +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Database\Database_MySQL +// File Base: Database_SQLite +// File Ext: cpp +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: ݿ +// History: +*********************************************************************/ +CDatabase_MySQL::CDatabase_MySQL() +{ + m_bChange = false; + xhData = 0; +} + +CDatabase_MySQL::~CDatabase_MySQL() +{ +} +////////////////////////////////////////////////////////////////////////// +// к +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +ƣDatabase_MYSQL_Init +ܣʼݿ + .һpSt_DBConnector + In/OutIn + ͣݽṹָ + ɿգN + ˼MYSQLݿϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bIsChange) +{ + SQLPacket_IsErrorOccur = false; + m_bChange = bIsChange; + if (NULL == pSt_DBConnector) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + _tcsxcpy(pSt_DBConnector->tszDBName, _X("XEngine_Authorize")); //ÿ + if (!DataBase_MySQL_Connect(&xhData, pSt_DBConnector)) //ݿ + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_Destroy +ܣݿ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_Destroy() +{ + SQLPacket_IsErrorOccur = false; + + DataBase_MySQL_Close(xhData); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserDelete +ܣɾһûݿ + .һlpszUserName + In/OutIn + ַָͣ + ɿգN + ˼Ҫɾû +ֵ + ͣ߼ + ˼Ƿɾɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserDelete(LPCXSTR lpszUserName) +{ + SQLPacket_IsErrorOccur = false; + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("delete from Authorize_User where UserName = '%s'"), lpszUserName); + //ִ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_EXEC; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserRegister +ܣûעᴦݿ亯 + .һpSt_UserInfo + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫû +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserRegister(AUTHREG_USERTABLE* pSt_UserInfo) +{ + SQLPacket_IsErrorOccur = false; + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + if (Database_MYSQL_UserQuery(pSt_UserInfo->st_UserInfo.tszUserName)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_EXIST; + return false; + } + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_User(UserName, Password, LeftTime, EmailAddr, HardCode, CardSerialType, PhoneNumber, IDCard, nUserLevel, CreateTime) values('%s','%s','%s','%s','%s','%d',%lld,%lld,%d,NOW())"), pSt_UserInfo->st_UserInfo.tszUserName, pSt_UserInfo->st_UserInfo.tszUserPass, pSt_UserInfo->tszLeftTime, pSt_UserInfo->st_UserInfo.tszEMailAddr, pSt_UserInfo->tszHardCode, pSt_UserInfo->enSerialType, pSt_UserInfo->st_UserInfo.nPhoneNumber, pSt_UserInfo->st_UserInfo.nIDNumber, pSt_UserInfo->st_UserInfo.nUserLevel); + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_INSERT; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserQuery +ܣѯûӦֵ + .һlpszUserName + In/OutIn + ַָͣ + ɿգN + ˼Ҫѯָû + .pSt_UserInfo + In/OutOut + ͣݽṹָ + ɿգY + ˼ΪNULLôֻжϴûǷ +ֵ + ͣ߼ + ˼Ƿѯɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserQuery(LPCXSTR lpszUserName, AUTHREG_USERTABLE* pSt_UserInfo) +{ + SQLPacket_IsErrorOccur = false; + //ѯ + XNETHANDLE xhTable = 0; + __int64u nColumn = 0; + __int64u nRow = 0; + + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("select * from Authorize_User where UserName = '%s'"), lpszUserName); + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + return false; + } + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + return false; + } + XCHAR** pptszResult = DataBase_MySQL_GetResult(xhData, xhTable); + XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + //NULLʾ֪ + if (NULL != pSt_UserInfo) + { + memset(pSt_UserInfo, '\0', sizeof(AUTHREG_USERTABLE)); + + //ID + int nFliedValue = 0; + + //û + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d û%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->st_UserInfo.tszUserName, pptszResult[nFliedValue]); + } + + // + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d 룺%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->st_UserInfo.tszUserPass, pptszResult[nFliedValue]); + } + + //ʱ + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d ʱ䣺%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->tszLeftTime, pptszResult[nFliedValue]); + } + + //ʼ + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d ʼ%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->st_UserInfo.tszEMailAddr, pptszResult[nFliedValue]); + } + + //Ӳ + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d Ӳ룺%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->tszHardCode, pptszResult[nFliedValue]); + } + + //ֵ + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d ֵͣ%s\n", nFliedValue, pptszResult[nFliedValue]); + pSt_UserInfo->enSerialType = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(pptszResult[nFliedValue]); + } + + //QQ + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d QQţ%s\n", nFliedValue, pptszResult[nFliedValue]); + pSt_UserInfo->st_UserInfo.nPhoneNumber = _ttxoll(pptszResult[nFliedValue]); + } + + //֤ID + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d ֤ID%s\n", nFliedValue, pptszResult[nFliedValue]); + pSt_UserInfo->st_UserInfo.nIDNumber = _ttxoll(pptszResult[nFliedValue]); + } + + //û -1ʾ + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d û -1ʾ%s\n", nFliedValue, pptszResult[nFliedValue]); + pSt_UserInfo->st_UserInfo.nUserLevel = _ttxoi(pptszResult[nFliedValue]); + } + + //¼ + nFliedValue++; + if (NULL != pptszResult[nFliedValue] && _tcsxlen(pptszResult[nFliedValue]) > 0) + { + //printf("%d ¼ڣ%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->st_UserInfo.tszLoginTime, pptszResult[nFliedValue]); + } + //ע + nFliedValue++; + if (NULL != pptszResult[nFliedValue]) { + //printf("%d עڣ%s\n", nFliedValue, pptszResult[nFliedValue]); + _tcsxcpy(pSt_UserInfo->st_UserInfo.tszCreateTime, pptszResult[nFliedValue]); + } + + } + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserPay +ܣûֵ + .һlpszUserName + In/OutIn + ַָͣ + ɿգN + ˼Ҫֵû + .lpszSerialName + In/OutIn + ַָͣ + ɿգN + ˼ֵʹõк +ֵ + ͣ߼ + ˼Ƿɹֵ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserPay(LPCXSTR lpszUserName, LPCXSTR lpszSerialName) +{ + SQLPacket_IsErrorOccur = false; + + AUTHREG_SERIALTABLE st_SerialTable; + AUTHREG_USERTABLE st_UserTable; + XCHAR tszSQLStatement[1024]; //SQL + + memset(tszSQLStatement, '\0', 1024); + memset(&st_SerialTable, '\0', sizeof(st_SerialTable)); + memset(&st_UserTable, '\0', sizeof(st_UserTable)); + // + if ((NULL == lpszUserName) || (NULL == lpszSerialName)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + //ѯֵǷ + if (!Database_MYSQL_SerialQuery(lpszSerialName, &st_SerialTable)) + { + return false; + } + //ֵǷʹ + if (st_SerialTable.bIsUsed) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_ISUSED; + return false; + } + //ѯûϢ + if (!Database_MYSQL_UserQuery(lpszUserName, &st_UserTable)) + { + return false; + } + //뷽ʽ + switch (st_SerialTable.enSerialType) + { + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_SECOND: + if (!Database_MYSQL_UserPayTime(lpszUserName, st_UserTable.tszLeftTime, st_SerialTable.tszMaxTime, st_SerialTable.enSerialType, st_UserTable.enSerialType)) + { + return false; + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_DAY: + if (!Database_MYSQL_UserPayTime(lpszUserName, st_UserTable.tszLeftTime, st_SerialTable.tszMaxTime, st_SerialTable.enSerialType, st_UserTable.enSerialType)) + { + return false; + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_TIME: + if (!Database_MYSQL_UserPayTime(lpszUserName, st_UserTable.tszLeftTime, st_SerialTable.tszMaxTime, st_SerialTable.enSerialType, st_UserTable.enSerialType)) + { + return false; + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_CUSTOM: + if (!Database_MYSQL_UserPayTime(lpszUserName, st_UserTable.tszLeftTime, st_SerialTable.tszMaxTime, st_SerialTable.enSerialType, st_UserTable.enSerialType)) + { + return false; + } + break; + default: + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_NOTSUPPORT; + return false; + } + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_Serial SET UserName = '%s',bIsUsed = '1' WHERE SerialNumber = '%s'"), lpszUserName, lpszSerialName); + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_UPDATAUSEDNAME; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserLeave +ܣû뿪¼ + .һpSt_TimeProtocol + In/OutIn + ͣݽṹָ + ɿգN + ˼뿪ûϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserLeave(AUTHREG_PROTOCOL_TIME* pSt_TimeProtocol) +{ + SQLPacket_IsErrorOccur = false; + + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + + if ((ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_DAY == pSt_TimeProtocol->enSerialType) || (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_CUSTOM == pSt_TimeProtocol->enSerialType)) + { + //ֻʣʱûеʱҪ + if (pSt_TimeProtocol->nTimeLeft <= 0) + { + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '0' WHERE UserName = '%s'"), pSt_TimeProtocol->tszUserName); + } + } + if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_SECOND == pSt_TimeProtocol->enSerialType) + { + //ӿҪʱܼ + if (pSt_TimeProtocol->nTimeLeft <= 0) + { + pSt_TimeProtocol->nTimeLeft = 0; + } + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%lld' WHERE UserName = '%s'"), pSt_TimeProtocol->nTimeLeft, pSt_TimeProtocol->tszUserName); + } + else if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_TIME == pSt_TimeProtocol->enSerialType) + { + //Ҫʱ,ֱӼȥһξͿ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%lld' WHERE UserName = '%s'"), _ttxoll(pSt_TimeProtocol->tszLeftTime), pSt_TimeProtocol->tszUserName); + } + else + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_UNKNOWTYPE; + return false; + } + //ûʣʱ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_UPDATA; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserSet +ܣûϢ + .һpSt_UserTable + In/OutIn + ͣݽṹָ + ɿգN + ˼ҪõϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserSet(AUTHREG_USERTABLE* pSt_UserTable) +{ + SQLPacket_IsErrorOccur = false; + + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET Password = '%s',LeftTime = '%s',EmailAddr = '%s',HardCode = '%s',CardSerialType = '%d',PhoneNumber = '%lld',IDCard = '%lld',nUserLevel = '%d',UPTime = NOW(),CreateTime = '%s' WHERE UserName = '%s'"), pSt_UserTable->st_UserInfo.tszUserPass, pSt_UserTable->tszLeftTime, pSt_UserTable->st_UserInfo.tszEMailAddr, pSt_UserTable->tszHardCode, pSt_UserTable->enSerialType, pSt_UserTable->st_UserInfo.nPhoneNumber, pSt_UserTable->st_UserInfo.nIDNumber, pSt_UserTable->st_UserInfo.nUserLevel/*, pSt_UserTable->st_UserInfo.tszLoginTime*/, pSt_UserTable->st_UserInfo.tszCreateTime, pSt_UserTable->st_UserInfo.tszUserName); + + //printf("22ûϢ(SQL)%s\n", tszSQLStatement); + //ûʣʱ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_UserList +ܣȡûб + .һpppSt_UserInfo + In/OutOut + ָͣ + ɿգN + ˼ûб,ڴûͷ + .pInt_ListCount + In/OutOut + ͣ + ɿգN + ˼б + .nPosStart + In/OutIn + ͣ + ɿգY + ˼ʼλ + .ģnPosEnd + In/OutIn + ͣ + ɿգY + ˼λ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserList(AUTHREG_USERTABLE*** pppSt_UserInfo, int* pInt_ListCount, int nPosStart, int nPosEnd) +{ + SQLPacket_IsErrorOccur = false; + + //ѯ + XNETHANDLE xhTable = 0; + __int64u nRow = 0; + __int64u nColumn = 0; + char** ppszResult = NULL; + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_User LIMIT %d,%d"), nPosStart, nPosEnd - nPosStart); + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + return false; + } + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_NOTUSER; + return false; + } + *pInt_ListCount = nRow; + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_UserInfo, (int)nRow, sizeof(AUTHREG_USERTABLE)); + + for (int i = 0; i < nRow; i++) + { + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + //ID + int nFliedValue = 0; + nFliedValue++; + //û + _tcsxcpy((*pppSt_UserInfo)[i]->st_UserInfo.tszUserName, ppszResult[nFliedValue]); + // + nFliedValue++; + _tcsxcpy((*pppSt_UserInfo)[i]->st_UserInfo.tszUserPass, ppszResult[nFliedValue]); + //ʱ + nFliedValue++; + _tcsxcpy((*pppSt_UserInfo)[i]->tszLeftTime, ppszResult[nFliedValue]); + //ʼ + nFliedValue++; + _tcsxcpy((*pppSt_UserInfo)[i]->st_UserInfo.tszEMailAddr, ppszResult[nFliedValue]); + //Ӳ + nFliedValue++; + _tcsxcpy((*pppSt_UserInfo)[i]->tszHardCode, ppszResult[nFliedValue]); + //ֵ + nFliedValue++; + (*pppSt_UserInfo)[i]->enSerialType = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(ppszResult[nFliedValue]); + //QQ + nFliedValue++; + (*pppSt_UserInfo)[i]->st_UserInfo.nPhoneNumber = _ttxoll(ppszResult[nFliedValue]); + //֤ID + nFliedValue++; + (*pppSt_UserInfo)[i]->st_UserInfo.nIDNumber = _ttxoll(ppszResult[nFliedValue]); + //û -1ʾ + nFliedValue++; + (*pppSt_UserInfo)[i]->st_UserInfo.nUserLevel = _ttxoi(ppszResult[nFliedValue]); + //¼ + nFliedValue++; + if (NULL != ppszResult[nFliedValue] && _tcsxlen(ppszResult[nFliedValue]) > 0) + { + _tcsxcpy((*pppSt_UserInfo)[i]->st_UserInfo.tszLoginTime, ppszResult[nFliedValue]); + } + //ע + nFliedValue++; + _tcsxcpy((*pppSt_UserInfo)[i]->st_UserInfo.tszCreateTime, ppszResult[nFliedValue]); + nFliedValue++; + } + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_SerialInsert +ܣһкŵݿ + .һlpszSerialNumber + In/OutIn + ַָͣ + ɿգN + ˼Ҫк +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_SerialInsert(LPCXSTR lpszSerialNumber) +{ + SQLPacket_IsErrorOccur = false; + + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + if (Database_MYSQL_SerialQuery(lpszSerialNumber)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_EXIST; + return false; + } + ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE enAuthSerialType; + XENGINE_LIBTIMER st_AuthTimer; + memset(&st_AuthTimer, '\0', sizeof(st_AuthTimer)); + + if (!Authorize_Serial_GetType(lpszSerialNumber, &enAuthSerialType, &st_AuthTimer)) + { + return false; + } + if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_SECOND == enAuthSerialType) + { + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Serial values(NULL,'NOT','%s','%d','%d',0,NOW())"), lpszSerialNumber, st_AuthTimer.wSecond, enAuthSerialType); + } + else if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_DAY == enAuthSerialType) + { + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Serial values(NULL,'NOT','%s','%d','%d',0,NOW())"), lpszSerialNumber, st_AuthTimer.wDay, enAuthSerialType); + } + else if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_TIME == enAuthSerialType) + { + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Serial values(NULL,'NOT','%s','%d','%d',0,NOW())"), lpszSerialNumber, st_AuthTimer.wFlags, enAuthSerialType); + } + else if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_CUSTOM == enAuthSerialType) + { + XCHAR tszLeftTime[MAX_PATH]; + memset(tszLeftTime, '\0', MAX_PATH); + _xstprintf(tszLeftTime, _X("%04d-%02d-%02d %02d:%02d:%02d"), st_AuthTimer.wYear, st_AuthTimer.wMonth, st_AuthTimer.wDay, st_AuthTimer.wHour, st_AuthTimer.wMinute, st_AuthTimer.wSecond); + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Serial values(NULL,'NOT','%s','%s','%d',0,NOW())"), lpszSerialNumber, tszLeftTime, enAuthSerialType); + } + else + { + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Serial values(NULL,'NOT','%s',0,'%d',0,NOW())"), lpszSerialNumber, enAuthSerialType); + } + + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_ISFAILED; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_SerialDelete +ܣݿɾָк + .һlpszSerialNumber + In/OutIn + ַָͣ + ɿգN + ˼Ҫɾк +ֵ + ͣ߼ + ˼Ƿɾɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_SerialDelete(LPCXSTR lpszSerialNumber) +{ + SQLPacket_IsErrorOccur = false; + + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("delete from Authorize_Serial where SerialNumber = '%s'"), lpszSerialNumber); + //ִ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_ISFAILED; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_SerialQuery +ܣѯһָкϢ + .һlpszSerialNumber + In/OutIn + ַָͣ + ɿգN + ˼Ҫѯк + .pSt_SerialTable + In/OutOut + ͣݽṹָ + ɿգY + ˼ѯϢΪNULL˲ +ֵ + ͣ߼ + ˼ǷѯɹڶΪNULLôֻǷк +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_SerialQuery(LPCXSTR lpszSerialNumber, LPAUTHREG_SERIALTABLE pSt_SerialTable) +{ + SQLPacket_IsErrorOccur = false; + XCHAR tszSQLStatement[1024]; //SQL + char** ppszResult = NULL; + XNETHANDLE xhTable = 0; + __int64u nRow = 0; + __int64u nColumn = 0; + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("select * from Authorize_Serial where SerialNumber = '%s'"), lpszSerialNumber); + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + return false; + } + + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_SERIAL; + return false; + } + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + if (NULL != pSt_SerialTable) + { + memset(pSt_SerialTable, '\0', sizeof(AUTHREG_SERIALTABLE)); + //ID + int nFliedValue = 0; + //ʹ + nFliedValue++; + _tcsxcpy(pSt_SerialTable->tszUserName, ppszResult[nFliedValue]); + //к + nFliedValue++; + _tcsxcpy(pSt_SerialTable->tszSerialNumber, ppszResult[nFliedValue]); + //ʱʱ + nFliedValue++; + _tcsxcpy(pSt_SerialTable->tszMaxTime, ppszResult[nFliedValue]); + //п + nFliedValue++; + pSt_SerialTable->enSerialType = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(ppszResult[nFliedValue]); + //ǷѾʹ + nFliedValue++; + pSt_SerialTable->bIsUsed = _ttxoi(ppszResult[nFliedValue]); + //ʱʱ + nFliedValue++; + _tcsxcpy(pSt_SerialTable->tszCreateTime, ppszResult[nFliedValue]); + } + + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_SerialQueryAll +ܣѯпек + .һpppSt_SerialTable + In/OutOut + ָͣ + ɿգN + ˼пб + .pInt_ListCount + In/OutOut + ָͣ + ɿգY + ˼ſ + .nPosStart + In/OutIn + ͣ + ɿգY + ˼ʼλ + .ģnPosEnd + In/OutIn + ͣ + ɿգY + ˼λ +ֵ + ͣ߼ + ˼Ƿѯɹ +עһҪûͷڴ溯ڴͷ +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_SerialQueryAll(AUTHREG_SERIALTABLE*** pppSt_SerialTable, int* pInt_ListCount, int nPosStart, int nPosEnd) +{ + SQLPacket_IsErrorOccur = false; + + XNETHANDLE xhTable = 0; + __int64u nRow = 0; + __int64u nColumn = 0; + char** ppszResult = NULL; + XCHAR tszSQLStatement[1024]; //SQL + + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_Serial LIMIT %d,%d"), nPosStart, nPosEnd - nPosStart); + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + return false; + } + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_NONE; + return false; + } + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_SerialTable, (int)nRow, sizeof(AUTHREG_SERIALTABLE)); + + *pInt_ListCount = nRow; + + for (int i = 0; i < nRow; i++) + { + // ȡݿ + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + int nFliedValue = 0; + //ID + nFliedValue++; + //ʹ + _tcsxcpy((*pppSt_SerialTable)[i]->tszUserName, ppszResult[nFliedValue]); + nFliedValue++; + //к + _tcsxcpy((*pppSt_SerialTable)[i]->tszSerialNumber, ppszResult[nFliedValue]); + nFliedValue++; + //ʱʱ + _tcsxcpy((*pppSt_SerialTable)[i]->tszMaxTime, ppszResult[nFliedValue]); + nFliedValue++; + //п + (*pppSt_SerialTable)[i]->enSerialType = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ǷѾʹ + (*pppSt_SerialTable)[i]->bIsUsed = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + _tcsxcpy((*pppSt_SerialTable)[i]->tszCreateTime, ppszResult[nFliedValue]); + nFliedValue++; + } + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_SerialPush +ܣһָкϢ + .һpSt_SerialTable + In/OutIn + ͣݽṹָ + ɿգN + ˼ҪϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_SerialPush(AUTHREG_SERIALTABLE* pSt_SerialTable) +{ + SQLPacket_IsErrorOccur = false; + + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + + if (Database_MYSQL_SerialQuery(pSt_SerialTable->tszSerialNumber)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_EXIST; + return false; + } + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Serial values(NULL,'%s','%s','%s',%d,%d,'%s')"), pSt_SerialTable->tszUserName, pSt_SerialTable->tszSerialNumber, pSt_SerialTable->tszMaxTime, pSt_SerialTable->enSerialType, pSt_SerialTable->bIsUsed, pSt_SerialTable->tszCreateTime); + + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_ISFAILED; + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_TryInsert +ܣʹģʽһ + .һpSt_AuthVer + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_TryInsert(AUTHREG_TEMPVER* pSt_AuthVer) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_AuthVer) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XCHAR tszSQLStatement[1024]; + AUTHREG_TEMPVER st_AuthVer; + + memset(tszSQLStatement, '\0', 1024); + memset(&st_AuthVer, '\0', sizeof(AUTHREG_TEMPVER)); + //printf("444444444444\n"); + //֤Ƿ + _tcsxcpy(st_AuthVer.tszVSerial, pSt_AuthVer->tszVSerial); + if (Database_MYSQL_TryQuery(&st_AuthVer)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_EXIST; + return false; + } + //ݿ + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_TempVer(tszVSerial,nVMode,nVTime,nLTime,CreateTime) VALUES('%s',%d,%d,%d,NOW())"), pSt_AuthVer->tszVSerial, pSt_AuthVer->enVMode, pSt_AuthVer->nVTime, pSt_AuthVer->nVTime); + + //printf("ʹģʽһݣSQL%s\n", tszSQLStatement); + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_TryQuery +ܣкŲѯ + .һpSt_AuthVer + In/OutIn/Out + ͣݽṹָ + ɿգN + ˼к,ȡ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_TryQuery(AUTHREG_TEMPVER* pSt_AuthVer) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_AuthVer) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XNETHANDLE xhTable = 0; + __int64u nColumn = 0; + __int64u nRow = 0; + XCHAR** ppszResult = NULL; + XCHAR tszSQLStatement[1024]; //SQL + + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_TempVer WHERE tszVSerial = '%s'"), pSt_AuthVer->tszVSerial); + + //printf("кŲѯLSQL䣺%s\n", tszSQLStatement); + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + + //printf("3333 :%d :%d\n", nRow, nColumn); + + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_NONE; + return false; + } + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + //ID + int nFliedValue = 0; + nFliedValue++; + //к + nFliedValue++; + + // + if (NULL != ppszResult[nFliedValue]) { + pSt_AuthVer->enVMode = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(ppszResult[nFliedValue]); + } + + //ʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) { + pSt_AuthVer->nVTime = _ttxoi(ppszResult[nFliedValue]); + } + + //ʣʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) { + pSt_AuthVer->nLTime = _ttxoi(ppszResult[nFliedValue]); + } + + //עʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) { + _tcsxcpy(pSt_AuthVer->tszVDate, ppszResult[nFliedValue]); + } + + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_TryDelete +ܣɾһָ + .һlpszSerial + In/OutIn + ַָͣ + ɿգN + ˼Ҫɾк +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_TryDelete(LPCXSTR lpszSerial) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == lpszSerial) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("DELETE FROM Authorize_TempVer WHERE tszVSerial = '%s'"), lpszSerial); + + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_TryClear +ܣ,Զ + .һnThanValue + In/OutIn + ͣ + ɿգN + ˼жҪڴ˵ֵ + .enVMode + In/OutIn + ͣö + ɿգY + ˼жע,Ĭϲжȫִ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_TryClear(int nThanValue, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE enVerMode) +{ + SQLPacket_IsErrorOccur = false; + + XNETHANDLE xhTable = 0; + __int64u nRow = 0; + __int64u nColumn = 0; + XCHAR** ppszResult = NULL; + XCHAR tszSQLStatement[1024]; //SQL + + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_TempVer")); + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + + list stl_ListVer; + //ѵ + for (int i = 0; i < nRow; i++) + { + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + int nFliedValue = 0; + AUTHREG_TEMPVER st_AuthVer; + memset(&st_AuthVer, '\0', sizeof(AUTHREG_TEMPVER)); + //ID + nFliedValue++; + //к + _tcsxcpy(st_AuthVer.tszVSerial, ppszResult[nFliedValue]); + nFliedValue++; + //ģʽ + st_AuthVer.enVMode = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + st_AuthVer.nVTime = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + st_AuthVer.nLTime = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //עʱ + _tcsxcpy(st_AuthVer.tszVDate, ppszResult[nFliedValue]); + + stl_ListVer.push_back(st_AuthVer); + } + DataBase_MySQL_FreeResult(xhData, xhTable); + // + list::const_iterator stl_ListIterator = stl_ListVer.begin(); + for (; stl_ListIterator != stl_ListVer.end(); stl_ListIterator++) + { + //жDzDzעģʽֱ + if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_UNKNOW == enVerMode) + { + if (nThanValue > stl_ListIterator->nVTime) + { + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("DELETE FROM Authorize_TempVer WHERE tszVSerial = '%s'"), stl_ListIterator->tszVSerial); + + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + } + } + else + { + if (enVerMode == stl_ListIterator->enVMode) + { + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("DELETE FROM Authorize_TempVer WHERE tszVSerial = '%s'"), stl_ListIterator->tszVSerial); + + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + } + } + } + stl_ListVer.clear(); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_TrySet +ܣûϢ + .һpSt_AuthVer + In/OutIn + ͣݽṹָ + ɿգN + ˼ҪµûϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_TrySet(AUTHREG_TEMPVER* pSt_AuthVer) +{ + SQLPacket_IsErrorOccur = false; + + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_TempVer SET nVMode = '%d',nVTime = '%d',nLTime = '%d',CreateTime = '%s' WHERE tszVSerial = '%s'"), pSt_AuthVer->enVMode, pSt_AuthVer->nVTime, pSt_AuthVer->nLTime, pSt_AuthVer->tszVDate, pSt_AuthVer->tszVSerial); + //û + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_TryList +ܣб + .һpppSt_AuthVer + In/OutOut + ָͣ + ɿգN + ˼ȡб + .pInt_ListCount + In/OutOut + ָͣ + ɿգN + ˼б + .nPosStart + In/OutIn + ͣ + ɿգN + ˼ѯʼ + .ģnPosEnd + In/OutIn + ͣ + ɿգN + ˼ѯ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_TryList(AUTHREG_TEMPVER*** pppSt_AuthVer, int* pInt_ListCount, int nPosStart, int nPosEnd) +{ + SQLPacket_IsErrorOccur = false; + + XNETHANDLE xhTable = 0; + __int64u nColumn = 0; + __int64u nRow = 0; + XCHAR** ppszResult = NULL; + XCHAR tszSQLStr[1024]; //SQL + + memset(tszSQLStr, '\0', 1024); + _xstprintf(tszSQLStr, _X("SELECT * FROM Authorize_TempVer LIMIT %d,%d"), nPosStart, nPosEnd - nPosStart); + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStr, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_AuthVer, (int)nRow, sizeof(AUTHREG_TEMPVER)); + + //ѵ + for (int i = 0; i < nRow; i++) + { + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + int nFliedValue = 0; + //ID + (*pppSt_AuthVer)[i]->nID = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //Ƿ + _tcsxcpy((*pppSt_AuthVer)[i]->tszVSerial, ppszResult[nFliedValue]); + nFliedValue++; + // + (*pppSt_AuthVer)[i]->enVMode = (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE)_ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + (*pppSt_AuthVer)[i]->nVTime = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + (*pppSt_AuthVer)[i]->nLTime = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //עʱ + _tcsxcpy((*pppSt_AuthVer)[i]->tszVDate, ppszResult[nFliedValue]); + nFliedValue++; + } + *pInt_ListCount = nRow; + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_BannedInsert +ܣб + .һpSt_Banned + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_BannedInsert(AUTHREG_BANNED* pSt_Banned) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_Banned) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + //ֱӷ + if (Database_MYSQL_BannedExist(pSt_Banned)) + { + return true; + } + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + // + if (_tcsxlen(pSt_Banned->tszUserName) > 0) + { + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_BannedUser(bEnable,tszUserName,tszLeftTime,tszCreateTime) VALUES(%d,'%s','%s',NOW())"), pSt_Banned->bEnable, pSt_Banned->tszUserName, pSt_Banned->tszLeftTime); + } + else + { + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_BannedAddr(bEnable,tszIPAddr,tszLeftTime,tszCreateTime) VALUES(%d,'%s','%s',NOW())"), pSt_Banned->bEnable, pSt_Banned->tszIPAddr, pSt_Banned->tszLeftTime); + } + + //printf("б(SQL):%s\n", tszSQLStatement); + //ݿ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_BannedDelete +ܣбɾ + .һpSt_Banned + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_BannedDelete(AUTHREG_BANNED* pSt_Banned) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_Banned) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', 1024); + // + if (_tcsxlen(pSt_Banned->tszUserName) > 0) + { + _xstprintf(tszSQLStatement, _X("DELETE FROM Authorize_BannedUser WHERE tszUserName = '%s'"), pSt_Banned->tszUserName); + } + else + { + _xstprintf(tszSQLStatement, _X("DELETE FROM Authorize_BannedAddr WHERE tszIPAddr = '%s'"), pSt_Banned->tszIPAddr); + } + //ݿ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_BannedList +ܣбѯ + .һpppSt_BannedUser + In/OutOut + ָͣ + ɿգN + ˼õûб + .pInt_UserCount + In/OutOut + ָͣ + ɿգN + ˼ûб + .pppSt_BannedAddr + In/OutOut + ָͣ + ɿգN + ˼õIPַб + .ģpInt_AddrCount + In/OutOut + ָͣ + ɿգN + ˼ַб + .壺nPosStart + In/OutIn + ͣ + ɿգN + ˼ʼλ + .nPosEnd + In/OutIn + ͣ + ɿգN + ˼ҽλ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_BannedList(AUTHREG_BANNED*** pppSt_BannedUser, int* pInt_UserCount, AUTHREG_BANNED*** pppSt_BannedAddr, int* pInt_AddrCount, int nPosStart, int nPosEnd) +{ + SQLPacket_IsErrorOccur = false; + //ѯ + XNETHANDLE xhTable = 0; + __int64u nColumn = 0; + __int64u nRow = 0; + + XCHAR** ppszResult = NULL; + XCHAR tszSQLStatement[1024]; //SQL + + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_BannedAddr LIMIT %d,%d"), nPosStart, nPosEnd - nPosStart); + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + + list stl_ListAddr; + //ѵ + for (int i = 0; i < nRow; i++) + { + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + int nFliedValue = 0; + + AUTHREG_BANNED st_Banned; + memset(&st_Banned, '\0', sizeof(AUTHREG_BANNED)); + //ID + st_Banned.nID = _ttxoll(ppszResult[nFliedValue]); + nFliedValue++; + //Ƿ + st_Banned.bEnable = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //ַ + _tcsxcpy(st_Banned.tszIPAddr, ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + _tcsxcpy(st_Banned.tszLeftTime, ppszResult[nFliedValue]); + nFliedValue++; + //עʱ + _tcsxcpy(st_Banned.tszCreateTime, ppszResult[nFliedValue]); + nFliedValue++; + + stl_ListAddr.push_back(st_Banned); + } + DataBase_MySQL_FreeResult(xhData, xhTable); + //ûб + xhTable = 0; + nRow = 0; + nColumn = 0; + ppszResult = NULL; + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_BannedUser LIMIT %d,%d"), nPosStart, nPosEnd - nPosStart); + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + + list stl_ListUser; + //ѵ + for (int i = 0; i < nRow; i++) + { + AUTHREG_BANNED st_Banned; + memset(&st_Banned, '\0', sizeof(AUTHREG_BANNED)); + + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + int nFliedValue = 0; + + //ID + st_Banned.nID = _ttxoll(ppszResult[nFliedValue]); + nFliedValue++; + //Ƿ + st_Banned.bEnable = _ttxoi(ppszResult[nFliedValue]); + nFliedValue++; + //û + _tcsxcpy(st_Banned.tszUserName, ppszResult[nFliedValue]); + nFliedValue++; + //ʱ + _tcsxcpy(st_Banned.tszLeftTime, ppszResult[nFliedValue]); + nFliedValue++; + //עʱ + _tcsxcpy(st_Banned.tszCreateTime, ppszResult[nFliedValue]); + nFliedValue++; + + stl_ListUser.push_back(st_Banned); + } + DataBase_MySQL_FreeResult(xhData, xhTable); + // + *pInt_AddrCount = stl_ListAddr.size(); + *pInt_UserCount = stl_ListUser.size(); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_BannedAddr, stl_ListAddr.size(), sizeof(AUTHREG_BANNED)); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_BannedUser, stl_ListUser.size(), sizeof(AUTHREG_BANNED)); + + list::const_iterator stl_ListIterator = stl_ListAddr.begin(); + for (int i = 0; stl_ListIterator != stl_ListAddr.end(); stl_ListIterator++, i++) + { + (*pppSt_BannedAddr)[i]->nID = stl_ListIterator->nID; + (*pppSt_BannedAddr)[i]->bEnable = stl_ListIterator->bEnable; + _tcsxcpy((*pppSt_BannedAddr)[i]->tszIPAddr, stl_ListIterator->tszIPAddr); + _tcsxcpy((*pppSt_BannedAddr)[i]->tszLeftTime, stl_ListIterator->tszLeftTime); + _tcsxcpy((*pppSt_BannedAddr)[i]->tszCreateTime, stl_ListIterator->tszCreateTime); + } + stl_ListIterator = stl_ListUser.begin(); + for (int i = 0; stl_ListIterator != stl_ListUser.end(); stl_ListIterator++, i++) + { + (*pppSt_BannedUser)[i]->nID = stl_ListIterator->nID; + (*pppSt_BannedUser)[i]->bEnable = stl_ListIterator->bEnable; + _tcsxcpy((*pppSt_BannedUser)[i]->tszUserName, stl_ListIterator->tszUserName); + _tcsxcpy((*pppSt_BannedUser)[i]->tszLeftTime, stl_ListIterator->tszLeftTime); + _tcsxcpy((*pppSt_BannedUser)[i]->tszCreateTime, stl_ListIterator->tszCreateTime); + } + + stl_ListAddr.clear(); + stl_ListUser.clear(); + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_BannedExist +ܣǷںб + .һpSt_Banned + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_BannedExist(AUTHREG_BANNED* pSt_Banned) +{ + SQLPacket_IsErrorOccur = false; + XCHAR** ppszResult = nullptr; + XLONG* pInt_Length = nullptr; + + //жûǷ + if (_tcsxlen(pSt_Banned->tszUserName) > 0) + { + __int64u nRow = 0; + __int64u nColumn = 0; + XNETHANDLE xhTable = 0; + + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_BannedUser WHERE tszUserName = '%s'"), pSt_Banned->tszUserName); + + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + DataBase_MySQL_FreeResult(xhData, xhTable); + return false; + } + + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + //ID + int nFliedValue = 0; + if (NULL != ppszResult[nFliedValue]) { + pSt_Banned->nID = _ttxoll(ppszResult[nFliedValue]); + } + //Ƿ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) { + pSt_Banned->bEnable = _ttxoi(ppszResult[nFliedValue]); + } + + //ַ + nFliedValue++; + + //ʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) { + _tcsxcpy(pSt_Banned->tszLeftTime, ppszResult[nFliedValue]); + } + + //עʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) { + _tcsxcpy(pSt_Banned->tszCreateTime, ppszResult[nFliedValue]); + } + + DataBase_MySQL_FreeResult(xhData, xhTable); + } + + //жIPַǷ + if (_tcsxlen(pSt_Banned->tszIPAddr) > 0) + { + XNETHANDLE xhTable = 0; + __int64u nRow = 0; + __int64u nColumn = 0; + ppszResult = nullptr; + pInt_Length = nullptr; + + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', 1024); + + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_BannedAddr WHERE tszIPAddr = '%s'"), pSt_Banned->tszIPAddr); + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + DataBase_MySQL_FreeResult(xhData, xhTable); + return false; + } + //printf("2 :%d :%d\n", nRow, nColumn); + + if (nRow <= 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_GETTABLE; + DataBase_MySQL_FreeResult(xhData, xhTable); + return false; + } + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + + //ID + int nFliedValue = 0; + if (NULL != ppszResult[nFliedValue]) + { + //printf("%d ID%s\n", nFliedValue, ppszResult[nFliedValue]); + pSt_Banned->nID = _ttxoll(ppszResult[nFliedValue]); + } + + //Ƿ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) + { + //printf("%d Ƿã%s\n", nFliedValue, ppszResult[nFliedValue]); + pSt_Banned->bEnable = _ttxoi(ppszResult[nFliedValue]); + } + + //ַ + nFliedValue++; + + //ʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) + { + //printf("%d ʱ䣺%s\n", nFliedValue, ppszResult[nFliedValue]); + _tcsxcpy(pSt_Banned->tszLeftTime, ppszResult[nFliedValue]); + } + + + //עʱ + nFliedValue++; + if (NULL != ppszResult[nFliedValue]) + { + //printf("%d עʱ䣺%s\n", nFliedValue, ppszResult[nFliedValue]); + _tcsxcpy(pSt_Banned->tszCreateTime, ppszResult[nFliedValue]); + } + + DataBase_MySQL_FreeResult(xhData, xhTable); + } + //Ƿ񱻽 + if (!pSt_Banned->bEnable) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_NOTENABLE; + return false; + } + if (_tcsxlen(pSt_Banned->tszLeftTime) > 0) + { + __int64x nTimer = 0; + XCHAR tszStrTime[128]; + memset(tszStrTime, '\0', sizeof(tszStrTime)); + BaseLib_OperatorTime_TimeToStr(tszStrTime); + BaseLib_OperatorTimeSpan_GetForStr(pSt_Banned->tszLeftTime, tszStrTime, &nTimer, 3); + if (nTimer > 0) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_TIMELEFT; + return false; + } + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_BannedUPDate +ܣбϢ + .һpSt_Banned + In/OutIn + ͣݽṹָ + ɿգN + ˼Ҫ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_BannedUPDate(AUTHREG_BANNED* pSt_Banned) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_Banned) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + // + if (_tcsxlen(pSt_Banned->tszUserName) > 0) + { + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_BannedUser SET bEnable = %d,tszLeftTime = '%s' WHERE tszUserName = '%s'"), pSt_Banned->bEnable, pSt_Banned->tszLeftTime, pSt_Banned->tszUserName); + } + else + { + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_BannedAddr SET bEnable = %d,tszLeftTime = '%s' WHERE tszIPAddr = '%s'"), pSt_Banned->bEnable, pSt_Banned->tszLeftTime, pSt_Banned->tszIPAddr); + } + //ݿ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_AnnouncementInsert +ܣ + .һpSt_Announcement + In/OutIn + ͣݽṹָ + ɿգN + ˼ҪϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_AnnouncementInsert(AUTHREG_ANNOUNCEMENT* pSt_Announcement) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_Announcement) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XCHAR tszSQLStatement[8192]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + + _xstprintf(tszSQLStatement, _X("INSERT INTO Authorize_Announcement(tszContext,tszCreateTime) VALUES('%s',NOW())"), pSt_Announcement->tszContext); + + //printf("SQL䣺%s\n", tszSQLStatement); + //ݿ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_AnnouncementDelete +ܣɾ + .һpSt_Announcement + In/OutIn + ͣݽṹָ + ɿգN + ˼ҪɾϢ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_AnnouncementDelete(AUTHREG_ANNOUNCEMENT* pSt_Announcement) +{ + SQLPacket_IsErrorOccur = false; + + if (NULL == pSt_Announcement) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_PARAMENT; + return false; + } + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + + _xstprintf(tszSQLStatement, _X("DELETE FROM Authorize_Announcement WHERE ID = %lld"), pSt_Announcement->nID); + //ݿ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + return true; +} +/******************************************************************** +ƣDatabase_MYSQL_AnnouncementList +ܣой + .һppppSt_Announcement + In/OutOut + ָͣ + ɿգN + ˼о + .pInt_ListCount + In/OutOut + ָͣ + ɿգN + ˼ݸ +ֵ + ͣ߼ + ˼Ƿɹ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_AnnouncementList(AUTHREG_ANNOUNCEMENT*** ppppSt_Announcement, int* pInt_ListCount) +{ + SQLPacket_IsErrorOccur = false; + XNETHANDLE xhTable = 0; + __int64u nRow = 0; + __int64u nColumn = 0; + XCHAR** ppszResult = NULL; + XCHAR tszSQLStatement[1024]; //SQL + memset(tszSQLStatement, '\0', 1024); + _xstprintf(tszSQLStatement, _X("SELECT * FROM Authorize_Announcement")); + + if (!DataBase_MySQL_ExecuteQuery(xhData, &xhTable, tszSQLStatement, &nRow, &nColumn)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = DataBase_GetLastError(); + return false; + } + *pInt_ListCount = nRow; + if (NULL == ppppSt_Announcement) + { + return true; + } + BaseLib_OperatorMemory_Malloc((XPPPMEM)ppppSt_Announcement, (int)nRow, sizeof(AUTHREG_ANNOUNCEMENT)); + + //ѵ + for (int i = 0; i < nRow; i++) + { + ppszResult = DataBase_MySQL_GetResult(xhData, xhTable); + //XLONG* pInt_Length = DataBase_MySQL_GetLength(xhData, xhTable); + int nFliedValue = 0; + (*ppppSt_Announcement)[i]->nID = _ttxoll(ppszResult[nFliedValue]); + nFliedValue++; + _tcsxcpy((*ppppSt_Announcement)[i]->tszContext, ppszResult[nFliedValue]); + nFliedValue++; + _tcsxcpy((*ppppSt_Announcement)[i]->tszCreateTime, ppszResult[nFliedValue]); + nFliedValue++; + + } + DataBase_MySQL_FreeResult(xhData, xhTable); + return true; +} + +////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +ƣDatabase_MYSQL_UserPayTime +ܣڷʽֵʽ + .һlpszUserName + In/OutIn + ַָͣ + ɿգN + ˼ֵû + .lpszUserTime + In/OutIn + ַָͣ + ɿգN + ˼ûǰijʱʱ + .lpszCardTime + In/OutIn + ַָͣ + ɿգN + ˼ֵʱ + .ģen_AuthSerialType + In/OutIn + ͣö + ɿգN + ˼ֵijֵ + .壺en_AuthUserType + In/OutIn + ͣö + ɿգN + ˼ûǰijֵ +ֵ + ͣ߼ + ˼Ƿɹֵ +ע +*********************************************************************/ +bool CDatabase_MySQL::Database_MYSQL_UserPayTime(LPCXSTR lpszUserName, LPCXSTR lpszUserTime, LPCXSTR lpszCardTime, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE en_AuthSerialType, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE en_AuthUserType) +{ + SQLPacket_IsErrorOccur = false; + XCHAR tszSQLStatement[1024]; + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + //жϺǰijֵǷƥ䡣 + if (en_AuthSerialType != en_AuthUserType) + { + //,Ҫд + if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_UNKNOW != en_AuthUserType) + { + //жǷд + if (!m_bChange) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_NOTMATCH; + return false; + } + } + //ûijֵ + memset(tszSQLStatement, '\0', sizeof(tszSQLStatement)); + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET CardSerialType = '%d' WHERE UserName = '%s'"), en_AuthSerialType, lpszUserName); + //ִû£Ϊпͱı䣬Ҫ¡ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_UPDATATYPE; + return false; + } + // + switch (en_AuthSerialType) + { + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_SECOND: + { + //Ƿӿ + //ǰijֵͲƥ䣬ôǰijֵȫᱻɾ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%d' WHERE UserName = '%s'"), _ttxoi(lpszCardTime), lpszUserName); //ûĹʱ + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_DAY: + { + // + //ûĹʱ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%d' WHERE UserName = '%s'"), _ttxoi(lpszCardTime), lpszUserName); //ûĹʱ + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_TIME: + { + //Ǵ + //ûĹʱ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%d' WHERE UserName = '%s'"), _ttxoi(lpszCardTime), lpszUserName); + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_CUSTOM: + { + XCHAR tszTime[128]; + XENGINE_LIBTIMER st_AuthTime; + ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE en_GeneraterSerialType; + + memset(tszTime, '\0', sizeof(tszTime)); + memset(&st_AuthTime, '\0', sizeof(XENGINE_LIBTIMER)); + //ȡÿͺʱ + if (!Authorize_Serial_GetType(lpszCardTime, &en_GeneraterSerialType, &st_AuthTime)) + { + return false; + } + _xstprintf(tszTime, _X("%04d-%02d-%02d %02d:%02d:%02d"), st_AuthTime.wYear, st_AuthTime.wMonth, st_AuthTime.wDay, st_AuthTime.wHour, st_AuthTime.wMinute, st_AuthTime.wSecond); + //ûĹʱ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%s' WHERE UserName = '%s'"), tszTime, lpszUserName); + } + break; + default: + break; + } + } + else + { + switch (en_AuthSerialType) + { + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_SECOND: + { + int nCardTime = _ttxoi(lpszCardTime); + nCardTime += _ttxoi(lpszUserTime); //ǰûǰʱҲ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%d' WHERE UserName = '%s'"), nCardTime, lpszUserName); //ûĹʱ + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_DAY: + { + int nCardTime = _ttxoi(lpszCardTime); + nCardTime += _ttxoi(lpszUserTime); //ǰûǰʱҲ + //ûĹʱ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%d' WHERE UserName = '%s'"), nCardTime, lpszUserName); + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_TIME: + { + //Ǵ + int nCardTime = _ttxoi(lpszCardTime); + nCardTime += _ttxoi(lpszUserTime); //ǰûǰʱҲ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%d' WHERE UserName = '%s'"), nCardTime, lpszUserName); //ûĹʱ + } + break; + case ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_CUSTOM: + { + //Զ忨,޷ + XCHAR tszTime[128]; + XENGINE_LIBTIMER st_AuthTime; + ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE en_GeneraterSerialType; + + memset(tszTime, '\0', sizeof(tszTime)); + memset(&st_AuthTime, '\0', sizeof(XENGINE_LIBTIMER)); + //ȡÿͺʱ + if (!Authorize_Serial_GetType(lpszCardTime, &en_GeneraterSerialType, &st_AuthTime)) + { + return false; + } + _xstprintf(tszTime, _X("%04d-%02d-%02d %02d:%02d:%02d"), st_AuthTime.wYear, st_AuthTime.wMonth, st_AuthTime.wDay, st_AuthTime.wHour, st_AuthTime.wMinute, st_AuthTime.wSecond); + //ûĹʱ + _xstprintf(tszSQLStatement, _X("UPDATE Authorize_User SET LeftTime = '%s' WHERE UserName = '%s'"), tszTime, lpszUserName); + } + break; + default: + break; + } + } + //ûĹʱ + if (!DataBase_MySQL_Execute(xhData, tszSQLStatement)) + { + SQLPacket_IsErrorOccur = true; + SQLPacket_dwErrorCode = ERROR_AUTHORIZE_MODULE_DATABASE_UPDATA; + return false; + } + return true; +} + diff --git a/XEngine_Source/AuthorizeModule_Database/Database_MySQL/Database_MySQL.h b/XEngine_Source/AuthorizeModule_Database/Database_MySQL/Database_MySQL.h new file mode 100644 index 0000000000000000000000000000000000000000..cd6c4724ac2fc4e3e2d676bcacdcbc4ccb98512c --- /dev/null +++ b/XEngine_Source/AuthorizeModule_Database/Database_MySQL/Database_MySQL.h @@ -0,0 +1,63 @@ +#pragma once +/******************************************************************** +// Created: 2022/05/26 11:01:06 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Database\Database_MySQL\Database_MySQL.h +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Database\Database_MySQL +// File Base: Database_MySQL +// File Ext: h +// Project: XEngine(ͨ) +// Author: qyt +// Purpose: ݿ +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// AuthReg_UserTableݣID û ע ʣʱ Ӳ עļ QQ ֤ +// AuthReg_SerialTableݣID ʹ к ʹʱ ʱ Ƿʹ +////////////////////////////////////////////////////////////////////////// +class CDatabase_MySQL +{ +public: + CDatabase_MySQL(); + ~CDatabase_MySQL(); +public: + bool Database_MYSQL_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bIsChange = true); //ʼ + bool Database_MYSQL_Destroy(); // +public: + bool Database_MYSQL_UserDelete(LPCXSTR lpszUserName); //ɾû + bool Database_MYSQL_UserRegister(AUTHREG_USERTABLE* pSt_UserInfo); //ûע + bool Database_MYSQL_UserQuery(LPCXSTR lpszUserName, AUTHREG_USERTABLE* pSt_UserInfo = NULL); //ûѯ + bool Database_MYSQL_UserPay(LPCXSTR lpszUserName, LPCXSTR lpszSerialName); //ֵֵ + bool Database_MYSQL_UserLeave(AUTHREG_PROTOCOL_TIME* pSt_TimeProtocol); //û뿪± + bool Database_MYSQL_UserSet(AUTHREG_USERTABLE* pSt_UserTable); //ûϢ + bool Database_MYSQL_UserList(AUTHREG_USERTABLE*** pppSt_UserInfo, int* pInt_ListCount, int nPosStart, int nPosEnd); //ȡûб +public: + bool Database_MYSQL_SerialInsert(LPCXSTR lpszSerialNumber); //п + bool Database_MYSQL_SerialDelete(LPCXSTR lpszSerialNumber); //ɾһк + bool Database_MYSQL_SerialQuery(LPCXSTR lpszSerialNumber, LPAUTHREG_SERIALTABLE pSt_SerialTable = NULL); //տŻûѯ + bool Database_MYSQL_SerialQueryAll(AUTHREG_SERIALTABLE*** pppSt_SerialTable, int* pInt_ListCount, int nPosStart, int nPosEnd);//ѯп + bool Database_MYSQL_SerialPush(AUTHREG_SERIALTABLE* pSt_SerialTable);//һָкϢ +public: + bool Database_MYSQL_TryInsert(AUTHREG_TEMPVER* pSt_AuthVer); //ʹģʽһ + bool Database_MYSQL_TryQuery(AUTHREG_TEMPVER* pSt_AuthVer); //кŲѯ + bool Database_MYSQL_TryDelete(LPCXSTR lpszSerial); //ɾһָ + bool Database_MYSQL_TryClear(int nThanValue, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE enVerMode = ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_UNKNOW); //,Զ + bool Database_MYSQL_TrySet(AUTHREG_TEMPVER* pSt_AuthVer); //ûϢ + bool Database_MYSQL_TryList(AUTHREG_TEMPVER*** pppSt_AuthVer, int* pInt_ListCount, int nPosStart = 0, int nPosEnd = 1000); //б +public: + bool Database_MYSQL_BannedInsert(AUTHREG_BANNED* pSt_Banned); //б + bool Database_MYSQL_BannedDelete(AUTHREG_BANNED* pSt_Banned); //бɾ + bool Database_MYSQL_BannedList(AUTHREG_BANNED*** pppSt_BannedUser, int* pInt_UserCount, AUTHREG_BANNED*** pppSt_BannedAddr, int* pInt_AddrCount, int nPosStart, int nPosEnd); //бѯ + bool Database_MYSQL_BannedExist(AUTHREG_BANNED* pSt_Banned); //Ƿںб + bool Database_MYSQL_BannedUPDate(AUTHREG_BANNED* pSt_Banned); //бϢ +public: + bool Database_MYSQL_AnnouncementInsert(AUTHREG_ANNOUNCEMENT* pSt_Announcement); // + bool Database_MYSQL_AnnouncementDelete(AUTHREG_ANNOUNCEMENT* pSt_Announcement); //ɾ + bool Database_MYSQL_AnnouncementList(AUTHREG_ANNOUNCEMENT*** ppppSt_Announcement, int* pInt_ListCount); //ой + + +protected: + bool Database_MYSQL_UserPayTime(LPCXSTR lpszUserName, LPCXSTR lpszUserTime, LPCXSTR lpszCardTime, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE en_AuthSerialType, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE en_AuthUserType); //ڷʽֵʽ +private: + bool m_bChange; + XNETHANDLE xhData; //ݿ +}; diff --git a/XEngine_Source/AuthorizeModule_Database/pch.cpp b/XEngine_Source/AuthorizeModule_Database/pch.cpp index 7b844cff974e7a3755d6d809091884750346ff27..1d0d83bae8c552ec2905900e9b703b418fdc09f0 100644 --- a/XEngine_Source/AuthorizeModule_Database/pch.cpp +++ b/XEngine_Source/AuthorizeModule_Database/pch.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "Database_SQLite/Database_SQLite.h" +#include "Database_MySQL/Database_MySQL.h" /******************************************************************** // Created: 2022/05/26 11:02:23 // File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Database\pch.cpp @@ -15,6 +16,7 @@ bool SQLPacket_IsErrorOccur = false; XLONG SQLPacket_dwErrorCode = 0; ////////////////////////////////////////////////////////////////////////// CDatabase_SQLite m_SQLAuth; +CDatabase_MySQL m_MySQL; ////////////////////////////////////////////////////////////////////////// // 导出的函数 ////////////////////////////////////////////////////////////////////////// @@ -140,4 +142,122 @@ extern "C" bool Database_SQLite_AnnouncementDelete(AUTHREG_ANNOUNCEMENT * pSt_An extern "C" bool Database_SQLite_AnnouncementList(AUTHREG_ANNOUNCEMENT * **ppppSt_Announcement, int* pInt_ListCount) { return m_SQLAuth.Database_SQLite_AnnouncementList(ppppSt_Announcement, pInt_ListCount); -} \ No newline at end of file +} + + + +/************************************************************************/ +/* MYSQL数据库服务导出函数 */ +/************************************************************************/ +extern "C" bool Database_MYSQL_Init(DATABASE_MYSQL_CONNECTINFO* pSt_DBConnector, bool bIsChange) +{ + return m_MySQL.Database_MYSQL_Init(pSt_DBConnector, bIsChange); +} +extern "C" bool Database_MYSQL_Destroy() +{ + return m_MySQL.Database_MYSQL_Destroy(); +} +extern "C" bool Database_MYSQL_UserDelete(LPCXSTR lpszUserName) +{ + return m_MySQL.Database_MYSQL_UserDelete(lpszUserName); +} +extern "C" bool Database_MYSQL_UserRegister(AUTHREG_USERTABLE* pSt_UserInfo) +{ + return m_MySQL.Database_MYSQL_UserRegister(pSt_UserInfo); +} +extern "C" bool Database_MYSQL_UserQuery(LPCXSTR lpszUserName, AUTHREG_USERTABLE* pSt_UserInfo) +{ + return m_MySQL.Database_MYSQL_UserQuery(lpszUserName, pSt_UserInfo); +} +extern "C" bool Database_MYSQL_UserPay(LPCXSTR lpszUserName, LPCXSTR lpszSerialName) +{ + return m_MySQL.Database_MYSQL_UserPay(lpszUserName, lpszSerialName); +} +extern "C" bool Database_MYSQL_UserLeave(AUTHREG_PROTOCOL_TIME* pSt_TimeProtocol) +{ + return m_MySQL.Database_MYSQL_UserLeave(pSt_TimeProtocol); +} +extern "C" bool Database_MYSQL_UserSet(AUTHREG_USERTABLE* pSt_UserTable) +{ + return m_MySQL.Database_MYSQL_UserSet(pSt_UserTable); +} +extern "C" bool Database_MYSQL_UserList(AUTHREG_USERTABLE*** pppSt_UserInfo, int* pInt_ListCount, int nPosStart, int nPosEnd) +{ + return m_MySQL.Database_MYSQL_UserList(pppSt_UserInfo, pInt_ListCount, nPosStart, nPosEnd); +} +extern "C" bool Database_MYSQL_SerialInsert(LPCXSTR lpszSerialNumber) +{ + return m_MySQL.Database_MYSQL_SerialInsert(lpszSerialNumber); +} +extern "C" bool Database_MYSQL_SerialDelete(LPCXSTR lpszSerialNumber) +{ + return m_MySQL.Database_MYSQL_SerialDelete(lpszSerialNumber); +} +extern "C" bool Database_MYSQL_SerialQuery(LPCXSTR lpszSerialNumber, LPAUTHREG_SERIALTABLE pSt_SerialTable) +{ + return m_MySQL.Database_MYSQL_SerialQuery(lpszSerialNumber, pSt_SerialTable); +} +extern "C" bool Database_MYSQL_SerialQueryAll(AUTHREG_SERIALTABLE*** pppSt_SerialTable, int* pInt_ListCount, int nPosStart, int nPosEnd) +{ + return m_MySQL.Database_MYSQL_SerialQueryAll(pppSt_SerialTable, pInt_ListCount, nPosStart, nPosEnd); +} +extern "C" bool Database_MYSQL_SerialPush(AUTHREG_SERIALTABLE* pSt_SerialTable) +{ + return m_MySQL.Database_MYSQL_SerialPush(pSt_SerialTable); +} +extern "C" bool Database_MYSQL_TryInsert(AUTHREG_TEMPVER* pSt_AuthVer) +{ + return m_MySQL.Database_MYSQL_TryInsert(pSt_AuthVer); +} +extern "C" bool Database_MYSQL_TryQuery(AUTHREG_TEMPVER* pSt_AuthVer) +{ + return m_MySQL.Database_MYSQL_TryQuery(pSt_AuthVer); +} +extern "C" bool Database_MYSQL_TryDelete(LPCXSTR lpszSerial) +{ + return m_MySQL.Database_MYSQL_TryDelete(lpszSerial); +} +extern "C" bool Database_MYSQL_TryClear(int nThanValue, ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE enVerMode) +{ + return m_MySQL.Database_MYSQL_TryClear(nThanValue, enVerMode); +} +extern "C" bool Database_MYSQL_TrySet(AUTHREG_TEMPVER* pSt_AuthVer) +{ + return m_MySQL.Database_MYSQL_TrySet(pSt_AuthVer); +} +extern "C" bool Database_MYSQL_TryList(AUTHREG_TEMPVER*** pppSt_AuthVer, int* pInt_ListCount, int nPosStart, int nPosEnd) +{ + return m_MySQL.Database_MYSQL_TryList(pppSt_AuthVer, pInt_ListCount, nPosStart, nPosEnd); +} +extern "C" bool Database_MYSQL_BannedInsert(AUTHREG_BANNED* pSt_Banned) +{ + return m_MySQL.Database_MYSQL_BannedInsert(pSt_Banned); +} +extern "C" bool Database_MYSQL_BannedDelete(AUTHREG_BANNED* pSt_Banned) +{ + return m_MySQL.Database_MYSQL_BannedDelete(pSt_Banned); +} +extern "C" bool Database_MYSQL_BannedList(AUTHREG_BANNED*** pppSt_BannedUser, int* pInt_UserCount, AUTHREG_BANNED*** pppSt_BannedAddr, int* pInt_AddrCount, int nPosStart, int nPosEnd) +{ + return m_MySQL.Database_MYSQL_BannedList(pppSt_BannedUser, pInt_UserCount, pppSt_BannedAddr, pInt_AddrCount, nPosStart, nPosEnd); +} +extern "C" bool Database_MYSQL_BannedExist(AUTHREG_BANNED* pSt_Banned) +{ + return m_MySQL.Database_MYSQL_BannedExist(pSt_Banned); +} +extern "C" bool Database_MYSQL_BannedUPDate(AUTHREG_BANNED* pSt_Banned) +{ + return m_MySQL.Database_MYSQL_BannedUPDate(pSt_Banned); +} +extern "C" bool Database_MYSQL_AnnouncementInsert(AUTHREG_ANNOUNCEMENT* pSt_Announcement) +{ + return m_MySQL.Database_MYSQL_AnnouncementInsert(pSt_Announcement); +} +extern "C" bool Database_MYSQL_AnnouncementDelete(AUTHREG_ANNOUNCEMENT* pSt_Announcement) +{ + return m_MySQL.Database_MYSQL_AnnouncementDelete(pSt_Announcement); +} +extern "C" bool Database_MYSQL_AnnouncementList(AUTHREG_ANNOUNCEMENT*** ppppSt_Announcement, int* pInt_ListCount) +{ + return m_MySQL.Database_MYSQL_AnnouncementList(ppppSt_Announcement, pInt_ListCount); +} diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.aps b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.aps index fd8fca75f835f886c52b3660918e5a37080ec846..3f2745f24017de2b69ae42e70fc25b607fa5f87d 100644 Binary files a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.aps and b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.aps differ diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.rc b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.rc index 84e6ae6c4e5c1a045c4b996780efb79e632a9a23..be7835cf58717e30caf9bb864b0036cdd9651102 100644 Binary files a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.rc and b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeApp/XEngineAuthorizeApp.rc differ diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Get/AuthorizeHTTP_Token.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Get/AuthorizeHTTP_Token.cpp index f7d2290feb5c6a44002822ace9e12d6e90f9583f..a70acae664b197b402e3b5a36516350eb5fe331e 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Get/AuthorizeHTTP_Token.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Get/AuthorizeHTTP_Token.cpp @@ -68,8 +68,16 @@ bool XEngine_AuthorizeHTTP_Token(LPCXSTR lpszClientAddr, XCHAR** pptszList, int return false; } } - if (!Database_SQLite_UserQuery(tszUserName, &st_UserTable)) - { + + //判断是使用哪个数据库 + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserQuery(tszUserName, &st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserQuery(tszUserName, &st_UserTable); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "user not found"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,登录失败,用户名不存在"), lpszClientAddr); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Announcement.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Announcement.cpp index 0f1e9ce935043f52b437c8510de8a4ffb72d792a..f9c9f7bc6e12bb60e9ec90496f4498800c7df5fa 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Announcement.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Announcement.cpp @@ -23,7 +23,14 @@ bool XEngine_AuthorizeHTTP_Announcement(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIN AUTHREG_ANNOUNCEMENT st_Announcement; memset(&st_Announcement, '\0', sizeof(AUTHREG_ANNOUNCEMENT)); - Database_SQLite_AnnouncementList(NULL, &nListCount); + if (st_AuthConfig.bDB) { + Database_SQLite_AnnouncementList(NULL, &nListCount); + } + else + { + Database_MYSQL_AnnouncementList(NULL, &nListCount); + } + if (nListCount > 10) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 510, "server limited"); @@ -32,7 +39,13 @@ bool XEngine_AuthorizeHTTP_Announcement(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIN return false; } Protocol_Parse_HttpParseAnnouncement(lpszMsgBuffer, nMsgLen, &st_Announcement); - Database_SQLite_AnnouncementInsert(&st_Announcement); + if (st_AuthConfig.bDB) { + Database_SQLite_AnnouncementInsert(&st_Announcement); + } + else + { + Database_MYSQL_AnnouncementInsert(&st_Announcement); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,插入公告成功,公告信息:%s"), lpszClientAddr, st_Announcement.tszContext); @@ -43,7 +56,13 @@ bool XEngine_AuthorizeHTTP_Announcement(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIN memset(&st_Announcement, '\0', sizeof(AUTHREG_ANNOUNCEMENT)); Protocol_Parse_HttpParseAnnouncement(lpszMsgBuffer, nMsgLen, &st_Announcement); - Database_SQLite_AnnouncementDelete(&st_Announcement); + if (st_AuthConfig.bDB) { + Database_SQLite_AnnouncementDelete(&st_Announcement); + } + else + { + Database_MYSQL_AnnouncementDelete(&st_Announcement); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,删除公告成功.删除公告ID:%lld"), lpszClientAddr, st_Announcement.nID); @@ -53,7 +72,13 @@ bool XEngine_AuthorizeHTTP_Announcement(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIN int nListCount = 0; AUTHREG_ANNOUNCEMENT** ppSt_Announcement; - Database_SQLite_AnnouncementList(&ppSt_Announcement, &nListCount); + if (st_AuthConfig.bDB) { + Database_SQLite_AnnouncementList(&ppSt_Announcement, &nListCount); + } + else + { + Database_MYSQL_AnnouncementList(&ppSt_Announcement, &nListCount); + } Protocol_Packet_HttpAnnouncement(tszSDBuffer, &nSDLen, &ppSt_Announcement, nListCount); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_Announcement, nListCount); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Banned.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Banned.cpp index f066df2e0ab9b22d2f49f5f14dd637ec6332ea38..fb33ceedf536417954c68105207532f8aa3b3f70 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Banned.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Banned.cpp @@ -17,7 +17,13 @@ bool XEngine_AuthorizeHTTP_Banned(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L memset(&st_Banned, '\0', sizeof(AUTHREG_BANNED)); Protocol_Parse_HttpParseBanned(lpszMsgBuffer, nMsgLen, &st_Banned); - Database_SQLite_BannedInsert(&st_Banned); + if (st_AuthConfig.bDB) { + Database_SQLite_BannedInsert(&st_Banned); + } + else + { + Database_MYSQL_BannedInsert(&st_Banned); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,插入禁用列表成功,禁用的用户:%s,禁用的IP地址:%s"), lpszClientAddr, st_Banned.tszUserName, st_Banned.tszIPAddr); @@ -28,7 +34,13 @@ bool XEngine_AuthorizeHTTP_Banned(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L memset(&st_Banned, '\0', sizeof(AUTHREG_BANNED)); Protocol_Parse_HttpParseBanned(lpszMsgBuffer, nMsgLen, &st_Banned); - Database_SQLite_BannedDelete(&st_Banned); + if (st_AuthConfig.bDB) { + Database_SQLite_BannedDelete(&st_Banned); + } + else + { + Database_MYSQL_BannedDelete(&st_Banned); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,删除禁用列表成功,删除禁用的用户:%s,删除禁用的IP地址:%s"), lpszClientAddr, st_Banned.tszUserName, st_Banned.tszIPAddr); @@ -44,7 +56,13 @@ bool XEngine_AuthorizeHTTP_Banned(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L Protocol_Parse_HttpParseBanned2(lpszMsgBuffer, nMsgLen, &nPosStart, &nPosEnd); - Database_SQLite_BannedList(&ppSt_BannedUser, &nCountUser, &ppSt_BannedAddr, &nCountAddr, nPosStart, nPosEnd); + if (st_AuthConfig.bDB) { + Database_SQLite_BannedList(&ppSt_BannedUser, &nCountUser, &ppSt_BannedAddr, &nCountAddr, nPosStart, nPosEnd); + } + else + { + Database_MYSQL_BannedList(&ppSt_BannedUser, &nCountUser, &ppSt_BannedAddr, &nCountAddr, nPosStart, nPosEnd); + } Protocol_Packet_HttpBanned(tszSDBuffer, &nSDLen, &ppSt_BannedUser, nCountUser, &ppSt_BannedAddr, nCountAddr); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_BannedAddr, nCountAddr); @@ -57,7 +75,13 @@ bool XEngine_AuthorizeHTTP_Banned(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L memset(&st_Banned, '\0', sizeof(AUTHREG_BANNED)); Protocol_Parse_HttpParseBanned(lpszMsgBuffer, nMsgLen, &st_Banned); - Database_SQLite_BannedUPDate(&st_Banned); + if (st_AuthConfig.bDB) { + Database_SQLite_BannedUPDate(&st_Banned); + } + else + { + Database_MYSQL_BannedUPDate(&st_Banned); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,修改禁用列表成功,修改的用户:%s,修改的IP地址:%s"), lpszClientAddr, st_Banned.tszUserName, st_Banned.tszIPAddr); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Client.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Client.cpp index c4f257b5b1e0f792db3ca52cade952a07f3b1990..753a3b2e2fa05e362bd33cd8874314d3f1eddce6 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Client.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Client.cpp @@ -17,8 +17,15 @@ bool XEngine_AuthorizeHTTP_Client(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L memset(&st_UserTable, '\0', sizeof(AUTHREG_USERTABLE)); Protocol_Parse_HttpParseUser(lpszMsgBuffer, nMsgLen, &st_UserTable.st_UserInfo); - if (!Database_SQLite_UserQuery(st_UserTable.st_UserInfo.tszUserName, &st_UserTable)) - { + + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserQuery(st_UserTable.st_UserInfo.tszUserName, &st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserQuery(st_UserTable.st_UserInfo.tszUserName, &st_UserTable); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "not found client"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求用户:%s 信息失败,错误码:%lX"), lpszClientAddr, st_UserTable.st_UserInfo.tszUserName, DBModule_GetLastError()); @@ -63,7 +70,14 @@ bool XEngine_AuthorizeHTTP_Client(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L if (!bOnline) { //只有bOnline不是在线列表的时候才执行 - Database_SQLite_UserList(&ppSt_UserInfo, &nOffCount, nPosStart, nPosEnd); + //判断是使用哪个数据库 + if (st_AuthConfig.bDB) { + Database_SQLite_UserList(&ppSt_UserInfo, &nOffCount, nPosStart, nPosEnd); + } + else + { + Database_MYSQL_UserList(&ppSt_UserInfo, &nOffCount, nPosStart, nPosEnd); + } } Protocol_Packet_HttpClientList(ptszMsgBuffer, &nSDLen, &ppSt_ListClient, nOnCount, &ppSt_UserInfo, nOffCount); @@ -104,8 +118,14 @@ bool XEngine_AuthorizeHTTP_Client(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L memset(&st_UserTable, '\0', sizeof(AUTHREG_USERTABLE)); Protocol_Parse_HttpParseTable(lpszMsgBuffer, nMsgLen, &st_UserTable); - if (!Database_SQLite_UserSet(&st_UserTable)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserSet(&st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserSet(&st_UserTable); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "not found client"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,请求修改用户信息失败:%s 错误码:%lX"), lpszClientAddr, st_UserTable.st_UserInfo.tszUserName, DBModule_GetLastError()); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Pass.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Pass.cpp index 94935d1cf5576fac3a2778f33abc4bc7921cb6b8..22e08b6effbe460dfae7fd8814581d46e9084c93 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Pass.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Pass.cpp @@ -19,8 +19,14 @@ bool XEngine_AuthorizeHTTP_Pass(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC memset(&st_UserTable, '\0', sizeof(AUTHREG_USERTABLE)); Protocol_Parse_HttpParseAuth(lpszMsgBuffer, nMsgLen, &st_UserAuth); - if (!Database_SQLite_UserQuery(st_UserAuth.tszUserName, &st_UserTable)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserQuery(st_UserAuth.tszUserName, &st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserQuery(st_UserAuth.tszUserName, &st_UserTable); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "user notfound"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("PASS客户端:%s,用户名:%s,登录失败,用户名不存在"), lpszClientAddr, st_UserAuth.tszUserName); @@ -43,7 +49,13 @@ bool XEngine_AuthorizeHTTP_Pass(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC memset(&st_ProtocolTime, '\0', sizeof(AUTHREG_PROTOCOL_TIME)); Protocol_Parse_HttpParseTime(lpszMsgBuffer, nMsgLen, &st_ProtocolTime); - Database_SQLite_UserLeave(&st_ProtocolTime); + if (st_AuthConfig.bDB) { + Database_SQLite_UserLeave(&st_ProtocolTime); + } + else + { + Database_MYSQL_UserLeave(&st_ProtocolTime); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); @@ -55,7 +67,13 @@ bool XEngine_AuthorizeHTTP_Pass(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC memset(&st_ProtocolTime, '\0', sizeof(AUTHREG_PROTOCOL_TIME)); Protocol_Parse_HttpParseTime(lpszMsgBuffer, nMsgLen, &st_ProtocolTime); - Database_SQLite_UserLeave(&st_ProtocolTime); + if (st_AuthConfig.bDB) { + Database_SQLite_UserLeave(&st_ProtocolTime); + } + else + { + Database_MYSQL_UserLeave(&st_ProtocolTime); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("PASS客户端:%s,用户名:%s,超时通知成功"), lpszClientAddr, st_ProtocolTime.tszUserName); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Serial.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Serial.cpp index 97bd0df59ce9503b27099077faa6719d929928c3..9cbefff33403af1c3af60d5e798a13f7fcf99da0 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Serial.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Serial.cpp @@ -32,7 +32,13 @@ bool XEngine_AuthorizeHTTP_Serial(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L return false; } AUTHREG_SERIALTABLE** ppSt_SerialTable; - Database_SQLite_SerialQueryAll(&ppSt_SerialTable, &nListCount, nPosStart, nPosEnd); + if (st_AuthConfig.bDB) { + Database_SQLite_SerialQueryAll(&ppSt_SerialTable, &nListCount, nPosStart, nPosEnd); + } + else + { + Database_MYSQL_SerialQueryAll(&ppSt_SerialTable, &nListCount, nPosStart, nPosEnd); + } Protocol_Packet_HttpSerialList(ptszMsgBuffer, &nSDLen, &ppSt_SerialTable, nListCount); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_SerialTable, nListCount); XEngine_Client_TaskSend(lpszClientAddr, ptszMsgBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); @@ -93,9 +99,15 @@ bool XEngine_AuthorizeHTTP_Serial(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L return false; } //导入序列卡 - for (int i = 0; i < nSerialCount; i++) - { - Database_SQLite_SerialInsert(pptszSerialNumber[i]); + if (st_AuthConfig.bDB) { + for (int i = 0; i < nSerialCount; i++) {//导入序列卡 + Database_SQLite_SerialInsert(pptszSerialNumber[i]); + } + } + else { + for (int i = 0; i < nSerialCount; i++) {//导入序列卡 + Database_MYSQL_SerialInsert(pptszSerialNumber[i]); + } } BaseLib_OperatorMemory_Free((XPPPMEM)&pptszSerialNumber, nSerialCount); Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); @@ -108,9 +120,17 @@ bool XEngine_AuthorizeHTTP_Serial(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L AUTHREG_SERIALTABLE** ppSt_SerialTable; Protocol_Parse_HttpParseSerial(lpszMsgBuffer, nMsgLen, &ppSt_SerialTable, &nListCount); - for (int i = 0; i < nListCount; i++) - { - Database_SQLite_SerialDelete(ppSt_SerialTable[i]->tszSerialNumber); + if (st_AuthConfig.bDB) { + for (int i = 0; i < nListCount; i++) + { + Database_SQLite_SerialDelete(ppSt_SerialTable[i]->tszSerialNumber); + } + } + else { + for (int i = 0; i < nListCount; i++) + { + Database_MYSQL_SerialDelete(ppSt_SerialTable[i]->tszSerialNumber); + } } BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_SerialTable, nListCount); Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); @@ -123,9 +143,17 @@ bool XEngine_AuthorizeHTTP_Serial(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, L AUTHREG_SERIALTABLE** ppSt_SerialTable; Protocol_Parse_HttpParseSerial(lpszMsgBuffer, nMsgLen, &ppSt_SerialTable, &nListCount); - for (int i = 0; i < nListCount; i++) - { - Database_SQLite_SerialPush(ppSt_SerialTable[i]); + if (st_AuthConfig.bDB) { + for (int i = 0; i < nListCount; i++) + { + Database_SQLite_SerialPush(ppSt_SerialTable[i]); + } + } + else { + for (int i = 0; i < nListCount; i++) + { + Database_MYSQL_SerialPush(ppSt_SerialTable[i]); + } } BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_SerialTable, nListCount); Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Try.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Try.cpp index 86d70890a06416c4e637dd23cd6983f4542cf127..fd3c080854b20183ce7e29426d7b44c5d69ac99d 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Try.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_Try.cpp @@ -29,7 +29,13 @@ bool XEngine_AuthorizeHTTP_Try(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPCX int nListCount = 0; AUTHREG_TEMPVER** ppSt_AuthVer; - Database_SQLite_TryList(&ppSt_AuthVer, &nListCount); + if (st_AuthConfig.bDB) { + Database_SQLite_TryList(&ppSt_AuthVer, &nListCount); + } + else + { + Database_MYSQL_TryList(&ppSt_AuthVer, &nListCount); + } Protocol_Packet_HttpTryList(ptszMsgBuffer, &nSDLen, &ppSt_AuthVer, nListCount); BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_AuthVer, nListCount); XEngine_Client_TaskSend(lpszClientAddr, ptszMsgBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); @@ -43,7 +49,14 @@ bool XEngine_AuthorizeHTTP_Try(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPCX memset(&st_VERTemp, '\0', sizeof(AUTHREG_TEMPVER)); Protocol_Parse_HttpParseTry(lpszMsgBuffer, nMsgLen, &st_VERTemp); - Database_SQLite_TryDelete(st_VERTemp.tszVSerial); + if (st_AuthConfig.bDB) { + Database_SQLite_TryDelete(st_VERTemp.tszVSerial); + } + else + { + Database_MYSQL_TryDelete(st_VERTemp.tszVSerial); + } + Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,序列号:%s,临时验证删除成功"), lpszClientAddr, st_VERTemp.tszVSerial); @@ -54,7 +67,13 @@ bool XEngine_AuthorizeHTTP_Try(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPCX memset(&st_VERTemp, '\0', sizeof(AUTHREG_TEMPVER)); Protocol_Parse_HttpParseTry(lpszMsgBuffer, nMsgLen, &st_VERTemp); - Database_SQLite_TrySet(&st_VERTemp); + if (st_AuthConfig.bDB) { + Database_SQLite_TrySet(&st_VERTemp); + } + else + { + Database_MYSQL_TrySet(&st_VERTemp); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,序列号:%s,临时验证修改成功"), lpszClientAddr, st_VERTemp.tszVSerial); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_User.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_User.cpp index 6654cee030c716c48e0908529f1ca10794fb6ea9..2172bb2cd6d2ddf9fed01cfa0bdab190c00a2c60 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_User.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/AuthorizeHTTP_Post/AuthorizeHTTP_User.cpp @@ -36,7 +36,13 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC } BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListClient, nListCount); - Database_SQLite_UserDelete(st_UserInfo.tszUserName); + if (st_AuthConfig.bDB) { + Database_SQLite_UserDelete(st_UserInfo.tszUserName); + } + else + { + Database_MYSQL_UserDelete(st_UserInfo.tszUserName); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,请求删除用户:%s 成功,在线用户数:%d"), lpszClientAddr, st_UserInfo.tszUserName, nListCount); @@ -60,8 +66,14 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC memset(&st_Banned, '\0', sizeof(AUTHREG_BANNED)); _tcsxcpy(st_Banned.tszUserName, st_UserTable.st_UserInfo.tszUserName); - if (Database_SQLite_BannedExist(&st_Banned)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_BannedExist(&st_Banned); + } + else { + bSuccess = Database_MYSQL_BannedExist(&st_Banned); + } + if (bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 423, "user name is banned"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,注册失败,用户名已经被禁用!"), lpszClientAddr, st_Banned.tszUserName); @@ -85,8 +97,14 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,注册失败,没有设置用户和密码"), lpszClientAddr); return false; } - if (!Database_SQLite_UserRegister(&st_UserTable)) - { + bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserRegister(&st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserRegister(&st_UserTable); + } + if (!bSuccess) { XLONG dwRet = DBModule_GetLastError(); Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, dwRet, "user register is failed"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); @@ -113,14 +131,26 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC return false; } Protocol_Parse_HttpParsePay(lpszMsgBuffer, nMsgLen, &st_UserPay); - if (!Database_SQLite_UserPay(st_UserPay.tszUserName, st_UserPay.tszSerialNumber)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserPay(st_UserPay.tszUserName, st_UserPay.tszSerialNumber); + } + else { + bSuccess = Database_MYSQL_UserPay(st_UserPay.tszUserName, st_UserPay.tszSerialNumber); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "Serial number not available"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,充值失败,无法继续,错误:%X"), lpszClientAddr, st_UserPay.tszUserName, DBModule_GetLastError()); return false; } - Database_SQLite_UserQuery(st_UserPay.tszUserName, &st_UserInfo); + if (st_AuthConfig.bDB) { + Database_SQLite_UserQuery(st_UserPay.tszUserName, &st_UserInfo); + } + else + { + Database_MYSQL_UserQuery(st_UserPay.tszUserName, &st_UserInfo); + } Session_Authorize_SetUser(&st_UserInfo); Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); @@ -144,8 +174,14 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC return false; } Protocol_Parse_HttpParseUser(lpszMsgBuffer, nMsgLen, &st_UserInfo); - if (!Database_SQLite_UserQuery(st_UserInfo.tszUserName, &st_UserTable)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserQuery(st_UserInfo.tszUserName, &st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserQuery(st_UserInfo.tszUserName, &st_UserTable); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 404, "user not found"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,用户名:%s,找回密码失败,用户不存在"), lpszClientAddr, st_UserInfo.tszUserName); @@ -200,8 +236,14 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC return false; } Protocol_Parse_HttpParseTry(lpszMsgBuffer, nMsgLen, &st_VERTemp); - if (Database_SQLite_TryQuery(&st_VERTemp)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_TryQuery(&st_VERTemp); + } + else { + bSuccess = Database_MYSQL_TryQuery(&st_VERTemp); + } + if (bSuccess) { __int64x nTimeSpan = 0; //根据方式来计算剩余时间 if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_TIME == st_VERTemp.enVMode) @@ -231,7 +273,13 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC //是否超过 if (nTimeSpan >= 0) { - Database_SQLite_TrySet(&st_VERTemp); + if (st_AuthConfig.bDB) { + Database_SQLite_TrySet(&st_VERTemp); + } + else + { + Database_MYSQL_TrySet(&st_VERTemp); + } Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("HTTP客户端:%s,序列号:%s,类型:%s,临时验证成功,剩余时间:%lld"), lpszClientAddr, st_VERTemp.tszVSerial, lpszXSerialType[st_VERTemp.enVMode], nTimeSpan); @@ -256,8 +304,14 @@ bool XEngine_AuthorizeHTTP_User(LPCXSTR lpszClientAddr, LPCXSTR lpszAPIName, LPC XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _X("HTTP客户端:%s,序列号:%s,临时验证插入失败,因为服务器关闭了此功能"), lpszClientAddr, st_VERTemp.tszVSerial); return false; } - if (!Database_SQLite_TryInsert(&st_VERTemp)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_TryInsert(&st_VERTemp); + } + else { + bSuccess = Database_MYSQL_TryInsert(&st_VERTemp); + } + if (!bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 500, "Internal Server Error"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("HTTP客户端:%s,序列号:%s,临时验证插入失败,无法继续,错误:%X"), lpszClientAddr, st_VERTemp.tszVSerial, DBModule_GetLastError()); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Hdr.h b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Hdr.h index 78d426db7c1a563e065e34de27522c9c58676d54..34784b83b6a8157e94a55d092aaa00c0bdff7dc5 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Hdr.h +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Hdr.h @@ -40,6 +40,8 @@ using namespace std; #include #include #include +#include +#include #include "../../XAuth_Protocol.h" #include "../../AuthorizeModule_Configure/Config_Define.h" #include "../../AuthorizeModule_Configure/Config_Error.h" diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_HttpTask.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_HttpTask.cpp index 1240c6b8a8a41cd59e2edf37e5008f97ea522bad..5db95682c3ea17e5dd59d0ca1505e7aee68cd3a6 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_HttpTask.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_HttpTask.cpp @@ -63,8 +63,14 @@ bool XEngine_Client_HttpTask(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int _tcsxcpy(st_Banned.tszIPAddr, lpszClientAddr); BaseLib_OperatorIPAddr_SegAddr(st_Banned.tszIPAddr); //是否在黑名单 - if (Database_SQLite_BannedExist(&st_Banned)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_BannedExist(&st_Banned); //IP地址是否在黑名单 + } + else { + bSuccess = Database_MYSQL_BannedExist(&st_Banned);//IP地址是否在黑名单 + } + if (bSuccess) { Protocol_Packet_HttpComm(tszSDBuffer, &nSDLen, 423, "ip address is banned"); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_AUTH_APP_NETTYPE_HTTP); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("客户端:%s,登录连接被阻止,IP地址被禁用!"), lpszClientAddr); diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Net.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Net.cpp index 56e57810fba4caebdf43ae46b2fffd5eb3683a67..80b86d14950406a0caffc3edd375327b7852a6df 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Net.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Net.cpp @@ -164,7 +164,15 @@ bool XEngine_SendMsg(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nMsgLen, } else if (XENGINE_AUTH_APP_NETTYPE_TCP == nNetType) { - NetCore_TCPXCore_SendEx(xhTCPSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen); + if (NULL == lpszPass) + { + NetCore_TCPXCore_SendEx(xhTCPSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen); + } + else + { + OPenSsl_XCrypto_Encoder(lpszMsgBuffer, &nMsgLen, (XBYTE*)ptszMsgBuffer, lpszPass); + NetCore_TCPXCore_SendEx(xhTCPSocket, lpszClientAddr, ptszMsgBuffer, nMsgLen); + } } else { diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_TCPTask.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_TCPTask.cpp index af26d111113f10ec4a5ba0a863196ee81ee2c870..5d6c9c42f2226e8fe82ceacd2d3bcab663c09b54 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_TCPTask.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_TCPTask.cpp @@ -61,8 +61,14 @@ bool XEngine_Client_TCPTask(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n _tcsxcpy(st_Banned.tszIPAddr, lpszClientAddr); BaseLib_OperatorIPAddr_SegAddr(st_Banned.tszIPAddr); //是否在黑名单 - if (Database_SQLite_BannedExist(&st_Banned)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_BannedExist(&st_Banned); //是否在黑名单 + } + else { + bSuccess = Database_MYSQL_BannedExist(&st_Banned);//是否在黑名单 + } + if (bSuccess) { pSt_ProtocolHdr->wReserve = 423; Protocol_Packet_HDRComm(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, nNetType); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, nNetType); @@ -132,8 +138,14 @@ bool XEngine_Client_TCPTask(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n } else { - if (!Database_SQLite_UserQuery(st_AuthProtocol.tszUserName, &st_UserTable)) - { + bool bSuccess = false; + if (st_AuthConfig.bDB) { + bSuccess = Database_SQLite_UserQuery(st_AuthProtocol.tszUserName, &st_UserTable); + } + else { + bSuccess = Database_MYSQL_UserQuery(st_AuthProtocol.tszUserName, &st_UserTable); + } + if (!bSuccess) { pSt_ProtocolHdr->wReserve = 251; Protocol_Packet_HDRComm(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, nNetType); XEngine_Client_TaskSend(lpszClientAddr, tszSDBuffer, nSDLen, nNetType); @@ -268,7 +280,14 @@ bool XEngine_Client_TCPTask(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n __int64x nTime = _ttxoll(st_UserTable.tszLeftTime) - 1; _xstprintf(st_UserTable.tszLeftTime, _X("%lld"), nTime); - Database_SQLite_UserSet(&st_UserTable); + if (st_AuthConfig.bDB) { + Database_SQLite_UserSet(&st_UserTable); + } + else + { + Database_MYSQL_UserSet(&st_UserTable); + + } } else if (ENUM_HELPCOMPONENTS_AUTHORIZE_SERIAL_TYPE_DAY == st_UserTable.enSerialType) { @@ -278,7 +297,14 @@ bool XEngine_Client_TCPTask(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n __int64x nTime = _ttxoll(st_UserTable.tszLeftTime) - 1; _xstprintf(st_UserTable.tszLeftTime, _X("%lld"), nTime); BaseLib_OperatorTime_TimeToStr(st_UserTable.st_UserInfo.tszLoginTime); - Database_SQLite_UserSet(&st_UserTable); + if (st_AuthConfig.bDB) { + Database_SQLite_UserSet(&st_UserTable); + } + else + { + Database_MYSQL_UserSet(&st_UserTable); + + } } } diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Task.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Task.cpp index 40e8fc89a61275d1087331290d5b81f98b0f069b..9750b59e2f59ca94ee728682a3e7b7f3b4d98af7 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Task.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_Task.cpp @@ -52,7 +52,13 @@ void CALLBACK XEngine_TaskEvent_Client(LPCXSTR lpszUserAddr, LPCXSTR lpszUserNam _tcsxcpy(st_AuthTime.tszUserName, lpszUserName); _tcsxcpy(st_AuthTime.tszUserAddr, lpszUserAddr); - Database_SQLite_UserLeave(&st_AuthTime); + if (st_AuthConfig.bDB) { + Database_SQLite_UserLeave(&st_AuthTime); + } + else + { + Database_MYSQL_UserLeave(&st_AuthTime); + } } void CALLBACK XEngine_TaskEvent_Token(XNETHANDLE xhToken, XPVOID lParam) { diff --git a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/XEngine_AuthorizeService.cpp b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/XEngine_AuthorizeService.cpp index ef866c7eae9d43773aa0b4cf750fbfe17538c669..8f08465b8bbbaa504d08fa6a5bf77beeedea3409 100644 --- a/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/XEngine_AuthorizeService.cpp +++ b/XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/XEngine_AuthorizeService.cpp @@ -50,7 +50,13 @@ void ServiceApp_Stop(int signo) Session_Authorize_Destroy(); Session_Token_Destroy(); AuthHelp_DynamicCode_Destory(); - Database_SQLite_Destroy(); + if (st_AuthConfig.bDB) { + Database_SQLite_Destroy();//销毁DB数据库服务 + } + else + { + Database_MYSQL_Destroy();// 待处理 销毁MYsql数据库服务 + } exit(0); } } @@ -138,13 +144,26 @@ int main(int argc, char** argv) goto XENGINE_EXITAPP; } XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化内存池成功")); - - if (!Database_SQLite_Init(st_AuthConfig.st_XSql.tszSQLite)) + + /*********** 初始化 MySql/DB数据库 ***********/ + if (st_AuthConfig.bDB) + { //SQLite数据库 + if (!Database_SQLite_Init(st_AuthConfig.st_XSql.tszSQLite)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化DB数据库服务失败,错误:%lX"), DBModule_GetLastError()); + goto XENGINE_EXITAPP; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化DB数据库服务成功,数据库:%s"), st_AuthConfig.st_XSql.tszSQLite); + } + else { - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化数据库服务失败,错误:%lX"), DBModule_GetLastError()); - goto XENGINE_EXITAPP; + if (!Database_MYSQL_Init((DATABASE_MYSQL_CONNECTINFO*)&st_AuthConfig.st_XSql)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("启动服务中,初始化MySql数据库失败,错误:%lX"), DBModule_GetLastError()); + goto XENGINE_EXITAPP; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化MySql数据库服务成功,数据库:%s"), st_AuthConfig.st_XSql.tszDBName); } - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("启动服务中,初始化数据库服务成功,数据库:%s"), st_AuthConfig.st_XSql.tszSQLite); if (!Session_Authorize_Init(XEngine_TaskEvent_Client)) { @@ -332,7 +351,14 @@ XENGINE_EXITAPP: Session_Authorize_Destroy(); Session_Token_Destroy(); AuthHelp_DynamicCode_Destory(); - Database_SQLite_Destroy(); + + if (st_AuthConfig.bDB) { + Database_SQLite_Destroy();//销毁DB数据库服务 + } + else + { + Database_MYSQL_Destroy();// 待处理 销毁MYsql数据库服务 + } } #ifdef _WINDOWS WSACleanup(); diff --git a/XEngine_Source/dllmain.cpp b/XEngine_Source/dllmain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daed8c8f7ac50ca1466016a0529648d18125a7e7 --- /dev/null +++ b/XEngine_Source/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : 定义 DLL 应用程序的入口点。 +#include "pch.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/XEngine_Source/framework.h b/XEngine_Source/framework.h new file mode 100644 index 0000000000000000000000000000000000000000..80cbbc9b06a9b0141f92ee19eceaed71328caff4 --- /dev/null +++ b/XEngine_Source/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/pch.cpp b/XEngine_Source/pch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7cfd6806caad5d62a2db9b5642a1453640e261a2 --- /dev/null +++ b/XEngine_Source/pch.cpp @@ -0,0 +1,60 @@ +#include "pch.h" +#include "AuthClient_Connector/AuthClient_Connector.h" +#include "AuthClient_HTTPVer/AuthClient_HTTPVer.h" +/******************************************************************** +// Created: 2023/11/15 11:28:22 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\pch.cpp +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +bool AuthClient_IsErrorOccur = false; +XLONG AuthClient_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CAuthClient_Connector m_Connector; +CAuthClient_HTTPVer m_HTTPVer; +////////////////////////////////////////////////////////////////////////// +// 导出的函数 +////////////////////////////////////////////////////////////////////////// +extern "C" XLONG AuthClient_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return AuthClient_dwErrorCode; +} +/************************************************************************/ +/* 验证客户端导出函数 */ +/************************************************************************/ +extern "C" bool AuthClient_Connector_Connect(LPCXSTR lpszClientAddr, int nPort, LPCXSTR lpszPass) +{ + return m_Connector.AuthClient_Connector_Connect(lpszClientAddr, nPort, lpszPass); +} +extern "C" bool AuthClient_Connector_Close() +{ + return m_Connector.AuthClient_Connector_Close(); +} +extern "C" bool AuthClient_Connector_GetAuth(bool* pbAuth) +{ + return m_Connector.AuthClient_Connector_GetAuth(pbAuth); +} +extern "C" bool AuthClient_Connector_Login(LPCXSTR lpszUser, LPCXSTR lpszPass, int nDYCode, XNETHANDLE xhToken) +{ + return m_Connector.AuthClient_Connector_Login(lpszUser, lpszPass, nDYCode, xhToken); +} +/************************************************************************/ +/* 临时验证函数 */ +/************************************************************************/ +extern "C" bool AuthClient_HTTPVer_TryRequest(LPCXSTR lpszURLAddr) +{ + return m_HTTPVer.AuthClient_HTTPVer_TryRequest(lpszURLAddr); +} +extern "C" bool AuthClient_HTTPVer_GetDCode(LPCXSTR lpszURLAddr, int* pInt_DYCode, XNETHANDLE * pxhToken, int* pInt_Timeout) +{ + return m_HTTPVer.AuthClient_HTTPVer_GetDCode(lpszURLAddr, pInt_DYCode, pxhToken, pInt_Timeout); +} \ No newline at end of file diff --git a/XEngine_Source/pch.h b/XEngine_Source/pch.h new file mode 100644 index 0000000000000000000000000000000000000000..74f40fa119fb9915fc9bd47b7801ba5b37b046cd --- /dev/null +++ b/XEngine_Source/pch.h @@ -0,0 +1,80 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#ifdef _MSC_BUILD +#include "framework.h" +#include +#endif +#endif //PCH_H +#include "../XAuth_BuildSwitch.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_TCP) +#include +#include +#include +#include +#include +#include +#include "../XAuth_Protocol.h" +#endif +#if (1 == _XAUTH_BUILD_SWITCH_CLIENT_HTTP) +#include +#include +#include +#include +#endif +#include "AuthClient_Define.h" +#include "AuthClient_Error.h" +using namespace std; +/******************************************************************** +// Created: 2023/11/15 10:37:19 +// File Name: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client\pch.h +// File Path: D:\XEngine_Authorize\XEngine_Source\AuthorizeModule_Client +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公有头文件 +// History: +*********************************************************************/ +extern bool AuthClient_IsErrorOccur; +extern XLONG AuthClient_dwErrorCode; + + +#ifdef _MSC_BUILD +#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_Client/XClient_APIHelp") +#pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi") +#ifdef _DEBUG +#ifdef _WIN64 +#pragma comment(lib,"../x64/Debug/jsoncpp") +#else +#pragma comment(lib,"../Debug/jsoncpp") +#endif +#else +#ifdef _WIN64 +#pragma comment(lib,"../x64/Release/jsoncpp") +#else +#pragma comment(lib,"../Release/jsoncpp") +#endif +#endif +#endif \ No newline at end of file