OpenGridProtocolModule.cs 53 KB

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