diff --git a/LibreMetaverse/AgentManager.cs b/LibreMetaverse/AgentManager.cs index 0d9e880d..27e65553 100644 --- a/LibreMetaverse/AgentManager.cs +++ b/LibreMetaverse/AgentManager.cs @@ -4317,7 +4317,9 @@ namespace OpenMetaverse SimAccess = (byte) msg.SimAccess, SimIP = Utils.IPToUInt(msg.IP), SimPort = (ushort) msg.Port, - TeleportFlags = (uint) msg.Flags + TeleportFlags = (uint) msg.Flags, + RegionSizeX = msg.RegionSizeX, + RegionSizeY = msg.RegionSizeY } }; // FIXME: Check This @@ -4380,7 +4382,8 @@ namespace OpenMetaverse // Connect to the new sim Client.Network.CurrentSim.AgentMovementComplete = false; // we're not there anymore Simulator newSimulator = Client.Network.Connect(new IPAddress(finish.Info.SimIP), - finish.Info.SimPort, finish.Info.RegionHandle, true, seedcaps); + finish.Info.SimPort, finish.Info.RegionHandle, true, seedcaps, + finish.Info.RegionSizeX, finish.Info.RegionSizeY); if (newSimulator != null) { @@ -4556,7 +4559,8 @@ namespace OpenMetaverse Logger.DebugLog($"Crossed in to new region area, attempting to connect to {endPoint}", Client); Simulator oldSim = Client.Network.CurrentSim; - Simulator newSim = Client.Network.Connect(endPoint, crossed.RegionHandle, true, crossed.SeedCapability); + Simulator newSim = Client.Network.Connect(endPoint, crossed.RegionHandle, true, crossed.SeedCapability, + crossed.RegionSizeX, crossed.RegionSizeY); if (newSim != null) { diff --git a/LibreMetaverse/Login.cs b/LibreMetaverse/Login.cs index de2d5936..bc1abddb 100644 --- a/LibreMetaverse/Login.cs +++ b/LibreMetaverse/Login.cs @@ -369,6 +369,8 @@ namespace OpenMetaverse public int CircuitCode; public uint RegionX; public uint RegionY; + public uint RegionSizeX; + public uint RegionSizeY; public ushort SimPort; public IPAddress SimIP; public string SeedCapability; @@ -488,6 +490,9 @@ namespace OpenMetaverse CircuitCode = (int)ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); + // Region size is returned by OpenSimulator derived systems but not SL + RegionSizeX = reply.ContainsKey("region_size_x") ? ParseUInt("region_size_x", reply) : Simulator.DefaultRegionSizeX; + RegionSizeY = reply.ContainsKey("region_size_y") ? ParseUInt("region_size_y", reply) : Simulator.DefaultRegionSizeY; SimPort = (ushort)ParseUInt("sim_port", reply); var simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); @@ -693,6 +698,9 @@ namespace OpenMetaverse CircuitCode = (int)ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); + // Region size is returned by OpenSimulator derived systems but not SL + RegionSizeX = reply.ContainsKey("region_size_x") ? ParseUInt("region_size_x", reply) : Simulator.DefaultRegionSizeX; + RegionSizeY = reply.ContainsKey("region_size_y") ? ParseUInt("region_size_y", reply) : Simulator.DefaultRegionSizeY; SimPort = (ushort)ParseUInt("sim_port", reply); var simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); @@ -1691,7 +1699,7 @@ namespace OpenMetaverse var handle = Utils.UIntsToLong(regionX, regionY); // Connect to the sim given in the login reply - if (Connect(reply.SimIP, simPort, handle, true, LoginSeedCapability) != null) + if (Connect(reply.SimIP, simPort, handle, true, LoginSeedCapability, reply.RegionSizeX, reply.RegionSizeY) != null) { // Request the economy data right after login SendPacket(new EconomyDataRequestPacket()); diff --git a/LibreMetaverse/Messages/LindenMessages.cs b/LibreMetaverse/Messages/LindenMessages.cs index 26ce20e9..ddd8aabe 100644 --- a/LibreMetaverse/Messages/LindenMessages.cs +++ b/LibreMetaverse/Messages/LindenMessages.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2006-2016, openmetaverse.co * Copyright (c) 2021-2022, Sjofn LLC * All rights reserved. @@ -61,6 +61,10 @@ namespace OpenMetaverse.Messages.Linden /// Status flags indicating the state of the Agent upon arrival, Flying, etc. public TeleportFlags Flags; + /// The size of the region teleporting into + public uint RegionSizeX; + public uint RegionSizeY; + /// /// Serialize the object /// @@ -80,7 +84,9 @@ namespace OpenMetaverse.Messages.Linden {"SimAccess", OSD.FromInteger((byte) SimAccess)}, {"SimIP", MessageUtils.FromIP(IP)}, {"SimPort", OSD.FromInteger(Port)}, - {"TeleportFlags", OSD.FromUInteger((uint) Flags)} + {"TeleportFlags", OSD.FromUInteger((uint) Flags)}, + {"RegionSizeX", OSD.FromUInteger((uint) RegionSizeX)}, + {"RegionSizeY", OSD.FromUInteger((uint) RegionSizeY)} }; // Unused by the client @@ -108,6 +114,8 @@ namespace OpenMetaverse.Messages.Linden IP = MessageUtils.ToIP(blockMap["SimIP"]); Port = blockMap["SimPort"].AsInteger(); Flags = (TeleportFlags)blockMap["TeleportFlags"].AsUInteger(); + RegionSizeX = blockMap.ContainsKey("RegionSizeX") ? blockMap["RegionSizeX"].AsUInteger() : Simulator.DefaultRegionSizeX; + RegionSizeY = blockMap.ContainsKey("RegionSizeY") ? blockMap["RegionSizeY"].AsUInteger() : Simulator.DefaultRegionSizeY; } } @@ -162,6 +170,8 @@ namespace OpenMetaverse.Messages.Linden public Uri SeedCapability; public IPAddress IP; public int Port; + public uint RegionSizeX; + public uint RegionSizeY; /// /// Serialize the object @@ -195,7 +205,9 @@ namespace OpenMetaverse.Messages.Linden ["RegionHandle"] = OSD.FromULong(RegionHandle), ["SeedCapability"] = OSD.FromUri(SeedCapability), ["SimIP"] = MessageUtils.FromIP(IP), - ["SimPort"] = OSD.FromInteger(Port) + ["SimPort"] = OSD.FromInteger(Port), + ["RegionSizeX"] = OSD.FromUInteger(RegionSizeX), + ["RegionSizeY"] = OSD.FromUInteger(RegionSizeY) }; regionDataArray.Add(regionDataMap); map["RegionData"] = regionDataArray; @@ -222,6 +234,8 @@ namespace OpenMetaverse.Messages.Linden SeedCapability = regionDataMap["SeedCapability"].AsUri(); IP = MessageUtils.ToIP(regionDataMap["SimIP"]); Port = regionDataMap["SimPort"].AsInteger(); + RegionSizeX = regionDataMap.ContainsKey("RegionSizeX") ? regionDataMap["RegionSizeX"].AsUInteger() : Simulator.DefaultRegionSizeX; + RegionSizeY = regionDataMap.ContainsKey("RegionSizeY") ? regionDataMap["RegionSizeY"].AsUInteger() : Simulator.DefaultRegionSizeY; } } @@ -232,6 +246,8 @@ namespace OpenMetaverse.Messages.Linden public ulong RegionHandle; public IPAddress IP; public int Port; + public uint RegionSizeX; + public uint RegionSizeY; } public SimulatorInfoBlock[] Simulators; @@ -251,7 +267,9 @@ namespace OpenMetaverse.Messages.Linden { ["Handle"] = OSD.FromULong(block.RegionHandle), ["IP"] = MessageUtils.FromIP(block.IP), - ["Port"] = OSD.FromInteger(block.Port) + ["Port"] = OSD.FromInteger(block.Port), + ["RegionSizeX"] = OSD.FromUInteger(block.RegionSizeX), + ["RegionSizeY"] = OSD.FromUInteger(block.RegionSizeY), }; array.Add(blockMap); } @@ -277,7 +295,9 @@ namespace OpenMetaverse.Messages.Linden { RegionHandle = blockMap["Handle"].AsULong(), IP = MessageUtils.ToIP(blockMap["IP"]), - Port = blockMap["Port"].AsInteger() + Port = blockMap["Port"].AsInteger(), + RegionSizeX = blockMap.ContainsKey("RegionSizeX") ? blockMap["RegionSizeX"].AsUInteger() : Simulator.DefaultRegionSizeX, + RegionSizeY = blockMap.ContainsKey("RegionSizeY") ? blockMap["RegionSizeY"].AsUInteger() : Simulator.DefaultRegionSizeY, }; Simulators[i] = block; } diff --git a/LibreMetaverse/NetworkManager.cs b/LibreMetaverse/NetworkManager.cs index 038364bf..8878c8fc 100644 --- a/LibreMetaverse/NetworkManager.cs +++ b/LibreMetaverse/NetworkManager.cs @@ -538,10 +538,11 @@ namespace OpenMetaverse /// URL of the capabilities server to use for /// this sim connection /// A Simulator object on success, otherwise null - public Simulator Connect(IPAddress ip, ushort port, ulong handle, bool setDefault, Uri seedcaps) + public Simulator Connect(IPAddress ip, ushort port, ulong handle, bool setDefault, Uri seedcaps, + uint sizeX = Simulator.DefaultRegionSizeX, uint sizeY = Simulator.DefaultRegionSizeY) { IPEndPoint endPoint = new IPEndPoint(ip, port); - return Connect(endPoint, handle, setDefault, seedcaps); + return Connect(endPoint, handle, setDefault, seedcaps, sizeX, sizeY); } /// @@ -555,14 +556,15 @@ namespace OpenMetaverse /// URL of the capabilities server to use for /// this sim connection /// A Simulator object on success, otherwise null - public Simulator Connect(IPEndPoint endPoint, ulong handle, bool setDefault, Uri seedcaps) + public Simulator Connect(IPEndPoint endPoint, ulong handle, bool setDefault, Uri seedcaps, + uint sizeX = Simulator.DefaultRegionSizeX, uint sizeY = Simulator.DefaultRegionSizeY) { Simulator simulator = FindSimulator(endPoint); if (simulator == null) { // We're not tracking this sim, create a new Simulator object - simulator = new Simulator(Client, endPoint, handle); + simulator = new Simulator(Client, endPoint, handle, sizeX, sizeY); // Immediately add this simulator to the list of current sims. It will be removed if the // connection fails @@ -1287,11 +1289,11 @@ namespace OpenMetaverse IPEndPoint endPoint = new IPEndPoint(ip, port); if (FindSimulator(endPoint) != null) return; - - if (Connect(ip, port, handle, false, null) == null) - { - Logger.Log($"Unable to connect to new sim {ip}:{port}", - Helpers.LogLevel.Error, Client); + + if (Connect(ip, port, handle, false, null, t.RegionSizeX, t.RegionSizeY) == null) + { + Logger.Log($"Unable to connect to new sim {ip}:{port}", + Helpers.LogLevel.Error, Client); } } } diff --git a/LibreMetaverse/Simulator.cs b/LibreMetaverse/Simulator.cs index 61da9c8e..79438ca0 100644 --- a/LibreMetaverse/Simulator.cs +++ b/LibreMetaverse/Simulator.cs @@ -252,6 +252,11 @@ namespace OpenMetaverse #endregion Structs #region Public Members + + // Default legacy simulator/region size + public const uint DefaultRegionSizeX = 256; + public const uint DefaultRegionSizeY = 256; + /// A public reference to the client that this Simulator object is attached to public GridClient Client; /// A Unique Cache identifier for this simulator @@ -260,6 +265,10 @@ namespace OpenMetaverse public Caps Caps; /// Unique identified for this region generated via it's coordinates on the world map public ulong Handle; + /// Simulator land size in X direction in meters + public uint SizeX; + /// Simulator land size in Y direction in meters + public uint SizeY; /// The current version of software this simulator is running public string SimVersion = String.Empty; /// Human readable name given to the simulator @@ -517,7 +526,7 @@ namespace OpenMetaverse /// Reference to the object /// IPEndPoint of the simulator /// Region handle for the simulator - public Simulator(GridClient client, IPEndPoint address, ulong handle) + public Simulator(GridClient client, IPEndPoint address, ulong handle, uint sizeX = DefaultRegionSizeX, uint sizeY = DefaultRegionSizeY) : base(address) { Client = client; @@ -529,6 +538,8 @@ namespace OpenMetaverse Handle = handle; Network = Client.Network; + SizeX = sizeX; + SizeY = sizeY; PacketArchive = new IncomingPacketIDCollection(Settings.PACKET_ARCHIVE_SIZE); InBytes = new Queue(Client.Settings.STATS_QUEUE_SIZE); OutBytes = new Queue(Client.Settings.STATS_QUEUE_SIZE); @@ -791,7 +802,7 @@ namespace OpenMetaverse /// True if the lookup was successful, otherwise false public bool TerrainHeightAtPoint(int x, int y, out float height) { - if (Terrain != null && x >= 0 && x < 256 && y >= 0 && y < 256) + if (Terrain != null && x >= 0 && x < SizeX && y >= 0 && y < SizeY) { int patchX = x / 16; int patchY = y / 16; diff --git a/LibreMetaverse/_Packets_.cs b/LibreMetaverse/_Packets_.cs index 096c5f37..4c90716d 100644 --- a/LibreMetaverse/_Packets_.cs +++ b/LibreMetaverse/_Packets_.cs @@ -10023,6 +10023,9 @@ namespace OpenMetaverse.Packets public byte[] SeedCapability; public byte SimAccess; public uint TeleportFlags; + // Sim/region size information sent in TeleportFinishMesssage + public uint RegionSizeX = Simulator.DefaultRegionSizeX; + public uint RegionSizeY = Simulator.DefaultRegionSizeY; public override int Length { @@ -10075,6 +10078,7 @@ namespace OpenMetaverse.Packets Buffer.BlockCopy(SeedCapability, 0, bytes, i, SeedCapability.Length); i += SeedCapability.Length; bytes[i++] = SimAccess; Utils.UIntToBytes(TeleportFlags, bytes, i); i += 4; + // size information is not sent in the UDP packet } } diff --git a/Programs/examples/TestClient/Commands/Stats/RegionInfoCommand.cs b/Programs/examples/TestClient/Commands/Stats/RegionInfoCommand.cs index 23ba205c..690d96d3 100644 --- a/Programs/examples/TestClient/Commands/Stats/RegionInfoCommand.cs +++ b/Programs/examples/TestClient/Commands/Stats/RegionInfoCommand.cs @@ -19,9 +19,13 @@ namespace OpenMetaverse.TestClient output.AppendLine(Client.Network.CurrentSim.ToString()); output.Append("UUID: "); output.AppendLine(Client.Network.CurrentSim.ID.ToString()); + uint x, y; Utils.LongToUInts(Client.Network.CurrentSim.Handle, out x, out y); output.AppendLine($"Handle: {Client.Network.CurrentSim.Handle} (X: {x} Y: {y})"); + + output.AppendLine($"Size: X: {Client.Network.CurrentSim.SizeX}, Y: {Client.Network.CurrentSim.SizeY}"); + output.Append("Access: "); output.AppendLine(Client.Network.CurrentSim.Access.ToString()); output.Append("Flags: ");