diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/General/RegionHandle.cs (renamed from OpenSim/Framework/General/Types/RegionHandle.cs) | 298 |
1 files changed, 149 insertions, 149 deletions
diff --git a/OpenSim/Framework/General/Types/RegionHandle.cs b/OpenSim/Framework/General/RegionHandle.cs index 5749296..d800e57 100644 --- a/OpenSim/Framework/General/Types/RegionHandle.cs +++ b/OpenSim/Framework/General/RegionHandle.cs | |||
@@ -1,149 +1,149 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Net; | 30 | using System.Net; |
31 | 31 | ||
32 | namespace OpenSim.Framework.Types | 32 | namespace OpenSim.Framework |
33 | { | 33 | { |
34 | /// <summary> | 34 | /// <summary> |
35 | /// A class for manipulating RegionHandle coordinates | 35 | /// A class for manipulating RegionHandle coordinates |
36 | /// </summary> | 36 | /// </summary> |
37 | class RegionHandle | 37 | class RegionHandle |
38 | { | 38 | { |
39 | private UInt64 handle; | 39 | private UInt64 handle; |
40 | 40 | ||
41 | /// <summary> | 41 | /// <summary> |
42 | /// Initialises a new grid-aware RegionHandle | 42 | /// Initialises a new grid-aware RegionHandle |
43 | /// </summary> | 43 | /// </summary> |
44 | /// <param name="ip">IP Address of the Grid Server for this region</param> | 44 | /// <param name="ip">IP Address of the Grid Server for this region</param> |
45 | /// <param name="x">Grid X Coordinate</param> | 45 | /// <param name="x">Grid X Coordinate</param> |
46 | /// <param name="y">Grid Y Coordinate</param> | 46 | /// <param name="y">Grid Y Coordinate</param> |
47 | public RegionHandle(string ip, short x, short y) | 47 | public RegionHandle(string ip, short x, short y) |
48 | { | 48 | { |
49 | IPAddress addr = IPAddress.Parse(ip); | 49 | IPAddress addr = IPAddress.Parse(ip); |
50 | 50 | ||
51 | if (addr.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork) | 51 | if (addr.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork) |
52 | throw new Exception("Bad RegionHandle Parameter - must be an IPv4 address"); | 52 | throw new Exception("Bad RegionHandle Parameter - must be an IPv4 address"); |
53 | 53 | ||
54 | uint baseHandle = BitConverter.ToUInt32(addr.GetAddressBytes(), 0); | 54 | uint baseHandle = BitConverter.ToUInt32(addr.GetAddressBytes(), 0); |
55 | 55 | ||
56 | // Split the IP address in half | 56 | // Split the IP address in half |
57 | short a = (short)((baseHandle << 16) & 0xFFFF); | 57 | short a = (short)((baseHandle << 16) & 0xFFFF); |
58 | short b = (short)((baseHandle << 0) & 0xFFFF); | 58 | short b = (short)((baseHandle << 0) & 0xFFFF); |
59 | 59 | ||
60 | // Raise the bounds a little | 60 | // Raise the bounds a little |
61 | uint nx = (uint)x; | 61 | uint nx = (uint)x; |
62 | uint ny = (uint)y; | 62 | uint ny = (uint)y; |
63 | 63 | ||
64 | // Multiply grid coords to get region coords | 64 | // Multiply grid coords to get region coords |
65 | nx *= 256; | 65 | nx *= 256; |
66 | ny *= 256; | 66 | ny *= 256; |
67 | 67 | ||
68 | // Stuff the IP address in too | 68 | // Stuff the IP address in too |
69 | nx = (uint)a << 16; | 69 | nx = (uint)a << 16; |
70 | ny = (uint)b << 16; | 70 | ny = (uint)b << 16; |
71 | 71 | ||
72 | handle = ((UInt64)nx << 32) | (uint)ny; | 72 | handle = ((UInt64)nx << 32) | (uint)ny; |
73 | } | 73 | } |
74 | 74 | ||
75 | /// <summary> | 75 | /// <summary> |
76 | /// Initialises a new RegionHandle that is not inter-grid aware | 76 | /// Initialises a new RegionHandle that is not inter-grid aware |
77 | /// </summary> | 77 | /// </summary> |
78 | /// <param name="x">Grid X Coordinate</param> | 78 | /// <param name="x">Grid X Coordinate</param> |
79 | /// <param name="y">Grid Y Coordinate</param> | 79 | /// <param name="y">Grid Y Coordinate</param> |
80 | public RegionHandle(uint x, uint y) | 80 | public RegionHandle(uint x, uint y) |
81 | { | 81 | { |
82 | handle = ((x * 256) << 32) | (y * 256); | 82 | handle = ((x * 256) << 32) | (y * 256); |
83 | } | 83 | } |
84 | 84 | ||
85 | /// <summary> | 85 | /// <summary> |
86 | /// Initialises a new RegionHandle from an existing value | 86 | /// Initialises a new RegionHandle from an existing value |
87 | /// </summary> | 87 | /// </summary> |
88 | /// <param name="Region">A U64 RegionHandle</param> | 88 | /// <param name="Region">A U64 RegionHandle</param> |
89 | public RegionHandle(UInt64 Region) | 89 | public RegionHandle(UInt64 Region) |
90 | { | 90 | { |
91 | handle = Region; | 91 | handle = Region; |
92 | } | 92 | } |
93 | 93 | ||
94 | /// <summary> | 94 | /// <summary> |
95 | /// Returns the Grid Masked RegionHandle - For use in Teleport packets and other packets where sending the grid IP address may be handy. | 95 | /// Returns the Grid Masked RegionHandle - For use in Teleport packets and other packets where sending the grid IP address may be handy. |
96 | /// </summary> | 96 | /// </summary> |
97 | /// <remarks>Do not use for SimulatorEnable packets. The client will choke.</remarks> | 97 | /// <remarks>Do not use for SimulatorEnable packets. The client will choke.</remarks> |
98 | /// <returns>Region Handle including IP Address encoding</returns> | 98 | /// <returns>Region Handle including IP Address encoding</returns> |
99 | public UInt64 getTeleportHandle() | 99 | public UInt64 getTeleportHandle() |
100 | { | 100 | { |
101 | return handle; | 101 | return handle; |
102 | } | 102 | } |
103 | 103 | ||
104 | /// <summary> | 104 | /// <summary> |
105 | /// Returns a RegionHandle which may be used for SimulatorEnable packets. Removes the IP address encoding and returns the lower bounds. | 105 | /// Returns a RegionHandle which may be used for SimulatorEnable packets. Removes the IP address encoding and returns the lower bounds. |
106 | /// </summary> | 106 | /// </summary> |
107 | /// <returns>A U64 RegionHandle for use in SimulatorEnable packets.</returns> | 107 | /// <returns>A U64 RegionHandle for use in SimulatorEnable packets.</returns> |
108 | public UInt64 getNeighbourHandle() | 108 | public UInt64 getNeighbourHandle() |
109 | { | 109 | { |
110 | UInt64 mask = 0x0000FFFF0000FFFF; | 110 | UInt64 mask = 0x0000FFFF0000FFFF; |
111 | 111 | ||
112 | return handle | mask; | 112 | return handle | mask; |
113 | } | 113 | } |
114 | 114 | ||
115 | /// <summary> | 115 | /// <summary> |
116 | /// Returns the IP Address of the GridServer from a Grid-Encoded RegionHandle | 116 | /// Returns the IP Address of the GridServer from a Grid-Encoded RegionHandle |
117 | /// </summary> | 117 | /// </summary> |
118 | /// <returns>Grid Server IP Address</returns> | 118 | /// <returns>Grid Server IP Address</returns> |
119 | public IPAddress getGridIP() | 119 | public IPAddress getGridIP() |
120 | { | 120 | { |
121 | uint a = (uint)((handle >> 16) & 0xFFFF); | 121 | uint a = (uint)((handle >> 16) & 0xFFFF); |
122 | uint b = (uint)((handle >> 48) & 0xFFFF); | 122 | uint b = (uint)((handle >> 48) & 0xFFFF); |
123 | 123 | ||
124 | return new IPAddress((long)(a << 16) | (long)b); | 124 | return new IPAddress((long)(a << 16) | (long)b); |
125 | } | 125 | } |
126 | 126 | ||
127 | /// <summary> | 127 | /// <summary> |
128 | /// Returns the X Coordinate from a Grid-Encoded RegionHandle | 128 | /// Returns the X Coordinate from a Grid-Encoded RegionHandle |
129 | /// </summary> | 129 | /// </summary> |
130 | /// <returns>X Coordinate</returns> | 130 | /// <returns>X Coordinate</returns> |
131 | public uint getGridX() | 131 | public uint getGridX() |
132 | { | 132 | { |
133 | uint x = (uint)((handle >> 32) & 0xFFFF); | 133 | uint x = (uint)((handle >> 32) & 0xFFFF); |
134 | 134 | ||
135 | return x; | 135 | return x; |
136 | } | 136 | } |
137 | 137 | ||
138 | /// <summary> | 138 | /// <summary> |
139 | /// Returns the Y Coordinate from a Grid-Encoded RegionHandle | 139 | /// Returns the Y Coordinate from a Grid-Encoded RegionHandle |
140 | /// </summary> | 140 | /// </summary> |
141 | /// <returns>Y Coordinate</returns> | 141 | /// <returns>Y Coordinate</returns> |
142 | public uint getGridY() | 142 | public uint getGridY() |
143 | { | 143 | { |
144 | uint y = (uint)((handle >> 0) & 0xFFFF); | 144 | uint y = (uint)((handle >> 0) & 0xFFFF); |
145 | 145 | ||
146 | return y; | 146 | return y; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | } | 149 | } |