clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Linq; |
||
31 | using System.Reflection; |
||
32 | using System.Text; |
||
33 | |||
34 | using OpenSim.Framework; |
||
35 | using OpenSim.Framework.Monitoring; |
||
36 | using OpenSim.Framework.Servers; |
||
37 | using OpenSim.Region.Framework.Scenes; |
||
38 | using OpenSim.Region.Framework.Interfaces; |
||
39 | using OpenSim.Services.Interfaces; |
||
40 | |||
41 | using OpenMetaverse; |
||
42 | using Mono.Addins; |
||
43 | using log4net; |
||
44 | using Nini.Config; |
||
45 | |||
46 | namespace OpenSim.Groups |
||
47 | { |
||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceHGConnectorModule")] |
||
49 | public class GroupsServiceHGConnectorModule : ISharedRegionModule, IGroupsServicesConnector |
||
50 | { |
||
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
52 | |||
53 | private bool m_Enabled = false; |
||
54 | private IGroupsServicesConnector m_LocalGroupsConnector; |
||
55 | private string m_LocalGroupsServiceLocation; |
||
56 | private IUserManagement m_UserManagement; |
||
57 | private IOfflineIMService m_OfflineIM; |
||
58 | private IMessageTransferModule m_Messaging; |
||
59 | private List<Scene> m_Scenes; |
||
60 | private ForeignImporter m_ForeignImporter; |
||
61 | private string m_ServiceLocation; |
||
62 | private IConfigSource m_Config; |
||
63 | |||
64 | private Dictionary<string, GroupsServiceHGConnector> m_NetworkConnectors = new Dictionary<string, GroupsServiceHGConnector>(); |
||
65 | private RemoteConnectorCacheWrapper m_CacheWrapper; // for caching info of external group services |
||
66 | |||
67 | #region ISharedRegionModule |
||
68 | |||
69 | public void Initialise(IConfigSource config) |
||
70 | { |
||
71 | IConfig groupsConfig = config.Configs["Groups"]; |
||
72 | if (groupsConfig == null) |
||
73 | return; |
||
74 | |||
75 | if ((groupsConfig.GetBoolean("Enabled", false) == false) |
||
76 | || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name)) |
||
77 | { |
||
78 | return; |
||
79 | } |
||
80 | |||
81 | m_Config = config; |
||
82 | m_ServiceLocation = groupsConfig.GetString("LocalService", "local"); // local or remote |
||
83 | m_LocalGroupsServiceLocation = groupsConfig.GetString("GroupsExternalURI", "http://127.0.0.1"); |
||
84 | m_Scenes = new List<Scene>(); |
||
85 | |||
86 | m_Enabled = true; |
||
87 | |||
88 | m_log.DebugFormat("[Groups]: Initializing {0} with LocalService {1}", this.Name, m_ServiceLocation); |
||
89 | } |
||
90 | |||
91 | public string Name |
||
92 | { |
||
93 | get { return "Groups HG Service Connector"; } |
||
94 | } |
||
95 | |||
96 | public Type ReplaceableInterface |
||
97 | { |
||
98 | get { return null; } |
||
99 | } |
||
100 | |||
101 | public void AddRegion(Scene scene) |
||
102 | { |
||
103 | if (!m_Enabled) |
||
104 | return; |
||
105 | |||
106 | m_log.DebugFormat("[Groups]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName); |
||
107 | scene.RegisterModuleInterface<IGroupsServicesConnector>(this); |
||
108 | m_Scenes.Add(scene); |
||
109 | |||
110 | scene.EventManager.OnNewClient += OnNewClient; |
||
111 | } |
||
112 | |||
113 | public void RemoveRegion(Scene scene) |
||
114 | { |
||
115 | if (!m_Enabled) |
||
116 | return; |
||
117 | |||
118 | scene.UnregisterModuleInterface<IGroupsServicesConnector>(this); |
||
119 | m_Scenes.Remove(scene); |
||
120 | } |
||
121 | |||
122 | public void RegionLoaded(Scene scene) |
||
123 | { |
||
124 | if (!m_Enabled) |
||
125 | return; |
||
126 | |||
127 | if (m_UserManagement == null) |
||
128 | { |
||
129 | m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); |
||
130 | m_OfflineIM = scene.RequestModuleInterface<IOfflineIMService>(); |
||
131 | m_Messaging = scene.RequestModuleInterface<IMessageTransferModule>(); |
||
132 | m_ForeignImporter = new ForeignImporter(m_UserManagement); |
||
133 | |||
134 | if (m_ServiceLocation.Equals("local")) |
||
135 | { |
||
136 | m_LocalGroupsConnector = new GroupsServiceLocalConnectorModule(m_Config, m_UserManagement); |
||
137 | // Also, if local, create the endpoint for the HGGroupsService |
||
138 | new HGGroupsServiceRobustConnector(m_Config, MainServer.Instance, string.Empty, |
||
139 | scene.RequestModuleInterface<IOfflineIMService>(), scene.RequestModuleInterface<IUserAccountService>()); |
||
140 | |||
141 | } |
||
142 | else |
||
143 | m_LocalGroupsConnector = new GroupsServiceRemoteConnectorModule(m_Config, m_UserManagement); |
||
144 | |||
145 | m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement); |
||
146 | } |
||
147 | |||
148 | } |
||
149 | |||
150 | public void PostInitialise() |
||
151 | { |
||
152 | } |
||
153 | |||
154 | public void Close() |
||
155 | { |
||
156 | } |
||
157 | |||
158 | #endregion |
||
159 | |||
160 | private void OnNewClient(IClientAPI client) |
||
161 | { |
||
162 | client.OnCompleteMovementToRegion += OnCompleteMovementToRegion; |
||
163 | } |
||
164 | |||
165 | void OnCompleteMovementToRegion(IClientAPI client, bool arg2) |
||
166 | { |
||
167 | object sp = null; |
||
168 | if (client.Scene.TryGetScenePresence(client.AgentId, out sp)) |
||
169 | { |
||
170 | if (sp is ScenePresence && ((ScenePresence)sp).PresenceType != PresenceType.Npc) |
||
171 | { |
||
172 | AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId); |
||
173 | if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0 && |
||
174 | m_OfflineIM != null && m_Messaging != null) |
||
175 | { |
||
176 | List<GridInstantMessage> ims = m_OfflineIM.GetMessages(aCircuit.AgentID); |
||
177 | if (ims != null && ims.Count > 0) |
||
178 | foreach (GridInstantMessage im in ims) |
||
179 | m_Messaging.SendInstantMessage(im, delegate(bool success) { }); |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | } |
||
184 | |||
185 | #region IGroupsServicesConnector |
||
186 | |||
187 | public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, |
||
188 | bool allowPublish, bool maturePublish, UUID founderID, out string reason) |
||
189 | { |
||
190 | reason = string.Empty; |
||
191 | if (m_UserManagement.IsLocalGridUser(RequestingAgentID)) |
||
192 | return m_LocalGroupsConnector.CreateGroup(RequestingAgentID, name, charter, showInList, insigniaID, |
||
193 | membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out reason); |
||
194 | else |
||
195 | { |
||
196 | reason = "Only local grid users are allowed to create a new group"; |
||
197 | return UUID.Zero; |
||
198 | } |
||
199 | } |
||
200 | |||
201 | public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, |
||
202 | bool openEnrollment, bool allowPublish, bool maturePublish, out string reason) |
||
203 | { |
||
204 | reason = string.Empty; |
||
205 | string url = string.Empty; |
||
206 | string name = string.Empty; |
||
207 | if (IsLocal(groupID, out url, out name)) |
||
208 | return m_LocalGroupsConnector.UpdateGroup(AgentUUI(RequestingAgentID), groupID, charter, showInList, insigniaID, membershipFee, |
||
209 | openEnrollment, allowPublish, maturePublish, out reason); |
||
210 | else |
||
211 | { |
||
212 | reason = "Changes to remote group not allowed. Please go to the group's original world."; |
||
213 | return false; |
||
214 | } |
||
215 | } |
||
216 | |||
217 | public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName) |
||
218 | { |
||
219 | string url = string.Empty; |
||
220 | string name = string.Empty; |
||
221 | if (IsLocal(GroupID, out url, out name)) |
||
222 | return m_LocalGroupsConnector.GetGroupRecord(AgentUUI(RequestingAgentID), GroupID, GroupName); |
||
223 | else if (url != string.Empty) |
||
224 | { |
||
225 | ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID); |
||
226 | string accessToken = string.Empty; |
||
227 | if (membership != null) |
||
228 | accessToken = membership.AccessToken; |
||
229 | else |
||
230 | return null; |
||
231 | |||
232 | GroupsServiceHGConnector c = GetConnector(url); |
||
233 | if (c != null) |
||
234 | { |
||
235 | ExtendedGroupRecord grec = m_CacheWrapper.GetGroupRecord(RequestingAgentID, GroupID, GroupName, delegate |
||
236 | { |
||
237 | return c.GetGroupRecord(AgentUUIForOutside(RequestingAgentID), GroupID, GroupName, accessToken); |
||
238 | }); |
||
239 | |||
240 | if (grec != null) |
||
241 | ImportForeigner(grec.FounderUUI); |
||
242 | return grec; |
||
243 | } |
||
244 | } |
||
245 | |||
246 | return null; |
||
247 | } |
||
248 | |||
249 | public List<DirGroupsReplyData> FindGroups(string RequestingAgentID, string search) |
||
250 | { |
||
251 | return m_LocalGroupsConnector.FindGroups(AgentUUI(RequestingAgentID), search); |
||
252 | } |
||
253 | |||
254 | public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID) |
||
255 | { |
||
256 | string url = string.Empty, gname = string.Empty; |
||
257 | if (IsLocal(GroupID, out url, out gname)) |
||
258 | { |
||
259 | string agentID = AgentUUI(RequestingAgentID); |
||
260 | return m_LocalGroupsConnector.GetGroupMembers(agentID, GroupID); |
||
261 | } |
||
262 | else if (!string.IsNullOrEmpty(url)) |
||
263 | { |
||
264 | ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, GroupID); |
||
265 | string accessToken = string.Empty; |
||
266 | if (membership != null) |
||
267 | accessToken = membership.AccessToken; |
||
268 | else |
||
269 | return null; |
||
270 | |||
271 | GroupsServiceHGConnector c = GetConnector(url); |
||
272 | if (c != null) |
||
273 | { |
||
274 | return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate |
||
275 | { |
||
276 | return c.GetGroupMembers(AgentUUIForOutside(RequestingAgentID), GroupID, accessToken); |
||
277 | }); |
||
278 | |||
279 | } |
||
280 | } |
||
281 | return new List<GroupMembersData>(); |
||
282 | } |
||
283 | |||
284 | public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason) |
||
285 | { |
||
286 | reason = string.Empty; |
||
287 | string url = string.Empty, gname = string.Empty; |
||
288 | |||
289 | if (IsLocal(groupID, out url, out gname)) |
||
290 | return m_LocalGroupsConnector.AddGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers, out reason); |
||
291 | else |
||
292 | { |
||
293 | reason = "Operation not allowed outside this group's origin world."; |
||
294 | return false; |
||
295 | } |
||
296 | } |
||
297 | |||
298 | public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers) |
||
299 | { |
||
300 | string url = string.Empty, gname = string.Empty; |
||
301 | |||
302 | if (IsLocal(groupID, out url, out gname)) |
||
303 | return m_LocalGroupsConnector.UpdateGroupRole(AgentUUI(RequestingAgentID), groupID, roleID, name, description, title, powers); |
||
304 | else |
||
305 | { |
||
306 | return false; |
||
307 | } |
||
308 | |||
309 | } |
||
310 | |||
311 | public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID) |
||
312 | { |
||
313 | string url = string.Empty, gname = string.Empty; |
||
314 | |||
315 | if (IsLocal(groupID, out url, out gname)) |
||
316 | m_LocalGroupsConnector.RemoveGroupRole(AgentUUI(RequestingAgentID), groupID, roleID); |
||
317 | else |
||
318 | { |
||
319 | return; |
||
320 | } |
||
321 | } |
||
322 | |||
323 | public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID groupID) |
||
324 | { |
||
325 | string url = string.Empty, gname = string.Empty; |
||
326 | |||
327 | if (IsLocal(groupID, out url, out gname)) |
||
328 | return m_LocalGroupsConnector.GetGroupRoles(AgentUUI(RequestingAgentID), groupID); |
||
329 | else if (!string.IsNullOrEmpty(url)) |
||
330 | { |
||
331 | ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID); |
||
332 | string accessToken = string.Empty; |
||
333 | if (membership != null) |
||
334 | accessToken = membership.AccessToken; |
||
335 | else |
||
336 | return null; |
||
337 | |||
338 | GroupsServiceHGConnector c = GetConnector(url); |
||
339 | if (c != null) |
||
340 | { |
||
341 | return m_CacheWrapper.GetGroupRoles(RequestingAgentID, groupID, delegate |
||
342 | { |
||
343 | return c.GetGroupRoles(AgentUUIForOutside(RequestingAgentID), groupID, accessToken); |
||
344 | }); |
||
345 | |||
346 | } |
||
347 | } |
||
348 | |||
349 | return new List<GroupRolesData>(); |
||
350 | } |
||
351 | |||
352 | public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID groupID) |
||
353 | { |
||
354 | string url = string.Empty, gname = string.Empty; |
||
355 | |||
356 | if (IsLocal(groupID, out url, out gname)) |
||
357 | return m_LocalGroupsConnector.GetGroupRoleMembers(AgentUUI(RequestingAgentID), groupID); |
||
358 | else if (!string.IsNullOrEmpty(url)) |
||
359 | { |
||
360 | ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(RequestingAgentID, RequestingAgentID, groupID); |
||
361 | string accessToken = string.Empty; |
||
362 | if (membership != null) |
||
363 | accessToken = membership.AccessToken; |
||
364 | else |
||
365 | return null; |
||
366 | |||
367 | GroupsServiceHGConnector c = GetConnector(url); |
||
368 | if (c != null) |
||
369 | { |
||
370 | return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, groupID, delegate |
||
371 | { |
||
372 | return c.GetGroupRoleMembers(AgentUUIForOutside(RequestingAgentID), groupID, accessToken); |
||
373 | }); |
||
374 | |||
375 | } |
||
376 | } |
||
377 | |||
378 | return new List<GroupRoleMembersData>(); |
||
379 | } |
||
380 | |||
381 | public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason) |
||
382 | { |
||
383 | string url = string.Empty; |
||
384 | string name = string.Empty; |
||
385 | reason = string.Empty; |
||
386 | |||
387 | UUID uid = new UUID(AgentID); |
||
388 | if (IsLocal(GroupID, out url, out name)) |
||
389 | { |
||
390 | if (m_UserManagement.IsLocalGridUser(uid)) // local user |
||
391 | { |
||
392 | // normal case: local group, local user |
||
393 | return m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason); |
||
394 | } |
||
395 | else // local group, foreign user |
||
396 | { |
||
397 | // the user is accepting the invitation, or joining, where the group resides |
||
398 | token = UUID.Random().ToString(); |
||
399 | bool success = m_LocalGroupsConnector.AddAgentToGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID, token, out reason); |
||
400 | |||
401 | if (success) |
||
402 | { |
||
403 | // Here we always return true. The user has been added to the local group, |
||
404 | // independent of whether the remote operation succeeds or not |
||
405 | url = m_UserManagement.GetUserServerURL(uid, "GroupsServerURI"); |
||
406 | if (url == string.Empty) |
||
407 | { |
||
408 | reason = "You don't have an accessible groups server in your home world. You membership to this group in only within this grid."; |
||
409 | return true; |
||
410 | } |
||
411 | |||
412 | GroupsServiceHGConnector c = GetConnector(url); |
||
413 | if (c != null) |
||
414 | c.CreateProxy(AgentUUI(RequestingAgentID), AgentID, token, GroupID, m_LocalGroupsServiceLocation, name, out reason); |
||
415 | return true; |
||
416 | } |
||
417 | return false; |
||
418 | } |
||
419 | } |
||
420 | else if (m_UserManagement.IsLocalGridUser(uid)) // local user |
||
421 | { |
||
422 | // foreign group, local user. She's been added already by the HG service. |
||
423 | // Let's just check |
||
424 | if (m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID) != null) |
||
425 | return true; |
||
426 | } |
||
427 | |||
428 | reason = "Operation not allowed outside this group's origin world"; |
||
429 | return false; |
||
430 | } |
||
431 | |||
432 | |||
433 | public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID) |
||
434 | { |
||
435 | string url = string.Empty, name = string.Empty; |
||
436 | if (!IsLocal(GroupID, out url, out name) && url != string.Empty) |
||
437 | { |
||
438 | ExtendedGroupMembershipData membership = m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID); |
||
439 | if (membership != null) |
||
440 | { |
||
441 | GroupsServiceHGConnector c = GetConnector(url); |
||
442 | if (c != null) |
||
443 | c.RemoveAgentFromGroup(AgentUUIForOutside(AgentID), GroupID, membership.AccessToken); |
||
444 | } |
||
445 | } |
||
446 | |||
447 | // remove from local service |
||
448 | m_LocalGroupsConnector.RemoveAgentFromGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID); |
||
449 | } |
||
450 | |||
451 | public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID) |
||
452 | { |
||
453 | string url = string.Empty, gname = string.Empty; |
||
454 | |||
455 | if (IsLocal(groupID, out url, out gname)) |
||
456 | return m_LocalGroupsConnector.AddAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID, groupID, roleID, AgentUUI(agentID)); |
||
457 | else |
||
458 | return false; |
||
459 | } |
||
460 | |||
461 | public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID) |
||
462 | { |
||
463 | return m_LocalGroupsConnector.GetAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID); ; |
||
464 | } |
||
465 | |||
466 | public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID) |
||
467 | { |
||
468 | m_LocalGroupsConnector.RemoveAgentToGroupInvite(AgentUUI(RequestingAgentID), inviteID); |
||
469 | } |
||
470 | |||
471 | public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) |
||
472 | { |
||
473 | string url = string.Empty, gname = string.Empty; |
||
474 | |||
475 | if (IsLocal(GroupID, out url, out gname)) |
||
476 | m_LocalGroupsConnector.AddAgentToGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID); |
||
477 | |||
478 | } |
||
479 | |||
480 | public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) |
||
481 | { |
||
482 | string url = string.Empty, gname = string.Empty; |
||
483 | |||
484 | if (IsLocal(GroupID, out url, out gname)) |
||
485 | m_LocalGroupsConnector.RemoveAgentFromGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID); |
||
486 | } |
||
487 | |||
488 | public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID) |
||
489 | { |
||
490 | string url = string.Empty, gname = string.Empty; |
||
491 | |||
492 | if (IsLocal(GroupID, out url, out gname)) |
||
493 | return m_LocalGroupsConnector.GetAgentGroupRoles(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID); |
||
494 | else |
||
495 | return new List<GroupRolesData>(); |
||
496 | } |
||
497 | |||
498 | public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID) |
||
499 | { |
||
500 | string url = string.Empty, gname = string.Empty; |
||
501 | |||
502 | if (IsLocal(GroupID, out url, out gname)) |
||
503 | m_LocalGroupsConnector.SetAgentActiveGroup(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID); |
||
504 | } |
||
505 | |||
506 | public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID) |
||
507 | { |
||
508 | return m_LocalGroupsConnector.GetAgentActiveMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID)); |
||
509 | } |
||
510 | |||
511 | public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) |
||
512 | { |
||
513 | string url = string.Empty, gname = string.Empty; |
||
514 | |||
515 | if (IsLocal(GroupID, out url, out gname)) |
||
516 | m_LocalGroupsConnector.SetAgentActiveGroupRole(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, RoleID); |
||
517 | } |
||
518 | |||
519 | public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile) |
||
520 | { |
||
521 | m_LocalGroupsConnector.UpdateMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID, AcceptNotices, ListInProfile); |
||
522 | } |
||
523 | |||
524 | public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID) |
||
525 | { |
||
526 | string url = string.Empty, gname = string.Empty; |
||
527 | |||
528 | if (IsLocal(GroupID, out url, out gname)) |
||
529 | return m_LocalGroupsConnector.GetAgentGroupMembership(AgentUUI(RequestingAgentID), AgentUUI(AgentID), GroupID); |
||
530 | else |
||
531 | return null; |
||
532 | } |
||
533 | |||
534 | public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID) |
||
535 | { |
||
536 | return m_LocalGroupsConnector.GetAgentGroupMemberships(AgentUUI(RequestingAgentID), AgentUUI(AgentID)); |
||
537 | } |
||
538 | |||
539 | public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, |
||
540 | bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID) |
||
541 | { |
||
542 | string url = string.Empty, gname = string.Empty; |
||
543 | |||
544 | if (IsLocal(groupID, out url, out gname)) |
||
545 | { |
||
546 | if (m_LocalGroupsConnector.AddGroupNotice(AgentUUI(RequestingAgentID), groupID, noticeID, fromName, subject, message, |
||
547 | hasAttachment, attType, attName, attItemID, AgentUUI(attOwnerID))) |
||
548 | { |
||
549 | // then send the notice to every grid for which there are members in this group |
||
550 | List<GroupMembersData> members = m_LocalGroupsConnector.GetGroupMembers(AgentUUI(RequestingAgentID), groupID); |
||
551 | List<string> urls = new List<string>(); |
||
552 | foreach (GroupMembersData m in members) |
||
553 | { |
||
554 | if (!m_UserManagement.IsLocalGridUser(m.AgentID)) |
||
555 | { |
||
556 | string gURL = m_UserManagement.GetUserServerURL(m.AgentID, "GroupsServerURI"); |
||
557 | if (!urls.Contains(gURL)) |
||
558 | urls.Add(gURL); |
||
559 | } |
||
560 | } |
||
561 | |||
562 | // so we have the list of urls to send the notice to |
||
563 | // this may take a long time... |
||
564 | Watchdog.RunInThread(delegate |
||
565 | { |
||
566 | foreach (string u in urls) |
||
567 | { |
||
568 | GroupsServiceHGConnector c = GetConnector(u); |
||
569 | if (c != null) |
||
570 | { |
||
571 | c.AddNotice(AgentUUIForOutside(RequestingAgentID), groupID, noticeID, fromName, subject, message, |
||
572 | hasAttachment, attType, attName, attItemID, AgentUUIForOutside(attOwnerID)); |
||
573 | } |
||
574 | } |
||
575 | }, string.Format("AddGroupNotice (agent {0}, group {1})", RequestingAgentID, groupID) , null); |
||
576 | |||
577 | return true; |
||
578 | } |
||
579 | |||
580 | return false; |
||
581 | } |
||
582 | else |
||
583 | return false; |
||
584 | } |
||
585 | |||
586 | public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID) |
||
587 | { |
||
588 | GroupNoticeInfo notice = m_LocalGroupsConnector.GetGroupNotice(AgentUUI(RequestingAgentID), noticeID); |
||
589 | |||
590 | if (notice != null && notice.noticeData.HasAttachment && notice.noticeData.AttachmentOwnerID != null) |
||
591 | ImportForeigner(notice.noticeData.AttachmentOwnerID); |
||
592 | |||
593 | return notice; |
||
594 | } |
||
595 | |||
596 | public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID) |
||
597 | { |
||
598 | return m_LocalGroupsConnector.GetGroupNotices(AgentUUI(RequestingAgentID), GroupID); |
||
599 | } |
||
600 | |||
601 | #endregion |
||
602 | |||
603 | #region hypergrid groups |
||
604 | |||
605 | private string AgentUUI(string AgentIDStr) |
||
606 | { |
||
607 | UUID AgentID = UUID.Zero; |
||
608 | try |
||
609 | { |
||
610 | AgentID = new UUID(AgentIDStr); |
||
611 | } |
||
612 | catch (FormatException) |
||
613 | { |
||
614 | return AgentID.ToString(); |
||
615 | } |
||
616 | |||
617 | if (m_UserManagement.IsLocalGridUser(AgentID)) |
||
618 | return AgentID.ToString(); |
||
619 | |||
620 | AgentCircuitData agent = null; |
||
621 | foreach (Scene scene in m_Scenes) |
||
622 | { |
||
623 | agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID); |
||
624 | if (agent != null) |
||
625 | break; |
||
626 | } |
||
627 | if (agent != null) |
||
628 | return Util.ProduceUserUniversalIdentifier(agent); |
||
629 | |||
630 | // we don't know anything about this foreign user |
||
631 | // try asking the user management module, which may know more |
||
632 | return m_UserManagement.GetUserUUI(AgentID); |
||
633 | |||
634 | } |
||
635 | |||
636 | private string AgentUUIForOutside(string AgentIDStr) |
||
637 | { |
||
638 | UUID AgentID = UUID.Zero; |
||
639 | try |
||
640 | { |
||
641 | AgentID = new UUID(AgentIDStr); |
||
642 | } |
||
643 | catch (FormatException) |
||
644 | { |
||
645 | return AgentID.ToString(); |
||
646 | } |
||
647 | |||
648 | AgentCircuitData agent = null; |
||
649 | foreach (Scene scene in m_Scenes) |
||
650 | { |
||
651 | agent = scene.AuthenticateHandler.GetAgentCircuitData(AgentID); |
||
652 | if (agent != null) |
||
653 | break; |
||
654 | } |
||
655 | if (agent == null) // oops |
||
656 | return AgentID.ToString(); |
||
657 | |||
658 | return Util.ProduceUserUniversalIdentifier(agent); |
||
659 | } |
||
660 | |||
661 | private UUID ImportForeigner(string uID) |
||
662 | { |
||
663 | UUID userID = UUID.Zero; |
||
664 | string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty; |
||
665 | if (Util.ParseUniversalUserIdentifier(uID, out userID, out url, out first, out last, out tmp)) |
||
666 | m_UserManagement.AddUser(userID, first, last, url); |
||
667 | |||
668 | return userID; |
||
669 | } |
||
670 | |||
671 | private bool IsLocal(UUID groupID, out string serviceLocation, out string name) |
||
672 | { |
||
673 | serviceLocation = string.Empty; |
||
674 | name = string.Empty; |
||
675 | if (groupID.Equals(UUID.Zero)) |
||
676 | return true; |
||
677 | |||
678 | ExtendedGroupRecord group = m_LocalGroupsConnector.GetGroupRecord(UUID.Zero.ToString(), groupID, string.Empty); |
||
679 | if (group == null) |
||
680 | { |
||
681 | //m_log.DebugFormat("[XXX]: IsLocal? group {0} not found -- no.", groupID); |
||
682 | return false; |
||
683 | } |
||
684 | |||
685 | serviceLocation = group.ServiceLocation; |
||
686 | name = group.GroupName; |
||
687 | bool isLocal = (group.ServiceLocation == string.Empty); |
||
688 | //m_log.DebugFormat("[XXX]: IsLocal? {0}", isLocal); |
||
689 | return isLocal; |
||
690 | } |
||
691 | |||
692 | private GroupsServiceHGConnector GetConnector(string url) |
||
693 | { |
||
694 | lock (m_NetworkConnectors) |
||
695 | { |
||
696 | if (m_NetworkConnectors.ContainsKey(url)) |
||
697 | return m_NetworkConnectors[url]; |
||
698 | |||
699 | GroupsServiceHGConnector c = new GroupsServiceHGConnector(url); |
||
700 | m_NetworkConnectors[url] = c; |
||
701 | } |
||
702 | |||
703 | return m_NetworkConnectors[url]; |
||
704 | } |
||
705 | #endregion |
||
706 | } |
||
707 | } |