aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Framework
diff options
context:
space:
mode:
authorMelanie2012-03-18 20:44:56 +0000
committerMelanie2012-03-18 20:44:56 +0000
commitc7e302864a2eef7f9587ed22286c96a6074ac5b3 (patch)
tree8f0df2f66811309fd790966770434fa3ff68bfdf /OpenSim/Region/CoreModules/Framework
parentMerge branch 'ubitwork' (diff)
parentAmend to previous commit: normalize strings ToLower. (diff)
downloadopensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.zip
opensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.tar.gz
opensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.tar.bz2
opensim-SC_OLD-c7e302864a2eef7f9587ed22286c96a6074ac5b3.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs OpenSim/Region/Framework/Scenes/Scene.cs
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework')
-rw-r--r--OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs123
-rw-r--r--OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs150
2 files changed, 240 insertions, 33 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs
new file mode 100644
index 0000000..8077a7a
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Framework/UserManagement/HGUserManagementModule.cs
@@ -0,0 +1,123 @@
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 OpenSimulator 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 */
27using System;
28using System.Collections.Generic;
29using System.IO;
30using System.Reflection;
31
32using OpenSim.Framework;
33using OpenSim.Framework.Console;
34using OpenSim.Region.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Services.Interfaces;
38using OpenSim.Services.Connectors.Hypergrid;
39
40using OpenMetaverse;
41using OpenMetaverse.Packets;
42using log4net;
43using Nini.Config;
44
45namespace OpenSim.Region.CoreModules.Framework.UserManagement
46{
47 public class HGUserManagementModule : UserManagementModule, ISharedRegionModule, IUserManagement
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51
52 #region ISharedRegionModule
53
54 public new void Initialise(IConfigSource config)
55 {
56 string umanmod = config.Configs["Modules"].GetString("UserManagementModule", base.Name);
57 if (umanmod == Name)
58 {
59 m_Enabled = true;
60 RegisterConsoleCmds();
61 m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name);
62 }
63 }
64
65 public override string Name
66 {
67 get { return "HGUserManagementModule"; }
68 }
69
70 #endregion ISharedRegionModule
71
72 protected override void AddAdditionalUsers(UUID avatarID, string query, List<UserData> users)
73 {
74 string[] words = query.Split(new char[] { ' ' });
75
76 for (int i = 0; i < words.Length; i++)
77 {
78 if (words[i].Length < 3)
79 {
80 if (i != words.Length - 1)
81 Array.Copy(words, i + 1, words, i, words.Length - i - 1);
82 Array.Resize(ref words, words.Length - 1);
83 }
84 }
85
86 if (words.Length == 0 || words.Length > 2)
87 return;
88
89 if (words.Length == 2) // First.Last @foo.com, maybe?
90 {
91 bool found = false;
92 foreach (UserData d in m_UserCache.Values)
93 {
94 if (d.LastName.StartsWith("@") &&
95 (d.FirstName.ToLower().Equals(words[0].ToLower()) ||
96 d.LastName.ToLower().Equals(words[1].ToLower())))
97 {
98 users.Add(d);
99 found = true;
100 break;
101 }
102 }
103 if (!found) // This is it! Let's ask the other world
104 {
105 // TODO
106 //UserAgentServiceConnector uasConn = new UserAgentServiceConnector(words[0]);
107 //uasConn.GetUserInfo(...);
108 }
109 }
110 else
111 {
112 foreach (UserData d in m_UserCache.Values)
113 {
114 if (d.LastName.StartsWith("@") &&
115 (d.FirstName.ToLower().StartsWith(query.ToLower()) ||
116 d.LastName.ToLower().StartsWith(query.ToLower())))
117 users.Add(d);
118 }
119 }
120 }
121
122 }
123} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
index 554af14..23ef0fc 100644
--- a/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/UserManagement/UserManagementModule.cs
@@ -38,12 +38,13 @@ using OpenSim.Services.Interfaces;
38using OpenSim.Services.Connectors.Hypergrid; 38using OpenSim.Services.Connectors.Hypergrid;
39 39
40using OpenMetaverse; 40using OpenMetaverse;
41using OpenMetaverse.Packets;
41using log4net; 42using log4net;
42using Nini.Config; 43using Nini.Config;
43 44
44namespace OpenSim.Region.CoreModules.Framework.UserManagement 45namespace OpenSim.Region.CoreModules.Framework.UserManagement
45{ 46{
46 class UserData 47 public class UserData
47 { 48 {
48 public UUID Id { get; set; } 49 public UUID Id { get; set; }
49 public string FirstName { get; set; } 50 public string FirstName { get; set; }
@@ -56,36 +57,23 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
56 { 57 {
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 58 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 59
59 private List<Scene> m_Scenes = new List<Scene>(); 60 protected bool m_Enabled;
61 protected List<Scene> m_Scenes = new List<Scene>();
60 62
61 // The cache 63 // The cache
62 Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>(); 64 protected Dictionary<UUID, UserData> m_UserCache = new Dictionary<UUID, UserData>();
63 65
64 #region ISharedRegionModule 66 #region ISharedRegionModule
65 67
66 public void Initialise(IConfigSource config) 68 public void Initialise(IConfigSource config)
67 { 69 {
68 //m_Enabled = config.Configs["Modules"].GetBoolean("LibraryModule", m_Enabled); 70 string umanmod = config.Configs["Modules"].GetString("UserManagementModule", Name);
69 //if (m_Enabled) 71 if (umanmod == Name)
70 //{ 72 {
71 // IConfig libConfig = config.Configs["LibraryService"]; 73 m_Enabled = true;
72 // if (libConfig != null) 74 RegisterConsoleCmds();
73 // { 75 m_log.DebugFormat("[USER MANAGEMENT MODULE]: {0} is enabled", Name);
74 // string dllName = libConfig.GetString("LocalServiceModule", string.Empty); 76 }
75 // m_log.Debug("[LIBRARY MODULE]: Library service dll is " + dllName);
76 // if (dllName != string.Empty)
77 // {
78 // Object[] args = new Object[] { config };
79 // m_Library = ServerUtils.LoadPlugin<ILibraryService>(dllName, args);
80 // }
81 // }
82 //}
83 MainConsole.Instance.Commands.AddCommand("Users", true,
84 "show names",
85 "show names",
86 "Show the bindings between user UUIDs and user names",
87 String.Empty,
88 HandleShowUsers);
89 } 77 }
90 78
91 public bool IsSharedModule 79 public bool IsSharedModule
@@ -93,9 +81,9 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
93 get { return true; } 81 get { return true; }
94 } 82 }
95 83
96 public string Name 84 public virtual string Name
97 { 85 {
98 get { return "UserManagement Module"; } 86 get { return "BasicUserManagementModule"; }
99 } 87 }
100 88
101 public Type ReplaceableInterface 89 public Type ReplaceableInterface
@@ -105,17 +93,23 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
105 93
106 public void AddRegion(Scene scene) 94 public void AddRegion(Scene scene)
107 { 95 {
108 m_Scenes.Add(scene); 96 if (m_Enabled)
97 {
98 m_Scenes.Add(scene);
109 99
110 scene.RegisterModuleInterface<IUserManagement>(this); 100 scene.RegisterModuleInterface<IUserManagement>(this);
111 scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient); 101 scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient);
112 scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded); 102 scene.EventManager.OnPrimsLoaded += new EventManager.PrimsLoaded(EventManager_OnPrimsLoaded);
103 }
113 } 104 }
114 105
115 public void RemoveRegion(Scene scene) 106 public void RemoveRegion(Scene scene)
116 { 107 {
117 scene.UnregisterModuleInterface<IUserManagement>(this); 108 if (m_Enabled)
118 m_Scenes.Remove(scene); 109 {
110 scene.UnregisterModuleInterface<IUserManagement>(this);
111 m_Scenes.Remove(scene);
112 }
119 } 113 }
120 114
121 public void RegionLoaded(Scene s) 115 public void RegionLoaded(Scene s)
@@ -149,7 +143,15 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
149 143
150 void EventManager_OnNewClient(IClientAPI client) 144 void EventManager_OnNewClient(IClientAPI client)
151 { 145 {
146 client.OnConnectionClosed += new Action<IClientAPI>(HandleConnectionClosed);
152 client.OnNameFromUUIDRequest += new UUIDNameRequest(HandleUUIDNameRequest); 147 client.OnNameFromUUIDRequest += new UUIDNameRequest(HandleUUIDNameRequest);
148 client.OnAvatarPickerRequest += new AvatarPickerRequest(HandleAvatarPickerRequest);
149 }
150
151 void HandleConnectionClosed(IClientAPI client)
152 {
153 client.OnNameFromUUIDRequest -= new UUIDNameRequest(HandleUUIDNameRequest);
154 client.OnAvatarPickerRequest -= new AvatarPickerRequest(HandleAvatarPickerRequest);
153 } 155 }
154 156
155 void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client) 157 void HandleUUIDNameRequest(UUID uuid, IClientAPI remote_client)
@@ -170,6 +172,78 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
170 } 172 }
171 } 173 }
172 174
175 public void HandleAvatarPickerRequest(IClientAPI client, UUID avatarID, UUID RequestID, string query)
176 {
177 //EventManager.TriggerAvatarPickerRequest();
178
179 m_log.DebugFormat("[USER MANAGEMENT MODULE]: HandleAvatarPickerRequest for {0}", query);
180
181 List<UserAccount> accs = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, query);
182
183 List<UserData> users = new List<UserData>();
184 if (accs != null)
185 {
186 m_log.DebugFormat("[USER MANAGEMENT MODULE]: Found {0} users", accs.Count);
187 foreach (UserAccount acc in accs)
188 {
189 UserData ud = new UserData();
190 ud.FirstName = acc.FirstName;
191 ud.LastName = acc.LastName;
192 ud.Id = acc.PrincipalID;
193 users.Add(ud);
194 }
195 }
196
197 AddAdditionalUsers(avatarID, query, users);
198
199 AvatarPickerReplyPacket replyPacket = (AvatarPickerReplyPacket)PacketPool.Instance.GetPacket(PacketType.AvatarPickerReply);
200 // TODO: don't create new blocks if recycling an old packet
201
202 AvatarPickerReplyPacket.DataBlock[] searchData =
203 new AvatarPickerReplyPacket.DataBlock[users.Count];
204 AvatarPickerReplyPacket.AgentDataBlock agentData = new AvatarPickerReplyPacket.AgentDataBlock();
205
206 agentData.AgentID = avatarID;
207 agentData.QueryID = RequestID;
208 replyPacket.AgentData = agentData;
209 //byte[] bytes = new byte[AvatarResponses.Count*32];
210
211 int i = 0;
212 foreach (UserData item in users)
213 {
214 UUID translatedIDtem = item.Id;
215 searchData[i] = new AvatarPickerReplyPacket.DataBlock();
216 searchData[i].AvatarID = translatedIDtem;
217 searchData[i].FirstName = Utils.StringToBytes((string)item.FirstName);
218 searchData[i].LastName = Utils.StringToBytes((string)item.LastName);
219 i++;
220 }
221 if (users.Count == 0)
222 {
223 searchData = new AvatarPickerReplyPacket.DataBlock[0];
224 }
225 replyPacket.Data = searchData;
226
227 AvatarPickerReplyAgentDataArgs agent_data = new AvatarPickerReplyAgentDataArgs();
228 agent_data.AgentID = replyPacket.AgentData.AgentID;
229 agent_data.QueryID = replyPacket.AgentData.QueryID;
230
231 List<AvatarPickerReplyDataArgs> data_args = new List<AvatarPickerReplyDataArgs>();
232 for (i = 0; i < replyPacket.Data.Length; i++)
233 {
234 AvatarPickerReplyDataArgs data_arg = new AvatarPickerReplyDataArgs();
235 data_arg.AvatarID = replyPacket.Data[i].AvatarID;
236 data_arg.FirstName = replyPacket.Data[i].FirstName;
237 data_arg.LastName = replyPacket.Data[i].LastName;
238 data_args.Add(data_arg);
239 }
240 client.SendAvatarPickerReply(agent_data, data_args);
241 }
242
243 protected virtual void AddAdditionalUsers(UUID avatarID, string query, List<UserData> users)
244 {
245 }
246
173 #endregion Event Handlers 247 #endregion Event Handlers
174 248
175 private void CacheCreators(SceneObjectGroup sog) 249 private void CacheCreators(SceneObjectGroup sog)
@@ -425,13 +499,23 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
425 499
426 #endregion IUserManagement 500 #endregion IUserManagement
427 501
502 protected void RegisterConsoleCmds()
503 {
504 MainConsole.Instance.Commands.AddCommand("Users", true,
505 "show names",
506 "show names",
507 "Show the bindings between user UUIDs and user names",
508 String.Empty,
509 HandleShowUsers);
510 }
511
428 private void HandleShowUsers(string module, string[] cmd) 512 private void HandleShowUsers(string module, string[] cmd)
429 { 513 {
430 lock (m_UserCache) 514 lock (m_UserCache)
431 { 515 {
432 if (m_UserCache.Count == 0) 516 if (m_UserCache.Count == 0)
433 { 517 {
434 MainConsole.Instance.Output("No users not found"); 518 MainConsole.Instance.Output("No users found");
435 return; 519 return;
436 } 520 }
437 521