12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319 |
- /********************************************************************/
- /* */
- /* CONNECTSOCKET.CPP */
- /* */
- /* Implementation of the Connect Socket. */
- /* This class is a part of the CConnectThread which handles */
- /* socket connections. Incomming data is processed in OnReceive */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Based partially on and inspired by FileZilla Server. */
- /* */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 15 july 2002 */
- /* */
- /********************************************************************/
- //在ConnectSocket.cpp文件中实现连接套接字的创建,该类是CConnectThread类的
- //一部分,收到数据由函数OnReceive()完成处理。
- #include "stdafx.h"
- #include "LYFZIPReceiveApp.h"
- #include "LYFZIPReceive.h"
- #include "ConnectSocket.h"
- #include "ConnectThread.h"
- #include "ApplicationDlg.h"
- #include "DataSocket.h"
- #include "mysqldata.h"
- #include "./include/netMain.h"
- #include "./include/protocolhdr.h"
- #include "./include/struct_def.h"
- #include "MyLock.h"
- #include "my32.h"
- #include "SoftKey.h"
- extern CLYFZIPReceive theServer;
- extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword);
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CLYFZIPReceive *g_pWndServer;
- CString GetAuthCode(CString requestcode, long newsecond)
- {
- if(0==g_bDogOK)return "";
- 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=atoi(year);
- m_month=atoi(month);
- m_day=atoi(day);
- m_hour=atoi(hour);
- m_minute=atoi(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 "";
- }
-
-
- requestcode.TrimLeft ();
- requestcode.TrimRight ();
- requestcode.Replace ("\n", "");
- requestcode.Replace ("\r", "");
- if(requestcode.IsEmpty ())
- {
- return "";
- }
- CString str,temp,temp2;
- long id,time1,time2,idtemp;
- int leng;
- str=requestcode;
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- id=atoi(temp2);
- if(temp.Right (1)=="1")id=-id;
- //////////////////////////////////////////////////
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- time1=atoi(temp2);
- if(temp.Right (1)=="1")time1=-time1;
- //////////////////////////////////////////////////
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- time2=atoi(temp2);
- if(temp.Right (1)=="1")time2=-time2;
- //////////////////////////////////////////////////////
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- idtemp=atoi(temp2);
- if(temp.Right (1)=="1")idtemp=-idtemp;
- //////////////////////////////////////////////////////
- // SoftKey ytSoftKey;
- int ret=0;//ytSoftKey.Ini();
- if (ret!=0 )
- {
- return "";
- }
- long d[8];double f[8];
- char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
- //运行自定义函数
- ret=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)
- {
- 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[50];
- sprintf(year, "%d", m_year);
- sprintf(month, "%d", m_month);
- sprintf(day, "%d", m_day);
- sprintf(hour, "%d", m_hour);
- sprintf(minute, "%d", m_minute);
- MakeTimerAuth("20D30D15FFB7F6AF9EAB30FD229F797B", id, year, month, day,
- hour, minute, OutString,DevicePath);
- CString authcode=OutString;
-
- str.Format ("%04d", m_year);
- authcode+=str;
- str.Format ("%02d", m_month);
- authcode+=str;
- str.Format ("%02d", m_day);
- authcode+=str;
- str.Format ("%02d", m_hour);
- authcode+=str;
- str.Format ("%02d", m_minute);
- authcode+=str;
- str.Format ("%08d", id);
- authcode+=str;
-
- CString 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);
-
- sprintf(s0, "%s", str1);
- sprintf(s1, "%s", str2);
- sprintf(s2, "%s", str3);
- sprintf(s3, "%s", str4);
- sprintf(s4, "%s", str5);
- //运行自定义函数
-
- {
- SoftKey ytSoftKey2;
- ret=ytSoftKey2.Ini();
- if (ret!=0 )
- {
- return "";
- }
- {
- long d[8];double f[8];
- char s5[50]="",s6[50]="",s7[50]="";
- ret=ytSoftKey2.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)
- {
- return "";
- }
- str1=s0;
- str2=s1;
- str3=s2;
- str4=s3;
- str5=s4;
- }
-
- authcode=str1;
- authcode+=str2;
- authcode+=str3;
- authcode+=str4;
- authcode+=str5;
- return authcode;
- }
- catch(...)
- {
- }
- }
- CString GetUseDays(CString requestcode)
- {
- if(0==g_bDogOK)return "";
- try
- {
- CString sRet;
- requestcode.TrimLeft ();
- requestcode.TrimRight ();
- requestcode.Replace ("\n", "");
- requestcode.Replace ("\r", "");
- if(requestcode.IsEmpty ())
- {
- return "";
- }
- CString str,temp,temp2;
- long id,time1,time2,idtemp;
- int leng;
- str=requestcode;
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- id=atoi(temp2);
- if(temp.Right (1)=="1")id=-id;
- //////////////////////////////////////////////////
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- time1=atoi(temp2);
- if(temp.Right (1)=="1")time1=-time1;
- //////////////////////////////////////////////////
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- time2=atoi(temp2);
- if(temp.Right (1)=="1")time2=-time2;
- //////////////////////////////////////////////////////
- temp=str.Left (3);
- str=str.Right (str.GetLength ()-3);
- leng=atoi(temp.Left (2));
- temp2=str.Left (leng);
- str=str.Right (str.GetLength ()-leng);
- idtemp=atoi(temp2);
- if(temp.Right (1)=="1")idtemp=-idtemp;
- //////////////////////////////////////////////////////
- // SoftKey ytSoftKey;
- int ret=0;//ytSoftKey.Ini();
- if (ret!=0 )
- {
- return "";
- }
- long d[8];double f[8];
- char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
- //运行自定义函数
-
- ret=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)
- {
- 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);
-
- temp.Format("已运行:%d年%d月%d日 ", atoi(year), atoi(month), atoi(day));
- sRet+=temp;
- if(time1>0)
- ConvertTimerToStringReal(time1, year, month, day, hour, minute, second);
- else
- {
- sprintf(year, "%s", "0");
- sprintf(month, "%s", "0");
- sprintf(day, "%s", "0");
- sprintf(hour, "%s", "0");
- sprintf(minute, "%s", "0");
- }
- temp.Format("能运行:%d年%d月%d日---%d", atoi(year), atoi(month), atoi(day), time2);
- sRet+=temp;
- return sRet;
- }
- catch(...)
- {
- }
- return "";
- }
-
- BOOL MyExecuteSQL(CDatabase *pdb, CString sql)
- {
- MyLock lock("xiaoaccessdbmsg");
- try
- {
- pdb->ExecuteSQL (sql);
- }
- catch(...)
- {
- return 0;
- }
- return 1;
- }
-
- extern void WriteLogin(CString str);
-
-
- void WriteLog(CString account, CString str)
- {
- }
- /********************************************************************/
- /* */
- /* Function name : CConnectSocket::CConnectSocket */
- /* Description : Constructor */
- /* */
- /********************************************************************/
- CConnectSocket::CConnectSocket()
- {
- m_bLoggedon = FALSE;
- m_bRenameFile = FALSE;
- m_pDataSocket = NULL;
- m_strRemoteHost = "";
- m_nRemotePort = -1;
- m_dwRestartOffset = 0;
- m_bPassiveMode = FALSE;
- m_reved=0;
- m_dateleng=0;
- m_pRevBuf=NULL;
- }
- /********************************************************************/
- /* */
- /* Function name : CConnectSocket::~CConnectSocket */
- /* Description : Destructor */
- /* */
- /********************************************************************/
- CConnectSocket::~CConnectSocket()
- {
- if(m_pRevBuf)delete []m_pRevBuf;
- }
- // Do not edit the following lines, which are needed by ClassWizard.
- #if 0
- BEGIN_MESSAGE_MAP(CConnectSocket, CSocket)
- //{{AFX_MSG_MAP(CConnectSocket)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- #endif // 0
- /********************************************************************/
- /* */
- /* Function name : OnClose */
- /* Description : Send WM_QUIT message to the thread containing */
- /* the socket to shutdown once the connection is */
- /* closed. */
- /* */
- /********************************************************************/
- void CConnectSocket::OnClose(int nErrorCode)
- {
- try
- {
- Close();
- // destroy connection
- AfxGetThread()->PostThreadMessage(WM_THREADMSG, 1, 0);
- TRACE("CConnectSocket() OnClose()\n");
- CSocket::OnClose(nErrorCode);
- }
- catch(...)
- {
- }
- }
- #define BUFFERSIZE 4096
- /********************************************************************/
- /* */
- /* Function name : OnReceive */
- /* Description : Called by the framework to notify this socket */
- /* that there is data in the buffer. */
- /* */
- /********************************************************************/
- //由主窗口调用通知套接字缓冲区中有数据要接收
- void CConnectSocket::OnReceive(int nErrorCode)
- {
- TCHAR buff[BUFFERSIZE];
- //接收数据并放到缓冲区
- int nRead = Receive(buff, BUFFERSIZE);
- switch (nRead)
- {
- case 0:
- Close();
- break;
- case SOCKET_ERROR:
- if (GetLastError() != WSAEWOULDBLOCK)
- {
- TCHAR szError[256];
- wsprintf(szError, "OnReceive error: %d", GetLastError());
-
- // AfxMessageBox (szError);
- }
- break;
- default:
- if (nRead != SOCKET_ERROR && nRead != 0)
- {
- ((CConnectThread *)AfxGetThread())->IncReceivedBytes(nRead);
- TMessageHeader *pMessageHeader = (TMessageHeader *)buff;
- 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;
- net_Send(&tHeader, (void *)&tLoginResult, dwDataLen);
- }
- else //if(pMessageHeader->wMessageId ==MSG_CHATMESSAGE_REQ)
- {
- /* char *pDataBuf = (char *)buff + MESSAGE_HEADER_LEN;
- TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
- DWORD dwConnectionID = pChatMessage->tCommonMsg.dwConnectionID;
- processChatMessageRequest((void *)pChatMessage);*/
- // 结束字符串
- if(pMessageHeader->wHeaderFlag==MESSAGE_HEADER_FLAG )
- {
- if(m_pRevBuf)delete []m_pRevBuf;m_pRevBuf=NULL;m_reved=0;
- m_dateleng=pMessageHeader->dwDataLen+MESSAGE_HEADER_LEN;
- m_pRevBuf=new BYTE[m_dateleng];
- //WriteLogin("开始接收");
- }
- ::memcpy(m_pRevBuf+m_reved, buff, min(nRead, m_dateleng-m_reved));
-
- // CString ss;
- // ss.Format("%d/%d", min(nRead, m_dateleng-m_reved), m_dateleng);
- // WriteLogin("接收"+ss);
- m_reved+=min(nRead, m_dateleng-m_reved);
-
- if(m_reved>=m_dateleng)
- {
- // WriteLogin("接收完成");
- char *pDataBuf = (char *)m_pRevBuf + MESSAGE_HEADER_LEN;
- TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
-
- m_reved=0;m_dateleng=0;
- processChatMessageRequest((void *)pChatMessage);
- }
- }
- }
- break;
- }
- CSocket::OnReceive(nErrorCode);
- }
- /********************************************************************/
- /* */
- /* Function name: GetRxCommand */
- /* Description : Get command from receiver buffer. */
- /* */
- /********************************************************************/
- //从接收缓冲区获得命令
- BOOL CConnectSocket::GetRxCommand(CString &strCommand, CString &strArguments)
- {
- return FALSE;
- }
- /********************************************************************/
- /* */
- /* Function name: GetRxLine */
- /* Description : Parse complete command line */
- /* */
- /********************************************************************/
- //解析整个命令行
- void CConnectSocket::GetRxLine()
- {
- }
- /********************************************************************/
- /* */
- /* Function name: OnConnect */
- /* Description : Called by the framework to notify this connecting */
- /* socket that its connection attempt is completed. */
- /* */
- /********************************************************************/
- void CConnectSocket::OnConnect(int nErrorCode)
- {
- CSocket::OnConnect(nErrorCode);
- }
- /********************************************************************/
- /* */
- /* Function name: HasConnectionDropped */
- /* Description : Check if connection has been dropped. */
- /* Used to detect if client has crashed. */
- /* */
- /********************************************************************/
- BOOL CConnectSocket::HasConnectionDropped(void)
- {
- try
- {
- BOOL bConnDropped = FALSE;
- INT iRet = 0;
- BOOL bOK = TRUE;
-
- if (m_hSocket == INVALID_SOCKET)
- return TRUE;
- struct timeval timeout = { 0, 0 };
- fd_set readSocketSet;
-
- FD_ZERO(&readSocketSet);
- FD_SET(m_hSocket, &readSocketSet);
-
- iRet = ::select(0, &readSocketSet, NULL, NULL, &timeout);
- bOK = (iRet > 0);
-
- if(bOK)
- {
- bOK = FD_ISSET(m_hSocket, &readSocketSet);
- }
-
- if(bOK)
- {
- CHAR szBuffer[1] = "";
- iRet = ::recv(m_hSocket, szBuffer, 1, MSG_PEEK);
- bOK = (iRet > 0);
- if(!bOK)
- {
- INT iError = ::WSAGetLastError();
- bConnDropped = (( iError == WSAENETRESET) ||
- (iError == WSAECONNABORTED) ||
- (iError == WSAECONNRESET) ||
- (iError == WSAEINVAL) ||
- (iRet == 0));
- }
- }
- return(bConnDropped);
- }
- catch(...)
- {
- }
- return 1;
- }
- /********************************************************************/
- /* */
- /* Function name: SendResponse */
- /* Description : Send response to client. */
- /* */
- /********************************************************************/
- //发送响应给客户端
- BOOL CConnectSocket::SendResponse(LPCTSTR pstrFormat, ...)
- {
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name: ParseCommand */
- /* Description : Parse and execute command from client. */
- /* */
- /* Based on code provided by FileZilla Server. */
- /* http://sourceforge.net/projects/filezilla */
- /* */
- /********************************************************************/
- //从客户端解析并执行命令
- void CConnectSocket::ParseCommand()
- {
- }
- /********************************************************************/
- /* */
- /* Function name: FireStatusMessage */
- /* Description : Fire status message. */
- /* */
- /********************************************************************/
- void CConnectSocket::FireStatusMessage(LPCTSTR lpszStatus, int nType)
- {
- try
- {
- g_pWndServer->AddTraceLine(nType, "[%d] %s", AfxGetThread()->m_nThreadID, lpszStatus);
- }
- catch(...)
- {
- }
- }
- /********************************************************************/
- /* */
- /* Function name: CreateDataConnection */
- /* Description : Create data transfer connection. */
- /* */
- /********************************************************************/
- BOOL CConnectSocket::CreateDataConnection(int nTransferType, LPCTSTR lpszData)
- {
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name: DestroyDataConnection */
- /* Description : Close data transfer connection. */
- /* */
- /********************************************************************/
- void CConnectSocket::DestroyDataConnection()
- {
- }
- unsigned long CConnectSocket::net_Send(IN void *pHeader, IN void *pMessage, IN unsigned long ulDataLen)
- {
- try
- {
- unsigned long ulSendLen = 0;
- unsigned long ulBufLen = 0;
- TMessageHeader *pSendHeader = (TMessageHeader *)pHeader;
- ulBufLen = MESSAGE_HEADER_LEN + ulDataLen;
- char *pSendBuf = new char[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);
- //Send the message
-
- // ulSendLen = CTransportImpl::net_Send(hSocket, (void *)pSendBuf, ulBufLen);
-
- //判断连接是否在活动状态
- if (HasConnectionDropped())
- {
- FireStatusMessage("Could not send reply, disconnected.", 2);
- Close();
- // 通知线程已经停止,关闭连接
- AfxGetThread()->PostThreadMessage(WM_THREADMSG, 1, 0);
- return FALSE;
- }
- int nBytes = CSocket::Send((void *)pSendBuf, ulBufLen);
- if (nBytes == SOCKET_ERROR)
- {
- Close();
- FireStatusMessage("Could not send reply, disconnected.", 2);
- //通知线程连接已经关闭
- AfxGetThread()->PostThreadMessage(WM_THREADMSG, 1, 0);
- return FALSE;
- }
-
- ((CConnectThread *)AfxGetThread())->IncSentBytes(nBytes);
-
-
- delete [] pSendBuf;
- pSendBuf = NULL;
- return nBytes;
- }
- catch(...)
- {
- }
- return 0;
- }
- BOOL g_bWork=0;
- void CConnectSocket::processChatMessageRequest(void *pChatMsg)
- {
- CString str;
- DWORD dwToUserID=100;
- try
- {
- g_bWork=1;
- if( NULL == pChatMsg )
- {
- g_bWork=0;
- return;
- }
- TCHAT_MESSAGE_STRU *ptChatMessage = (TCHAT_MESSAGE_STRU *)pChatMsg;
- DWORD dwUserID = ptChatMessage->tCommonMsg.dwConnectionID;
- if(ptChatMessage->length[98]!=987123768)
- {
- WriteLogin("987123768");
- g_bWork=0;
- return;
- }
-
-
- int nMessageLen = ptChatMessage->wMessageLen;
- if( nMessageLen > 3 )
- {
- dwToUserID = ptChatMessage->dwToUserID;
- if(dwToUserID!=9)//企业版分店权限设置
- {
- char *szChatMessage;
- szChatMessage = new char[nMessageLen+1];
- memset(szChatMessage, 0x00, nMessageLen+1);
- memcpy(szChatMessage, ptChatMessage->byFileContent, nMessageLen);
- EncryptFile2((BYTE*)szChatMessage, nMessageLen, "888666333");
- str=szChatMessage;delete []szChatMessage;
- }
- else
- str.Empty ();
- BYTE *pBranchData=NULL;
- DWORD nBranchDataLeng=0;
- int nBranchArraySize=0;
- if(dwToUserID==0)
- {
- }
- else if(dwToUserID==1)//改密码
- {
- }
- else if(dwToUserID==2)//查询使用
- {
- }
- else if(dwToUserID==3)//查询余额
- {
- }
- else if(dwToUserID==4)//查发送记录
- {
- }
- else if(dwToUserID==5)//查询余额
- {
- }
- else if(dwToUserID==6)//登记客人IP
- {
- MyLock lock("accessclientip");
- int pos=str.Find ("&@&@&");
- if(pos!=-1)
- {
- CString info=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-5);
- pos=info.Find (":");
- CString dindan="订单数:"+info.Right (info.GetLength ()-pos-1);
- pos=info.Find ("订单数:");
- info=info.Left (pos);
- CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
- CString sql,execute;
- BOOL bexist=0;
- if(1)
- {MyLock lock("xiaoaccessdbmsg");
- CRecordset myset(&g_db);
- sql="select execute from unauth where name='"+info+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- {
- myset.GetFieldValue ("execute", execute);
- bexist=1;
- }
- myset.Close();
- }
- if(execute=="停止运行")
- {
- str="无域名字段,请确认";
- }
- else
- {
- if(bexist==0)
- sql.Format("insert into [unauth]([name],[dindan],[datetime],[execute])values('%s','%s','%s','%s')", info, dindan, datetime, "0");
- else
- sql.Format("update [unauth] set [dindan]='%s',[datetime]='%s' where [name]='%s'",dindan, datetime, info);
- MyExecuteSQL(&g_db, sql);
- }
- }
- else
- {
- CString name=str;
- pos=str.Find (";");
- long id;
- CString logcontent="未升级,无法获知";
- CString temp,regcode,regcode2,regcodebak;
-
- if(pos!=-1)
- {
- name=str.Left (pos);
- logcontent=str.Right (str.GetLength ()-pos-1);
- if(name=="20120817143012340694.ly.com")
- {
- WriteLogin("xxx:"+logcontent);
- }
- pos=logcontent.Find ("***");
- if(pos!=-1)
- {
- regcode=logcontent.Right (logcontent.GetLength ()-pos-3);
- regcodebak=regcode;
- logcontent=logcontent.Left(pos);
- str=GetUseDays(regcode);
- regcode=str;
-
- pos=regcode.Find ("---");
- if(pos!=-1)
- regcodebak+="---"+regcode.Right (regcode.GetLength ()-pos-3);
- }
- }
-
-
-
- UINT nPeerPort;
- GetPeerName(str, nPeerPort);
-
- CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
- pos=regcode.Find ("---");
- if(pos!=-1)
- temp=regcode.Left (pos);
- else
- temp=regcode;
- CString sql="update [clientip] set [ip]='"+str+"',[datetime]='"+datetime+"',[log]='"+logcontent+"',[regcode]='"+temp+"' where [name]='"+name+"'";
- MyExecuteSQL(&g_db, sql);
-
- if(1)
- {
- MyLock lock("xiaoaccessdbmsg");
- CString enterprisename;
- CRstClientIP rsSt;
- rsSt.m_strFilter ="name='"+name+"'";
- rsSt.Open();
- if(!rsSt.IsEOF())
- {
- sql=rsSt.m_branchname ;
- enterprisename=rsSt.m_enterprisename ;
- regcode2=rsSt.regcode2 ;
- }
- else
- {
- sql="xxx!";
- str="此域名未绑定";
- }
- rsSt.Close();
-
- }
- regcode=regcodebak;
- if(regcode!="" && (regcode2.GetLength ()==10||regcode2=="永久") )
- {
- CTime curtm=CTime::GetCurrentTime ();
- long newsecond=0;long dtsecond=0;
- if(regcode2=="永久")
- {
- newsecond=60;
- int pos=regcode.Find ("---");
- if(pos!=-1)regcodebak=regcode.Left (pos);
- }
- else
- {
- CTime destm( atoi(regcode2.Mid (0,4)), atoi(regcode2.Mid (5,2)), atoi(regcode2.Mid (8,2)), 0, 0, 0);
- CTimeSpan dt=destm-curtm;
- dtsecond=dt.GetTotalSeconds();
- dtsecond/=2;
- int pos=regcode.Find ("---");
- if(pos!=-1 && dtsecond>0)
- {
- regcodebak=regcode.Left (pos);
- regcode=regcode.Right (regcode.GetLength ()-pos-3);
-
- long usedsecond=atoi(regcode);
- newsecond=usedsecond+dtsecond;
- }
- }
- if(newsecond)
- {
- str+="authcodexiao"+GetAuthCode(regcodebak, newsecond);
- }
- }
-
- }
- }
- else if(dwToUserID==7)//查询客人IP
- {
- MyLock lock("xiaoaccessdbmsg");
- CRecordset myset(&g_db);
- CString sql="select ip from clientip where name='"+str+"'";
- str="";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("ip", str);
- else
- str+="没有此域名的记录!";
- myset.Close();
- }
- else if(dwToUserID==14)//查询客人IP
- {
- MyLock lock("xiaoaccessdbmsg");
- CRecordset myset(&g_db);
- CString sql="select ip from clientip where name='20120829094720383019.ly.com'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("ip", str);
- else
- {
- str+="没有此域名的记录!";
- sql="insert into clientip(name,)values('20120829094720383019.ly.com');";
- CString date=CTime::GetCurrentTime ().Format ("%Y-%m-%d");
- CString date2=CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S");
- sql= "insert into clientip([name],[applydate],[branchname],[modifydate]) values(\
- '20120829094720383019.ly.com',\
- '"+date+"',\
- 'xiao测试',\
- '"+date2+"')";
- MyExecuteSQL(&g_db, sql);
- }
- myset.Close();
- }
- else if(dwToUserID==15)//登记客人IP
- {
- MyLock lock("accessclientip");
- UINT nPeerPort;
- GetPeerName(str, nPeerPort);
- CString name="20120829094720383019.ly.com";
- CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
- CString sql="update [clientip] set [ip]='"+str+"',[datetime]='"+datetime+"' where [name]='"+name+"'";
- MyExecuteSQL(&g_db, sql);
- }
- else if(dwToUserID==8)//企业版客人查询企业资料
- {
- CString name=str;CString temp,sql;
- CString rights,bmain,enterprisename;
- CRecordset myset(&g_db);
- if(1)
- {MyLock lock("xiaoaccessdbmsg");
- sql="select enterprisename from clientip where name='"+name+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- {
-
- myset.GetFieldValue ("enterprisename", enterprisename);
- }
- else
- sql="xxx!";
- myset.Close();
-
- }
- if(1)
- {
- MyLock lock("xiaoaccessdbmsg");
- str=enterprisename;
- str.TrimLeft ();
- str.TrimRight ();
- if(str.IsEmpty ()==0)
- {
- CRecordset myset(&g_db);
- CString sql="select count(*) as cot from clientip where [enterprisename]='"+str+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- myset.GetFieldValue ("cot", sql);
- myset.Close();
- if(atol(sql))
- {
- CArray<CStringArray, CStringArray>m_List1array;
- m_List1array.SetSize(atol(sql) , 1 );
- CRstClientIP rsSt;
- rsSt.m_strFilter ="[enterprisename]='"+str+"'";
- rsSt.Open();
- DWORD ii=0;
- while(!rsSt.IsEOF())
- {
- m_List1array.ElementAt (ii).RemoveAll ();
- m_List1array.ElementAt (ii).Add(rsSt.m_name) ;
- m_List1array.ElementAt (ii).Add(rsSt.m_branchname) ;
- m_List1array.ElementAt (ii).Add(rsSt.m_ip) ;
- m_List1array.ElementAt (ii).Add(rsSt.m_bmain) ;
- m_List1array.ElementAt (ii).Add(rsSt.m_enterprisename) ;
- rights=","+rsSt.m_rights+",";
- m_List1array.ElementAt (ii).Add(rights) ;
- m_List1array.ElementAt (ii).Add(rsSt.m_name2) ;
- ii++;
- rsSt.MoveNext();if(m_List1array.GetSize ()<=ii)break;
- }
- rsSt.Close();m_List1array.SetSize(ii , 1 );
- str.Empty ();
- nBranchArraySize=ii;
-
-
- CMemFile memfile;
- CArchive ar(&memfile, CArchive::store);
- for( ii=0; ii<m_List1array.GetSize (); ii++)
- {
- m_List1array.ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- nBranchDataLeng=memfile.GetLength ();
- pBranchData=memfile.Detach();
- str="ok";
- }
- else
- str+="没有此企业的资料";
- // WriteLogin("查询企业资料成功");
- }
- else
- str+="没有此企业的资料";
- }
- }
- else if(dwToUserID==9)//企业版分店权限设置
- {
- CArray<CStringArray, CStringArray>m_List1array;
- CMemFile memfile;
- memfile.Attach (ptChatMessage->byFileContent+sizeof(DWORD), nMessageLen-sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- DWORD arraysize;
- memcpy(&arraysize, ptChatMessage->byFileContent, sizeof(DWORD));
- m_List1array.SetSize(arraysize);
- for(int ii=0; ii<m_List1array.GetSize (); ii++)
- {
- m_List1array.ElementAt (ii).Serialize (ar);
- }
- ar.Close();
- memfile.Detach ();CString enterprisename;
- if(m_List1array.GetSize ())
- {
- enterprisename=m_List1array.ElementAt (0).ElementAt (0);
-
- CString branchname,rights;
- for(ii=0; ii<m_List1array.GetSize (); ii++)
- {
- branchname=m_List1array.ElementAt (ii).ElementAt (1);
- rights.Empty ();
- for(int j=2; j<m_List1array.ElementAt (ii).GetSize (); j++)
- {
- rights+=m_List1array.ElementAt (ii).ElementAt (j);
- rights+=",";
- }
- rights.TrimRight (",");
- CString sql= "update clientip set [rights]='"+rights+"' where [enterprisename]='"+enterprisename+"' and [branchname]='"+branchname+"'";
- MyExecuteSQL(&g_db, sql);
- }
- }
- str="set ok";
- // WriteLogin("设置企业访问权限成功");
- }
- else if(dwToUserID==10)//登记客人IP
- {
- MyLock lock("accessclientip2");
- CString name=str;
-
- UINT nPeerPort;
- GetPeerName(str, nPeerPort);
-
- CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
- CString sql="update [clientip2] set [ip]='"+str+"',[datetime]='"+datetime+"' where [name]='"+name+"'";
- MyExecuteSQL(&g_db, sql);
- }
- else if(dwToUserID==11)//查询客人IP
- {
- MyLock lock("xiaoaccessdbmsg");
- CRecordset myset(&g_db);
- CString sql="select ip from clientip2 where name='"+str+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("ip", str);
- else
- str+="没有此域名的记录!";
- myset.Close();
- }
- else if(dwToUserID==12)//执行sql
- {
- g_db.ExecuteSQL (str);str="ok";
- }
- else if(dwToUserID==13)//查询sql
- {
- CString m_sql=str;
- while(1)
- {
- str="ok";
- if(m_sql.GetLength ()<6)break;
- if(m_sql.Left (6)!="select")break;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- CRecordset myset(&g_db);
- myset.Open (CRecordset::forwardOnly, m_sql);
- str="";
- while(!myset.IsEOF ())
- {
- colcount=myset.GetODBCFieldCount ();
- for( i=0; i<colcount; i++)
- {
- myset.GetFieldValue(i, temp);
- str+="'"+temp+"',";
- }
- str.TrimRight (",");
- str+="\r\n";
- myset.MoveNext ();
- }
- myset.Close();break;
- }
- }
- else if(dwToUserID==16)//登记客人
- {
- MyLock lock("accessclientip3");
- CString separator="*%!X";
- int sepleng=separator.GetLength();
- CString domain,m_edit1,m_edit2,m_edit3,m_edit4,m_edit5,danshu;
- int pos=str.Find(separator);
- if(pos!=-1)
- {
- domain=str.Left(pos);
- str=str.Right(str.GetLength()-pos-sepleng);
- }
- pos=str.Find(separator);
- if(pos!=-1)
- {
- m_edit1=str.Left(pos);
- str=str.Right(str.GetLength()-pos-sepleng);
- }
- pos=str.Find(separator);
- if(pos!=-1)
- {
- m_edit2=str.Left(pos);
- str=str.Right(str.GetLength()-pos-sepleng);
- }
- pos=str.Find(separator);
- if(pos!=-1)
- {
- m_edit3=str.Left(pos);
- str=str.Right(str.GetLength()-pos-sepleng);
- }
- pos=str.Find(separator);
- if(pos!=-1)
- {
- m_edit4=str.Left(pos);
- str=str.Right(str.GetLength()-pos-sepleng);
- }
- pos=str.Find(separator);
- if(pos!=-1)
- {
- m_edit5=str.Left(pos);
- str=str.Right(str.GetLength()-pos-sepleng);
- danshu=str;
- }
- UINT nPeerPort;
- GetPeerName(str, nPeerPort);
- CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
- CString sql;
- CString ret;
- CRecordset myset(&g_db);
- sql="select ret from [softclient] where [domain]='"+domain+"' and [name]='"+m_edit1+"' and [phone]='"+m_edit2+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("ret", ret);
- myset.Close();
- sql="delete from [softclient] where [domain]='"+domain+"' and [name]='"+m_edit1+"' and [phone]='"+m_edit2+"'";
- MyExecuteSQL(&g_db, sql);
- sql.Format("insert into [softclient]([domain],[name],[phone],[addr],[admin],[version],[cot],[ip],[datetime],[ret])\
- values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", domain,m_edit1,m_edit2,m_edit3,m_edit4,m_edit5,danshu,str,datetime,ret);
- MyExecuteSQL(&g_db, sql);
-
- str=ret;
- }
- /* else if(dwToUserID==14)//登记客人IP
- {
- CString name=str;
- int pos=name.Find (";");
- if(pos!=-1)
- {
- str=name.Right (name.GetLength ()-pos-1);
- name=name.Left (pos);
- CString datetime=CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S");
- CString sql="update [clientip] set [ip]='"+str+"',[datetime]='"+datetime+"' where [name]='"+name+"'";
- MyExecuteSQL(&g_db, sql);
- WriteLogin2(name+"登记IP2");
- }
- else
- str="0";
- }*/
- DWORD dwFromUserID = dwUserID;
- WORD wMessageId = MSG_CHATMESSAGE_RESP;
- DWORD dwDataLen;
- BYTE *pSendData;
- TCHAT_MESSAGE_STRU *pChatMessage;
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- tHeader.dwDataLen = dwDataLen;
-
- if(str.IsEmpty ())str="OK";
- int nDataLen=str.GetLength ();
- if(nBranchDataLeng)
- {
- nDataLen=nBranchDataLeng;
- g_sendhead.count[0]=nBranchArraySize;
- }
-
- dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen ;
- pSendData = new BYTE[dwDataLen];
- pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
- memset(pChatMessage, 0x00, dwDataLen);
- memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
- pChatMessage->tCommonMsg.dwConnectionID = dwFromUserID;
- pChatMessage->tCommonMsg.wMessageId = wMessageId;
- pChatMessage->dwFromUserID = dwFromUserID;
- pChatMessage->dwToUserID = dwToUserID;
- pChatMessage->wMessageLen = nDataLen;
-
-
- if(nBranchDataLeng)
- {
- memcpy(pChatMessage->byFileContent, pBranchData, nDataLen); delete []pBranchData;
- }
- else
- {
- memcpy(pChatMessage->byFileContent, str.GetBuffer (0), nDataLen);
- str.ReleaseBuffer ();
- }
-
- net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
- delete [] pSendData;
-
- }
- }
- catch(...)
- {
- CString str;
- str.Format ("出错-%d", dwToUserID);
- WriteLogin(str);
- }
- g_bWork=0;
-
- }
- //没有此域名的记录
|