aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenSim.Framework/Types/RegionHandle.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common/OpenSim.Framework/Types/RegionHandle.cs')
-rw-r--r--Common/OpenSim.Framework/Types/RegionHandle.cs120
1 files changed, 120 insertions, 0 deletions
diff --git a/Common/OpenSim.Framework/Types/RegionHandle.cs b/Common/OpenSim.Framework/Types/RegionHandle.cs
new file mode 100644
index 0000000..1271d04
--- /dev/null
+++ b/Common/OpenSim.Framework/Types/RegionHandle.cs
@@ -0,0 +1,120 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Net;
5
6namespace OpenSim.Framework.Types
7{
8 /// <summary>
9 /// A class for manipulating RegionHandle coordinates
10 /// </summary>
11 class RegionHandle
12 {
13 private UInt64 handle;
14
15 /// <summary>
16 /// Initialises a new grid-aware RegionHandle
17 /// </summary>
18 /// <param name="ip">IP Address of the Grid Server for this region</param>
19 /// <param name="x">Grid X Coordinate</param>
20 /// <param name="y">Grid Y Coordinate</param>
21 public RegionHandle(string ip, short x, short y)
22 {
23 IPAddress addr = IPAddress.Parse(ip);
24
25 long baseHandle = addr.Address;
26
27 // Split the IP address in half
28 short a = (short)((baseHandle << 16) & 0xFFFF);
29 short b = (short)((baseHandle << 0) & 0xFFFF);
30
31 // Raise the bounds a little
32 uint nx = (uint)x;
33 uint ny = (uint)y;
34
35 // Multiply grid coords to get region coords
36 nx *= 256;
37 ny *= 256;
38
39 // Stuff the IP address in too
40 nx = (uint)a << 16;
41 ny = (uint)b << 16;
42
43 handle = ((UInt64)nx << 32) | (uint)ny;
44 }
45
46 /// <summary>
47 /// Initialises a new RegionHandle that is not inter-grid aware
48 /// </summary>
49 /// <param name="x">Grid X Coordinate</param>
50 /// <param name="y">Grid Y Coordinate</param>
51 public RegionHandle(uint x, uint y)
52 {
53 handle = ((x * 256) << 32) | (y * 256);
54 }
55
56 /// <summary>
57 /// Initialises a new RegionHandle from an existing value
58 /// </summary>
59 /// <param name="Region">A U64 RegionHandle</param>
60 public RegionHandle(UInt64 Region)
61 {
62 handle = Region;
63 }
64
65 /// <summary>
66 /// Returns the Grid Masked RegionHandle - For use in Teleport packets and other packets where sending the grid IP address may be handy.
67 /// </summary>
68 /// <remarks>Do not use for SimulatorEnable packets. The client will choke.</remarks>
69 /// <returns>Region Handle including IP Address encoding</returns>
70 public UInt64 getTeleportHandle()
71 {
72 return handle;
73 }
74
75 /// <summary>
76 /// Returns a RegionHandle which may be used for SimulatorEnable packets. Removes the IP address encoding and returns the lower bounds.
77 /// </summary>
78 /// <returns>A U64 RegionHandle for use in SimulatorEnable packets.</returns>
79 public UInt64 getNeighbourHandle()
80 {
81 UInt64 mask = 0x0000FFFF0000FFFF;
82
83 return handle | mask;
84 }
85
86 /// <summary>
87 /// Returns the IP Address of the GridServer from a Grid-Encoded RegionHandle
88 /// </summary>
89 /// <returns>Grid Server IP Address</returns>
90 public IPAddress getGridIP()
91 {
92 uint a = (uint)((handle >> 16) & 0xFFFF);
93 uint b = (uint)((handle >> 48) & 0xFFFF);
94
95 return new IPAddress((long)(a << 16) | (long)b);
96 }
97
98 /// <summary>
99 /// Returns the X Coordinate from a Grid-Encoded RegionHandle
100 /// </summary>
101 /// <returns>X Coordinate</returns>
102 public uint getGridX()
103 {
104 uint x = (uint)((handle >> 32) & 0xFFFF);
105
106 return x;
107 }
108
109 /// <summary>
110 /// Returns the Y Coordinate from a Grid-Encoded RegionHandle
111 /// </summary>
112 /// <returns>Y Coordinate</returns>
113 public uint getGridY()
114 {
115 uint y = (uint)((handle >> 0) & 0xFFFF);
116
117 return y;
118 }
119 }
120}