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

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llviewernetwork.cpp
  3.  * @author James Cook, Richard Nelson
  4.  * @brief Networking constants and globals for viewer.
  5.  *
  6.  * $LicenseInfo:firstyear=2006&license=viewergpl$
  7.  * 
  8.  * Copyright (c) 2006-2010, Linden Research, Inc.
  9.  * 
  10.  * Second Life Viewer Source Code
  11.  * The source code in this file ("Source Code") is provided by Linden Lab
  12.  * to you under the terms of the GNU General Public License, version 2.0
  13.  * ("GPL"), unless you have obtained a separate licensing agreement
  14.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  15.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17.  * 
  18.  * There are special exceptions to the terms and conditions of the GPL as
  19.  * it is applied to this Source Code. View the full text of the exception
  20.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  21.  * online at
  22.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23.  * 
  24.  * By copying, modifying or distributing this software, you acknowledge
  25.  * that you have read and understood your obligations described above,
  26.  * and agree to abide by those obligations.
  27.  * 
  28.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30.  * COMPLETENESS OR PERFORMANCE.
  31.  * $/LicenseInfo$
  32.  */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llviewernetwork.h"
  35. #include "llevents.h"
  36. #include "net.h"
  37. #include "llviewercontrol.h"
  38. #include "lllogin.h"
  39. struct LLGridData
  40. {
  41. const char* mLabel;
  42. const char* mName;
  43. const char* mLoginURI;
  44. const char* mHelperURI;
  45. };
  46. static LLGridData gGridInfo[GRID_INFO_COUNT] = 
  47. {
  48. { "None", "", "", ""},
  49. { "Aditi", 
  50.   "util.aditi.lindenlab.com", 
  51.   "https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
  52.   "http://aditi-secondlife.webdev.lindenlab.com/helpers/" },
  53. { "Agni", 
  54.   "util.agni.lindenlab.com", 
  55.   "https://login.agni.lindenlab.com/cgi-bin/login.cgi",
  56.   "https://secondlife.com/helpers/" },
  57. { "Aruna",
  58.   "util.aruna.lindenlab.com",
  59.   "https://login.aruna.lindenlab.com/cgi-bin/login.cgi",
  60.   "http://aruna-secondlife.webdev.lindenlab.com/helpers/" },
  61. { "Bharati",
  62.   "util.bharati.lindenlab.com",
  63.   "https://login.bharati.lindenlab.com/cgi-bin/login.cgi",
  64.   "http://bharati-secondlife.webdev.lindenlab.com/helpers/" },
  65. { "Chandra",
  66.   "util.chandra.lindenlab.com",
  67.   "https://login.chandra.lindenlab.com/cgi-bin/login.cgi",
  68.   "http://chandra-secondlife.webdev.lindenlab.com/helpers/" },
  69. { "Damballah",
  70.   "util.damballah.lindenlab.com",
  71.   "https://login.damballah.lindenlab.com/cgi-bin/login.cgi",
  72.   "http://damballah-secondlife.webdev.lindenlab.com/helpers/" },
  73. { "Danu",
  74.   "util.danu.lindenlab.com",
  75.   "https://login.danu.lindenlab.com/cgi-bin/login.cgi",
  76.   "http://danu-secondlife.webdev.lindenlab.com/helpers/" },
  77. { "Durga",
  78.   "util.durga.lindenlab.com",
  79.   "https://login.durga.lindenlab.com/cgi-bin/login.cgi",
  80.   "http://durga-secondlife.webdev.lindenlab.com/helpers/" },
  81. { "Ganga",
  82.   "util.ganga.lindenlab.com",
  83.   "https://login.ganga.lindenlab.com/cgi-bin/login.cgi",
  84.   "http://ganga-secondlife.webdev.lindenlab.com/helpers/" },
  85. { "Mitra",
  86.   "util.mitra.lindenlab.com",
  87.   "https://login.mitra.lindenlab.com/cgi-bin/login.cgi",
  88.   "http://mitra-secondlife.webdev.lindenlab.com/helpers/" },
  89. { "Mohini",
  90.   "util.mohini.lindenlab.com",
  91.   "https://login.mohini.lindenlab.com/cgi-bin/login.cgi",
  92.   "http://mohini-secondlife.webdev.lindenlab.com/helpers/" },
  93.    { "Nandi",
  94.   "util.nandi.lindenlab.com",
  95.   "https://login.nandi.lindenlab.com/cgi-bin/login.cgi",
  96.   "http://nandi-secondlife.webdev.lindenlab.com/helpers/" },
  97. { "Parvati",
  98.   "util.parvati.lindenlab.com",
  99.   "https://login.parvati.lindenlab.com/cgi-bin/login.cgi",
  100.   "http://parvati-secondlife.webdev.lindenlab.com/helpers/" },
  101. { "Radha",
  102.   "util.radha.lindenlab.com",
  103.   "https://login.radha.lindenlab.com/cgi-bin/login.cgi",
  104.   "http://radha-secondlife.webdev.lindenlab.com/helpers/" },
  105. { "Ravi",
  106.   "util.ravi.lindenlab.com",
  107.   "https://login.ravi.lindenlab.com/cgi-bin/login.cgi",
  108.   "http://ravi-secondlife.webdev.lindenlab.com/helpers/" },
  109. { "Siva", 
  110.   "util.siva.lindenlab.com",
  111.   "https://login.siva.lindenlab.com/cgi-bin/login.cgi",
  112.   "http://siva-secondlife.webdev.lindenlab.com/helpers/" },
  113. { "Shakti",
  114.   "util.shakti.lindenlab.com",
  115.   "https://login.shakti.lindenlab.com/cgi-bin/login.cgi",
  116.   "http://shakti-secondlife.webdev.lindenlab.com/helpers/" },
  117. { "Skanda",
  118.   "util.skanda.lindenlab.com",
  119.   "https://login.skanda.lindenlab.com/cgi-bin/login.cgi",
  120.   "http://skanda-secondlife.webdev.lindenlab.com/helpers/" },
  121. { "Soma",
  122.   "util.soma.lindenlab.com",
  123.   "https://login.soma.lindenlab.com/cgi-bin/login.cgi",
  124.   "http://soma-secondlife.webdev.lindenlab.com/helpers/" },
  125. { "Uma",
  126.   "util.uma.lindenlab.com",
  127.   "https://login.uma.lindenlab.com/cgi-bin/login.cgi",
  128.   "http://uma-secondlife.webdev.lindenlab.com/helpers/" },
  129. { "Vaak",
  130.   "util.vaak.lindenlab.com",
  131.   "https://login.vaak.lindenlab.com/cgi-bin/login.cgi",
  132.   "http://vaak-secondlife.webdev.lindenlab.com/helpers/" },
  133. { "Yami",
  134.   "util.yami.lindenlab.com",
  135.   "https://login.yami.lindenlab.com/cgi-bin/login.cgi",
  136.   "http://yami-secondlife.webdev.lindenlab.com/helpers/" },
  137. { "Local", 
  138.   "localhost", 
  139.   "https://login.dmz.lindenlab.com/cgi-bin/login.cgi",
  140.   "" },
  141. { "Other", 
  142.   "", 
  143.   "https://login.dmz.lindenlab.com/cgi-bin/login.cgi",
  144.   "" }
  145. };
  146. const EGridInfo DEFAULT_GRID_CHOICE = GRID_INFO_AGNI;
  147. unsigned char gMACAddress[MAC_ADDRESS_BYTES]; /* Flawfinder: ignore */
  148. LLViewerLogin::LLViewerLogin() :
  149. mGridChoice(DEFAULT_GRID_CHOICE)
  150. {
  151. }
  152.  LLViewerLogin::~LLViewerLogin() 
  153.  {
  154.  }
  155. void LLViewerLogin::setGridChoice(EGridInfo grid)
  156. {
  157. if(grid < 0 || grid >= GRID_INFO_COUNT)
  158. {
  159. llerrs << "Invalid grid index specified." << llendl;
  160. return;
  161. }
  162. if(mGridChoice != grid || gSavedSettings.getS32("ServerChoice") != grid)
  163. {
  164. mGridChoice = grid;
  165. if(GRID_INFO_LOCAL == mGridChoice)
  166. {
  167. mGridName = LOOPBACK_ADDRESS_STRING;
  168. }
  169. else if(GRID_INFO_OTHER == mGridChoice)
  170. {
  171. // *FIX:Mani - could this possibly be valid?
  172. mGridName = "other"; 
  173. }
  174. else
  175. {
  176. mGridName = gGridInfo[mGridChoice].mLabel;
  177. }
  178. gSavedSettings.setS32("ServerChoice", mGridChoice);
  179. gSavedSettings.setString("CustomServer", "");
  180. }
  181. }
  182. void LLViewerLogin::setGridChoice(const std::string& grid_name)
  183. {
  184. // Set the grid choice based on a string.
  185. // The string can be:
  186. // - a grid label from the gGridInfo table 
  187. // - an ip address
  188.     if(!grid_name.empty())
  189.     {
  190.         // find the grid choice from the user setting.
  191.         int grid_index = GRID_INFO_NONE; 
  192.         for(;grid_index < GRID_INFO_OTHER; ++grid_index)
  193.         {
  194.             if(0 == LLStringUtil::compareInsensitive(gGridInfo[grid_index].mLabel, grid_name))
  195.             {
  196. // Founding a matching label in the list...
  197. setGridChoice((EGridInfo)grid_index);
  198. break;
  199.             }
  200.         }
  201.         if(GRID_INFO_OTHER == grid_index)
  202.         {
  203.             // *FIX:MEP Can and should we validate that this is an IP address?
  204.             mGridChoice = GRID_INFO_OTHER;
  205.             mGridName = grid_name;
  206. gSavedSettings.setS32("ServerChoice", mGridChoice);
  207. gSavedSettings.setString("CustomServer", mGridName);
  208.         }
  209.     }
  210. }
  211. void LLViewerLogin::resetURIs()
  212. {
  213.     // Clear URIs when picking a new server
  214. gSavedSettings.setLLSD("CmdLineLoginURI", LLSD::emptyArray());
  215. gSavedSettings.setString("CmdLineHelperURI", "");
  216. }
  217. EGridInfo LLViewerLogin::getGridChoice() const
  218. {
  219. return mGridChoice;
  220. }
  221. std::string LLViewerLogin::getGridLabel() const
  222. {
  223. if(mGridChoice == GRID_INFO_NONE)
  224. {
  225. return "None";
  226. }
  227. else if(mGridChoice < GRID_INFO_OTHER)
  228. {
  229. return gGridInfo[mGridChoice].mLabel;
  230. }
  231. return mGridName;
  232. }
  233. std::string LLViewerLogin::getKnownGridLabel(EGridInfo grid_index) const
  234. {
  235. if(grid_index > GRID_INFO_NONE && grid_index < GRID_INFO_OTHER)
  236. {
  237. return gGridInfo[grid_index].mLabel;
  238. }
  239. return gGridInfo[GRID_INFO_NONE].mLabel;
  240. }
  241. void LLViewerLogin::getLoginURIs(std::vector<std::string>& uris) const
  242. {
  243. // return the login uri set on the command line.
  244. LLControlVariable* c = gSavedSettings.getControl("CmdLineLoginURI");
  245. if(c)
  246. {
  247. LLSD v = c->getValue();
  248. if(v.isArray())
  249. {
  250. for(LLSD::array_const_iterator itr = v.beginArray();
  251. itr != v.endArray(); ++itr)
  252. {
  253. std::string uri = itr->asString();
  254. if(!uri.empty())
  255. {
  256. uris.push_back(uri);
  257. }
  258. }
  259. }
  260. else
  261. {
  262. std::string uri = v.asString();
  263. if(!uri.empty())
  264. {
  265. uris.push_back(uri);
  266. }
  267. }
  268. }
  269. // If there was no command line uri...
  270. if(uris.empty())
  271. {
  272. // If its a known grid choice, get the uri from the table,
  273. // else try the grid name.
  274. if(mGridChoice > GRID_INFO_NONE && mGridChoice < GRID_INFO_OTHER)
  275. {
  276. uris.push_back(gGridInfo[mGridChoice].mLoginURI);
  277. }
  278. else
  279. {
  280. uris.push_back(mGridName);
  281. }
  282. }
  283. }
  284. std::string LLViewerLogin::getHelperURI() const
  285. {
  286. std::string helper_uri = gSavedSettings.getString("CmdLineHelperURI");
  287. if (helper_uri.empty())
  288. {
  289. // grab URI from selected grid
  290. if(mGridChoice > GRID_INFO_NONE && mGridChoice < GRID_INFO_OTHER)
  291. {
  292. helper_uri = gGridInfo[mGridChoice].mHelperURI;
  293. }
  294. if (helper_uri.empty())
  295. {
  296. // what do we do with unnamed/miscellaneous grids?
  297. // for now, operations that rely on the helper URI (currency/land purchasing) will fail
  298. }
  299. }
  300. return helper_uri;
  301. }
  302. bool LLViewerLogin::isInProductionGrid()
  303. {
  304. // *NOTE:Mani This used to compare GRID_INFO_AGNI to gGridChoice,
  305. // but it seems that loginURI trumps that.
  306. std::vector<std::string> uris;
  307. getLoginURIs(uris);
  308. LLStringUtil::toLower(uris[0]);
  309. if((uris[0].find("agni") != std::string::npos))
  310. {
  311. return true;
  312. }
  313. return false;
  314. }