mainCtrl.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. //mainCtrl.cpp TCHAT_MESSAGE_STRU
  2. #include "stdafx.h"
  3. ///////////////////////////////////////////////////////////////////////////////
  4. #include "mainCtrl.h"
  5. #include "mysqldata.h"
  6. #include "LYFZIPManage.h"
  7. extern CString g_mainpath;
  8. extern CDatabase g_db;
  9. CStringArray g_baduserarray;
  10. #include "MyTimer.h"
  11. ////////////////////////////////////////clientip
  12. BOOL BadUser(CString account)
  13. {
  14. for(int i=0; i<g_baduserarray.GetSize (); i++)
  15. {
  16. if(account==g_baduserarray.ElementAt (i))return 1;
  17. }
  18. return 0;
  19. }
  20. ///////////////////////////////////////////////////////////////////////////////
  21. ///////////////////////////////////////////////////////////////////////////////
  22. static void HandleServerNetEvent(IN SOCKET hSocket, IN ETransportEvent eEvent,
  23. IN void *pDataBuf, IN unsigned long nDataLen,
  24. IN int nError, IN void *pContext)
  25. {
  26. if( nError != TRANSPORT_OK ) return;
  27. CMainCtrl *pMainCtrl = (CMainCtrl *)pContext;
  28. if( NULL == pMainCtrl ) return;
  29. pMainCtrl->processNetEvent(hSocket, eEvent, pDataBuf, nDataLen);
  30. }
  31. ///////////////////////////////////////////////////////////////////////////////
  32. CMainCtrl::CMainCtrl()
  33. {
  34. int nElementSize = sizeof(TUSER_GAME_INFO_STRU);
  35. m_tClientConnections.Init(nElementSize, "SERVERTUNNEL_CONNECTION_TABLE");
  36. // g_baduserarray.Add ("564531");
  37. }
  38. CMainCtrl::~CMainCtrl()
  39. {
  40. }
  41. int CMainCtrl::StartServer()
  42. {
  43. /*for Client, Port can be 0,
  44. and for Server, Port is Listening Port*/
  45. unsigned short usPort = 8379;
  46. int nResult = m_tServerTunnel.net_OpenSocket(Transport_Server,
  47. usPort,
  48. HandleServerNetEvent, this);
  49. if( TRANSPORT_OK != nResult )
  50. {
  51. // printf("net_OpenSocket failed!\n");
  52. return nResult;
  53. }
  54. // printf("Server is ready! Port = %d...\n", usPort);
  55. return TRANSPORT_OK;
  56. }
  57. int CMainCtrl::StopServer()
  58. {
  59. //printf("\nNow is Stopping Server, please wait...");
  60. m_tServerTunnel.net_CloseSocket();
  61. m_tClientConnections.End();
  62. return TRANSPORT_OK;
  63. }
  64. CTableInfoMgr *CMainCtrl::GetClientConnectionTable()
  65. {
  66. return &m_tClientConnections;
  67. }
  68. ///////////////////////////////////////////////////////////////////////////////
  69. void CMainCtrl::processNetEvent(IN SOCKET hSocket,
  70. IN ETransportEvent eEvent,
  71. IN void *pRecvMsg, IN unsigned long nDataLen)
  72. {
  73. unsigned long ulUserID = hSocket;
  74. if( Transport_AcceptEv == eEvent )
  75. {
  76. // printf("Accept one new connection. Socket = %d\n", hSocket);
  77. }
  78. else if( Transport_ReadEv == eEvent )
  79. {
  80. if( NULL == pRecvMsg ) return;
  81. TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg;
  82. char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN;
  83. WORD dwMessageID = pHeader->wMessageId;
  84. switch(dwMessageID)
  85. {
  86. case MSG_LOGIN_REQ:
  87. {
  88. TLOGIN_STRU tLoginInfo = {0};
  89. memcpy(&tLoginInfo, pDataBuf, sizeof(TLOGIN_STRU));
  90. DWORD dwConnectionID = tLoginInfo.tCommonMsg.dwConnectionID;
  91. if( dwConnectionID != hSocket )
  92. {
  93. dwConnectionID = hSocket;
  94. tLoginInfo.tCommonMsg.dwConnectionID = dwConnectionID;
  95. }
  96. processLoginRequest(&tLoginInfo);
  97. break;
  98. }
  99. case MSG_CHATMESSAGE_REQ:
  100. {
  101. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  102. DWORD dwConnectionID = pChatMessage->tCommonMsg.dwConnectionID;
  103. if( dwConnectionID != hSocket )
  104. {
  105. dwConnectionID = hSocket;
  106. pChatMessage->tCommonMsg.dwConnectionID = dwConnectionID;
  107. }
  108. processChatMessageRequest((void *)pChatMessage);
  109. break;
  110. }
  111. }
  112. }
  113. else if( Transport_CloseEv == eEvent )
  114. {
  115. unsigned long ulUserID = hSocket;
  116. processDiconnection(ulUserID);
  117. }
  118. }
  119. void CMainCtrl::processLoginRequest(void *pLoginInfo)
  120. {
  121. if( NULL == pLoginInfo ) return;
  122. TLOGIN_STRU *ptLoginInfo = (TLOGIN_STRU *)pLoginInfo;
  123. DWORD dwUserID = ptLoginInfo->tCommonMsg.dwConnectionID;
  124. int nResult = VerifyUserLoginInfo((void *)ptLoginInfo);
  125. DWORD dwConnectionID = (LOGIN_RESULT_SUC == nResult) ? dwUserID : INVALID_SOCKET;
  126. WORD wMessageId = MSG_LOGIN_RESP;
  127. LOGIN_RESULT_STRU tLoginResult = {0};
  128. tLoginResult.tCommonMsg.dwConnectionID = dwConnectionID;
  129. tLoginResult.tCommonMsg.wMessageId = wMessageId;
  130. tLoginResult.byResult = nResult;
  131. tLoginResult.dwUserID = dwConnectionID;
  132. tLoginResult.byStatus =
  133. (LOGIN_RESULT_SUC == nResult) ? USER_STATUS_ONLINE : USER_STATUS_OFFLINE;
  134. CTableInfoMgr *pConnectionTable = GetClientConnectionTable();
  135. long lCount = pConnectionTable->GetItemCount();
  136. tLoginResult.wUserCount = (WORD)lCount;
  137. DWORD dwDataLen = sizeof(LOGIN_RESULT_STRU);
  138. TMessageHeader tHeader = {0};
  139. tHeader.wMessageId = wMessageId;
  140. tHeader.dwDataLen = dwDataLen;
  141. SOCKET hSocket = (SOCKET)dwUserID;
  142. m_tServerTunnel.net_Send(hSocket, &tHeader, (void *)&tLoginResult, dwDataLen);
  143. /*Send User Info*/
  144. TUSERLIST_INFO_STRU tUserListInfo = {0};
  145. dwDataLen = sizeof(TUSERLIST_INFO_STRU);
  146. memset(&tHeader, 0x00, sizeof(TMessageHeader));
  147. tHeader.wMessageId = MSG_USERINFO_RESP;
  148. tHeader.dwDataLen = dwDataLen;
  149. for(long lIndex = 0; lIndex < lCount; lIndex++)
  150. {
  151. TUSER_GAME_INFO_STRU *pUserInfo = (TUSER_GAME_INFO_STRU *)pConnectionTable->GetItemValue(lIndex);
  152. if( NULL == pUserInfo ) continue;
  153. memset(&tUserListInfo, 0x00, sizeof(TUSERLIST_INFO_STRU));
  154. tUserListInfo.dwConnectionID = pUserInfo->dwConnectionID;
  155. tUserListInfo.byStatus = pUserInfo->tUserInfo.byStatus;
  156. strcpy(tUserListInfo.szUserName, pUserInfo->tUserInfo.szUserName);
  157. if( dwUserID == pUserInfo->dwConnectionID ) /*The owner*/
  158. {
  159. sendMessageToAllUsers(&tHeader, (void *)&tUserListInfo, dwDataLen);
  160. }
  161. else /*The Others*/
  162. {
  163. m_tServerTunnel.net_Send(hSocket, &tHeader, (void *)&tUserListInfo, dwDataLen);
  164. }
  165. }
  166. }
  167. void CMainCtrl::processDiconnection(unsigned long ulUserID)
  168. {
  169. CTableInfoMgr *pConnectionTable = GetClientConnectionTable();
  170. TUSER_GAME_INFO_STRU *pUserInfo = (TUSER_GAME_INFO_STRU *)pConnectionTable->Find(ulUserID);
  171. if( NULL != pUserInfo )
  172. {
  173. TUSERLIST_INFO_STRU tUserListInfo = {0};
  174. DWORD dwDataLen = sizeof(TUSERLIST_INFO_STRU);
  175. TMessageHeader tHeader = {0};
  176. memset(&tHeader, 0x00, sizeof(TMessageHeader));
  177. tHeader.wMessageId = MSG_LOGOUT_RESP;
  178. tHeader.dwDataLen = dwDataLen;
  179. tUserListInfo.dwConnectionID = pUserInfo->dwConnectionID;
  180. tUserListInfo.byStatus = USER_STATUS_OFFLINE;
  181. strcpy(tUserListInfo.szUserName, pUserInfo->tUserInfo.szUserName);
  182. pConnectionTable->Delete(ulUserID);
  183. sendMessageToAllUsers(&tHeader, (void *)&tUserListInfo, dwDataLen);
  184. }
  185. // printf("Disconnect one connection. Socket = %ld\n", ulUserID);
  186. }
  187. void FillHeader(BYTE *pSendData, WORD wMessageId, DWORD dwDataLen)
  188. {
  189. TMessageHeader *pMessageHeader =(TMessageHeader*)pSendData;
  190. pMessageHeader->byVersion = 101;
  191. pMessageHeader->wHeaderFlag = MESSAGE_HEADER_FLAG;
  192. pMessageHeader->wMessageId = wMessageId;
  193. pMessageHeader->wMessageSubId = 0;
  194. pMessageHeader->dwDataLen = dwDataLen;
  195. pMessageHeader->wReserve = 0;
  196. /* convert network word */
  197. htons(pMessageHeader->wHeaderFlag);
  198. htons(pMessageHeader->wMessageId);
  199. htons(pMessageHeader->wMessageSubId);
  200. htonl(pMessageHeader->dwDataLen);
  201. htons(pMessageHeader->wCheckSum);
  202. htonl(pMessageHeader->wReserve);
  203. }
  204. BOOL CheckUser(CString account, CString psw)
  205. {
  206. CRstClientInfo rsSt;
  207. rsSt.m_strFilter ="[account]='"+account+"' and [psw]='"+psw+"'";
  208. rsSt.Open();
  209. if(!rsSt.IsEOF())
  210. {
  211. rsSt.Close();
  212. return 1;
  213. }
  214. rsSt.Close();
  215. return 0;
  216. }
  217. int CheckPhoneType(CString phoneno)//移动:0 联通:1 电信:2 小灵通:3 未知:-1
  218. {
  219. int i = 0;
  220. if(phoneno.IsEmpty ())return -1;
  221. for( i=0; i<phoneno.GetLength (); i++)
  222. {
  223. if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
  224. }
  225. if(phoneno.GetAt (0)=='1')
  226. {
  227. if(phoneno.GetLength ()!=11)
  228. return -1;
  229. int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144,182};
  230. int unicom[]={130,131,132,155,156,186,185};
  231. int telecom[]={133,153,189,180,181};
  232. for(i=0; i<sizeof(mobile)/sizeof(int); i++)
  233. {
  234. if(mobile[i]==atoi(phoneno.Left (3)))
  235. {
  236. return 0;
  237. }
  238. }
  239. for(i=0; i<sizeof(unicom)/sizeof(int); i++)
  240. {
  241. if(unicom[i]==atoi(phoneno.Left (3)))
  242. {
  243. return 1;
  244. }
  245. }
  246. for(i=0; i<sizeof(telecom)/sizeof(int); i++)
  247. {
  248. if(telecom[i]==atoi(phoneno.Left (3)))
  249. {
  250. return 2;
  251. }
  252. }
  253. return -1;
  254. }
  255. else if(phoneno.GetAt (0)=='0')
  256. {
  257. if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
  258. {
  259. return 3;
  260. }
  261. }
  262. return -1;
  263. }
  264. /*
  265. 移动:
  266. 139,138,137,136,135,134,159,158,152,151,150,157,188,187,144
  267. 联通:
  268. 130,131,132,155,156,186,185
  269. 电信:
  270. 133,153,189,180
  271. */
  272. extern void ReCalAccount(CString account);
  273. extern void WriteLogin(CString str);
  274. int GetBalance(CString account)
  275. {
  276. CString count1="";
  277. CString count2="";
  278. CString count3="";
  279. try
  280. {
  281. CRecordset myset(&g_db);
  282. CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
  283. myset.Open (CRecordset::forwardOnly, sql);
  284. if(!myset.IsEOF())
  285. myset.GetFieldValue ("cot", count1);
  286. myset.Close();
  287. sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
  288. myset.Open (CRecordset::forwardOnly, sql);
  289. if(!myset.IsEOF())
  290. myset.GetFieldValue ("cot", count2);
  291. myset.Close();
  292. sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
  293. myset.Open (CRecordset::forwardOnly, sql);
  294. if(!myset.IsEOF())
  295. myset.GetFieldValue ("cot", count3);
  296. myset.Close();
  297. // return atoi(count1)-min(atoi(count2),atoi(count3));
  298. return atoi(count1)-atoi(count2);
  299. }
  300. catch(...)
  301. {
  302. return -1;
  303. }
  304. }
  305. BOOL g_bWork=0;
  306. void CMainCtrl::processChatMessageRequest(void *pChatMsg)
  307. {
  308. }
  309. void CMainCtrl::sendMessageToAllUsers(void *pHeader,
  310. void *pDataBuf, unsigned long ulDataLen)
  311. {
  312. if( (NULL == pHeader) || (NULL == pDataBuf) || (0 >= ulDataLen) ) return;
  313. CTableInfoMgr *pConnectionTable = GetClientConnectionTable();
  314. long lCount = pConnectionTable->GetItemCount();
  315. for(long lIndex = 0; lIndex < lCount; lIndex++)
  316. {
  317. TUSER_GAME_INFO_STRU *pUserInfo = (TUSER_GAME_INFO_STRU *)pConnectionTable->GetItemValue(lIndex);
  318. if( NULL == pUserInfo ) continue;
  319. SOCKET hSocket = (SOCKET)pUserInfo->dwConnectionID;
  320. m_tServerTunnel.net_Send(hSocket, pHeader, pDataBuf, ulDataLen);
  321. }
  322. }
  323. ///////////////////////////////////////////////////////////////////////////////
  324. int CMainCtrl::VerifyUserLoginInfo(void *pLoginInfo)
  325. {
  326. /* static ticks=::GetTickCount ();
  327. if(::GetTickCount ()-ticks<500)
  328. {
  329. ticks=::GetTickCount ();
  330. return LOGIN_RESULT_FAILED;
  331. }
  332. ticks=::GetTickCount ();*/
  333. int nResult = LOGIN_RESULT_SUC;
  334. if( NULL == pLoginInfo )
  335. {
  336. return LOGIN_RESULT_FAILED;
  337. }
  338. TLOGIN_STRU *ptLoginInfo = (TLOGIN_STRU *)pLoginInfo;
  339. DWORD dwUserID = ptLoginInfo->tCommonMsg.dwConnectionID;
  340. /* CString ip;
  341. struct sockaddr_in sa;
  342. int salen = sizeof(sa);
  343. SOCKET s=dwUserID;
  344. ::getpeername( s, (struct sockaddr*)&sa, &salen );
  345. ip.Format ("%d.%d.%d.%d", (BYTE)sa.sin_addr.S_un.S_un_b.s_b1 , (BYTE)sa.sin_addr.S_un.S_un_b.s_b2 , (BYTE)sa.sin_addr.S_un.S_un_b.s_b3 , (BYTE)sa.sin_addr.S_un.S_un_b.s_b4);
  346. CRecordset myset(&g_db);
  347. CString sql="select count(*) as cot from noregisterdomain where [ip]='"+ip+"'";
  348. myset.Open (CRecordset::forwardOnly, sql);
  349. myset.GetFieldValue ("cot", sql);
  350. myset.Close();
  351. if(atoi(sql))
  352. {
  353. WriteLogin2(ip+"-此IP未绑定");
  354. shutdown(s,SD_BOTH);
  355. closesocket(s);
  356. return LOGIN_RESULT_FAILED;
  357. }*/
  358. /*verify the user information*/
  359. CTableInfoMgr *pConnectionTable = GetClientConnectionTable();
  360. long lCount = pConnectionTable->GetItemCount();
  361. for(long lIndex = 0; lIndex < lCount; lIndex++)
  362. {
  363. TUSER_GAME_INFO_STRU *pUserInfo = (TUSER_GAME_INFO_STRU *)pConnectionTable->GetItemValue(lIndex);
  364. if( NULL == pUserInfo ) continue;
  365. if( (0 == stricmp(pUserInfo->tUserInfo.szUserName, ptLoginInfo->tUserInfo.szUserName))
  366. && (USER_STATUS_ONLINE == pUserInfo->tUserInfo.byStatus) )
  367. {
  368. return LOGIN_RESULT_MULTI;
  369. }
  370. }
  371. TUSER_GAME_INFO_STRU *pUserGameInfo = new TUSER_GAME_INFO_STRU;
  372. memset(pUserGameInfo, 0x00, sizeof(TUSER_GAME_INFO_STRU));
  373. pUserGameInfo->dwConnectionID = dwUserID;
  374. pUserGameInfo->tUserInfo.dwUserID = dwUserID;
  375. strcpy(pUserGameInfo->tUserInfo.szUserName, ptLoginInfo->tUserInfo.szUserName);
  376. strcpy(pUserGameInfo->tUserInfo.szPassword, ptLoginInfo->tUserInfo.szPassword);
  377. pUserGameInfo->tUserInfo.byStatus = USER_STATUS_ONLINE;
  378. pConnectionTable->Add(pUserGameInfo->dwConnectionID, (void *)pUserGameInfo);
  379. return nResult;
  380. }
  381. int CMainCtrl::GetLengthEx(CString str)
  382. {
  383. int leng=0;
  384. TBYTE ucHigh, ucLow;
  385. for (int i=0; i<str.GetLength(); i++)
  386. {
  387. if ( (TBYTE)str[i] < 0x80 )
  388. {
  389. leng++;
  390. continue;
  391. }
  392. ucHigh = (TBYTE)str[i];
  393. if(i+1==str.GetLength())
  394. {
  395. leng++;
  396. break;
  397. }
  398. ucLow = (TBYTE)str[i+1];
  399. if ( ucHigh < 0xa1 || ucLow < 0xa1)
  400. {
  401. leng++;
  402. continue;
  403. }
  404. leng++;
  405. i++;
  406. }
  407. return leng;
  408. }
  409. int CMainCtrl::GetCount(CString phones, CString content)
  410. {
  411. int count=0;
  412. int leng=GetLengthEx(content);
  413. int m_nMobile=0;
  414. int m_nPhone=0;
  415. CStringArray phonearray;
  416. int pos=phones.Find (",");
  417. if(pos!=-1)
  418. {
  419. phonearray.Add(phones.Left (pos));
  420. phones=phones.Right (phones.GetLength ()-pos-1);
  421. pos=phones.Find (",");
  422. while(pos!=-1)
  423. {
  424. phonearray.Add (phones.Left (pos));
  425. phones=phones.Right (phones.GetLength ()-pos-1);
  426. pos=phones.Find (",");
  427. }
  428. phonearray.Add (phones);
  429. }
  430. else
  431. phonearray.Add (phones);
  432. for(int i=0; i<phonearray.GetSize (); i++)
  433. {
  434. phones=phonearray.ElementAt (i);
  435. if(CheckPhoneType(phones)==0 || CheckPhoneType(phones)==1 || CheckPhoneType(phones)==2)
  436. m_nMobile++;
  437. else if(CheckPhoneType(phones)==3)
  438. m_nPhone++;
  439. }
  440. if(m_nMobile)
  441. {
  442. count+=m_nMobile*(leng/70);
  443. if(leng%70)
  444. count+=m_nMobile;
  445. }
  446. if(m_nPhone)
  447. {
  448. count+=m_nPhone*(leng/56);
  449. if(leng%56)
  450. count+=m_nPhone;
  451. }
  452. return count;
  453. }
  454. BOOL CMainCtrl::IsExist(CString account, CString phones, CString content, CString timestamp)
  455. {//已保存此条记录, 不再保存, 否则重复
  456. CRecordset myset(&g_db);
  457. CString sql="select count(*) as cot from sendreg where [account]='"+account+"' and [content]='"+content+"' and [phones]='"+phones+"' and [timestamp]='"+timestamp+"'";
  458. myset.Open (CRecordset::forwardOnly, sql);
  459. if(!myset.IsEOF())
  460. {
  461. myset.GetFieldValue ("cot", sql);
  462. if(atoi(sql))
  463. return 1;
  464. else
  465. return 0;
  466. }
  467. else
  468. return 0;
  469. }
  470. void CMainCtrl::WriteLog(CString account, CString content)
  471. {
  472. }
  473. /*
  474. CStringArray contentarray;
  475. CStringArray contentarray2;
  476. int leng[2]={70,56};
  477. CStringArray *pArray[2]={&contentarray,&contentarray2};
  478. for(int a=0; a<1; a++)
  479. {
  480. CString contenttemp=content;
  481. if(GetLengthEx(contenttemp)>leng[a])
  482. {
  483. while(GetLengthEx(contenttemp)>leng[a])
  484. {
  485. for(int pos=leng[a]; pos<contenttemp.GetLength (); pos++)
  486. {
  487. if(GetLengthEx(contenttemp.Left (pos))==leng[a])
  488. {
  489. if((pos+1)<contenttemp.GetLength ())
  490. {
  491. if(GetLengthEx(contenttemp.Left (pos+1))==leng[a])
  492. pos++;
  493. }
  494. break;
  495. }
  496. }
  497. if(pos==contenttemp.GetLength ())
  498. {
  499. pArray[a]->Add (contenttemp);
  500. contenttemp.Empty ();
  501. break;
  502. }
  503. else
  504. {
  505. pArray[a]->Add (contenttemp.Left (pos));
  506. contenttemp=contenttemp.Right (contenttemp.GetLength ()-pos);
  507. }
  508. }
  509. if(!contenttemp.IsEmpty ())
  510. pArray[a]->Add (contenttemp);
  511. }
  512. else
  513. pArray[a]->Add (content);
  514. }
  515. CStringArray phonearray;
  516. int pos=phones.Find (",");
  517. if(pos!=-1)
  518. {
  519. phonearray.Add(phones.Left (pos));
  520. phones=phones.Right (phones.GetLength ()-pos-1);
  521. pos=phones.Find (",");
  522. while(pos!=-1)
  523. {
  524. phonearray.Add (phones.Left (pos));
  525. phones=phones.Right (phones.GetLength ()-pos-1);
  526. pos=phones.Find (",");
  527. }
  528. phonearray.Add (phones);
  529. }
  530. else
  531. phonearray.Add (phones);
  532. int phonearraysize1,phonearraysize2,phonearraysize3,phonearraysize4;
  533. CArray<CStringArray, CStringArray>multiphonearray1;
  534. CArray<CStringArray, CStringArray>multiphonearray2;
  535. CArray<CStringArray, CStringArray>multiphonearray3;
  536. CArray<CStringArray, CStringArray>multiphonearray4;
  537. phonearraysize1=phonearraysize2=phonearraysize3=phonearraysize4=1;
  538. multiphonearray1.SetSize(phonearraysize1);multiphonearray1.ElementAt (0).RemoveAll ();
  539. multiphonearray2.SetSize(phonearraysize2);multiphonearray2.ElementAt (0).RemoveAll ();
  540. multiphonearray3.SetSize(phonearraysize3);multiphonearray3.ElementAt (0).RemoveAll ();
  541. multiphonearray4.SetSize(phonearraysize4);multiphonearray4.ElementAt (0).RemoveAll ();
  542. int size[4]={1,1,1,1};
  543. CArray<CStringArray, CStringArray> *pPhoneArray[4]={&multiphonearray1,&multiphonearray2,&multiphonearray3,&multiphonearray4};
  544. for(int i=0; i<phonearray.GetSize (); i++)
  545. {
  546. phones=phonearray.ElementAt (i);
  547. pos=CheckPhoneType(phones);
  548. if(pos==-1)continue;
  549. if(pPhoneArray[pos]->ElementAt (size[pos]-1).GetSize ()>=1000)
  550. {
  551. size[pos]++;
  552. pPhoneArray[pos]->SetSize(size[pos]);
  553. pPhoneArray[pos]->ElementAt (size[pos]-1).RemoveAll ();
  554. pPhoneArray[pos]->ElementAt (size[pos]-1).Add (phones);
  555. }
  556. else
  557. {
  558. pPhoneArray[pos]->ElementAt (size[pos]-1).Add (phones);
  559. }
  560. }
  561. ///
  562. for(i=0; i<4; i++)
  563. {
  564. for(int j=0; j<pPhoneArray[i]->GetSize (); j++)
  565. {
  566. if(!pPhoneArray[i]->ElementAt(j).GetSize ())continue;
  567. phones.Empty ();
  568. for(int n=0; n<pPhoneArray[i]->ElementAt (j).GetSize (); n++)
  569. {
  570. phones+=pPhoneArray[i]->ElementAt (j).ElementAt (n);
  571. phones+=",";
  572. }
  573. phones.TrimRight (",");
  574. if(i<3)
  575. {
  576. for(int m=0; m<contentarray.GetSize (); m++)
  577. {
  578. content=contentarray.ElementAt (m);
  579. int count=GetCount(phones,content);
  580. count2+=count;
  581. CString scount;
  582. scount.Format ("%d", count);
  583. if(IsExist(account,phones,content,timestamp))
  584. break;
  585. sql="insert into sendreg([account],[phones],[content],[timestamp],[msgcount],[msgcount2]) values\
  586. ('"+account+"','"+phones+"','"+content+"','"+timestamp+"','"+scount+"','0')";
  587. MyExecuteSQL(&g_db, sql);
  588. }
  589. }
  590. else
  591. {
  592. }
  593. }
  594. }
  595. // if(count2!=count)
  596. // AfxMessageBox("数量不一至");
  597. ReCalAccount(account);
  598. str="发送信息成功!";
  599. */
  600. //nullbalance