SerializableRegionInfo.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 SerializableRegionInfo
  35. {
  36. public bool m_allow_alternate_ports;
  37. protected string m_externalHostName;
  38. /// <value>
  39. /// The port by which http communication occurs with the region (most noticeably, CAPS communication)
  40. ///
  41. /// FIXME: Defaulting to 9000 temporarily (on the basis that this is the http port most region
  42. /// servers are running) until the revision in which this change is made propogates around grids.
  43. /// </value>
  44. protected uint m_httpPort = 9000;
  45. protected IPEndPoint m_internalEndPoint;
  46. protected Guid m_originRegionID = LLUUID.Zero.UUID;
  47. protected string m_proxyUrl;
  48. protected uint? m_regionLocX;
  49. protected uint? m_regionLocY;
  50. protected string m_regionName;
  51. public uint m_remotingPort;
  52. protected string m_serverURI;
  53. public Guid RegionID = LLUUID.Zero.UUID;
  54. public string RemotingAddress;
  55. /// <summary>
  56. /// This is a serializable version of RegionInfo
  57. /// </summary>
  58. public SerializableRegionInfo()
  59. {
  60. }
  61. public SerializableRegionInfo(RegionInfo ConvertFrom)
  62. {
  63. m_regionLocX = ConvertFrom.RegionLocX;
  64. m_regionLocY = ConvertFrom.RegionLocY;
  65. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  66. m_externalHostName = ConvertFrom.ExternalHostName;
  67. m_remotingPort = ConvertFrom.RemotingPort;
  68. m_httpPort = ConvertFrom.HttpPort;
  69. m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports;
  70. RemotingAddress = ConvertFrom.RemotingAddress;
  71. m_proxyUrl = ConvertFrom.proxyUrl;
  72. OriginRegionID = ConvertFrom.originRegionID;
  73. RegionName = ConvertFrom.RegionName;
  74. ServerURI = ConvertFrom.ServerURI;
  75. }
  76. public SerializableRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  77. {
  78. m_regionLocX = regionLocX;
  79. m_regionLocY = regionLocY;
  80. m_internalEndPoint = internalEndPoint;
  81. m_externalHostName = externalUri;
  82. }
  83. public SerializableRegionInfo(uint regionLocX, uint regionLocY, string externalUri, uint port)
  84. {
  85. m_regionLocX = regionLocX;
  86. m_regionLocY = regionLocY;
  87. m_externalHostName = externalUri;
  88. m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) port);
  89. }
  90. public uint RemotingPort
  91. {
  92. get { return m_remotingPort; }
  93. set { m_remotingPort = value; }
  94. }
  95. public uint HttpPort
  96. {
  97. get { return m_httpPort; }
  98. set { m_httpPort = value; }
  99. }
  100. public IPEndPoint ExternalEndPoint
  101. {
  102. get
  103. {
  104. // Old one defaults to IPv6
  105. //return new IPEndPoint(Dns.GetHostAddresses(m_externalHostName)[0], m_internalEndPoint.Port);
  106. IPAddress ia = null;
  107. // If it is already an IP, don't resolve it - just return directly
  108. if (IPAddress.TryParse(m_externalHostName, out ia))
  109. return new IPEndPoint(ia, m_internalEndPoint.Port);
  110. // Reset for next check
  111. ia = null;
  112. // New method favors IPv4
  113. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  114. {
  115. if (ia == null)
  116. ia = Adr;
  117. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  118. {
  119. ia = Adr;
  120. break;
  121. }
  122. }
  123. return new IPEndPoint(ia, m_internalEndPoint.Port);
  124. }
  125. set { m_externalHostName = value.ToString(); }
  126. }
  127. public string ExternalHostName
  128. {
  129. get { return m_externalHostName; }
  130. set { m_externalHostName = value; }
  131. }
  132. public IPEndPoint InternalEndPoint
  133. {
  134. get { return m_internalEndPoint; }
  135. set { m_internalEndPoint = value; }
  136. }
  137. public uint RegionLocX
  138. {
  139. get { return m_regionLocX.Value; }
  140. set { m_regionLocX = value; }
  141. }
  142. public uint RegionLocY
  143. {
  144. get { return m_regionLocY.Value; }
  145. set { m_regionLocY = value; }
  146. }
  147. public ulong RegionHandle
  148. {
  149. get { return Util.UIntsToLong((RegionLocX * (uint) Constants.RegionSize), (RegionLocY * (uint) Constants.RegionSize)); }
  150. }
  151. public string ProxyUrl
  152. {
  153. get { return m_proxyUrl; }
  154. set { m_proxyUrl = value; }
  155. }
  156. public LLUUID OriginRegionID
  157. {
  158. get { return new LLUUID(m_originRegionID); }
  159. set { m_originRegionID = value.UUID; }
  160. }
  161. public string RegionName
  162. {
  163. get { return m_regionName; }
  164. set { m_regionName = value; }
  165. }
  166. public string ServerURI
  167. {
  168. get { return m_serverURI; }
  169. set { m_serverURI = value; }
  170. }
  171. }
  172. }