// AutoRun3Dlg.cpp : implementation file // #include "stdafx.h" #include "AutoRun3.h" #include "AutoRun3Dlg2.h" #include // #include "ConnectDlg.h" #include "SendDataDlg.h" #include "AddContact.h" #include "SendReg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern DWORD g_nSendCode; extern BOOL g_bReturned2; ///////////////////////////////////////////////////////////////////////////// extern HWND g_hSendWnd; extern HWND g_hConnectWnd; #define DISCONNECT_TIMER (WM_USER + 101) #define LOGINFAILED_TIMER (WM_USER + 102) ///////////////////////////////////////////////////////////////////////////// static void HandleClientNetEvent2(IN SOCKET hSocket, IN ETransportEvent eEvent, IN void *pDataBuf, IN unsigned long nDataLen, IN int nError, IN void *pContext) { if( nError != TRANSPORT_OK ) return; CAutoRun3Dlg2 *pDlg = (CAutoRun3Dlg2 *)pContext; if( NULL == pDlg ) return; pDlg->ProcessNetEvent(eEvent, pDataBuf, nDataLen); } CAutoRun3Dlg2::CAutoRun3Dlg2(CWnd* pParent /*=NULL*/) : CDialog(CAutoRun3Dlg2::IDD, pParent) { //{{AFX_DATA_INIT(CAutoRun3Dlg2) m_strSendSms = _T(""); m_strLoginID = _T(""); m_strLoginPwd = _T(""); m_strRecvMobi = _T(""); m_strNewPwd = _T(""); m_mobicount = 0; m_check1 = FALSE; m_count = 0; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_nMobile=0; m_nPhone=0; CString version = _T ("Version 1.0"); m_strLoginID=AfxGetApp()->GetProfileString (version, "account", ""); m_strLoginPwd=AfxGetApp()->GetProfileString (version, "psw", ""); if(!m_strLoginPwd.IsEmpty())m_check1=1; } void CAutoRun3Dlg2::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAutoRun3Dlg2) DDX_Control(pDX, IDC_LIST2, m_List1); DDX_Control(pDX, IDC_BTN_SEND, m_btnSend); DDX_Control(pDX, IDC_LST_SMS, m_listCtrl); DDX_Text(pDX, IDC_EDT_SMS, m_strSendSms); DDV_MaxChars(pDX, m_strSendSms, 2000); DDX_Text(pDX, IDC_EDT_LOGIN_ID, m_strLoginID); DDV_MaxChars(pDX, m_strLoginID, 11); DDX_Text(pDX, IDC_EDT_LOGIN_PWD, m_strLoginPwd); DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_strRecvMobi); DDX_Text(pDX, IDC_EDT_NEW_PWD, m_strNewPwd); DDX_Text(pDX, IDC_EDT_NUM, m_mobicount); DDX_Check(pDX, IDC_CHECK1, m_check1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAutoRun3Dlg2, CDialog) //{{AFX_MSG_MAP(CAutoRun3Dlg2) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend) ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery) ON_BN_CLICKED(IDC_BTN_Query2, OnBTNQuery2) ON_BN_CLICKED(IDC_BTN_CHANGE_PWD, OnBtnChangePwd) ON_BN_CLICKED(IDC_BTN_GET_STATUS, OnBtnGetStatus) ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTadd, OnBUTadd) ON_BN_CLICKED(IDC_BUTdel, OnBUTdel) ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2) ON_EN_CHANGE(IDC_EDT_SMS, OnChangeEdtSms) ON_EN_CHANGE(IDC_EDT_RECV_MOBI, OnChangeEdtRecvMobi) ON_BN_CLICKED(IDC_CHECK1, OnCheck1) ON_BN_CLICKED(IDC_BTN_REG, OnBtnReg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// BOOL CAutoRun3Dlg2::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog // g_pMainWnd=this; ///////////////////////////////// // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } DWORD CAutoRun3Dlg2::GetConnectionID() { return m_dwConnectionID; } void CAutoRun3Dlg2::SetConnectionID(DWORD dwConnection) { m_dwConnectionID = dwConnection; } void CAutoRun3Dlg2::ProcessChatMessageRequest2(CString sql) { const char *szDataBuf = sql.GetBuffer(0); sql.ReleaseBuffer(); ProcessChatMessageRequest((void*)szDataBuf, strlen(szDataBuf) + 1); } void CAutoRun3Dlg2::ProcessChatMessageRequest2(BYTE code) { ProcessChatMessageRequest(&code, sizeof(BYTE)); } void CAutoRun3Dlg2::ProcessChatMessageRequest2(BYTE *pData, int length) { ProcessChatMessageRequest((void*)pData, length); } BOOL CAutoRun3Dlg2::ProcessChatMessageRequest(void *szDataBuf, int nDataLen) { g_bReturned2=0; DWORD dwFromUserID = GetConnectionID(); WORD wMessageId = MSG_CHATMESSAGE_REQ; DWORD dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen; BYTE *pSendData = new BYTE[dwDataLen]; TCHAT_MESSAGE_STRU *pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData; memset(pChatMessage, 0x00, dwDataLen); g_sendhead.length[98]=987123768; memcpy(pSendData, &g_sendhead, sizeof(g_sendhead)); pChatMessage->tCommonMsg.dwConnectionID = GetConnectionID(); pChatMessage->tCommonMsg.wMessageId = wMessageId; pChatMessage->dwFromUserID = dwFromUserID; pChatMessage->dwToUserID = 15; pChatMessage->wMessageLen = nDataLen; memcpy(pChatMessage->byFileContent, szDataBuf, nDataLen); TMessageHeader tHeader = {0}; tHeader.wMessageId = wMessageId; tHeader.dwDataLen = dwDataLen; BOOL bRet=0; unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)pChatMessage, dwDataLen); if( ulSendLen != SOCKET_ERROR ) { bRet=1; } delete [] pSendData; return bRet; } BOOL CAutoRun3Dlg2::OnConnect() { CString strServerAddress = g_server2; char *szServerAddress = strServerAddress.GetBuffer(0); strServerAddress.ReleaseBuffer(); /*for Client, IP and Port can be 0, and for Server, IP is LocalIP, and Port is Listening Port*/ int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client, 0, HandleClientNetEvent2, this); if( TRANSPORT_OK != nResult ) { return 0; } DWORD dwRemoteIPValue = inet_addr(szServerAddress); WORD wPort = 5678; nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort); if( TRANSPORT_OK != nResult ) { m_tClientTunnel.net_CloseSocket(); return 0; } return ProcessLoginRequest(); } void CAutoRun3Dlg2::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen) { if( Transport_ReadEv == nEventType ) { if( NULL == pRecvMsg ) return; TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg; char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN; WORD dwMessageID = pHeader->wMessageId; switch(dwMessageID) { case MSG_LOGIN_RESP: { LOGIN_RESULT_STRU tLoginResult = {0}; memcpy(&tLoginResult, pDataBuf, sizeof(LOGIN_RESULT_STRU)); ProcessLoginResponse(&tLoginResult); break; } case MSG_USERINFO_RESP: { TUSERLIST_INFO_STRU tUserListInfo = {0}; memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU)); // ProcessUserListInfoResponse(&tUserListInfo); break; } case MSG_LOGOUT_RESP: { TUSERLIST_INFO_STRU tUserListInfo = {0}; memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU)); // ProcessLogoutResponse(&tUserListInfo); break; } case MSG_CHATMESSAGE_RESP: { TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf; ProcessChatMessageResponse((void *)pChatMessage); break; } default: { break; } } } else if( Transport_CloseEv == nEventType ) { SetTimer(DISCONNECT_TIMER, 0, NULL); } /////// } void CAutoRun3Dlg2::OnDisconnect() { m_tClientTunnel.net_CloseSocket(); SetConnectionID(INVALID_SOCKET); } void CAutoRun3Dlg2::ProcessLoginResponse(void *pLoginResult) { if( NULL == pLoginResult ) return; LOGIN_RESULT_STRU *ptLoginResult = (LOGIN_RESULT_STRU *)pLoginResult; DWORD dwConnectionID = ptLoginResult->tCommonMsg.dwConnectionID; SetConnectionID(dwConnectionID); BYTE byResult = ptLoginResult->byResult; if(LOGIN_RESULT_SUC == byResult) { } else { SetTimer(LOGINFAILED_TIMER, 0, NULL); } CString strCommentInfo(""); strCommentInfo.Format("%s. 用户代号: %ld", ((LOGIN_RESULT_SUC == byResult) ? "登录成功" : (LOGIN_RESULT_MULTI == byResult) ? "重复登录" : (LOGIN_RESULT_NAMERROR == byResult) ? "名字不存在" : (LOGIN_RESULT_PWERROR == byResult) ? "密码错误" : "登录失败"), dwConnectionID); // MessageBox((CString)strCommentInfo); } extern void MyGetIPByName(CString &name); extern CString g_localip; BOOL CAutoRun3Dlg2::ProcessLoginRequest() { WORD wMessageId = MSG_LOGIN_REQ; TLOGIN_STRU tLogonInfo = {0}; tLogonInfo.tCommonMsg.dwConnectionID = GetConnectionID(); tLogonInfo.tCommonMsg.wMessageId = wMessageId; if(g_localip.IsEmpty ()) { char path[MAX_PATH]; ::memset (path, 0, MAX_PATH); DWORD leng=50; ::GetComputerName (path, &leng); g_localip=path; MyGetIPByName(g_localip); return 0; } CString strUserName = "rtghj3wsdfg"+g_localip; strUserName.TrimLeft(); strUserName.TrimRight(); strcpy(tLogonInfo.tUserInfo.szUserName, strUserName); DWORD dwDataLen = sizeof(TLOGIN_STRU); TMessageHeader tHeader = {0}; tHeader.wMessageId = wMessageId; tHeader.dwDataLen = dwDataLen; unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)&tLogonInfo, dwDataLen); if( ulSendLen == SOCKET_ERROR ) { return 0; } return 1; } //--------------------------------------------------------------------------- void CAutoRun3Dlg2::OnDestroy() { CDialog::OnDestroy(); OnDisconnect(); } void CAutoRun3Dlg2::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if( DISCONNECT_TIMER == nIDEvent ) { KillTimer(nIDEvent); OnDisconnect(); } else if( LOGINFAILED_TIMER == nIDEvent ) { KillTimer(nIDEvent); OnDisconnect(); } } void CAutoRun3Dlg2::OnBUTadd() { // TODO: Add your control notification handler code here AddContact dlg; if(dlg.DoModal ()!=IDOK)return; CString str; int pos; for(int i=0; i'9')return -1; } if(phoneno.GetAt (0)=='1') { if(phoneno.GetLength ()!=11) return -1; int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144}; int unicom[]={130,131,132,155,156,186,185}; int telecom[]={133,153,189,180}; BOOL bFind=0; for(i=0; i=10 && phoneno.GetLength ()<=12) { // m_nPhone++; return 1; } } return -1; } void CAutoRun3Dlg2::OnChangeEdtRecvMobi() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. // TODO: Add your control notification handler code here } void CAutoRun3Dlg2::OnChangeEdtSms() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. UpdateData(); m_strSendSms.Replace ("'", "'"); m_strSendSms.Replace ("(", "("); m_strSendSms.Replace (")", ")"); SetDlgItemText(IDC_EDT_SMS, m_strSendSms); ((CEdit*)GetDlgItem(IDC_EDT_SMS))->SetSel(m_strSendSms.GetLength (),m_strSendSms.GetLength ()); CString str; int count=0; int leng=GetLengthEx(m_strSendSms); if(m_nMobile) { count+=m_nMobile*(leng/70); if(leng%70) count+=m_nMobile; } if(m_nPhone) { count+=m_nPhone*(leng/56); if(leng%56) count+=m_nPhone; } m_count=count; str.Format ("短信内容(手机70字/条,小灵通56字/条)(现%d字,共%d条短信)", leng,count); GetDlgItem(IDC_STATIC1)->SetWindowText(str); // TODO: Add your control notification handler code here } int CAutoRun3Dlg2::GetLengthEx(CString str) { int leng=0; TBYTE ucHigh, ucLow; for (int i=0; i20)m_strNewPwd=m_strNewPwd.Left (20); CString str; str=m_strLoginID; str+="\r\n"; str+=m_strLoginPwd; str+="\r\n"; str+=m_strNewPwd; BYTE *pData=new BYTE[str.GetLength ()]; memcpy(pData, str.GetBuffer (0), str.GetLength ()); str.ReleaseBuffer (); EncryptFile2(pData, str.GetLength (), "888666333"); g_nSendCode=1; ProcessChatMessageRequest2(pData, str.GetLength ()); g_nSendCode=0; delete []pData; } void CAutoRun3Dlg2::OnBtnGetStatus() { } BOOL CAutoRun3Dlg2::MyExecuteSQL(CDatabase *pdb, CString sql) { try { pdb->ExecuteSQL (sql); } catch(...) { return 0; } return 1; } BOOL CAutoRun3Dlg2::CheckExist(CString content, CString phones) { CRecordset myset(&g_db); CString sql="select count(*) as cot from sendreg where [content]='"+content+"' and [phones]='"+phones+"'"; myset.Open (CRecordset::forwardOnly, sql); if(!myset.IsEOF()) { myset.GetFieldValue ("cot", sql); if(atoi(sql)) return 1; else return 0; } else return 0; } void CAutoRun3Dlg2::OnBtnReg() { // TODO: Add your control notification handler code here UpdateData(); SendReg dlg; dlg.m_strLoginID=m_strLoginID; dlg.m_strLoginPwd=m_strLoginPwd; dlg.DoModal (); } extern CArrayg_List1array; extern DWORD g_nLeng; extern BYTE *g_pData; extern DWORD g_ncount2; void CAutoRun3Dlg2::ProcessChatMessageResponse(void *pResponse) { if( NULL == pResponse ) return; TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pResponse; int nMessageLen = pChatMessage->wMessageLen; // if(nMessageLen==0) // return; if(g_pData)delete []g_pData;g_pData=NULL; g_pData=new BYTE[nMessageLen]; memcpy(g_pData, pChatMessage->byFileContent, nMessageLen); memcpy( &g_sendhead, pChatMessage, sizeof(g_sendhead)); g_nLeng=nMessageLen; if(nMessageLen<=sizeof(DWORD)) { memcpy(&g_ncount2, pChatMessage->byFileContent, sizeof(DWORD)); } g_bReturned2=1; }