1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using libsecondlife;
using libsecondlife.StructuredData;
using Nwc.XmlRpc;
using OpenSim.Framework.Console;
namespace OpenSim.Framework.UserManagement
{
/// <summary>
/// A temp class to handle login response.
/// Should make use of UserProfileManager where possible.
/// </summary>
public class LoginResponse
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Hashtable loginFlagsHash;
private Hashtable globalTexturesHash;
private Hashtable loginError;
private Hashtable uiConfigHash;
private ArrayList loginFlags;
private ArrayList globalTextures;
private ArrayList eventCategories;
private ArrayList uiConfig;
private ArrayList classifiedCategories;
private ArrayList inventoryRoot;
private ArrayList initialOutfit;
private ArrayList agentInventory;
private ArrayList inventoryLibraryOwner;
private ArrayList inventoryLibRoot;
private ArrayList inventoryLibrary;
private UserInfo userProfile;
private LLUUID agentID;
private LLUUID sessionID;
private LLUUID secureSessionID;
// Login Flags
private string dst;
private string stipendSinceLogin;
private string gendered;
private string everLoggedIn;
private string login;
private uint simPort;
private string simAddress;
private string agentAccess;
private Int32 circuitCode;
private uint regionX;
private uint regionY;
// Login
private string firstname;
private string lastname;
// Global Textures
private string sunTexture;
private string cloudTexture;
private string moonTexture;
// Error Flags
private string errorReason;
private string errorMessage;
// Response
private XmlRpcResponse xmlRpcResponse;
private XmlRpcResponse defaultXmlRpcResponse;
private string welcomeMessage;
private string startLocation;
private string allowFirstLife;
private string home;
private string seedCapability;
private string lookAt;
private BuddyList m_buddyList = null;
public LoginResponse()
{
loginFlags = new ArrayList();
globalTextures = new ArrayList();
eventCategories = new ArrayList();
uiConfig = new ArrayList();
classifiedCategories = new ArrayList();
loginError = new Hashtable();
uiConfigHash = new Hashtable();
defaultXmlRpcResponse = new XmlRpcResponse();
userProfile = new UserInfo();
inventoryRoot = new ArrayList();
initialOutfit = new ArrayList();
agentInventory = new ArrayList();
inventoryLibrary = new ArrayList();
inventoryLibraryOwner = new ArrayList();
xmlRpcResponse = new XmlRpcResponse();
defaultXmlRpcResponse = new XmlRpcResponse();
SetDefaultValues();
}
public void SetDefaultValues()
{
DST = "N";
StipendSinceLogin = "N";
Gendered = "Y";
EverLoggedIn = "Y";
login = "false";
firstname = "Test";
lastname = "User";
agentAccess = "M";
startLocation = "last";
allowFirstLife = "Y";
SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
CloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621";
MoonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621";
ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
ErrorReason = "key";
welcomeMessage = "Welcome to OpenSim!";
seedCapability = String.Empty;
home = "{'region_handle':[r" + (1000*Constants.RegionSize).ToString() + ",r" + (1000*Constants.RegionSize).ToString() + "], 'position':[r" +
userProfile.homepos.X.ToString() + ",r" + userProfile.homepos.Y.ToString() + ",r" +
userProfile.homepos.Z.ToString() + "], 'look_at':[r" + userProfile.homelookat.X.ToString() + ",r" +
userProfile.homelookat.Y.ToString() + ",r" + userProfile.homelookat.Z.ToString() + "]}";
lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
RegionX = (uint) 255232;
RegionY = (uint) 254976;
// Classifieds;
AddClassifiedCategory((Int32) 1, "Shopping");
AddClassifiedCategory((Int32) 2, "Land Rental");
AddClassifiedCategory((Int32) 3, "Property Rental");
AddClassifiedCategory((Int32) 4, "Special Attraction");
AddClassifiedCategory((Int32) 5, "New Products");
AddClassifiedCategory((Int32) 6, "Employment");
AddClassifiedCategory((Int32) 7, "Wanted");
AddClassifiedCategory((Int32) 8, "Service");
AddClassifiedCategory((Int32) 9, "Personal");
SessionID = LLUUID.Random();
SecureSessionID = LLUUID.Random();
AgentID = LLUUID.Random();
Hashtable InitialOutfitHash = new Hashtable();
InitialOutfitHash["folder_name"] = "Nightclub Female";
InitialOutfitHash["gender"] = "female";
initialOutfit.Add(InitialOutfitHash);
}
#region Login Failure Methods
public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
{
// Overwrite any default values;
xmlRpcResponse = new XmlRpcResponse();
// Ensure Login Failed message/reason;
ErrorMessage = message;
ErrorReason = reason;
loginError["reason"] = ErrorReason;
loginError["message"] = ErrorMessage;
loginError["login"] = login;
xmlRpcResponse.Value = loginError;
return (xmlRpcResponse);
}
public LLSD GenerateFailureResponseLLSD(string reason, string message, string login)
{
LLSDMap map = new LLSDMap();
// Ensure Login Failed message/reason;
ErrorMessage = message;
ErrorReason = reason;
map["reason"] = LLSD.FromString(ErrorReason);
map["message"] = LLSD.FromString(ErrorMessage);
map["login"] = LLSD.FromString(login);
return map;
}
public XmlRpcResponse CreateFailedResponse()
{
return (CreateLoginFailedResponse());
}
public LLSD CreateFailedResponseLLSD()
{
return CreateLoginFailedResponseLLSD();
}
public XmlRpcResponse CreateLoginFailedResponse()
{
return
(GenerateFailureResponse("key",
"Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
"false"));
}
public LLSD CreateLoginFailedResponseLLSD()
{
return GenerateFailureResponseLLSD(
"key",
"Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.",
"false");
}
public XmlRpcResponse CreateAlreadyLoggedInResponse()
{
return
(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. " +
"Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.",
"false"));
}
public LLSD CreateAlreadyLoggedInResponseLLSD()
{
return GenerateFailureResponseLLSD(
"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");
}
public XmlRpcResponse CreateDeadRegionResponse()
{
return
(GenerateFailureResponse("key",
"The region you are attempting to log into is not responding. Please select another region and try again.",
"false"));
}
public LLSD CreateDeadRegionResponseLLSD()
{
return GenerateFailureResponseLLSD(
"key",
"The region you are attempting to log into is not responding. Please select another region and try again.",
"false");
}
public XmlRpcResponse CreateGridErrorResponse()
{
return
(GenerateFailureResponse("key",
"Error connecting to grid. Could not percieve credentials from login XML.",
"false"));
}
public LLSD CreateGridErrorResponseLLSD()
{
return GenerateFailureResponseLLSD(
"key",
"Error connecting to grid. Could not percieve credentials from login XML.",
"false");
}
#endregion
public XmlRpcResponse ToXmlRpcResponse()
{
try
{
Hashtable responseData = new Hashtable();
loginFlagsHash = new Hashtable();
loginFlagsHash["daylight_savings"] = DST;
loginFlagsHash["stipend_since_login"] = StipendSinceLogin;
loginFlagsHash["gendered"] = Gendered;
loginFlagsHash["ever_logged_in"] = EverLoggedIn;
loginFlags.Add(loginFlagsHash);
responseData["first_name"] = Firstname;
responseData["last_name"] = Lastname;
responseData["agent_access"] = agentAccess;
globalTexturesHash = new Hashtable();
globalTexturesHash["sun_texture_id"] = SunTexture;
globalTexturesHash["cloud_texture_id"] = CloudTexture;
globalTexturesHash["moon_texture_id"] = MoonTexture;
globalTextures.Add(globalTexturesHash);
// this.eventCategories.Add(this.eventCategoriesHash);
AddToUIConfig("allow_first_life", allowFirstLife);
uiConfig.Add(uiConfigHash);
responseData["sim_port"] = (Int32) SimPort;
responseData["sim_ip"] = SimAddress;
responseData["agent_id"] = AgentID.ToString();
responseData["session_id"] = SessionID.ToString();
responseData["secure_session_id"] = SecureSessionID.ToString();
responseData["circuit_code"] = CircuitCode;
responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
responseData["login-flags"] = loginFlags;
responseData["global-textures"] = globalTextures;
responseData["seed_capability"] = seedCapability;
responseData["event_categories"] = eventCategories;
responseData["event_notifications"] = new ArrayList(); // todo
responseData["classified_categories"] = classifiedCategories;
responseData["ui-config"] = uiConfig;
responseData["inventory-skeleton"] = agentInventory;
responseData["inventory-skel-lib"] = inventoryLibrary;
responseData["inventory-root"] = inventoryRoot;
responseData["inventory-lib-root"] = inventoryLibRoot;
responseData["gestures"] = new ArrayList(); // todo
responseData["inventory-lib-owner"] = inventoryLibraryOwner;
responseData["initial-outfit"] = initialOutfit;
responseData["start_location"] = startLocation;
responseData["seed_capability"] = seedCapability;
responseData["home"] = home;
responseData["look_at"] = lookAt;
responseData["message"] = welcomeMessage;
responseData["region_x"] = (Int32)(RegionX * Constants.RegionSize);
responseData["region_y"] = (Int32)(RegionY * Constants.RegionSize);
//responseData["inventory-lib-root"] = new ArrayList(); // todo
if (m_buddyList != null)
{
responseData["buddy-list"] = m_buddyList.ToArray();
}
responseData["login"] = "true";
xmlRpcResponse.Value = responseData;
return (xmlRpcResponse);
}
catch (Exception e)
{
m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message);
return (GenerateFailureResponse("Internal Error", "Error generating Login Response", "false"));
}
}
public LLSD ToLLSDResponse()
{
try
{
LLSDMap map = new LLSDMap();
map["first_name"] = LLSD.FromString(Firstname);
map["last_name"] = LLSD.FromString(Lastname);
map["agent_access"] = LLSD.FromString(agentAccess);
map["sim_port"] = LLSD.FromInteger(SimPort);
map["sim_ip"] = LLSD.FromString(SimAddress);
map["agent_id"] = LLSD.FromUUID(AgentID);
map["session_id"] = LLSD.FromUUID(SessionID);
map["secure_session_id"] = LLSD.FromUUID(SecureSessionID);
map["circuit_code"] = LLSD.FromInteger(CircuitCode);
map["seconds_since_epoch"] = LLSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
#region Login Flags
LLSDMap loginFlagsLLSD = new LLSDMap();
loginFlagsLLSD["daylight_savings"] = LLSD.FromString(DST);
loginFlagsLLSD["stipend_since_login"] = LLSD.FromString(StipendSinceLogin);
loginFlagsLLSD["gendered"] = LLSD.FromString(Gendered);
loginFlagsLLSD["ever_logged_in"] = LLSD.FromString(EverLoggedIn);
map["login-flags"] = WrapLLSDMap(loginFlagsLLSD);
#endregion Login Flags
#region Global Textures
LLSDMap globalTexturesLLSD = new LLSDMap();
globalTexturesLLSD["sun_texture_id"] = LLSD.FromString(SunTexture);
globalTexturesLLSD["cloud_texture_id"] = LLSD.FromString(CloudTexture);
globalTexturesLLSD["moon_texture_id"] = LLSD.FromString(MoonTexture);
map["global-textures"] = WrapLLSDMap(globalTexturesLLSD);
#endregion Global Textures
map["seed_capability"] = LLSD.FromString(seedCapability);
// FIXME: Need a function that will convert these ArrayLists in to LLSDArrays,
// and convert the data inside them to LLSD objects as well
//map["event_categories"] = eventCategories;
//map["event_notifications"] = new LLSDArray(); // todo
//map["classified_categories"] = classifiedCategories;
#region UI Config
LLSDMap uiConfigLLSD = new LLSDMap();
uiConfigLLSD["allow_first_life"] = LLSD.FromString(allowFirstLife);
map["ui-config"] = WrapLLSDMap(uiConfigLLSD);
#endregion UI Config
#region Inventory
//map["inventory-skeleton"] = agentInventory;
//map["inventory-skel-lib"] = inventoryLibrary;
//map["inventory-root"] = inventoryRoot;
//map["inventory-lib-root"] = inventoryLibRoot;
//map["inventory-lib-owner"] = inventoryLibraryOwner;
#endregion Inventory
map["gestures"] = new LLSDArray(); // todo
//responseData["initial-outfit"] = initialOutfit;
//responseData["start_location"] = startLocation;
map["seed_capability"] = LLSD.FromString(seedCapability);
map["home"] = LLSD.FromString(home);
map["look_at"] = LLSD.FromString(lookAt);
map["message"] = LLSD.FromString(welcomeMessage);
map["region_x"] = LLSD.FromInteger(RegionX * Constants.RegionSize);
map["region_y"] = LLSD.FromInteger(RegionY * Constants.RegionSize);
if (m_buddyList != null)
{
//map["buddy-list"] = m_buddyList.ToArray();
}
map["login"] = LLSD.FromString("true");
return map;
}
catch (Exception e)
{
m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message);
return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false");
}
}
private LLSDArray WrapLLSDMap(LLSDMap wrapMe)
{
LLSDArray array = new LLSDArray();
array.Add(wrapMe);
return array;
}
public void SetEventCategories(string category, string value)
{
// this.eventCategoriesHash[category] = value;
//TODO
}
public void AddToUIConfig(string itemName, string item)
{
uiConfigHash[itemName] = item;
}
public void AddClassifiedCategory(Int32 ID, string categoryName)
{
Hashtable hash = new Hashtable();
hash["category_name"] = categoryName;
hash["category_id"] = ID;
classifiedCategories.Add(hash);
// this.classifiedCategoriesHash.Clear();
}
#region Properties
public string Login
{
get { return login; }
set { login = value; }
}
public string DST
{
get { return dst; }
set { dst = value; }
}
public string StipendSinceLogin
{
get { return stipendSinceLogin; }
set { stipendSinceLogin = value; }
}
public string Gendered
{
get { return gendered; }
set { gendered = value; }
}
public string EverLoggedIn
{
get { return everLoggedIn; }
set { everLoggedIn = value; }
}
public uint SimPort
{
get { return simPort; }
set { simPort = value; }
}
public string SimAddress
{
get { return simAddress; }
set { simAddress = value; }
}
public LLUUID AgentID
{
get { return agentID; }
set { agentID = value; }
}
public LLUUID SessionID
{
get { return sessionID; }
set { sessionID = value; }
}
public LLUUID SecureSessionID
{
get { return secureSessionID; }
set { secureSessionID = value; }
}
public Int32 CircuitCode
{
get { return circuitCode; }
set { circuitCode = value; }
}
public uint RegionX
{
get { return regionX; }
set { regionX = value; }
}
public uint RegionY
{
get { return regionY; }
set { regionY = value; }
}
public string SunTexture
{
get { return sunTexture; }
set { sunTexture = value; }
}
public string CloudTexture
{
get { return cloudTexture; }
set { cloudTexture = value; }
}
public string MoonTexture
{
get { return moonTexture; }
set { moonTexture = value; }
}
public string Firstname
{
get { return firstname; }
set { firstname = value; }
}
public string Lastname
{
get { return lastname; }
set { lastname = value; }
}
public string AgentAccess
{
get { return agentAccess; }
set { agentAccess = value; }
}
public string StartLocation
{
get { return startLocation; }
set { startLocation = value; }
}
public string LookAt
{
get { return lookAt; }
set { lookAt = value; }
}
public string SeedCapability
{
get { return seedCapability; }
set { seedCapability = value; }
}
public string ErrorReason
{
get { return errorReason; }
set { errorReason = value; }
}
public string ErrorMessage
{
get { return errorMessage; }
set { errorMessage = value; }
}
public ArrayList InventoryRoot
{
get { return inventoryRoot; }
set { inventoryRoot = value; }
}
public ArrayList InventorySkeleton
{
get { return agentInventory; }
set { agentInventory = value; }
}
public ArrayList InventoryLibrary
{
get { return inventoryLibrary; }
set { inventoryLibrary = value; }
}
public ArrayList InventoryLibraryOwner
{
get { return inventoryLibraryOwner; }
set { inventoryLibraryOwner = value; }
}
public ArrayList InventoryLibRoot
{
get { return inventoryLibRoot; }
set { inventoryLibRoot = value; }
}
public string Home
{
get { return home; }
set { home = value; }
}
public string Message
{
get { return welcomeMessage; }
set { welcomeMessage = value; }
}
public BuddyList BuddList
{
get { return m_buddyList; }
set { m_buddyList = value; }
}
#endregion
public class UserInfo
{
public string firstname;
public string lastname;
public ulong homeregionhandle;
public LLVector3 homepos;
public LLVector3 homelookat;
}
public class BuddyList
{
public List<BuddyInfo> Buddies = new List<BuddyInfo>();
public void AddNewBuddy(BuddyInfo buddy)
{
if (!Buddies.Contains(buddy))
{
Buddies.Add(buddy);
}
}
public ArrayList ToArray()
{
ArrayList buddyArray = new ArrayList();
foreach (BuddyInfo buddy in Buddies)
{
buddyArray.Add(buddy.ToHashTable());
}
return buddyArray;
}
public class BuddyInfo
{
public int BuddyRightsHave = 1;
public int BuddyRightsGiven = 1;
public LLUUID BuddyID;
public BuddyInfo(string buddyID)
{
BuddyID = new LLUUID(buddyID);
}
public BuddyInfo(LLUUID buddyID)
{
BuddyID = buddyID;
}
public Hashtable ToHashTable()
{
Hashtable hTable = new Hashtable();
hTable["buddy_rights_has"] = BuddyRightsHave;
hTable["buddy_rights_given"] = BuddyRightsGiven;
hTable["buddy_id"] = BuddyID.ToString();
return hTable;
}
}
}
}
}
|