diff --git a/CHANGELOG b/CHANGELOG index 5010432fb38a2a7635bd2fa7dedbda2107568f3a..92ae9c0d3c8d40fa96d8ace3dd3688cf49427082 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,24 @@ +XEngine_ProxyServer V1.6.0.1001 + +增加:数据转发解绑协议支持 +增加:数据转发为会话模块插入现在有用户信息了 +更新:匹配XEngine到V8.15版本 +修改:数据转发枚举用户信息现在有更多信息 +修正:数据转发枚举用户列表没有释放内存的问题 +修正:数据转发用户登录的时候没有创建包管理器的问题 +修正:数据转发用户退出没有释放包资源的问题 +删除:数据转发没有用的协议处理代码 + +added:unbind protocol supported +added:insert have user info for session module +update:match xengine v8.15 +modify:Enumerating users now has more information +fixed:does not free memory when enum user +fixed:forward does not create packet when client login +fixed:does not delete packet res when client close +modify:does not close bind client when client close +delete:unused protocol code +====================================================================================== XEngine_ProxyServer V1.5.1.1001 更新:匹配XEngine到V8.x版本 diff --git a/README.en.md b/README.en.md index 4244be25fe61f7b53124a99c5aa608fc3a337908..8be2a81bd0826f27f7e7797a62f40b327040ff59 100644 --- a/README.en.md +++ b/README.en.md @@ -25,7 +25,7 @@ this software support following features ## install #### XEngine Evn -you must install XEngine,need V8.10 or above,install XEngine can be refer to xengine Readme docment +you must install XEngine,need V8.15 or above,install XEngine can be refer to xengine Readme docment GITEE:https://gitee.com/xyry/libxengine GITHUB:https://github.com/libxengine/xengine diff --git a/README.md b/README.md index 3a20df47aae83f723003cef97292666e09007a83..e58d7716f7b6abfeb4e7a04b9ad488e64d6948c5 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ c c++ Socks5 Proxy Service,HTTP Tunnel Proxy Service,tcp forward service ## 安装教程 #### XEngine环境 -必须安装XEngine,版本需要V8.10或者以上版本,安装XEngine可以参考其Readme文档 +必须安装XEngine,版本需要V8.15或者以上版本,安装XEngine可以参考其Readme文档 GITEE:https://gitee.com/xyry/libxengine GITHUB:https://github.com/libxengine/xengine @@ -89,6 +89,9 @@ make FLAGS=CleanAll 清理编译 透传代理 转发代理支持权限和确认 支持加密代理 +转发代理绑定解绑支持附加用户信息 +转发代理绑定支持拒绝 +转发代理支持用户验证 ## 关注我们 如果你觉得这个软件对你有帮助,请你给我们一个START吧 diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp index 2a44da8425e354635e2909aa29deea7c19442112..215956096b148183c294d1621a29cc476daf6579 100644 --- a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.cpp @@ -45,20 +45,31 @@ int main(int argc, char** argv) int nMsgLen = 0; XENGINE_PROTOCOLHDR st_ProtocolHdr; + XENGINE_PROTOCOL_USERAUTH st_UserAuth; + memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR)); + memset(&st_UserAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH)); //登录 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 = sizeof(XENGINE_PROTOCOL_USERAUTH); st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_AUTH; st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREQ; + _tcsxcpy(st_UserAuth.tszUserName, "test"); + if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCXSTR)&st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR))) { printf("发送失败!\n"); return 0; } + if (!XClient_TCPSelect_SendMsg(m_Socket, (LPCXSTR)&st_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH))) + { + printf("发送失败!\n"); + return 0; + } nMsgLen = 0; XCHAR* ptszMsgBuffer = NULL; @@ -104,7 +115,7 @@ int main(int argc, char** argv) //请求绑定 Json::Value st_JsonRoot; Json::Value st_JsonArray = st_JsonAddr["Array"]; - st_JsonRoot["tszDstAddr"] = st_JsonArray[0].asCString(); + st_JsonRoot["tszDstAddr"] = st_JsonArray[0]["tszSrcAddr"].asCString(); st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER; st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL; @@ -172,7 +183,7 @@ int main(int argc, char** argv) } } - std::this_thread::sleep_for(std::chrono::seconds(5000)); + std::this_thread::sleep_for(std::chrono::seconds(20000)); XClient_TCPSelect_Close(m_Socket); #ifdef _MSC_BUILD WSACleanup(); diff --git a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj index 821892afbb4bcc5d5e0efe21f00825879405ad1d..72245284290ea0dfa93af946fa69dfa7d693b9ba 100644 --- a/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj +++ b/XEngine_APPClient/APPClient_ForwardExample/APPClient_ForwardExample.vcxproj @@ -78,7 +78,7 @@ Level3 true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true diff --git a/XEngine_Docment/Docment_en.docx b/XEngine_Docment/Docment_en.docx index 300c22efd5f6ee8484f37cd4b9d1dcf358766510..0dc825f93a36bb7143147f78b555a35295ae2487 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 456ab94df0fe5b4f2f74f52503d1f682d7d75a34..b2ddcc719bf3611707e64aff380f2f5ef180e831 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 f33e4a685049b3291fbf53d53ff209a4dcdb9a79..353d57e9e79267fcf5338096419aa964e76e9c27 100644 --- a/XEngine_Release/XEngine_Config/XEngine_Config.json +++ b/XEngine_Release/XEngine_Config/XEngine_Config.json @@ -14,19 +14,20 @@ "nTimeCheck": 3, "nSocksTimeOut": 5, "nTunnelTimeOut": 5, - "nForwardTimeOut": 5 + "nForwardTimeOut": 0 }, "XLog": { "MaxSize": 1024000, "MaxCount": 10, "LogLeave": 32, - "tszLogFile": "./XEngine_Log/XEngine_ServiceApp.log" + "tszLogFile": "./XEngine_Log/XEngine_ProxyServiceApp.log" }, "XAuth": { "bAuth": 0, "tszAuthFile": "./XEngine_Config/UserList.txt" }, "XVer": [ + "1.6.0.1001 Build20230817", "1.5.1.1001 Build20230426", "1.5.0.1001 Build20230202", "1.4.0.1001 Build20221111", diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h index 4726aec400d53b60575804c4688a6f4d3b1bd25c..1050015047fc8871716a3946f067e0f64242cbc6 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Define.h @@ -35,7 +35,7 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError = NULL); 类型:协议头 可空:N 意思:输入请求的头 - 参数.四:ppptszListAddr + 参数.四:pppSt_ListUser In/Out:In 类型:三级指针 可空:N @@ -50,7 +50,7 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError = NULL); 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XCHAR*** ppptszListAddr, int nCount); +extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD * **pppSt_ListUser, int nCount); /************************************************************************/ /* 解析导出函数 */ /************************************************************************/ diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp index 823cca22b9d5dabf712cd115408fb76cfd87e003..cfa60ff1d026770487798ff8340fbc1a54005ff3 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.cpp @@ -40,7 +40,7 @@ CModuleProtocol_Packet::~CModuleProtocol_Packet() 类型:协议头 可空:N 意思:输入请求的头 - 参数.四:ppptszListAddr + 参数.四:pppSt_ListUser In/Out:In 类型:三级指针 可空:N @@ -55,7 +55,7 @@ CModuleProtocol_Packet::~CModuleProtocol_Packet() 意思:是否成功 备注: *********************************************************************/ -bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XCHAR*** ppptszListAddr, int nCount) +bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD*** pppSt_ListUser, int nCount) { Protocol_IsErrorOccur = false; @@ -70,7 +70,20 @@ bool CModuleProtocol_Packet::ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuf for (int i = 0; i < nCount; i++) { - st_JsonArray[i] = (*ppptszListAddr)[i]; + Json::Value st_JsonObject; + Json::Value st_JsonSub; + st_JsonObject["bForward"] = (*pppSt_ListUser)[i]->bForward; + st_JsonObject["tszSrcAddr"] = (*pppSt_ListUser)[i]->tszSrcAddr; + st_JsonObject["tszDstAddr"] = (*pppSt_ListUser)[i]->tszDstAddr; + + st_JsonSub["tszUserName"] = (*pppSt_ListUser)[i]->st_UserAuth.tszUserName; + st_JsonSub["tszUserPass"] = (*pppSt_ListUser)[i]->st_UserAuth.tszUserPass; + st_JsonSub["tszDCode"] = (*pppSt_ListUser)[i]->st_UserAuth.tszDCode; + st_JsonSub["enClientType"] = (*pppSt_ListUser)[i]->st_UserAuth.enClientType; + st_JsonSub["enDeviceType"] = (*pppSt_ListUser)[i]->st_UserAuth.enDeviceType; + + st_JsonObject["st_UserAuth"] = st_JsonSub; + st_JsonArray.append(st_JsonObject); } st_JsonRoot["Count"] = nCount; st_JsonRoot["Array"] = st_JsonArray; diff --git a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h index 8f0d43fbacab434a68bccd4b79c10402bd8526b9..4367f0e655a70fdbfb2fa2aa3a6d243800d10187 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h +++ b/XEngine_Source/XEngine_ModuleProtocol/ModuleProtocol_Packet/ModuleProtocol_Packet.h @@ -17,6 +17,6 @@ public: CModuleProtocol_Packet(); ~CModuleProtocol_Packet(); public: - bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XCHAR*** ppptszListAddr, int nCount); + bool ModuleProtocol_Packet_ForwardList(XCHAR* ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, SESSION_FORWARD*** pppSt_ListUser, int nCount); private: }; \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp index 3b7e0e73fe6a49438d15ad0e16d4b3eebe9b9a5f..0a6fc70cd68809eddbda8158d40b9d861ee1d38b 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/pch.cpp +++ b/XEngine_Source/XEngine_ModuleProtocol/pch.cpp @@ -31,9 +31,9 @@ extern "C" XLONG ModuleProtocol_GetLastError(int* pInt_SysError) /************************************************************************/ /* 封包导出函数 */ /************************************************************************/ -extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR * ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XCHAR * **ppptszListAddr, int nCount) +extern "C" bool ModuleProtocol_Packet_ForwardList(XCHAR * ptszMsgBuffer, int* pInt_Len, XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, SESSION_FORWARD * **pppSt_ListUser, int nCount) { - return m_ProtocolPacket.ModuleProtocol_Packet_ForwardList(ptszMsgBuffer, pInt_Len, pSt_ProtocolHdr, ppptszListAddr, nCount); + return m_ProtocolPacket.ModuleProtocol_Packet_ForwardList(ptszMsgBuffer, pInt_Len, pSt_ProtocolHdr, pppSt_ListUser, nCount); } /************************************************************************/ /* 解析导出函数 */ diff --git a/XEngine_Source/XEngine_ModuleProtocol/pch.h b/XEngine_Source/XEngine_ModuleProtocol/pch.h index 38e32f9ed4ae9b34c893c76d1c851c75796d6b69..f3bc0883becf6d46928edc9062607af2790571b0 100644 --- a/XEngine_Source/XEngine_ModuleProtocol/pch.h +++ b/XEngine_Source/XEngine_ModuleProtocol/pch.h @@ -22,6 +22,7 @@ using namespace std; #include #include #include "../XEngine_UserProtocol.h" +#include "../XEngine_ModuleSession/ModuleSession_Define.h" #include "ModuleProtocol_Define.h" #include "ModuleProtocol_Error.h" /******************************************************************** diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h index 6180c962d9dc2f48eff1455c19d39dc29c09dec0..569cf44b265694f4a197d245fa615b9bd5cf9529 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Define.h @@ -10,6 +10,13 @@ // Purpose: 导出定义 // History: *********************************************************************/ +typedef struct +{ + XENGINE_PROTOCOL_USERAUTH st_UserAuth; + XCHAR tszSrcAddr[128]; + XCHAR tszDstAddr[128]; + bool bForward; +}SESSION_FORWARD, * LPSESSION_FORWARD; ////////////////////////////////////////////////////////////////////////// // 导出函数 ////////////////////////////////////////////////////////////////////////// @@ -25,16 +32,21 @@ extern "C" XLONG ModuleSession_GetLastError(int* pInt_SysError = NULL); 类型:常量字符指针 可空:N 意思:输入要插入的客户端 + 参数.二:pSt_UserAuth + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要保存的客户端附加数据 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr); +extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH * pSt_UserAuth); /******************************************************************** 函数名称:ModuleSession_Forward_List 函数功能:获取列表 - 参数.一:ppptszListAddr + 参数.一:pppSt_ListUser In/Out:Out 类型:三级指针 可空:N @@ -54,7 +66,7 @@ extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr); 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr = NULL); +extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL); /******************************************************************** 函数名称:ModuleSession_Forward_Bind 函数功能:绑定转发需求 @@ -75,6 +87,25 @@ extern "C" bool ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Co *********************************************************************/ extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); /******************************************************************** +函数名称:ModuleSession_Forward_UNBind +函数功能:解除绑定转发需求 + 参数.一:lpszSrcAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入绑定的原始地址 + 参数.二:lpszDstAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输出绑定的目标地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +extern "C" bool ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); +/******************************************************************** 函数名称:ModuleSession_Forward_Delete 函数功能:删除用户 参数.一:lpszAddr @@ -85,14 +116,14 @@ extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstA 参数.二:ptszDstAddr In/Out:Out 类型:字符指针 - 可空:N + 可空:Y 意思:输出解绑的地址 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr); +extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr = NULL); /******************************************************************** 函数名称:ModuleSession_Forward_Get 函数功能:获取转发用户给 diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp index 2f7d507766ce33e202bf5763249f3adf756bd795..d49c84bdda86c60eb304b77ca05ab9d451046eea 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.cpp @@ -30,12 +30,17 @@ CModuleSession_Forward::~CModuleSession_Forward() 类型:常量字符指针 可空:N 意思:输入要插入的客户端 + 参数.二:pSt_UserAuth + In/Out:In + 类型:数据结构指针 + 可空:N + 意思:输入要保存的客户端附加数据 返回值 类型:逻辑型 意思:是否成功 备注: *********************************************************************/ -bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr) +bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH* pSt_UserAuth) { Session_IsErrorOccur = false; @@ -49,6 +54,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr) memset(&st_Forward, '\0', sizeof(SESSION_FORWARD)); _tcsxcpy(st_Forward.tszSrcAddr, lpszAddr); + memcpy(&st_Forward.st_UserAuth, pSt_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH)); st_Locker.lock(); unordered_map::const_iterator stl_MapIterator = stl_MapSession.find(lpszAddr); @@ -86,7 +92,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Insert(LPCXSTR lpszAddr) 意思:是否成功 备注: *********************************************************************/ -bool CModuleSession_Forward::ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr) +bool CModuleSession_Forward::ModuleSession_Forward_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr /* = NULL */) { Session_IsErrorOccur = false; @@ -106,7 +112,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(XCHAR*** ppptszListAddr, { *pInt_Count = stl_MapSession.size() - 1; //减去自己 } - BaseLib_OperatorMemory_Malloc((XPPPMEM)ppptszListAddr, *pInt_Count, 128); + BaseLib_OperatorMemory_Malloc((XPPPMEM)pppSt_ListUser, *pInt_Count, sizeof(SESSION_FORWARD)); //遍历 auto stl_MapIterator = stl_MapSession.begin(); for (int i = 0; stl_MapIterator != stl_MapSession.end(); stl_MapIterator++, i++) @@ -118,7 +124,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_List(XCHAR*** ppptszListAddr, continue; } } - _tcsxcpy((*ppptszListAddr)[i], stl_MapIterator->first.c_str()); + *(*pppSt_ListUser)[i] = stl_MapIterator->second; } st_Locker.unlock_shared(); return true; @@ -180,6 +186,54 @@ bool CModuleSession_Forward::ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPC return true; } /******************************************************************** +函数名称:ModuleSession_Forward_UNBind +函数功能:解除绑定转发需求 + 参数.一:lpszSrcAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输入绑定的原始地址 + 参数.二:lpszDstAddr + In/Out:In + 类型:常量字符指针 + 可空:N + 意思:输出绑定的目标地址 +返回值 + 类型:逻辑型 + 意思:是否成功 +备注: +*********************************************************************/ +bool CModuleSession_Forward::ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR 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; + } + //解除双方绑定 + stl_MapSrcIterator->second.bForward = false; + memset(stl_MapSrcIterator->second.tszDstAddr, '\0', sizeof(stl_MapSrcIterator->second.tszDstAddr)); + + stl_MapDstIterator->second.bForward = false; + memset(stl_MapDstIterator->second.tszDstAddr, '\0', sizeof(stl_MapDstIterator->second.tszDstAddr)); + st_Locker.unlock_shared(); + return true; +} +/******************************************************************** 函数名称:ModuleSession_Forward_Delete 函数功能:删除用户 参数.一:lpszAddr @@ -190,7 +244,7 @@ bool CModuleSession_Forward::ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPC 参数.二:ptszDstAddr In/Out:Out 类型:字符指针 - 可空:N + 可空:Y 意思:输出解绑的地址 返回值 类型:逻辑型 @@ -220,7 +274,11 @@ bool CModuleSession_Forward::ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHA //如果有转发,需要清理对方的转发设置 if (stl_MapSrcIterator->second.bForward) { - _tcsxcpy(ptszDstAddr, stl_MapSrcIterator->second.tszDstAddr); + if (NULL != ptszDstAddr) + { + _tcsxcpy(ptszDstAddr, stl_MapSrcIterator->second.tszDstAddr); + } + auto stl_MapDstIterator = stl_MapSession.find(stl_MapSrcIterator->second.tszSrcAddr); if (stl_MapDstIterator == stl_MapSession.end()) { diff --git a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h index f1939334c44e05f7282490f2213880703c37ee8f..eb65cb0e522838068c9a6af513e1f7b7b318b590 100644 --- a/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h +++ b/XEngine_Source/XEngine_ModuleSession/ModuleSession_Forward/ModuleSession_Forward.h @@ -10,12 +10,6 @@ // Purpose: 会话转发协议 // History: *********************************************************************/ -typedef struct -{ - XCHAR tszSrcAddr[128]; - XCHAR tszDstAddr[128]; - bool bForward; -}SESSION_FORWARD, * LPSESSION_FORWARD; class CModuleSession_Forward { @@ -23,10 +17,11 @@ public: CModuleSession_Forward(); ~CModuleSession_Forward(); public: - bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr); - bool ModuleSession_Forward_List(XCHAR*** ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr = NULL); + bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH* pSt_UserAuth); + bool ModuleSession_Forward_List(SESSION_FORWARD*** pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr = NULL); bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); - bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR* ptszDstAddr); + bool ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr); + bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR* ptszDstAddr = NULL); bool ModuleSession_Forward_Get(LPCXSTR lpszAddr, XCHAR* ptszDstAddr); private: shared_mutex st_Locker; diff --git a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def index 9a8c8aca31f222a901793b62702d7b6a7dad1ae2..f04006375134c4a7506aaaeaea070137d2171948 100644 --- a/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def +++ b/XEngine_Source/XEngine_ModuleSession/XEngine_ModuleSession.def @@ -6,5 +6,6 @@ EXPORTS ModuleSession_Forward_Insert ModuleSession_Forward_List ModuleSession_Forward_Bind + ModuleSession_Forward_UNBind ModuleSession_Forward_Delete ModuleSession_Forward_Get \ No newline at end of file diff --git a/XEngine_Source/XEngine_ModuleSession/pch.cpp b/XEngine_Source/XEngine_ModuleSession/pch.cpp index e6741b2c306ed3583116dbe502dd78fc5a667720..68c76a32f3093b9ed51d0de1b678895d97e26ec6 100644 --- a/XEngine_Source/XEngine_ModuleSession/pch.cpp +++ b/XEngine_Source/XEngine_ModuleSession/pch.cpp @@ -29,18 +29,22 @@ extern "C" XLONG ModuleSession_GetLastError(int* pInt_SysError) /************************************************************************/ /* 转发导出函数 */ /************************************************************************/ -extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr) +extern "C" bool ModuleSession_Forward_Insert(LPCXSTR lpszAddr, XENGINE_PROTOCOL_USERAUTH * pSt_UserAuth) { - return m_Forward.ModuleSession_Forward_Insert(lpszAddr); + return m_Forward.ModuleSession_Forward_Insert(lpszAddr, pSt_UserAuth); } -extern "C" bool ModuleSession_Forward_List(XCHAR * **ppptszListAddr, int* pInt_Count, LPCXSTR lpszAddr) +extern "C" bool ModuleSession_Forward_List(SESSION_FORWARD * **pppSt_ListUser, int* pInt_Count, LPCXSTR lpszAddr) { - return m_Forward.ModuleSession_Forward_List(ppptszListAddr, pInt_Count, lpszAddr); + return m_Forward.ModuleSession_Forward_List(pppSt_ListUser, pInt_Count, lpszAddr); } extern "C" bool ModuleSession_Forward_Bind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr) { return m_Forward.ModuleSession_Forward_Bind(lpszSrcAddr, lpszDstAddr); } +extern "C" bool ModuleSession_Forward_UNBind(LPCXSTR lpszSrcAddr, LPCXSTR lpszDstAddr) +{ + return m_Forward.ModuleSession_Forward_UNBind(lpszSrcAddr, lpszDstAddr); +} extern "C" bool ModuleSession_Forward_Delete(LPCXSTR lpszAddr, XCHAR * ptszDstAddr) { return m_Forward.ModuleSession_Forward_Delete(lpszAddr, ptszDstAddr); diff --git a/XEngine_Source/XEngine_ModuleSession/pch.h b/XEngine_Source/XEngine_ModuleSession/pch.h index bf917ba04155bdbd114e80b6415918ca059ba130..7821a374cd94a8e4af1c28d4086a75ba4b4325ff 100644 --- a/XEngine_Source/XEngine_ModuleSession/pch.h +++ b/XEngine_Source/XEngine_ModuleSession/pch.h @@ -20,6 +20,7 @@ using namespace std; #include #include +#include #include #include #include "ModuleSession_Define.h" diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp index debf044a5c1b540c0bcf21c3d564c2a47bc68f30..007394dd72e831947e2f7eec66373e8d3a87b58c 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_ForwardTask.cpp @@ -22,7 +22,7 @@ XHTHREAD CALLBACK XEngine_Forward_Thread(XPVOID lParam) continue; } int nListCount = 0; - HELPCOMPONENT_PACKET_CLIENT** ppSt_ListClient; + XENGINE_MANAGEPOOL_TASKEVENT** ppSt_ListClient; HelpComponents_Datas_GetPoolEx(xhForwardPacket, nThreadPos, &ppSt_ListClient, &nListCount); for (int i = 0; i < nListCount; i++) { @@ -47,21 +47,22 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n int nSDLen = 10240; XCHAR 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, _X("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) { + XENGINE_PROTOCOL_USERAUTH st_UserAuth; + memset(&st_UserAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH)); + + memcpy(&st_UserAuth, lpszMsgBuffer, sizeof(XENGINE_PROTOCOL_USERAUTH)); + + pSt_ProtocolHdr->wReserve = 0; + pSt_ProtocolHdr->unPacketSize = 0; pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LOGREP; - ModuleSession_Forward_Insert(lpszClientAddr); + ModuleSession_Forward_Insert(lpszClientAddr, &st_UserAuth); XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); - XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,登录到服务器"), lpszClientAddr); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,设置的用户:%s,登录到服务器"), lpszClientAddr, st_UserAuth.tszUserName); } } //处理转发协议 @@ -70,12 +71,13 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREQ == pSt_ProtocolHdr->unOperatorCode) { int nListCount = 0; - XCHAR** pptszListAddr; + SESSION_FORWARD** ppSt_ListUser; pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_LISTREP; - if (ModuleSession_Forward_List(&pptszListAddr, &nListCount, lpszClientAddr)) + if (ModuleSession_Forward_List(&ppSt_ListUser, &nListCount, lpszClientAddr)) { - ModuleProtocol_Packet_ForwardList(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, &pptszListAddr, nListCount); + ModuleProtocol_Packet_ForwardList(tszSDBuffer, &nSDLen, pSt_ProtocolHdr, &ppSt_ListUser, nListCount); + BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_ListUser, nListCount); XEngine_Network_Send(lpszClientAddr, tszSDBuffer, nSDLen, XENGINE_CLIENT_NETTYPE_FORWARD); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求可用转发列表成功"), lpszClientAddr); } @@ -113,6 +115,38 @@ bool XEngine_Forward_Handle(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int n XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求绑定转发地址:%s 成功"), lpszClientAddr, tszDstAddr); } + else if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREQ == pSt_ProtocolHdr->unOperatorCode) + { + XCHAR tszDstAddr[128]; + memset(tszDstAddr, '\0', sizeof(tszDstAddr)); + + if (!ModuleSession_Forward_Get(lpszClientAddr, tszDstAddr)) + { + pSt_ProtocolHdr->wReserve = 411; + pSt_ProtocolHdr->unPacketSize = 0; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP; + XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Forward客户端:%s,请求解绑失败,错误:%lX"), lpszClientAddr, ModuleSession_GetLastError()); + return false; + } + if (!ModuleSession_Forward_UNBind(lpszClientAddr, tszDstAddr)) + { + pSt_ProtocolHdr->wReserve = 411; + pSt_ProtocolHdr->unPacketSize = 0; + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP; + XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("Forward客户端:%s,请求解绑失败,解除绑定的地址:%s,错误:%lX"), lpszClientAddr, tszDstAddr, ModuleSession_GetLastError()); + return false; + } + //先告知对方要转发数据 + pSt_ProtocolHdr->wReserve = 0; + pSt_ProtocolHdr->unPacketSize = 0; + XEngine_Network_Send(tszDstAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + //最后返回结果 + pSt_ProtocolHdr->unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_FORWARD_UNREP; + XEngine_Network_Send(lpszClientAddr, (LPCXSTR)pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR), XENGINE_CLIENT_NETTYPE_FORWARD); + XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,请求解绑转发地址:%s 成功"), lpszClientAddr, tszDstAddr); + } } return true; diff --git a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp index 5b7a8018bc6169d99f0806ceed73f367e5c4e850..1148c50204da4e6315b890eb0d22de36bcfa1d32 100644 --- a/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp +++ b/XEngine_Source/XEngine_ServiceApp/XEngine_Network.cpp @@ -61,6 +61,7 @@ void CALLBACK Network_Callback_TunnelHeart(LPCXSTR lpszClientAddr, XSOCKET hSock //////////////////////////////////////////////////////////////////////////下面是Tunnel网络IO相关代码处理函数 bool CALLBACK Network_Callback_ForwardLogin(LPCXSTR lpszClientAddr, XSOCKET hSocket, XPVOID lParam) { + HelpComponents_Datas_CreateEx(xhForwardPacket, lpszClientAddr); SocketOpt_HeartBeat_InsertAddrEx(xhForwardHeart, lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,连接到服务器"), lpszClientAddr); return true; @@ -177,14 +178,8 @@ void XEngine_Network_Close(LPCXSTR lpszClientAddr, int nIPProto, int nCloseType) SocketOpt_HeartBeat_DeleteAddrEx(xhForwardHeart, lpszClientAddr); NetCore_TCPXCore_CloseForClientEx(xhForwardSocket, lpszClientAddr); } - XCHAR tszClientAddr[128]; - memset(tszClientAddr, '\0', sizeof(tszClientAddr)); - ModuleSession_Forward_Delete(lpszClientAddr, tszClientAddr); - - if (_tcsxlen(tszClientAddr) > 0) - { - XEngine_Network_Close(tszClientAddr, XENGINE_CLIENT_NETTYPE_FORWARD, XENGINE_CLIENT_CLOSE_SERVICE); - } + HelpComponents_Datas_DeleteEx(xhForwardPacket, lpszClientAddr); + ModuleSession_Forward_Delete(lpszClientAddr); XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _X("Forward客户端:%s,离开服务器,离开类型;%d"), lpszClientAddr, nCloseType); } else