corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
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 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using OpenMetaverse.Packets; |
||
29 | |||
30 | namespace OpenMetaverse |
||
31 | { |
||
32 | /// <summary> |
||
33 | /// Throttles the network traffic for various different traffic types. |
||
34 | /// Access this class through GridClient.Throttle |
||
35 | /// </summary> |
||
36 | public class AgentThrottle |
||
37 | { |
||
38 | /// <summary>Maximum bits per second for resending unacknowledged packets</summary> |
||
39 | public float Resend |
||
40 | { |
||
41 | get { return resend; } |
||
42 | set |
||
43 | { |
||
44 | if (value > 150000.0f) resend = 150000.0f; |
||
45 | else if (value < 10000.0f) resend = 10000.0f; |
||
46 | else resend = value; |
||
47 | } |
||
48 | } |
||
49 | /// <summary>Maximum bits per second for LayerData terrain</summary> |
||
50 | public float Land |
||
51 | { |
||
52 | get { return land; } |
||
53 | set |
||
54 | { |
||
55 | if (value > 170000.0f) land = 170000.0f; |
||
56 | else if (value < 0.0f) land = 0.0f; // We don't have control of these so allow throttling to 0 |
||
57 | else land = value; |
||
58 | } |
||
59 | } |
||
60 | /// <summary>Maximum bits per second for LayerData wind data</summary> |
||
61 | public float Wind |
||
62 | { |
||
63 | get { return wind; } |
||
64 | set |
||
65 | { |
||
66 | if (value > 34000.0f) wind = 34000.0f; |
||
67 | else if (value < 0.0f) wind = 0.0f; // We don't have control of these so allow throttling to 0 |
||
68 | else wind = value; |
||
69 | } |
||
70 | } |
||
71 | /// <summary>Maximum bits per second for LayerData clouds</summary> |
||
72 | public float Cloud |
||
73 | { |
||
74 | get { return cloud; } |
||
75 | set |
||
76 | { |
||
77 | if (value > 34000.0f) cloud = 34000.0f; |
||
78 | else if (value < 0.0f) cloud = 0.0f; // We don't have control of these so allow throttling to 0 |
||
79 | else cloud = value; |
||
80 | } |
||
81 | } |
||
82 | /// <summary>Unknown, includes object data</summary> |
||
83 | public float Task |
||
84 | { |
||
85 | get { return task; } |
||
86 | set |
||
87 | { |
||
88 | if (value > 446000.0f) task = 446000.0f; |
||
89 | else if (value < 4000.0f) task = 4000.0f; |
||
90 | else task = value; |
||
91 | } |
||
92 | } |
||
93 | /// <summary>Maximum bits per second for textures</summary> |
||
94 | public float Texture |
||
95 | { |
||
96 | get { return texture; } |
||
97 | set |
||
98 | { |
||
99 | if (value > 446000.0f) texture = 446000.0f; |
||
100 | else if (value < 4000.0f) texture = 4000.0f; |
||
101 | else texture = value; |
||
102 | } |
||
103 | } |
||
104 | /// <summary>Maximum bits per second for downloaded assets</summary> |
||
105 | public float Asset |
||
106 | { |
||
107 | get { return asset; } |
||
108 | set |
||
109 | { |
||
110 | if (value > 220000.0f) asset = 220000.0f; |
||
111 | else if (value < 10000.0f) asset = 10000.0f; |
||
112 | else asset = value; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | /// <summary>Maximum bits per second the entire connection, divided up |
||
117 | /// between invidiual streams using default multipliers</summary> |
||
118 | public float Total |
||
119 | { |
||
120 | get { return Resend + Land + Wind + Cloud + Task + Texture + Asset; } |
||
121 | set |
||
122 | { |
||
123 | // Sane initial values |
||
124 | Resend = (value * 0.1f); |
||
125 | Land = (float)(value * 0.52f / 3f); |
||
126 | Wind = (float)(value * 0.05f); |
||
127 | Cloud = (float)(value * 0.05f); |
||
128 | Task = (float)(value * 0.704f / 3f); |
||
129 | Texture = (float)(value * 0.704f / 3f); |
||
130 | Asset = (float)(value * 0.484f / 3f); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | private GridClient Client; |
||
135 | private float resend; |
||
136 | private float land; |
||
137 | private float wind; |
||
138 | private float cloud; |
||
139 | private float task; |
||
140 | private float texture; |
||
141 | private float asset; |
||
142 | |||
143 | /// <summary> |
||
144 | /// Default constructor, uses a default high total of 1500 KBps (1536000) |
||
145 | /// </summary> |
||
146 | public AgentThrottle(GridClient client) |
||
147 | { |
||
148 | Client = client; |
||
149 | Total = 1536000.0f; |
||
150 | } |
||
151 | |||
152 | /// <summary> |
||
153 | /// Constructor that decodes an existing AgentThrottle packet in to |
||
154 | /// individual values |
||
155 | /// </summary> |
||
156 | /// <param name="data">Reference to the throttle data in an AgentThrottle |
||
157 | /// packet</param> |
||
158 | /// <param name="pos">Offset position to start reading at in the |
||
159 | /// throttle data</param> |
||
160 | /// <remarks>This is generally not needed in clients as the server will |
||
161 | /// never send a throttle packet to the client</remarks> |
||
162 | public AgentThrottle(byte[] data, int pos) |
||
163 | { |
||
164 | byte[] adjData; |
||
165 | |||
166 | if (!BitConverter.IsLittleEndian) |
||
167 | { |
||
168 | byte[] newData = new byte[7 * 4]; |
||
169 | Buffer.BlockCopy(data, pos, newData, 0, 7 * 4); |
||
170 | |||
171 | for (int i = 0; i < 7; i++) |
||
172 | Array.Reverse(newData, i * 4, 4); |
||
173 | |||
174 | adjData = newData; |
||
175 | } |
||
176 | else |
||
177 | { |
||
178 | adjData = data; |
||
179 | } |
||
180 | |||
181 | Resend = BitConverter.ToSingle(adjData, pos); pos += 4; |
||
182 | Land = BitConverter.ToSingle(adjData, pos); pos += 4; |
||
183 | Wind = BitConverter.ToSingle(adjData, pos); pos += 4; |
||
184 | Cloud = BitConverter.ToSingle(adjData, pos); pos += 4; |
||
185 | Task = BitConverter.ToSingle(adjData, pos); pos += 4; |
||
186 | Texture = BitConverter.ToSingle(adjData, pos); pos += 4; |
||
187 | Asset = BitConverter.ToSingle(adjData, pos); |
||
188 | } |
||
189 | |||
190 | /// <summary> |
||
191 | /// Send an AgentThrottle packet to the current server using the |
||
192 | /// current values |
||
193 | /// </summary> |
||
194 | public void Set() |
||
195 | { |
||
196 | Set(Client.Network.CurrentSim); |
||
197 | } |
||
198 | |||
199 | /// <summary> |
||
200 | /// Send an AgentThrottle packet to the specified server using the |
||
201 | /// current values |
||
202 | /// </summary> |
||
203 | public void Set(Simulator simulator) |
||
204 | { |
||
205 | AgentThrottlePacket throttle = new AgentThrottlePacket(); |
||
206 | throttle.AgentData.AgentID = Client.Self.AgentID; |
||
207 | throttle.AgentData.SessionID = Client.Self.SessionID; |
||
208 | throttle.AgentData.CircuitCode = Client.Network.CircuitCode; |
||
209 | throttle.Throttle.GenCounter = 0; |
||
210 | throttle.Throttle.Throttles = this.ToBytes(); |
||
211 | |||
212 | Client.Network.SendPacket(throttle, simulator); |
||
213 | } |
||
214 | |||
215 | /// <summary> |
||
216 | /// Convert the current throttle values to a byte array that can be put |
||
217 | /// in an AgentThrottle packet |
||
218 | /// </summary> |
||
219 | /// <returns>Byte array containing all the throttle values</returns> |
||
220 | public byte[] ToBytes() |
||
221 | { |
||
222 | byte[] data = new byte[7 * 4]; |
||
223 | int i = 0; |
||
224 | |||
225 | Buffer.BlockCopy(Utils.FloatToBytes(Resend), 0, data, i, 4); i += 4; |
||
226 | Buffer.BlockCopy(Utils.FloatToBytes(Land), 0, data, i, 4); i += 4; |
||
227 | Buffer.BlockCopy(Utils.FloatToBytes(Wind), 0, data, i, 4); i += 4; |
||
228 | Buffer.BlockCopy(Utils.FloatToBytes(Cloud), 0, data, i, 4); i += 4; |
||
229 | Buffer.BlockCopy(Utils.FloatToBytes(Task), 0, data, i, 4); i += 4; |
||
230 | Buffer.BlockCopy(Utils.FloatToBytes(Texture), 0, data, i, 4); i += 4; |
||
231 | Buffer.BlockCopy(Utils.FloatToBytes(Asset), 0, data, i, 4); i += 4; |
||
232 | |||
233 | return data; |
||
234 | } |
||
235 | } |
||
236 | } |