GETRegionInfoHandler.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.IO;
  29. using System.Xml.Serialization;
  30. using OpenMetaverse;
  31. using OpenSim.Framework.Servers;
  32. using OpenSim.Framework.Servers.HttpServer;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using OpenSim.Region.Framework.Scenes;
  35. namespace OpenSim.ApplicationPlugins.Rest.Regions
  36. {
  37. public partial class RestRegionPlugin : RestPlugin
  38. {
  39. #region GET methods
  40. public string GetRegionInfoHandler(string request, string path, string param,
  41. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  42. {
  43. // foreach (string h in httpRequest.Headers.AllKeys)
  44. // foreach (string v in httpRequest.Headers.GetValues(h))
  45. // m_log.DebugFormat("{0} IsGod: {1} -> {2}", MsgID, h, v);
  46. MsgID = RequestID;
  47. m_log.DebugFormat("{0} GET path {1} param {2}", MsgID, path, param);
  48. try
  49. {
  50. // param empty: regions list
  51. // if (String.IsNullOrEmpty(param))
  52. return GetRegionInfoHandlerRegions(httpResponse);
  53. // // param not empty: specific region
  54. // return GetRegionInfoHandlerRegion(httpResponse, param);
  55. }
  56. catch (Exception e)
  57. {
  58. return Failure(httpResponse, OSHttpStatusCode.ServerErrorInternalError, "GET", e);
  59. }
  60. }
  61. public string GetRegionInfoHandlerRegions(OSHttpResponse httpResponse)
  62. {
  63. // regions info
  64. XmlWriter.WriteStartElement(String.Empty, "regions", String.Empty);
  65. {
  66. // regions info: number of regions
  67. XmlWriter.WriteStartAttribute(String.Empty, "number", String.Empty);
  68. XmlWriter.WriteValue(App.SceneManager.Scenes.Count);
  69. XmlWriter.WriteEndAttribute();
  70. // regions info: max number of regions
  71. XmlWriter.WriteStartAttribute(String.Empty, "max", String.Empty);
  72. if (App.ConfigSource.Source.Configs["RemoteAdmin"] != null)
  73. {
  74. XmlWriter.WriteValue(App.ConfigSource.Source.Configs["RemoteAdmin"].GetInt("region_limit", -1));
  75. }
  76. else
  77. {
  78. XmlWriter.WriteValue(-1);
  79. }
  80. XmlWriter.WriteEndAttribute();
  81. // regions info: region
  82. foreach (Scene s in App.SceneManager.Scenes)
  83. {
  84. XmlWriter.WriteStartElement(String.Empty, "region", String.Empty);
  85. XmlWriter.WriteStartAttribute(String.Empty, "uuid", String.Empty);
  86. XmlWriter.WriteString(s.RegionInfo.RegionID.ToString());
  87. XmlWriter.WriteEndAttribute();
  88. XmlWriter.WriteStartAttribute(String.Empty, "name", String.Empty);
  89. XmlWriter.WriteString(s.RegionInfo.RegionName);
  90. XmlWriter.WriteEndAttribute();
  91. XmlWriter.WriteStartAttribute(String.Empty, "x", String.Empty);
  92. XmlWriter.WriteValue(s.RegionInfo.RegionLocX);
  93. XmlWriter.WriteEndAttribute();
  94. XmlWriter.WriteStartAttribute(String.Empty, "y", String.Empty);
  95. XmlWriter.WriteValue(s.RegionInfo.RegionLocY);
  96. XmlWriter.WriteEndAttribute();
  97. XmlWriter.WriteStartAttribute(String.Empty, "external_hostname", String.Empty);
  98. XmlWriter.WriteString(s.RegionInfo.ExternalHostName);
  99. XmlWriter.WriteEndAttribute();
  100. XmlWriter.WriteStartAttribute(String.Empty, "master_name", String.Empty);
  101. XmlWriter.WriteString(String.Format("{0} {1}", s.RegionInfo.MasterAvatarFirstName, s.RegionInfo.MasterAvatarLastName));
  102. XmlWriter.WriteEndAttribute();
  103. XmlWriter.WriteStartAttribute(String.Empty, "master_uuid", String.Empty);
  104. XmlWriter.WriteString(s.RegionInfo.MasterAvatarAssignedUUID.ToString());
  105. XmlWriter.WriteEndAttribute();
  106. XmlWriter.WriteStartAttribute(String.Empty, "ip", String.Empty);
  107. XmlWriter.WriteString(s.RegionInfo.InternalEndPoint.ToString());
  108. XmlWriter.WriteEndAttribute();
  109. int users = s.GetAvatars().Count;
  110. XmlWriter.WriteStartAttribute(String.Empty, "avatars", String.Empty);
  111. XmlWriter.WriteValue(users);
  112. XmlWriter.WriteEndAttribute();
  113. XmlWriter.WriteStartAttribute(String.Empty, "objects", String.Empty);
  114. XmlWriter.WriteValue(s.Entities.Count - users);
  115. XmlWriter.WriteEndAttribute();
  116. XmlWriter.WriteEndElement();
  117. }
  118. }
  119. XmlWriter.WriteEndElement();
  120. return XmlWriterResult;
  121. }
  122. #endregion GET methods
  123. }
  124. }