aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications')
-rw-r--r--OpenSim/Framework/Communications/CAPSService.cs38
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetTransactions.cs2
-rw-r--r--OpenSim/Framework/Communications/Cache/CachedUserInfo.cs6
-rw-r--r--OpenSim/Framework/Communications/Cache/UserProfileCache.cs6
-rw-r--r--OpenSim/Framework/Communications/CommunicationsManager.cs61
-rw-r--r--OpenSim/Framework/Communications/IInventoryServices.cs8
-rw-r--r--OpenSim/Framework/Communications/IUserServices.cs5
-rw-r--r--OpenSim/Framework/Communications/InventoryServiceBase.cs211
-rw-r--r--OpenSim/Framework/Communications/LoginResponse.cs667
-rw-r--r--OpenSim/Framework/Communications/LoginService.cs287
-rw-r--r--OpenSim/Framework/Communications/UserManagerBase.cs379
11 files changed, 1629 insertions, 41 deletions
diff --git a/OpenSim/Framework/Communications/CAPSService.cs b/OpenSim/Framework/Communications/CAPSService.cs
new file mode 100644
index 0000000..a8eac26
--- /dev/null
+++ b/OpenSim/Framework/Communications/CAPSService.cs
@@ -0,0 +1,38 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Reflection;
5using System.Security.Cryptography;
6using libsecondlife;
7using Nwc.XmlRpc;
8using OpenSim.Framework.Console;
9using OpenSim.Framework.Data;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Inventory;
12using OpenSim.Framework.Utilities;
13using OpenSim.Framework.Servers;
14
15namespace OpenSim.Framework.UserManagement
16{
17 public class CAPSService
18 {
19 private BaseHttpServer m_server;
20
21 public CAPSService(BaseHttpServer httpServer)
22 {
23 m_server = httpServer;
24 this.AddCapsSeedHandler("/CapsSeed/", CapsRequest);
25 }
26
27 private void AddCapsSeedHandler(string path, RestMethod restMethod)
28 {
29 m_server.AddStreamHandler(new RestStreamHandler("POST", path, restMethod));
30 }
31
32 public string CapsRequest(string request, string path, string param)
33 {
34 System.Console.WriteLine("new caps request " + request +" from path "+ path);
35 return "";
36 }
37 }
38}
diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
index 59a9e00..d0507d0 100644
--- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs
@@ -316,7 +316,7 @@ namespace OpenSim.Framework.Communications.Caches
316 { 316 {
317 //really need to fix this call, if lbsa71 saw this he would die. 317 //really need to fix this call, if lbsa71 saw this he would die.
318 this.m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(this.Asset); 318 this.m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(this.Asset);
319 CachedUserInfo userInfo = m_userTransactions.Manager.CommsManager.UserProfiles.GetUserDetails(ourClient.AgentId); 319 CachedUserInfo userInfo = m_userTransactions.Manager.CommsManager.UserProfileCache.GetUserDetails(ourClient.AgentId);
320 if (userInfo != null) 320 if (userInfo != null)
321 { 321 {
322 InventoryItemBase item = new InventoryItemBase(); 322 InventoryItemBase item = new InventoryItemBase();
diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
index acdb6db..99dc45a 100644
--- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
+++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
@@ -101,7 +101,7 @@ namespace OpenSim.Framework.Communications.Caches
101 if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) 101 if ((userID == this.UserProfile.UUID) && (this.RootFolder != null))
102 { 102 {
103 this.ItemReceive(userID, itemInfo); 103 this.ItemReceive(userID, itemInfo);
104 this.m_parentCommsManager.InventoryServer.AddNewInventoryItem(userID, itemInfo); 104 this.m_parentCommsManager.InventoryService.AddNewInventoryItem(userID, itemInfo);
105 } 105 }
106 } 106 }
107 107
@@ -109,7 +109,7 @@ namespace OpenSim.Framework.Communications.Caches
109 { 109 {
110 if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) 110 if ((userID == this.UserProfile.UUID) && (this.RootFolder != null))
111 { 111 {
112 this.m_parentCommsManager.InventoryServer.AddNewInventoryItem(userID, itemInfo); 112 this.m_parentCommsManager.InventoryService.AddNewInventoryItem(userID, itemInfo);
113 } 113 }
114 } 114 }
115 115
@@ -121,7 +121,7 @@ namespace OpenSim.Framework.Communications.Caches
121 result = RootFolder.DeleteItem(item.inventoryID); 121 result = RootFolder.DeleteItem(item.inventoryID);
122 if (result) 122 if (result)
123 { 123 {
124 this.m_parentCommsManager.InventoryServer.DeleteInventoryItem(userID, item); 124 this.m_parentCommsManager.InventoryService.DeleteInventoryItem(userID, item);
125 } 125 }
126 } 126 }
127 return result; 127 return result;
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
index 0c8c0f9..390b938 100644
--- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
+++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs
@@ -106,7 +106,7 @@ namespace OpenSim.Framework.Communications.Caches
106 InventoryFolder createdFolder = info.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); 106 InventoryFolder createdFolder = info.RootFolder.CreateNewSubFolder(folderID, folderName, folderType);
107 if (createdFolder != null) 107 if (createdFolder != null)
108 { 108 {
109 this.m_parent.InventoryServer.AddNewInventoryFolder(remoteClient.AgentId, createdFolder); 109 this.m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdFolder);
110 } 110 }
111 } 111 }
112 else 112 else
@@ -181,7 +181,7 @@ namespace OpenSim.Framework.Communications.Caches
181 /// <param name="userID"></param> 181 /// <param name="userID"></param>
182 private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) 182 private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo)
183 { 183 {
184 this.m_parent.InventoryServer.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); 184 this.m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive);
185 } 185 }
186 186
187 /// <summary> 187 /// <summary>
@@ -190,7 +190,7 @@ namespace OpenSim.Framework.Communications.Caches
190 /// <param name="userID"></param> 190 /// <param name="userID"></param>
191 private UserProfileData RequestUserProfileForUser(LLUUID userID) 191 private UserProfileData RequestUserProfileForUser(LLUUID userID)
192 { 192 {
193 return this.m_parent.UserServer.GetUserProfile(userID); 193 return this.m_parent.UserService.GetUserProfile(userID);
194 } 194 }
195 195
196 /// <summary> 196 /// <summary>
diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs
index 2a87306..6ea3c29 100644
--- a/OpenSim/Framework/Communications/CommunicationsManager.cs
+++ b/OpenSim/Framework/Communications/CommunicationsManager.cs
@@ -37,81 +37,74 @@ namespace OpenSim.Framework.Communications
37{ 37{
38 public class CommunicationsManager 38 public class CommunicationsManager
39 { 39 {
40 protected AssetCache m_assetCache; 40 protected IUserServices m_userService;
41 protected IGridServices m_gridServer; 41 public IUserServices UserService
42 protected IInterRegionCommunications m_interRegion;
43 protected IInventoryServices m_inventoryServer;
44 protected AssetTransactionManager m_transactionsManager;
45 protected UserProfileCache m_userProfiles;
46 protected IUserServices m_userServer;
47 protected NetworkServersInfo m_networkServersInfo;
48
49 public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, AssetCache assetCache)
50 {
51 m_networkServersInfo = serversInfo;
52 m_assetCache = assetCache;
53 m_userProfiles = new UserProfileCache(this);
54 m_transactionsManager = new AssetTransactionManager(this);
55 }
56
57 public IUserServices UserServer
58 { 42 {
59 get { return m_userServer; } 43 get { return m_userService; }
60 set { m_userServer = value; }
61 } 44 }
62 45
63 public IGridServices GridServer 46 protected IGridServices m_gridService;
47 public IGridServices GridService
64 { 48 {
65 get { return m_gridServer; } 49 get { return m_gridService; }
66 } 50 }
67 51
68 public IInventoryServices InventoryServer 52 protected IInventoryServices m_inventoryService;
53 public IInventoryServices InventoryService
69 { 54 {
70 get { return m_inventoryServer; } 55 get { return m_inventoryService; }
71 set { m_inventoryServer = value; }
72 } 56 }
73 57
58 protected IInterRegionCommunications m_interRegion;
74 public IInterRegionCommunications InterRegion 59 public IInterRegionCommunications InterRegion
75 { 60 {
76 get { return m_interRegion; } 61 get { return m_interRegion; }
77 set { m_interRegion = value; }
78 } 62 }
79 63
80 public UserProfileCache UserProfiles 64 protected UserProfileCache m_userProfileCache;
65 public UserProfileCache UserProfileCache
81 { 66 {
82 get { return m_userProfiles; } 67 get { return m_userProfileCache; }
83 set { m_userProfiles = value; }
84 } 68 }
85 69
70 protected AssetTransactionManager m_transactionsManager;
86 public AssetTransactionManager TransactionsManager 71 public AssetTransactionManager TransactionsManager
87 { 72 {
88 get { return m_transactionsManager; } 73 get { return m_transactionsManager; }
89 set { m_transactionsManager = value; }
90 } 74 }
91 75
76 protected AssetCache m_assetCache;
92 public AssetCache AssetCache 77 public AssetCache AssetCache
93 { 78 {
94 get { return m_assetCache; } 79 get { return m_assetCache; }
95 set { m_assetCache = value; }
96 } 80 }
97 81
82 protected NetworkServersInfo m_networkServersInfo;
98 public NetworkServersInfo NetworkServersInfo 83 public NetworkServersInfo NetworkServersInfo
99 { 84 {
100 get { return m_networkServersInfo; } 85 get { return m_networkServersInfo; }
101 set { m_networkServersInfo = value; }
102 } 86 }
103 87
88 public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, AssetCache assetCache)
89 {
90 m_networkServersInfo = serversInfo;
91 m_assetCache = assetCache;
92 m_userProfileCache = new UserProfileCache(this);
93 m_transactionsManager = new AssetTransactionManager(this);
94 }
95
96
104 #region Packet Handlers 97 #region Packet Handlers
105 98
106 public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client) 99 public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client)
107 { 100 {
108 if (uuid == m_userProfiles.libraryRoot.agentID) 101 if (uuid == m_userProfileCache.libraryRoot.agentID)
109 { 102 {
110 remote_client.SendNameReply(uuid, "Mr", "OpenSim"); 103 remote_client.SendNameReply(uuid, "Mr", "OpenSim");
111 } 104 }
112 else 105 else
113 { 106 {
114 UserProfileData profileData = m_userServer.GetUserProfile(uuid); 107 UserProfileData profileData = m_userService.GetUserProfile(uuid);
115 if (profileData != null) 108 if (profileData != null)
116 { 109 {
117 LLUUID profileId = profileData.UUID; 110 LLUUID profileId = profileData.UUID;
diff --git a/OpenSim/Framework/Communications/IInventoryServices.cs b/OpenSim/Framework/Communications/IInventoryServices.cs
index bd58756..80c2e64 100644
--- a/OpenSim/Framework/Communications/IInventoryServices.cs
+++ b/OpenSim/Framework/Communications/IInventoryServices.cs
@@ -17,5 +17,13 @@ namespace OpenSim.Framework.Communications
17 void AddNewInventoryFolder(LLUUID userID, InventoryFolder folder); 17 void AddNewInventoryFolder(LLUUID userID, InventoryFolder folder);
18 void AddNewInventoryItem(LLUUID userID, InventoryItemBase item); 18 void AddNewInventoryItem(LLUUID userID, InventoryItemBase item);
19 void DeleteInventoryItem(LLUUID userID, InventoryItemBase item); 19 void DeleteInventoryItem(LLUUID userID, InventoryItemBase item);
20 void CreateNewUserInventory(LLUUID user);
21
22 /// <summary>
23 /// Returns the root folder plus any folders in root (so down one level in the Inventory folders tree)
24 /// </summary>
25 /// <param name="userID"></param>
26 /// <returns></returns>
27 List<InventoryFolderBase> RequestFirstLevelFolders(LLUUID userID);
20 } 28 }
21} 29}
diff --git a/OpenSim/Framework/Communications/IUserServices.cs b/OpenSim/Framework/Communications/IUserServices.cs
index c1bea48..13dd378 100644
--- a/OpenSim/Framework/Communications/IUserServices.cs
+++ b/OpenSim/Framework/Communications/IUserServices.cs
@@ -40,5 +40,10 @@ namespace OpenSim.Framework.Communications
40 UserProfileData SetupMasterUser(string firstName, string lastName); 40 UserProfileData SetupMasterUser(string firstName, string lastName);
41 UserProfileData SetupMasterUser(string firstName, string lastName, string password); 41 UserProfileData SetupMasterUser(string firstName, string lastName, string password);
42 42
43 /// <summary>
44 ///
45 /// </summary>
46 /// <param name="user"></param>
47 void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY);
43 } 48 }
44} 49}
diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs
new file mode 100644
index 0000000..da7a0ce
--- /dev/null
+++ b/OpenSim/Framework/Communications/InventoryServiceBase.cs
@@ -0,0 +1,211 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using libsecondlife;
5using OpenSim.Framework.Communications;
6using OpenSim.Framework.Console;
7using OpenSim.Framework.Data;
8using InventoryFolder=OpenSim.Framework.Communications.Caches.InventoryFolder;
9
10namespace OpenSim.Framework.Communications
11{
12 public abstract class InventoryServiceBase : IInventoryServices
13 {
14 protected Dictionary<string, IInventoryData> m_plugins = new Dictionary<string, IInventoryData>();
15 //protected IAssetServer m_assetServer;
16
17 public InventoryServiceBase()
18 {
19 //m_assetServer = assetServer;
20 }
21
22 /// <summary>
23 /// Adds a new user server plugin - plugins will be requested in the order they were loaded.
24 /// </summary>
25 /// <param name="FileName">The filename to the user server plugin DLL</param>
26 public void AddPlugin(string FileName)
27 {
28 if (!String.IsNullOrEmpty(FileName))
29 {
30 MainLog.Instance.Verbose("Inventory", "Inventorystorage: Attempting to load " + FileName);
31 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
32
33 foreach (Type pluginType in pluginAssembly.GetTypes())
34 {
35 if (!pluginType.IsAbstract)
36 {
37 Type typeInterface = pluginType.GetInterface("IInventoryData", true);
38
39 if (typeInterface != null)
40 {
41 IInventoryData plug =
42 (IInventoryData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
43 plug.Initialise();
44 this.m_plugins.Add(plug.getName(), plug);
45 MainLog.Instance.Verbose("Inventorystorage: Added IInventoryData Interface");
46 }
47 }
48 }
49 }
50 }
51
52 /// <summary>
53 /// Returns the root folder plus any folders in root (so down one level in the Inventory folders tree)
54 /// </summary>
55 /// <param name="userID"></param>
56 /// <returns></returns>
57 public List<InventoryFolderBase> RequestFirstLevelFolders(LLUUID userID)
58 {
59 List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>();
60 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
61 {
62 InventoryFolderBase rootFolder = plugin.Value.getUserRootFolder(userID);
63 if (rootFolder != null)
64 {
65 inventoryList = plugin.Value.getInventoryFolders(rootFolder.folderID);
66 inventoryList.Insert(0, rootFolder);
67 return inventoryList;
68 }
69 }
70 return inventoryList;
71 }
72
73 /// <summary>
74 ///
75 /// </summary>
76 public InventoryFolderBase RequestUsersRoot(LLUUID userID)
77 {
78 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
79 {
80 return plugin.Value.getUserRootFolder(userID);
81 }
82 return null;
83 }
84
85 /// <summary>
86 ///
87 /// </summary>
88 /// <param name="parentFolderID"></param>
89 /// <returns></returns>
90 public List<InventoryFolderBase> RequestSubFolders(LLUUID parentFolderID)
91 {
92 List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>();
93 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
94 {
95 return plugin.Value.getInventoryFolders(parentFolderID);
96 }
97 return inventoryList;
98 }
99
100 public List<InventoryItemBase> RequestFolderItems(LLUUID folderID)
101 {
102 List<InventoryItemBase> itemsList = new List<InventoryItemBase>();
103 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
104 {
105 itemsList = plugin.Value.getInventoryInFolder(folderID);
106 return itemsList;
107 }
108 return itemsList;
109 }
110
111 public void AddFolder(InventoryFolderBase folder)
112 {
113 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
114 {
115 plugin.Value.addInventoryFolder(folder);
116 }
117 }
118
119 public void AddItem(InventoryItemBase item)
120 {
121 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
122 {
123 plugin.Value.addInventoryItem(item);
124 }
125 }
126
127 public void deleteItem(InventoryItemBase item)
128 {
129 foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins)
130 {
131 plugin.Value.deleteInventoryItem(item);
132 }
133 }
134
135 /// <summary>
136 ///
137 /// </summary>
138 /// <param name="inventory"></param>
139 public void AddNewInventorySet(UsersInventory inventory)
140 {
141 foreach (InventoryFolderBase folder in inventory.Folders.Values)
142 {
143 this.AddFolder(folder);
144 }
145 }
146
147 public void CreateNewUserInventory(LLUUID user)
148 {
149 UsersInventory inven = new UsersInventory();
150 inven.CreateNewInventorySet(user);
151 this.AddNewInventorySet(inven);
152 }
153
154 public class UsersInventory
155 {
156 public Dictionary<LLUUID, InventoryFolderBase> Folders = new Dictionary<LLUUID, InventoryFolderBase>();
157 public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>();
158
159 public UsersInventory()
160 {
161
162 }
163
164 public virtual void CreateNewInventorySet(LLUUID user)
165 {
166 InventoryFolderBase folder = new InventoryFolderBase();
167 folder.parentID = LLUUID.Zero;
168 folder.agentID = user;
169 folder.folderID = LLUUID.Random();
170 folder.name = "My Inventory";
171 folder.type = 8;
172 folder.version = 1;
173 Folders.Add(folder.folderID, folder);
174
175 LLUUID rootFolder = folder.folderID;
176
177 folder = new InventoryFolderBase();
178 folder.parentID = rootFolder;
179 folder.agentID = user;
180 folder.folderID = LLUUID.Random();
181 folder.name = "Textures";
182 folder.type = 0;
183 folder.version = 1;
184 Folders.Add(folder.folderID, folder);
185
186 folder = new InventoryFolderBase();
187 folder.parentID = rootFolder;
188 folder.agentID = user;
189 folder.folderID = LLUUID.Random();
190 folder.name = "Objects";
191 folder.type = 6;
192 folder.version = 1;
193 Folders.Add(folder.folderID, folder);
194
195 folder = new InventoryFolderBase();
196 folder.parentID = rootFolder;
197 folder.agentID = user;
198 folder.folderID = LLUUID.Random();
199 folder.name = "Clothes";
200 folder.type = 5;
201 folder.version = 1;
202 Folders.Add(folder.folderID, folder);
203 }
204 }
205
206 public abstract void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack);
207 public abstract void AddNewInventoryFolder(LLUUID userID, InventoryFolder folder);
208 public abstract void AddNewInventoryItem(LLUUID userID, InventoryItemBase item);
209 public abstract void DeleteInventoryItem(LLUUID userID, InventoryItemBase item);
210 }
211} \ No newline at end of file
diff --git a/OpenSim/Framework/Communications/LoginResponse.cs b/OpenSim/Framework/Communications/LoginResponse.cs
new file mode 100644
index 0000000..b5a4184
--- /dev/null
+++ b/OpenSim/Framework/Communications/LoginResponse.cs
@@ -0,0 +1,667 @@
1using System;
2using System.Collections;
3using libsecondlife;
4using Nwc.XmlRpc;
5using OpenSim.Framework.Console;
6
7namespace OpenSim.Framework.UserManagement
8{
9
10 /// <summary>
11 /// A temp class to handle login response.
12 /// Should make use of UserProfileManager where possible.
13 /// </summary>
14
15 public class LoginResponse
16 {
17 private Hashtable loginFlagsHash;
18 private Hashtable globalTexturesHash;
19 private Hashtable loginError;
20 private Hashtable uiConfigHash;
21
22 private ArrayList loginFlags;
23 private ArrayList globalTextures;
24 private ArrayList eventCategories;
25 private ArrayList uiConfig;
26 private ArrayList classifiedCategories;
27 private ArrayList inventoryRoot;
28 private ArrayList initialOutfit;
29 private ArrayList agentInventory;
30 private ArrayList inventoryLibraryOwner;
31 private ArrayList inventoryLibrary;
32
33 private UserInfo userProfile;
34
35 private LLUUID agentID;
36 private LLUUID sessionID;
37 private LLUUID secureSessionID;
38
39 // Login Flags
40 private string dst;
41 private string stipendSinceLogin;
42 private string gendered;
43 private string everLoggedIn;
44 private string login;
45 private int simPort;
46 private string simAddress;
47 private string agentAccess;
48 private Int32 circuitCode;
49 private uint regionX;
50 private uint regionY;
51
52 // Login
53 private string firstname;
54 private string lastname;
55
56 // Global Textures
57 private string sunTexture;
58 private string cloudTexture;
59 private string moonTexture;
60
61 // Error Flags
62 private string errorReason;
63 private string errorMessage;
64
65 // Response
66 private XmlRpcResponse xmlRpcResponse;
67 private XmlRpcResponse defaultXmlRpcResponse;
68
69 private string welcomeMessage;
70 private string startLocation;
71 private string allowFirstLife;
72 private string home;
73 private string seedCapability;
74 private string lookAt;
75
76 public LoginResponse()
77 {
78 this.loginFlags = new ArrayList();
79 this.globalTextures = new ArrayList();
80 this.eventCategories = new ArrayList();
81 this.uiConfig = new ArrayList();
82 this.classifiedCategories = new ArrayList();
83
84 this.loginError = new Hashtable();
85 this.uiConfigHash = new Hashtable();
86
87 this.defaultXmlRpcResponse = new XmlRpcResponse();
88 this.userProfile = new UserInfo();
89 this.inventoryRoot = new ArrayList();
90 this.initialOutfit = new ArrayList();
91 this.agentInventory = new ArrayList();
92 this.inventoryLibrary = new ArrayList();
93 this.inventoryLibraryOwner = new ArrayList();
94
95 this.xmlRpcResponse = new XmlRpcResponse();
96 this.defaultXmlRpcResponse = new XmlRpcResponse();
97
98 this.SetDefaultValues();
99 } // LoginServer
100
101 public void SetDefaultValues()
102 {
103 this.DST = "N";
104 this.StipendSinceLogin = "N";
105 this.Gendered = "Y";
106 this.EverLoggedIn = "Y";
107 this.login = "false";
108 this.firstname = "Test";
109 this.lastname = "User";
110 this.agentAccess = "M";
111 this.startLocation = "last";
112 this.allowFirstLife = "Y";
113
114 this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
115 this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
116 this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
117
118 this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
119 this.ErrorReason = "key";
120 this.welcomeMessage = "Welcome to OpenSim!";
121 this.seedCapability = "";
122 this.home = "{'region_handle':[r" + (1000 * 256).ToString() + ",r" + (1000 * 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() + "]}";
123 this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
124 this.RegionX = (uint)255232;
125 this.RegionY = (uint)254976;
126
127 // Classifieds;
128 this.AddClassifiedCategory((Int32)1, "Shopping");
129 this.AddClassifiedCategory((Int32)2, "Land Rental");
130 this.AddClassifiedCategory((Int32)3, "Property Rental");
131 this.AddClassifiedCategory((Int32)4, "Special Attraction");
132 this.AddClassifiedCategory((Int32)5, "New Products");
133 this.AddClassifiedCategory((Int32)6, "Employment");
134 this.AddClassifiedCategory((Int32)7, "Wanted");
135 this.AddClassifiedCategory((Int32)8, "Service");
136 this.AddClassifiedCategory((Int32)9, "Personal");
137
138
139 this.SessionID = LLUUID.Random();
140 this.SecureSessionID = LLUUID.Random();
141 this.AgentID = LLUUID.Random();
142
143 Hashtable InitialOutfitHash = new Hashtable();
144 InitialOutfitHash["folder_name"] = "Nightclub Female";
145 InitialOutfitHash["gender"] = "female";
146 this.initialOutfit.Add(InitialOutfitHash);
147
148
149 } // SetDefaultValues
150
151 #region Login Failure Methods
152 public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
153 {
154 // Overwrite any default values;
155 this.xmlRpcResponse = new XmlRpcResponse();
156
157 // Ensure Login Failed message/reason;
158 this.ErrorMessage = message;
159 this.ErrorReason = reason;
160
161 this.loginError["reason"] = this.ErrorReason;
162 this.loginError["message"] = this.ErrorMessage;
163 this.loginError["login"] = login;
164 this.xmlRpcResponse.Value = this.loginError;
165 return (this.xmlRpcResponse);
166 } // GenerateResponse
167
168 public XmlRpcResponse CreateFailedResponse()
169 {
170 return (this.CreateLoginFailedResponse());
171 } // CreateErrorConnectingToGridResponse()
172
173 public XmlRpcResponse CreateLoginFailedResponse()
174 {
175 return (this.GenerateFailureResponse("key", "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", "false"));
176 } // LoginFailedResponse
177
178 public XmlRpcResponse CreateAlreadyLoggedInResponse()
179 {
180 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"));
181 } // CreateAlreadyLoggedInResponse()
182
183 public XmlRpcResponse CreateDeadRegionResponse()
184 {
185 return (this.GenerateFailureResponse("key", "The region you are attempting to log into is not responding. Please select another region and try again.", "false"));
186 }
187
188 public XmlRpcResponse CreateGridErrorResponse()
189 {
190 return (this.GenerateFailureResponse("key", "Error connecting to grid. Could not percieve credentials from login XML.", "false"));
191 }
192
193 #endregion
194
195 public XmlRpcResponse ToXmlRpcResponse()
196 {
197 try
198 {
199
200 Hashtable responseData = new Hashtable();
201
202 this.loginFlagsHash = new Hashtable();
203 this.loginFlagsHash["daylight_savings"] = this.DST;
204 this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
205 this.loginFlagsHash["gendered"] = this.Gendered;
206 this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
207 this.loginFlags.Add(this.loginFlagsHash);
208
209 responseData["first_name"] = this.Firstname;
210 responseData["last_name"] = this.Lastname;
211 responseData["agent_access"] = this.agentAccess;
212
213 this.globalTexturesHash = new Hashtable();
214 this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
215 this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
216 this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
217 this.globalTextures.Add(this.globalTexturesHash);
218 // this.eventCategories.Add(this.eventCategoriesHash);
219
220 this.AddToUIConfig("allow_first_life", this.allowFirstLife);
221 this.uiConfig.Add(this.uiConfigHash);
222
223 responseData["sim_port"] =(Int32) this.SimPort;
224 responseData["sim_ip"] = this.SimAddress;
225
226 responseData["agent_id"] = this.AgentID.ToStringHyphenated();
227 responseData["session_id"] = this.SessionID.ToStringHyphenated();
228 responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated();
229 responseData["circuit_code"] = this.CircuitCode;
230 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
231 responseData["login-flags"] = this.loginFlags;
232 responseData["global-textures"] = this.globalTextures;
233 responseData["seed_capability"] = this.seedCapability;
234
235 responseData["event_categories"] = this.eventCategories;
236 responseData["event_notifications"] = new ArrayList(); // todo
237 responseData["classified_categories"] = this.classifiedCategories;
238 responseData["ui-config"] = this.uiConfig;
239
240 responseData["inventory-skeleton"] = this.agentInventory;
241 responseData["inventory-skel-lib"] = this.inventoryLibrary;
242 responseData["inventory-root"] = this.inventoryRoot;
243 responseData["gestures"] = new ArrayList(); // todo
244 responseData["inventory-lib-owner"] = this.inventoryLibraryOwner;
245 responseData["initial-outfit"] = this.initialOutfit;
246 responseData["start_location"] = this.startLocation;
247 responseData["seed_capability"] = this.seedCapability;
248 responseData["home"] = this.home;
249 responseData["look_at"] = this.lookAt;
250 responseData["message"] = this.welcomeMessage;
251 responseData["region_x"] = (Int32)this.RegionX * 256;
252 responseData["region_y"] = (Int32)this.RegionY * 256;
253
254 //responseData["inventory-lib-root"] = new ArrayList(); // todo
255 //responseData["buddy-list"] = new ArrayList(); // todo
256
257 responseData["login"] = "true";
258 this.xmlRpcResponse.Value = responseData;
259
260 return (this.xmlRpcResponse);
261 }
262 catch (Exception e)
263 {
264 MainLog.Instance.Warn(
265 "CLIENT",
266 "LoginResponse: Error creating XML-RPC Response: " + e.Message
267 );
268 return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false"));
269
270 }
271
272 } // ToXmlRpcResponse
273
274 public void SetEventCategories(string category, string value)
275 {
276 // this.eventCategoriesHash[category] = value;
277 //TODO
278 } // SetEventCategories
279
280 public void AddToUIConfig(string itemName, string item)
281 {
282 this.uiConfigHash[itemName] = item;
283 } // SetUIConfig
284
285 public void AddClassifiedCategory(Int32 ID, string categoryName)
286 {
287 Hashtable hash = new Hashtable();
288 hash["category_name"] = categoryName;
289 hash["category_id"] = ID;
290 this.classifiedCategories.Add(hash);
291 // this.classifiedCategoriesHash.Clear();
292 } // SetClassifiedCategory
293
294 #region Properties
295 public string Login
296 {
297 get
298 {
299 return this.login;
300 }
301 set
302 {
303 this.login = value;
304 }
305 } // Login
306
307 public string DST
308 {
309 get
310 {
311 return this.dst;
312 }
313 set
314 {
315 this.dst = value;
316 }
317 } // DST
318
319 public string StipendSinceLogin
320 {
321 get
322 {
323 return this.stipendSinceLogin;
324 }
325 set
326 {
327 this.stipendSinceLogin = value;
328 }
329 } // StipendSinceLogin
330
331 public string Gendered
332 {
333 get
334 {
335 return this.gendered;
336 }
337 set
338 {
339 this.gendered = value;
340 }
341 } // Gendered
342
343 public string EverLoggedIn
344 {
345 get
346 {
347 return this.everLoggedIn;
348 }
349 set
350 {
351 this.everLoggedIn = value;
352 }
353 } // EverLoggedIn
354
355 public int SimPort
356 {
357 get
358 {
359 return this.simPort;
360 }
361 set
362 {
363 this.simPort = value;
364 }
365 } // SimPort
366
367 public string SimAddress
368 {
369 get
370 {
371 return this.simAddress;
372 }
373 set
374 {
375 this.simAddress = value;
376 }
377 } // SimAddress
378
379 public LLUUID AgentID
380 {
381 get
382 {
383 return this.agentID;
384 }
385 set
386 {
387 this.agentID = value;
388 }
389 } // AgentID
390
391 public LLUUID SessionID
392 {
393 get
394 {
395 return this.sessionID;
396 }
397 set
398 {
399 this.sessionID = value;
400 }
401 } // SessionID
402
403 public LLUUID SecureSessionID
404 {
405 get
406 {
407 return this.secureSessionID;
408 }
409 set
410 {
411 this.secureSessionID = value;
412 }
413 } // SecureSessionID
414
415 public Int32 CircuitCode
416 {
417 get
418 {
419 return this.circuitCode;
420 }
421 set
422 {
423 this.circuitCode = value;
424 }
425 } // CircuitCode
426
427 public uint RegionX
428 {
429 get
430 {
431 return this.regionX;
432 }
433 set
434 {
435 this.regionX = value;
436 }
437 } // RegionX
438
439 public uint RegionY
440 {
441 get
442 {
443 return this.regionY;
444 }
445 set
446 {
447 this.regionY = value;
448 }
449 } // RegionY
450
451 public string SunTexture
452 {
453 get
454 {
455 return this.sunTexture;
456 }
457 set
458 {
459 this.sunTexture = value;
460 }
461 } // SunTexture
462
463 public string CloudTexture
464 {
465 get
466 {
467 return this.cloudTexture;
468 }
469 set
470 {
471 this.cloudTexture = value;
472 }
473 } // CloudTexture
474
475 public string MoonTexture
476 {
477 get
478 {
479 return this.moonTexture;
480 }
481 set
482 {
483 this.moonTexture = value;
484 }
485 } // MoonTexture
486
487 public string Firstname
488 {
489 get
490 {
491 return this.firstname;
492 }
493 set
494 {
495 this.firstname = value;
496 }
497 } // Firstname
498
499 public string Lastname
500 {
501 get
502 {
503 return this.lastname;
504 }
505 set
506 {
507 this.lastname = value;
508 }
509 } // Lastname
510
511 public string AgentAccess
512 {
513 get
514 {
515 return this.agentAccess;
516 }
517 set
518 {
519 this.agentAccess = value;
520 }
521 }
522
523 public string StartLocation
524 {
525 get
526 {
527 return this.startLocation;
528 }
529 set
530 {
531 this.startLocation = value;
532 }
533 } // StartLocation
534
535 public string LookAt
536 {
537 get
538 {
539 return this.lookAt;
540 }
541 set
542 {
543 this.lookAt = value;
544 }
545 }
546
547 public string SeedCapability
548 {
549 get
550 {
551 return this.seedCapability;
552 }
553 set
554 {
555 this.seedCapability = value;
556 }
557 } // SeedCapability
558
559 public string ErrorReason
560 {
561 get
562 {
563 return this.errorReason;
564 }
565 set
566 {
567 this.errorReason = value;
568 }
569 } // ErrorReason
570
571 public string ErrorMessage
572 {
573 get
574 {
575 return this.errorMessage;
576 }
577 set
578 {
579 this.errorMessage = value;
580 }
581 } // ErrorMessage
582
583 public ArrayList InventoryRoot
584 {
585 get
586 {
587 return this.inventoryRoot;
588 }
589 set
590 {
591 this.inventoryRoot = value;
592 }
593 }
594
595 public ArrayList InventorySkeleton
596 {
597 get
598 {
599 return this.agentInventory;
600 }
601 set
602 {
603 this.agentInventory = value;
604 }
605 }
606
607 public ArrayList InventoryLibrary
608 {
609 get
610 {
611 return this.inventoryLibrary;
612 }
613 set
614 {
615 this.inventoryLibrary = value;
616 }
617 }
618
619 public ArrayList InventoryLibraryOwner
620 {
621 get
622 {
623 return this.inventoryLibraryOwner;
624 }
625 set
626 {
627 this.inventoryLibraryOwner = value;
628 }
629 }
630
631 public string Home
632 {
633 get
634 {
635 return this.home;
636 }
637 set
638 {
639 this.home = value;
640 }
641 }
642
643 public string Message
644 {
645 get
646 {
647 return this.welcomeMessage;
648 }
649 set
650 {
651 this.welcomeMessage = value;
652 }
653 }
654 #endregion
655
656
657 public class UserInfo
658 {
659 public string firstname;
660 public string lastname;
661 public ulong homeregionhandle;
662 public LLVector3 homepos;
663 public LLVector3 homelookat;
664 }
665 }
666}
667
diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs
new file mode 100644
index 0000000..8e7cf80
--- /dev/null
+++ b/OpenSim/Framework/Communications/LoginService.cs
@@ -0,0 +1,287 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Reflection;
5using System.Security.Cryptography;
6using libsecondlife;
7using Nwc.XmlRpc;
8using OpenSim.Framework.Console;
9using OpenSim.Framework.Data;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Inventory;
12using OpenSim.Framework.Utilities;
13
14using OpenSim.Framework.Configuration;
15using InventoryFolder = OpenSim.Framework.Inventory.InventoryFolder;
16
17namespace OpenSim.Framework.UserManagement
18{
19 public class LoginService
20 {
21 protected string m_welcomeMessage = "Welcome to OpenSim";
22 protected UserManagerBase m_userManager = null;
23
24 public LoginService(UserManagerBase userManager, string welcomeMess)
25 {
26 m_userManager = userManager;
27 if (welcomeMess != "")
28 {
29 m_welcomeMessage = welcomeMess;
30 }
31 }
32
33 /// <summary>
34 /// Main user login function
35 /// </summary>
36 /// <param name="request">The XMLRPC request</param>
37 /// <returns>The response to send</returns>
38 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
39 {
40
41 System.Console.WriteLine("Attempting login now...");
42 XmlRpcResponse response = new XmlRpcResponse();
43 Hashtable requestData = (Hashtable)request.Params[0];
44
45 bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
46 bool GoodLogin = false;
47
48 UserProfileData userProfile;
49 LoginResponse logResponse = new LoginResponse();
50
51 if (GoodXML)
52 {
53 string firstname = (string)requestData["first"];
54 string lastname = (string)requestData["last"];
55 string passwd = (string)requestData["passwd"];
56
57 userProfile = GetTheUser(firstname, lastname);
58 if (userProfile == null)
59 return logResponse.CreateLoginFailedResponse();
60
61 GoodLogin = AuthenticateUser(userProfile, passwd);
62 }
63 else
64 {
65 return logResponse.CreateGridErrorResponse();
66 }
67
68 if (!GoodLogin)
69 {
70 return logResponse.CreateLoginFailedResponse();
71 }
72 else
73 {
74 // If we already have a session...
75 if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline)
76 {
77 // Reject the login
78 return logResponse.CreateAlreadyLoggedInResponse();
79 }
80 // Otherwise...
81 // Create a new agent session
82 CreateAgent(userProfile, request);
83
84 try
85 {
86 LLUUID agentID = userProfile.UUID;
87
88 // Inventory Library Section
89 InventoryData inventData = this.CreateInventoryData(agentID);
90 ArrayList AgentInventoryArray = inventData.InventoryArray;
91
92 Hashtable InventoryRootHash = new Hashtable();
93 InventoryRootHash["folder_id"] = inventData.RootFolderID.ToStringHyphenated();
94 ArrayList InventoryRoot = new ArrayList();
95 InventoryRoot.Add(InventoryRootHash);
96 userProfile.rootInventoryFolderID = inventData.RootFolderID;
97
98 // Circuit Code
99 uint circode = (uint)(Util.RandomClass.Next());
100
101 logResponse.Lastname = userProfile.surname;
102 logResponse.Firstname = userProfile.username;
103 logResponse.AgentID = agentID.ToStringHyphenated();
104 logResponse.SessionID = userProfile.currentAgent.sessionID.ToStringHyphenated();
105 logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToStringHyphenated();
106 logResponse.InventoryRoot = InventoryRoot;
107 logResponse.InventorySkeleton = AgentInventoryArray;
108 logResponse.InventoryLibrary = this.GetInventoryLibrary();
109 logResponse.InventoryLibraryOwner = this.GetLibraryOwner();
110 logResponse.CircuitCode = (Int32)circode;
111 //logResponse.RegionX = 0; //overwritten
112 //logResponse.RegionY = 0; //overwritten
113 logResponse.Home = "!!null temporary value {home}!!"; // Overwritten
114 //logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
115 //logResponse.SimAddress = "127.0.0.1"; //overwritten
116 //logResponse.SimPort = 0; //overwritten
117 logResponse.Message = this.GetMessage();
118
119 try
120 {
121 this.CustomiseResponse(logResponse, userProfile);
122 }
123 catch (Exception e)
124 {
125 System.Console.WriteLine(e.ToString());
126 return logResponse.CreateDeadRegionResponse();
127 //return logResponse.ToXmlRpcResponse();
128 }
129 CommitAgent(ref userProfile);
130 return logResponse.ToXmlRpcResponse();
131
132 }
133
134 catch (Exception E)
135 {
136 System.Console.WriteLine(E.ToString());
137 }
138 //}
139 }
140 return response;
141
142 }
143
144 /// <summary>
145 /// Customises the login response and fills in missing values.
146 /// </summary>
147 /// <param name="response">The existing response</param>
148 /// <param name="theUser">The user profile</param>
149 public virtual void CustomiseResponse(LoginResponse response, UserProfileData theUser)
150 {
151 }
152
153 /// <summary>
154 /// Saves a target agent to the database
155 /// </summary>
156 /// <param name="profile">The users profile</param>
157 /// <returns>Successful?</returns>
158 public bool CommitAgent(ref UserProfileData profile)
159 {
160 // Saves the agent to database
161 return true;
162 }
163
164
165 /// <summary>
166 /// Checks a user against it's password hash
167 /// </summary>
168 /// <param name="profile">The users profile</param>
169 /// <param name="password">The supplied password</param>
170 /// <returns>Authenticated?</returns>
171 public virtual bool AuthenticateUser(UserProfileData profile, string password)
172 {
173
174 MainLog.Instance.Verbose(
175 "Authenticating " + profile.username + " " + profile.surname);
176
177 password = password.Remove(0, 3); //remove $1$
178
179 string s = Util.Md5Hash(password + ":" + profile.passwordSalt);
180
181 return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase);
182 }
183
184 /// <summary>
185 ///
186 /// </summary>
187 /// <param name="profile"></param>
188 /// <param name="request"></param>
189 public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
190 {
191 this.m_userManager.CreateAgent(profile, request);
192 }
193
194 /// <summary>
195 ///
196 /// </summary>
197 /// <param name="firstname"></param>
198 /// <param name="lastname"></param>
199 /// <returns></returns>
200 public virtual UserProfileData GetTheUser(string firstname, string lastname)
201 {
202 return this.m_userManager.GetUserProfile(firstname, lastname);
203 }
204
205 /// <summary>
206 ///
207 /// </summary>
208 /// <returns></returns>
209 public virtual string GetMessage()
210 {
211 return m_welcomeMessage;
212 }
213
214 /// <summary>
215 ///
216 /// </summary>
217 /// <returns></returns>
218 protected virtual ArrayList GetInventoryLibrary()
219 {
220 //return new ArrayList();
221 Hashtable TempHash = new Hashtable();
222 TempHash["name"] = "OpenSim Library";
223 TempHash["parent_id"] = LLUUID.Zero.ToStringHyphenated();
224 TempHash["version"] = 1;
225 TempHash["type_default"] = -1;
226 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
227 ArrayList temp = new ArrayList();
228 temp.Add(TempHash);
229
230 TempHash = new Hashtable();
231 TempHash["name"] = "Texture Library";
232 TempHash["parent_id"] = "00000112-000f-0000-0000-000100bba000";
233 TempHash["version"] = 1;
234 TempHash["type_default"] = -1;
235 TempHash["folder_id"] = "00000112-000f-0000-0000-000100bba001";
236 temp.Add(TempHash);
237 return temp;
238 }
239
240 /// <summary>
241 ///
242 /// </summary>
243 /// <returns></returns>
244 protected virtual ArrayList GetLibraryOwner()
245 {
246 //for now create random inventory library owner
247 Hashtable TempHash = new Hashtable();
248 TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
249 ArrayList inventoryLibOwner = new ArrayList();
250 inventoryLibOwner.Add(TempHash);
251 return inventoryLibOwner;
252 }
253
254 protected virtual InventoryData CreateInventoryData(LLUUID userID)
255 {
256 AgentInventory userInventory = new AgentInventory();
257 userInventory.CreateRootFolder(userID, false);
258
259 ArrayList AgentInventoryArray = new ArrayList();
260 Hashtable TempHash;
261 foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values)
262 {
263 TempHash = new Hashtable();
264 TempHash["name"] = InvFolder.FolderName;
265 TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated();
266 TempHash["version"] = (Int32)InvFolder.Version;
267 TempHash["type_default"] = (Int32)InvFolder.DefaultType;
268 TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated();
269 AgentInventoryArray.Add(TempHash);
270 }
271
272 return new InventoryData(AgentInventoryArray, userInventory.InventoryRoot.FolderID);
273 }
274
275 public class InventoryData
276 {
277 public ArrayList InventoryArray = null;
278 public LLUUID RootFolderID = LLUUID.Zero;
279
280 public InventoryData(ArrayList invList, LLUUID rootID)
281 {
282 InventoryArray = invList;
283 RootFolderID = rootID;
284 }
285 }
286 }
287}
diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs
new file mode 100644
index 0000000..d1bbde1
--- /dev/null
+++ b/OpenSim/Framework/Communications/UserManagerBase.cs
@@ -0,0 +1,379 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.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
29using System;
30using System.Collections;
31using System.Collections.Generic;
32using System.Reflection;
33using System.Security.Cryptography;
34using libsecondlife;
35using Nwc.XmlRpc;
36using OpenSim.Framework.Communications;
37using OpenSim.Framework.Configuration;
38using OpenSim.Framework.Console;
39using OpenSim.Framework.Data;
40using OpenSim.Framework.Utilities;
41
42namespace OpenSim.Framework.UserManagement
43{
44 public abstract class UserManagerBase : IUserServices
45 {
46 public UserConfig _config;
47 Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>();
48
49 /// <summary>
50 /// Adds a new user server plugin - user servers will be requested in the order they were loaded.
51 /// </summary>
52 /// <param name="FileName">The filename to the user server plugin DLL</param>
53 public void AddPlugin(string FileName)
54 {
55 if (!String.IsNullOrEmpty(FileName))
56 {
57 MainLog.Instance.Verbose("Userstorage: Attempting to load " + FileName);
58 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
59
60 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 =
70 (IUserData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
71 AddPlugin(plug);
72 }
73 }
74 }
75 }
76 }
77
78 public void AddPlugin(IUserData plug)
79 {
80 plug.Initialise();
81 this._plugins.Add(plug.getName(), plug);
82 MainLog.Instance.Verbose( "Userstorage: Added IUserData Interface");
83 }
84
85 #region Get UserProfile
86 /// <summary>
87 /// Loads a user profile from a database by UUID
88 /// </summary>
89 /// <param name="uuid">The target UUID</param>
90 /// <returns>A user profile</returns>
91 public UserProfileData GetUserProfile(LLUUID uuid)
92 {
93 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
94 {
95 try
96 {
97 UserProfileData profile = plugin.Value.GetUserByUUID(uuid);
98 profile.currentAgent = getUserAgent(profile.UUID);
99 return profile;
100 }
101 catch (Exception e)
102 {
103 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
104 }
105 }
106
107 return null;
108 }
109
110
111 /// <summary>
112 /// Loads a user profile by name
113 /// </summary>
114 /// <param name="name">The target name</param>
115 /// <returns>A user profile</returns>
116 public UserProfileData GetUserProfile(string name)
117 {
118 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
119 {
120 try
121 {
122 UserProfileData profile = plugin.Value.GetUserByName(name);
123 profile.currentAgent = getUserAgent(profile.UUID);
124 return profile;
125 }
126 catch (Exception e)
127 {
128 System.Console.WriteLine("EEK!");
129 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
130 }
131 }
132
133 return null;
134 }
135
136 /// <summary>
137 /// Loads a user profile by name
138 /// </summary>
139 /// <param name="fname">First name</param>
140 /// <param name="lname">Last name</param>
141 /// <returns>A user profile</returns>
142 public UserProfileData GetUserProfile(string fname, string lname)
143 {
144 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
145 {
146 try
147 {
148 UserProfileData profile = plugin.Value.GetUserByName(fname,lname);
149
150 profile.currentAgent = getUserAgent(profile.UUID);
151
152 return profile;
153 }
154 catch (Exception e)
155 {
156 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
157 }
158 }
159
160 return null;
161 }
162
163 /// <summary>
164 /// Set's user profile from object
165 /// </summary>
166 /// <param name="fname">First name</param>
167 /// <param name="lname">Last name</param>
168 /// <returns>A user profile</returns>
169 public bool setUserProfile(UserProfileData data)
170 {
171 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
172 {
173 try {
174 plugin.Value.UpdateUserProfile(data);
175 return true;
176 } catch (Exception e) {
177 MainLog.Instance.Verbose( "Unable to set user via " + plugin.Key + "(" + e.ToString() + ")");
178 }
179 }
180
181 return false;
182 }
183
184 #endregion
185
186 #region Get UserAgent
187 /// <summary>
188 /// Loads a user agent by uuid (not called directly)
189 /// </summary>
190 /// <param name="uuid">The agents UUID</param>
191 /// <returns>Agent profiles</returns>
192 public UserAgentData getUserAgent(LLUUID uuid)
193 {
194 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
195 {
196 try
197 {
198 return plugin.Value.GetAgentByUUID(uuid);
199 }
200 catch (Exception e)
201 {
202 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
203 }
204 }
205
206 return null;
207 }
208
209 /// <summary>
210 /// Loads a user agent by name (not called directly)
211 /// </summary>
212 /// <param name="name">The agents name</param>
213 /// <returns>A user agent</returns>
214 public UserAgentData getUserAgent(string name)
215 {
216 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
217 {
218 try
219 {
220 return plugin.Value.GetAgentByName(name);
221 }
222 catch (Exception e)
223 {
224 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
225 }
226 }
227
228 return null;
229 }
230
231 // TODO: document
232 public void clearUserAgent(LLUUID agentID)
233 {
234 UserProfileData profile = GetUserProfile(agentID);
235 profile.currentAgent = null;
236 setUserProfile(profile);
237 }
238
239
240 /// <summary>
241 /// Loads a user agent by name (not called directly)
242 /// </summary>
243 /// <param name="fname">The agents firstname</param>
244 /// <param name="lname">The agents lastname</param>
245 /// <returns>A user agent</returns>
246 public UserAgentData getUserAgent(string fname, string lname)
247 {
248 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
249 {
250 try
251 {
252 return plugin.Value.GetAgentByName(fname,lname);
253 }
254 catch (Exception e)
255 {
256 MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
257 }
258 }
259
260 return null;
261 }
262
263 #endregion
264
265 #region CreateAgent
266 /// <summary>
267 /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB
268 /// </summary>
269 /// <param name="profile">The users profile</param>
270 /// <param name="request">The users loginrequest</param>
271 public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
272 {
273 Hashtable requestData = (Hashtable)request.Params[0];
274
275 UserAgentData agent = new UserAgentData();
276
277 // User connection
278 agent.agentOnline = true;
279
280 // Generate sessions
281 RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
282 byte[] randDataS = new byte[16];
283 byte[] randDataSS = new byte[16];
284 rand.GetBytes(randDataS);
285 rand.GetBytes(randDataSS);
286
287 agent.secureSessionID = new LLUUID(randDataSS, 0);
288 agent.sessionID = new LLUUID(randDataS, 0);
289
290 // Profile UUID
291 agent.UUID = profile.UUID;
292
293 // Current position (from Home)
294 agent.currentHandle = profile.homeRegion;
295 agent.currentPos = profile.homeLocation;
296
297 // If user specified additional start, use that
298 if (requestData.ContainsKey("start"))
299 {
300 string startLoc = ((string)requestData["start"]).Trim();
301 if (!(startLoc == "last" || startLoc == "home"))
302 {
303 // Format: uri:Ahern&162&213&34
304 try
305 {
306 string[] parts = startLoc.Remove(0, 4).Split('&');
307 string region = parts[0];
308
309 ////////////////////////////////////////////////////
310 //SimProfile SimInfo = new SimProfile();
311 //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey);
312 }
313 catch (Exception)
314 {
315
316 }
317 }
318 }
319
320 // What time did the user login?
321 agent.loginTime = Util.UnixTimeSinceEpoch();
322 agent.logoutTime = 0;
323
324 // Current location
325 agent.regionID = new LLUUID(); // Fill in later
326 agent.currentRegion = new LLUUID(); // Fill in later
327
328 profile.currentAgent = agent;
329 }
330
331 /// <summary>
332 /// Saves a target agent to the database
333 /// </summary>
334 /// <param name="profile">The users profile</param>
335 /// <returns>Successful?</returns>
336 public bool CommitAgent(ref UserProfileData profile)
337 {
338 // Saves the agent to database
339 return true;
340 }
341
342 #endregion
343
344 /// <summary>
345 ///
346 /// </summary>
347 /// <param name="user"></param>
348 public void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY)
349 {
350 UserProfileData user = new UserProfileData();
351 user.homeLocation = new LLVector3(128, 128, 100);
352 user.UUID = LLUUID.Random();
353 user.username = firstName;
354 user.surname = lastName;
355 user.passwordHash = pass;
356 user.passwordSalt = "";
357 user.created = Util.UnixTimeSinceEpoch();
358 user.homeLookAt = new LLVector3(100, 100, 100);
359 user.homeRegionX = regX;
360 user.homeRegionY = regY;
361
362 foreach (KeyValuePair<string, IUserData> plugin in _plugins)
363 {
364 try
365 {
366 plugin.Value.AddNewUserProfile(user);
367
368 }
369 catch (Exception e)
370 {
371 MainLog.Instance.Verbose("Unable to add user via " + plugin.Key + "(" + e.ToString() + ")");
372 }
373 }
374 }
375
376 public abstract UserProfileData SetupMasterUser(string firstName, string lastName);
377 public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password);
378 }
379}