aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/LoginService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/LoginService.cs')
-rw-r--r--OpenSim/Framework/Communications/LoginService.cs287
1 files changed, 287 insertions, 0 deletions
diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs
new file mode 100644
index 0000000..8e7cf80
--- /dev/null
+++ b/OpenSim/Framework/Communications/LoginService.cs
@@ -0,0 +1,287 @@
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
48 UserProfileData userProfile;
49 LoginResponse logResponse = new LoginResponse();
50
51 if (GoodXML)
52 {
53 string firstname = (string)requestData["first"];
54 string lastname = (string)requestData["last"];
55 string passwd = (string)requestData["passwd"];
56
57 userProfile = GetTheUser(firstname, lastname);
58 if (userProfile == null)
59 return logResponse.CreateLoginFailedResponse();
60
61 GoodLogin = AuthenticateUser(userProfile, passwd);
62 }
63 else
64 {
65 return logResponse.CreateGridErrorResponse();
66 }
67
68 if (!GoodLogin)
69 {
70 return logResponse.CreateLoginFailedResponse();
71 }
72 else
73 {
74 // If we already have a session...
75 if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline)
76 {
77 // Reject the login
78 return logResponse.CreateAlreadyLoggedInResponse();
79 }
80 // Otherwise...
81 // Create a new agent session
82 CreateAgent(userProfile, request);
83
84 try
85 {
86 LLUUID agentID = userProfile.UUID;
87
88 // Inventory Library Section
89 InventoryData inventData = this.CreateInventoryData(agentID);
90 ArrayList AgentInventoryArray = inventData.InventoryArray;
91
92 Hashtable InventoryRootHash = new Hashtable();
93 InventoryRootHash["folder_id"] = inventData.RootFolderID.ToStringHyphenated();
94 ArrayList InventoryRoot = new ArrayList();
95 InventoryRoot.Add(InventoryRootHash);
96 userProfile.rootInventoryFolderID = inventData.RootFolderID;
97
98 // Circuit Code
99 uint circode = (uint)(Util.RandomClass.Next());
100
101 logResponse.Lastname = userProfile.surname;
102 logResponse.Firstname = userProfile.username;
103 logResponse.AgentID = agentID.ToStringHyphenated();
104 logResponse.SessionID = userProfile.currentAgent.sessionID.ToStringHyphenated();
105 logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated();
106 logResponse.InventoryRoot = InventoryRoot;
107 logResponse.InventorySkeleton = AgentInventoryArray;
108 logResponse.InventoryLibrary = this.GetInventoryLibrary();
109 logResponse.InventoryLibraryOwner = this.GetLibraryOwner();
110 logResponse.CircuitCode = (Int32)circode;
111 //logResponse.RegionX = 0; //overwritten
112 //logResponse.RegionY = 0; //overwritten
113 logResponse.Home = "!!null temporary value {home}!!"; // Overwritten
114 //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
115 //logResponse.SimAddress = "127.0.0.1"; //overwritten
116 //logResponse.SimPort = 0; //overwritten
117 logResponse.Message = this.GetMessage();
118
119 try
120 {
121 this.CustomiseResponse(logResponse, userProfile);
122 }
123 catch (Exception e)
124 {
125 System.Console.WriteLine(e.ToString());
126 return logResponse.CreateDeadRegionResponse();
127 //return logResponse.ToXmlRpcResponse();
128 }
129 CommitAgent(ref userProfile);
130 return logResponse.ToXmlRpcResponse();
131
132 }
133
134 catch (Exception E)
135 {
136 System.Console.WriteLine(E.ToString());
137 }
138 //}
139 }
140 return response;
141
142 }
143
144 /// <summary>
145 /// Customises the login response and fills in missing values.
146 /// </summary>
147 /// <param name="response">The existing response</param>
148 /// <param name="theUser">The user profile</param>
149 public virtual void CustomiseResponse(LoginResponse response, UserProfileData theUser)
150 {
151 }
152
153 /// <summary>
154 /// Saves a target agent to the database
155 /// </summary>
156 /// <param name="profile">The users profile</param>
157 /// <returns>Successful?</returns>
158 public bool CommitAgent(ref UserProfileData profile)
159 {
160 // Saves the agent to database
161 return true;
162 }
163
164
165 /// <summary>
166 /// Checks a user against it's password hash
167 /// </summary>
168 /// <param name="profile">The users profile</param>
169 /// <param name="password">The supplied password</param>
170 /// <returns>Authenticated?</returns>
171 public virtual bool AuthenticateUser(UserProfileData profile, string password)
172 {
173
174 MainLog.Instance.Verbose(
175 "Authenticating " + profile.username + " " + profile.surname);
176
177 password = password.Remove(0, 3); //remove $1$
178
179 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
180
181 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
182 }
183
184 /// <summary>
185 ///
186 /// </summary>
187 /// <param name="profile"></param>
188 /// <param name="request"></param>
189 public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
190 {
191 this.m_userManager.CreateAgent(profile, request);
192 }
193
194 /// <summary>
195 ///
196 /// </summary>
197 /// <param name="firstname"></param>
198 /// <param name="lastname"></param>
199 /// <returns></returns>
200 public virtual UserProfileData GetTheUser(string firstname, string lastname)
201 {
202 return this.m_userManager.GetUserProfile(firstname, lastname);
203 }
204
205 /// <summary>
206 ///
207 /// </summary>
208 /// <returns></returns>
209 public virtual string GetMessage()
210 {
211 return m_welcomeMessage;
212 }
213
214 /// <summary>
215 ///
216 /// </summary>
217 /// <returns></returns>
218 protected virtual ArrayList GetInventoryLibrary()
219 {
220 //return new ArrayList();
221 Hashtable TempHash = new Hashtable();
222 TempHash["name"] = "OpenSim Library";
223 TempHash["parent_id"] = LLUUID.Zero.ToStringHyphenated();
224 TempHash["version"] = 1;
225 TempHash["type_default"] = -1;
226 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
227 ArrayList temp = new ArrayList();
228 temp.Add(TempHash);
229
230 TempHash = new Hashtable();
231 TempHash["name"] = "Texture Library";
232 TempHash["parent_id"] = "00000112-000f-0000-0000-000100bba000";
233 TempHash["version"] = 1;
234 TempHash["type_default"] = -1;
235 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba001";
236 temp.Add(TempHash);
237 return temp;
238 }
239
240 /// <summary>
241 ///
242 /// </summary>
243 /// <returns></returns>
244 protected virtual ArrayList GetLibraryOwner()
245 {
246 //for now create random inventory library owner
247 Hashtable TempHash = new Hashtable();
248 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
249 ArrayList inventoryLibOwner = new ArrayList();
250 inventoryLibOwner.Add(TempHash);
251 return inventoryLibOwner;
252 }
253
254 protected virtual InventoryData CreateInventoryData(LLUUID userID)
255 {
256 AgentInventory userInventory = new AgentInventory();
257 userInventory.CreateRootFolder(userID, false);
258
259 ArrayList AgentInventoryArray = new ArrayList();
260 Hashtable TempHash;
261 foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values)
262 {
263 TempHash = new Hashtable();
264 TempHash["name"] = InvFolder.FolderName;
265 TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
266 TempHash["version"] = (Int32)InvFolder.Version;
267 TempHash["type_default"] = (Int32)InvFolder.DefaultType;
268 TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
269 AgentInventoryArray.Add(TempHash);
270 }
271
272 return new InventoryData(AgentInventoryArray, userInventory.InventoryRoot.FolderID);
273 }
274
275 public class InventoryData
276 {
277 public ArrayList InventoryArray = null;
278 public LLUUID RootFolderID = LLUUID.Zero;
279
280 public InventoryData(ArrayList invList, LLUUID rootID)
281 {
282 InventoryArray = invList;
283 RootFolderID = rootID;
284 }
285 }
286 }
287}