OpenGridProtocolModule.cs 53 KB

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