| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : Combat *
- * *
- * $Archive:: /Commando/Code/Commando/mpsettingsmgr.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 2/06/02 2:58p $*
- * *
- * $Revision:: 23 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "mpsettingsmgr.h"
- #include "registry.h"
- #include "bittype.h"
- #include "_globals.h"
- #include "wwonline\\wolsession.h"
- #include <WWOnline\WOLLangCodes.h>
- #include "time.h"
- ////////////////////////////////////////////////////////////////
- // Static member initialization
- ////////////////////////////////////////////////////////////////
- StringClass MPSettingsMgrClass::SelectedLogin;
- StringClass MPSettingsMgrClass::LastLogin;
- StringClass MPSettingsMgrClass::AutoLogin;
- StringClass MPSettingsMgrClass::AutoPassword;
- bool MPSettingsMgrClass::HasMOTDBeenViewed = false;
- bool MPSettingsMgrClass::DisplaySidebarHelp = true;
- bool MPSettingsMgrClass::IsAutoLoginPromptEnabled = true;
- bool MPSettingsMgrClass::AreSkinsUnlocked = false;
- #ifdef OBSOLETE
- MPSettingsMgrClass::GameModeMap MPSettingsMgrClass::_mModePrefs;
- #endif
- int MPSettingsMgrClass::OptionFlags = OPTION_DEFAULTS;
- ////////////////////////////////////////////////////////////////
- // Constants
- ////////////////////////////////////////////////////////////////
- static const int MAX_PERSONA_LEN = 64;
- ////////////////////////////////////////////////////////////////////////////////////////////////
- // Registry key names
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //static const char *QUICKMATCH_SUB_KEY = APPLICATION_SUB_KEY_NAME_WOLSETTINGS "\\QuickMatch";
- ////////////////////////////////////////////////////////////////////////////////////////////////
- // Registry value names
- ////////////////////////////////////////////////////////////////////////////////////////////////
- static const char *REG_VALUE_LAST_LOGIN = "LastLogin";
- static const char *REG_VALUE_AUTOLOGIN = "AutoLogin";
- static const char *REG_VALUE_AUTOPASSWORD = "AutoPassword";
- static const char *REG_VALUE_SIDEBAR_HELP = "SidebarHelp";
- static const char *REG_VALUE_AUTOLOGIN_PROMPT = "AutoLoginPrompt";
- static const char *REG_VALUE_OPTIONS = "Options";
- static const char *REG_VALUE_ARE_SKINS_UNLOCKED = "PrimeSocket";
- ////////////////////////////////////////////////////////////////
- //
- // Load_Settings
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Load_Settings (void)
- {
- //
- // Attempt to open the MP settings sub-key
- //
- RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS, false);
- if (registry.Is_Valid ()) {
- //
- // Read the simple data from the registry
- //
- registry.Get_String(REG_VALUE_LAST_LOGIN, LastLogin.Get_Buffer(MAX_PERSONA_LEN), MAX_PERSONA_LEN, "");
- registry.Get_String(REG_VALUE_AUTOLOGIN, AutoLogin.Get_Buffer(MAX_PERSONA_LEN), MAX_PERSONA_LEN, "");
- registry.Get_String(REG_VALUE_AUTOPASSWORD, AutoPassword.Get_Buffer(MAX_PERSONA_LEN), MAX_PERSONA_LEN, "");
- DisplaySidebarHelp = registry.Get_Bool (REG_VALUE_SIDEBAR_HELP, true);
- IsAutoLoginPromptEnabled = registry.Get_Bool (REG_VALUE_AUTOLOGIN_PROMPT, true);
- AreSkinsUnlocked = registry.Get_Bool (REG_VALUE_ARE_SKINS_UNLOCKED, false);
- // The default options are language specific
- int defaultOptions = OPTION_DEFAULTS;
- RegistryClass skuReg(APPLICATION_SUB_KEY_NAME, false);
- if (skuReg.Is_Valid()) {
- unsigned long sku = skuReg.Get_Int("SKU", RENEGADE_BASE_SKU);
- unsigned long lang = (sku & 0xFF);
- // If this is not an Asian language region then use the Western defaults
- if ((WWOnline::LANGCODE_JAPANESE != lang) && (WWOnline::LANGCODE_KOREAN != lang)
- && (WWOnline::LANGCODE_CHINESE != lang)) {
- defaultOptions = OPTION_DEFAULTS_LATIN;
- }
- }
- OptionFlags = registry.Get_Int (REG_VALUE_OPTIONS, defaultOptions);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_Last_Logon
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Set_Last_Login(const char *name)
- {
- LastLogin = name;
- RegistryClass registry(APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid()) {
- registry.Set_String(REG_VALUE_LAST_LOGIN, LastLogin);
- }
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Last_Logon
- //
- ////////////////////////////////////////////////////////////////
- const char*
- MPSettingsMgrClass::Get_Last_Login(void)
- {
- return (const char*)LastLogin;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_Auto_Login
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Set_Auto_Login(const char* login)
- {
- AutoLogin = login;
- RegistryClass registry(APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid()) {
- registry.Set_String(REG_VALUE_AUTOLOGIN, AutoLogin);
- }
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Auto_Login
- //
- ////////////////////////////////////////////////////////////////
- const char*
- MPSettingsMgrClass::Get_Auto_Login(void)
- {
- return (const char*)AutoLogin;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_Auto_Password
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Set_Auto_Password(const char* pass)
- {
- AutoPassword = pass;
- RegistryClass registry(APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid()) {
- registry.Set_String(REG_VALUE_AUTOPASSWORD, AutoPassword);
- }
- }
- ////////////////////////////////////////////////////////////////
- //
- // Get_Auto_Password
- //
- ////////////////////////////////////////////////////////////////
- const char*
- MPSettingsMgrClass::Get_Auto_Password(void)
- {
- return (const char*)AutoPassword;
- }
- #ifdef OBSOLETE
- ////////////////////////////////////////////////////////////////
- //
- // Get_QuickMatch_Mode_Preference
- //
- ////////////////////////////////////////////////////////////////
- int
- MPSettingsMgrClass::Get_QuickMatch_Mode_Preference (const char *mode)
- {
- GameModeMap::iterator modePref = _mModePrefs.find(mode);
- if (modePref == _mModePrefs.end()) {
- RegistryClass registry(APPLICATION_SUB_KEY_NAME_QUICKMATCH);
- if (registry.Is_Valid()) {
- int pref = registry.Get_Int(mode, 10);
- _mModePrefs[mode] = pref;
- return pref;
- }
- }
- return (*modePref).second;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_QuickMatch_Mode_Preference
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Set_QuickMatch_Mode_Preference (const char *mode, int preference)
- {
- _mModePrefs[mode] = preference;
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Save_QuickMatch_Mode_Preferences
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Save_QuickMatch_Mode_Preferences (void)
- {
- RegistryClass registry(APPLICATION_SUB_KEY_NAME_QUICKMATCH);
- if (registry.Is_Valid()) {
- GameModeMap::iterator iter = _mModePrefs.begin();
- while (iter != _mModePrefs.end()) {
- registry.Set_Int((*iter).first, (*iter).second);
- iter++;
- }
- }
- }
- #endif // OBSOLETE
- ////////////////////////////////////////////////////////////////
- //
- // Set_Is_Sidebar_Help_Displayed
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Set_Is_Sidebar_Help_Displayed (bool onoff)
- {
- DisplaySidebarHelp = onoff;
- //
- // Attempt to open the MP settings sub-key
- //
- RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid ()) {
- registry.Set_Bool (REG_VALUE_SIDEBAR_HELP, DisplaySidebarHelp);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Enable_Auto_Login_Prompt
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Enable_Auto_Login_Prompt (bool onoff)
- {
- IsAutoLoginPromptEnabled = onoff;
- //
- // Attempt to open the MP settings sub-key
- //
- RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid ()) {
- registry.Set_Bool (REG_VALUE_AUTOLOGIN_PROMPT, IsAutoLoginPromptEnabled);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Set_Option_Flag
- //
- ////////////////////////////////////////////////////////////////
- void
- MPSettingsMgrClass::Set_Option_Flag (OPTION flag, bool onoff)
- {
- if (onoff) {
- OptionFlags |= flag;
- } else {
- OptionFlags &= (~flag);
- }
- //
- // Save this setting in the registry
- //
- RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid ()) {
- registry.Set_Int (REG_VALUE_OPTIONS, OptionFlags);
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////
- //
- // Are_Alternate_Skins_Unlocked
- //
- ////////////////////////////////////////////////////////////////
- bool
- MPSettingsMgrClass::Are_Alternate_Skins_Unlocked (void)
- {
- if (AreSkinsUnlocked == false) {
-
- //
- // Do we have a valid WOL session to query?
- //
- RefPtr<WWOnline::Session> wol_session = WWOnline::Session::GetInstance ();
- if (wol_session.IsValid ()) {
- //
- // First check the insider status of the current user. If that faild, then
- // check the server time to see if its past the waiting period.
- //
- AreSkinsUnlocked = wol_session->IsCurrUserInsider ();
- if (AreSkinsUnlocked == false) {
-
- //
- // First, build a time structure representing when the skins are unlocked for everybody
- //
- struct tm expiration_time_struct = { 0 };
- expiration_time_struct.tm_year = 102;
- expiration_time_struct.tm_mon = 2;
- expiration_time_struct.tm_mday = 15;
- time_t expire_time = ::mktime (&expiration_time_struct);
- //
- // Now, do a simple check to see if time has expired
- //
- AreSkinsUnlocked = (wol_session->GetServerTime () >= expire_time);
- }
- //
- // If we've found out from WOL that the skins are unlocked, then cache
- // this information in the registry.
- //
- if (AreSkinsUnlocked) {
-
- //
- // Save this setting in the registry
- //
- RegistryClass registry (APPLICATION_SUB_KEY_NAME_WOLSETTINGS);
- if (registry.Is_Valid ()) {
- registry.Set_Bool (REG_VALUE_ARE_SKINS_UNLOCKED, AreSkinsUnlocked);
- }
- }
- } else {
- //
- // First, build a time structure representing when the skins are unlocked for everybody
- //
- struct tm expiration_time_struct = { 0 };
- expiration_time_struct.tm_year = 102;
- expiration_time_struct.tm_mon = 2;
- expiration_time_struct.tm_mday = 15;
- time_t expire_time = ::mktime (&expiration_time_struct);
- //
- // Now, simply check to see if time has expired
- //
- time_t curr_time;
- AreSkinsUnlocked = (::time (&curr_time) >= expire_time);
- }
- }
- return AreSkinsUnlocked;
- }
|