forked from LiXizhi/TMInterface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestInterfaceTM.cpp
More file actions
247 lines (191 loc) · 7.1 KB
/
Copy pathTestInterfaceTM.cpp
File metadata and controls
247 lines (191 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#include <stdio.h>
#include "pdumanip.hpp"
#include "byteswap.hpp"
#include "MsgTM.hpp"
#include <string>
#include <boost/asio.hpp>
#include "MD5.h"
#include "TMService.hpp"
using boost::asio::ip::tcp;
using namespace std;
using namespace taomee;
void EncodeRegist(char *pkgbuf,int &iOutLength)
{
MsgTMHead msgHead;
MsgTMRegister msgRegister;
char sSrcString[32];
sprintf(sSrcString,"passwd");
unsigned char md5value[MD5::LENGTH];
MD5::GenerateDigest((const unsigned char*)sSrcString, 6, md5value);
string sDlMD5String = MD5::ToHexString(md5value);
printf("md5:%s\n",sDlMD5String.c_str());
sprintf(msgRegister.passwd,"%s",sDlMD5String.c_str());
sprintf(msgRegister.email,"gosling_test3@paraengine.com");
msgRegister.sex[0]=1;
msgRegister.register_type = 111;
msgRegister.birthday = 1253000093;
msgRegister.Encode(pkgbuf+HEAD_LENGTH,iOutLength);
string sTemp=MD5::ToHexFormat(pkgbuf+HEAD_LENGTH,iOutLength);
printf("body length:%d,%s\n",iOutLength,sTemp.c_str());
msgHead.PkgLen = iOutLength+HEAD_LENGTH;
msgHead.Version = 1;
msgHead.CommandID = 0x0002;
msgHead.UserID = 13220;
msgHead.Result = 0;
msgHead.Encode(pkgbuf,iOutLength);
sTemp=MD5::ToHexFormat(pkgbuf,iOutLength);
printf("head length:%d,%s\n",iOutLength,sTemp.c_str());
iOutLength = msgHead.PkgLen;
printf("Encoding End...................\n");
}
void DecodeRegist(const char *pkgbuf, const int iInLength)
{
MsgTMHead msgHead;
MsgTMRegister msgRegister;
msgHead.Decode(pkgbuf,iInLength);
printf("len:%d,Version:%d,commandId:%d,UserID:%d,Result:%d\n",msgHead.PkgLen,msgHead.Version,msgHead.CommandID,msgHead.UserID,msgHead.Result);
if(msgHead.PkgLen > HEAD_LENGTH)
{
msgRegister.Decode(pkgbuf+HEAD_LENGTH,msgHead.PkgLen-HEAD_LENGTH);
string sTemp=MD5::ToHexFormat(msgRegister.session,SESSION_LENGTH);
printf("session,%s\n",sTemp.c_str());
printf("session:%s\n",msgRegister.session);
}
}
void EncodeGetID(char *pkgbuf,int &iOutLength)
{
TMDBProxyHead msgHead;
TMDBProxyGetID msgGetID;
sprintf(msgGetID.email,"gosling_test1@paraengine.com");
msgGetID.Encode(pkgbuf+DBPROXY_HEAD_LENGTH,iOutLength);
string sTemp=MD5::ToHexFormat(pkgbuf+DBPROXY_HEAD_LENGTH,iOutLength);
printf("body length:%d,%s\n",iOutLength,sTemp.c_str());
msgHead.PkgLen = iOutLength+DBPROXY_HEAD_LENGTH;
msgHead.Seq = 1;
msgHead.CommandID = CMD_GET_TAOMEE_ID;
msgHead.Result = 0;
msgHead.UserID = 0;
msgHead.Encode(pkgbuf,iOutLength);
sTemp=MD5::ToHexFormat(pkgbuf,iOutLength);
printf("head length:%d,%s\n",iOutLength,sTemp.c_str());
iOutLength = msgHead.PkgLen;
printf("Encoding End...................\n");
}
void DecodeGetID(const char *pkgbuf, const int iInLength)
{
TMDBProxyHead msgHead;
TMDBProxyGetID msgGetID;
msgHead.Decode(pkgbuf,iInLength);
printf("len:%d,Seq:%d,commandId:%d,UserID:%d,Result:%d\n",msgHead.PkgLen,msgHead.Seq,msgHead.CommandID,msgHead.UserID,msgHead.Result);
if(msgHead.PkgLen > DBPROXY_HEAD_LENGTH)
{
msgGetID.Decode(pkgbuf+DBPROXY_HEAD_LENGTH,msgHead.PkgLen-DBPROXY_HEAD_LENGTH);
printf("return:%d\n",msgGetID.map_userid);
}
}
void EncodeLogin(char *pkgbuf,int &iOutLength)
{
TMDBProxyHead msgHead;
TMDBProxyLogin msgLogin;
char sSrcString[32];
sprintf(sSrcString,"passwd");
unsigned char md5value[MD5::LENGTH];
MD5::GenerateDigest((const unsigned char*)sSrcString, 6, md5value);
string sDlMD5String = MD5::ToHexString(md5value);
printf("md5:%s\n",sDlMD5String.c_str());
msgLogin.SetPassword(sDlMD5String.c_str(),32);
msgLogin.ip = 0;
msgLogin.login_channel = 31;
msgLogin.Encode(pkgbuf+DBPROXY_HEAD_LENGTH,iOutLength);
string sTemp=MD5::ToHexFormat(pkgbuf+DBPROXY_HEAD_LENGTH,iOutLength);
printf("body length:%d,%s\n",iOutLength,sTemp.c_str());
msgHead.PkgLen = iOutLength+DBPROXY_HEAD_LENGTH;
msgHead.Seq = 1;
msgHead.CommandID = CMD_LOGIN;
msgHead.Result = 0;
msgHead.UserID = 40612277;
msgHead.Encode(pkgbuf,iOutLength);
sTemp=MD5::ToHexFormat(pkgbuf,iOutLength);
printf("head length:%d,%s\n",iOutLength,sTemp.c_str());
iOutLength = msgHead.PkgLen;
printf("Encoding End...................\n");
}
void DecodeLogin(const char *pkgbuf, const int iInLength)
{
TMDBProxyHead msgHead;
TMDBProxyLogin msgLogin;
msgHead.Decode(pkgbuf,iInLength);
printf("len:%d,Seq:%d,commandId:%d,UserID:%d,Result:%d\n",msgHead.PkgLen,msgHead.Seq,msgHead.CommandID,msgHead.UserID,msgHead.Result);
if(msgHead.PkgLen > DBPROXY_HEAD_LENGTH)
{
msgLogin.Decode(pkgbuf+DBPROXY_HEAD_LENGTH,msgHead.PkgLen-DBPROXY_HEAD_LENGTH);
printf("return:%d\n",msgLogin.game_flag);
}
}
void EncodeSetGameFlag(char *pkgbuf,int &iOutLength)
{
TMDBProxyHead msgHead;
TMDBProxySetGameFlag msgSetGameFlag;
msgSetGameFlag.gameid_flag = 21;
msgSetGameFlag.Encode(pkgbuf+DBPROXY_HEAD_LENGTH,iOutLength);
string sTemp=MD5::ToHexFormat(pkgbuf+DBPROXY_HEAD_LENGTH,iOutLength);
printf("body length:%d,%s\n",iOutLength,sTemp.c_str());
msgHead.PkgLen = iOutLength+DBPROXY_HEAD_LENGTH;
msgHead.Seq = 1;
msgHead.CommandID = CMD_SET_GAME_FLAG;
msgHead.Result = 0;
msgHead.UserID = 40612277;
msgHead.Encode(pkgbuf,iOutLength);
sTemp=MD5::ToHexFormat(pkgbuf,iOutLength);
printf("head length:%d,%s\n",iOutLength,sTemp.c_str());
iOutLength = msgHead.PkgLen;
printf("Encoding End...................\n");
}
void DecodeSetGameFlag(const char *pkgbuf, const int iInLength)
{
TMDBProxyHead msgHead;
TMDBProxySetGameFlag msgSetGameFlag;
msgHead.Decode(pkgbuf,iInLength);
printf("len:%d,Seq:%d,commandId:%d,UserID:%d,Result:%d\n",msgHead.PkgLen,msgHead.Seq,msgHead.CommandID,msgHead.UserID,msgHead.Result);
}
void SendAndRecv(const char *sendbuf, const int iOutLength,char *recvbuf, int &iInLength)
{
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
//register test ip&port
//tcp::resolver::query query(tcp::v4(), "114.80.99.91", "3200");
//login&other test ip&port
tcp::resolver::query query(tcp::v4(), "114.80.99.91", "21001");
tcp::resolver::iterator iterator = resolver.resolve(query);
tcp::socket s(io_service);
s.connect(*iterator);
boost::system::error_code error;
boost::asio::write(s, boost::asio::buffer(sendbuf, iOutLength));
memset(recvbuf,0,1024);
iInLength=1024;
size_t ret = boost::asio::read(s,boost::asio::buffer(recvbuf, iInLength),boost::asio::transfer_at_least(1), error);
iInLength = ret;
printf("recv:%d\n",iInLength);
s.close();
}
int main()
{
char sendbuf[1024]={0};
char recvbuf[1024]={0};
int iOutLength = 0,iInLength=1024;
string email= "gosling_test5@paraengine.com";
string user="40612277";
string passwd= "passwd";
string callback = "callback";
TMService::Instance().EncodeRegist(sendbuf,iOutLength,email,passwd);
TMService::Instance().DeliverWithTimeout(sendbuf,iOutLength,recvbuf, iInLength,1);
TMService::Instance().DecodeRegist(recvbuf,iInLength,callback);
//TMService::Instance().EncodeLogin(sendbuf,iOutLength,email,passwd);
//TMService::Instance().DeliverWithTimeout(sendbuf,iOutLength,recvbuf, iInLength,2);
//TMService::Instance().DecodeLogin(recvbuf,iInLength,callback);
//
//TMService::Instance().EncodeSetGameFlag(sendbuf,iOutLength,user);
//TMService::Instance().DeliverWithTimeout(sendbuf,iOutLength,recvbuf, iInLength,2);
//TMService::Instance().DecodeSetGameFlag(recvbuf,iInLength);
return 0;
}