Skip to content

Commit 936c4a0

Browse files
committed
added:wlan packet protocol function
1 parent 1e86644 commit 936c4a0

File tree

5 files changed

+165
-15
lines changed

5 files changed

+165
-15
lines changed

XEngine_Source/XEngine_P2XPComponents/XEngine_P2XPProtocol/P2XPProtocol_Define.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,35 @@ extern "C" BOOL P2XPProtocol_Packet_Common(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr
185185
*********************************************************************/
186186
extern "C" BOOL P2XPProtocol_Packet_Lan(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_P2XPPEER_PROTOCOL*** pppSt_ListClients, int nListCount, TCHAR* ptszMsgBuffer, int* pInt_Len);
187187
/********************************************************************
188+
函数名称:P2XPProtocol_Packet_WLan
189+
函数功能:响应同步局域网所有地址列表
190+
参数.一:pSt_ProtocolHdr
191+
In/Out:In
192+
类型:数据结构指针
193+
可空:N
194+
意思:输入要打包的协议头
195+
参数.二:pStl_ListClients
196+
In/Out:In
197+
类型:容器指针
198+
可空:N
199+
意思:客户端列表
200+
参数.三:ptszMsgBuffer
201+
In/Out:Out
202+
类型:字符指针
203+
可空:N
204+
意思:导出封装好的缓冲区
205+
参数.四:pInt_MsgLen
206+
In/Out:In/Out
207+
类型:整数型指针
208+
可空:N
209+
意思:输入你的缓冲区大小,输出缓冲区真实大小
210+
返回值
211+
类型:逻辑型
212+
意思:是否成功
213+
备注:
214+
*********************************************************************/
215+
extern "C" BOOL P2XPProtocol_Packet_WLan(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, list<XENGINE_P2XPPEER_PROTOCOL>* pStl_ListClients, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
216+
/********************************************************************
188217
函数名称:P2XPProtocol_Packet_User
189218
函数功能:响应用户查询用户信息的请求协议封包函数
190219
参数.一:pSt_ProtocolHdr

XEngine_Source/XEngine_P2XPComponents/XEngine_P2XPProtocol/P2XPProtocol_Packet/P2XPProtocol_Packet.cpp

Lines changed: 115 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,127 @@ BOOL CP2XPProtocol_Packet::P2XPProtocol_Packet_Lan(XENGINE_PROTOCOLHDR* pSt_Prot
117117
P2XPProtocol_dwErrorCode = ERROR_XENGINE_P2XP_PROTOCOL_PARAMENT;
118118
return FALSE;
119119
}
120-
Json::Value st_JsonRoot;
121-
Json::Value st_JsonArray;
122-
for (int i = 0; i < nListCount; i++)
123-
{
124-
Json::Value st_JsonObject;
125-
st_JsonObject["ClientUser"] = (*pppSt_ListClients)[i]->tszUserName;
126-
st_JsonObject["ClientAddr"] = (*pppSt_ListClients)[i]->tszPrivateAddr;
127-
st_JsonArray.append(st_JsonObject);
128-
}
129-
st_JsonRoot["nCode"] = 0;
130-
st_JsonRoot["lpszMsgBuffer"] = "sucess";
131-
st_JsonRoot["ClientArray"] = st_JsonArray;
132-
st_JsonRoot["ClientCount"] = nListCount;
120+
Json::Value st_JsonRoot;
121+
Json::Value st_JsonArray;
122+
for (int i = 0; i < nListCount; i++)
123+
{
124+
Json::Value st_JsonObject;
125+
st_JsonObject["ClientUser"] = (*pppSt_ListClients)[i]->tszUserName;
126+
st_JsonObject["ClientAddr"] = (*pppSt_ListClients)[i]->tszPrivateAddr;
127+
st_JsonArray.append(st_JsonObject);
128+
}
129+
st_JsonRoot["nCode"] = 0;
130+
st_JsonRoot["lpszMsgBuffer"] = "sucess";
131+
st_JsonRoot["ClientArray"] = st_JsonArray;
132+
st_JsonRoot["ClientCount"] = nListCount;
133133

134134
pSt_ProtocolHdr->unPacketSize = st_JsonRoot.toStyledString().length();
135135

136136
*pInt_MsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_JsonRoot.toStyledString().length();
137137
memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
138138
memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), pSt_ProtocolHdr->unPacketSize);
139-
return TRUE;
139+
return TRUE;
140+
}
141+
/********************************************************************
142+
函数名称:P2XPProtocol_Packet_WLan
143+
函数功能:响应同步局域网所有地址列表
144+
参数.一:pSt_ProtocolHdr
145+
In/Out:In
146+
类型:数据结构指针
147+
可空:N
148+
意思:输入要打包的协议头
149+
参数.二:pStl_ListClients
150+
In/Out:In
151+
类型:容器指针
152+
可空:N
153+
意思:客户端列表
154+
参数.三:ptszMsgBuffer
155+
In/Out:Out
156+
类型:字符指针
157+
可空:N
158+
意思:导出封装好的缓冲区
159+
参数.四:pInt_MsgLen
160+
In/Out:In/Out
161+
类型:整数型指针
162+
可空:N
163+
意思:输入你的缓冲区大小,输出缓冲区真实大小
164+
返回值
165+
类型:逻辑型
166+
意思:是否成功
167+
备注:
168+
*********************************************************************/
169+
BOOL CP2XPProtocol_Packet::P2XPProtocol_Packet_WLan(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, list<XENGINE_P2XPPEER_PROTOCOL>* pStl_ListClients, TCHAR* ptszMsgBuffer, int* pInt_MsgLen)
170+
{
171+
P2XPProtocol_IsErrorOccur = FALSE;
172+
173+
if ((NULL == pStl_ListClients) || (NULL == ptszMsgBuffer) || (NULL == pInt_MsgLen))
174+
{
175+
P2XPProtocol_IsErrorOccur = FALSE;
176+
P2XPProtocol_dwErrorCode = ERROR_XENGINE_P2XP_PROTOCOL_PARAMENT;
177+
return FALSE;
178+
}
179+
unordered_map<tstring, list<P2XPPROTOCOL_LANPACKET>> stl_MapClient;
180+
//首先处理公网下的局域网网段列表
181+
for (auto stl_ListIterator = pStl_ListClients->begin(); stl_ListIterator != pStl_ListClients->end(); stl_ListIterator++)
182+
{
183+
TCHAR tszClientAddr[128];
184+
XENGINE_LIBADDR st_LibAddr;
185+
P2XPPROTOCOL_LANPACKET st_LANPacket;
186+
187+
memset(tszClientAddr, '\0', sizeof(tszClientAddr));
188+
memset(&st_LibAddr, '\0', sizeof(XENGINE_LIBADDR));
189+
memset(&st_LANPacket, '\0', sizeof(P2XPPROTOCOL_LANPACKET));
190+
//分割
191+
BaseLib_OperatorIPAddr_IsIPV4Addr(stl_ListIterator->tszPrivateAddr, &st_LibAddr);
192+
_stprintf(tszClientAddr, _T("%d.%d.%d"), st_LibAddr.nIPAddr1, st_LibAddr.nIPAddr2, st_LibAddr.nIPAddr3);
193+
//赋值
194+
_tcscpy(st_LANPacket.tszUsername, stl_ListIterator->tszUserName);
195+
_tcscpy(st_LANPacket.tszClientAddr, stl_ListIterator->tszPrivateAddr);
196+
//判断是否存在
197+
unordered_map<tstring, list<P2XPPROTOCOL_LANPACKET>>::iterator stl_MapIterator = stl_MapClient.find(tszClientAddr);
198+
if (stl_MapIterator == stl_MapClient.end())
199+
{
200+
list<P2XPPROTOCOL_LANPACKET> stl_ListClient;
201+
202+
stl_ListClient.push_back(st_LANPacket);
203+
stl_MapClient.insert(make_pair(tszClientAddr, stl_ListClient));
204+
}
205+
else
206+
{
207+
stl_MapIterator->second.push_back(st_LANPacket);
208+
}
209+
}
210+
//打包成JSON数据
211+
int nCount = 0;
212+
Json::Value st_JsonRoot;
213+
Json::Value st_JsonArray;
214+
215+
for (auto stl_MapIterator = stl_MapClient.begin(); stl_MapIterator != stl_MapClient.end(); stl_MapIterator++)
216+
{
217+
Json::Value st_JsonList;
218+
for (auto stl_ListIterator = stl_MapIterator->second.begin(); stl_ListIterator != stl_MapIterator->second.end(); stl_ListIterator++)
219+
{
220+
Json::Value st_JsonObject;
221+
222+
nCount++;
223+
st_JsonObject["ClientUser"] = stl_ListIterator->tszUsername;
224+
st_JsonObject["ClientAddr"] = stl_ListIterator->tszClientAddr;
225+
st_JsonList.append(st_JsonObject);
226+
}
227+
st_JsonArray["tszLANAddr"] = stl_MapIterator->first.c_str();
228+
st_JsonArray["tszLANList"] = st_JsonList;
229+
}
230+
st_JsonRoot["nCode"] = 0;
231+
st_JsonRoot["lpszMsgBuffer"] = "sucess";
232+
st_JsonRoot["ClientArray"] = st_JsonArray;
233+
st_JsonRoot["ClientCount"] = nCount;
234+
235+
pSt_ProtocolHdr->unPacketSize = st_JsonRoot.toStyledString().length();
236+
237+
*pInt_MsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_JsonRoot.toStyledString().length();
238+
memcpy(ptszMsgBuffer, pSt_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
239+
memcpy(ptszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), pSt_ProtocolHdr->unPacketSize);
240+
return TRUE;
140241
}
141242
/********************************************************************
142243
函数名称:P2XPProtocol_Packet_User

XEngine_Source/XEngine_P2XPComponents/XEngine_P2XPProtocol/P2XPProtocol_Packet/P2XPProtocol_Packet.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
// Purpose: 打包类
1010
// History:
1111
*********************************************************************/
12+
typedef struct
13+
{
14+
TCHAR tszUsername[MAX_PATH];
15+
TCHAR tszClientAddr[128];
16+
}P2XPPROTOCOL_LANPACKET;
1217

1318
class CP2XPProtocol_Packet
1419
{
@@ -18,6 +23,7 @@ class CP2XPProtocol_Packet
1823
public:
1924
BOOL P2XPProtocol_Packet_Common(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, TCHAR* ptszMsgBuffer, int* pInt_MsgLen, int nCode = 0, LPCTSTR lpszMsgBuffer = NULL);
2025
BOOL P2XPProtocol_Packet_Lan(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_P2XPPEER_PROTOCOL*** pppSt_ListClients, int nListCount, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
26+
BOOL P2XPProtocol_Packet_WLan(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, list<XENGINE_P2XPPEER_PROTOCOL>* pStl_ListClients, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
2127
BOOL P2XPProtocol_Packet_User(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_P2XPPEER_PROTOCOL* pSt_PeerInfo, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
2228
BOOL P2XPProtocol_Packet_Connect(XENGINE_PROTOCOLHDR* pSt_ProtocolHdr, XENGINE_P2XPIO_PROTOCOL* pSt_IOProtocol, TCHAR* ptszMsgBuffer, int* pInt_MsgLen);
2329
protected:

XEngine_Source/XEngine_P2XPComponents/XEngine_P2XPProtocol/pch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ extern "C" BOOL P2XPProtocol_Packet_Lan(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, X
5656
{
5757
return m_P2XPPacket.P2XPProtocol_Packet_Lan(pSt_ProtocolHdr, pppSt_ListClients, nListCount, ptszMsgBuffer, pInt_Len);
5858
}
59+
extern "C" BOOL P2XPProtocol_Packet_WLan(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, list<XENGINE_P2XPPEER_PROTOCOL>*pStl_ListClients, TCHAR * ptszMsgBuffer, int* pInt_MsgLen)
60+
{
61+
return m_P2XPPacket.P2XPProtocol_Packet_WLan(pSt_ProtocolHdr, pStl_ListClients, ptszMsgBuffer, pInt_MsgLen);
62+
}
5963
extern "C" BOOL P2XPProtocol_Packet_User(XENGINE_PROTOCOLHDR * pSt_ProtocolHdr, XENGINE_P2XPPEER_PROTOCOL * pSt_PeerInfo, TCHAR * ptszMsgBuffer, int* pInt_Len)
6064
{
6165
return m_P2XPPacket.P2XPProtocol_Packet_User(pSt_ProtocolHdr, pSt_PeerInfo, ptszMsgBuffer, pInt_Len);

XEngine_Source/XEngine_P2XPComponents/XEngine_P2XPProtocol/pch.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ using namespace std;
3636
#include <XEngine_Include/XEngine_CommHdr.h>
3737
#include <XEngine_Include/XEngine_Types.h>
3838
#include <XEngine_Include/XEngine_ProtocolHdr.h>
39+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
40+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
3941
#include "../../XStorage_Protocol.h"
4042
#include "P2XPProtocol_Define.h"
4143
#include "P2XPProtocol_Error.h"
@@ -57,4 +59,12 @@ extern DWORD P2XPProtocol_dwErrorCode;
5759
typedef std::wstring tstring;
5860
#else
5961
typedef std::string tstring;
60-
#endif
62+
#endif
63+
64+
#ifdef _WINDOWS
65+
#ifdef _WIN64
66+
#pragma comment(lib,"x64/XEngine_BaseLib/XEngine_BaseLib.lib")
67+
#else
68+
#pragma comment(lib,"x86/XEngine_BaseLib/XEngine_BaseLib.lib")
69+
#endif
70+
#endif

0 commit comments

Comments
 (0)