ClientProcess.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. #include "StdAfx.h"
  2. #include "ClientProcess.h"
  3. #ifdef _DEBUG
  4. #define new DEBUG_NEW
  5. #endif
  6. CRITICAL_SECTION CClientProcess::m_csMsgInfo;
  7. list<MsgInfo> CClientProcess::m_listMsgInfo;
  8. CString GetAuthCode(CString requestcode, long newsecond)
  9. {
  10. try
  11. {
  12. UINT m_year;
  13. UINT m_month;
  14. UINT m_day;
  15. UINT m_hour;
  16. UINT m_minute;
  17. {
  18. TCHAR year[10],month[10],day[10],hour[10],minute[10], second[10];
  19. ConvertTimerToStringReal(newsecond, year, month, day, hour, minute, second);
  20. m_year=_ttoi(year);
  21. m_month=_ttoi(month);
  22. m_day=_ttoi(day);
  23. m_hour=_ttoi(hour);
  24. m_minute=_ttoi(minute);
  25. if(newsecond==60)
  26. {
  27. m_year=60;
  28. m_month=0;
  29. m_day=0;
  30. m_hour=0;
  31. m_minute=0;
  32. }
  33. }
  34. if(m_year<0 || m_month<0 || m_day<0 || m_hour<0 || m_minute<0)
  35. {
  36. return _T("");
  37. }
  38. requestcode.TrimLeft();
  39. requestcode.TrimRight();
  40. requestcode.Replace("\n", "");
  41. requestcode.Replace("\r", "");
  42. if(requestcode.IsEmpty())
  43. {
  44. return "";
  45. }
  46. TString str,temp,temp2;
  47. int id,time1,time2,idtemp;
  48. int leng;
  49. str=requestcode;
  50. temp=str.substr(0,3);
  51. str=str.substr(3);
  52. leng=_ttoi(temp.substr(0,2).c_str());
  53. temp2=str.substr(0, leng);
  54. str=str.substr(leng);
  55. id=_ttoi(temp2.c_str());
  56. if(temp.substr(temp.length() -1)=="1")id=-id;
  57. //////////////////////////////////////////////////
  58. temp=str.substr(0,3);
  59. str=str.substr(3);
  60. leng=_ttoi(temp.substr(0,2).c_str());
  61. temp2=str.substr(0, leng);
  62. str=str.substr(leng);
  63. time1=_ttoi(temp2.c_str());
  64. if(temp.substr(temp.length() -1)=="1")time1=-time1;
  65. //////////////////////////////////////////////////
  66. temp=str.substr(0,3);
  67. str=str.substr(3);
  68. leng=_ttoi(temp.substr(0,2).c_str());
  69. temp2=str.substr(0, leng);
  70. str=str.substr(leng);
  71. time2=_ttoi(temp2.c_str());
  72. if(temp.substr(temp.length() -1)=="1")time2=-time2;
  73. //////////////////////////////////////////////////////
  74. temp=str.substr(0,3);
  75. str=str.substr(3);
  76. leng=_ttoi(temp.substr(0,2).c_str());
  77. temp2=str.substr(0, leng);
  78. str=str.substr(leng);
  79. idtemp=_ttoi(temp2.c_str());
  80. if(temp.substr(temp.length() -1)=="1")idtemp=-idtemp;
  81. //////////////////////////////////////////////////////
  82. // SoftKey ytSoftKey;
  83. int ret=0;//ytSoftKey.Ini();
  84. if (ret!=0 )
  85. {
  86. return "";
  87. }
  88. int d[8];double f[8];
  89. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  90. // 运行自定义函数;
  91. ret=ytSoftKey.code2(&id,&idtemp,&time1,&time2,&d[4],&d[5],&d[6],&d[7],
  92. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  93. s0,s1,s2,s3,s4,s5,s6,s7);
  94. if(ret!=0 && ret!=-43)
  95. {
  96. return "";
  97. }
  98. ////////////////////////////////////////////////////////////////////////
  99. TCHAR DevicePath[ 260];
  100. if(FindPort(0,DevicePath)!=0)
  101. return "";
  102. DWORD OutID;
  103. int version;
  104. GetIDVersion(&OutID, &version, DevicePath);
  105. TCHAR year[10],month[10],day[10],hour[10],minute[10], OutString[100];
  106. _stprintf_s(year, _T("%d"), m_year);
  107. _stprintf_s(month, _T("%d"), m_month);
  108. _stprintf_s(day, _T("%d"), m_day);
  109. _stprintf_s(hour, _T("%d"), m_hour);
  110. _stprintf_s(minute, _T("%d"), m_minute);
  111. MakeTimerAuth("20D30D15FFB7F6AF9EAB30FD229F797B", id, year, month, day, hour, minute, OutString,DevicePath);
  112. CString authcode=OutString;
  113. TCHAR szTemp[50] = {0};
  114. //str.Format ("%04d", m_year);
  115. _stprintf_s(szTemp, _T("%04d"), m_year);
  116. authcode += szTemp;
  117. //str.Format ("%02d", m_month);
  118. _stprintf_s(szTemp, _T("%02d"), m_month);
  119. authcode += szTemp;
  120. //str.Format ("%02d", m_day);
  121. _stprintf_s(szTemp, _T("%02d"), m_day);
  122. authcode+=szTemp;
  123. _stprintf_s(szTemp, _T("%02d"), m_hour);
  124. //str.Format ("%02d", m_hour);
  125. authcode+=szTemp;
  126. _stprintf_s(szTemp, _T("%02d"), m_minute);
  127. //str.Format ("%02d", m_minute);
  128. authcode+=szTemp;
  129. //str.Format ("%08d", id);
  130. _stprintf_s(szTemp, _T("%08d"), id);
  131. authcode+=szTemp;
  132. TString str1,str2,str3,str4,str5;
  133. str1=authcode.Mid (0, 20);
  134. str2=authcode.Mid (20, 20);
  135. str3=authcode.Mid (40, 20);
  136. str4=authcode.Mid (60, 20);
  137. str5=authcode.Mid (80, 20);
  138. _stprintf_s(s0, "%s", str1.c_str());
  139. _stprintf_s(s1, "%s", str2.c_str());
  140. _stprintf_s(s2, "%s", str3.c_str());
  141. _stprintf_s(s3, "%s", str4.c_str());
  142. _stprintf_s(s4, "%s", str5.c_str());
  143. //运行自定义函数
  144. {
  145. SoftKey ytSoftKey2;
  146. ret=ytSoftKey2.Ini();
  147. if (ret!=0 )
  148. {
  149. return "";
  150. }
  151. {
  152. int d[8];double f[8];
  153. char s5[50]="",s6[50]="",s7[50]="";
  154. ret=ytSoftKey2.code1(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
  155. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  156. s0,s1,s2,s3,s4,s5,s6,s7);
  157. }
  158. if(ret!=0 && ret!=-43)
  159. {
  160. return "";
  161. }
  162. str1=s0;
  163. str2=s1;
  164. str3=s2;
  165. str4=s3;
  166. str5=s4;
  167. }
  168. authcode=str1.c_str();
  169. authcode+=str2.c_str();
  170. authcode+=str3.c_str();
  171. authcode+=str4.c_str();
  172. authcode+=str5.c_str();
  173. return authcode;
  174. }
  175. catch(...)
  176. {
  177. }
  178. return _T("");
  179. }
  180. CString GetUseDays(CString requestcode)
  181. {
  182. try
  183. {
  184. CString sRet;
  185. requestcode.TrimLeft();
  186. requestcode.TrimRight();
  187. requestcode.Replace("\n", "");
  188. requestcode.Replace("\r", "");
  189. if(requestcode.IsEmpty())
  190. {
  191. return "";
  192. }
  193. TString str,temp,temp2;
  194. int id,time1,time2,idtemp;
  195. int leng;
  196. str=requestcode;
  197. temp=str.substr(0,3);
  198. str=str.substr(3);
  199. leng=_ttoi(temp.substr(0,2).c_str());
  200. temp2=str.substr(0,leng);
  201. str=str.substr(leng);
  202. id=_ttoi(temp2.c_str());
  203. if(temp.substr(temp.length() - 1)=="1")id=-id;
  204. //////////////////////////////////////////////////
  205. temp=str.substr(0,3);
  206. str=str.substr(3);
  207. leng=_ttoi(temp.substr(0,2).c_str());
  208. temp2=str.substr(0,leng);
  209. str=str.substr(leng);
  210. time1=_ttoi(temp2.c_str());
  211. if(temp.substr(temp.length() - 1)=="1")time1=-time1;
  212. //////////////////////////////////////////////////
  213. temp=str.substr(0,3);
  214. str=str.substr(3);
  215. leng=_ttoi(temp.substr(0,2).c_str());
  216. temp2=str.substr(0,leng);
  217. str=str.substr(leng);
  218. time2=_ttoi(temp2.c_str());
  219. if(temp.substr(temp.length() - 1)=="1")time2=-time2;
  220. //////////////////////////////////////////////////////
  221. temp=str.substr(0,3);
  222. str=str.substr(3);
  223. leng=_ttoi(temp.substr(0,2).c_str());
  224. temp2=str.substr(0,leng);
  225. str=str.substr(leng);
  226. idtemp=_ttoi(temp2.c_str());
  227. if(temp.substr(temp.length() - 1)=="1")idtemp=-idtemp;
  228. //////////////////////////////////////////////////////
  229. // SoftKey ytSoftKey;
  230. int ret=0;//ytSoftKey.Ini();
  231. if (ret!=0 )
  232. {
  233. return "";
  234. }
  235. int d[8];double f[8];
  236. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  237. //运行自定义函数
  238. ret=ytSoftKey.code2(&id,&idtemp,&time1,&time2,&d[4],&d[5],&d[6],&d[7],
  239. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  240. s0,s1,s2,s3,s4,s5,s6,s7);
  241. if(ret!=0 && ret!=-43)
  242. {
  243. return "";
  244. }
  245. // TODO: Add your control notification handler code here
  246. TCHAR year[10],month[10],day[10],hour[10],minute[10], second[10];
  247. ConvertTimerToStringReal(time2, year, month, day, hour, minute, second);
  248. TCHAR szTemp[MAX_PATH];
  249. _stprintf_s(szTemp, _T("已运行:%d年%d月%d日 "), _ttoi(year), _ttoi(month), _ttoi(day));
  250. sRet+=szTemp;
  251. if(time1>0)
  252. ConvertTimerToStringReal(time1, year, month, day, hour, minute, second);
  253. else
  254. {
  255. _stprintf_s(year, "%s", "0");
  256. _stprintf_s(month, "%s", "0");
  257. _stprintf_s(day, "%s", "0");
  258. _stprintf_s(hour, "%s", "0");
  259. _stprintf_s(minute, "%s", "0");
  260. }
  261. _stprintf_s(szTemp, _T("能运行:%d年%d月%d日---%d"), _ttoi(year), _ttoi(month), _ttoi(day), time2);
  262. sRet+=szTemp;
  263. return sRet;
  264. }
  265. catch(...)
  266. {
  267. }
  268. return "";
  269. }
  270. CClientProcess::CClientProcess(void)
  271. {
  272. m_hEvent = NULL;
  273. m_hThread = NULL;
  274. m_hEvent2 = NULL;
  275. m_hThread2 = NULL;
  276. InitializeCriticalSection(&m_csMsgInfo);
  277. }
  278. CClientProcess::~CClientProcess(void)
  279. {
  280. DeleteCriticalSection(&m_csMsgInfo);
  281. m_listMsgInfo.clear();
  282. }
  283. void CClientProcess::StartMsgWork()
  284. {
  285. m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  286. if ( m_hEvent == NULL )
  287. {
  288. // 创建事件失败;
  289. return;
  290. }
  291. m_hThread = CreateThread(NULL, 0, MsgThread, this, 0, NULL);
  292. if ( m_hThread == NULL )
  293. {
  294. CloseHandle(m_hEvent);
  295. m_hEvent = NULL;
  296. }
  297. //////////////////////////////////////////////////////////////////////////
  298. m_hEvent2 = CreateEvent(NULL, TRUE, FALSE, NULL);
  299. if ( m_hEvent2 == NULL )
  300. {
  301. // 创建事件失败;
  302. return;
  303. }
  304. m_hThread2 = CreateThread(NULL, 0, MsgThread, this, 0, NULL);
  305. if ( m_hThread2 == NULL )
  306. {
  307. CloseHandle(m_hEvent2);
  308. m_hEvent2 = NULL;
  309. }
  310. }
  311. void CClientProcess::EndOfMsgWork()
  312. {
  313. if ( m_hEvent )
  314. {
  315. SetEvent(m_hEvent);
  316. }
  317. if ( m_hThread )
  318. {
  319. WaitForSingleObject(m_hThread, INFINITE);
  320. CloseHandle(m_hThread);
  321. m_hThread = NULL;
  322. }
  323. if (m_hEvent)
  324. CloseHandle(m_hEvent);
  325. m_hEvent = NULL;
  326. //////////////////////////////////////////////////////////////////////////
  327. if ( m_hEvent2 )
  328. {
  329. SetEvent(m_hEvent2);
  330. }
  331. if ( m_hThread2 )
  332. {
  333. WaitForSingleObject(m_hThread2, INFINITE);
  334. CloseHandle(m_hThread2);
  335. m_hThread2 = NULL;
  336. }
  337. if (m_hEvent2)
  338. CloseHandle(m_hEvent2);
  339. m_hEvent2 = NULL;
  340. }
  341. void CClientProcess::InsertMsgInfo(IN MsgInfo& msgInfo)
  342. {
  343. EnterCriticalSection(&m_csMsgInfo);
  344. m_listMsgInfo.push_back(msgInfo);
  345. LeaveCriticalSection(&m_csMsgInfo);
  346. }
  347. BOOL CClientProcess::PopMsgInfo(IN MsgInfo& msgInfo)
  348. {
  349. BOOL bRet = FALSE;
  350. EnterCriticalSection(&m_csMsgInfo);
  351. if ( m_listMsgInfo.size())
  352. {
  353. msgInfo = m_listMsgInfo.front();
  354. m_listMsgInfo.pop_front();
  355. bRet = TRUE;
  356. }
  357. LeaveCriticalSection(&m_csMsgInfo);
  358. return bRet;
  359. }
  360. void CClientProcess::WorkSendInfo(IN CONST SOCKET& nSock, IN CONST INT& wMessageLen, IN TString &strInfo, OUT INT& ArySize, OUT BYTE** pAryData, OUT DWORD& dwAryDataSize)
  361. {
  362. //////////////////////////////////////////////////////////////////////////
  363. DWORD dwFromUserID = wMessageLen;
  364. WORD wMessageId = MSG_CHATMESSAGE_RESP;
  365. DWORD dwDataLen;
  366. BYTE *pSendData;
  367. TCHAT_MESSAGE_STRU *pChatMessage;
  368. TMessageHeader tHeader = {0};
  369. tHeader.wMessageId = wMessageId;
  370. SENDHEAD tSendhead;
  371. ZeroMemory(&tSendhead,sizeof(SENDHEAD));
  372. if ( strInfo.empty() )
  373. strInfo = _T("OK");
  374. int nDataLen = strInfo.length();
  375. if(dwAryDataSize)
  376. {
  377. nDataLen = dwAryDataSize;
  378. tSendhead.count[0] = ArySize;
  379. }
  380. dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen ;
  381. pSendData = new BYTE[dwDataLen];
  382. pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
  383. memset(pChatMessage, 0x00, dwDataLen);
  384. memcpy(pSendData, &tSendhead, sizeof(SENDHEAD));
  385. pChatMessage->tCommonMsg.dwConnectionID = dwFromUserID;
  386. pChatMessage->tCommonMsg.wMessageId = wMessageId;
  387. pChatMessage->dwFromUserID = dwFromUserID;
  388. pChatMessage->dwToUserID = pChatMessage->wMessageLen;
  389. pChatMessage->wMessageLen = nDataLen;
  390. if(dwAryDataSize)
  391. {
  392. memcpy(pChatMessage->byFileContent, *pAryData, nDataLen);
  393. //delete []*pAryData;
  394. }
  395. else
  396. {
  397. memcpy(pChatMessage->byFileContent, strInfo.c_str(), nDataLen);
  398. }
  399. CSocketHandle tClientSo;
  400. tClientSo.Attach(nSock);
  401. net_Send(&tClientSo, &tHeader, (void *)pChatMessage, dwDataLen);
  402. tClientSo.Detach();
  403. delete [] pSendData;
  404. }
  405. DWORD CClientProcess::MsgThread(LPVOID lpParam)
  406. {
  407. MsgInfo tagMsgInfo;
  408. BOOL bSend = FALSE;
  409. INT nArySize = 0;
  410. DWORD dwAryDataSize = 0;
  411. BYTE *pAryData = NULL;
  412. CClientProcess *pInstance = (CClientProcess*)lpParam;
  413. do
  414. {
  415. if ( PopMsgInfo(tagMsgInfo) )
  416. {
  417. bSend = FALSE;
  418. switch( tagMsgInfo.dwUserId )
  419. {
  420. case 6:
  421. bSend = Work_No6(tagMsgInfo.strMessage, tagMsgInfo.strIPAddress.c_str());
  422. break;
  423. case 7:
  424. bSend = Work_No7(tagMsgInfo.strMessage);
  425. break;
  426. case 8:
  427. bSend = Work_No8(tagMsgInfo.strMessage, nArySize, &pAryData, dwAryDataSize);
  428. break;
  429. case 9:
  430. bSend = Work_No9(tagMsgInfo.strMessage, tagMsgInfo.pData, tagMsgInfo.wMessageLen);
  431. break;
  432. case 10:
  433. bSend = Work_No10(tagMsgInfo.strIPAddress.c_str(), tagMsgInfo.strMessage);
  434. break;
  435. case 11:
  436. bSend = Work_No11(tagMsgInfo.strMessage);
  437. break;
  438. case 12:
  439. bSend = Work_No12(tagMsgInfo.strMessage);
  440. break;
  441. case 13:
  442. bSend = Work_No13(tagMsgInfo.strMessage);
  443. break;
  444. case 14:
  445. bSend = Work_No14(tagMsgInfo.strMessage);
  446. break;
  447. case 15:
  448. bSend = Work_No15(tagMsgInfo.strMessage);
  449. break;
  450. case 16:
  451. bSend = Work_No16(tagMsgInfo.strIPAddress.c_str(), tagMsgInfo.strMessage);
  452. break;
  453. default:
  454. break;
  455. }
  456. if ( bSend )
  457. {
  458. WorkSendInfo(tagMsgInfo.nSocket, tagMsgInfo.wMessageLen, tagMsgInfo.strMessage, nArySize, &pAryData, dwAryDataSize);
  459. if ( pAryData )
  460. {
  461. delete []pAryData;
  462. pAryData = NULL;
  463. }
  464. nArySize = 0;
  465. dwAryDataSize = 0;
  466. }
  467. }
  468. } while (WaitForSingleObject(pInstance->m_hEvent, 10) == WAIT_TIMEOUT );
  469. return 0;
  470. }
  471. DWORD CClientProcess::net_Send(CSocketHandle* pSH, IN void *pHeader, IN void *pMessage, IN unsigned long ulDataLen)
  472. {
  473. unsigned long ulSendLen = 0;
  474. unsigned long ulBufLen = 0;
  475. TMessageHeader *pSendHeader = (TMessageHeader *)pHeader;
  476. ulBufLen = MESSAGE_HEADER_LEN + ulDataLen;
  477. BYTE *pSendBuf = new BYTE[ulBufLen];
  478. memset(pSendBuf, 0, ulBufLen);
  479. TMessageHeader *pMessageHeader = (TMessageHeader *)pSendBuf;
  480. pMessageHeader->byVersion = 101;
  481. pMessageHeader->wHeaderFlag = MESSAGE_HEADER_FLAG;
  482. pMessageHeader->wMessageId = pSendHeader->wMessageId;
  483. pMessageHeader->wMessageSubId = pSendHeader->wMessageSubId;
  484. pMessageHeader->dwDataLen = ulDataLen;
  485. pMessageHeader->wReserve = 0;
  486. memcpy((void *)(pSendBuf+MESSAGE_HEADER_LEN), pMessage, ulDataLen);
  487. // convert network word
  488. htons(pMessageHeader->wHeaderFlag);
  489. htons(pMessageHeader->wMessageId);
  490. htons(pMessageHeader->wMessageSubId);
  491. htonl(pMessageHeader->dwDataLen);
  492. htons(pMessageHeader->wCheckSum);
  493. htonl(pMessageHeader->wReserve);
  494. INT nBytes = pSH->Write(pSendBuf, ulBufLen, NULL, 1000);
  495. DWORD dwError = WSAGetLastError();
  496. if ( dwError != 0 )
  497. {
  498. printf("\t发送给客户端信息失败:%d\n", dwError);
  499. }
  500. delete []pSendBuf;
  501. pSendBuf = NULL;
  502. return nBytes;
  503. }
  504. void CClientProcess::ClientProcess(IN const SOCKET sClient, IN const BYTE* pbData, IN DWORD dwCount, IN LPCTSTR lpaddr, IN BYTE** PendingBuf, IN UINT &nPendingSize, IN UINT &nCurSize)
  505. {
  506. try
  507. {
  508. TMessageHeader *pMessageHeader = (TMessageHeader *)pbData;
  509. if(pMessageHeader->wMessageId == MSG_LOGIN_REQ)
  510. {
  511. WORD wMessageId = MSG_LOGIN_RESP;
  512. LOGIN_RESULT_STRU tLoginResult = {0};
  513. tLoginResult.tCommonMsg.dwConnectionID = 0;
  514. tLoginResult.tCommonMsg.wMessageId = wMessageId;
  515. tLoginResult.byResult = LOGIN_RESULT_SUC;
  516. tLoginResult.dwUserID = 0;
  517. tLoginResult.byStatus = USER_STATUS_ONLINE ;
  518. DWORD dwDataLen = sizeof(LOGIN_RESULT_STRU);
  519. TMessageHeader tHeader = {0};
  520. tHeader.wMessageId = wMessageId;
  521. tHeader.dwDataLen = dwDataLen;
  522. if ( (pMessageHeader->dwDataLen + sizeof(LOGIN_RESULT_STRU)) != dwCount )
  523. {
  524. return;
  525. }
  526. CSocketHandle hClient;
  527. hClient.Attach(sClient);
  528. net_Send(&hClient, &tHeader, (void *)&tLoginResult, dwDataLen);
  529. hClient.Detach();
  530. }
  531. else //if(pMessageHeader->wMessageId == MSG_CHATMESSAGE_REQ)
  532. {
  533. if ( pMessageHeader->wHeaderFlag == MESSAGE_HEADER_FLAG && pMessageHeader->wMessageId == MSG_CHATMESSAGE_REQ )
  534. {
  535. if ( *PendingBuf )
  536. delete []*PendingBuf;
  537. *PendingBuf = NULL;
  538. nCurSize = 0;
  539. nPendingSize = 0;
  540. nPendingSize = pMessageHeader->dwDataLen + MESSAGE_HEADER_LEN;
  541. *PendingBuf = new BYTE[nPendingSize];
  542. }
  543. if ( nPendingSize == 0 )
  544. {
  545. return;
  546. }
  547. memcpy(PendingBuf + nCurSize, pbData, min(dwCount, nPendingSize - nCurSize));
  548. nCurSize += min(dwCount, nPendingSize - nCurSize);
  549. if (nCurSize >= nPendingSize)
  550. {
  551. TCHAT_MESSAGE_STRU *ptChatMessage = (TCHAT_MESSAGE_STRU *)(*PendingBuf + MESSAGE_HEADER_LEN);
  552. nCurSize = 0;
  553. nPendingSize = 0;
  554. DWORD dwUserId = ptChatMessage->tCommonMsg.dwConnectionID;
  555. if ( ptChatMessage->length[98] != 987123768 )
  556. {
  557. return;
  558. }
  559. TString strContent = _T("");
  560. if ( ptChatMessage->wMessageLen > 3 )
  561. {
  562. if ( ptChatMessage->dwToUserID != 9 )
  563. {
  564. BYTE *szChatMessage = new BYTE[ptChatMessage->wMessageLen + 1];
  565. memset(szChatMessage, 0, ptChatMessage->wMessageLen+1);
  566. memcpy(szChatMessage, ptChatMessage->byFileContent, ptChatMessage->wMessageLen);
  567. Global::EncryptFile2((BYTE*)szChatMessage, ptChatMessage->wMessageLen, _T("888666333"));
  568. MsgInfo tagMsgInfo;
  569. tagMsgInfo.nSocket = sClient;
  570. tagMsgInfo.strIPAddress = lpaddr;
  571. tagMsgInfo.dwUserId = ptChatMessage->dwToUserID;
  572. tagMsgInfo.strMessage = (TCHAR*)szChatMessage;
  573. tagMsgInfo.wMessageLen = ptChatMessage->wMessageLen;
  574. InsertMsgInfo(tagMsgInfo);
  575. delete []szChatMessage;
  576. }
  577. else
  578. {
  579. MsgInfo tagMsgInfo;
  580. tagMsgInfo.nSocket = sClient;
  581. tagMsgInfo.strIPAddress = lpaddr;
  582. tagMsgInfo.dwUserId = ptChatMessage->dwToUserID;
  583. //tagMsgInfo.strMessage = (TCHAR*)szChatMessage;
  584. tagMsgInfo.wMessageLen = ptChatMessage->wMessageLen;
  585. tagMsgInfo.pData = new BYTE[tagMsgInfo.wMessageLen];
  586. memcpy(tagMsgInfo.pData, ptChatMessage->byFileContent, tagMsgInfo.wMessageLen);
  587. InsertMsgInfo(tagMsgInfo);
  588. }
  589. }
  590. }
  591. }
  592. }
  593. catch (CException* e)
  594. {
  595. e->ReportError();
  596. }
  597. return;
  598. }
  599. BOOL CClientProcess::Work_No0(IN TString& strContent)
  600. {
  601. TString strAccount;
  602. TString strPsw;
  603. TString strPhones;
  604. TString strMsgContent;
  605. TString strTimestamp;
  606. INT nIndex = strContent.find(_T("\r\n"));
  607. if ( nIndex == TString::npos )
  608. {
  609. return FALSE;
  610. }
  611. // 获取短信账号;
  612. strAccount = strContent.substr(0,nIndex);
  613. strContent = strContent.substr(nIndex + 2);
  614. nIndex = strContent.find(_T("\r\n"));
  615. if ( nIndex == TString::npos )
  616. {
  617. return FALSE;
  618. }
  619. // 获取短信的账号密码;
  620. strPsw = strContent.substr(0, nIndex);
  621. strContent = strContent.substr(nIndex + 2);
  622. nIndex = strContent.find(_T("\r\n"));
  623. if ( nIndex == TString::npos )
  624. {
  625. return FALSE;
  626. }
  627. // 获取短信的接收号码;
  628. strPhones = strContent.substr(0, nIndex);
  629. strContent = strContent.substr(nIndex + 2);
  630. nIndex = strContent.find_last_of(_T("\r"));
  631. if ( nIndex == TString::npos )
  632. {
  633. return FALSE;
  634. }
  635. // 获取短信的内容;
  636. strMsgContent = strContent.substr(0, nIndex);
  637. strContent = strContent.substr(nIndex + 2);
  638. // 获取短信时间;
  639. strTimestamp = strContent;
  640. if ( /* 是否存在该用户 */1 )
  641. {
  642. return FALSE;
  643. }
  644. if ( /* 校验用户名密码是否正确 */1 )
  645. {
  646. strContent = _T("账户或密码错误");
  647. }
  648. }
  649. BOOL CClientProcess::Work_No6(IN TString& strContent, IN LPCTSTR lpIPAddress)
  650. {
  651. printf(" \t\t ------Work No.6------ \n");
  652. if ( strContent.find(_T(";")) == TString::npos)
  653. {
  654. return FALSE;
  655. }
  656. INT nStrlen = 0;
  657. INT pos = strContent.find(_T("&@&@&"));
  658. if( pos != TString::npos )
  659. {
  660. // 影楼信息及订单数;
  661. TString info = strContent.substr(0,pos);
  662. nStrlen = strContent.length() - pos - 5;
  663. if ( nStrlen <= 0 )
  664. {
  665. printf("\t\t work 6 长度错误\n");
  666. return FALSE;
  667. }
  668. strContent = strContent.substr(strContent.length() - nStrlen);
  669. pos = info.find_last_of(_T(":"));
  670. if ( pos != TString::npos )
  671. {
  672. nStrlen = info.length() - pos - 1;
  673. if ( nStrlen <= 0 )
  674. {
  675. printf("\t\t work 6 长度错误\n");
  676. return FALSE;
  677. }
  678. TString dindan = _T("订单数:") + info.substr(info.length() - nStrlen);
  679. pos = info.find_last_of(_T("订单数:"));
  680. if ( pos != TString::npos )
  681. {
  682. info = info.substr(0, pos - _tcslen(_T("订单数")));
  683. TString datetime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
  684. TString sql,execute;
  685. BOOL bexist=0;
  686. // 获取远程控制的SQL语句(影楼客户端接收);
  687. TString strResult;
  688. #ifdef USE_ODBC_DLL
  689. if( !g_podbc->GetunauthInfo(info.c_str(), strResult, 5000) )
  690. #else
  691. if( !CODBCPool::GetInstance()->GetunauthInfo(info.c_str(), strResult, 5000) )
  692. #endif
  693. {
  694. printf("\t\t work 6 获取控制SQL语句失败\n");
  695. return FALSE;
  696. }
  697. execute = strResult.c_str();
  698. if( execute == _T("停止运行") )
  699. {
  700. strContent = _T("无域名字段,请确认");
  701. }
  702. else
  703. {
  704. if(execute.empty())
  705. {
  706. sql.append(_T("insert into [unauth]([name],[dindan],[datetime],[execute])values('"));
  707. sql.append(info);
  708. sql.append(_T("','"));
  709. sql.append(dindan);
  710. sql.append(_T("','"));
  711. sql.append(datetime);
  712. sql.append(_T("','"));
  713. sql.append(_T("0"));
  714. sql.append(_T("')"));
  715. }
  716. else
  717. {
  718. sql.append(_T("update [unauth] set [dindan]='"));
  719. sql.append(dindan);
  720. sql.append(_T("',[datetime]='"));
  721. sql.append(datetime);
  722. sql.append(_T("' where [name]='"));
  723. sql.append(info);
  724. sql.append(_T("'"));
  725. }
  726. #ifdef USE_ODBC_DLL
  727. if( !g_podbc->ExecuteSQL(sql.c_str(), 5000) )
  728. #else
  729. if( !CODBCPool::GetInstance()->ExecuteSQL(sql.c_str(), 5000) )
  730. #endif
  731. {
  732. printf("\t\t work 6 更新影楼信息出错");
  733. return FALSE;
  734. }
  735. }
  736. }
  737. }
  738. }
  739. else
  740. {
  741. // 影楼域名;
  742. TString strBranchId = strContent;
  743. pos = strContent.find(_T(";"));
  744. // 日志信息及注册码;
  745. TString logcontent = _T("未升级,无法获知");
  746. TString temp,regcode,regcode2,regcodebak;
  747. if( pos != TString::npos )
  748. {
  749. // 获取到域名;
  750. strBranchId = strContent.substr(0,pos);
  751. if ( strBranchId.empty() || !( strBranchId.find(_T(".ly.com")) != TString::npos || strBranchId.find(_T(".lyfz.com")) != TString::npos || strBranchId.find(_T(".eicp.net")) != TString::npos ))
  752. {
  753. printf("\t\t work 6 域名出错\n");
  754. return FALSE;
  755. }
  756. nStrlen = strContent.length() - pos - 1;
  757. if ( nStrlen <= 0 || nStrlen >= strContent.length())
  758. {
  759. printf("\t\t work 6 长度错误1\n");
  760. return FALSE;
  761. }
  762. logcontent = strContent.substr(strContent.length() - nStrlen);
  763. pos = logcontent.find(_T("***"));
  764. if( pos != TString::npos )
  765. {
  766. nStrlen = logcontent.length() - pos - 3;
  767. if ( nStrlen <= 0 )
  768. {
  769. printf("\t\t work 6 长度错误2\n");
  770. return FALSE;
  771. }
  772. // 解析出DBServer.exe加密的加时请求授权码(regcode.txt);
  773. regcode = logcontent.substr(logcontent.length() - nStrlen).c_str();
  774. regcodebak = regcode;
  775. logcontent = logcontent.substr(0, pos).c_str();
  776. strContent = GetUseDays(regcode.c_str());
  777. regcode = strContent;
  778. // 获取可运行的时间值;
  779. pos = regcode.find(_T("---"));
  780. if(pos != TString::npos )
  781. {
  782. nStrlen = regcode.length() - pos - 3;
  783. if ( nStrlen <= 0 )
  784. {
  785. printf("\t\t work 6 长度错误3\n");
  786. return FALSE;
  787. }
  788. regcodebak.append(_T("---"));
  789. regcodebak.append(regcode.substr(regcode.length() - nStrlen));
  790. }
  791. }
  792. }
  793. //////////////////////////////////////////////////////////////////////////
  794. // 获取客户端ip地址;
  795. strContent = lpIPAddress;
  796. pos = strContent.find(_T(":"));
  797. if ( pos == TString::npos )
  798. {
  799. printf("\t\t work 6 无IP地址\n");
  800. return FALSE;
  801. }
  802. strContent = strContent.substr(0,pos -1);
  803. TString datetime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
  804. pos = regcode.find(_T("---"));
  805. if(pos != TString::npos )
  806. {
  807. temp = regcode.substr(0,pos);
  808. }
  809. else
  810. temp = regcode;
  811. TString sql ;
  812. sql.append(_T("update [clientip] set [ip]='"));
  813. sql.append(strContent);
  814. sql.append(_T("',[datetime]='"));
  815. sql.append(datetime);
  816. sql.append(_T("',"));
  817. sql.append(_T("[log]='"));
  818. sql.append(logcontent);
  819. sql.append(_T("',"));
  820. sql.append(_T("[regcode]='"));
  821. sql.append(temp);
  822. sql.append(_T("' where [name]='"));
  823. sql.append(strBranchId);
  824. sql.append(_T("'"));
  825. #ifdef USE_ODBC_DLL
  826. if ( !g_podbc->ExecuteSQL(sql.c_str(), 5000) )
  827. #else
  828. if ( !CODBCPool::GetInstance()->ExecuteSQL(sql.c_str(), 5000) )
  829. #endif
  830. {
  831. printf("\n更新影楼IP:%s\n",sql.c_str());
  832. printf("\t\t work 6 更新影楼IP出错\n");
  833. return FALSE;
  834. }
  835. TblClientip1 Clientip;
  836. sql = _T("name = '");
  837. sql.append(strBranchId);
  838. sql.append(_T("'"));
  839. #ifdef USE_ODBC_DLL
  840. INT nSQLRetsult = g_podbc->GetClientEnterpriseName(sql.c_str(), &Clientip, 5000);
  841. #else
  842. INT nSQLRetsult = CODBCPool::GetInstance()->GetClientEnterpriseName(sql.c_str(), &Clientip, 5000);
  843. #endif
  844. if ( nSQLRetsult == 1 )
  845. {
  846. sql = Clientip.szBranchname;
  847. regcode2 = Clientip.szRegcode2;
  848. }
  849. else if ( nSQLRetsult == 0 )
  850. {
  851. sql = _T("xxx!");
  852. strContent = _T("此域名未绑定!");
  853. }
  854. else
  855. {
  856. printf("\t\t work 6 获取企业名出错, %s\n", sql.c_str());
  857. return FALSE;
  858. }
  859. regcode = regcodebak;
  860. if(regcode != _T("") && (regcode2.length() == 10 || regcode2 == _T("永久")) )
  861. {
  862. long newsecond = 0;
  863. long dtsecond = 0;
  864. CTime curtm = CTime::GetCurrentTime();
  865. if(regcode2 == _T("永久"))
  866. {
  867. newsecond = 60;
  868. pos = regcode.find(_T("---"));
  869. if( pos != TString::npos )
  870. regcodebak = regcode.substr(0,pos);
  871. }
  872. else
  873. {
  874. CTime destm( _ttoi(regcode2.substr(0,4).c_str()), _ttoi(regcode2.substr (5,2).c_str()), _ttoi(regcode2.substr(8,2).c_str()), 0, 0, 0);
  875. CTimeSpan dt = destm-curtm;
  876. dtsecond = dt.GetTotalSeconds();
  877. dtsecond /= 2;
  878. pos = regcode.find(_T("---"));
  879. if( pos != TString::npos && dtsecond > 0 )
  880. {
  881. regcodebak = regcode.substr(0, pos);
  882. regcode = regcode.substr( pos + 3 );
  883. long usedsecond = _ttoi(regcode.c_str());
  884. newsecond = usedsecond + dtsecond;
  885. }
  886. }
  887. if( newsecond )
  888. {
  889. strContent.append(_T("authcodexiao"));
  890. strContent.append(GetAuthCode(regcodebak.c_str(), newsecond));
  891. }
  892. }
  893. }
  894. return TRUE;
  895. }
  896. BOOL CClientProcess::Work_No7(OUT TString& strBranchId)
  897. {
  898. printf(" \t\t ------Work No.7------ \n");
  899. if ( strBranchId.empty() || !( strBranchId.find(_T(".ly.com")) != TString::npos || strBranchId.find(_T(".lyfz.com")) != TString::npos || strBranchId.find(_T(".eicp.net")) != TString::npos ))
  900. {
  901. // 域名空;
  902. printf("\t\t work 7 域名错误\n");
  903. return FALSE;
  904. }
  905. TString strName = _T("name = ");
  906. strName.append(_T("'"));
  907. strName.append(strBranchId);
  908. strName.append(_T("'"));
  909. TCHAR szResult[MAX_PATH] = {0};
  910. #ifdef USE_ODBC_DLL
  911. if ( g_podbc->GetSelectby(_T("clientip"), _T("ip"), strName.c_str(), szResult, MAX_PATH) )
  912. #else
  913. if ( CODBCPool::GetInstance()->GetSelectby(_T("clientip"), _T("ip"), strName.c_str(), szResult, MAX_PATH) )
  914. #endif
  915. {
  916. if ( _tcslen(szResult) )
  917. strBranchId = szResult;
  918. else
  919. strBranchId.append(_T("没有此域名的记录!"));
  920. }
  921. else
  922. {
  923. return FALSE;
  924. }
  925. return TRUE;
  926. }
  927. BOOL CClientProcess::Work_No8(IN TString& strContent, OUT INT& ArySize, OUT BYTE** pAryData, OUT DWORD& dwAryDataSize)
  928. {
  929. printf(" \t\t ------Work No.8------ \n");
  930. TString strSQL, strBranchId, strTemp;
  931. strBranchId = strContent;
  932. if ( strBranchId.empty() || !( strBranchId.find(_T(".ly.com")) != TString::npos || strBranchId.find(_T(".lyfz.com")) != TString::npos || strBranchId.find(_T(".eicp.net")) != TString::npos ))
  933. {
  934. printf("\t\t work 8 域名错误\n");
  935. return FALSE;
  936. }
  937. // 查询数据;
  938. TString strEnterprisName;
  939. TString strName = _T("name = ");
  940. strName.append(_T("'"));
  941. strName.append(strBranchId);
  942. strName.append(_T("'"));
  943. TCHAR szResult[MAX_PATH] = {0};
  944. #ifdef USE_ODBC_DLL
  945. if ( g_podbc->GetSelectby(_T("clientip"), _T("enterprisename"), strName.c_str(), szResult, MAX_PATH, 5000) )
  946. #else
  947. if ( CODBCPool::GetInstance()->GetSelectby(_T("clientip"), _T("enterprisename"), strName.c_str(), szResult, MAX_PATH, 5000) )
  948. #endif
  949. {
  950. if ( _tcslen(szResult) )
  951. strEnterprisName = szResult;
  952. else
  953. strSQL = _T("xxx!");
  954. }
  955. else
  956. {
  957. return FALSE;
  958. }
  959. // 再查询数据;
  960. strContent = strEnterprisName;
  961. if ( !strContent.empty() )
  962. {
  963. CArray<CStringArray,CStringArray> AryEnterprisInfo;
  964. #ifdef USE_ODBC_DLL
  965. INT nCount = g_podbc->GetEnterprisInfo(strContent.c_str(), AryEnterprisInfo, 5000);
  966. #else
  967. INT nCount = CODBCPool::GetInstance()->GetEnterprisInfo(strContent.c_str(), AryEnterprisInfo, 5000);
  968. #endif
  969. if ( nCount > 0 )
  970. {
  971. strContent = _T("");
  972. CMemFile mf;
  973. CArchive ar(&mf, CArchive::store);
  974. ArySize = nCount;
  975. for ( int i = 0; i < nCount; i++ )
  976. {
  977. AryEnterprisInfo.ElementAt(i).Serialize(ar);
  978. }
  979. ar.Close();
  980. // 附加给专用变量;
  981. dwAryDataSize = mf.GetLength();
  982. *pAryData = mf.Detach();
  983. strContent = _T("ok");
  984. }
  985. else if ( nCount == 0 )
  986. {
  987. strContent.append(_T("没有此企业的资料"));
  988. }
  989. else
  990. {
  991. return FALSE;
  992. }
  993. }
  994. else
  995. {
  996. strContent.append(_T("没有此企业的资料"));
  997. }
  998. return TRUE;
  999. }
  1000. BOOL CClientProcess::Work_No9(OUT TString& strContent, IN BYTE* pData, IN CONST INT &nMessageLen)
  1001. {
  1002. printf(" \t\t ------Work No.9------ \n");
  1003. printf("\n ****影楼修改分店访问权限**** \n");
  1004. if ( pData == NULL || nMessageLen < 4 )
  1005. return FALSE;
  1006. CMemFile mf;
  1007. mf.Attach(pData + sizeof(DWORD), nMessageLen - sizeof(DWORD));
  1008. CArchive ar(&mf, CArchive::load);
  1009. DWORD dwArySize = 0;
  1010. memcpy(&dwArySize, pData, sizeof(DWORD));
  1011. CArray<CStringArray,CStringArray> AryRights;
  1012. AryRights.SetSize(dwArySize);
  1013. for ( int i = 0; i < dwArySize; i++ )
  1014. {
  1015. AryRights.ElementAt(i).Serialize(ar);
  1016. }
  1017. ar.Close();
  1018. mf.Detach();
  1019. BOOL bRet = FALSE;
  1020. TString strEnterpriseName = _T("");
  1021. if ( AryRights.GetSize() )
  1022. {
  1023. strEnterpriseName = AryRights.ElementAt(0).ElementAt(0);
  1024. TString strBranchName, strRights;
  1025. for ( int i = 0; i < AryRights.GetSize(); i++ )
  1026. {
  1027. strBranchName = AryRights.ElementAt(i).ElementAt(1);
  1028. strRights = _T("");
  1029. for ( int j = 2; j < AryRights.ElementAt(i).GetSize(); j++ )
  1030. {
  1031. strRights.append(AryRights.ElementAt(i).ElementAt(j));
  1032. strRights.append(_T(","));
  1033. }
  1034. if (strRights.length() && strRights[strRights.length() - 1] == _T(','))
  1035. strRights.erase(strRights.length() - 1);
  1036. TString strSQL = _T("update clientip set [rights]='");
  1037. strSQL.append(strRights);
  1038. strSQL.append(_T("' where [enterprisename]='"));
  1039. strSQL.append(strEnterpriseName);
  1040. strSQL.append(_T("' and [branchname]='"));
  1041. strSQL.append(strBranchName);
  1042. strSQL.append(_T("'"));
  1043. #ifdef USE_ODBC_DLL
  1044. bRet = g_podbc->ExecuteSQL(strSQL.c_str(), 5000);
  1045. #else
  1046. bRet = CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str(), 5000);
  1047. #endif
  1048. }
  1049. }
  1050. if ( pData )
  1051. {
  1052. delete []pData;
  1053. pData = NULL;
  1054. }
  1055. strContent = _T("set ok");
  1056. return bRet;
  1057. }
  1058. BOOL CClientProcess::Work_No10(IN LPCTSTR lpIPAddress, IN TString& strContent)
  1059. {// 记录影楼IP地址;
  1060. printf(" \t\t ------Work No.10------ \n");
  1061. if ( lpIPAddress == NULL || lpIPAddress[0] == _T('\0'))
  1062. {
  1063. return FALSE;
  1064. }
  1065. // 获取客户端ip地址;
  1066. TString strIPAddress = lpIPAddress;
  1067. INT nIndex = strIPAddress.find(_T(":"));
  1068. if ( nIndex == TString::npos )
  1069. {
  1070. printf("\t\t work 10 无IP地址\n");
  1071. return FALSE;
  1072. }
  1073. strIPAddress = strIPAddress.substr(0,nIndex -1);
  1074. TString strDateTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
  1075. TString strSQL = _T("update [clientip2] set [ip] ='");
  1076. strSQL.append(strIPAddress);
  1077. strSQL.append(_T("',[datetime] = '"));
  1078. strSQL.append(strDateTime);
  1079. strSQL.append(_T("' where [name] = '"));
  1080. strSQL.append(strContent);
  1081. strSQL.append(_T("'"));
  1082. #ifdef USE_ODBC_DLL
  1083. return g_podbc->ExecuteSQL(strSQL.c_str());
  1084. #else
  1085. return CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str());
  1086. #endif
  1087. }
  1088. BOOL CClientProcess::Work_No11(IN TString& strContent)
  1089. {
  1090. printf(" \t\t ------Work No.11------ \n");
  1091. TString strFilters;
  1092. strFilters = _T("name = '");
  1093. strFilters.append(strContent);
  1094. strFilters = _T("'");
  1095. TCHAR szResult[MAX_PATH] = {0};
  1096. #ifdef USE_ODBC_DLL
  1097. if ( g_podbc->GetSelectby(_T("clientip2"), _T("[ip]"), strFilters.c_str(), szResult, MAX_PATH) )
  1098. #else
  1099. if ( CODBCPool::GetInstance()->GetSelectby(_T("clientip2"), _T("[ip]"), strFilters.c_str(), szResult, MAX_PATH) )
  1100. #endif
  1101. {
  1102. if (szResult[0] != _T('\0'))
  1103. strContent = szResult;
  1104. else
  1105. strContent.append(_T("没有此域名的记录"));
  1106. return TRUE;
  1107. }
  1108. return FALSE;
  1109. }
  1110. BOOL CClientProcess::Work_No12(IN TString& strContent)
  1111. {
  1112. printf(" \t\t ------Work No.12------ \n");
  1113. #ifdef USE_ODBC_DLL
  1114. if ( g_podbc->ExecuteSQL(strContent.c_str()) )
  1115. #else
  1116. if ( CODBCPool::GetInstance()->ExecuteSQL(strContent.c_str()) )
  1117. #endif
  1118. {
  1119. strContent = _T("ok");
  1120. }
  1121. return TRUE;
  1122. }
  1123. BOOL CClientProcess::Work_No13(IN TString& strContent)
  1124. {
  1125. printf(" \t\t ------Work No.13------ \n");
  1126. TString strSQL = strContent;
  1127. strContent = _T("ok");
  1128. if ( strSQL.length() < 6 )
  1129. {
  1130. return FALSE;
  1131. }
  1132. if ( strSQL.substr(0, 6) != _T("select") )
  1133. {
  1134. return FALSE;
  1135. }
  1136. #ifdef USE_ODBC_DLL
  1137. return g_podbc->GetDBCFileInfo(strSQL.c_str(), strContent);
  1138. #else
  1139. return CODBCPool::GetInstance()->GetDBCFileInfo(strSQL.c_str(), strContent);
  1140. #endif
  1141. }
  1142. BOOL CClientProcess::Work_No14(IN TString& strContent)
  1143. {
  1144. printf(" \t\t ------Work No.14------ \n");
  1145. // 前任测试,废弃;
  1146. return TRUE;
  1147. }
  1148. BOOL CClientProcess::Work_No15(IN TString& strContent)
  1149. {
  1150. printf(" \t\t ------Work No.15------ \n");
  1151. // 前任测试,废弃;
  1152. return TRUE;
  1153. }
  1154. BOOL CClientProcess::Work_No16(IN LPCTSTR lpIPAddress, IN TString& strContent)
  1155. {
  1156. printf(" \t\t ------Work No.16------ \n");
  1157. if ( lpIPAddress == NULL || lpIPAddress[0] == _T('\0') )
  1158. {
  1159. return FALSE;
  1160. }
  1161. INT nIndex = 0;
  1162. TString strSeperator = _T("*%!X");
  1163. INT nSeperator = strSeperator.length();
  1164. // 获取影楼的域名;
  1165. TString strBranchId = _T("");
  1166. nIndex = strContent.find(strSeperator);
  1167. if ( nIndex != TString::npos )
  1168. {
  1169. strBranchId = strContent.substr(0, nIndex);
  1170. strContent = strContent.substr(nIndex + nSeperator);
  1171. }
  1172. // 获取影楼名称;
  1173. TString strEdit1 = _T("");
  1174. nIndex = strContent.find(strSeperator);
  1175. if ( nIndex != TString::npos )
  1176. {
  1177. strEdit1 = strContent.substr(0, nIndex);
  1178. strContent = strContent.substr(nIndex + nSeperator);
  1179. }
  1180. // 获取影楼老板电话;
  1181. TString strEdit2 = _T("");
  1182. nIndex = strContent.find(strSeperator);
  1183. if ( nIndex != TString::npos )
  1184. {
  1185. strEdit2 = strContent.substr(0, nIndex);
  1186. strContent = strContent.substr(nIndex + nSeperator);
  1187. }
  1188. // 获取地址;
  1189. TString strEdit3 = _T("");
  1190. nIndex = strContent.find(strSeperator);
  1191. if ( nIndex != TString::npos )
  1192. {
  1193. strEdit3 = strContent.substr(0, nIndex);
  1194. strContent = strContent.substr(nIndex + nSeperator);
  1195. }
  1196. // 获取老板名称;
  1197. TString strEdit4 = _T("");
  1198. nIndex = strContent.find(strSeperator);
  1199. if ( nIndex != TString::npos )
  1200. {
  1201. strEdit4 = strContent.substr(0, nIndex);
  1202. strContent = strContent.substr(nIndex + nSeperator);
  1203. }
  1204. // 获取订单数量;
  1205. TString strOrderNum = _T("");
  1206. TString strEdit5 = _T("");
  1207. nIndex = strContent.find(strSeperator);
  1208. if ( nIndex != TString::npos )
  1209. {
  1210. strEdit5 = strContent.substr(0, nIndex);
  1211. strContent = strContent.substr(nIndex + nSeperator);
  1212. strOrderNum = strContent;
  1213. }
  1214. // 构建SQL语句;
  1215. TCHAR szRet[MAX_PATH] = {0};
  1216. TString strSQL = _T("");
  1217. TString strDateTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
  1218. strSQL = _T("domain = '");
  1219. strSQL.append(strBranchId);
  1220. strSQL.append(_T("' and name = '"));
  1221. strSQL.append(strEdit1);
  1222. strSQL.append(_T("' and phone = '"));
  1223. strSQL.append(strEdit2);
  1224. strSQL.append(_T("'"));
  1225. #ifdef USE_ODBC_DLL
  1226. if ( FALSE == g_podbc->GetSelectby(_T("softclient"), _T("ret"), strSQL.c_str(), szRet, MAX_PATH) )
  1227. #else
  1228. if ( FALSE == CODBCPool::GetInstance()->GetSelectby(_T("softclient"), _T("ret"), strSQL.c_str(), szRet, MAX_PATH) )
  1229. #endif
  1230. {
  1231. return FALSE;
  1232. }
  1233. strSQL = _T("delete from softclient where domain = '");
  1234. strSQL.append(strBranchId);
  1235. strSQL.append(_T("' and name = '"));
  1236. strSQL.append(strEdit1);
  1237. strSQL.append(_T("' and phone = '"));
  1238. strSQL.append(strEdit2);
  1239. strSQL.append(_T("'"));
  1240. #ifdef USE_ODBC_DLL
  1241. g_podbc->ExecuteSQL(strSQL.c_str());
  1242. #else
  1243. CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str());
  1244. #endif
  1245. // 获取客户端ip地址;
  1246. strContent = lpIPAddress;
  1247. nIndex = strContent.find(_T(":"));
  1248. if ( nIndex == TString::npos )
  1249. {
  1250. printf("\t\t work 16 无IP地址\n");
  1251. return FALSE;
  1252. }
  1253. strContent = strContent.substr(0,nIndex -1);
  1254. strSQL = _T("insert into [softclient]([domain],[name],[phone],[addr],[admin],[version],[cot],[ip],[datetime],[ret]) values ('");
  1255. strSQL.append(strBranchId);
  1256. strSQL.append(_T("','"));
  1257. strSQL.append(strEdit1);
  1258. strSQL.append(_T("','"));
  1259. strSQL.append(strEdit2);
  1260. strSQL.append(_T("','"));
  1261. strSQL.append(strEdit3);
  1262. strSQL.append(_T("','"));
  1263. strSQL.append(strEdit4);
  1264. strSQL.append(_T("','"));
  1265. strSQL.append(strEdit5);
  1266. strSQL.append(_T("','"));
  1267. strSQL.append(strOrderNum);
  1268. strSQL.append(_T("','"));
  1269. strSQL.append(strContent);
  1270. strSQL.append(_T("','"));
  1271. strSQL.append(strDateTime);
  1272. strSQL.append(_T("','"));
  1273. strSQL.append(szRet);
  1274. strSQL.append(_T("')"));
  1275. #ifdef USE_ODBC_DLL
  1276. g_podbc->ExecuteSQL(strSQL.c_str());
  1277. #else
  1278. CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str());
  1279. #endif
  1280. strContent = szRet;
  1281. return TRUE;
  1282. }