aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/LLLoginService
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginResponse.cs (renamed from OpenSim/Framework/Communications/Services/LoginResponse.cs)519
-rw-r--r--OpenSim/Services/LLLoginService/LLLoginService.cs650
2 files changed, 984 insertions, 185 deletions
diff --git a/OpenSim/Framework/Communications/Services/LoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
index ec5f428..05f5b4c 100644
--- a/OpenSim/Framework/Communications/Services/LoginResponse.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs
@@ -28,25 +28,108 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net;
31using System.Reflection; 32using System.Reflection;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Capabilities;
36using OpenSim.Services.Interfaces;
37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
38using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
39
32using log4net; 40using log4net;
33using Nwc.XmlRpc;
34using OpenMetaverse; 41using OpenMetaverse;
35using OpenMetaverse.StructuredData; 42using OpenMetaverse.StructuredData;
43using OSDArray = OpenMetaverse.StructuredData.OSDArray;
44using OSDMap = OpenMetaverse.StructuredData.OSDMap;
36 45
37namespace OpenSim.Framework.Communications.Services 46namespace OpenSim.Services.LLLoginService
38{ 47{
48 public class LLFailedLoginResponse : OpenSim.Services.Interfaces.FailedLoginResponse
49 {
50 string m_key;
51 string m_value;
52 string m_login;
53
54 public static LLFailedLoginResponse UserProblem;
55 public static LLFailedLoginResponse AuthorizationProblem;
56 public static LLFailedLoginResponse GridProblem;
57 public static LLFailedLoginResponse InventoryProblem;
58 public static LLFailedLoginResponse DeadRegionProblem;
59 public static LLFailedLoginResponse LoginBlockedProblem;
60 public static LLFailedLoginResponse AlreadyLoggedInProblem;
61 public static LLFailedLoginResponse InternalError;
62
63 static LLFailedLoginResponse()
64 {
65 UserProblem = new LLFailedLoginResponse("key",
66 "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
67 "false");
68 AuthorizationProblem = new LLFailedLoginResponse("key",
69 "Error connecting to grid. Unable to authorize your session into the region.",
70 "false");
71 GridProblem = new LLFailedLoginResponse("key",
72 "Error connecting to the desired location. Try connecting to another region.",
73 "false");
74 InventoryProblem = new LLFailedLoginResponse("key",
75 "The inventory service is not responding. Please notify your login region operator.",
76 "false");
77 DeadRegionProblem = new LLFailedLoginResponse("key",
78 "The region you are attempting to log into is not responding. Please select another region and try again.",
79 "false");
80 LoginBlockedProblem = new LLFailedLoginResponse("presence",
81 "Logins are currently restricted. Please try again later.",
82 "false");
83 AlreadyLoggedInProblem = new LLFailedLoginResponse("presence",
84 "You appear to be already logged in. " +
85 "If this is not the case please wait for your session to timeout. " +
86 "If this takes longer than a few minutes please contact the grid owner. " +
87 "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.",
88 "false");
89 InternalError = new LLFailedLoginResponse("Internal Error", "Error generating Login Response", "false");
90 }
91
92 public LLFailedLoginResponse(string key, string value, string login)
93 {
94 m_key = key;
95 m_value = value;
96 m_login = login;
97 }
98
99 public override Hashtable ToHashtable()
100 {
101 Hashtable loginError = new Hashtable();
102 loginError["reason"] = m_key;
103 loginError["message"] = m_value;
104 loginError["login"] = m_login;
105 return loginError;
106 }
107
108 public override OSD ToOSDMap()
109 {
110 OSDMap map = new OSDMap();
111
112 map["reason"] = OSD.FromString(m_key);
113 map["message"] = OSD.FromString(m_value);
114 map["login"] = OSD.FromString(m_login);
115
116 return map;
117 }
118 }
119
39 /// <summary> 120 /// <summary>
40 /// A temp class to handle login response. 121 /// A class to handle LL login response.
41 /// Should make use of UserProfileManager where possible.
42 /// </summary> 122 /// </summary>
43 public class LoginResponse 123 public class LLLoginResponse : OpenSim.Services.Interfaces.LoginResponse
44 { 124 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 125 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
126 private static Hashtable globalTexturesHash;
127 // Global Textures
128 private static string sunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
129 private static string cloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
130 private static string moonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
46 131
47 private Hashtable loginFlagsHash; 132 private Hashtable loginFlagsHash;
48 private Hashtable globalTexturesHash;
49 private Hashtable loginError;
50 private Hashtable uiConfigHash; 133 private Hashtable uiConfigHash;
51 134
52 private ArrayList loginFlags; 135 private ArrayList loginFlags;
@@ -87,19 +170,10 @@ namespace OpenSim.Framework.Communications.Services
87 private string firstname; 170 private string firstname;
88 private string lastname; 171 private string lastname;
89 172
90 // Global Textures
91 private string sunTexture;
92 private string cloudTexture;
93 private string moonTexture;
94
95 // Error Flags 173 // Error Flags
96 private string errorReason; 174 private string errorReason;
97 private string errorMessage; 175 private string errorMessage;
98 176
99 // Response
100 private XmlRpcResponse xmlRpcResponse;
101 // private XmlRpcResponse defaultXmlRpcResponse;
102
103 private string welcomeMessage; 177 private string welcomeMessage;
104 private string startLocation; 178 private string startLocation;
105 private string allowFirstLife; 179 private string allowFirstLife;
@@ -109,7 +183,17 @@ namespace OpenSim.Framework.Communications.Services
109 183
110 private BuddyList m_buddyList = null; 184 private BuddyList m_buddyList = null;
111 185
112 public LoginResponse() 186 static LLLoginResponse()
187 {
188 // This is being set, but it's not used
189 // not sure why.
190 globalTexturesHash = new Hashtable();
191 globalTexturesHash["sun_texture_id"] = sunTexture;
192 globalTexturesHash["cloud_texture_id"] = cloudTexture;
193 globalTexturesHash["moon_texture_id"] = moonTexture;
194 }
195
196 public LLLoginResponse()
113 { 197 {
114 loginFlags = new ArrayList(); 198 loginFlags = new ArrayList();
115 globalTextures = new ArrayList(); 199 globalTextures = new ArrayList();
@@ -117,7 +201,6 @@ namespace OpenSim.Framework.Communications.Services
117 uiConfig = new ArrayList(); 201 uiConfig = new ArrayList();
118 classifiedCategories = new ArrayList(); 202 classifiedCategories = new ArrayList();
119 203
120 loginError = new Hashtable();
121 uiConfigHash = new Hashtable(); 204 uiConfigHash = new Hashtable();
122 205
123 // defaultXmlRpcResponse = new XmlRpcResponse(); 206 // defaultXmlRpcResponse = new XmlRpcResponse();
@@ -129,12 +212,136 @@ namespace OpenSim.Framework.Communications.Services
129 inventoryLibraryOwner = new ArrayList(); 212 inventoryLibraryOwner = new ArrayList();
130 activeGestures = new ArrayList(); 213 activeGestures = new ArrayList();
131 214
132 xmlRpcResponse = new XmlRpcResponse();
133 // defaultXmlRpcResponse = new XmlRpcResponse();
134
135 SetDefaultValues(); 215 SetDefaultValues();
136 } 216 }
137 217
218 public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, PresenceInfo pinfo,
219 GridRegion destination, List<InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService,
220 string where, string startlocation, Vector3 position, Vector3 lookAt, string message,
221 GridRegion home, IPEndPoint clientIP)
222 : this()
223 {
224 FillOutInventoryData(invSkel, libService);
225
226 CircuitCode = (int)aCircuit.circuitcode;
227 Lastname = account.LastName;
228 Firstname = account.FirstName;
229 AgentID = account.PrincipalID;
230 SessionID = aCircuit.SessionID;
231 SecureSessionID = aCircuit.SecureSessionID;
232 Message = message;
233 BuddList = ConvertFriendListItem(friendsList);
234 StartLocation = where;
235
236 FillOutHomeData(pinfo, home);
237 LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z);
238
239 FillOutRegionData(destination);
240
241 FillOutSeedCap(aCircuit, destination, clientIP);
242
243 }
244
245 private void FillOutInventoryData(List<InventoryFolderBase> invSkel, ILibraryService libService)
246 {
247 InventoryData inventData = null;
248
249 try
250 {
251 inventData = GetInventorySkeleton(invSkel);
252 }
253 catch (Exception e)
254 {
255 m_log.WarnFormat(
256 "[LLLOGIN SERVICE]: Error processing inventory skeleton of agent {0} - {1}",
257 agentID, e);
258
259 // ignore and continue
260 }
261
262 if (inventData != null)
263 {
264 ArrayList AgentInventoryArray = inventData.InventoryArray;
265
266 Hashtable InventoryRootHash = new Hashtable();
267 InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
268 InventoryRoot = new ArrayList();
269 InventoryRoot.Add(InventoryRootHash);
270 InventorySkeleton = AgentInventoryArray;
271 }
272
273 // Inventory Library Section
274 if (libService != null && libService.LibraryRootFolder != null)
275 {
276 Hashtable InventoryLibRootHash = new Hashtable();
277 InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
278 InventoryLibRoot = new ArrayList();
279 InventoryLibRoot.Add(InventoryLibRootHash);
280
281 InventoryLibraryOwner = GetLibraryOwner(libService.LibraryRootFolder);
282 InventoryLibrary = GetInventoryLibrary(libService);
283 }
284 }
285
286 private void FillOutHomeData(PresenceInfo pinfo, GridRegion home)
287 {
288 int x = 1000 * (int)Constants.RegionSize, y = 1000 * (int)Constants.RegionSize;
289 if (home != null)
290 {
291 x = home.RegionLocX;
292 y = home.RegionLocY;
293 }
294
295 Home = string.Format(
296 "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}",
297 x,
298 y,
299 pinfo.HomePosition.X, pinfo.HomePosition.Y, pinfo.HomePosition.Z,
300 pinfo.HomeLookAt.X, pinfo.HomeLookAt.Y, pinfo.HomeLookAt.Z);
301
302 }
303
304 private void FillOutRegionData(GridRegion destination)
305 {
306 IPEndPoint endPoint = destination.ExternalEndPoint;
307 SimAddress = endPoint.Address.ToString();
308 SimPort = (uint)endPoint.Port;
309 RegionX = (uint)destination.RegionLocX;
310 RegionY = (uint)destination.RegionLocY;
311 }
312
313 private void FillOutSeedCap(AgentCircuitData aCircuit, GridRegion destination, IPEndPoint ipepClient)
314 {
315 string capsSeedPath = String.Empty;
316
317 // Don't use the following! It Fails for logging into any region not on the same port as the http server!
318 // Kept here so it doesn't happen again!
319 // response.SeedCapability = regionInfo.ServerURI + capsSeedPath;
320
321 #region IP Translation for NAT
322 if (ipepClient != null)
323 {
324 capsSeedPath
325 = "http://"
326 + NetworkUtil.GetHostFor(ipepClient.Address, destination.ExternalHostName)
327 + ":"
328 + destination.HttpPort
329 + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
330 }
331 else
332 {
333 capsSeedPath
334 = "http://"
335 + destination.ExternalHostName
336 + ":"
337 + destination.HttpPort
338 + CapsUtil.GetCapsSeedPath(aCircuit.CapsPath);
339 }
340 #endregion
341
342 SeedCapability = capsSeedPath;
343 }
344
138 private void SetDefaultValues() 345 private void SetDefaultValues()
139 { 346 {
140 DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N"; 347 DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N";
@@ -149,10 +356,6 @@ namespace OpenSim.Framework.Communications.Services
149 startLocation = "last"; 356 startLocation = "last";
150 allowFirstLife = "Y"; 357 allowFirstLife = "Y";
151 358
152 SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
153 CloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
154 MoonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
155
156 ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; 359 ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
157 ErrorReason = "key"; 360 ErrorReason = "key";
158 welcomeMessage = "Welcome to OpenSim!"; 361 welcomeMessage = "Welcome to OpenSim!";
@@ -186,149 +389,8 @@ namespace OpenSim.Framework.Communications.Services
186 initialOutfit.Add(InitialOutfitHash); 389 initialOutfit.Add(InitialOutfitHash);
187 } 390 }
188 391
189 #region Login Failure Methods
190
191 public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
192 {
193 // Overwrite any default values;
194 xmlRpcResponse = new XmlRpcResponse();
195
196 // Ensure Login Failed message/reason;
197 ErrorMessage = message;
198 ErrorReason = reason;
199
200 loginError["reason"] = ErrorReason;
201 loginError["message"] = ErrorMessage;
202 loginError["login"] = login;
203 xmlRpcResponse.Value = loginError;
204 return (xmlRpcResponse);
205 }
206 392
207 public OSD GenerateFailureResponseLLSD(string reason, string message, string login) 393 public override Hashtable ToHashtable()
208 {
209 OSDMap map = new OSDMap();
210
211 // Ensure Login Failed message/reason;
212 ErrorMessage = message;
213 ErrorReason = reason;
214
215 map["reason"] = OSD.FromString(ErrorReason);
216 map["message"] = OSD.FromString(ErrorMessage);
217 map["login"] = OSD.FromString(login);
218
219 return map;
220 }
221
222 public XmlRpcResponse CreateFailedResponse()
223 {
224 return (CreateLoginFailedResponse());
225 }
226
227 public OSD CreateFailedResponseLLSD()
228 {
229 return CreateLoginFailedResponseLLSD();
230 }
231
232 public XmlRpcResponse CreateLoginFailedResponse()
233 {
234 return
235 (GenerateFailureResponse("key",
236 "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
237 "false"));
238 }
239
240 public OSD CreateLoginFailedResponseLLSD()
241 {
242 return GenerateFailureResponseLLSD(
243 "key",
244 "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
245 "false");
246 }
247
248 /// <summary>
249 /// Response to indicate that login failed because the agent's inventory was not available.
250 /// </summary>
251 /// <returns></returns>
252 public XmlRpcResponse CreateLoginInventoryFailedResponse()
253 {
254 return GenerateFailureResponse(
255 "key",
256 "The avatar inventory service is not responding. Please notify your login region operator.",
257 "false");
258 }
259
260 public XmlRpcResponse CreateAlreadyLoggedInResponse()
261 {
262 return
263 (GenerateFailureResponse("presence",
264 "You appear to be already logged in. " +
265 "If this is not the case please wait for your session to timeout. " +
266 "If this takes longer than a few minutes please contact the grid owner. " +
267 "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.",
268 "false"));
269 }
270
271 public OSD CreateAlreadyLoggedInResponseLLSD()
272 {
273 return GenerateFailureResponseLLSD(
274 "presence",
275 "You appear to be already logged in. " +
276 "If this is not the case please wait for your session to timeout. " +
277 "If this takes longer than a few minutes please contact the grid owner",
278 "false");
279 }
280
281 public XmlRpcResponse CreateLoginBlockedResponse()
282 {
283 return
284 (GenerateFailureResponse("presence",
285 "Logins are currently restricted. Please try again later",
286 "false"));
287 }
288
289 public OSD CreateLoginBlockedResponseLLSD()
290 {
291 return GenerateFailureResponseLLSD(
292 "presence",
293 "Logins are currently restricted. Please try again later",
294 "false");
295 }
296
297 public XmlRpcResponse CreateDeadRegionResponse()
298 {
299 return
300 (GenerateFailureResponse("key",
301 "The region you are attempting to log into is not responding. Please select another region and try again.",
302 "false"));
303 }
304
305 public OSD CreateDeadRegionResponseLLSD()
306 {
307 return GenerateFailureResponseLLSD(
308 "key",
309 "The region you are attempting to log into is not responding. Please select another region and try again.",
310 "false");
311 }
312
313 public XmlRpcResponse CreateGridErrorResponse()
314 {
315 return
316 (GenerateFailureResponse("key",
317 "Error connecting to grid. Could not percieve credentials from login XML.",
318 "false"));
319 }
320
321 public OSD CreateGridErrorResponseLLSD()
322 {
323 return GenerateFailureResponseLLSD(
324 "key",
325 "Error connecting to grid. Could not perceive credentials from login XML.",
326 "false");
327 }
328
329 #endregion
330
331 public virtual XmlRpcResponse ToXmlRpcResponse()
332 { 394 {
333 try 395 try
334 { 396 {
@@ -346,10 +408,6 @@ namespace OpenSim.Framework.Communications.Services
346 responseData["agent_access"] = agentAccess; 408 responseData["agent_access"] = agentAccess;
347 responseData["agent_access_max"] = agentAccessMax; 409 responseData["agent_access_max"] = agentAccessMax;
348 410
349 globalTexturesHash = new Hashtable();
350 globalTexturesHash["sun_texture_id"] = SunTexture;
351 globalTexturesHash["cloud_texture_id"] = CloudTexture;
352 globalTexturesHash["moon_texture_id"] = MoonTexture;
353 globalTextures.Add(globalTexturesHash); 411 globalTextures.Add(globalTexturesHash);
354 // this.eventCategories.Add(this.eventCategoriesHash); 412 // this.eventCategories.Add(this.eventCategoriesHash);
355 413
@@ -389,8 +447,8 @@ namespace OpenSim.Framework.Communications.Services
389 responseData["home"] = home; 447 responseData["home"] = home;
390 responseData["look_at"] = lookAt; 448 responseData["look_at"] = lookAt;
391 responseData["message"] = welcomeMessage; 449 responseData["message"] = welcomeMessage;
392 responseData["region_x"] = (Int32)(RegionX * Constants.RegionSize); 450 responseData["region_x"] = (Int32)(RegionX);
393 responseData["region_y"] = (Int32)(RegionY * Constants.RegionSize); 451 responseData["region_y"] = (Int32)(RegionY);
394 452
395 if (m_buddyList != null) 453 if (m_buddyList != null)
396 { 454 {
@@ -398,19 +456,18 @@ namespace OpenSim.Framework.Communications.Services
398 } 456 }
399 457
400 responseData["login"] = "true"; 458 responseData["login"] = "true";
401 xmlRpcResponse.Value = responseData;
402 459
403 return (xmlRpcResponse); 460 return responseData;
404 } 461 }
405 catch (Exception e) 462 catch (Exception e)
406 { 463 {
407 m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message); 464 m_log.Warn("[CLIENT]: LoginResponse: Error creating Hashtable Response: " + e.Message);
408 465
409 return (GenerateFailureResponse("Internal Error", "Error generating Login Response", "false")); 466 return LLFailedLoginResponse.InternalError.ToHashtable();
410 } 467 }
411 } 468 }
412 469
413 public OSD ToLLSDResponse() 470 public override OSD ToOSDMap()
414 { 471 {
415 try 472 try
416 { 473 {
@@ -486,8 +543,8 @@ namespace OpenSim.Framework.Communications.Services
486 map["home"] = OSD.FromString(home); 543 map["home"] = OSD.FromString(home);
487 map["look_at"] = OSD.FromString(lookAt); 544 map["look_at"] = OSD.FromString(lookAt);
488 map["message"] = OSD.FromString(welcomeMessage); 545 map["message"] = OSD.FromString(welcomeMessage);
489 map["region_x"] = OSD.FromInteger(RegionX * Constants.RegionSize); 546 map["region_x"] = OSD.FromInteger(RegionX);
490 map["region_y"] = OSD.FromInteger(RegionY * Constants.RegionSize); 547 map["region_y"] = OSD.FromInteger(RegionY);
491 548
492 if (m_buddyList != null) 549 if (m_buddyList != null)
493 { 550 {
@@ -502,7 +559,7 @@ namespace OpenSim.Framework.Communications.Services
502 { 559 {
503 m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message); 560 m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message);
504 561
505 return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false"); 562 return LLFailedLoginResponse.InternalError.ToOSDMap();
506 } 563 }
507 } 564 }
508 565
@@ -548,6 +605,98 @@ namespace OpenSim.Framework.Communications.Services
548 // this.classifiedCategoriesHash.Clear(); 605 // this.classifiedCategoriesHash.Clear();
549 } 606 }
550 607
608
609 private static LLLoginResponse.BuddyList ConvertFriendListItem(FriendInfo[] friendsList)
610 {
611 LLLoginResponse.BuddyList buddylistreturn = new LLLoginResponse.BuddyList();
612 foreach (FriendInfo finfo in friendsList)
613 {
614 if (finfo.TheirFlags == -1)
615 continue;
616 LLLoginResponse.BuddyList.BuddyInfo buddyitem = new LLLoginResponse.BuddyList.BuddyInfo(finfo.Friend);
617 buddyitem.BuddyID = finfo.Friend;
618 buddyitem.BuddyRightsHave = (int)finfo.TheirFlags;
619 buddyitem.BuddyRightsGiven = (int)finfo.MyFlags;
620 buddylistreturn.AddNewBuddy(buddyitem);
621 }
622 return buddylistreturn;
623 }
624
625 private InventoryData GetInventorySkeleton(List<InventoryFolderBase> folders)
626 {
627 UUID rootID = UUID.Zero;
628 ArrayList AgentInventoryArray = new ArrayList();
629 Hashtable TempHash;
630 foreach (InventoryFolderBase InvFolder in folders)
631 {
632 if (InvFolder.ParentID == UUID.Zero)
633 {
634 rootID = InvFolder.ID;
635 }
636 TempHash = new Hashtable();
637 TempHash["name"] = InvFolder.Name;
638 TempHash["parent_id"] = InvFolder.ParentID.ToString();
639 TempHash["version"] = (Int32)InvFolder.Version;
640 TempHash["type_default"] = (Int32)InvFolder.Type;
641 TempHash["folder_id"] = InvFolder.ID.ToString();
642 AgentInventoryArray.Add(TempHash);
643 }
644
645 return new InventoryData(AgentInventoryArray, rootID);
646
647 }
648
649 /// <summary>
650 /// Converts the inventory library skeleton into the form required by the rpc request.
651 /// </summary>
652 /// <returns></returns>
653 protected virtual ArrayList GetInventoryLibrary(ILibraryService library)
654 {
655 Dictionary<UUID, InventoryFolderImpl> rootFolders = library.GetAllFolders();
656 m_log.DebugFormat("[LLOGIN]: Library has {0} folders", rootFolders.Count);
657 //Dictionary<UUID, InventoryFolderImpl> rootFolders = new Dictionary<UUID,InventoryFolderImpl>();
658 ArrayList folderHashes = new ArrayList();
659
660 foreach (InventoryFolderBase folder in rootFolders.Values)
661 {
662 Hashtable TempHash = new Hashtable();
663 TempHash["name"] = folder.Name;
664 TempHash["parent_id"] = folder.ParentID.ToString();
665 TempHash["version"] = (Int32)folder.Version;
666 TempHash["type_default"] = (Int32)folder.Type;
667 TempHash["folder_id"] = folder.ID.ToString();
668 folderHashes.Add(TempHash);
669 }
670
671 return folderHashes;
672 }
673
674 /// <summary>
675 ///
676 /// </summary>
677 /// <returns></returns>
678 protected virtual ArrayList GetLibraryOwner(InventoryFolderImpl libFolder)
679 {
680 //for now create random inventory library owner
681 Hashtable TempHash = new Hashtable();
682 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; // libFolder.Owner
683 ArrayList inventoryLibOwner = new ArrayList();
684 inventoryLibOwner.Add(TempHash);
685 return inventoryLibOwner;
686 }
687
688 public class InventoryData
689 {
690 public ArrayList InventoryArray = null;
691 public UUID RootFolderID = UUID.Zero;
692
693 public InventoryData(ArrayList invList, UUID rootID)
694 {
695 InventoryArray = invList;
696 RootFolderID = rootID;
697 }
698 }
699
551 #region Properties 700 #region Properties
552 701
553 public string Login 702 public string Login
@@ -797,16 +946,16 @@ namespace OpenSim.Framework.Communications.Services
797 { 946 {
798 public int BuddyRightsHave = 1; 947 public int BuddyRightsHave = 1;
799 public int BuddyRightsGiven = 1; 948 public int BuddyRightsGiven = 1;
800 public UUID BuddyID; 949 public string BuddyID;
801 950
802 public BuddyInfo(string buddyID) 951 public BuddyInfo(string buddyID)
803 { 952 {
804 BuddyID = new UUID(buddyID); 953 BuddyID = buddyID;
805 } 954 }
806 955
807 public BuddyInfo(UUID buddyID) 956 public BuddyInfo(UUID buddyID)
808 { 957 {
809 BuddyID = buddyID; 958 BuddyID = buddyID.ToString();
810 } 959 }
811 960
812 public Hashtable ToHashTable() 961 public Hashtable ToHashTable()
@@ -814,7 +963,7 @@ namespace OpenSim.Framework.Communications.Services
814 Hashtable hTable = new Hashtable(); 963 Hashtable hTable = new Hashtable();
815 hTable["buddy_rights_has"] = BuddyRightsHave; 964 hTable["buddy_rights_has"] = BuddyRightsHave;
816 hTable["buddy_rights_given"] = BuddyRightsGiven; 965 hTable["buddy_rights_given"] = BuddyRightsGiven;
817 hTable["buddy_id"] = BuddyID.ToString(); 966 hTable["buddy_id"] = BuddyID;
818 return hTable; 967 return hTable;
819 } 968 }
820 } 969 }
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
new file mode 100644
index 0000000..143e5f1
--- /dev/null
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -0,0 +1,650 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Reflection;
5using System.Text.RegularExpressions;
6
7using log4net;
8using Nini.Config;
9using OpenMetaverse;
10
11using OpenSim.Framework;
12using OpenSim.Framework.Capabilities;
13using OpenSim.Framework.Console;
14using OpenSim.Server.Base;
15using OpenSim.Services.Interfaces;
16using GridRegion = OpenSim.Services.Interfaces.GridRegion;
17using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
18using OpenSim.Services.Connectors.Hypergrid;
19
20namespace OpenSim.Services.LLLoginService
21{
22 public class LLLoginService : ILoginService
23 {
24 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
25 private static bool Initialized = false;
26
27 private IUserAccountService m_UserAccountService;
28 private IAuthenticationService m_AuthenticationService;
29 private IInventoryService m_InventoryService;
30 private IGridService m_GridService;
31 private IPresenceService m_PresenceService;
32 private ISimulationService m_LocalSimulationService;
33 private ISimulationService m_RemoteSimulationService;
34 private ILibraryService m_LibraryService;
35 private IFriendsService m_FriendsService;
36 private IAvatarService m_AvatarService;
37 private IUserAgentService m_UserAgentService;
38
39 private GatekeeperServiceConnector m_GatekeeperConnector;
40
41 private string m_DefaultRegionName;
42 private string m_WelcomeMessage;
43 private bool m_RequireInventory;
44 private int m_MinLoginLevel;
45 private string m_GatekeeperURL;
46
47 IConfig m_LoginServerConfig;
48
49 public LLLoginService(IConfigSource config, ISimulationService simService, ILibraryService libraryService)
50 {
51 m_LoginServerConfig = config.Configs["LoginService"];
52 if (m_LoginServerConfig == null)
53 throw new Exception(String.Format("No section LoginService in config file"));
54
55 string accountService = m_LoginServerConfig.GetString("UserAccountService", String.Empty);
56 string agentService = m_LoginServerConfig.GetString("UserAgentService", String.Empty);
57 string authService = m_LoginServerConfig.GetString("AuthenticationService", String.Empty);
58 string invService = m_LoginServerConfig.GetString("InventoryService", String.Empty);
59 string gridService = m_LoginServerConfig.GetString("GridService", String.Empty);
60 string presenceService = m_LoginServerConfig.GetString("PresenceService", String.Empty);
61 string libService = m_LoginServerConfig.GetString("LibraryService", String.Empty);
62 string friendsService = m_LoginServerConfig.GetString("FriendsService", String.Empty);
63 string avatarService = m_LoginServerConfig.GetString("AvatarService", String.Empty);
64 string simulationService = m_LoginServerConfig.GetString("SimulationService", String.Empty);
65
66 m_DefaultRegionName = m_LoginServerConfig.GetString("DefaultRegion", String.Empty);
67 m_WelcomeMessage = m_LoginServerConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
68 m_RequireInventory = m_LoginServerConfig.GetBoolean("RequireInventory", true);
69 m_GatekeeperURL = m_LoginServerConfig.GetString("GatekeeperURI", string.Empty);
70
71 // These are required; the others aren't
72 if (accountService == string.Empty || authService == string.Empty)
73 throw new Exception("LoginService is missing service specifications");
74
75 Object[] args = new Object[] { config };
76 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
77 m_AuthenticationService = ServerUtils.LoadPlugin<IAuthenticationService>(authService, args);
78 m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(invService, args);
79 if (gridService != string.Empty)
80 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
81 if (presenceService != string.Empty)
82 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
83 if (avatarService != string.Empty)
84 m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarService, args);
85 if (friendsService != string.Empty)
86 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(friendsService, args);
87 if (simulationService != string.Empty)
88 m_RemoteSimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
89 if (agentService != string.Empty)
90 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(agentService, args);
91
92 //
93 // deal with the services given as argument
94 //
95 m_LocalSimulationService = simService;
96 if (libraryService != null)
97 {
98 m_log.DebugFormat("[LLOGIN SERVICE]: Using LibraryService given as argument");
99 m_LibraryService = libraryService;
100 }
101 else if (libService != string.Empty)
102 {
103 m_log.DebugFormat("[LLOGIN SERVICE]: Using instantiated LibraryService");
104 m_LibraryService = ServerUtils.LoadPlugin<ILibraryService>(libService, args);
105 }
106
107 m_GatekeeperConnector = new GatekeeperServiceConnector();
108
109 if (!Initialized)
110 {
111 Initialized = true;
112 RegisterCommands();
113 }
114
115 m_log.DebugFormat("[LLOGIN SERVICE]: Starting...");
116
117 }
118
119 public LLLoginService(IConfigSource config) : this(config, null, null)
120 {
121 }
122
123 public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, IPEndPoint clientIP)
124 {
125 bool success = false;
126 UUID session = UUID.Random();
127
128 try
129 {
130 //
131 // Get the account and check that it exists
132 //
133 UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
134 if (account == null)
135 {
136 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: user not found");
137 return LLFailedLoginResponse.UserProblem;
138 }
139
140 if (account.UserLevel < m_MinLoginLevel)
141 {
142 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: login is blocked for user level {0}", account.UserLevel);
143 return LLFailedLoginResponse.LoginBlockedProblem;
144 }
145
146 //
147 // Authenticate this user
148 //
149 if (!passwd.StartsWith("$1$"))
150 passwd = "$1$" + Util.Md5Hash(passwd);
151 passwd = passwd.Remove(0, 3); //remove $1$
152 string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30);
153 UUID secureSession = UUID.Zero;
154 if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession)))
155 {
156 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: authentication failed");
157 return LLFailedLoginResponse.UserProblem;
158 }
159
160 //
161 // Get the user's inventory
162 //
163 if (m_RequireInventory && m_InventoryService == null)
164 {
165 m_log.WarnFormat("[LLOGIN SERVICE]: Login failed, reason: inventory service not set up");
166 return LLFailedLoginResponse.InventoryProblem;
167 }
168 List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID);
169 if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)))
170 {
171 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory");
172 return LLFailedLoginResponse.InventoryProblem;
173 }
174
175 //
176 // Login the presence
177 //
178 PresenceInfo presence = null;
179 GridRegion home = null;
180 if (m_PresenceService != null)
181 {
182 success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession);
183 if (!success)
184 {
185 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: could not login presence");
186 return LLFailedLoginResponse.GridProblem;
187 }
188
189 // Get the updated presence info
190 presence = m_PresenceService.GetAgent(session);
191
192 // Get the home region
193 if ((presence.HomeRegionID != UUID.Zero) && m_GridService != null)
194 {
195 home = m_GridService.GetRegionByUUID(account.ScopeID, presence.HomeRegionID);
196 }
197 }
198
199 //
200 // Find the destination region/grid
201 //
202 string where = string.Empty;
203 Vector3 position = Vector3.Zero;
204 Vector3 lookAt = Vector3.Zero;
205 GridRegion gatekeeper = null;
206 GridRegion destination = FindDestination(account, presence, session, startLocation, out gatekeeper, out where, out position, out lookAt);
207 if (destination == null)
208 {
209 m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt);
210 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found");
211 return LLFailedLoginResponse.GridProblem;
212 }
213
214 //
215 // Get the avatar
216 //
217 AvatarData avatar = null;
218 if (m_AvatarService != null)
219 {
220 avatar = m_AvatarService.GetAvatar(account.PrincipalID);
221 }
222
223 //
224 // Instantiate/get the simulation interface and launch an agent at the destination
225 //
226 string reason = string.Empty;
227 AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where, out where, out reason);
228
229 if (aCircuit == null)
230 {
231 m_PresenceService.LogoutAgent(session, presence.Position, presence.LookAt);
232 m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason);
233 return LLFailedLoginResponse.AuthorizationProblem;
234
235 }
236 // Get Friends list
237 FriendInfo[] friendsList = new FriendInfo[0];
238 if (m_FriendsService != null)
239 {
240 friendsList = m_FriendsService.GetFriends(account.PrincipalID);
241 m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length);
242 }
243
244 //
245 // Finally, fill out the response and return it
246 //
247 LLLoginResponse response = new LLLoginResponse(account, aCircuit, presence, destination, inventorySkel, friendsList, m_LibraryService,
248 where, startLocation, position, lookAt, m_WelcomeMessage, home, clientIP);
249
250 return response;
251 }
252 catch (Exception e)
253 {
254 m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2}", firstName, lastName, e.ToString());
255 if (m_PresenceService != null)
256 m_PresenceService.LogoutAgent(session, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
257 return LLFailedLoginResponse.InternalError;
258 }
259 }
260
261 private GridRegion FindDestination(UserAccount account, PresenceInfo pinfo, UUID sessionID, string startLocation, out GridRegion gatekeeper, out string where, out Vector3 position, out Vector3 lookAt)
262 {
263 m_log.DebugFormat("[LLOGIN SERVICE]: FindDestination for start location {0}", startLocation);
264
265 gatekeeper = null;
266 where = "home";
267 position = new Vector3(128, 128, 0);
268 lookAt = new Vector3(0, 1, 0);
269
270 if (m_GridService == null)
271 return null;
272
273 if (startLocation.Equals("home"))
274 {
275 // logging into home region
276 if (pinfo == null)
277 return null;
278
279 GridRegion region = null;
280
281 if (pinfo.HomeRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID)) == null)
282 {
283 List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID);
284 if (defaults != null && defaults.Count > 0)
285 {
286 region = defaults[0];
287 where = "safe";
288 }
289 else
290 m_log.WarnFormat("[LLOGIN SERVICE]: User {0} {1} does not have a home set and this grid does not have default locations.",
291 account.FirstName, account.LastName);
292 }
293
294 return region;
295 }
296 else if (startLocation.Equals("last"))
297 {
298 // logging into last visited region
299 where = "last";
300
301 if (pinfo == null)
302 return null;
303
304 GridRegion region = null;
305
306 if (pinfo.RegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.RegionID)) == null)
307 {
308 List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID);
309 if (defaults != null && defaults.Count > 0)
310 {
311 region = defaults[0];
312 where = "safe";
313 }
314 }
315 else
316 {
317 position = pinfo.Position;
318 lookAt = pinfo.LookAt;
319 }
320 return region;
321
322 }
323 else
324 {
325 // free uri form
326 // e.g. New Moon&135&46 New Moon@osgrid.org:8002&153&34
327 where = "url";
328 Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$");
329 Match uriMatch = reURI.Match(startLocation);
330 if (uriMatch == null)
331 {
332 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it", startLocation);
333 return null;
334 }
335 else
336 {
337 position = new Vector3(float.Parse(uriMatch.Groups["x"].Value),
338 float.Parse(uriMatch.Groups["y"].Value),
339 float.Parse(uriMatch.Groups["z"].Value));
340
341 string regionName = uriMatch.Groups["region"].ToString();
342 if (regionName != null)
343 {
344 if (!regionName.Contains("@"))
345 {
346
347 List<GridRegion> regions = m_GridService.GetRegionsByName(account.ScopeID, regionName, 1);
348 if ((regions == null) || (regions != null && regions.Count == 0))
349 {
350 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults.", startLocation, regionName);
351 regions = m_GridService.GetDefaultRegions(UUID.Zero);
352 if (regions != null && regions.Count > 0)
353 {
354 where = "safe";
355 return regions[0];
356 }
357 else
358 {
359 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not provide default regions.", startLocation);
360 return null;
361 }
362 }
363 return regions[0];
364 }
365 else
366 {
367 if (m_UserAgentService == null)
368 {
369 m_log.WarnFormat("[LLLOGIN SERVICE]: This llogin service is not running a user agent service, as such it can't lauch agents at foreign grids");
370 return null;
371 }
372 string[] parts = regionName.Split(new char[] { '@' });
373 if (parts.Length < 2)
374 {
375 m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName);
376 return null;
377 }
378 // Valid specification of a remote grid
379 regionName = parts[0];
380 string domainLocator = parts[1];
381 parts = domainLocator.Split(new char[] {':'});
382 string domainName = parts[0];
383 uint port = 0;
384 if (parts.Length > 1)
385 UInt32.TryParse(parts[1], out port);
386 GridRegion region = FindForeignRegion(domainName, port, regionName, out gatekeeper);
387 return region;
388 }
389 }
390 else
391 {
392 List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.ScopeID);
393 if (defaults != null && defaults.Count > 0)
394 {
395 where = "safe";
396 return defaults[0];
397 }
398 else
399 return null;
400 }
401 }
402 //response.LookAt = "[r0,r1,r0]";
403 //// can be: last, home, safe, url
404 //response.StartLocation = "url";
405
406 }
407
408 }
409
410 private GridRegion FindForeignRegion(string domainName, uint port, string regionName, out GridRegion gatekeeper)
411 {
412 gatekeeper = new GridRegion();
413 gatekeeper.ExternalHostName = domainName;
414 gatekeeper.HttpPort = port;
415 gatekeeper.RegionName = regionName;
416 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
417
418 UUID regionID;
419 ulong handle;
420 string imageURL = string.Empty, reason = string.Empty;
421 if (m_GatekeeperConnector.LinkRegion(gatekeeper, out regionID, out handle, out domainName, out imageURL, out reason))
422 {
423 GridRegion destination = m_GatekeeperConnector.GetHyperlinkRegion(gatekeeper, regionID);
424 return destination;
425 }
426
427 return null;
428 }
429
430 private string hostName = string.Empty;
431 private int port = 0;
432
433 private void SetHostAndPort(string url)
434 {
435 try
436 {
437 Uri uri = new Uri(url);
438 hostName = uri.Host;
439 port = uri.Port;
440 }
441 catch
442 {
443 m_log.WarnFormat("[LLLogin SERVICE]: Unable to parse GatekeeperURL {0}", url);
444 }
445 }
446
447 private AgentCircuitData LaunchAgentAtGrid(GridRegion gatekeeper, GridRegion destination, UserAccount account, AvatarData avatar,
448 UUID session, UUID secureSession, Vector3 position, string currentWhere, out string where, out string reason)
449 {
450 where = currentWhere;
451 ISimulationService simConnector = null;
452 reason = string.Empty;
453 uint circuitCode = 0;
454 AgentCircuitData aCircuit = null;
455
456 if (m_UserAgentService == null)
457 {
458 // HG standalones have both a localSimulatonDll and a remoteSimulationDll
459 // non-HG standalones have just a localSimulationDll
460 // independent login servers have just a remoteSimulationDll
461 if (m_LocalSimulationService != null)
462 simConnector = m_LocalSimulationService;
463 else if (m_RemoteSimulationService != null)
464 simConnector = m_RemoteSimulationService;
465 }
466 else // User Agent Service is on
467 {
468 if (gatekeeper == null) // login to local grid
469 {
470 if (hostName == string.Empty)
471 SetHostAndPort(m_GatekeeperURL);
472
473 gatekeeper = new GridRegion(destination);
474 gatekeeper.ExternalHostName = hostName;
475 gatekeeper.HttpPort = (uint)port;
476
477 }
478 else // login to foreign grid
479 {
480 }
481 }
482
483 bool success = false;
484
485 if (m_UserAgentService == null && simConnector != null)
486 {
487 circuitCode = (uint)Util.RandomClass.Next(); ;
488 aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position);
489 success = LaunchAgentDirectly(simConnector, destination, aCircuit, out reason);
490 if (!success && m_GridService != null)
491 {
492 // Try the fallback regions
493 List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
494 if (fallbacks != null)
495 {
496 foreach (GridRegion r in fallbacks)
497 {
498 success = LaunchAgentDirectly(simConnector, r, aCircuit, out reason);
499 if (success)
500 {
501 where = "safe";
502 destination = r;
503 break;
504 }
505 }
506 }
507 }
508 }
509
510 if (m_UserAgentService != null)
511 {
512 circuitCode = (uint)Util.RandomClass.Next(); ;
513 aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position);
514 success = LaunchAgentIndirectly(gatekeeper, destination, aCircuit, out reason);
515 if (!success && m_GridService != null)
516 {
517 // Try the fallback regions
518 List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.ScopeID, destination.RegionLocX, destination.RegionLocY);
519 if (fallbacks != null)
520 {
521 foreach (GridRegion r in fallbacks)
522 {
523 success = LaunchAgentIndirectly(gatekeeper, r, aCircuit, out reason);
524 if (success)
525 {
526 where = "safe";
527 destination = r;
528 break;
529 }
530 }
531 }
532 }
533 }
534
535 if (success)
536 return aCircuit;
537 else
538 return null;
539 }
540
541 private AgentCircuitData MakeAgent(GridRegion region, UserAccount account,
542 AvatarData avatar, UUID session, UUID secureSession, uint circuit, Vector3 position)
543 {
544 AgentCircuitData aCircuit = new AgentCircuitData();
545
546 aCircuit.AgentID = account.PrincipalID;
547 if (avatar != null)
548 aCircuit.Appearance = avatar.ToAvatarAppearance(account.PrincipalID);
549 else
550 aCircuit.Appearance = new AvatarAppearance(account.PrincipalID);
551
552 //aCircuit.BaseFolder = irrelevant
553 aCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
554 aCircuit.child = false; // the first login agent is root
555 aCircuit.ChildrenCapSeeds = new Dictionary<ulong, string>();
556 aCircuit.circuitcode = circuit;
557 aCircuit.firstname = account.FirstName;
558 //aCircuit.InventoryFolder = irrelevant
559 aCircuit.lastname = account.LastName;
560 aCircuit.SecureSessionID = secureSession;
561 aCircuit.SessionID = session;
562 aCircuit.startpos = position;
563 SetServiceURLs(aCircuit, account);
564
565 return aCircuit;
566
567 //m_UserAgentService.LoginAgentToGrid(aCircuit, GatekeeperServiceConnector, region, out reason);
568 //if (simConnector.CreateAgent(region, aCircuit, 0, out reason))
569 // return aCircuit;
570
571 //return null;
572
573 }
574
575 private void SetServiceURLs(AgentCircuitData aCircuit, UserAccount account)
576 {
577 aCircuit.ServiceURLs = new Dictionary<string, object>();
578 if (account.ServiceURLs == null)
579 return;
580
581 foreach (KeyValuePair<string, object> kvp in account.ServiceURLs)
582 {
583 if (kvp.Value == null || (kvp.Value != null && kvp.Value.ToString() == string.Empty))
584 {
585 aCircuit.ServiceURLs[kvp.Key] = m_LoginServerConfig.GetString(kvp.Key, string.Empty);
586 }
587 else
588 {
589 aCircuit.ServiceURLs[kvp.Key] = kvp.Value;
590 }
591 }
592 }
593
594 private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, out string reason)
595 {
596 return simConnector.CreateAgent(region, aCircuit, (int)Constants.TeleportFlags.ViaLogin, out reason);
597 }
598
599 private bool LaunchAgentIndirectly(GridRegion gatekeeper, GridRegion destination, AgentCircuitData aCircuit, out string reason)
600 {
601 m_log.Debug("[LLOGIN SERVICE] Launching agent at " + destination.RegionName);
602 return m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason);
603 }
604
605 #region Console Commands
606 private void RegisterCommands()
607 {
608 //MainConsole.Instance.Commands.AddCommand
609 MainConsole.Instance.Commands.AddCommand("loginservice", false, "login level",
610 "login level <level>",
611 "Set the minimum user level to log in", HandleLoginCommand);
612
613 MainConsole.Instance.Commands.AddCommand("loginservice", false, "login reset",
614 "login reset",
615 "Reset the login level to allow all users",
616 HandleLoginCommand);
617
618 MainConsole.Instance.Commands.AddCommand("loginservice", false, "login text",
619 "login text <text>",
620 "Set the text users will see on login", HandleLoginCommand);
621
622 }
623
624 private void HandleLoginCommand(string module, string[] cmd)
625 {
626 string subcommand = cmd[1];
627
628 switch (subcommand)
629 {
630 case "level":
631 // Set the minimum level to allow login
632 // Useful to allow grid update without worrying about users.
633 // or fixing critical issues
634 //
635 if (cmd.Length > 2)
636 Int32.TryParse(cmd[2], out m_MinLoginLevel);
637 break;
638 case "reset":
639 m_MinLoginLevel = 0;
640 break;
641 case "text":
642 if (cmd.Length > 2)
643 m_WelcomeMessage = cmd[2];
644 break;
645 }
646 }
647 }
648
649 #endregion
650}