TestConnIPDlg.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // TestConnIPDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "TestConnIP.h"
  5. #include "TestConnIPDlg.h"
  6. #include <afxsock.h>//<Winsock2.h>
  7. #include "ConnectDlg.h"
  8. #include "SendDataDlg.h"
  9. #include "SendReg.h"
  10. #include <Mmsystem.h>
  11. #include <afxinet.h>
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. #pragma comment(lib, "Winmm.lib")
  18. #define WM_ICON_NOTIFY WM_USER+12
  19. DWORD g_nSendCode=0; //g_bSendOK
  20. /////////////////////////////////////////////////////////////////////////////
  21. HWND g_hSendWnd;
  22. extern HWND g_hConnectWnd;
  23. #define DISCONNECT_TIMER (WM_USER + 101)
  24. #define LOGINFAILED_TIMER (WM_USER + 102)
  25. void MyGetIPByName(CString &name)
  26. {
  27. CString strIP=name;
  28. name.Empty ();
  29. DWORD dwServerIP=0;
  30. HOSTENT *host = gethostbyname(strIP);
  31. struct in_addr addr;
  32. if (host != NULL)
  33. {
  34. for(int i = 0; host-> h_addr_list[i] != NULL; i ++)
  35. {
  36. memset(&addr, 0, sizeof(addr));
  37. memcpy(&addr.S_un.S_addr, host-> h_addr_list[i], host-> h_length);
  38. dwServerIP = ntohl(addr.S_un.S_addr);
  39. BYTE* pIP = (BYTE*)&dwServerIP;
  40. name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  41. }
  42. }
  43. }
  44. BOOL g_bReturned=0;
  45. extern DWORD FindAppProcessID(CString path);
  46. void WriteLogin(CString str)
  47. {
  48. CStdioFile fp;
  49. CString path=g_mainpath+"\\TestConnIP.log";
  50. if(::PathFileExists (path))
  51. {
  52. fp.Open (path, CFile::modeWrite);
  53. int length=fp.GetLength ();
  54. fp.SeekToEnd ();
  55. }
  56. else
  57. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  58. fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+" "+str+"\r\n" );
  59. fp.Close ();
  60. }
  61. unsigned __stdcall SendMsgThread(LPVOID lpParam)
  62. {
  63. BOOL nNeedConn=1;//信息服务器
  64. int i;
  65. CString str,ss;
  66. BYTE *pData;
  67. int failconn=0;
  68. int successconn=0;
  69. int failsend=0;
  70. int successsend=0;
  71. while(1)
  72. {
  73. ll: if(g_pMainWnd->m_bTerminate)
  74. break;
  75. if(1)//nNeedConn)
  76. {
  77. if(g_pMainWnd->OnConnect()==0)
  78. {
  79. nNeedConn=1;
  80. ::Sleep (1500);
  81. failconn++;
  82. ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d", failconn, successconn, failsend, successsend);
  83. WriteLogin(ss);
  84. goto ll;
  85. }
  86. else
  87. {
  88. successconn++;
  89. nNeedConn=0;
  90. ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d", failconn, successconn, failsend, successsend);
  91. WriteLogin(ss);
  92. }
  93. }
  94. str="20111101151606303195.ly.com";
  95. pData=new BYTE[str.GetLength ()];
  96. memcpy(pData, str.GetBuffer (0), str.GetLength ());
  97. str.ReleaseBuffer ();
  98. EncryptFile2(pData, str.GetLength (), "888666333");
  99. g_nSendCode=7;
  100. g_pMainWnd->ProcessChatMessageRequest2(pData, str.GetLength ());
  101. for(i=0; i<20; i++)
  102. {
  103. if(g_bReturned)break;
  104. ::Sleep (1500);
  105. }
  106. delete []pData;g_pMainWnd->OnDisconnect();
  107. if(g_bReturned==0)
  108. {
  109. failsend++;
  110. nNeedConn=1;
  111. ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d", failconn, successconn, failsend, successsend);
  112. WriteLogin(ss);
  113. goto ll;
  114. }
  115. else
  116. {
  117. successsend++;
  118. ss.Format ("failconn:%d,succonn:%d,failsend:%d,sucend:%d,%s", failconn, successconn, failsend+failconn, successsend,g_str);
  119. WriteLogin(ss);
  120. }
  121. for(i=0; i<60; i++)
  122. {
  123. if(g_pMainWnd->m_bTerminate)break;
  124. ::Sleep (1000);
  125. }
  126. }
  127. g_pMainWnd->m_bRunning=false;
  128. g_pMainWnd->m_bTerminate=false;
  129. _endthreadex( 0 );
  130. return 0;
  131. }
  132. //MessageBox
  133. /////////////////////////////////////////////////////////////////////////////
  134. static void HandleClientNetEvent(IN SOCKET hSocket, IN ETransportEvent eEvent,
  135. IN void *pDataBuf, IN unsigned long nDataLen,
  136. IN int nError, IN void *pContext)
  137. {
  138. if( nError != TRANSPORT_OK ) return;
  139. CTestConnIPDlg *pDlg = (CTestConnIPDlg *)pContext;
  140. if( NULL == pDlg ) return;
  141. pDlg->ProcessNetEvent(eEvent, pDataBuf, nDataLen);
  142. }
  143. CTestConnIPDlg::CTestConnIPDlg(CWnd* pParent /*=NULL*/)
  144. : CDialog(CTestConnIPDlg::IDD, pParent)
  145. {
  146. //{{AFX_DATA_INIT(CTestConnIPDlg)
  147. //}}AFX_DATA_INIT
  148. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  149. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  150. }
  151. void CTestConnIPDlg::DoDataExchange(CDataExchange* pDX)
  152. {
  153. CDialog::DoDataExchange(pDX);
  154. //{{AFX_DATA_MAP(CTestConnIPDlg)
  155. //}}AFX_DATA_MAP
  156. }
  157. BEGIN_MESSAGE_MAP(CTestConnIPDlg, CDialog)
  158. //{{AFX_MSG_MAP(CTestConnIPDlg)
  159. ON_WM_PAINT()
  160. ON_WM_QUERYDRAGICON()
  161. ON_WM_DESTROY()
  162. ON_WM_TIMER()
  163. ON_COMMAND(IDM_CLOSE, OnClose)
  164. ON_COMMAND(IDM_TestConnIP, OnTestConnIP)
  165. //}}AFX_MSG_MAP
  166. END_MESSAGE_MAP()
  167. /////////////////////////////////////////////////////////////////////////////
  168. BOOL CTestConnIPDlg::OnInitDialog()
  169. {
  170. CDialog::OnInitDialog();
  171. // Set the icon for this dialog. The framework does this automatically
  172. // when the application's main window is not a dialog
  173. SetIcon(m_hIcon, TRUE); // Set big icon
  174. SetIcon(m_hIcon, FALSE); // Set small icon
  175. g_pMainWnd=this;
  176. SetTimer(1, 10, NULL);
  177. /////////////////////////////////
  178. // TODO: Add extra initialization here
  179. return TRUE; // return TRUE unless you set the focus to a control
  180. }
  181. // If you add a minimize button to your dialog, you will need the code below
  182. // to draw the icon. For MFC applications using the document/view model,
  183. // this is automatically done for you by the framework.
  184. void CTestConnIPDlg::OnPaint()
  185. {
  186. if (IsIconic())
  187. {
  188. CPaintDC dc(this); // device context for painting
  189. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  190. // Center icon in client rectangle
  191. int cxIcon = GetSystemMetrics(SM_CXICON);
  192. int cyIcon = GetSystemMetrics(SM_CYICON);
  193. CRect rect;
  194. GetClientRect(&rect);
  195. int x = (rect.Width() - cxIcon + 1) / 2;
  196. int y = (rect.Height() - cyIcon + 1) / 2;
  197. // Draw the icon
  198. dc.DrawIcon(x, y, m_hIcon);
  199. }
  200. else
  201. {
  202. CDialog::OnPaint();
  203. }
  204. }
  205. // The system calls this to obtain the cursor to display while the user drags
  206. // the minimized window.
  207. HCURSOR CTestConnIPDlg::OnQueryDragIcon()
  208. {
  209. return (HCURSOR) m_hIcon;
  210. }
  211. DWORD CTestConnIPDlg::GetConnectionID()
  212. {
  213. return m_dwConnectionID;
  214. }
  215. void CTestConnIPDlg::SetConnectionID(DWORD dwConnection)
  216. {
  217. m_dwConnectionID = dwConnection;
  218. }
  219. void CTestConnIPDlg::ProcessChatMessageRequest2(CString sql)
  220. {
  221. const char *szDataBuf = sql.GetBuffer(0);
  222. sql.ReleaseBuffer();
  223. ProcessChatMessageRequest((void*)szDataBuf, strlen(szDataBuf) + 1);
  224. }
  225. void CTestConnIPDlg::ProcessChatMessageRequest2(BYTE *pData, int length)
  226. {
  227. ProcessChatMessageRequest((void*)pData, length);
  228. }
  229. BOOL CTestConnIPDlg::ProcessChatMessageRequest(void *szDataBuf, int nDataLen)
  230. {
  231. g_bReturned=0;
  232. DWORD dwFromUserID = GetConnectionID();
  233. WORD wMessageId = MSG_CHATMESSAGE_REQ;
  234. DWORD dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen;
  235. BYTE *pSendData = new BYTE[dwDataLen];
  236. TCHAT_MESSAGE_STRU *pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
  237. memset(pChatMessage, 0x00, dwDataLen);
  238. g_sendhead.length[98]=987123768;
  239. memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
  240. pChatMessage->tCommonMsg.dwConnectionID = GetConnectionID();
  241. pChatMessage->tCommonMsg.wMessageId = wMessageId;
  242. pChatMessage->dwFromUserID = dwFromUserID;
  243. pChatMessage->dwToUserID = g_nSendCode;
  244. pChatMessage->wMessageLen = nDataLen;
  245. memcpy(pChatMessage->byFileContent, szDataBuf, nDataLen);
  246. TMessageHeader tHeader = {0};
  247. tHeader.wMessageId = wMessageId;
  248. tHeader.dwDataLen = dwDataLen;
  249. BOOL bRet=0;
  250. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
  251. if( ulSendLen != SOCKET_ERROR )
  252. {
  253. bRet=1;
  254. }
  255. delete [] pSendData;
  256. return bRet;
  257. }
  258. BOOL CTestConnIPDlg::OnConnect()
  259. {
  260. g_server="lijiafz.vicp.net" ;
  261. MyGetIPByName(g_server);
  262. if(g_server.IsEmpty ())return OnConnect2();
  263. CString strServerAddress = g_server;
  264. char *szServerAddress = strServerAddress.GetBuffer(0);
  265. strServerAddress.ReleaseBuffer();
  266. /*for Client, IP and Port can be 0,
  267. and for Server, IP is LocalIP, and Port is Listening Port*/
  268. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  269. 0,
  270. HandleClientNetEvent,
  271. this);
  272. if( TRANSPORT_OK != nResult )
  273. {
  274. return 0;
  275. }
  276. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  277. WORD wPort = GetPort();
  278. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  279. if( TRANSPORT_OK != nResult )
  280. {
  281. m_tClientTunnel.net_CloseSocket();
  282. return OnConnect2();
  283. }
  284. return ProcessLoginRequest();
  285. }
  286. BOOL CTestConnIPDlg::OnConnect2()
  287. {
  288. CString server="http://www.lyfz.net/download/ip.txt";
  289. char buf[MAX_PATH];
  290. ::GetTempPath(sizeof(buf),buf);
  291. CString m_strTempDir=buf;
  292. DWORD m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
  293. INTERNET_PORT m_dwPort;
  294. DWORD dwType;
  295. CInternetSession m_cis;
  296. CHttpConnection *m_pHttp;
  297. CString m_strServer;
  298. CString m_strIniPath;
  299. AfxParseURL(server,dwType,m_strServer,m_strIniPath,m_dwPort);
  300. if(dwType!=AFX_INET_SERVICE_HTTP)
  301. {
  302. return OnConnect3();
  303. }
  304. m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
  305. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  306. try
  307. {
  308. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  309. }
  310. catch(CInternetException* pEx)
  311. {
  312. return OnConnect3();
  313. }
  314. CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
  315. m_strIniPath, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
  316. try
  317. {
  318. pFile->SendRequest();
  319. }
  320. catch(CInternetException* pEx)
  321. {
  322. pFile->Close();
  323. return OnConnect3();
  324. }
  325. if(pFile)
  326. {
  327. CStdioFile csf;
  328. csf.Open(m_strTempDir+"\\ip.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
  329. char buf[2048];
  330. int n;
  331. while((n=pFile->Read(buf,2048))>0)
  332. csf.Write(buf,n);
  333. csf.Close();
  334. pFile->Close();
  335. }
  336. CStdioFile fp;
  337. fp.Open (m_strTempDir+"\\ip.txt", CFile::modeRead);
  338. fp.ReadString (g_server);
  339. fp.Close ();
  340. CString strServerAddress = g_server;
  341. char *szServerAddress = strServerAddress.GetBuffer(0);
  342. strServerAddress.ReleaseBuffer();
  343. /*for Client, IP and Port can be 0,
  344. and for Server, IP is LocalIP, and Port is Listening Port*/
  345. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  346. 0,
  347. HandleClientNetEvent,
  348. this);
  349. if( TRANSPORT_OK != nResult )
  350. {
  351. return 0;
  352. }
  353. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  354. WORD wPort = GetPort();
  355. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  356. if( TRANSPORT_OK != nResult )
  357. {
  358. m_tClientTunnel.net_CloseSocket();
  359. return OnConnect3();
  360. }
  361. return ProcessLoginRequest();
  362. }
  363. BOOL CTestConnIPDlg::OnConnect3()
  364. {
  365. CString server="http://photo.bjlyfz.com/download/ip.txt";
  366. char buf[MAX_PATH];
  367. ::GetTempPath(sizeof(buf),buf);
  368. CString m_strTempDir=buf;
  369. DWORD m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
  370. INTERNET_PORT m_dwPort;
  371. DWORD dwType;
  372. CInternetSession m_cis;
  373. CHttpConnection *m_pHttp;
  374. CString m_strServer;
  375. CString m_strIniPath;
  376. AfxParseURL(server,dwType,m_strServer,m_strIniPath,m_dwPort);
  377. if(dwType!=AFX_INET_SERVICE_HTTP)
  378. {
  379. return FALSE;
  380. }
  381. m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
  382. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  383. try
  384. {
  385. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  386. }
  387. catch(CInternetException* pEx)
  388. {
  389. return false;
  390. }
  391. CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
  392. m_strIniPath, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
  393. try
  394. {
  395. pFile->SendRequest();
  396. }
  397. catch(CInternetException* pEx)
  398. {
  399. pFile->Close();
  400. return false;
  401. }
  402. if(pFile)
  403. {
  404. CStdioFile csf;
  405. csf.Open(m_strTempDir+"\\ip.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
  406. char buf[2048];
  407. int n;
  408. while((n=pFile->Read(buf,2048))>0)
  409. csf.Write(buf,n);
  410. csf.Close();
  411. pFile->Close();
  412. }
  413. CStdioFile fp;
  414. fp.Open (m_strTempDir+"\\ip.txt", CFile::modeRead);
  415. fp.ReadString (g_server);
  416. fp.Close ();
  417. CString strServerAddress = g_server;
  418. char *szServerAddress = strServerAddress.GetBuffer(0);
  419. strServerAddress.ReleaseBuffer();
  420. /*for Client, IP and Port can be 0,
  421. and for Server, IP is LocalIP, and Port is Listening Port*/
  422. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  423. 0,
  424. HandleClientNetEvent,
  425. this);
  426. if( TRANSPORT_OK != nResult )
  427. {
  428. return 0;
  429. }
  430. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  431. WORD wPort = GetPort();
  432. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  433. if( TRANSPORT_OK != nResult )
  434. {
  435. m_tClientTunnel.net_CloseSocket();
  436. return 0;
  437. }
  438. return ProcessLoginRequest();
  439. }
  440. void CTestConnIPDlg::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen)
  441. {
  442. if( Transport_ReadEv == nEventType )
  443. {
  444. if( NULL == pRecvMsg ) return;
  445. TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg;
  446. char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN;
  447. WORD dwMessageID = pHeader->wMessageId;
  448. switch(dwMessageID)
  449. {
  450. case MSG_LOGIN_RESP:
  451. {
  452. LOGIN_RESULT_STRU tLoginResult = {0};
  453. memcpy(&tLoginResult, pDataBuf, sizeof(LOGIN_RESULT_STRU));
  454. ProcessLoginResponse(&tLoginResult);
  455. break;
  456. }
  457. case MSG_USERINFO_RESP:
  458. {
  459. TUSERLIST_INFO_STRU tUserListInfo = {0};
  460. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  461. // ProcessUserListInfoResponse(&tUserListInfo);
  462. break;
  463. }
  464. case MSG_LOGOUT_RESP:
  465. {
  466. TUSERLIST_INFO_STRU tUserListInfo = {0};
  467. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  468. // ProcessLogoutResponse(&tUserListInfo);
  469. break;
  470. }
  471. case MSG_CHATMESSAGE_RESP:
  472. {
  473. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  474. ProcessChatMessageResponse((void *)pChatMessage);
  475. break;
  476. }
  477. default:
  478. {
  479. break;
  480. }
  481. }
  482. }
  483. else if( Transport_CloseEv == nEventType )
  484. {
  485. SetTimer(DISCONNECT_TIMER, 0, NULL);
  486. }
  487. ///////
  488. }
  489. void CTestConnIPDlg::OnDisconnect()
  490. {
  491. m_tClientTunnel.net_CloseSocket();
  492. SetConnectionID(INVALID_SOCKET);
  493. }
  494. void CTestConnIPDlg::ProcessLoginResponse(void *pLoginResult)
  495. {
  496. if( NULL == pLoginResult ) return;
  497. LOGIN_RESULT_STRU *ptLoginResult = (LOGIN_RESULT_STRU *)pLoginResult;
  498. DWORD dwConnectionID = ptLoginResult->tCommonMsg.dwConnectionID;
  499. SetConnectionID(dwConnectionID);
  500. BYTE byResult = ptLoginResult->byResult;
  501. if(LOGIN_RESULT_SUC == byResult)
  502. {
  503. }
  504. else
  505. {
  506. SetTimer(LOGINFAILED_TIMER, 0, NULL);
  507. }
  508. CString strCommentInfo("");
  509. strCommentInfo.Format("%s. 用户代号: %ld",
  510. ((LOGIN_RESULT_SUC == byResult) ? "登录成功" :
  511. (LOGIN_RESULT_MULTI == byResult) ? "重复登录" :
  512. (LOGIN_RESULT_NAMERROR == byResult) ? "名字不存在" :
  513. (LOGIN_RESULT_PWERROR == byResult) ? "密码错误" : "登录失败"),
  514. dwConnectionID);
  515. // MessageBox((CString)strCommentInfo);
  516. }
  517. CString newGUID()
  518. {
  519. CString str;
  520. GUID guid;
  521. // CoInitialize(NULL);
  522. if (S_OK == ::CoCreateGuid(&guid))
  523. {
  524. str.Format (
  525. "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  526. guid.Data1,
  527. guid.Data2,
  528. guid.Data3,
  529. guid.Data4[0], guid.Data4[1],
  530. guid.Data4[2], guid.Data4[3],
  531. guid.Data4[4], guid.Data4[5],
  532. guid.Data4[6], guid.Data4[7]);
  533. }
  534. // CoUninitialize();
  535. return str.Left (28);
  536. }
  537. BOOL CTestConnIPDlg::ProcessLoginRequest()
  538. {
  539. WORD wMessageId = MSG_LOGIN_REQ;
  540. TLOGIN_STRU tLogonInfo = {0};
  541. tLogonInfo.tCommonMsg.dwConnectionID = GetConnectionID();
  542. tLogonInfo.tCommonMsg.wMessageId = wMessageId;
  543. CString strUserName = newGUID();
  544. strUserName.TrimLeft();
  545. strUserName.TrimRight();
  546. strcpy(tLogonInfo.tUserInfo.szUserName, strUserName);
  547. DWORD dwDataLen = sizeof(TLOGIN_STRU);
  548. TMessageHeader tHeader = {0};
  549. tHeader.wMessageId = wMessageId;
  550. tHeader.dwDataLen = dwDataLen;
  551. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)&tLogonInfo, dwDataLen);
  552. if( ulSendLen == SOCKET_ERROR )
  553. {
  554. return 0;
  555. }
  556. return 1;
  557. }
  558. //---------------------------------------------------------------------------
  559. void CTestConnIPDlg::OnDestroy()
  560. {
  561. OnDisconnect();
  562. Transport_UnInit();
  563. CDialog::OnDestroy();
  564. }
  565. void CTestConnIPDlg::OnTimer(UINT nIDEvent)
  566. {
  567. // TODO: Add your message handler code here and/or call default
  568. if( DISCONNECT_TIMER == nIDEvent )
  569. {
  570. KillTimer(nIDEvent);
  571. OnDisconnect();
  572. }
  573. else if( LOGINFAILED_TIMER == nIDEvent )
  574. {
  575. KillTimer(nIDEvent);
  576. OnDisconnect();
  577. }
  578. else if( 1 == nIDEvent )
  579. {
  580. KillTimer(1);
  581. m_bTerminate=false;
  582. m_bRunning=false;
  583. m_hThread = NULL;
  584. m_bRunning=true;
  585. m_hThread = (HANDLE)_beginthreadex(NULL,0, SendMsgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  586. }
  587. }
  588. void CTestConnIPDlg::OnClose()
  589. {
  590. // TODO: Add your command handler code here
  591. TerminateThread();
  592. CDialog::OnCancel ();
  593. }
  594. BOOL CTestConnIPDlg::TerminateThread()
  595. {
  596. try
  597. {
  598. if ( !m_bRunning )
  599. return TRUE;
  600. m_bTerminate=true;
  601. for( ; ; )
  602. {
  603. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  604. break;
  605. MSG msg;
  606. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  607. {
  608. if (!AfxGetApp()->PumpMessage())
  609. break;
  610. }
  611. }
  612. ::CloseHandle(m_hThread);
  613. m_bRunning=false;
  614. return TRUE;
  615. }
  616. catch(...)
  617. {
  618. }
  619. }
  620. CArray<CStringArray, CStringArray>g_List1array;
  621. DWORD g_nLeng=0;
  622. BYTE *g_pData=NULL;
  623. CString g_str="";
  624. extern BOOL g_bSendData;
  625. void CTestConnIPDlg::ProcessChatMessageResponse(void *pResponse)
  626. {
  627. if( NULL == pResponse ) return;
  628. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pResponse;
  629. int nMessageLen = pChatMessage->wMessageLen;
  630. DWORD dwToUserID = pChatMessage->dwToUserID;
  631. // memcpy( &g_sendhead, pChatMessage, sizeof(g_sendhead));
  632. char *szChatMessage = new char[nMessageLen+1];
  633. memset(szChatMessage, 0x00, nMessageLen+1);
  634. memcpy(szChatMessage, pChatMessage->byFileContent, nMessageLen);
  635. g_str="xx";
  636. g_str=szChatMessage;
  637. delete []szChatMessage;
  638. g_bReturned=1;
  639. }
  640. BOOL g_bShowDlg=0;
  641. void CTestConnIPDlg::OnTestConnIP()
  642. {
  643. // TODO: Add your command handler code here
  644. }
  645. int CTestConnIPDlg::GetPort()
  646. {
  647. static int aaa=-1;
  648. if(aaa==-1)
  649. {
  650. aaa=CTime::GetCurrentTime ().GetSecond ()%7;
  651. }
  652. aaa++;
  653. if(aaa>=7)aaa=0;
  654. return 8387+aaa;
  655. }