aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/UserManager/LoginService.cs281
-rw-r--r--OpenSim/Grid/UserServer/UserLoginService.cs80
-rw-r--r--OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs2
-rw-r--r--OpenSim/Region/Communications/Local/LocalLoginService.cs113
4 files changed, 474 insertions, 2 deletions
diff --git a/OpenSim/Framework/UserManager/LoginService.cs b/OpenSim/Framework/UserManager/LoginService.cs
new file mode 100644
index 0000000..a26a0c4
--- /dev/null
+++ b/OpenSim/Framework/UserManager/LoginService.cs
@@ -0,0 +1,281 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Reflection;
5using System.Security.Cryptography;
6using libsecondlife;
7using Nwc.XmlRpc;
8using OpenSim.Framework.Console;
9using OpenSim.Framework.Data;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Inventory;
12using OpenSim.Framework.Utilities;
13
14using OpenSim.Framework.Configuration;
15using InventoryFolder = OpenSim.Framework.Inventory.InventoryFolder;
16
17namespace OpenSim.Framework.UserManagement
18{
19 public class LoginService
20 {
21 protected string m_welcomeMessage = "Welcome to OpenSim";
22 protected UserManagerBase m_userManager = null;
23
24 public LoginService(UserManagerBase userManager, string welcomeMess)
25 {
26 m_userManager = userManager;
27 if (welcomeMess != "")
28 {
29 m_welcomeMessage = welcomeMess;
30 }
31 }
32
33 /// <summary>
34 /// Main user login function
35 /// </summary>
36 /// <param name="request">The XMLRPC request</param>
37 /// <returns>The response to send</returns>
38 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
39 {
40
41 System.Console.WriteLine("Attempting login now...");
42 XmlRpcResponse response = new XmlRpcResponse();
43 Hashtable requestData = (Hashtable)request.Params[0];
44
45 bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
46 bool GoodLogin = false;
47 string firstname = "";
48 string lastname = "";
49 string passwd = "";
50
51 UserProfileData userProfile;
52 LoginResponse logResponse = new LoginResponse();
53
54 if (GoodXML)
55 {
56 firstname = (string)requestData["first"];
57 lastname = (string)requestData["last"];
58 passwd = (string)requestData["passwd"];
59
60 userProfile = GetTheUser(firstname, lastname);
61 if (userProfile == null)
62 return logResponse.CreateLoginFailedResponse();
63
64 GoodLogin = AuthenticateUser(userProfile, passwd);
65 }
66 else
67 {
68 return logResponse.CreateGridErrorResponse();
69 }
70
71 if (!GoodLogin)
72 {
73 return logResponse.CreateLoginFailedResponse();
74 }
75 else
76 {
77 // If we already have a session...
78 if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline)
79 {
80 // Reject the login
81 return logResponse.CreateAlreadyLoggedInResponse();
82 }
83 // Otherwise...
84 // Create a new agent session
85 CreateAgent(userProfile, request);
86
87 try
88 {
89 LLUUID agentID = userProfile.UUID;
90
91 // Inventory Library Section
92 AgentInventory userInventory = this.GetUsersInventory(agentID);
93 ArrayList AgentInventoryArray = this.CreateInventoryArray(userInventory);
94
95 Hashtable InventoryRootHash = new Hashtable();
96 InventoryRootHash["folder_id"] = userInventory.InventoryRoot.FolderID.ToStringHyphenated();
97 ArrayList InventoryRoot = new ArrayList();
98 InventoryRoot.Add(InventoryRootHash);
99 userProfile.rootInventoryFolderID = userInventory.InventoryRoot.FolderID;
100
101 // Circuit Code
102 uint circode = (uint)(Util.RandomClass.Next());
103
104 logResponse.Lastname = userProfile.surname;
105 logResponse.Firstname = userProfile.username;
106 logResponse.AgentID = agentID.ToStringHyphenated();
107 logResponse.SessionID = userProfile.currentAgent.sessionID.ToStringHyphenated();
108 logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated();
109 logResponse.InventoryRoot = InventoryRoot;
110 logResponse.InventorySkeleton = AgentInventoryArray;
111 logResponse.InventoryLibrary = this.GetInventoryLibrary();
112 logResponse.InventoryLibraryOwner = this.GetLibraryOwner();
113 logResponse.CircuitCode = (Int32)circode;
114 //logResponse.RegionX = 0; //overwritten
115 //logResponse.RegionY = 0; //overwritten
116 logResponse.Home = "!!null temporary value {home}!!"; // Overwritten
117 //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
118 //logResponse.SimAddress = "127.0.0.1"; //overwritten
119 //logResponse.SimPort = 0; //overwritten
120 logResponse.Message = this.GetMessage();
121
122 try
123 {
124 this.CustomiseResponse(logResponse, userProfile);
125 }
126 catch (Exception e)
127 {
128 System.Console.WriteLine(e.ToString());
129 return logResponse.CreateDeadRegionResponse();
130 //return logResponse.ToXmlRpcResponse();
131 }
132 CommitAgent(ref userProfile);
133 return logResponse.ToXmlRpcResponse();
134
135 }
136
137 catch (Exception E)
138 {
139 System.Console.WriteLine(E.ToString());
140 }
141 //}
142 }
143 return response;
144
145 }
146
147 /// <summary>
148 /// Customises the login response and fills in missing values.
149 /// </summary>
150 /// <param name="response">The existing response</param>
151 /// <param name="theUser">The user profile</param>
152 public virtual void CustomiseResponse(LoginResponse response, UserProfileData theUser)
153 {
154 }
155
156 /// <summary>
157 /// Saves a target agent to the database
158 /// </summary>
159 /// <param name="profile">The users profile</param>
160 /// <returns>Successful?</returns>
161 public bool CommitAgent(ref UserProfileData profile)
162 {
163 // Saves the agent to database
164 return true;
165 }
166
167
168 /// <summary>
169 /// Checks a user against it's password hash
170 /// </summary>
171 /// <param name="profile">The users profile</param>
172 /// <param name="password">The supplied password</param>
173 /// <returns>Authenticated?</returns>
174 public virtual bool AuthenticateUser(UserProfileData profile, string password)
175 {
176 MainLog.Instance.Verbose(
177 "Authenticating " + profile.username + " " + profile.surname);
178
179 password = password.Remove(0, 3); //remove $1$
180
181 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
182
183 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
184 }
185
186 /// <summary>
187 ///
188 /// </summary>
189 /// <param name="profile"></param>
190 /// <param name="request"></param>
191 public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
192 {
193 this.m_userManager.CreateAgent(profile, request);
194 }
195
196 /// <summary>
197 ///
198 /// </summary>
199 /// <param name="firstname"></param>
200 /// <param name="lastname"></param>
201 /// <returns></returns>
202 public virtual UserProfileData GetTheUser(string firstname, string lastname)
203 {
204 return this.m_userManager.getUserProfile(firstname, lastname);
205 }
206
207 /// <summary>
208 ///
209 /// </summary>
210 /// <returns></returns>
211 public virtual string GetMessage()
212 {
213 return m_welcomeMessage;
214 }
215
216 /// <summary>
217 ///
218 /// </summary>
219 /// <returns></returns>
220 protected virtual ArrayList GetInventoryLibrary()
221 {
222 //return new ArrayList();
223 Hashtable TempHash = new Hashtable();
224 TempHash["name"] = "OpenSim Library";
225 TempHash["parent_id"] = LLUUID.Zero.ToStringHyphenated();
226 TempHash["version"] = "1";
227 TempHash["type_default"] = "-1";
228 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
229 ArrayList temp = new ArrayList();
230 temp.Add(TempHash);
231
232 TempHash = new Hashtable();
233 TempHash["name"] = "Texture Library";
234 TempHash["parent_id"] = "00000112-000f-0000-0000-000100bba000";
235 TempHash["version"] = "1";
236 TempHash["type_default"] = "-1";
237 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba001";
238 temp.Add(TempHash);
239 return temp;
240 }
241
242 /// <summary>
243 ///
244 /// </summary>
245 /// <returns></returns>
246 protected virtual ArrayList GetLibraryOwner()
247 {
248 //for now create random inventory library owner
249 Hashtable TempHash = new Hashtable();
250 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
251 ArrayList inventoryLibOwner = new ArrayList();
252 inventoryLibOwner.Add(TempHash);
253 return inventoryLibOwner;
254 }
255
256 protected virtual AgentInventory GetUsersInventory(LLUUID agentID)
257 {
258 AgentInventory userInventory = new AgentInventory();
259 userInventory.CreateRootFolder(agentID, false);
260
261 return userInventory;
262 }
263
264 protected virtual ArrayList CreateInventoryArray(AgentInventory userInventory)
265 {
266 ArrayList AgentInventoryArray = new ArrayList();
267 Hashtable TempHash;
268 foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values)
269 {
270 TempHash = new Hashtable();
271 TempHash["name"] = InvFolder.FolderName;
272 TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
273 TempHash["version"] = (Int32)InvFolder.Version;
274 TempHash["type_default"] = (Int32)InvFolder.DefaultType;
275 TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
276 AgentInventoryArray.Add(TempHash);
277 }
278 return AgentInventoryArray;
279 }
280 }
281}
diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs
new file mode 100644
index 0000000..57652b0
--- /dev/null
+++ b/OpenSim/Grid/UserServer/UserLoginService.cs
@@ -0,0 +1,80 @@
1using System;
2using System.Collections;
3using System.Net;
4using Nwc.XmlRpc;
5using OpenSim.Framework.Data;
6using OpenSim.Framework.UserManagement;
7using OpenSim.Framework.Utilities;
8using OpenSim.Framework.Configuration;
9
10namespace OpenSim.Grid.UserServer
11{
12 public class UserLoginService : LoginService
13 {
14 public UserConfig m_config;
15
16 public UserLoginService(UserManagerBase userManager, UserConfig config, string welcomeMess)
17 : base(userManager, welcomeMess)
18 {
19 m_config = config;
20 }
21
22 /// <summary>
23 /// Customises the login response and fills in missing values.
24 /// </summary>
25 /// <param name="response">The existing response</param>
26 /// <param name="theUser">The user profile</param>
27 public override void CustomiseResponse(LoginResponse response, UserProfileData theUser)
28 {
29 // Load information from the gridserver
30 SimProfileData SimInfo = new SimProfileData();
31 SimInfo = SimInfo.RequestSimProfileData(theUser.currentAgent.currentHandle, m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey);
32
33 // Customise the response
34 // Home Location
35 response.Home = "{'region_handle':[r" + (SimInfo.regionLocX * 256).ToString() + ",r" + (SimInfo.regionLocY * 256).ToString() + "], " +
36 "'position':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
37 "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
38
39 // Destination
40 Console.WriteLine("CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " + SimInfo.regionLocY);
41 response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
42 response.SimPort = (Int32)SimInfo.serverPort;
43 response.RegionX = SimInfo.regionLocX;
44 response.RegionY = SimInfo.regionLocY;
45
46 //Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
47 string capsPath = Util.GetRandomCapsPath();
48 response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
49
50 // Notify the target of an incoming user
51 Console.WriteLine("Notifying " + SimInfo.regionName + " (" + SimInfo.serverURI + ")");
52
53 // Prepare notification
54 Hashtable SimParams = new Hashtable();
55 SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
56 SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
57 SimParams["firstname"] = theUser.username;
58 SimParams["lastname"] = theUser.surname;
59 SimParams["agent_id"] = theUser.UUID.ToString();
60 SimParams["circuit_code"] = (Int32)Convert.ToUInt32(response.CircuitCode);
61 SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
62 SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
63 SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
64 SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
65 SimParams["caps_path"] = capsPath;
66 ArrayList SendParams = new ArrayList();
67 SendParams.Add(SimParams);
68
69 // Update agent with target sim
70 theUser.currentAgent.currentRegion = SimInfo.UUID;
71 theUser.currentAgent.currentHandle = SimInfo.regionHandle;
72
73 System.Console.WriteLine("Informing region --> " + SimInfo.httpServerURI);
74 // Send
75 XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
76 XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 3000);
77 }
78 }
79}
80
diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
index 401f500..58d4cfe 100644
--- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
+++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
@@ -443,8 +443,6 @@ namespace OpenSim.Region.ClientStack
443 case PacketType.UpdateTaskInventory: 443 case PacketType.UpdateTaskInventory:
444 // Console.WriteLine(Pack.ToString()); 444 // Console.WriteLine(Pack.ToString());
445 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack; 445 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
446 AgentInventory myinventory = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
447
448 break; 446 break;
449 case PacketType.MapLayerRequest: 447 case PacketType.MapLayerRequest:
450 this.RequestMapLayer(); 448 this.RequestMapLayer();
diff --git a/OpenSim/Region/Communications/Local/LocalLoginService.cs b/OpenSim/Region/Communications/Local/LocalLoginService.cs
new file mode 100644
index 0000000..19a1e8c
--- /dev/null
+++ b/OpenSim/Region/Communications/Local/LocalLoginService.cs
@@ -0,0 +1,113 @@
1using System;
2using libsecondlife;
3using OpenSim.Framework.Communications;
4using OpenSim.Framework.Data;
5using OpenSim.Framework.Types;
6using OpenSim.Framework.UserManagement;
7using OpenSim.Framework.Utilities;
8
9namespace OpenSim.Region.Communications.Local
10{
11 public class LocalLoginService : LoginService
12 {
13 private CommunicationsLocal m_Parent;
14
15 private NetworkServersInfo serversInfo;
16 private uint defaultHomeX;
17 private uint defaultHomeY;
18 private bool authUsers = false;
19
20 public LocalLoginService(UserManagerBase userManager, string welcomeMess, CommunicationsLocal parent, NetworkServersInfo serversInfo, bool authenticate)
21 : base(userManager, welcomeMess)
22 {
23 m_Parent = parent;
24 this.serversInfo = serversInfo;
25 defaultHomeX = this.serversInfo.DefaultHomeLocX;
26 defaultHomeY = this.serversInfo.DefaultHomeLocY;
27 this.authUsers = authenticate;
28 }
29
30
31 public override UserProfileData GetTheUser(string firstname, string lastname)
32 {
33 UserProfileData profile = this.m_userManager.getUserProfile(firstname, lastname);
34 if (profile != null)
35 {
36
37 return profile;
38 }
39
40 if (!authUsers)
41 {
42 //no current user account so make one
43 Console.WriteLine("No User account found so creating a new one ");
44 this.m_userManager.AddUserProfile(firstname, lastname, "test", defaultHomeX, defaultHomeY);
45
46 profile = this.m_userManager.getUserProfile(firstname, lastname);
47
48 return profile;
49 }
50 return null;
51 }
52
53 public override bool AuthenticateUser(UserProfileData profile, string password)
54 {
55 if (!authUsers)
56 {
57 //for now we will accept any password in sandbox mode
58 Console.WriteLine("authorising user");
59 return true;
60 }
61 else
62 {
63 Console.WriteLine("Authenticating " + profile.username + " " + profile.surname);
64
65 password = password.Remove(0, 3); //remove $1$
66
67 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
68
69 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
70 }
71 }
72
73 public override void CustomiseResponse(LoginResponse response, UserProfileData theUser)
74 {
75 ulong currentRegion = theUser.currentAgent.currentHandle;
76 RegionInfo reg = m_Parent.GridServer.RequestNeighbourInfo(currentRegion);
77
78 if (reg != null)
79 {
80 response.Home = "{'region_handle':[r" + (reg.RegionLocX * 256).ToString() + ",r" + (reg.RegionLocY * 256).ToString() + "], " +
81 "'position':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
82 "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
83 string capsPath = Util.GetRandomCapsPath();
84 response.SimAddress = reg.ExternalEndPoint.Address.ToString();
85 response.SimPort = (Int32)reg.ExternalEndPoint.Port;
86 response.RegionX = reg.RegionLocX;
87 response.RegionY = reg.RegionLocY;
88
89 //following port needs changing as we don't want a http listener for every region (or do we?)
90 response.SeedCapability = "http://" + reg.ExternalHostName + ":" + this.serversInfo.HttpListenerPort.ToString() + "/CAPS/" + capsPath + "0000/";
91 theUser.currentAgent.currentRegion = reg.SimUUID;
92 theUser.currentAgent.currentHandle = reg.RegionHandle;
93
94 Login _login = new Login();
95 //copy data to login object
96 _login.First = response.Firstname;
97 _login.Last = response.Lastname;
98 _login.Agent = response.AgentID;
99 _login.Session = response.SessionID;
100 _login.SecureSession = response.SecureSessionID;
101 _login.CircuitCode = (uint)response.CircuitCode;
102 _login.CapsPath = capsPath;
103
104 m_Parent.InformRegionOfLogin(currentRegion, _login);
105 }
106 else
107 {
108 Console.WriteLine("not found region " + currentRegion);
109 }
110
111 }
112 }
113}