DlgWOLLogon.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/Commando/DlgWOLLogon.cpp $
  22. *
  23. * DESCRIPTION
  24. * Westwood Online Login Dialog. This is the dialog that gathers the login
  25. * information from the user.
  26. *
  27. * PROGRAMMER
  28. * Denzil E. Long, Jr.
  29. * $Author: Denzil_l $
  30. *
  31. * VERSION INFO
  32. * $Revision: 21 $
  33. * $Modtime: 1/19/02 12:05a $
  34. *
  35. ******************************************************************************/
  36. #include "DlgWOLLogon.h"
  37. #include "RenegadeDialogMgr.h"
  38. #include "MPSettingsMgr.h"
  39. #include "DlgMessageBox.h"
  40. #include "DlgWOLSettings.h"
  41. #include <WWOnline\WOLLoginInfo.h>
  42. #include <WWUI\ComboBoxCtrl.h>
  43. #include <WWUI\EditCtrl.h>
  44. #include "DlgWebpage.h"
  45. #include "string_ids.h"
  46. #include "Resource.h"
  47. using namespace WWOnline;
  48. /******************************************************************************
  49. *
  50. * NAME
  51. * DlgWOLLogon::DoDialog
  52. *
  53. * DESCRIPTION
  54. *
  55. * INPUTS
  56. * Login - Login to display
  57. * Observer - Observer to be notified.
  58. *
  59. * RESULT
  60. * Success - True if dialog successfully started.
  61. *
  62. ******************************************************************************/
  63. bool DlgWOLLogon::DoDialog(const wchar_t* login, Observer<DlgWOLLogonEvent>* observer)
  64. {
  65. DlgWOLLogon* dialog = new DlgWOLLogon;
  66. if (dialog)
  67. {
  68. if (dialog->FinalizeCreate(login))
  69. {
  70. if (observer)
  71. {
  72. dialog->AddObserver(*observer);
  73. }
  74. dialog->Start_Dialog();
  75. }
  76. dialog->Release_Ref();
  77. }
  78. return (dialog != NULL);
  79. }
  80. /******************************************************************************
  81. *
  82. * NAME
  83. * DlgWOLLogon::DlgWOLLogon
  84. *
  85. * DESCRIPTION
  86. * Constructor
  87. *
  88. * INPUTS
  89. * NONE
  90. *
  91. * RESULT
  92. * NONE
  93. *
  94. ******************************************************************************/
  95. DlgWOLLogon::DlgWOLLogon() :
  96. PopupDialogClass(IDD_WOL_LOGON),
  97. mIsPasswordEncrypted(false)
  98. {
  99. WWDEBUG_SAY(("DlgWOLLogon: Instantiated\n"));
  100. }
  101. /******************************************************************************
  102. *
  103. * NAME
  104. * DlgWOLLogon::~DlgWOLLogon
  105. *
  106. * DESCRIPTION
  107. * Destructor
  108. *
  109. * INPUTS
  110. * NONE
  111. *
  112. * RESULT
  113. * NONE
  114. *
  115. ******************************************************************************/
  116. DlgWOLLogon::~DlgWOLLogon()
  117. {
  118. WWDEBUG_SAY(("DlgWOLLogon: Destroyed\n"));
  119. }
  120. /******************************************************************************
  121. *
  122. * NAME
  123. * DlgWOLLogon::FinalizeCreate
  124. *
  125. * DESCRIPTION
  126. * Finalize the creation of this object (Initialize).
  127. *
  128. * INPUTS
  129. *
  130. * RESULT
  131. * Success - True if successful.
  132. *
  133. ******************************************************************************/
  134. bool DlgWOLLogon::FinalizeCreate(const wchar_t* login)
  135. {
  136. mLogin = login;
  137. return true;
  138. }
  139. /******************************************************************************
  140. *
  141. * NAME
  142. * DlgWOLLogon::On_Init_Dialog
  143. *
  144. * DESCRIPTION
  145. * Initialize the dialog.
  146. *
  147. * INPUTS
  148. * NONE
  149. *
  150. * RESULT
  151. * NONE
  152. *
  153. ******************************************************************************/
  154. void DlgWOLLogon::On_Init_Dialog(void)
  155. {
  156. Check_Dlg_Button(IDC_REMEMBER_LOGIN_CHECK, false);
  157. Enable_Dlg_Item(IDC_WOL_LOG_ON_BUTTON, false);
  158. // Limit password length to 8 characters.
  159. EditCtrlClass* edit = (EditCtrlClass*)Get_Dlg_Item(IDC_PASSWORD_EDIT);
  160. if (edit)
  161. {
  162. edit->Set_Text_Limit(8);
  163. }
  164. UpdatePersonas();
  165. SelectPersona(mLogin);
  166. PopupDialogClass::On_Init_Dialog();
  167. }
  168. /******************************************************************************
  169. *
  170. * NAME
  171. * DlgWOLLogon::On_Command
  172. *
  173. * DESCRIPTION
  174. * Handle command notification for the dialog.
  175. *
  176. * INPUTS
  177. * Ctrl - ID of control originating command
  178. * Message - Command message
  179. * Param - Message parameter
  180. *
  181. * RESULT
  182. * NONE
  183. *
  184. ******************************************************************************/
  185. void DlgWOLLogon::On_Command(int ctrl, int message, DWORD param)
  186. {
  187. switch (ctrl)
  188. {
  189. case IDC_WOL_LOG_ON_BUTTON:
  190. {
  191. // If this login is not stored then always use the password typed by the user.
  192. const wchar_t* name = Get_Dlg_Item_Text(IDC_PERSONA_COMBO);
  193. RefPtr<LoginInfo> login = LoginInfo::Find(name);
  194. if (login.IsValid() && !login->IsStored())
  195. {
  196. const wchar_t* password = Get_Dlg_Item_Text(IDC_PASSWORD_EDIT);
  197. login->SetPassword(password, false);
  198. mIsPasswordEncrypted = false;
  199. }
  200. Add_Ref();
  201. DlgWOLLogonEvent event(DlgWOLLogonEvent::Login, *this);
  202. NotifyObservers(event);
  203. Release_Ref();
  204. End_Dialog();
  205. }
  206. break;
  207. case IDC_DELETE_ACCOUNT_BUTTON:
  208. {
  209. // Delete this login from our local cache and purge it from storage.
  210. const WCHAR* nickname = Get_Dlg_Item_Text(IDC_PERSONA_COMBO);
  211. RefPtr<LoginInfo> login = LoginInfo::Find(nickname);
  212. if (login.IsValid())
  213. {
  214. login->Forget(true);
  215. }
  216. // Refresh the UI
  217. UpdatePersonas();
  218. SelectPersona(NULL);
  219. }
  220. break;
  221. case IDC_MANAGE_ACCOUNT_BUTTON:
  222. DlgWebPage::DoDialog("Signup");
  223. break;
  224. case IDC_MENU_BACK_BUTTON:
  225. Add_Ref();
  226. DlgWOLLogonEvent event(DlgWOLLogonEvent::Cancel, *this);
  227. NotifyObservers(event);
  228. Release_Ref();
  229. break;
  230. }
  231. PopupDialogClass::On_Command(ctrl, message, param);
  232. }
  233. /******************************************************************************
  234. *
  235. * NAME
  236. * DlgWOLLogon::GetLogin
  237. *
  238. * DESCRIPTION
  239. * Get the login information.
  240. *
  241. * INPUTS
  242. * Name - On return; Name to login in with.
  243. * Password - On return; Password to login with.
  244. * Encrypted - Flag indicating if the password is encrypted.
  245. *
  246. * RESULT
  247. * NONE
  248. *
  249. ******************************************************************************/
  250. void DlgWOLLogon::GetLogin(const wchar_t** name, const wchar_t** password,
  251. bool& encrypted)
  252. {
  253. if (name)
  254. {
  255. *name = Get_Dlg_Item_Text(IDC_PERSONA_COMBO);
  256. }
  257. if (password)
  258. {
  259. *password = Get_Dlg_Item_Text(IDC_PASSWORD_EDIT);
  260. }
  261. encrypted = mIsPasswordEncrypted;
  262. }
  263. /******************************************************************************
  264. *
  265. * NAME
  266. * DlgWOLLogon::IsRememberLoginChecked
  267. *
  268. * DESCRIPTION
  269. * Get the "checked" state of the remember login checkbox.
  270. *
  271. * INPUTS
  272. * NONE
  273. *
  274. * RESULT
  275. * True if remember login checkbox is selected; false otherwise.
  276. *
  277. ******************************************************************************/
  278. bool DlgWOLLogon::IsRememberLoginChecked(void)
  279. {
  280. return Is_Dlg_Button_Checked(IDC_REMEMBER_LOGIN_CHECK);
  281. }
  282. /******************************************************************************
  283. *
  284. * NAME
  285. * DlgWOLLogon::UpdatePersonas
  286. *
  287. * DESCRIPTION
  288. * Update the persona combo box with cached logins.
  289. *
  290. * INPUTS
  291. * NONE
  292. *
  293. * RESULT
  294. * NONE
  295. *
  296. ******************************************************************************/
  297. void DlgWOLLogon::UpdatePersonas(void)
  298. {
  299. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  300. if (combo)
  301. {
  302. combo->Reset_Content();
  303. const LoginInfoList& personas = LoginInfo::GetList();
  304. const unsigned int count = personas.size();
  305. for (unsigned int index = 0; index < count; ++index)
  306. {
  307. const WideStringClass& name = personas[index]->GetNickname();
  308. combo->Add_String(name);
  309. }
  310. }
  311. }
  312. /******************************************************************************
  313. *
  314. * NAME
  315. * DlgWOLLogon::SelectPersona
  316. *
  317. * DESCRIPTION
  318. * Select the persona with the specified name.
  319. *
  320. * INPUTS
  321. * Name - Name of persona.
  322. *
  323. * RESULT
  324. * NONE
  325. *
  326. ******************************************************************************/
  327. void DlgWOLLogon::SelectPersona(const wchar_t* name)
  328. {
  329. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  330. if (combo)
  331. {
  332. // Select the specified persona or the first one in the list.
  333. if (name && (wcslen(name) > 0))
  334. {
  335. int index = combo->Select_String(name);
  336. // If the persona is not in the list then put it into the edit field
  337. if (index == -1)
  338. {
  339. combo->Set_Text(name);
  340. }
  341. }
  342. else
  343. {
  344. name = combo->Get_Text();
  345. }
  346. AutoComplete(name);
  347. }
  348. }
  349. /******************************************************************************
  350. *
  351. * NAME
  352. * DlgWOLLogon::AutoComplete
  353. *
  354. * DESCRIPTION
  355. * Automatically complete the login dialog fields if an existing login
  356. * matches the provided name.
  357. *
  358. * INPUTS
  359. * Name - Login name to auto complete.
  360. *
  361. * RESULT
  362. * NONE
  363. *
  364. ******************************************************************************/
  365. void DlgWOLLogon::AutoComplete(const wchar_t* name)
  366. {
  367. // If the persona has a valid login then fill in the dialog with
  368. // the login information. Otherwise use the provided persona name.
  369. RefPtr<LoginInfo> login = LoginInfo::Find(name);
  370. if (login.IsValid() && login->IsStored())
  371. {
  372. // Fill in password
  373. const WideStringClass& password = login->GetPassword();
  374. Set_Dlg_Item_Text(IDC_PASSWORD_EDIT, password);
  375. mIsPasswordEncrypted = login->IsPasswordEncrypted();
  376. // WOL passwords must be exactly 8 characters
  377. WWASSERT(password.Get_Length() == 8);
  378. Enable_Dlg_Item(IDC_PASSWORD_EDIT, false);
  379. Check_Dlg_Button(IDC_REMEMBER_LOGIN_CHECK, true);
  380. Enable_Dlg_Item(IDC_REMEMBER_LOGIN_CHECK, false);
  381. Enable_Dlg_Item(IDC_DELETE_ACCOUNT_BUTTON, true);
  382. Enable_Dlg_Item(IDC_WOL_LOG_ON_BUTTON, true);
  383. }
  384. else
  385. {
  386. // Erase the password and enable the remember checkbox
  387. Set_Dlg_Item_Text(IDC_PASSWORD_EDIT, L"");
  388. mIsPasswordEncrypted = false;
  389. Enable_Dlg_Item(IDC_PASSWORD_EDIT, true);
  390. Enable_Dlg_Item(IDC_REMEMBER_LOGIN_CHECK, true);
  391. Enable_Dlg_Item(IDC_DELETE_ACCOUNT_BUTTON, false);
  392. Enable_Dlg_Item(IDC_WOL_LOG_ON_BUTTON, false);
  393. }
  394. }
  395. /******************************************************************************
  396. *
  397. * NAME
  398. * DlgWOLLogon::On_ComboBoxCtrl_Sel_Change
  399. *
  400. * DESCRIPTION
  401. * Notification sent by a combobox when the selection is changed by user
  402. * interaction.
  403. *
  404. * INPUTS
  405. * Combo - Pointer to notifying combobox control.
  406. * ID - ID of notifying combobox control.
  407. * OldSel - Index of previous selection.
  408. * NewSel - Index of new selection.
  409. *
  410. * RESULT
  411. * NONE
  412. *
  413. ******************************************************************************/
  414. void DlgWOLLogon::On_ComboBoxCtrl_Sel_Change(ComboBoxCtrlClass* combo, int id, int, int)
  415. {
  416. if (IDC_PERSONA_COMBO == id)
  417. {
  418. const WCHAR* text = combo->Get_Text();
  419. AutoComplete(text);
  420. }
  421. }
  422. /******************************************************************************
  423. *
  424. * NAME
  425. * DlgWOLLogon::On_ComboBoxCtrl_Edit_Change
  426. *
  427. * DESCRIPTION
  428. * Notification sent by a combobox when the text in the edit field is
  429. * changed by user interaction.
  430. *
  431. * INPUTS
  432. * Combo - Pointer to notifying combobox control.
  433. * ID - ID of notifying combobox control.
  434. *
  435. * RESULT
  436. * NONE
  437. *
  438. ******************************************************************************/
  439. void DlgWOLLogon::On_ComboBoxCtrl_Edit_Change(ComboBoxCtrlClass* combo, int id)
  440. {
  441. if (IDC_PERSONA_COMBO == id)
  442. {
  443. const WCHAR* text = combo->Get_Text();
  444. AutoComplete(text);
  445. }
  446. }
  447. /******************************************************************************
  448. *
  449. * NAME
  450. * DlgWOLLogon::On_EditCtrl_Change
  451. *
  452. * DESCRIPTION
  453. * Notification sent by an edit control when the text in the edit field is
  454. * changed by user interaction.
  455. *
  456. * INPUTS
  457. * Edit - Pointer to notifying edit control.
  458. * ID - ID of notifying edit control.
  459. *
  460. * RESULT
  461. * NONE
  462. *
  463. ******************************************************************************/
  464. void DlgWOLLogon::On_EditCtrl_Change(EditCtrlClass* edit, int id)
  465. {
  466. if (IDC_PASSWORD_EDIT == id)
  467. {
  468. // If the user entered text then password is not encrypted.
  469. mIsPasswordEncrypted = false;
  470. // WOL passwords must be exactly 8 characters
  471. int length = edit->Get_Text_Length();
  472. bool enable = (8 == length);
  473. Enable_Dlg_Item(IDC_WOL_LOG_ON_BUTTON, enable);
  474. }
  475. }
  476. /******************************************************************************
  477. *
  478. * NAME
  479. * DlgWOLLogon::On_EditCtrl_Enter_Pressed
  480. *
  481. * DESCRIPTION
  482. * Notification sent by an edit control that the enter key was pressed.
  483. *
  484. * INPUTS
  485. * Edit - Pointer to notifying edit control.
  486. * ID - ID of notifying edit control.
  487. *
  488. * RESULT
  489. * NONE
  490. *
  491. ******************************************************************************/
  492. void DlgWOLLogon::On_EditCtrl_Enter_Pressed(EditCtrlClass* edit, int id)
  493. {
  494. EditCtrlClass* passwordEdit = (EditCtrlClass*)Get_Dlg_Item(IDC_PASSWORD_EDIT);
  495. if (passwordEdit)
  496. {
  497. const WCHAR* name = Get_Dlg_Item_Text(IDC_PERSONA_COMBO);
  498. bool nameOK = (name && (wcslen(name) > 0));
  499. bool passOK = (passwordEdit->Get_Text_Length() == 8);
  500. if (nameOK && passOK)
  501. {
  502. Add_Ref();
  503. DlgWOLLogonEvent event(DlgWOLLogonEvent::Login, *this);
  504. NotifyObservers(event);
  505. Release_Ref();
  506. End_Dialog();
  507. }
  508. }
  509. }