WOL2Dialog.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Installer *
  23. * *
  24. * $Archive:: /Commando/Code/Installer/WOL2Dialog.cp $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 11/24/01 9:27p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // Includes.
  36. #include "WOL2Dialog.h"
  37. #include "Installer.h"
  38. #include "ListCtrl.h"
  39. #include "Resource.h"
  40. #include "Translator.h"
  41. // Defines.
  42. #define ENCRYPTED_STRING_LENGTH 8
  43. /***********************************************************************************************
  44. * WOL2DialogClass::On_Init_Dialog -- *
  45. * *
  46. * INPUT: *
  47. * *
  48. * OUTPUT: *
  49. * *
  50. * WARNINGS: *
  51. * *
  52. * HISTORY: *
  53. * 08/22/01 IML : Created. *
  54. *=============================================================================================*/
  55. void WOL2DialogClass::On_Init_Dialog (void)
  56. {
  57. ListCtrlClass *listctrl;
  58. unsigned i;
  59. WideStringClass name, password;
  60. // Get the list of nicknames.
  61. listctrl = Get_Dlg_Item (IDC_WOL2_LIST)->As_ListCtrlClass();
  62. listctrl->Add_Column (L"", 1.0f, Vector3 (1.0f, 1.0f, 1.0f));
  63. i = 0;
  64. while (_Installer.Get_WOL_Account (i, name, password)) {
  65. listctrl->Insert_Entry (i, name);
  66. i++;
  67. }
  68. // Select the topmost item.
  69. listctrl->Set_Curr_Sel (0);
  70. }
  71. /***********************************************************************************************
  72. * WOL2DialogClass::On_Command -- *
  73. * *
  74. * INPUT: *
  75. * *
  76. * OUTPUT: *
  77. * *
  78. * WARNINGS: *
  79. * *
  80. * HISTORY: *
  81. * 08/22/01 IML : Created. *
  82. *=============================================================================================*/
  83. void WOL2DialogClass::On_Command (int ctrl_id, int message_id, DWORD param)
  84. {
  85. switch (ctrl_id) {
  86. case IDCANCEL:
  87. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  88. return;
  89. case IDOK:
  90. {
  91. ListCtrlClass *listctrl;
  92. WideStringClass userpassword (Get_Dlg_Item_Text (IDC_WOL2_EDIT));
  93. WideStringClass accountname, accountpassword;
  94. StringClass encrypteduserpassword;
  95. // Verify that the user password is the correct length.
  96. if (userpassword.Get_Length() != ENCRYPTED_STRING_LENGTH) {
  97. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_INVALID_PASSWORD), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  98. return;
  99. }
  100. // Verify that the user password is alphanumeric ie. do not allow any punctuation or Asian characters.
  101. for (int i = 0; i < userpassword.Get_Length(); i++) {
  102. if (!iswalnum (userpassword [i])) {
  103. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_INVALID_PASSWORD), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  104. return;
  105. }
  106. }
  107. // Verify that the user password is correct for the selected account name.
  108. listctrl = Get_Dlg_Item (IDC_WOL2_LIST)->As_ListCtrlClass();
  109. _Installer.Get_WOL_Account (listctrl->Get_Curr_Sel(), accountname, accountpassword);
  110. Encrypt_Password (StringClass (userpassword), encrypteduserpassword);
  111. if (accountpassword.Compare (WideStringClass (encrypteduserpassword)) != 0) {
  112. MessageBoxClass::Do_Dialog (TxWideStringClass (IDS_WARNING), TxWideStringClass (IDS_INCORRECT_PASSWORD), MessageBoxClass::MESSAGE_BOX_TYPE_OK, this);
  113. return;
  114. }
  115. _Installer.Set_Preferred_WOL_Account (accountname);
  116. break;
  117. }
  118. }
  119. InstallMenuDialogClass::On_Command (ctrl_id, message_id, param);
  120. }
  121. /***********************************************************************************************
  122. * WOL2DialogClass::Encrypt_Password -- *
  123. * *
  124. * INPUT: *
  125. * *
  126. * OUTPUT: *
  127. * *
  128. * WARNINGS: *
  129. * *
  130. * HISTORY: *
  131. * 08/22/01 IML : Created. *
  132. *=============================================================================================*/
  133. StringClass &WOL2DialogClass::Encrypt_Password (const StringClass &password, StringClass &encryptedpassword)
  134. {
  135. const static char _basestring [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
  136. char tempbuffer [ENCRYPTED_STRING_LENGTH + 1];
  137. unsigned upcnt = 0, dncnt = 0, cnt = 0;
  138. WWASSERT (password.Get_Length() == ENCRYPTED_STRING_LENGTH);
  139. for (upcnt = 0, dncnt = ENCRYPTED_STRING_LENGTH; upcnt < ENCRYPTED_STRING_LENGTH; upcnt++, dncnt--) {
  140. if (*(password.Peek_Buffer() + upcnt) & 0x01) {
  141. tempbuffer [upcnt] = (*(password.Peek_Buffer() + upcnt) << (*(password.Peek_Buffer() + upcnt) & 0x01)) & *(password.Peek_Buffer() + dncnt);
  142. } else {
  143. tempbuffer [upcnt] = (*(password.Peek_Buffer() + upcnt) << (*(password.Peek_Buffer() + upcnt) & 0x01)) ^ *(password.Peek_Buffer() + dncnt);
  144. }
  145. }
  146. encryptedpassword.Get_Buffer (ENCRYPTED_STRING_LENGTH + 1);
  147. for (cnt = 0; cnt < ENCRYPTED_STRING_LENGTH; cnt++) {
  148. *(encryptedpassword.Peek_Buffer() + cnt) = _basestring [tempbuffer [cnt] & 0x3f];
  149. }
  150. *(encryptedpassword.Peek_Buffer() + cnt) = '\0';
  151. return (encryptedpassword);
  152. }