Skip to content

Commit 4f8e89c

Browse files
committed
delete:p2xp client module.
added:p2xp client test app fixed:p2xp protocol module return size is error fixed:p2xp client is not delete from peer module fixed:string Codec error
1 parent 5868da6 commit 4f8e89c

File tree

20 files changed

+248
-1157
lines changed

20 files changed

+248
-1157
lines changed
Lines changed: 216 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,221 @@
1-
// APPClient_P2XPClient.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
2-
//
1+
#ifdef _WINDOWS
2+
#include <windows.h>
3+
#include <tchar.h>
4+
#else
5+
#endif
6+
#include <json/json.h>
7+
#include <XEngine_Include/XEngine_CommHdr.h>
8+
#include <XEngine_Include/XEngine_ProtocolHdr.h>
9+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
10+
#include <XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
11+
#include <XEngine_Include/XEngine_Client/XClient_Define.h>
12+
#include <XEngine_Include/XEngine_Client/XClient_Error.h>
13+
#include <XEngine_Include/XEngine_Core/NetXApi_Define.h>
14+
#include <XEngine_Include/XEngine_Core/NetXApi_Error.h>
15+
#include <XEngine_Include/XEngine_NetHelp/APIHelp_Define.h>
16+
#include <XEngine_Include/XEngine_NetHelp/APIHelp_Error.h>
17+
#include "../../XEngine_Source/XStorage_Protocol.h"
318

4-
#include <iostream>
19+
#pragma comment(lib,"x86/XEngine_BaseLib/XEngine_BaseLib")
20+
#pragma comment(lib,"x86/XEngine_Client/XClient_Socket")
21+
#pragma comment(lib,"x86/XEngine_Core/XEngine_NetXApi")
22+
#pragma comment(lib,"x86/XEngine_NetHelp/NetHelp_APIHelp")
23+
#pragma comment(lib,"Ws2_32")
24+
25+
LPCTSTR lpszUserName = _T("123123aa");
26+
LPCTSTR lpszAddr = _T("192.168.1.7");
27+
28+
TCHAR tszPublicAddr[128];
29+
TCHAR tszPrivateAddr[128];
30+
31+
int nPort = 5103;
32+
SOCKET m_hSocket;
33+
34+
int APPClient_P2XPLogin()
35+
{
36+
DWORD dwNetType = 0;
37+
Json::Value st_JsonRoot;
38+
TCHAR tszMsgBuffer[2048];
39+
XENGINE_PROTOCOLHDR st_ProtocolHdr;
40+
41+
memset(tszPublicAddr, '\0', sizeof(tszPublicAddr));
42+
memset(tszPrivateAddr, '\0', sizeof(tszPrivateAddr));
43+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
44+
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
45+
46+
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
47+
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_P2XP;
48+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN;
49+
st_ProtocolHdr.byVersion = 2;
50+
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
51+
52+
//获取网络连接类型
53+
if (!NetXApi_Socket_GetNetConnectType(&dwNetType))
54+
{
55+
return -1;
56+
}
57+
int nListCount = 0;
58+
APIHELP_NETCARD** ppSt_APICard;
59+
if (!APIHelp_NetWork_GetIPAddr(&ppSt_APICard, &nListCount, TRUE, tszPublicAddr))
60+
{
61+
return -1;
62+
}
63+
if (nListCount <= 0)
64+
{
65+
return -1;
66+
}
67+
_tcscpy(tszPrivateAddr, ppSt_APICard[0]->tszIPAddr);
68+
BaseLib_OperatorMemory_Free((XPPPMEM)&ppSt_APICard, nListCount);
69+
70+
st_JsonRoot["tszUserName"] = lpszUserName;
71+
st_JsonRoot["tszPrivateAddr"] = tszPrivateAddr;
72+
st_JsonRoot["tszPublicAddr"] = tszPublicAddr;
73+
st_JsonRoot["dwConnectType"] = (Json::Value::UInt)dwNetType;
74+
st_JsonRoot["dwPeerType"] = 0;
75+
st_ProtocolHdr.unPacketSize = st_JsonRoot.toStyledString().length();
76+
77+
int nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
78+
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
79+
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), st_ProtocolHdr.unPacketSize);
80+
81+
if (!XClient_TCPSelect_SendMsg(m_hSocket, tszMsgBuffer, nMsgLen))
82+
{
83+
return -1;
84+
}
85+
86+
nMsgLen = sizeof(tszMsgBuffer);
87+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
88+
XClient_TCPSelect_RecvMsg(m_hSocket, tszMsgBuffer, &nMsgLen, FALSE);
89+
90+
printf("APPClient_P2XPLogin:%s\n", tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR));
91+
return 0;
92+
}
93+
94+
int APPClient_P2XPList()
95+
{
96+
Json::Value st_JsonRoot;
97+
TCHAR tszMsgBuffer[2048];
98+
XENGINE_PROTOCOLHDR st_ProtocolHdr;
99+
100+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
101+
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
102+
103+
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
104+
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_P2XP;
105+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_P2XP_REQLANLIST;
106+
st_ProtocolHdr.byVersion = 2;
107+
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
108+
109+
st_JsonRoot["tszPublicAddr"] = tszPublicAddr;
110+
st_JsonRoot["tszPrivateAddr"] = tszPrivateAddr;
111+
112+
st_ProtocolHdr.unPacketSize = st_JsonRoot.toStyledString().length();
113+
114+
int nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
115+
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
116+
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), st_ProtocolHdr.unPacketSize);
117+
118+
if (!XClient_TCPSelect_SendMsg(m_hSocket, tszMsgBuffer, nMsgLen))
119+
{
120+
return -1;
121+
}
122+
123+
nMsgLen = sizeof(tszMsgBuffer);
124+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
125+
XClient_TCPSelect_RecvMsg(m_hSocket, tszMsgBuffer, &nMsgLen, FALSE);
126+
127+
printf("APPClient_P2XPList:%s\n", tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR));
128+
return 0;
129+
}
130+
131+
int APPClient_P2XPGetUser()
132+
{
133+
Json::Value st_JsonRoot;
134+
TCHAR tszMsgBuffer[2048];
135+
XENGINE_PROTOCOLHDR st_ProtocolHdr;
136+
137+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
138+
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
139+
140+
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
141+
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_P2XP;
142+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_P2XP_REQUSERQUERY;
143+
st_ProtocolHdr.byVersion = 2;
144+
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
145+
146+
st_JsonRoot["tszUserName"] = lpszUserName;
147+
148+
st_ProtocolHdr.unPacketSize = st_JsonRoot.toStyledString().length();
149+
150+
int nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
151+
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
152+
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), st_ProtocolHdr.unPacketSize);
153+
154+
if (!XClient_TCPSelect_SendMsg(m_hSocket, tszMsgBuffer, nMsgLen))
155+
{
156+
return -1;
157+
}
158+
159+
nMsgLen = sizeof(tszMsgBuffer);
160+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
161+
XClient_TCPSelect_RecvMsg(m_hSocket, tszMsgBuffer, &nMsgLen, FALSE);
162+
163+
printf("APPClient_P2XPGetUser:%s\n", tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR));
164+
return 0;
165+
}
166+
167+
int APPClient_P2XPConnect()
168+
{
169+
Json::Value st_JsonRoot;
170+
TCHAR tszMsgBuffer[2048];
171+
XENGINE_PROTOCOLHDR st_ProtocolHdr;
172+
173+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
174+
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
175+
176+
st_ProtocolHdr.wHeader = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_HEADER;
177+
st_ProtocolHdr.unOperatorType = ENUM_XENGINE_COMMUNICATION_PROTOCOL_TYPE_P2XP;
178+
st_ProtocolHdr.unOperatorCode = XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_P2XP_REQCONNECT;
179+
st_ProtocolHdr.byVersion = 2;
180+
st_ProtocolHdr.wTail = XENGIEN_COMMUNICATION_PACKET_PROTOCOL_TAIL;
181+
182+
st_JsonRoot["tszPublicAddr"] = tszPublicAddr;
183+
st_JsonRoot["tszPrivateAddr"] = tszPrivateAddr;
184+
185+
st_ProtocolHdr.unPacketSize = st_JsonRoot.toStyledString().length();
186+
187+
int nMsgLen = sizeof(XENGINE_PROTOCOLHDR) + st_ProtocolHdr.unPacketSize;
188+
memcpy(tszMsgBuffer, &st_ProtocolHdr, sizeof(XENGINE_PROTOCOLHDR));
189+
memcpy(tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR), st_JsonRoot.toStyledString().c_str(), st_ProtocolHdr.unPacketSize);
190+
191+
if (!XClient_TCPSelect_SendMsg(m_hSocket, tszMsgBuffer, nMsgLen))
192+
{
193+
return -1;
194+
}
195+
196+
nMsgLen = sizeof(tszMsgBuffer);
197+
memset(tszMsgBuffer, '\0', sizeof(tszMsgBuffer));
198+
XClient_TCPSelect_RecvMsg(m_hSocket, tszMsgBuffer, &nMsgLen, FALSE);
199+
200+
printf("%s\n", tszMsgBuffer + sizeof(XENGINE_PROTOCOLHDR));
201+
return 0;
202+
}
5203

