1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185 |
- #include "StdAfx.h"
- #include "ClientProcess.h"
- #include "GuardInfo.h"
- #include "GuardCommand.h"
- #include "..\..\..\common\cJson\cJSON.h"
- #include "Base64.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- #define INVALID_VALUE ((DWORD)-1)
- CRITICAL_SECTION CClientProcess::m_csMsgInfo;
- list<MsgInfo> CClientProcess::m_listMsgInfo;
- ThreadSection g_critSection;
- CString GetAuthCode(CString requestcode, long newsecond)
- {
- AutoThreadSection aSection(&g_critSection);
- try
- {
- UINT m_year;
- UINT m_month;
- UINT m_day;
- UINT m_hour;
- UINT m_minute;
- {
- TCHAR year[10],month[10],day[10],hour[10],minute[10], second[10];
- ConvertTimerToStringReal(newsecond, year, month, day, hour, minute, second);
- m_year=_ttoi(year);
- m_month=_ttoi(month);
- m_day=_ttoi(day);
- m_hour=_ttoi(hour);
- m_minute=_ttoi(minute);
- if(newsecond==60)
- {
- m_year=60;
- m_month=0;
- m_day=0;
- m_hour=0;
- m_minute=0;
- }
- }
- if(m_year<0 || m_month<0 || m_day<0 || m_hour<0 || m_minute<0)
- {
- return _T("");
- }
- requestcode.TrimLeft();
- requestcode.TrimRight();
- requestcode.Replace("\n", "");
- requestcode.Replace("\r", "");
- if(requestcode.IsEmpty())
- {
- return "";
- }
- TString str,temp,temp2;
- int id,time1,time2,idtemp;
- int leng;
- str=requestcode;
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0, leng);
- str=str.substr(leng);
- id=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() -1)=="1")id=-id;
- //////////////////////////////////////////////////
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0, leng);
- str=str.substr(leng);
- time1=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() -1)=="1")time1=-time1;
- //////////////////////////////////////////////////
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0, leng);
- str=str.substr(leng);
- time2=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() -1)=="1")time2=-time2;
- //////////////////////////////////////////////////////
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0, leng);
- str=str.substr(leng);
- idtemp=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() -1)=="1")idtemp=-idtemp;
- //////////////////////////////////////////////////////
- int ret=0;//ytSoftKey.Ini();
- int d[8];double f[8];
- char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
- // 运行自定义函数;
- ret = g_ytSoftKey.code2(&id,&idtemp,&time1,&time2,&d[4],&d[5],&d[6],&d[7],&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],s0,s1,s2,s3,s4,s5,s6,s7);
- if( ret!=0 && ret != -43)
- {
- printf("获取用户运行时间出错:%s\n",Encryptlockkernel::GetYtUSBKey32ErrInfo(ret));
- LOG4C_NO_FILENUM((LOG_NOTICE, "获取用户运行时间出错:%s", Encryptlockkernel::GetYtUSBKey32ErrInfo(ret)));
- return "";
- }
- ////////////////////////////////////////////////////////////////////////
- TCHAR DevicePath[ 260];
- if(FindPort(0,DevicePath)!=0)
- return "";
- DWORD OutID;
- int version;
- GetIDVersion(&OutID, &version, DevicePath);
- TCHAR year[10],month[10],day[10],hour[10],minute[10], OutString[100];
- _stprintf_s(year, _T("%d"), m_year);
- _stprintf_s(month, _T("%d"), m_month);
- _stprintf_s(day, _T("%d"), m_day);
- _stprintf_s(hour, _T("%d"), m_hour);
- _stprintf_s(minute, _T("%d"), m_minute);
- MakeTimerAuth("20D30D15FFB7F6AF9EAB30FD229F797B", id, year, month, day, hour, minute, OutString,DevicePath);
- CString authcode=OutString;
- TCHAR szTemp[50] = {0};
- //str.Format ("%04d", m_year);
- _stprintf_s(szTemp, _T("%04d"), m_year);
- authcode += szTemp;
- //str.Format ("%02d", m_month);
- _stprintf_s(szTemp, _T("%02d"), m_month);
- authcode += szTemp;
- //str.Format ("%02d", m_day);
- _stprintf_s(szTemp, _T("%02d"), m_day);
- authcode+=szTemp;
- _stprintf_s(szTemp, _T("%02d"), m_hour);
- //str.Format ("%02d", m_hour);
- authcode+=szTemp;
- _stprintf_s(szTemp, _T("%02d"), m_minute);
- //str.Format ("%02d", m_minute);
- authcode+=szTemp;
- //str.Format ("%08d", id);
- _stprintf_s(szTemp, _T("%08d"), id);
- authcode+=szTemp;
- TString str1,str2,str3,str4,str5;
- str1=authcode.Mid (0, 20);
- str2=authcode.Mid (20, 20);
- str3=authcode.Mid (40, 20);
- str4=authcode.Mid (60, 20);
- str5=authcode.Mid (80, 20);
- _stprintf_s(s0, "%s", str1.c_str());
- _stprintf_s(s1, "%s", str2.c_str());
- _stprintf_s(s2, "%s", str3.c_str());
- _stprintf_s(s3, "%s", str4.c_str());
- _stprintf_s(s4, "%s", str5.c_str());
- //运行自定义函数
- {
- //SoftKey ytSoftKey2;
- //ret=ytSoftKey2.Ini();
- //if (ret!=0 )
- //{
- // return "";
- //}
- {
- int d[8];double f[8];
- char s5[50]="",s6[50]="",s7[50]="";
- ret=g_ytSoftKey.code1(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],s0,s1,s2,s3,s4,s5,s6,s7);
- if(ret!=0 && ret!=-43)
- {
- printf("解释用户运行时间出错:%s\n",Encryptlockkernel::GetYtUSBKey32ErrInfo(ret));
- LOG4C_NO_FILENUM((LOG_NOTICE, "解释用户运行时间出错:%s", Encryptlockkernel::GetYtUSBKey32ErrInfo(ret)));
- return "";
- }
- }
-
- str1=s0;
- str2=s1;
- str3=s2;
- str4=s3;
- str5=s4;
- }
- authcode=str1.c_str();
- authcode+=str2.c_str();
- authcode+=str3.c_str();
- authcode+=str4.c_str();
- authcode+=str5.c_str();
- return authcode;
- }
- catch(...)
- {
- }
- return _T("");
- }
- CString GetUseDays(CString requestcode)
- {
- AutoThreadSection aSection(&g_critSection);
- try
- {
- CString sRet;
- requestcode.TrimLeft();
- requestcode.TrimRight();
- requestcode.Replace("\n", "");
- requestcode.Replace("\r", "");
- if(requestcode.IsEmpty())
- {
- printf("获取运行时间出错:请求码空\n");
- //LOG4C_NO_FILENUM((LOG_NOTICE, "获取运行时间出错:请求码空"));
- return "";
- }
- TString str,temp,temp2;
- int id,time1,time2,idtemp;
- int leng;
- str=requestcode;
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0,leng);
- str=str.substr(leng);
- id=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() - 1)=="1")id=-id;
- //////////////////////////////////////////////////
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0,leng);
- str=str.substr(leng);
- time1=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() - 1)=="1")time1=-time1;
- //////////////////////////////////////////////////
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0,leng);
- str=str.substr(leng);
- time2=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() - 1)=="1")time2=-time2;
- //////////////////////////////////////////////////////
- temp=str.substr(0,3);
- str=str.substr(3);
- leng=_ttoi(temp.substr(0,2).c_str());
- temp2=str.substr(0,leng);
- str=str.substr(leng);
- idtemp=_ttoi(temp2.c_str());
- if(temp.substr(temp.length() - 1)=="1")idtemp=-idtemp;
- //////////////////////////////////////////////////////
- int ret=0;
- int d[8];double f[8];
- char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
- //运行自定义函数
- ret=g_ytSoftKey.code2(&id,&idtemp,&time1,&time2,&d[4],&d[5],&d[6],&d[7],&f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],s0,s1,s2,s3,s4,s5,s6,s7);
- if(ret!=0 && ret!=-43)
- {
- printf("获取用户运行时间出错:%s\n",Encryptlockkernel::GetYtUSBKey32ErrInfo(ret));
- LOG4C_NO_FILENUM((LOG_NOTICE, "获取用户运行时间出错:%s", Encryptlockkernel::GetYtUSBKey32ErrInfo(ret)));
- return "";
- }
- // TODO: Add your control notification handler code here
- TCHAR year[10],month[10],day[10],hour[10],minute[10], second[10];
- ConvertTimerToStringReal(time2, year, month, day, hour, minute, second);
- TCHAR szTemp[MAX_PATH];
- _stprintf_s(szTemp, _T("已运行:%d年%d月%d日 "), _ttoi(year), _ttoi(month), _ttoi(day));
- sRet+=szTemp;
- if(time1>0)
- ConvertTimerToStringReal(time1, year, month, day, hour, minute, second);
- else
- {
- _stprintf_s(year, "%s", "0");
- _stprintf_s(month, "%s", "0");
- _stprintf_s(day, "%s", "0");
- _stprintf_s(hour, "%s", "0");
- _stprintf_s(minute, "%s", "0");
- }
- _stprintf_s(szTemp, _T("能运行:%d年%d月%d日---%d"), _ttoi(year), _ttoi(month), _ttoi(day), time2);
- sRet+=szTemp;
- return sRet;
- }
- catch(...)
- {
- }
- return "";
- }
- CClientProcess::CClientProcess(void)
- {
- m_hEvent = NULL;
- m_hThread = NULL;
- m_hEvent2 = NULL;
- m_hThread2 = NULL;
- m_dwOverBuffer = m_dwOverIndex = 0;
- m_pOverBuffer = NULL;
- InitializeCriticalSection(&m_csMsgInfo);
- }
- CClientProcess::~CClientProcess(void)
- {
- DeleteCriticalSection(&m_csMsgInfo);
- m_listMsgInfo.clear();
- }
- void CClientProcess::StartMsgWork()
- {
- m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- if ( m_hEvent == NULL )
- {
- // 创建事件失败;
- return;
- }
- m_hThread = CreateThread(NULL, 0, MsgThread, this, 0, NULL);
- if ( m_hThread == NULL )
- {
- CloseHandle(m_hEvent);
- m_hEvent = NULL;
- }
- //////////////////////////////////////////////////////////////////////////
- m_hEvent2 = CreateEvent(NULL, TRUE, FALSE, NULL);
- if ( m_hEvent2 == NULL )
- {
- // 创建事件失败;
- return;
- }
- m_hThread2 = CreateThread(NULL, 0, MsgThread, this, 0, NULL);
- if ( m_hThread2 == NULL )
- {
- CloseHandle(m_hEvent2);
- m_hEvent2 = NULL;
- }
- }
- void CClientProcess::EndOfMsgWork()
- {
- if ( m_hEvent )
- {
- SetEvent(m_hEvent);
- }
- if ( m_hThread )
- {
- WaitForSingleObject(m_hThread, INFINITE);
- CloseHandle(m_hThread);
- m_hThread = NULL;
- }
- if (m_hEvent)
- CloseHandle(m_hEvent);
- m_hEvent = NULL;
- //////////////////////////////////////////////////////////////////////////
- if ( m_hEvent2 )
- {
- SetEvent(m_hEvent2);
- }
- if ( m_hThread2 )
- {
- WaitForSingleObject(m_hThread2, INFINITE);
- CloseHandle(m_hThread2);
- m_hThread2 = NULL;
- }
- if (m_hEvent2)
- CloseHandle(m_hEvent2);
- m_hEvent2 = NULL;
- }
- void CClientProcess::InsertMsgInfo(IN MsgInfo& msgInfo)
- {
- EnterCriticalSection(&m_csMsgInfo);
- m_listMsgInfo.push_back(msgInfo);
- LeaveCriticalSection(&m_csMsgInfo);
- }
- BOOL CClientProcess::PopMsgInfo(IN MsgInfo& msgInfo)
- {
- BOOL bRet = FALSE;
- EnterCriticalSection(&m_csMsgInfo);
- if ( m_listMsgInfo.size())
- {
- msgInfo = m_listMsgInfo.front();
- m_listMsgInfo.pop_front();
- bRet = TRUE;
- }
- LeaveCriticalSection(&m_csMsgInfo);
- return bRet;
- }
- DWORD CClientProcess::WorkSendInfo(IN CONST SOCKET& nSock, IN TString &strIPAddr, IN const DWORD& dwUserId, IN CONST INT& wMessageLen, IN TString &strInfo, OUT INT& ArySize, OUT BYTE** pAryData, OUT DWORD& dwAryDataSize)
- {
- CSocketHandle tClientSo;
- tClientSo.Attach(nSock);
- SockAddrIn saddr;
- tClientSo.GetPeerName(saddr);
- TCHAR szIPAddr[MAX_PATH] = { 0 };
- CSocketHandle::FormatIP(szIPAddr, MAX_PATH, saddr);
- CString str;
- str.Format(_T("%s : %d"), szIPAddr, static_cast<int>(static_cast<UINT>(ntohs(saddr.GetPort()))));
- if ( str.CompareNoCase(strIPAddr.c_str()) != 0 )
- {
- tClientSo.Detach();
- printf("SOCKET[%d]地址接收前[%s]和发送前地址[%s]不一样\n", nSock, strIPAddr.c_str(), str.GetString());
- //LOG4C_NO_FILENUM((LOG_NOTICE,"SOCKET[%d]地址接收前[%s]和发送前地址[%s]不一样", nSock, strIPAddr.c_str(), str.GetString()));
- return INVALID_VALUE;
- }
- //////////////////////////////////////////////////////////////////////////
- DWORD dwFromUserID = wMessageLen;
- WORD wMessageId = MSG_CHATMESSAGE_RESP;
- DWORD dwDataLen;
- BYTE *pSendData;
- TCHAT_MESSAGE_STRU *pChatMessage;
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- SENDHEAD tSendhead;
- ZeroMemory(&tSendhead,sizeof(SENDHEAD));
- if ( strInfo.empty() )
- strInfo = _T("OK");
- int nDataLen = strInfo.length();
- if( dwAryDataSize )
- {
- nDataLen = dwAryDataSize;
- if ( dwUserId == 8)
- tSendhead.count[0] = ArySize;
- }
- dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen ;
- pSendData = new BYTE[dwDataLen];
- pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
- memset(pChatMessage, 0x00, dwDataLen);
- memcpy(pSendData, &tSendhead, sizeof(SENDHEAD));
- pChatMessage->tCommonMsg.dwConnectionID = dwFromUserID;
- pChatMessage->tCommonMsg.wMessageId = wMessageId;
- pChatMessage->dwFromUserID = dwFromUserID;
- pChatMessage->dwToUserID = pChatMessage->wMessageLen;
- pChatMessage->wMessageLen = nDataLen;
- if(dwAryDataSize)
- {
- memcpy(pChatMessage->byFileContent, *pAryData, nDataLen);
- }
- else
- {
- memcpy(pChatMessage->byFileContent, strInfo.c_str(), nDataLen);
- }
-
- DWORD dwResult = net_Send(&tClientSo, &tHeader, (void *)pChatMessage, dwDataLen);
- tClientSo.Detach();
- delete [] pSendData;
- return dwResult;
- }
- DWORD CClientProcess::MsgThread(LPVOID lpParam)
- {
- INT nRet = -1;
- BOOL bSend = FALSE;
- INT nArySize = 0;
- DWORD dwAryDataSize = 0;
- BYTE *pAryData = NULL;
- CClientProcess *pInstance = (CClientProcess*)lpParam;
- do
- {
- MsgInfo tagMsgInfo;
- if ( PopMsgInfo(tagMsgInfo) )
- {
- bSend = FALSE;
- switch( tagMsgInfo.dwUserId )
- {
- case 6:
- bSend = Work_No6(tagMsgInfo.strMessage, tagMsgInfo.strIPAddress.c_str());
- break;
- case 7:
- bSend = Work_No7(tagMsgInfo.strMessage);
- break;
- case 8:
- bSend = Work_No8(tagMsgInfo.strMessage, nArySize, &pAryData, dwAryDataSize);
- break;
- case 9:
- bSend = Work_No9(tagMsgInfo.strMessage, tagMsgInfo.pData, tagMsgInfo.wMessageLen);
- break;
- case 10:
- bSend = Work_No10(tagMsgInfo.strIPAddress.c_str(), tagMsgInfo.strMessage);
- break;
- case 11:
- bSend = Work_No11(tagMsgInfo.strMessage);
- break;
- case 12:
- bSend = Work_No12(tagMsgInfo.strMessage);
- break;
- case 13:
- bSend = Work_No13(tagMsgInfo.strMessage);
- break;
- case 14:
- bSend = Work_No14(tagMsgInfo.strMessage);
- break;
- case 15:
- bSend = Work_No15(tagMsgInfo.strMessage);
- break;
- case 16:
- bSend = Work_No16(tagMsgInfo.strIPAddress.c_str(), tagMsgInfo.strMessage);
- break;
- case 17:
- bSend = Work_No17(tagMsgInfo.strIPAddress.c_str(), tagMsgInfo.pData, tagMsgInfo.wMessageLen, &pAryData, dwAryDataSize);
- break;
- case 18:
- nRet = Work_No18(tagMsgInfo.strIPAddress.c_str(), tagMsgInfo.strMessage);
- break;
- default:
- break;
- }
- if ( tagMsgInfo.dwUserId == 18 )
- {
- DWORD dwResult = WorkSendInfo(tagMsgInfo.nSocket, tagMsgInfo.strIPAddress, tagMsgInfo.dwUserId, tagMsgInfo.wMessageLen, tagMsgInfo.strMessage, nArySize, &pAryData, dwAryDataSize);
- if ( pAryData )
- {
- delete []pAryData;
- pAryData = NULL;
- }
- nArySize = 0;
- dwAryDataSize = 0;
- if ( nRet > 0 && dwResult != INVALID_VALUE )
- {// 更新;
- CString strSQL = _T("");
- strSQL.Format(_T("UPDATE [StudioInfo] SET [CommandStatus] = 'true' WHERE [StudioAutoID] = %d"), nRet);
- g_podbc->ExecuteSQL(strSQL);
- }
- }
- else if ( bSend )
- {
- WorkSendInfo(tagMsgInfo.nSocket, tagMsgInfo.strIPAddress, tagMsgInfo.dwUserId, tagMsgInfo.wMessageLen, tagMsgInfo.strMessage, nArySize, &pAryData, dwAryDataSize);
- if ( tagMsgInfo.dwUserId == 17 && tagMsgInfo.pData )
- {
- delete []tagMsgInfo.pData;
- }
- if ( pAryData )
- {
- delete []pAryData;
- pAryData = NULL;
- }
- nArySize = 0;
- dwAryDataSize = 0;
- }
- else
- {
- // 这里有问题,原来旧的代码也没有做处理,会导致客户端接收不到服务器响应;
- }
- }
- } while (WaitForSingleObject(pInstance->m_hEvent, 10) == WAIT_TIMEOUT );
- return 0;
- }
- DWORD CClientProcess::net_Send(CSocketHandle* pSH, IN void *pHeader, IN void *pMessage, IN unsigned long ulDataLen)
- {
- unsigned long ulSendLen = 0;
- unsigned long ulBufLen = 0;
- TMessageHeader *pSendHeader = (TMessageHeader *)pHeader;
- ulBufLen = MESSAGE_HEADER_LEN + ulDataLen;
- BYTE *pSendBuf = new BYTE[ulBufLen];
- memset(pSendBuf, 0, ulBufLen);
- TMessageHeader *pMessageHeader = (TMessageHeader *)pSendBuf;
- pMessageHeader->byVersion = 101;
- pMessageHeader->wHeaderFlag = MESSAGE_HEADER_FLAG;
- pMessageHeader->wMessageId = pSendHeader->wMessageId;
- pMessageHeader->wMessageSubId = pSendHeader->wMessageSubId;
- pMessageHeader->dwDataLen = ulDataLen;
- pMessageHeader->wReserve = 0;
- memcpy((void *)(pSendBuf+MESSAGE_HEADER_LEN), pMessage, ulDataLen);
- // convert network word
- htons(pMessageHeader->wHeaderFlag);
- htons(pMessageHeader->wMessageId);
- htons(pMessageHeader->wMessageSubId);
- htonl(pMessageHeader->dwDataLen);
- htons(pMessageHeader->wCheckSum);
- htonl(pMessageHeader->wReserve);
- INT nBytes = pSH->Write(pSendBuf, ulBufLen, NULL, 1000);
- DWORD dwError = WSAGetLastError();
- if ( dwError != 0 )
- {
- printf("\t发送给客户端信息失败:%d\n", dwError);
- }
- delete []pSendBuf;
- pSendBuf = NULL;
- return nBytes;
- }
- 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)
- {
- try
- {
- TMessageHeader *pMessageHeader = (TMessageHeader *)pbData;
- if(pMessageHeader->wMessageId == MSG_LOGIN_REQ)
- {
- WORD wMessageId = MSG_LOGIN_RESP;
- LOGIN_RESULT_STRU tLoginResult = {0};
- tLoginResult.tCommonMsg.dwConnectionID = 0;
- tLoginResult.tCommonMsg.wMessageId = wMessageId;
- tLoginResult.byResult = LOGIN_RESULT_SUC;
- tLoginResult.dwUserID = 0;
- tLoginResult.byStatus = USER_STATUS_ONLINE ;
- DWORD dwDataLen = sizeof(LOGIN_RESULT_STRU);
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- tHeader.dwDataLen = dwDataLen;
- if ( (pMessageHeader->dwDataLen + sizeof(LOGIN_RESULT_STRU)) != dwCount )
- {
- return;
- }
- CSocketHandle hClient;
- hClient.Attach(sClient);
- net_Send(&hClient, &tHeader, (void *)&tLoginResult, dwDataLen);
- hClient.Detach();
- }
- else //if(pMessageHeader->wMessageId == MSG_CHATMESSAGE_REQ)
- {
- TCHAT_MESSAGE_STRU *ptChatMessage = (TCHAT_MESSAGE_STRU *)(pbData+MESSAGE_HEADER_LEN);
- if ( dwCount != ( ptChatMessage->wMessageLen + sizeof(TCHAT_MESSAGE_STRU) + sizeof(TMessageHeader) ))
- {
- return;
- if (m_pOverBuffer == NULL && m_dwOverBuffer == 0 && m_dwOverIndex == 0)
- {
- m_dwOverBuffer = ptChatMessage->wMessageLen + sizeof(TCHAT_MESSAGE_STRU) + sizeof(TMessageHeader);
- m_pOverBuffer = new BYTE[m_dwOverBuffer];
- memset(m_pOverBuffer, 0, m_dwOverBuffer);
- }
- memcpy(m_pOverBuffer + m_dwOverIndex, pbData, dwCount);
- m_dwOverIndex += dwCount;
- if ( m_dwOverBuffer == m_dwOverIndex )
- {
- ptChatMessage = (TCHAT_MESSAGE_STRU *)(m_pOverBuffer+MESSAGE_HEADER_LEN);
- }
- else if ( m_dwOverIndex > m_dwOverBuffer )
- {
- if (m_pOverBuffer)
- {
- delete []m_pOverBuffer;
- m_pOverBuffer = NULL;
- m_dwOverIndex = m_dwOverBuffer = 0;
- }
- return;
- }
- else
- {
- return;
- }
- }
- DWORD dwUserId = ptChatMessage->tCommonMsg.dwConnectionID;
- if ( ptChatMessage->length[98] != 987123768 )
- {
- if (m_pOverBuffer)
- {
- delete []m_pOverBuffer;
- m_pOverBuffer = NULL;
- m_dwOverIndex = m_dwOverBuffer = 0;
- }
- return;
- }
- TString strContent = _T("");
- if ( ptChatMessage->wMessageLen > 3 )
- {
- if ( ptChatMessage->dwToUserID != 9 )
- {
- BYTE *szChatMessage = new BYTE[ptChatMessage->wMessageLen + 1];
- memset(szChatMessage, 0, ptChatMessage->wMessageLen+1);
- memcpy(szChatMessage, ptChatMessage->byFileContent, ptChatMessage->wMessageLen);
- Global::EncryptFile2((BYTE*)szChatMessage, ptChatMessage->wMessageLen, _T("888666333"));
- #if 1
- MsgInfo tagMsgInfo;
- tagMsgInfo.nSocket = sClient;
- tagMsgInfo.strIPAddress = lpaddr;
- tagMsgInfo.dwUserId = ptChatMessage->dwToUserID;
- if ( ptChatMessage->dwToUserID != 17)
- {
- tagMsgInfo.strMessage = (TCHAR*)szChatMessage;
- }
- else
- {
- tagMsgInfo.pData = new BYTE[ptChatMessage->wMessageLen];
- memset(tagMsgInfo.pData, 0, ptChatMessage->wMessageLen);
- memcpy(tagMsgInfo.pData, szChatMessage, ptChatMessage->wMessageLen);
- }
- tagMsgInfo.wMessageLen = ptChatMessage->wMessageLen;
- InsertMsgInfo(tagMsgInfo);
- delete []szChatMessage;
- #else
- strContent = (TCHAR*)szChatMessage;
- delete []szChatMessage;
- // 企业版 8 使用;
- BYTE *pAryData = NULL;
- DWORD dwAryDataSize = 0;
- INT nArySize = 0;
- //////////////////////////////////////////////////////////////////////////
- // 处理回复;
- INT nStrlen = 0;
- INT nSQLRetsult = 0;
- if ( ptChatMessage->dwToUserID == 6 )
- {
- if ( Work_No6(strContent, lpaddr) == FALSE )
- {
- return;
- }
- }
- else if ( ptChatMessage->dwToUserID == 7 )
- {
- if ( Work_No7(strContent) == FALSE )
- {
- return;
- }
- }
- else if ( ptChatMessage->dwToUserID == 8 )
- {
- if (Work_No8(strContent, nArySize, &pAryData, dwAryDataSize) == FALSE )
- {
- return;
- }
- }
- else if ( ptChatMessage->dwToUserID == 9 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 10 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 11 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 12 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 13 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 14 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 15 )
- {
- }
- else if ( ptChatMessage->dwToUserID == 16 )
- {
- }
- WorkSendInfo(sClient, ptChatMessage->wMessageLen, strContent, nArySize, &pAryData, dwAryDataSize);
- if (pAryData)
- delete []pAryData;
- #endif
- }
- else
- {
- MsgInfo tagMsgInfo;
- tagMsgInfo.nSocket = sClient;
- tagMsgInfo.strIPAddress = lpaddr;
- tagMsgInfo.dwUserId = ptChatMessage->dwToUserID;
- //tagMsgInfo.strMessage = (TCHAR*)szChatMessage;
- tagMsgInfo.wMessageLen = ptChatMessage->wMessageLen;
- tagMsgInfo.pData = new BYTE[tagMsgInfo.wMessageLen];
- memcpy(tagMsgInfo.pData, ptChatMessage->byFileContent, tagMsgInfo.wMessageLen);
- InsertMsgInfo(tagMsgInfo);
- }
- }
- if (m_pOverBuffer)
- {
- delete []m_pOverBuffer;
- m_pOverBuffer = NULL;
- m_dwOverIndex = m_dwOverBuffer = 0;
- }
- }
- }
- catch (CException* e)
- {
- e->ReportError();
- }
- return;
- }
- BOOL CClientProcess::Work_No6(IN TString& strContent, IN LPCTSTR lpIPAddress)
- {
- if ( strContent.find(_T(";")) == TString::npos)
- {
- strContent = _T("长度错误c");
- return FALSE;
- }
- INT nStrlen = 0;
- INT pos = strContent.find(_T("&@&@&"));
- if( pos != TString::npos )
- {
- // 影楼信息及订单数;
- TString info = strContent.substr(0,pos);
- nStrlen = strContent.length() - pos - 5;
- if ( nStrlen <= 0 )
- {
- //printf("\t\t work 6 长度错误\n");
- strContent = _T("长度错误a");
- return FALSE;
- }
- strContent = strContent.substr(strContent.length() - nStrlen);
- pos = info.find_last_of(_T(":"));
- if ( pos != TString::npos )
- {
- nStrlen = info.length() - pos - 1;
- if ( nStrlen <= 0 )
- {
- //printf("\t\t work 6 长度错误\n");
- strContent = _T("长度错误b");
- return FALSE;
- }
- TString dindan = _T("订单数:") + info.substr(info.length() - nStrlen);
- pos = info.find_last_of(_T("订单数:"));
- if ( pos != TString::npos )
- {
- info = info.substr(0, pos - _tcslen(_T("订单数")));
- TString datetime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
- TString sql,execute;
- BOOL bexist=0;
- // 获取远程控制的SQL语句(影楼客户端接收);
- TString strResult;
- #ifdef USE_ODBC_DLL
- if( !g_podbc->GetunauthInfo(info.c_str(), strResult, 5000) )
- #else
- if( !CODBCPool::GetInstance()->GetunauthInfo(info.c_str(), strResult, 5000) )
- #endif
- {
- //printf("\t\t work 6 获取控制SQL语句失败\n");
- return FALSE;
- }
- execute = strResult.c_str();
- if( execute == _T("停止运行") )
- {
- strContent = _T("无域名字段,请确认");
- }
- else
- {
- if(execute.empty())
- {
- sql.append(_T("insert into [unauth]([name],[dindan],[datetime],[execute])values('"));
- sql.append(info);
- sql.append(_T("','"));
- sql.append(dindan);
- sql.append(_T("','"));
- sql.append(datetime);
- sql.append(_T("','"));
- sql.append(_T("0"));
- sql.append(_T("')"));
- }
- else
- {
- sql.append(_T("update [unauth] set [dindan]='"));
- sql.append(dindan);
- sql.append(_T("',[datetime]='"));
- sql.append(datetime);
- sql.append(_T("' where [name]='"));
- sql.append(info);
- sql.append(_T("'"));
- }
- #ifdef USE_ODBC_DLL
- if( !g_podbc->ExecuteSQL(sql.c_str(), 5000) )
- #else
- if( !CODBCPool::GetInstance()->ExecuteSQL(sql.c_str(), 5000) )
- #endif
- {
- //printf("\t\t work 6 更新影楼信息出错");
- strContent = _T("更新影楼信息出错");
- return FALSE;
- }
- }
- }
- }
- }
- else
- {
- // 影楼域名;
- TString strBranchId = strContent;
- pos = strContent.find(_T(";"));
- // 日志信息及注册码;
- TString logcontent = _T("未升级,无法获知");
- TString temp,regcode,regcode2,regcodebak;
- if( pos != TString::npos )
- {
- // 获取到域名;
- strBranchId = strContent.substr(0,pos);
- if ( strBranchId.empty() || !( strBranchId.find(_T(".ly.com")) != TString::npos || strBranchId.find(_T(".lyfz.com")) != TString::npos || strBranchId.find(_T(".eicp.net")) != TString::npos ))
- {
- //printf("\t\t work 6 域名出错\n");
- strContent = _T("域名出错");
- return FALSE;
- }
- nStrlen = strContent.length() - pos - 1;
- if ( nStrlen <= 0 || nStrlen >= strContent.length())
- {
- //printf("\t\t work 6 长度错误1\n");
- strContent = _T("长度错误1");
- return FALSE;
- }
- logcontent = strContent.substr(strContent.length() - nStrlen);
- pos = logcontent.find(_T("***"));
- if( pos != TString::npos )
- {
- nStrlen = logcontent.length() - pos - 3;
- if ( nStrlen <= 0 )
- {
- //printf("\t\t work 6 长度错误2\n");
- strContent = _T("长度错误2");
- return FALSE;
- }
- // 解析出DBServer.exe加密的加时请求授权码(regcode.txt);
- regcode = logcontent.substr(logcontent.length() - nStrlen).c_str();
- regcodebak = regcode;
- logcontent = logcontent.substr(0, pos).c_str();
- strContent = GetUseDays(regcode.c_str());
- regcode = strContent;
- // 获取可运行的时间值;
- pos = regcode.find(_T("---"));
- if(pos != TString::npos )
- {
- nStrlen = regcode.length() - pos - 3;
- if ( nStrlen <= 0 )
- {
- //printf("\t\t work 6 长度错误3\n");
- strContent = _T("长度错误3");
- return FALSE;
- }
- regcodebak.append(_T("---"));
- regcodebak.append(regcode.substr(regcode.length() - nStrlen));
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////
- // 获取客户端ip地址;
- strContent = lpIPAddress;
- pos = strContent.find(_T(":"));
- if ( pos == TString::npos )
- {
- //printf("\t\t work 6 无IP地址\n");
- strContent = _T("无IP地址");
- return FALSE;
- }
- strContent = strContent.substr(0,pos -1);
- TString datetime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
- pos = regcode.find(_T("---"));
- if(pos != TString::npos )
- {
- temp = regcode.substr(0,pos);
- }
- else
- temp = regcode;
- TString sql ;
- sql.append(_T("update [clientip] set [ip]='"));
- sql.append(strContent);
- sql.append(_T("',[datetime]='"));
- sql.append(datetime);
- sql.append(_T("',"));
- sql.append(_T("[log]='"));
- sql.append(logcontent);
- sql.append(_T("',"));
- sql.append(_T("[regcode]='"));
- sql.append(temp);
- sql.append(_T("' where [name]='"));
- sql.append(strBranchId);
- sql.append(_T("'"));
- #ifdef USE_ODBC_DLL
- if ( !g_podbc->ExecuteSQL(sql.c_str(), 5000) )
- #else
- if ( !CODBCPool::GetInstance()->ExecuteSQL(sql.c_str(), 5000) )
- #endif
- {
- //printf("\n更新影楼IP:%s\n",sql.c_str());
- //printf("\t\t work 6 更新影楼IP出错\n");
- strContent = _T("更新影楼IP出错");
- return FALSE;
- }
- TblClientip1 Clientip;
- sql = _T("name = '");
- sql.append(strBranchId);
- sql.append(_T("'"));
- #ifdef USE_ODBC_DLL
- INT nSQLRetsult = g_podbc->GetClientEnterpriseName(sql.c_str(), &Clientip, 5000);
- #else
- INT nSQLRetsult = CODBCPool::GetInstance()->GetClientEnterpriseName(sql.c_str(), &Clientip, 5000);
- #endif
- if ( nSQLRetsult == 1 )
- {
- sql = Clientip.szBranchname;
- regcode2 = Clientip.szRegcode2;
- }
- else if ( nSQLRetsult == 0 )
- {
- sql = _T("xxx!");
- strContent = _T("此域名未绑定!");
- }
- else
- {
- //printf("\t\t work 6 获取企业名出错, %s\n", sql.c_str());
- strContent = _T("获取企业名出错");
- return FALSE;
- }
- regcode = regcodebak;
- if(regcode != _T("") && (regcode2.length() == 10 || regcode2 == _T("永久")) )
- {
- long newsecond = 0;
- long dtsecond = 0;
- CTime curtm = CTime::GetCurrentTime();
- if(regcode2 == _T("永久"))
- {
- newsecond = 60;
- pos = regcode.find(_T("---"));
- if( pos != TString::npos )
- regcodebak = regcode.substr(0,pos);
- }
- else
- {
- 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);
- CTimeSpan dt = destm-curtm;
- dtsecond = dt.GetTotalSeconds();
- dtsecond /= 2;
- pos = regcode.find(_T("---"));
- if( pos != TString::npos && dtsecond > 0 )
- {
- regcodebak = regcode.substr(0, pos);
- regcode = regcode.substr( pos + 3 );
- long usedsecond = _ttoi(regcode.c_str());
- newsecond = usedsecond + dtsecond;
- }
- }
- if( newsecond )
- {
- strContent.append(_T("authcodexiao"));
- strContent.append(GetAuthCode(regcodebak.c_str(), newsecond));
- }
- }
- }
- return TRUE;
- }
- BOOL CClientProcess::Work_No7(OUT TString& strBranchId)
- {
- if ( strBranchId.empty() || !( strBranchId.find(_T(".ly.com")) != TString::npos || strBranchId.find(_T(".lyfz.com")) != TString::npos || strBranchId.find(_T(".eicp.net")) != TString::npos ))
- {
- // 域名空;
- //printf("\t\t work 7 域名错误\n");
- return FALSE;
- }
- TString strName = _T("name = ");
- strName.append(_T("'"));
- strName.append(strBranchId);
- strName.append(_T("'"));
- TCHAR szResult[MAX_PATH] = {0};
- #ifdef USE_ODBC_DLL
- if ( g_podbc->GetSelectby(_T("clientip"), _T("ip"), strName.c_str(), szResult, MAX_PATH) )
- #else
- if ( CODBCPool::GetInstance()->GetSelectby(_T("clientip"), _T("ip"), strName.c_str(), szResult, MAX_PATH) )
- #endif
- {
- if ( _tcslen(szResult) )
- strBranchId = szResult;
- else
- strBranchId.append(_T("没有此域名的记录!"));
- }
- else
- {
- return FALSE;
- }
- return TRUE;
- }
- BOOL CClientProcess::Work_No8(IN TString& strContent, OUT INT& ArySize, OUT BYTE** pAryData, OUT DWORD& dwAryDataSize)
- {
- TString strSQL, strBranchId, strTemp;
- strBranchId = strContent;
- if ( strBranchId.empty() || !( strBranchId.find(_T(".ly.com")) != TString::npos || strBranchId.find(_T(".lyfz.com")) != TString::npos || strBranchId.find(_T(".eicp.net")) != TString::npos ))
- {
- //printf("\t\t work 8 域名错误\n");
- return FALSE;
- }
- // 查询数据;
- TString strEnterprisName;
- TString strName = _T("name = ");
- strName.append(_T("'"));
- strName.append(strBranchId);
- strName.append(_T("'"));
- TCHAR szResult[MAX_PATH] = {0};
- #ifdef USE_ODBC_DLL
- if ( g_podbc->GetSelectby(_T("clientip"), _T("enterprisename"), strName.c_str(), szResult, MAX_PATH, 5000) )
- #else
- if ( CODBCPool::GetInstance()->GetSelectby(_T("clientip"), _T("enterprisename"), strName.c_str(), szResult, MAX_PATH, 5000) )
- #endif
- {
- if ( _tcslen(szResult) )
- strEnterprisName = szResult;
- else
- strSQL = _T("xxx!");
- }
- else
- {
- return FALSE;
- }
- // 再查询数据;
- strContent = strEnterprisName;
- if ( !strContent.empty() )
- {
- CArray<CStringArray,CStringArray> AryEnterprisInfo;
- #ifdef USE_ODBC_DLL
- INT nCount = g_podbc->GetEnterprisInfo(strContent.c_str(), AryEnterprisInfo, 5000);
- #else
- INT nCount = CODBCPool::GetInstance()->GetEnterprisInfo(strContent.c_str(), AryEnterprisInfo, 5000);
- #endif
- if ( nCount > 0 )
- {
- strContent = _T("");
- CMemFile mf;
- CArchive ar(&mf, CArchive::store);
- ArySize = nCount;
- for ( int i = 0; i < nCount; i++ )
- {
- AryEnterprisInfo.ElementAt(i).Serialize(ar);
- }
- ar.Close();
- // 附加给专用变量;
- dwAryDataSize = mf.GetLength();
- *pAryData = mf.Detach();
- strContent = _T("ok");
- }
- else if ( nCount == 0 )
- {
- strContent.append(_T("没有此企业的资料"));
- }
- else
- {
- return FALSE;
- }
- }
- else
- {
- strContent.append(_T("没有此企业的资料"));
- }
- return TRUE;
- }
- BOOL CClientProcess::Work_No9(OUT TString& strContent, IN BYTE* pData, IN CONST INT &nMessageLen)
- {
- if ( pData == NULL || nMessageLen < 4 )
- return FALSE;
- CMemFile mf;
- mf.Attach(pData + sizeof(DWORD), nMessageLen - sizeof(DWORD));
- CArchive ar(&mf, CArchive::load);
- DWORD dwArySize = 0;
- memcpy(&dwArySize, pData, sizeof(DWORD));
- CArray<CStringArray,CStringArray> AryRights;
- AryRights.SetSize(dwArySize);
- for ( int i = 0; i < dwArySize; i++ )
- {
- AryRights.ElementAt(i).Serialize(ar);
- }
- ar.Close();
- mf.Detach();
- BOOL bRet = FALSE;
- TString strEnterpriseName = _T("");
- if ( AryRights.GetSize() )
- {
- strEnterpriseName = AryRights.ElementAt(0).ElementAt(0);
- TString strBranchName, strRights;
- for ( int i = 0; i < AryRights.GetSize(); i++ )
- {
- strBranchName = AryRights.ElementAt(i).ElementAt(1);
- strRights = _T("");
- for ( int j = 2; j < AryRights.ElementAt(i).GetSize(); j++ )
- {
- strRights.append(AryRights.ElementAt(i).ElementAt(j));
- strRights.append(_T(","));
- }
- if (strRights.length() && strRights[strRights.length() - 1] == _T(','))
- strRights.erase(strRights.length() - 1);
- TString strSQL = _T("update clientip set [rights]='");
- strSQL.append(strRights);
- strSQL.append(_T("' where [enterprisename]='"));
- strSQL.append(strEnterpriseName);
- strSQL.append(_T("' and [branchname]='"));
- strSQL.append(strBranchName);
- strSQL.append(_T("'"));
- #ifdef USE_ODBC_DLL
- bRet = g_podbc->ExecuteSQL(strSQL.c_str(), 5000);
- #else
- bRet = CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str(), 5000);
- #endif
- }
- }
- if ( pData )
- {
- delete []pData;
- pData = NULL;
- }
- strContent = _T("set ok");
- return bRet;
- }
- BOOL CClientProcess::Work_No10(IN LPCTSTR lpIPAddress, IN TString& strContent)
- {// 记录影楼IP地址;
- if ( lpIPAddress == NULL || lpIPAddress[0] == _T('\0'))
- {
- return FALSE;
- }
- // 获取客户端ip地址;
- TString strIPAddress = lpIPAddress;
- INT nIndex = strIPAddress.find(_T(":"));
- if ( nIndex == TString::npos )
- {
- //printf("\t\t work 10 无IP地址\n");
- return FALSE;
- }
- strIPAddress = strIPAddress.substr(0,nIndex -1);
- TString strDateTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
- TString strSQL = _T("update [clientip2] set [ip] ='");
- strSQL.append(strIPAddress);
- strSQL.append(_T("',[datetime] = '"));
- strSQL.append(strDateTime);
- strSQL.append(_T("' where [name] = '"));
- strSQL.append(strContent);
- strSQL.append(_T("'"));
- #ifdef USE_ODBC_DLL
- return g_podbc->ExecuteSQL(strSQL.c_str());
- #else
- return CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str());
- #endif
- }
- BOOL CClientProcess::Work_No11(IN TString& strContent)
- {
- TString strFilters;
- strFilters = _T("name = '");
- strFilters.append(strContent);
- strFilters = _T("'");
- TCHAR szResult[MAX_PATH] = {0};
- #ifdef USE_ODBC_DLL
- if ( g_podbc->GetSelectby(_T("clientip2"), _T("[ip]"), strFilters.c_str(), szResult, MAX_PATH) )
- #else
- if ( CODBCPool::GetInstance()->GetSelectby(_T("clientip2"), _T("[ip]"), strFilters.c_str(), szResult, MAX_PATH) )
- #endif
- {
- if (szResult[0] != _T('\0'))
- strContent = szResult;
- else
- strContent.append(_T("没有此域名的记录"));
- return TRUE;
- }
- return FALSE;
- }
- BOOL CClientProcess::Work_No12(IN TString& strContent)
- {
- #ifdef USE_ODBC_DLL
- if ( g_podbc->ExecuteSQL(strContent.c_str()) )
- #else
- if ( CODBCPool::GetInstance()->ExecuteSQL(strContent.c_str()) )
- #endif
- {
- strContent = _T("ok");
- }
- return TRUE;
- }
- BOOL CClientProcess::Work_No13(IN TString& strContent)
- {
- TString strSQL = strContent;
- strContent = _T("ok");
- if ( strSQL.length() < 6 )
- {
- return FALSE;
- }
- if ( strSQL.substr(0, 6) != _T("select") )
- {
- return FALSE;
- }
- #ifdef USE_ODBC_DLL
- return g_podbc->GetDBCFileInfo(strSQL.c_str(), strContent);
- #else
- return CODBCPool::GetInstance()->GetDBCFileInfo(strSQL.c_str(), strContent);
- #endif
- }
- BOOL CClientProcess::Work_No14(IN TString& strContent)
- {
- //printf(" \t\t ------Work No.14------ \n");
- // 前任测试,废弃;
- return TRUE;
- }
- BOOL CClientProcess::Work_No15(IN TString& strContent)
- {
- //printf(" \t\t ------Work No.15------ \n");
- // 前任测试,废弃;
- return TRUE;
- }
- /************************************************************************/
- /* 函数:[8/29/2016 IT];
- /* 描述:接收YLGL.exe客户端发回的信息;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- BOOL CClientProcess::Work_No16(IN LPCTSTR lpIPAddress, IN TString& strContent)
- {
- if ( lpIPAddress == NULL || lpIPAddress[0] == _T('\0') )
- {
- return FALSE;
- }
- INT nIndex = 0;
- TString strSeperator = _T("*%!X");
- INT nSeperator = strSeperator.length();
- // 获取影楼的域名;
- TString strBranchId = _T("");
- nIndex = strContent.find(strSeperator);
- if ( nIndex != TString::npos )
- {
- strBranchId = strContent.substr(0, nIndex);
- strContent = strContent.substr(nIndex + nSeperator);
- }
- // 获取影楼名称;
- TString strEdit1 = _T("");
- nIndex = strContent.find(strSeperator);
- if ( nIndex != TString::npos )
- {
- strEdit1 = strContent.substr(0, nIndex);
- strContent = strContent.substr(nIndex + nSeperator);
- }
- // 获取影楼老板电话;
- TString strEdit2 = _T("");
- nIndex = strContent.find(strSeperator);
- if ( nIndex != TString::npos )
- {
- strEdit2 = strContent.substr(0, nIndex);
- strContent = strContent.substr(nIndex + nSeperator);
- }
- // 获取地址;
- TString strEdit3 = _T("");
- nIndex = strContent.find(strSeperator);
- if ( nIndex != TString::npos )
- {
- strEdit3 = strContent.substr(0, nIndex);
- strContent = strContent.substr(nIndex + nSeperator);
- }
- // 获取老板名称;
- TString strEdit4 = _T("");
- nIndex = strContent.find(strSeperator);
- if ( nIndex != TString::npos )
- {
- strEdit4 = strContent.substr(0, nIndex);
- strContent = strContent.substr(nIndex + nSeperator);
- }
- // 获取订单数量;
- TString strOrderNum = _T("");
- TString strEdit5 = _T("");
- nIndex = strContent.find(strSeperator);
- if ( nIndex != TString::npos )
- {
- strEdit5 = strContent.substr(0, nIndex);
- strContent = strContent.substr(nIndex + nSeperator);
- strOrderNum = strContent;
- }
- Global::WriteTextLog(_T("【\n域名:%s\n 名称:%s\n 电话:%s\n 地址:%s\n 老板:%s\n 订单数量:%s】\n"), strBranchId.c_str(), strEdit1.c_str(), strEdit2.c_str(), strEdit3.c_str(), strEdit4.c_str(), strEdit5.c_str());
- // 构建SQL语句;
- TCHAR szRet[MAX_PATH] = {0};
- TString strSQL = _T("");
- TString strDateTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S"));
- strSQL = _T("domain = '");
- strSQL.append(strBranchId);
- strSQL.append(_T("' and name = '"));
- strSQL.append(strEdit1);
- strSQL.append(_T("' and phone = '"));
- strSQL.append(strEdit2);
- strSQL.append(_T("'"));
- #ifdef USE_ODBC_DLL
- if ( FALSE == g_podbc->GetSelectby(_T("softclient"), _T("ret"), strSQL.c_str(), szRet, MAX_PATH) )
- #else
- if ( FALSE == CODBCPool::GetInstance()->GetSelectby(_T("softclient"), _T("ret"), strSQL.c_str(), szRet, MAX_PATH) )
- #endif
- {
- return FALSE;
- }
- strSQL = _T("delete from softclient where domain = '");
- strSQL.append(strBranchId);
- strSQL.append(_T("' and name = '"));
- strSQL.append(strEdit1);
- strSQL.append(_T("' and phone = '"));
- strSQL.append(strEdit2);
- strSQL.append(_T("'"));
- #ifdef USE_ODBC_DLL
- g_podbc->ExecuteSQL(strSQL.c_str());
- #else
- CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str());
- #endif
- // 获取客户端ip地址;
- strContent = lpIPAddress;
- nIndex = strContent.find(_T(":"));
- if ( nIndex == TString::npos )
- {
- printf("\t\t work 16 无IP地址\n");
- return FALSE;
- }
- strContent = strContent.substr(0,nIndex -1);
- strSQL = _T("insert into [softclient]([domain],[name],[phone],[addr],[admin],[version],[cot],[ip],[datetime],[ret]) values ('");
- strSQL.append(strBranchId);
- strSQL.append(_T("','"));
- strSQL.append(strEdit1);
- strSQL.append(_T("','"));
- strSQL.append(strEdit2);
- strSQL.append(_T("','"));
- strSQL.append(strEdit3);
- strSQL.append(_T("','"));
- strSQL.append(strEdit4);
- strSQL.append(_T("','"));
- strSQL.append(strEdit5);
- strSQL.append(_T("','"));
- strSQL.append(strOrderNum);
- strSQL.append(_T("','"));
- strSQL.append(strContent);
- strSQL.append(_T("','"));
- strSQL.append(strDateTime);
- strSQL.append(_T("','"));
- strSQL.append(szRet);
- strSQL.append(_T("')"));
- #ifdef USE_ODBC_DLL
- g_podbc->ExecuteSQL(strSQL.c_str());
- #else
- CODBCPool::GetInstance()->ExecuteSQL(strSQL.c_str());
- #endif
- strContent = szRet;
- return TRUE;
- }
- /************************************************************************/
- /* 函数:[8/29/2016 IT];
- /* 描述:接收YLGL.exe客户端发回的信息;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- BOOL CClientProcess::Work_No17(IN LPCTSTR lpIPAddress, IN BYTE* pData, IN const DWORD& dwLen, OUT BYTE** pSendData, OUT DWORD& dwSendSize)
- {
- printf(" \t\t ------防盗信息------ \n");
- if ( lpIPAddress == NULL || lpIPAddress[0] == _T('\0') || pData == NULL || dwLen == 0 )
- return FALSE;
- CMemFile mf;
- mf.Attach(pData, dwLen);
- CArchive ar(&mf, CArchive::load);
- CGuardInfo GuardInfo;
- try
- {
- GuardInfo.Serialize(ar);
- ar.Close();
- mf.Detach();
- mf.Close();
- }
- catch (CException* e)
- {
- e->Delete();
- return FALSE;
- }
-
- INT nCount = -1;
- TString strSQL;
- strSQL = _T("domain = '");
- strSQL.append(GuardInfo.m_StudioDomain);
- strSQL.append(_T("' and name = '"));
- strSQL.append(GuardInfo.m_StudioName);
- strSQL.append(_T("' and phone = '"));
- strSQL.append(GuardInfo.m_StudioTel);
- strSQL.append(_T("'"));
- #ifdef USE_ODBC_DLL
- nCount = g_podbc->GetTblRecordCount(_T("softclient"), strSQL.c_str());
- #else
- nCount = CODBCPool::GetTblRecordCount()->GetSelectby(_T("softclient"), strSQL.c_str());
- #endif
- if ( nCount == -1 )
- {// 数据库错误 ;
- return FALSE;
- }
- #if 0
- // 从数据库中读取命令;
- CGuardCommand tagGuardCommand;
- tagGuardCommand.m_byTrigger = GTE_NextTimeTrigger;
- tagGuardCommand.m_nClientCount = 1000;
- tagGuardCommand.m_nExecCommand = GEC_EncryptA0 | GEC_EncryptB0;
- tagGuardCommand.m_nHistoryOrderCount = 2000;
- tagGuardCommand.m_nOrderCount = 3000;
- tagGuardCommand.m_strNewFieldName = _T("dindanbukuans");
- tagGuardCommand.m_strNewTableName = _T("ids");
- tagGuardCommand.m_strOldFieldName = _T("dindanbukuan");
- tagGuardCommand.m_strOldTableName = _T("id");
- tagGuardCommand.m_strExecTime = CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S "));
- CMemFile mf2;
- CArchive ar2(&mf2, CArchive::store);
- tagGuardCommand.Serialize(ar2);
- ar2.Close();
- dwSendSize = mf2.GetLength();
- *pSendData = mf2.Detach();
- mf2.Close();
- if ( nCount == 0 )
- {
- CString strfilter = _T("");
- strfilter.Format(_T(" StudioMac = '%s' and StudioGuid = '%s' "), GuardInfo.m_StudioMac, GuardInfo.m_StudioGuid);
- g_podbc->InsertGuardcmd(strfilter, *pSendData, dwSendSize, 0);
- }
- else
- {
- dwSendSize = 4096;
- g_podbc->GetGuardCommand(GuardInfo.m_StudioMac, GuardInfo.m_StudioGuid, *pSendData, dwSendSize);
- }
- #else
- if ( nCount == 0)
- {// 没有找到该影楼的注册信息,疑为盗版用户;
- strSQL = _T("StudioMac = '");
- strSQL.append(GuardInfo.m_StudioMac);
- strSQL.append(_T("' and StudioGuid = '"));
- strSQL.append(GuardInfo.m_StudioGuid);
- strSQL.append(_T("'"));
- #ifdef USE_ODBC_DLL
- nCount = g_podbc->GetTblRecordCount(_T("ListOfTheftName"), strSQL.c_str());
- #else
- nCount = CODBCPool::GetTblRecordCount()->GetSelectby(_T("softclient"), strSQL.c_str());
- #endif
- TCHAR szSQL[MAX_PATH*3] = {0};
- if ( nCount == 0 )
- {// 未记录过该盗版用户信息,插入记录;
- _stprintf_s(szSQL, _T("insert into ListOfTheftName(StudioMac, StudioGuid, IsYtUSB, StudioName, StudioTel, StudioAddress, StudioOwner, StudioInfo, StudioVer, Uptodate) values ('%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s')"),
- GuardInfo.m_StudioMac, GuardInfo.m_StudioGuid, GuardInfo.m_bUseYtUsb, GuardInfo.m_StudioName, GuardInfo.m_StudioTel, GuardInfo.m_StudioAddress, GuardInfo.m_StudioOwner, GuardInfo.m_StudioInfo, GuardInfo.m_StudioVer, GuardInfo.m_Uptodate);
- g_podbc->ExecuteSQL(szSQL);
- }
- else
- {// 更新该盗版用户信息;
- _stprintf_s(szSQL, _T("update ListOfTheftName set StudioName = '%s', StudioTel = '%s', StudioAddress = '%s', StudioOwner = '%s', StudioInfo = '%s', StudioVer = '%s', Uptodate = '%s', ExecResult = '%s' where StudioMac = '%s' and StudioGuid = '%s'"),
- GuardInfo.m_StudioName, GuardInfo.m_StudioTel, GuardInfo.m_StudioAddress, GuardInfo.m_StudioOwner, GuardInfo.m_StudioInfo, GuardInfo.m_StudioVer, GuardInfo.m_Uptodate, GuardInfo.m_ExecResult, GuardInfo.m_StudioMac, GuardInfo.m_StudioGuid);
- g_podbc->ExecuteSQL(szSQL);
- // 获取防盗命令行;
- dwSendSize = 4128;
- *pSendData = new BYTE[4128];
- memset(*pSendData, 0, 4128);
- DWORD dwReturn = dwSendSize;
- g_podbc->GetGuardCommand(GuardInfo.m_StudioMac, GuardInfo.m_StudioGuid, *pSendData + 32, dwReturn);
- dwSendSize = dwReturn + 32;
- CMD5 md5(*pSendData+32, dwReturn);
- memcpy(*pSendData, md5.GetMD5Digest(), 32);
- OutputDebugString(md5.GetMD5Digest());
- OutputDebugString(_T("\n"));
- }
- }
- #endif
-
- return TRUE;
- }
- /************************************************************************/
- /* 函数:[8/29/2016 IT];
- /* 描述:接收YLGL.exe客户端发回的信息;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- INT CClientProcess::Work_No18(IN LPCTSTR lpIPAddress, IN TString& strContent)
- {
- if ( lpIPAddress == NULL || lpIPAddress[0] == _T('\0') )
- {
- return -1;
- }
- #ifdef _DEBUG
- Global::WriteTextLog(strContent.c_str());
- #endif
- // 1.解析出数据;
- STAntiTheft AntitheftInfo;
- cJSON *pJson = cJSON_Parse(strContent.c_str());
- char *pDetail = cJSON_Print(cJSON_GetObjectItem(pJson, "Detail"));
- AntitheftInfo.strDetail = pDetail;
- delete []pDetail;
- AntitheftInfo.strStudioVer = cJSON_GetObjectItem(pJson, "软件版本")->valuestring;
- AntitheftInfo.strStudioName = cJSON_GetObjectItem(pJson, "影楼名称")->valuestring;
- AntitheftInfo.strStudioPhone = cJSON_GetObjectItem(pJson, "影楼电话")->valuestring;
- AntitheftInfo.strStudioAddress = cJSON_GetObjectItem(pJson, "影楼地址")->valuestring;
- AntitheftInfo.strStudioWebSite = cJSON_GetObjectItem(pJson, "影楼网址")->valuestring;
- AntitheftInfo.strStudioManager = cJSON_GetObjectItem(pJson, "影楼老板")->valuestring;
- AntitheftInfo.strStudioDomain = cJSON_GetObjectItem(pJson, "影楼域名")->valuestring;
- AntitheftInfo.dwStudioOrderCount = cJSON_GetObjectItem(pJson, "订单数量")->valueint;
- AntitheftInfo.dwStudioHistoryOrderCount = cJSON_GetObjectItem(pJson, "历史订单数量")->valueint;
-
- INT nSize = 0;
- INT nStudioAutoID = -1;
- cJSON *pItem = NULL;
- CString strSQL = _T("");
- BOOL bMacExist = FALSE;
- CArray<CStringArray, CStringArray> AryStudioInfo;
- // 获取网卡;
- CString strFirstPICMac = _T("");
- CString strPICMac = _T("");
- CString strUSBMac = _T("");
- CString strHardWare = _T("");
- cJSON *pSubJson = cJSON_GetObjectItem(pJson, "MAC");
- if ( pSubJson )
- {
- nSize = cJSON_GetArraySize(pSubJson);
- for ( int i = 0; i < nSize; i++ )
- {
- pItem = cJSON_GetArrayItem(pSubJson, i);
- if ( pItem )
- {
- MacAddress tagMac;
- _stprintf_s(tagMac.szNICKind, _T("%s"), cJSON_GetObjectItem(pItem, "kind")->valuestring);
- _stprintf_s(tagMac.szMacAddress, _T("%s"), cJSON_GetObjectItem(pItem, "Address")->valuestring);
- if ( strFirstPICMac.IsEmpty() && _tcscmp(tagMac.szNICKind, _T("NIC_PCI")) == 0 )
- {
- // 第一个pic网卡mac;
- strFirstPICMac = tagMac.szMacAddress;
- }
- if ( _tcscmp(tagMac.szNICKind, _T("NIC_PCI")) == 0 )
- {
- strPICMac += tagMac.szMacAddress;
- strPICMac += _T(";");
- }
- if ( _tcscmp(tagMac.szNICKind, _T("NIC_USB")) == 0 )
- {
- strUSBMac += tagMac.szMacAddress;
- strUSBMac += _T(";");
- }
- if ( !bMacExist )
- {
- if ( _tcscmp(tagMac.szNICKind, _T("NIC_PCI")) == 0)
- strSQL.Format(_T(" StudioMac = '%s' or StudioPICMAC like '%%%s%%' "), tagMac.szMacAddress, tagMac.szMacAddress);
- else if ( _tcscmp(tagMac.szNICKind, _T("NIC_USB")) == 0 )
- strSQL.Format(_T(" StudioUSBMAC like '%%%s%%'"), tagMac.szMacAddress);
-
- AryStudioInfo.RemoveAll();
- if ( g_podbc->GetStudioInfo(strSQL, AryStudioInfo, 1000) != 0 )
- {
- INT nResultSize = AryStudioInfo.GetSize();
- if ( nResultSize == 1)
- {
- // 只有一个时,才更新;// 有二个以上,插入这条记录;
- bMacExist = TRUE;
- nStudioAutoID = _tstoi(AryStudioInfo.ElementAt(0).ElementAt(0));
- }
- }
- }
- AntitheftInfo.vtMacAddress.push_back(tagMac);
- }
- }
- }
- // 获取硬盘序列号;
- pSubJson = cJSON_GetObjectItem(pJson, "HD");
- if ( pSubJson )
- {
- nSize = cJSON_GetArraySize(pSubJson);
- for ( int i = 0; i < nSize; i++ )
- {
- pItem = cJSON_GetArrayItem(pSubJson, i);
- if ( pItem )
- {
- AntitheftInfo.vtHardDiskID.push_back(cJSON_GetObjectItem(pItem, "SerialNum")->valuestring);
- strHardWare += cJSON_GetObjectItem(pItem, "SerialNum")->valuestring;
- strHardWare += _T(";");
- }
- }
- }
- // 释放JSON;
- cJSON_Delete(pJson);
- pJson = NULL;
- // 更新或插入数据;
- if ( bMacExist )
- {// 更新数据;
- CString strAntiTheftCommand;
- strAntiTheftCommand = CBase64::Base64ToStringA(AryStudioInfo.ElementAt(0).ElementAt(12));
- if ( strAntiTheftCommand.IsEmpty() )
- {// 只更新;
- strSQL.Format(
- _T("UPDATE [StudioInfo] SET")
- _T("[StudioMac] = '%s'")
- _T(",[StudioVersion] = '%s'")
- _T(",[StudioName] = '%s'")
- _T(",[StudioPhone] = '%s'")
- _T(",[StudioAddress] = '%s'")
- _T(",[StudioWebSite] = '%s'")
- _T(",[StudioOwner] = '%s'")
- _T(",[StudioDomain] = '%s'")
- _T(",[StudioOrderInfo] = '%d/%d'")
- _T(",[RefreshDate] = '%s'")
- _T(",[StudioConnectIP] = '%s'")
- _T(",[AntiTheftCommand] = '%s'")
- _T(",[StudioPICMAC] = '%s'")
- _T(",[StudioUSBMAC] = '%s'")
- _T(",[StudioHardDisk] = '%s'")
- _T("WHERE StudioAutoID = %d"),
- strFirstPICMac,
- AntitheftInfo.strStudioVer,
- AntitheftInfo.strStudioName,
- AntitheftInfo.strStudioPhone,
- AntitheftInfo.strStudioAddress,
- AntitheftInfo.strStudioWebSite,
- AntitheftInfo.strStudioManager,
- AntitheftInfo.strStudioDomain,
- AntitheftInfo.dwStudioOrderCount,
- AntitheftInfo.dwStudioHistoryOrderCount,
- CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")),
- lpIPAddress,
- CBase64::StringToBase64A(AntitheftInfo.strDetail),
- strPICMac,
- strUSBMac,
- strHardWare,
- nStudioAutoID
- );
- #ifdef _DEBUG
- Global::WriteTextLog(_T("更新数据"));
- #endif
- }
- else
- {
- if ( !strAntiTheftCommand.IsEmpty() )
- {
- pJson = cJSON_Parse(strAntiTheftCommand);
- if ( pJson )
- {
- CString strCmdGuid = cJSON_GetObjectItem(pJson, "cmd-guid") ? cJSON_GetObjectItem(pJson, "cmd-guid")->valuestring : "";
- if ( !strCmdGuid.IsEmpty() )
- {
- // 解析出接收的cmd-guid值;
- cJSON *pDetail = cJSON_Parse(AntitheftInfo.strDetail);
- if ( pDetail )
- {
- CString strCmdGuid2 = cJSON_GetObjectItem(pDetail, "cmd-guid") ? cJSON_GetObjectItem(pDetail, "cmd-guid")->valuestring : "";
- if ( strCmdGuid2.IsEmpty() )
- {
- // 影楼没有接收过命令,则将当前数据库记录的命令发送给影楼;
- strContent = strAntiTheftCommand.GetString();
- // 并更新其他信息;
- strSQL.Format(
- _T("UPDATE [StudioInfo] SET")
- _T("[StudioMac] = '%s'")
- _T(",[StudioVersion] = '%s'")
- _T(",[StudioName] = '%s'")
- _T(",[StudioPhone] = '%s'")
- _T(",[StudioAddress] = '%s'")
- _T(",[StudioWebSite] = '%s'")
- _T(",[StudioOwner] = '%s'")
- _T(",[StudioDomain] = '%s'")
- _T(",[StudioOrderInfo] = '%d/%d'")
- _T(",[RefreshDate] = '%s'")
- _T(",[StudioConnectIP] = '%s'")
- /*_T(",[AntiTheftCommand] = '%s'")*/
- _T(",[StudioPICMAC] = '%s'")
- _T(",[StudioUSBMAC] = '%s'")
- _T(",[StudioHardDisk] = '%s'")
- _T("WHERE StudioAutoID = %d"),
- strFirstPICMac,
- AntitheftInfo.strStudioVer,
- AntitheftInfo.strStudioName,
- AntitheftInfo.strStudioPhone,
- AntitheftInfo.strStudioAddress,
- AntitheftInfo.strStudioWebSite,
- AntitheftInfo.strStudioManager,
- AntitheftInfo.strStudioDomain,
- AntitheftInfo.dwStudioOrderCount,
- AntitheftInfo.dwStudioHistoryOrderCount,
- CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")),
- lpIPAddress,
- /*AntitheftInfo.strDetail,*/
- strPICMac,
- strUSBMac,
- strHardWare,
- nStudioAutoID
- );
- }
- else
- {
- if ( strCmdGuid2.CompareNoCase(strCmdGuid) == 0 )
- {
- strSQL.Format(
- _T("UPDATE [StudioInfo] SET")
- _T("[StudioMac] = '%s'")
- _T(",[StudioVersion] = '%s'")
- _T(",[StudioName] = '%s'")
- _T(",[StudioPhone] = '%s'")
- _T(",[StudioAddress] = '%s'")
- _T(",[StudioWebSite] = '%s'")
- _T(",[StudioOwner] = '%s'")
- _T(",[StudioDomain] = '%s'")
- _T(",[StudioOrderInfo] = '%d/%d'")
- _T(",[RefreshDate] = '%s'")
- _T(",[StudioConnectIP] = '%s'")
- _T(",[AntiTheftCommand] = '%s'")
- _T(",[StudioPICMAC] = '%s'")
- _T(",[StudioUSBMAC] = '%s'")
- _T(",[StudioHardDisk] = '%s'")
- _T("WHERE StudioAutoID = %d"),
- strFirstPICMac,
- AntitheftInfo.strStudioVer,
- AntitheftInfo.strStudioName,
- AntitheftInfo.strStudioPhone,
- AntitheftInfo.strStudioAddress,
- AntitheftInfo.strStudioWebSite,
- AntitheftInfo.strStudioManager,
- AntitheftInfo.strStudioDomain,
- AntitheftInfo.dwStudioOrderCount,
- AntitheftInfo.dwStudioHistoryOrderCount,
- CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")),
- lpIPAddress,
- CBase64::StringToBase64A(AntitheftInfo.strDetail),
- strPICMac,
- strUSBMac,
- strHardWare,
- nStudioAutoID
- );
- }
- else
- {// guid值不一致,可能不是同一个用户,建议插入新记录;
- strSQL.Format(
- _T("INSERT INTO [StudioInfo]")
- _T("([StudioMac]")
- _T(",[StudioVersion]")
- _T(",[StudioName]")
- _T(",[StudioPhone]")
- _T(",[StudioAddress]")
- _T(",[StudioWebSite]")
- _T(",[StudioOwner]")
- _T(",[StudioDomain]")
- _T(",[StudioOrderInfo]")
- _T(",[RefreshDate]")
- _T(",[StudioConnectIP]")
- _T(",[AntiTheftCommand]")
- _T(",[StudioPICMAC]")
- _T(",[StudioUSBMAC]")
- _T(",[StudioHardDisk])")
- _T("VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%d/%d','%s','%s','%s','%s','%s','%s')"),
- strFirstPICMac,
- AntitheftInfo.strStudioVer,
- AntitheftInfo.strStudioName,
- AntitheftInfo.strStudioPhone,
- AntitheftInfo.strStudioAddress,
- AntitheftInfo.strStudioWebSite,
- AntitheftInfo.strStudioManager,
- AntitheftInfo.strStudioDomain,
- AntitheftInfo.dwStudioOrderCount,
- AntitheftInfo.dwStudioHistoryOrderCount,
- CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")),
- lpIPAddress,
- CBase64::StringToBase64A(AntitheftInfo.strDetail),
- strPICMac,
- strUSBMac,
- strHardWare
- );
- // 新增数据,自增列设置为0;
- nStudioAutoID = 0;
- }
- }
- }
- else
- {// 影楼没有接收过命令,则将当前数据库记录的命令发送给影楼;
- strContent = strAntiTheftCommand.GetString();
- // 并更新其他信息;
- strSQL.Format(
- _T("UPDATE [StudioInfo] SET")
- _T("[StudioMac] = '%s'")
- _T(",[StudioVersion] = '%s'")
- _T(",[StudioName] = '%s'")
- _T(",[StudioPhone] = '%s'")
- _T(",[StudioAddress] = '%s'")
- _T(",[StudioWebSite] = '%s'")
- _T(",[StudioOwner] = '%s'")
- _T(",[StudioDomain] = '%s'")
- _T(",[StudioOrderInfo] = '%d/%d'")
- _T(",[RefreshDate] = '%s'")
- _T(",[StudioConnectIP] = '%s'")
- /*_T(",[AntiTheftCommand] = '%s'")*/
- _T(",[StudioPICMAC] = '%s'")
- _T(",[StudioUSBMAC] = '%s'")
- _T(",[StudioHardDisk] = '%s'")
- _T("WHERE StudioAutoID = %d"),
- strFirstPICMac,
- AntitheftInfo.strStudioVer,
- AntitheftInfo.strStudioName,
- AntitheftInfo.strStudioPhone,
- AntitheftInfo.strStudioAddress,
- AntitheftInfo.strStudioWebSite,
- AntitheftInfo.strStudioManager,
- AntitheftInfo.strStudioDomain,
- AntitheftInfo.dwStudioOrderCount,
- AntitheftInfo.dwStudioHistoryOrderCount,
- CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")),
- lpIPAddress,
- /*AntitheftInfo.strDetail,*/
- strPICMac,
- strUSBMac,
- strHardWare,
- nStudioAutoID
- );
- }
- }
- }
- }
- else
- {
- strContent = "";
- }
- }
- }
- else
- {// 插入数据;
- strSQL.Format(
- _T("INSERT INTO [StudioInfo]")
- _T("([StudioMac]")
- _T(",[StudioVersion]")
- _T(",[StudioName]")
- _T(",[StudioPhone]")
- _T(",[StudioAddress]")
- _T(",[StudioWebSite]")
- _T(",[StudioOwner]")
- _T(",[StudioDomain]")
- _T(",[StudioOrderInfo]")
- _T(",[RefreshDate]")
- _T(",[StudioConnectIP]")
- _T(",[AntiTheftCommand]")
- _T(",[StudioPICMAC]")
- _T(",[StudioUSBMAC]")
- _T(",[StudioHardDisk])")
- _T("VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%d/%d','%s','%s','%s','%s','%s','%s')"),
- strFirstPICMac,
- AntitheftInfo.strStudioVer,
- AntitheftInfo.strStudioName,
- AntitheftInfo.strStudioPhone,
- AntitheftInfo.strStudioAddress,
- AntitheftInfo.strStudioWebSite,
- AntitheftInfo.strStudioManager,
- AntitheftInfo.strStudioDomain,
- AntitheftInfo.dwStudioOrderCount,
- AntitheftInfo.dwStudioHistoryOrderCount,
- CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S")),
- lpIPAddress,
- CBase64::StringToBase64A(AntitheftInfo.strDetail),
- strPICMac,
- strUSBMac,
- strHardWare
- );
- // 新增数据,自增列设置为0;
- nStudioAutoID = 0;
- }
-
- g_podbc->ExecuteSQL(strSQL);
- // 2.从数据库查询是否有命令行要发回;
- // 暂无;
- #if 0
- // 模拟测试;
- pJson = cJSON_CreateObject();
- cJSON_AddStringToObject(pJson, "cmd-guid", _T("98149909-0841-4709-85BF-1028E92916DA"));
- // SQL语句操作;
- cJSON_AddBoolToObject(pJson, "SQL-Opt", TRUE);
- // 文件操作;
- cJSON_AddBoolToObject(pJson, "Data-Opt", TRUE);
- // 加密狗操作-只有一个操作:true就授权过期;
- cJSON_AddBoolToObject(pJson, "Dog-Opt", TRUE);
- //////////////////////////////////////////////////////////////////////////
- // SQL语句操作;
- cJSON *pSQLArry = cJSON_CreateArray();
- cJSON_AddItemToObject(pJson, "SQL-Ary",pSQLArry);
- pItem = NULL;
- // 1.重命名表;
- pItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pItem, "Statement", "EXEC sp_rename 'dindansp3', 'dindansp3_back'");
- cJSON_AddStringToObject(pItem, "ExecTime", "CC:CC");
- cJSON_AddBoolToObject(pItem, "ExecStatus", false); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pItem);
- pItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pItem, "Statement", "EXEC sp_rename 'dindansp2', 'dindansp2_back'");
- cJSON_AddStringToObject(pItem, "ExecTime", "CC:CC");
- cJSON_AddBoolToObject(pItem, "ExecStatus", false); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pItem);
- pItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pItem, "Statement", "EXEC sp_rename 'client3', 'client3'");
- cJSON_AddStringToObject(pItem, "ExecTime", "CC:CC");
- cJSON_AddBoolToObject(pItem, "ExecStatus", false); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pItem);
- // 2.重命字段;
- pItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pItem, "Statement", "EXEC sp_rename 'dindan.[id]', 'id', 'column'");
- cJSON_AddStringToObject(pItem, "ExecTime", "CC:CC");
- cJSON_AddBoolToObject(pItem, "ExecStatus", false); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pItem);
- pItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pItem, "Statement", "EXEC sp_rename 'dindan.[name1]', 'name1', 'column'");
- cJSON_AddStringToObject(pItem, "ExecTime", "CC:CC");
- cJSON_AddBoolToObject(pItem, "ExecStatus", false); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pItem);
- //////////////////////////////////////////////////////////////////////////
- // 文件操作;
- pSQLArry = cJSON_CreateArray();
- cJSON_AddItemToObject(pJson, "Data-Ary",pSQLArry);
- pItem = cJSON_CreateObject();
- cJSON_AddNumberToObject(pItem, "Type", 1);// 未选, 未取;
- cJSON_AddStringToObject(pItem, "ExecTime", "NN:NN");
- cJSON_AddNumberToObject(pItem, "Count", 10);
- cJSON_AddBoolToObject(pItem, "ExecStatus", false); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pItem);
- char *out = cJSON_Print(pJson);
- cJSON_Delete(pJson);
- strContent = out;
- if (out)delete []out;
- #endif
- return nStudioAutoID;
- }
|