aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AgentCircuitData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/AgentCircuitData.cs')
-rw-r--r--OpenSim/Framework/AgentCircuitData.cs386
1 files changed, 386 insertions, 0 deletions
diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs
new file mode 100644
index 0000000..0d053e4
--- /dev/null
+++ b/OpenSim/Framework/AgentCircuitData.cs
@@ -0,0 +1,386 @@
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
28using System;
29using System.Reflection;
30using System.Collections.Generic;
31using log4net;
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34
35namespace OpenSim.Framework
36{
37 /// <summary>
38 /// Circuit data for an agent. Connection information shared between
39 /// regions that accept UDP connections from a client
40 /// </summary>
41 public class AgentCircuitData
42 {
43// DEBUG ON
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47// DEBUG OFF
48
49 /// <summary>
50 /// Avatar Unique Agent Identifier
51 /// </summary>
52 public UUID AgentID;
53
54 /// <summary>
55 /// Avatar's Appearance
56 /// </summary>
57 public AvatarAppearance Appearance;
58
59 /// <summary>
60 /// Agent's root inventory folder
61 /// </summary>
62 public UUID BaseFolder;
63
64 /// <summary>
65 /// Base Caps path for user
66 /// </summary>
67 public string CapsPath = String.Empty;
68
69 /// <summary>
70 /// Seed caps for neighbor regions that the user can see into
71 /// </summary>
72 public Dictionary<ulong, string> ChildrenCapSeeds;
73
74 /// <summary>
75 /// Root agent, or Child agent
76 /// </summary>
77 public bool child;
78
79 /// <summary>
80 /// Number given to the client when they log-in that they provide
81 /// as credentials to the UDP server
82 /// </summary>
83 public uint circuitcode;
84
85 /// <summary>
86 /// How this agent got here
87 /// </summary>
88 public uint teleportFlags;
89
90 /// <summary>
91 /// Agent's account first name
92 /// </summary>
93 public string firstname;
94 public UUID InventoryFolder;
95
96 /// <summary>
97 /// Agent's account last name
98 /// </summary>
99 public string lastname;
100
101 /// <summary>
102 /// Agent's full name.
103 /// </summary>
104 public string Name { get { return string.Format("{0} {1}", firstname, lastname); } }
105
106 /// <summary>
107 /// Random Unique GUID for this session. Client gets this at login and it's
108 /// only supposed to be disclosed over secure channels
109 /// </summary>
110 public UUID SecureSessionID;
111
112 /// <summary>
113 /// Non secure Session ID
114 /// </summary>
115 public UUID SessionID;
116
117 /// <summary>
118 /// Hypergrid service token; generated by the user domain, consumed by the receiving grid.
119 /// There is one such unique token for each grid visited.
120 /// </summary>
121 public string ServiceSessionID = string.Empty;
122
123 /// <summary>
124 /// The client's IP address, as captured by the login service
125 /// </summary>
126 public string IPAddress;
127
128 /// <summary>
129 /// Viewer's version string as reported by the viewer at login
130 /// </summary>
131 private string m_viewerInternal;
132
133 /// <summary>
134 /// Viewer's version string
135 /// </summary>
136 public string Viewer
137 {
138 set { m_viewerInternal = value; }
139
140 // Try to return consistent viewer string taking into account
141 // that viewers have chaagned how version is reported
142 // See http://opensimulator.org/mantis/view.php?id=6851
143 get
144 {
145 // Old style version string contains viewer name followed by a space followed by a version number
146 if (m_viewerInternal == null || m_viewerInternal.Contains(" "))
147 {
148 return m_viewerInternal;
149 }
150 else // New style version contains no spaces, just version number
151 {
152 return Channel + " " + m_viewerInternal;
153 }
154 }
155 }
156
157 /// <summary>
158 /// The channel strinf sent by the viewer at login
159 /// </summary>
160 public string Channel;
161
162 /// <summary>
163 /// The Mac address as reported by the viewer at login
164 /// </summary>
165 public string Mac;
166
167 /// <summary>
168 /// The id0 as reported by the viewer at login
169 /// </summary>
170 public string Id0;
171
172 /// <summary>
173 /// Position the Agent's Avatar starts in the region
174 /// </summary>
175 public Vector3 startpos;
176
177 public Dictionary<string, object> ServiceURLs;
178
179 public AgentCircuitData()
180 {
181 }
182
183 /// <summary>
184 /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
185 /// </summary>
186 /// <returns>map of the agent circuit data</returns>
187 public OSDMap PackAgentCircuitData()
188 {
189 OSDMap args = new OSDMap();
190 args["agent_id"] = OSD.FromUUID(AgentID);
191 args["base_folder"] = OSD.FromUUID(BaseFolder);
192 args["caps_path"] = OSD.FromString(CapsPath);
193
194 if (ChildrenCapSeeds != null)
195 {
196 OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
197 foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
198 {
199 OSDMap pair = new OSDMap();
200 pair["handle"] = OSD.FromString(kvp.Key.ToString());
201 pair["seed"] = OSD.FromString(kvp.Value);
202 childrenSeeds.Add(pair);
203 }
204 if (ChildrenCapSeeds.Count > 0)
205 args["children_seeds"] = childrenSeeds;
206 }
207 args["child"] = OSD.FromBoolean(child);
208 args["circuit_code"] = OSD.FromString(circuitcode.ToString());
209 args["first_name"] = OSD.FromString(firstname);
210 args["last_name"] = OSD.FromString(lastname);
211 args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
212 args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
213 args["session_id"] = OSD.FromUUID(SessionID);
214
215 args["service_session_id"] = OSD.FromString(ServiceSessionID);
216 args["start_pos"] = OSD.FromString(startpos.ToString());
217 args["client_ip"] = OSD.FromString(IPAddress);
218 args["viewer"] = OSD.FromString(Viewer);
219 args["channel"] = OSD.FromString(Channel);
220 args["mac"] = OSD.FromString(Mac);
221 args["id0"] = OSD.FromString(Id0);
222
223 if (Appearance != null)
224 {
225 args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
226
227 OSDMap appmap = Appearance.Pack();
228 args["packed_appearance"] = appmap;
229 }
230
231 // Old, bad way. Keeping it fow now for backwards compatibility
232 // OBSOLETE -- soon to be deleted
233 if (ServiceURLs != null && ServiceURLs.Count > 0)
234 {
235 OSDArray urls = new OSDArray(ServiceURLs.Count * 2);
236 foreach (KeyValuePair<string, object> kvp in ServiceURLs)
237 {
238 //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
239 urls.Add(OSD.FromString(kvp.Key));
240 urls.Add(OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString()));
241 }
242 args["service_urls"] = urls;
243 }
244
245 // again, this time the right way
246 if (ServiceURLs != null && ServiceURLs.Count > 0)
247 {
248 OSDMap urls = new OSDMap();
249 foreach (KeyValuePair<string, object> kvp in ServiceURLs)
250 {
251 //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
252 urls[kvp.Key] = OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString());
253 }
254 args["serviceurls"] = urls;
255 }
256
257
258 return args;
259 }
260
261 /// <summary>
262 /// Unpack agent circuit data map into an AgentCiruitData object
263 /// </summary>
264 /// <param name="args"></param>
265 public void UnpackAgentCircuitData(OSDMap args)
266 {
267 if (args["agent_id"] != null)
268 AgentID = args["agent_id"].AsUUID();
269 if (args["base_folder"] != null)
270 BaseFolder = args["base_folder"].AsUUID();
271 if (args["caps_path"] != null)
272 CapsPath = args["caps_path"].AsString();
273
274 if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
275 {
276 OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
277 ChildrenCapSeeds = new Dictionary<ulong, string>();
278 foreach (OSD o in childrenSeeds)
279 {
280 if (o.Type == OSDType.Map)
281 {
282 ulong handle = 0;
283 string seed = "";
284 OSDMap pair = (OSDMap)o;
285 if (pair["handle"] != null)
286 if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
287 continue;
288 if (pair["seed"] != null)
289 seed = pair["seed"].AsString();
290 if (!ChildrenCapSeeds.ContainsKey(handle))
291 ChildrenCapSeeds.Add(handle, seed);
292 }
293 }
294 }
295 else
296 ChildrenCapSeeds = new Dictionary<ulong, string>();
297
298 if (args["child"] != null)
299 child = args["child"].AsBoolean();
300 if (args["circuit_code"] != null)
301 UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
302 if (args["first_name"] != null)
303 firstname = args["first_name"].AsString();
304 if (args["last_name"] != null)
305 lastname = args["last_name"].AsString();
306 if (args["inventory_folder"] != null)
307 InventoryFolder = args["inventory_folder"].AsUUID();
308 if (args["secure_session_id"] != null)
309 SecureSessionID = args["secure_session_id"].AsUUID();
310 if (args["session_id"] != null)
311 SessionID = args["session_id"].AsUUID();
312 if (args["service_session_id"] != null)
313 ServiceSessionID = args["service_session_id"].AsString();
314 if (args["client_ip"] != null)
315 IPAddress = args["client_ip"].AsString();
316 if (args["viewer"] != null)
317 Viewer = args["viewer"].AsString();
318 if (args["channel"] != null)
319 Channel = args["channel"].AsString();
320 if (args["mac"] != null)
321 Mac = args["mac"].AsString();
322 if (args["id0"] != null)
323 Id0 = args["id0"].AsString();
324 if (args["teleport_flags"] != null)
325 teleportFlags = args["teleport_flags"].AsUInteger();
326
327 if (args["start_pos"] != null)
328 Vector3.TryParse(args["start_pos"].AsString(), out startpos);
329
330 //m_log.InfoFormat("[AGENTCIRCUITDATA]: agentid={0}, child={1}, startpos={2}", AgentID, child, startpos);
331
332 try
333 {
334 // Unpack various appearance elements
335 Appearance = new AvatarAppearance();
336
337 // Eventually this code should be deprecated, use full appearance
338 // packing in packed_appearance
339 if (args["appearance_serial"] != null)
340 Appearance.Serial = args["appearance_serial"].AsInteger();
341
342 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
343 {
344 Appearance.Unpack((OSDMap)args["packed_appearance"]);
345// m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
346 }
347 else
348 {
349 m_log.Warn("[AGENTCIRCUITDATA]: failed to find a valid packed_appearance");
350 }
351 }
352 catch (Exception e)
353 {
354 m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
355 }
356
357 ServiceURLs = new Dictionary<string, object>();
358 // Try parse the new way, OSDMap
359 if (args.ContainsKey("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
360 {
361 OSDMap urls = (OSDMap)(args["serviceurls"]);
362 foreach (KeyValuePair<String, OSD> kvp in urls)
363 {
364 ServiceURLs[kvp.Key] = kvp.Value.AsString();
365 //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);
366
367 }
368 }
369 // else try the old way, OSDArray
370 // OBSOLETE -- soon to be deleted
371 else if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
372 {
373 OSDArray urls = (OSDArray)(args["service_urls"]);
374 for (int i = 0; i < urls.Count / 2; i++)
375 {
376 ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
377 //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
378
379 }
380 }
381 }
382
383 }
384
385
386}