diff options
Diffstat (limited to 'OpenSim/Grid/UserServer.Modules/UserLoginService.cs')
-rw-r--r-- | OpenSim/Grid/UserServer.Modules/UserLoginService.cs | 423 |
1 files changed, 0 insertions, 423 deletions
diff --git a/OpenSim/Grid/UserServer.Modules/UserLoginService.cs b/OpenSim/Grid/UserServer.Modules/UserLoginService.cs deleted file mode 100644 index d46ff9b..0000000 --- a/OpenSim/Grid/UserServer.Modules/UserLoginService.cs +++ /dev/null | |||
@@ -1,423 +0,0 @@ | |||
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 | using System.Text.RegularExpressions; | ||
34 | using log4net; | ||
35 | using Nwc.XmlRpc; | ||
36 | using OpenMetaverse; | ||
37 | using Nini.Config; | ||
38 | using OpenSim.Data; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Framework.Communications; | ||
41 | using OpenSim.Framework.Communications.Services; | ||
42 | using OpenSim.Framework.Communications.Cache; | ||
43 | using OpenSim.Framework.Capabilities; | ||
44 | using OpenSim.Framework.Servers; | ||
45 | using OpenSim.Framework.Servers.HttpServer; | ||
46 | using OpenSim.Services.Interfaces; | ||
47 | using OpenSim.Services.Connectors; | ||
48 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
49 | |||
50 | namespace OpenSim.Grid.UserServer.Modules | ||
51 | { | ||
52 | public delegate void UserLoggedInAtLocation(UUID agentID, UUID sessionID, UUID RegionID, | ||
53 | ulong regionhandle, float positionX, float positionY, float positionZ, | ||
54 | string firstname, string lastname); | ||
55 | |||
56 | /// <summary> | ||
57 | /// Login service used in grid mode. | ||
58 | /// </summary> | ||
59 | public class UserLoginService : LoginService | ||
60 | { | ||
61 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
62 | |||
63 | public event UserLoggedInAtLocation OnUserLoggedInAtLocation; | ||
64 | |||
65 | private UserLoggedInAtLocation handlerUserLoggedInAtLocation; | ||
66 | |||
67 | public UserConfig m_config; | ||
68 | private readonly IRegionProfileRouter m_regionProfileService; | ||
69 | |||
70 | private IGridService m_GridService; | ||
71 | |||
72 | protected BaseHttpServer m_httpServer; | ||
73 | |||
74 | public UserLoginService( | ||
75 | UserManagerBase userManager, IInterServiceInventoryServices inventoryService, | ||
76 | LibraryRootFolder libraryRootFolder, | ||
77 | UserConfig config, string welcomeMess, IRegionProfileRouter regionProfileService) | ||
78 | : base(userManager, libraryRootFolder, welcomeMess) | ||
79 | { | ||
80 | m_config = config; | ||
81 | m_defaultHomeX = m_config.DefaultX; | ||
82 | m_defaultHomeY = m_config.DefaultY; | ||
83 | m_interInventoryService = inventoryService; | ||
84 | m_regionProfileService = regionProfileService; | ||
85 | |||
86 | m_GridService = new GridServicesConnector(config.GridServerURL.ToString()); | ||
87 | } | ||
88 | |||
89 | public void RegisterHandlers(BaseHttpServer httpServer, bool registerLLSDHandler, bool registerOpenIDHandlers) | ||
90 | { | ||
91 | m_httpServer = httpServer; | ||
92 | |||
93 | m_httpServer.AddXmlRPCHandler("login_to_simulator", XmlRpcLoginMethod); | ||
94 | m_httpServer.AddHTTPHandler("login", ProcessHTMLLogin); | ||
95 | m_httpServer.AddXmlRPCHandler("set_login_params", XmlRPCSetLoginParams); | ||
96 | m_httpServer.AddXmlRPCHandler("check_auth_session", XmlRPCCheckAuthSession, false); | ||
97 | |||
98 | if (registerLLSDHandler) | ||
99 | { | ||
100 | m_httpServer.SetDefaultLLSDHandler(LLSDLoginMethod); | ||
101 | } | ||
102 | |||
103 | if (registerOpenIDHandlers) | ||
104 | { | ||
105 | // Handler for OpenID avatar identity pages | ||
106 | m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", this)); | ||
107 | // Handlers for the OpenID endpoint server | ||
108 | m_httpServer.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", this)); | ||
109 | m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", this)); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public void setloginlevel(int level) | ||
114 | { | ||
115 | m_minLoginLevel = level; | ||
116 | m_log.InfoFormat("[GRID]: Login Level set to {0} ", level); | ||
117 | } | ||
118 | public void setwelcometext(string text) | ||
119 | { | ||
120 | m_welcomeMessage = text; | ||
121 | m_log.InfoFormat("[GRID]: Login text set to {0} ", text); | ||
122 | } | ||
123 | |||
124 | public override void LogOffUser(UserProfileData theUser, string message) | ||
125 | { | ||
126 | RegionProfileData SimInfo; | ||
127 | try | ||
128 | { | ||
129 | SimInfo = m_regionProfileService.RequestSimProfileData( | ||
130 | theUser.CurrentAgent.Handle, m_config.GridServerURL, | ||
131 | m_config.GridSendKey, m_config.GridRecvKey); | ||
132 | |||
133 | if (SimInfo == null) | ||
134 | { | ||
135 | m_log.Error("[GRID]: Region user was in isn't currently logged in"); | ||
136 | return; | ||
137 | } | ||
138 | } | ||
139 | catch (Exception) | ||
140 | { | ||
141 | m_log.Error("[GRID]: Unable to look up region to log user off"); | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | // Prepare notification | ||
146 | Hashtable SimParams = new Hashtable(); | ||
147 | SimParams["agent_id"] = theUser.ID.ToString(); | ||
148 | SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString(); | ||
149 | SimParams["region_secret2"] = SimInfo.regionSecret; | ||
150 | //m_log.Info(SimInfo.regionSecret); | ||
151 | SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); | ||
152 | SimParams["message"] = message; | ||
153 | ArrayList SendParams = new ArrayList(); | ||
154 | SendParams.Add(SimParams); | ||
155 | |||
156 | m_log.InfoFormat( | ||
157 | "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", | ||
158 | SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, | ||
159 | theUser.FirstName + " " + theUser.SurName); | ||
160 | |||
161 | try | ||
162 | { | ||
163 | XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); | ||
164 | XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); | ||
165 | |||
166 | if (GridResp.IsFault) | ||
167 | { | ||
168 | m_log.ErrorFormat( | ||
169 | "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", | ||
170 | SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); | ||
171 | } | ||
172 | } | ||
173 | catch (Exception) | ||
174 | { | ||
175 | m_log.Error("[LOGIN]: Error telling region to logout user!"); | ||
176 | } | ||
177 | |||
178 | // Prepare notification | ||
179 | SimParams = new Hashtable(); | ||
180 | SimParams["agent_id"] = theUser.ID.ToString(); | ||
181 | SimParams["region_secret"] = SimInfo.regionSecret; | ||
182 | //m_log.Info(SimInfo.regionSecret); | ||
183 | SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); | ||
184 | SimParams["message"] = message; | ||
185 | SendParams = new ArrayList(); | ||
186 | SendParams.Add(SimParams); | ||
187 | |||
188 | m_log.InfoFormat( | ||
189 | "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", | ||
190 | SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, | ||
191 | theUser.FirstName + " " + theUser.SurName); | ||
192 | |||
193 | try | ||
194 | { | ||
195 | XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); | ||
196 | XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); | ||
197 | |||
198 | if (GridResp.IsFault) | ||
199 | { | ||
200 | m_log.ErrorFormat( | ||
201 | "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", | ||
202 | SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); | ||
203 | } | ||
204 | } | ||
205 | catch (Exception) | ||
206 | { | ||
207 | m_log.Error("[LOGIN]: Error telling region to logout user!"); | ||
208 | } | ||
209 | //base.LogOffUser(theUser); | ||
210 | } | ||
211 | |||
212 | protected override RegionInfo RequestClosestRegion(string region) | ||
213 | { | ||
214 | return GridRegionToRegionInfo(m_GridService.GetRegionByName(UUID.Zero, region)); | ||
215 | } | ||
216 | |||
217 | protected override RegionInfo GetRegionInfo(ulong homeRegionHandle) | ||
218 | { | ||
219 | uint x = 0, y = 0; | ||
220 | Utils.LongToUInts(homeRegionHandle, out x, out y); | ||
221 | return GridRegionToRegionInfo(m_GridService.GetRegionByPosition(UUID.Zero, (int)x, (int)y)); | ||
222 | } | ||
223 | |||
224 | protected override RegionInfo GetRegionInfo(UUID homeRegionId) | ||
225 | { | ||
226 | return GridRegionToRegionInfo(m_GridService.GetRegionByUUID(UUID.Zero, homeRegionId)); | ||
227 | } | ||
228 | |||
229 | private RegionInfo GridRegionToRegionInfo(GridRegion gregion) | ||
230 | { | ||
231 | if (gregion == null) | ||
232 | return null; | ||
233 | |||
234 | RegionInfo rinfo = new RegionInfo(); | ||
235 | rinfo.ExternalHostName = gregion.ExternalHostName; | ||
236 | rinfo.HttpPort = gregion.HttpPort; | ||
237 | rinfo.InternalEndPoint = gregion.InternalEndPoint; | ||
238 | rinfo.RegionID = gregion.RegionID; | ||
239 | rinfo.RegionLocX = (uint)(gregion.RegionLocX / Constants.RegionSize); | ||
240 | rinfo.RegionLocY = (uint)(gregion.RegionLocY / Constants.RegionSize); | ||
241 | rinfo.RegionName = gregion.RegionName; | ||
242 | rinfo.ScopeID = gregion.ScopeID; | ||
243 | rinfo.ServerURI = gregion.ServerURI; | ||
244 | |||
245 | return rinfo; | ||
246 | } | ||
247 | |||
248 | protected override bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response, IPEndPoint remoteClient) | ||
249 | { | ||
250 | return PrepareLoginToRegion(RegionProfileData.FromRegionInfo(regionInfo), user, response, remoteClient); | ||
251 | } | ||
252 | |||
253 | /// <summary> | ||
254 | /// Prepare a login to the given region. This involves both telling the region to expect a connection | ||
255 | /// and appropriately customising the response to the user. | ||
256 | /// </summary> | ||
257 | /// <param name="regionInfo"></param> | ||
258 | /// <param name="user"></param> | ||
259 | /// <param name="response"></param> | ||
260 | /// <returns>true if the region was successfully contacted, false otherwise</returns> | ||
261 | private bool PrepareLoginToRegion(RegionProfileData regionInfo, UserProfileData user, LoginResponse response, IPEndPoint remoteClient) | ||
262 | { | ||
263 | try | ||
264 | { | ||
265 | response.SimAddress = Util.GetHostFromURL(regionInfo.serverURI).ToString(); | ||
266 | response.SimPort = uint.Parse(regionInfo.serverURI.Split(new char[] { '/', ':' })[4]); | ||
267 | response.RegionX = regionInfo.regionLocX; | ||
268 | response.RegionY = regionInfo.regionLocY; | ||
269 | |||
270 | string capsPath = CapsUtil.GetRandomCapsObjectPath(); | ||
271 | |||
272 | // Adam's working code commented for now -- Diva 5/25/2009 | ||
273 | //// For NAT | ||
274 | ////string host = NetworkUtil.GetHostFor(remoteClient.Address, regionInfo.ServerIP); | ||
275 | //string host = response.SimAddress; | ||
276 | //// TODO: This doesnt support SSL. -Adam | ||
277 | //string serverURI = "http://" + host + ":" + regionInfo.ServerPort; | ||
278 | |||
279 | //response.SeedCapability = serverURI + CapsUtil.GetCapsSeedPath(capsPath); | ||
280 | |||
281 | // Take off trailing / so that the caps path isn't //CAPS/someUUID | ||
282 | string uri = regionInfo.httpServerURI.Trim(new char[] { '/' }); | ||
283 | response.SeedCapability = uri + CapsUtil.GetCapsSeedPath(capsPath); | ||
284 | |||
285 | |||
286 | // Notify the target of an incoming user | ||
287 | m_log.InfoFormat( | ||
288 | "[LOGIN]: Telling {0} @ {1},{2} ({3}) to prepare for client connection", | ||
289 | regionInfo.regionName, response.RegionX, response.RegionY, regionInfo.httpServerURI); | ||
290 | |||
291 | // Update agent with target sim | ||
292 | user.CurrentAgent.Region = regionInfo.UUID; | ||
293 | user.CurrentAgent.Handle = regionInfo.regionHandle; | ||
294 | |||
295 | // Prepare notification | ||
296 | Hashtable loginParams = new Hashtable(); | ||
297 | loginParams["session_id"] = user.CurrentAgent.SessionID.ToString(); | ||
298 | loginParams["secure_session_id"] = user.CurrentAgent.SecureSessionID.ToString(); | ||
299 | loginParams["firstname"] = user.FirstName; | ||
300 | loginParams["lastname"] = user.SurName; | ||
301 | loginParams["agent_id"] = user.ID.ToString(); | ||
302 | loginParams["circuit_code"] = (Int32)Convert.ToUInt32(response.CircuitCode); | ||
303 | loginParams["startpos_x"] = user.CurrentAgent.Position.X.ToString(); | ||
304 | loginParams["startpos_y"] = user.CurrentAgent.Position.Y.ToString(); | ||
305 | loginParams["startpos_z"] = user.CurrentAgent.Position.Z.ToString(); | ||
306 | loginParams["regionhandle"] = user.CurrentAgent.Handle.ToString(); | ||
307 | loginParams["caps_path"] = capsPath; | ||
308 | |||
309 | // Get appearance | ||
310 | AvatarAppearance appearance = m_userManager.GetUserAppearance(user.ID); | ||
311 | if (appearance != null) | ||
312 | { | ||
313 | loginParams["appearance"] = appearance.ToHashTable(); | ||
314 | m_log.DebugFormat("[LOGIN]: Found appearance for {0} {1}", user.FirstName, user.SurName); | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | m_log.DebugFormat("[LOGIN]: Appearance not for {0} {1}. Creating default.", user.FirstName, user.SurName); | ||
319 | appearance = new AvatarAppearance(user.ID); | ||
320 | loginParams["appearance"] = appearance.ToHashTable(); | ||
321 | } | ||
322 | |||
323 | ArrayList SendParams = new ArrayList(); | ||
324 | SendParams.Add(loginParams); | ||
325 | |||
326 | // Send | ||
327 | XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams); | ||
328 | XmlRpcResponse GridResp = GridReq.Send(regionInfo.httpServerURI, 6000); | ||
329 | |||
330 | if (!GridResp.IsFault) | ||
331 | { | ||
332 | bool responseSuccess = true; | ||
333 | |||
334 | if (GridResp.Value != null) | ||
335 | { | ||
336 | Hashtable resp = (Hashtable)GridResp.Value; | ||
337 | if (resp.ContainsKey("success")) | ||
338 | { | ||
339 | if ((string)resp["success"] == "FALSE") | ||
340 | { | ||
341 | responseSuccess = false; | ||
342 | } | ||
343 | } | ||
344 | } | ||
345 | |||
346 | if (responseSuccess) | ||
347 | { | ||
348 | handlerUserLoggedInAtLocation = OnUserLoggedInAtLocation; | ||
349 | if (handlerUserLoggedInAtLocation != null) | ||
350 | { | ||
351 | handlerUserLoggedInAtLocation(user.ID, user.CurrentAgent.SessionID, | ||
352 | user.CurrentAgent.Region, | ||
353 | user.CurrentAgent.Handle, | ||
354 | user.CurrentAgent.Position.X, | ||
355 | user.CurrentAgent.Position.Y, | ||
356 | user.CurrentAgent.Position.Z, | ||
357 | user.FirstName, user.SurName); | ||
358 | } | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | m_log.ErrorFormat("[LOGIN]: Region responded that it is not available to receive clients"); | ||
363 | return false; | ||
364 | } | ||
365 | } | ||
366 | else | ||
367 | { | ||
368 | m_log.ErrorFormat("[LOGIN]: XmlRpc request to region failed with message {0}, code {1} ", GridResp.FaultString, GridResp.FaultCode); | ||
369 | return false; | ||
370 | } | ||
371 | } | ||
372 | catch (Exception e) | ||
373 | { | ||
374 | m_log.ErrorFormat("[LOGIN]: Region not available for login, {0}", e); | ||
375 | return false; | ||
376 | } | ||
377 | |||
378 | return true; | ||
379 | } | ||
380 | |||
381 | public XmlRpcResponse XmlRPCSetLoginParams(XmlRpcRequest request, IPEndPoint remoteClient) | ||
382 | { | ||
383 | XmlRpcResponse response = new XmlRpcResponse(); | ||
384 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
385 | UserProfileData userProfile; | ||
386 | Hashtable responseData = new Hashtable(); | ||
387 | |||
388 | UUID uid; | ||
389 | string pass = requestData["password"].ToString(); | ||
390 | |||
391 | if (!UUID.TryParse((string)requestData["avatar_uuid"], out uid)) | ||
392 | { | ||
393 | responseData["error"] = "No authorization"; | ||
394 | response.Value = responseData; | ||
395 | return response; | ||
396 | } | ||
397 | |||
398 | userProfile = m_userManager.GetUserProfile(uid); | ||
399 | |||
400 | if (userProfile == null || | ||
401 | (!AuthenticateUser(userProfile, pass)) || | ||
402 | userProfile.GodLevel < 200) | ||
403 | { | ||
404 | responseData["error"] = "No authorization"; | ||
405 | response.Value = responseData; | ||
406 | return response; | ||
407 | } | ||
408 | |||
409 | if (requestData.ContainsKey("login_level")) | ||
410 | { | ||
411 | m_minLoginLevel = Convert.ToInt32(requestData["login_level"]); | ||
412 | } | ||
413 | |||
414 | if (requestData.ContainsKey("login_motd")) | ||
415 | { | ||
416 | m_welcomeMessage = requestData["login_motd"].ToString(); | ||
417 | } | ||
418 | |||
419 | response.Value = responseData; | ||
420 | return response; | ||
421 | } | ||
422 | } | ||
423 | } | ||