ActiveConnectionsAJAX.cs 9.9 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 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.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.Text;
  32. using Mono.Data.SqliteClient;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Framework.Statistics;
  37. namespace OpenSim.Region.UserStatistics
  38. {
  39. public class ActiveConnectionsAJAX : IStatsController
  40. {
  41. private Vector3 DefaultNeighborPosition = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 70);
  42. #region IStatsController Members
  43. public string ReportName
  44. {
  45. get { return ""; }
  46. }
  47. public Hashtable ProcessModel(Hashtable pParams)
  48. {
  49. List<Scene> m_scene = (List<Scene>)pParams["Scenes"];
  50. Hashtable nh = new Hashtable();
  51. nh.Add("hdata", m_scene);
  52. return nh;
  53. }
  54. public string RenderView(Hashtable pModelResult)
  55. {
  56. List<Scene> all_scenes = (List<Scene>) pModelResult["hdata"];
  57. StringBuilder output = new StringBuilder();
  58. HTMLUtil.OL_O(ref output, "");
  59. foreach (Scene scene in all_scenes)
  60. {
  61. ScenePresence[] avatarInScene = scene.GetScenePresences();
  62. HTMLUtil.LI_O(ref output, String.Empty);
  63. output.Append(scene.RegionInfo.RegionName);
  64. HTMLUtil.OL_O(ref output, String.Empty);
  65. foreach (ScenePresence av in avatarInScene)
  66. {
  67. Dictionary<string,string> queues = new Dictionary<string, string>();
  68. if (av.ControllingClient is IStatsCollector)
  69. {
  70. IStatsCollector isClient = (IStatsCollector) av.ControllingClient;
  71. queues = decodeQueueReport(isClient.Report());
  72. }
  73. HTMLUtil.LI_O(ref output, String.Empty);
  74. output.Append(av.Name);
  75. output.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
  76. output.Append((av.IsChildAgent ? "Child" : "Root"));
  77. if (av.AbsolutePosition == DefaultNeighborPosition)
  78. {
  79. output.Append("<br />Position: ?");
  80. }
  81. else
  82. {
  83. output.Append(string.Format("<br /><NOBR>Position: <{0},{1},{2}></NOBR>", (int)av.AbsolutePosition.X,
  84. (int) av.AbsolutePosition.Y,
  85. (int) av.AbsolutePosition.Z));
  86. }
  87. Dictionary<string, int> throttles = DecodeClientThrottles(av.ControllingClient.GetThrottlesPacked(1));
  88. HTMLUtil.UL_O(ref output, String.Empty);
  89. foreach (string throttlename in throttles.Keys)
  90. {
  91. HTMLUtil.LI_O(ref output, String.Empty);
  92. output.Append(throttlename);
  93. output.Append(":");
  94. output.Append(throttles[throttlename].ToString());
  95. if (queues.ContainsKey(throttlename))
  96. {
  97. output.Append("/");
  98. output.Append(queues[throttlename]);
  99. }
  100. HTMLUtil.LI_C(ref output);
  101. }
  102. if (queues.ContainsKey("Incoming") && queues.ContainsKey("Outgoing"))
  103. {
  104. HTMLUtil.LI_O(ref output, "red");
  105. output.Append("SEND:");
  106. output.Append(queues["Outgoing"]);
  107. output.Append("/");
  108. output.Append(queues["Incoming"]);
  109. HTMLUtil.LI_C(ref output);
  110. }
  111. HTMLUtil.UL_C(ref output);
  112. HTMLUtil.LI_C(ref output);
  113. }
  114. HTMLUtil.OL_C(ref output);
  115. }
  116. HTMLUtil.OL_C(ref output);
  117. return output.ToString();
  118. }
  119. public Dictionary<string, int> DecodeClientThrottles(byte[] throttle)
  120. {
  121. Dictionary<string, int> returndict = new Dictionary<string, int>();
  122. // From mantis http://opensimulator.org/mantis/view.php?id=1374
  123. // it appears that sometimes we are receiving empty throttle byte arrays.
  124. // TODO: Investigate this behaviour
  125. if (throttle.Length == 0)
  126. {
  127. return new Dictionary<string, int>();
  128. }
  129. int tResend = -1;
  130. int tLand = -1;
  131. int tWind = -1;
  132. int tCloud = -1;
  133. int tTask = -1;
  134. int tTexture = -1;
  135. int tAsset = -1;
  136. int tall = -1;
  137. const int singlefloat = 4;
  138. //Agent Throttle Block contains 7 single floatingpoint values.
  139. int j = 0;
  140. // Some Systems may be big endian...
  141. // it might be smart to do this check more often...
  142. if (!BitConverter.IsLittleEndian)
  143. for (int i = 0; i < 7; i++)
  144. Array.Reverse(throttle, j + i * singlefloat, singlefloat);
  145. // values gotten from OpenMetaverse.org/wiki/Throttle. Thanks MW_
  146. // bytes
  147. // Convert to integer, since.. the full fp space isn't used.
  148. tResend = (int)BitConverter.ToSingle(throttle, j);
  149. returndict.Add("Resend", tResend);
  150. j += singlefloat;
  151. tLand = (int)BitConverter.ToSingle(throttle, j);
  152. returndict.Add("Land", tLand);
  153. j += singlefloat;
  154. tWind = (int)BitConverter.ToSingle(throttle, j);
  155. returndict.Add("Wind", tWind);
  156. j += singlefloat;
  157. tCloud = (int)BitConverter.ToSingle(throttle, j);
  158. returndict.Add("Cloud", tCloud);
  159. j += singlefloat;
  160. tTask = (int)BitConverter.ToSingle(throttle, j);
  161. returndict.Add("Task", tTask);
  162. j += singlefloat;
  163. tTexture = (int)BitConverter.ToSingle(throttle, j);
  164. returndict.Add("Texture", tTexture);
  165. j += singlefloat;
  166. tAsset = (int)BitConverter.ToSingle(throttle, j);
  167. returndict.Add("Asset", tAsset);
  168. tall = tResend + tLand + tWind + tCloud + tTask + tTexture + tAsset;
  169. returndict.Add("All", tall);
  170. return returndict;
  171. }
  172. public Dictionary<string,string> decodeQueueReport(string rep)
  173. {
  174. Dictionary<string, string> returndic = new Dictionary<string, string>();
  175. if (rep.Length == 79)
  176. {
  177. int pos = 1;
  178. returndic.Add("All", rep.Substring((6 * pos), 8)); pos++;
  179. returndic.Add("Incoming", rep.Substring((7 * pos), 8)); pos++;
  180. returndic.Add("Outgoing", rep.Substring((7 * pos) , 8)); pos++;
  181. returndic.Add("Resend", rep.Substring((7 * pos) , 8)); pos++;
  182. returndic.Add("Land", rep.Substring((7 * pos) , 8)); pos++;
  183. returndic.Add("Wind", rep.Substring((7 * pos) , 8)); pos++;
  184. returndic.Add("Cloud", rep.Substring((7 * pos) , 8)); pos++;
  185. returndic.Add("Task", rep.Substring((7 * pos) , 8)); pos++;
  186. returndic.Add("Texture", rep.Substring((7 * pos), 8)); pos++;
  187. returndic.Add("Asset", rep.Substring((7 * pos), 8));
  188. /*
  189. * return string.Format("{0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7}",
  190. SendQueue.Count(),
  191. IncomingPacketQueue.Count,
  192. OutgoingPacketQueue.Count,
  193. ResendOutgoingPacketQueue.Count,
  194. LandOutgoingPacketQueue.Count,
  195. WindOutgoingPacketQueue.Count,
  196. CloudOutgoingPacketQueue.Count,
  197. TaskOutgoingPacketQueue.Count,
  198. TextureOutgoingPacketQueue.Count,
  199. AssetOutgoingPacketQueue.Count);
  200. */
  201. }
  202. return returndic;
  203. }
  204. #endregion
  205. }
  206. }