// LoginDlg.cpp : implementation file // #include "stdafx.h" #include "nel/misc/string_mapper.h" #include "nel/misc/config_file.h" #include "nel/misc/path.h" #include "nel_launcherDlg.h" #include "nel_launcher.h" #include "MsgDlg.h" #include "LoginDlg.h" #include "patch.h" #include "Md5.h" ///////////////////////////////////////////////////////////////////////////// // CLoginDlg dialog using namespace std; #define LOGIN_BG_X 0 #define LOGIN_BG_Y 0 CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/) : CDialog(CLoginDlg::IDD, pParent) { //{{AFX_DATA_INIT(CLoginDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT APP.ResetConnection(); } void CLoginDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CLoginDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CLoginDlg, CDialog) //{{AFX_MSG_MAP(CLoginDlg) ON_WM_CTLCOLOR() ON_WM_SETCURSOR() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_NCLBUTTONUP() ON_WM_ERASEBKGND() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLoginDlg message handlers HBRUSH CLoginDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(pWnd && pWnd->GetDlgCtrlID() == IDC_ERR_STATIC) { hbr = m_brush; pDC->SetBkColor(RGB(12, 42, 52)); pDC->SetTextColor(RGB(255, 0, 0)); } else if(nCtlColor == CTLCOLOR_STATIC) { hbr = m_brush; pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255, 255, 127)); } else if(nCtlColor == CTLCOLOR_EDIT) { hbr = m_brushEdit; pDC->SetTextColor(RGB(255, 255, 127)); pDC->SetBkColor(RGB(12, 42, 52)); } return hbr; } CString CLoginDlg::GetLogin() { return APP.m_csLogin; } CString CLoginDlg::GetPassword() { return APP.m_csPassword; } BOOL CLoginDlg::OnInitDialog() { CDialog::OnInitDialog(); CString csLogin = APP.GetRegKeyValue(_T("Pseudo")); m_brush.CreateStockObject(NULL_BRUSH); m_brushEdit.CreateSolidBrush(RGB(12, 42, 52)); SetDlgItemText(IDC_ERR_STATIC, ""); SetDlgItemText(IDC_LOGIN_EDIT, csLogin); if(csLogin.IsEmpty()) GotoDlgCtrl(GetDlgItem(IDC_LOGIN_EDIT)); else GotoDlgCtrl(GetDlgItem(IDC_PWD_EDIT)); GetDlgItem(IDC_LOGINU_STATIC)->ShowWindow(SW_SHOW); GetDlgItem(IDC_LOGIND_STATIC)->ShowWindow(SW_HIDE); GetDlgItem(IDC_QUITU_STATIC)->ShowWindow(SW_SHOW); GetDlgItem(IDC_QUITD_STATIC)->ShowWindow(SW_HIDE); ((CEdit*)GetDlgItem(IDC_LOGIN_EDIT))->SetLimitText(12); m_pictBG.LoadPicture(IDP_BG_LOGIN); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CLoginDlg::OnLogin() { unsigned char lpszBuffer[16]; CMD5 md5; CString csHash; char httpBuff[1024]; int nBytes; CString csBuff; CWaitCursor wc; CString csUrl; string Version = getVersion(); CTime t = CTime::GetCurrentTime(); APP.m_bAuthGame = FALSE; GetDlgItemText(IDC_LOGIN_EDIT, APP.m_csLogin); GetDlgItemText(IDC_PWD_EDIT, APP.m_csPassword); SetDlgItemText(IDC_ERR_STATIC, ""); md5.SetContent(APP.m_csLogin + APP.m_csPassword + t.Format("%Y%m%d") + MAGIC_KEY_MD5); md5.GetDigest(lpszBuffer); csHash = md5.ConvertToAscii(lpszBuffer); csUrl = "http://" + APP.m_config.m_csHost + APP.m_config.m_csUrlMain + "?digest=" + csHash + "&newlogin=" + APP.m_csLogin + "&clientApplication=ryzom"; TRY { CInternetSession session("nel_launcher"); session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 1000); session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3); CFile* pf = session.OpenURL(csUrl, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD); while(nBytes = pf->Read(httpBuff, 1024)) { csBuff += httpBuff; } } CATCH_ALL(error) { SetDlgItemText(IDC_ERR_STATIC, "Cannot connect to server !"); return; } END_CATCH_ALL; if(csBuff.Find("