aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.UserServer
diff options
context:
space:
mode:
Diffstat (limited to 'OpenGridServices.UserServer')
-rw-r--r--OpenGridServices.UserServer/Main.cs20
-rw-r--r--OpenGridServices.UserServer/UserManager.cs340
2 files changed, 346 insertions, 14 deletions
diff --git a/OpenGridServices.UserServer/Main.cs b/OpenGridServices.UserServer/Main.cs
index 1c6ad8c..5006e6d 100644
--- a/OpenGridServices.UserServer/Main.cs
+++ b/OpenGridServices.UserServer/Main.cs
@@ -52,7 +52,7 @@ namespace OpenGridServices.UserServer
52 52
53 public UserManager m_userManager; // Replaces below. 53 public UserManager m_userManager; // Replaces below.
54 54
55 private UserProfileManager m_userProfileManager; 55 //private UserProfileManager m_userProfileManager; // Depreciated
56 56
57 public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>(); 57 public Dictionary<LLUUID, UserProfile> UserSessions = new Dictionary<LLUUID, UserProfile>();
58 58
@@ -93,17 +93,18 @@ namespace OpenGridServices.UserServer
93 93
94 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Establishing data connection"); 94 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Establishing data connection");
95 m_userManager = new UserManager(); 95 m_userManager = new UserManager();
96 m_userManager._config = Cfg;
96 97
97 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Creating user profile manager"); 98 //MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Creating user profile manager");
98 m_userProfileManager = new UserProfileManager(); 99 //m_userProfileManager = new UserProfileManager();
99 m_userProfileManager.InitUserProfiles(); 100 //m_userProfileManager.InitUserProfiles();
100 m_userProfileManager.SetKeys(Cfg.GridSendKey, Cfg.GridRecvKey, Cfg.GridServerURL, Cfg.DefaultStartupMsg); 101 //m_userProfileManager.SetKeys(Cfg.GridSendKey, Cfg.GridRecvKey, Cfg.GridServerURL, Cfg.DefaultStartupMsg);
101 102
102 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process"); 103 MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process");
103 BaseHttpServer httpServer = new BaseHttpServer(8002); 104 BaseHttpServer httpServer = new BaseHttpServer(8002);
104 105
105 httpServer.AddXmlRPCHandler("login_to_simulator", m_userProfileManager.XmlRpcLoginMethod); 106 httpServer.AddXmlRPCHandler("login_to_simulator", m_userManager.XmlRpcLoginMethod);
106 httpServer.AddRestHandler("DELETE", "/usersessions/", m_userProfileManager.RestDeleteUserSessionMethod); 107 httpServer.AddRestHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod);
107 108
108 httpServer.Start(); 109 httpServer.Start();
109 } 110 }
@@ -114,7 +115,9 @@ namespace OpenGridServices.UserServer
114 switch (what) 115 switch (what)
115 { 116 {
116 case "user": 117 case "user":
117 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"Creating new user profile"); 118 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"Commandline user creation is currently disabled.");
119 break;
120 /*
118 string tempfirstname; 121 string tempfirstname;
119 string templastname; 122 string templastname;
120 string tempMD5Passwd; 123 string tempMD5Passwd;
@@ -138,6 +141,7 @@ namespace OpenGridServices.UserServer
138 newuser.homepos = new LLVector3(128f, 128f, 150f); 141 newuser.homepos = new LLVector3(128f, 128f, 150f);
139 m_userProfileManager.SaveUserProfiles(); 142 m_userProfileManager.SaveUserProfiles();
140 break; 143 break;
144 */
141 } 145 }
142 } 146 }
143 147
diff --git a/OpenGridServices.UserServer/UserManager.cs b/OpenGridServices.UserServer/UserManager.cs
index 057fb79..b93c26f 100644
--- a/OpenGridServices.UserServer/UserManager.cs
+++ b/OpenGridServices.UserServer/UserManager.cs
@@ -1,4 +1,5 @@
1using System; 1using System;
2using System.Collections;
2using System.Collections.Generic; 3using System.Collections.Generic;
3using System.Text; 4using System.Text;
4using OpenGrid.Framework.Data; 5using OpenGrid.Framework.Data;
@@ -11,10 +12,13 @@ using OpenSim.Framework.Sims;
11using OpenSim.Framework.Inventory; 12using OpenSim.Framework.Inventory;
12using OpenSim.Framework.Utilities; 13using OpenSim.Framework.Utilities;
13 14
15using System.Security.Cryptography;
16
14namespace OpenGridServices.UserServer 17namespace OpenGridServices.UserServer
15{ 18{
16 public class UserManager 19 public class UserManager
17 { 20 {
21 public OpenSim.Framework.Interfaces.UserConfig _config;
18 Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>(); 22 Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>();
19 23
20 /// <summary> 24 /// <summary>
@@ -23,10 +27,10 @@ namespace OpenGridServices.UserServer
23 /// <param name="FileName">The filename to the user server plugin DLL</param> 27 /// <param name="FileName">The filename to the user server plugin DLL</param>
24 public void AddPlugin(string FileName) 28 public void AddPlugin(string FileName)
25 { 29 {
26 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Storage: Attempting to load " + FileName); 30 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Userstorage: Attempting to load " + FileName);
27 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 31 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
28 32
29 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Storage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); 33 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Userstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
30 foreach (Type pluginType in pluginAssembly.GetTypes()) 34 foreach (Type pluginType in pluginAssembly.GetTypes())
31 { 35 {
32 if (!pluginType.IsAbstract) 36 if (!pluginType.IsAbstract)
@@ -38,7 +42,7 @@ namespace OpenGridServices.UserServer
38 IUserData plug = (IUserData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 42 IUserData plug = (IUserData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
39 plug.Initialise(); 43 plug.Initialise();
40 this._plugins.Add(plug.getName(), plug); 44 this._plugins.Add(plug.getName(), plug);
41 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Storage: Added IUserData Interface"); 45 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Userstorage: Added IUserData Interface");
42 } 46 }
43 47
44 typeInterface = null; 48 typeInterface = null;
@@ -54,7 +58,9 @@ namespace OpenGridServices.UserServer
54 { 58 {
55 try 59 try
56 { 60 {
57 return plugin.Value.getUserByUUID(uuid); 61 UserProfileData profile = plugin.Value.getUserByUUID(uuid);
62 profile.currentAgent = getUserAgent(profile.UUID);
63 return profile;
58 } 64 }
59 catch (Exception e) 65 catch (Exception e)
60 { 66 {
@@ -71,7 +77,9 @@ namespace OpenGridServices.UserServer
71 { 77 {
72 try 78 try
73 { 79 {
74 return plugin.Value.getUserByName(name); 80 UserProfileData profile = plugin.Value.getUserByName(name);
81 profile.currentAgent = getUserAgent(profile.UUID);
82 return profile;
75 } 83 }
76 catch (Exception e) 84 catch (Exception e)
77 { 85 {
@@ -88,7 +96,9 @@ namespace OpenGridServices.UserServer
88 { 96 {
89 try 97 try
90 { 98 {
91 return plugin.Value.getUserByName(fname,lname); 99 UserProfileData profile = plugin.Value.getUserByName(fname,lname);
100 profile.currentAgent = getUserAgent(profile.UUID);
101 return profile;
92 } 102 }
93 catch (Exception e) 103 catch (Exception e)
94 { 104 {
@@ -149,5 +159,323 @@ namespace OpenGridServices.UserServer
149 159
150 return null; 160 return null;
151 } 161 }
162
163 private static XmlRpcResponse CreateErrorConnectingToGridResponse()
164 {
165 XmlRpcResponse response = new XmlRpcResponse();
166 Hashtable ErrorRespData = new Hashtable();
167 ErrorRespData["reason"] = "key";
168 ErrorRespData["message"] = "Error connecting to grid. Could not percieve credentials from login XML.";
169 ErrorRespData["login"] = "false";
170 response.Value = ErrorRespData;
171 return response;
172 }
173
174 private static XmlRpcResponse CreateLoginErrorResponse()
175 {
176 XmlRpcResponse response = new XmlRpcResponse();
177 Hashtable ErrorRespData = new Hashtable();
178 ErrorRespData["reason"] = "key";
179 ErrorRespData["message"] = "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.";
180 ErrorRespData["login"] = "false";
181 response.Value = ErrorRespData;
182 return response;
183 }
184
185 private static XmlRpcResponse CreateAlreadyLoggedInResponse()
186 {
187 XmlRpcResponse response = new XmlRpcResponse();
188 Hashtable PresenceErrorRespData = new Hashtable();
189 PresenceErrorRespData["reason"] = "presence";
190 PresenceErrorRespData["message"] = "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner";
191 PresenceErrorRespData["login"] = "false";
192 response.Value = PresenceErrorRespData;
193 return response;
194 }
195
196 public virtual void CustomiseResponse(ref Hashtable response, ref UserProfileData theUser)
197 {
198 // Load information from the gridserver
199 SimProfile SimInfo = new SimProfile();
200 SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey);
201
202 // Customise the response
203 // Home Location
204 response["home"] = "{'region_handle':[r" + (SimInfo.RegionLocX * 256).ToString() + ",r" + (SimInfo.RegionLocY * 256).ToString() + "], " +
205 "'position':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
206 "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
207
208 // Destination
209 response["sim_ip"] = SimInfo.sim_ip;
210 response["sim_port"] = (Int32)SimInfo.sim_port;
211 response["region_y"] = (Int32)SimInfo.RegionLocY * 256;
212 response["region_x"] = (Int32)SimInfo.RegionLocX * 256;
213
214 // Notify the target of an incoming user
215 Console.WriteLine("Notifying " + SimInfo.regionname + " (" + SimInfo.caps_url + ")");
216
217 // Prepare notification
218 Hashtable SimParams = new Hashtable();
219 SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
220 SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
221 SimParams["firstname"] = theUser.username;
222 SimParams["lastname"] = theUser.surname;
223 SimParams["agent_id"] = theUser.UUID.ToString();
224 SimParams["circuit_code"] = (Int32)Convert.ToUInt32(response["circuit_code"]);
225 SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
226 SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
227 SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
228 ArrayList SendParams = new ArrayList();
229 SendParams.Add(SimParams);
230
231 // Update agent with target sim
232 theUser.currentAgent.currentRegion = SimInfo.UUID;
233 theUser.currentAgent.currentHandle = SimInfo.regionhandle;
234
235 // Send
236 XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
237 XmlRpcResponse GridResp = GridReq.Send(SimInfo.caps_url, 3000);
238 }
239
240 public bool AuthenticateUser(ref UserProfileData profile, string password)
241 {
242 password = password.Remove(0, 3); //remove $1$
243
244 MD5CryptoServiceProvider MD5summer = new MD5CryptoServiceProvider();
245
246 byte[] byteString = System.Text.Encoding.ASCII.GetBytes(password + ":" + profile.passwordSalt);
247
248 byteString = MD5summer.ComputeHash(byteString);
249 System.Text.StringBuilder s = new System.Text.StringBuilder();
250 foreach (byte b in byteString)
251 {
252 s.Append(b.ToString("x2").ToLower());
253 }
254
255 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
256 }
257
258 public void CreateAgent(ref UserProfileData profile, XmlRpcRequest request)
259 {
260 Hashtable requestData = (Hashtable)request.Params[0];
261
262 UserAgentData agent = new UserAgentData();
263
264 // User connection
265 agent.agentIP = "";
266 agent.agentOnline = true;
267 agent.agentPort = 0;
268
269 // Generate sessions
270 RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
271 byte[] randDataS = new byte[16];
272 byte[] randDataSS = new byte[16];
273 rand.GetBytes(randDataS);
274 rand.GetBytes(randDataSS);
275
276 agent.secureSessionID = new LLUUID(randDataSS, 0);
277 agent.sessionID = new LLUUID(randDataS, 0);
278
279 // Profile UUID
280 agent.UUID = profile.UUID;
281
282 // Current position (from Home)
283 agent.currentHandle = profile.homeRegion;
284 agent.currentPos = profile.homeLocation;
285
286 // If user specified additional start, use that
287 if (requestData.ContainsKey("start"))
288 {
289 string startLoc = (string)requestData["start"];
290 if (!(startLoc == "last" || startLoc == "home"))
291 {
292 // Ignore it! Heh.
293 }
294 }
295
296 // What time did the user login?
297 agent.loginTime = Util.UnixTimeSinceEpoch();
298 agent.logoutTime = 0;
299
300 // Current location
301 agent.regionID = new LLUUID(); // Fill in later
302 agent.currentRegion = ""; // Fill in later
303 }
304
305 public bool CommitAgent(ref UserProfileData profile)
306 {
307 // Saves the agent to database
308 return true;
309 }
310
311 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
312 {
313 XmlRpcResponse response = new XmlRpcResponse();
314 Hashtable requestData = (Hashtable)request.Params[0];
315
316 bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
317 bool GoodLogin = false;
318 string firstname = "";
319 string lastname = "";
320 string passwd = "";
321
322 UserProfileData TheUser;
323
324 if (GoodXML)
325 {
326 firstname = (string)requestData["first"];
327 lastname = (string)requestData["last"];
328 passwd = (string)requestData["passwd"];
329
330 TheUser = getUserProfile(firstname, lastname);
331 GoodLogin = AuthenticateUser(ref TheUser, passwd);
332 }
333 else
334 {
335 return CreateErrorConnectingToGridResponse();
336 }
337
338 if (!GoodLogin)
339 {
340 return CreateLoginErrorResponse();
341 }
342 else
343 {
344 // If we already have a session...
345 if (TheUser.currentAgent != null && TheUser.currentAgent.agentOnline)
346 {
347 // Reject the login
348 return CreateAlreadyLoggedInResponse();
349 }
350 // Otherwise...
351 // Create a new agent session
352 CreateAgent(ref TheUser, request);
353
354 try
355 {
356 Hashtable responseData = new Hashtable();
357
358 LLUUID AgentID = TheUser.UUID;
359
360 // Global Texture Section
361 Hashtable GlobalT = new Hashtable();
362 GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
363 GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
364 GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
365 ArrayList GlobalTextures = new ArrayList();
366 GlobalTextures.Add(GlobalT);
367
368 // Login Flags Section
369 Hashtable LoginFlagsHash = new Hashtable();
370 LoginFlagsHash["daylight_savings"] = "N";
371 LoginFlagsHash["stipend_since_login"] = "N";
372 LoginFlagsHash["gendered"] = "Y";
373 LoginFlagsHash["ever_logged_in"] = "N"; // Should allow male/female av selection
374 ArrayList LoginFlags = new ArrayList();
375 LoginFlags.Add(LoginFlagsHash);
376
377 // UI Customisation Section
378 Hashtable uiconfig = new Hashtable();
379 uiconfig["allow_first_life"] = "Y";
380 ArrayList ui_config = new ArrayList();
381 ui_config.Add(uiconfig);
382
383 // Classified Categories Section
384 Hashtable ClassifiedCategoriesHash = new Hashtable();
385 ClassifiedCategoriesHash["category_name"] = "Generic";
386 ClassifiedCategoriesHash["category_id"] = (Int32)1;
387 ArrayList ClassifiedCategories = new ArrayList();
388 ClassifiedCategories.Add(ClassifiedCategoriesHash);
389
390 // Inventory Library Section
391 ArrayList AgentInventoryArray = new ArrayList();
392 Hashtable TempHash;
393
394 AgentInventory Library = new AgentInventory();
395 Library.CreateRootFolder(AgentID, true);
396
397 foreach (InventoryFolder InvFolder in Library.InventoryFolders.Values)
398 {
399 TempHash = new Hashtable();
400 TempHash["name"] = InvFolder.FolderName;
401 TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
402 TempHash["version"] = (Int32)InvFolder.Version;
403 TempHash["type_default"] = (Int32)InvFolder.DefaultType;
404 TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
405 AgentInventoryArray.Add(TempHash);
406 }
407
408 Hashtable InventoryRootHash = new Hashtable();
409 InventoryRootHash["folder_id"] = Library.InventoryRoot.FolderID.ToStringHyphenated();
410 ArrayList InventoryRoot = new ArrayList();
411 InventoryRoot.Add(InventoryRootHash);
412
413 Hashtable InitialOutfitHash = new Hashtable();
414 InitialOutfitHash["folder_name"] = "Nightclub Female";
415 InitialOutfitHash["gender"] = "female";
416 ArrayList InitialOutfit = new ArrayList();
417 InitialOutfit.Add(InitialOutfitHash);
418
419 // Circuit Code
420 uint circode = (uint)(Util.RandomClass.Next());
421
422 // Generics
423 responseData["last_name"] = TheUser.surname;
424 responseData["ui-config"] = ui_config;
425 responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString();
426 responseData["login-flags"] = LoginFlags;
427 responseData["global-textures"] = GlobalTextures;
428 responseData["classified_categories"] = ClassifiedCategories;
429 responseData["event_categories"] = new ArrayList();
430 responseData["inventory-skeleton"] = AgentInventoryArray;
431 responseData["inventory-skel-lib"] = new ArrayList();
432 responseData["inventory-root"] = InventoryRoot;
433 responseData["event_notifications"] = new ArrayList();
434 responseData["gestures"] = new ArrayList();
435 responseData["inventory-lib-owner"] = new ArrayList();
436 responseData["initial-outfit"] = InitialOutfit;
437 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
438 responseData["start_location"] = "last";
439 responseData["home"] = "!!null temporary value {home}!!"; // Overwritten
440 responseData["message"] = _config.DefaultStartupMsg;
441 responseData["first_name"] = TheUser.username;
442 responseData["circuit_code"] = (Int32)circode;
443 responseData["sim_port"] = 0; //(Int32)SimInfo.sim_port;
444 responseData["secure_session_id"] = TheUser.currentAgent.secureSessionID.ToStringHyphenated();
445 responseData["look_at"] = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
446 responseData["agent_id"] = AgentID.ToStringHyphenated();
447 responseData["region_y"] = (Int32)0; // Overwritten
448 responseData["region_x"] = (Int32)0; // Overwritten
449 responseData["seed_capability"] = "";
450 responseData["agent_access"] = "M";
451 responseData["session_id"] = TheUser.currentAgent.sessionID.ToStringHyphenated();
452 responseData["login"] = "true";
453
454 this.CustomiseResponse(ref responseData, ref TheUser);
455
456 CommitAgent(ref TheUser);
457
458 response.Value = responseData;
459 // TheUser.SendDataToSim(SimInfo);
460 return response;
461
462 }
463 catch (Exception E)
464 {
465 Console.WriteLine(E.ToString());
466 }
467 //}
468 }
469 return response;
470
471 }
472
473 public string RestDeleteUserSessionMethod(string request, string path, string param)
474 {
475 // TODO! Important!
476
477 return "OK";
478 }
479
152 } 480 }
153} 481}