mpsettingsmgr.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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/mpsettingsmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/06/02 2:58p $*
  29. * *
  30. * $Revision:: 23 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "mpsettingsmgr.h"
  36. #include "registry.h"
  37. #include "bittype.h"
  38. #include "_globals.h"
  39. #include "wwonline\\wolsession.h"
  40. #include <WWOnline\WOLLangCodes.h>
  41. #include "time.h"
  42. ////////////////////////////////////////////////////////////////
  43. // Static member initialization
  44. ////////////////////////////////////////////////////////////////
  45. StringClass MPSettingsMgrClass::SelectedLogin;
  46. StringClass MPSettingsMgrClass::LastLogin;
  47. StringClass MPSettingsMgrClass::AutoLogin;
  48. StringClass MPSettingsMgrClass::AutoPassword;
  49. bool MPSettingsMgrClass::HasMOTDBeenViewed = false;
  50. bool MPSettingsMgrClass::DisplaySidebarHelp = true;
  51. bool MPSettingsMgrClass::IsAutoLoginPromptEnabled = true;
  52. bool MPSettingsMgrClass::AreSkinsUnlocked = false;
  53. #ifdef OBSOLETE
  54. MPSettingsMgrClass::GameModeMap MPSettingsMgrClass::_mModePrefs;
  55. #endif
  56. int MPSettingsMgrClass::OptionFlags = OPTION_DEFAULTS;
  57. ////////////////////////////////////////////////////////////////
  58. // Constants
  59. ////////////////////////////////////////////////////////////////
  60. static const int MAX_PERSONA_LEN = 64;
  61. ////////////////////////////////////////////////////////////////////////////////////////////////
  62. // Registry key names
  63. ////////////////////////////////////////////////////////////////////////////////////////////////
  64. //static const char *QUICKMATCH_SUB_KEY = APPLICATION_SUB_KEY_NAME_WOLSETTINGS "\\QuickMatch";
  65. ////////////////////////////////////////////////////////////////////////////////////////////////
  66. // Registry value names
  67. ////////////////////////////////////////////////////////////////////////////////////////////////
  68. static const char *REG_VALUE_LAST_LOGIN = "LastLogin";
  69. static const char *REG_VALUE_AUTOLOGIN = "AutoLogin";
  70. static const char *REG_VALUE_AUTOPASSWORD = "AutoPassword";
  71. static const char *REG_VALUE_SIDEBAR_HELP = "SidebarHelp";
  72. static const char *REG_VALUE_AUTOLOGIN_PROMPT = "AutoLoginPrompt";
  73. static const char *REG_VALUE_OPTIONS = "Options";
  74. static const char *REG_VALUE_ARE_SKINS_UNLOCKED = "PrimeSocket";
  75. ////////////////////////////////////////////////////////////////
  76. //
  77. // Load_Settings
  78. //
  79. ////////////////////////////////////////////////////////////////
  80. void
  81. MPSettingsMgrClass::Load_Settings (void)
  82. {
  83. //
  84. // Attempt to open the MP settings sub-key
  85. //
  86. RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS, false);
  87. if (registry.Is_Valid ()) {
  88. //
  89. // Read the simple data from the registry
  90. //
  91. registry.Get_String(REG_VALUE_LAST_LOGIN, LastLogin.Get_Buffer(MAX_PERSONA_LEN), MAX_PERSONA_LEN, "");
  92. registry.Get_String(REG_VALUE_AUTOLOGIN, AutoLogin.Get_Buffer(MAX_PERSONA_LEN), MAX_PERSONA_LEN, "");
  93. registry.Get_String(REG_VALUE_AUTOPASSWORD, AutoPassword.Get_Buffer(MAX_PERSONA_LEN), MAX_PERSONA_LEN, "");
  94. DisplaySidebarHelp = registry.Get_Bool (REG_VALUE_SIDEBAR_HELP, true);
  95. IsAutoLoginPromptEnabled = registry.Get_Bool (REG_VALUE_AUTOLOGIN_PROMPT, true);
  96. AreSkinsUnlocked = registry.Get_Bool (REG_VALUE_ARE_SKINS_UNLOCKED, false);
  97. // The default options are language specific
  98. int defaultOptions = OPTION_DEFAULTS;
  99. RegistryClass skuReg(APPLICATION_SUB_KEY_NAME, false);
  100. if (skuReg.Is_Valid()) {
  101. unsigned long sku = skuReg.Get_Int("SKU", RENEGADE_BASE_SKU);
  102. unsigned long lang = (sku & 0xFF);
  103. // If this is not an Asian language region then use the Western defaults
  104. if ((WWOnline::LANGCODE_JAPANESE != lang) && (WWOnline::LANGCODE_KOREAN != lang)
  105. && (WWOnline::LANGCODE_CHINESE != lang)) {
  106. defaultOptions = OPTION_DEFAULTS_LATIN;
  107. }
  108. }
  109. OptionFlags = registry.Get_Int (REG_VALUE_OPTIONS, defaultOptions);
  110. }
  111. return ;
  112. }
  113. ////////////////////////////////////////////////////////////////
  114. //
  115. // Set_Last_Logon
  116. //
  117. ////////////////////////////////////////////////////////////////
  118. void
  119. MPSettingsMgrClass::Set_Last_Login(const char *name)
  120. {
  121. LastLogin = name;
  122. RegistryClass registry(APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  123. if (registry.Is_Valid()) {
  124. registry.Set_String(REG_VALUE_LAST_LOGIN, LastLogin);
  125. }
  126. }
  127. ////////////////////////////////////////////////////////////////
  128. //
  129. // Get_Last_Logon
  130. //
  131. ////////////////////////////////////////////////////////////////
  132. const char*
  133. MPSettingsMgrClass::Get_Last_Login(void)
  134. {
  135. return (const char*)LastLogin;
  136. }
  137. ////////////////////////////////////////////////////////////////
  138. //
  139. // Set_Auto_Login
  140. //
  141. ////////////////////////////////////////////////////////////////
  142. void
  143. MPSettingsMgrClass::Set_Auto_Login(const char* login)
  144. {
  145. AutoLogin = login;
  146. RegistryClass registry(APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  147. if (registry.Is_Valid()) {
  148. registry.Set_String(REG_VALUE_AUTOLOGIN, AutoLogin);
  149. }
  150. }
  151. ////////////////////////////////////////////////////////////////
  152. //
  153. // Get_Auto_Login
  154. //
  155. ////////////////////////////////////////////////////////////////
  156. const char*
  157. MPSettingsMgrClass::Get_Auto_Login(void)
  158. {
  159. return (const char*)AutoLogin;
  160. }
  161. ////////////////////////////////////////////////////////////////
  162. //
  163. // Set_Auto_Password
  164. //
  165. ////////////////////////////////////////////////////////////////
  166. void
  167. MPSettingsMgrClass::Set_Auto_Password(const char* pass)
  168. {
  169. AutoPassword = pass;
  170. RegistryClass registry(APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  171. if (registry.Is_Valid()) {
  172. registry.Set_String(REG_VALUE_AUTOPASSWORD, AutoPassword);
  173. }
  174. }
  175. ////////////////////////////////////////////////////////////////
  176. //
  177. // Get_Auto_Password
  178. //
  179. ////////////////////////////////////////////////////////////////
  180. const char*
  181. MPSettingsMgrClass::Get_Auto_Password(void)
  182. {
  183. return (const char*)AutoPassword;
  184. }
  185. #ifdef OBSOLETE
  186. ////////////////////////////////////////////////////////////////
  187. //
  188. // Get_QuickMatch_Mode_Preference
  189. //
  190. ////////////////////////////////////////////////////////////////
  191. int
  192. MPSettingsMgrClass::Get_QuickMatch_Mode_Preference (const char *mode)
  193. {
  194. GameModeMap::iterator modePref = _mModePrefs.find(mode);
  195. if (modePref == _mModePrefs.end()) {
  196. RegistryClass registry(APPLICATION_SUB_KEY_NAME_QUICKMATCH);
  197. if (registry.Is_Valid()) {
  198. int pref = registry.Get_Int(mode, 10);
  199. _mModePrefs[mode] = pref;
  200. return pref;
  201. }
  202. }
  203. return (*modePref).second;
  204. }
  205. ////////////////////////////////////////////////////////////////
  206. //
  207. // Set_QuickMatch_Mode_Preference
  208. //
  209. ////////////////////////////////////////////////////////////////
  210. void
  211. MPSettingsMgrClass::Set_QuickMatch_Mode_Preference (const char *mode, int preference)
  212. {
  213. _mModePrefs[mode] = preference;
  214. return ;
  215. }
  216. ////////////////////////////////////////////////////////////////
  217. //
  218. // Save_QuickMatch_Mode_Preferences
  219. //
  220. ////////////////////////////////////////////////////////////////
  221. void
  222. MPSettingsMgrClass::Save_QuickMatch_Mode_Preferences (void)
  223. {
  224. RegistryClass registry(APPLICATION_SUB_KEY_NAME_QUICKMATCH);
  225. if (registry.Is_Valid()) {
  226. GameModeMap::iterator iter = _mModePrefs.begin();
  227. while (iter != _mModePrefs.end()) {
  228. registry.Set_Int((*iter).first, (*iter).second);
  229. iter++;
  230. }
  231. }
  232. }
  233. #endif // OBSOLETE
  234. ////////////////////////////////////////////////////////////////
  235. //
  236. // Set_Is_Sidebar_Help_Displayed
  237. //
  238. ////////////////////////////////////////////////////////////////
  239. void
  240. MPSettingsMgrClass::Set_Is_Sidebar_Help_Displayed (bool onoff)
  241. {
  242. DisplaySidebarHelp = onoff;
  243. //
  244. // Attempt to open the MP settings sub-key
  245. //
  246. RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  247. if (registry.Is_Valid ()) {
  248. registry.Set_Bool (REG_VALUE_SIDEBAR_HELP, DisplaySidebarHelp);
  249. }
  250. return ;
  251. }
  252. ////////////////////////////////////////////////////////////////
  253. //
  254. // Enable_Auto_Login_Prompt
  255. //
  256. ////////////////////////////////////////////////////////////////
  257. void
  258. MPSettingsMgrClass::Enable_Auto_Login_Prompt (bool onoff)
  259. {
  260. IsAutoLoginPromptEnabled = onoff;
  261. //
  262. // Attempt to open the MP settings sub-key
  263. //
  264. RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  265. if (registry.Is_Valid ()) {
  266. registry.Set_Bool (REG_VALUE_AUTOLOGIN_PROMPT, IsAutoLoginPromptEnabled);
  267. }
  268. return ;
  269. }
  270. ////////////////////////////////////////////////////////////////
  271. //
  272. // Set_Option_Flag
  273. //
  274. ////////////////////////////////////////////////////////////////
  275. void
  276. MPSettingsMgrClass::Set_Option_Flag (OPTION flag, bool onoff)
  277. {
  278. if (onoff) {
  279. OptionFlags |= flag;
  280. } else {
  281. OptionFlags &= (~flag);
  282. }
  283. //
  284. // Save this setting in the registry
  285. //
  286. RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  287. if (registry.Is_Valid ()) {
  288. registry.Set_Int (REG_VALUE_OPTIONS, OptionFlags);
  289. }
  290. return ;
  291. }
  292. ////////////////////////////////////////////////////////////////
  293. //
  294. // Are_Alternate_Skins_Unlocked
  295. //
  296. ////////////////////////////////////////////////////////////////
  297. bool
  298. MPSettingsMgrClass::Are_Alternate_Skins_Unlocked (void)
  299. {
  300. if (AreSkinsUnlocked == false) {
  301. //
  302. // Do we have a valid WOL session to query?
  303. //
  304. RefPtr<WWOnline::Session> wol_session = WWOnline::Session::GetInstance ();
  305. if (wol_session.IsValid ()) {
  306. //
  307. // First check the insider status of the current user. If that faild, then
  308. // check the server time to see if its past the waiting period.
  309. //
  310. AreSkinsUnlocked = wol_session->IsCurrUserInsider ();
  311. if (AreSkinsUnlocked == false) {
  312. //
  313. // First, build a time structure representing when the skins are unlocked for everybody
  314. //
  315. struct tm expiration_time_struct = { 0 };
  316. expiration_time_struct.tm_year = 102;
  317. expiration_time_struct.tm_mon = 2;
  318. expiration_time_struct.tm_mday = 15;
  319. time_t expire_time = ::mktime (&expiration_time_struct);
  320. //
  321. // Now, do a simple check to see if time has expired
  322. //
  323. AreSkinsUnlocked = (wol_session->GetServerTime () >= expire_time);
  324. }
  325. //
  326. // If we've found out from WOL that the skins are unlocked, then cache
  327. // this information in the registry.
  328. //
  329. if (AreSkinsUnlocked) {
  330. //
  331. // Save this setting in the registry
  332. //
  333. RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
  334. if (registry.Is_Valid ()) {
  335. registry.Set_Bool (REG_VALUE_ARE_SKINS_UNLOCKED, AreSkinsUnlocked);
  336. }
  337. }
  338. } else {
  339. //
  340. // First, build a time structure representing when the skins are unlocked for everybody
  341. //
  342. struct tm expiration_time_struct = { 0 };
  343. expiration_time_struct.tm_year = 102;
  344. expiration_time_struct.tm_mon = 2;
  345. expiration_time_struct.tm_mday = 15;
  346. time_t expire_time = ::mktime (&expiration_time_struct);
  347. //
  348. // Now, simply check to see if time has expired
  349. //
  350. time_t curr_time;
  351. AreSkinsUnlocked = (::time (&curr_time) >= expire_time);
  352. }
  353. }
  354. return AreSkinsUnlocked;
  355. }