diff --git a/LibreMetaverse/AgentManager.cs b/LibreMetaverse/AgentManager.cs index 81b9e251..e4298735 100644 --- a/LibreMetaverse/AgentManager.cs +++ b/LibreMetaverse/AgentManager.cs @@ -1302,12 +1302,15 @@ public event EventHandler MuteListUpdated /// A which specifies the angular speed, and axis about which an Avatar is rotating. public Vector3 AngularVelocity => angularVelocity; + /// Region handle for 'home' region + public ulong HomeRegionHandle => home.RegionHandle; + /// Position avatar client will goto when login to 'home' or during /// teleport request to 'home' region. - public Vector3 HomePosition => homePosition; + public Vector3 HomePosition => home.Position; /// LookAt point saved/restored with HomePosition - public Vector3 HomeLookAt => homeLookAt; + public Vector3 HomeLookAt => home.LookAt; /// Avatar First Name (i.e. Philip) public string FirstName => firstName; @@ -1472,8 +1475,7 @@ public Vector3d GlobalPosition private UUID secureSessionID; private string startLocation = string.Empty; private string agentAccess = string.Empty; - private Vector3 homePosition; - private Vector3 homeLookAt; + private HomeInfo home; private Vector3 lookAt; private string firstName = string.Empty; private string lastName = string.Empty; @@ -4501,8 +4503,7 @@ private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string me startLocation = reply.StartLocation; agentAccess = reply.AgentAccess; Movement.Camera.LookDirection(reply.LookAt); - homePosition = reply.HomePosition; - homeLookAt = reply.HomeLookAt; + home = reply.Home; lookAt = reply.LookAt; if (reply.Gestures != null) diff --git a/LibreMetaverse/Login.cs b/LibreMetaverse/Login.cs index b57aa1d9..932d5f9d 100644 --- a/LibreMetaverse/Login.cs +++ b/LibreMetaverse/Login.cs @@ -262,6 +262,13 @@ public struct BuddyListEntry public int BuddyRightsHas; } + public struct HomeInfo + { + public ulong RegionHandle; + public Vector3 Position; + public Vector3 LookAt; + } + /// /// The decoded data returned from the login server after a successful login /// @@ -287,9 +294,7 @@ public struct LoginResponseData public string AgentRegionAccess; public string InitialOutfit; public Vector3 LookAt; - public ulong HomeRegion; - public Vector3 HomePosition; - public Vector3 HomeLookAt; + public HomeInfo Home; public int CircuitCode; public uint RegionX; public uint RegionY; @@ -375,19 +380,19 @@ public void Parse(OSDMap reply) if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) { var homeArray = (OSDArray)homeRegion; - HomeRegion = homeArray.Count == 2 + Home.RegionHandle = homeArray.Count == 2 ? Utils.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()) : 0; } - HomePosition = ParseVector3("position", home); - HomeLookAt = ParseVector3("look_at", home); + Home.Position = ParseVector3("position", home); + Home.LookAt = ParseVector3("look_at", home); } else { - HomeRegion = 0; - HomePosition = Vector3.Zero; - HomeLookAt = Vector3.Zero; + Home.RegionHandle = 0; + Home.Position = Vector3.Zero; + Home.LookAt = Vector3.Zero; } CircuitCode = (int)ParseUInt("circuit_code", reply); @@ -468,55 +473,50 @@ public void Parse(Hashtable reply) } if (!Success) { return; } - // Home - if (reply.ContainsKey("home")) + // HomeInfo + try { - try + if (reply.ContainsKey("home_info")) { - if (reply?["home"] is Hashtable map) + if (reply?["home_info"] is Hashtable map) { - HomePosition = ParseVector3("position", map); - HomeLookAt = ParseVector3("look_at", map); + Home.Position = ParseVector3("position", map); + Home.LookAt = ParseVector3("look_at", map); var coords = (OSDArray)OSDParser.DeserializeLLSDNotation(map["region_handle"].ToString()); if (coords.Type == OSDType.Array) { - HomeRegion = (coords.Count == 2) + Home.RegionHandle = (coords.Count == 2) ? Utils.UIntsToLong((uint)coords[0].AsInteger(), (uint)coords[1].AsInteger()) : 0; } } - else if (reply?["home"] is string osdString) + } + + // Home + if (Home.RegionHandle == 0 && reply.ContainsKey("home")) + { + var osdHome = OSDParser.DeserializeLLSDNotation(reply["home"].ToString()); + + if (osdHome.Type == OSDType.Map) { - var osdMap = (OSDMap)OSDParser.DeserializeLLSDNotation(osdString); + var home = (OSDMap)osdHome; + OSD homeRegion; - if (osdMap.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) + if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == OSDType.Array) { - var homeArray = (OSDArray)homeRegion; - HomeRegion = (homeArray.Count == 2) - ? Utils.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()) : 0; - } + var coords = (OSDArray)homeRegion; + Home.RegionHandle = (coords.Count == 2) + ? Utils.UIntsToLong((uint)coords[0].AsInteger(), (uint)coords[1].AsInteger()) : 0; - HomePosition = ParseVector3("position", osdMap); - HomeLookAt = ParseVector3("look_at", osdMap); - } - else - { - throw new Exception("Could not parse 'home' in Login Response"); + } + Home.Position = ParseVector3("position", home); + Home.LookAt = ParseVector3("look_at", home); } - } - catch (Exception ex) - { - Logger.Log("Could not parse 'home' field in login response. Setting nil.", Helpers.LogLevel.Warning, ex); - HomeRegion = 0; - HomePosition = Vector3.Zero; - HomeLookAt = Vector3.Zero; } - } - else + } catch (Exception ex) { - HomeRegion = 0; - HomePosition = Vector3.Zero; - HomeLookAt = Vector3.Zero; + Logger.Log("Could not parse home info from login response. Setting nil", Helpers.LogLevel.Warning, ex); + Home = new HomeInfo(); } CircuitCode = (int)ParseUInt("circuit_code", reply);