clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using System.Reflection;
30 using System.Collections.Generic;
31 using log4net;
32 using OpenMetaverse;
33 using OpenMetaverse.StructuredData;
34  
35 namespace 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 public string Viewer;
132  
133 /// <summary>
134 /// The channel strinf sent by the viewer at login
135 /// </summary>
136 public string Channel;
137  
138 /// <summary>
139 /// The Mac address as reported by the viewer at login
140 /// </summary>
141 public string Mac;
142  
143 /// <summary>
144 /// The id0 as reported by the viewer at login
145 /// </summary>
146 public string Id0;
147  
148 /// <summary>
149 /// Position the Agent's Avatar starts in the region
150 /// </summary>
151 public Vector3 startpos;
152  
153 public Dictionary<string, object> ServiceURLs;
154  
155 public AgentCircuitData()
156 {
157 }
158  
159 /// <summary>
160 /// Pack AgentCircuitData into an OSDMap for transmission over LLSD XML or LLSD json
161 /// </summary>
162 /// <returns>map of the agent circuit data</returns>
163 public OSDMap PackAgentCircuitData()
164 {
165 OSDMap args = new OSDMap();
166 args["agent_id"] = OSD.FromUUID(AgentID);
167 args["base_folder"] = OSD.FromUUID(BaseFolder);
168 args["caps_path"] = OSD.FromString(CapsPath);
169  
170 if (ChildrenCapSeeds != null)
171 {
172 OSDArray childrenSeeds = new OSDArray(ChildrenCapSeeds.Count);
173 foreach (KeyValuePair<ulong, string> kvp in ChildrenCapSeeds)
174 {
175 OSDMap pair = new OSDMap();
176 pair["handle"] = OSD.FromString(kvp.Key.ToString());
177 pair["seed"] = OSD.FromString(kvp.Value);
178 childrenSeeds.Add(pair);
179 }
180 if (ChildrenCapSeeds.Count > 0)
181 args["children_seeds"] = childrenSeeds;
182 }
183 args["child"] = OSD.FromBoolean(child);
184 args["circuit_code"] = OSD.FromString(circuitcode.ToString());
185 args["first_name"] = OSD.FromString(firstname);
186 args["last_name"] = OSD.FromString(lastname);
187 args["inventory_folder"] = OSD.FromUUID(InventoryFolder);
188 args["secure_session_id"] = OSD.FromUUID(SecureSessionID);
189 args["session_id"] = OSD.FromUUID(SessionID);
190  
191 args["service_session_id"] = OSD.FromString(ServiceSessionID);
192 args["start_pos"] = OSD.FromString(startpos.ToString());
193 args["client_ip"] = OSD.FromString(IPAddress);
194 args["viewer"] = OSD.FromString(Viewer);
195 args["channel"] = OSD.FromString(Channel);
196 args["mac"] = OSD.FromString(Mac);
197 args["id0"] = OSD.FromString(Id0);
198  
199 if (Appearance != null)
200 {
201 args["appearance_serial"] = OSD.FromInteger(Appearance.Serial);
202  
203 OSDMap appmap = Appearance.Pack();
204 args["packed_appearance"] = appmap;
205 }
206  
207 // Old, bad way. Keeping it fow now for backwards compatibility
208 // OBSOLETE -- soon to be deleted
209 if (ServiceURLs != null && ServiceURLs.Count > 0)
210 {
211 OSDArray urls = new OSDArray(ServiceURLs.Count * 2);
212 foreach (KeyValuePair<string, object> kvp in ServiceURLs)
213 {
214 //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
215 urls.Add(OSD.FromString(kvp.Key));
216 urls.Add(OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString()));
217 }
218 args["service_urls"] = urls;
219 }
220  
221 // again, this time the right way
222 if (ServiceURLs != null && ServiceURLs.Count > 0)
223 {
224 OSDMap urls = new OSDMap();
225 foreach (KeyValuePair<string, object> kvp in ServiceURLs)
226 {
227 //System.Console.WriteLine("XXX " + kvp.Key + "=" + kvp.Value);
228 urls[kvp.Key] = OSD.FromString((kvp.Value == null) ? string.Empty : kvp.Value.ToString());
229 }
230 args["serviceurls"] = urls;
231 }
232  
233  
234 return args;
235 }
236  
237 /// <summary>
238 /// Unpack agent circuit data map into an AgentCiruitData object
239 /// </summary>
240 /// <param name="args"></param>
241 public void UnpackAgentCircuitData(OSDMap args)
242 {
243 if (args["agent_id"] != null)
244 AgentID = args["agent_id"].AsUUID();
245 if (args["base_folder"] != null)
246 BaseFolder = args["base_folder"].AsUUID();
247 if (args["caps_path"] != null)
248 CapsPath = args["caps_path"].AsString();
249  
250 if ((args["children_seeds"] != null) && (args["children_seeds"].Type == OSDType.Array))
251 {
252 OSDArray childrenSeeds = (OSDArray)(args["children_seeds"]);
253 ChildrenCapSeeds = new Dictionary<ulong, string>();
254 foreach (OSD o in childrenSeeds)
255 {
256 if (o.Type == OSDType.Map)
257 {
258 ulong handle = 0;
259 string seed = "";
260 OSDMap pair = (OSDMap)o;
261 if (pair["handle"] != null)
262 if (!UInt64.TryParse(pair["handle"].AsString(), out handle))
263 continue;
264 if (pair["seed"] != null)
265 seed = pair["seed"].AsString();
266 if (!ChildrenCapSeeds.ContainsKey(handle))
267 ChildrenCapSeeds.Add(handle, seed);
268 }
269 }
270 }
271 else
272 ChildrenCapSeeds = new Dictionary<ulong, string>();
273  
274 if (args["child"] != null)
275 child = args["child"].AsBoolean();
276 if (args["circuit_code"] != null)
277 UInt32.TryParse(args["circuit_code"].AsString(), out circuitcode);
278 if (args["first_name"] != null)
279 firstname = args["first_name"].AsString();
280 if (args["last_name"] != null)
281 lastname = args["last_name"].AsString();
282 if (args["inventory_folder"] != null)
283 InventoryFolder = args["inventory_folder"].AsUUID();
284 if (args["secure_session_id"] != null)
285 SecureSessionID = args["secure_session_id"].AsUUID();
286 if (args["session_id"] != null)
287 SessionID = args["session_id"].AsUUID();
288 if (args["service_session_id"] != null)
289 ServiceSessionID = args["service_session_id"].AsString();
290 if (args["client_ip"] != null)
291 IPAddress = args["client_ip"].AsString();
292 if (args["viewer"] != null)
293 Viewer = args["viewer"].AsString();
294 if (args["channel"] != null)
295 Channel = args["channel"].AsString();
296 if (args["mac"] != null)
297 Mac = args["mac"].AsString();
298 if (args["id0"] != null)
299 Id0 = args["id0"].AsString();
300  
301 if (args["start_pos"] != null)
302 Vector3.TryParse(args["start_pos"].AsString(), out startpos);
303  
304 //m_log.InfoFormat("[AGENTCIRCUITDATA]: agentid={0}, child={1}, startpos={2}", AgentID, child, startpos);
305  
306 try
307 {
308 // Unpack various appearance elements
309 Appearance = new AvatarAppearance();
310  
311 // Eventually this code should be deprecated, use full appearance
312 // packing in packed_appearance
313 if (args["appearance_serial"] != null)
314 Appearance.Serial = args["appearance_serial"].AsInteger();
315  
316 if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
317 {
318 Appearance.Unpack((OSDMap)args["packed_appearance"]);
319 // m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
320 }
321 else
322 {
323 m_log.Warn("[AGENTCIRCUITDATA]: failed to find a valid packed_appearance");
324 }
325 }
326 catch (Exception e)
327 {
328 m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
329 }
330  
331 ServiceURLs = new Dictionary<string, object>();
332 // Try parse the new way, OSDMap
333 if (args.ContainsKey("serviceurls") && args["serviceurls"] != null && (args["serviceurls"]).Type == OSDType.Map)
334 {
335 OSDMap urls = (OSDMap)(args["serviceurls"]);
336 foreach (KeyValuePair<String, OSD> kvp in urls)
337 {
338 ServiceURLs[kvp.Key] = kvp.Value.AsString();
339 //System.Console.WriteLine("XXX " + kvp.Key + "=" + ServiceURLs[kvp.Key]);
340  
341 }
342 }
343 // else try the old way, OSDArray
344 // OBSOLETE -- soon to be deleted
345 else if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array)
346 {
347 OSDArray urls = (OSDArray)(args["service_urls"]);
348 for (int i = 0; i < urls.Count / 2; i++)
349 {
350 ServiceURLs[urls[i * 2].AsString()] = urls[(i * 2) + 1].AsString();
351 //System.Console.WriteLine("XXX " + urls[i * 2].AsString() + "=" + urls[(i * 2) + 1].AsString());
352  
353 }
354 }
355 }
356  
357 }
358  
359  
360 }