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