diff options
Diffstat (limited to 'OpenSim/Framework/UserManager')
4 files changed, 1423 insertions, 0 deletions
diff --git a/OpenSim/Framework/UserManager/LoginResponse.cs b/OpenSim/Framework/UserManager/LoginResponse.cs new file mode 100644 index 0000000..5ca223f --- /dev/null +++ b/OpenSim/Framework/UserManager/LoginResponse.cs | |||
@@ -0,0 +1,645 @@ | |||
1 | using System; | ||
2 | using System.Text; | ||
3 | using System.Text.RegularExpressions; | ||
4 | using System.Threading; | ||
5 | using System.Collections; | ||
6 | using System.Xml; | ||
7 | using libsecondlife; | ||
8 | using OpenSim.Framework.Utilities; | ||
9 | using OpenSim.Framework.Interfaces; | ||
10 | using Nwc.XmlRpc; | ||
11 | |||
12 | namespace OpenSim.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 | |||
44 | // Login Flags | ||
45 | private string dst; | ||
46 | private string stipendSinceLogin; | ||
47 | private string gendered; | ||
48 | private string everLoggedIn; | ||
49 | private string login; | ||
50 | private int simPort; | ||
51 | private string simAddress; | ||
52 | private string agentAccess; | ||
53 | private Int32 circuitCode; | ||
54 | private uint regionX; | ||
55 | private uint regionY; | ||
56 | |||
57 | // Login | ||
58 | private string firstname; | ||
59 | private string lastname; | ||
60 | |||
61 | // Global Textures | ||
62 | private string sunTexture; | ||
63 | private string cloudTexture; | ||
64 | private string moonTexture; | ||
65 | |||
66 | // Error Flags | ||
67 | private string errorReason; | ||
68 | private string errorMessage; | ||
69 | |||
70 | // Response | ||
71 | private XmlRpcResponse xmlRpcResponse; | ||
72 | private XmlRpcResponse defaultXmlRpcResponse; | ||
73 | |||
74 | private string welcomeMessage; | ||
75 | private string startLocation; | ||
76 | private string allowFirstLife; | ||
77 | private string home; | ||
78 | private string seedCapability; | ||
79 | private string lookAt; | ||
80 | |||
81 | public LoginResponse() | ||
82 | { | ||
83 | this.loginFlags = new ArrayList(); | ||
84 | this.globalTextures = new ArrayList(); | ||
85 | this.eventCategories = new ArrayList(); | ||
86 | this.uiConfig = new ArrayList(); | ||
87 | this.classifiedCategories = new ArrayList(); | ||
88 | |||
89 | this.loginError = new Hashtable(); | ||
90 | this.eventCategoriesHash = new Hashtable(); | ||
91 | this.classifiedCategoriesHash = new Hashtable(); | ||
92 | this.uiConfigHash = new Hashtable(); | ||
93 | |||
94 | this.defaultXmlRpcResponse = new XmlRpcResponse(); | ||
95 | this.userProfile = new UserInfo(); | ||
96 | this.inventoryRoot = new ArrayList(); | ||
97 | this.initialOutfit = new ArrayList(); | ||
98 | this.agentInventory = new ArrayList(); | ||
99 | |||
100 | this.xmlRpcResponse = new XmlRpcResponse(); | ||
101 | this.defaultXmlRpcResponse = new XmlRpcResponse(); | ||
102 | |||
103 | this.SetDefaultValues(); | ||
104 | } // LoginServer | ||
105 | |||
106 | public void SetDefaultValues() | ||
107 | { | ||
108 | this.DST = "N"; | ||
109 | this.StipendSinceLogin = "N"; | ||
110 | this.Gendered = "Y"; | ||
111 | this.EverLoggedIn = "Y"; | ||
112 | this.login = "false"; | ||
113 | this.firstname = "Test"; | ||
114 | this.lastname = "User"; | ||
115 | this.agentAccess = "M"; | ||
116 | this.startLocation = "last"; | ||
117 | this.allowFirstLife = "Y"; | ||
118 | |||
119 | this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271"; | ||
120 | this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
121 | this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; | ||
122 | |||
123 | this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; | ||
124 | this.ErrorReason = "key"; | ||
125 | this.welcomeMessage = "Welcome to OpenSim!"; | ||
126 | this.seedCapability = ""; | ||
127 | 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() + "]}"; | ||
128 | this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]"; | ||
129 | this.RegionX = (uint)255232; | ||
130 | this.RegionY = (uint)254976; | ||
131 | |||
132 | // Classifieds; | ||
133 | this.AddClassifiedCategory((Int32)1, "Shopping"); | ||
134 | this.AddClassifiedCategory((Int32)2, "Land Rental"); | ||
135 | this.AddClassifiedCategory((Int32)3, "Property Rental"); | ||
136 | this.AddClassifiedCategory((Int32)4, "Special Attraction"); | ||
137 | this.AddClassifiedCategory((Int32)5, "New Products"); | ||
138 | this.AddClassifiedCategory((Int32)6, "Employment"); | ||
139 | this.AddClassifiedCategory((Int32)7, "Wanted"); | ||
140 | this.AddClassifiedCategory((Int32)8, "Service"); | ||
141 | this.AddClassifiedCategory((Int32)9, "Personal"); | ||
142 | |||
143 | |||
144 | this.SessionID = LLUUID.Random(); | ||
145 | this.SecureSessionID = LLUUID.Random(); | ||
146 | this.AgentID = LLUUID.Random(); | ||
147 | |||
148 | Hashtable InitialOutfitHash = new Hashtable(); | ||
149 | InitialOutfitHash["folder_name"] = "Nightclub Female"; | ||
150 | InitialOutfitHash["gender"] = "female"; | ||
151 | this.initialOutfit.Add(InitialOutfitHash); | ||
152 | |||
153 | |||
154 | } // SetDefaultValues | ||
155 | |||
156 | #region Login Failure Methods | ||
157 | public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login) | ||
158 | { | ||
159 | // Overwrite any default values; | ||
160 | this.xmlRpcResponse = new XmlRpcResponse(); | ||
161 | |||
162 | // Ensure Login Failed message/reason; | ||
163 | this.ErrorMessage = message; | ||
164 | this.ErrorReason = reason; | ||
165 | |||
166 | this.loginError["reason"] = this.ErrorReason; | ||
167 | this.loginError["message"] = this.ErrorMessage; | ||
168 | this.loginError["login"] = login; | ||
169 | this.xmlRpcResponse.Value = this.loginError; | ||
170 | return (this.xmlRpcResponse); | ||
171 | } // GenerateResponse | ||
172 | |||
173 | public XmlRpcResponse CreateFailedResponse() | ||
174 | { | ||
175 | return (this.CreateLoginFailedResponse()); | ||
176 | } // CreateErrorConnectingToGridResponse() | ||
177 | |||
178 | public XmlRpcResponse CreateLoginFailedResponse() | ||
179 | { | ||
180 | return (this.GenerateFailureResponse("key", "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", "false")); | ||
181 | } // LoginFailedResponse | ||
182 | |||
183 | public XmlRpcResponse CreateAlreadyLoggedInResponse() | ||
184 | { | ||
185 | 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")); | ||
186 | } // CreateAlreadyLoggedInResponse() | ||
187 | |||
188 | public XmlRpcResponse CreateDeadRegionResponse() | ||
189 | { | ||
190 | return (this.GenerateFailureResponse("key", "The region you are attempting to log into is not responding. Please select another region and try again.", "false")); | ||
191 | } | ||
192 | |||
193 | public XmlRpcResponse CreateGridErrorResponse() | ||
194 | { | ||
195 | return (this.GenerateFailureResponse("key", "Error connecting to grid. Could not percieve credentials from login XML.", "false")); | ||
196 | } | ||
197 | |||
198 | #endregion | ||
199 | |||
200 | public XmlRpcResponse ToXmlRpcResponse() | ||
201 | { | ||
202 | try | ||
203 | { | ||
204 | |||
205 | Hashtable responseData = new Hashtable(); | ||
206 | |||
207 | this.loginFlagsHash = new Hashtable(); | ||
208 | this.loginFlagsHash["daylight_savings"] = this.DST; | ||
209 | this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin; | ||
210 | this.loginFlagsHash["gendered"] = this.Gendered; | ||
211 | this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn; | ||
212 | this.loginFlags.Add(this.loginFlagsHash); | ||
213 | |||
214 | responseData["first_name"] = this.Firstname; | ||
215 | responseData["last_name"] = this.Lastname; | ||
216 | responseData["agent_access"] = this.agentAccess; | ||
217 | |||
218 | this.globalTexturesHash = new Hashtable(); | ||
219 | this.globalTexturesHash["sun_texture_id"] = this.SunTexture; | ||
220 | this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture; | ||
221 | this.globalTexturesHash["moon_texture_id"] = this.MoonTexture; | ||
222 | this.globalTextures.Add(this.globalTexturesHash); | ||
223 | this.eventCategories.Add(this.eventCategoriesHash); | ||
224 | |||
225 | this.AddToUIConfig("allow_first_life", this.allowFirstLife); | ||
226 | this.uiConfig.Add(this.uiConfigHash); | ||
227 | |||
228 | responseData["sim_port"] =(Int32) this.SimPort; | ||
229 | responseData["sim_ip"] = this.SimAddress; | ||
230 | responseData["agent_id"] = this.AgentID.ToStringHyphenated(); | ||
231 | responseData["session_id"] = this.SessionID.ToStringHyphenated(); | ||
232 | responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated(); | ||
233 | responseData["circuit_code"] = this.CircuitCode; | ||
234 | responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
235 | responseData["login-flags"] = this.loginFlags; | ||
236 | responseData["global-textures"] = this.globalTextures; | ||
237 | responseData["seed_capability"] = this.seedCapability; | ||
238 | |||
239 | responseData["event_categories"] = this.eventCategories; | ||
240 | responseData["event_notifications"] = new ArrayList(); // todo | ||
241 | responseData["classified_categories"] = this.classifiedCategories; | ||
242 | responseData["ui-config"] = this.uiConfig; | ||
243 | |||
244 | responseData["inventory-skeleton"] = this.agentInventory; | ||
245 | responseData["inventory-skel-lib"] = new ArrayList(); // todo | ||
246 | responseData["inventory-root"] = this.inventoryRoot; | ||
247 | responseData["gestures"] = new ArrayList(); // todo | ||
248 | responseData["inventory-lib-owner"] = new ArrayList(); // todo | ||
249 | responseData["initial-outfit"] = this.initialOutfit; | ||
250 | responseData["start_location"] = this.startLocation; | ||
251 | responseData["seed_capability"] = this.seedCapability; | ||
252 | responseData["home"] = this.home; | ||
253 | responseData["look_at"] = this.lookAt; | ||
254 | responseData["message"] = this.welcomeMessage; | ||
255 | responseData["region_x"] = (Int32)this.RegionX * 256; | ||
256 | responseData["region_y"] = (Int32)this.RegionY * 256; | ||
257 | |||
258 | //responseData["inventory-lib-root"] = new ArrayList(); // todo | ||
259 | //responseData["buddy-list"] = new ArrayList(); // todo | ||
260 | |||
261 | responseData["login"] = "true"; | ||
262 | this.xmlRpcResponse.Value = responseData; | ||
263 | |||
264 | return (this.xmlRpcResponse); | ||
265 | } | ||
266 | catch (Exception e) | ||
267 | { | ||
268 | OpenSim.Framework.Console.MainLog.Instance.WriteLine( | ||
269 | OpenSim.Framework.Console.LogPriority.LOW, | ||
270 | "LoginResponse: Error creating XML-RPC Response: " + e.Message | ||
271 | ); | ||
272 | return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false")); | ||
273 | |||
274 | } | ||
275 | |||
276 | } // ToXmlRpcResponse | ||
277 | |||
278 | public void SetEventCategories(string category, string value) | ||
279 | { | ||
280 | this.eventCategoriesHash[category] = value; | ||
281 | } // SetEventCategories | ||
282 | |||
283 | public void AddToUIConfig(string itemName, string item) | ||
284 | { | ||
285 | this.uiConfigHash[itemName] = item; | ||
286 | } // SetUIConfig | ||
287 | |||
288 | public void AddClassifiedCategory(Int32 ID, string categoryName) | ||
289 | { | ||
290 | this.classifiedCategoriesHash["category_name"] = categoryName; | ||
291 | this.classifiedCategoriesHash["category_id"] = ID; | ||
292 | this.classifiedCategories.Add(this.classifiedCategoriesHash); | ||
293 | // this.classifiedCategoriesHash.Clear(); | ||
294 | } // SetClassifiedCategory | ||
295 | |||
296 | #region Properties | ||
297 | public string Login | ||
298 | { | ||
299 | get | ||
300 | { | ||
301 | return this.login; | ||
302 | } | ||
303 | set | ||
304 | { | ||
305 | this.login = value; | ||
306 | } | ||
307 | } // Login | ||
308 | |||
309 | public string DST | ||
310 | { | ||
311 | get | ||
312 | { | ||
313 | return this.dst; | ||
314 | } | ||
315 | set | ||
316 | { | ||
317 | this.dst = value; | ||
318 | } | ||
319 | } // DST | ||
320 | |||
321 | public string StipendSinceLogin | ||
322 | { | ||
323 | get | ||
324 | { | ||
325 | return this.stipendSinceLogin; | ||
326 | } | ||
327 | set | ||
328 | { | ||
329 | this.stipendSinceLogin = value; | ||
330 | } | ||
331 | } // StipendSinceLogin | ||
332 | |||
333 | public string Gendered | ||
334 | { | ||
335 | get | ||
336 | { | ||
337 | return this.gendered; | ||
338 | } | ||
339 | set | ||
340 | { | ||
341 | this.gendered = value; | ||
342 | } | ||
343 | } // Gendered | ||
344 | |||
345 | public string EverLoggedIn | ||
346 | { | ||
347 | get | ||
348 | { | ||
349 | return this.everLoggedIn; | ||
350 | } | ||
351 | set | ||
352 | { | ||
353 | this.everLoggedIn = value; | ||
354 | } | ||
355 | } // EverLoggedIn | ||
356 | |||
357 | public int SimPort | ||
358 | { | ||
359 | get | ||
360 | { | ||
361 | return this.simPort; | ||
362 | } | ||
363 | set | ||
364 | { | ||
365 | this.simPort = value; | ||
366 | } | ||
367 | } // SimPort | ||
368 | |||
369 | public string SimAddress | ||
370 | { | ||
371 | get | ||
372 | { | ||
373 | return this.simAddress; | ||
374 | } | ||
375 | set | ||
376 | { | ||
377 | this.simAddress = value; | ||
378 | } | ||
379 | } // SimAddress | ||
380 | |||
381 | public LLUUID AgentID | ||
382 | { | ||
383 | get | ||
384 | { | ||
385 | return this.agentID; | ||
386 | } | ||
387 | set | ||
388 | { | ||
389 | this.agentID = value; | ||
390 | } | ||
391 | } // AgentID | ||
392 | |||
393 | public LLUUID SessionID | ||
394 | { | ||
395 | get | ||
396 | { | ||
397 | return this.sessionID; | ||
398 | } | ||
399 | set | ||
400 | { | ||
401 | this.sessionID = value; | ||
402 | } | ||
403 | } // SessionID | ||
404 | |||
405 | public LLUUID SecureSessionID | ||
406 | { | ||
407 | get | ||
408 | { | ||
409 | return this.secureSessionID; | ||
410 | } | ||
411 | set | ||
412 | { | ||
413 | this.secureSessionID = value; | ||
414 | } | ||
415 | } // SecureSessionID | ||
416 | |||
417 | public Int32 CircuitCode | ||
418 | { | ||
419 | get | ||
420 | { | ||
421 | return this.circuitCode; | ||
422 | } | ||
423 | set | ||
424 | { | ||
425 | this.circuitCode = value; | ||
426 | } | ||
427 | } // CircuitCode | ||
428 | |||
429 | public uint RegionX | ||
430 | { | ||
431 | get | ||
432 | { | ||
433 | return this.regionX; | ||
434 | } | ||
435 | set | ||
436 | { | ||
437 | this.regionX = value; | ||
438 | } | ||
439 | } // RegionX | ||
440 | |||
441 | public uint RegionY | ||
442 | { | ||
443 | get | ||
444 | { | ||
445 | return this.regionY; | ||
446 | } | ||
447 | set | ||
448 | { | ||
449 | this.regionY = value; | ||
450 | } | ||
451 | } // RegionY | ||
452 | |||
453 | public string SunTexture | ||
454 | { | ||
455 | get | ||
456 | { | ||
457 | return this.sunTexture; | ||
458 | } | ||
459 | set | ||
460 | { | ||
461 | this.sunTexture = value; | ||
462 | } | ||
463 | } // SunTexture | ||
464 | |||
465 | public string CloudTexture | ||
466 | { | ||
467 | get | ||
468 | { | ||
469 | return this.cloudTexture; | ||
470 | } | ||
471 | set | ||
472 | { | ||
473 | this.cloudTexture = value; | ||
474 | } | ||
475 | } // CloudTexture | ||
476 | |||
477 | public string MoonTexture | ||
478 | { | ||
479 | get | ||
480 | { | ||
481 | return this.moonTexture; | ||
482 | } | ||
483 | set | ||
484 | { | ||
485 | this.moonTexture = value; | ||
486 | } | ||
487 | } // MoonTexture | ||
488 | |||
489 | public string Firstname | ||
490 | { | ||
491 | get | ||
492 | { | ||
493 | return this.firstname; | ||
494 | } | ||
495 | set | ||
496 | { | ||
497 | this.firstname = value; | ||
498 | } | ||
499 | } // Firstname | ||
500 | |||
501 | public string Lastname | ||
502 | { | ||
503 | get | ||
504 | { | ||
505 | return this.lastname; | ||
506 | } | ||
507 | set | ||
508 | { | ||
509 | this.lastname = value; | ||
510 | } | ||
511 | } // Lastname | ||
512 | |||
513 | public string AgentAccess | ||
514 | { | ||
515 | get | ||
516 | { | ||
517 | return this.agentAccess; | ||
518 | } | ||
519 | set | ||
520 | { | ||
521 | this.agentAccess = value; | ||
522 | } | ||
523 | } | ||
524 | |||
525 | public string StartLocation | ||
526 | { | ||
527 | get | ||
528 | { | ||
529 | return this.startLocation; | ||
530 | } | ||
531 | set | ||
532 | { | ||
533 | this.startLocation = value; | ||
534 | } | ||
535 | } // StartLocation | ||
536 | |||
537 | public string LookAt | ||
538 | { | ||
539 | get | ||
540 | { | ||
541 | return this.lookAt; | ||
542 | } | ||
543 | set | ||
544 | { | ||
545 | this.lookAt = value; | ||
546 | } | ||
547 | } | ||
548 | |||
549 | public string SeedCapability | ||
550 | { | ||
551 | get | ||
552 | { | ||
553 | return this.seedCapability; | ||
554 | } | ||
555 | set | ||
556 | { | ||
557 | this.seedCapability = value; | ||
558 | } | ||
559 | } // SeedCapability | ||
560 | |||
561 | public string ErrorReason | ||
562 | { | ||
563 | get | ||
564 | { | ||
565 | return this.errorReason; | ||
566 | } | ||
567 | set | ||
568 | { | ||
569 | this.errorReason = value; | ||
570 | } | ||
571 | } // ErrorReason | ||
572 | |||
573 | public string ErrorMessage | ||
574 | { | ||
575 | get | ||
576 | { | ||
577 | return this.errorMessage; | ||
578 | } | ||
579 | set | ||
580 | { | ||
581 | this.errorMessage = value; | ||
582 | } | ||
583 | } // ErrorMessage | ||
584 | |||
585 | public ArrayList InventoryRoot | ||
586 | { | ||
587 | get | ||
588 | { | ||
589 | return this.inventoryRoot; | ||
590 | } | ||
591 | set | ||
592 | { | ||
593 | this.inventoryRoot = value; | ||
594 | } | ||
595 | } | ||
596 | |||
597 | public ArrayList InventorySkeleton | ||
598 | { | ||
599 | get | ||
600 | { | ||
601 | return this.agentInventory; | ||
602 | } | ||
603 | set | ||
604 | { | ||
605 | this.agentInventory = value; | ||
606 | } | ||
607 | } | ||
608 | |||
609 | public string Home | ||
610 | { | ||
611 | get | ||
612 | { | ||
613 | return this.home; | ||
614 | } | ||
615 | set | ||
616 | { | ||
617 | this.home = value; | ||
618 | } | ||
619 | } | ||
620 | |||
621 | public string Message | ||
622 | { | ||
623 | get | ||
624 | { | ||
625 | return this.welcomeMessage; | ||
626 | } | ||
627 | set | ||
628 | { | ||
629 | this.welcomeMessage = value; | ||
630 | } | ||
631 | } | ||
632 | #endregion | ||
633 | |||
634 | |||
635 | public class UserInfo | ||
636 | { | ||
637 | public string firstname; | ||
638 | public string lastname; | ||
639 | public ulong homeregionhandle; | ||
640 | public LLVector3 homepos; | ||
641 | public LLVector3 homelookat; | ||
642 | } | ||
643 | } | ||
644 | } | ||
645 | |||
diff --git a/OpenSim/Framework/UserManager/OpenSim.Framework.UserManagement.csproj b/OpenSim/Framework/UserManager/OpenSim.Framework.UserManagement.csproj new file mode 100644 index 0000000..02aa3f3 --- /dev/null +++ b/OpenSim/Framework/UserManager/OpenSim.Framework.UserManagement.csproj | |||
@@ -0,0 +1,125 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
2 | <PropertyGroup> | ||
3 | <ProjectType>Local</ProjectType> | ||
4 | <ProductVersion>8.0.50727</ProductVersion> | ||
5 | <SchemaVersion>2.0</SchemaVersion> | ||
6 | <ProjectGuid>{586E2916-0000-0000-0000-000000000000}</ProjectGuid> | ||
7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
9 | <ApplicationIcon></ApplicationIcon> | ||
10 | <AssemblyKeyContainerName> | ||
11 | </AssemblyKeyContainerName> | ||
12 | <AssemblyName>OpenSim.Framework.UserManagement</AssemblyName> | ||
13 | <DefaultClientScript>JScript</DefaultClientScript> | ||
14 | <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> | ||
15 | <DefaultTargetSchema>IE50</DefaultTargetSchema> | ||
16 | <DelaySign>false</DelaySign> | ||
17 | <OutputType>Library</OutputType> | ||
18 | <AppDesignerFolder></AppDesignerFolder> | ||
19 | <RootNamespace>OpenSim.Framework.UserManagement</RootNamespace> | ||
20 | <StartupObject></StartupObject> | ||
21 | <FileUpgradeFlags> | ||
22 | </FileUpgradeFlags> | ||
23 | </PropertyGroup> | ||
24 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
25 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> | ||
26 | <BaseAddress>285212672</BaseAddress> | ||
27 | <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
28 | <ConfigurationOverrideFile> | ||
29 | </ConfigurationOverrideFile> | ||
30 | <DefineConstants>TRACE;DEBUG</DefineConstants> | ||
31 | <DocumentationFile></DocumentationFile> | ||
32 | <DebugSymbols>True</DebugSymbols> | ||
33 | <FileAlignment>4096</FileAlignment> | ||
34 | <Optimize>False</Optimize> | ||
35 | <OutputPath>..\..\..\bin\</OutputPath> | ||
36 | <RegisterForComInterop>False</RegisterForComInterop> | ||
37 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | ||
38 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | ||
39 | <WarningLevel>4</WarningLevel> | ||
40 | <NoWarn></NoWarn> | ||
41 | </PropertyGroup> | ||
42 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
43 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> | ||
44 | <BaseAddress>285212672</BaseAddress> | ||
45 | <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
46 | <ConfigurationOverrideFile> | ||
47 | </ConfigurationOverrideFile> | ||
48 | <DefineConstants>TRACE</DefineConstants> | ||
49 | <DocumentationFile></DocumentationFile> | ||
50 | <DebugSymbols>False</DebugSymbols> | ||
51 | <FileAlignment>4096</FileAlignment> | ||
52 | <Optimize>True</Optimize> | ||
53 | <OutputPath>..\..\..\bin\</OutputPath> | ||
54 | <RegisterForComInterop>False</RegisterForComInterop> | ||
55 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | ||
56 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | ||
57 | <WarningLevel>4</WarningLevel> | ||
58 | <NoWarn></NoWarn> | ||
59 | </PropertyGroup> | ||
60 | <ItemGroup> | ||
61 | <Reference Include="Db4objects.Db4o.dll" > | ||
62 | <HintPath>..\..\..\bin\Db4objects.Db4o.dll</HintPath> | ||
63 | <Private>False</Private> | ||
64 | </Reference> | ||
65 | <Reference Include="libsecondlife.dll" > | ||
66 | <HintPath>..\..\..\bin\libsecondlife.dll</HintPath> | ||
67 | <Private>False</Private> | ||
68 | </Reference> | ||
69 | <Reference Include="OpenSim.Framework" > | ||
70 | <HintPath>OpenSim.Framework.dll</HintPath> | ||
71 | <Private>False</Private> | ||
72 | </Reference> | ||
73 | <Reference Include="OpenSim.Framework.Console" > | ||
74 | <HintPath>OpenSim.Framework.Console.dll</HintPath> | ||
75 | <Private>False</Private> | ||
76 | </Reference> | ||
77 | <Reference Include="OpenSim.Framework.GenericConfig.Xml" > | ||
78 | <HintPath>OpenSim.Framework.GenericConfig.Xml.dll</HintPath> | ||
79 | <Private>False</Private> | ||
80 | </Reference> | ||
81 | <Reference Include="OpenSim.Framework.Servers" > | ||
82 | <HintPath>OpenSim.Framework.Servers.dll</HintPath> | ||
83 | <Private>False</Private> | ||
84 | </Reference> | ||
85 | <Reference Include="System" > | ||
86 | <HintPath>System.dll</HintPath> | ||
87 | <Private>False</Private> | ||
88 | </Reference> | ||
89 | <Reference Include="System.Data" > | ||
90 | <HintPath>System.Data.dll</HintPath> | ||
91 | <Private>False</Private> | ||
92 | </Reference> | ||
93 | <Reference Include="System.Xml" > | ||
94 | <HintPath>System.Xml.dll</HintPath> | ||
95 | <Private>False</Private> | ||
96 | </Reference> | ||
97 | <Reference Include="XMLRPC.dll" > | ||
98 | <HintPath>..\..\..\bin\XMLRPC.dll</HintPath> | ||
99 | <Private>False</Private> | ||
100 | </Reference> | ||
101 | </ItemGroup> | ||
102 | <ItemGroup> | ||
103 | <ProjectReference Include="..\Data\OpenSim.Framework.Data.csproj"> | ||
104 | <Name>OpenSim.Framework.Data</Name> | ||
105 | <Project>{36B72A9B-0000-0000-0000-000000000000}</Project> | ||
106 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | ||
107 | <Private>False</Private> | ||
108 | </ProjectReference> | ||
109 | </ItemGroup> | ||
110 | <ItemGroup> | ||
111 | <Compile Include="LoginResponse.cs"> | ||
112 | <SubType>Code</SubType> | ||
113 | </Compile> | ||
114 | <Compile Include="UserManagerBase.cs"> | ||
115 | <SubType>Code</SubType> | ||
116 | </Compile> | ||
117 | </ItemGroup> | ||
118 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> | ||
119 | <PropertyGroup> | ||
120 | <PreBuildEvent> | ||
121 | </PreBuildEvent> | ||
122 | <PostBuildEvent> | ||
123 | </PostBuildEvent> | ||
124 | </PropertyGroup> | ||
125 | </Project> | ||
diff --git a/OpenSim/Framework/UserManager/OpenSim.Framework.UserManagement.csproj.user b/OpenSim/Framework/UserManager/OpenSim.Framework.UserManagement.csproj.user new file mode 100644 index 0000000..6841907 --- /dev/null +++ b/OpenSim/Framework/UserManager/OpenSim.Framework.UserManagement.csproj.user | |||
@@ -0,0 +1,12 @@ | |||
1 | <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
2 | <PropertyGroup> | ||
3 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
4 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
5 | <ReferencePath>C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-06\NameSpaceChanges\bin\</ReferencePath> | ||
6 | <LastOpenVersion>8.0.50727</LastOpenVersion> | ||
7 | <ProjectView>ProjectFiles</ProjectView> | ||
8 | <ProjectTrust>0</ProjectTrust> | ||
9 | </PropertyGroup> | ||
10 | <PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " /> | ||
11 | <PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> | ||
12 | </Project> | ||
diff --git a/OpenSim/Framework/UserManager/UserManagerBase.cs b/OpenSim/Framework/UserManager/UserManagerBase.cs new file mode 100644 index 0000000..eb46c14 --- /dev/null +++ b/OpenSim/Framework/UserManager/UserManagerBase.cs | |||
@@ -0,0 +1,641 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using OpenSim.Framework.Data; | ||
33 | using libsecondlife; | ||
34 | using System.Reflection; | ||
35 | |||
36 | using System.Xml; | ||
37 | using Nwc.XmlRpc; | ||
38 | using OpenSim.Framework.Sims; | ||
39 | using OpenSim.Framework.Inventory; | ||
40 | using OpenSim.Framework.Utilities; | ||
41 | |||
42 | using System.Security.Cryptography; | ||
43 | |||
44 | namespace OpenSim.Framework.UserManagement | ||
45 | { | ||
46 | public class UserManagerBase | ||
47 | { | ||
48 | public OpenSim.Framework.Interfaces.UserConfig _config; | ||
49 | Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>(); | ||
50 | |||
51 | /// <summary> | ||
52 | /// Adds a new user server plugin - user servers will be requested in the order they were loaded. | ||
53 | /// </summary> | ||
54 | /// <param name="FileName">The filename to the user server plugin DLL</param> | ||
55 | public void AddPlugin(string FileName) | ||
56 | { | ||
57 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Userstorage: Attempting to load " + FileName); | ||
58 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||
59 | |||
60 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Userstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); | ||
61 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
62 | { | ||
63 | if (!pluginType.IsAbstract) | ||
64 | { | ||
65 | Type typeInterface = pluginType.GetInterface("IUserData", true); | ||
66 | |||
67 | if (typeInterface != null) | ||
68 | { | ||
69 | IUserData plug = (IUserData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
70 | plug.Initialise(); | ||
71 | this._plugins.Add(plug.getName(), plug); | ||
72 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Userstorage: Added IUserData Interface"); | ||
73 | } | ||
74 | |||
75 | typeInterface = null; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | pluginAssembly = null; | ||
80 | } | ||
81 | |||
82 | #region Get UserProfile | ||
83 | /// <summary> | ||
84 | /// Loads a user profile from a database by UUID | ||
85 | /// </summary> | ||
86 | /// <param name="uuid">The target UUID</param> | ||
87 | /// <returns>A user profile</returns> | ||
88 | public UserProfileData getUserProfile(LLUUID uuid) | ||
89 | { | ||
90 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
91 | { | ||
92 | try | ||
93 | { | ||
94 | UserProfileData profile = plugin.Value.getUserByUUID(uuid); | ||
95 | profile.currentAgent = getUserAgent(profile.UUID); | ||
96 | return profile; | ||
97 | } | ||
98 | catch (Exception e) | ||
99 | { | ||
100 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | return null; | ||
105 | } | ||
106 | |||
107 | |||
108 | /// <summary> | ||
109 | /// Loads a user profile by name | ||
110 | /// </summary> | ||
111 | /// <param name="name">The target name</param> | ||
112 | /// <returns>A user profile</returns> | ||
113 | public UserProfileData getUserProfile(string name) | ||
114 | { | ||
115 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
116 | { | ||
117 | try | ||
118 | { | ||
119 | UserProfileData profile = plugin.Value.getUserByName(name); | ||
120 | profile.currentAgent = getUserAgent(profile.UUID); | ||
121 | return profile; | ||
122 | } | ||
123 | catch (Exception e) | ||
124 | { | ||
125 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | return null; | ||
130 | } | ||
131 | |||
132 | /// <summary> | ||
133 | /// Loads a user profile by name | ||
134 | /// </summary> | ||
135 | /// <param name="fname">First name</param> | ||
136 | /// <param name="lname">Last name</param> | ||
137 | /// <returns>A user profile</returns> | ||
138 | public UserProfileData getUserProfile(string fname, string lname) | ||
139 | { | ||
140 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
141 | { | ||
142 | try | ||
143 | { | ||
144 | UserProfileData profile = plugin.Value.getUserByName(fname,lname); | ||
145 | try | ||
146 | { | ||
147 | profile.currentAgent = getUserAgent(profile.UUID); | ||
148 | } | ||
149 | catch (Exception e) | ||
150 | { | ||
151 | // Ignore | ||
152 | } | ||
153 | return profile; | ||
154 | } | ||
155 | catch (Exception e) | ||
156 | { | ||
157 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | return null; | ||
162 | } | ||
163 | #endregion | ||
164 | |||
165 | #region Get UserAgent | ||
166 | /// <summary> | ||
167 | /// Loads a user agent by uuid (not called directly) | ||
168 | /// </summary> | ||
169 | /// <param name="uuid">The agents UUID</param> | ||
170 | /// <returns>Agent profiles</returns> | ||
171 | public UserAgentData getUserAgent(LLUUID uuid) | ||
172 | { | ||
173 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
174 | { | ||
175 | try | ||
176 | { | ||
177 | return plugin.Value.getAgentByUUID(uuid); | ||
178 | } | ||
179 | catch (Exception e) | ||
180 | { | ||
181 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
182 | } | ||
183 | } | ||
184 | |||
185 | return null; | ||
186 | } | ||
187 | |||
188 | /// <summary> | ||
189 | /// Loads a user agent by name (not called directly) | ||
190 | /// </summary> | ||
191 | /// <param name="name">The agents name</param> | ||
192 | /// <returns>A user agent</returns> | ||
193 | public UserAgentData getUserAgent(string name) | ||
194 | { | ||
195 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
196 | { | ||
197 | try | ||
198 | { | ||
199 | return plugin.Value.getAgentByName(name); | ||
200 | } | ||
201 | catch (Exception e) | ||
202 | { | ||
203 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
204 | } | ||
205 | } | ||
206 | |||
207 | return null; | ||
208 | } | ||
209 | |||
210 | /// <summary> | ||
211 | /// Loads a user agent by name (not called directly) | ||
212 | /// </summary> | ||
213 | /// <param name="fname">The agents firstname</param> | ||
214 | /// <param name="lname">The agents lastname</param> | ||
215 | /// <returns>A user agent</returns> | ||
216 | public UserAgentData getUserAgent(string fname, string lname) | ||
217 | { | ||
218 | foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||
219 | { | ||
220 | try | ||
221 | { | ||
222 | return plugin.Value.getAgentByName(fname,lname); | ||
223 | } | ||
224 | catch (Exception e) | ||
225 | { | ||
226 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | return null; | ||
231 | } | ||
232 | |||
233 | #endregion | ||
234 | |||
235 | #region CreateAgent | ||
236 | /// <summary> | ||
237 | /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB | ||
238 | /// </summary> | ||
239 | /// <param name="profile">The users profile</param> | ||
240 | /// <param name="request">The users loginrequest</param> | ||
241 | public void CreateAgent(ref UserProfileData profile, XmlRpcRequest request) | ||
242 | { | ||
243 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
244 | |||
245 | UserAgentData agent = new UserAgentData(); | ||
246 | |||
247 | // User connection | ||
248 | agent.agentIP = ""; | ||
249 | agent.agentOnline = true; | ||
250 | agent.agentPort = 0; | ||
251 | |||
252 | // Generate sessions | ||
253 | RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider(); | ||
254 | byte[] randDataS = new byte[16]; | ||
255 | byte[] randDataSS = new byte[16]; | ||
256 | rand.GetBytes(randDataS); | ||
257 | rand.GetBytes(randDataSS); | ||
258 | |||
259 | agent.secureSessionID = new LLUUID(randDataSS, 0); | ||
260 | agent.sessionID = new LLUUID(randDataS, 0); | ||
261 | |||
262 | // Profile UUID | ||
263 | agent.UUID = profile.UUID; | ||
264 | |||
265 | // Current position (from Home) | ||
266 | agent.currentHandle = profile.homeRegion; | ||
267 | agent.currentPos = profile.homeLocation; | ||
268 | |||
269 | // If user specified additional start, use that | ||
270 | if (requestData.ContainsKey("start")) | ||
271 | { | ||
272 | string startLoc = ((string)requestData["start"]).Trim(); | ||
273 | if (!(startLoc == "last" || startLoc == "home")) | ||
274 | { | ||
275 | // Format: uri:Ahern&162&213&34 | ||
276 | try | ||
277 | { | ||
278 | string[] parts = startLoc.Remove(0, 4).Split('&'); | ||
279 | string region = parts[0]; | ||
280 | |||
281 | //////////////////////////////////////////////////// | ||
282 | //SimProfile SimInfo = new SimProfile(); | ||
283 | //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey); | ||
284 | } | ||
285 | catch (Exception e) | ||
286 | { | ||
287 | |||
288 | } | ||
289 | } | ||
290 | } | ||
291 | |||
292 | // What time did the user login? | ||
293 | agent.loginTime = Util.UnixTimeSinceEpoch(); | ||
294 | agent.logoutTime = 0; | ||
295 | |||
296 | // Current location | ||
297 | agent.regionID = new LLUUID(); // Fill in later | ||
298 | agent.currentRegion = new LLUUID(); // Fill in later | ||
299 | |||
300 | profile.currentAgent = agent; | ||
301 | } | ||
302 | |||
303 | /// <summary> | ||
304 | /// Saves a target agent to the database | ||
305 | /// </summary> | ||
306 | /// <param name="profile">The users profile</param> | ||
307 | /// <returns>Successful?</returns> | ||
308 | public bool CommitAgent(ref UserProfileData profile) | ||
309 | { | ||
310 | // Saves the agent to database | ||
311 | return true; | ||
312 | } | ||
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 | |||
366 | /// <summary> | ||
367 | /// Main user login function | ||
368 | /// </summary> | ||
369 | /// <param name="request">The XMLRPC request</param> | ||
370 | /// <returns>The response to send</returns> | ||
371 | public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) | ||
372 | { | ||
373 | XmlRpcResponse response = new XmlRpcResponse(); | ||
374 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
375 | |||
376 | bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd")); | ||
377 | bool GoodLogin = false; | ||
378 | string firstname = ""; | ||
379 | string lastname = ""; | ||
380 | string passwd = ""; | ||
381 | |||
382 | UserProfileData TheUser; | ||
383 | LoginResponse logResponse = new LoginResponse(); | ||
384 | |||
385 | if (GoodXML) | ||
386 | { | ||
387 | firstname = (string)requestData["first"]; | ||
388 | lastname = (string)requestData["last"]; | ||
389 | passwd = (string)requestData["passwd"]; | ||
390 | |||
391 | TheUser = GetTheUser(firstname, lastname); | ||
392 | if (TheUser == null) | ||
393 | return logResponse.CreateLoginFailedResponse(); | ||
394 | |||
395 | GoodLogin = AuthenticateUser(ref TheUser, passwd); | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | return logResponse.CreateGridErrorResponse(); | ||
400 | } | ||
401 | |||
402 | if (!GoodLogin) | ||
403 | { | ||
404 | return logResponse.CreateLoginFailedResponse(); | ||
405 | } | ||
406 | else | ||
407 | { | ||
408 | // If we already have a session... | ||
409 | if (TheUser.currentAgent != null && TheUser.currentAgent.agentOnline) | ||
410 | { | ||
411 | // Reject the login | ||
412 | return logResponse.CreateAlreadyLoggedInResponse(); | ||
413 | } | ||
414 | // Otherwise... | ||
415 | // Create a new agent session | ||
416 | CreateAgent(ref TheUser, request); | ||
417 | |||
418 | try | ||
419 | { | ||
420 | |||
421 | LLUUID AgentID = TheUser.UUID; | ||
422 | |||
423 | // Inventory Library Section | ||
424 | ArrayList AgentInventoryArray = new ArrayList(); | ||
425 | Hashtable TempHash; | ||
426 | |||
427 | AgentInventory Library = new AgentInventory(); | ||
428 | Library.CreateRootFolder(AgentID, true); | ||
429 | |||
430 | foreach (InventoryFolder InvFolder in Library.InventoryFolders.Values) | ||
431 | { | ||
432 | TempHash = new Hashtable(); | ||
433 | TempHash["name"] = InvFolder.FolderName; | ||
434 | TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated(); | ||
435 | TempHash["version"] = (Int32)InvFolder.Version; | ||
436 | TempHash["type_default"] = (Int32)InvFolder.DefaultType; | ||
437 | TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated(); | ||
438 | AgentInventoryArray.Add(TempHash); | ||
439 | } | ||
440 | |||
441 | Hashtable InventoryRootHash = new Hashtable(); | ||
442 | InventoryRootHash["folder_id"] = Library.InventoryRoot.FolderID.ToStringHyphenated(); | ||
443 | ArrayList InventoryRoot = new ArrayList(); | ||
444 | InventoryRoot.Add(InventoryRootHash); | ||
445 | |||
446 | // Circuit Code | ||
447 | uint circode = (uint)(Util.RandomClass.Next()); | ||
448 | |||
449 | logResponse.Lastname = TheUser.surname; | ||
450 | logResponse.Firstname = TheUser.username; | ||
451 | logResponse.AgentID = AgentID.ToStringHyphenated(); | ||
452 | logResponse.SessionID = TheUser.currentAgent.sessionID.ToStringHyphenated(); | ||
453 | logResponse.SecureSessionID = TheUser.currentAgent.secureSessionID.ToStringHyphenated(); | ||
454 | logResponse.InventoryRoot = InventoryRoot; | ||
455 | logResponse.InventorySkeleton = AgentInventoryArray; | ||
456 | logResponse.CircuitCode = (Int32)circode; | ||
457 | logResponse.RegionX = 0; //overwritten | ||
458 | logResponse.RegionY = 0; //overwritten | ||
459 | logResponse.Home = "!!null temporary value {home}!!"; // Overwritten | ||
460 | //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n"; | ||
461 | logResponse.SimAddress = "127.0.0.1"; //overwritten | ||
462 | logResponse.SimPort = 0; //overwritten | ||
463 | logResponse.Message = this.GetMessage(); | ||
464 | |||
465 | try | ||
466 | { | ||
467 | this.CustomiseResponse(ref logResponse, ref TheUser); | ||
468 | } | ||
469 | catch (Exception e) | ||
470 | { | ||
471 | System.Console.WriteLine(e.ToString()); | ||
472 | return logResponse.CreateDeadRegionResponse(); | ||
473 | } | ||
474 | CommitAgent(ref TheUser); | ||
475 | |||
476 | return logResponse.ToXmlRpcResponse(); | ||
477 | |||
478 | } | ||
479 | catch (Exception E) | ||
480 | { | ||
481 | System.Console.WriteLine(E.ToString()); | ||
482 | } | ||
483 | //} | ||
484 | } | ||
485 | return response; | ||
486 | |||
487 | } | ||
488 | |||
489 | #endregion | ||
490 | |||
491 | /// <summary> | ||
492 | /// Deletes an active agent session | ||
493 | /// </summary> | ||
494 | /// <param name="request">The request</param> | ||
495 | /// <param name="path">The path (eg /bork/narf/test)</param> | ||
496 | /// <param name="param">Parameters sent</param> | ||
497 | /// <returns>Success "OK" else error</returns> | ||
498 | public string RestDeleteUserSessionMethod(string request, string path, string param) | ||
499 | { | ||
500 | // TODO! Important! | ||
501 | |||
502 | return "OK"; | ||
503 | } | ||
504 | |||
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> | ||
537 | /// Returns an error message that the user could not be found in the database | ||
538 | /// </summary> | ||
539 | /// <returns>XML string consisting of a error element containing individual error(s)</returns> | ||
540 | public string CreateUnknownUserErrorResponse() | ||
541 | { | ||
542 | System.IO.StringWriter sw = new System.IO.StringWriter(); | ||
543 | XmlTextWriter xw = new XmlTextWriter(sw); | ||
544 | |||
545 | // Header | ||
546 | xw.Formatting = Formatting.Indented; | ||
547 | xw.WriteStartDocument(); | ||
548 | xw.WriteDocType("error", null, null, null); | ||
549 | xw.WriteComment("An error occured"); | ||
550 | xw.WriteStartElement("error"); | ||
551 | |||
552 | // User | ||
553 | xw.WriteElementString("unknownuser", "Unable to find a user with that name"); | ||
554 | |||
555 | // Footer | ||
556 | xw.WriteEndElement(); | ||
557 | xw.Flush(); | ||
558 | xw.Close(); | ||
559 | |||
560 | return sw.ToString(); | ||
561 | } | ||
562 | |||
563 | /// <summary> | ||
564 | /// Converts a user profile to an XML element which can be returned | ||
565 | /// </summary> | ||
566 | /// <param name="profile">The user profile</param> | ||
567 | /// <returns>A string containing an XML Document of the user profile</returns> | ||
568 | public string ProfileToXml(UserProfileData profile) | ||
569 | { | ||
570 | System.IO.StringWriter sw = new System.IO.StringWriter(); | ||
571 | XmlTextWriter xw = new XmlTextWriter(sw); | ||
572 | |||
573 | // Header | ||
574 | xw.Formatting = Formatting.Indented; | ||
575 | xw.WriteStartDocument(); | ||
576 | xw.WriteDocType("userprofile", null, null, null); | ||
577 | xw.WriteComment("Found user profiles matching the request"); | ||
578 | xw.WriteStartElement("users"); | ||
579 | |||
580 | // User | ||
581 | xw.WriteStartElement("user"); | ||
582 | // Account information | ||
583 | xw.WriteAttributeString("firstname", profile.username); | ||
584 | xw.WriteAttributeString("lastname", profile.surname); | ||
585 | xw.WriteAttributeString("uuid", profile.UUID.ToStringHyphenated()); | ||
586 | // Server Information | ||
587 | xw.WriteAttributeString("server_inventory", profile.userInventoryURI); | ||
588 | xw.WriteAttributeString("server_asset", profile.userAssetURI); | ||
589 | // Profile Information | ||
590 | xw.WriteAttributeString("profile_about", profile.profileAboutText); | ||
591 | xw.WriteAttributeString("profile_firstlife_about", profile.profileFirstText); | ||
592 | xw.WriteAttributeString("profile_firstlife_image", profile.profileFirstImage.ToStringHyphenated()); | ||
593 | xw.WriteAttributeString("profile_can_do", profile.profileCanDoMask.ToString()); | ||
594 | xw.WriteAttributeString("profile_want_do", profile.profileWantDoMask.ToString()); | ||
595 | xw.WriteAttributeString("profile_image", profile.profileImage.ToStringHyphenated()); | ||
596 | xw.WriteAttributeString("profile_created",profile.created.ToString()); | ||
597 | xw.WriteAttributeString("profile_lastlogin",profile.lastLogin.ToString()); | ||
598 | // Home region information | ||
599 | xw.WriteAttributeString("home_coordinates", profile.homeLocation.ToString()); | ||
600 | xw.WriteAttributeString("home_region", profile.homeRegion.ToString()); | ||
601 | xw.WriteAttributeString("home_look", profile.homeLookAt.ToString()); | ||
602 | |||
603 | xw.WriteEndElement(); | ||
604 | |||
605 | // Footer | ||
606 | xw.WriteEndElement(); | ||
607 | xw.Flush(); | ||
608 | xw.Close(); | ||
609 | |||
610 | return sw.ToString(); | ||
611 | } | ||
612 | |||
613 | #region REST Methods | ||
614 | //should most likely move out of here and into the grid's userserver sub class | ||
615 | public string RestGetUserMethodName(string request, string path, string param) | ||
616 | { | ||
617 | UserProfileData userProfile = getUserProfile(param.Trim()); | ||
618 | |||
619 | if (userProfile == null) | ||
620 | { | ||
621 | return CreateUnknownUserErrorResponse(); | ||
622 | } | ||
623 | |||
624 | return ProfileToXml(userProfile); | ||
625 | } | ||
626 | |||
627 | public string RestGetUserMethodUUID(string request, string path, string param) | ||
628 | { | ||
629 | UserProfileData userProfile = getUserProfile(new LLUUID(param)); | ||
630 | |||
631 | if (userProfile == null) | ||
632 | { | ||
633 | return CreateUnknownUserErrorResponse(); | ||
634 | } | ||
635 | |||
636 | return ProfileToXml(userProfile); | ||
637 | } | ||
638 | #endregion | ||
639 | |||
640 | } | ||
641 | } | ||