clockwerk-opensim – 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.Collections;
30 using System.Collections.Generic;
31 using System.Net;
32 using System.Reflection;
33  
34 using OpenSim.Framework;
35 using OpenSim.Services.Interfaces;
36 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37 using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
38  
39 using log4net;
40 using OpenMetaverse;
41 using OpenMetaverse.StructuredData;
42 using OSDArray = OpenMetaverse.StructuredData.OSDArray;
43 using OSDMap = OpenMetaverse.StructuredData.OSDMap;
44  
45 namespace OpenSim.Services.LLLoginService
46 {
47 public class LLFailedLoginResponse : OpenSim.Services.Interfaces.FailedLoginResponse
48 {
49 protected string m_key;
50 protected string m_value;
51 protected string m_login;
52  
53 public static LLFailedLoginResponse UserProblem;
54 public static LLFailedLoginResponse GridProblem;
55 public static LLFailedLoginResponse InventoryProblem;
56 public static LLFailedLoginResponse DeadRegionProblem;
57 public static LLFailedLoginResponse LoginBlockedProblem;
58 public static LLFailedLoginResponse AlreadyLoggedInProblem;
59 public static LLFailedLoginResponse InternalError;
60  
61 static LLFailedLoginResponse()
62 {
63 UserProblem = new LLFailedLoginResponse("key",
64 "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
65 "false");
66 GridProblem = new LLFailedLoginResponse("key",
67 "Error connecting to the desired location. Try connecting to another region.",
68 "false");
69 InventoryProblem = new LLFailedLoginResponse("key",
70 "The inventory service is not responding. Please notify your login region operator.",
71 "false");
72 DeadRegionProblem = new LLFailedLoginResponse("key",
73 "The region you are attempting to log into is not responding. Please select another region and try again.",
74 "false");
75 LoginBlockedProblem = new LLFailedLoginResponse("presence",
76 "Logins are currently restricted. Please try again later.",
77 "false");
78 AlreadyLoggedInProblem = new LLFailedLoginResponse("presence",
79 "You appear to be already logged in. " +
80 "If this is not the case please wait for your session to timeout. " +
81 "If this takes longer than a few minutes please contact the grid owner. " +
82 "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.",
83 "false");
84 InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false");
85 }
86  
87 public LLFailedLoginResponse(string key, string value, string login)
88 {
89 m_key = key;
90 m_value = value;
91 m_login = login;
92 }
93  
94 public override Hashtable ToHashtable()
95 {
96 Hashtable loginError = new Hashtable();
97 loginError["reason"] = m_key;
98 loginError["message"] = m_value;
99 loginError["login"] = m_login;
100 return loginError;
101 }
102  
103 public override OSD ToOSDMap()
104 {
105 OSDMap map = new OSDMap();
106  
107 map["reason"] = OSD.FromString(m_key);
108 map["message"] = OSD.FromString(m_value);
109 map["login"] = OSD.FromString(m_login);
110  
111 return map;
112 }
113 }
114  
115 /// <summary>
116 /// A class to handle LL login response.
117 /// </summary>
118 public class LLLoginResponse : OpenSim.Services.Interfaces.LoginResponse
119 {
120 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
121 private static Hashtable globalTexturesHash;
122 // Global Textures
123 private static string sunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
124 private static string cloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
125 private static string moonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
126  
127 private Hashtable loginFlagsHash;
128 private Hashtable uiConfigHash;
129  
130 private ArrayList loginFlags;
131 private ArrayList globalTextures;
132 private ArrayList eventCategories;
133 private ArrayList uiConfig;
134 private ArrayList classifiedCategories;
135 private ArrayList inventoryRoot;
136 private ArrayList initialOutfit;
137 private ArrayList agentInventory;
138 private ArrayList inventoryLibraryOwner;
139 private ArrayList inventoryLibRoot;
140 private ArrayList inventoryLibrary;
141 private ArrayList activeGestures;
142  
143 private UserInfo userProfile;
144  
145 private UUID agentID;
146 private UUID sessionID;
147 private UUID secureSessionID;
148  
149 // Login Flags
150 private string dst;
151 private string stipendSinceLogin;
152 private string gendered;
153 private string everLoggedIn;
154 private string login;
155 private uint simPort;
156 private uint simHttpPort;
157 private string simAddress;
158 private string agentAccess;
159 private string agentAccessMax;
160 private Int32 circuitCode;
161 private uint regionX;
162 private uint regionY;
163  
164 // Login
165 private string firstname;
166 private string lastname;
167  
168 // Web map
169 private string mapTileURL;
170  
171 // Web Profiles
172 private string profileURL;
173  
174 // OpenID
175 private string openIDURL;
176  
177 private string searchURL;
178  
179 // Error Flags
180 private string errorReason;
181 private string errorMessage;
182  
183 private string welcomeMessage;
184 private string startLocation;
185 private string allowFirstLife;
186 private string home;
187 private string seedCapability;
188 private string lookAt;
189  
190 private BuddyList m_buddyList = null;
191  
192 private string currency;
193 private string classifiedFee;
194  
195 static LLLoginResponse()
196 {
197 // This is being set, but it's not used
198 // not sure why.
199 globalTexturesHash = new Hashtable();
200 globalTexturesHash["sun_texture_id"] = sunTexture;
201 globalTexturesHash["cloud_texture_id"] = cloudTexture;
202 globalTexturesHash["moon_texture_id"] = moonTexture;
203 }
204  
205 public LLLoginResponse()
206 {
207 loginFlags = new ArrayList();
208 globalTextures = new ArrayList();
209 eventCategories = new ArrayList();
210 uiConfig = new ArrayList();
211 classifiedCategories = new ArrayList();
212  
213 uiConfigHash = new Hashtable();
214  
215 // defaultXmlRpcResponse = new XmlRpcResponse();
216 userProfile = new UserInfo();
217 inventoryRoot = new ArrayList();
218 initialOutfit = new ArrayList();
219 agentInventory = new ArrayList();
220 inventoryLibrary = new ArrayList();
221 inventoryLibraryOwner = new ArrayList();
222 activeGestures = new ArrayList();
223  
224 SetDefaultValues();
225 }
226  
227 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo,
228 GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService,
229 string where, string startlocation, Vector3 position, Vector3 lookAt, List<InventoryItemBase> gestures, string message,
230 GridRegion home, IPEndPoint clientIP, string mapTileURL, string searchURL, string currency,
231 string DSTZone, string destinationsURL, string avatarsURL, string classifiedFee)
232 : this()
233 {
234 FillOutInventoryData(invSkel, libService);
235  
236 FillOutActiveGestures(gestures);
237  
238 CircuitCode = (int)aCircuit.circuitcode;
239 Lastname = account.LastName;
240 Firstname = account.FirstName;
241 AgentID = account.PrincipalID;
242 SessionID = aCircuit.SessionID;
243 SecureSessionID = aCircuit.SecureSessionID;
244 Message = message;
245 BuddList = ConvertFriendListItem(friendsList);
246 StartLocation = where;
247 MapTileURL = mapTileURL;
248 ProfileURL = profileURL;
249 OpenIDURL = openIDURL;
250 DestinationsURL = destinationsURL;
251 AvatarsURL = avatarsURL;
252  
253 SearchURL = searchURL;
254 Currency = currency;
255 ClassifiedFee = classifiedFee;
256  
257 FillOutHomeData(pinfo, home);
258 LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);
259  
260 FillOutRegionData(destination);
261 m_log.DebugFormat("[LOGIN RESPONSE] LLLoginResponse create. sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY);
262  
263 FillOutSeedCap(aCircuit, destination, clientIP);
264  
265 switch (DSTZone)
266 {
267 case "none":
268 DST = "N";
269 break;
270 case "local":
271 DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
272 break;
273 default:
274 TimeZoneInfo dstTimeZone = null;
275 string[] tzList = DSTZone.Split(';');
276  
277 foreach (string tzName in tzList)
278 {
279 try
280 {
281 dstTimeZone = TimeZoneInfo.FindSystemTimeZoneById(tzName);
282 }
283 catch
284 {
285 continue;
286 }
287 break;
288 }
289  
290 if (dstTimeZone == null)
291 {
292 m_log.WarnFormat(
293 "[LLOGIN RESPONSE]: No valid timezone found for DST in {0}, falling back to system time.", tzList);
294 DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
295 }
296 else
297 {
298 DST = dstTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
299 }
300  
301 break;
302 }
303 }
304  
305 private void FillOutInventoryData(List<InventoryFolderBase> invSkel, ILibraryService libService)
306 {
307 InventoryData inventData = null;
308  
309 try
310 {
311 inventData = GetInventorySkeleton(invSkel);
312 }
313 catch (Exception e)
314 {
315 m_log.WarnFormat(
316 "[LLLOGIN SERVICE]: Error processing inventory skeleton of agent {0} - {1}",
317 agentID, e);
318  
319 // ignore and continue
320 }
321  
322 if (inventData != null)
323 {
324 ArrayList AgentInventoryArray = inventData.InventoryArray;
325  
326 Hashtable InventoryRootHash = new Hashtable();
327 InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
328 InventoryRoot = new ArrayList();
329 InventoryRoot.Add(InventoryRootHash);
330 InventorySkeleton = AgentInventoryArray;
331 }
332  
333 // Inventory Library Section
334 if (libService != null && libService.LibraryRootFolder != null)
335 {
336 Hashtable InventoryLibRootHash = new Hashtable();
337 InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
338 InventoryLibRoot = new ArrayList();
339 InventoryLibRoot.Add(InventoryLibRootHash);
340  
341 InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder);
342 InventoryLibrary = GetInventoryLibrary(libService);
343 }
344 }
345  
346 private void FillOutActiveGestures(List<InventoryItemBase> gestures)
347 {
348 ArrayList list = new ArrayList();
349 if (gestures != null)
350 {
351 foreach (InventoryItemBase gesture in gestures)
352 {
353 Hashtable item = new Hashtable();
354 item["item_id"] = gesture.ID.ToString();
355 item["asset_id"] = gesture.AssetID.ToString();
356 list.Add(item);
357 }
358 }
359 ActiveGestures = list;
360 }
361  
362 private void FillOutHomeData(GridUserInfo pinfo, GridRegion home)
363 {
364 int x = (int)Util.RegionToWorldLoc(1000);
365 int y = (int)Util.RegionToWorldLoc(1000);
366 if (home != null)
367 {
368 x = home.RegionLocX;
369 y = home.RegionLocY;
370 }
371  
372 Home = string.Format(
373 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
374 x,
375 y,
376 pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z,
377 pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z);
378  
379 }
380  
381 private void FillOutRegionData(GridRegion destination)
382 {
383 IPEndPoint endPoint = destination.ExternalEndPoint;
384 SimAddress = endPoint.Address.ToString();
385 SimPort = (uint)endPoint.Port;
386 RegionX = (uint)destination.RegionLocX;
387 RegionY = (uint)destination.RegionLocY;
388 RegionSizeX = destination.RegionSizeX;
389 RegionSizeY = destination.RegionSizeY;
390 }
391  
392 private void FillOutSeedCap(AgentCircuitData aCircuit, GridRegion destination, IPEndPoint ipepClient)
393 {
394 SeedCapability = destination.ServerURI + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
395 }
396  
397 private void SetDefaultValues()
398 {
399 TimeZoneInfo gridTimeZone;
400  
401 // Disabled for now pending making timezone a config value, which can at some point have a default of
402 // a ; separated list of possible timezones.
403 // The problem here is that US/Pacific (or even the Olsen America/Los_Angeles) is not universal across
404 // windows, mac and various distributions of linux, introducing another element of consistency.
405 // The server operator needs to be able to control this setting
406 // try
407 // {
408 // // First try to fetch DST from Pacific Standard Time, because this is
409 // // the one expected by the viewer. "US/Pacific" is the string to search
410 // // on linux and mac, and should work also on Windows (to confirm)
411 // gridTimeZone = TimeZoneInfo.FindSystemTimeZoneById("US/Pacific");
412 // }
413 // catch (Exception e)
414 // {
415 // m_log.WarnFormat(
416 // "[TIMEZONE]: {0} Falling back to system time. System time should be set to Pacific Standard Time to provide the expected time",
417 // e.Message);
418  
419 gridTimeZone = TimeZoneInfo.Local;
420 // }
421  
422 DST = gridTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
423  
424 StipendSinceLogin = "N";
425 Gendered = "Y";
426 EverLoggedIn = "Y";
427 login = "false";
428 firstname = "Test";
429 lastname = "User";
430 agentAccess = "M";
431 agentAccessMax = "A";
432 startLocation = "last";
433 allowFirstLife = "Y";
434  
435 ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
436 ErrorReason = "key";
437 welcomeMessage = "Welcome to OpenSim!";
438 seedCapability = String.Empty;
439 home = "{'region_handle':["
440 + "r" + Util.RegionToWorldLoc(1000).ToString()
441 + ","
442 + "r" + Util.RegionToWorldLoc(1000).ToString()
443 + "], 'position':["
444 + "r" + userProfile.homepos.X.ToString()
445 + ","
446 + "r" + userProfile.homepos.Y.ToString()
447 + ","
448 + "r" + userProfile.homepos.Z.ToString()
449 + "], 'look_at':["
450 + "r" + userProfile.homelookat.X.ToString()
451 + ","
452 + "r" + userProfile.homelookat.Y.ToString()
453 + ","
454 + "r" + userProfile.homelookat.Z.ToString()
455 + "]}";
456 lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
457 RegionX = (uint) 255232;
458 RegionY = (uint) 254976;
459  
460 // Classifieds;
461 AddClassifiedCategory((Int32) 1, "Shopping");
462 AddClassifiedCategory((Int32) 2, "Land Rental");
463 AddClassifiedCategory((Int32) 3, "Property Rental");
464 AddClassifiedCategory((Int32) 4, "Special Attraction");
465 AddClassifiedCategory((Int32) 5, "New Products");
466 AddClassifiedCategory((Int32) 6, "Employment");
467 AddClassifiedCategory((Int32) 7, "Wanted");
468 AddClassifiedCategory((Int32) 8, "Service");
469 AddClassifiedCategory((Int32) 9, "Personal");
470  
471 SessionID = UUID.Random();
472 SecureSessionID = UUID.Random();
473 AgentID = UUID.Random();
474  
475 Hashtable InitialOutfitHash = new Hashtable();
476 InitialOutfitHash["folder_name"] = "Nightclub Female";
477 InitialOutfitHash["gender"] = "female";
478 initialOutfit.Add(InitialOutfitHash);
479 mapTileURL = String.Empty;
480 profileURL = String.Empty;
481 openIDURL = String.Empty;
482 searchURL = String.Empty;
483  
484 currency = String.Empty;
485 ClassifiedFee = "0";
486 }
487  
488  
489 public override Hashtable ToHashtable()
490 {
491 try
492 {
493 Hashtable responseData = new Hashtable();
494  
495 loginFlagsHash = new Hashtable();
496 loginFlagsHash["daylight_savings"] = DST;
497 loginFlagsHash["stipend_since_login"] = StipendSinceLogin;
498 loginFlagsHash["gendered"] = Gendered;
499 loginFlagsHash["ever_logged_in"] = EverLoggedIn;
500 loginFlags.Add(loginFlagsHash);
501  
502 responseData["first_name"] = Firstname;
503 responseData["last_name"] = Lastname;
504 responseData["agent_access"] = agentAccess;
505 responseData["agent_access_max"] = agentAccessMax;
506  
507 globalTextures.Add(globalTexturesHash);
508 // this.eventCategories.Add(this.eventCategoriesHash);
509  
510 AddToUIConfig("allow_first_life", allowFirstLife);
511 uiConfig.Add(uiConfigHash);
512  
513 responseData["sim_port"] = (Int32) SimPort;
514 responseData["sim_ip"] = SimAddress;
515 responseData["http_port"] = (Int32)SimHttpPort;
516  
517 responseData["agent_id"] = AgentID.ToString();
518 responseData["session_id"] = SessionID.ToString();
519 responseData["secure_session_id"] = SecureSessionID.ToString();
520 responseData["circuit_code"] = CircuitCode;
521 responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
522 responseData["login-flags"] = loginFlags;
523 responseData["global-textures"] = globalTextures;
524 responseData["seed_capability"] = seedCapability;
525  
526 responseData["event_categories"] = eventCategories;
527 responseData["event_notifications"] = new ArrayList(); // todo
528 responseData["classified_categories"] = classifiedCategories;
529 responseData["ui-config"] = uiConfig;
530  
531 if (agentInventory != null)
532 {
533 responseData["inventory-skeleton"] = agentInventory;
534 responseData["inventory-root"] = inventoryRoot;
535 }
536 responseData["inventory-skel-lib"] = inventoryLibrary;
537 responseData["inventory-lib-root"] = inventoryLibRoot;
538 responseData["gestures"] = activeGestures;
539 responseData["inventory-lib-owner"] = inventoryLibraryOwner;
540 responseData["initial-outfit"] = initialOutfit;
541 responseData["start_location"] = startLocation;
542 responseData["seed_capability"] = seedCapability;
543 responseData["home"] = home;
544 responseData["look_at"] = lookAt;
545 responseData["message"] = welcomeMessage;
546 responseData["region_x"] = (Int32)(RegionX);
547 responseData["region_y"] = (Int32)(RegionY);
548 responseData["region_size_x"] = (Int32)RegionSizeX;
549 responseData["region_size_y"] = (Int32)RegionSizeY;
550 m_log.DebugFormat("[LOGIN RESPONSE] returning sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY);
551  
552 if (searchURL != String.Empty)
553 responseData["search"] = searchURL;
554  
555 if (mapTileURL != String.Empty)
556 responseData["map-server-url"] = mapTileURL;
557  
558 if (profileURL != String.Empty)
559 responseData["profile-server-url"] = profileURL;
560  
561 if (DestinationsURL != String.Empty)
562 responseData["destination_guide_url"] = DestinationsURL;
563  
564 if (AvatarsURL != String.Empty)
565 responseData["avatar_picker_url"] = AvatarsURL;
566  
567 // We need to send an openid_token back in the response too
568 if (openIDURL != String.Empty)
569 responseData["openid_url"] = openIDURL;
570  
571 if (m_buddyList != null)
572 {
573 responseData["buddy-list"] = m_buddyList.ToArray();
574 }
575  
576 if (currency != String.Empty)
577 {
578 // responseData["real_currency"] = currency;
579 responseData["currency"] = currency;
580 }
581  
582 if (ClassifiedFee != String.Empty)
583 responseData["classified_fee"] = ClassifiedFee;
584  
585 responseData["login"] = "true";
586  
587 return responseData;
588 }
589 catch (Exception e)
590 {
591 m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message);
592  
593 return LLFailedLoginResponse.InternalError.ToHashtable();
594 }
595 }
596  
597 public override OSD ToOSDMap()
598 {
599 try
600 {
601 OSDMap map = new OSDMap();
602  
603 map["first_name"] = OSD.FromString(Firstname);
604 map["last_name"] = OSD.FromString(Lastname);
605 map["agent_access"] = OSD.FromString(agentAccess);
606 map["agent_access_max"] = OSD.FromString(agentAccessMax);
607  
608 map["sim_port"] = OSD.FromInteger(SimPort);
609 map["sim_ip"] = OSD.FromString(SimAddress);
610  
611 map["agent_id"] = OSD.FromUUID(AgentID);
612 map["session_id"] = OSD.FromUUID(SessionID);
613 map["secure_session_id"] = OSD.FromUUID(SecureSessionID);
614 map["circuit_code"] = OSD.FromInteger(CircuitCode);
615 map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
616  
617 #region Login Flags
618  
619 OSDMap loginFlagsLLSD = new OSDMap();
620 loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST);
621 loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin);
622 loginFlagsLLSD["gendered"] = OSD.FromString(Gendered);
623 loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn);
624 map["login-flags"] = WrapOSDMap(loginFlagsLLSD);
625  
626 #endregion Login Flags
627  
628 #region Global Textures
629  
630 OSDMap globalTexturesLLSD = new OSDMap();
631 globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture);
632 globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture);
633 globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture);
634  
635 map["global-textures"] = WrapOSDMap(globalTexturesLLSD);
636  
637 #endregion Global Textures
638  
639 map["seed_capability"] = OSD.FromString(seedCapability);
640  
641 map["event_categories"] = ArrayListToOSDArray(eventCategories);
642 //map["event_notifications"] = new OSDArray(); // todo
643 map["classified_categories"] = ArrayListToOSDArray(classifiedCategories);
644  
645 #region UI Config
646  
647 OSDMap uiConfigLLSD = new OSDMap();
648 uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife);
649 map["ui-config"] = WrapOSDMap(uiConfigLLSD);
650  
651 #endregion UI Config
652  
653 #region Inventory
654  
655 map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory);
656  
657 map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary);
658 map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ;
659 map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot);
660 map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner);
661  
662 #endregion Inventory
663  
664 map["gestures"] = ArrayListToOSDArray(activeGestures);
665  
666 map["initial-outfit"] = ArrayListToOSDArray(initialOutfit);
667 map["start_location"] = OSD.FromString(startLocation);
668  
669 map["seed_capability"] = OSD.FromString(seedCapability);
670 map["home"] = OSD.FromString(home);
671 map["look_at"] = OSD.FromString(lookAt);
672 map["message"] = OSD.FromString(welcomeMessage);
673 map["region_x"] = OSD.FromInteger(RegionX);
674 map["region_y"] = OSD.FromInteger(RegionY);
675  
676 if (mapTileURL != String.Empty)
677 map["map-server-url"] = OSD.FromString(mapTileURL);
678  
679 if (profileURL != String.Empty)
680 map["profile-server-url"] = OSD.FromString(profileURL);
681  
682 if (openIDURL != String.Empty)
683 map["openid_url"] = OSD.FromString(openIDURL);
684  
685 if (searchURL != String.Empty)
686 map["search"] = OSD.FromString(searchURL);
687  
688 if (ClassifiedFee != String.Empty)
689 map["classified_fee"] = OSD.FromString(ClassifiedFee);
690  
691 if (m_buddyList != null)
692 {
693 map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray());
694 }
695  
696 map["login"] = OSD.FromString("true");
697  
698 return map;
699 }
700 catch (Exception e)
701 {
702 m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message);
703  
704 return LLFailedLoginResponse.InternalError.ToOSDMap();
705 }
706 }
707  
708 public OSDArray ArrayListToOSDArray(ArrayList arrlst)
709 {
710 OSDArray llsdBack = new OSDArray();
711 foreach (Hashtable ht in arrlst)
712 {
713 OSDMap mp = new OSDMap();
714 foreach (DictionaryEntry deHt in ht)
715 {
716 mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value));
717 }
718 llsdBack.Add(mp);
719 }
720 return llsdBack;
721 }
722  
723 private static OSDArray WrapOSDMap(OSDMap wrapMe)
724 {
725 OSDArray array = new OSDArray();
726 array.Add(wrapMe);
727 return array;
728 }
729  
730 public void SetEventCategories(string category, string value)
731 {
732 // this.eventCategoriesHash[category] = value;
733 //TODO
734 }
735  
736 public void AddToUIConfig(string itemName, string item)
737 {
738 uiConfigHash[itemName] = item;
739 }
740  
741 public void AddClassifiedCategory(Int32 ID, string categoryName)
742 {
743 Hashtable hash = new Hashtable();
744 hash["category_name"] = categoryName;
745 hash["category_id"] = ID;
746 classifiedCategories.Add(hash);
747 // this.classifiedCategoriesHash.Clear();
748 }
749  
750  
751 private static LLLoginResponse.BuddyList ConvertFriendListItem(FriendInfo[] friendsList)
752 {
753 LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList();
754 foreach (FriendInfo finfo in friendsList)
755 {
756 if (finfo.TheirFlags == -1)
757 continue;
758 LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend);
759 // finfo.Friend may not be a simple uuid
760 UUID friendID = UUID.Zero;
761 if (UUID.TryParse(finfo.Friend, out friendID))
762 buddyitem.BuddyID = finfo.Friend;
763 else
764 {
765 string tmp;
766 if (Util.ParseUniversalUserIdentifier(finfo.Friend, out friendID, out tmp, out tmp, out tmp, out tmp))
767 buddyitem.BuddyID = friendID.ToString();
768 else
769 // junk entry
770 continue;
771 }
772 buddyitem.BuddyRightsHave = (int)finfo.TheirFlags;
773 buddyitem.BuddyRightsGiven = (int)finfo.MyFlags;
774 buddylistreturn.AddNewBuddy(buddyitem);
775 }
776 return buddylistreturn;
777 }
778  
779 private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
780 {
781 UUID rootID = UUID.Zero;
782 ArrayList AgentInventoryArray = new ArrayList();
783 Hashtable TempHash;
784 foreach (InventoryFolderBase InvFolder in folders)
785 {
786 if (InvFolder.ParentID == UUID.Zero && InvFolder.Name == "My Inventory")
787 {
788 rootID = InvFolder.ID;
789 }
790 TempHash = new Hashtable();
791 TempHash["name"] = InvFolder.Name;
792 TempHash["parent_id"] = InvFolder.ParentID.ToString();
793 TempHash["version"] = (Int32)InvFolder.Version;
794 TempHash["type_default"] = (Int32)InvFolder.Type;
795 TempHash["folder_id"] = InvFolder.ID.ToString();
796 AgentInventoryArray.Add(TempHash);
797 }
798  
799 return new InventoryData(AgentInventoryArray, rootID);
800  
801 }
802  
803 /// <summary>
804 /// Converts the inventory library skeleton into the form required by the rpc request.
805 /// </summary>
806 /// <returns></returns>
807 protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
808 {
809 Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
810 // m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
811 //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
812 ArrayList folderHashes = new ArrayList();
813  
814 foreach (InventoryFolderBase folder in rootFolders.Values)
815 {
816 Hashtable TempHash = new Hashtable();
817 TempHash["name"] = folder.Name;
818 TempHash["parent_id"] = folder.ParentID.ToString();
819 TempHash["version"] = (Int32)folder.Version;
820 TempHash["type_default"] = (Int32)folder.Type;
821 TempHash["folder_id"] = folder.ID.ToString();
822 folderHashes.Add(TempHash);
823 }
824  
825 return folderHashes;
826 }
827  
828 /// <summary>
829 ///
830 /// </summary>
831 /// <returns></returns>
832 protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
833 {
834 //for now create random inventory library owner
835 Hashtable TempHash = new Hashtable();
836 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
837 ArrayList inventoryLibOwner = new ArrayList();
838 inventoryLibOwner.Add(TempHash);
839 return inventoryLibOwner;
840 }
841  
842 public class InventoryData
843 {
844 public ArrayList InventoryArray = null;
845 public UUID RootFolderID = UUID.Zero;
846  
847 public InventoryData(ArrayList invList, UUID rootID)
848 {
849 InventoryArray = invList;
850 RootFolderID = rootID;
851 }
852 }
853  
854 #region Properties
855  
856 public string Login
857 {
858 get { return login; }
859 set { login = value; }
860 }
861  
862 public string DST
863 {
864 get { return dst; }
865 set { dst = value; }
866 }
867  
868 public string StipendSinceLogin
869 {
870 get { return stipendSinceLogin; }
871 set { stipendSinceLogin = value; }
872 }
873  
874 public string Gendered
875 {
876 get { return gendered; }
877 set { gendered = value; }
878 }
879  
880 public string EverLoggedIn
881 {
882 get { return everLoggedIn; }
883 set { everLoggedIn = value; }
884 }
885  
886 public uint SimPort
887 {
888 get { return simPort; }
889 set { simPort = value; }
890 }
891  
892 public uint SimHttpPort
893 {
894 get { return simHttpPort; }
895 set { simHttpPort = value; }
896 }
897  
898 public string SimAddress
899 {
900 get { return simAddress; }
901 set { simAddress = value; }
902 }
903  
904 public UUID AgentID
905 {
906 get { return agentID; }
907 set { agentID = value; }
908 }
909  
910 public UUID SessionID
911 {
912 get { return sessionID; }
913 set { sessionID = value; }
914 }
915  
916 public UUID SecureSessionID
917 {
918 get { return secureSessionID; }
919 set { secureSessionID = value; }
920 }
921  
922 public Int32 CircuitCode
923 {
924 get { return circuitCode; }
925 set { circuitCode = value; }
926 }
927  
928 public uint RegionX
929 {
930 get { return regionX; }
931 set { regionX = value; }
932 }
933  
934 public uint RegionY
935 {
936 get { return regionY; }
937 set { regionY = value; }
938 }
939  
940 public int RegionSizeX { get; private set; }
941 public int RegionSizeY { get; private set; }
942  
943 public string SunTexture
944 {
945 get { return sunTexture; }
946 set { sunTexture = value; }
947 }
948  
949 public string CloudTexture
950 {
951 get { return cloudTexture; }
952 set { cloudTexture = value; }
953 }
954  
955 public string MoonTexture
956 {
957 get { return moonTexture; }
958 set { moonTexture = value; }
959 }
960  
961 public string Firstname
962 {
963 get { return firstname; }
964 set { firstname = value; }
965 }
966  
967 public string Lastname
968 {
969 get { return lastname; }
970 set { lastname = value; }
971 }
972  
973 public string AgentAccess
974 {
975 get { return agentAccess; }
976 set { agentAccess = value; }
977 }
978  
979 public string AgentAccessMax
980 {
981 get { return agentAccessMax; }
982 set { agentAccessMax = value; }
983 }
984  
985 public string StartLocation
986 {
987 get { return startLocation; }
988 set { startLocation = value; }
989 }
990  
991 public string LookAt
992 {
993 get { return lookAt; }
994 set { lookAt = value; }
995 }
996  
997 public string SeedCapability
998 {
999 get { return seedCapability; }
1000 set { seedCapability = value; }
1001 }
1002  
1003 public string ErrorReason
1004 {
1005 get { return errorReason; }
1006 set { errorReason = value; }
1007 }
1008  
1009 public string ErrorMessage
1010 {
1011 get { return errorMessage; }
1012 set { errorMessage = value; }
1013 }
1014  
1015 public ArrayList InventoryRoot
1016 {
1017 get { return inventoryRoot; }
1018 set { inventoryRoot = value; }
1019 }
1020  
1021 public ArrayList InventorySkeleton
1022 {
1023 get { return agentInventory; }
1024 set { agentInventory = value; }
1025 }
1026  
1027 public ArrayList InventoryLibrary
1028 {
1029 get { return inventoryLibrary; }
1030 set { inventoryLibrary = value; }
1031 }
1032  
1033 public ArrayList InventoryLibraryOwner
1034 {
1035 get { return inventoryLibraryOwner; }
1036 set { inventoryLibraryOwner = value; }
1037 }
1038  
1039 public ArrayList InventoryLibRoot
1040 {
1041 get { return inventoryLibRoot; }
1042 set { inventoryLibRoot = value; }
1043 }
1044  
1045 public ArrayList ActiveGestures
1046 {
1047 get { return activeGestures; }
1048 set { activeGestures = value; }
1049 }
1050  
1051 public string Home
1052 {
1053 get { return home; }
1054 set { home = value; }
1055 }
1056  
1057 public string MapTileURL
1058 {
1059 get { return mapTileURL; }
1060 set { mapTileURL = value; }
1061 }
1062  
1063 public string ProfileURL
1064 {
1065 get { return profileURL; }
1066 set { profileURL = value; }
1067 }
1068  
1069 public string OpenIDURL
1070 {
1071 get { return openIDURL; }
1072 set { openIDURL = value; }
1073 }
1074  
1075 public string SearchURL
1076 {
1077 get { return searchURL; }
1078 set { searchURL = value; }
1079 }
1080  
1081 public string Message
1082 {
1083 get { return welcomeMessage; }
1084 set { welcomeMessage = value; }
1085 }
1086  
1087 public BuddyList BuddList
1088 {
1089 get { return m_buddyList; }
1090 set { m_buddyList = value; }
1091 }
1092  
1093 public string Currency
1094 {
1095 get { return currency; }
1096 set { currency = value; }
1097 }
1098  
1099 public string ClassifiedFee
1100 {
1101 get { return classifiedFee; }
1102 set { classifiedFee = value; }
1103 }
1104  
1105 public string DestinationsURL
1106 {
1107 get; set;
1108 }
1109  
1110 public string AvatarsURL
1111 {
1112 get; set;
1113 }
1114  
1115 #endregion
1116  
1117 public class UserInfo
1118 {
1119 public string firstname;
1120 public string lastname;
1121 public ulong homeregionhandle;
1122 public Vector3 homepos;
1123 public Vector3 homelookat;
1124 }
1125  
1126 public class BuddyList
1127 {
1128 public List<BuddyInfo> Buddies = new List<BuddyInfo>();
1129  
1130 public void AddNewBuddy(BuddyInfo buddy)
1131 {
1132 if (!Buddies.Contains(buddy))
1133 {
1134 Buddies.Add(buddy);
1135 }
1136 }
1137  
1138 public ArrayList ToArray()
1139 {
1140 ArrayList buddyArray = new ArrayList();
1141 foreach (BuddyInfo buddy in Buddies)
1142 {
1143 buddyArray.Add(buddy.ToHashTable());
1144 }
1145 return buddyArray;
1146 }
1147  
1148 public class BuddyInfo
1149 {
1150 public int BuddyRightsHave = 1;
1151 public int BuddyRightsGiven = 1;
1152 public string BuddyID;
1153  
1154 public BuddyInfo(string buddyID)
1155 {
1156 BuddyID = buddyID;
1157 }
1158  
1159 public BuddyInfo(UUID buddyID)
1160 {
1161 BuddyID = buddyID.ToString();
1162 }
1163  
1164 public Hashtable ToHashTable()
1165 {
1166 Hashtable hTable = new Hashtable();
1167 hTable["buddy_rights_has"] = BuddyRightsHave;
1168 hTable["buddy_rights_given"] = BuddyRightsGiven;
1169 hTable["buddy_id"] = BuddyID;
1170 return hTable;
1171 }
1172 }
1173 }
1174 }
1175 }