* Added experimental RegionHandle class to Framework.Types - see email posted to mailing list for technical details. Not actually enabled anywhere and could be helpful for ordinary RegionHandles as well.

Sugilite
Adam Frisby 2007-06-14 08:32:59 +00:00
parent 93eaddd583
commit 62c6c9fe8b
2 changed files with 143 additions and 15 deletions

View File

@ -1,4 +1,4 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion>
@ -6,7 +6,8 @@
<ProjectGuid>{8ACA2445-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon></ApplicationIcon>
<ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>OpenSim.Framework</AssemblyName>
@ -15,9 +16,11 @@
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<AppDesignerFolder></AppDesignerFolder>
<AppDesignerFolder>
</AppDesignerFolder>
<RootNamespace>OpenSim.Framework</RootNamespace>
<StartupObject></StartupObject>
<StartupObject>
</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
</PropertyGroup>
@ -28,7 +31,8 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DocumentationFile></DocumentationFile>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
@ -37,7 +41,8 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn></NoWarn>
<NoWarn>
</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -46,7 +51,8 @@
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
@ -55,22 +61,23 @@
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn></NoWarn>
<NoWarn>
</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" >
<Reference Include="System">
<HintPath>System.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml" >
<Reference Include="System.Xml">
<HintPath>System.Xml.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="libsecondlife.dll" >
<Reference Include="libsecondlife.dll">
<HintPath>..\..\bin\libsecondlife.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Db4objects.Db4o.dll" >
<Reference Include="Db4objects.Db4o.dll">
<HintPath>..\..\bin\Db4objects.Db4o.dll</HintPath>
<Private>False</Private>
</Reference>
@ -80,13 +87,13 @@
<Name>XMLRPC</Name>
<Project>{8E81D43C-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\OpenSim.Framework.Console\OpenSim.Framework.Console.csproj">
<Name>OpenSim.Framework.Console</Name>
<Project>{A7CD0630-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
@ -114,6 +121,7 @@
<Compile Include="SimProfile.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Types\RegionHandle.cs" />
<Compile Include="UserProfile.cs">
<SubType>Code</SubType>
</Compile>

View File

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
namespace OpenSim.Framework.Types
{
/// <summary>
/// A class for manipulating RegionHandle coordinates
/// </summary>
class RegionHandle
{
private UInt64 handle;
/// <summary>
/// Initialises a new grid-aware RegionHandle
/// </summary>
/// <param name="ip">IP Address of the Grid Server for this region</param>
/// <param name="x">Grid X Coordinate</param>
/// <param name="y">Grid Y Coordinate</param>
public RegionHandle(string ip, short x, short y)
{
IPAddress addr = IPAddress.Parse(ip);
long baseHandle = addr.Address;
// Split the IP address in half
short a = (short)((baseHandle << 16) & 0xFFFF);
short b = (short)((baseHandle << 0) & 0xFFFF);
// Raise the bounds a little
uint nx = (uint)x;
uint ny = (uint)y;
// Multiply grid coords to get region coords
nx *= 256;
ny *= 256;
// Stuff the IP address in too
nx = (uint)a << 16;
ny = (uint)b << 16;
handle = ((UInt64)nx << 32) | (uint)ny;
}
/// <summary>
/// Initialises a new RegionHandle that is not inter-grid aware
/// </summary>
/// <param name="x">Grid X Coordinate</param>
/// <param name="y">Grid Y Coordinate</param>
public RegionHandle(uint x, uint y)
{
handle = ((x * 256) << 32) | (y * 256);
}
/// <summary>
/// Initialises a new RegionHandle from an existing value
/// </summary>
/// <param name="Region">A U64 RegionHandle</param>
public RegionHandle(UInt64 Region)
{
handle = Region;
}
/// <summary>
/// Returns the Grid Masked RegionHandle - For use in Teleport packets and other packets where sending the grid IP address may be handy.
/// </summary>
/// <remarks>Do not use for SimulatorEnable packets. The client will choke.</remarks>
/// <returns>Region Handle including IP Address encoding</returns>
public UInt64 getTeleportHandle()
{
return handle;
}
/// <summary>
/// Returns a RegionHandle which may be used for SimulatorEnable packets. Removes the IP address encoding and returns the lower bounds.
/// </summary>
/// <returns>A U64 RegionHandle for use in SimulatorEnable packets.</returns>
public UInt64 getNeighbourHandle()
{
UInt64 mask = 0x0000FFFF0000FFFF;
return handle | mask;
}
/// <summary>
/// Returns the IP Address of the GridServer from a Grid-Encoded RegionHandle
/// </summary>
/// <returns>Grid Server IP Address</returns>
public IPAddress getGridIP()
{
uint a = (uint)((handle >> 16) & 0xFFFF);
uint b = (uint)((handle >> 48) & 0xFFFF);
return new IPAddress((long)(a << 16) | (long)b);
}
/// <summary>
/// Returns the X Coordinate from a Grid-Encoded RegionHandle
/// </summary>
/// <returns>X Coordinate</returns>
public uint getGridX()
{
uint x = (uint)((handle >> 32) & 0xFFFF);
return x;
}
/// <summary>
/// Returns the Y Coordinate from a Grid-Encoded RegionHandle
/// </summary>
/// <returns>Y Coordinate</returns>
public uint getGridY()
{
uint y = (uint)((handle >> 0) & 0xFFFF);
return y;
}
}
}