diff options
author | Melanie | 2010-03-03 02:07:03 +0000 |
---|---|---|
committer | Melanie | 2010-03-03 02:07:03 +0000 |
commit | 028a87fe37002e7a0611f66babf1deee46c83804 (patch) | |
tree | 387aec499fd60c2012bed8148e6a2ddc847c3d95 /OpenSim/Services/LLLoginService/LLLoginService.cs | |
parent | Revert "test" (diff) | |
parent | Fixes Region.Framework tests. Although these tests don't fail, they need to b... (diff) | |
download | opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.zip opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.tar.gz opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.tar.bz2 opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.tar.xz |
Merge branch 'master' into careminster-presence-refactor
This brings careminster on the level of master. To be tested
Diffstat (limited to 'OpenSim/Services/LLLoginService/LLLoginService.cs')
-rw-r--r-- | OpenSim/Services/LLLoginService/LLLoginService.cs | 650 |
1 files changed, 650 insertions, 0 deletions
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Net; | ||
4 | using System.Reflection; | ||
5 | using System.Text.RegularExpressions; | ||
6 | |||
7 | using log4net; | ||
8 | using Nini.Config; | ||
9 | using OpenMetaverse; | ||
10 | |||
11 | using OpenSim.Framework; | ||
12 | using OpenSim.Framework.Capabilities; | ||
13 | using OpenSim.Framework.Console; | ||
14 | using OpenSim.Server.Base; | ||
15 | using OpenSim.Services.Interfaces; | ||
16 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
17 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
18 | using OpenSim.Services.Connectors.Hypergrid; | ||
19 | |||
20 | namespace 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 | } | ||