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