OpenGridProtocolModule.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Net;
  31. using System.Net.Security;
  32. using System.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.Communications.Capabilities;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. using Caps=OpenSim.Framework.Communications.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.Communications.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. responseMap["sim_access"] = OSD.FromString((reg.RegionSettings.Maturity == 1) ? "Mature" : "PG");
  391. // Generate a dummy agent for the user so we can get back a CAPS path
  392. AgentCircuitData agentData = new AgentCircuitData();
  393. agentData.AgentID = LocalAgentID;
  394. agentData.BaseFolder = UUID.Zero;
  395. agentData.CapsPath = CapsUtil.GetRandomCapsObjectPath();
  396. agentData.child = false;
  397. agentData.circuitcode = (uint)(Util.RandomClass.Next());
  398. agentData.firstname = FirstName;
  399. agentData.lastname = LastName;
  400. agentData.SecureSessionID = UUID.Random();
  401. agentData.SessionID = UUID.Random();
  402. agentData.startpos = new Vector3(128f, 128f, 100f);
  403. // Pre-Fill our region cache with information on the agent.
  404. UserAgentData useragent = new UserAgentData();
  405. useragent.AgentIP = "unknown";
  406. useragent.AgentOnline = true;
  407. useragent.AgentPort = (uint)0;
  408. useragent.Handle = regionhandle;
  409. useragent.InitialRegion = reg.originRegionID;
  410. useragent.LoginTime = Util.UnixTimeSinceEpoch();
  411. useragent.LogoutTime = 0;
  412. useragent.Position = agentData.startpos;
  413. useragent.Region = reg.originRegionID;
  414. useragent.SecureSessionID = agentData.SecureSessionID;
  415. useragent.SessionID = agentData.SessionID;
  416. UserProfileData userProfile = new UserProfileData();
  417. userProfile.AboutText = "OGP User";
  418. userProfile.CanDoMask = (uint)0;
  419. userProfile.Created = Util.UnixTimeSinceEpoch();
  420. userProfile.CurrentAgent = useragent;
  421. userProfile.CustomType = "OGP";
  422. userProfile.FirstLifeAboutText = "I'm testing OpenGrid Protocol";
  423. userProfile.FirstLifeImage = UUID.Zero;
  424. userProfile.FirstName = agentData.firstname;
  425. userProfile.GodLevel = 0;
  426. userProfile.HomeLocation = agentData.startpos;
  427. userProfile.HomeLocationX = agentData.startpos.X;
  428. userProfile.HomeLocationY = agentData.startpos.Y;
  429. userProfile.HomeLocationZ = agentData.startpos.Z;
  430. userProfile.HomeLookAt = Vector3.Zero;
  431. userProfile.HomeLookAtX = userProfile.HomeLookAt.X;
  432. userProfile.HomeLookAtY = userProfile.HomeLookAt.Y;
  433. userProfile.HomeLookAtZ = userProfile.HomeLookAt.Z;
  434. userProfile.HomeRegion = reg.RegionHandle;
  435. userProfile.HomeRegionID = reg.originRegionID;
  436. userProfile.HomeRegionX = reg.RegionLocX;
  437. userProfile.HomeRegionY = reg.RegionLocY;
  438. userProfile.ID = agentData.AgentID;
  439. userProfile.Image = UUID.Zero;
  440. userProfile.LastLogin = Util.UnixTimeSinceEpoch();
  441. userProfile.Partner = UUID.Zero;
  442. userProfile.PasswordHash = "$1$";
  443. userProfile.PasswordSalt = "";
  444. userProfile.RootInventoryFolderID = UUID.Zero;
  445. userProfile.SurName = agentData.lastname;
  446. userProfile.UserAssetURI = homeScene.CommsManager.NetworkServersInfo.AssetURL;
  447. userProfile.UserFlags = 0;
  448. userProfile.UserInventoryURI = homeScene.CommsManager.NetworkServersInfo.InventoryURL;
  449. userProfile.WantDoMask = 0;
  450. userProfile.WebLoginKey = UUID.Random();
  451. // Do caps registration
  452. // get seed capagentData.firstname = FirstName;agentData.lastname = LastName;
  453. if (homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID) == null && !GridMode)
  454. {
  455. homeScene.CommsManager.UserAdminService.AddUser(
  456. agentData.firstname, agentData.lastname, CreateRandomStr(7), "",
  457. homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
  458. UserProfileData userProfile2 = homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID);
  459. if (userProfile2 != null)
  460. {
  461. userProfile = userProfile2;
  462. userProfile.AboutText = "OGP USER";
  463. userProfile.FirstLifeAboutText = "OGP USER";
  464. homeScene.CommsManager.UserService.UpdateUserProfile(userProfile);
  465. }
  466. }
  467. // Stick our data in the cache so the region will know something about us
  468. homeScene.CommsManager.UserProfileCacheService.PreloadUserCache(agentData.AgentID, userProfile);
  469. // Call 'new user' event handler
  470. homeScene.NewUserConnection(agentData);
  471. //string raCap = string.Empty;
  472. UUID AvatarRezCapUUID = LocalAgentID;
  473. string rezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/rez";
  474. string derezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/derez";
  475. // Get a reference to the user's cap so we can pull out the Caps Object Path
  476. Caps userCap
  477. = homeScene.CapsModule.GetCapsHandlerForUser(agentData.AgentID);
  478. string rezHttpProtocol = "http://";
  479. string regionCapsHttpProtocol = "http://";
  480. string httpaddr = reg.ExternalHostName;
  481. string urlport = reg.HttpPort.ToString();
  482. if (httpSSL)
  483. {
  484. rezHttpProtocol = "https://";
  485. regionCapsHttpProtocol = "https://";
  486. urlport = httpsslport.ToString();
  487. if (httpsCN.Length > 0)
  488. httpaddr = httpsCN;
  489. }
  490. // DEPRECIATED
  491. responseMap["seed_capability"]
  492. = OSD.FromString(
  493. regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
  494. // REPLACEMENT
  495. responseMap["region_seed_capability"]
  496. = OSD.FromString(
  497. regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
  498. responseMap["rez_avatar"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
  499. responseMap["rez_avatar/rez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
  500. responseMap["rez_avatar/derez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + derezAvatarPath);
  501. // Add the user to the list of CAPS that are outstanding.
  502. // well allow the caps hosts in this dictionary
  503. lock (CapsLoginID)
  504. {
  505. if (CapsLoginID.ContainsKey(rezAvatarPath))
  506. {
  507. CapsLoginID[rezAvatarPath] = agentData;
  508. // 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!
  509. m_log.Error("[OGP]: Holy anomoly batman! Caps path already existed! All the UUID Duplication worries were founded!");
  510. }
  511. else
  512. {
  513. CapsLoginID.Add(rezAvatarPath, agentData);
  514. }
  515. }
  516. //m_log.Debug("Response:" + responseMap.ToString());
  517. return responseMap;
  518. }
  519. public OSD RezAvatarMethod(string path, OSD request)
  520. {
  521. m_log.WarnFormat("[REZAVATAR]: {0}", request.ToString());
  522. OSDMap responseMap = new OSDMap();
  523. AgentCircuitData userData = null;
  524. // Only people we've issued a cap can go further
  525. if (TryGetAgentCircuitData(path,out userData))
  526. {
  527. OSDMap requestMap = (OSDMap)request;
  528. // take these values to start. There's a few more
  529. UUID SecureSessionID=requestMap["secure_session_id"].AsUUID();
  530. UUID SessionID = requestMap["session_id"].AsUUID();
  531. int circuitcode = requestMap["circuit_code"].AsInteger();
  532. OSDArray Parameter = new OSDArray();
  533. if (requestMap.ContainsKey("parameter"))
  534. {
  535. Parameter = (OSDArray)requestMap["parameter"];
  536. }
  537. //int version = 1;
  538. int estateID = 1;
  539. int parentEstateID = 1;
  540. UUID regionID = UUID.Zero;
  541. bool visibleToParent = true;
  542. for (int i = 0; i < Parameter.Count; i++)
  543. {
  544. OSDMap item = (OSDMap)Parameter[i];
  545. // if (item.ContainsKey("version"))
  546. // {
  547. // version = item["version"].AsInteger();
  548. // }
  549. if (item.ContainsKey("estate_id"))
  550. {
  551. estateID = item["estate_id"].AsInteger();
  552. }
  553. if (item.ContainsKey("parent_estate_id"))
  554. {
  555. parentEstateID = item["parent_estate_id"].AsInteger();
  556. }
  557. if (item.ContainsKey("region_id"))
  558. {
  559. regionID = item["region_id"].AsUUID();
  560. }
  561. if (item.ContainsKey("visible_to_parent"))
  562. {
  563. visibleToParent = item["visible_to_parent"].AsBoolean();
  564. }
  565. }
  566. //Update our Circuit data with the real values
  567. userData.SecureSessionID = SecureSessionID;
  568. userData.SessionID = SessionID;
  569. OGPState userState = GetOGPState(userData.AgentID);
  570. // Locate a home scene suitable for the user.
  571. Scene homeScene = null;
  572. homeScene = GetScene(userState.teleported_into_region);
  573. if (homeScene == null)
  574. homeScene = GetRootScene();
  575. if (homeScene != null)
  576. {
  577. // Get a referenceokay - to their Cap object so we can pull out the capobjectroot
  578. Caps userCap
  579. = homeScene.CapsModule.GetCapsHandlerForUser(userData.AgentID);
  580. //Update the circuit data in the region so this user is authorized
  581. homeScene.UpdateCircuitData(userData);
  582. homeScene.ChangeCircuitCode(userData.circuitcode,(uint)circuitcode);
  583. // Load state
  584. // Keep state changes
  585. userState.first_name = requestMap["first_name"].AsString();
  586. userState.secure_session_id = requestMap["secure_session_id"].AsUUID();
  587. userState.age_verified = requestMap["age_verified"].AsBoolean();
  588. userState.region_id = homeScene.RegionInfo.originRegionID; // replace 0000000 with our regionid
  589. userState.transacted = requestMap["transacted"].AsBoolean();
  590. userState.agent_access = requestMap["agent_access"].AsBoolean();
  591. userState.inventory_host = requestMap["inventory_host"].AsString();
  592. userState.identified = requestMap["identified"].AsBoolean();
  593. userState.session_id = requestMap["session_id"].AsUUID();
  594. userState.god_level = (uint)requestMap["god_level"].AsInteger();
  595. userState.last_name = requestMap["last_name"].AsString();
  596. userState.god_overide = requestMap["god_override"].AsBoolean();
  597. userState.circuit_code = (uint)requestMap["circuit_code"].AsInteger();
  598. userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
  599. userState.src_estate_id = estateID;
  600. userState.region_id = regionID;
  601. userState.src_parent_estate_id = parentEstateID;
  602. userState.visible_to_parent = visibleToParent;
  603. // Save state changes
  604. UpdateOGPState(userData.AgentID, userState);
  605. // Get the region information for the home region.
  606. RegionInfo reg = homeScene.RegionInfo;
  607. // Dummy positional and look at info.. we don't have it.
  608. OSDArray PositionArray = new OSDArray();
  609. PositionArray.Add(OSD.FromInteger(128));
  610. PositionArray.Add(OSD.FromInteger(128));
  611. PositionArray.Add(OSD.FromInteger(40));
  612. OSDArray LookAtArray = new OSDArray();
  613. LookAtArray.Add(OSD.FromInteger(1));
  614. LookAtArray.Add(OSD.FromInteger(1));
  615. LookAtArray.Add(OSD.FromInteger(1));
  616. // Our region's X and Y position in OpenSimulator space.
  617. uint fooX = reg.RegionLocX;
  618. uint fooY = reg.RegionLocY;
  619. m_log.InfoFormat("[OGP]: region x({0}) region y({1})", fooX, fooY);
  620. m_log.InfoFormat("[OGP]: region http {0} {1}", reg.ServerURI, reg.HttpPort);
  621. m_log.InfoFormat("[OGO]: region UUID {0} ", reg.RegionID);
  622. // Convert the X and Y position to LL space
  623. responseMap["region_x"] = OSD.FromInteger(fooX * (uint)Constants.RegionSize); // convert it to LL X
  624. responseMap["region_y"] = OSD.FromInteger(fooY * (uint)Constants.RegionSize); // convert it to LL Y
  625. // Give em a new seed capability
  626. responseMap["seed_capability"] = OSD.FromString("http://" + reg.ExternalHostName + ":" + reg.HttpPort + "/CAPS/" + userCap.CapsObjectPath + "0000/");
  627. responseMap["region"] = OSD.FromUUID(reg.originRegionID);
  628. responseMap["look_at"] = LookAtArray;
  629. responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
  630. responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);// + ":" + reg.InternalEndPoint.Port.ToString());
  631. // DEPRECIATED
  632. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
  633. responseMap["session_id"] = OSD.FromUUID(SessionID);
  634. responseMap["secure_session_id"] = OSD.FromUUID(SecureSessionID);
  635. responseMap["circuit_code"] = OSD.FromInteger(circuitcode);
  636. responseMap["position"] = PositionArray;
  637. responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);
  638. responseMap["sim_access"] = OSD.FromString("Mature");
  639. responseMap["connect"] = OSD.FromBoolean(true);
  640. m_log.InfoFormat("[OGP]: host: {0}, IP {1}", responseMap["sim_host"].ToString(), responseMap["sim_ip"].ToString());
  641. }
  642. }
  643. return responseMap;
  644. }
  645. public OSD DerezAvatarMethod(string path, OSD request)
  646. {
  647. m_log.ErrorFormat("DerezPath: {0}, Request: {1}", path, request.ToString());
  648. //LLSD llsdResponse = null;
  649. OSDMap responseMap = new OSDMap();
  650. string[] PathArray = path.Split('/');
  651. m_log.InfoFormat("[OGP]: prefix {0}, uuid {1}, suffix {2}", PathArray[1], PathArray[2], PathArray[3]);
  652. string uuidString = PathArray[2];
  653. m_log.InfoFormat("[OGP]: Request to Derez avatar with UUID {0}", uuidString);
  654. UUID userUUID = UUID.Zero;
  655. if (UUID.TryParse(uuidString, out userUUID))
  656. {
  657. UUID RemoteID = (UUID)uuidString;
  658. UUID LocalID = RemoteID;
  659. // FIXME: TODO: Routine to map RemoteUUIDs to LocalUUIds
  660. // would be done already.. but the client connects with the Aditi UUID
  661. // regardless over the UDP stack
  662. OGPState userState = GetOGPState(LocalID);
  663. if (userState.agent_id != UUID.Zero)
  664. {
  665. //OSDMap outboundRequestMap = new OSDMap();
  666. OSDMap inboundRequestMap = (OSDMap)request;
  667. string rezAvatarString = inboundRequestMap["rez_avatar"].AsString();
  668. if (rezAvatarString.Length == 0)
  669. {
  670. rezAvatarString = inboundRequestMap["rez_avatar/rez"].AsString();
  671. }
  672. OSDArray LookAtArray = new OSDArray();
  673. LookAtArray.Add(OSD.FromInteger(1));
  674. LookAtArray.Add(OSD.FromInteger(1));
  675. LookAtArray.Add(OSD.FromInteger(1));
  676. OSDArray PositionArray = new OSDArray();
  677. PositionArray.Add(OSD.FromInteger(128));
  678. PositionArray.Add(OSD.FromInteger(128));
  679. PositionArray.Add(OSD.FromInteger(40));
  680. OSDArray lookArray = new OSDArray();
  681. lookArray.Add(OSD.FromInteger(128));
  682. lookArray.Add(OSD.FromInteger(128));
  683. lookArray.Add(OSD.FromInteger(40));
  684. responseMap["connect"] = OSD.FromBoolean(true);// it's okay to give this user up
  685. responseMap["look_at"] = LookAtArray;
  686. m_log.WarnFormat("[OGP]: Invoking rez_avatar on host:{0} for avatar: {1} {2}", rezAvatarString, userState.first_name, userState.last_name);
  687. OSDMap rezResponseMap = invokeRezAvatarCap(responseMap, rezAvatarString,userState);
  688. // If invoking it returned an error, parse and end
  689. if (rezResponseMap.ContainsKey("connect"))
  690. {
  691. if (rezResponseMap["connect"].AsBoolean() == false)
  692. {
  693. return responseMap;
  694. }
  695. }
  696. string rezRespSeedCap = "";
  697. // DEPRECIATED
  698. if (rezResponseMap.ContainsKey("seed_capability"))
  699. rezRespSeedCap = rezResponseMap["seed_capability"].AsString();
  700. // REPLACEMENT
  701. if (rezResponseMap.ContainsKey("region_seed_capability"))
  702. rezRespSeedCap = rezResponseMap["region_seed_capability"].AsString();
  703. // REPLACEMENT
  704. if (rezResponseMap.ContainsKey("rez_avatar/rez"))
  705. rezRespSeedCap = rezResponseMap["rez_avatar/rez"].AsString();
  706. // DEPRECIATED
  707. string rezRespSim_ip = rezResponseMap["sim_ip"].AsString();
  708. string rezRespSim_host = rezResponseMap["sim_host"].AsString();
  709. int rrPort = rezResponseMap["sim_port"].AsInteger();
  710. int rrX = rezResponseMap["region_x"].AsInteger();
  711. int rrY = rezResponseMap["region_y"].AsInteger();
  712. m_log.ErrorFormat("X:{0}, Y:{1}", rrX, rrY);
  713. UUID rrRID = rezResponseMap["region_id"].AsUUID();
  714. OSDArray RezResponsePositionArray = null;
  715. string rrAccess = rezResponseMap["sim_access"].AsString();
  716. if (rezResponseMap.ContainsKey("position"))
  717. {
  718. RezResponsePositionArray = (OSDArray)rezResponseMap["position"];
  719. }
  720. // DEPRECIATED
  721. responseMap["seed_capability"] = OSD.FromString(rezRespSeedCap);
  722. // REPLACEMENT r3
  723. responseMap["region_seed_capability"] = OSD.FromString(rezRespSeedCap);
  724. // DEPRECIATED
  725. responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(rezRespSim_ip).ToString());
  726. responseMap["sim_host"] = OSD.FromString(rezRespSim_host);
  727. responseMap["sim_port"] = OSD.FromInteger(rrPort);
  728. responseMap["region_x"] = OSD.FromInteger(rrX );
  729. responseMap["region_y"] = OSD.FromInteger(rrY );
  730. responseMap["region_id"] = OSD.FromUUID(rrRID);
  731. responseMap["sim_access"] = OSD.FromString(rrAccess);
  732. if (RezResponsePositionArray != null)
  733. {
  734. responseMap["position"] = RezResponsePositionArray;
  735. }
  736. responseMap["look_at"] = lookArray;
  737. responseMap["connect"] = OSD.FromBoolean(true);
  738. ShutdownConnection(LocalID,this);
  739. // PLEASE STOP CHANGING THIS TO an M_LOG, M_LOG DOESN'T WORK ON MULTILINE .TOSTRINGS
  740. Console.WriteLine("RESPONSEDEREZ: " + responseMap.ToString());
  741. return responseMap;
  742. }
  743. else
  744. {
  745. return GenerateNoStateMessage(LocalID);
  746. }
  747. }
  748. else
  749. {
  750. return GenerateNoHandlerMessage();
  751. }
  752. //return responseMap;
  753. }
  754. private OSDMap invokeRezAvatarCap(OSDMap responseMap, string CapAddress, OGPState userState)
  755. {
  756. Scene reg = GetRootScene();
  757. WebRequest DeRezRequest = WebRequest.Create(CapAddress);
  758. DeRezRequest.Method = "POST";
  759. DeRezRequest.ContentType = "application/xml+llsd";
  760. OSDMap RAMap = new OSDMap();
  761. OSDMap AgentParms = new OSDMap();
  762. OSDMap RegionParms = new OSDMap();
  763. OSDArray Parameter = new OSDArray(2);
  764. OSDMap version = new OSDMap();
  765. version["version"] = OSD.FromInteger(userState.src_version);
  766. Parameter.Add(version);
  767. OSDMap SrcData = new OSDMap();
  768. SrcData["estate_id"] = OSD.FromInteger(reg.RegionInfo.EstateSettings.EstateID);
  769. SrcData["parent_estate_id"] = OSD.FromInteger((reg.RegionInfo.EstateSettings.ParentEstateID == 100 ? 1 : reg.RegionInfo.EstateSettings.ParentEstateID));
  770. SrcData["region_id"] = OSD.FromUUID(reg.RegionInfo.originRegionID);
  771. SrcData["visible_to_parent"] = OSD.FromBoolean(userState.visible_to_parent);
  772. Parameter.Add(SrcData);
  773. AgentParms["first_name"] = OSD.FromString(userState.first_name);
  774. AgentParms["last_name"] = OSD.FromString(userState.last_name);
  775. AgentParms["agent_id"] = OSD.FromUUID(userState.agent_id);
  776. RegionParms["region_id"] = OSD.FromUUID(userState.region_id);
  777. AgentParms["circuit_code"] = OSD.FromInteger(userState.circuit_code);
  778. AgentParms["secure_session_id"] = OSD.FromUUID(userState.secure_session_id);
  779. AgentParms["session_id"] = OSD.FromUUID(userState.session_id);
  780. AgentParms["agent_access"] = OSD.FromBoolean(userState.agent_access);
  781. AgentParms["god_level"] = OSD.FromInteger(userState.god_level);
  782. AgentParms["god_overide"] = OSD.FromBoolean(userState.god_overide);
  783. AgentParms["identified"] = OSD.FromBoolean(userState.identified);
  784. AgentParms["transacted"] = OSD.FromBoolean(userState.transacted);
  785. AgentParms["age_verified"] = OSD.FromBoolean(userState.age_verified);
  786. AgentParms["limited_to_estate"] = OSD.FromInteger(userState.limited_to_estate);
  787. AgentParms["inventory_host"] = OSD.FromString(userState.inventory_host);
  788. // version 1
  789. RAMap = AgentParms;
  790. // Planned for version 2
  791. // RAMap["agent_params"] = AgentParms;
  792. RAMap["region_params"] = RegionParms;
  793. RAMap["parameter"] = Parameter;
  794. string RAMapString = RAMap.ToString();
  795. m_log.InfoFormat("[OGP] RAMap string {0}", RAMapString);
  796. OSD LLSDofRAMap = RAMap; // RENAME if this works
  797. m_log.InfoFormat("[OGP]: LLSD of map as string was {0}", LLSDofRAMap.ToString());
  798. //m_log.InfoFormat("[OGP]: LLSD+XML: {0}", LLSDParser.SerializeXmlString(LLSDofRAMap));
  799. byte[] buffer = OSDParser.SerializeLLSDXmlBytes(LLSDofRAMap);
  800. //string bufferDump = System.Text.Encoding.ASCII.GetString(buffer);
  801. //m_log.InfoFormat("[OGP]: buffer form is {0}",bufferDump);
  802. //m_log.InfoFormat("[OGP]: LLSD of map was {0}",buffer.Length);
  803. Stream os = null;
  804. try
  805. { // send the Post
  806. DeRezRequest.ContentLength = buffer.Length; //Count bytes to send
  807. os = DeRezRequest.GetRequestStream();
  808. os.Write(buffer, 0, buffer.Length); //Send it
  809. os.Close();
  810. m_log.InfoFormat("[OGP]: Derez Avatar Posted Rez Avatar request to remote sim {0}", CapAddress);
  811. }
  812. catch (WebException ex)
  813. {
  814. m_log.InfoFormat("[OGP] Bad send on de_rez_avatar {0}", ex.Message);
  815. responseMap["connect"] = OSD.FromBoolean(false);
  816. return responseMap;
  817. }
  818. m_log.Info("[OGP] waiting for a reply after rez avatar send");
  819. string rez_avatar_reply = null;
  820. { // get the response
  821. try
  822. {
  823. WebResponse webResponse = DeRezRequest.GetResponse();
  824. if (webResponse == null)
  825. {
  826. m_log.Info("[OGP:] Null reply on rez_avatar post");
  827. }
  828. StreamReader sr = new StreamReader(webResponse.GetResponseStream());
  829. rez_avatar_reply = sr.ReadToEnd().Trim();
  830. m_log.InfoFormat("[OGP]: rez_avatar reply was {0} ", rez_avatar_reply);
  831. }
  832. catch (WebException ex)
  833. {
  834. m_log.InfoFormat("[OGP]: exception on read after send of rez avatar {0}", ex.Message);
  835. responseMap["connect"] = OSD.FromBoolean(false);
  836. return responseMap;
  837. }
  838. OSD rezResponse = null;
  839. try
  840. {
  841. rezResponse = OSDParser.DeserializeLLSDXml(rez_avatar_reply);
  842. responseMap = (OSDMap)rezResponse;
  843. }
  844. catch (Exception ex)
  845. {
  846. m_log.InfoFormat("[OGP]: exception on parse of rez reply {0}", ex.Message);
  847. responseMap["connect"] = OSD.FromBoolean(false);
  848. return responseMap;
  849. }
  850. }
  851. return responseMap;
  852. }
  853. public OSD GenerateNoHandlerMessage()
  854. {
  855. OSDMap map = new OSDMap();
  856. map["reason"] = OSD.FromString("LLSDRequest");
  857. map["message"] = OSD.FromString("No handler registered for LLSD Requests");
  858. map["login"] = OSD.FromString("false");
  859. map["connect"] = OSD.FromString("false");
  860. return map;
  861. }
  862. public OSD GenerateNoStateMessage(UUID passedAvatar)
  863. {
  864. OSDMap map = new OSDMap();
  865. map["reason"] = OSD.FromString("derez failed");
  866. map["message"] = OSD.FromString("Unable to locate OGP state for avatar " + passedAvatar.ToString());
  867. map["login"] = OSD.FromString("false");
  868. map["connect"] = OSD.FromString("false");
  869. return map;
  870. }
  871. private bool TryGetAgentCircuitData(string path, out AgentCircuitData userdata)
  872. {
  873. userdata = null;
  874. lock (CapsLoginID)
  875. {
  876. if (CapsLoginID.ContainsKey(path))
  877. {
  878. userdata = CapsLoginID[path];
  879. DiscardUsedCap(path);
  880. return true;
  881. }
  882. }
  883. return false;
  884. }
  885. private void DiscardUsedCap(string path)
  886. {
  887. CapsLoginID.Remove(path);
  888. }
  889. private Scene GetRootScene()
  890. {
  891. Scene ReturnScene = null;
  892. lock (m_scene)
  893. {
  894. if (m_scene.Count > 0)
  895. {
  896. ReturnScene = m_scene[0];
  897. }
  898. }
  899. return ReturnScene;
  900. }
  901. private Scene GetScene(string scenename)
  902. {
  903. Scene ReturnScene = null;
  904. lock (m_scene)
  905. {
  906. foreach (Scene s in m_scene)
  907. {
  908. if (s.RegionInfo.RegionName.ToLower() == scenename)
  909. {
  910. ReturnScene = s;
  911. break;
  912. }
  913. }
  914. }
  915. return ReturnScene;
  916. }
  917. private ulong GetOSCompatibleRegionHandle(RegionInfo reg)
  918. {
  919. return Util.UIntsToLong(reg.RegionLocX, reg.RegionLocY);
  920. }
  921. private OGPState InitializeNewState()
  922. {
  923. OGPState returnState = new OGPState();
  924. returnState.first_name = "";
  925. returnState.last_name = "";
  926. returnState.agent_id = UUID.Zero;
  927. returnState.local_agent_id = UUID.Zero;
  928. returnState.region_id = UUID.Zero;
  929. returnState.circuit_code = 0;
  930. returnState.secure_session_id = UUID.Zero;
  931. returnState.session_id = UUID.Zero;
  932. returnState.agent_access = true;
  933. returnState.god_level = 0;
  934. returnState.god_overide = false;
  935. returnState.identified = false;
  936. returnState.transacted = false;
  937. returnState.age_verified = false;
  938. returnState.limited_to_estate = 1;
  939. returnState.inventory_host = "http://inv4.mysql.aditi.lindenlab.com";
  940. returnState.allow_redirect = true;
  941. returnState.sim_access = "";
  942. returnState.src_can_see_mainland = true;
  943. returnState.src_estate_id = 1;
  944. returnState.src_version = 1;
  945. returnState.src_parent_estate_id = 1;
  946. returnState.visible_to_parent = true;
  947. returnState.teleported_into_region = "";
  948. return returnState;
  949. }
  950. private OGPState GetOGPState(UUID agentId)
  951. {
  952. lock (m_OGPState)
  953. {
  954. if (m_OGPState.ContainsKey(agentId))
  955. {
  956. return m_OGPState[agentId];
  957. }
  958. else
  959. {
  960. return InitializeNewState();
  961. }
  962. }
  963. }
  964. public void DeleteOGPState(UUID agentId)
  965. {
  966. lock (m_OGPState)
  967. {
  968. if (m_OGPState.ContainsKey(agentId))
  969. m_OGPState.Remove(agentId);
  970. }
  971. }
  972. private void UpdateOGPState(UUID agentId, OGPState state)
  973. {
  974. lock (m_OGPState)
  975. {
  976. if (m_OGPState.ContainsKey(agentId))
  977. {
  978. m_OGPState[agentId] = state;
  979. }
  980. else
  981. {
  982. m_OGPState.Add(agentId,state);
  983. }
  984. }
  985. }
  986. private bool SceneListDuplicateCheck(string str)
  987. {
  988. // no lock, called from locked space!
  989. bool found = false;
  990. foreach (Scene s in m_scene)
  991. {
  992. if (s.RegionInfo.RegionName == str)
  993. {
  994. found = true;
  995. break;
  996. }
  997. }
  998. return found;
  999. }
  1000. public void ShutdownConnection(UUID avatarId, OpenGridProtocolModule mod)
  1001. {
  1002. Scene homeScene = GetRootScene();
  1003. ScenePresence avatar = null;
  1004. if (homeScene.TryGetAvatar(avatarId,out avatar))
  1005. {
  1006. KillAUser ku = new KillAUser(avatar,mod);
  1007. Thread ta = new Thread(ku.ShutdownNoLogout);
  1008. ta.IsBackground = true;
  1009. ta.Name = "ShutdownThread";
  1010. ta.Start();
  1011. }
  1012. }
  1013. private string CreateRandomStr(int len)
  1014. {
  1015. Random rnd = new Random(Environment.TickCount);
  1016. string returnstring = "";
  1017. string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  1018. for (int i = 0; i < len; i++)
  1019. {
  1020. returnstring += chars.Substring(rnd.Next(chars.Length), 1);
  1021. }
  1022. return returnstring;
  1023. }
  1024. // Temporary hack to allow teleporting to and from Vaak
  1025. private static bool customXertificateValidation(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
  1026. {
  1027. //if (cert.Subject == "[email protected], CN=*.vaak.lindenlab.com, O=\"Linden Lab, Inc.\", L=San Francisco, S=California, C=US")
  1028. //{
  1029. return true;
  1030. //}
  1031. //return false;
  1032. }
  1033. }
  1034. public class KillAUser
  1035. {
  1036. private ScenePresence avToBeKilled = null;
  1037. private OpenGridProtocolModule m_mod = null;
  1038. public KillAUser(ScenePresence avatar, OpenGridProtocolModule mod)
  1039. {
  1040. avToBeKilled = avatar;
  1041. m_mod = mod;
  1042. }
  1043. public void ShutdownNoLogout()
  1044. {
  1045. UUID avUUID = UUID.Zero;
  1046. if (avToBeKilled != null)
  1047. {
  1048. avUUID = avToBeKilled.UUID;
  1049. avToBeKilled.MakeChildAgent();
  1050. avToBeKilled.ControllingClient.SendLogoutPacketWhenClosing = false;
  1051. Thread.Sleep(30000);
  1052. // test for child agent because they might have come back
  1053. if (avToBeKilled.IsChildAgent)
  1054. {
  1055. m_mod.DeleteOGPState(avUUID);
  1056. avToBeKilled.ControllingClient.Close(true);
  1057. }
  1058. }
  1059. }
  1060. }
  1061. public class MonoCert : ICertificatePolicy
  1062. {
  1063. #region ICertificatePolicy Members
  1064. public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
  1065. {
  1066. return true;
  1067. }
  1068. #endregion
  1069. }
  1070. }