6204
int main()
7205
{
8-
std::cout << "Hello World!\n";
206+
WSADATA st_WSAData;
207+
WSAStartup(MAKEWORD(2, 2), &st_WSAData);
208+
209+
if (!XClient_TCPSelect_Create(&m_hSocket, lpszAddr, nPort))
210+
{
211+
return -1;
212+
}
213+
APPClient_P2XPLogin();
214+
APPClient_P2XPList();
215+
APPClient_P2XPGetUser();
216+
APPClient_P2XPConnect();
217+
218+
XClient_TCPSelect_Close(m_hSocket);
219+
WSACleanup();
220+
return 0;
9221
}

XEngine_APPClient/APPClient_P2XPClient/APPClient_P2XPClient.vcxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ConfigurationType>Application</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
3232
<PlatformToolset>v142</PlatformToolset>
33-
<CharacterSet>Unicode</CharacterSet>
33+
<CharacterSet>MultiByte</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>Application</ConfigurationType>
@@ -72,6 +72,8 @@
7272
<PropertyGroup Label="UserMacros" />
7373
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7474
<LinkIncremental>true</LinkIncremental>
75+
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
76+
<LibraryPath>$(XEngine_Library);$(LibraryPath)</LibraryPath>
7577
</PropertyGroup>
7678
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7779
<LinkIncremental>false</LinkIncremental>
@@ -86,7 +88,7 @@
8688
<ClCompile>
8789
<WarningLevel>Level3</WarningLevel>
8890
<SDLCheck>true</SDLCheck>
89-
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
91+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
9092
<ConformanceMode>true</ConformanceMode>
9193
</ClCompile>
9294
<Link>

XEngine_APPClient/StorageModule_P2PClient/P2XPClient_Define.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

XEngine_APPClient/StorageModule_P2PClient/P2XPClient_Error.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)