DlgWOLSettings.cpp 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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/DlgWOLSettings.cpp $
  22. *
  23. * DESCRIPTION
  24. * Westwood Online Account Settings
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Greg_h $
  29. *
  30. * VERSION INFO
  31. * $Revision: 43 $
  32. * $Modtime: 6/21/02 11:40a $
  33. *
  34. ******************************************************************************/
  35. #include "DlgWOLSettings.h"
  36. #include "UserOptions.h"
  37. #include "RenegadeDialogMgr.h"
  38. #include "MPSettingsMgr.h"
  39. #include "DlgMessageBox.h"
  40. #include "DlgWOLWait.h"
  41. #include "DlgWebPage.h"
  42. #include "WOLLoginProfile.h"
  43. #include "WOLLogonMgr.h"
  44. #include <WWOnline\WOLServer.h>
  45. #include <WWOnline\WOLLoginInfo.h>
  46. #include <WWOnline\PingProfile.h>
  47. #include <WWUI\ComboBoxCtrl.h>
  48. #include <WWUI\ShortcutBarCtrl.h>
  49. #include "bandwidthcheck.h"
  50. #include "Resource.h"
  51. #include "String_ids.h"
  52. #include <WWTranslateDB\TranslateDB.h>
  53. using namespace WWOnline;
  54. /******************************************************************************
  55. *
  56. * NAME
  57. * DlgWOLSettings::DoDialog
  58. *
  59. * DESCRIPTION
  60. * Start Westwood Online settings dialog.
  61. *
  62. * INPUTS
  63. * NONE
  64. *
  65. * RESULT
  66. * True if dialog successfully started.
  67. *
  68. ******************************************************************************/
  69. bool DlgWOLSettings::DoDialog(void)
  70. {
  71. DlgWOLSettings* dialog = new DlgWOLSettings;
  72. if (dialog)
  73. {
  74. if (dialog->FinalizeCreate())
  75. {
  76. dialog->Start_Dialog();
  77. }
  78. dialog->Release_Ref();
  79. }
  80. return (dialog != NULL);
  81. }
  82. /******************************************************************************
  83. *
  84. * NAME
  85. * DlgWOLSettings::DlgWOLSettings
  86. *
  87. * DESCRIPTION
  88. * Constructor
  89. *
  90. * INPUTS
  91. * NONE
  92. *
  93. * RESULT
  94. * NONE
  95. *
  96. ******************************************************************************/
  97. DlgWOLSettings::DlgWOLSettings() :
  98. MenuDialogClass(IDD_WOL_SETTINGS),
  99. DetectingBandwidth(false),
  100. WaitingToExitDialog(false)
  101. {
  102. WWDEBUG_SAY(("DlgWOLSettings: Instantiated\n"));
  103. }
  104. /******************************************************************************
  105. *
  106. * NAME
  107. * DlgWOLSettings::~DlgWOLSettings
  108. *
  109. * DESCRIPTION
  110. * Destructor
  111. *
  112. * INPUTS
  113. * NONE
  114. *
  115. * RESULT
  116. * NONE
  117. *
  118. ******************************************************************************/
  119. DlgWOLSettings::~DlgWOLSettings()
  120. {
  121. WWDEBUG_SAY(("DlgWOLSettings: Destroyed\n"));
  122. }
  123. /******************************************************************************
  124. *
  125. * NAME
  126. * DlgWOLSettings::FinalizeCreate
  127. *
  128. * DESCRIPTION
  129. * Finalize the creation of this object (Initialize).
  130. *
  131. * INPUTS
  132. * NONE
  133. *
  134. * RESULT
  135. * True if successful
  136. *
  137. ******************************************************************************/
  138. bool DlgWOLSettings::FinalizeCreate(void)
  139. {
  140. mWOLSession = Session::GetInstance(false);
  141. return mWOLSession.IsValid();
  142. }
  143. /******************************************************************************
  144. *
  145. * NAME
  146. * DlgWOLSettings::On_Init_Dialog
  147. *
  148. * DESCRIPTION
  149. * Initialize dialog for first time.
  150. *
  151. * INPUTS
  152. * NONE
  153. *
  154. * RESULT
  155. * NONE
  156. *
  157. ******************************************************************************/
  158. void DlgWOLSettings::On_Init_Dialog(void)
  159. {
  160. // Configure the shortcut bar
  161. ShortcutBarCtrlClass* bar = (ShortcutBarCtrlClass*)Get_Dlg_Item(IDC_SHORTCUT_BAR);
  162. if (bar)
  163. {
  164. bar->Add_Button(IDC_MP_SHORTCUT_INTERNET_OPTIONS, TRANSLATE(IDS_INTERNET_OPTIONS));
  165. #ifdef QUICKMATCH_OPTIONS
  166. bar->Add_Button(IDC_MP_SHORTCUT_QUICKMATCH_OPTIONS, TRANSLATE(IDS_MENU_TEXT364));
  167. #endif
  168. bar->Add_Button(IDC_MP_SHORTCUT_NEWS, TRANSLATE(IDS_MP_SHORTCUT_NEWS));
  169. bar->Add_Button(IDC_MP_SHORTCUT_CLANS, TRANSLATE(IDS_MP_SHORTCUT_CLANS));
  170. bar->Add_Button(IDC_MP_SHORTCUT_RANKINGS, TRANSLATE(IDS_MP_SHORTCUT_RANKINGS));
  171. bar->Add_Button(IDC_MP_SHORTCUT_NET_STATUS, TRANSLATE(IDS_MP_SHORTCUT_NET_STATUS));
  172. }
  173. // Initialize combos
  174. InitPersonaCombo();
  175. InitSideCombo();
  176. InitLocaleCombo();
  177. InitConnectionSpeedCombo();
  178. UpdateForPersona();
  179. // Initialize server combos
  180. const IRCServerList& servers = mWOLSession->GetIRCServerList();
  181. // If we already have a list of servers then use those. Otherwise
  182. // request a server list from WOL
  183. if (servers.size() > 0)
  184. {
  185. InitServersCombo(servers);
  186. }
  187. else
  188. {
  189. RefPtr<SerialWait> serverWait = SerialWait::Create();
  190. WWASSERT(serverWait.IsValid());
  191. if (BandwidthCheckerClass::Got_Bandwidth() == 0 && cUserOptions::Get_Bandwidth_Type() == BANDWIDTH_AUTO)
  192. {
  193. DetectingBandwidth = true;
  194. Add_Ref();
  195. RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
  196. serverWait->Add(bandwidth_wait);
  197. }
  198. // Request server list.
  199. WWDEBUG_SAY(("DlgWOLSettings: Requesting ServerList\n"));
  200. RefPtr<WaitCondition> listWait = mWOLSession->GetNewServerList();
  201. serverWait->Add(listWait);
  202. RefPtr<WaitCondition> pingWait = PingProfileWait::Create();
  203. serverWait->Add(pingWait);
  204. RefPtr<WaitCondition> wait(serverWait);
  205. DlgWOLWait::DoDialog(IDS_WOL_SERVERLISTFETCH, wait, this);
  206. }
  207. MenuDialogClass::On_Init_Dialog();
  208. }
  209. /******************************************************************************
  210. *
  211. * NAME
  212. * DlgWOLSettings::On_Destroy
  213. *
  214. * DESCRIPTION
  215. * Handle dialog shutdown.
  216. *
  217. * INPUTS
  218. * NONE
  219. *
  220. * RESULT
  221. * NONE
  222. *
  223. ******************************************************************************/
  224. void DlgWOLSettings::On_Destroy(void)
  225. {
  226. ClearPersonaCombo();
  227. MenuDialogClass::On_Destroy();
  228. }
  229. /******************************************************************************
  230. *
  231. * NAME
  232. * DlgWOLSettings::On_Command
  233. *
  234. * DESCRIPTION
  235. *
  236. * INPUTS
  237. * Ctrl - Control command is from.
  238. * Msg - Command message
  239. * Param - Command parameter
  240. *
  241. * RESULT
  242. * NONE
  243. *
  244. ******************************************************************************/
  245. void DlgWOLSettings::On_Command(int ctrl, int message, DWORD param)
  246. {
  247. switch (ctrl)
  248. {
  249. case IDOK:
  250. {
  251. ComboBoxCtrlClass* connectCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CONNECTION_SPEED_COMBO);
  252. if (connectCombo && BandwidthCheckerClass::Got_Bandwidth() == 0)
  253. {
  254. int sel = connectCombo->Get_Curr_Sel();
  255. if (sel >= 0)
  256. {
  257. BANDWIDTH_TYPE_ENUM bandwidth = min<BANDWIDTH_TYPE_ENUM>((BANDWIDTH_TYPE_ENUM)(sel + BANDWIDTH_FIRST), BANDWIDTH_LAST);
  258. if (bandwidth == BANDWIDTH_AUTO)
  259. {
  260. if (!DetectingBandwidth)
  261. {
  262. RefPtr<SerialWait> serverWait = SerialWait::Create();
  263. WWASSERT(serverWait.IsValid());
  264. DetectingBandwidth = true;
  265. Add_Ref();
  266. RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
  267. DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), bandwidth_wait, this);
  268. WaitingToExitDialog = true;
  269. break;
  270. }
  271. }
  272. }
  273. }
  274. if (SaveSettings())
  275. {
  276. End_Dialog();
  277. }
  278. }
  279. return;
  280. break;
  281. case IDC_DELETE_ACCOUNT_BUTTON:
  282. DeleteSelectedPersona();
  283. break;
  284. case IDC_NEWPERSONA:
  285. DlgWebPage::DoDialog("Signup");
  286. break;
  287. case IDC_CHECK_BANDWIDTH:
  288. if (!DetectingBandwidth)
  289. {
  290. RefPtr<SerialWait> serverWait = SerialWait::Create();
  291. WWASSERT(serverWait.IsValid());
  292. DetectingBandwidth = true;
  293. Add_Ref();
  294. RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
  295. DlgWOLWait::DoDialog(TRANSLATE (IDS_MENU_DETECTING_BANDWIDTH), bandwidth_wait, this);
  296. }
  297. break;
  298. case IDC_AUTOLOGIN_CHECK:
  299. if (param && mWOLSession->IsAutoLoginAllowed())
  300. {
  301. // Get preferred login
  302. WideStringClass name(64, true);
  303. name = Get_Dlg_Item_Text(IDC_PERSONA_COMBO);
  304. // Save preferred login
  305. StringClass saveName(64, true);
  306. name.Convert_To(saveName);
  307. MPSettingsMgrClass::Set_Auto_Login(saveName);
  308. }
  309. else
  310. {
  311. MPSettingsMgrClass::Set_Auto_Login("");
  312. }
  313. break;
  314. case IDC_MENU_BACK_BUTTON:
  315. break;
  316. }
  317. MenuDialogClass::On_Command(ctrl, message, param);
  318. }
  319. /******************************************************************************
  320. *
  321. * NAME
  322. * DlgWOLSettings::SaveSettings
  323. *
  324. * DESCRIPTION
  325. * Save the users settings.
  326. *
  327. * INPUTS
  328. * NONE
  329. *
  330. * RESULT
  331. * True if save successful.
  332. *
  333. ******************************************************************************/
  334. bool DlgWOLSettings::SaveSettings(void)
  335. {
  336. WWDEBUG_SAY(("DlgWOLSettings: Saving settings\n"));
  337. // Save the settings for each login.
  338. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  339. if (combo)
  340. {
  341. int count = combo->Get_Item_Count();
  342. for (int index = 0; index < count; ++index)
  343. {
  344. LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(index);
  345. if (profile)
  346. {
  347. profile->SaveSettings();
  348. }
  349. }
  350. }
  351. // Save connection speed
  352. ComboBoxCtrlClass* connectCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CONNECTION_SPEED_COMBO);
  353. if (connectCombo)
  354. {
  355. int sel = connectCombo->Get_Curr_Sel();
  356. if (sel >= 0)
  357. {
  358. BANDWIDTH_TYPE_ENUM bandwidth = min<BANDWIDTH_TYPE_ENUM>((BANDWIDTH_TYPE_ENUM)(sel + BANDWIDTH_FIRST), BANDWIDTH_LAST);
  359. cUserOptions::Set_Bandwidth_Type(bandwidth);
  360. }
  361. }
  362. return true;
  363. }
  364. /******************************************************************************
  365. *
  366. * NAME
  367. * DlgWOLSettings::InitPersonaCombo
  368. *
  369. * DESCRIPTION
  370. * Initialize the preferred login combo box with the cached WWOnline
  371. * accounts.
  372. *
  373. * INPUTS
  374. * NONE
  375. *
  376. * RESULT
  377. * NONE
  378. *
  379. ******************************************************************************/
  380. void DlgWOLSettings::InitPersonaCombo(void)
  381. {
  382. ClearPersonaCombo();
  383. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  384. if (combo)
  385. {
  386. // Populate the persona combo box with the list of WWOnline logins.
  387. const LoginInfoList& logins = LoginInfo::GetList();
  388. const unsigned int count = logins.size();
  389. for (unsigned int index = 0; index < count; ++index)
  390. {
  391. RefPtr<LoginInfo> login = logins[index];
  392. WWASSERT(login.IsValid());
  393. if (login.IsValid())
  394. {
  395. const WideStringClass& name = login->GetNickname();
  396. int item = combo->Add_String(name);
  397. // Create a profile for each login
  398. if (item >= 0)
  399. {
  400. LoginProfile* profile = LoginProfile::Get(name, true);
  401. combo->Set_Item_Data(item, (uint32)profile);
  402. }
  403. }
  404. }
  405. combo->Set_Curr_Sel(0);
  406. // Select the last login
  407. WideStringClass loginName(64, true);
  408. loginName = MPSettingsMgrClass::Get_Last_Login();
  409. combo->Select_String(loginName);
  410. }
  411. }
  412. /******************************************************************************
  413. *
  414. * NAME
  415. * DlgWOLSettings::ClearPersonaCombo
  416. *
  417. * DESCRIPTION
  418. * Release the personas.
  419. *
  420. * INPUTS
  421. * NONE
  422. *
  423. * RESULT
  424. * NONE
  425. *
  426. ******************************************************************************/
  427. void DlgWOLSettings::ClearPersonaCombo(void)
  428. {
  429. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  430. if (combo)
  431. {
  432. // Release the login profiles
  433. const int count = combo->Get_Item_Count();
  434. for (int index = 0; index < count; ++index)
  435. {
  436. LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(index);
  437. if (profile)
  438. {
  439. profile->Release_Ref();
  440. }
  441. }
  442. combo->Reset_Content();
  443. }
  444. }
  445. /******************************************************************************
  446. *
  447. * NAME
  448. * DlgWOLSettings::DeleteSelectedPersona
  449. *
  450. * DESCRIPTION
  451. * Delete the currently selected persona.
  452. *
  453. * INPUTS
  454. * NONE
  455. *
  456. * RESULT
  457. * NONE
  458. *
  459. ******************************************************************************/
  460. void DlgWOLSettings::DeleteSelectedPersona(void)
  461. {
  462. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  463. if (combo)
  464. {
  465. int sel = combo->Get_Curr_Sel();
  466. if (sel >= 0)
  467. {
  468. const WCHAR* name = combo->Get_Text();
  469. // Delete this login from our local cache and purge it from disk.
  470. RefPtr<LoginInfo> login = LoginInfo::Find(name);
  471. if (login.IsValid())
  472. {
  473. login->Forget(true);
  474. }
  475. // Release the login profile
  476. LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(sel);
  477. if (profile)
  478. {
  479. profile->Release_Ref();
  480. }
  481. // Delete the persistent profile.
  482. LoginProfile::Delete(name);
  483. // Remove the persona from the combo box.
  484. combo->Delete_String(sel);
  485. // Refresh the dialog
  486. UpdateForPersona();
  487. }
  488. }
  489. }
  490. /******************************************************************************
  491. *
  492. * NAME
  493. * DlgWOLSettings::UpdateForPersona
  494. *
  495. * DESCRIPTION
  496. * Update the dialog for the selected persona
  497. *
  498. * INPUTS
  499. * NONE
  500. *
  501. * RESULT
  502. * NONE
  503. *
  504. ******************************************************************************/
  505. void DlgWOLSettings::UpdateForPersona(void)
  506. {
  507. int sel = -1;
  508. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  509. if (combo)
  510. {
  511. sel = combo->Get_Curr_Sel();
  512. if (sel >= 0)
  513. {
  514. // Update the dialog with settings from the persona's profile.
  515. WideStringClass newLogin(64, true);
  516. combo->Get_String(sel, newLogin);
  517. LoginProfile* profile = (LoginProfile*)combo->Get_Item_Data(sel);
  518. // Set dialog to reflect the profile settings
  519. if (profile)
  520. {
  521. SetServerCombo(profile->GetPreferredServer());
  522. SetSideCombo(profile->GetSidePreference());
  523. SetLocaleCombo(profile->GetLocale());
  524. }
  525. else
  526. {
  527. SetServerCombo("");
  528. SetSideCombo(-1);
  529. SetLocaleCombo(WOL::LOC_UNKNOWN);
  530. }
  531. ShowProfileRanking(this, profile);
  532. // Set the autologin checkbox appropriately for this persona.
  533. WideStringClass preferred(64, true);
  534. preferred = MPSettingsMgrClass::Get_Auto_Login();
  535. bool autoLogin = (mWOLSession->IsAutoLoginAllowed() && (newLogin.Compare_No_Case(preferred) == 0));
  536. Check_Dlg_Button(IDC_AUTOLOGIN_CHECK, autoLogin);
  537. // Set the selected login to the persona that is selected.
  538. StringClass loginName(64, true);
  539. newLogin.Convert_To(loginName);
  540. MPSettingsMgrClass::Set_Last_Login(loginName);
  541. }
  542. else
  543. {
  544. SetServerCombo("");
  545. SetSideCombo(-1);
  546. SetLocaleCombo(WOL::LOC_UNKNOWN);
  547. ShowProfileRanking(this, NULL);
  548. }
  549. }
  550. bool isValid = (sel >= 0);
  551. Enable_Dlg_Item(IDC_PERSONA_COMBO, isValid);
  552. Enable_Dlg_Item(IDC_GAMESERVER_COMBO, isValid);
  553. Enable_Dlg_Item(IDC_CHOOSESIDE_COMBO, isValid);
  554. Enable_Dlg_Item(IDC_LOCALE_COMBO, isValid);
  555. Enable_Dlg_Item(IDC_AUTOLOGIN_CHECK, isValid && mWOLSession->IsAutoLoginAllowed());
  556. Enable_Dlg_Item(IDC_DELETE_ACCOUNT_BUTTON, isValid);
  557. }
  558. /******************************************************************************
  559. *
  560. * NAME
  561. * DlgWOLSettings::InitServersCombo
  562. *
  563. * DESCRIPTION
  564. * Initialize server combo boxes
  565. *
  566. * INPUTS
  567. * Servers - List of servers to populate combo with.
  568. *
  569. * RESULT
  570. * NONE
  571. *
  572. ******************************************************************************/
  573. void DlgWOLSettings::InitServersCombo(const IRCServerList& servers)
  574. {
  575. ComboBoxCtrlClass* gameCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_GAMESERVER_COMBO);
  576. if (gameCombo)
  577. {
  578. // Remember current chat selection
  579. WideStringClass gameSelName(0, true);
  580. LoginProfile* profile = GetLoginProfile();
  581. if (profile)
  582. {
  583. gameSelName = profile->GetPreferredServer();
  584. }
  585. int gameSel = -1;
  586. gameCombo->Reset_Content();
  587. // convenience reference for list of ping servers
  588. const PingServerList& pingers = mWOLSession->GetPingServerList();
  589. int bestTime = INT_MAX;
  590. int tmpSel = -1;
  591. // walk the list of servers and add them to the combo box
  592. const unsigned int serverCount = servers.size();
  593. for (unsigned int index = 0; index < serverCount; ++index)
  594. {
  595. const RefPtr<IRCServerData>& server = servers[index];
  596. // Filter out servers that do not have a set of supported languages.
  597. if (server->HasLanguageCode())
  598. {
  599. WideStringClass serverName(0, true);
  600. serverName = server->GetName();
  601. int pos = gameCombo->Add_String(serverName);
  602. // Now, figure out which one to pick
  603. // they haven't picked a preferred server
  604. if (gameSelName.Is_Empty())
  605. {
  606. // lets pick a default server for them!
  607. if (server->MatchesLanguageCode())
  608. {
  609. float serverLong = server->GetLongitude();
  610. float serverLat = server->GetLattitude();
  611. // Find the ping server with the best time that matches this server's lat/long
  612. const unsigned int pingersCount = pingers.size();
  613. for (unsigned int pingindex = 0; pingindex < pingersCount; ++pingindex)
  614. {
  615. const RefPtr<PingServerData>& thisPing = pingers[pingindex];
  616. float pingLong = thisPing->GetLongitude();
  617. float pingLat = thisPing->GetLattitude();
  618. // make sure the ping server is associated with the chat server
  619. if (serverLong == pingLong && serverLat == pingLat)
  620. {
  621. int pingTime = thisPing->GetPingTime();
  622. // sanity check
  623. if (pingTime == -1)
  624. {
  625. pingTime = INT_MAX;
  626. }
  627. // here's our main test! Find the best ping time
  628. if (pingTime < bestTime)
  629. {
  630. bestTime = pingTime;
  631. tmpSel = pos;
  632. }
  633. }
  634. } // end for each ping server
  635. }
  636. }
  637. // If this is their preferred server
  638. else if ((gameSelName.Compare_No_Case(serverName) == 0) && (gameSel == -1))
  639. {
  640. gameSel = pos; // they picked one, and this is it!
  641. gameCombo->Set_Curr_Sel(pos);
  642. if (profile)
  643. {
  644. profile->SetPreferredServer(server->GetName());
  645. }
  646. }
  647. } // if server has a langcode - sanity check
  648. }
  649. if ((gameSel == -1) && (tmpSel != -1))
  650. {
  651. gameSel = tmpSel;
  652. gameCombo->Set_Curr_Sel(tmpSel);
  653. }
  654. } // if valid gameCombo box
  655. }
  656. /******************************************************************************
  657. *
  658. * NAME
  659. * DlgWOLSettings::SetServerCombo
  660. *
  661. * DESCRIPTION
  662. * Set the server combo to the specified server.
  663. *
  664. * INPUTS
  665. * Name - Server to set server combo to.
  666. *
  667. * RESULT
  668. * NONE
  669. *
  670. ******************************************************************************/
  671. void DlgWOLSettings::SetServerCombo(const char* serverName)
  672. {
  673. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_GAMESERVER_COMBO);
  674. if (combo)
  675. {
  676. WWDEBUG_SAY(("ServerCombo = %s\n", serverName));
  677. WideStringClass name(64, true);
  678. name = serverName;
  679. int sel = combo->Select_String(name);
  680. if (sel == -1)
  681. {
  682. RefPtr<IRCServerData> defaultServer = WOLLogonMgr::GetDefaultServer();
  683. if (defaultServer.IsValid())
  684. {
  685. name = defaultServer->GetName();
  686. combo->Select_String(name);
  687. }
  688. else
  689. {
  690. combo->Set_Curr_Sel(0);
  691. }
  692. }
  693. }
  694. }
  695. /******************************************************************************
  696. *
  697. * NAME
  698. * DlgWOLSettings::InitSideCombo
  699. *
  700. * DESCRIPTION
  701. *
  702. * INPUTS
  703. * NONE
  704. *
  705. * RESULT
  706. * NONE
  707. *
  708. ******************************************************************************/
  709. void DlgWOLSettings::InitSideCombo(void)
  710. {
  711. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CHOOSESIDE_COMBO);
  712. if (combo)
  713. {
  714. //(gth) Renegade day 120 Patch: re-translate these strings each time!
  715. struct {const wchar_t* TeamName; int TeamID;} _teams[] =
  716. {
  717. {TRANSLATE (IDS_MENU_RANDOM), -1},
  718. {TRANSLATE (IDS_MENU_TEXT933), 1},
  719. {TRANSLATE (IDS_MENU_TEXT934), 0},
  720. {NULL, -1},
  721. };
  722. int index = 0;
  723. while (_teams[index].TeamName != NULL)
  724. {
  725. int item = combo->Add_String(_teams[index].TeamName);
  726. if (item >= 0)
  727. {
  728. combo->Set_Item_Data(item, (uint32)_teams[index].TeamID);
  729. }
  730. ++index;
  731. }
  732. }
  733. // Selected current logins preference
  734. int side = -1;
  735. LoginProfile* profile = GetLoginProfile();
  736. if (profile)
  737. {
  738. side = profile->GetSidePreference();
  739. }
  740. SetSideCombo(side);
  741. }
  742. /******************************************************************************
  743. *
  744. * NAME
  745. * DlgWOLSettings::SetSideCombo
  746. *
  747. * DESCRIPTION
  748. *
  749. * INPUTS
  750. *
  751. * RESULT
  752. * NONE
  753. *
  754. ******************************************************************************/
  755. void DlgWOLSettings::SetSideCombo(int side)
  756. {
  757. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CHOOSESIDE_COMBO);
  758. if (combo)
  759. {
  760. const int count = combo->Get_Item_Count();
  761. for (int index = 0; index < count; ++index)
  762. {
  763. if (combo->Get_Item_Data(index) == (uint32)side)
  764. {
  765. combo->Set_Curr_Sel(index);
  766. break;
  767. }
  768. }
  769. }
  770. }
  771. /******************************************************************************
  772. *
  773. * NAME
  774. * DlgWOLSettings::InitLocaleCombo
  775. *
  776. * DESCRIPTION
  777. * Update the locale combo box with the selectable WWOnline locales.
  778. *
  779. * INPUTS
  780. * NONE
  781. *
  782. * RESULT
  783. * NONE
  784. *
  785. ******************************************************************************/
  786. void DlgWOLSettings::InitLocaleCombo(void)
  787. {
  788. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_LOCALE_COMBO);
  789. if (combo)
  790. {
  791. combo->Reset_Content();
  792. std::vector<WideStringClass> localeNames;
  793. mWOLSession->GetLocaleStrings(localeNames);
  794. const unsigned int localeCount = localeNames.size();
  795. for (unsigned int index = 0; index < localeCount; ++index)
  796. {
  797. WideStringClass& locale = localeNames[index];
  798. combo->Add_String(locale);
  799. }
  800. int locale = WOL::LOC_UNKNOWN;
  801. LoginProfile* profile = GetLoginProfile();
  802. if (profile)
  803. {
  804. locale = profile->GetLocale();
  805. }
  806. combo->Set_Curr_Sel(locale);
  807. }
  808. }
  809. /******************************************************************************
  810. *
  811. * NAME
  812. * DlgWOLSettings::SetLocaleCombo
  813. *
  814. * DESCRIPTION
  815. *
  816. * INPUTS
  817. * Name - Persona to set locale for.
  818. *
  819. * RESULT
  820. * NONE
  821. *
  822. ******************************************************************************/
  823. void DlgWOLSettings::SetLocaleCombo(WOL::Locale locale)
  824. {
  825. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_LOCALE_COMBO);
  826. if (combo)
  827. {
  828. WWDEBUG_SAY(("LocaleCombo = %ld\n", locale));
  829. combo->Set_Curr_Sel((int)locale);
  830. }
  831. }
  832. /******************************************************************************
  833. *
  834. * NAME
  835. * DlgWOLSettings::InitConnectionSpeedCombo
  836. *
  837. * DESCRIPTION
  838. *
  839. * INPUTS
  840. * NONE
  841. *
  842. * RESULT
  843. * NONE
  844. *
  845. ******************************************************************************/
  846. void DlgWOLSettings::InitConnectionSpeedCombo(void)
  847. {
  848. // Configure the connection type combobox
  849. ComboBoxCtrlClass* connectCombo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_CONNECTION_SPEED_COMBO);
  850. if (connectCombo)
  851. {
  852. connectCombo->Reset_Content();
  853. connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_288));
  854. connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_336));
  855. connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_56));
  856. connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_ISDN));
  857. connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_CABLE));
  858. connectCombo->Add_String(TRANSLATE(IDS_MP_CONNECTION_T1));
  859. WideStringClass auto_set_str(256, true);
  860. if (BandwidthCheckerClass::Get_Reported_Upstream_Bandwidth())
  861. {
  862. auto_set_str.Format(TRANSLATE (IDS_MENU_AUTO_FORMAT), BandwidthCheckerClass::Get_Bandwidth_As_String());
  863. }
  864. else
  865. {
  866. auto_set_str.Format(TRANSLATE (IDS_MENU_AUTO));
  867. }
  868. connectCombo->Add_String(auto_set_str);
  869. // Set the current selection
  870. connectCombo->Set_Curr_Sel(cUserOptions::Get_Bandwidth_Type() - BANDWIDTH_FIRST);
  871. connectCombo->Set_Dirty(true);
  872. }
  873. }
  874. /******************************************************************************
  875. *
  876. * NAME
  877. * DlgWOLSettings::On_ComboBoxCtrl_Sel_Change
  878. *
  879. * DESCRIPTION
  880. *
  881. * INPUTS
  882. *
  883. * RESULT
  884. * NONE
  885. *
  886. ******************************************************************************/
  887. void DlgWOLSettings::On_ComboBoxCtrl_Sel_Change(ComboBoxCtrlClass* combo, int ctrl,
  888. int oldSel, int newSel)
  889. {
  890. switch (ctrl)
  891. {
  892. case IDC_PERSONA_COMBO:
  893. UpdateForPersona();
  894. break;
  895. case IDC_GAMESERVER_COMBO:
  896. {
  897. LoginProfile* profile = GetLoginProfile();
  898. if (profile)
  899. {
  900. // Save selected game server
  901. WideStringClass name(64, true);
  902. combo->Get_String(newSel, name);
  903. StringClass saveName(64, true);
  904. name.Convert_To(saveName);
  905. profile->SetPreferredServer(saveName);
  906. }
  907. }
  908. break;
  909. case IDC_CHOOSESIDE_COMBO:
  910. {
  911. LoginProfile* profile = GetLoginProfile();
  912. if (profile)
  913. {
  914. int side = combo->Get_Item_Data(newSel);
  915. profile->SetSidePreference(side);
  916. }
  917. }
  918. break;
  919. case IDC_LOCALE_COMBO:
  920. {
  921. LoginProfile* profile = GetLoginProfile();
  922. if (profile)
  923. {
  924. profile->SetLocale((WOL::Locale)newSel);
  925. }
  926. }
  927. break;
  928. default:
  929. break;
  930. }
  931. }
  932. /******************************************************************************
  933. *
  934. * NAME
  935. * DlgWOLSettings::HandleNotification(DlgWOLWaitEvent)
  936. *
  937. * DESCRIPTION
  938. *
  939. * INPUTS
  940. *
  941. * RESULT
  942. * NONE
  943. *
  944. ******************************************************************************/
  945. void DlgWOLSettings::HandleNotification(DlgWOLWaitEvent& event)
  946. {
  947. if (WaitCondition::ConditionMet == event.Result())
  948. {
  949. if (DetectingBandwidth)
  950. {
  951. DetectingBandwidth = false;
  952. cUserOptions::Set_Bandwidth_Type(BANDWIDTH_AUTO);
  953. // Re-init the connection speed combo.
  954. InitConnectionSpeedCombo();
  955. Release_Ref();
  956. if (WaitingToExitDialog)
  957. {
  958. if (SaveSettings())
  959. {
  960. End_Dialog();
  961. return;
  962. }
  963. }
  964. }
  965. // Check if we got the server list.
  966. const IRCServerList& servers = mWOLSession->GetIRCServerList();
  967. if (servers.size())
  968. {
  969. InitServersCombo(servers);
  970. }
  971. }
  972. else if (DetectingBandwidth == false)
  973. {
  974. Enable_Dlg_Item(IDC_GAMESERVER_COMBO, false);
  975. }
  976. }
  977. /******************************************************************************
  978. *
  979. * NAME
  980. * DlgWOLSettings::GetLoginProfile
  981. *
  982. * DESCRIPTION
  983. *
  984. * INPUTS
  985. * NONE
  986. *
  987. * RESULT
  988. *
  989. ******************************************************************************/
  990. LoginProfile* DlgWOLSettings::GetLoginProfile(void)
  991. {
  992. ComboBoxCtrlClass* combo = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_PERSONA_COMBO);
  993. if (combo)
  994. {
  995. int sel = combo->Get_Curr_Sel();
  996. if (sel >= 0)
  997. {
  998. return (LoginProfile*)combo->Get_Item_Data(sel);
  999. }
  1000. }
  1001. return NULL;
  1002. }