aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/UserStatistics/ActiveConnectionsAJAX.cs
blob: ed8fc408d2b33cfe20b4407f844c45b923e0bb8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Mono.Data.SqliteClient;
using OpenMetaverse;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Framework.Statistics;

namespace OpenSim.Region.UserStatistics
{
    public class ActiveConnectionsAJAX : IStatsController
    {
        #region IStatsController Members

        private Vector3 DefaultNeighborPosition = new Vector3(128, 128, 70);
        public Hashtable ProcessModel(Hashtable pParams)
        {
            
            List<Scene> m_scene = (List<Scene>)pParams["Scenes"];

            Hashtable nh = new Hashtable();
            nh.Add("hdata", m_scene);

            return nh;
        }

        public string RenderView(Hashtable pModelResult)
        {
            List<Scene> all_scenes = (List<Scene>) pModelResult["hdata"];

            StringBuilder output = new StringBuilder();
            HTMLUtil.OL_O(ref output, "");
            foreach (Scene scene in all_scenes)
            {
                List<ScenePresence> avatarInScene = scene.GetScenePresences();

                HTMLUtil.LI_O(ref output, "");
                output.Append(scene.RegionInfo.RegionName);
                HTMLUtil.OL_O(ref output, "");
                foreach (ScenePresence av in avatarInScene)
                {
                    Dictionary<string,string> queues = new Dictionary<string, string>();
                    if (av.ControllingClient is IStatsCollector)
                    {
                        IStatsCollector isClient = (IStatsCollector) av.ControllingClient;
                        queues = decodeQueueReport(isClient.Report());
                    }
                    HTMLUtil.LI_O(ref output, "");
                    output.Append(av.Name);
                    output.Append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                    output.Append((av.IsChildAgent ? "Child" : "Root"));
                    if (av.AbsolutePosition == DefaultNeighborPosition)
                    {
                        output.Append("<br />Position: ?");
                    }
                    else
                    {
                        output.Append(string.Format("<br /><NOBR>Position: <{0},{1},{2}></NOBR>", (int)av.AbsolutePosition.X,
                                                    (int) av.AbsolutePosition.Y,
                                                    (int) av.AbsolutePosition.Z));
                    }
                    Dictionary<string, int> throttles = DecodeClientThrottles(av.ControllingClient.GetThrottlesPacked(1));
                    
                    HTMLUtil.UL_O(ref output, "");

                    foreach (string throttlename in throttles.Keys)
                    {
                        HTMLUtil.LI_O(ref output, "");
                        output.Append(throttlename);
                        output.Append(":");
                        output.Append(throttles[throttlename].ToString());
                        if (queues.ContainsKey(throttlename))
                        {
                            output.Append("/");
                            output.Append(queues[throttlename]);
                        }
                        HTMLUtil.LI_C(ref output);
                    }
                    if (queues.ContainsKey("Incoming") && queues.ContainsKey("Outgoing"))
                    {
                        HTMLUtil.LI_O(ref output, "red");
                        output.Append("SEND:");
                        output.Append(queues["Outgoing"]);
                        output.Append("/");
                        output.Append(queues["Incoming"]);
                        HTMLUtil.LI_C(ref output);
                    }

                    HTMLUtil.UL_C(ref output);
                    HTMLUtil.LI_C(ref output);
                }
                HTMLUtil.OL_C(ref output);
            }
            HTMLUtil.OL_C(ref output);
            return output.ToString();
        }

        public Dictionary<string, int> DecodeClientThrottles(byte[] throttle)
        {
            Dictionary<string, int> returndict = new Dictionary<string, int>();
            // From mantis http://opensimulator.org/mantis/view.php?id=1374
            // it appears that sometimes we are receiving empty throttle byte arrays.
            // TODO: Investigate this behaviour
            if (throttle.Length == 0)
            {
                return new Dictionary<string, int>();
            }

            int tResend = -1;
            int tLand = -1;
            int tWind = -1;
            int tCloud = -1;
            int tTask = -1;
            int tTexture = -1;
            int tAsset = -1;
            int tall = -1;
            const int singlefloat = 4;

            //Agent Throttle Block contains 7 single floatingpoint values.
            int j = 0;

            // Some Systems may be big endian...
            // it might be smart to do this check more often...
            if (!BitConverter.IsLittleEndian)
                for (int i = 0; i < 7; i++)
                    Array.Reverse(throttle, j + i * singlefloat, singlefloat);

            // values gotten from OpenMetaverse.org/wiki/Throttle.  Thanks MW_
            // bytes
            // Convert to integer, since..   the full fp space isn't used.
            tResend = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Resend", tResend);
            j += singlefloat;
            tLand = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Land", tLand);
            j += singlefloat;
            tWind = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Wind", tWind);
            j += singlefloat;
            tCloud = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Cloud", tCloud);
            j += singlefloat;
            tTask = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Task", tTask);
            j += singlefloat;
            tTexture = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Texture", tTexture);
            j += singlefloat;
            tAsset = (int)BitConverter.ToSingle(throttle, j);
            returndict.Add("Asset", tAsset);

            tall = tResend + tLand + tWind + tCloud + tTask + tTexture + tAsset;
            returndict.Add("All", tall);

            return returndict;
        }
        public Dictionary<string,string> decodeQueueReport(string rep)
        {
            Dictionary<string, string> returndic = new Dictionary<string, string>();
            if (rep.Length == 79)
            {
                int pos = 1;
                returndic.Add("All", rep.Substring((6 * pos), 8)); pos++;
                returndic.Add("Incoming", rep.Substring((7 * pos), 8)); pos++;
                returndic.Add("Outgoing", rep.Substring((7 * pos) , 8)); pos++;
                returndic.Add("Resend", rep.Substring((7 * pos) , 8)); pos++;
                returndic.Add("Land", rep.Substring((7 * pos) , 8)); pos++;
                returndic.Add("Wind", rep.Substring((7 * pos) , 8)); pos++;
                returndic.Add("Cloud", rep.Substring((7 * pos) , 8)); pos++;
                returndic.Add("Task", rep.Substring((7 * pos) , 8)); pos++;
                returndic.Add("Texture", rep.Substring((7 * pos), 8)); pos++;
                returndic.Add("Asset", rep.Substring((7 * pos), 8)); 
                /*
                 * return string.Format("{0,7} {1,7} {2,7} {3,7} {4,7} {5,7} {6,7} {7,7} {8,7} {9,7}",
                                 SendQueue.Count(),
                                 IncomingPacketQueue.Count,
                                 OutgoingPacketQueue.Count,
                                 ResendOutgoingPacketQueue.Count,
                                 LandOutgoingPacketQueue.Count,
                                 WindOutgoingPacketQueue.Count,
                                 CloudOutgoingPacketQueue.Count,
                                 TaskOutgoingPacketQueue.Count,
                                 TextureOutgoingPacketQueue.Count,
                                 AssetOutgoingPacketQueue.Count);
                 */
            }



            return returndic;
        }
        #endregion
    }
}