SerializableRegionInfo.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. */
  28. using System;
  29. using System.Net;
  30. using System.Net.Sockets;
  31. using libsecondlife;
  32. namespace OpenSim.Framework
  33. {
  34. [Serializable]
  35. public class SearializableRegionInfo
  36. {
  37. /// <summary>
  38. /// This is a serializable version of RegionInfo
  39. /// </summary>
  40. public SearializableRegionInfo()
  41. {
  42. }
  43. public SearializableRegionInfo(RegionInfo ConvertFrom)
  44. {
  45. m_regionLocX = ConvertFrom.RegionLocX;
  46. m_regionLocY = ConvertFrom.RegionLocY;
  47. m_internalEndPoint = ConvertFrom.InternalEndPoint;
  48. m_externalHostName = ConvertFrom.ExternalHostName;
  49. m_remotingPort = ConvertFrom.RemotingPort;
  50. RemotingAddress = ConvertFrom.RemotingAddress;
  51. }
  52. public SearializableRegionInfo(uint regionLocX, uint regionLocY, IPEndPoint internalEndPoint, string externalUri)
  53. {
  54. m_regionLocX = regionLocX;
  55. m_regionLocY = regionLocY;
  56. m_internalEndPoint = internalEndPoint;
  57. m_externalHostName = externalUri;
  58. }
  59. public SearializableRegionInfo(uint regionLocX, uint regionLocY, string externalUri, uint port)
  60. {
  61. m_regionLocX = regionLocX;
  62. m_regionLocY = regionLocY;
  63. m_externalHostName = externalUri;
  64. m_internalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) port);
  65. }
  66. public Guid RegionID = LLUUID.Zero.UUID;
  67. public uint m_remotingPort;
  68. public uint RemotingPort
  69. {
  70. get { return m_remotingPort; }
  71. set { m_remotingPort = value; }
  72. }
  73. public string RemotingAddress;
  74. public IPEndPoint ExternalEndPoint
  75. {
  76. get
  77. {
  78. // Old one defaults to IPv6
  79. //return new IPEndPoint( Dns.GetHostAddresses( m_externalHostName )[0], m_internalEndPoint.Port );
  80. IPAddress ia = null;
  81. // If it is already an IP, don't resolve it - just return directly
  82. if (IPAddress.TryParse(m_externalHostName, out ia))
  83. return new IPEndPoint(ia, m_internalEndPoint.Port);
  84. // Reset for next check
  85. ia = null;
  86. // New method favors IPv4
  87. foreach (IPAddress Adr in Dns.GetHostAddresses(m_externalHostName))
  88. {
  89. if (ia == null)
  90. ia = Adr;
  91. if (Adr.AddressFamily == AddressFamily.InterNetwork)
  92. {
  93. ia = Adr;
  94. break;
  95. }
  96. }
  97. return new IPEndPoint(ia, m_internalEndPoint.Port);
  98. }
  99. set { m_externalHostName = value.ToString(); }
  100. }
  101. protected string m_externalHostName;
  102. public string ExternalHostName
  103. {
  104. get { return m_externalHostName; }
  105. set { m_externalHostName = value; }
  106. }
  107. protected IPEndPoint m_internalEndPoint;
  108. public IPEndPoint InternalEndPoint
  109. {
  110. get { return m_internalEndPoint; }
  111. set { m_internalEndPoint = value; }
  112. }
  113. protected uint? m_regionLocX;
  114. public uint RegionLocX
  115. {
  116. get { return m_regionLocX.Value; }
  117. set { m_regionLocX = value; }
  118. }
  119. protected uint? m_regionLocY;
  120. public uint RegionLocY
  121. {
  122. get { return m_regionLocY.Value; }
  123. set { m_regionLocY = value; }
  124. }
  125. public ulong RegionHandle
  126. {
  127. get { return Util.UIntsToLong((RegionLocX*256), (RegionLocY*256)); }
  128. }
  129. }
  130. }