OpenGridProtocolModule.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Net;
  31. using System.Net.Security;
  32. using System.Security.Cryptography.X509Certificates;
  33. using System.Reflection;
  34. using System.Threading;
  35. using System.Web;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. using OpenMetaverse.Packets;
  39. using log4net;
  40. using Nini.Config;
  41. using OpenSim.Framework;
  42. using OpenSim.Framework.Servers;
  43. using OpenSim.Region.Environment.Interfaces;
  44. using OpenSim.Region.Environment.Scenes;
  45. using OSD = OpenMetaverse.StructuredData.OSD;
  46. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  47. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  48. namespace OpenSim.Region.Environment.Modules.InterGrid
  49. {
  50. public struct OGPState
  51. {
  52. public string first_name;
  53. public string last_name;
  54. public UUID agent_id;
  55. public UUID local_agent_id;
  56. public UUID region_id;
  57. public uint circuit_code;
  58. public UUID secure_session_id;
  59. public UUID session_id;
  60. public bool agent_access;
  61. public string sim_access;
  62. public uint god_level;
  63. public bool god_overide;
  64. public bool identified;
  65. public bool transacted;
  66. public bool age_verified;
  67. public bool allow_redirect;
  68. public int limited_to_estate;
  69. public string inventory_host;
  70. public bool src_can_see_mainland;
  71. public int src_estate_id;
  72. public int src_version;
  73. public int src_parent_estate_id;
  74. public bool visible_to_parent;
  75. public string teleported_into_region;
  76. }
  77. public class OpenGridProtocolModule : IRegionModule
  78. {
  79. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  80. private List<Scene> m_scene = new List<Scene>();
  81. private Dictionary<string, AgentCircuitData> CapsLoginID = new Dictionary<string, AgentCircuitData>();
  82. private Dictionary<UUID, OGPState> m_OGPState = new Dictionary<UUID, OGPState>();
  83. private Dictionary<string, string> m_loginToRegionState = new Dictionary<string, string>();
  84. private string LastNameSuffix = "_EXTERNAL";
  85. private string FirstNamePrefix = "";
  86. private string httpsCN = "";
  87. private bool httpSSL = false;
  88. private uint httpsslport = 0;
  89. private bool GridMode = false;
  90. #region IRegionModule Members
  91. public void Initialise(Scene scene, IConfigSource config)
  92. {
  93. bool enabled = false;
  94. IConfig cfg = null;
  95. IConfig httpcfg = null;
  96. IConfig startupcfg = null;
  97. try
  98. {
  99. cfg = config.Configs["OpenGridProtocol"];
  100. } catch (NullReferenceException)
  101. {
  102. enabled = false;
  103. }
  104. try
  105. {
  106. httpcfg = config.Configs["Network"];
  107. }
  108. catch (NullReferenceException)
  109. {
  110. }
  111. try
  112. {
  113. startupcfg = config.Configs["Startup"];
  114. }
  115. catch (NullReferenceException)
  116. {
  117. }
  118. if (startupcfg != null)
  119. {
  120. GridMode = enabled = startupcfg.GetBoolean("gridmode", false);
  121. }
  122. if (cfg != null)
  123. {
  124. enabled = cfg.GetBoolean("ogp_enabled", false);
  125. LastNameSuffix = cfg.GetString("ogp_lastname_suffix", "_EXTERNAL");
  126. FirstNamePrefix = cfg.GetString("ogp_firstname_prefix", "");
  127. if (enabled)
  128. {
  129. m_log.Warn("[OGP]: Open Grid Protocol is on, Listening for Clients on /agent/");
  130. lock (m_scene)
  131. {
  132. if (m_scene.Count == 0)
  133. {
  134. scene.AddLLSDHandler("/agent/", ProcessAgentDomainMessage);
  135. scene.AddLLSDHandler("/", ProcessRegionDomainSeed);
  136. try
  137. {
  138. ServicePointManager.ServerCertificateValidationCallback += customXertificateValidation;
  139. }
  140. catch (NotImplementedException)
  141. {
  142. try
  143. {
  144. #pragma warning disable 0612, 0618
  145. // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet! Don't remove this!
  146. ServicePointManager.CertificatePolicy = new MonoCert();
  147. #pragma warning restore 0612, 0618
  148. }
  149. catch (Exception)
  150. {
  151. m_log.Error("[OGP]: Certificate validation handler change not supported. You may get ssl certificate validation errors teleporting from your region to some SSL regions.");
  152. }
  153. }
  154. }
  155. // can't pick the region 'agent' because it would conflict with our agent domain handler
  156. // a zero length region name would conflict with are base region seed cap
  157. if (!SceneListDuplicateCheck(scene.RegionInfo.RegionName) && scene.RegionInfo.RegionName.ToLower() != "agent" && scene.RegionInfo.RegionName.Length > 0)
  158. {
  159. scene.AddLLSDHandler("/" + HttpUtility.UrlPathEncode(scene.RegionInfo.RegionName.ToLower()),ProcessRegionDomainSeed);
  160. }
  161. if (!m_scene.Contains(scene))
  162. m_scene.Add(scene);
  163. }
  164. }
  165. }
  166. lock (m_scene)
  167. {
  168. if (m_scene.Count == 1)
  169. {
  170. if (httpcfg != null)
  171. {
  172. httpSSL = httpcfg.GetBoolean("http_listener_ssl", false);
  173. httpsCN = httpcfg.GetString("http_listener_cn", scene.RegionInfo.ExternalHostName);
  174. if (httpsCN.Length == 0)
  175. httpsCN = scene.RegionInfo.ExternalHostName;
  176. httpsslport = (uint)httpcfg.GetInt("http_listener_sslport",((int)scene.RegionInfo.HttpPort + 1));
  177. }
  178. }
  179. }
  180. }
  181. public void PostInitialise()
  182. {
  183. }
  184. public void Close()
  185. {
  186. //scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel;
  187. }
  188. public string Name
  189. {
  190. get { return "OpenGridProtocolModule"; }
  191. }
  192. public bool IsSharedModule
  193. {
  194. get { return true; }
  195. }
  196. #endregion
  197. public OSD ProcessRegionDomainSeed(string path, OSD request, string endpoint)
  198. {
  199. string[] pathSegments = path.Split('/');
  200. if (pathSegments.Length <= 1)
  201. {
  202. return GenerateNoHandlerMessage();
  203. }
  204. return GenerateRezAvatarRequestMessage(pathSegments[1]);
  205. //m_log.InfoFormat("[OGP]: path {0}, segments {1} segment[1] {2} Last segment {3}",
  206. // path, pathSegments.Length, pathSegments[1], pathSegments[pathSegments.Length - 1]);
  207. //return new OSDMap();
  208. }
  209. public OSD ProcessAgentDomainMessage(string path, OSD request, string endpoint)
  210. {
  211. // /agent/*
  212. string[] pathSegments = path.Split('/');
  213. if (pathSegments.Length <= 1)
  214. {
  215. return GenerateNoHandlerMessage();
  216. }
  217. if (pathSegments[0].Length == 0 && pathSegments[1].Length == 0)
  218. {
  219. return GenerateRezAvatarRequestMessage("");
  220. }
  221. m_log.InfoFormat("[OGP]: path {0}, segments {1} segment[1] {2} Last segment {3}",
  222. path, pathSegments.Length, pathSegments[1], pathSegments[pathSegments.Length - 1]);
  223. switch (pathSegments[pathSegments.Length - 1])
  224. {
  225. case "rez_avatar":
  226. return RezAvatarMethod(path, request);
  227. //break;
  228. case "derez_avatar":
  229. return DerezAvatarMethod(path, request);
  230. //break;
  231. }
  232. if (path.Length < 2)
  233. {
  234. return GenerateNoHandlerMessage();
  235. }
  236. switch (pathSegments[pathSegments.Length - 2] + "/" + pathSegments[pathSegments.Length - 1])
  237. {
  238. case "rez_avatar/rez":
  239. return RezAvatarMethod(path, request);
  240. //break;
  241. case "rez_avatar/request":
  242. return RequestRezAvatarMethod(path, request);
  243. case "rez_avatar/place":
  244. return RequestRezAvatarMethod(path, request);
  245. case "rez_avatar/derez":
  246. return DerezAvatarMethod(path, request);
  247. //break;
  248. default:
  249. return GenerateNoHandlerMessage();
  250. }
  251. //return null;
  252. }
  253. private OSD GenerateRezAvatarRequestMessage(string regionname)
  254. {
  255. Scene region = null;
  256. bool usedroot = false;
  257. if (regionname.Length == 0)
  258. {
  259. region = GetRootScene();
  260. usedroot = true;
  261. }
  262. else
  263. {
  264. region = GetScene(HttpUtility.UrlDecode(regionname).ToLower());
  265. }
  266. // this shouldn't happen since we don't listen for a region that is down.. but
  267. // it might if the region was taken down or is in the middle of restarting
  268. if (region == null)
  269. {
  270. region = GetRootScene();
  271. usedroot = true;
  272. }
  273. UUID statekeeper = UUID.Random();
  274. RegionInfo reg = region.RegionInfo;
  275. OSDMap responseMap = new OSDMap();
  276. string rezHttpProtocol = "http://";
  277. //string regionCapsHttpProtocol = "http://";
  278. string httpaddr = reg.ExternalHostName;
  279. string urlport = reg.HttpPort.ToString();
  280. string requestpath = "/agent/" + statekeeper + "/rez_avatar/request";
  281. if (!usedroot)
  282. {
  283. lock (m_loginToRegionState)
  284. {
  285. if (!m_loginToRegionState.ContainsKey(requestpath))
  286. {
  287. m_loginToRegionState.Add(requestpath, region.RegionInfo.RegionName.ToLower());
  288. }
  289. }
  290. }
  291. if (httpSSL)
  292. {
  293. rezHttpProtocol = "https://";
  294. //regionCapsHttpProtocol = "https://";
  295. urlport = httpsslport.ToString();
  296. if (httpsCN.Length > 0)
  297. httpaddr = httpsCN;
  298. }
  299. responseMap["connect"] = OSD.FromBoolean(true);
  300. OSDMap capabilitiesMap = new OSDMap();
  301. capabilitiesMap["rez_avatar/request"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + requestpath);
  302. responseMap["capabilities"] = capabilitiesMap;
  303. return responseMap;
  304. }
  305. // Using OpenSim.Framework.Communications.Capabilities.Caps here one time..
  306. // so the long name is probably better then a using statement
  307. public void OnRegisterCaps(UUID agentID, OpenSim.Framework.Communications.Capabilities.Caps caps)
  308. {
  309. /* If we ever want to register our own caps here....
  310. *
  311. string capsBase = "/CAPS/" + caps.CapsObjectPath;
  312. caps.RegisterHandler("CAPNAME",
  313. new RestStreamHandler("POST", capsBase + CAPSPOSTFIX!,
  314. delegate(string request, string path, string param,
  315. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  316. {
  317. return METHODHANDLER(request, path, param,
  318. agentID, caps);
  319. }));
  320. *
  321. */
  322. }
  323. public OSD RequestRezAvatarMethod(string path, OSD request)
  324. {
  325. //System.Console.WriteLine("[REQUESTREZAVATAR]: " + request.ToString());
  326. OSDMap requestMap = (OSDMap)request;
  327. Scene homeScene = null;
  328. lock (m_loginToRegionState)
  329. {
  330. if (m_loginToRegionState.ContainsKey(path))
  331. {
  332. homeScene = GetScene(m_loginToRegionState[path]);
  333. m_loginToRegionState.Remove(path);
  334. if (homeScene == null)
  335. homeScene = GetRootScene();
  336. }
  337. else
  338. {
  339. homeScene = GetRootScene();
  340. }
  341. }
  342. // Homescene is still null, we must have no regions that are up
  343. if (homeScene == null)
  344. return GenerateNoHandlerMessage();
  345. RegionInfo reg = homeScene.RegionInfo;
  346. ulong regionhandle = GetOSCompatibleRegionHandle(reg);
  347. //string RegionURI = reg.ServerURI;
  348. //int RegionPort = (int)reg.HttpPort;
  349. UUID RemoteAgentID = requestMap["agent_id"].AsUUID();
  350. // will be used in the future. The client always connects with the aditi agentid currently
  351. UUID LocalAgentID = RemoteAgentID;
  352. string FirstName = requestMap["first_name"].AsString();
  353. string LastName = requestMap["last_name"].AsString();
  354. FirstName = FirstNamePrefix + FirstName;
  355. LastName = LastName + LastNameSuffix;
  356. OGPState userState = GetOGPState(LocalAgentID);
  357. userState.first_name = requestMap["first_name"].AsString();
  358. userState.last_name = requestMap["last_name"].AsString();
  359. userState.age_verified = requestMap["age_verified"].AsBoolean();
  360. userState.transacted = requestMap["transacted"].AsBoolean();
  361. userState.agent_access = requestMap["agent_access"].AsBoolean();
  362. userState.allow_redirect = requestMap["allow_redirect"].AsBoolean();
  363. userState.identified = requestMap["identified"].AsBoolean();
  364. userState.god_level = (uint)requestMap["god_level"].AsInteger();
  365. userState.sim_access = requestMap["sim_access"].AsString();
  366. userState.agent_id = RemoteAgentID;
  367. userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
  368. userState.src_can_see_mainland = requestMap["src_can_see_mainland"].AsBoolean();
  369. userState.src_estate_id = requestMap["src_estate_id"].AsInteger();
  370. userState.local_agent_id = LocalAgentID;
  371. userState.teleported_into_region = reg.RegionName.ToLower();
  372. UpdateOGPState(LocalAgentID, userState);
  373. OSDMap responseMap = new OSDMap();
  374. if (RemoteAgentID == UUID.Zero)
  375. {
  376. responseMap["connect"] = OSD.FromBoolean(false);
  377. responseMap["message"] = OSD.FromString("No agent ID was specified in rez_avatar/request");
  378. m_log.Error("[OGP]: rez_avatar/request failed because no avatar UUID was provided in the request body");
  379. return responseMap;
  380. }
  381. responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);
  382. // DEPRECIATED
  383. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
  384. responseMap["connect"] = OSD.FromBoolean(true);
  385. responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
  386. responseMap["region_x"] = OSD.FromInteger(reg.RegionLocX * (uint)Constants.RegionSize); // LLX
  387. responseMap["region_y"] = OSD.FromInteger(reg.RegionLocY * (uint)Constants.RegionSize); // LLY
  388. responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);
  389. responseMap["sim_access"] = OSD.FromString((reg.RegionSettings.Maturity == 1) ? "Mature" : "PG");
  390. // Generate a dummy agent for the user so we can get back a CAPS path
  391. AgentCircuitData agentData = new AgentCircuitData();
  392. agentData.AgentID = LocalAgentID;
  393. agentData.BaseFolder=UUID.Zero;
  394. agentData.CapsPath=Util.GetRandomCapsPath();
  395. agentData.child = false;
  396. agentData.circuitcode = (uint)(Util.RandomClass.Next());
  397. agentData.firstname = FirstName;
  398. agentData.lastname = LastName;
  399. agentData.SecureSessionID=UUID.Random();
  400. agentData.SessionID=UUID.Random();
  401. agentData.startpos = new Vector3(128f, 128f, 100f);
  402. // Pre-Fill our region cache with information on the agent.
  403. UserAgentData useragent = new UserAgentData();
  404. useragent.AgentIP="unknown";
  405. useragent.AgentOnline=true;
  406. useragent.AgentPort = (uint)0;
  407. useragent.Handle = regionhandle;
  408. useragent.InitialRegion = reg.originRegionID;
  409. useragent.LoginTime=Util.UnixTimeSinceEpoch();
  410. useragent.LogoutTime = 0;
  411. useragent.Position=agentData.startpos;
  412. useragent.Region=reg.originRegionID;
  413. useragent.SecureSessionID=agentData.SecureSessionID;
  414. useragent.SessionID = agentData.SessionID;
  415. UserProfileData userProfile = new UserProfileData();
  416. userProfile.AboutText = "OGP User";
  417. userProfile.CanDoMask = (uint)0;
  418. userProfile.Created = Util.UnixTimeSinceEpoch();
  419. userProfile.CurrentAgent = useragent;
  420. userProfile.CustomType = "OGP";
  421. userProfile.FirstLifeAboutText = "I'm testing OpenGrid Protocol";
  422. userProfile.FirstLifeImage = UUID.Zero;
  423. userProfile.FirstName = agentData.firstname;
  424. userProfile.GodLevel = 0;
  425. userProfile.HomeLocation = agentData.startpos;
  426. userProfile.HomeLocationX = agentData.startpos.X;
  427. userProfile.HomeLocationY = agentData.startpos.Y;
  428. userProfile.HomeLocationZ = agentData.startpos.Z;
  429. userProfile.HomeLookAt = Vector3.Zero;
  430. userProfile.HomeLookAtX = userProfile.HomeLookAt.X;
  431. userProfile.HomeLookAtY = userProfile.HomeLookAt.Y;
  432. userProfile.HomeLookAtZ = userProfile.HomeLookAt.Z;
  433. userProfile.HomeRegion = reg.RegionHandle;
  434. userProfile.HomeRegionID = reg.originRegionID;
  435. userProfile.HomeRegionX = reg.RegionLocX;
  436. userProfile.HomeRegionY = reg.RegionLocY;
  437. userProfile.ID = agentData.AgentID;
  438. userProfile.Image = UUID.Zero;
  439. userProfile.LastLogin = Util.UnixTimeSinceEpoch();
  440. userProfile.Partner = UUID.Zero;
  441. userProfile.PasswordHash = "$1$";
  442. userProfile.PasswordSalt = "";
  443. userProfile.RootInventoryFolderID = UUID.Zero;
  444. userProfile.SurName = agentData.lastname;
  445. userProfile.UserAssetURI = homeScene.CommsManager.NetworkServersInfo.AssetURL;
  446. userProfile.UserFlags = 0;
  447. userProfile.UserInventoryURI = homeScene.CommsManager.NetworkServersInfo.InventoryURL;
  448. userProfile.WantDoMask = 0;
  449. userProfile.WebLoginKey = UUID.Random();
  450. // Do caps registration
  451. // get seed capagentData.firstname = FirstName;agentData.lastname = LastName;
  452. if (homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID) == null && !GridMode)
  453. {
  454. homeScene.CommsManager.UserAdminService.AddUser(
  455. agentData.firstname, agentData.lastname, CreateRandomStr(7), "",
  456. homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
  457. UserProfileData userProfile2 = homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID);
  458. if (userProfile2 != null)
  459. {
  460. userProfile = userProfile2;
  461. userProfile.AboutText = "OGP USER";
  462. userProfile.FirstLifeAboutText = "OGP USER";
  463. homeScene.CommsManager.UserService.UpdateUserProfile(userProfile);
  464. }
  465. }
  466. // Stick our data in the cache so the region will know something about us
  467. homeScene.CommsManager.UserProfileCacheService.PreloadUserCache(agentData.AgentID, userProfile);
  468. // Call 'new user' event handler
  469. homeScene.NewUserConnection(agentData);
  470. //string raCap = string.Empty;
  471. UUID AvatarRezCapUUID = LocalAgentID;
  472. string rezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/rez";
  473. string derezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/derez";
  474. // Get a reference to the user's cap so we can pull out the Caps Object Path
  475. OpenSim.Framework.Communications.Capabilities.Caps userCap = homeScene.GetCapsHandlerForUser(agentData.AgentID);
  476. string rezHttpProtocol = "http://";
  477. string regionCapsHttpProtocol = "http://";
  478. string httpaddr = reg.ExternalHostName;
  479. string urlport = reg.HttpPort.ToString();
  480. if (httpSSL)
  481. {
  482. rezHttpProtocol = "https://";
  483. regionCapsHttpProtocol = "https://";
  484. urlport = httpsslport.ToString();
  485. if (httpsCN.Length > 0)
  486. httpaddr = httpsCN;
  487. }
  488. // DEPRECIATED
  489. responseMap["seed_capability"] = OSD.FromString(regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + "/CAPS/" + userCap.CapsObjectPath + "0000/");
  490. // REPLACEMENT
  491. responseMap["region_seed_capability"] = OSD.FromString(regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + "/CAPS/" + userCap.CapsObjectPath + "0000/");
  492. responseMap["rez_avatar"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
  493. responseMap["rez_avatar/rez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
  494. responseMap["rez_avatar/derez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + derezAvatarPath);
  495. // Add the user to the list of CAPS that are outstanding.
  496. // well allow the caps hosts in this dictionary
  497. lock (CapsLoginID)
  498. {
  499. if (CapsLoginID.ContainsKey(rezAvatarPath))
  500. {
  501. CapsLoginID[rezAvatarPath] = agentData;
  502. // This is a joke, if you didn't notice... It's so unlikely to happen, that I'll print this message if it does occur!
  503. m_log.Error("[OGP]: Holy anomoly batman! Caps path already existed! All the UUID Duplication worries were founded!");
  504. }
  505. else
  506. {
  507. CapsLoginID.Add(rezAvatarPath, agentData);
  508. }
  509. }
  510. //System.Console.WriteLine("Response:" + responseMap.ToString());
  511. return responseMap;
  512. }
  513. public OSD RezAvatarMethod(string path, OSD request)
  514. {
  515. m_log.WarnFormat("[REZAVATAR]: {0}", request.ToString());
  516. OSDMap responseMap = new OSDMap();
  517. AgentCircuitData userData = null;
  518. // Only people we've issued a cap can go further
  519. if (TryGetAgentCircuitData(path,out userData))
  520. {
  521. OSDMap requestMap = (OSDMap)request;
  522. // take these values to start. There's a few more
  523. UUID SecureSessionID=requestMap["secure_session_id"].AsUUID();
  524. UUID SessionID = requestMap["session_id"].AsUUID();
  525. int circuitcode = requestMap["circuit_code"].AsInteger();
  526. OSDArray Parameter = new OSDArray();
  527. if (requestMap.ContainsKey("parameter"))
  528. {
  529. Parameter = (OSDArray)requestMap["parameter"];
  530. }
  531. //int version = 1;
  532. int estateID = 1;
  533. int parentEstateID = 1;
  534. UUID regionID = UUID.Zero;
  535. bool visibleToParent = true;
  536. for (int i = 0; i < Parameter.Count; i++)
  537. {
  538. OSDMap item = (OSDMap)Parameter[i];
  539. // if (item.ContainsKey("version"))
  540. // {
  541. // version = item["version"].AsInteger();
  542. // }
  543. if (item.ContainsKey("estate_id"))
  544. {
  545. estateID = item["estate_id"].AsInteger();
  546. }
  547. if (item.ContainsKey("parent_estate_id"))
  548. {
  549. parentEstateID = item["parent_estate_id"].AsInteger();
  550. }
  551. if (item.ContainsKey("region_id"))
  552. {
  553. regionID = item["region_id"].AsUUID();
  554. }
  555. if (item.ContainsKey("visible_to_parent"))
  556. {
  557. visibleToParent = item["visible_to_parent"].AsBoolean();
  558. }
  559. }
  560. //Update our Circuit data with the real values
  561. userData.SecureSessionID = SecureSessionID;
  562. userData.SessionID = SessionID;
  563. OGPState userState = GetOGPState(userData.AgentID);
  564. // Locate a home scene suitable for the user.
  565. Scene homeScene = null;
  566. homeScene = GetScene(userState.teleported_into_region);
  567. if (homeScene == null)
  568. homeScene = GetRootScene();
  569. if (homeScene != null)
  570. {
  571. // Get a reference to their Cap object so we can pull out the capobjectroot
  572. OpenSim.Framework.Communications.Capabilities.Caps userCap =
  573. homeScene.GetCapsHandlerForUser(userData.AgentID);
  574. //Update the circuit data in the region so this user is authorized
  575. homeScene.UpdateCircuitData(userData);
  576. homeScene.ChangeCircuitCode(userData.circuitcode,(uint)circuitcode);
  577. // Load state
  578. // Keep state changes
  579. userState.first_name = requestMap["first_name"].AsString();
  580. userState.secure_session_id = requestMap["secure_session_id"].AsUUID();
  581. userState.age_verified = requestMap["age_verified"].AsBoolean();
  582. userState.region_id = homeScene.RegionInfo.originRegionID; // replace 0000000 with our regionid
  583. userState.transacted = requestMap["transacted"].AsBoolean();
  584. userState.agent_access = requestMap["agent_access"].AsBoolean();
  585. userState.inventory_host = requestMap["inventory_host"].AsString();
  586. userState.identified = requestMap["identified"].AsBoolean();
  587. userState.session_id = requestMap["session_id"].AsUUID();
  588. userState.god_level = (uint)requestMap["god_level"].AsInteger();
  589. userState.last_name = requestMap["last_name"].AsString();
  590. userState.god_overide = requestMap["god_override"].AsBoolean();
  591. userState.circuit_code = (uint)requestMap["circuit_code"].AsInteger();
  592. userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
  593. userState.src_estate_id = estateID;
  594. userState.region_id = regionID;
  595. userState.src_parent_estate_id = parentEstateID;
  596. userState.visible_to_parent = visibleToParent;
  597. // Save state changes
  598. UpdateOGPState(userData.AgentID, userState);
  599. // Get the region information for the home region.
  600. RegionInfo reg = homeScene.RegionInfo;
  601. // Dummy positional and look at info.. we don't have it.
  602. OSDArray PositionArray = new OSDArray();
  603. PositionArray.Add(OSD.FromInteger(128));
  604. PositionArray.Add(OSD.FromInteger(128));
  605. PositionArray.Add(OSD.FromInteger(40));
  606. OSDArray LookAtArray = new OSDArray();
  607. LookAtArray.Add(OSD.FromInteger(1));
  608. LookAtArray.Add(OSD.FromInteger(1));
  609. LookAtArray.Add(OSD.FromInteger(1));
  610. // Our region's X and Y position in OpenSimulator space.
  611. uint fooX = reg.RegionLocX;
  612. uint fooY = reg.RegionLocY;
  613. m_log.InfoFormat("[OGP]: region x({0}) region y({1})", fooX, fooY);
  614. m_log.InfoFormat("[OGP]: region http {0} {1}", reg.ServerURI, reg.HttpPort);
  615. m_log.InfoFormat("[OGO]: region UUID {0} ", reg.RegionID);
  616. // Convert the X and Y position to LL space
  617. responseMap["region_x"] = OSD.FromInteger(fooX * (uint)Constants.RegionSize); // convert it to LL X
  618. responseMap["region_y"] = OSD.FromInteger(fooY * (uint)Constants.RegionSize); // convert it to LL Y
  619. // Give em a new seed capability
  620. responseMap["seed_capability"] = OSD.FromString("http://" + reg.ExternalHostName + ":" + reg.HttpPort + "/CAPS/" + userCap.CapsObjectPath + "0000/");
  621. responseMap["region"] = OSD.FromUUID(reg.originRegionID);
  622. responseMap["look_at"] = LookAtArray;
  623. responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
  624. responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);// + ":" + reg.InternalEndPoint.Port.ToString());
  625. // DEPRECIATED
  626. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
  627. responseMap["session_id"] = OSD.FromUUID(SessionID);
  628. responseMap["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  629. responseMap["circuit_code"] = OSD.FromInteger(circuitcode);
  630. responseMap["position"] = PositionArray;
  631. responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);
  632. responseMap["sim_access"] = OSD.FromString("Mature");
  633. responseMap["connect"] = OSD.FromBoolean(true);
  634. m_log.InfoFormat("[OGP]: host: {0}, IP {1}", responseMap["sim_host"].ToString(), responseMap["sim_ip"].ToString());
  635. }
  636. }
  637. return responseMap;
  638. }
  639. public OSD DerezAvatarMethod(string path, OSD request)
  640. {
  641. m_log.ErrorFormat("DerezPath: {0}, Request: {1}", path, request.ToString());
  642. //LLSD llsdResponse = null;
  643. OSDMap responseMap = new OSDMap();
  644. string[] PathArray = path.Split('/');
  645. m_log.InfoFormat("[OGP]: prefix {0}, uuid {1}, suffix {2}", PathArray[1], PathArray[2], PathArray[3]);
  646. string uuidString = PathArray[2];
  647. m_log.InfoFormat("[OGP]: Request to Derez avatar with UUID {0}", uuidString);
  648. UUID userUUID = UUID.Zero;
  649. if (UUID.TryParse(uuidString, out userUUID))
  650. {
  651. UUID RemoteID = (UUID)uuidString;
  652. UUID LocalID = RemoteID;
  653. // FIXME: TODO: Routine to map RemoteUUIDs to LocalUUIds
  654. // would be done already.. but the client connects with the Aditi UUID
  655. // regardless over the UDP stack
  656. OGPState userState = GetOGPState(LocalID);
  657. if (userState.agent_id != UUID.Zero)
  658. {
  659. //OSDMap outboundRequestMap = new OSDMap();
  660. OSDMap inboundRequestMap = (OSDMap)request;
  661. string rezAvatarString = inboundRequestMap["rez_avatar"].AsString();
  662. if (rezAvatarString.Length == 0)
  663. {
  664. rezAvatarString = inboundRequestMap["rez_avatar/rez"].AsString();
  665. }
  666. OSDArray LookAtArray = new OSDArray();
  667. LookAtArray.Add(OSD.FromInteger(1));
  668. LookAtArray.Add(OSD.FromInteger(1));
  669. LookAtArray.Add(OSD.FromInteger(1));
  670. OSDArray PositionArray = new OSDArray();
  671. PositionArray.Add(OSD.FromInteger(128));
  672. PositionArray.Add(OSD.FromInteger(128));
  673. PositionArray.Add(OSD.FromInteger(40));
  674. OSDArray lookArray = new OSDArray();
  675. lookArray.Add(OSD.FromInteger(128));
  676. lookArray.Add(OSD.FromInteger(128));
  677. lookArray.Add(OSD.FromInteger(40));
  678. responseMap["connect"] = OSD.FromBoolean(true);// it's okay to give this user up
  679. responseMap["look_at"] = LookAtArray;
  680. m_log.WarnFormat("[OGP]: Invoking rez_avatar on host:{0} for avatar: {1} {2}", rezAvatarString, userState.first_name, userState.last_name);
  681. OSDMap rezResponseMap = invokeRezAvatarCap(responseMap, rezAvatarString,userState);
  682. // If invoking it returned an error, parse and end
  683. if (rezResponseMap.ContainsKey("connect"))
  684. {
  685. if (rezResponseMap["connect"].AsBoolean() == false)
  686. {
  687. return responseMap;
  688. }
  689. }
  690. string rezRespSeedCap = "";
  691. // DEPRECIATED
  692. if (rezResponseMap.ContainsKey("seed_capability"))
  693. rezRespSeedCap = rezResponseMap["seed_capability"].AsString();
  694. // REPLACEMENT
  695. if (rezResponseMap.ContainsKey("region_seed_capability"))
  696. rezRespSeedCap = rezResponseMap["region_seed_capability"].AsString();
  697. // REPLACEMENT
  698. if (rezResponseMap.ContainsKey("rez_avatar/rez"))
  699. rezRespSeedCap = rezResponseMap["rez_avatar/rez"].AsString();
  700. // DEPRECIATED
  701. string rezRespSim_ip = rezResponseMap["sim_ip"].AsString();
  702. string rezRespSim_host = rezResponseMap["sim_host"].AsString();
  703. int rrPort = rezResponseMap["sim_port"].AsInteger();
  704. int rrX = rezResponseMap["region_x"].AsInteger();
  705. int rrY = rezResponseMap["region_y"].AsInteger();
  706. m_log.ErrorFormat("X:{0}, Y:{1}", rrX, rrY);
  707. UUID rrRID = rezResponseMap["region_id"].AsUUID();
  708. OSDArray RezResponsePositionArray = null;
  709. string rrAccess = rezResponseMap["sim_access"].AsString();
  710. if (rezResponseMap.ContainsKey("position"))
  711. {
  712. RezResponsePositionArray = (OSDArray)rezResponseMap["position"];
  713. }
  714. // DEPRECIATED
  715. responseMap["seed_capability"] = OSD.FromString(rezRespSeedCap);
  716. // REPLACEMENT r3
  717. responseMap["region_seed_capability"] = OSD.FromString(rezRespSeedCap);
  718. // DEPRECIATED
  719. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(rezRespSim_ip).ToString());
  720. responseMap["sim_host"] = OSD.FromString(rezRespSim_host);
  721. responseMap["sim_port"] = OSD.FromInteger(rrPort);
  722. responseMap["region_x"] = OSD.FromInteger(rrX );
  723. responseMap["region_y"] = OSD.FromInteger(rrY );
  724. responseMap["region_id"] = OSD.FromUUID(rrRID);
  725. responseMap["sim_access"] = OSD.FromString(rrAccess);
  726. if (RezResponsePositionArray != null)
  727. {
  728. responseMap["position"] = RezResponsePositionArray;
  729. }
  730. responseMap["look_at"] = lookArray;
  731. responseMap["connect"] = OSD.FromBoolean(true);
  732. ShutdownConnection(LocalID,this);
  733. // PLEASE STOP CHANGING THIS TO an M_LOG, M_LOG DOESN'T WORK ON MULTILINE .TOSTRINGS
  734. System.Console.WriteLine("RESPONSEDEREZ: " + responseMap.ToString());
  735. return responseMap;
  736. }
  737. else
  738. {
  739. return GenerateNoStateMessage(LocalID);
  740. }
  741. }
  742. else
  743. {
  744. return GenerateNoHandlerMessage();
  745. }
  746. //return responseMap;
  747. }
  748. private OSDMap invokeRezAvatarCap(OSDMap responseMap, string CapAddress, OGPState userState)
  749. {
  750. Scene reg = GetRootScene();
  751. WebRequest DeRezRequest = WebRequest.Create(CapAddress);
  752. DeRezRequest.Method = "POST";
  753. DeRezRequest.ContentType = "application/xml+llsd";
  754. OSDMap RAMap = new OSDMap();
  755. OSDMap AgentParms = new OSDMap();
  756. OSDMap RegionParms = new OSDMap();
  757. OSDArray Parameter = new OSDArray(2);
  758. OSDMap version = new OSDMap();
  759. version["version"] = OSD.FromInteger(userState.src_version);
  760. Parameter.Add(version);
  761. OSDMap SrcData = new OSDMap();
  762. SrcData["estate_id"] = OSD.FromInteger(reg.RegionInfo.EstateSettings.EstateID);
  763. SrcData["parent_estate_id"] = OSD.FromInteger((reg.RegionInfo.EstateSettings.ParentEstateID == 100 ? 1 : reg.RegionInfo.EstateSettings.ParentEstateID));
  764. SrcData["region_id"] = OSD.FromUUID(reg.RegionInfo.originRegionID);
  765. SrcData["visible_to_parent"] = OSD.FromBoolean(userState.visible_to_parent);
  766. Parameter.Add(SrcData);
  767. AgentParms["first_name"] = OSD.FromString(userState.first_name);
  768. AgentParms["last_name"] = OSD.FromString(userState.last_name);
  769. AgentParms["agent_id"] = OSD.FromUUID(userState.agent_id);
  770. RegionParms["region_id"] = OSD.FromUUID(userState.region_id);
  771. AgentParms["circuit_code"] = OSD.FromInteger(userState.circuit_code);
  772. AgentParms["secure_session_id"] = OSD.FromUUID(userState.secure_session_id);
  773. AgentParms["session_id"] = OSD.FromUUID(userState.session_id);
  774. AgentParms["agent_access"] = OSD.FromBoolean(userState.agent_access);
  775. AgentParms["god_level"] = OSD.FromInteger(userState.god_level);
  776. AgentParms["god_overide"] = OSD.FromBoolean(userState.god_overide);
  777. AgentParms["identified"] = OSD.FromBoolean(userState.identified);
  778. AgentParms["transacted"] = OSD.FromBoolean(userState.transacted);
  779. AgentParms["age_verified"] = OSD.FromBoolean(userState.age_verified);
  780. AgentParms["limited_to_estate"] = OSD.FromInteger(userState.limited_to_estate);
  781. AgentParms["inventory_host"] = OSD.FromString(userState.inventory_host);
  782. // version 1
  783. RAMap = AgentParms;
  784. // Planned for version 2
  785. // RAMap["agent_params"] = AgentParms;
  786. RAMap["region_params"] = RegionParms;
  787. RAMap["parameter"] = Parameter;
  788. string RAMapString = RAMap.ToString();
  789. m_log.InfoFormat("[OGP] RAMap string {0}", RAMapString);
  790. OSD LLSDofRAMap = RAMap; // RENAME if this works
  791. m_log.InfoFormat("[OGP]: LLSD of map as string was {0}", LLSDofRAMap.ToString());
  792. //m_log.InfoFormat("[OGP]: LLSD+XML: {0}", LLSDParser.SerializeXmlString(LLSDofRAMap));
  793. byte[] buffer = OSDParser.SerializeLLSDXmlBytes(LLSDofRAMap);
  794. //string bufferDump = System.Text.Encoding.ASCII.GetString(buffer);
  795. //m_log.InfoFormat("[OGP]: buffer form is {0}",bufferDump);
  796. //m_log.InfoFormat("[OGP]: LLSD of map was {0}",buffer.Length);
  797. Stream os = null;
  798. try
  799. { // send the Post
  800. DeRezRequest.ContentLength = buffer.Length; //Count bytes to send
  801. os = DeRezRequest.GetRequestStream();
  802. os.Write(buffer, 0, buffer.Length); //Send it
  803. os.Close();
  804. m_log.InfoFormat("[OGP]: Derez Avatar Posted Rez Avatar request to remote sim {0}", CapAddress);
  805. }
  806. catch (WebException ex)
  807. {
  808. m_log.InfoFormat("[OGP] Bad send on de_rez_avatar {0}", ex.Message);
  809. responseMap["connect"] = OSD.FromBoolean(false);
  810. return responseMap;
  811. }
  812. m_log.Info("[OGP] waiting for a reply after rez avatar send");
  813. string rez_avatar_reply = null;
  814. { // get the response
  815. try
  816. {
  817. WebResponse webResponse = DeRezRequest.GetResponse();
  818. if (webResponse == null)
  819. {
  820. m_log.Info("[OGP:] Null reply on rez_avatar post");
  821. }
  822. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  823. rez_avatar_reply = sr.ReadToEnd().Trim();
  824. m_log.InfoFormat("[OGP]: rez_avatar reply was {0} ", rez_avatar_reply);
  825. }
  826. catch (WebException ex)
  827. {
  828. m_log.InfoFormat("[OGP]: exception on read after send of rez avatar {0}", ex.Message);
  829. responseMap["connect"] = OSD.FromBoolean(false);
  830. return responseMap;
  831. }
  832. OSD rezResponse = null;
  833. try
  834. {
  835. rezResponse = OSDParser.DeserializeLLSDXml(rez_avatar_reply);
  836. responseMap = (OSDMap)rezResponse;
  837. }
  838. catch (Exception ex)
  839. {
  840. m_log.InfoFormat("[OGP]: exception on parse of rez reply {0}", ex.Message);
  841. responseMap["connect"] = OSD.FromBoolean(false);
  842. return responseMap;
  843. }
  844. }
  845. return responseMap;
  846. }
  847. public OSD GenerateNoHandlerMessage()
  848. {
  849. OSDMap map = new OSDMap();
  850. map["reason"] = OSD.FromString("LLSDRequest");
  851. map["message"] = OSD.FromString("No handler registered for LLSD Requests");
  852. map["login"] = OSD.FromString("false");
  853. map["connect"] = OSD.FromString("false");
  854. return map;
  855. }
  856. public OSD GenerateNoStateMessage(UUID passedAvatar)
  857. {
  858. OSDMap map = new OSDMap();
  859. map["reason"] = OSD.FromString("derez failed");
  860. map["message"] = OSD.FromString("Unable to locate OGP state for avatar " + passedAvatar.ToString());
  861. map["login"] = OSD.FromString("false");
  862. map["connect"] = OSD.FromString("false");
  863. return map;
  864. }
  865. private bool TryGetAgentCircuitData(string path, out AgentCircuitData userdata)
  866. {
  867. userdata = null;
  868. lock (CapsLoginID)
  869. {
  870. if (CapsLoginID.ContainsKey(path))
  871. {
  872. userdata = CapsLoginID[path];
  873. DiscardUsedCap(path);
  874. return true;
  875. }
  876. }
  877. return false;
  878. }
  879. private void DiscardUsedCap(string path)
  880. {
  881. CapsLoginID.Remove(path);
  882. }
  883. private Scene GetRootScene()
  884. {
  885. Scene ReturnScene = null;
  886. lock (m_scene)
  887. {
  888. if (m_scene.Count > 0)
  889. {
  890. ReturnScene = m_scene[0];
  891. }
  892. }
  893. return ReturnScene;
  894. }
  895. private Scene GetScene(string scenename)
  896. {
  897. Scene ReturnScene = null;
  898. lock (m_scene)
  899. {
  900. foreach (Scene s in m_scene)
  901. {
  902. if (s.RegionInfo.RegionName.ToLower() == scenename)
  903. {
  904. ReturnScene = s;
  905. break;
  906. }
  907. }
  908. }
  909. return ReturnScene;
  910. }
  911. private ulong GetOSCompatibleRegionHandle(RegionInfo reg)
  912. {
  913. return Util.UIntsToLong(reg.RegionLocX, reg.RegionLocY);
  914. }
  915. private OGPState InitializeNewState()
  916. {
  917. OGPState returnState = new OGPState();
  918. returnState.first_name = "";
  919. returnState.last_name = "";
  920. returnState.agent_id = UUID.Zero;
  921. returnState.local_agent_id = UUID.Zero;
  922. returnState.region_id = UUID.Zero;
  923. returnState.circuit_code = 0;
  924. returnState.secure_session_id = UUID.Zero;
  925. returnState.session_id = UUID.Zero;
  926. returnState.agent_access = true;
  927. returnState.god_level = 0;
  928. returnState.god_overide = false;
  929. returnState.identified = false;
  930. returnState.transacted = false;
  931. returnState.age_verified = false;
  932. returnState.limited_to_estate = 1;
  933. returnState.inventory_host = "http://inv4.mysql.aditi.lindenlab.com";
  934. returnState.allow_redirect = true;
  935. returnState.sim_access = "";
  936. returnState.src_can_see_mainland = true;
  937. returnState.src_estate_id = 1;
  938. returnState.src_version = 1;
  939. returnState.src_parent_estate_id = 1;
  940. returnState.visible_to_parent = true;
  941. returnState.teleported_into_region = "";
  942. return returnState;
  943. }
  944. private OGPState GetOGPState(UUID agentId)
  945. {
  946. lock (m_OGPState)
  947. {
  948. if (m_OGPState.ContainsKey(agentId))
  949. {
  950. return m_OGPState[agentId];
  951. }
  952. else
  953. {
  954. return InitializeNewState();
  955. }
  956. }
  957. }
  958. public void DeleteOGPState(UUID agentId)
  959. {
  960. lock (m_OGPState)
  961. {
  962. if (m_OGPState.ContainsKey(agentId))
  963. m_OGPState.Remove(agentId);
  964. }
  965. }
  966. private void UpdateOGPState(UUID agentId, OGPState state)
  967. {
  968. lock (m_OGPState)
  969. {
  970. if (m_OGPState.ContainsKey(agentId))
  971. {
  972. m_OGPState[agentId] = state;
  973. }
  974. else
  975. {
  976. m_OGPState.Add(agentId,state);
  977. }
  978. }
  979. }
  980. private bool SceneListDuplicateCheck(string str)
  981. {
  982. // no lock, called from locked space!
  983. bool found = false;
  984. foreach (Scene s in m_scene)
  985. {
  986. if (s.RegionInfo.RegionName == str)
  987. {
  988. found = true;
  989. break;
  990. }
  991. }
  992. return found;
  993. }
  994. public void ShutdownConnection(UUID avatarId, OpenGridProtocolModule mod)
  995. {
  996. Scene homeScene = GetRootScene();
  997. ScenePresence avatar = null;
  998. if (homeScene.TryGetAvatar(avatarId,out avatar))
  999. {
  1000. KillAUser ku = new KillAUser(avatar,mod);
  1001. Thread ta = new Thread(ku.ShutdownNoLogout);
  1002. ta.IsBackground = true;
  1003. ta.Name = "ShutdownThread";
  1004. ta.Start();
  1005. }
  1006. }
  1007. private string CreateRandomStr(int len)
  1008. {
  1009. Random rnd = new Random(System.Environment.TickCount);
  1010. string returnstring = "";
  1011. string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  1012. for (int i = 0; i < len; i++)
  1013. {
  1014. returnstring += chars.Substring(rnd.Next(chars.Length), 1);
  1015. }
  1016. return returnstring;
  1017. }
  1018. // Temporary hack to allow teleporting to and from Vaak
  1019. private static bool customXertificateValidation(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
  1020. {
  1021. //if (cert.Subject == "[email protected], CN=*.vaak.lindenlab.com, O=\"Linden Lab, Inc.\", L=San Francisco, S=California, C=US")
  1022. //{
  1023. return true;
  1024. //}
  1025. //return false;
  1026. }
  1027. }
  1028. public class KillAUser
  1029. {
  1030. private ScenePresence avToBeKilled = null;
  1031. private OpenGridProtocolModule m_mod = null;
  1032. public KillAUser(ScenePresence avatar, OpenGridProtocolModule mod)
  1033. {
  1034. avToBeKilled = avatar;
  1035. m_mod = mod;
  1036. }
  1037. public void ShutdownNoLogout()
  1038. {
  1039. UUID avUUID = UUID.Zero;
  1040. if (avToBeKilled != null)
  1041. {
  1042. avUUID = avToBeKilled.UUID;
  1043. avToBeKilled.MakeChildAgent();
  1044. avToBeKilled.ControllingClient.SendLogoutPacketWhenClosing = false;
  1045. Thread.Sleep(30000);
  1046. // test for child agent because they might have come back
  1047. if (avToBeKilled.IsChildAgent)
  1048. {
  1049. m_mod.DeleteOGPState(avUUID);
  1050. avToBeKilled.ControllingClient.Close(true);
  1051. }
  1052. }
  1053. }
  1054. }
  1055. public class MonoCert : ICertificatePolicy
  1056. {
  1057. #region ICertificatePolicy Members
  1058. public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
  1059. {
  1060. return true;
  1061. }
  1062. #endregion
  1063. }
  1064. }