ZoneClubScreen.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. #include "pch.h"
  2. #include <zreg.h>
  3. // #define NO_CLUB_SERVER_CONNECTION 1 // comment out before checkin
  4. //////////////////////////////////////////////////////////////////////////////
  5. //
  6. // ZoneClub Screen
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. bool g_fZoneAuth =
  10. #ifdef USEAUTH
  11. true;
  12. #else
  13. false;
  14. #endif
  15. extern bool g_bDownloadZoneMessage;
  16. extern bool g_bDownloadNewConfig;
  17. extern bool g_bDisableZoneClub;
  18. extern bool g_bSkipAutoUpdate;
  19. const char * szValidCfg = "THIS IS A VALID CONFIG FILE";
  20. const char * szValidMotd = "THIS IS A VALID MESSAGE OF THE DAY FILE";
  21. class ZoneClubScreen :
  22. public Screen,
  23. public LogonSite,
  24. public TrekClientEventSink,
  25. public IIntegerEventSink,
  26. public IAutoUpdateSink,
  27. public EventTargetContainer<ZoneClubScreen>
  28. {
  29. private:
  30. TRef<Modeler> m_pmodeler;
  31. TRef<Pane> m_ppane;
  32. TRef<ButtonPane> m_pbuttonGames;
  33. TRef<ButtonPane> m_pbuttonGamesBig;
  34. TRef<ButtonPane> m_pbuttonZoneEvents;
  35. TRef<ButtonPane> m_pbuttonSquads;
  36. TRef<ButtonPane> m_pbuttonMainMenu;
  37. TRef<ButtonPane> m_pbuttonPlayerProfile;
  38. TRef<ButtonPane> m_pbuttonLeaderboard;
  39. TRef<ButtonPane> m_pbuttonWeb;
  40. TRef<MDLFileImage> m_pMDLFileImage;
  41. char m_szName[c_cbPassportName];
  42. char m_szPW[c_cbName];
  43. char m_szPWOrig[c_cbName];
  44. char m_szConfig[MAX_PATH];
  45. BOOL m_fRememberPW;
  46. bool m_bErrorOccured;
  47. bool m_bMessageStage; // if true then we are at the Message of the day stage, if false then we are at the Config download stage
  48. bool m_bTriedCurrentLogin;
  49. IHTTPSession * m_pSession;
  50. bool m_bConnectLobby; // true means lobby server; false means Club server
  51. TRef<IMessageBox> m_pmsgBox;
  52. ScreenID m_screenPostConnect;
  53. static bool s_bWasAuthenticated;
  54. public:
  55. ZoneClubScreen(Modeler* pmodeler, Number* ptime) :
  56. m_pSession(NULL),
  57. m_bErrorOccured(false),
  58. m_bMessageStage(false),
  59. m_pmsgBox(NULL),
  60. m_pmodeler(pmodeler),
  61. m_bTriedCurrentLogin(false)
  62. {
  63. TRef<INameSpace> pnsZoneClubData = GetModeler()->CreateNameSpace("zoneclubdata");
  64. pnsZoneClubData->AddMember("timeStart", ptime->MakeConstant());
  65. TRef<INameSpace> pns = pmodeler->GetNameSpace(
  66. trekClient.GetIsZoneClub() ? "zoneclubscreen" : "zonepublicscreen");
  67. CastTo(m_ppane, pns->FindMember("screen"));
  68. CastTo(m_pMDLFileImage, (Value*)pns->FindMember("messageImage"));
  69. CastTo(m_pbuttonGames, pns->FindMember("gamesButtonPane"));
  70. CastTo(m_pbuttonGamesBig, pns->FindMember("gamesBigButtonPane"));
  71. CastTo(m_pbuttonZoneEvents, pns->FindMember("zoneEventsButtonPane"));
  72. CastTo(m_pbuttonSquads, pns->FindMember("squadsButtonPane"));
  73. CastTo(m_pbuttonMainMenu, pns->FindMember("mainmenuButtonPane"));
  74. CastTo(m_pbuttonPlayerProfile, pns->FindMember("playerProfileButtonPane"));
  75. CastTo(m_pbuttonLeaderboard, pns->FindMember("leaderboardButtonPane"));
  76. CastTo(m_pbuttonWeb, pns->FindMember("webButtonPane"));
  77. AddEventTarget(OnButtonGames, m_pbuttonGames->GetEventSource());
  78. AddEventTarget(OnButtonGames, m_pbuttonGamesBig->GetEventSource());
  79. AddEventTarget(OnButtonMainMenu, m_pbuttonMainMenu->GetEventSource());
  80. if (trekClient.GetIsZoneClub())
  81. {
  82. AddEventTarget(OnButtonZoneEvents, m_pbuttonZoneEvents->GetEventSource());
  83. AddEventTarget(OnButtonSquads, m_pbuttonSquads->GetEventSource());
  84. AddEventTarget(OnButtonPlayerProfile, m_pbuttonPlayerProfile->GetEventSource());
  85. AddEventTarget(OnButtonZoneWeb, m_pbuttonWeb->GetEventSource());
  86. AddEventTarget(OnButtonLeaderBoard, m_pbuttonLeaderboard->GetEventSource());
  87. }
  88. //temporarily disable all buttons
  89. m_pbuttonMainMenu->SetEnabled(false); // force download to finish before leaving this screen
  90. m_pbuttonGames->SetEnabled(false);
  91. m_pbuttonGamesBig->SetEnabled(false);
  92. if (trekClient.GetIsZoneClub())
  93. {
  94. m_pbuttonSquads->SetEnabled(false);
  95. m_pbuttonZoneEvents->SetEnabled(false);
  96. m_pbuttonPlayerProfile->SetEnabled(false);
  97. m_pbuttonLeaderboard->SetEnabled(false);
  98. }
  99. pmodeler->UnloadNameSpace(pns);
  100. BeginConfigDownload();
  101. if (g_bQuickstart)
  102. AddEventTarget(OnButtonGames, GetWindow(), 0.01f);
  103. trekClient.FlushSessionLostMessage();
  104. }
  105. ~ZoneClubScreen()
  106. {
  107. //trekClient.m_pzac = NULL;
  108. if (m_pSession)
  109. {
  110. delete m_pSession;
  111. m_pSession = NULL;
  112. }
  113. }
  114. // connect to either Zone Lobby server or Zone Club (wrapper to provide appropriate prompt)
  115. void ConnectToZone(bool bConnectLobby, ScreenID screenid)
  116. {
  117. ZString strPrompt;
  118. #ifdef USEAUTH
  119. if (trekClient.GetCfgInfo().bUsePassport)
  120. strPrompt = "Sign in to Microsoft Passport";
  121. else
  122. strPrompt = "Sign in to the Microsoft Gaming Zone";
  123. #else
  124. strPrompt = "Enter a call sign (player name) to use for this game.";
  125. #endif
  126. ConnectToZone(bConnectLobby, screenid, strPrompt);
  127. }
  128. // connect to either Zone Lobby server or Zone Club
  129. void ConnectToZone(bool bConnectLobby, ScreenID screenid, const ZString& strPrompt)
  130. {
  131. if (bConnectLobby)
  132. {
  133. if (trekClient.GetIsZoneClub())
  134. {
  135. if (trekClient.GetCfgInfo().strClubLobby.IsEmpty())
  136. {
  137. TRef<IMessageBox> pmsgBox = CreateMessageBox(
  138. "The Allegiance Zone lobby is not available at the moment. "
  139. + ZString(trekClient.GetCfgInfo().strPublicLobby.IsEmpty()
  140. ? "Please try again later."
  141. : "Please try the free lobby instead.")
  142. );
  143. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  144. return;
  145. }
  146. }
  147. else
  148. {
  149. if (trekClient.GetCfgInfo().strPublicLobby.IsEmpty())
  150. {
  151. TRef<IMessageBox> pmsgBox = CreateMessageBox(
  152. "The free lobby is not available at the moment. "
  153. + ZString(trekClient.GetCfgInfo().strClubLobby.IsEmpty()
  154. ? "Please try again later."
  155. : "Please try the Allegiance Zone instead.")
  156. );
  157. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  158. return;
  159. }
  160. }
  161. }
  162. else
  163. {
  164. if (trekClient.GetCfgInfo().strClub.IsEmpty())
  165. {
  166. TRef<IMessageBox> pmsgBox = CreateMessageBox(
  167. "The Club server is not available at the moment. "
  168. "Please try again later."
  169. );
  170. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  171. return;
  172. }
  173. }
  174. m_bConnectLobby = bConnectLobby;
  175. m_screenPostConnect = screenid;
  176. assert (!trekClient.LoggedOn() && !trekClient.m_fm.IsConnected());
  177. HRESULT hr = E_FAIL;
  178. #ifdef USEAUTH
  179. TRef<IZoneAuthClient> pzac;
  180. if (g_fZoneAuth)
  181. {
  182. pzac = trekClient.GetZoneAuthClient();
  183. if (!pzac)
  184. pzac = trekClient.CreateZoneAuthClient();
  185. if (trekClient.GetCfgInfo().bUsePassport
  186. && !pzac->HasInterface(trekClient.GetCfgInfo().guidZoneAuth))
  187. {
  188. // take them to the web page...
  189. GetWindow()->ShowWebPage(trekClient.GetCfgInfo().strPassportUpdateURL);
  190. // shut down the client
  191. GetWindow()->PostMessage(WM_CLOSE);
  192. return;
  193. }
  194. if (s_bWasAuthenticated)
  195. {
  196. hr = S_OK;
  197. }
  198. else
  199. {
  200. pzac->SetAuthServer(trekClient.GetCfgInfo().strZAuth);
  201. if (!m_bTriedCurrentLogin)
  202. hr = pzac->IsAuthenticated(5000);
  203. }
  204. }
  205. if (SUCCEEDED(hr)) // must be false if !g_fZoneAuth
  206. {
  207. BaseClient::ConnectInfo ci;
  208. DWORD cbZoneTicket;
  209. DWORD cbName = sizeof(ci.szName);
  210. ZSucceeded(pzac->GetTicket(&ci.pZoneTicket, &cbZoneTicket, ci.szName, &cbName));
  211. assert(cbName <= sizeof(ci.szName));
  212. ci.cbZoneTicket = cbZoneTicket;
  213. if(m_bConnectLobby)
  214. trekClient.ConnectToLobby(&ci);
  215. else
  216. trekClient.ConnectToClub(&ci);
  217. m_bTriedCurrentLogin = true;
  218. }
  219. else
  220. #endif
  221. {
  222. m_szName[0] = '\0';
  223. m_szPWOrig[0] = '\0';
  224. #ifdef USEAUTH
  225. if (g_fZoneAuth)
  226. pzac->GetDefaultLogonInfo(m_szName, m_szPWOrig, &m_fRememberPW);
  227. #else
  228. lstrcpy(m_szName, trekClient.GetSavedCharacterName());
  229. #endif
  230. TRef<IPopup> plogonPopup = CreateLogonPopup(m_pmodeler, this,
  231. (trekClient.GetIsZoneClub() ?
  232. LogonAllegianceZone :
  233. #ifdef USEAUTH
  234. LogonFreeZone
  235. #else
  236. LogonLAN
  237. #endif
  238. ), strPrompt, m_szName, m_szPWOrig, m_fRememberPW);
  239. Point point(c_PopupX, c_PopupY);
  240. Rect rect(point, point);
  241. GetWindow()->GetPopupContainer()->OpenPopup(plogonPopup, rect, false);
  242. }
  243. }
  244. bool OnButtonMainMenu()
  245. {
  246. GetWindow()->screen(ScreenIDIntroScreen);
  247. return true;
  248. }
  249. bool OnButtonSquads()
  250. {
  251. if (trekClient.LoggedOnToClub())
  252. {
  253. GetWindow()->screen(ScreenIDSquadsScreen);
  254. }
  255. else
  256. {
  257. ConnectToZone(false, ScreenIDSquadsScreen);
  258. }
  259. return true;
  260. }
  261. bool OnButtonGames()
  262. {
  263. // if (trekClient.LoggedOnToLobby())
  264. // {
  265. // GetWindow()->screen(ScreenIDGameScreen);
  266. // }
  267. // else
  268. // {
  269. ConnectToZone(true, ScreenIDGameScreen);
  270. // }
  271. return true;
  272. }
  273. bool OnButtonZoneEvents()
  274. {
  275. GetWindow()->screen(ScreenIDZoneEvents);
  276. //ConnectToZone(true, ScreenIDZoneEvents);
  277. return true;
  278. }
  279. bool OnButtonPlayerProfile()
  280. {
  281. #ifdef NO_CLUB_SERVER_CONNECTION
  282. GetWindow()->screen(ScreenIDCharInfo);
  283. #else
  284. if (trekClient.LoggedOnToClub())
  285. {
  286. GetWindow()->screen(ScreenIDCharInfo);
  287. }
  288. else
  289. {
  290. ConnectToZone(false, ScreenIDCharInfo);
  291. }
  292. #endif
  293. return true;
  294. }
  295. bool OnButtonZoneWeb()
  296. {
  297. // note: users can also access web page from the introscreen
  298. GetWindow()->ShowWebPage();
  299. return true;
  300. }
  301. bool OnButtonLeaderBoard()
  302. {
  303. if (trekClient.LoggedOnToClub())
  304. {
  305. GetWindow()->screen(ScreenIDLeaderBoard);
  306. }
  307. else
  308. {
  309. ConnectToZone(false, ScreenIDLeaderBoard);
  310. }
  311. return true;
  312. }
  313. void BeginConfigDownload()
  314. {
  315. if (!g_bDownloadNewConfig)
  316. {
  317. debugf("Skipping download of config file due to command-line switch.\n");
  318. OnConfigDownloadDone(true, false);
  319. return;
  320. }
  321. lstrcpy(m_szConfig, "http://Allegiance.zone.com/Allegiance.cfg");
  322. HKEY hKey;
  323. if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, KEY_READ, &hKey))
  324. {
  325. DWORD cbValue = MAX_PATH;
  326. char szConfig[MAX_PATH];
  327. szConfig[0] = '\0';
  328. ::RegQueryValueEx(hKey, "CfgFile", NULL, NULL, (LPBYTE)&szConfig, &cbValue);
  329. // if it didn't succeed, we'll just use the default above
  330. if (lstrlen(szConfig) > 0)
  331. lstrcpy(m_szConfig, szConfig);
  332. }
  333. if (ZString(m_szConfig).Find("http://") == -1)
  334. {
  335. debugf("Using local config file due to registry setting for ConfigFile because \"http://\" was missing from it. %s\n", m_szConfig);
  336. if (!IsFileValid(m_szConfig))
  337. {
  338. #ifndef DEBUG // don't give warning twice for debug users
  339. m_pmsgBox = CreateMessageBox("Warning, Local CFG missing validation string");
  340. GetWindow()->GetPopupContainer()->OpenPopup(m_pmsgBox, false);
  341. #endif
  342. }
  343. OnConfigDownloadDone(false, false);
  344. return;
  345. }
  346. if (m_pSession)
  347. return;
  348. debugf("Beginning Config Download: %s.\n", m_szConfig);
  349. m_pSession = CreateHTTPSession(this);
  350. const char * szFileList[] = { m_szConfig, "temp.cfg", NULL };
  351. m_pSession->InitiateDownload(szFileList, "."); // . means EXE path
  352. return;
  353. }
  354. void BeginMessageOfDayDownload()
  355. {
  356. if (!g_bDownloadZoneMessage)
  357. {
  358. debugf("Skipping download of Message Of the Day due to command-line switch.\n");
  359. OnMessageOfDayDone(false);
  360. return;
  361. }
  362. PCC szMessageOfTheDayFileName = trekClient.GetIsZoneClub()
  363. ? "clubmessageoftheday.mdl" : "publicmessageoftheday.mdl";
  364. PathString path(trekClient.GetArtPath());
  365. path = path + szMessageOfTheDayFileName;
  366. int crc = FileCRC(PCC(path), NULL);
  367. if (crc != 0 && crc == (trekClient.GetIsZoneClub()
  368. ? trekClient.GetCfgInfo().crcClubMessageFile
  369. : trekClient.GetCfgInfo().crcPublicMessageFile))
  370. {
  371. debugf("Existing messageoftheday file has the correct CRC, skipping download.\n");
  372. OnMessageOfDayDone(true);
  373. return;
  374. }
  375. else
  376. {
  377. debugf("Existing messageoftheday file has the wrong CRC (%X).\n", crc);
  378. }
  379. if (m_pSession)
  380. return;
  381. PCC szMessageOfTheDayURL = trekClient.GetIsZoneClub()
  382. ? PCC(trekClient.GetCfgInfo().strClubMessageURL)
  383. : PCC(trekClient.GetCfgInfo().strPublicMessageURL);
  384. debugf("Beginning messageoftheday download: %s.\n", szMessageOfTheDayURL);
  385. m_pSession = CreateHTTPSession(this);
  386. const char * szFileList[3] = { szMessageOfTheDayURL, szMessageOfTheDayFileName, NULL };
  387. m_pSession->InitiateDownload(szFileList, trekClient.GetArtPath());
  388. return;
  389. }
  390. void OnError(char * szErrorMessage) // on HTTP download error
  391. {
  392. // Errors are essentially ignored
  393. debugf("Error while downloading file.\n");
  394. debugf("%s\n", szErrorMessage);
  395. m_bErrorOccured = true;
  396. }
  397. bool IsFileValid(char * szFileName)
  398. {
  399. ZFile file(szFileName);
  400. int n = file.GetLength(); // -1 means error
  401. if (n != -1 && n != 0)
  402. {
  403. char * pData = new char[n+1];
  404. memcpy(pData, file.GetPointer(), n);
  405. pData[n] = 0;
  406. if (m_bMessageStage)
  407. {
  408. if (strstr(pData, szValidMotd) == NULL)
  409. {
  410. debugf("File %s is not a valid messageoftheday file.\n", szFileName);
  411. #ifdef DEBUG
  412. m_pmsgBox = CreateMessageBox("Warning, downloaded Motd file missing validation string");
  413. GetWindow()->GetPopupContainer()->OpenPopup(m_pmsgBox, false);
  414. #endif
  415. delete[] pData;
  416. return false;
  417. }
  418. }
  419. else
  420. {
  421. if (strstr(pData, szValidCfg) == NULL)
  422. {
  423. debugf("File %s is not a valid config file.\n", szFileName);
  424. #ifdef DEBUG
  425. m_pmsgBox = CreateMessageBox("Warning, CFG file missing validation string");
  426. GetWindow()->GetPopupContainer()->OpenPopup(m_pmsgBox, false);
  427. #endif
  428. delete[] pData;
  429. return false;
  430. }
  431. }
  432. delete[] pData;
  433. }
  434. else
  435. {
  436. debugf("File %s error while trying to load downloaded config file.\n", szFileName);
  437. return false;
  438. }
  439. return true;
  440. }
  441. bool OnFileCompleted(char * szFileName)
  442. {
  443. debugf("Downloaded file: %s\n", szFileName);
  444. char szPath[MAX_PATH+20];
  445. strcpy(szPath, m_pSession->GetDownloadPath());
  446. strcat(szPath, szFileName);
  447. if (!IsFileValid(szPath))
  448. {
  449. m_bErrorOccured = true;
  450. debugf("Aborting either cfg or motd because file is invalid.");
  451. m_pmsgBox = CreateMessageBox("Unable to connect to Zone. Please try again later.");
  452. GetWindow()->GetPopupContainer()->OpenPopup(m_pmsgBox, false);
  453. }
  454. return true; // true means don't retry download
  455. }
  456. void OnFrame()
  457. {
  458. if (m_pSession)
  459. {
  460. if(m_bErrorOccured || !m_pSession->ContinueDownload())
  461. {
  462. if (m_bMessageStage)
  463. OnMessageOfDayDone(!m_bErrorOccured);
  464. else
  465. OnConfigDownloadDone(true, !m_bErrorOccured);
  466. }
  467. }
  468. }
  469. void OnConfigDownloadDone(bool bUseEXEFolder, bool bDownloadSuccesful)
  470. {
  471. m_bMessageStage = true;
  472. if (m_pSession)
  473. {
  474. delete m_pSession;
  475. m_pSession = NULL;
  476. }
  477. if (bUseEXEFolder)
  478. {
  479. PathString pathEXE(PathString::GetCurrentDirectory());
  480. PathString pathConfig(pathEXE + PathString(PathString(m_szConfig).GetFilename()));
  481. if (bDownloadSuccesful)
  482. {
  483. PathString pathTemp(pathEXE + "temp.cfg");
  484. trekClient.GetCfgInfo().Load(PCC(pathTemp));
  485. debugf("Loaded downloaded config file: %s\n", PCC(pathTemp));
  486. // rename file, so that next time if there is an error, there is
  487. // a recent config file to use.
  488. debugf("Renaming %s to %s\n", PCC(pathTemp), PCC(pathConfig));
  489. DeleteFile(PCC(pathConfig));
  490. MoveFile(PCC(pathTemp), PCC(pathConfig));
  491. }
  492. else
  493. {
  494. debugf("Error detected, loading existing config file: %s\n", PCC(pathConfig));
  495. trekClient.GetCfgInfo().Load(PCC(pathConfig));
  496. }
  497. }
  498. else
  499. {
  500. debugf("Using local config file %s\n", m_szConfig);
  501. trekClient.GetCfgInfo().Load(m_szConfig);
  502. }
  503. if (!m_bErrorOccured)
  504. {
  505. if(!g_bSkipAutoUpdate)
  506. {
  507. if (trekClient.GetCfgInfo().crcFileList != 0 &&
  508. trekClient.GetCfgInfo().nFilelistSize != 0 &&
  509. trekClient.GetCfgInfo().strFilelistSite != "" &&
  510. trekClient.GetCfgInfo().strFilelistDirectory != "")
  511. {
  512. bool bForceFileCheck = trekClient.ShouldCheckFiles();
  513. if (bForceFileCheck || trekClient.GetCfgInfo().crcFileList != FileCRC("Filelist.txt", NULL))
  514. {
  515. if (trekClient.m_pAutoDownload == NULL)
  516. trekClient.m_pAutoDownload = CreateAutoDownload();
  517. IAutoUpdateSink * pAutoUpdateSink = trekClient.OnBeginAutoUpdate(this, false);
  518. assert(pAutoUpdateSink);
  519. trekClient.m_pAutoDownload->SetFTPSite(PCC(trekClient.GetCfgInfo().strFilelistSite),
  520. PCC(trekClient.GetCfgInfo().strFilelistDirectory),
  521. "blah", // account
  522. "blah"); // pw
  523. trekClient.m_pAutoDownload->SetOfficialFileListAttributes(trekClient.GetCfgInfo().crcFileList,
  524. trekClient.GetCfgInfo().nFilelistSize);
  525. trekClient.m_pAutoDownload->SetArtPath(trekClient.GetArtPath());
  526. //
  527. // Let's do it!
  528. //
  529. trekClient.m_pAutoDownload->BeginUpdate(pAutoUpdateSink, bForceFileCheck, false);
  530. // m_pAutoDownload could be NULL at this point, if the autodownload system decided
  531. // not to do a download after all. This can happen if there is an error or if
  532. // the client was already up-to-date.
  533. }
  534. else
  535. {
  536. // signal successful update/version already up-to-date
  537. OnAutoUpdateSystemTermination(false, false);
  538. }
  539. }
  540. else
  541. {
  542. debugf("Your cfg file is missing one or more of the following:\nFilelistCRC, FilelistSize, FilelistSite, FilelistDirectory\nSkipping AutoUpdate.\n");
  543. // signal successful update/version already up-to-date
  544. OnAutoUpdateSystemTermination(false, false);
  545. // m_pmsgBox = CreateMessageBox("Unable to connect to Zone. CFG File is missing key components. Please try again later.");
  546. // GetWindow()->GetPopupContainer()->OpenPopup(m_pmsgBox, false);
  547. }
  548. }
  549. else
  550. {
  551. // signal successful update/version already up-to-date
  552. OnAutoUpdateSystemTermination(false, false);
  553. }
  554. BeginMessageOfDayDownload();
  555. }
  556. else
  557. m_pbuttonMainMenu->SetEnabled(true); // allow users to leave screen even if cfg file failed to download
  558. }
  559. void OnMessageOfDayDone(bool bSuccessful)
  560. {
  561. if (m_pSession)
  562. {
  563. delete m_pSession;
  564. m_pSession = NULL;
  565. }
  566. m_pbuttonMainMenu->SetEnabled(true); // allow users to leave screen even if cfg file failed to download
  567. if (bSuccessful)
  568. {
  569. debugf("Loading messageoftheday file.\n");
  570. m_pMDLFileImage->Load(trekClient.GetIsZoneClub()
  571. ? "clubmessageoftheday" : "publicmessageoftheday");
  572. }
  573. else
  574. {
  575. debugf("Errors detected while downloading message of the day. Skipping load.\n");
  576. }
  577. }
  578. ////////////////////////////////////////////////////////////////////
  579. //
  580. // Events associated with IAutoDownloadSink
  581. //
  582. ////////////////////////////////////////////////////////////////////
  583. virtual void OnAutoUpdateSystemTermination(bool bErrorOccurred, bool bRestarting)
  584. {
  585. m_pbuttonMainMenu->SetEnabled(true); // force download to finish before leaving this screen
  586. if (!bErrorOccurred && !bRestarting)
  587. {
  588. m_pbuttonGames->SetEnabled(true);
  589. m_pbuttonGamesBig->SetEnabled(true);
  590. if (trekClient.GetIsZoneClub())
  591. {
  592. m_pbuttonPlayerProfile->SetEnabled(true);
  593. m_pbuttonLeaderboard->SetEnabled(true);
  594. m_pbuttonSquads->SetEnabled(!g_bDisableZoneClub);
  595. m_pbuttonZoneEvents->SetEnabled(!trekClient.GetCfgInfo().strZoneEventsURL.IsEmpty());
  596. }
  597. }
  598. }
  599. ////////////////////////////////////////////////////////////////////
  600. //
  601. // Events associated with IIntegerEventSink
  602. //
  603. ////////////////////////////////////////////////////////////////////
  604. bool OnEvent(IIntegerEventSource* pevent, int value)
  605. {
  606. //
  607. // User must have pressed Okay button after error
  608. //
  609. assert(m_pmsgBox);
  610. GetWindow()->GetPopupContainer()->ClosePopup(m_pmsgBox);
  611. GetWindow()->RestoreCursor();
  612. return false;
  613. }
  614. //////////////////////////////////////////////////////////////////////////////
  615. //
  616. // LogonSite methods
  617. //
  618. //////////////////////////////////////////////////////////////////////////////
  619. void OnLogon(const ZString& strName, const ZString& strPassword, BOOL fRememberPW)
  620. {
  621. lstrcpy(m_szName, strName);
  622. lstrcpy(m_szPW, strPassword);
  623. m_fRememberPW = fRememberPW;
  624. #ifdef USEAUTH
  625. #else
  626. trekClient.SaveCharacterName(strName);
  627. #endif
  628. GetWindow()->SetWaitCursor();
  629. TRef<IMessageBox> pmsgBox = CreateMessageBox("Connecting...", NULL, false);
  630. Point point(c_PopupX, c_PopupY);
  631. Rect rect(point, point);
  632. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, rect, false);
  633. // pause to let the "connecting..." box draw itself
  634. AddEventTarget(OnUsernameAndPassword, GetWindow(), 0.1f);
  635. }
  636. bool OnUsernameAndPassword()
  637. {
  638. HRESULT hr = E_FAIL;
  639. #ifdef USEAUTH
  640. TRef<IZoneAuthClient> pzac;
  641. if (g_fZoneAuth)
  642. {
  643. pzac = trekClient.GetZoneAuthClient();
  644. hr = pzac->Authenticate(m_szName, m_szPW,
  645. !!lstrcmp(m_szPW, m_szPWOrig), m_fRememberPW, 5000);
  646. }
  647. if (g_fZoneAuth && FAILED(hr))
  648. {
  649. bool bRetry;
  650. ZString strReason;
  651. if (ZT_E_AUTH_DENIED == hr)
  652. {
  653. if (trekClient.GetCfgInfo().bUsePassport)
  654. strReason = "Either the username or the password you supplied was incorrect. Be sure to sign in with your Microsoft Passport name (not your Zone ID).";
  655. else
  656. strReason = "Either the username or the password you supplied was incorrect. Please try again.";
  657. bRetry = true;
  658. }
  659. else
  660. {
  661. strReason = "Unable to contact the authentication server. Please check your network connection.";
  662. bRetry = false;
  663. }
  664. // if the logon fails, close the connecting dialog box.
  665. GetWindow()->GetPopupContainer()->ClosePopup(m_pmsgBox);
  666. GetWindow()->RestoreCursor();
  667. if (m_bConnectLobby)
  668. OnLogonLobbyFailed(bRetry, strReason);
  669. else
  670. OnLogonClubFailed(bRetry, strReason);
  671. }
  672. else
  673. #endif
  674. {
  675. s_bWasAuthenticated = true;
  676. BaseClient::ConnectInfo ci;
  677. DWORD cbZoneTicket = 0;
  678. ci.pZoneTicket = NULL;
  679. DWORD cbName = sizeof(ci.szName);
  680. #ifdef USEAUTH
  681. if (g_fZoneAuth)
  682. {
  683. ZSucceeded(pzac->GetTicket(&ci.pZoneTicket, &cbZoneTicket, ci.szName, &cbName));
  684. assert(cbName <= sizeof(ci.szName));
  685. ci.cbZoneTicket = cbZoneTicket;
  686. }
  687. else
  688. #endif
  689. lstrcpy(ci.szName, m_szName);
  690. ZeroMemory(&ci.ftLastArtUpdate, sizeof(ci.ftLastArtUpdate));
  691. if (m_bConnectLobby)
  692. trekClient.ConnectToLobby(&ci);
  693. else
  694. trekClient.ConnectToClub(&ci);
  695. }
  696. return false;
  697. }
  698. void OnAbort()
  699. {
  700. }
  701. void OnLogonLobby()
  702. {
  703. GetWindow()->screen(m_screenPostConnect);
  704. }
  705. void OnLogonLobbyFailed(bool bRetry, const char* szReason)
  706. {
  707. if (bRetry)
  708. {
  709. s_bWasAuthenticated = false;
  710. ConnectToZone(true, m_screenPostConnect, szReason);
  711. }
  712. else
  713. {
  714. TRef<IMessageBox> pmsgBox = CreateMessageBox(szReason);
  715. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  716. }
  717. }
  718. void OnLogonClub()
  719. {
  720. GetWindow()->screen(m_screenPostConnect);
  721. }
  722. void OnLogonClubFailed(bool bRetry, const char* szReason)
  723. {
  724. if (bRetry)
  725. {
  726. s_bWasAuthenticated = false;
  727. ConnectToZone(false, m_screenPostConnect, szReason);
  728. }
  729. else
  730. {
  731. TRef<IMessageBox> pmsgBox = CreateMessageBox(szReason);
  732. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  733. }
  734. }
  735. //////////////////////////////////////////////////////////////////////////////
  736. //
  737. // Screen Methods
  738. //
  739. //////////////////////////////////////////////////////////////////////////////
  740. Pane* GetPane()
  741. {
  742. return m_ppane;
  743. }
  744. };
  745. bool ZoneClubScreen::s_bWasAuthenticated = false;
  746. //////////////////////////////////////////////////////////////////////////////
  747. //
  748. // Constructor
  749. //
  750. //////////////////////////////////////////////////////////////////////////////
  751. TRef<Screen> CreateZoneClubScreen(Modeler* pmodeler, Number * ptime)
  752. {
  753. return new ZoneClubScreen(pmodeler, ptime);
  754. }