ConnectSocket.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  1. /********************************************************************/
  2. /* */
  3. /* CONNECTSOCKET.CPP */
  4. /* */
  5. /* Implementation of the Connect Socket. */
  6. /* This class is a part of the CConnectThread which handles */
  7. /* socket connections. Incomming data is processed in OnReceive */
  8. /* */
  9. /* Programmed by LYFZ van der Meer */
  10. /* Based partially on and inspired by FileZilla Server. */
  11. /* */
  12. /* http://www.LYFZvandermeer.nl */
  13. /* */
  14. /* Last updated: 15 july 2002 */
  15. /* */
  16. /********************************************************************/
  17. //在ConnectSocket.cpp文件中实现连接套接字的创建,该类是CConnectThread类的
  18. //一部分,收到数据由函数OnReceive()完成处理。
  19. #include "stdafx.h"
  20. #include "LYFZIPReceiveApp.h"
  21. #include "LYFZIPReceive.h"
  22. #include "ConnectSocket.h"
  23. #include "ConnectThread.h"
  24. #include "ApplicationDlg.h"
  25. #include "DataSocket.h"
  26. #include "mysqldata.h"
  27. #include "./include/netMain.h"
  28. #include "./include/protocolhdr.h"
  29. #include "./include/struct_def.h"
  30. #include "MyLock.h"
  31. #include "my32.h"
  32. #include "SoftKey.h"
  33. extern CLYFZIPReceive theServer;
  34. extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword);
  35. #ifdef _DEBUG
  36. #define new DEBUG_NEW
  37. #undef THIS_FILE
  38. static char THIS_FILE[] = __FILE__;
  39. #endif
  40. extern CLYFZIPReceive *g_pWndServer;
  41. CString GetAuthCode(CString requestcode, long newsecond)
  42. {
  43. if(0==g_bDogOK)return "";
  44. try
  45. {
  46. UINT m_year;
  47. UINT m_month;
  48. UINT m_day;
  49. UINT m_hour;
  50. UINT m_minute;
  51. {
  52. TCHAR year[10],month[10],day[10],hour[10],minute[10], second[10];
  53. ConvertTimerToStringReal(newsecond, year, month, day, hour, minute, second);
  54. m_year=atoi(year);
  55. m_month=atoi(month);
  56. m_day=atoi(day);
  57. m_hour=atoi(hour);
  58. m_minute=atoi(minute);
  59. if(newsecond==60)
  60. {
  61. m_year=60;
  62. m_month=0;
  63. m_day=0;
  64. m_hour=0;
  65. m_minute=0;
  66. }
  67. }
  68. if(m_year<0 || m_month<0 || m_day<0 || m_hour<0 || m_minute<0)
  69. {
  70. return "";
  71. }
  72. requestcode.TrimLeft ();
  73. requestcode.TrimRight ();
  74. requestcode.Replace ("\n", "");
  75. requestcode.Replace ("\r", "");
  76. if(requestcode.IsEmpty ())
  77. {
  78. return "";
  79. }
  80. CString str,temp,temp2;
  81. long id,time1,time2,idtemp;
  82. int leng;
  83. str=requestcode;
  84. temp=str.Left (3);
  85. str=str.Right (str.GetLength ()-3);
  86. leng=atoi(temp.Left (2));
  87. temp2=str.Left (leng);
  88. str=str.Right (str.GetLength ()-leng);
  89. id=atoi(temp2);
  90. if(temp.Right (1)=="1")id=-id;
  91. //////////////////////////////////////////////////
  92. temp=str.Left (3);
  93. str=str.Right (str.GetLength ()-3);
  94. leng=atoi(temp.Left (2));
  95. temp2=str.Left (leng);
  96. str=str.Right (str.GetLength ()-leng);
  97. time1=atoi(temp2);
  98. if(temp.Right (1)=="1")time1=-time1;
  99. //////////////////////////////////////////////////
  100. temp=str.Left (3);
  101. str=str.Right (str.GetLength ()-3);
  102. leng=atoi(temp.Left (2));
  103. temp2=str.Left (leng);
  104. str=str.Right (str.GetLength ()-leng);
  105. time2=atoi(temp2);
  106. if(temp.Right (1)=="1")time2=-time2;
  107. //////////////////////////////////////////////////////
  108. temp=str.Left (3);
  109. str=str.Right (str.GetLength ()-3);
  110. leng=atoi(temp.Left (2));
  111. temp2=str.Left (leng);
  112. str=str.Right (str.GetLength ()-leng);
  113. idtemp=atoi(temp2);
  114. if(temp.Right (1)=="1")idtemp=-idtemp;
  115. //////////////////////////////////////////////////////
  116. // SoftKey ytSoftKey;
  117. int ret=0;//ytSoftKey.Ini();
  118. if (ret!=0 )
  119. {
  120. return "";
  121. }
  122. long d[8];double f[8];
  123. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  124. //运行自定义函数
  125. ret=ytSoftKey.code2(&id,&idtemp,&time1,&time2,&d[4],&d[5],&d[6],&d[7],
  126. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  127. s0,s1,s2,s3,s4,s5,s6,s7);
  128. if(ret!=0 && ret!=-43)
  129. {
  130. return "";
  131. }
  132. ////////////////////////////////////////////////////////////////////////
  133. TCHAR DevicePath[ 260];
  134. if(FindPort(0,DevicePath)!=0)
  135. return "";
  136. DWORD OutID;
  137. int version;
  138. GetIDVersion(&OutID, &version, DevicePath);
  139. TCHAR year[10],month[10],day[10],hour[10],minute[10], OutString[50];
  140. sprintf(year, "%d", m_year);
  141. sprintf(month, "%d", m_month);
  142. sprintf(day, "%d", m_day);
  143. sprintf(hour, "%d", m_hour);
  144. sprintf(minute, "%d", m_minute);
  145. MakeTimerAuth("20D30D15FFB7F6AF9EAB30FD229F797B", id, year, month, day,
  146. hour, minute, OutString,DevicePath);
  147. CString authcode=OutString;
  148. str.Format ("%04d", m_year);
  149. authcode+=str;
  150. str.Format ("%02d", m_month);
  151. authcode+=str;
  152. str.Format ("%02d", m_day);
  153. authcode+=str;
  154. str.Format ("%02d", m_hour);
  155. authcode+=str;
  156. str.Format ("%02d", m_minute);
  157. authcode+=str;
  158. str.Format ("%08d", id);
  159. authcode+=str;
  160. CString str1,str2,str3,str4,str5;
  161. str1=authcode.Mid (0, 20);
  162. str2=authcode.Mid (20, 20);
  163. str3=authcode.Mid (40, 20);
  164. str4=authcode.Mid (60, 20);
  165. str5=authcode.Mid (80, 20);
  166. sprintf(s0, "%s", str1);
  167. sprintf(s1, "%s", str2);
  168. sprintf(s2, "%s", str3);
  169. sprintf(s3, "%s", str4);
  170. sprintf(s4, "%s", str5);
  171. //运行自定义函数
  172. {
  173. SoftKey ytSoftKey2;
  174. ret=ytSoftKey2.Ini();
  175. if (ret!=0 )
  176. {
  177. return "";
  178. }
  179. {
  180. long d[8];double f[8];
  181. char s5[50]="",s6[50]="",s7[50]="";
  182. ret=ytSoftKey2.code1(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
  183. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  184. s0,s1,s2,s3,s4,s5,s6,s7);
  185. }
  186. if(ret!=0 && ret!=-43)
  187. {
  188. return "";
  189. }
  190. str1=s0;
  191. str2=s1;
  192. str3=s2;
  193. str4=s3;
  194. str5=s4;
  195. }
  196. authcode=str1;
  197. authcode+=str2;
  198. authcode+=str3;
  199. authcode+=str4;
  200. authcode+=str5;
  201. return authcode;
  202. }
  203. catch(...)
  204. {
  205. }
  206. }
  207. CString GetUseDays(CString requestcode)
  208. {
  209. if(0==g_bDogOK)return "";
  210. try
  211. {
  212. CString sRet;
  213. requestcode.TrimLeft ();
  214. requestcode.TrimRight ();
  215. requestcode.Replace ("\n", "");
  216. requestcode.Replace ("\r", "");
  217. if(requestcode.IsEmpty ())
  218. {
  219. return "";
  220. }
  221. CString str,temp,temp2;
  222. long id,time1,time2,idtemp;
  223. int leng;
  224. str=requestcode;
  225. temp=str.Left (3);
  226. str=str.Right (str.GetLength ()-3);
  227. leng=atoi(temp.Left (2));
  228. temp2=str.Left (leng);
  229. str=str.Right (str.GetLength ()-leng);
  230. id=atoi(temp2);
  231. if(temp.Right (1)=="1")id=-id;
  232. //////////////////////////////////////////////////
  233. temp=str.Left (3);
  234. str=str.Right (str.GetLength ()-3);
  235. leng=atoi(temp.Left (2));
  236. temp2=str.Left (leng);
  237. str=str.Right (str.GetLength ()-leng);
  238. time1=atoi(temp2);
  239. if(temp.Right (1)=="1")time1=-time1;
  240. //////////////////////////////////////////////////
  241. temp=str.Left (3);
  242. str=str.Right (str.GetLength ()-3);
  243. leng=atoi(temp.Left (2));
  244. temp2=str.Left (leng);
  245. str=str.Right (str.GetLength ()-leng);
  246. time2=atoi(temp2);
  247. if(temp.Right (1)=="1")time2=-time2;
  248. //////////////////////////////////////////////////////
  249. temp=str.Left (3);
  250. str=str.Right (str.GetLength ()-3);
  251. leng=atoi(temp.Left (2));
  252. temp2=str.Left (leng);
  253. str=str.Right (str.GetLength ()-leng);
  254. idtemp=atoi(temp2);
  255. if(temp.Right (1)=="1")idtemp=-idtemp;
  256. //////////////////////////////////////////////////////
  257. // SoftKey ytSoftKey;
  258. int ret=0;//ytSoftKey.Ini();
  259. if (ret!=0 )
  260. {
  261. return "";
  262. }
  263. long d[8];double f[8];
  264. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  265. //运行自定义函数
  266. ret=ytSoftKey.code2(&id,&idtemp,&time1,&time2,&d[4],&d[5],&d[6],&d[7],
  267. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  268. s0,s1,s2,s3,s4,s5,s6,s7);
  269. if(ret!=0 && ret!=-43)
  270. {
  271. return "";
  272. }
  273. // TODO: Add your control notification handler code here
  274. TCHAR year[10],month[10],day[10],hour[10],minute[10], second[10];
  275. ConvertTimerToStringReal(time2, year, month, day, hour, minute, second);
  276. temp.Format("已运行:%d年%d月%d日 ", atoi(year), atoi(month), atoi(day));
  277. sRet+=temp;
  278. if(time1>0)
  279. ConvertTimerToStringReal(time1, year, month, day, hour, minute, second);
  280. else
  281. {
  282. sprintf(year, "%s", "0");
  283. sprintf(month, "%s", "0");
  284. sprintf(day, "%s", "0");
  285. sprintf(hour, "%s", "0");
  286. sprintf(minute, "%s", "0");
  287. }
  288. temp.Format("能运行:%d年%d月%d日---%d", atoi(year), atoi(month), atoi(day), time2);
  289. sRet+=temp;
  290. return sRet;
  291. }
  292. catch(...)
  293. {
  294. }
  295. return "";
  296. }
  297. BOOL MyExecuteSQL(CDatabase *pdb, CString sql)
  298. {
  299. MyLock lock("xiaoaccessdbmsg");
  300. try
  301. {
  302. pdb->ExecuteSQL (sql);
  303. }
  304. catch(...)
  305. {
  306. return 0;
  307. }
  308. return 1;
  309. }
  310. extern void WriteLogin(CString str);
  311. void WriteLog(CString account, CString str)
  312. {
  313. }
  314. /********************************************************************/
  315. /* */
  316. /* Function name : CConnectSocket::CConnectSocket */
  317. /* Description : Constructor */
  318. /* */
  319. /********************************************************************/
  320. CConnectSocket::CConnectSocket()
  321. {
  322. m_bLoggedon = FALSE;
  323. m_bRenameFile = FALSE;
  324. m_pDataSocket = NULL;
  325. m_strRemoteHost = "";
  326. m_nRemotePort = -1;
  327. m_dwRestartOffset = 0;
  328. m_bPassiveMode = FALSE;
  329. m_reved=0;
  330. m_dateleng=0;
  331. m_pRevBuf=NULL;
  332. }
  333. /********************************************************************/
  334. /* */
  335. /* Function name : CConnectSocket::~CConnectSocket */
  336. /* Description : Destructor */
  337. /* */
  338. /********************************************************************/
  339. CConnectSocket::~CConnectSocket()
  340. {
  341. if(m_pRevBuf)delete []m_pRevBuf;
  342. }
  343. // Do not edit the following lines, which are needed by ClassWizard.
  344. #if 0
  345. BEGIN_MESSAGE_MAP(CConnectSocket, CSocket)
  346. //{{AFX_MSG_MAP(CConnectSocket)
  347. //}}AFX_MSG_MAP
  348. END_MESSAGE_MAP()
  349. #endif // 0
  350. /********************************************************************/
  351. /* */
  352. /* Function name : OnClose */
  353. /* Description : Send WM_QUIT message to the thread containing */
  354. /* the socket to shutdown once the connection is */
  355. /* closed. */
  356. /* */
  357. /********************************************************************/
  358. void CConnectSocket::OnClose(int nErrorCode)
  359. {
  360. try
  361. {
  362. Close();
  363. // destroy connection
  364. AfxGetThread()->PostThreadMessage(WM_THREADMSG, 1, 0);
  365. TRACE("CConnectSocket() OnClose()\n");
  366. CSocket::OnClose(nErrorCode);
  367. }
  368. catch(...)
  369. {
  370. }
  371. }
  372. #define BUFFERSIZE 4096
  373. /********************************************************************/
  374. /* */
  375. /* Function name : OnReceive */
  376. /* Description : Called by the framework to notify this socket */
  377. /* that there is data in the buffer. */
  378. /* */
  379. /********************************************************************/
  380. //由主窗口调用通知套接字缓冲区中有数据要接收
  381. void CConnectSocket::OnReceive(int nErrorCode)
  382. {
  383. TCHAR buff[BUFFERSIZE];
  384. //接收数据并放到缓冲区
  385. int nRead = Receive(buff, BUFFERSIZE);
  386. switch (nRead)
  387. {
  388. case 0:
  389. Close();
  390. break;
  391. case SOCKET_ERROR:
  392. if (GetLastError() != WSAEWOULDBLOCK)
  393. {
  394. TCHAR szError[256];
  395. wsprintf(szError, "OnReceive error: %d", GetLastError());
  396. // AfxMessageBox (szError);
  397. }
  398. break;
  399. default:
  400. if (nRead != SOCKET_ERROR && nRead != 0)
  401. {
  402. ((CConnectThread *)AfxGetThread())->IncReceivedBytes(nRead);
  403. TMessageHeader *pMessageHeader = (TMessageHeader *)buff;
  404. if(pMessageHeader->wMessageId ==MSG_LOGIN_REQ)
  405. {
  406. WORD wMessageId = MSG_LOGIN_RESP;
  407. LOGIN_RESULT_STRU tLoginResult = {0};
  408. tLoginResult.tCommonMsg.dwConnectionID = 0;
  409. tLoginResult.tCommonMsg.wMessageId = wMessageId;
  410. tLoginResult.byResult = LOGIN_RESULT_SUC;
  411. tLoginResult.dwUserID = 0;
  412. tLoginResult.byStatus = USER_STATUS_ONLINE ;
  413. DWORD dwDataLen = sizeof(LOGIN_RESULT_STRU);
  414. TMessageHeader tHeader = {0};
  415. tHeader.wMessageId = wMessageId;
  416. tHeader.dwDataLen = dwDataLen;
  417. net_Send(&tHeader, (void *)&tLoginResult, dwDataLen);
  418. }
  419. else //if(pMessageHeader->wMessageId ==MSG_CHATMESSAGE_REQ)
  420. {
  421. /* char *pDataBuf = (char *)buff + MESSAGE_HEADER_LEN;
  422. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  423. DWORD dwConnectionID = pChatMessage->tCommonMsg.dwConnectionID;
  424. processChatMessageRequest((void *)pChatMessage);*/
  425. // 结束字符串
  426. if(pMessageHeader->wHeaderFlag==MESSAGE_HEADER_FLAG )
  427. {
  428. if(m_pRevBuf)delete []m_pRevBuf;m_pRevBuf=NULL;m_reved=0;
  429. m_dateleng=pMessageHeader->dwDataLen+MESSAGE_HEADER_LEN;
  430. m_pRevBuf=new BYTE[m_dateleng];
  431. //WriteLogin("开始接收");
  432. }
  433. ::memcpy(m_pRevBuf+m_reved, buff, min(nRead, m_dateleng-m_reved));
  434. // CString ss;
  435. // ss.Format("%d/%d", min(nRead, m_dateleng-m_reved), m_dateleng);
  436. // WriteLogin("接收"+ss);
  437. m_reved+=min(nRead, m_dateleng-m_reved);
  438. if(m_reved>=m_dateleng)
  439. {
  440. // WriteLogin("接收完成");
  441. char *pDataBuf = (char *)m_pRevBuf + MESSAGE_HEADER_LEN;
  442. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  443. m_reved=0;m_dateleng=0;
  444. processChatMessageRequest((void *)pChatMessage);
  445. }
  446. }
  447. }
  448. break;
  449. }
  450. CSocket::OnReceive(nErrorCode);
  451. }
  452. /********************************************************************/
  453. /* */
  454. /* Function name: GetRxCommand */
  455. /* Description : Get command from receiver buffer. */
  456. /* */
  457. /********************************************************************/
  458. //从接收缓冲区获得命令
  459. BOOL CConnectSocket::GetRxCommand(CString &strCommand, CString &strArguments)
  460. {
  461. return FALSE;
  462. }
  463. /********************************************************************/
  464. /* */
  465. /* Function name: GetRxLine */
  466. /* Description : Parse complete command line */
  467. /* */
  468. /********************************************************************/
  469. //解析整个命令行
  470. void CConnectSocket::GetRxLine()
  471. {
  472. }
  473. /********************************************************************/
  474. /* */
  475. /* Function name: OnConnect */
  476. /* Description : Called by the framework to notify this connecting */
  477. /* socket that its connection attempt is completed. */
  478. /* */
  479. /********************************************************************/
  480. void CConnectSocket::OnConnect(int nErrorCode)
  481. {
  482. CSocket::OnConnect(nErrorCode);
  483. }
  484. /********************************************************************/
  485. /* */
  486. /* Function name: HasConnectionDropped */
  487. /* Description : Check if connection has been dropped. */
  488. /* Used to detect if client has crashed. */
  489. /* */
  490. /********************************************************************/
  491. BOOL CConnectSocket::HasConnectionDropped(void)
  492. {
  493. try
  494. {
  495. BOOL bConnDropped = FALSE;
  496. INT iRet = 0;
  497. BOOL bOK = TRUE;
  498. if (m_hSocket == INVALID_SOCKET)
  499. return TRUE;
  500. struct timeval timeout = { 0, 0 };
  501. fd_set readSocketSet;
  502. FD_ZERO(&readSocketSet);
  503. FD_SET(m_hSocket, &readSocketSet);
  504. iRet = ::select(0, &readSocketSet, NULL, NULL, &timeout);
  505. bOK = (iRet > 0);
  506. if(bOK)
  507. {
  508. bOK = FD_ISSET(m_hSocket, &readSocketSet);
  509. }
  510. if(bOK)
  511. {
  512. CHAR szBuffer[1] = "";
  513. iRet = ::recv(m_hSocket, szBuffer, 1, MSG_PEEK);
  514. bOK = (iRet > 0);
  515. if(!bOK)
  516. {
  517. INT iError = ::WSAGetLastError();
  518. bConnDropped = (( iError == WSAENETRESET) ||
  519. (iError == WSAECONNABORTED) ||
  520. (iError == WSAECONNRESET) ||
  521. (iError == WSAEINVAL) ||
  522. (iRet == 0));
  523. }
  524. }
  525. return(bConnDropped);
  526. }
  527. catch(...)
  528. {
  529. }
  530. return 1;
  531. }
  532. /********************************************************************/
  533. /* */
  534. /* Function name: SendResponse */
  535. /* Description : Send response to client. */
  536. /* */
  537. /********************************************************************/
  538. //发送响应给客户端
  539. BOOL CConnectSocket::SendResponse(LPCTSTR pstrFormat, ...)
  540. {
  541. return TRUE;
  542. }
  543. /********************************************************************/
  544. /* */
  545. /* Function name: ParseCommand */
  546. /* Description : Parse and execute command from client. */
  547. /* */
  548. /* Based on code provided by FileZilla Server. */
  549. /* http://sourceforge.net/projects/filezilla */
  550. /* */
  551. /********************************************************************/
  552. //从客户端解析并执行命令
  553. void CConnectSocket::ParseCommand()
  554. {
  555. }
  556. /********************************************************************/
  557. /* */
  558. /* Function name: FireStatusMessage */
  559. /* Description : Fire status message. */
  560. /* */
  561. /********************************************************************/
  562. void CConnectSocket::FireStatusMessage(LPCTSTR lpszStatus, int nType)
  563. {
  564. try
  565. {
  566. g_pWndServer->AddTraceLine(nType, "[%d] %s", AfxGetThread()->m_nThreadID, lpszStatus);
  567. }
  568. catch(...)
  569. {
  570. }
  571. }
  572. /********************************************************************/
  573. /* */
  574. /* Function name: CreateDataConnection */
  575. /* Description : Create data transfer connection. */
  576. /* */
  577. /********************************************************************/
  578. BOOL CConnectSocket::CreateDataConnection(int nTransferType, LPCTSTR lpszData)
  579. {
  580. return TRUE;
  581. }
  582. /********************************************************************/
  583. /* */
  584. /* Function name: DestroyDataConnection */
  585. /* Description : Close data transfer connection. */
  586. /* */
  587. /********************************************************************/
  588. void CConnectSocket::DestroyDataConnection()
  589. {
  590. }
  591. unsigned long CConnectSocket::net_Send(IN void *pHeader, IN void *pMessage, IN unsigned long ulDataLen)
  592. {
  593. try
  594. {
  595. unsigned long ulSendLen = 0;
  596. unsigned long ulBufLen = 0;
  597. TMessageHeader *pSendHeader = (TMessageHeader *)pHeader;
  598. ulBufLen = MESSAGE_HEADER_LEN + ulDataLen;
  599. char *pSendBuf = new char[ulBufLen];
  600. memset(pSendBuf, 0, ulBufLen);
  601. TMessageHeader *pMessageHeader = (TMessageHeader *)pSendBuf;
  602. pMessageHeader->byVersion = 101;
  603. pMessageHeader->wHeaderFlag = MESSAGE_HEADER_FLAG;
  604. pMessageHeader->wMessageId = pSendHeader->wMessageId;
  605. pMessageHeader->wMessageSubId = pSendHeader->wMessageSubId;
  606. pMessageHeader->dwDataLen = ulDataLen;
  607. pMessageHeader->wReserve = 0;
  608. memcpy((void *)(pSendBuf+MESSAGE_HEADER_LEN), pMessage, ulDataLen);
  609. // convert network word
  610. htons(pMessageHeader->wHeaderFlag);
  611. htons(pMessageHeader->wMessageId);
  612. htons(pMessageHeader->wMessageSubId);
  613. htonl(pMessageHeader->dwDataLen);
  614. htons(pMessageHeader->wCheckSum);
  615. htonl(pMessageHeader->wReserve);
  616. //Send the message
  617. // ulSendLen = CTransportImpl::net_Send(hSocket, (void *)pSendBuf, ulBufLen);
  618. //判断连接是否在活动状态
  619. if (HasConnectionDropped())
  620. {
  621. FireStatusMessage("Could not send reply, disconnected.", 2);
  622. Close();
  623. // 通知线程已经停止,关闭连接
  624. AfxGetThread()->PostThreadMessage(WM_THREADMSG, 1, 0);
  625. return FALSE;
  626. }
  627. int nBytes = CSocket::Send((void *)pSendBuf, ulBufLen);
  628. if (nBytes == SOCKET_ERROR)
  629. {
  630. Close();
  631. FireStatusMessage("Could not send reply, disconnected.", 2);
  632. //通知线程连接已经关闭
  633. AfxGetThread()->PostThreadMessage(WM_THREADMSG, 1, 0);
  634. return FALSE;
  635. }
  636. ((CConnectThread *)AfxGetThread())->IncSentBytes(nBytes);
  637. delete [] pSendBuf;
  638. pSendBuf = NULL;
  639. return nBytes;
  640. }
  641. catch(...)
  642. {
  643. }
  644. return 0;
  645. }
  646. BOOL g_bWork=0;
  647. void CConnectSocket::processChatMessageRequest(void *pChatMsg)
  648. {
  649. CString str;
  650. DWORD dwToUserID=100;
  651. try
  652. {
  653. g_bWork=1;
  654. if( NULL == pChatMsg )
  655. {
  656. g_bWork=0;
  657. return;
  658. }
  659. TCHAT_MESSAGE_STRU *ptChatMessage = (TCHAT_MESSAGE_STRU *)pChatMsg;
  660. DWORD dwUserID = ptChatMessage->tCommonMsg.dwConnectionID;
  661. if(ptChatMessage->length[98]!=987123768)
  662. {
  663. WriteLogin("987123768");
  664. g_bWork=0;
  665. return;
  666. }
  667. int nMessageLen = ptChatMessage->wMessageLen;
  668. if( nMessageLen > 3 )
  669. {
  670. dwToUserID = ptChatMessage->dwToUserID;
  671. if(dwToUserID!=9)//企业版分店权限设置
  672. {
  673. char *szChatMessage;
  674. szChatMessage = new char[nMessageLen+1];
  675. memset(szChatMessage, 0x00, nMessageLen+1);
  676. memcpy(szChatMessage, ptChatMessage->byFileContent, nMessageLen);
  677. EncryptFile2((BYTE*)szChatMessage, nMessageLen, "888666333");
  678. str=szChatMessage;delete []szChatMessage;
  679. }
  680. else
  681. str.Empty ();
  682. BYTE *pBranchData=NULL;
  683. DWORD nBranchDataLeng=0;
  684. int nBranchArraySize=0;
  685. if(dwToUserID==0)
  686. {
  687. }
  688. else if(dwToUserID==1)//改密码
  689. {
  690. }
  691. else if(dwToUserID==2)//查询使用
  692. {
  693. }
  694. else if(dwToUserID==3)//查询余额
  695. {
  696. }
  697. else if(dwToUserID==4)//查发送记录
  698. {
  699. }
  700. else if(dwToUserID==5)//查询余额
  701. {
  702. }
  703. else if(dwToUserID==6)//登记客人IP
  704. {
  705. MyLock lock("accessclientip");
  706. int pos=str.Find ("&@&@&");
  707. if(pos!=-1)
  708. {
  709. CString info=str.Left (pos);
  710. str=str.Right (str.GetLength ()-pos-5);
  711. pos=info.Find (":");
  712. CString dindan="订单数:"+info.Right (info.GetLength ()-pos-1);
  713. pos=info.Find ("订单数:");
  714. info=info.Left (pos);
  715. CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
  716. CString sql,execute;
  717. BOOL bexist=0;
  718. if(1)
  719. {MyLock lock("xiaoaccessdbmsg");
  720. CRecordset myset(&g_db);
  721. sql="select execute from unauth where name='"+info+"'";
  722. myset.Open (CRecordset::forwardOnly, sql);
  723. if(!myset.IsEOF())
  724. {
  725. myset.GetFieldValue ("execute", execute);
  726. bexist=1;
  727. }
  728. myset.Close();
  729. }
  730. if(execute=="停止运行")
  731. {
  732. str="无域名字段,请确认";
  733. }
  734. else
  735. {
  736. if(bexist==0)
  737. sql.Format("insert into [unauth]([name],[dindan],[datetime],[execute])values('%s','%s','%s','%s')", info, dindan, datetime, "0");
  738. else
  739. sql.Format("update [unauth] set [dindan]='%s',[datetime]='%s' where [name]='%s'",dindan, datetime, info);
  740. MyExecuteSQL(&g_db, sql);
  741. }
  742. }
  743. else
  744. {
  745. CString name=str;
  746. pos=str.Find (";");
  747. long id;
  748. CString logcontent="未升级,无法获知";
  749. CString temp,regcode,regcode2,regcodebak;
  750. if(pos!=-1)
  751. {
  752. name=str.Left (pos);
  753. logcontent=str.Right (str.GetLength ()-pos-1);
  754. if(name=="20120817143012340694.ly.com")
  755. {
  756. WriteLogin("xxx:"+logcontent);
  757. }
  758. pos=logcontent.Find ("***");
  759. if(pos!=-1)
  760. {
  761. regcode=logcontent.Right (logcontent.GetLength ()-pos-3);
  762. regcodebak=regcode;
  763. logcontent=logcontent.Left(pos);
  764. str=GetUseDays(regcode);
  765. regcode=str;
  766. pos=regcode.Find ("---");
  767. if(pos!=-1)
  768. regcodebak+="---"+regcode.Right (regcode.GetLength ()-pos-3);
  769. }
  770. }
  771. UINT nPeerPort;
  772. GetPeerName(str, nPeerPort);
  773. CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
  774. pos=regcode.Find ("---");
  775. if(pos!=-1)
  776. temp=regcode.Left (pos);
  777. else
  778. temp=regcode;
  779. CString sql="update [clientip] set [ip]='"+str+"',[datetime]='"+datetime+"',[log]='"+logcontent+"',[regcode]='"+temp+"' where [name]='"+name+"'";
  780. MyExecuteSQL(&g_db, sql);
  781. if(1)
  782. {
  783. MyLock lock("xiaoaccessdbmsg");
  784. CString enterprisename;
  785. CRstClientIP rsSt;
  786. rsSt.m_strFilter ="name='"+name+"'";
  787. rsSt.Open();
  788. if(!rsSt.IsEOF())
  789. {
  790. sql=rsSt.m_branchname ;
  791. enterprisename=rsSt.m_enterprisename ;
  792. regcode2=rsSt.regcode2 ;
  793. }
  794. else
  795. {
  796. sql="xxx!";
  797. str="此域名未绑定";
  798. }
  799. rsSt.Close();
  800. }
  801. regcode=regcodebak;
  802. if(regcode!="" && (regcode2.GetLength ()==10||regcode2=="永久") )
  803. {
  804. CTime curtm=CTime::GetCurrentTime ();
  805. long newsecond=0;long dtsecond=0;
  806. if(regcode2=="永久")
  807. {
  808. newsecond=60;
  809. int pos=regcode.Find ("---");
  810. if(pos!=-1)regcodebak=regcode.Left (pos);
  811. }
  812. else
  813. {
  814. CTime destm( atoi(regcode2.Mid (0,4)), atoi(regcode2.Mid (5,2)), atoi(regcode2.Mid (8,2)), 0, 0, 0);
  815. CTimeSpan dt=destm-curtm;
  816. dtsecond=dt.GetTotalSeconds();
  817. dtsecond/=2;
  818. int pos=regcode.Find ("---");
  819. if(pos!=-1 && dtsecond>0)
  820. {
  821. regcodebak=regcode.Left (pos);
  822. regcode=regcode.Right (regcode.GetLength ()-pos-3);
  823. long usedsecond=atoi(regcode);
  824. newsecond=usedsecond+dtsecond;
  825. }
  826. }
  827. if(newsecond)
  828. {
  829. str+="authcodexiao"+GetAuthCode(regcodebak, newsecond);
  830. }
  831. }
  832. }
  833. }
  834. else if(dwToUserID==7)//查询客人IP
  835. {
  836. MyLock lock("xiaoaccessdbmsg");
  837. CRecordset myset(&g_db);
  838. CString sql="select ip from clientip where name='"+str+"'";
  839. str="";
  840. myset.Open (CRecordset::forwardOnly, sql);
  841. if(!myset.IsEOF())
  842. myset.GetFieldValue ("ip", str);
  843. else
  844. str+="没有此域名的记录!";
  845. myset.Close();
  846. }
  847. else if(dwToUserID==14)//查询客人IP
  848. {
  849. MyLock lock("xiaoaccessdbmsg");
  850. CRecordset myset(&g_db);
  851. CString sql="select ip from clientip where name='20120829094720383019.ly.com'";
  852. myset.Open (CRecordset::forwardOnly, sql);
  853. if(!myset.IsEOF())
  854. myset.GetFieldValue ("ip", str);
  855. else
  856. {
  857. str+="没有此域名的记录!";
  858. sql="insert into clientip(name,)values('20120829094720383019.ly.com');";
  859. CString date=CTime::GetCurrentTime ().Format ("%Y-%m-%d");
  860. CString date2=CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S");
  861. sql= "insert into clientip([name],[applydate],[branchname],[modifydate]) values(\
  862. '20120829094720383019.ly.com',\
  863. '"+date+"',\
  864. 'xiao测试',\
  865. '"+date2+"')";
  866. MyExecuteSQL(&g_db, sql);
  867. }
  868. myset.Close();
  869. }
  870. else if(dwToUserID==15)//登记客人IP
  871. {
  872. MyLock lock("accessclientip");
  873. UINT nPeerPort;
  874. GetPeerName(str, nPeerPort);
  875. CString name="20120829094720383019.ly.com";
  876. CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
  877. CString sql="update [clientip] set [ip]='"+str+"',[datetime]='"+datetime+"' where [name]='"+name+"'";
  878. MyExecuteSQL(&g_db, sql);
  879. }
  880. else if(dwToUserID==8)//企业版客人查询企业资料
  881. {
  882. CString name=str;CString temp,sql;
  883. CString rights,bmain,enterprisename;
  884. CRecordset myset(&g_db);
  885. if(1)
  886. {MyLock lock("xiaoaccessdbmsg");
  887. sql="select enterprisename from clientip where name='"+name+"'";
  888. myset.Open (CRecordset::forwardOnly, sql);
  889. if(!myset.IsEOF())
  890. {
  891. myset.GetFieldValue ("enterprisename", enterprisename);
  892. }
  893. else
  894. sql="xxx!";
  895. myset.Close();
  896. }
  897. if(1)
  898. {
  899. MyLock lock("xiaoaccessdbmsg");
  900. str=enterprisename;
  901. str.TrimLeft ();
  902. str.TrimRight ();
  903. if(str.IsEmpty ()==0)
  904. {
  905. CRecordset myset(&g_db);
  906. CString sql="select count(*) as cot from clientip where [enterprisename]='"+str+"'";
  907. myset.Open (CRecordset::forwardOnly, sql);
  908. myset.GetFieldValue ("cot", sql);
  909. myset.Close();
  910. if(atol(sql))
  911. {
  912. CArray<CStringArray, CStringArray>m_List1array;
  913. m_List1array.SetSize(atol(sql) , 1 );
  914. CRstClientIP rsSt;
  915. rsSt.m_strFilter ="[enterprisename]='"+str+"'";
  916. rsSt.Open();
  917. DWORD ii=0;
  918. while(!rsSt.IsEOF())
  919. {
  920. m_List1array.ElementAt (ii).RemoveAll ();
  921. m_List1array.ElementAt (ii).Add(rsSt.m_name) ;
  922. m_List1array.ElementAt (ii).Add(rsSt.m_branchname) ;
  923. m_List1array.ElementAt (ii).Add(rsSt.m_ip) ;
  924. m_List1array.ElementAt (ii).Add(rsSt.m_bmain) ;
  925. m_List1array.ElementAt (ii).Add(rsSt.m_enterprisename) ;
  926. rights=","+rsSt.m_rights+",";
  927. m_List1array.ElementAt (ii).Add(rights) ;
  928. m_List1array.ElementAt (ii).Add(rsSt.m_name2) ;
  929. ii++;
  930. rsSt.MoveNext();if(m_List1array.GetSize ()<=ii)break;
  931. }
  932. rsSt.Close();m_List1array.SetSize(ii , 1 );
  933. str.Empty ();
  934. nBranchArraySize=ii;
  935. CMemFile memfile;
  936. CArchive ar(&memfile, CArchive::store);
  937. for( ii=0; ii<m_List1array.GetSize (); ii++)
  938. {
  939. m_List1array.ElementAt (ii).Serialize (ar);
  940. }
  941. ar.Close();
  942. nBranchDataLeng=memfile.GetLength ();
  943. pBranchData=memfile.Detach();
  944. str="ok";
  945. }
  946. else
  947. str+="没有此企业的资料";
  948. // WriteLogin("查询企业资料成功");
  949. }
  950. else
  951. str+="没有此企业的资料";
  952. }
  953. }
  954. else if(dwToUserID==9)//企业版分店权限设置
  955. {
  956. CArray<CStringArray, CStringArray>m_List1array;
  957. CMemFile memfile;
  958. memfile.Attach (ptChatMessage->byFileContent+sizeof(DWORD), nMessageLen-sizeof(DWORD));
  959. CArchive ar(&memfile, CArchive::load);
  960. DWORD arraysize;
  961. memcpy(&arraysize, ptChatMessage->byFileContent, sizeof(DWORD));
  962. m_List1array.SetSize(arraysize);
  963. for(int ii=0; ii<m_List1array.GetSize (); ii++)
  964. {
  965. m_List1array.ElementAt (ii).Serialize (ar);
  966. }
  967. ar.Close();
  968. memfile.Detach ();CString enterprisename;
  969. if(m_List1array.GetSize ())
  970. {
  971. enterprisename=m_List1array.ElementAt (0).ElementAt (0);
  972. CString branchname,rights;
  973. for(ii=0; ii<m_List1array.GetSize (); ii++)
  974. {
  975. branchname=m_List1array.ElementAt (ii).ElementAt (1);
  976. rights.Empty ();
  977. for(int j=2; j<m_List1array.ElementAt (ii).GetSize (); j++)
  978. {
  979. rights+=m_List1array.ElementAt (ii).ElementAt (j);
  980. rights+=",";
  981. }
  982. rights.TrimRight (",");
  983. CString sql= "update clientip set [rights]='"+rights+"' where [enterprisename]='"+enterprisename+"' and [branchname]='"+branchname+"'";
  984. MyExecuteSQL(&g_db, sql);
  985. }
  986. }
  987. str="set ok";
  988. // WriteLogin("设置企业访问权限成功");
  989. }
  990. else if(dwToUserID==10)//登记客人IP
  991. {
  992. MyLock lock("accessclientip2");
  993. CString name=str;
  994. UINT nPeerPort;
  995. GetPeerName(str, nPeerPort);
  996. CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
  997. CString sql="update [clientip2] set [ip]='"+str+"',[datetime]='"+datetime+"' where [name]='"+name+"'";
  998. MyExecuteSQL(&g_db, sql);
  999. }
  1000. else if(dwToUserID==11)//查询客人IP
  1001. {
  1002. MyLock lock("xiaoaccessdbmsg");
  1003. CRecordset myset(&g_db);
  1004. CString sql="select ip from clientip2 where name='"+str+"'";
  1005. myset.Open (CRecordset::forwardOnly, sql);
  1006. if(!myset.IsEOF())
  1007. myset.GetFieldValue ("ip", str);
  1008. else
  1009. str+="没有此域名的记录!";
  1010. myset.Close();
  1011. }
  1012. else if(dwToUserID==12)//执行sql
  1013. {
  1014. g_db.ExecuteSQL (str);str="ok";
  1015. }
  1016. else if(dwToUserID==13)//查询sql
  1017. {
  1018. CString m_sql=str;
  1019. while(1)
  1020. {
  1021. str="ok";
  1022. if(m_sql.GetLength ()<6)break;
  1023. if(m_sql.Left (6)!="select")break;
  1024. int i;
  1025. CString temp;
  1026. int colcount;
  1027. CODBCFieldInfo fieldinfo;
  1028. CRecordset myset(&g_db);
  1029. myset.Open (CRecordset::forwardOnly, m_sql);
  1030. str="";
  1031. while(!myset.IsEOF ())
  1032. {
  1033. colcount=myset.GetODBCFieldCount ();
  1034. for( i=0; i<colcount; i++)
  1035. {
  1036. myset.GetFieldValue(i, temp);
  1037. str+="'"+temp+"',";
  1038. }
  1039. str.TrimRight (",");
  1040. str+="\r\n";
  1041. myset.MoveNext ();
  1042. }
  1043. myset.Close();break;
  1044. }
  1045. }
  1046. else if(dwToUserID==16)//登记客人
  1047. {
  1048. MyLock lock("accessclientip3");
  1049. CString separator="*%!X";
  1050. int sepleng=separator.GetLength();
  1051. CString domain,m_edit1,m_edit2,m_edit3,m_edit4,m_edit5,danshu;
  1052. int pos=str.Find(separator);
  1053. if(pos!=-1)
  1054. {
  1055. domain=str.Left(pos);
  1056. str=str.Right(str.GetLength()-pos-sepleng);
  1057. }
  1058. pos=str.Find(separator);
  1059. if(pos!=-1)
  1060. {
  1061. m_edit1=str.Left(pos);
  1062. str=str.Right(str.GetLength()-pos-sepleng);
  1063. }
  1064. pos=str.Find(separator);
  1065. if(pos!=-1)
  1066. {
  1067. m_edit2=str.Left(pos);
  1068. str=str.Right(str.GetLength()-pos-sepleng);
  1069. }
  1070. pos=str.Find(separator);
  1071. if(pos!=-1)
  1072. {
  1073. m_edit3=str.Left(pos);
  1074. str=str.Right(str.GetLength()-pos-sepleng);
  1075. }
  1076. pos=str.Find(separator);
  1077. if(pos!=-1)
  1078. {
  1079. m_edit4=str.Left(pos);
  1080. str=str.Right(str.GetLength()-pos-sepleng);
  1081. }
  1082. pos=str.Find(separator);
  1083. if(pos!=-1)
  1084. {
  1085. m_edit5=str.Left(pos);
  1086. str=str.Right(str.GetLength()-pos-sepleng);
  1087. danshu=str;
  1088. }
  1089. UINT nPeerPort;
  1090. GetPeerName(str, nPeerPort);
  1091. CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
  1092. CString sql;
  1093. CString ret;
  1094. CRecordset myset(&g_db);
  1095. sql="select ret from [softclient] where [domain]='"+domain+"' and [name]='"+m_edit1+"' and [phone]='"+m_edit2+"'";
  1096. myset.Open (CRecordset::forwardOnly, sql);
  1097. if(!myset.IsEOF())
  1098. myset.GetFieldValue ("ret", ret);
  1099. myset.Close();
  1100. sql="delete from [softclient] where [domain]='"+domain+"' and [name]='"+m_edit1+"' and [phone]='"+m_edit2+"'";
  1101. MyExecuteSQL(&g_db, sql);
  1102. sql.Format("insert into [softclient]([domain],[name],[phone],[addr],[admin],[version],[cot],[ip],[datetime],[ret])\
  1103. values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", domain,m_edit1,m_edit2,m_edit3,m_edit4,m_edit5,danshu,str,datetime,ret);
  1104. MyExecuteSQL(&g_db, sql);
  1105. str=ret;
  1106. }
  1107. /* else if(dwToUserID==14)//登记客人IP
  1108. {
  1109. CString name=str;
  1110. int pos=name.Find (";");
  1111. if(pos!=-1)
  1112. {
  1113. str=name.Right (name.GetLength ()-pos-1);
  1114. name=name.Left (pos);
  1115. CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
  1116. CString sql="update [clientip] set [ip]='"+str+"',[datetime]='"+datetime+"' where [name]='"+name+"'";
  1117. MyExecuteSQL(&g_db, sql);
  1118. WriteLogin2(name+"登记IP2");
  1119. }
  1120. else
  1121. str="0";
  1122. }*/
  1123. DWORD dwFromUserID = dwUserID;
  1124. WORD wMessageId = MSG_CHATMESSAGE_RESP;
  1125. DWORD dwDataLen;
  1126. BYTE *pSendData;
  1127. TCHAT_MESSAGE_STRU *pChatMessage;
  1128. TMessageHeader tHeader = {0};
  1129. tHeader.wMessageId = wMessageId;
  1130. tHeader.dwDataLen = dwDataLen;
  1131. if(str.IsEmpty ())str="OK";
  1132. int nDataLen=str.GetLength ();
  1133. if(nBranchDataLeng)
  1134. {
  1135. nDataLen=nBranchDataLeng;
  1136. g_sendhead.count[0]=nBranchArraySize;
  1137. }
  1138. dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen ;
  1139. pSendData = new BYTE[dwDataLen];
  1140. pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
  1141. memset(pChatMessage, 0x00, dwDataLen);
  1142. memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
  1143. pChatMessage->tCommonMsg.dwConnectionID = dwFromUserID;
  1144. pChatMessage->tCommonMsg.wMessageId = wMessageId;
  1145. pChatMessage->dwFromUserID = dwFromUserID;
  1146. pChatMessage->dwToUserID = dwToUserID;
  1147. pChatMessage->wMessageLen = nDataLen;
  1148. if(nBranchDataLeng)
  1149. {
  1150. memcpy(pChatMessage->byFileContent, pBranchData, nDataLen); delete []pBranchData;
  1151. }
  1152. else
  1153. {
  1154. memcpy(pChatMessage->byFileContent, str.GetBuffer (0), nDataLen);
  1155. str.ReleaseBuffer ();
  1156. }
  1157. net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
  1158. delete [] pSendData;
  1159. }
  1160. }
  1161. catch(...)
  1162. {
  1163. CString str;
  1164. str.Format ("出错-%d", dwToUserID);
  1165. WriteLogin(str);
  1166. }
  1167. g_bWork=0;
  1168. }
  1169. //没有此域名的记录