1
0

ActiveConnectionsAJAX.cs 9.8 KB

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