aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/RegionHandle.cs
diff options
context:
space:
mode:
authorJeff Ames2007-10-31 01:21:04 +0000
committerJeff Ames2007-10-31 01:21:04 +0000
commit98b238cf6b75e9d26cf8f423decfbfd9df36b438 (patch)
tree553a190fec2f6e7492dd28129326929e3dbb3e15 /OpenSim/Framework/General/RegionHandle.cs
parentTevarus' patch for object flags & implemented Phantom edits (diff)
downloadopensim-SC_OLD-98b238cf6b75e9d26cf8f423decfbfd9df36b438.zip
opensim-SC_OLD-98b238cf6b75e9d26cf8f423decfbfd9df36b438.tar.gz
opensim-SC_OLD-98b238cf6b75e9d26cf8f423decfbfd9df36b438.tar.bz2
opensim-SC_OLD-98b238cf6b75e9d26cf8f423decfbfd9df36b438.tar.xz
set svn:eol-style
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/General/RegionHandle.cs298
1 files changed, 149 insertions, 149 deletions
diff --git a/OpenSim/Framework/General/RegionHandle.cs b/OpenSim/Framework/General/RegionHandle.cs
index 807a17c..440aaf6 100644
--- a/OpenSim/Framework/General/RegionHandle.cs
+++ b/OpenSim/Framework/General/RegionHandle.cs
@@ -1,150 +1,150 @@
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
29using System; 29using System;
30using System.Net; 30using System.Net;
31using System.Net.Sockets; 31using System.Net.Sockets;
32 32
33namespace OpenSim.Framework 33namespace OpenSim.Framework
34{ 34{
35 /// <summary> 35 /// <summary>
36 /// A class for manipulating RegionHandle coordinates 36 /// A class for manipulating RegionHandle coordinates
37 /// </summary> 37 /// </summary>
38 internal class RegionHandle 38 internal class RegionHandle
39 { 39 {
40 private UInt64 handle; 40 private UInt64 handle;
41 41
42 /// <summary> 42 /// <summary>
43 /// Initialises a new grid-aware RegionHandle 43 /// Initialises a new grid-aware RegionHandle
44 /// </summary> 44 /// </summary>
45 /// <param name="ip">IP Address of the Grid Server for this region</param> 45 /// <param name="ip">IP Address of the Grid Server for this region</param>
46 /// <param name="x">Grid X Coordinate</param> 46 /// <param name="x">Grid X Coordinate</param>
47 /// <param name="y">Grid Y Coordinate</param> 47 /// <param name="y">Grid Y Coordinate</param>
48 public RegionHandle(string ip, short x, short y) 48 public RegionHandle(string ip, short x, short y)
49 { 49 {
50 IPAddress addr = IPAddress.Parse(ip); 50 IPAddress addr = IPAddress.Parse(ip);
51 51
52 if (addr.AddressFamily != AddressFamily.InterNetwork) 52 if (addr.AddressFamily != AddressFamily.InterNetwork)
53 throw new Exception("Bad RegionHandle Parameter - must be an IPv4 address"); 53 throw new Exception("Bad RegionHandle Parameter - must be an IPv4 address");
54 54
55 uint baseHandle = BitConverter.ToUInt32(addr.GetAddressBytes(), 0); 55 uint baseHandle = BitConverter.ToUInt32(addr.GetAddressBytes(), 0);
56 56
57 // Split the IP address in half 57 // Split the IP address in half
58 short a = (short) ((baseHandle << 16) & 0xFFFF); 58 short a = (short) ((baseHandle << 16) & 0xFFFF);
59 short b = (short) ((baseHandle << 0) & 0xFFFF); 59 short b = (short) ((baseHandle << 0) & 0xFFFF);
60 60
61 // Raise the bounds a little 61 // Raise the bounds a little
62 uint nx = (uint) x; 62 uint nx = (uint) x;
63 uint ny = (uint) y; 63 uint ny = (uint) y;
64 64
65 // Multiply grid coords to get region coords 65 // Multiply grid coords to get region coords
66 nx *= 256; 66 nx *= 256;
67 ny *= 256; 67 ny *= 256;
68 68
69 // Stuff the IP address in too 69 // Stuff the IP address in too
70 nx = (uint) a << 16; 70 nx = (uint) a << 16;
71 ny = (uint) b << 16; 71 ny = (uint) b << 16;
72 72
73 handle = ((UInt64) nx << 32) | (uint) ny; 73 handle = ((UInt64) nx << 32) | (uint) ny;
74 } 74 }
75 75
76 /// <summary> 76 /// <summary>
77 /// Initialises a new RegionHandle that is not inter-grid aware 77 /// Initialises a new RegionHandle that is not inter-grid aware
78 /// </summary> 78 /// </summary>
79 /// <param name="x">Grid X Coordinate</param> 79 /// <param name="x">Grid X Coordinate</param>
80 /// <param name="y">Grid Y Coordinate</param> 80 /// <param name="y">Grid Y Coordinate</param>
81 public RegionHandle(uint x, uint y) 81 public RegionHandle(uint x, uint y)
82 { 82 {
83 handle = ((x*256) << 32) | (y*256); 83 handle = ((x*256) << 32) | (y*256);
84 } 84 }
85 85
86 /// <summary> 86 /// <summary>
87 /// Initialises a new RegionHandle from an existing value 87 /// Initialises a new RegionHandle from an existing value
88 /// </summary> 88 /// </summary>
89 /// <param name="Region">A U64 RegionHandle</param> 89 /// <param name="Region">A U64 RegionHandle</param>
90 public RegionHandle(UInt64 Region) 90 public RegionHandle(UInt64 Region)
91 { 91 {
92 handle = Region; 92 handle = Region;
93 } 93 }
94 94
95 /// <summary> 95 /// <summary>
96 /// Returns the Grid Masked RegionHandle - For use in Teleport packets and other packets where sending the grid IP address may be handy. 96 /// Returns the Grid Masked RegionHandle - For use in Teleport packets and other packets where sending the grid IP address may be handy.
97 /// </summary> 97 /// </summary>
98 /// <remarks>Do not use for SimulatorEnable packets. The client will choke.</remarks> 98 /// <remarks>Do not use for SimulatorEnable packets. The client will choke.</remarks>
99 /// <returns>Region Handle including IP Address encoding</returns> 99 /// <returns>Region Handle including IP Address encoding</returns>
100 public UInt64 getTeleportHandle() 100 public UInt64 getTeleportHandle()
101 { 101 {
102 return handle; 102 return handle;
103 } 103 }
104 104
105 /// <summary> 105 /// <summary>
106 /// Returns a RegionHandle which may be used for SimulatorEnable packets. Removes the IP address encoding and returns the lower bounds. 106 /// Returns a RegionHandle which may be used for SimulatorEnable packets. Removes the IP address encoding and returns the lower bounds.
107 /// </summary> 107 /// </summary>
108 /// <returns>A U64 RegionHandle for use in SimulatorEnable packets.</returns> 108 /// <returns>A U64 RegionHandle for use in SimulatorEnable packets.</returns>
109 public UInt64 getNeighbourHandle() 109 public UInt64 getNeighbourHandle()
110 { 110 {
111 UInt64 mask = 0x0000FFFF0000FFFF; 111 UInt64 mask = 0x0000FFFF0000FFFF;
112 112
113 return handle | mask; 113 return handle | mask;
114 } 114 }
115 115
116 /// <summary> 116 /// <summary>
117 /// Returns the IP Address of the GridServer from a Grid-Encoded RegionHandle 117 /// Returns the IP Address of the GridServer from a Grid-Encoded RegionHandle
118 /// </summary> 118 /// </summary>
119 /// <returns>Grid Server IP Address</returns> 119 /// <returns>Grid Server IP Address</returns>
120 public IPAddress getGridIP() 120 public IPAddress getGridIP()
121 { 121 {
122 uint a = (uint) ((handle >> 16) & 0xFFFF); 122 uint a = (uint) ((handle >> 16) & 0xFFFF);
123 uint b = (uint) ((handle >> 48) & 0xFFFF); 123 uint b = (uint) ((handle >> 48) & 0xFFFF);
124 124
125 return new IPAddress((long) (a << 16) | (long) b); 125 return new IPAddress((long) (a << 16) | (long) b);
126 } 126 }
127 127
128 /// <summary> 128 /// <summary>
129 /// Returns the X Coordinate from a Grid-Encoded RegionHandle 129 /// Returns the X Coordinate from a Grid-Encoded RegionHandle
130 /// </summary> 130 /// </summary>
131 /// <returns>X Coordinate</returns> 131 /// <returns>X Coordinate</returns>
132 public uint getGridX() 132 public uint getGridX()
133 { 133 {
134 uint x = (uint) ((handle >> 32) & 0xFFFF); 134 uint x = (uint) ((handle >> 32) & 0xFFFF);
135 135
136 return x; 136 return x;
137 } 137 }
138 138
139 /// <summary> 139 /// <summary>
140 /// Returns the Y Coordinate from a Grid-Encoded RegionHandle 140 /// Returns the Y Coordinate from a Grid-Encoded RegionHandle
141 /// </summary> 141 /// </summary>
142 /// <returns>Y Coordinate</returns> 142 /// <returns>Y Coordinate</returns>
143 public uint getGridY() 143 public uint getGridY()
144 { 144 {
145 uint y = (uint) ((handle >> 0) & 0xFFFF); 145 uint y = (uint) ((handle >> 0) & 0xFFFF);
146 146
147 return y; 147 return y;
148 } 148 }
149 } 149 }
150} \ No newline at end of file 150} \ No newline at end of file