logon.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #include "pch.h"
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Logon Popup
  5. //
  6. //////////////////////////////////////////////////////////////////////////////
  7. class LogonPopup :
  8. public IPopup,
  9. public EventTargetContainer<LogonPopup>,
  10. public TEvent<ZString>::Sink
  11. {
  12. private:
  13. TRef<Pane> m_ppane;
  14. TRef<ButtonPane> m_pbuttonLogon;
  15. TRef<ButtonPane> m_pbuttonAbort;
  16. TRef<ButtonPane> m_pbuttonSignUp;
  17. TRef<ButtonPane> m_pbuttonCDKey;
  18. TRef<ButtonPane> m_pbuttonSavePassword;
  19. TRef<EditPane> m_peditName;
  20. TRef<EditPane> m_peditPassword;
  21. TRef<Pane> m_ppanePassword;
  22. TRef<LogonSite> m_psite;
  23. TRef<IKeyboardInput> m_pfocus;
  24. LogonType m_lt;
  25. public:
  26. LogonPopup(Modeler* pmodeler, LogonSite* psite, LogonType lt,
  27. LPCSTR szPrompt, LPCSTR szName, LPCSTR szPW, BOOL fRememberPW) :
  28. m_psite(psite),
  29. m_lt(lt)
  30. {
  31. enum LogonNameType { lntCallsign, lntZone, lntPassport } logonNameType;
  32. if (lt == LogonLAN)
  33. logonNameType = lntCallsign;
  34. else if (trekClient.GetCfgInfo().bUsePassport)
  35. logonNameType = lntPassport;
  36. else
  37. logonNameType = lntZone;
  38. TRef<INameSpace> pnsLogonData = pmodeler->CreateNameSpace("logondata", pmodeler->GetNameSpace("gamepanes"));
  39. pnsLogonData->AddMember("promptText", new ModifiableString(szPrompt));
  40. pnsLogonData->AddMember("Callsign", new ModifiableNumber((float)lntCallsign));
  41. pnsLogonData->AddMember("ZoneID", new ModifiableNumber((float)lntZone));
  42. pnsLogonData->AddMember("PassportID", new ModifiableNumber((float)lntPassport));
  43. pnsLogonData->AddMember("logonNameType", new ModifiableNumber((float)logonNameType));
  44. TRef<INameSpace> pns = pmodeler->GetNameSpace("logon");
  45. CastTo(m_ppane, pns->FindMember("popup"));
  46. CastTo(m_pbuttonLogon, pns->FindMember("logonButtonPane"));
  47. AddEventTarget(OnButtonLogon, m_pbuttonLogon->GetEventSource());
  48. CastTo(m_pbuttonAbort, pns->FindMember("abortButtonPane"));
  49. AddEventTarget(OnButtonAbort, m_pbuttonAbort->GetEventSource());
  50. CastTo(m_pbuttonSignUp, pns->FindMember("signUpButtonPane"));
  51. AddEventTarget(OnButtonSignUp, m_pbuttonSignUp->GetEventSource());
  52. CastTo(m_pbuttonCDKey, pns->FindMember("cdKeyButtonPane"));
  53. AddEventTarget(OnButtonCDKey, m_pbuttonCDKey->GetEventSource());
  54. CastTo(m_peditName, (Pane*)pns->FindMember("nameEditPane" ));
  55. AddEventTarget(OnNameClick, m_peditName->GetClickEvent());
  56. CastTo(m_pbuttonSavePassword, pns->FindMember("savePasswordButtonPane"));
  57. CastTo(m_ppanePassword, pns->FindMember("passwordPane"));
  58. CastTo(m_peditPassword, (Pane*)pns->FindMember("passwordEditPane"));
  59. AddEventTarget(OnPasswordClick, m_peditPassword->GetClickEvent());
  60. m_peditPassword->SetType(EditPane::Password);
  61. m_peditPassword->SetString(ZString());
  62. m_peditName->SetString(ZString());
  63. // !!! disable logon button if name is empty
  64. // Get defaults
  65. if (LogonLAN == lt)
  66. {
  67. m_ppanePassword->SetHidden(true);
  68. m_pbuttonSavePassword->SetHidden(true);
  69. m_pbuttonCDKey->SetHidden(true);
  70. m_pbuttonSignUp->SetHidden(true);
  71. }
  72. else
  73. {
  74. m_peditPassword->SetString(szPW);
  75. m_pbuttonSavePassword->SetChecked(!!fRememberPW);
  76. }
  77. m_peditName->SetString(szName);
  78. m_peditName->SetMaxLength((LogonLAN != lt && trekClient.GetCfgInfo().bUsePassport)
  79. ? (c_cbPassportName - 1)
  80. : (c_cbName - 1)
  81. );
  82. if (m_peditName->GetString().IsEmpty()) {
  83. SetFocus(m_peditName);
  84. } else {
  85. SetFocus(m_peditPassword);
  86. }
  87. pmodeler->UnloadNameSpace(pns);
  88. }
  89. bool OnButtonLogon()
  90. {
  91. // Make sure that they have entered a CD Key
  92. if (g_bAskForCDKey && trekClient.GetCDKey().IsEmpty())
  93. {
  94. TRef<IPopup> ppopupCDKey = CreateCDKeyPopup();
  95. GetWindow()->GetPopupContainer()->OpenPopup(ppopupCDKey, false);
  96. }
  97. else
  98. {
  99. //
  100. // Grab info from the controls
  101. //
  102. ZString strName = m_peditName->GetString();
  103. ZString strPassword = m_peditPassword->GetString();
  104. bool fRememberPW = m_pbuttonSavePassword->GetChecked();
  105. if (strName[0] != ' ' && strName[0] != '\0') // give 'em a msg box?
  106. {
  107. //
  108. // Close
  109. //
  110. TRef<LogonPopup> pthis = this;
  111. ClosePopup(NULL);
  112. //
  113. // Tell the site
  114. //
  115. m_psite->OnLogon(strName, strPassword, fRememberPW);
  116. }
  117. }
  118. return true;
  119. }
  120. bool OnButtonAbort()
  121. {
  122. m_psite->OnAbort();
  123. ClosePopup(NULL);
  124. return true;
  125. }
  126. bool OnButtonSignUp()
  127. {
  128. GetWindow()->ShowWebPage("http://www.zone.com/allegiance/minilaunch1.asp");
  129. return true;
  130. }
  131. bool OnButtonCDKey()
  132. {
  133. TRef<IPopup> ppopupCDKey = CreateCDKeyPopup();
  134. GetWindow()->GetPopupContainer()->OpenPopup(ppopupCDKey, false);
  135. return true;
  136. }
  137. void SetFocus(IKeyboardInput* pfocus)
  138. {
  139. if (m_pfocus) {
  140. m_pfocus->SetFocusState(false);
  141. }
  142. m_pfocus = pfocus;
  143. m_pfocus->SetFocusState(true);
  144. }
  145. bool OnEvent(TEvent<ZString>::Source* psource, ZString str)
  146. {
  147. m_pbuttonLogon->SetEnabled(!str.IsEmpty());
  148. return true;
  149. }
  150. bool OnNameClick()
  151. {
  152. SetFocus(m_peditName);
  153. return true;
  154. }
  155. bool OnPasswordClick()
  156. {
  157. SetFocus(m_peditPassword);
  158. return true;
  159. }
  160. //////////////////////////////////////////////////////////////////////////////
  161. //
  162. // IPopup Methods
  163. //
  164. //////////////////////////////////////////////////////////////////////////////
  165. void SetContainer(IPopupContainer* pcontainer)
  166. {
  167. IPopup::SetContainer(pcontainer);
  168. if (g_bQuickstart || g_bReloaded)
  169. {
  170. g_bReloaded = false; // we do this just once
  171. OnButtonLogon();
  172. }
  173. }
  174. Pane* GetPane()
  175. {
  176. return m_ppane;
  177. }
  178. //////////////////////////////////////////////////////////////////////////////
  179. //
  180. // IKeyboardInput Methods
  181. //
  182. //////////////////////////////////////////////////////////////////////////////
  183. bool OnKey(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
  184. {
  185. if (ks.bDown)
  186. {
  187. if (ks.vk == VK_RETURN)
  188. {
  189. if (m_pbuttonLogon->GetEnabled())
  190. {
  191. OnButtonLogon();
  192. }
  193. else
  194. {
  195. OnButtonAbort();
  196. }
  197. return true;
  198. }
  199. else if (ks.vk == VK_ESCAPE)
  200. {
  201. OnButtonAbort();
  202. return true;
  203. }
  204. else if (ks.vk == VK_TAB)
  205. {
  206. if (m_pfocus == m_peditName
  207. && (LogonAllegianceZone == m_lt || LogonFreeZone == m_lt))
  208. {
  209. SetFocus(m_peditPassword);
  210. } else
  211. {
  212. SetFocus(m_peditName);
  213. }
  214. return true;
  215. }
  216. }
  217. return m_pfocus->OnKey(pprovider, ks, fForceTranslate);
  218. }
  219. bool OnChar(IInputProvider* pprovider, const KeyState& ks)
  220. {
  221. return m_pfocus->OnChar(pprovider, ks);
  222. }
  223. };
  224. //////////////////////////////////////////////////////////////////////////////
  225. //
  226. // Constructor
  227. //
  228. //////////////////////////////////////////////////////////////////////////////
  229. TRef<IPopup> CreateLogonPopup(Modeler* pmodeler, LogonSite* psite, LogonType lt, LPCSTR szPrompt, LPCSTR szName, LPCSTR szPW, BOOL fRememberPW)
  230. {
  231. return new LogonPopup(pmodeler, psite, lt, szPrompt, szName, szPW, fRememberPW);
  232. }