1 // WebDlg.cpp : implementation file
5 #include "nel_launcher.h"
6 #include "nel_launcherDlg.h"
16 static char THIS_FILE
[] = __FILE__
;
19 /////////////////////////////////////////////////////////////////////////////
23 CWebDlg::CWebDlg(CWnd
* pParent
/*=NULL*/)
24 : CDialog(CWebDlg::IDD
, pParent
)
26 //{{AFX_DATA_INIT(CWebDlg)
27 // NOTE: the ClassWizard will add member initialization here
32 void CWebDlg::DoDataExchange(CDataExchange
* pDX
)
34 CDialog::DoDataExchange(pDX
);
35 //{{AFX_DATA_MAP(CWebDlg)
36 DDX_Control(pDX
, IDC_EXPLORER1
, m_explore
);
41 BEGIN_MESSAGE_MAP(CWebDlg
, CDialog
)
42 //{{AFX_MSG_MAP(CWebDlg)
49 /////////////////////////////////////////////////////////////////////////////
50 // CWebDlg message handlers
52 BEGIN_EVENTSINK_MAP(CWebDlg
, CDialog
)
53 //{{AFX_EVENTSINK_MAP(CWebDlg)
54 ON_EVENT(CWebDlg
, IDC_EXPLORER1
, 250 /* BeforeNavigate2 */, OnBeforeNavigate2
, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL
)
55 ON_EVENT(CWebDlg
, IDC_EXPLORER1
, 259 /* DocumentComplete */, OnDocumentComplete
, VTS_DISPATCH VTS_PVARIANT
)
56 ON_EVENT(CWebDlg
, IDC_EXPLORER1
, 252 /* NavigateComplete2 */, OnNavigateComplete2Explorer1
, VTS_DISPATCH VTS_PVARIANT
)
60 void CWebDlg::OnBeforeNavigate2(LPDISPATCH pDisp
, VARIANT FAR
* URL
, VARIANT FAR
* Flags
, VARIANT FAR
* TargetFrameName
, VARIANT FAR
* PostData
, VARIANT FAR
* Headers
, BOOL FAR
* Cancel
)
66 m_dlgLoading.MoveWindow(r.left+BROWSER_X, r.top+BROWSER_Y, BROWSER_W, BROWSER_H);
67 m_dlgLoading.ShowWindow(SW_SHOW);*/
69 // set the user agent to nel_launcher changing the header
70 CString
csHeader(Headers
->bstrVal
);
72 if(csHeader
.IsEmpty())
74 IWebBrowser2
*pBrowser
;
77 pDisp
->QueryInterface(IID_IWebBrowser2
, (void**) &pBrowser
);
78 pBrowser
->get_Container(&pWebDisp
);
80 BSTR bstr
= SysAllocString(L
"User-Agent: nel_launcher\r\n");
81 Headers
->bstrVal
= bstr
;
83 pBrowser
->Navigate2(URL
, Flags
, TargetFrameName
, PostData
, Headers
);
98 VARIANT
CWebDlg::ExecuteScript(CString csCode
, CString csLanguage
)
102 IHTMLDocument2
* pHTMLDocument2
;
103 IHTMLWindow2
* pHTMLWindow2
;
104 LPDISPATCH lpDispatch
;
105 lpDispatch
= m_explore
.GetDocument();
107 BSTR bstrCode
= _bstr_t((const char *)csCode
);
108 BSTR bstrLang
= _bstr_t((const char *)csLanguage
);
113 hr
= lpDispatch
->QueryInterface(IID_IHTMLDocument2
, (void**)&pHTMLDocument2
);
116 hr
= pHTMLDocument2
->get_parentWindow(&pHTMLWindow2
);
119 pHTMLWindow2
->execScript(bstrCode
, bstrLang
, &varRet
);
120 pHTMLWindow2
->Release();
122 pHTMLDocument2
->Release();
124 lpDispatch
->Release();
129 VARIANT
CWebDlg::ExecuteJavascript(CString csCode
)
131 return ExecuteScript(csCode
, "Javascript");
134 void CWebDlg::OpenUrl(CString csUrl
)
137 m_explore
.Navigate(csUrl
, NULL
, NULL
, NULL
, NULL
);
140 void CWebDlg::OpenUrl(const std::string
&url
)
142 m_csUrl
= url
.c_str();
143 m_explore
.Navigate(url
.c_str(), NULL
, NULL
, NULL
, NULL
);
146 void CWebDlg::OnDocumentComplete(LPDISPATCH pDisp
, VARIANT FAR
* URL
)
148 IHTMLDocument2
* pHTMLDocument2
;
149 LPDISPATCH lpDispatch
;
150 lpDispatch
= m_explore
.GetDocument();
155 hr
= lpDispatch
->QueryInterface(IID_IHTMLDocument2
, (LPVOID
*) &pHTMLDocument2
);
156 lpDispatch
->Release();
161 if (pHTMLDocument2
== NULL
)
165 hr
= pHTMLDocument2
->get_body(&pBody
);
174 pBody
->get_innerHTML(&bstr
);
176 CString
csSourceCode(bstr
);
183 if(csSourceCode
.Find("newlogin") != -1)
185 // Authentication not ok !
186 APP
.m_bAuthGame
= FALSE
;
187 APP
.m_bAuthWeb
= FALSE
;
188 ((CNel_launcherDlg
*)AfxGetMainWnd())->m_wndTabs
.DestroyWindow();
190 ((CNel_launcherDlg
*)AfxGetMainWnd())->Login();
194 // ACE: BADDDDDD!!!! the good web page can contains 404 in the cookie because the cookie contains any number we want
195 /* else if(csSourceCode.Find("404") != -1)
197 // Authentication lost, try to redo the authentication
204 */ int iFindAction1
= csSourceCode
.Find("<!--nel");
209 if(iFindAction1
!= -1)
211 iFindAction1
= csSourceCode
.Find('"', iFindAction1
);
212 if(iFindAction1
!= -1)
214 iFindAction2
= csSourceCode
.Find('"', iFindAction1
+1);
215 if(iFindAction2
!= -1)
217 csAction
= csSourceCode
.Mid(iFindAction1
+1, iFindAction2
- iFindAction1
-1);
219 iFindComment1
= iFindAction2
+ 2;
220 if(iFindComment1
!= -1)
222 iFindComment2
= csSourceCode
.Find("-->", iFindAction1
);
223 if(iFindComment2
!= -1)
225 csComment
= csSourceCode
.Mid(iFindComment1
, iFindComment2
- iFindComment1
);
226 csComment
.TrimRight();
227 csComment
.TrimLeft();
229 if(csAction
== "launch")
230 ((CNel_launcherDlg
*)GetParent())->launch(csComment
);
231 else if(csAction
== "patch")
232 ((CNel_launcherDlg
*)GetParent())->patch(csComment
);
239 // m_dlgLoading.ShowWindow(SW_HIDE);
242 BOOL
CWebDlg::OnInitDialog()
244 CDialog::OnInitDialog();
248 m_brushBG
.CreateSolidBrush(RGB(0, 16, 0));
251 GetDlgItem(IDC_EXPLORER1
)->MoveWindow(-2, -2, r
.Width()-48, r
.Height());
253 // m_dlgLoading.Create(IDD_LOADING_PAGE, this);
254 // m_dlgLoading.ShowWindow(SW_HIDE);
256 // ClientToScreen(&r);
257 // m_dlgLoading.MoveWindow(r.left+BROWSER_X, r.top+BROWSER_Y, BROWSER_W, BROWSER_H);
259 return TRUE
; // return TRUE unless you set the focus to a control
260 // EXCEPTION: OCX Property Pages should return FALSE
263 void CWebDlg::OnSize(UINT nType
, int cx
, int cy
)
265 CDialog::OnSize(nType
, cx
, cy
);
268 HBRUSH
CWebDlg::OnCtlColor(CDC
* pDC
, CWnd
* pWnd
, UINT nCtlColor
)
270 HBRUSH hbr
= CDialog::OnCtlColor(pDC
, pWnd
, nCtlColor
);
272 if(nCtlColor
== CTLCOLOR_DLG
)
275 pDC
->SetBkColor(RGB(0, 16, 0));
276 pDC
->SetBkMode(OPAQUE
);
281 void CWebDlg::OnNavigateComplete2Explorer1(LPDISPATCH pDisp
, VARIANT FAR
* URL
)
285 BOOL
CWebDlg::OnEraseBkgnd(CDC
* pDC
)
287 CBrush
backBrush(RGB(0, 16, 0));
288 CBrush
* pOldBrush
= pDC
->SelectObject(&backBrush
);
291 pDC
->GetClipBox(&r
); // Erase the area needed.
292 pDC
->PatBlt(r
.left
, r
.top
, r
.Width(), r
.Height(), PATCOPY
);
293 pDC
->SelectObject(pOldBrush
);