RecvData.cpp
上传用户:guangzhiyw
上传日期:2007-01-09
资源大小:495k
文件大小:34k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////
  2. //   //
  3. // 处理客户请求的工人线程函数   //
  4. //   //
  5. //   //
  6. ////////////////////////////////////////////////////////////////
  7. #include "stdafx.h"
  8. #include "common.h"
  9. #include "msg.h"
  10. #include "Server.h"
  11. #include "MainFrm.h"
  12. #include "ServerView.h"
  13. UINT ProcessRecvData(LPVOID param)
  14. {
  15. CData* pData=(CData*)param;
  16. UINT index=pData->index;
  17. CServerApp * pApp=(CServerApp*)AfxGetApp();
  18. CMainFrame* pMainWnd=(CMainFrame*)(pApp->m_pMainWnd);
  19. CServerView *pView=(CServerView*)(pMainWnd->GetActiveView());
  20. UserOnline * pUsers=pApp->m_pUsers;
  21. CDatabase * pDatabase=&pApp->m_Database;
  22. CServerSocket * pSocket=&pApp->m_Socket;
  23. ::InterlockedIncrement((long*)&pApp->m_nRecvMsg);
  24. switch(index)
  25. {
  26. case ONHIDE:
  27. {
  28. int pIndex=pData->MyId-UserIdRadix;
  29. if(pIndex>=0&&pIndex<pApp->m_nTotalUserNumber)  // true means it esxit
  30. {
  31. if(pUsers[pIndex].State==0||pUsers[pIndex].State==1)
  32. {
  33. CData mc;
  34. mc.index=ONHIDE_OK;
  35. mc.MyId=pData->MyId;
  36. mc.tarIP=pData->tarIP;
  37. mc.nPort=pData->nPort;
  38. mc.wIndex=pData->wIndex;
  39. if(!pSocket->SendData(&mc))break;
  40. if(pUsers[pIndex].State==0)
  41. {
  42. //找出我的朋友
  43. CRecordset recordset(pDatabase);
  44. CString mysql;
  45. mysql.Format("select FriendId from Friends where MyId=%d",pUsers[pIndex].Id);
  46. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  47. CDBVariant value;
  48. CArray<DWORD,DWORD>pFriendId;
  49. while(!recordset.IsEOF())
  50. {
  51. recordset.GetFieldValue(short(0),value);
  52. pFriendId.Add(value.m_lVal);
  53. recordset.MoveNext();
  54. }
  55. recordset.Close();
  56. // 发送好友列表给用户
  57. CMsg2 msg;
  58. msg.index=ALL_FRIEND_ID;
  59. msg.wIndex=pData->wIndex;
  60. msg.tarIP=pData->tarIP;
  61. msg.nPort=pData->nPort;
  62. msg.MyId=pData->MyId;
  63. msg.aFriendId.Append(pFriendId);
  64. if(!pSocket->SendData(&msg))break;
  65. // 发送在线好友给用户
  66. CMsgOnlineFriend msg1;
  67. msg1.index=ONLINE_FRIEND;
  68. msg1.wIndex=pData->wIndex;
  69. msg1.tarIP=pData->tarIP;
  70. msg1.nPort=pData->nPort;
  71. msg1.MyId=pData->MyId;
  72. for(int i=0;i<pFriendId.GetSize();i++)
  73. {
  74. int pi=pFriendId.GetAt(i)-UserIdRadix;
  75. if(pUsers[pi].State)
  76. {
  77. msg1.aFriendId.Add(pUsers[pi].Id);
  78. msg1.aFriendIP.Add(pUsers[pi].IP);
  79. msg1.aFriendPort.Add(pUsers[pi].Port);
  80. msg1.aFriendState.Add(pUsers[pi].State);
  81. }
  82. }
  83. Sleep(500);
  84. if(!pSocket->SendData(&msg1))break;
  85. //发送离线广播消息
  86. mysql.Format("select broadcast.SendTime,broadcast.SenderId,broadcast.msg,offbroadcast.num from broadcast,offbroadcast where offbroadcast.msgid=broadcast.msgid and offbroadcast.RecvId=%d",pData->MyId);
  87. CRecordset rs(pDatabase);
  88. rs.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  89. CMsg1 msg3;
  90. CDBVariant s1;
  91. msg3.tarIP=pData->tarIP;
  92. msg3.nPort=pData->nPort;
  93. msg3.index=SYSTEM_BROADCAST;
  94. msg3.wIndex=pData->wIndex;
  95. msg3.FriendId=pData->MyId;
  96. while(!rs.IsEOF())
  97. {
  98. rs.GetFieldValue(short(0),s1);
  99. msg3.Time=s1.m_lVal;
  100. rs.GetFieldValue(1,s1);
  101. msg3.MyId=s1.m_lVal;
  102. rs.GetFieldValue(2,msg3.Msg);
  103. rs.GetFieldValue(3,s1);
  104. int inum=0;
  105. inum=s1.m_lVal;
  106. Sleep(500);
  107. if(pSocket->SendData(&msg3))
  108. {
  109. CString sql1;
  110. sql1.Format("delete from offbroadcast where num=%d",inum);
  111. pDatabase->ExecuteSQL(sql1);
  112. }
  113. else
  114. {
  115. rs.Close();
  116. goto proc_end;
  117. }
  118. rs.MoveNext();
  119. }
  120. rs.Close();
  121. //发送离线消息
  122. mysql.Format("select * from offmsg where RecvId=%d",pData->MyId);
  123. rs.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  124. CMsg1 offmsg3;
  125. CDBVariant dbMsgId,dbSenderId,dbRecvId,dbRecvTime,dbmIndex;
  126. offmsg3.tarIP=pData->tarIP;
  127. offmsg3.nPort=pData->nPort;
  128. offmsg3.FriendId=pData->MyId;
  129. offmsg3.wIndex=pData->wIndex;
  130. while(!rs.IsEOF())
  131. {
  132. rs.GetFieldValue("MsgId",dbMsgId);
  133. rs.GetFieldValue("SenderId",dbSenderId);
  134. rs.GetFieldValue("RecvId",dbRecvId);
  135. rs.GetFieldValue("RecvTime",dbRecvTime);
  136. rs.GetFieldValue("mIndex",dbmIndex);
  137. rs.GetFieldValue("Msg",offmsg3.Msg);
  138. offmsg3.MyId=dbSenderId.m_lVal;
  139. offmsg3.Time=dbRecvTime.m_lVal;
  140. offmsg3.index=dbmIndex.m_chVal;
  141. int inum=0;
  142. inum=dbMsgId.m_lVal;
  143. Sleep(500);
  144. if(pSocket->SendData(&offmsg3))
  145. {
  146. CString sql1;
  147. sql1.Format("delete from offmsg where MsgID=%d",inum);
  148. pDatabase->ExecuteSQL(sql1);
  149. }
  150. else
  151. {
  152. rs.Close();
  153. goto proc_end;
  154. }
  155. rs.MoveNext();
  156. }
  157. rs.Close();
  158. pUsers[pIndex].IP=pData->tarIP;
  159. pUsers[pIndex].Port=pData->nPort;
  160. ::InterlockedIncrement((LPLONG)&pApp->m_nNumberOnline);
  161. }
  162. pUsers[pIndex].State=2;
  163. //找出把我当为好友的人,给其中在线或隐身的人发送我的隐身消息
  164. CRecordset recordset(pDatabase);
  165. CString mysql;
  166. mysql.Format("select MyId from Friends where FriendId=%d",pUsers[pIndex].Id);
  167. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  168. CDBVariant value;
  169. CNoticeMsg msg;
  170. msg.index=SOMEONE_ONHIDE;
  171. msg.MyId=pData->MyId;
  172. msg.IP=pData->tarIP;
  173. msg.Port=pData->nPort;
  174. while(!recordset.IsEOF())
  175. {
  176. recordset.GetFieldValue(short(0),value);
  177. int pi=value.m_lVal-UserIdRadix;
  178. if(pUsers[pi].State)
  179. {
  180. msg.tarIP=pUsers[pi].IP;
  181. msg.nPort=pUsers[pi].Port;
  182. pSocket->SendData(&msg);
  183. }
  184. recordset.MoveNext();
  185. }
  186. recordset.Close();
  187. }
  188. CString str;
  189. in_addr tIP;
  190. tIP.S_un.S_addr=pData->tarIP;
  191. str.Format("ID: %d 隐身登陆,IP: %s,Port: %d",pData->MyId,inet_ntoa(tIP),pData->nPort);
  192. #ifdef _DEBUG
  193. pView->ShowMessage(str);
  194. #endif
  195. }
  196. else
  197. {
  198. CString str;
  199. str.Format("ID: %d A Invalid ID",pData->MyId);
  200. #ifdef _DEBUG
  201. pView->ShowMessage(str);
  202. #endif
  203. }
  204. break;
  205. }
  206. case ONLINE:
  207. {
  208. int pIndex=pData->MyId-UserIdRadix;
  209. if(pIndex>=0&&pIndex<pApp->m_nTotalUserNumber)  // true means it esxit
  210. {
  211. if(pUsers[pIndex].State==0||pUsers[pIndex].State==2)
  212. {
  213. CData mc;
  214. mc.index=ONLINE_OK;
  215. mc.wIndex=pData->wIndex;
  216. mc.MyId=pData->MyId;
  217. mc.tarIP=pData->tarIP;
  218. mc.nPort=pData->nPort;
  219. if(!pSocket->SendData(&mc))break;
  220. if(pUsers[pIndex].State==0)
  221. {
  222. CRecordset recordset(pDatabase);
  223. CString mysql;
  224. mysql.Format("select FriendId from Friends where MyId=%d",pUsers[pIndex].Id);
  225. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  226. CDBVariant value;
  227. CArray<DWORD,DWORD>pFriendId;
  228. while(!recordset.IsEOF())
  229. {
  230. recordset.GetFieldValue(short(0),value);
  231. pFriendId.Add(value.m_lVal);
  232. recordset.MoveNext();
  233. }
  234. recordset.Close();
  235. // 发送好友列表给用户
  236. CMsg2 msg;
  237. msg.index=ALL_FRIEND_ID;
  238. msg.wIndex=pData->wIndex;
  239. msg.tarIP=pData->tarIP;
  240. msg.nPort=pData->nPort;
  241. msg.MyId=pData->MyId;
  242. msg.aFriendId.Append(pFriendId);
  243. if(!pSocket->SendData(&msg))break;
  244. // 发送在线好友给用户
  245. CMsgOnlineFriend msg1;
  246. msg1.index=ONLINE_FRIEND;
  247. msg1.wIndex=pData->wIndex;
  248. msg1.tarIP=pData->tarIP;
  249. msg1.nPort=pData->nPort;
  250. msg1.MyId=pData->MyId;
  251. for(int i=0;i<pFriendId.GetSize();i++)
  252. {
  253. int pi=pFriendId.GetAt(i)-UserIdRadix;
  254. if(pUsers[pi].State)
  255. {
  256. msg1.aFriendId.Add(pUsers[pi].Id);
  257. msg1.aFriendIP.Add(pUsers[pi].IP);
  258. msg1.aFriendPort.Add(pUsers[pi].Port);
  259. msg1.aFriendState.Add(pUsers[pi].State);
  260. }
  261. }
  262. Sleep(500);
  263. if(!pSocket->SendData(&msg1))break;
  264. //offline broadcast
  265. mysql.Format("select broadcast.SendTime,broadcast.SenderId,broadcast.msg,offbroadcast.num from broadcast,offbroadcast where offbroadcast.msgid=broadcast.msgid and offbroadcast.RecvId=%d",pData->MyId);
  266. CRecordset rs(pDatabase);
  267. rs.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  268. CMsg1 msg3;
  269. CDBVariant s1;
  270. msg3.wIndex=pData->wIndex;
  271. msg3.tarIP=pData->tarIP;
  272. msg3.nPort=pData->nPort;
  273. msg3.index=SYSTEM_BROADCAST;
  274. msg3.FriendId=pData->MyId;
  275. while(!rs.IsEOF())
  276. {
  277. rs.GetFieldValue(short(0),s1);
  278. msg3.Time=s1.m_lVal;
  279. rs.GetFieldValue(1,s1);
  280. msg3.MyId=s1.m_lVal;
  281. rs.GetFieldValue(2,msg3.Msg);
  282. rs.GetFieldValue(3,s1);
  283. int inum=0;
  284. inum=s1.m_lVal;
  285. Sleep(500);
  286. if(pSocket->SendData(&msg3))
  287. {
  288. CString sql1;
  289. sql1.Format("delete from offbroadcast where num=%d",inum);
  290. pDatabase->ExecuteSQL(sql1);
  291. }
  292. else
  293. {
  294. rs.Close();
  295. goto proc_end;
  296. }
  297. rs.MoveNext();
  298. }
  299. rs.Close();
  300. //offline msg
  301. mysql.Format("select * from offmsg where RecvId=%d",pData->MyId);
  302. rs.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  303. CMsg1 offmsg3;
  304. CDBVariant dbMsgId,dbSenderId,dbRecvId,dbRecvTime,dbmIndex;
  305. offmsg3.tarIP=pData->tarIP;
  306. offmsg3.nPort=pData->nPort;
  307. offmsg3.FriendId=pData->MyId;
  308. offmsg3.wIndex=pData->wIndex;
  309. while(!rs.IsEOF())
  310. {
  311. rs.GetFieldValue("MsgId",dbMsgId);
  312. rs.GetFieldValue("SenderId",dbSenderId);
  313. rs.GetFieldValue("RecvId",dbRecvId);
  314. rs.GetFieldValue("RecvTime",dbRecvTime);
  315. rs.GetFieldValue("mIndex",dbmIndex);
  316. rs.GetFieldValue("Msg",offmsg3.Msg);
  317. offmsg3.MyId=dbSenderId.m_lVal;
  318. offmsg3.Time=dbRecvTime.m_lVal;
  319. offmsg3.index=dbmIndex.m_chVal;
  320. int inum=0;
  321. inum=dbMsgId.m_lVal;
  322. Sleep(500);
  323. if(pSocket->SendData(&offmsg3))
  324. {
  325. CString sql1;
  326. sql1.Format("delete from offmsg where MsgID=%d",inum);
  327. pDatabase->ExecuteSQL(sql1);
  328. }
  329. else
  330. {
  331. rs.Close();
  332. goto proc_end;
  333. }
  334. rs.MoveNext();
  335. }
  336. rs.Close();
  337. ::InterlockedIncrement((LPLONG)&pApp->m_nNumberOnline);
  338. }
  339. pUsers[pIndex].State=1;
  340. pUsers[pIndex].IP=pData->tarIP;
  341. pUsers[pIndex].Port=pData->nPort;
  342. //找出把我当作好友的人,并发ONLINE消息
  343. CRecordset recordset(pDatabase);
  344. CString mysql;
  345. mysql.Format("select MyId from Friends where FriendId=%d",pUsers[pIndex].Id);
  346. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  347.     CDBVariant value;
  348. CNoticeMsg msg;
  349. msg.index=SOMEONE_ONLINE;
  350. msg.MyId=pData->MyId;
  351. msg.IP=pData->tarIP;
  352. msg.Port=pData->nPort;
  353. while(!recordset.IsEOF())
  354. {
  355. recordset.GetFieldValue(short(0),value);
  356. int pi=value.m_lVal-UserIdRadix;
  357. if(pUsers[pi].State)
  358. {
  359. msg.tarIP=pUsers[pi].IP;
  360. msg.nPort=pUsers[pi].Port;
  361. pSocket->SendData(&msg);
  362. }
  363. recordset.MoveNext();
  364. }
  365. recordset.Close();
  366. }
  367. CString str;
  368. in_addr tIP;
  369. tIP.S_un.S_addr=pData->tarIP;
  370. str.Format("ID: %d 上线(正常登陆),IP: %s,Port: %d",pData->MyId,inet_ntoa(tIP),pData->nPort);
  371. #ifdef _DEBUG
  372. pView->ShowMessage(str);
  373. #endif
  374. }
  375. else
  376. {
  377. CString str;
  378. str.Format("ID: %d A Invalid ID",pData->MyId);
  379. #ifdef _DEBUG
  380. pView->ShowMessage(str);
  381. #endif
  382. }
  383. break;
  384. }
  385. case OFFLINE:
  386. {
  387. int pIndex=pData->MyId-UserIdRadix;
  388. if(pIndex>=0&&pIndex<pApp->m_nTotalUserNumber)  // true means it esxit
  389. {
  390. if(pUsers[pIndex].State)
  391. {
  392. pUsers[pIndex].State=0;
  393. ::InterlockedDecrement((LPLONG)&pApp->m_nNumberOnline);
  394. //找出把我当作好友的人,并发OFFLINE消息
  395. CRecordset recordset(pDatabase);
  396. CString mysql;
  397. mysql.Format("select MyId from Friends where FriendId=%d",pUsers[pIndex].Id);
  398. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  399. CDBVariant value;
  400. CData msg;
  401. msg.index=SOMEONE_OFFLINE;
  402. msg.MyId=pData->MyId;
  403. while(!recordset.IsEOF())
  404. {
  405. recordset.GetFieldValue(short(0),value);
  406. int pi=value.m_lVal-UserIdRadix;
  407. if(pUsers[pi].State)
  408. {
  409. msg.tarIP=pUsers[pi].IP;
  410. msg.nPort=pUsers[pi].Port;
  411. pSocket->SendData(&msg);
  412. }
  413. recordset.MoveNext();
  414. }
  415. recordset.Close();
  416. }
  417. CString str;
  418. str.Format("ID: %d 下线",pData->MyId);
  419. #ifdef _DEBUG
  420. pView->ShowMessage(str);
  421. #endif
  422. }
  423. else
  424. {
  425. CString str;
  426. str.Format("ID: %d A Invalid ID",pData->MyId);
  427. #ifdef _DEBUG
  428. pView->ShowMessage(str);
  429. #endif
  430. }
  431. break;
  432. }
  433. case SEND_MSG_TO_FRIEND:
  434. case REFUSE_AS_FRIEND:
  435. case ACCEPT_AS_FRIEND:
  436. case FRIEND_IDENTITY_VALIDATE:
  437. {
  438. //  用户给朋友发的离线消息 
  439. CMsg1 msg;
  440. CopyDataBuf(&msg,pData);
  441. if(!msg.LoadFromBuf())
  442. {
  443. #ifdef _DEBUG
  444. pView->ShowMessage("msg.LoadFromBuf error!");
  445. #endif
  446. break;
  447. }
  448. int pIndex=msg.FriendId-UserIdRadix;
  449. int mIndex=msg.MyId-UserIdRadix;
  450. if(pIndex>=0&&pIndex<pApp->m_nTotalUserNumber&&mIndex>=0&&mIndex<pApp->m_nTotalUserNumber) //It's fit user
  451. {
  452. if(index==ACCEPT_AS_FRIEND)
  453. {
  454. CRecordset rs(pDatabase);
  455. CString sql1;
  456. sql1.Format("select friendid from friends where myid=%d and friendid=%d",msg.FriendId,msg.MyId);
  457. rs.Open(AFX_DB_USE_DEFAULT_TYPE,sql1);
  458. int count=rs.GetRecordCount();
  459. rs.Close();
  460. if(count==0)
  461. {
  462. CString mysql;
  463. mysql.Format("insert into Friends(Myid,FriendId) values(%d,%d)",msg.FriendId,msg.MyId);
  464. pDatabase->ExecuteSQL(mysql);
  465. }
  466. else break;
  467. }
  468. // Is frined online?
  469. BOOL SendOK=FALSE;
  470. if(pUsers[pIndex].State)
  471. {
  472. msg.tarIP=pUsers[pIndex].IP;
  473. msg.nPort=pUsers[pIndex].Port;
  474. if(pSocket->SendData(&msg))
  475. SendOK=TRUE;
  476. }
  477. // Save it to database
  478. if(!SendOK)
  479. {
  480. CString mysql;
  481. CTime t1=CTime::GetCurrentTime();
  482. mysql.Format("insert into offmsg(SenderId,RecvId,mIndex,RecvTime,Msg) values(%d,%d,%d,%d,'%s')",
  483. msg.MyId,msg.FriendId,msg.index,t1,msg.Msg);
  484. try
  485. {
  486. pDatabase->ExecuteSQL(mysql);
  487. }
  488. catch(CDBException e)
  489. {
  490. #ifdef _DEBUG
  491. pView->ShowMessage(e.m_strError);
  492. #endif
  493. }
  494. }
  495. CString str;
  496. str.Format("ID: %d To ID: %d 用户给朋友发的离线消息",msg.MyId,msg.FriendId);
  497. #ifdef _DEBUG
  498. pView->ShowMessage(str);
  499. #endif
  500. }
  501. else
  502. {
  503. #ifdef _DEBUG
  504. pView->ShowMessage("A Invalid Id");
  505. #endif
  506. }
  507. break;
  508. }
  509. case MULTI_SEND_MSG:
  510. {
  511. //  用户给多个朋友发的离线消息 
  512. CMsg2 msg;
  513. CopyDataBuf(&msg,pData);
  514. if(!msg.LoadFromBuf())
  515. {
  516. TRACE0("msg.LoadFromBuf error!n");
  517. break;
  518. }
  519. int mIndex=msg.MyId-UserIdRadix;
  520. if(mIndex>=0&&mIndex<pApp->m_nTotalUserNumber) //It's fit user
  521. {
  522. for(int i=0;i<msg.aFriendId.GetSize();i++)
  523. {
  524. int pIndex=msg.aFriendId.GetAt(i)-UserIdRadix;
  525. if(pIndex<0||pIndex>=pApp->m_nTotalUserNumber)continue;
  526. // Is This frined online?
  527. BOOL SendOK=FALSE;
  528. if(pUsers[pIndex].State)
  529. {
  530. CMsg1 msg1;
  531. msg1.index=SEND_MSG_TO_FRIEND;
  532. msg1.Msg=msg.Msg;
  533. msg1.MyId=msg.MyId;
  534. msg1.Time=msg.Time;
  535. msg1.FriendId=msg.aFriendId.GetAt(i);
  536. msg1.tarIP=pUsers[pIndex].IP;
  537. msg1.nPort=pUsers[pIndex].Port;
  538. if(pSocket->SendData(&msg1))
  539. SendOK=TRUE;
  540. }
  541. if(!SendOK)
  542. {
  543. // Save it to database
  544. CString mysql;
  545. CTime t1=CTime::GetCurrentTime();
  546. mysql.Format("insert into offmsg(SenderId,RecvId,mIndex,RecvTime,Msg) values(%d,%d,%d,%d,'%s')",
  547. msg.MyId,msg.aFriendId.GetAt(i),SEND_MSG_TO_FRIEND,t1,msg.Msg);
  548. try
  549. {
  550. pDatabase->ExecuteSQL(mysql);
  551. }
  552. catch(CDBException e)
  553. {
  554. #ifdef _DEBUG
  555. pView->ShowMessage(e.m_strError);
  556. #endif
  557. }
  558. }
  559. }
  560. CString str;
  561. str.Format("ID: %d 用户给多个朋友发的离线消息",msg.MyId);
  562. #ifdef _DEBUG
  563. pView->ShowMessage(str);
  564. #endif
  565. }
  566. break;
  567. }
  568. case SEND_BROADCAST:
  569. {
  570. //  发送广播消息
  571. CMsg4 msg;
  572. CopyDataBuf(&msg,pData);
  573. if(!msg.LoadFromBuf())
  574. {
  575. TRACE0("msg.LoadFromBuf error!n");
  576. break;
  577. }
  578. int mIndex=msg.MyId-UserIdRadix;
  579. if(mIndex>=0&&mIndex<pApp->m_nTotalUserNumber)
  580. {
  581. if(msg.BroadcastPwd==pApp->m_strBroadcastPwd)
  582. {
  583. CString mysql;
  584. CTime t1=CTime::GetCurrentTime();
  585. mysql.Format("insert into broadcast(SenderId,SendTime,Msg) values(%d,%d,'%s')",msg.MyId,t1,msg.Msg);
  586. pDatabase->ExecuteSQL(mysql);
  587. int CurMsgId=0;
  588. CRecordset rs(pDatabase);
  589. rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select last(MsgId) from broadcast");
  590. CDBVariant v1;
  591. rs.GetFieldValue(short(0),v1);
  592. rs.Close();
  593. CurMsgId=v1.m_lVal;
  594. // Check for everyone ,send broadcast
  595. CMsg1 msg1;
  596. msg1.index=SYSTEM_BROADCAST;
  597. msg1.MyId=msg.MyId;
  598. msg1.Msg=msg.Msg;
  599. msg1.Time=t1;
  600. for(int i=0;i<pApp->m_nTotalUserNumber;i++)
  601. {
  602. if(pUsers[i].Id==0||pUsers[i].Id==msg.MyId)
  603. continue;
  604. BOOL SendOK=FALSE;
  605. if(pUsers[i].State)
  606. {
  607. msg1.tarIP=pUsers[i].IP;
  608. msg1.nPort=pUsers[i].Port;
  609. if(pSocket->SendData(&msg1))
  610. SendOK=TRUE;
  611. }
  612. if(!SendOK)
  613. {
  614. //Save it to Database
  615. CString mysql;
  616. mysql.Format("insert into OffBroadcast(RecvId,MsgId) values(%d,%d)",i+1+UserIdRadix,CurMsgId);
  617. pDatabase->ExecuteSQL(mysql);
  618. }
  619. }
  620. CString str;
  621. str.Format("ID: %d 发送广播消息",msg.MyId);
  622. #ifdef _DEBUG
  623. pView->ShowMessage(str);
  624. #endif
  625. }
  626. }
  627. break;
  628. }
  629. case FRIEND_DETAIL:
  630. {
  631. // 好友详细信息
  632. CMsg1 msg;
  633. CopyDataBuf(&msg,pData);
  634. if(!msg.LoadFromBuf())
  635. {
  636. TRACE0("msg.LoadFromBuf error!n");
  637. break;
  638. }
  639. TRACE1("Request Friend Detail %dn",msg.FriendId);
  640. int mIndex=msg.FriendId-UserIdRadix;
  641. if(mIndex>=0&&mIndex<pApp->m_nTotalUserNumber&&pUsers[mIndex].Id)
  642. {
  643. CMsgPerson msg1;
  644. msg1.index=RE_FRIEND_DETAIL;
  645. msg1.wIndex=msg.wIndex;
  646. msg1.tarIP=msg.tarIP;
  647. msg1.nPort=msg.nPort;
  648. msg1.MyId=pUsers[mIndex].Id;
  649. msg1.Name=pUsers[mIndex].Name;
  650. msg1.PhotoId=pUsers[mIndex].PhotoId;
  651. msg1.Department=pUsers[mIndex].Department;
  652. CRecordset recordset(pDatabase);
  653. CString mysql;
  654. mysql.Format("select Sex,Age,Email,Homepage,Address,Phone,fax,description,canbeadd from Users where Id=%d",msg.FriendId);
  655. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  656. if(recordset.GetRecordCount()==0)break;
  657. CDBVariant s1;
  658. recordset.GetFieldValue(short(0),s1);
  659. msg1.Sex=s1.m_chVal;
  660. recordset.GetFieldValue(1,msg1.Age);
  661. recordset.GetFieldValue(2,msg1.Email);
  662. recordset.GetFieldValue(3,msg1.Homepage);
  663. recordset.GetFieldValue(4,msg1.Address);
  664. recordset.GetFieldValue(5,msg1.Phone);
  665. recordset.GetFieldValue(6,msg1.Fax);
  666. recordset.GetFieldValue(7,msg1.Description);
  667. recordset.GetFieldValue(8,s1);
  668. msg1.Canbeadd=s1.m_chVal;
  669. recordset.Close();
  670. if(pSocket->SendData(&msg1))
  671. {
  672. CString str;
  673. str.Format("ID: %d FriendID: %d 好友详细信息",msg.MyId,msg.FriendId);
  674. #ifdef _DEBUG
  675. pView->ShowMessage(str);
  676. #endif
  677. }
  678. }
  679. break;
  680. }
  681. case ADD_AS_FRIEND:
  682. {
  683. // 加为好友请求
  684. CMsg1 msg;
  685. CopyDataBuf(&msg,pData);
  686. if(!msg.LoadFromBuf())
  687. {
  688. TRACE0("msg.LoadFromBuf error!n");
  689. break;
  690. }
  691. int MyIndex=msg.MyId-UserIdRadix;
  692. int FriendIndex=msg.FriendId-UserIdRadix;
  693. //if it is not valid user.
  694. if(MyIndex<0||MyIndex>=pApp->m_nTotalUserNumber||FriendIndex<0||FriendIndex>=pApp->m_nTotalUserNumber)
  695. break;
  696. if(!pUsers[MyIndex].Id||!pUsers[FriendIndex].Id)break;
  697. // find the friendid user
  698. CMsg3 msg3;
  699. msg3.tarIP=msg.tarIP;
  700. msg3.nPort=msg.nPort;
  701. msg3.index=RE_ADD_AS_FRIEND;
  702. msg3.wIndex=msg.wIndex;
  703. if(pUsers[FriendIndex].CanbeAdd!=1)
  704. {
  705. // 拒绝任何人加入 or 需要身份验证
  706. msg3.Value=pUsers[FriendIndex].CanbeAdd;
  707. if(!pSocket->SendData(&msg3))
  708. break;
  709. }
  710. else
  711. {
  712. // add it be my friend
  713. CRecordset rs(pDatabase);
  714. CString sql1;
  715. sql1.Format("select friendid from friends where myid=%d and friendid=%d",msg.MyId,msg.FriendId);
  716. rs.Open(AFX_DB_USE_DEFAULT_TYPE,sql1);
  717. int count=rs.GetRecordCount();
  718. rs.Close();
  719. if(msg.MyId!=msg.FriendId&&count==0)
  720. {
  721. CString mysql;
  722. mysql.Format("insert into Friends(Myid,FriendId) values(%d,%d)",msg.MyId,msg.FriendId);
  723. pDatabase->ExecuteSQL(mysql);
  724. msg3.Value=1;
  725. //成功加入
  726. pSocket->SendData(&msg3);
  727. //通知被加入的人
  728. CMsg1 msg4;
  729. msg4.tarIP=pUsers[FriendIndex].IP;
  730. msg4.nPort=pUsers[FriendIndex].Port;
  731. msg4.index=BE_ADDED_AS_FRIEND;
  732. msg4.MyId=msg.MyId;
  733. msg4.FriendId=msg.FriendId;
  734. msg4.Msg.Format("%d 把你加为好友",msg.MyId);
  735. msg4.Time=CTime::GetCurrentTime();
  736. if(pUsers[FriendIndex].State&&pSocket->SendData(&msg4))
  737. {
  738. Sleep(500);
  739. CNoticeMsg msg5;
  740. if(pUsers[FriendIndex].State==1)
  741. msg5.index=SOMEONE_ONLINE;
  742. else
  743. msg5.index=SOMEONE_ONHIDE;
  744. msg5.MyId=pUsers[FriendIndex].Id;
  745. msg5.IP=pUsers[FriendIndex].IP;
  746. msg5.Port=pUsers[FriendIndex].Port;
  747. msg5.tarIP=pData->tarIP;
  748. msg5.nPort=pData->nPort;
  749. pSocket->SendData(&msg5);
  750. }
  751. else
  752. {
  753. CString mysql;
  754. mysql.Format("insert into offmsg(SenderId,RecvId,mIndex,RecvTime,Msg) values(%d,%d,%d,%d,'%s')",
  755. msg4.MyId,msg4.FriendId,msg4.index,msg4.Time,msg4.Msg);
  756. try
  757. {
  758. pDatabase->ExecuteSQL(mysql);
  759. }
  760. catch(CDBException e)
  761. {
  762. #ifdef _DEBUG
  763. pView->ShowMessage(e.m_strError);
  764. #endif
  765. }
  766. }
  767. }
  768. else
  769. {
  770. // this friend is already in your friends
  771. msg3.Value=3;
  772. if(!pSocket->SendData(&msg3))
  773. goto proc_end;
  774. }
  775. }
  776. CString str;
  777. str.Format("ID: %d want add ID: %d as friend!",msg.MyId,msg.FriendId);
  778. #ifdef _DEBUG
  779. pView->ShowMessage(str);
  780. #endif
  781. break;
  782. }
  783. case APPLY_SHOW_ONLINE:
  784. {
  785. //查看在线的人
  786. CMsg3 msg;
  787. CopyDataBuf(&msg,pData);
  788. if(!msg.LoadFromBuf())break;
  789. int mIndex=msg.MyId-UserIdRadix;
  790. if(mIndex<0||mIndex>=pApp->m_nTotalUserNumber||!pUsers[mIndex].Id)break;
  791. int offsize=msg.Value;
  792. int count=0;
  793. int mOff=offsize*PersonNumEveryTime;
  794. if(mOff>=pApp->m_nTotalUserNumber) break;
  795. for(int i=0;i<pApp->m_nTotalUserNumber&&count<mOff;i++)
  796. if(pUsers[i].State)count++;
  797. if(count==mOff)
  798. {
  799. CShowOnlinePeople msg1;
  800. msg1.tarIP=msg.tarIP;
  801. msg1.nPort=msg.nPort;
  802. msg1.index=RECV_SHOW_ONLINE;
  803. msg1.wIndex=msg.wIndex;
  804. msg1.MyId=msg.MyId;
  805. for(int j=0;i<pApp->m_nTotalUserNumber&&j<PersonNumEveryTime;i++)
  806. {
  807. if(pUsers[i].State)
  808. {
  809. msg1.aPhotoId.Add(pUsers[i].PhotoId);
  810. msg1.aId.Add(pUsers[i].Id);
  811. msg1.aName.Add(pUsers[i].Name);
  812. msg1.aDepartment.Add(pUsers[i].Department);
  813. j++;
  814. }
  815. }
  816. if(msg1.aId.GetSize()>0)
  817. pSocket->SendData(&msg1);
  818. }
  819. #ifdef _DEBUG
  820. pView->ShowMessage("查看在线的人");
  821. #endif
  822. break;
  823. }
  824. case FIND_FRIEND_BY_ID:
  825. {
  826. //用号码查找朋友
  827. CMsg1 msg;
  828. CopyDataBuf(&msg,pData);
  829. if(!msg.LoadFromBuf())break;
  830. int mIndex=msg.MyId-UserIdRadix;
  831. int fIndex=msg.FriendId-UserIdRadix;
  832. if(mIndex>=0&&mIndex<pApp->m_nTotalUserNumber&&fIndex>=0&&fIndex<pApp->m_nTotalUserNumber&&pUsers[fIndex].Id&&pUsers[mIndex].Id)  //fint it
  833. {
  834. //return this peron's detail
  835. CMsgPerson msg1;
  836. msg1.index=FOUND_FRIEND_BY_ID;
  837. msg1.wIndex=msg.wIndex;
  838. msg1.tarIP=msg.tarIP;
  839. msg1.nPort=msg.nPort;
  840. msg1.MyId=pUsers[fIndex].Id;
  841. msg1.Name=pUsers[fIndex].Name;
  842. msg1.PhotoId=pUsers[fIndex].PhotoId;
  843. msg1.Department=pUsers[fIndex].Department;
  844. CRecordset recordset(pDatabase);
  845. CString mysql;
  846. mysql.Format("select Sex,Age,Email,Homepage,Address,Phone,fax,description,canbeadd from Users where Id=%d",msg.FriendId);
  847. recordset.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  848. if(recordset.GetRecordCount()==0)break;
  849. CDBVariant s1;
  850. recordset.GetFieldValue(short(0),s1);
  851. msg1.Sex=s1.m_chVal;
  852. recordset.GetFieldValue(1,msg1.Age);
  853. recordset.GetFieldValue(2,msg1.Email);
  854. recordset.GetFieldValue(3,msg1.Homepage);
  855. recordset.GetFieldValue(4,msg1.Address);
  856. recordset.GetFieldValue(5,msg1.Phone);
  857. recordset.GetFieldValue(6,msg1.Fax);
  858. recordset.GetFieldValue(7,msg1.Description);
  859. recordset.GetFieldValue(8,s1);
  860. msg1.Canbeadd=s1.m_chVal;
  861. recordset.Close();
  862. pSocket->SendData(&msg1);
  863. }
  864. else
  865. {
  866. //return not found!
  867. CData msg1;
  868. msg1.index=ID_NOT_FOUND_BY_ID;
  869. msg1.wIndex=msg.wIndex;
  870. msg1.tarIP=msg.tarIP;
  871. msg1.nPort=msg.nPort;
  872. msg1.MyId=msg.MyId;
  873. pSocket->SendData(&msg1);
  874. }
  875. //-----------------------
  876. #ifdef _DEBUG
  877. pView->ShowMessage("用号码查找朋友");
  878. #endif
  879. break;
  880. }
  881. case FIND_FRIEND_BY_NAME:
  882. {
  883. //用姓名查找朋友
  884. CMsg4 msg;
  885. CopyDataBuf(&msg,pData);
  886. if(!msg.LoadFromBuf())break;
  887. int mIndex=msg.MyId-UserIdRadix;
  888. if(mIndex<0||mIndex>=pApp->m_nTotalUserNumber||!pUsers[mIndex].Id)break;
  889. CShowOnlinePeople msg1;
  890. for(int i=0;i<pApp->m_nTotalUserNumber;i++)
  891. {
  892. if(pUsers[i].Name==msg.Msg)
  893. {
  894. msg1.aPhotoId.Add(pUsers[i].PhotoId);
  895. msg1.aId.Add(pUsers[i].Id);
  896. msg1.aName.Add(pUsers[i].Name);
  897. msg1.aDepartment.Add(pUsers[i].Department);
  898. }
  899. }
  900. if(msg1.aId.GetSize()>0)
  901. {
  902. msg1.tarIP=msg.tarIP;
  903. msg1.nPort=msg.nPort;
  904. msg1.MyId=msg.MyId;
  905. msg1.index=FOUND_FRIEND_BY_NAME;
  906. msg1.wIndex=msg.wIndex;
  907. pSocket->SendData(&msg1);
  908. }
  909. else
  910. {
  911. CData msg2;
  912. msg2.tarIP=msg.tarIP;
  913. msg2.nPort=msg.nPort;
  914. msg2.MyId=msg.MyId;
  915. msg2.index=NAME_NOT_FOUND_BY_NAME;
  916. msg2.wIndex=msg.wIndex;
  917. pSocket->SendData(&msg2);
  918. }
  919. #ifdef _DEBUG
  920. pView->ShowMessage("用姓名查找朋友");
  921. #endif
  922. break;
  923. }
  924. case DELETE_A_FRIEND:
  925. {
  926. // 删除一个好友
  927. CMsg1 msg;
  928. CopyDataBuf(&msg,pData);
  929. if(!msg.LoadFromBuf())break;
  930. int MyIndex=msg.MyId-UserIdRadix;
  931. int FriendIndex=msg.FriendId-UserIdRadix;
  932. //if it is not valid user.
  933. if(MyIndex<0||MyIndex>=pApp->m_nTotalUserNumber||FriendIndex<0||FriendIndex>=pApp->m_nTotalUserNumber)
  934. break;
  935. if(!pUsers[MyIndex].Id||!pUsers[FriendIndex].Id)break;
  936. // delete the friendid user
  937. CString mysql;
  938. mysql.Format("delete from friends where myid=%d and friendid=%d",msg.MyId,msg.FriendId);
  939. pDatabase->ExecuteSQL(mysql);
  940. CString str;
  941. str.Format("ID: %d want 删除一个好友ID: %d",msg.MyId,msg.FriendId);
  942. #ifdef _DEBUG
  943. pView->ShowMessage(str);
  944. #endif
  945. break;
  946. }
  947. case DELETE_SELF_IN_FRIEND:
  948. {
  949. //选择在某人的好友中删除自己
  950. CMsg1 msg;
  951. CopyDataBuf(&msg,pData);
  952. if(!msg.LoadFromBuf())break;
  953. int MyIndex=msg.MyId-UserIdRadix;
  954. int FriendIndex=msg.FriendId-UserIdRadix;
  955. //if it is not valid user.
  956. if(MyIndex<0||MyIndex>=pApp->m_nTotalUserNumber||FriendIndex<0||FriendIndex>=pApp->m_nTotalUserNumber)
  957. break;
  958. if(!pUsers[MyIndex].Id||!pUsers[FriendIndex].Id)break;
  959. CString mysql;
  960. mysql.Format("delete from friends where myid=%d and friendid=%d",msg.FriendId,msg.MyId);
  961. pDatabase->ExecuteSQL(mysql);
  962. #ifdef _DEBUG
  963. pView->ShowMessage("选择在某人的好友中删除自己");
  964. #endif
  965. break;
  966. }
  967. case CHANGE_PERSONAL_INFO:
  968. {
  969. CMsgChangePI msg;
  970. CopyDataBuf(&msg,pData);
  971. if(!msg.LoadFromBuf())break;
  972. int mIndex=msg.MyId-UserIdRadix;
  973. if(mIndex<0||mIndex>=pApp->m_nTotalUserNumber||!pUsers[mIndex].Id)break;
  974. if(!msg.Mask)break;
  975. CString strHead,strWhere,str,Mysql;
  976. strHead.Format("update users set ");
  977. strWhere.Format(" where id=%d",msg.MyId);
  978. if(msg.Mask&CMsgChangePI::NAME)
  979. str.Format("Name='%s',",msg.Name),strHead+=str;
  980. if(msg.Mask&CMsgChangePI::SEX)
  981. str.Format("Sex='%d',",msg.Sex),strHead+=str;
  982. if(msg.Mask&CMsgChangePI::AGE)
  983. str.Format("Age='%s',",msg.Age),strHead+=str;
  984. if(msg.Mask&CMsgChangePI::CANBEADD)
  985. str.Format("Canbeadd=%d,",msg.Canbeadd),strHead+=str;
  986. if(msg.Mask&CMsgChangePI::ADDRESS)
  987. str.Format("Address=%d,",msg.Address),strHead+=str;
  988. if(msg.Mask&CMsgChangePI::DEPARTMENT)
  989. str.Format("department='%s',",msg.Department),strHead+=str;
  990. if(msg.Mask&CMsgChangePI::DESCRIPTION)
  991. str.Format("Description='%s',",msg.Description),strHead+=str;
  992. if(msg.Mask&CMsgChangePI::EMAIL)
  993. str.Format("email='%s',",msg.Email),strHead+=str;
  994. if(msg.Mask&CMsgChangePI::FAX)
  995. str.Format("Fax='%s',",msg.Fax),strHead+=str;
  996. if(msg.Mask&CMsgChangePI::HOMEPAGE)
  997. str.Format("Homepage='%s',",msg.Homepage),strHead+=str;
  998. if(msg.Mask&CMsgChangePI::PHONE)
  999. str.Format("Phone='%s',",msg.Phone),strHead+=str;
  1000. if(msg.Mask&CMsgChangePI::PHOTOID)
  1001. str.Format("Photoid=%d,",msg.PhotoId),strHead+=str;
  1002. if(strHead.GetAt(strHead.GetLength()-1)==',')
  1003. Mysql=strHead.Left(strHead.GetLength()-1);
  1004. else Mysql=strHead;
  1005. Mysql+=strWhere;
  1006. pDatabase->ExecuteSQL(Mysql);
  1007. // change in pUsers array
  1008. if(msg.Mask&CMsgChangePI::NAME)
  1009. pUsers[mIndex].Name=msg.Name;
  1010. if(msg.Mask&CMsgChangePI::CANBEADD)
  1011. pUsers[mIndex].CanbeAdd=msg.Canbeadd;
  1012. if(msg.Mask&CMsgChangePI::DEPARTMENT)
  1013. pUsers[mIndex].Department=msg.Department;
  1014. if(msg.Mask&CMsgChangePI::PHOTOID)
  1015. pUsers[mIndex].PhotoId=msg.PhotoId;
  1016. #ifdef _DEBUG
  1017. pView->ShowMessage("CHANGE_PERSONAL_INFORMATION");
  1018. #endif
  1019. break;
  1020. }
  1021. case CHANGE_PASSWORD:
  1022. {
  1023. CMsgModifyPwd msg;
  1024. CopyDataBuf(&msg,pData);
  1025. if(!msg.LoadFromBuf())break;
  1026. int mIndex=msg.MyId-UserIdRadix;
  1027. if(mIndex>=0&&mIndex<pApp->m_nTotalUserNumber&&pUsers[mIndex].Id)
  1028. {
  1029. CRecordset rs(pDatabase);
  1030. CString mysql;
  1031. mysql.Format("select Password from users where id=%d",msg.MyId);
  1032. rs.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  1033. if(rs.GetRecordCount==0)break;
  1034. CString pwd;
  1035. rs.GetFieldValue(short(0),pwd);
  1036. if(msg.OldPwd==pwd)
  1037. {
  1038. CString sql1;
  1039. sql1.Format("update users set Password=%s where id=%d",msg.NewPwd,msg.MyId);
  1040. pDatabase->ExecuteSQL(sql1);
  1041. }
  1042. }
  1043. CString str;
  1044. str.Format("ID: %d 修改个人信息",msg.MyId);
  1045. #ifdef _DEBUG
  1046. pView->ShowMessage(str);
  1047. #endif
  1048. break;
  1049. }
  1050. case APPLY_ID_LOGIN:
  1051. {
  1052. CMsgPerson msg;
  1053. CopyDataBuf(&msg,pData);
  1054. if(!msg.LoadFromBuf())break;
  1055. CString mysql; 
  1056. int nAppID=0;
  1057. pApp->m_criticalMaxUserId.Lock();
  1058. pApp->m_nTotalUserNumber++;
  1059. pApp->m_nMaxUserId++;
  1060. nAppID=pApp->m_nMaxUserId;
  1061. pApp->m_criticalMaxUserId.Unlock();
  1062. mysql.Format("insert into users(id,photoid,password,name,sex,age,canbeadd,email,homepage,address,phone,fax,department,description) values(%d,%d,'%s','%s',%d,'%s',%d,'%s','%s','%s','%s','%s','%s','%s')",
  1063. nAppID,msg.PhotoId,msg.Password,msg.Name,msg.Sex,msg.Age,msg.Canbeadd,msg.Email,msg.Homepage,msg.Address,msg.Phone,msg.Fax,msg.Department,msg.Description);
  1064. try
  1065. {
  1066. pDatabase->ExecuteSQL(mysql);
  1067. }
  1068. catch(CDBException e)
  1069. {
  1070. AfxMessageBox(e.m_strError);
  1071. }
  1072. CData msg1;
  1073. msg1.index=APPLY_ID_OK;
  1074. msg1.MyId=nAppID;
  1075. msg1.tarIP=msg.tarIP;
  1076. msg1.nPort=msg.nPort;
  1077. pSocket->SendData(&msg1);
  1078. ::InterlockedIncrement((LPLONG)&pApp->m_nNumberOnline);
  1079. pUsers[msg1.MyId-UserIdRadix].Id=msg1.MyId;
  1080. pUsers[msg1.MyId-UserIdRadix].Name=msg.Name;
  1081. pUsers[msg1.MyId-UserIdRadix].CanbeAdd=msg.Canbeadd;
  1082. pUsers[msg1.MyId-UserIdRadix].PhotoId=msg.PhotoId;
  1083. pUsers[msg1.MyId-UserIdRadix].Department=msg.Department;
  1084. pUsers[msg1.MyId-UserIdRadix].IP=msg.tarIP;
  1085. pUsers[msg1.MyId-UserIdRadix].Port=msg.nPort;
  1086. pUsers[msg1.MyId-UserIdRadix].State=1;
  1087. CString str;
  1088. str.Format("用户:%s 申请帐号成功,ID:%d",msg.Name,msg1.MyId);
  1089. #ifdef _DEBUG
  1090. pView->ShowMessage(str);
  1091. #endif
  1092. break;
  1093. }
  1094. case HAVE_ID_LOGIN:
  1095. {
  1096. //使用已有号码进行登陆
  1097. CMsgModifyPwd msg;
  1098. CopyDataBuf(&msg,pData);
  1099. if(!msg.LoadFromBuf())break;
  1100. int mIndex=msg.MyId-UserIdRadix;
  1101. CMsg3 msg1;
  1102. msg1.index=RE_LOGIN_INFO;
  1103. msg1.wIndex=msg.wIndex;
  1104. msg1.MyId=msg.MyId;
  1105. msg1.tarIP=msg.tarIP;
  1106. msg1.nPort=msg.nPort;
  1107. if(mIndex>=0&&mIndex<pApp->m_nTotalUserNumber&&pUsers[mIndex].Id)
  1108. {
  1109. CRecordset rs(pDatabase);
  1110. CString mysql;
  1111. mysql.Format("select Password from users where id=%d",msg.MyId);
  1112. rs.Open(AFX_DB_USE_DEFAULT_TYPE,mysql);
  1113. if(rs.GetRecordCount==0)break;
  1114. CString pwd;
  1115. rs.GetFieldValue(short(0),pwd);
  1116. if(msg.OldPwd!=pwd)
  1117. {
  1118. msg1.Value=1;
  1119. pSocket->SendData(&msg1);
  1120. }
  1121. else
  1122. {
  1123. msg1.Value=2;
  1124. pSocket->SendData(&msg1);
  1125. }
  1126. }
  1127. else
  1128. {
  1129. msg1.Value=0;
  1130. pSocket->SendData(&msg1);
  1131. }
  1132. CString str;
  1133. str.Format("ID: %d 使用已有ID进行登陆!",msg.MyId);
  1134. #ifdef _DEBUG
  1135. pView->ShowMessage(str);
  1136. #endif
  1137. break;
  1138. }
  1139. }
  1140. proc_end:
  1141. if(pData)
  1142. {
  1143. delete pData;
  1144. pData=NULL;
  1145. }
  1146. return 0;
  1147. }