diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 259148fa18f9fb7ef58563f4ff15fc7b172339fb..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1,32 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app diff --git a/CHANGELOG b/CHANGELOG index f33c9ff86f0f849ca22978617db43629a8651111..819276d0f75eeedd2c929db0a5dd042115bce8d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,27 @@ +XEngine_ProxyServer V1.3.0.1001 + +添加:会话转发模块 +添加:协议转发模块 +添加:转发处理框架代码 +添加:转发配置字段 +添加:转发线程数配置 +修改:验证模块错误定义 +修改:移动客户端接口到新的地方 +修改:获取xengine版本的方法 +优化:线程处理代码 +修正:客户端离开后多次打印日志 + +added:forward of session module +added:forward of protocol module +added:forward process code of the framework +added:configure of forward field +added:thread number of the forward for configure +modify:error code for auth +modify:move client strtuct to new dir +modify:get xengine ver method +improved:thread process +fixed:mulit print client log of leave +====================================================================================== XEngine_ProxyServer V1.2.0.1001 添加:jsoncpp模块到项目 diff --git a/README.en.md b/README.en.md index c64a46a8283759cd4da8d56a408b0351640fbf98..ba56cecde33baafa7650f51a3d8f6ec2690bf2e4 100644 --- a/README.en.md +++ b/README.en.md @@ -1,9 +1,10 @@ # XEngine_ProxyServer -we have a development and a master branch. If you want to use it, please use the code under the master branch +we have a development and a master branch. If you want to use it, please use the code under the master branch +As long as the repository is not in suspended state, we will maintain and develop it all the time, please use it with confidence #### Description -c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 -c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service +c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 tcp转发服务 +c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service #### Software Architecture the software developed based on xengine,using c/c++ development @@ -13,11 +14,12 @@ This software is a standard proxy server that supports Socks5 and HTTP tunnel pr this software support following features 1. SOCKS5 proxy 2. Tunnel proxy -3. support Permission Validation -4. operator log -5. encrypt Communication(planning) -6. load balanc(planning) -7. custom cert proxy protocol(planning) +3. forward proxy +4. support Permission Validation +5. operator log +6. encrypt Communication(planning) +7. load balanc(planning) +8. custom cert proxy protocol(planning) ## install diff --git a/README.md b/README.md index 43b59647a299abe2c39c1cb6ff914cf46389209d..dfb8f26f72dacbc6947e92e8176d57e31e437c39 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ [中文](README.md) || [English](README.en.md) # XEngine_ProxyServer 本仓库有开发和主分支,如果要使用,请使用master分支下的代码 +只要仓库不是在暂停状态,那么就会有人一直维护和开发,请放心使用 ## 介绍 -c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 -c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service +c c++ SOCKS5代理服务 HTTP Tunnel隧道代理服务 tcp转发服务 +c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service ## 软件架构 此软件基于XEngine开发.采用C/C++作为开发语言 @@ -12,12 +13,13 @@ c c++ Socks5 Proxy Service HTTP Tunnel Proxy Service ## 软件特性 此软件支持以下特性 1. SOCKS5代理 -2. Tunnel代理 -3. 权限验证 -4. 操作日志 -5. 加密通信(planning) -6. 负载均衡(planning) -7. 自定义证书代理协议(planning) +2. Tunnel代理 +3. 数据转发服务 +4. 权限验证 +5. 操作日志 +6. 加密通信(planning) +7. 负载均衡(planning) +8. 自定义证书代理协议(planning) ## 安装教程 diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp new file mode 100644 index 0000000000000000000000000000000000000000..708502da57b6cf8374ffc7553d0d6d44d93f281c --- /dev/null +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp @@ -0,0 +1,180 @@ +#ifdef _MSC_BUILD +#include +#include +#pragma comment(lib,"Ws2_32.lib") +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") +#pragma comment(lib,"XEngine_Client/XClient_Socket.lib") +#pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol") +#pragma comment(lib,"../../XEngine_Source//Debug/jsoncpp") +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../../XEngine_Source/XEngine_UserProtocol.h" + +//需要优先配置XEngine +//WINDOWS支持VS2022 x86 debug 编译调试 +//linux使用下面的命令编译 +//g++ -std=c++17 -Wall -g APPClient_ForwardExample.cpp -o APPClient_ForwardExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol +int main(int argc, char** argv) +{ +#ifdef _MSC_BUILD + WSADATA st_WSAData; + WSAStartup(MAKEWORD(2, 2), &st_WSAData); +#endif + SOCKET m_Socket; + LPCTSTR lpszServiceAddr = _T("127.0.0.1"); + if (!XClient_TCPSelect_Create(&m_Socket, lpszServiceAddr, 5402)) + { + printf("连接失败!错误:%lX\n", XClient_GetLastError()); + return 0; + } + printf("连接成功!\n"); + + int nMsgLen = 0; + XENGINE_PROTOCOLHDR st_ProtocolHdr; + memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR)); + //登录 + st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; + st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; + st_ProtocolHdr.byIsReply = true; + st_ProtocolHdr.byVersion = 0; + st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH; + st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREQ; + + if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCTSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR))) + { + printf("发送失败!\n"); + return 0; + } + + nMsgLen = 0; + TCHAR* ptszMsgBuffer = NULL; + memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR)); + if (!XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + printf("接受数据失败!\n"); + return 0; + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + //列举 + st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; + st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; + st_ProtocolHdr.byIsReply = true; + st_ProtocolHdr.byVersion = 0; + st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER_FORWARD; + st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREQ; + if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCTSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR))) + { + printf("发送失败!\n"); + return 0; + } + nMsgLen = 0; + if (!XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + printf("接受数据失败!\n"); + return 0; + } + printf("%s\n", ptszMsgBuffer); + + Json::Value st_JsonAddr; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_JsonBuilder; + //开始解析配置文件 + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); + if (!pSt_JsonReader->parse(ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonAddr, &st_JsonError)) + { + return FALSE; + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + if (st_JsonAddr["Count"].asInt() > 0) + { + //请求绑定 + Json::Value st_JsonRoot; + Json::Value st_JsonArray = st_JsonAddr["Array"]; + st_JsonRoot["tszDstAddr"] = st_JsonArray[0].asCString(); + + st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; + st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; + st_ProtocolHdr.byIsReply = true; + st_ProtocolHdr.byVersion = 0; + st_ProtocolHdr.unPacketSize = st_JsonRoot.toStyledString().length(); + st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER_FORWARD; + st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ; + if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCTSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR))) + { + printf("发送失败!\n"); + return 0; + } + if (!XClient_TCPSelect_SendMsg(m_Socket, st_JsonRoot.toStyledString().c_str(), st_ProtocolHdr.unPacketSize)) + { + printf("发送失败!\n"); + return 0; + } + nMsgLen = 2048; + if (!XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + printf("接受数据失败!\n"); + return 0; + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + //成功后发送数据 + for (int i = 0; i < 10; i++) + { + XClient_TCPSelect_SendMsg(m_Socket, "hello", 5); + std::this_thread::sleep_for(std::chrono::seconds(1)); + printf("send 5 str\n"); + } + } + else + { + BOOL bGet = FALSE; + while (1) + { + if (bGet) + { + //收到转发请求 + nMsgLen = 2048; + TCHAR tszMsgBuffer[2048]; + + memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer)); + + if (XClient_TCPSelect_RecvMsg(m_Socket, tszMsgBuffer, &nMsgLen, FALSE)) + { + printf("%s\n", tszMsgBuffer); + } + } + else + { + if (XClient_TCPSelect_RecvPkt(m_Socket, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + //收到转发请求 + if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ == st_ProtocolHdr.unOperatorCode) + { + bGet = TRUE; + printf("get forward\n"); + } + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + } + } + } + } + + std::this_thread::sleep_for(std::chrono::seconds(5000)); + XClient_TCPSelect_Close(m_Socket); +#ifdef _MSC_BUILD + WSACleanup(); +#endif + return 0; +} \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..821892afbb4bcc5d5e0efe21f00825879405ad1d --- /dev/null +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {340ebea1-a232-49ce-a9a5-fb66c114aa48} + APPClientForwardExample + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);../../XEngine_Source/XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj.filters b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..f6f512a98f0a75f68962ae1ecb8d1c6d03cad936 --- /dev/null +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {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 + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj.user b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp index c77b0a57f02377023b6af328e1925316aa307f02..9c521af53c4b8262cb24a644f09aa5f7c7a37a4f 100644 --- a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.cpp @@ -20,7 +20,7 @@ #include "../../XEngine_Source/XEngine_UserProtocol.h" //需要优先配置XEngine -//WINDOWS支持VS2019 x86 debug 编译调试 +//WINDOWS支持VS2022 x86 debug 编译调试 //linux使用下面的命令编译 //g++ -std=c++17 -Wall -g APPClient_SocksExample.cpp -o APPClient_SocksExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol int main(int argc, char** argv) diff --git a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj index 4d9b1083b3184914856c2b0a4a20877908005e89..5c0ebb1f4ba21dd1c3b61d453bf2aea86f09549d 100644 --- a/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj +++ b/XEngine_APPClient/APPClient_SocksExample/APPClient_SocksExample.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 MultiByte Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp index 9584d4b9fb22fb605ae5a2586bb101ed641b32bb..a11d0cbae15c5c6671c76159ab0557827d4eb214 100644 --- a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.cpp @@ -20,7 +20,7 @@ #include "../../XEngine_Source/XEngine_UserProtocol.h" //需要优先配置XEngine -//WINDOWS支持VS2019 x86 debug 编译调试 +//WINDOWS支持VS2022 x86 debug 编译调试 //linux使用下面的命令编译 //g++ -std=c++17 -Wall -g APPClient_TunnelExample.cpp -o APPClient_TunnelExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_Client -L /usr/local/lib/XEngine_Release/XEngine_RfcComponents -lXEngine_BaseLib -lXClient_Socket -lRfcComponents_ProxyProtocol int main(int argc, char** argv) diff --git a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj index 1cc92e0af5f61d463b53d7e4ec7235594a8daa45..fb1714429e231154ef870d770328090968a2c570 100644 --- a/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj +++ b/XEngine_APPClient/APPClient_TunnelExample/APPClient_TunnelExample.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 MultiByte Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode diff --git a/XEngine_APPClient/VSCopy.bat b/XEngine_APPClient/VSCopy.bat new file mode 100644 index 0000000000000000000000000000000000000000..2c11177d409701ebf8adabfd92a5c435c1cfdcae --- /dev/null +++ b/XEngine_APPClient/VSCopy.bat @@ -0,0 +1,4 @@ +copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_BaseLib.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_BaseLib\XEngine_Algorithm.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_Client\XClient_Socket.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" \ No newline at end of file diff --git a/XEngine_APPClient/XEngine_APPClient.sln b/XEngine_APPClient/XEngine_APPClient.sln index a2284381eaa9a3d20eea72f71b3c603b04531a2d..d00c05dce302d1cc5f9385cad2114aced17eff41 100644 --- a/XEngine_APPClient/XEngine_APPClient.sln +++ b/XEngine_APPClient/XEngine_APPClient.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31911.196 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_SocksExample", "APPClient_SocksExample\APPClient_SocksExample.vcxproj", "{420E0F5F-CEFD-4BDF-A61A-BC23B7803549}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_TunnelExample", "APPClient_TunnelExample\APPClient_TunnelExample.vcxproj", "{BFA995E0-82C3-47D6-B421-08937DEE7F18}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "APPClient_ForwardExample", "APPClient_ForwardExample\APPClient_ForwardExample.vcxproj", "{340EBEA1-A232-49CE-A9A5-FB66C114AA48}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +33,14 @@ Global {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x64.Build.0 = Release|x64 {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x86.ActiveCfg = Release|Win32 {BFA995E0-82C3-47D6-B421-08937DEE7F18}.Release|x86.Build.0 = Release|Win32 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Debug|x64.ActiveCfg = Debug|x64 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Debug|x64.Build.0 = Debug|x64 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Debug|x86.ActiveCfg = Debug|Win32 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Debug|x86.Build.0 = Debug|Win32 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Release|x64.ActiveCfg = Release|x64 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Release|x64.Build.0 = Release|x64 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Release|x86.ActiveCfg = Release|Win32 + {340EBEA1-A232-49CE-A9A5-FB66C114AA48}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 73eb262507cd78e430a18a6a9ee1b7d9cc1c7ede..b6f6834c9885f4c391b73279954a0c273d66a252 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 7063c3426e39862632e781ae0561089812364089..5f1fae7315fcccf2acd4073e86f9ed626ea47943 100644 Binary files a/XEngine_Docment/Docment_zh.docx and b/XEngine_Docment/Docment_zh.docx differ diff --git a/XEngine_Release/XEngine_Config/XEngine_Config.json b/XEngine_Release/XEngine_Config/XEngine_Config.json index 82e93497c65347779edde0571b7b314bc3db8b2d..97d2d4357ccb3e258fb14028140c87f910214f9c 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -1,31 +1,35 @@ { - "tszIPAddr":"192.168.1.12", - "bDeamon":0, - "nSocksPort":5400, - "nTunnelPort":5401, - "XMax":{ - "nMaxClient":10000, - "nMaxQueue":10000, - "nIOThread":1 - }, - "XTime":{ - "nTimeCheck":3, - "nSocksTimeOut":0, - "nTunnelTimeOut":0 - }, - "XLog":{ - "MaxSize":1024000, - "MaxCount":10, - "LogLeave":32, - "tszLogFile":"./XEngine_Log/XEngine_ServiceApp.log" - }, - "XAuth":{ - "bAuth":2, - "tszAuthFile":"./XEngine_Config/UserList.txt" - }, - "XVer":[ - "1.2.0.1001 Build20220413", - "1.1.0.1001 Build20211231", - "1.0.0.1001 Build20211211" - ] + "tszIPAddr": "192.168.1.12", + "bDeamon": 0, + "nSocksPort": 5400, + "nTunnelPort": 5401, + "nForwardPort": 5402, + "XMax": { + "nMaxClient": 10000, + "nMaxQueue": 10000, + "nIOThread": 1, + "nForwardThread": 1 + }, + "XTime": { + "nTimeCheck": 3, + "nSocksTimeOut": 0, + "nTunnelTimeOut": 0, + "nForwardTimeOut": 0 + }, + "XLog": { + "MaxSize": 1024000, + "MaxCount": 10, + "LogLeave": 32, + "tszLogFile": "./XEngine_Log/XEngine_ServiceApp.log" + }, + "XAuth": { + "bAuth": 2, + "tszAuthFile": "./XEngine_Config/UserList.txt" + }, + "XVer": [ + "1.3.0.1001 Build20220617", + "1.2.0.1001 Build20220413", + "1.1.0.1001 Build20211231", + "1.0.0.1001 Build20211211" + ] } \ No newline at end of file diff --git a/XEngine_Source/Makefile b/XEngine_Source/Makefile index b666bf30561850a707d0d49dc2f0a1538fc2f0a7..f828b1de0cda64e38a853e161782e01619fe093a 100644 --- a/XEngine_Source/Makefile +++ b/XEngine_Source/Makefile @@ -7,9 +7,11 @@ THIRDPART_MODULE_JSONCPP = ./XEngine_ThirdPart/jsoncpp MODULE_CONFIGURE_PATH = ./XEngine_ModuleConfigure MODULE_AUTHORIZE_PATH = ./XEngine_ModuleAuthorize +MODULE_PROTOCOL_PATH = ./XEngine_ModuleProtocol +MODULE_SESSION_PATH = ./XEngine_ModuleSession APP_SERVICE_PATH = ./XEngine_ServiceApp -XENGINE_MODULES = libjsoncpp.so libXEngine_ModuleConfigure.so libXEngine_ModuleAuthorize.so XEngine_ServiceApp.exe +XENGINE_MODULES = libjsoncpp.so libXEngine_ModuleConfigure.so libXEngine_ModuleAuthorize.so libXEngine_ModuleProtocol.so libXEngine_ModuleSession.so XEngine_ServiceApp.exe .PHONY:MakeAll MakeAll:$(XENGINE_MODULES) @@ -21,6 +23,10 @@ libXEngine_ModuleConfigure.so: make -C $(MODULE_CONFIGURE_PATH) $(FLAGS) libXEngine_ModuleAuthorize.so: make -C $(MODULE_AUTHORIZE_PATH) $(FLAGS) +libXEngine_ModuleProtocol.so: + make -C $(MODULE_PROTOCOL_PATH) $(FLAGS) +libXEngine_ModuleSession.so: + make -C $(MODULE_SESSION_PATH) $(FLAGS) XEngine_ServiceApp.exe: make -C $(APP_SERVICE_PATH) $(FLAGS) diff --git a/XEngine_Source/VSCopy-Debug.bat b/XEngine_Source/VSCopy-Debug.bat index 9187c7c2f22b3daecbe3bc9b1a1784d6e076b055..7fc034a94b4c0f9831b0bc39d0d5c2e076c9072d 100644 --- a/XEngine_Source/VSCopy-Debug.bat +++ b/XEngine_Source/VSCopy-Debug.bat @@ -9,6 +9,7 @@ copy /y "D:\XEngine\XEngine_SourceCode\Debug\NetHelp_APIHelp.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XClient_Socket.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_XLog.dll" "./" +copy /y "D:\XEngine\XEngine_SourceCode\Debug\HelpComponents_Packets.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\RfcComponents_ProxyProtocol.dll" "./" copy /y "D:\XEngine\XEngine_SourceCode\Debug\XEngine_ProcFile.dll" "./" diff --git a/XEngine_Source/VSCopy-x64.bat b/XEngine_Source/VSCopy-x64.bat index 8f3c7d76894c457b19897dd1fce4fd37348ab830..b3d43b51aab3bcb1fa337c46455eed5f67a2a225 100644 --- a/XEngine_Source/VSCopy-x64.bat +++ b/XEngine_Source/VSCopy-x64.bat @@ -9,6 +9,7 @@ copy /y "%XEngine_Lib64%\x64\XEngine_NetHelp\NetHelp_APIHelp.dll" "./" copy /y "%XEngine_Lib64%\x64\XEngine_Client\XClient_Socket.dll" "./" copy /y "%XEngine_Lib64%\x64\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" +copy /y "%XEngine_Lib64%\x64\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" copy /y "%XEngine_Lib64%\x64\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" copy /y "%XEngine_Lib64%\x64\XEngine_SystemSdk\XEngine_ProcFile.dll" "./" diff --git a/XEngine_Source/VSCopy-x86.bat b/XEngine_Source/VSCopy-x86.bat index 94062095f66c801587c87f89c4c05e96f7aa9b6f..c273055f19998d9c4f0459717b69067596c8465b 100644 --- a/XEngine_Source/VSCopy-x86.bat +++ b/XEngine_Source/VSCopy-x86.bat @@ -9,6 +9,7 @@ copy /y "%XEngine_Lib32%\XEngine_NetHelp\NetHelp_APIHelp.dll" "./" copy /y "%XEngine_Lib32%\XEngine_Client\XClient_Socket.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_XLog.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_HelpComponents\HelpComponents_Packets.dll" "./" copy /y "%XEngine_Lib32%\XEngine_RfcComponents\RfcComponents_ProxyProtocol.dll" "./" copy /y "%XEngine_Lib32%\XEngine_SystemSdk\XEngine_ProcFile.dll" "./" @@ -20,4 +21,5 @@ copy /y "%XEngine_Lib32%\XEngine_SystemSdk\XEngine_SystemApi.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\libcrypto-3.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\libssl-3.dll" "./" copy /y "%XEngine_Lib32%\XEngine_LibEx\libcurl.dll" "./" +copy /y "%XEngine_Lib32%\XEngine_LibEx\nghttp2.dll" "./" copy /y "%XEngine_Lib32%\XEngine_HelpComponents\zlib1.dll" "./" \ No newline at end of file diff --git a/XEngine_Source/XEngine.sln b/XEngine_Source/XEngine.sln index 6fc27e952629e6ae446f322b0fc75b53eaf82aaf..02c92cb45a9b5e8b39d7a87da7f8829697aa9702 100644 --- a/XEngine_Source/XEngine.sln +++ b/XEngine_Source/XEngine.sln @@ -18,6 +18,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XEngine_ThirdPart", "XEngin EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jsoncpp", "XEngine_ThirdPart\jsoncpp\jsoncpp.vcxproj", "{F1736B3F-03A2-4FC7-B045-A12BA8D724FB}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ModuleSession", "XEngine_ModuleSession\XEngine_ModuleSession.vcxproj", "{237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XEngine_ModuleProtocol", "XEngine_ModuleProtocol\XEngine_ModuleProtocol.vcxproj", "{9512A610-7197-4522-9AEF-1486619C99FE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -58,6 +62,22 @@ Global {F1736B3F-03A2-4FC7-B045-A12BA8D724FB}.Release|x64.Build.0 = Release|x64 {F1736B3F-03A2-4FC7-B045-A12BA8D724FB}.Release|x86.ActiveCfg = Release|Win32 {F1736B3F-03A2-4FC7-B045-A12BA8D724FB}.Release|x86.Build.0 = Release|Win32 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Debug|x64.ActiveCfg = Debug|x64 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Debug|x64.Build.0 = Debug|x64 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Debug|x86.ActiveCfg = Debug|Win32 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Debug|x86.Build.0 = Debug|Win32 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Release|x64.ActiveCfg = Release|x64 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Release|x64.Build.0 = Release|x64 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Release|x86.ActiveCfg = Release|Win32 + {237AF017-9AD2-44D8-A6C4-ECDEF7674FF2}.Release|x86.Build.0 = Release|Win32 + {9512A610-7197-4522-9AEF-1486619C99FE}.Debug|x64.ActiveCfg = Debug|x64 + {9512A610-7197-4522-9AEF-1486619C99FE}.Debug|x64.Build.0 = Debug|x64 + {9512A610-7197-4522-9AEF-1486619C99FE}.Debug|x86.ActiveCfg = Debug|Win32 + {9512A610-7197-4522-9AEF-1486619C99FE}.Debug|x86.Build.0 = Debug|Win32 + {9512A610-7197-4522-9AEF-1486619C99FE}.Release|x64.ActiveCfg = Release|x64 + {9512A610-7197-4522-9AEF-1486619C99FE}.Release|x64.Build.0 = Release|x64 + {9512A610-7197-4522-9AEF-1486619C99FE}.Release|x86.ActiveCfg = Release|Win32 + {9512A610-7197-4522-9AEF-1486619C99FE}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h index ae4012756fe600f4bfc012d8185d24aaf3799fbe..1b1353dc52d967dd50cb57a2e3bf3058e3655f5e 100644 --- a/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h +++ b/XEngine_Source/XEngine_ModuleAuthorize/ModuleAuth_Error.h @@ -1,6 +1,6 @@ #pragma once /******************************************************************** -// Created: 2021/12/29 10:29:54 +// Created: 2022/06/08 10:04:25 // File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuth_Error.h // File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize // File Base: ModuleAuth_Error @@ -10,7 +10,7 @@ // Purpose: 导出错误 // History: *********************************************************************/ -#define ERROR_MODULE_AUTHORIZE_USER_PARAMENT 0xA0001 //参数错误 -#define ERROR_MODULE_AUTHORIZE_USER_OPENFILE 0xA0002 //打开文件失败 -#define ERROR_MODULE_AUTHORIZE_USER_NOTFOUND 0xA0003 //没有找到 -#define ERROR_MODULE_AUTHORIZE_USER_PASSWORD 0xA0004 //密码错误 \ No newline at end of file +#define ERROR_MODULE_AUTHORIZE_USER_PARAMENT 0xB0001 //参数错误 +#define ERROR_MODULE_AUTHORIZE_USER_OPENFILE 0xB0002 //打开文件失败 +#define ERROR_MODULE_AUTHORIZE_USER_NOTFOUND 0xB0003 //没有找到 +#define ERROR_MODULE_AUTHORIZE_USER_PASSWORD 0xB0004 //密码错误 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h index 50750c4da846a2241cd5bebf11edb3e3c6c75d1e..0707ded36928051bc86a4e9fddbc550ba294f9a1 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfig_Define.h @@ -19,17 +19,20 @@ typedef struct tag_XEngine_ServiceConfig BOOL bDeamon; //是否以守护进程启动,LINUX有效 int nSocksPort; //Socks端口,<=0不启用 int nTunnelPort; //Tunnel服务端口 + int nForwardPort; //数据转发端口 struct { int nMaxClient; //最大客户端个数 int nMaxQueue; //最大队列个数 int nIOThread; //网络IO线程数 + int nForwardThread; //转发服务 }st_XMax; struct { int nTimeCheck; //检测次数 int nSocksTimeOut; //TCP超时时间 int nTunnelTimeOut; //HTTP超时时间 + int nForwardTimeOut; //转发超时时间 }st_XTime; //次数*时间=超时 struct { diff --git a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp index d3c10db65b723b6783ba8849fd35076671badb97..676a8bca3603d7b9c98256c64e246aa6db9c705c 100644 --- a/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp +++ b/XEngine_Source/XEngine_ModuleConfigure/ModuleConfigure_Json/ModuleConfigure_Json.cpp @@ -85,8 +85,9 @@ BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XE pSt_ServerConfig->bDeamon = st_JsonRoot["bDeamon"].asInt(); pSt_ServerConfig->nSocksPort = st_JsonRoot["nSocksPort"].asInt(); pSt_ServerConfig->nTunnelPort = st_JsonRoot["nTunnelPort"].asInt(); + pSt_ServerConfig->nForwardPort = st_JsonRoot["nForwardPort"].asInt(); - if (st_JsonRoot["XMax"].empty() || (3 != st_JsonRoot["XMax"].size())) + if (st_JsonRoot["XMax"].empty() || (4 != st_JsonRoot["XMax"].size())) { Config_IsErrorOccur = TRUE; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XMAX; @@ -96,8 +97,9 @@ BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XE pSt_ServerConfig->st_XMax.nMaxClient = st_JsonXMax["nMaxClient"].asInt(); pSt_ServerConfig->st_XMax.nMaxQueue = st_JsonXMax["nMaxQueue"].asInt(); pSt_ServerConfig->st_XMax.nIOThread = st_JsonXMax["nIOThread"].asInt(); + pSt_ServerConfig->st_XMax.nForwardThread = st_JsonXMax["nForwardThread"].asInt(); - if (st_JsonRoot["XTime"].empty() || (3 != st_JsonRoot["XTime"].size())) + if (st_JsonRoot["XTime"].empty() || (4 != st_JsonRoot["XTime"].size())) { Config_IsErrorOccur = TRUE; Config_dwErrorCode = ERROR_MODULE_CONFIGURE_JSON_XTIME; @@ -107,6 +109,7 @@ BOOL CModuleConfigure_Json::ModuleConfigure_Json_File(LPCTSTR lpszConfigFile, XE pSt_ServerConfig->st_XTime.nTimeCheck = st_JsonXTime["nTimeCheck"].asInt(); pSt_ServerConfig->st_XTime.nSocksTimeOut = st_JsonXTime["nSocksTimeOut"].asInt(); pSt_ServerConfig->st_XTime.nTunnelTimeOut = st_JsonXTime["nTunnelTimeOut"].asInt(); + pSt_ServerConfig->st_XTime.nForwardTimeOut = st_JsonXTime["nForwardTimeOut"].asInt(); if (st_JsonRoot["XLog"].empty() || (4 != st_JsonRoot["XLog"].size())) { diff --git a/XEngine_Source/XEngine_ModuleProtocol/Makefile b/XEngine_Source/XEngine_ModuleProtocol/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f584fdc1eb233e5c618092e1c15555a49f2fa9c0 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/Makefile @@ -0,0 +1,47 @@ +CC = g++ -Wall -std=c++17 -fPIC +RELEASE = 0 +UNICODE = 0 +INCLUDE = -I ./ -I ../XEngine_ThirdPart/jsoncpp +LOADBIN = -L ../XEngine_ThirdPart/jsoncpp +LIB = -ljsoncpp +LIBEX = -ldl -lpthread +LOADSO = -Wl,-rpath=./,--disable-new-dtags +LIBINCLUDE = ModuleProtocol_Packet.o ModuleProtocol_Parse.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c -O2 +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + + +all:$(LIBINCLUDE) + $(CC) $(DEBUG) $(LIBINCLUDE) -o libXEngine_ModuleProtocol.so -shared -fPIC $(LOADBIN) $(LIB) $(LIBEX) $(LOADSO) + +ModuleProtocol_Packet.o:./ModuleProtocol_Packet/ModuleProtocol_Packet.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./ModuleProtocol_Packet/ModuleProtocol_Packet.cpp +ModuleProtocol_Parse.o:./ModuleProtocol_Parse/ModuleProtocol_Parse.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./ModuleProtocol_Parse/ModuleProtocol_Parse.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libXEngine_ModuleProtocol.so + cp ./libXEngine_ModuleProtocol.so ../../XEngine_Release/libXEngine_ModuleProtocol.so + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.so diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h new file mode 100644 index 0000000000000000000000000000000000000000..fcab271454d99097aa6d355035a2946b56583184 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h @@ -0,0 +1,85 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 11:28:19 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Define.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol +// File Base: ModuleProtocol_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出定义 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleProtocol_GetLastError(int* pInt_SysError = NULL); +/************************************************************************/ +/* 封包导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:ModuleProtocol_Packet_ForwardList +函数功能:转发协议封装请求 + 参数.一:ptszMsgBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出封装好的包 + 参数.二:pInt_Len + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出封装大小 + 参数.三:pSt_ProtocolHdr + In/Out:In + 类型:协议头 + 可空:N + 意思:输入请求的头 + 参数.四:ppptszListAddr + In/Out:In + 类型:三级指针 + 可空:N + 意思:输入要处理的列表 + 参数.五:nCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleProtocol_Packet_ForwardList(TCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, TCHAR*** ppptszListAddr, int nCount); +/************************************************************************/ +/* 解析导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:ModuleProtocol_Packet_ForwardList +函数功能:转发协议封装请求 + 参数.一:lpszMsgBuffer + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要解析的缓冲区 + 参数.二:nMsgLen + In/Out:In + 类型:整数型 + 可空:N + 意思:输入解析的大小 + 参数.三:ptszSrcAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出解析的原始地址 + 参数.四:ptszDstAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出解析的目的地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleProtocol_Parse_ForwardBind(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR * ptszSrcAddr, TCHAR * ptszDstAddr); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Error.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Error.h new file mode 100644 index 0000000000000000000000000000000000000000..df672c5ad6d722e992322271f00674b6ff7757e7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Error.h @@ -0,0 +1,21 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 11:21:20 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Error.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol +// File Base: ModuleProtocol_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出错误 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出的打包错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_MODULE_PROTOCOL_PACKET_PARAMENT 0xD0001 //参数错误 +////////////////////////////////////////////////////////////////////////// +// 导出的解析错误 +////////////////////////////////////////////////////////////////////////// +#define ERROR_MODULE_PROTOCOL_PARSE_PARAMENT 0xD1001 //参数错误 +#define ERROR_MODULE_PROTOCOL_PARSE_JSON 0xD1002 //解析JSON错误 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc163c62a72532ca5b458ee9aa891102cd02301b --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp @@ -0,0 +1,84 @@ +#include "pch.h" +#include "ModuleProtocol_Packet.h" +/******************************************************************** +// Created: 2022/06/08 13:55:09 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Packet\ModuleProtocol_Packet.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Packet +// File Base: ModuleProtocol_Packet +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 封装协议 +// History: +*********************************************************************/ +CModuleProtocol_Packet::CModuleProtocol_Packet() +{ + +} +CModuleProtocol_Packet::~CModuleProtocol_Packet() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公用函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:ModuleProtocol_Packet_ForwardList +函数功能:转发协议封装请求 + 参数.一:ptszMsgBuffer + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出封装好的包 + 参数.二:pInt_Len + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出封装大小 + 参数.三:pSt_ProtocolHdr + In/Out:In + 类型:协议头 + 可空:N + 意思:输入请求的头 + 参数.四:ppptszListAddr + In/Out:In + 类型:三级指针 + 可空:N + 意思:输入要处理的列表 + 参数.五:nCount + In/Out:In + 类型:整数型 + 可空:N + 意思:输入列表个数 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(TCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, TCHAR*** ppptszListAddr, int nCount) +{ + Protocol_IsErrorOccur = FALSE; + + if ((NULL == ptszMsgBuffer) || (NULL == pInt_Len)) + { + Protocol_IsErrorOccur = TRUE; + Protocol_dwErrorCode = ERROR_MODULE_PROTOCOL_PACKET_PARAMENT; + return FALSE; + } + Json::Value st_JsonRoot; + Json::Value st_JsonArray; + + for (int i = 0; i < nCount; i++) + { + st_JsonArray[i] = (*ppptszListAddr)[i]; + } + st_JsonRoot["Count"] = nCount; + st_JsonRoot["Array"] = st_JsonArray; + + pSt_ProtocolHdr->unPacketSize = st_JsonRoot.toStyledString().length(); + + *pInt_Len = sizeof(XENGINE_PROTOCOLHDR) + pSt_ProtocolHdr->unPacketSize; + memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR)); + memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), pSt_ProtocolHdr->unPacketSize); + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h new file mode 100644 index 0000000000000000000000000000000000000000..950480b6812f4140be5a6ce81b0d09c97d00b624 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h @@ -0,0 +1,22 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 13:54:47 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Packet\ModuleProtocol_Packet.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Packet +// File Base: ModuleProtocol_Packet +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 封装协议 +// History: +*********************************************************************/ + +class CModuleProtocol_Packet +{ +public: + CModuleProtocol_Packet(); + ~CModuleProtocol_Packet(); +public: + BOOL ModuleProtocol_Packet_ForwardList(TCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, TCHAR*** ppptszListAddr, int nCount); +private: +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14d4ed444628faf02b8e93cfe7da0bd164485826 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.cpp @@ -0,0 +1,78 @@ +#include "pch.h" +#include "ModuleProtocol_Parse.h" +/******************************************************************** +// Created: 2022/06/08 13:56:46 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Parse\ModuleProtocol_Parse.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Parse +// File Base: ModuleProtocol_Parse +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 解析协议类 +// History: +*********************************************************************/ +CModuleProtocol_Parse::CModuleProtocol_Parse() +{ + +} +CModuleProtocol_Parse::~CModuleProtocol_Parse() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公用函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:ModuleProtocol_Packet_ForwardList +函数功能:转发协议封装请求 + 参数.一:lpszMsgBuffer + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要解析的缓冲区 + 参数.二:nMsgLen + In/Out:In + 类型:整数型 + 可空:N + 意思:输入解析的大小 + 参数.三:ptszSrcAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出解析的原始地址 + 参数.四:ptszDstAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出解析的目的地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleProtocol_Parse::ModuleProtocol_Parse_ForwardBind(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR* ptszSrcAddr, TCHAR* ptszDstAddr) +{ + Protocol_IsErrorOccur = FALSE; + + if (NULL == lpszMsgBuffer) + { + Protocol_IsErrorOccur = TRUE; + Protocol_dwErrorCode = ERROR_MODULE_PROTOCOL_PARSE_PARAMENT; + return FALSE; + } + Json::Value st_JsonRoot; + JSONCPP_STRING st_JsonError; + Json::CharReaderBuilder st_JsonBuilder; + //开始解析配置文件 + std::unique_ptr const pSt_JsonReader(st_JsonBuilder.newCharReader()); + if (!pSt_JsonReader->parse(lpszMsgBuffer, lpszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError)) + { + Protocol_IsErrorOccur = TRUE; + Protocol_dwErrorCode = ERROR_MODULE_PROTOCOL_PARSE_JSON; + return FALSE; + } + //_tcscpy(ptszSrcAddr, st_JsonRoot["tszSrcAddr"].asCString()); 暂时不支持 + _tcscpy(ptszDstAddr, st_JsonRoot["tszDstAddr"].asCString()); + + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h new file mode 100644 index 0000000000000000000000000000000000000000..dd3b62255451b6df5f32063125f70c821d53ec9c --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Parse/ModuleProtocol_Parse.h @@ -0,0 +1,22 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 13:56:05 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Parse\ModuleProtocol_Parse.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\ModuleProtocol_Parse +// File Base: ModuleProtocol_Parse +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 解析协议类 +// History: +*********************************************************************/ + +class CModuleProtocol_Parse +{ +public: + CModuleProtocol_Parse(); + ~CModuleProtocol_Parse(); +public: + BOOL ModuleProtocol_Parse_ForwardBind(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR* ptszSrcAddr, TCHAR* ptszDstAddr); +private: +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def new file mode 100644 index 0000000000000000000000000000000000000000..5d5832cdda29b48119d4a928614a2ce440a21006 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.def @@ -0,0 +1,8 @@ +LIBRARY + +EXPORTS + ModuleProtocol_GetLastError + + ModuleProtocol_Packet_ForwardList + + ModuleProtocol_Parse_ForwardBind \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..be8065e28030b84fa4b8922d4d4b6df5b0397c08 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj @@ -0,0 +1,184 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {9512a610-7197-4522-9aef-1486619c99fe} + XEngineModuleProtocol + 10.0 + + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + + + $(XEngine_Include);../XEngine_ThirdPart/jsoncpp;$(IncludePath) + + + + Level3 + true + WIN32;_DEBUG;XENGINEMODULEPROTOCOL_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleProtocol.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;XENGINEMODULEPROTOCOL_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleProtocol.def + + + + + Level3 + true + _DEBUG;XENGINEMODULEPROTOCOL_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleProtocol.def + + + + + Level3 + true + true + true + NDEBUG;XENGINEMODULEPROTOCOL_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleProtocol.def + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj.filters b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..ae6258745b631a78c3298617f68ee8ba41f27763 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.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 + + + {c315e498-4a4b-4626-8519-6c7cb27959f4} + + + {e7666a8d-be4e-4e59-97fb-801399ede644} + + + {07c75a04-5174-484f-b2cb-2519684c7e97} + + + {b901b18c-b203-4bf3-bc69-3ad8bba7a692} + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件\ModuleProtocol_Packet + + + 头文件\ModuleProtocol_Parse + + + + + 源文件 + + + 源文件 + + + 源文件\ModuleProtocol_Packet + + + 源文件\ModuleProtocol_Parse + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj.user b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/XEngine_ModuleProtocol.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/dllmain.cpp b/XEngine_Source/XEngine_ModuleProtocol/dllmain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daed8c8f7ac50ca1466016a0529648d18125a7e7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/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/XEngine_ModuleProtocol/framework.h b/XEngine_Source/XEngine_ModuleProtocol/framework.h new file mode 100644 index 0000000000000000000000000000000000000000..80cbbc9b06a9b0141f92ee19eceaed71328caff4 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0991c41981a4b94529a5d70f742252a8c9e70b1d --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp @@ -0,0 +1,44 @@ +#include "pch.h" +#include "ModuleProtocol_Packet/ModuleProtocol_Packet.h" +#include "ModuleProtocol_Parse/ModuleProtocol_Parse.h" +/******************************************************************** +// Created: 2022/06/08 13:15:13 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\pch.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +BOOL Protocol_IsErrorOccur = FALSE; +DWORD Protocol_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CModuleProtocol_Packet m_ProtocolPacket; +CModuleProtocol_Parse m_ProtocolParse; +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleProtocol_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return Protocol_dwErrorCode; +} +/************************************************************************/ +/* 封包导出函数 */ +/************************************************************************/ +extern "C" BOOL ModuleProtocol_Packet_ForwardList(TCHAR * ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, TCHAR * **ppptszListAddr, int nCount) +{ + return m_ProtocolPacket.ModuleProtocol_Packet_ForwardList(ptszMsgBuffer, pInt_Len, pSt_ProtocolHdr, ppptszListAddr, nCount); +} +/************************************************************************/ +/* 解析导出函数 */ +/************************************************************************/ +extern "C" BOOL ModuleProtocol_Parse_ForwardBind(LPCTSTR lpszMsgBuffer, int nMsgLen, TCHAR * ptszSrcAddr, TCHAR * ptszDstAddr) +{ + return m_ProtocolParse.ModuleProtocol_Parse_ForwardBind(lpszMsgBuffer, nMsgLen, ptszSrcAddr, ptszDstAddr); +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/pch.h b/XEngine_Source/XEngine_ModuleProtocol/pch.h new file mode 100644 index 0000000000000000000000000000000000000000..bd50bec8d19d4015088e4aaf22d19fd4114880e4 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleProtocol/pch.h @@ -0,0 +1,55 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +// 添加要在此处预编译的标头 +#ifdef _MSC_BUILD +#include "framework.h" +#include +#endif +#endif //PCH_H +#include +#include +#include +#include +using namespace std; +#include +#include +#include +#include "../XEngine_UserProtocol.h" +#include "ModuleProtocol_Define.h" +#include "ModuleProtocol_Error.h" +/******************************************************************** +// Created: 2022/06/08 11:22:29 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol\pch.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleProtocol +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头文件 +// History: +*********************************************************************/ +extern BOOL Protocol_IsErrorOccur; +extern DWORD Protocol_dwErrorCode; + +#ifdef _MSC_BUILD +#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 diff --git a/XEngine_Source/XEngine_ModuleSession/Makefile b/XEngine_Source/XEngine_ModuleSession/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9b91388bbe23fa9f3215492296bd5ba35d990ec0 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/Makefile @@ -0,0 +1,45 @@ +CC = g++ -Wall -std=c++17 -fPIC +RELEASE = 0 +UNICODE = 0 +INCLUDE = -I ./ +LOADBIN = +LIB = +LIBEX = -ldl -lpthread +LOADSO = -Wl,-rpath= +LIBINCLUDE = ModuleSession_Forward.o pch.o + +ifeq ($(RELEASE),1) +FLAGS = -c -O2 +DEBUG = +else +FLAGS = -c -lc_p +DEBUG = -g -pg +endif + +ifeq ($(UNICODE),1) +UNICODE = -D _UNICODE +else +UNICODE = +endif + + +all:$(LIBINCLUDE) + $(CC) $(DEBUG) $(LIBINCLUDE) -o libXEngine_ModuleSession.so -shared -fPIC $(LOADBIN) $(LIB) $(LIBEX) $(LOADSO) + +ModuleSession_Forward.o:./ModuleSession_Forward/ModuleSession_Forward.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./ModuleSession_Forward/ModuleSession_Forward.cpp + +pch.o:./pch.cpp + $(CC) $(DEBUG) $(FLAGS) $(UNICODE) $(INCLUDE) ./pch.cpp + + +InstallAll:InstallSo +InstallSo:./libXEngine_ModuleSession.so + cp ./libXEngine_ModuleSession.so ../../XEngine_Release/libXEngine_ModuleSession.so + + +CleanAll:CleanObj CleanMk +CleanObj: + rm *.o +CleanMk: + rm *.so diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h new file mode 100644 index 0000000000000000000000000000000000000000..bfc5c179430c585651b69a15beb53f66853df1b4 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h @@ -0,0 +1,114 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 10:10:08 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Define.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession +// File Base: ModuleSession_Define +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出定义 +// History: +*********************************************************************/ +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleSession_GetLastError(int* pInt_SysError = NULL); +/************************************************************************/ +/* 转发导出函数 */ +/************************************************************************/ +/******************************************************************** +函数名称:ModuleSession_Forward_Insert +函数功能:插入一条记录到会话中 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleSession_Forward_Insert(LPCTSTR lpszAddr); +/******************************************************************** +函数名称:ModuleSession_Forward_List +函数功能:获取列表 + 参数.一:ppptszListAddr + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出地址列表 + 参数.二:pInt_Count + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 + 参数.三:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入忽略地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleSession_Forward_List(TCHAR*** ppptszListAddr, int* pInt_Count, LPCTSTR lpszAddr = NULL); +/******************************************************************** +函数名称:ModuleSession_Forward_Bind +函数功能:绑定转发需求 + 参数.一:lpszSrcAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入绑定的原始地址 + 参数.二:lpszDstAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输出绑定的目标地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleSession_Forward_Bind(LPCTSTR lpszSrcAddr, LPCTSTR lpszDstAddr); +/******************************************************************** +函数名称:ModuleSession_Forward_Delete +函数功能:删除用户 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要删除的客户端 + 参数.二:ptszDstAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出解绑的地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleSession_Forward_Delete(LPCTSTR lpszAddr, TCHAR * ptszDstAddr); +/******************************************************************** +函数名称:ModuleSession_Forward_Get +函数功能:获取转发用户给 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要操作的客户端 + 参数.二:ptszDstAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出对端地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" BOOL ModuleSession_Forward_Get(LPCTSTR lpszAddr, TCHAR* ptszDstAddr); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h new file mode 100644 index 0000000000000000000000000000000000000000..73ac198d6855693cf6c12b7430f1e42cd537ba5d --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Error.h @@ -0,0 +1,17 @@ +#pragma once +/******************************************************************** +// Created: 2021/12/29 10:29:54 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize\ModuleAuth_Error.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleAuthorize +// File Base: ModuleAuth_Error +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出错误 +// History: +*********************************************************************/ +#define ERROR_MODULE_SESSION_FORWARD_PARAMENT 0xC0001 //参数错误 +#define ERROR_MODULE_SESSION_FORWARD_NOTFOUND 0xC0002 //没有找到 +#define ERROR_MODULE_SESSION_FORWARD_BIND 0xC0003 //已经绑定 +#define ERROR_MODULE_SESSION_FORWARD_NOTFORWARD 0xC0004 //没有转发 +#define ERROR_MODULE_SESSION_FORWARD_EXIST 0xC0005 //已经存在 \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c357932eee040a529665b2fb59ad959514148e1 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp @@ -0,0 +1,284 @@ +#include "pch.h" +#include "ModuleSession_Forward.h" +/******************************************************************** +// Created: 2022/06/08 09:58:49 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Forward\ModuleSession_Forward.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Forward +// File Base: ModuleSession_Forward +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 会话转发协议 +// History: +*********************************************************************/ +CModuleSession_Forward::CModuleSession_Forward() +{ + +} +CModuleSession_Forward::~CModuleSession_Forward() +{ + +} +////////////////////////////////////////////////////////////////////////// +// 公用函数 +////////////////////////////////////////////////////////////////////////// +/******************************************************************** +函数名称:ModuleSession_Forward_Insert +函数功能:插入一条记录到会话中 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要插入的客户端 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleSession_Forward::ModuleSession_Forward_Insert(LPCTSTR lpszAddr) +{ + Session_IsErrorOccur = FALSE; + + if (NULL == lpszAddr) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; + return FALSE; + } + SESSION_FORWARD st_Forward; + memset(&st_Forward, '\0', sizeof(SESSION_FORWARD)); + + _tcscpy(st_Forward.tszSrcAddr, lpszAddr); + + st_Locker.lock(); + unordered_map::const_iterator stl_MapIterator = stl_MapSession.find(lpszAddr); + if (stl_MapIterator != stl_MapSession.end()) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_EXIST; + st_Locker.unlock(); + return FALSE; + } + stl_MapSession.insert(make_pair(lpszAddr, st_Forward)); + st_Locker.unlock(); + return TRUE; +} +/******************************************************************** +函数名称:ModuleSession_Forward_List +函数功能:获取列表 + 参数.一:ppptszListAddr + In/Out:Out + 类型:三级指针 + 可空:N + 意思:输出地址列表 + 参数.二:pInt_Count + In/Out:Out + 类型:整数型指针 + 可空:N + 意思:输出列表个数 + 参数.三:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:Y + 意思:输入忽略地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleSession_Forward::ModuleSession_Forward_List(TCHAR*** ppptszListAddr, int* pInt_Count, LPCTSTR lpszAddr) +{ + Session_IsErrorOccur = FALSE; + + if (NULL == pInt_Count) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; + return FALSE; + } + st_Locker.lock_shared(); + + if (NULL == lpszAddr) + { + *pInt_Count = stl_MapSession.size(); + } + else + { + *pInt_Count = stl_MapSession.size() - 1; //减去自己 + } + BaseLib_OperatorMemory_Malloc((XPPPMEM)ppptszListAddr, *pInt_Count, 128); + //遍历 + auto stl_MapIterator = stl_MapSession.begin(); + for (int i = 0; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++, i++) + { + if (NULL != lpszAddr) + { + if (0 == _tcsncmp(lpszAddr, stl_MapIterator->first.c_str(), _tcslen(lpszAddr))) + { + continue; + } + } + _tcscpy((*ppptszListAddr)[i], stl_MapIterator->first.c_str()); + } + st_Locker.unlock_shared(); + return TRUE; +} +/******************************************************************** +函数名称:ModuleSession_Forward_Bind +函数功能:绑定转发需求 + 参数.一:lpszSrcAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入绑定的原始地址 + 参数.二:lpszDstAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输出绑定的目标地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleSession_Forward::ModuleSession_Forward_Bind(LPCTSTR lpszSrcAddr, LPCTSTR lpszDstAddr) +{ + Session_IsErrorOccur = FALSE; + + if ((NULL == lpszSrcAddr) || (NULL == lpszDstAddr)) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; + return FALSE; + } + st_Locker.lock_shared(); + //查找 + auto stl_MapSrcIterator = stl_MapSession.find(lpszSrcAddr); + auto stl_MapDstIterator = stl_MapSession.find(lpszDstAddr); + if (stl_MapSrcIterator == stl_MapSession.end() || stl_MapDstIterator == stl_MapSession.end()) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_NOTFOUND; + st_Locker.unlock_shared(); + return FALSE; + } + //如果设置过,不允许在设置 + if (stl_MapSrcIterator->second.bForward || stl_MapDstIterator->second.bForward) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_BIND; + st_Locker.unlock_shared(); + return FALSE; + } + //需要设置两方的转发内容 + stl_MapSrcIterator->second.bForward = TRUE; + _tcscpy(stl_MapSrcIterator->second.tszDstAddr, lpszDstAddr); + + stl_MapDstIterator->second.bForward = TRUE; + _tcscpy(stl_MapDstIterator->second.tszDstAddr, lpszSrcAddr); + st_Locker.unlock_shared(); + return TRUE; +} +/******************************************************************** +函数名称:ModuleSession_Forward_Delete +函数功能:删除用户 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要删除的客户端 + 参数.二:ptszDstAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出解绑的地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleSession_Forward::ModuleSession_Forward_Delete(LPCTSTR lpszAddr, TCHAR* ptszDstAddr) +{ + Session_IsErrorOccur = FALSE; + + if (NULL == lpszAddr) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; + return FALSE; + } + st_Locker.lock(); + //查找 + auto stl_MapSrcIterator = stl_MapSession.find(lpszAddr); + if (stl_MapSrcIterator == stl_MapSession.end()) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_NOTFOUND; + st_Locker.unlock(); + return FALSE; + } + //如果有转发,需要清理对方的转发设置 + if (stl_MapSrcIterator->second.bForward) + { + _tcscpy(ptszDstAddr, stl_MapSrcIterator->second.tszDstAddr); + auto stl_MapDstIterator = stl_MapSession.find(stl_MapSrcIterator->second.tszSrcAddr); + if (stl_MapDstIterator == stl_MapSession.end()) + { + stl_MapDstIterator->second.bForward = FALSE; + memset(stl_MapDstIterator->second.tszDstAddr, '\0', sizeof(stl_MapDstIterator->second.tszDstAddr)); + } + } + stl_MapSession.erase(stl_MapSrcIterator); + st_Locker.unlock(); + return TRUE; +} +/******************************************************************** +函数名称:ModuleSession_Forward_Get +函数功能:获取转发用户给 + 参数.一:lpszAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入要操作的客户端 + 参数.二:ptszDstAddr + In/Out:Out + 类型:字符指针 + 可空:N + 意思:输出对端地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +BOOL CModuleSession_Forward::ModuleSession_Forward_Get(LPCTSTR lpszAddr, TCHAR* ptszDstAddr) +{ + Session_IsErrorOccur = FALSE; + + if ((NULL == lpszAddr) || (NULL == ptszDstAddr)) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_PARAMENT; + return FALSE; + } + st_Locker.lock_shared(); + //查找 + auto stl_MapIterator = stl_MapSession.find(lpszAddr); + if (stl_MapIterator == stl_MapSession.end()) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_NOTFOUND; + st_Locker.unlock_shared(); + return FALSE; + } + //如果有转发,需要清理对方的转发设置 + if (!stl_MapIterator->second.bForward) + { + Session_IsErrorOccur = TRUE; + Session_dwErrorCode = ERROR_MODULE_SESSION_FORWARD_NOTFORWARD; + st_Locker.unlock_shared(); + return FALSE; + } + _tcscpy(ptszDstAddr, stl_MapIterator->second.tszDstAddr); + st_Locker.unlock_shared(); + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h new file mode 100644 index 0000000000000000000000000000000000000000..5654b16e711119d418eb092e680df88eb0cc63ad --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h @@ -0,0 +1,35 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 09:57:34 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Forward\ModuleSession_Forward.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\ModuleSession_Forward +// File Base: ModuleSession_Forward +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 会话转发协议 +// History: +*********************************************************************/ +typedef struct +{ + TCHAR tszSrcAddr[128]; + TCHAR tszDstAddr[128]; + BOOL bForward; +}SESSION_FORWARD, * LPSESSION_FORWARD; + +class CModuleSession_Forward +{ +public: + CModuleSession_Forward(); + ~CModuleSession_Forward(); +public: + BOOL ModuleSession_Forward_Insert(LPCTSTR lpszAddr); + BOOL ModuleSession_Forward_List(TCHAR*** ppptszListAddr, int* pInt_Count, LPCTSTR lpszAddr = NULL); + BOOL ModuleSession_Forward_Bind(LPCTSTR lpszSrcAddr, LPCTSTR lpszDstAddr); + BOOL ModuleSession_Forward_Delete(LPCTSTR lpszAddr, TCHAR* ptszDstAddr); + BOOL ModuleSession_Forward_Get(LPCTSTR lpszAddr, TCHAR* ptszDstAddr); +private: + shared_mutex st_Locker; +private: + unordered_map stl_MapSession; +}; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def new file mode 100644 index 0000000000000000000000000000000000000000..9a8c8aca31f222a901793b62702d7b6a7dad1ae2 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def @@ -0,0 +1,10 @@ +LIBRARY + +EXPORTS + ModuleSession_GetLastError + + ModuleSession_Forward_Insert + ModuleSession_Forward_List + ModuleSession_Forward_Bind + ModuleSession_Forward_Delete + ModuleSession_Forward_Get \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..706d81ba2bb0782e733e1fa475fe140db73e8917 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj @@ -0,0 +1,184 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {237af017-9ad2-44d8-a6c4-ecdef7674ff2} + XEngineModuleSession + 10.0 + + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib32);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + $(XEngine_Include);$(IncludePath) + $(XEngine_Lib64);$(LibraryPath) + + + + Level3 + true + WIN32;_DEBUG;XENGINEMODULESESSION_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleSession.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;XENGINEMODULESESSION_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleSession.def + + + + + Level3 + true + _DEBUG;XENGINEMODULESESSION_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + XEngine_ModuleSession.def + + + + + Level3 + true + true + true + NDEBUG;XENGINEMODULESESSION_EXPORTS;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + XEngine_ModuleSession.def + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..6f92c68264d73f924b3126066732ea976c33b0ce --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.filters @@ -0,0 +1,56 @@ + + + + + {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 + + + {17d588b2-3db9-4c2e-9c20-a0c0c2cd3f2d} + + + {8893a952-de7d-4b08-a49e-b46bbe302e17} + + + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件\ModuleSession_Forward + + + + + 源文件 + + + 源文件 + + + 源文件\ModuleSession_Forward + + + + + 源文件 + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.user b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..88a550947edbc3c5003a41726f0749201fdb6822 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/dllmain.cpp b/XEngine_Source/XEngine_ModuleSession/dllmain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daed8c8f7ac50ca1466016a0529648d18125a7e7 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/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/XEngine_ModuleSession/framework.h b/XEngine_Source/XEngine_ModuleSession/framework.h new file mode 100644 index 0000000000000000000000000000000000000000..80cbbc9b06a9b0141f92ee19eceaed71328caff4 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/framework.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 +// Windows 头文件 +#include diff --git a/XEngine_Source/XEngine_ModuleSession/pch.cpp b/XEngine_Source/XEngine_ModuleSession/pch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8be30dcabca6f9f67e3ed1a5c1c3ab5f3fdb9ee2 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/pch.cpp @@ -0,0 +1,51 @@ +#include "pch.h" +#include "ModuleSession_Forward/ModuleSession_Forward.h" +/******************************************************************** +// Created: 2022/06/08 10:10:52 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\pch.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession +// File Base: pch +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 导出实现 +// History: +*********************************************************************/ +BOOL Session_IsErrorOccur = FALSE; +DWORD Session_dwErrorCode = 0; +////////////////////////////////////////////////////////////////////////// +CModuleSession_Forward m_Forward; +////////////////////////////////////////////////////////////////////////// +// 导出函数 +////////////////////////////////////////////////////////////////////////// +extern "C" DWORD ModuleSession_GetLastError(int* pInt_SysError) +{ + if (NULL != pInt_SysError) + { + *pInt_SysError = errno; + } + return Session_dwErrorCode; +} +/************************************************************************/ +/* 转发导出函数 */ +/************************************************************************/ +extern "C" BOOL ModuleSession_Forward_Insert(LPCTSTR lpszAddr) +{ + return m_Forward.ModuleSession_Forward_Insert(lpszAddr); +} +extern "C" BOOL ModuleSession_Forward_List(TCHAR * **ppptszListAddr, int* pInt_Count, LPCTSTR lpszAddr) +{ + return m_Forward.ModuleSession_Forward_List(ppptszListAddr, pInt_Count, lpszAddr); +} +extern "C" BOOL ModuleSession_Forward_Bind(LPCTSTR lpszSrcAddr, LPCTSTR lpszDstAddr) +{ + return m_Forward.ModuleSession_Forward_Bind(lpszSrcAddr, lpszDstAddr); +} +extern "C" BOOL ModuleSession_Forward_Delete(LPCTSTR lpszAddr, TCHAR * ptszDstAddr) +{ + return m_Forward.ModuleSession_Forward_Delete(lpszAddr, ptszDstAddr); +} +extern "C" BOOL ModuleSession_Forward_Get(LPCTSTR lpszAddr, TCHAR * ptszDstAddr) +{ + return m_Forward.ModuleSession_Forward_Get(lpszAddr, ptszDstAddr); +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/pch.h b/XEngine_Source/XEngine_ModuleSession/pch.h new file mode 100644 index 0000000000000000000000000000000000000000..9b9ffc8e59a7f7f45d2e353749cda493ef041456 --- /dev/null +++ b/XEngine_Source/XEngine_ModuleSession/pch.h @@ -0,0 +1,49 @@ +// pch.h: 这是预编译标头文件。 +// 下方列出的文件仅编译一次,提高了将来生成的生成性能。 +// 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 +// 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 +// 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 + +#ifndef PCH_H +#define PCH_H + +#ifdef _MSC_BUILD +// 添加要在此处预编译的标头 +#include "framework.h" +#include +#endif +#endif //PCH_H +#include +#include +#include +#include +using namespace std; +#include +#include +#include +#include +#include "ModuleSession_Define.h" +#include "ModuleSession_Error.h" +/******************************************************************** +// Created: 2022/06/08 10:03:03 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession\pch.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ModuleSession +// File Base: pch +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 公用头文件 +// History: +*********************************************************************/ +extern BOOL Session_IsErrorOccur; +extern DWORD Session_dwErrorCode; + +#ifdef _UNICODE +typedef std::wstring tstring; +#else +typedef std::string tstring; +#endif + +#ifdef _MSC_BUILD +#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib") +#endif \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp new file mode 100644 index 0000000000000000000000000000000000000000..25eee39f80c7b80a1dc6d876799e19c4fa179f99 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp @@ -0,0 +1,119 @@ +#include "XEngine_Hdr.h" +/******************************************************************** +// Created: 2022/06/08 13:44:41 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp\XEngine_ForwardTask.cpp +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_ForwardTask +// File Ext: cpp +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 代理转发协议 +// History: +*********************************************************************/ +XHTHREAD CALLBACK XEngine_Forward_Thread(LPVOID lParam) +{ + int nPoolIndex = *(int*)lParam; + int nThreadPos = nPoolIndex + 1; + + while (bIsRun) + { + if (!HelpComponents_Datas_WaitEventEx(xhForwardPacket, nThreadPos)) + { + continue; + } + int nListCount = 0; + HELPCOMPONENT_PACKET_CLIENT** ppSt_ListClient; + HelpComponents_Datas_GetPoolEx(xhForwardPacket, nThreadPos, &ppSt_ListClient, &nListCount); + for (int i = 0; i < nListCount; i++) + { + int nMsgLen = 0; + CHAR* ptszMsgBuffer = NULL; + XENGINE_PROTOCOLHDR st_ProtocolHdr; + memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR)); + + if (HelpComponents_Datas_GetMemoryEx(xhForwardPacket, ppSt_ListClient[i]->tszClientAddr, &ptszMsgBuffer, &nMsgLen, &st_ProtocolHdr)) + { + XEngine_Forward_Handle(ppSt_ListClient[i]->tszClientAddr, ptszMsgBuffer, nMsgLen, &st_ProtocolHdr); + BaseLib_OperatorMemory_FreeCStyle((XPPMEM)&ptszMsgBuffer); + } + } + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListClient, nListCount); + } + return 0; +} + +BOOL XEngine_Forward_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr) +{ + int nSDLen = 10240; + TCHAR tszSDBuffer[10240]; + memset(tszSDBuffer, '\0', sizeof(tszSDBuffer)); + //判断协议头和尾部 + if ((XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER != pSt_ProtocolHdr->wHeader) || (XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL != pSt_ProtocolHdr->wTail)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Forward客户端:%s,协议错误"), lpszClientAddr); + return FALSE; + } + //处理验证协议 + if (ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH == pSt_ProtocolHdr->unOperatorType) + { + if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREQ == pSt_ProtocolHdr->unOperatorCode) + { + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREP; + ModuleSession_Forward_Insert(lpszClientAddr); + XEngine_Network_Send(lpszClientAddr, (LPCTSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,登录到服务器"), lpszClientAddr); + } + } + //处理转发协议 + if (ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER_FORWARD == pSt_ProtocolHdr->unOperatorType) + { + if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREQ == pSt_ProtocolHdr->unOperatorCode) + { + int nListCount = 0; + TCHAR** pptszListAddr; + + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREP; + if (ModuleSession_Forward_List(&pptszListAddr, &nListCount, lpszClientAddr)) + { + ModuleProtocol_Packet_ForwardList(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, &pptszListAddr, nListCount); + XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,请求可用转发列表成功"), lpszClientAddr); + } + else + { + pSt_ProtocolHdr->unPacketSize = 0; + XEngine_Network_Send(lpszClientAddr, (LPCTSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,请求可用转发列表失败,错误;%lx"), lpszClientAddr, ModuleSession_GetLastError()); + } + } + else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ == pSt_ProtocolHdr->unOperatorCode) + { + TCHAR tszSrcAddr[128]; + TCHAR tszDstAddr[128]; + + memset(tszSrcAddr, '\0', sizeof(tszSrcAddr)); + memset(tszDstAddr, '\0', sizeof(tszDstAddr)); + + ModuleProtocol_Parse_ForwardBind(lpszMsgBuffer, nMsgLen, tszSrcAddr, tszDstAddr); + if (!ModuleSession_Forward_Bind(lpszClientAddr, tszDstAddr)) + { + pSt_ProtocolHdr->wReserve = 401; + pSt_ProtocolHdr->unPacketSize = 0; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP; + XEngine_Network_Send(lpszClientAddr, (LPCTSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,请求绑定转发地址:%s 失败,错误:%lX"), lpszClientAddr, tszDstAddr); + return FALSE; + } + //先告知对方要转发数据 + pSt_ProtocolHdr->wReserve = 0; + pSt_ProtocolHdr->unPacketSize = 0; + XEngine_Network_Send(tszDstAddr, (LPCTSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + //最后返回结果 + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP; + XEngine_Network_Send(lpszClientAddr, (LPCTSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,请求绑定转发地址:%s 成功"), lpszClientAddr, tszDstAddr); + } + } + + return TRUE; +} \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h new file mode 100644 index 0000000000000000000000000000000000000000..7899dbf0b096dd12df79b0ccaca22bebf9ce3453 --- /dev/null +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.h @@ -0,0 +1,15 @@ +#pragma once +/******************************************************************** +// Created: 2022/06/08 13:44:36 +// File Name: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp\XEngine_ForwardTask.h +// File Path: D:\XEngine_ProxyServer\XEngine_Source\XEngine_ServiceApp +// File Base: XEngine_ForwardTask +// File Ext: h +// Project: XEngine(网络通信引擎) +// Author: qyt +// Purpose: 代理转发协议 +// History: +*********************************************************************/ +//任务处理相关函数,处理包的内容 +XHTHREAD CALLBACK XEngine_Forward_Thread(LPVOID lParam); +BOOL XEngine_Forward_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h index 8cd2696fcfff2e9d639db80256977b25fb7cf22b..db48ed66b48914e6f61634e39cebe5857ad41bfe 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Hdr.h @@ -28,6 +28,8 @@ using namespace std; #include #include #include +#include +#include #include #include #include @@ -36,6 +38,8 @@ using namespace std; #include #include #include +#include +#include #include #include #include @@ -46,11 +50,16 @@ using namespace std; #include "../XEngine_ModuleConfigure/ModuleConfig_Error.h" #include "../XEngine_ModuleAuthorize/ModuleAuth_Define.h" #include "../XEngine_ModuleAuthorize/ModuleAuth_Error.h" +#include "../XEngine_ModuleSession/ModuleSession_Define.h" +#include "../XEngine_ModuleSession/ModuleSession_Error.h" +#include "../XEngine_ModuleProtocol/ModuleProtocol_Define.h" +#include "../XEngine_ModuleProtocol/ModuleProtocol_Error.h" //加载自己的头文件 #include "XEngine_Configure.h" #include "XEngine_Network.h" #include "XEngine_SocksTask.h" #include "XEngine_TunnelTask.h" +#include "XEngine_ForwardTask.h" /******************************************************************** // Created: 2021/12/02 16:34:41 // File Name: D:\XEngine_ServiceApp\XEngine_Source\XEngine_ServiceApp\XEngine_Hdr.h @@ -70,37 +79,66 @@ extern XNETHANDLE xhSocksHeart; //Tunnel服务器 extern XNETHANDLE xhTunnelSocket; extern XNETHANDLE xhTunnelHeart; +//Forward服务器 +extern XNETHANDLE xhForwardSocket; +extern XNETHANDLE xhForwardHeart; +extern XNETHANDLE xhForwardPool; +extern XHANDLE xhForwardPacket; //配置文件 extern XENGINE_SERVICECONFIG st_ServiceConfig; //网络类型定义 #define XENGINE_CLIENT_NETTYPE_SOCKS 1 #define XENGINE_CLIENT_NETTYPE_TUNNEL 2 +#define XENGINE_CLIENT_NETTYPE_FORWARD 3 //关闭模式 #define XENGINE_CLIENT_CLOSE_NETWORK 1 #define XENGINE_CLIENT_CLOSE_HEARTBEAT 2 #define XENGINE_CLIENT_CLOSE_SERVICE 3 +typedef struct +{ + TCHAR tszIPAddr[128]; + ENUM_RFCCOMPONENTS_PROXY_STATUS enStatus; + SOCKET hSocket; + BOOL bClose; +}PROXYPROTOCOL_CLIENTINFO; + //连接库 #ifdef _MSC_BUILD #ifdef _WIN64 +#ifdef _DEBUG +#pragma comment(lib,"../x64/Debug/XEngine_ModuleConfigure.lib") +#pragma comment(lib,"../x64/Debug/XEngine_ModuleAuthorize.lib") +#pragma comment(lib,"../x64/Debug/XEngine_ModuleSession.lib") +#pragma comment(lib,"../x64/Debug/XEngine_ModuleProtocol.lib") +#else #pragma comment(lib,"../x64/Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../x64/Release/XEngine_ModuleAuthorize.lib") +#pragma comment(lib,"../x64/Release/XEngine_ModuleSession.lib") +#pragma comment(lib,"../x64/Release/XEngine_ModuleProtocol.lib") +#endif #else #ifdef _DEBUG #pragma comment(lib,"../Debug/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../Debug/XEngine_ModuleAuthorize.lib") +#pragma comment(lib,"../Debug/XEngine_ModuleSession.lib") +#pragma comment(lib,"../Debug/XEngine_ModuleProtocol.lib") #else #pragma comment(lib,"../Release/XEngine_ModuleConfigure.lib") #pragma comment(lib,"../Release/XEngine_ModuleAuthorize.lib") +#pragma comment(lib,"../Release/XEngine_ModuleSession.lib") +#pragma comment(lib,"../Release/XEngine_ModuleProtocol.lib") #endif #endif #pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib") #pragma comment(lib,"XEngine_Core/XEngine_Core.lib") +#pragma comment(lib,"XEngine_Core/XEngine_ManagePool.lib") #pragma comment(lib,"XEngine_Core/XEngine_OPenSsl.lib") #pragma comment(lib,"XEngine_Core/XEngine_NetXApi.lib") #pragma comment(lib,"XEngine_NetHelp/NetHelp_APIHelp.lib") #pragma comment(lib,"XEngine_HelpComponents/HelpComponents_XLog.lib") +#pragma comment(lib,"XEngine_HelpComponents/HelpComponents_Packets.lib") #pragma comment(lib,"XEngine_RfcComponents/RfcComponents_ProxyProtocol.lib") #pragma comment(lib,"XEngine_Client/XClient_Socket.lib") #pragma comment(lib,"Ws2_32.lib") diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index d4af7cae0e336d22446769468c5370f69096feeb..d9b27f30fb6d71f086578ba9cded56cf2b82c781 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -58,6 +58,42 @@ void __stdcall Network_Callback_TunnelHeart(LPCTSTR lpszClientAddr, SOCKET hSock { XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, XENGINE_CLIENT_CLOSE_HEARTBEAT); } +//////////////////////////////////////////////////////////////////////////下面是Tunnel网络IO相关代码处理函数 +BOOL __stdcall Network_Callback_ForwardLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +{ + SocketOpt_HeartBeat_InsertAddrEx(xhForwardHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,连接到服务器"), lpszClientAddr); + return TRUE; +} +void __stdcall Network_Callback_ForwardRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam) +{ + TCHAR tszDstAddr[128]; + memset(tszDstAddr, '\0', sizeof(tszDstAddr)); + + if (ModuleSession_Forward_Get(lpszClientAddr, tszDstAddr)) + { + //如果有转发,直接转发 + XEngine_Network_Send(tszDstAddr, lpszRecvMsg, nMsgLen, XENGINE_CLIENT_NETTYPE_FORWARD); + } + else + { + //没有绑定转发,投递到包中处理 + if (!HelpComponents_Datas_PostEx(xhForwardPacket, lpszClientAddr, lpszRecvMsg, nMsgLen)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Forward客户端:%s,投递数据包失败,大小:%d,错误:%lX"), lpszClientAddr, nMsgLen, Packets_GetLastError()); + } + } + SocketOpt_HeartBeat_ActiveAddrEx(xhForwardHeart, lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG, _T("Forward客户端:%s,投递数据包到组包队列成功,大小:%d"), lpszClientAddr, nMsgLen); +} +void __stdcall Network_Callback_ForwardLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_FORWARD, XENGINE_CLIENT_CLOSE_NETWORK); +} +void __stdcall Network_Callback_ForwardHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam) +{ + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_FORWARD, XENGINE_CLIENT_CLOSE_HEARTBEAT); +} //////////////////////////////////////////////////////////////////////////网络IO关闭操作 void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, int nCloseType) { @@ -83,9 +119,9 @@ void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, int nCloseType) memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); if (ProxyProtocol_SocksCore_GetInfo(lpszClientAddr, &st_ProxyClient)) { - XClient_TCPSelect_Close(st_ProxyClient.hSocket); + st_ProxyClient.bClose = TRUE; + ProxyProtocol_SocksCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); } - ProxyProtocol_SocksCore_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("SOCKS客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } else if (XENGINE_CLIENT_NETTYPE_TUNNEL == nIPProto) @@ -107,11 +143,36 @@ void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, int nCloseType) memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); if (ProxyProtocol_TunnelCore_GetInfo(lpszClientAddr, &st_ProxyClient)) { - XClient_TCPSelect_Close(st_ProxyClient.hSocket); + st_ProxyClient.bClose = TRUE; + ProxyProtocol_TunnelCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); } - ProxyProtocol_TunnelCore_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Tunnel客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } + else if (XENGINE_CLIENT_NETTYPE_FORWARD == nIPProto) + { + if (XENGINE_CLIENT_CLOSE_NETWORK == nCloseType) + { + SocketOpt_HeartBeat_DeleteAddrEx(xhForwardHeart, lpszClientAddr); + } + else if (XENGINE_CLIENT_CLOSE_HEARTBEAT == nCloseType) + { + NetCore_TCPXCore_CloseForClientEx(xhForwardSocket, lpszClientAddr); + } + else + { + SocketOpt_HeartBeat_DeleteAddrEx(xhForwardHeart, lpszClientAddr); + NetCore_TCPXCore_CloseForClientEx(xhForwardSocket, lpszClientAddr); + } + TCHAR tszClientAddr[128]; + memset(tszClientAddr, '\0', sizeof(tszClientAddr)); + ModuleSession_Forward_Delete(lpszClientAddr, tszClientAddr); + + if (_tcslen(tszClientAddr) > 0) + { + XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_FORWARD, XENGINE_CLIENT_CLOSE_SERVICE); + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("Forward客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); + } else { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("未知客户端:%s,离开服务器"), lpszClientAddr); @@ -141,6 +202,15 @@ BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMs } SocketOpt_HeartBeat_ActiveAddrEx(xhTunnelHeart, lpszClientAddr); } + else if (XENGINE_CLIENT_NETTYPE_FORWARD == nIPProto) + { + if (!NetCore_TCPXCore_SendEx(xhForwardSocket, lpszClientAddr, lpszMsgBuffer, nMsgLen, 1, 1)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("Forward客户端:%s,发送数据失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); + return FALSE; + } + SocketOpt_HeartBeat_ActiveAddrEx(xhForwardHeart, lpszClientAddr); + } else { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("未知客户端:%s,发送数据给失败,错误:%lX"), lpszClientAddr, NetCore_GetLastError()); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h index a433e44b9b3ce12cf56b9be05508bcf3e9defb2c..c56839ed8c1effe2f29f09a5daa9d0acd1928421 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.h @@ -20,6 +20,11 @@ BOOL __stdcall Network_Callback_TunnelLogin(LPCTSTR lpszClientAddr, SOCKET hSock void __stdcall Network_Callback_TunnelRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); void __stdcall Network_Callback_TunnelLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); void __stdcall Network_Callback_TunnelHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); +//Forward相关 +BOOL __stdcall Network_Callback_ForwardLogin(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); +void __stdcall Network_Callback_ForwardRecv(LPCTSTR lpszClientAddr, SOCKET hSocket, LPCTSTR lpszRecvMsg, int nMsgLen, LPVOID lParam); +void __stdcall Network_Callback_ForwardLeave(LPCTSTR lpszClientAddr, SOCKET hSocket, LPVOID lParam); +void __stdcall Network_Callback_ForwardHeart(LPCTSTR lpszClientAddr, SOCKET hSocket, int nStatus, LPVOID lParam); //关闭与发送 void XEngine_Network_Close(LPCTSTR lpszClientAddr, int nIPProto, int nCloseType); BOOL XEngine_Network_Send(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen, int nIPProto); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp index e3b225d96031ec3003de09a9c6998a4267cc5f27..b0c84e85b417e72eda1e72abd97e329119ab71e8 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.cpp @@ -8,6 +8,11 @@ XNETHANDLE xhSocksHeart = 0; XNETHANDLE xhTunnelSocket = 0; XNETHANDLE xhTunnelHeart = 0; + +XNETHANDLE xhForwardSocket = 0; +XNETHANDLE xhForwardHeart = 0; +XNETHANDLE xhForwardPool = 0; +XHANDLE xhForwardPacket = NULL; //配置文件 XENGINE_SERVICECONFIG st_ServiceConfig; @@ -23,6 +28,11 @@ void ServiceApp_Stop(int signo) //销毁Tunnel资源 NetCore_TCPXCore_DestroyEx(xhTunnelSocket); SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); + //销毁Forward资源 + HelpComponents_Packets_Destory(xhForwardPacket); + NetCore_TCPXCore_DestroyEx(xhForwardSocket); + SocketOpt_HeartBeat_DestoryEx(xhForwardHeart); + ManagePool_Thread_NQDestroy(xhForwardPool); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); ModuleAuthorize_User_Destory(); @@ -184,8 +194,65 @@ int main(int argc, char** argv) { XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Tunnel消息服务没有被启用")); } + //启动转发协议服务 + if (st_ServiceConfig.nForwardPort > 0) + { + //组包器 + xhForwardPacket = HelpComponents_Datas_Init(st_ServiceConfig.st_XMax.nMaxQueue, st_ServiceConfig.st_XMax.nForwardThread); + if (NULL == xhForwardPacket) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("初始化Forward组包器失败,错误:%lX"), Packets_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动Forward组包器成功")); + //启动心跳 + if (st_ServiceConfig.st_XTime.nForwardTimeOut > 0) + { + if (!SocketOpt_HeartBeat_InitEx(&xhForwardHeart, st_ServiceConfig.st_XTime.nForwardTimeOut, st_ServiceConfig.st_XTime.nTimeCheck, Network_Callback_ForwardHeart)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,初始化Forward心跳服务失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,初始化Forward心跳服务成功,句柄:%llu,时间:%d,次数:%d"), xhForwardHeart, st_ServiceConfig.st_XTime.nForwardTimeOut, st_ServiceConfig.st_XTime.nTimeCheck); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Forward心跳服务被设置为不启用")); + } + //网络 + if (!NetCore_TCPXCore_StartEx(&xhForwardSocket, st_ServiceConfig.nForwardPort, st_ServiceConfig.st_XMax.nMaxClient, st_ServiceConfig.st_XMax.nIOThread)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动服务中,启动Forward网络服务器失败,错误:%lX"), NetCore_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动Forward网络服务器成功,Forward端口:%d,IO:%d"), st_ServiceConfig.nForwardPort, st_ServiceConfig.st_XMax.nIOThread); + NetCore_TCPXCore_RegisterCallBackEx(xhForwardSocket, Network_Callback_ForwardLogin, Network_Callback_ForwardRecv, Network_Callback_ForwardLeave); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,注册Forward网络事件成功")); + //任务池 + THREADPOOL_PARAMENT** ppSt_ListParam; + BaseLib_OperatorMemory_Malloc((XPPPMEM)&ppSt_ListParam, st_ServiceConfig.st_XMax.nForwardThread, sizeof(THREADPOOL_PARAMENT)); + for (int i = 0; i < st_ServiceConfig.st_XMax.nForwardThread; i++) + { + int* pInt_Pos = new int; + + *pInt_Pos = i; + ppSt_ListParam[i]->lParam = pInt_Pos; + ppSt_ListParam[i]->fpCall_ThreadsTask = XEngine_Forward_Thread; + } + if (!ManagePool_Thread_NQCreate(&xhForwardPool, &ppSt_ListParam, st_ServiceConfig.st_XMax.nForwardThread)) + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("启动Forward线程池服务失败,错误:%lX"), ManagePool_GetLastError()); + goto XENGINE_SERVICEAPP_EXIT; + } + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("启动服务中,启动Forward线程池服务成功,启动个数:%d"), st_ServiceConfig.st_XMax.nForwardThread); + } + else + { + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("启动服务中,Forward服务没有被启用")); + } + + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("所有服务成功启动,服务运行中,XEngine版本:%s,服务版本;%s,发行次数:%d。。。"), BaseLib_OperatorVer_XGetStr(), st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str(), st_ServiceConfig.st_XVer.pStl_ListVer->size()); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("所有服务成功启动,服务运行中,XEngine版本:%s,服务版本;%s,发行次数:%d。。。"), XENGINE_VERSION_STR, st_ServiceConfig.st_XVer.pStl_ListVer->front().c_str(), st_ServiceConfig.st_XVer.pStl_ListVer->size()); while (bIsRun) { std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -201,6 +268,11 @@ XENGINE_SERVICEAPP_EXIT: //销毁Tunnel资源 NetCore_TCPXCore_DestroyEx(xhTunnelSocket); SocketOpt_HeartBeat_DestoryEx(xhTunnelHeart); + //销毁Forward资源 + HelpComponents_Packets_Destory(xhForwardPacket); + NetCore_TCPXCore_DestroyEx(xhForwardSocket); + SocketOpt_HeartBeat_DestoryEx(xhForwardHeart); + ManagePool_Thread_NQDestroy(xhForwardPool); //销毁日志资源 HelpComponents_XLog_Destroy(xhLog); ModuleAuthorize_User_Destory(); diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj index 2ef6fddc4c2d0c99ac266bb15121c4540a6fd8cc..9b17ecf140a3c96b33eba5b6e75b8f46377c321d 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj @@ -153,6 +153,7 @@ + @@ -160,6 +161,7 @@ + diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters index 447abc3953a57c1ea5d66673222396f430b3a40e..808b1e54274fc58f11a6f0752cd2d98d7f1b849a 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ServiceApp.vcxproj.filters @@ -30,6 +30,9 @@ 源文件 + + 源文件 + @@ -47,5 +50,8 @@ 头文件 + + 头文件 + \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp index 8e349d00b5e1f35a27611eb28fb8a656d580605c..adb79ee750c8d0c27d81f804d079ebc0bef1191a 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.cpp @@ -173,7 +173,7 @@ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int _tcscpy(st_ProxyClient.tszIPAddr, lpszClientAddr); ProxyProtocol_SocksCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); //创建转发线程 - std::thread pSTDThread(XEngine_SocksTask_Thread, lpszClientAddr); + std::thread pSTDThread(XEngine_SocksTask_Thread, lpszClientAddr, st_ProxyClient.hSocket); pSTDThread.detach(); //回复结果 ProxyProtocol_SocksCore_HdrPacket(lpszClientAddr, tszMsgBuffer, &nLen, XENGINE_RFCCOMPONENT_PROXY_SOCKS_RESPONSE_SUCCESS); @@ -196,29 +196,31 @@ BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int } return TRUE; } -XHTHREAD CALLBACK XEngine_SocksTask_Thread(LPCTSTR lpszClientAddr) +XHTHREAD CALLBACK XEngine_SocksTask_Thread(LPCTSTR lpszClientAddr, SOCKET hSocket) { - TCHAR tszClientAddr[128]; - PROXYPROTOCOL_CLIENTINFO st_ProxyClient; - - memset(tszClientAddr, '\0', sizeof(tszClientAddr)); - _tcscpy(tszClientAddr, lpszClientAddr); + TCHAR tszMsgBuffer[4096]; while (1) { int nMsgLen = 4096; - TCHAR tszMsgBuffer[4096]; - - memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); - if (!ProxyProtocol_SocksCore_GetInfo(tszClientAddr, &st_ProxyClient)) + if (!XClient_TCPSelect_RecvMsg(hSocket, tszMsgBuffer, &nMsgLen, FALSE)) { break; } - if (!XClient_TCPSelect_RecvMsg(st_ProxyClient.hSocket, tszMsgBuffer, &nMsgLen, FALSE)) + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_SOCKS); + } + //退出处理 + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (ProxyProtocol_SocksCore_GetInfo(lpszClientAddr, &st_ProxyClient)) + { + ProxyProtocol_SocksCore_Delete(lpszClientAddr); + //是主动关闭的还是被动触发的 + if (!st_ProxyClient.bClose) { - break; + //主动关闭,需要调用 + XClient_TCPSelect_Close(st_ProxyClient.hSocket); + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, XENGINE_CLIENT_CLOSE_SERVICE); } - XEngine_Network_Send(st_ProxyClient.tszIPAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_SOCKS); } - XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_SOCKS, XENGINE_CLIENT_CLOSE_SERVICE); return 0; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h index d4ace2112f8303a4a674d231f96a421b94836b5c..089b403ebe3e5f16cbb0b7d9f58fbb9fac1d67b1 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_SocksTask.h @@ -12,4 +12,4 @@ *********************************************************************/ //任务处理相关函数,处理包的内容 BOOL XEngine_SocksTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); -XHTHREAD CALLBACK XEngine_SocksTask_Thread(LPCTSTR lpszClientAddr); \ No newline at end of file +XHTHREAD CALLBACK XEngine_SocksTask_Thread(LPCTSTR lpszClientAddr, SOCKET hSocket); \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp index ee948a8f0c7f40a9374d14b910117ae2cc3e9b03..effb198932f47b946354f0562e37609a7be41506 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.cpp @@ -107,7 +107,7 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in _tcscpy(st_ProxyClient.tszIPAddr, lpszClientAddr); ProxyProtocol_TunnelCore_SetInfo(lpszClientAddr, &st_ProxyClient, sizeof(PROXYPROTOCOL_CLIENTINFO)); //启动线程 - std::thread pSTDThread(XEngine_TunnelTask_Thread, lpszClientAddr); + std::thread pSTDThread(XEngine_TunnelTask_Thread, lpszClientAddr, st_ProxyClient.hSocket); pSTDThread.detach(); //判断是代理还是非代理协议 if (bProxy) @@ -129,29 +129,31 @@ BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, in } return TRUE; } -XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr) +XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr, SOCKET hSocket) { - TCHAR tszClientAddr[128]; - PROXYPROTOCOL_CLIENTINFO st_ProxyClient; - - memset(tszClientAddr, '\0', sizeof(tszClientAddr)); - _tcscpy(tszClientAddr, lpszClientAddr); + TCHAR tszMsgBuffer[4096]; while (1) { int nMsgLen = 4096; - TCHAR tszMsgBuffer[4096]; - - memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); - if (!ProxyProtocol_TunnelCore_GetInfo(tszClientAddr, &st_ProxyClient)) + if (!XClient_TCPSelect_RecvMsg(hSocket, tszMsgBuffer, &nMsgLen, FALSE)) { break; } - if (!XClient_TCPSelect_RecvMsg(st_ProxyClient.hSocket, tszMsgBuffer, &nMsgLen, FALSE)) + XEngine_Network_Send(lpszClientAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_TUNNEL); + } + //退出处理 + PROXYPROTOCOL_CLIENTINFO st_ProxyClient; + memset(&st_ProxyClient, '\0', sizeof(PROXYPROTOCOL_CLIENTINFO)); + if (ProxyProtocol_TunnelCore_GetInfo(lpszClientAddr, &st_ProxyClient)) + { + ProxyProtocol_TunnelCore_Delete(lpszClientAddr); + //是主动关闭的还是被动触发的 + if (!st_ProxyClient.bClose) { - break; + //主动关闭,需要调用 + XClient_TCPSelect_Close(hSocket); + XEngine_Network_Close(lpszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, XENGINE_CLIENT_CLOSE_SERVICE); } - XEngine_Network_Send(st_ProxyClient.tszIPAddr, tszMsgBuffer, nMsgLen, XENGINE_CLIENT_NETTYPE_TUNNEL); } - XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_TUNNEL, XENGINE_CLIENT_CLOSE_SERVICE); return 0; } \ No newline at end of file diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h index ccec4d598808024716a5febaf22deded73d9526d..e143428aef712388498fc7b9c8d9bf329d1ee729 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_TunnelTask.h @@ -12,4 +12,4 @@ *********************************************************************/ //任务处理相关函数,处理包的内容 BOOL XEngine_TunnelTask_Handle(LPCTSTR lpszClientAddr, LPCTSTR lpszMsgBuffer, int nMsgLen); -XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr); \ No newline at end of file +XHTHREAD CALLBACK XEngine_TunnelTask_Thread(LPCTSTR lpszClientAddr, SOCKET hSocket); \ No newline at end of file diff --git a/XEngine_Source/XEngine_UserProtocol.h b/XEngine_Source/XEngine_UserProtocol.h index cfb46262f859aa3315762f631c031738ec02ecf1..7bfd641a22f355acf77d59af9e70a176c730f355 100644 --- a/XEngine_Source/XEngine_UserProtocol.h +++ b/XEngine_Source/XEngine_UserProtocol.h @@ -11,15 +11,25 @@ // History: *********************************************************************/ /////////////////////////////////////////////////////////////////////////// +// 导出的协议定义 +/////////////////////////////////////////////////////////////////////////// +typedef enum en_XEngine_XUser_Protocol +{ + ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER_FORWARD = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_USER + 1 +}ENUM_XNETENGINE_XUSER_PROTOCOL; +//转发协议 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREQ 0xE1000 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREP 0xE1001 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREQ 0xE1002 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREP 0xE1003 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREQ 0xE1004 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_BINDREP 0xE1005 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREQ 0xE1006 +#define XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP 0xE1007 +/////////////////////////////////////////////////////////////////////////// // 导出的数据结构 /////////////////////////////////////////////////////////////////////////// #pragma pack(push) #pragma pack(1) -typedef struct -{ - TCHAR tszIPAddr[128]; - ENUM_RFCCOMPONENTS_PROXY_STATUS enStatus; - SOCKET hSocket; - BOOL bConnect; -}PROXYPROTOCOL_CLIENTINFO; + #pragma pack(pop) \ No newline at end of file