dlgmpwolmain.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgmpwolmain.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/11/02 8:57p $*
  29. * *
  30. * $Revision:: 46 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgmpwolmain.h"
  36. #include "shortcutbarctrl.h"
  37. #include "renegadedialogmgr.h"
  38. #include "translatedb.h"
  39. #include "string_ids.h"
  40. #include "dialogmgr.h"
  41. #include "dlgmessagebox.h"
  42. #include "dlgdownload.h"
  43. #include "dlgquickmatch.h"
  44. #include "dlgmpwolgamelist.h"
  45. #include "mpsettingsmgr.h"
  46. #include "dlgsidebarhelp.h"
  47. #include "WOLLoginProfile.h"
  48. #include "bandwidthcheck.h"
  49. #include "autostart.h"
  50. ////////////////////////////////////////////////////////////////
  51. // Static member initialization
  52. ////////////////////////////////////////////////////////////////
  53. MPWolMainMenuClass * MPWolMainMenuClass::_TheInstance = NULL;
  54. ////////////////////////////////////////////////////////////////
  55. //
  56. // MPWolMainMenuClass
  57. //
  58. ////////////////////////////////////////////////////////////////
  59. MPWolMainMenuClass::MPWolMainMenuClass (void) :
  60. IsSidebarHelpPending (true),
  61. mPendingCmd(-1),
  62. MenuDialogClass (IDD_MP_WOL_MAIN)
  63. {
  64. _TheInstance = this;
  65. return ;
  66. }
  67. ////////////////////////////////////////////////////////////////
  68. //
  69. // ~MPWolMainMenuClass
  70. //
  71. ////////////////////////////////////////////////////////////////
  72. MPWolMainMenuClass::~MPWolMainMenuClass (void)
  73. {
  74. _TheInstance = NULL;
  75. return ;
  76. }
  77. ////////////////////////////////////////////////////////////////
  78. //
  79. // On_Init_Dialog
  80. //
  81. ////////////////////////////////////////////////////////////////
  82. void
  83. MPWolMainMenuClass::On_Init_Dialog (void)
  84. {
  85. //
  86. // Configure the shortcut bar
  87. //
  88. ShortcutBarCtrlClass *bar = (ShortcutBarCtrlClass *)Get_Dlg_Item (IDC_SHORTCUT_BAR);
  89. if (bar != NULL) {
  90. bar->Add_Button(IDC_MP_SHORTCUT_BUDDIES, TRANSLATE(IDS_MP_SHORTCUT_BUDDIES));
  91. bar->Add_Button(IDC_MP_SHORTCUT_INTERNET_OPTIONS, TRANSLATE(IDS_INTERNET_OPTIONS));
  92. #ifdef QUICKMATCH_OPTIONS
  93. bar->Add_Button(IDC_MP_SHORTCUT_QUICKMATCH_OPTIONS, TRANSLATE(IDS_MENU_TEXT364));
  94. #endif
  95. bar->Add_Button(IDC_MP_SHORTCUT_NEWS, TRANSLATE(IDS_MP_SHORTCUT_NEWS));
  96. bar->Add_Button(IDC_MP_SHORTCUT_CLANS, TRANSLATE(IDS_MP_SHORTCUT_CLANS));
  97. bar->Add_Button(IDC_MP_SHORTCUT_RANKINGS, TRANSLATE(IDS_MP_SHORTCUT_RANKINGS));
  98. bar->Add_Button(IDC_MP_SHORTCUT_ACCOUNT, TRANSLATE(IDS_MP_SHORTCUT_ACCOUNT));
  99. bar->Add_Button(IDC_MP_SHORTCUT_NET_STATUS, TRANSLATE(IDS_MP_SHORTCUT_NET_STATUS));
  100. //
  101. // Force the bar to be displayed
  102. //
  103. if (MPSettingsMgrClass::Is_Sidebar_Help_Displayed ()) {
  104. bar->Display (true);
  105. }
  106. }
  107. MenuDialogClass::On_Init_Dialog ();
  108. bool wolValid = CheckWOLVersion();
  109. if (!wolValid) {
  110. DlgMsgBox::DoDialog(IDS_WOL_ERROR, IDS_WOL_WRONGVERSION);
  111. End_Dialog();
  112. }
  113. }
  114. // Check the version of the Westwood online component
  115. bool MPWolMainMenuClass::CheckWOLVersion(void)
  116. {
  117. RefPtr<WWOnline::Session> wolSession = WWOnline::Session::GetInstance(false);
  118. if (!wolSession.IsValid()) {
  119. return false;
  120. }
  121. // WOLAPI version 1.19.3 or better required.
  122. const LONG minVersion = MAKELONG(19,1);
  123. const LONG minBuild = MAKELONG(0,3);
  124. unsigned long wolVersion = 0;
  125. unsigned long wolBuild = 0;
  126. wolSession->GetChatObject()->GetVersion(&wolVersion);
  127. WideStringClass wolText(255, true);
  128. if (BandwidthCheckerClass::Get_Reported_Upstream_Bandwidth()) {
  129. WideStringClass conn(BandwidthCheckerClass::Get_Bandwidth_As_String(), true);
  130. wolText.Format(TRANSLATE(IDS_MENU_CONNECTION_SPEED_FORMAT), conn);
  131. }
  132. WideStringClass string(0, true);
  133. string.Format(L"WOLAPI V%u.%u", HIWORD(wolVersion), LOWORD(wolVersion));
  134. wolText += string;
  135. char buildString[32] = {0};
  136. LPCSTR value = (LPCSTR)(&buildString[0]);
  137. HRESULT hr = wolSession->GetChatObject()->GetAttributeValue("BuildNumber", &value);
  138. if (SUCCEEDED(hr)) {
  139. wolBuild = atol(buildString);
  140. string.Format(L".%u", HIWORD(wolBuild));
  141. wolText += string;
  142. }
  143. Set_Dlg_Item_Text(IDC_WOLAPI_VER, wolText);
  144. // Are we below the minimum version
  145. if (wolVersion < minVersion) {
  146. return false;
  147. }
  148. // If the version is the same then are we below the minimum build
  149. if ((wolVersion == minVersion) && (wolBuild < minBuild)) {
  150. return false;
  151. }
  152. return true;
  153. }
  154. ////////////////////////////////////////////////////////////////
  155. //
  156. // On_Frame_Update
  157. //
  158. ////////////////////////////////////////////////////////////////
  159. void
  160. MPWolMainMenuClass::On_Frame_Update (void)
  161. {
  162. if (IsSidebarHelpPending) {
  163. IsSidebarHelpPending = false;
  164. //
  165. // Show the sidebar help (if necessary)
  166. //
  167. if (MPSettingsMgrClass::Is_Sidebar_Help_Displayed ()) {
  168. START_DIALOG (SidebarHelpDialogClass);
  169. }
  170. }
  171. MenuDialogClass::On_Frame_Update ();
  172. return ;
  173. }
  174. ////////////////////////////////////////////////////////////////
  175. //
  176. // On_Command
  177. //
  178. ////////////////////////////////////////////////////////////////
  179. void
  180. MPWolMainMenuClass::On_Command (int ctrl_id, int message_id, DWORD param)
  181. {
  182. switch (ctrl_id)
  183. {
  184. case IDC_MP_WOL_QUICK_MATCH_BUTTON:
  185. case IDC_MP_WOL_ADVANCED_LISTINGS_BUTTON: // intentional fall through
  186. case IDC_MP_SHORTCUT_CHAT: // intentional fall through
  187. case IDC_MP_SHORTCUT_BUDDIES: // intentional fall through
  188. mPendingCmd = ctrl_id;
  189. WOLLogonMgr::Logon(this);
  190. return;
  191. break;
  192. }
  193. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  194. return ;
  195. }
  196. void MPWolMainMenuClass::HandleNotification(WOLLogonAction& action)
  197. {
  198. if (WOLLOGON_SUCCESS == action) {
  199. switch (mPendingCmd) {
  200. case IDC_MP_WOL_ADVANCED_LISTINGS_BUTTON:
  201. MPWolGameListMenuClass::DoDialog();
  202. break;
  203. case IDC_MP_WOL_QUICK_MATCH_BUTTON:
  204. DlgQuickMatch::DoDialog();
  205. break;
  206. case -1:
  207. break;
  208. default:
  209. MenuDialogClass::On_Command(mPendingCmd, 0, 0);
  210. break;
  211. }
  212. } else if (WOLLOGON_PATCHREQUIRED == action) {
  213. // If a patch is required, ask the user if they want to download it now.
  214. DlgMsgBox::DoDialog(TRANSLATE(IDS_WOL_PATCHREQUIRED),
  215. TRANSLATE(IDS_WOL_DOWNLOADPROMPT), DlgMsgBox::YesNo, this);
  216. }
  217. mPendingCmd = -1;
  218. }
  219. void MPWolMainMenuClass::HandleNotification(DlgMsgBoxEvent& event)
  220. {
  221. if (DlgMsgBoxEvent::Yes == event.Event()) {
  222. RefPtr<WWOnline::Session> wolSession = WWOnline::Session::GetInstance(false);
  223. WWOnline::DownloadList& patchList = wolSession->GetPatchDownloadList();
  224. bool quiet = AutoRestart.Is_Active();
  225. DlgDownload::DoDialog(TRANSLATE(IDS_WOL_DOWNLOAD), patchList, quiet);
  226. }
  227. }
  228. ////////////////////////////////////////////////////////////////
  229. //
  230. // Display
  231. //
  232. ////////////////////////////////////////////////////////////////
  233. void
  234. MPWolMainMenuClass::Display (void)
  235. {
  236. //
  237. // Create the dialog if necessary, otherwise simply bring it to the front
  238. //
  239. if (_TheInstance == NULL) {
  240. START_DIALOG (MPWolMainMenuClass);
  241. } else {
  242. if (_TheInstance->Is_Active_Menu () == false) {
  243. DialogMgrClass::Rollback (_TheInstance);
  244. }
  245. }
  246. return ;
  247. }
  248. ////////////////////////////////////////////////////////////////
  249. //
  250. // On_Activate
  251. //
  252. ////////////////////////////////////////////////////////////////
  253. void
  254. MPWolMainMenuClass::On_Activate(bool onoff)
  255. {
  256. MenuDialogClass::On_Activate(onoff);
  257. if (onoff) {
  258. Update_Login_Profile();
  259. WOLLogonMgr::Logoff();
  260. }
  261. }
  262. ////////////////////////////////////////////////////////////////
  263. //
  264. // On_Last_Menu_Ending
  265. //
  266. ////////////////////////////////////////////////////////////////
  267. void
  268. MPWolMainMenuClass::On_Last_Menu_Ending (void)
  269. {
  270. RenegadeDialogMgrClass::Goto_Location (RenegadeDialogMgrClass::LOC_MAIN_MENU);
  271. return ;
  272. }
  273. ////////////////////////////////////////////////////////////////
  274. //
  275. // Update_Login_Profile
  276. //
  277. ////////////////////////////////////////////////////////////////
  278. void
  279. MPWolMainMenuClass::Update_Login_Profile(void)
  280. {
  281. WideStringClass lastlogin(64, true);
  282. lastlogin = MPSettingsMgrClass::Get_Last_Login();
  283. LoginProfile* profile = LoginProfile::Get(lastlogin);
  284. ShowProfileRanking(this, profile);
  285. if (profile) {
  286. profile->Release_Ref();
  287. }
  288. }