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