OpenGridProtocolModule.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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. scene.CommsManager.HttpServer.AddLLSDHandler("/agent/", ProcessAgentDomainMessage);
  134. scene.CommsManager.HttpServer.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. scene.CommsManager.HttpServer.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. // DEPRECIATED
  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.RootInventoryFolderID = UUID.Zero;
  456. userProfile.SurName = agentData.lastname;
  457. userProfile.UserAssetURI = homeScene.CommsManager.NetworkServersInfo.AssetURL;
  458. userProfile.UserFlags = 0;
  459. userProfile.UserInventoryURI = homeScene.CommsManager.NetworkServersInfo.InventoryURL;
  460. userProfile.WantDoMask = 0;
  461. userProfile.WebLoginKey = UUID.Random();
  462. // Do caps registration
  463. // get seed capagentData.firstname = FirstName;agentData.lastname = LastName;
  464. if (homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID) == null && !GridMode)
  465. {
  466. homeScene.CommsManager.UserAdminService.AddUser(
  467. agentData.firstname, agentData.lastname, CreateRandomStr(7), "",
  468. homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
  469. UserProfileData userProfile2 = homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID);
  470. if (userProfile2 != null)
  471. {
  472. userProfile = userProfile2;
  473. userProfile.AboutText = "OGP USER";
  474. userProfile.FirstLifeAboutText = "OGP USER";
  475. homeScene.CommsManager.UserService.UpdateUserProfile(userProfile);
  476. }
  477. }
  478. // Stick our data in the cache so the region will know something about us
  479. homeScene.CommsManager.UserProfileCacheService.PreloadUserCache(userProfile);
  480. // Call 'new user' event handler
  481. string reason;
  482. if (!homeScene.NewUserConnection(agentData, out reason))
  483. {
  484. responseMap["connect"] = OSD.FromBoolean(false);
  485. responseMap["message"] = OSD.FromString(String.Format("Connection refused: {0}", reason));
  486. m_log.ErrorFormat("[OGP]: rez_avatar/request failed: {0}", reason);
  487. return responseMap;
  488. }
  489. //string raCap = string.Empty;
  490. UUID AvatarRezCapUUID = LocalAgentID;
  491. string rezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/rez";
  492. string derezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/derez";
  493. // Get a reference to the user's cap so we can pull out the Caps Object Path
  494. Caps userCap
  495. = homeScene.CapsModule.GetCapsHandlerForUser(agentData.AgentID);
  496. string rezHttpProtocol = "http://";
  497. string regionCapsHttpProtocol = "http://";
  498. string httpaddr = reg.ExternalHostName;
  499. string urlport = reg.HttpPort.ToString();
  500. if (httpSSL)
  501. {
  502. rezHttpProtocol = "https://";
  503. regionCapsHttpProtocol = "https://";
  504. urlport = httpsslport.ToString();
  505. if (httpsCN.Length > 0)
  506. httpaddr = httpsCN;
  507. }
  508. // DEPRECIATED
  509. responseMap["seed_capability"]
  510. = OSD.FromString(
  511. regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
  512. // REPLACEMENT
  513. responseMap["region_seed_capability"]
  514. = OSD.FromString(
  515. regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
  516. responseMap["rez_avatar"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
  517. responseMap["rez_avatar/rez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
  518. responseMap["rez_avatar/derez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + derezAvatarPath);
  519. // Add the user to the list of CAPS that are outstanding.
  520. // well allow the caps hosts in this dictionary
  521. lock (CapsLoginID)
  522. {
  523. if (CapsLoginID.ContainsKey(rezAvatarPath))
  524. {
  525. CapsLoginID[rezAvatarPath] = agentData;
  526. // 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!
  527. m_log.Error("[OGP]: Holy anomoly batman! Caps path already existed! All the UUID Duplication worries were founded!");
  528. }
  529. else
  530. {
  531. CapsLoginID.Add(rezAvatarPath, agentData);
  532. }
  533. }
  534. //m_log.Debug("Response:" + responseMap.ToString());
  535. return responseMap;
  536. }
  537. public OSD RezAvatarMethod(string path, OSD request)
  538. {
  539. m_log.WarnFormat("[REZAVATAR]: {0}", request.ToString());
  540. OSDMap responseMap = new OSDMap();
  541. AgentCircuitData userData = null;
  542. // Only people we've issued a cap can go further
  543. if (TryGetAgentCircuitData(path,out userData))
  544. {
  545. OSDMap requestMap = (OSDMap)request;
  546. // take these values to start. There's a few more
  547. UUID SecureSessionID=requestMap["secure_session_id"].AsUUID();
  548. UUID SessionID = requestMap["session_id"].AsUUID();
  549. int circuitcode = requestMap["circuit_code"].AsInteger();
  550. OSDArray Parameter = new OSDArray();
  551. if (requestMap.ContainsKey("parameter"))
  552. {
  553. Parameter = (OSDArray)requestMap["parameter"];
  554. }
  555. //int version = 1;
  556. int estateID = 1;
  557. int parentEstateID = 1;
  558. UUID regionID = UUID.Zero;
  559. bool visibleToParent = true;
  560. for (int i = 0; i < Parameter.Count; i++)
  561. {
  562. OSDMap item = (OSDMap)Parameter[i];
  563. // if (item.ContainsKey("version"))
  564. // {
  565. // version = item["version"].AsInteger();
  566. // }
  567. if (item.ContainsKey("estate_id"))
  568. {
  569. estateID = item["estate_id"].AsInteger();
  570. }
  571. if (item.ContainsKey("parent_estate_id"))
  572. {
  573. parentEstateID = item["parent_estate_id"].AsInteger();
  574. }
  575. if (item.ContainsKey("region_id"))
  576. {
  577. regionID = item["region_id"].AsUUID();
  578. }
  579. if (item.ContainsKey("visible_to_parent"))
  580. {
  581. visibleToParent = item["visible_to_parent"].AsBoolean();
  582. }
  583. }
  584. //Update our Circuit data with the real values
  585. userData.SecureSessionID = SecureSessionID;
  586. userData.SessionID = SessionID;
  587. OGPState userState = GetOGPState(userData.AgentID);
  588. // Locate a home scene suitable for the user.
  589. Scene homeScene = null;
  590. homeScene = GetScene(userState.teleported_into_region);
  591. if (homeScene == null)
  592. homeScene = GetRootScene();
  593. if (homeScene != null)
  594. {
  595. // Get a referenceokay - to their Cap object so we can pull out the capobjectroot
  596. Caps userCap
  597. = homeScene.CapsModule.GetCapsHandlerForUser(userData.AgentID);
  598. //Update the circuit data in the region so this user is authorized
  599. homeScene.UpdateCircuitData(userData);
  600. homeScene.ChangeCircuitCode(userData.circuitcode,(uint)circuitcode);
  601. // Load state
  602. // Keep state changes
  603. userState.first_name = requestMap["first_name"].AsString();
  604. userState.secure_session_id = requestMap["secure_session_id"].AsUUID();
  605. userState.age_verified = requestMap["age_verified"].AsBoolean();
  606. userState.region_id = homeScene.RegionInfo.originRegionID; // replace 0000000 with our regionid
  607. userState.transacted = requestMap["transacted"].AsBoolean();
  608. userState.agent_access = requestMap["agent_access"].AsBoolean();
  609. userState.inventory_host = requestMap["inventory_host"].AsString();
  610. userState.identified = requestMap["identified"].AsBoolean();
  611. userState.session_id = requestMap["session_id"].AsUUID();
  612. userState.god_level = (uint)requestMap["god_level"].AsInteger();
  613. userState.last_name = requestMap["last_name"].AsString();
  614. userState.god_overide = requestMap["god_override"].AsBoolean();
  615. userState.circuit_code = (uint)requestMap["circuit_code"].AsInteger();
  616. userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
  617. userState.src_estate_id = estateID;
  618. userState.region_id = regionID;
  619. userState.src_parent_estate_id = parentEstateID;
  620. userState.visible_to_parent = visibleToParent;
  621. // Save state changes
  622. UpdateOGPState(userData.AgentID, userState);
  623. // Get the region information for the home region.
  624. RegionInfo reg = homeScene.RegionInfo;
  625. // Dummy positional and look at info.. we don't have it.
  626. OSDArray PositionArray = new OSDArray();
  627. PositionArray.Add(OSD.FromInteger(128));
  628. PositionArray.Add(OSD.FromInteger(128));
  629. PositionArray.Add(OSD.FromInteger(40));
  630. OSDArray LookAtArray = new OSDArray();
  631. LookAtArray.Add(OSD.FromInteger(1));
  632. LookAtArray.Add(OSD.FromInteger(1));
  633. LookAtArray.Add(OSD.FromInteger(1));
  634. // Our region's X and Y position in OpenSimulator space.
  635. uint fooX = reg.RegionLocX;
  636. uint fooY = reg.RegionLocY;
  637. m_log.InfoFormat("[OGP]: region x({0}) region y({1})", fooX, fooY);
  638. m_log.InfoFormat("[OGP]: region http {0} {1}", reg.ServerURI, reg.HttpPort);
  639. m_log.InfoFormat("[OGO]: region UUID {0} ", reg.RegionID);
  640. // Convert the X and Y position to LL space
  641. responseMap["region_x"] = OSD.FromInteger(fooX * (uint)Constants.RegionSize); // convert it to LL X
  642. responseMap["region_y"] = OSD.FromInteger(fooY * (uint)Constants.RegionSize); // convert it to LL Y
  643. // Give em a new seed capability
  644. responseMap["seed_capability"] = OSD.FromString("http://" + reg.ExternalHostName + ":" + reg.HttpPort + "/CAPS/" + userCap.CapsObjectPath + "0000/");
  645. responseMap["region"] = OSD.FromUUID(reg.originRegionID);
  646. responseMap["look_at"] = LookAtArray;
  647. responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
  648. responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);// + ":" + reg.InternalEndPoint.Port.ToString());
  649. // DEPRECIATED
  650. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
  651. responseMap["session_id"] = OSD.FromUUID(SessionID);
  652. responseMap["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  653. responseMap["circuit_code"] = OSD.FromInteger(circuitcode);
  654. responseMap["position"] = PositionArray;
  655. responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);
  656. responseMap["sim_access"] = OSD.FromString("Mature");
  657. responseMap["connect"] = OSD.FromBoolean(true);
  658. m_log.InfoFormat("[OGP]: host: {0}, IP {1}", responseMap["sim_host"].ToString(), responseMap["sim_ip"].ToString());
  659. }
  660. }
  661. return responseMap;
  662. }
  663. public OSD DerezAvatarMethod(string path, OSD request)
  664. {
  665. m_log.ErrorFormat("DerezPath: {0}, Request: {1}", path, request.ToString());
  666. //LLSD llsdResponse = null;
  667. OSDMap responseMap = new OSDMap();
  668. string[] PathArray = path.Split('/');
  669. m_log.InfoFormat("[OGP]: prefix {0}, uuid {1}, suffix {2}", PathArray[1], PathArray[2], PathArray[3]);
  670. string uuidString = PathArray[2];
  671. m_log.InfoFormat("[OGP]: Request to Derez avatar with UUID {0}", uuidString);
  672. UUID userUUID = UUID.Zero;
  673. if (UUID.TryParse(uuidString, out userUUID))
  674. {
  675. UUID RemoteID = (UUID)uuidString;
  676. UUID LocalID = RemoteID;
  677. // FIXME: TODO: Routine to map RemoteUUIDs to LocalUUIds
  678. // would be done already.. but the client connects with the Aditi UUID
  679. // regardless over the UDP stack
  680. OGPState userState = GetOGPState(LocalID);
  681. if (userState.agent_id != UUID.Zero)
  682. {
  683. //OSDMap outboundRequestMap = new OSDMap();
  684. OSDMap inboundRequestMap = (OSDMap)request;
  685. string rezAvatarString = inboundRequestMap["rez_avatar"].AsString();
  686. if (rezAvatarString.Length == 0)
  687. {
  688. rezAvatarString = inboundRequestMap["rez_avatar/rez"].AsString();
  689. }
  690. OSDArray LookAtArray = new OSDArray();
  691. LookAtArray.Add(OSD.FromInteger(1));
  692. LookAtArray.Add(OSD.FromInteger(1));
  693. LookAtArray.Add(OSD.FromInteger(1));
  694. OSDArray PositionArray = new OSDArray();
  695. PositionArray.Add(OSD.FromInteger(128));
  696. PositionArray.Add(OSD.FromInteger(128));
  697. PositionArray.Add(OSD.FromInteger(40));
  698. OSDArray lookArray = new OSDArray();
  699. lookArray.Add(OSD.FromInteger(128));
  700. lookArray.Add(OSD.FromInteger(128));
  701. lookArray.Add(OSD.FromInteger(40));
  702. responseMap["connect"] = OSD.FromBoolean(true);// it's okay to give this user up
  703. responseMap["look_at"] = LookAtArray;
  704. m_log.WarnFormat("[OGP]: Invoking rez_avatar on host:{0} for avatar: {1} {2}", rezAvatarString, userState.first_name, userState.last_name);
  705. OSDMap rezResponseMap = invokeRezAvatarCap(responseMap, rezAvatarString,userState);
  706. // If invoking it returned an error, parse and end
  707. if (rezResponseMap.ContainsKey("connect"))
  708. {
  709. if (rezResponseMap["connect"].AsBoolean() == false)
  710. {
  711. return responseMap;
  712. }
  713. }
  714. string rezRespSeedCap = "";
  715. // DEPRECIATED
  716. if (rezResponseMap.ContainsKey("seed_capability"))
  717. rezRespSeedCap = rezResponseMap["seed_capability"].AsString();
  718. // REPLACEMENT
  719. if (rezResponseMap.ContainsKey("region_seed_capability"))
  720. rezRespSeedCap = rezResponseMap["region_seed_capability"].AsString();
  721. // REPLACEMENT
  722. if (rezResponseMap.ContainsKey("rez_avatar/rez"))
  723. rezRespSeedCap = rezResponseMap["rez_avatar/rez"].AsString();
  724. // DEPRECIATED
  725. string rezRespSim_ip = rezResponseMap["sim_ip"].AsString();
  726. string rezRespSim_host = rezResponseMap["sim_host"].AsString();
  727. int rrPort = rezResponseMap["sim_port"].AsInteger();
  728. int rrX = rezResponseMap["region_x"].AsInteger();
  729. int rrY = rezResponseMap["region_y"].AsInteger();
  730. m_log.ErrorFormat("X:{0}, Y:{1}", rrX, rrY);
  731. UUID rrRID = rezResponseMap["region_id"].AsUUID();
  732. OSDArray RezResponsePositionArray = null;
  733. string rrAccess = rezResponseMap["sim_access"].AsString();
  734. if (rezResponseMap.ContainsKey("position"))
  735. {
  736. RezResponsePositionArray = (OSDArray)rezResponseMap["position"];
  737. }
  738. // DEPRECIATED
  739. responseMap["seed_capability"] = OSD.FromString(rezRespSeedCap);
  740. // REPLACEMENT r3
  741. responseMap["region_seed_capability"] = OSD.FromString(rezRespSeedCap);
  742. // DEPRECIATED
  743. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(rezRespSim_ip).ToString());
  744. responseMap["sim_host"] = OSD.FromString(rezRespSim_host);
  745. responseMap["sim_port"] = OSD.FromInteger(rrPort);
  746. responseMap["region_x"] = OSD.FromInteger(rrX);
  747. responseMap["region_y"] = OSD.FromInteger(rrY);
  748. responseMap["region_id"] = OSD.FromUUID(rrRID);
  749. responseMap["sim_access"] = OSD.FromString(rrAccess);
  750. if (RezResponsePositionArray != null)
  751. {
  752. responseMap["position"] = RezResponsePositionArray;
  753. }
  754. responseMap["look_at"] = lookArray;
  755. responseMap["connect"] = OSD.FromBoolean(true);
  756. ShutdownConnection(LocalID,this);
  757. // PLEASE STOP CHANGING THIS TO an M_LOG, M_LOG DOESN'T WORK ON MULTILINE .TOSTRINGS
  758. Console.WriteLine("RESPONSEDEREZ: " + responseMap.ToString());
  759. return responseMap;
  760. }
  761. else
  762. {
  763. return GenerateNoStateMessage(LocalID);
  764. }
  765. }
  766. else
  767. {
  768. return GenerateNoHandlerMessage();
  769. }
  770. //return responseMap;
  771. }
  772. private OSDMap invokeRezAvatarCap(OSDMap responseMap, string CapAddress, OGPState userState)
  773. {
  774. Scene reg = GetRootScene();
  775. WebRequest DeRezRequest = WebRequest.Create(CapAddress);
  776. DeRezRequest.Method = "POST";
  777. DeRezRequest.ContentType = "application/xml+llsd";
  778. OSDMap RAMap = new OSDMap();
  779. OSDMap AgentParms = new OSDMap();
  780. OSDMap RegionParms = new OSDMap();
  781. OSDArray Parameter = new OSDArray(2);
  782. OSDMap version = new OSDMap();
  783. version["version"] = OSD.FromInteger(userState.src_version);
  784. Parameter.Add(version);
  785. OSDMap SrcData = new OSDMap();
  786. SrcData["estate_id"] = OSD.FromInteger(reg.RegionInfo.EstateSettings.EstateID);
  787. SrcData["parent_estate_id"] = OSD.FromInteger((reg.RegionInfo.EstateSettings.ParentEstateID == 100 ? 1 : reg.RegionInfo.EstateSettings.ParentEstateID));
  788. SrcData["region_id"] = OSD.FromUUID(reg.RegionInfo.originRegionID);
  789. SrcData["visible_to_parent"] = OSD.FromBoolean(userState.visible_to_parent);
  790. Parameter.Add(SrcData);
  791. AgentParms["first_name"] = OSD.FromString(userState.first_name);
  792. AgentParms["last_name"] = OSD.FromString(userState.last_name);
  793. AgentParms["agent_id"] = OSD.FromUUID(userState.agent_id);
  794. RegionParms["region_id"] = OSD.FromUUID(userState.region_id);
  795. AgentParms["circuit_code"] = OSD.FromInteger(userState.circuit_code);
  796. AgentParms["secure_session_id"] = OSD.FromUUID(userState.secure_session_id);
  797. AgentParms["session_id"] = OSD.FromUUID(userState.session_id);
  798. AgentParms["agent_access"] = OSD.FromBoolean(userState.agent_access);
  799. AgentParms["god_level"] = OSD.FromInteger(userState.god_level);
  800. AgentParms["god_overide"] = OSD.FromBoolean(userState.god_overide);
  801. AgentParms["identified"] = OSD.FromBoolean(userState.identified);
  802. AgentParms["transacted"] = OSD.FromBoolean(userState.transacted);
  803. AgentParms["age_verified"] = OSD.FromBoolean(userState.age_verified);
  804. AgentParms["limited_to_estate"] = OSD.FromInteger(userState.limited_to_estate);
  805. AgentParms["inventory_host"] = OSD.FromString(userState.inventory_host);
  806. // version 1
  807. RAMap = AgentParms;
  808. // Planned for version 2
  809. // RAMap["agent_params"] = AgentParms;
  810. RAMap["region_params"] = RegionParms;
  811. RAMap["parameter"] = Parameter;
  812. string RAMapString = RAMap.ToString();
  813. m_log.InfoFormat("[OGP] RAMap string {0}", RAMapString);
  814. OSD LLSDofRAMap = RAMap; // RENAME if this works
  815. m_log.InfoFormat("[OGP]: LLSD of map as string was {0}", LLSDofRAMap.ToString());
  816. //m_log.InfoFormat("[OGP]: LLSD+XML: {0}", LLSDParser.SerializeXmlString(LLSDofRAMap));
  817. byte[] buffer = OSDParser.SerializeLLSDXmlBytes(LLSDofRAMap);
  818. //string bufferDump = System.Text.Encoding.ASCII.GetString(buffer);
  819. //m_log.InfoFormat("[OGP]: buffer form is {0}",bufferDump);
  820. //m_log.InfoFormat("[OGP]: LLSD of map was {0}",buffer.Length);
  821. Stream os = null;
  822. try
  823. { // send the Post
  824. DeRezRequest.ContentLength = buffer.Length; //Count bytes to send
  825. os = DeRezRequest.GetRequestStream();
  826. os.Write(buffer, 0, buffer.Length); //Send it
  827. os.Close();
  828. m_log.InfoFormat("[OGP]: Derez Avatar Posted Rez Avatar request to remote sim {0}", CapAddress);
  829. }
  830. catch (WebException ex)
  831. {
  832. m_log.InfoFormat("[OGP] Bad send on de_rez_avatar {0}", ex.Message);
  833. responseMap["connect"] = OSD.FromBoolean(false);
  834. return responseMap;
  835. }
  836. m_log.Info("[OGP] waiting for a reply after rez avatar send");
  837. string rez_avatar_reply = null;
  838. { // get the response
  839. try
  840. {
  841. WebResponse webResponse = DeRezRequest.GetResponse();
  842. if (webResponse == null)
  843. {
  844. m_log.Info("[OGP:] Null reply on rez_avatar post");
  845. }
  846. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  847. rez_avatar_reply = sr.ReadToEnd().Trim();
  848. m_log.InfoFormat("[OGP]: rez_avatar reply was {0} ", rez_avatar_reply);
  849. }
  850. catch (WebException ex)
  851. {
  852. m_log.InfoFormat("[OGP]: exception on read after send of rez avatar {0}", ex.Message);
  853. responseMap["connect"] = OSD.FromBoolean(false);
  854. return responseMap;
  855. }
  856. OSD rezResponse = null;
  857. try
  858. {
  859. rezResponse = OSDParser.DeserializeLLSDXml(rez_avatar_reply);
  860. responseMap = (OSDMap)rezResponse;
  861. }
  862. catch (Exception ex)
  863. {
  864. m_log.InfoFormat("[OGP]: exception on parse of rez reply {0}", ex.Message);
  865. responseMap["connect"] = OSD.FromBoolean(false);
  866. return responseMap;
  867. }
  868. }
  869. return responseMap;
  870. }
  871. public OSD GenerateNoHandlerMessage()
  872. {
  873. OSDMap map = new OSDMap();
  874. map["reason"] = OSD.FromString("LLSDRequest");
  875. map["message"] = OSD.FromString("No handler registered for LLSD Requests");
  876. map["login"] = OSD.FromString("false");
  877. map["connect"] = OSD.FromString("false");
  878. return map;
  879. }
  880. public OSD GenerateNoStateMessage(UUID passedAvatar)
  881. {
  882. OSDMap map = new OSDMap();
  883. map["reason"] = OSD.FromString("derez failed");
  884. map["message"] = OSD.FromString("Unable to locate OGP state for avatar " + passedAvatar.ToString());
  885. map["login"] = OSD.FromString("false");
  886. map["connect"] = OSD.FromString("false");
  887. return map;
  888. }
  889. private bool TryGetAgentCircuitData(string path, out AgentCircuitData userdata)
  890. {
  891. userdata = null;
  892. lock (CapsLoginID)
  893. {
  894. if (CapsLoginID.ContainsKey(path))
  895. {
  896. userdata = CapsLoginID[path];
  897. DiscardUsedCap(path);
  898. return true;
  899. }
  900. }
  901. return false;
  902. }
  903. private void DiscardUsedCap(string path)
  904. {
  905. CapsLoginID.Remove(path);
  906. }
  907. private Scene GetRootScene()
  908. {
  909. Scene ReturnScene = null;
  910. lock (m_scene)
  911. {
  912. if (m_scene.Count > 0)
  913. {
  914. ReturnScene = m_scene[0];
  915. }
  916. }
  917. return ReturnScene;
  918. }
  919. private Scene GetScene(string scenename)
  920. {
  921. Scene ReturnScene = null;
  922. lock (m_scene)
  923. {
  924. foreach (Scene s in m_scene)
  925. {
  926. if (s.RegionInfo.RegionName.ToLower() == scenename)
  927. {
  928. ReturnScene = s;
  929. break;
  930. }
  931. }
  932. }
  933. return ReturnScene;
  934. }
  935. private ulong GetOSCompatibleRegionHandle(RegionInfo reg)
  936. {
  937. return Util.UIntsToLong(reg.RegionLocX, reg.RegionLocY);
  938. }
  939. private OGPState InitializeNewState()
  940. {
  941. OGPState returnState = new OGPState();
  942. returnState.first_name = "";
  943. returnState.last_name = "";
  944. returnState.agent_id = UUID.Zero;
  945. returnState.local_agent_id = UUID.Zero;
  946. returnState.region_id = UUID.Zero;
  947. returnState.circuit_code = 0;
  948. returnState.secure_session_id = UUID.Zero;
  949. returnState.session_id = UUID.Zero;
  950. returnState.agent_access = true;
  951. returnState.god_level = 0;
  952. returnState.god_overide = false;
  953. returnState.identified = false;
  954. returnState.transacted = false;
  955. returnState.age_verified = false;
  956. returnState.limited_to_estate = 1;
  957. returnState.inventory_host = "http://inv4.mysql.aditi.lindenlab.com";
  958. returnState.allow_redirect = true;
  959. returnState.sim_access = "";
  960. returnState.src_can_see_mainland = true;
  961. returnState.src_estate_id = 1;
  962. returnState.src_version = 1;
  963. returnState.src_parent_estate_id = 1;
  964. returnState.visible_to_parent = true;
  965. returnState.teleported_into_region = "";
  966. return returnState;
  967. }
  968. private OGPState GetOGPState(UUID agentId)
  969. {
  970. lock (m_OGPState)
  971. {
  972. if (m_OGPState.ContainsKey(agentId))
  973. {
  974. return m_OGPState[agentId];
  975. }
  976. else
  977. {
  978. return InitializeNewState();
  979. }
  980. }
  981. }
  982. public void DeleteOGPState(UUID agentId)
  983. {
  984. lock (m_OGPState)
  985. {
  986. if (m_OGPState.ContainsKey(agentId))
  987. m_OGPState.Remove(agentId);
  988. }
  989. }
  990. private void UpdateOGPState(UUID agentId, OGPState state)
  991. {
  992. lock (m_OGPState)
  993. {
  994. if (m_OGPState.ContainsKey(agentId))
  995. {
  996. m_OGPState[agentId] = state;
  997. }
  998. else
  999. {
  1000. m_OGPState.Add(agentId,state);
  1001. }
  1002. }
  1003. }
  1004. private bool SceneListDuplicateCheck(string str)
  1005. {
  1006. // no lock, called from locked space!
  1007. bool found = false;
  1008. foreach (Scene s in m_scene)
  1009. {
  1010. if (s.RegionInfo.RegionName == str)
  1011. {
  1012. found = true;
  1013. break;
  1014. }
  1015. }
  1016. return found;
  1017. }
  1018. public void ShutdownConnection(UUID avatarId, OpenGridProtocolModule mod)
  1019. {
  1020. Scene homeScene = GetRootScene();
  1021. ScenePresence avatar = null;
  1022. if (homeScene.TryGetAvatar(avatarId,out avatar))
  1023. {
  1024. KillAUser ku = new KillAUser(avatar,mod);
  1025. Thread ta = new Thread(ku.ShutdownNoLogout);
  1026. ta.IsBackground = true;
  1027. ta.Name = "ShutdownThread";
  1028. ta.Start();
  1029. }
  1030. }
  1031. private string CreateRandomStr(int len)
  1032. {
  1033. Random rnd = new Random(Environment.TickCount);
  1034. string returnstring = "";
  1035. string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  1036. for (int i = 0; i < len; i++)
  1037. {
  1038. returnstring += chars.Substring(rnd.Next(chars.Length), 1);
  1039. }
  1040. return returnstring;
  1041. }
  1042. // Temporary hack to allow teleporting to and from Vaak
  1043. private static bool customXertificateValidation(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
  1044. {
  1045. //if (cert.Subject == "[email protected], CN=*.vaak.lindenlab.com, O=\"Linden Lab, Inc.\", L=San Francisco, S=California, C=US")
  1046. //{
  1047. return true;
  1048. //}
  1049. //return false;
  1050. }
  1051. }
  1052. public class KillAUser
  1053. {
  1054. private ScenePresence avToBeKilled = null;
  1055. private OpenGridProtocolModule m_mod = null;
  1056. public KillAUser(ScenePresence avatar, OpenGridProtocolModule mod)
  1057. {
  1058. avToBeKilled = avatar;
  1059. m_mod = mod;
  1060. }
  1061. public void ShutdownNoLogout()
  1062. {
  1063. UUID avUUID = UUID.Zero;
  1064. if (avToBeKilled != null)
  1065. {
  1066. avUUID = avToBeKilled.UUID;
  1067. avToBeKilled.MakeChildAgent();
  1068. avToBeKilled.ControllingClient.SendLogoutPacketWhenClosing = false;
  1069. Thread.Sleep(30000);
  1070. // test for child agent because they might have come back
  1071. if (avToBeKilled.IsChildAgent)
  1072. {
  1073. m_mod.DeleteOGPState(avUUID);
  1074. avToBeKilled.ControllingClient.Close(true);
  1075. }
  1076. }
  1077. }
  1078. }
  1079. public class MonoCert : ICertificatePolicy
  1080. {
  1081. #region ICertificatePolicy Members
  1082. public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
  1083. {
  1084. return true;
  1085. }
  1086. #endregion
  1087. }
  1088. }