SerializableRegionInfo.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  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
  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
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Net;
  29. using System.Net.Sockets;
  30. using libsecondlife;
  31. namespace OpenSim.Framework
  32. {
  33. [Serializable]
  34. public class SearializableRegionInfo
  35. {
  36. /// <summary>
  37. /// This is a serializable version of RegionInfo
  38. /// </summary>
  39. public SearializableRegionInfo()
  40. {
  41. }
  42. public SearializableRegionInfo(RegionInfo ConvertFrom)
  43. {
  44. m_regionLocX = ConvertFrom.RegionLocX;
  45. m_regionLocY = ConvertFrom.RegionLocY;
  46. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  47. m_externalHostName = ConvertFrom.ExternalHostName;
  48. m_remotingPort = ConvertFrom.RemotingPort;
  49. m_httpPort = ConvertFrom.HttpPort;
  50. m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
  51. RemotingAddress = ConvertFrom.RemotingAddress;
  52. m_proxyUrl = ConvertFrom.proxyUrl;
  53. OriginRegionID = ConvertFrom.originRegionID;
  54. RegionName = ConvertFrom.RegionName;
  55. ServerURI = ConvertFrom.ServerURI;
  56. }
  57. public SearializableRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  58. {
  59. m_regionLocX = regionLocX;
  60. m_regionLocY = regionLocY;
  61. m_internalEndPoint = internalEndPoint;
  62. m_externalHostName = externalUri;
  63. }
  64. public SearializableRegionInfo(uint regionLocX, uint regionLocY, string externalUri, uint port)
  65. {
  66. m_regionLocX = regionLocX;
  67. m_regionLocY = regionLocY;
  68. m_externalHostName = externalUri;
  69. m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) port);
  70. }
  71. public Guid RegionID = LLUUID.Zero.UUID;
  72. public uint m_remotingPort;
  73. public uint RemotingPort
  74. {
  75. get { return m_remotingPort; }
  76. set { m_remotingPort = value; }
  77. }
  78. /// <value>
  79. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  80. ///
  81. /// FIXME: Defaulting to 9000 temporarily (on the basis that this is the http port most region
  82. /// servers are running) until the revision in which this change is made propogates around grids.
  83. /// </value>
  84. protected uint m_httpPort = 9000;
  85. public uint HttpPort
  86. {
  87. get { return m_httpPort; }
  88. set { m_httpPort = value; }
  89. }
  90. public bool m_allow_alternate_ports;
  91. public string RemotingAddress;
  92. public IPEndPoint ExternalEndPoint
  93. {
  94. get
  95. {
  96. // Old one defaults to IPv6
  97. //return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port );
  98. IPAddress ia = null;
  99. // If it is already an IP, don't resolve it - just return directly
  100. if (IPAddress.TryParse(m_externalHostName, out ia))
  101. return new IPEndPoint(ia, m_internalEndPoint.Port);
  102. // Reset for next check
  103. ia = null;
  104. // New method favors IPv4
  105. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  106. {
  107. if (ia == null)
  108. ia = Adr;
  109. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  110. {
  111. ia = Adr;
  112. break;
  113. }
  114. }
  115. return new IPEndPoint(ia, m_internalEndPoint.Port);
  116. }
  117. set { m_externalHostName = value.ToString(); }
  118. }
  119. protected string m_externalHostName;
  120. public string ExternalHostName
  121. {
  122. get { return m_externalHostName; }
  123. set { m_externalHostName = value; }
  124. }
  125. protected IPEndPoint m_internalEndPoint;
  126. public IPEndPoint InternalEndPoint
  127. {
  128. get { return m_internalEndPoint; }
  129. set { m_internalEndPoint = value; }
  130. }
  131. protected uint? m_regionLocX;
  132. public uint RegionLocX
  133. {
  134. get { return m_regionLocX.Value; }
  135. set { m_regionLocX = value; }
  136. }
  137. protected uint? m_regionLocY;
  138. public uint RegionLocY
  139. {
  140. get { return m_regionLocY.Value; }
  141. set { m_regionLocY = value; }
  142. }
  143. public ulong RegionHandle
  144. {
  145. get { return Util.UIntsToLong((RegionLocX * (uint)Constants.RegionSize), (RegionLocY * (uint)Constants.RegionSize)); }
  146. }
  147. protected string m_proxyUrl;
  148. public string ProxyUrl
  149. {
  150. get
  151. {
  152. return m_proxyUrl;
  153. }
  154. set
  155. {
  156. m_proxyUrl = value;
  157. }
  158. }
  159. protected Guid m_originRegionID = LLUUID.Zero.UUID;
  160. public LLUUID OriginRegionID
  161. {
  162. get
  163. {
  164. return new LLUUID(m_originRegionID);
  165. }
  166. set
  167. {
  168. m_originRegionID = value.UUID;
  169. }
  170. }
  171. protected string m_regionName;
  172. public string RegionName
  173. {
  174. get
  175. {
  176. return m_regionName;
  177. }
  178. set
  179. {
  180. m_regionName = value;
  181. }
  182. }
  183. protected string m_serverURI;
  184. public string ServerURI
  185. {
  186. get
  187. {
  188. return m_serverURI;
  189. }
  190. set
  191. {
  192. m_serverURI = value;
  193. }
  194. }
  195. }
  196. }