aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenGrid.Framework.UserManager
diff options
context:
space:
mode:
authorMW2007-06-22 18:28:49 +0000
committerMW2007-06-22 18:28:49 +0000
commita9dde515ba7d35b6069a3b2cd8b66bb72b007801 (patch)
tree5c219b4f52c2a58d0ac507b90556afc2a6848f94 /Common/OpenGrid.Framework.UserManager
parent* Porting console fix from Trunk to Sugilite (diff)
downloadopensim-SC_OLD-a9dde515ba7d35b6069a3b2cd8b66bb72b007801.zip
opensim-SC_OLD-a9dde515ba7d35b6069a3b2cd8b66bb72b007801.tar.gz
opensim-SC_OLD-a9dde515ba7d35b6069a3b2cd8b66bb72b007801.tar.bz2
opensim-SC_OLD-a9dde515ba7d35b6069a3b2cd8b66bb72b007801.tar.xz
SandBox mode login now shares a base class with the grid mode user server.
To allow people to login without creating accounts first in sandbox mode anytime a login request is received without a matching account already being in the database, a new account will be made. (also in sandbox mode, passwords aren't currently used).
Diffstat (limited to 'Common/OpenGrid.Framework.UserManager')
-rw-r--r--Common/OpenGrid.Framework.UserManager/LoginResponse.cs656
-rw-r--r--Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.csproj3
-rw-r--r--Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.dll.build1
-rw-r--r--Common/OpenGrid.Framework.UserManager/UserManagerBase.cs318
4 files changed, 779 insertions, 199 deletions
diff --git a/Common/OpenGrid.Framework.UserManager/LoginResponse.cs b/Common/OpenGrid.Framework.UserManager/LoginResponse.cs
new file mode 100644
index 0000000..1c51aeb
--- /dev/null
+++ b/Common/OpenGrid.Framework.UserManager/LoginResponse.cs
@@ -0,0 +1,656 @@
1using System;
2using System.Text;
3using System.Text.RegularExpressions;
4using System.Threading;
5using System.Collections;
6using System.Xml;
7using libsecondlife;
8using OpenSim.Framework.Utilities;
9using OpenSim.Framework.Interfaces;
10using Nwc.XmlRpc;
11
12namespace OpenGrid.Framework.UserManagement
13{
14
15 /// <summary>
16 /// A temp class to handle login response.
17 /// Should make use of UserProfileManager where possible.
18 /// </summary>
19
20 public class LoginResponse
21 {
22 private Hashtable loginFlagsHash;
23 private Hashtable globalTexturesHash;
24 private Hashtable loginError;
25 private Hashtable eventCategoriesHash;
26 private Hashtable uiConfigHash;
27 private Hashtable classifiedCategoriesHash;
28
29 private ArrayList loginFlags;
30 private ArrayList globalTextures;
31 private ArrayList eventCategories;
32 private ArrayList uiConfig;
33 private ArrayList classifiedCategories;
34 private ArrayList inventoryRoot;
35 private ArrayList initialOutfit;
36 private ArrayList agentInventory;
37
38 private UserInfo userProfile;
39
40 private LLUUID agentID;
41 private LLUUID sessionID;
42 private LLUUID secureSessionID;
43 private LLUUID baseFolderID;
44 private LLUUID inventoryFolderID;
45
46 // Login Flags
47 private string dst;
48 private string stipendSinceLogin;
49 private string gendered;
50 private string everLoggedIn;
51 private string login;
52 private int simPort;
53 private string simAddress;
54 private string agentAccess;
55 private Int32 circuitCode;
56 private uint regionX;
57 private uint regionY;
58
59 // Login
60 private string firstname;
61 private string lastname;
62
63 // Global Textures
64 private string sunTexture;
65 private string cloudTexture;
66 private string moonTexture;
67
68 // Error Flags
69 private string errorReason;
70 private string errorMessage;
71
72 // Response
73 private XmlRpcResponse xmlRpcResponse;
74 private XmlRpcResponse defaultXmlRpcResponse;
75
76 private string welcomeMessage;
77 private string startLocation;
78 private string allowFirstLife;
79 private string home;
80 private string seedCapability;
81 private string lookAt;
82
83 public LoginResponse()
84 {
85 this.loginFlags = new ArrayList();
86 this.globalTextures = new ArrayList();
87 this.eventCategories = new ArrayList();
88 this.uiConfig = new ArrayList();
89 this.classifiedCategories = new ArrayList();
90
91 this.loginError = new Hashtable();
92 this.eventCategoriesHash = new Hashtable();
93 this.classifiedCategoriesHash = new Hashtable();
94 this.uiConfigHash = new Hashtable();
95
96 this.defaultXmlRpcResponse = new XmlRpcResponse();
97 this.userProfile = new UserInfo();
98 this.inventoryRoot = new ArrayList();
99 this.initialOutfit = new ArrayList();
100 this.agentInventory = new ArrayList();
101
102 this.xmlRpcResponse = new XmlRpcResponse();
103 this.defaultXmlRpcResponse = new XmlRpcResponse();
104
105 this.SetDefaultValues();
106 } // LoginServer
107
108 public void SetDefaultValues()
109 {
110 try
111 {
112 this.DST = "N";
113 this.StipendSinceLogin = "N";
114 this.Gendered = "Y";
115 this.EverLoggedIn = "Y";
116 this.login = "false";
117 this.firstname = "Test";
118 this.lastname = "User";
119 this.agentAccess = "M";
120 this.startLocation = "last";
121 this.allowFirstLife = "Y";
122
123 this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
124 this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
125 this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
126
127 this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
128 this.ErrorReason = "key";
129 this.welcomeMessage = "Welcome to OpenSim!";
130 this.seedCapability = "";
131 this.home = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + this.userProfile.homepos.X.ToString() + ",r" + this.userProfile.homepos.Y.ToString() + ",r" + this.userProfile.homepos.Z.ToString() + "], 'look_at':[r" + this.userProfile.homelookat.X.ToString() + ",r" + this.userProfile.homelookat.Y.ToString() + ",r" + this.userProfile.homelookat.Z.ToString() + "]}";
132 this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
133 this.RegionX = (uint)255232;
134 this.RegionY = (uint)254976;
135
136 // Classifieds;
137 this.AddClassifiedCategory((Int32)1, "Shopping");
138 this.AddClassifiedCategory((Int32)2, "Land Rental");
139 this.AddClassifiedCategory((Int32)3, "Property Rental");
140 this.AddClassifiedCategory((Int32)4, "Special Attraction");
141 this.AddClassifiedCategory((Int32)5, "New Products");
142 this.AddClassifiedCategory((Int32)6, "Employment");
143 this.AddClassifiedCategory((Int32)7, "Wanted");
144 this.AddClassifiedCategory((Int32)8, "Service");
145 this.AddClassifiedCategory((Int32)9, "Personal");
146
147
148 this.SessionID = LLUUID.Random();
149 this.SecureSessionID = LLUUID.Random();
150 this.AgentID = LLUUID.Random();
151
152 Hashtable InitialOutfitHash = new Hashtable();
153 InitialOutfitHash["folder_name"] = "Nightclub Female";
154 InitialOutfitHash["gender"] = "female";
155 this.initialOutfit.Add(InitialOutfitHash);
156 }
157 catch (Exception e)
158 {
159 OpenSim.Framework.Console.MainLog.Instance.WriteLine(
160 OpenSim.Framework.Console.LogPriority.LOW,
161 "LoginResponse: Unable to set default values: " + e.Message
162 );
163 }
164
165 } // SetDefaultValues
166
167 #region Login Failure Methods
168 public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
169 {
170 // Overwrite any default values;
171 this.xmlRpcResponse = new XmlRpcResponse();
172
173 // Ensure Login Failed message/reason;
174 this.ErrorMessage = message;
175 this.ErrorReason = reason;
176
177 this.loginError["reason"] = this.ErrorReason;
178 this.loginError["message"] = this.ErrorMessage;
179 this.loginError["login"] = login;
180 this.xmlRpcResponse.Value = this.loginError;
181 return (this.xmlRpcResponse);
182 } // GenerateResponse
183
184 public XmlRpcResponse CreateFailedResponse()
185 {
186 return (this.CreateLoginFailedResponse());
187 } // CreateErrorConnectingToGridResponse()
188
189 public XmlRpcResponse CreateLoginFailedResponse()
190 {
191 return (this.GenerateFailureResponse("key", "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", "false"));
192 } // LoginFailedResponse
193
194 public XmlRpcResponse CreateAlreadyLoggedInResponse()
195 {
196 return (this.GenerateFailureResponse("presence", "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", "false"));
197 } // CreateAlreadyLoggedInResponse()
198
199 public XmlRpcResponse CreateDeadRegionResponse()
200 {
201 return (this.GenerateFailureResponse("key", "The region you are attempting to log into is not responding. Please select another region and try again.", "false"));
202 }
203
204 public XmlRpcResponse CreateGridErrorResponse()
205 {
206 return (this.GenerateFailureResponse("key", "Error connecting to grid. Could not percieve credentials from login XML.", "false"));
207 }
208
209 #endregion
210
211 public XmlRpcResponse ToXmlRpcResponse()
212 {
213 try
214 {
215
216 Hashtable responseData = new Hashtable();
217
218 this.loginFlagsHash = new Hashtable();
219 this.loginFlagsHash["daylight_savings"] = this.DST;
220 this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
221 this.loginFlagsHash["gendered"] = this.Gendered;
222 this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
223 this.loginFlags.Add(this.loginFlagsHash);
224
225 responseData["first_name"] = this.Firstname;
226 responseData["last_name"] = this.Lastname;
227 responseData["agent_access"] = this.agentAccess;
228
229 this.globalTexturesHash = new Hashtable();
230 this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
231 this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
232 this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
233 this.globalTextures.Add(this.globalTexturesHash);
234 this.eventCategories.Add(this.eventCategoriesHash);
235
236 this.AddToUIConfig("allow_first_life", this.allowFirstLife);
237 this.uiConfig.Add(this.uiConfigHash);
238
239 responseData["sim_port"] =(Int32) this.SimPort;
240 responseData["sim_ip"] = this.SimAddress;
241 responseData["agent_id"] = this.AgentID.ToStringHyphenated();
242 responseData["session_id"] = this.SessionID.ToStringHyphenated();
243 responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated();
244 responseData["circuit_code"] = this.CircuitCode;
245 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
246 responseData["login-flags"] = this.loginFlags;
247 responseData["global-textures"] = this.globalTextures;
248 responseData["seed_capability"] = this.seedCapability;
249
250 responseData["event_categories"] = this.eventCategories;
251 responseData["event_notifications"] = new ArrayList(); // todo
252 responseData["classified_categories"] = this.classifiedCategories;
253 responseData["ui-config"] = this.uiConfig;
254
255 responseData["inventory-skeleton"] = this.agentInventory;
256 responseData["inventory-skel-lib"] = new ArrayList(); // todo
257 responseData["inventory-root"] = this.inventoryRoot;
258 responseData["gestures"] = new ArrayList(); // todo
259 responseData["inventory-lib-owner"] = new ArrayList(); // todo
260 responseData["initial-outfit"] = this.initialOutfit;
261 responseData["start_location"] = this.startLocation;
262 responseData["seed_capability"] = this.seedCapability;
263 responseData["home"] = this.home;
264 responseData["look_at"] = this.lookAt;
265 responseData["message"] = this.welcomeMessage;
266 responseData["region_x"] = (Int32)this.RegionX * 256;
267 responseData["region_y"] = (Int32)this.RegionY * 256;
268
269 //responseData["inventory-lib-root"] = new ArrayList(); // todo
270 //responseData["buddy-list"] = new ArrayList(); // todo
271
272 responseData["login"] = "true";
273 this.xmlRpcResponse.Value = responseData;
274
275 return (this.xmlRpcResponse);
276 }
277 catch (Exception e)
278 {
279 OpenSim.Framework.Console.MainLog.Instance.WriteLine(
280 OpenSim.Framework.Console.LogPriority.LOW,
281 "LoginResponse: Error creating XML-RPC Response: " + e.Message
282 );
283 return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false"));
284
285 }
286
287 } // ToXmlRpcResponse
288
289 public void SetEventCategories(string category, string value)
290 {
291 this.eventCategoriesHash[category] = value;
292 } // SetEventCategories
293
294 public void AddToUIConfig(string itemName, string item)
295 {
296 this.uiConfigHash[itemName] = item;
297 } // SetUIConfig
298
299 public void AddClassifiedCategory(Int32 ID, string categoryName)
300 {
301 this.classifiedCategoriesHash["category_name"] = categoryName;
302 this.classifiedCategoriesHash["category_id"] = ID;
303 this.classifiedCategories.Add(this.classifiedCategoriesHash);
304 // this.classifiedCategoriesHash.Clear();
305 } // SetClassifiedCategory
306
307 #region Properties
308 public string Login
309 {
310 get
311 {
312 return this.login;
313 }
314 set
315 {
316 this.login = value;
317 }
318 } // Login
319
320 public string DST
321 {
322 get
323 {
324 return this.dst;
325 }
326 set
327 {
328 this.dst = value;
329 }
330 } // DST
331
332 public string StipendSinceLogin
333 {
334 get
335 {
336 return this.stipendSinceLogin;
337 }
338 set
339 {
340 this.stipendSinceLogin = value;
341 }
342 } // StipendSinceLogin
343
344 public string Gendered
345 {
346 get
347 {
348 return this.gendered;
349 }
350 set
351 {
352 this.gendered = value;
353 }
354 } // Gendered
355
356 public string EverLoggedIn
357 {
358 get
359 {
360 return this.everLoggedIn;
361 }
362 set
363 {
364 this.everLoggedIn = value;
365 }
366 } // EverLoggedIn
367
368 public int SimPort
369 {
370 get
371 {
372 return this.simPort;
373 }
374 set
375 {
376 this.simPort = value;
377 }
378 } // SimPort
379
380 public string SimAddress
381 {
382 get
383 {
384 return this.simAddress;
385 }
386 set
387 {
388 this.simAddress = value;
389 }
390 } // SimAddress
391
392 public LLUUID AgentID
393 {
394 get
395 {
396 return this.agentID;
397 }
398 set
399 {
400 this.agentID = value;
401 }
402 } // AgentID
403
404 public LLUUID SessionID
405 {
406 get
407 {
408 return this.sessionID;
409 }
410 set
411 {
412 this.sessionID = value;
413 }
414 } // SessionID
415
416 public LLUUID SecureSessionID
417 {
418 get
419 {
420 return this.secureSessionID;
421 }
422 set
423 {
424 this.secureSessionID = value;
425 }
426 } // SecureSessionID
427
428 public Int32 CircuitCode
429 {
430 get
431 {
432 return this.circuitCode;
433 }
434 set
435 {
436 this.circuitCode = value;
437 }
438 } // CircuitCode
439
440 public uint RegionX
441 {
442 get
443 {
444 return this.regionX;
445 }
446 set
447 {
448 this.regionX = value;
449 }
450 } // RegionX
451
452 public uint RegionY
453 {
454 get
455 {
456 return this.regionY;
457 }
458 set
459 {
460 this.regionY = value;
461 }
462 } // RegionY
463
464 public string SunTexture
465 {
466 get
467 {
468 return this.sunTexture;
469 }
470 set
471 {
472 this.sunTexture = value;
473 }
474 } // SunTexture
475
476 public string CloudTexture
477 {
478 get
479 {
480 return this.cloudTexture;
481 }
482 set
483 {
484 this.cloudTexture = value;
485 }
486 } // CloudTexture
487
488 public string MoonTexture
489 {
490 get
491 {
492 return this.moonTexture;
493 }
494 set
495 {
496 this.moonTexture = value;
497 }
498 } // MoonTexture
499
500 public string Firstname
501 {
502 get
503 {
504 return this.firstname;
505 }
506 set
507 {
508 this.firstname = value;
509 }
510 } // Firstname
511
512 public string Lastname
513 {
514 get
515 {
516 return this.lastname;
517 }
518 set
519 {
520 this.lastname = value;
521 }
522 } // Lastname
523
524 public string AgentAccess
525 {
526 get
527 {
528 return this.agentAccess;
529 }
530 set
531 {
532 this.agentAccess = value;
533 }
534 }
535
536 public string StartLocation
537 {
538 get
539 {
540 return this.startLocation;
541 }
542 set
543 {
544 this.startLocation = value;
545 }
546 } // StartLocation
547
548 public string LookAt
549 {
550 get
551 {
552 return this.lookAt;
553 }
554 set
555 {
556 this.lookAt = value;
557 }
558 }
559
560 public string SeedCapability
561 {
562 get
563 {
564 return this.seedCapability;
565 }
566 set
567 {
568 this.seedCapability = value;
569 }
570 } // SeedCapability
571
572 public string ErrorReason
573 {
574 get
575 {
576 return this.errorReason;
577 }
578 set
579 {
580 this.errorReason = value;
581 }
582 } // ErrorReason
583
584 public string ErrorMessage
585 {
586 get
587 {
588 return this.errorMessage;
589 }
590 set
591 {
592 this.errorMessage = value;
593 }
594 } // ErrorMessage
595
596 public ArrayList InventoryRoot
597 {
598 get
599 {
600 return this.inventoryRoot;
601 }
602 set
603 {
604 this.inventoryRoot = value;
605 }
606 }
607
608 public ArrayList InventorySkeleton
609 {
610 get
611 {
612 return this.agentInventory;
613 }
614 set
615 {
616 this.agentInventory = value;
617 }
618 }
619
620 public string Home
621 {
622 get
623 {
624 return this.home;
625 }
626 set
627 {
628 this.home = value;
629 }
630 }
631
632 public string Message
633 {
634 get
635 {
636 return this.welcomeMessage;
637 }
638 set
639 {
640 this.welcomeMessage = value;
641 }
642 }
643 #endregion
644
645
646 public class UserInfo
647 {
648 public string firstname;
649 public string lastname;
650 public ulong homeregionhandle;
651 public LLVector3 homepos;
652 public LLVector3 homelookat;
653 }
654 }
655}
656
diff --git a/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.csproj b/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.csproj
index 232712b..9a3cdba 100644
--- a/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.csproj
+++ b/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.csproj
@@ -108,6 +108,9 @@
108 </ProjectReference> 108 </ProjectReference>
109 </ItemGroup> 109 </ItemGroup>
110 <ItemGroup> 110 <ItemGroup>
111 <Compile Include="LoginResponse.cs">
112 <SubType>Code</SubType>
113 </Compile>
111 <Compile Include="UserManagerBase.cs"> 114 <Compile Include="UserManagerBase.cs">
112 <SubType>Code</SubType> 115 <SubType>Code</SubType>
113 </Compile> 116 </Compile>
diff --git a/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.dll.build b/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.dll.build
index a2f5d13..9dc2383 100644
--- a/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.dll.build
+++ b/Common/OpenGrid.Framework.UserManager/OpenGrid.Framework.UserManagement.dll.build
@@ -11,6 +11,7 @@
11 <resources prefix="OpenGrid.Framework.UserManagement" dynamicprefix="true" > 11 <resources prefix="OpenGrid.Framework.UserManagement" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="LoginResponse.cs" />
14 <include name="UserManagerBase.cs" /> 15 <include name="UserManagerBase.cs" />
15 </sources> 16 </sources>
16 <references basedir="${project::get-base-directory()}"> 17 <references basedir="${project::get-base-directory()}">
diff --git a/Common/OpenGrid.Framework.UserManager/UserManagerBase.cs b/Common/OpenGrid.Framework.UserManager/UserManagerBase.cs
index eaa53dd..01fbf3a 100644
--- a/Common/OpenGrid.Framework.UserManager/UserManagerBase.cs
+++ b/Common/OpenGrid.Framework.UserManager/UserManagerBase.cs
@@ -79,37 +79,7 @@ namespace OpenGrid.Framework.UserManagement
79 pluginAssembly = null; 79 pluginAssembly = null;
80 } 80 }
81 81
82 /// <summary> 82 #region Get UserProfile
83 ///
84 /// </summary>
85 /// <param name="user"></param>
86 public void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
87 {
88 UserProfileData user = new UserProfileData();
89 user.homeLocation = new LLVector3(128, 128, 100);
90 user.UUID = LLUUID.Random();
91 user.username = firstName;
92 user.surname = lastName;
93 user.passwordHash = pass;
94 user.passwordSalt = "";
95 user.created = Util.UnixTimeSinceEpoch();
96 user.homeLookAt = new LLVector3(100, 100, 100);
97 user.homeRegion = Util.UIntsToLong((regX * 256), (regY * 256));
98
99 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
100 {
101 try
102 {
103 plugin.Value.addNewUserProfile(user);
104
105 }
106 catch (Exception e)
107 {
108 OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
109 }
110 }
111 }
112
113 /// <summary> 83 /// <summary>
114 /// Loads a user profile from a database by UUID 84 /// Loads a user profile from a database by UUID
115 /// </summary> 85 /// </summary>
@@ -190,7 +160,9 @@ namespace OpenGrid.Framework.UserManagement
190 160
191 return null; 161 return null;
192 } 162 }
163 #endregion
193 164
165 #region Get UserAgent
194 /// <summary> 166 /// <summary>
195 /// Loads a user agent by uuid (not called directly) 167 /// Loads a user agent by uuid (not called directly)
196 /// </summary> 168 /// </summary>
@@ -258,94 +230,9 @@ namespace OpenGrid.Framework.UserManagement
258 return null; 230 return null;
259 } 231 }
260 232
261 /// <summary> 233 #endregion
262 /// Creates a error response caused by invalid XML
263 /// </summary>
264 /// <returns>An XMLRPC response</returns>
265 private static XmlRpcResponse CreateErrorConnectingToGridResponse()
266 {
267 XmlRpcResponse response = new XmlRpcResponse();
268 Hashtable ErrorRespData = new Hashtable();
269 ErrorRespData["reason"] = "key";
270 ErrorRespData["message"] = "Error connecting to grid. Could not percieve credentials from login XML.";
271 ErrorRespData["login"] = "false";
272 response.Value = ErrorRespData;
273 return response;
274 }
275
276 /// <summary>
277 /// Creates an error response caused by bad login credentials
278 /// </summary>
279 /// <returns>An XMLRPC response</returns>
280 private static XmlRpcResponse CreateLoginErrorResponse()
281 {
282 XmlRpcResponse response = new XmlRpcResponse();
283 Hashtable ErrorRespData = new Hashtable();
284 ErrorRespData["reason"] = "key";
285 ErrorRespData["message"] = "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.";
286 ErrorRespData["login"] = "false";
287 response.Value = ErrorRespData;
288 return response;
289 }
290
291 /// <summary>
292 /// Creates an error response caused by being logged in already
293 /// </summary>
294 /// <returns>An XMLRPC Response</returns>
295 private static XmlRpcResponse CreateAlreadyLoggedInResponse()
296 {
297 XmlRpcResponse response = new XmlRpcResponse();
298 Hashtable PresenceErrorRespData = new Hashtable();
299 PresenceErrorRespData["reason"] = "presence";
300 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";
301 PresenceErrorRespData["login"] = "false";
302 response.Value = PresenceErrorRespData;
303 return response;
304 }
305
306 /// <summary>
307 /// Creates an error response caused by target region being down
308 /// </summary>
309 /// <returns>An XMLRPC Response</returns>
310 private static XmlRpcResponse CreateDeadRegionResponse()
311 {
312 XmlRpcResponse response = new XmlRpcResponse();
313 Hashtable PresenceErrorRespData = new Hashtable();
314 PresenceErrorRespData["reason"] = "key";
315 PresenceErrorRespData["message"] = "The region you are attempting to log into is not responding. Please select another region and try again.";
316 PresenceErrorRespData["login"] = "false";
317 response.Value = PresenceErrorRespData;
318 return response;
319 }
320
321 /// <summary>
322 /// Customises the login response and fills in missing values.
323 /// </summary>
324 /// <param name="response">The existing response</param>
325 /// <param name="theUser">The user profile</param>
326 public virtual void CustomiseResponse(ref Hashtable response, ref UserProfileData theUser)
327 {
328
329 }
330
331 /// <summary>
332 /// Checks a user against it's password hash
333 /// </summary>
334 /// <param name="profile">The users profile</param>
335 /// <param name="password">The supplied password</param>
336 /// <returns>Authenticated?</returns>
337 public bool AuthenticateUser(ref UserProfileData profile, string password)
338 {
339 OpenSim.Framework.Console.MainLog.Instance.Verbose(
340 "Authenticating " + profile.username + " " + profile.surname);
341
342 password = password.Remove(0, 3); //remove $1$
343
344 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
345
346 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
347 }
348 234
235 #region CreateAgent
349 /// <summary> 236 /// <summary>
350 /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB 237 /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB
351 /// </summary> 238 /// </summary>
@@ -390,7 +277,7 @@ namespace OpenGrid.Framework.UserManagement
390 { 277 {
391 string[] parts = startLoc.Remove(0, 4).Split('&'); 278 string[] parts = startLoc.Remove(0, 4).Split('&');
392 string region = parts[0]; 279 string region = parts[0];
393 280
394 //////////////////////////////////////////////////// 281 ////////////////////////////////////////////////////
395 //SimProfile SimInfo = new SimProfile(); 282 //SimProfile SimInfo = new SimProfile();
396 //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey); 283 //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey);
@@ -424,6 +311,58 @@ namespace OpenGrid.Framework.UserManagement
424 return true; 311 return true;
425 } 312 }
426 313
314 #endregion
315
316 /// <summary>
317 /// Checks a user against it's password hash
318 /// </summary>
319 /// <param name="profile">The users profile</param>
320 /// <param name="password">The supplied password</param>
321 /// <returns>Authenticated?</returns>
322 public virtual bool AuthenticateUser(ref UserProfileData profile, string password)
323 {
324 OpenSim.Framework.Console.MainLog.Instance.Verbose(
325 "Authenticating " + profile.username + " " + profile.surname);
326
327 password = password.Remove(0, 3); //remove $1$
328
329 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
330
331 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
332 }
333
334 #region Xml Response
335
336 /// <summary>
337 ///
338 /// </summary>
339 /// <param name="firstname"></param>
340 /// <param name="lastname"></param>
341 /// <returns></returns>
342 public virtual UserProfileData GetTheUser(string firstname, string lastname)
343 {
344 return getUserProfile(firstname, lastname);
345 }
346
347 /// <summary>
348 ///
349 /// </summary>
350 /// <returns></returns>
351 public virtual string GetMessage()
352 {
353 return _config.DefaultStartupMsg;
354 }
355
356 /// <summary>
357 /// Customises the login response and fills in missing values.
358 /// </summary>
359 /// <param name="response">The existing response</param>
360 /// <param name="theUser">The user profile</param>
361 public virtual void CustomiseResponse(ref LoginResponse response, ref UserProfileData theUser)
362 {
363
364 }
365
427 /// <summary> 366 /// <summary>
428 /// Main user login function 367 /// Main user login function
429 /// </summary> 368 /// </summary>
@@ -441,6 +380,7 @@ namespace OpenGrid.Framework.UserManagement
441 string passwd = ""; 380 string passwd = "";
442 381
443 UserProfileData TheUser; 382 UserProfileData TheUser;
383 LoginResponse logResponse = new LoginResponse();
444 384
445 if (GoodXML) 385 if (GoodXML)
446 { 386 {
@@ -448,20 +388,20 @@ namespace OpenGrid.Framework.UserManagement
448 lastname = (string)requestData["last"]; 388 lastname = (string)requestData["last"];
449 passwd = (string)requestData["passwd"]; 389 passwd = (string)requestData["passwd"];
450 390
451 TheUser = getUserProfile(firstname, lastname); 391 TheUser = GetTheUser(firstname, lastname);
452 if (TheUser == null) 392 if (TheUser == null)
453 return CreateLoginErrorResponse(); 393 return logResponse.CreateLoginFailedResponse();
454 394
455 GoodLogin = AuthenticateUser(ref TheUser, passwd); 395 GoodLogin = AuthenticateUser(ref TheUser, passwd);
456 } 396 }
457 else 397 else
458 { 398 {
459 return CreateErrorConnectingToGridResponse(); 399 return logResponse.CreateGridErrorResponse();
460 } 400 }
461 401
462 if (!GoodLogin) 402 if (!GoodLogin)
463 { 403 {
464 return CreateLoginErrorResponse(); 404 return logResponse.CreateLoginFailedResponse();
465 } 405 }
466 else 406 else
467 { 407 {
@@ -469,7 +409,7 @@ namespace OpenGrid.Framework.UserManagement
469 if (TheUser.currentAgent != null && TheUser.currentAgent.agentOnline) 409 if (TheUser.currentAgent != null && TheUser.currentAgent.agentOnline)
470 { 410 {
471 // Reject the login 411 // Reject the login
472 return CreateAlreadyLoggedInResponse(); 412 return logResponse.CreateAlreadyLoggedInResponse();
473 } 413 }
474 // Otherwise... 414 // Otherwise...
475 // Create a new agent session 415 // Create a new agent session
@@ -477,39 +417,8 @@ namespace OpenGrid.Framework.UserManagement
477 417
478 try 418 try
479 { 419 {
480 Hashtable responseData = new Hashtable();
481 420
482 LLUUID AgentID = TheUser.UUID; 421 LLUUID AgentID = TheUser.UUID;
483
484 // Global Texture Section
485 Hashtable GlobalT = new Hashtable();
486 GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
487 GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
488 GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
489 ArrayList GlobalTextures = new ArrayList();
490 GlobalTextures.Add(GlobalT);
491
492 // Login Flags Section
493 Hashtable LoginFlagsHash = new Hashtable();
494 LoginFlagsHash["daylight_savings"] = "N";
495 LoginFlagsHash["stipend_since_login"] = "N";
496 LoginFlagsHash["gendered"] = "Y"; // Needs to be combined with below...
497 LoginFlagsHash["ever_logged_in"] = "Y"; // Should allow male/female av selection
498 ArrayList LoginFlags = new ArrayList();
499 LoginFlags.Add(LoginFlagsHash);
500
501 // UI Customisation Section
502 Hashtable uiconfig = new Hashtable();
503 uiconfig["allow_first_life"] = "Y";
504 ArrayList ui_config = new ArrayList();
505 ui_config.Add(uiconfig);
506
507 // Classified Categories Section
508 Hashtable ClassifiedCategoriesHash = new Hashtable();
509 ClassifiedCategoriesHash["category_name"] = "Generic";
510 ClassifiedCategoriesHash["category_id"] = (Int32)1;
511 ArrayList ClassifiedCategories = new ArrayList();
512 ClassifiedCategories.Add(ClassifiedCategoriesHash);
513 422
514 // Inventory Library Section 423 // Inventory Library Section
515 ArrayList AgentInventoryArray = new ArrayList(); 424 ArrayList AgentInventoryArray = new ArrayList();
@@ -534,62 +443,37 @@ namespace OpenGrid.Framework.UserManagement
534 ArrayList InventoryRoot = new ArrayList(); 443 ArrayList InventoryRoot = new ArrayList();
535 InventoryRoot.Add(InventoryRootHash); 444 InventoryRoot.Add(InventoryRootHash);
536 445
537 Hashtable InitialOutfitHash = new Hashtable();
538 InitialOutfitHash["folder_name"] = "Nightclub Female";
539 InitialOutfitHash["gender"] = "female";
540 ArrayList InitialOutfit = new ArrayList();
541 InitialOutfit.Add(InitialOutfitHash);
542
543 // Circuit Code 446 // Circuit Code
544 uint circode = (uint)(Util.RandomClass.Next()); 447 uint circode = (uint)(Util.RandomClass.Next());
545 448
546 // Generics 449 logResponse.Lastname = TheUser.surname;
547 responseData["last_name"] = TheUser.surname; 450 logResponse.Firstname = TheUser.username;
548 responseData["ui-config"] = ui_config; 451 logResponse.AgentID = AgentID.ToStringHyphenated();
549 responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString(); 452 logResponse.SessionID = TheUser.currentAgent.sessionID.ToStringHyphenated();
550 responseData["login-flags"] = LoginFlags; 453 logResponse.SecureSessionID = TheUser.currentAgent.secureSessionID.ToStringHyphenated();
551 responseData["global-textures"] = GlobalTextures; 454 logResponse.InventoryRoot = InventoryRoot;
552 responseData["classified_categories"] = ClassifiedCategories; 455 logResponse.InventorySkeleton = AgentInventoryArray;
553 responseData["event_categories"] = new ArrayList(); 456 logResponse.CircuitCode = (Int32)circode;
554 responseData["inventory-skeleton"] = AgentInventoryArray; 457 logResponse.RegionX = 0; //overwritten
555 responseData["inventory-skel-lib"] = new ArrayList(); 458 logResponse.RegionY = 0; //overwritten
556 responseData["inventory-root"] = InventoryRoot; 459 logResponse.Home = "!!null temporary value {home}!!"; // Overwritten
557 responseData["event_notifications"] = new ArrayList(); 460 //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
558 responseData["gestures"] = new ArrayList(); 461 logResponse.SimAddress = "127.0.0.1"; //overwritten
559 responseData["inventory-lib-owner"] = new ArrayList(); 462 logResponse.SimPort = 0; //overwritten
560 responseData["initial-outfit"] = InitialOutfit; 463 logResponse.Message = this.GetMessage();
561 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; 464
562 responseData["start_location"] = "last";
563 responseData["home"] = "!!null temporary value {home}!!"; // Overwritten
564 responseData["message"] = _config.DefaultStartupMsg;
565 responseData["first_name"] = TheUser.username;
566 responseData["circuit_code"] = (Int32)circode;
567 responseData["sim_port"] = 0; //(Int32)SimInfo.sim_port;
568 responseData["secure_session_id"] = TheUser.currentAgent.secureSessionID.ToStringHyphenated();
569 responseData["look_at"] = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
570 responseData["agent_id"] = AgentID.ToStringHyphenated();
571 responseData["region_y"] = (Int32)0; // Overwritten
572 responseData["region_x"] = (Int32)0; // Overwritten
573 responseData["seed_capability"] = "";
574 responseData["agent_access"] = "M";
575 responseData["session_id"] = TheUser.currentAgent.sessionID.ToStringHyphenated();
576 responseData["login"] = "true";
577
578 try 465 try
579 { 466 {
580 this.CustomiseResponse(ref responseData, ref TheUser); 467 this.CustomiseResponse(ref logResponse, ref TheUser);
581 } 468 }
582 catch (Exception e) 469 catch (Exception e)
583 { 470 {
584 Console.WriteLine(e.ToString()); 471 Console.WriteLine(e.ToString());
585 return CreateDeadRegionResponse(); 472 return logResponse.CreateDeadRegionResponse();
586 } 473 }
587
588 CommitAgent(ref TheUser); 474 CommitAgent(ref TheUser);
589 475
590 response.Value = responseData; 476 return logResponse.ToXmlRpcResponse();
591 // TheUser.SendDataToSim(SimInfo);
592 return response;
593 477
594 } 478 }
595 catch (Exception E) 479 catch (Exception E)
@@ -602,6 +486,8 @@ namespace OpenGrid.Framework.UserManagement
602 486
603 } 487 }
604 488
489 #endregion
490
605 /// <summary> 491 /// <summary>
606 /// Deletes an active agent session 492 /// Deletes an active agent session
607 /// </summary> 493 /// </summary>
@@ -617,6 +503,37 @@ namespace OpenGrid.Framework.UserManagement
617 } 503 }
618 504
619 /// <summary> 505 /// <summary>
506 ///
507 /// </summary>
508 /// <param name="user"></param>
509 public void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
510 {
511 UserProfileData user = new UserProfileData();
512 user.homeLocation = new LLVector3(128, 128, 100);
513 user.UUID = LLUUID.Random();
514 user.username = firstName;
515 user.surname = lastName;
516 user.passwordHash = pass;
517 user.passwordSalt = "";
518 user.created = Util.UnixTimeSinceEpoch();
519 user.homeLookAt = new LLVector3(100, 100, 100);
520 user.homeRegion = Util.UIntsToLong((regX * 256), (regY * 256));
521
522 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
523 {
524 try
525 {
526 plugin.Value.addNewUserProfile(user);
527
528 }
529 catch (Exception e)
530 {
531 OpenSim.Framework.Console.MainLog.Instance.Verbose("Unable to add user via " + plugin.Key + "(" + e.ToString() + ")");
532 }
533 }
534 }
535
536 /// <summary>
620 /// Returns an error message that the user could not be found in the database 537 /// Returns an error message that the user could not be found in the database
621 /// </summary> 538 /// </summary>
622 /// <returns>XML string consisting of a error element containing individual error(s)</returns> 539 /// <returns>XML string consisting of a error element containing individual error(s)</returns>
@@ -693,6 +610,8 @@ namespace OpenGrid.Framework.UserManagement
693 return sw.ToString(); 610 return sw.ToString();
694 } 611 }
695 612
613 #region REST Methods
614 //should most likely move out of here and into the grid's userserver sub class
696 public string RestGetUserMethodName(string request, string path, string param) 615 public string RestGetUserMethodName(string request, string path, string param)
697 { 616 {
698 UserProfileData userProfile = getUserProfile(param.Trim()); 617 UserProfileData userProfile = getUserProfile(param.Trim());
@@ -716,6 +635,7 @@ namespace OpenGrid.Framework.UserManagement
716 635
717 return ProfileToXml(userProfile); 636 return ProfileToXml(userProfile);
718 } 637 }
638 #endregion
719 639
720 } 640 }
721} 641}