Skip to content

Commit

Permalink
Linden Lab is rolling back the change... Add support for the next fun…
Browse files Browse the repository at this point in the history
… API change.

While we're at it, change our own by introducing HomeInfo struct
  • Loading branch information
cinderblocks committed Dec 6, 2021
1 parent 3f4d7bd commit bd3705f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
13 changes: 7 additions & 6 deletions LibreMetaverse/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,12 +1302,15 @@ protected virtual void OnMuteListUpdated(EventArgs e)
/// <summary>A <seealso cref="Vector3"/> which specifies the angular speed, and axis about which an Avatar is rotating.</summary>
public Vector3 AngularVelocity => angularVelocity;

/// <summary>Region handle for 'home' region</summary>
public ulong HomeRegionHandle => home.RegionHandle;

/// <summary>Position avatar client will goto when login to 'home' or during
/// teleport request to 'home' region.</summary>
public Vector3 HomePosition => homePosition;
public Vector3 HomePosition => home.Position;

/// <summary>LookAt point saved/restored with HomePosition</summary>
public Vector3 HomeLookAt => homeLookAt;
public Vector3 HomeLookAt => home.LookAt;

/// <summary>Avatar First Name (i.e. Philip)</summary>
public string FirstName => firstName;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4501,8 +4503,7 @@ protected void MeanCollisionAlertHandler(object sender, PacketReceivedEventArgs
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)
Expand Down
82 changes: 41 additions & 41 deletions LibreMetaverse/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ public struct BuddyListEntry
public int BuddyRightsHas;
}

public struct HomeInfo
{
public ulong RegionHandle;
public Vector3 Position;
public Vector3 LookAt;
}

/// <summary>
/// The decoded data returned from the login server after a successful login
/// </summary>
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bd3705f

Please sign in to comment.