lllogininstance.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:13k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file lllogininstance.cpp
  3.  * @brief Viewer's host for a login connection.
  4.  *
  5.  * $LicenseInfo:firstyear=2009&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2009-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "lllogininstance.h"
  34. // llcommon
  35. #include "llevents.h"
  36. #include "llmd5.h"
  37. #include "stringize.h"
  38. // llmessage (!)
  39. #include "llfiltersd2xmlrpc.h" // for xml_escape_string()
  40. // login
  41. #include "lllogin.h"
  42. // newview
  43. #include "llviewernetwork.h"
  44. #include "llviewercontrol.h"
  45. #include "llurlsimstring.h"
  46. #include "llfloaterreg.h"
  47. #include "llnotifications.h"
  48. #include "llwindow.h"
  49. #if LL_LINUX || LL_SOLARIS
  50. #include "lltrans.h"
  51. #endif
  52. static const char * const TOS_REPLY_PUMP = "lllogininstance_tos_callback";
  53. static const char * const TOS_LISTENER_NAME = "lllogininstance_tos";
  54. std::string construct_start_string();
  55. LLLoginInstance::LLLoginInstance() :
  56. mLoginModule(new LLLogin()),
  57. mNotifications(NULL),
  58. mLoginState("offline"),
  59. mUserInteraction(true),
  60. mSkipOptionalUpdate(false),
  61. mAttemptComplete(false),
  62. mTransferRate(0.0f),
  63. mDispatcher("LLLoginInstance", "change")
  64. {
  65. mLoginModule->getEventPump().listen("lllogininstance", 
  66. boost::bind(&LLLoginInstance::handleLoginEvent, this, _1));
  67. mDispatcher.add("fail.login", boost::bind(&LLLoginInstance::handleLoginFailure, this, _1));
  68. mDispatcher.add("connect",    boost::bind(&LLLoginInstance::handleLoginSuccess, this, _1));
  69. mDispatcher.add("disconnect", boost::bind(&LLLoginInstance::handleDisconnect, this, _1));
  70. mDispatcher.add("indeterminate", boost::bind(&LLLoginInstance::handleIndeterminate, this, _1));
  71. }
  72. LLLoginInstance::~LLLoginInstance()
  73. {
  74. }
  75. void LLLoginInstance::connect(const LLSD& credentials)
  76. {
  77. std::vector<std::string> uris;
  78. LLViewerLogin::getInstance()->getLoginURIs(uris);
  79. connect(uris.front(), credentials);
  80. }
  81. void LLLoginInstance::connect(const std::string& uri, const LLSD& credentials)
  82. {
  83. mAttemptComplete = false; // Reset attempt complete at this point!
  84. constructAuthParams(credentials);
  85. mLoginModule->connect(uri, mRequestData);
  86. }
  87. void LLLoginInstance::reconnect()
  88. {
  89. // Sort of like connect, only using the pre-existing
  90. // request params.
  91. std::vector<std::string> uris;
  92. LLViewerLogin::getInstance()->getLoginURIs(uris);
  93. mLoginModule->connect(uris.front(), mRequestData);
  94. }
  95. void LLLoginInstance::disconnect()
  96. {
  97. mAttemptComplete = false; // Reset attempt complete at this point!
  98. mRequestData.clear();
  99. mLoginModule->disconnect();
  100. }
  101. LLSD LLLoginInstance::getResponse() 
  102. {
  103. return mResponseData; 
  104. }
  105. void LLLoginInstance::constructAuthParams(const LLSD& credentials)
  106. {
  107. // Set up auth request options.
  108. //#define LL_MINIMIAL_REQUESTED_OPTIONS
  109. LLSD requested_options;
  110. // *Note: this is where gUserAuth used to be created.
  111. requested_options.append("inventory-root");
  112. requested_options.append("inventory-skeleton");
  113. //requested_options.append("inventory-meat");
  114. //requested_options.append("inventory-skel-targets");
  115. #if (!defined LL_MINIMIAL_REQUESTED_OPTIONS)
  116. if(FALSE == gSavedSettings.getBOOL("NoInventoryLibrary"))
  117. {
  118. requested_options.append("inventory-lib-root");
  119. requested_options.append("inventory-lib-owner");
  120. requested_options.append("inventory-skel-lib");
  121. // requested_options.append("inventory-meat-lib");
  122. }
  123. requested_options.append("initial-outfit");
  124. requested_options.append("gestures");
  125. requested_options.append("event_categories");
  126. requested_options.append("event_notifications");
  127. requested_options.append("classified_categories");
  128. requested_options.append("adult_compliant"); 
  129. //requested_options.append("inventory-targets");
  130. requested_options.append("buddy-list");
  131. requested_options.append("ui-config");
  132. #endif
  133. requested_options.append("tutorial_setting");
  134. requested_options.append("login-flags");
  135. requested_options.append("global-textures");
  136. if(gSavedSettings.getBOOL("ConnectAsGod"))
  137. {
  138. gSavedSettings.setBOOL("UseDebugMenus", TRUE);
  139. requested_options.append("god-connect");
  140. }
  141. char hashed_mac_string[MD5HEX_STR_SIZE]; /* Flawfinder: ignore */
  142. LLMD5 hashed_mac;
  143. hashed_mac.update( gMACAddress, MAC_ADDRESS_BYTES );
  144. hashed_mac.finalize();
  145. hashed_mac.hex_digest(hashed_mac_string);
  146. // prepend "$1$" to the password to indicate its the md5'd version.
  147. std::string dpasswd("$1$");
  148. dpasswd.append(credentials["passwd"].asString());
  149. // (re)initialize the request params with creds.
  150. LLSD request_params(credentials);
  151. request_params["passwd"] = dpasswd;
  152. request_params["start"] = construct_start_string();
  153. request_params["skipoptional"] = mSkipOptionalUpdate;
  154. request_params["agree_to_tos"] = false; // Always false here. Set true in 
  155. request_params["read_critical"] = false; // handleTOSResponse
  156. request_params["last_exec_event"] = mLastExecEvent;
  157. request_params["mac"] = hashed_mac_string;
  158. request_params["version"] = gCurrentVersion; // Includes channel name
  159. request_params["channel"] = gSavedSettings.getString("VersionChannelName");
  160. request_params["id0"] = mSerialNumber;
  161. mRequestData.clear();
  162. mRequestData["method"] = "login_to_simulator";
  163. mRequestData["params"] = request_params;
  164. mRequestData["options"] = requested_options;
  165. mRequestData["cfg_srv_timeout"] = gSavedSettings.getF32("LoginSRVTimeout");
  166. mRequestData["cfg_srv_pump"] = gSavedSettings.getString("LoginSRVPump");
  167. }
  168. bool LLLoginInstance::handleLoginEvent(const LLSD& event)
  169. {
  170. LL_DEBUGS("LLLogin") << "LoginListener called!: n" << event << LL_ENDL;
  171. if(!(event.has("state") && event.has("change") && event.has("progress")))
  172. {
  173. llerrs << "Unknown message from LLLogin: " << event << llendl;
  174. }
  175. mLoginState = event["state"].asString();
  176. mResponseData = event["data"];
  177. if(event.has("transfer_rate"))
  178. {
  179. mTransferRate = event["transfer_rate"].asReal();
  180. }
  181. // Call the method registered in constructor, if any, for more specific
  182. // handling
  183. LLEventDispatcher::Callable method(mDispatcher.get(event["change"]));
  184. if (! method.empty())
  185. {
  186. method(event);
  187. }
  188. return false;
  189. }
  190. void LLLoginInstance::handleLoginFailure(const LLSD& event)
  191. {
  192. // Login has failed. 
  193. // Figure out why and respond...
  194. LLSD response = event["data"];
  195. std::string reason_response = response["reason"].asString();
  196. std::string message_response = response["message"].asString();
  197. if(mUserInteraction)
  198. {
  199. // For the cases of critical message or TOS agreement,
  200. // start the TOS dialog. The dialog response will be handled
  201. // by the LLLoginInstance::handleTOSResponse() callback.
  202. // The callback intiates the login attempt next step, either 
  203. // to reconnect or to end the attempt in failure.
  204. if(reason_response == "tos")
  205. {
  206. LLSD data(LLSD::emptyMap());
  207. data["message"] = message_response;
  208. data["reply_pump"] = TOS_REPLY_PUMP;
  209. LLFloaterReg::showInstance("message_tos", data);
  210. LLEventPumps::instance().obtain(TOS_REPLY_PUMP)
  211. .listen(TOS_LISTENER_NAME,
  212. boost::bind(&LLLoginInstance::handleTOSResponse, 
  213. this, _1, "agree_to_tos"));
  214. }
  215. else if(reason_response == "critical")
  216. {
  217. LLSD data(LLSD::emptyMap());
  218. data["message"] = message_response;
  219. data["reply_pump"] = TOS_REPLY_PUMP;
  220. LLFloaterReg::showInstance("message_critical", data);
  221. LLEventPumps::instance().obtain(TOS_REPLY_PUMP)
  222. .listen(TOS_LISTENER_NAME,
  223. boost::bind(&LLLoginInstance::handleTOSResponse, 
  224. this, _1, "read_critical"));
  225. }
  226. else if(reason_response == "update" || gSavedSettings.getBOOL("ForceMandatoryUpdate"))
  227. {
  228. gSavedSettings.setBOOL("ForceMandatoryUpdate", FALSE);
  229. updateApp(true, message_response);
  230. }
  231. else if(reason_response == "optional")
  232. {
  233. updateApp(false, message_response);
  234. }
  235. else
  236. {
  237. attemptComplete();
  238. }
  239. }
  240. else // no user interaction
  241. {
  242. attemptComplete();
  243. }
  244. }
  245. void LLLoginInstance::handleLoginSuccess(const LLSD& event)
  246. {
  247. if(gSavedSettings.getBOOL("ForceMandatoryUpdate"))
  248. {
  249. LLSD response = event["data"];
  250. std::string message_response = response["message"].asString();
  251. // Testing update...
  252. gSavedSettings.setBOOL("ForceMandatoryUpdate", FALSE);
  253. // Don't confuse startup by leaving login "online".
  254. mLoginModule->disconnect(); 
  255. updateApp(true, message_response);
  256. }
  257. else
  258. {
  259. attemptComplete();
  260. }
  261. }
  262. void LLLoginInstance::handleDisconnect(const LLSD& event)
  263. {
  264.     // placeholder
  265. }
  266. void LLLoginInstance::handleIndeterminate(const LLSD& event)
  267. {
  268. // The indeterminate response means that the server
  269. // gave the viewer a new url and params to try.
  270. // The login module handles the retry, but it gives us the
  271. // server response so that we may show
  272. // the user some status.
  273. LLSD message = event.get("data").get("message");
  274. if(message.isDefined())
  275. {
  276. LLSD progress_update;
  277. progress_update["desc"] = message;
  278. LLEventPumps::getInstance()->obtain("LLProgressView").post(progress_update);
  279. }
  280. }
  281. bool LLLoginInstance::handleTOSResponse(bool accepted, const std::string& key)
  282. {
  283. if(accepted)
  284. {
  285. // Set the request data to true and retry login.
  286. mRequestData["params"][key] = true; 
  287. reconnect();
  288. }
  289. else
  290. {
  291. attemptComplete();
  292. }
  293. LLEventPumps::instance().obtain(TOS_REPLY_PUMP).stopListening(TOS_LISTENER_NAME);
  294. return true;
  295. }
  296. void LLLoginInstance::updateApp(bool mandatory, const std::string& auth_msg)
  297. {
  298. // store off config state, as we might quit soon
  299. gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
  300. LLUIColorTable::instance().saveUserSettings();
  301. std::ostringstream message;
  302. std::string msg;
  303. if (!auth_msg.empty())
  304. {
  305. msg = "(" + auth_msg + ") n";
  306. }
  307. LLSD args;
  308. args["MESSAGE"] = msg;
  309. LLSD payload;
  310. payload["mandatory"] = mandatory;
  311. /*
  312.  We're constructing one of the following 6 strings here:
  313.  "DownloadWindowsMandatory"
  314.  "DownloadWindowsReleaseForDownload"
  315.  "DownloadWindows"
  316.  "DownloadMacMandatory"
  317.  "DownloadMacReleaseForDownload"
  318.  "DownloadMac"
  319.  
  320.  I've called them out explicitly in this comment so that they can be grepped for.
  321.  
  322.  Also, we assume that if we're not Windows we're Mac. If we ever intend to support 
  323.  Linux with autoupdate, this should be an explicit #elif LL_DARWIN, but 
  324.  we'd rather deliver the wrong message than no message, so until Linux is supported
  325.  we'll leave it alone.
  326.  */
  327. std::string notification_name = "Download";
  328. #if LL_WINDOWS
  329. notification_name += "Windows";
  330. #elif LL_DARWIN
  331. notification_name += "Mac";
  332. #else
  333. notification_name += "Linux";
  334. #endif
  335. if (mandatory)
  336. {
  337. notification_name += "Mandatory";
  338. }
  339. else
  340. {
  341. #if LL_RELEASE_FOR_DOWNLOAD
  342. notification_name += "ReleaseForDownload";
  343. #endif
  344. }
  345. if(mNotifications)
  346. {
  347. mNotifications->add(notification_name, args, payload, 
  348. boost::bind(&LLLoginInstance::updateDialogCallback, this, _1, _2));
  349. }
  350. }
  351. bool LLLoginInstance::updateDialogCallback(const LLSD& notification, const LLSD& response)
  352. {
  353. S32 option = LLNotification::getSelectedOption(notification, response);
  354. std::string update_exe_path;
  355. bool mandatory = notification["payload"]["mandatory"].asBoolean();
  356. #if !LL_RELEASE_FOR_DOWNLOAD
  357. if (option == 2)
  358. {
  359. // This condition attempts to skip the 
  360. // update if using a dev build.
  361. // The relog probably won't work if the 
  362. // update is mandatory. :)
  363.     // *REMOVE:Mani - Saving for reference...
  364. //LLStartUp::setStartupState( STATE_LOGIN_AUTH_INIT ); 
  365. mSkipOptionalUpdate = true;
  366. reconnect();
  367. return false;
  368. }
  369. #endif
  370. if (option == 1)
  371. {
  372. // ...user doesn't want to do it
  373. if (mandatory)
  374. {
  375. // Mandatory update, user chose to not to update...
  376. // The login attemp is complete, startup should 
  377. // quit when detecting this.
  378. attemptComplete();
  379. // *REMOVE:Mani - Saving for reference...
  380. //LLAppViewer::instance()->forceQuit();
  381. // // Bump them back to the login screen.
  382. // //reset_login();
  383. }
  384. else
  385. {
  386. // Optional update, user chose to skip
  387. mSkipOptionalUpdate = true;
  388. reconnect();
  389. }
  390. return false;
  391. }
  392.   if(mUpdaterLauncher)
  393.    {
  394.   mUpdaterLauncher();
  395.    }
  396.   
  397.   attemptComplete();
  398. return false;
  399. }
  400. std::string construct_start_string()
  401. {
  402. std::string start;
  403. if (LLURLSimString::parse())
  404. {
  405. // a startup URL was specified
  406. std::string unescaped_start = 
  407. STRINGIZE(  "uri:" 
  408. << LLURLSimString::sInstance.mSimName << "&" 
  409. << LLURLSimString::sInstance.mX << "&" 
  410. << LLURLSimString::sInstance.mY << "&" 
  411. << LLURLSimString::sInstance.mZ);
  412. start = xml_escape_string(unescaped_start);
  413. }
  414. else
  415. {
  416. start = gSavedSettings.getString("LoginLocation");
  417. }
  418. return start;
  419. }