ActiveConnectionsAJAX.cs 7.5 KB

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