1
0

GETRegionInfoHandler.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 OpenSimulator 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. IOSHttpRequest httpRequest, IOSHttpResponse 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(IOSHttpResponse httpResponse)
  62. {
  63. RestXmlWriter rxw = new RestXmlWriter(new StringWriter());
  64. // regions info
  65. rxw.WriteStartElement(String.Empty, "regions", String.Empty);
  66. {
  67. // regions info: number of regions
  68. rxw.WriteStartAttribute(String.Empty, "number", String.Empty);
  69. rxw.WriteValue(App.SceneManager.Scenes.Count);
  70. rxw.WriteEndAttribute();
  71. // regions info: max number of regions
  72. rxw.WriteStartAttribute(String.Empty, "max", String.Empty);
  73. if (App.ConfigSource.Source.Configs["RemoteAdmin"] != null)
  74. {
  75. rxw.WriteValue(App.ConfigSource.Source.Configs["RemoteAdmin"].GetInt("region_limit", -1));
  76. }
  77. else
  78. {
  79. rxw.WriteValue(-1);
  80. }
  81. rxw.WriteEndAttribute();
  82. // regions info: region
  83. foreach (Scene s in App.SceneManager.Scenes)
  84. {
  85. rxw.WriteStartElement(String.Empty, "region", String.Empty);
  86. rxw.WriteStartAttribute(String.Empty, "uuid", String.Empty);
  87. rxw.WriteString(s.RegionInfo.RegionID.ToString());
  88. rxw.WriteEndAttribute();
  89. rxw.WriteStartAttribute(String.Empty, "name", String.Empty);
  90. rxw.WriteString(s.RegionInfo.RegionName);
  91. rxw.WriteEndAttribute();
  92. rxw.WriteStartAttribute(String.Empty, "x", String.Empty);
  93. rxw.WriteValue(s.RegionInfo.RegionLocX);
  94. rxw.WriteEndAttribute();
  95. rxw.WriteStartAttribute(String.Empty, "y", String.Empty);
  96. rxw.WriteValue(s.RegionInfo.RegionLocY);
  97. rxw.WriteEndAttribute();
  98. rxw.WriteStartAttribute(String.Empty, "external_hostname", String.Empty);
  99. rxw.WriteString(s.RegionInfo.ExternalHostName);
  100. rxw.WriteEndAttribute();
  101. rxw.WriteStartAttribute(String.Empty, "ip", String.Empty);
  102. rxw.WriteString(s.RegionInfo.InternalEndPoint.ToString());
  103. rxw.WriteEndAttribute();
  104. int users = s.GetRootAgentCount();
  105. rxw.WriteStartAttribute(String.Empty, "avatars", String.Empty);
  106. rxw.WriteValue(users);
  107. rxw.WriteEndAttribute();
  108. rxw.WriteStartAttribute(String.Empty, "objects", String.Empty);
  109. rxw.WriteValue(s.Entities.Count - users);
  110. rxw.WriteEndAttribute();
  111. rxw.WriteEndElement();
  112. }
  113. }
  114. return rxw.ToString();
  115. }
  116. #endregion GET methods
  117. }
  118. }