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