aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/UserManager/LoginService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/UserManager/LoginService.cs')
-rw-r--r--OpenSim/Framework/UserManager/LoginService.cs281
1 files changed, 281 insertions, 0 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}