WOLLogonMgr.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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/WOLLogonMgr.cpp $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * Denzil E. Long, Jr.
  27. * $Author: Tom_s $
  28. *
  29. * VERSION INFO
  30. * $Revision: 59 $
  31. * $Modtime: 2/11/02 4:07p $
  32. *
  33. ******************************************************************************/
  34. #include "WOLLogonMgr.h"
  35. #include "MPSettingsMgr.h"
  36. #include "DlgMessageBox.h"
  37. #include "DlgWOLWait.h"
  38. #include "DlgMPWOLMain.h"
  39. #include "DlgMPWOLAutoLoginPrompt.h"
  40. #include "DlgMPWOLmotd.h"
  41. #include "WOLLoginProfile.h"
  42. #include "WOLLocaleMgr.h"
  43. #include "NetInterface.h"
  44. #include "nat.h"
  45. #include "FirewallWait.h"
  46. #include "BandwidthCheck.h"
  47. #include <WWOnline\WOLLoginInfo.h>
  48. #include <WWOnline\WOLServer.h>
  49. #include <WWOnline\WOLLoginInfo.h>
  50. #include <WWOnline\WaitCondition.h>
  51. #include <WWOnline\PingProfile.h>
  52. #include "string_ids.h"
  53. #include <WWTranslateDB\TranslateDB.h>
  54. #include <WWDebug\WWDebug.h>
  55. #include "UserOptions.h"
  56. #include "autostart.h"
  57. #include "consolemode.h"
  58. #include "specialbuilds.h"
  59. #include "serversettings.h"
  60. using namespace WWOnline;
  61. bool WOLLogonMgr::mQuietMode = false;
  62. /******************************************************************************
  63. *
  64. * NAME
  65. * WOLLogonMgr::Logon
  66. *
  67. * DESCRIPTION
  68. * Log on to Westwood Online
  69. *
  70. * INPUTS
  71. * ServerType - Type of server to log onto.
  72. * Observer - Logon observer
  73. *
  74. * RESULT
  75. * NONE
  76. *
  77. ******************************************************************************/
  78. void WOLLogonMgr::Logon(Observer<WOLLogonAction>* observer)
  79. {
  80. WWDEBUG_SAY(("WOLLogonMgr: Logon\n"));
  81. WOLLogonMgr* logon = new WOLLogonMgr;
  82. if (logon)
  83. {
  84. if (observer)
  85. {
  86. logon->AddObserver(*observer);
  87. }
  88. logon->InitiateLogon(false);
  89. logon->Release_Ref();
  90. }
  91. }
  92. /******************************************************************************
  93. *
  94. * NAME
  95. * WOLLogonMgr::Logoff
  96. *
  97. * DESCRIPTION
  98. * Log the current user off of Westwood Online.
  99. *
  100. * INPUTS
  101. * NONE
  102. *
  103. * RESULT
  104. * NONE
  105. *
  106. ******************************************************************************/
  107. void WOLLogonMgr::Logoff(void)
  108. {
  109. WWDEBUG_SAY(("WOLLogonMgr: Logoff\n"));
  110. RefPtr<Session> wolSession = Session::GetInstance(false);
  111. if (wolSession.IsValid())
  112. {
  113. ConnectionStatus status = wolSession->GetConnectionStatus();
  114. // If we are connected then disconnected now
  115. if (ConnectionConnected == status || ConnectionConnecting == status)
  116. {
  117. RefPtr<WaitCondition> wait = wolSession->Logout();
  118. DlgWOLWait::DoDialog(IDS_WOL_LOGOFF, wait);
  119. }
  120. }
  121. }
  122. /******************************************************************************
  123. *
  124. * NAME
  125. * WOLLogonMgr::GetLoginName
  126. *
  127. * DESCRIPTION
  128. * Get name of the logged in user.
  129. *
  130. * INPUTS
  131. * Name - On return; name of user.
  132. *
  133. * RESULT
  134. * True if logged in otherwise false.
  135. *
  136. ******************************************************************************/
  137. bool WOLLogonMgr::GetLoginName(WideStringClass& name)
  138. {
  139. RefPtr<Session> wolSession = Session::GetInstance(false);
  140. if (wolSession.IsValid())
  141. {
  142. const RefPtr<LoginInfo>& login = wolSession->GetCurrentLogin();
  143. if (login.IsValid())
  144. {
  145. name = login->GetNickname();
  146. return true;
  147. }
  148. }
  149. return false;
  150. }
  151. /******************************************************************************
  152. *
  153. * NAME
  154. * WOLLogonMgr::GetServerName
  155. *
  156. * DESCRIPTION
  157. * Get name of the server logged onto.
  158. *
  159. * INPUTS
  160. * Name - On return; name of the server connected to.
  161. *
  162. * RESULT
  163. * True if connected to server.
  164. *
  165. ******************************************************************************/
  166. bool WOLLogonMgr::GetServerName(WideStringClass& name)
  167. {
  168. RefPtr<Session> wolSession = Session::GetInstance(false);
  169. if (wolSession.IsValid())
  170. {
  171. const RefPtr<IRCServerData>& server = wolSession->GetCurrentServer();
  172. if (server.IsValid())
  173. {
  174. name = server->GetName();
  175. return true;
  176. }
  177. }
  178. return false;
  179. }
  180. /******************************************************************************
  181. *
  182. * NAME
  183. * WOLLogonMgr::GetDefaultServer
  184. *
  185. * DESCRIPTION
  186. * Retrieve the default server for the client.
  187. *
  188. * INPUTS
  189. * ServerType - Type of server to get default for.
  190. *
  191. * RESULT
  192. * Server -
  193. *
  194. ******************************************************************************/
  195. RefPtr<IRCServerData> WOLLogonMgr::GetDefaultServer(void)
  196. {
  197. RefPtr<Session> wolSession = Session::GetInstance(false);
  198. if (!wolSession.IsValid())
  199. {
  200. return NULL;
  201. }
  202. // Find the server closets to us.
  203. RefPtr<IRCServerData> server;
  204. int bestTime = INT_MAX;
  205. const IRCServerList& serverList = wolSession->GetIRCServerList();
  206. const PingServerList& pingers = wolSession->GetPingServerList();
  207. const unsigned int numServers = serverList.size();
  208. for (unsigned int index = 0; index < numServers; ++index)
  209. {
  210. const RefPtr<IRCServerData>& thisServer = serverList[index];
  211. // check that chat server matches game client lang code
  212. if (thisServer->MatchesLanguageCode())
  213. {
  214. float serverLong = thisServer->GetLongitude();
  215. float serverLat = thisServer->GetLattitude();
  216. // Find the ping server with the best time.
  217. for (unsigned int pingindex = 0; pingindex < pingers.size(); pingindex++)
  218. {
  219. const RefPtr<PingServerData>& thisPing = pingers[pingindex];
  220. float pingLong = thisPing->GetLongitude();
  221. float pingLat = thisPing->GetLattitude();
  222. // make sure the ping server is associated with the chat server
  223. if (serverLong == pingLong && serverLat == pingLat)
  224. {
  225. int pingTime = thisPing->GetPingTime();
  226. // sanity check
  227. if (pingTime == -1)
  228. {
  229. pingTime = INT_MAX;
  230. }
  231. // here's our main test! Find the best ping time
  232. if (pingTime <= bestTime)
  233. {
  234. bestTime = pingTime;
  235. server = thisServer;
  236. }
  237. }
  238. }
  239. }
  240. else
  241. {
  242. // If we haven't found a match then use the first server that has
  243. // a language specification.
  244. if (!server.IsValid() && thisServer->HasLanguageCode())
  245. {
  246. server = thisServer;
  247. }
  248. }
  249. }
  250. return server;
  251. }
  252. /******************************************************************************
  253. *
  254. * NAME
  255. * WOLLogonMgr::ConfigureSession
  256. *
  257. * DESCRIPTION
  258. * Configure the WWOnline session with the users options.
  259. *
  260. * INPUTS
  261. * NONE
  262. *
  263. * RESULT
  264. * NONE
  265. *
  266. ******************************************************************************/
  267. void WOLLogonMgr::ConfigureSession(void)
  268. {
  269. RefPtr<Session> wolSession = Session::GetInstance(false);
  270. if (wolSession.IsValid())
  271. {
  272. if (ConnectionConnected == wolSession->GetConnectionStatus())
  273. {
  274. bool allowFind = MPSettingsMgrClass::Get_Option_Flag(MPSettingsMgrClass::OPTION_ALLOW_FIND);
  275. bool allowPages = MPSettingsMgrClass::Get_Option_Flag(MPSettingsMgrClass::OPTION_ALLOW_PAGES);
  276. wolSession->AllowFindPage(allowFind, allowPages);
  277. bool filterBadLang = MPSettingsMgrClass::Get_Option_Flag(MPSettingsMgrClass::OPTION_LANGUAGE_FILTER);
  278. wolSession->SetBadLanguageFilter(filterBadLang);
  279. }
  280. }
  281. }
  282. /******************************************************************************
  283. *
  284. * NAME
  285. * WOLLogonMgr::WOLLogonMgr
  286. *
  287. * DESCRIPTION
  288. * Constructor
  289. *
  290. * INPUTS
  291. * NONE
  292. *
  293. * RESULT
  294. * NONE
  295. *
  296. ******************************************************************************/
  297. WOLLogonMgr::WOLLogonMgr() :
  298. mState(DISCONNECTED),
  299. mRememberLogin(true),
  300. mPasswordEncrypted(false)
  301. {
  302. WWDEBUG_SAY(("WOLLogonMgr: Instantiated\n"));
  303. //---------------------------------------------------------------------------
  304. // Get the default login to use.
  305. //---------------------------------------------------------------------------
  306. mLoginName = MPSettingsMgrClass::Get_Auto_Login();
  307. // If there isn't a auto login then use the last login.
  308. if (mLoginName.Is_Empty())
  309. {
  310. mLoginName = MPSettingsMgrClass::Get_Last_Login();
  311. }
  312. #ifndef FREEDEDICATEDSERVER
  313. if (AutoRestart.Is_Active())
  314. #endif //FREEDEDICATEDSERVER
  315. {
  316. mPassword = MPSettingsMgrClass::Get_Auto_Password();
  317. }
  318. // Get WOL session
  319. mWOLSession = Session::GetInstance(false);
  320. WWASSERT_PRINT(mWOLSession.IsValid(), "WOLSession not instantiated!");
  321. Observer<ServerError>::NotifyMe(*mWOLSession);
  322. }
  323. /******************************************************************************
  324. *
  325. * NAME
  326. * WOLLogonMgr::~WOLLogonMgr
  327. *
  328. * DESCRIPTION
  329. * Destructor
  330. *
  331. * INPUTS
  332. * NONE
  333. *
  334. * RESULT
  335. * NONE
  336. *
  337. ******************************************************************************/
  338. WOLLogonMgr::~WOLLogonMgr()
  339. {
  340. WWDEBUG_SAY(("WOLLogonMgr: Destroyed\n"));
  341. }
  342. /******************************************************************************
  343. *
  344. * NAME
  345. * WOLLogonMgr::IsConnectedToServer
  346. *
  347. * DESCRIPTION
  348. * Check if a user is connected to a server.
  349. *
  350. * INPUTS
  351. * Login - User to check.
  352. * Server - Server to check.
  353. *
  354. * RESULT
  355. * True if user is connected to the specified server.
  356. *
  357. ******************************************************************************/
  358. bool WOLLogonMgr::IsConnectedToServer(const wchar_t* login, RefPtr<IRCServerData>& server)
  359. {
  360. if (!mWOLSession.IsValid())
  361. {
  362. return false;
  363. }
  364. // Check connection
  365. ConnectionStatus status = mWOLSession->GetConnectionStatus();
  366. // Check login
  367. bool loginOk = IsUserLoggedIn(login);
  368. // Check server
  369. bool serverOk = false;
  370. if (server.IsValid())
  371. {
  372. RefPtr<IRCServerData> curServer = mWOLSession->GetCurrentServer();
  373. serverOk = (curServer.IsValid() && (server == curServer));
  374. }
  375. return ((status == ConnectionConnected) && loginOk && serverOk);
  376. }
  377. /******************************************************************************
  378. *
  379. * NAME
  380. * WOLLogonMgr::IsUserLoggedIn
  381. *
  382. * DESCRIPTION
  383. * Check if a user is logged in.
  384. *
  385. * INPUTS
  386. * Login - User to check.
  387. *
  388. * RESULT
  389. * True if user is logged in.
  390. *
  391. ******************************************************************************/
  392. bool WOLLogonMgr::IsUserLoggedIn(const wchar_t* login)
  393. {
  394. if (!mWOLSession.IsValid())
  395. {
  396. return false;
  397. }
  398. // Check connection
  399. ConnectionStatus status = mWOLSession->GetConnectionStatus();
  400. // Check login
  401. bool loginOk = false;
  402. if (login)
  403. {
  404. RefPtr<LoginInfo> curLogin = mWOLSession->GetCurrentLogin();
  405. if (curLogin.IsValid())
  406. {
  407. loginOk = (curLogin->GetNickname().Compare_No_Case(login) == 0);
  408. }
  409. }
  410. return ((status == ConnectionConnected) && loginOk);
  411. }
  412. /******************************************************************************
  413. *
  414. * NAME
  415. * WOLLogonMgr::IsAutoLogin
  416. *
  417. * DESCRIPTION
  418. * Check if login should automatically logon.
  419. *
  420. * INPUTS
  421. * Login - Name of login to check for autologon
  422. *
  423. * RESULT
  424. * True if this login should auto logon
  425. *
  426. ******************************************************************************/
  427. bool WOLLogonMgr::IsAutoLogin(const wchar_t* login)
  428. {
  429. if (mWOLSession->IsAutoLoginAllowed())
  430. {
  431. WideStringClass autoName(64, true);
  432. autoName = MPSettingsMgrClass::Get_Auto_Login();
  433. return (autoName.Compare_No_Case(login) == 0);
  434. }
  435. return false;
  436. }
  437. /******************************************************************************
  438. *
  439. * NAME
  440. * WOLLogonMgr::GetPreferredServer
  441. *
  442. * DESCRIPTION
  443. * Get the users preferred server to connect to.
  444. *
  445. * INPUTS
  446. * Type - Type of server to obtain.
  447. *
  448. * RESULT
  449. * Server - Preferred server if provided.
  450. *
  451. ******************************************************************************/
  452. RefPtr<IRCServerData> WOLLogonMgr::GetPreferredServer(const wchar_t* login)
  453. {
  454. const char* preferred = "";
  455. #ifdef FREEDEDICATEDSERVER
  456. preferred = ServerSettingsClass::Get_Preferred_Server(mWOLSession->GetIRCServerList());
  457. #else //FREEDEDICATEDSERVER
  458. // Get the user's preferred server if available.
  459. LoginProfile* profile = LoginProfile::Get(login);
  460. if (profile)
  461. {
  462. preferred = profile->GetPreferredServer();
  463. profile->Release_Ref();
  464. }
  465. #endif //FREEDEDICATEDSERVER
  466. // Find the preferred server
  467. RefPtr<IRCServerData> server;
  468. const IRCServerList& serverList = mWOLSession->GetIRCServerList();
  469. for (unsigned int index = 0; index < serverList.size(); index++)
  470. {
  471. const RefPtr<IRCServerData>& thisServer = serverList[index];
  472. const char* name = thisServer->GetName();
  473. WWASSERT(name != NULL && "NULL server name");
  474. if (preferred && (stricmp(preferred, name) == 0))
  475. {
  476. server = thisServer;
  477. break;
  478. }
  479. }
  480. return server;
  481. }
  482. /******************************************************************************
  483. *
  484. * NAME
  485. * WOLLogonMgr::RememberLogin
  486. *
  487. * DESCRIPTION
  488. * Store the last successful login
  489. *
  490. * INPUTS
  491. * NONE
  492. *
  493. * RESULT
  494. * NONE
  495. *
  496. ******************************************************************************/
  497. void WOLLogonMgr::RememberLogin(void)
  498. {
  499. // Get the successful login.
  500. const RefPtr<LoginInfo>& currentLogin = mWOLSession->GetCurrentLogin();
  501. if (currentLogin.IsValid())
  502. {
  503. // Set login name as the network nickname.
  504. const WideStringClass& nickname = currentLogin->GetNickname();
  505. WWASSERT(nickname.Get_Length() > 0);
  506. cNetInterface::Set_Nickname((WideStringClass&)nickname);
  507. // Set the name of the last successful login
  508. StringClass lastname(64, true);
  509. nickname.Convert_To(lastname);
  510. MPSettingsMgrClass::Set_Last_Login((const char*)lastname);
  511. // Remember the login preferences
  512. LoginProfile* profile = LoginProfile::Get(nickname, true);
  513. LoginProfile::SetCurrent(profile);
  514. // Remember this login
  515. currentLogin->Remember(mRememberLogin);
  516. // Store login information to disk
  517. if (mRememberLogin)
  518. {
  519. // Save preferences for this login
  520. if (profile)
  521. {
  522. profile->SaveSettings();
  523. }
  524. // Should we display the auto-login prompt
  525. bool autoLoginAllowed = (!mQuietMode && mWOLSession->IsAutoLoginAllowed());
  526. if (autoLoginAllowed && MPSettingsMgrClass::Is_Auto_Login_Prompt_Enabled())
  527. {
  528. MPWolAutoLoginPromptDialogClass* dialog = new MPWolAutoLoginPromptDialogClass;
  529. WWASSERT(dialog);
  530. if (dialog)
  531. {
  532. dialog->Start_Dialog();
  533. REF_PTR_RELEASE(dialog);
  534. }
  535. }
  536. }
  537. if (profile)
  538. {
  539. profile->Release_Ref();
  540. }
  541. }
  542. }
  543. /******************************************************************************
  544. *
  545. * NAME
  546. * WOLLogonMgr::HasServerList
  547. *
  548. * DESCRIPTION
  549. * Check if there is a server list.
  550. *
  551. * INPUTS
  552. * NONE
  553. *
  554. * RESULT
  555. * True if valid server list is available
  556. *
  557. ******************************************************************************/
  558. bool WOLLogonMgr::HasServerList(void)
  559. {
  560. const IRCServerList& servers = mWOLSession->GetIRCServerList();
  561. return (servers.size() > 0);
  562. }
  563. /******************************************************************************
  564. *
  565. * NAME
  566. * WOLLogonMgr::HasValidPings
  567. *
  568. * DESCRIPTION
  569. * Check if there are valid location pings available.
  570. *
  571. * INPUTS
  572. * NONE
  573. *
  574. * RESULT
  575. * True if valid location pings are available.
  576. *
  577. ******************************************************************************/
  578. bool WOLLogonMgr::HasValidPings(void)
  579. {
  580. const PingServerList& pingers = mWOLSession->GetPingServerList();
  581. unsigned int count = pingers.size();
  582. for (unsigned int index = 0; index < count; ++index)
  583. {
  584. int pingTime = pingers[index]->GetPingTime();
  585. // If a ping time is -1 then we dont have valid pings
  586. if (pingTime == -1)
  587. {
  588. return false;
  589. }
  590. }
  591. return (count != 0);
  592. }
  593. /******************************************************************************
  594. *
  595. * NAME
  596. * WOLLogonMgr::InitiateLogon
  597. *
  598. * DESCRIPTION
  599. * Start logon sequence.
  600. *
  601. * INPUTS
  602. * Forced - Attempt to logon with current persona.
  603. *
  604. * RESULT
  605. * NONE
  606. *
  607. ******************************************************************************/
  608. void WOLLogonMgr::InitiateLogon(bool forced)
  609. {
  610. WWDEBUG_SAY(("WOLLogonMgr: Initiating logon sequence\n"));
  611. // Make sure WWOnline session is active.
  612. if (!mWOLSession.IsValid())
  613. {
  614. WWDEBUG_SAY(("WOLLogonMgr: Error - WWOnline session not initialized!\n"));
  615. DlgMsgBox::DoDialog(IDS_WOL_LOGONFAILED, IDS_WOL_NOTINITIALIZED);
  616. return;
  617. }
  618. // Do bandwidth detection if needed.
  619. if (BandwidthCheckerClass::Got_Bandwidth() == false && cUserOptions::Get_Bandwidth_Type() == BANDWIDTH_AUTO)
  620. {
  621. WWDEBUG_SAY(("WOLLogonMgr: Detecting bandwidth...\n"));
  622. mState = DETECTING_BANDWIDTH;
  623. // Detect the bandwidth.
  624. RefPtr<WaitCondition> bandwidth_wait = BandwidthCheckerClass::Detect();
  625. bool detecting = DlgWOLWait::DoDialog(TRANSLATE(IDS_MENU_DETECTING_BANDWIDTH), bandwidth_wait, this, 0, mQuietMode ? 0xffffffff : 0);
  626. if (detecting)
  627. {
  628. Add_Ref();
  629. }
  630. return;
  631. }
  632. //---------------------------------------------------------------------------
  633. // Make sure we have a server list. If we don't then request it before allowing
  634. // logon to continue.
  635. //
  636. // Note: The IRCServerList notification will reinitiate the logon when the
  637. // server list is obtained.
  638. //---------------------------------------------------------------------------
  639. if (HasServerList() == false)
  640. {
  641. WWDEBUG_SAY(("WOLLogonMgr: Fetching server list...\n"));
  642. mState = FETCHING_SERVERLIST;
  643. // Request a server list. If a patch is available the serverlist request will
  644. // fail with a ServerError notification of CHAT_E_MUSTPATH. See the ServerError
  645. // notification handler.
  646. RefPtr<WaitCondition> fetch = mWOLSession->GetNewServerList();
  647. bool fetching = DlgWOLWait::DoDialog(IDS_WOL_LOGON, fetch, this, 0, mQuietMode ? 0xffffffff : 0);
  648. // If fetching server list then keep alive while we are waiting.
  649. if (fetching)
  650. {
  651. Add_Ref();
  652. }
  653. return;
  654. }
  655. // Get a server to logon to.
  656. RefPtr<IRCServerData> server = GetPreferredServer(mLoginName);
  657. if (server.IsValid() == false)
  658. {
  659. // Before we can pick a default server we must first have valid server pings.
  660. if (HasValidPings() == false)
  661. {
  662. WWDEBUG_SAY(("WOLLogonMgr: Waiting on server pings...\n"));
  663. mState = WAITING_PINGS;
  664. // Request a server list.
  665. RefPtr<WaitCondition> pings = PingProfileWait::Create();
  666. bool pinging = DlgWOLWait::DoDialog(IDS_WOL_LOGON, pings, this, 0, mQuietMode ? 0xffffffff : 0);
  667. // If waiting for pings then keep alive
  668. if (pinging)
  669. {
  670. Add_Ref();
  671. }
  672. return;
  673. }
  674. // Choose a default server
  675. server = GetDefaultServer();
  676. }
  677. ConsoleBox.Print("Logging onto %s\n", server->GetName());
  678. // Check if the user is already logged onto the requested server.
  679. if (IsConnectedToServer(mLoginName, server))
  680. {
  681. WWDEBUG_SAY(("WOLLogonMgr: User already connected.\n"));
  682. mState = CONNECTED;
  683. Add_Ref();
  684. WOLLogonAction action = WOLLOGON_SUCCESS;
  685. NotifyObservers(action);
  686. Release_Ref();
  687. return;
  688. }
  689. //---------------------------------------------------------------------------
  690. // Show the logon dialog if:
  691. // 1) Not forcing a logon.
  692. // 2) The user is not logged in to another server and auto logon is off.
  693. // 3) The login information is invalid.
  694. //---------------------------------------------------------------------------
  695. bool loggedIn = IsUserLoggedIn(mLoginName);
  696. bool autoLogin = IsAutoLogin(mLoginName);
  697. if (!forced && ((!loggedIn && !autoLogin) || mLoginName.Is_Empty()))
  698. {
  699. #ifdef FREEDEDICATEDSERVER
  700. Add_Ref();
  701. WOLLogonAction action = WOLLOGON_FAILED;
  702. NotifyObservers(action);
  703. Release_Ref();
  704. #else //FREEDEDICATEDSERVER
  705. WWDEBUG_SAY(("WOLLogonMgr: Requesting logon information.\n"));
  706. // Keep alive while we are waiting on the logon dialog.
  707. Add_Ref();
  708. // Prompt the user to enter login information.
  709. DlgWOLLogon::DoDialog(mLoginName, this);
  710. #endif //FREEDEDICATEDSERVER
  711. return;
  712. }
  713. //---------------------------------------------------------------------------
  714. // Logon to WWOnline server
  715. //---------------------------------------------------------------------------
  716. WWDEBUG_SAY(("WOLLogonMgr: Connecting user '%S' to server '%s'\n", (const WCHAR*)mLoginName, server->GetName()));
  717. RefPtr<LoginInfo> login = LoginInfo::Find(mLoginName);
  718. #ifndef FREEDEDICATEDSERVER
  719. if (login.IsValid() == false)
  720. #endif //FREEDEDICATEDSERVER
  721. {
  722. if (AutoRestart.Is_Active() && strlen(MPSettingsMgrClass::Get_Auto_Password()))
  723. {
  724. mPasswordEncrypted = false;
  725. }
  726. login = LoginInfo::Create(mLoginName, mPassword, mPasswordEncrypted);
  727. }
  728. mState = CONNECTING;
  729. RefPtr<SerialWait> connectWait = SerialWait::Create();
  730. if (connectWait.IsValid())
  731. {
  732. // Listen for various connection events
  733. Observer<ConnectionStatus>::NotifyMe(*mWOLSession);
  734. Observer<MessageOfTheDayEvent>::NotifyMe(*mWOLSession);
  735. // Gather ping times
  736. RefPtr<WaitCondition> pingsWait = PingProfileWait::Create();
  737. connectWait->Add(pingsWait);
  738. // Detect firewall settings.
  739. RefPtr<WaitCondition> firewallWait = FirewallDetectWait::Create();
  740. connectWait->Add(firewallWait);
  741. // Request loging to server
  742. RefPtr<WaitCondition> loginWait = mWOLSession->LoginServer(server, login);
  743. connectWait->Add(loginWait);
  744. RefPtr<WaitCondition> connect = connectWait;
  745. bool connecting = DlgWOLWait::DoDialog(IDS_WOL_LOGON, connect, this, 0, mQuietMode ? 0xffffffff : 0);
  746. // If connecting then keep alive until complete...
  747. if (connecting)
  748. {
  749. // Keep alive while we are connecting.
  750. Add_Ref();
  751. }
  752. }
  753. }
  754. /******************************************************************************
  755. *
  756. * NAME
  757. * WOLLogonMgr::HandleNotification(DlgWOLWaitEvent)
  758. *
  759. * DESCRIPTION
  760. * Handle completion of wait event dialog.
  761. *
  762. * INPUTS
  763. * WaitEvent - Completed wait event.
  764. *
  765. * RESULT
  766. * NONE
  767. *
  768. ******************************************************************************/
  769. void WOLLogonMgr::HandleNotification(DlgWOLWaitEvent& waitEvent)
  770. {
  771. WaitCondition::WaitResult result = waitEvent.Result();
  772. switch (mState)
  773. {
  774. // If we were waiting to detect bandwidth
  775. case DETECTING_BANDWIDTH:
  776. mState = DISCONNECTED;
  777. // Failure to detect bandwidth is not neccessarily fatal.
  778. // Or maybe it is. ST - 11/6/2001 11:33AM
  779. if ((result != WaitCondition::Waiting && result != WaitCondition::UserCancel)
  780. && BandwidthCheckerClass::Got_Bandwidth())
  781. {
  782. WWDEBUG_SAY(("WOLLogonMgr: Finished bandwidth check\n"));
  783. cUserOptions::Set_Bandwidth_Type(BANDWIDTH_AUTO);
  784. InitiateLogon(false);
  785. }
  786. else
  787. {
  788. //Should never get here unless there is no internet connection at all.
  789. WWDEBUG_SAY(("WOLLogonMgr: Failed to detect bandwidth.\n"));
  790. cUserOptions::Set_Bandwidth_Type(BANDWIDTH_MODEM_56);
  791. if (result != WaitCondition::UserCancel)
  792. {
  793. //if (BandwidthCheckerClass::Failed_Due_To_No_Connection())
  794. // {
  795. if (mQuietMode)
  796. {
  797. // Try again. The auto detect won't fire off a second time since we switched to 56k
  798. if (ConsoleBox.Is_Exclusive()) {
  799. cUserOptions::Set_Bandwidth_Type(BANDWIDTH_LANT1);
  800. }
  801. InitiateLogon(false);
  802. //Add_Ref();
  803. //WOLLogonAction action = WOLLOGON_FAILED;
  804. //NotifyObservers(action);
  805. //Release_Ref();
  806. }
  807. else
  808. {
  809. //DlgMsgBox::DoDialog(L"IDS_WOL_LOGONFAILED", TRANSLATE (IDS_MENU_NO_INET_CONNECTION));
  810. // Text reads....
  811. // Renegade is unable to detect your Internet connection speed\n.
  812. // Defaulting connection speed to 56k.\n
  813. // If this is incorrect, you can change it on the My Information page.
  814. Add_Ref();
  815. DlgMsgBox::DoDialog(L"", TRANSLATE (IDS_MENU_SET_CONNECTION_SPEED), DlgMsgBox::Okay, this);
  816. mState = WAITING_BANDWIDTH_DIALOG_OKAY;
  817. }
  818. // }
  819. //else
  820. // {
  821. // InitiateLogon(false);
  822. // }
  823. }
  824. else
  825. {
  826. Add_Ref();
  827. WOLLogonAction action = WOLLOGON_FAILED;
  828. NotifyObservers(action);
  829. Release_Ref();
  830. }
  831. }
  832. break;
  833. // If we were waiting for the serverlist
  834. case FETCHING_SERVERLIST:
  835. mState = DISCONNECTED;
  836. if (result == WaitCondition::ConditionMet)
  837. {
  838. WWDEBUG_SAY(("WOLLogonMgr: Got server list\n"));
  839. ConsoleBox.Print("Got server list\n");
  840. if (HasServerList())
  841. {
  842. InitiateLogon(false);
  843. }
  844. else
  845. {
  846. WWDEBUG_SAY(("WOLLogonMgr: Serverlist empty!\n"));
  847. if (mQuietMode)
  848. {
  849. Add_Ref();
  850. WOLLogonAction action = WOLLOGON_FAILED;
  851. NotifyObservers(action);
  852. Release_Ref();
  853. }
  854. else
  855. {
  856. DlgMsgBox::DoDialog(IDS_WOL_LOGONFAILED, IDS_WOL_SERVERLISTERROR);
  857. }
  858. }
  859. }
  860. else
  861. {
  862. const wchar_t* resultText = waitEvent.Subject()->GetResultText();
  863. WWDEBUG_SAY(("WOLLogonMgr: Serverlist error %S\n", resultText));
  864. if (mQuietMode)
  865. {
  866. Add_Ref();
  867. WOLLogonAction action = WOLLOGON_FAILED;
  868. NotifyObservers(action);
  869. Release_Ref();
  870. }
  871. else if (WaitCondition::UserCancel != result)
  872. {
  873. DlgMsgBox::DoDialog(TRANSLATE(IDS_WOL_LOGONFAILED), resultText);
  874. }
  875. }
  876. break;
  877. // If we are waiting on pings.
  878. case WAITING_PINGS:
  879. mState = DISCONNECTED;
  880. if ((result == WaitCondition::ConditionMet) && HasValidPings())
  881. {
  882. WWDEBUG_SAY(("WOLLogonMgr: Got server pings\n"));
  883. ConsoleBox.Print("Got server pings\n");
  884. InitiateLogon(false);
  885. }
  886. else
  887. {
  888. WWDEBUG_SAY(("WOLLogonMgr: Ping server list error.\n"));
  889. if (mQuietMode)
  890. {
  891. Add_Ref();
  892. WOLLogonAction action = WOLLOGON_FAILED;
  893. NotifyObservers(action);
  894. Release_Ref();
  895. }
  896. else if (WaitCondition::UserCancel != result)
  897. {
  898. DlgMsgBox::DoDialog(TRANSLATE(IDS_WOL_LOGONFAILED), TRANSLATE(IDS_MENU_UNABLE_TO_DETERMINE_SERVER_LOC));
  899. }
  900. }
  901. break;
  902. // If we are waiting for connection
  903. case CONNECTING:
  904. if (WaitCondition::ConditionMet == result)
  905. {
  906. WWDEBUG_SAY(("WOLLogonMgr: Connection succeeded\n"));
  907. mState = CONNECTED;
  908. RememberLogin();
  909. Add_Ref();
  910. WOLLogonAction action = WOLLOGON_SUCCESS;
  911. NotifyObservers(action);
  912. Release_Ref();
  913. }
  914. else
  915. {
  916. WWDEBUG_SAY(("WOLLogonMgr: Connection failed!\n"));
  917. mState = DISCONNECTED;
  918. // Prevent event handling after error or user abort
  919. Observer<ConnectionStatus>::StopObserving();
  920. Observer<MessageOfTheDayEvent>::StopObserving();
  921. // No feedback to the user if we are in 'quiet' mode.
  922. if (mQuietMode)
  923. {
  924. Add_Ref();
  925. WOLLogonAction action = WOLLOGON_FAILED;
  926. NotifyObservers(action);
  927. Release_Ref();
  928. }
  929. else if (WaitCondition::UserCancel != result)
  930. {
  931. // Bring up dialog to allow user to adjust login information
  932. WWDEBUG_SAY(("WOLLogonMgr: Requesting login information.\n"));
  933. DlgWOLLogon::DoDialog(mLoginName, this);
  934. // Show reason we could not connect.
  935. RefPtr<WaitCondition> wait = waitEvent.Subject();
  936. WideStringClass errorMsg(255, true);
  937. errorMsg.Format(TRANSLATE (IDS_MENU_UNABLE_TO_CONNECT_TO_SERVER), wait->GetResultText());
  938. DlgMsgBox::DoDialog(TRANSLATE(IDS_WOL_LOGONFAILED), errorMsg);
  939. // Keep alive while waiting for user to correct logon information.
  940. Add_Ref();
  941. }
  942. }
  943. break;
  944. case DISCONNECTED:
  945. default:
  946. break;
  947. }
  948. // Release keep alive reference
  949. Release_Ref();
  950. }
  951. /******************************************************************************
  952. *
  953. * NAME
  954. * WOLLogonMgr::HandleNotification(DlgWOLLogonAction)
  955. *
  956. * DESCRIPTION
  957. * Handle notification from logon dialog.
  958. *
  959. * INPUTS
  960. * Event - Event action from logon dialog.
  961. *
  962. * RESULT
  963. * NONE
  964. *
  965. ******************************************************************************/
  966. void WOLLogonMgr::HandleNotification(DlgWOLLogonEvent& event)
  967. {
  968. // If the user clicked "Login" then attempt to login with the information
  969. // entered by the user in the login dialog.
  970. if (event.GetEvent() == DlgWOLLogonEvent::Login)
  971. {
  972. DlgWOLLogon& logonDialog = event.Subject();
  973. // Get selected login
  974. const wchar_t* name = NULL;
  975. const wchar_t* password = NULL;
  976. logonDialog.GetLogin(&name, &password, mPasswordEncrypted);
  977. mLoginName = name;
  978. mPassword = password;
  979. mRememberLogin = logonDialog.IsRememberLoginChecked();
  980. InitiateLogon(true);
  981. }
  982. // If the user clicked "cancel" the abort then cancel the login procedure
  983. else if (event.GetEvent() == DlgWOLLogonEvent::Cancel)
  984. {
  985. Add_Ref();
  986. WOLLogonAction action = WOLLOGON_CANCEL;
  987. NotifyObservers(action);
  988. Release_Ref();
  989. }
  990. // Release keep alive reference
  991. Release_Ref();
  992. }
  993. /******************************************************************************
  994. *
  995. * NAME
  996. * WOLLogonMgr::HandleNotification(ServerError)
  997. *
  998. * DESCRIPTION
  999. *
  1000. * INPUTS
  1001. *
  1002. * RESULT
  1003. * NONE
  1004. *
  1005. ******************************************************************************/
  1006. void WOLLogonMgr::HandleNotification(ServerError& error)
  1007. {
  1008. if (CHAT_E_MUSTPATCH == error.GetErrorCode())
  1009. {
  1010. mState = DISCONNECTED;
  1011. Add_Ref();
  1012. WOLLogonAction action = WOLLOGON_PATCHREQUIRED;
  1013. NotifyObservers(action);
  1014. Release_Ref();
  1015. }
  1016. }
  1017. /******************************************************************************
  1018. *
  1019. * NAME
  1020. * WOLLogonMgr::HandleNotification(ConnectionStatus)
  1021. *
  1022. * DESCRIPTION
  1023. * Handle connection to WOL server status.
  1024. *
  1025. * INPUTS
  1026. * Status - Connection status
  1027. *
  1028. * RESULT
  1029. * NONE
  1030. *
  1031. ******************************************************************************/
  1032. void WOLLogonMgr::HandleNotification(ConnectionStatus& status)
  1033. {
  1034. if (status == ConnectionConnected)
  1035. {
  1036. ConfigureSession();
  1037. // Nag the user about properly configuring their locale (if necessary)
  1038. if (!mQuietMode)
  1039. {
  1040. WolLocaleMgrClass::Display_Nag_Dialog();
  1041. }
  1042. }
  1043. }
  1044. /******************************************************************************
  1045. *
  1046. * NAME
  1047. * WOLLogonMgr::HandleNotification(DlgMsgBoxEvent)
  1048. *
  1049. * DESCRIPTION
  1050. * Handle any dialog box notifications.
  1051. *
  1052. * INPUTS
  1053. * Event - Dialog box event
  1054. *
  1055. * RESULT
  1056. * NONE
  1057. *
  1058. ******************************************************************************/
  1059. void WOLLogonMgr::HandleNotification(DlgMsgBoxEvent &event)
  1060. {
  1061. if (event.Event () == DlgMsgBoxEvent::Okay && mState == WAITING_BANDWIDTH_DIALOG_OKAY)
  1062. {
  1063. mState = DISCONNECTED;
  1064. InitiateLogon(false);
  1065. Release_Ref();
  1066. }
  1067. }
  1068. /******************************************************************************
  1069. *
  1070. * NAME
  1071. * WOLLogonMgr::HandleNotification(MessageOfTheDayEvent)
  1072. *
  1073. * DESCRIPTION
  1074. * Handle the message of the day text.
  1075. *
  1076. * INPUTS
  1077. * Event - Message of the day event.
  1078. *
  1079. * RESULT
  1080. * NONE
  1081. *
  1082. ******************************************************************************/
  1083. void WOLLogonMgr::HandleNotification(MessageOfTheDayEvent &event)
  1084. {
  1085. // Get the name of the current server and the text of the message
  1086. WideStringClass& message = event.Subject();
  1087. const WCHAR* TAG_NEWS_START = L"<news>";
  1088. const WCHAR* TAG_NEWS_END = L"</news>";
  1089. const int TAG_NEWS_START_LEN = ::wcslen(TAG_NEWS_START);
  1090. bool display_motd = false;
  1091. // Does this message have the embedded news tag?
  1092. const WCHAR* news = ::wcsstr(message, TAG_NEWS_START);
  1093. if (news)
  1094. {
  1095. // Get the text of the news section
  1096. WideStringClass news_body(0, true);
  1097. news_body = news + TAG_NEWS_START_LEN;
  1098. WCHAR* news_end = ::wcsstr(news_body, TAG_NEWS_END);
  1099. if (news_end)
  1100. {
  1101. news_end[0] = 0;
  1102. }
  1103. // If the message of the day has already been viewed, then
  1104. // we just want to display the news items, otherwise display
  1105. // the whole message (minus the embedded tags)
  1106. if (MPSettingsMgrClass::Has_MOTD_Been_Viewed())
  1107. {
  1108. message = news_body;
  1109. }
  1110. else
  1111. {
  1112. // Simply erase the tags from the message
  1113. int tag1_index = news - message.Peek_Buffer();
  1114. int tag2_index = tag1_index + (TAG_NEWS_START_LEN) + ::wcslen(news_body);
  1115. message.Erase(tag2_index, ::wcslen(TAG_NEWS_END));
  1116. message.Erase(tag1_index, ::wcslen(TAG_NEWS_START));
  1117. }
  1118. display_motd = true;
  1119. }
  1120. // Only display the message if the user hasn't already seen it
  1121. if (MPSettingsMgrClass::Has_MOTD_Been_Viewed() == false || display_motd)
  1122. {
  1123. // Show the MOTD dialog
  1124. MPWolMOTDDialogClass* dialog = new MPWolMOTDDialogClass;
  1125. if (dialog)
  1126. {
  1127. // Don't show the message of the day if we are in restart mode.
  1128. if (!AutoRestart.Is_Active())
  1129. {
  1130. dialog->Set_Message(message);
  1131. dialog->Start_Dialog();
  1132. }
  1133. REF_PTR_RELEASE(dialog);
  1134. // Remember that we've already viewed the message of the day
  1135. MPSettingsMgrClass::Set_MOTD_Viewed(true);
  1136. }
  1137. }
  1138. }