/********************************************************************/ /* */ /* 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)) { CArraym_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; iim_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; iitCommonMsg.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; } //没有此域名的记录