OpenGridProtocolModule.cs 53 KB

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