aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Addons/Groups/Hypergrid
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Addons/Groups/Hypergrid')
-rw-r--r--OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnector.cs289
-rw-r--r--OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs707
-rw-r--r--OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs444
3 files changed, 1440 insertions, 0 deletions
diff --git a/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnector.cs b/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnector.cs
new file mode 100644
index 0000000..653dbac
--- /dev/null
+++ b/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnector.cs
@@ -0,0 +1,289 @@
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
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Text;
33
34using OpenSim.Framework;
35using OpenSim.Server.Base;
36
37using OpenMetaverse;
38using log4net;
39
40namespace OpenSim.Groups
41{
42 public class GroupsServiceHGConnector
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45
46 private string m_ServerURI;
47 private object m_Lock = new object();
48
49 public GroupsServiceHGConnector(string url)
50 {
51 m_ServerURI = url;
52 if (!m_ServerURI.EndsWith("/"))
53 m_ServerURI += "/";
54
55 m_log.DebugFormat("[Groups.HGConnector]: Groups server at {0}", m_ServerURI);
56 }
57
58 public bool CreateProxy(string RequestingAgentID, string AgentID, string accessToken, UUID groupID, string url, string name, out string reason)
59 {
60 reason = string.Empty;
61
62 Dictionary<string, object> sendData = new Dictionary<string,object>();
63 sendData["RequestingAgentID"] = RequestingAgentID;
64 sendData["AgentID"] = AgentID.ToString();
65 sendData["AccessToken"] = accessToken;
66 sendData["GroupID"] = groupID.ToString();
67 sendData["Location"] = url;
68 sendData["Name"] = name;
69 Dictionary<string, object> ret = MakeRequest("POSTGROUP", sendData);
70
71 if (ret == null)
72 return false;
73
74 if (!ret.ContainsKey("RESULT"))
75 return false;
76
77 if (ret["RESULT"].ToString().ToLower() != "true")
78 {
79 reason = ret["REASON"].ToString();
80 return false;
81 }
82
83 return true;
84
85 }
86
87 public void RemoveAgentFromGroup(string AgentID, UUID GroupID, string token)
88 {
89 Dictionary<string, object> sendData = new Dictionary<string, object>();
90 sendData["AgentID"] = AgentID;
91 sendData["GroupID"] = GroupID.ToString();
92 sendData["AccessToken"] = GroupsDataUtils.Sanitize(token);
93 MakeRequest("REMOVEAGENTFROMGROUP", sendData);
94 }
95
96 public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName, string token)
97 {
98 if (GroupID == UUID.Zero && (GroupName == null || (GroupName != null && GroupName == string.Empty)))
99 return null;
100
101 Dictionary<string, object> sendData = new Dictionary<string, object>();
102 if (GroupID != UUID.Zero)
103 sendData["GroupID"] = GroupID.ToString();
104 if (!string.IsNullOrEmpty(GroupName))
105 sendData["Name"] = GroupsDataUtils.Sanitize(GroupName);
106
107 sendData["RequestingAgentID"] = RequestingAgentID;
108 sendData["AccessToken"] = GroupsDataUtils.Sanitize(token);
109
110 Dictionary<string, object> ret = MakeRequest("GETGROUP", sendData);
111
112 if (ret == null)
113 return null;
114
115 if (!ret.ContainsKey("RESULT"))
116 return null;
117
118 if (ret["RESULT"].ToString() == "NULL")
119 return null;
120
121 return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
122 }
123
124 public List<ExtendedGroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID, string token)
125 {
126 List<ExtendedGroupMembersData> members = new List<ExtendedGroupMembersData>();
127
128 Dictionary<string, object> sendData = new Dictionary<string, object>();
129 sendData["GroupID"] = GroupID.ToString();
130 sendData["RequestingAgentID"] = RequestingAgentID;
131 sendData["AccessToken"] = GroupsDataUtils.Sanitize(token);
132 Dictionary<string, object> ret = MakeRequest("GETGROUPMEMBERS", sendData);
133
134 if (ret == null)
135 return members;
136
137 if (!ret.ContainsKey("RESULT"))
138 return members;
139
140 if (ret["RESULT"].ToString() == "NULL")
141 return members;
142 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
143 {
144 ExtendedGroupMembersData m = GroupsDataUtils.GroupMembersData((Dictionary<string, object>)v);
145 members.Add(m);
146 }
147
148 return members;
149 }
150
151 public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID, string token)
152 {
153 List<GroupRolesData> roles = new List<GroupRolesData>();
154
155 Dictionary<string, object> sendData = new Dictionary<string, object>();
156 sendData["GroupID"] = GroupID.ToString();
157 sendData["RequestingAgentID"] = RequestingAgentID;
158 sendData["AccessToken"] = GroupsDataUtils.Sanitize(token);
159 Dictionary<string, object> ret = MakeRequest("GETGROUPROLES", sendData);
160
161 if (ret == null)
162 return roles;
163
164 if (!ret.ContainsKey("RESULT"))
165 return roles;
166
167 if (ret["RESULT"].ToString() == "NULL")
168 return roles;
169 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
170 {
171 GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
172 roles.Add(m);
173 }
174
175 return roles;
176 }
177
178 public List<ExtendedGroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID, string token)
179 {
180 List<ExtendedGroupRoleMembersData> rmembers = new List<ExtendedGroupRoleMembersData>();
181
182 Dictionary<string, object> sendData = new Dictionary<string, object>();
183 sendData["GroupID"] = GroupID.ToString();
184 sendData["RequestingAgentID"] = RequestingAgentID;
185 sendData["AccessToken"] = GroupsDataUtils.Sanitize(token);
186 Dictionary<string, object> ret = MakeRequest("GETROLEMEMBERS", sendData);
187
188 if (ret == null)
189 return rmembers;
190
191 if (!ret.ContainsKey("RESULT"))
192 return rmembers;
193
194 if (ret["RESULT"].ToString() == "NULL")
195 return rmembers;
196
197 foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
198 {
199 ExtendedGroupRoleMembersData m = GroupsDataUtils.GroupRoleMembersData((Dictionary<string, object>)v);
200 rmembers.Add(m);
201 }
202
203 return rmembers;
204 }
205
206 public bool AddNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
207 bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
208 {
209 Dictionary<string, object> sendData = new Dictionary<string, object>();
210 sendData["GroupID"] = groupID.ToString();
211 sendData["NoticeID"] = noticeID.ToString();
212 sendData["FromName"] = GroupsDataUtils.Sanitize(fromName);
213 sendData["Subject"] = GroupsDataUtils.Sanitize(subject);
214 sendData["Message"] = GroupsDataUtils.Sanitize(message);
215 sendData["HasAttachment"] = hasAttachment.ToString();
216 if (hasAttachment)
217 {
218 sendData["AttachmentType"] = attType.ToString();
219 sendData["AttachmentName"] = attName.ToString();
220 sendData["AttachmentItemID"] = attItemID.ToString();
221 sendData["AttachmentOwnerID"] = attOwnerID;
222 }
223 sendData["RequestingAgentID"] = RequestingAgentID;
224
225 Dictionary<string, object> ret = MakeRequest("ADDNOTICE", sendData);
226
227 if (ret == null)
228 return false;
229
230 if (!ret.ContainsKey("RESULT"))
231 return false;
232
233 if (ret["RESULT"].ToString().ToLower() != "true")
234 return false;
235
236 return true;
237 }
238
239 public bool VerifyNotice(UUID noticeID, UUID groupID)
240 {
241 Dictionary<string, object> sendData = new Dictionary<string, object>();
242 sendData["NoticeID"] = noticeID.ToString();
243 sendData["GroupID"] = groupID.ToString();
244 Dictionary<string, object> ret = MakeRequest("VERIFYNOTICE", sendData);
245
246 if (ret == null)
247 return false;
248
249 if (!ret.ContainsKey("RESULT"))
250 return false;
251
252 if (ret["RESULT"].ToString().ToLower() != "true")
253 return false;
254
255 return true;
256 }
257
258 //
259 //
260 //
261 //
262 //
263
264 #region Make Request
265
266 private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData)
267 {
268 sendData["METHOD"] = method;
269
270 string reply = string.Empty;
271 lock (m_Lock)
272 reply = SynchronousRestFormsRequester.MakeRequest("POST",
273 m_ServerURI + "hg-groups",
274 ServerUtils.BuildQueryString(sendData));
275
276 //m_log.DebugFormat("[XXX]: reply was {0}", reply);
277
278 if (string.IsNullOrEmpty(reply))
279 return null;
280
281 Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
282 reply);
283
284 return replyData;
285 }
286 #endregion
287
288 }
289}
diff --git a/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs b/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs
new file mode 100644
index 0000000..7d57de1
--- /dev/null
+++ b/OpenSim/Addons/Groups/Hypergrid/GroupsServiceHGConnectorModule.cs
@@ -0,0 +1,707 @@
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
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Text;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Monitoring;
36using OpenSim.Framework.Servers;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Services.Interfaces;
40
41using OpenMetaverse;
42using Mono.Addins;
43using log4net;
44using Nini.Config;
45
46namespace 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 WorkManager.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 }, null, string.Format("AddGroupNotice (agent {0}, group {1})", RequestingAgentID, groupID));
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}
diff --git a/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs b/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs
new file mode 100644
index 0000000..f60c1a5
--- /dev/null
+++ b/OpenSim/Addons/Groups/Hypergrid/HGGroupsServiceRobustConnector.cs
@@ -0,0 +1,444 @@
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
28using System;
29using System.Reflection;
30using System.Text;
31using System.Xml;
32using System.Collections.Generic;
33using System.IO;
34using Nini.Config;
35using OpenSim.Framework;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Server.Handlers.Base;
40using log4net;
41using OpenMetaverse;
42
43namespace OpenSim.Groups
44{
45 public class HGGroupsServiceRobustConnector : ServiceConnector
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private HGGroupsService m_GroupsService;
50 private string m_ConfigName = "Groups";
51
52 // Called by Robust shell
53 public HGGroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName) :
54 this(config, server, configName, null, null)
55 {
56 }
57
58 // Called by the sim-bound module
59 public HGGroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName, IOfflineIMService im, IUserAccountService users) :
60 base(config, server, configName)
61 {
62 if (configName != String.Empty)
63 m_ConfigName = configName;
64
65 m_log.DebugFormat("[Groups.RobustHGConnector]: Starting with config name {0}", m_ConfigName);
66
67 string homeURI = Util.GetConfigVarFromSections<string>(config, "HomeURI",
68 new string[] { "Startup", "Hypergrid", m_ConfigName}, string.Empty);
69 if (homeURI == string.Empty)
70 throw new Exception(String.Format("[Groups.RobustHGConnector]: please provide the HomeURI [Startup] or in section {0}", m_ConfigName));
71
72 IConfig cnf = config.Configs[m_ConfigName];
73 if (cnf == null)
74 throw new Exception(String.Format("[Groups.RobustHGConnector]: {0} section does not exist", m_ConfigName));
75
76 if (im == null)
77 {
78 string imDll = cnf.GetString("OfflineIMService", string.Empty);
79 if (imDll == string.Empty)
80 throw new Exception(String.Format("[Groups.RobustHGConnector]: please provide OfflineIMService in section {0}", m_ConfigName));
81
82 Object[] args = new Object[] { config };
83 im = ServerUtils.LoadPlugin<IOfflineIMService>(imDll, args);
84 }
85
86 if (users == null)
87 {
88 string usersDll = cnf.GetString("UserAccountService", string.Empty);
89 if (usersDll == string.Empty)
90 throw new Exception(String.Format("[Groups.RobustHGConnector]: please provide UserAccountService in section {0}", m_ConfigName));
91
92 Object[] args = new Object[] { config };
93 users = ServerUtils.LoadPlugin<IUserAccountService>(usersDll, args);
94 }
95
96 m_GroupsService = new HGGroupsService(config, im, users, homeURI);
97
98 server.AddStreamHandler(new HGGroupsServicePostHandler(m_GroupsService));
99 }
100
101 }
102
103 public class HGGroupsServicePostHandler : BaseStreamHandler
104 {
105 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
106
107 private HGGroupsService m_GroupsService;
108
109 public HGGroupsServicePostHandler(HGGroupsService service) :
110 base("POST", "/hg-groups")
111 {
112 m_GroupsService = service;
113 }
114
115 protected override byte[] ProcessRequest(string path, Stream requestData,
116 IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
117 {
118 StreamReader sr = new StreamReader(requestData);
119 string body = sr.ReadToEnd();
120 sr.Close();
121 body = body.Trim();
122
123 //m_log.DebugFormat("[XXX]: query String: {0}", body);
124
125 try
126 {
127 Dictionary<string, object> request =
128 ServerUtils.ParseQueryString(body);
129
130 if (!request.ContainsKey("METHOD"))
131 return FailureResult();
132
133 string method = request["METHOD"].ToString();
134 request.Remove("METHOD");
135
136 m_log.DebugFormat("[Groups.RobustHGConnector]: {0}", method);
137 switch (method)
138 {
139 case "POSTGROUP":
140 return HandleAddGroupProxy(request);
141 case "REMOVEAGENTFROMGROUP":
142 return HandleRemoveAgentFromGroup(request);
143 case "GETGROUP":
144 return HandleGetGroup(request);
145 case "ADDNOTICE":
146 return HandleAddNotice(request);
147 case "VERIFYNOTICE":
148 return HandleVerifyNotice(request);
149 case "GETGROUPMEMBERS":
150 return HandleGetGroupMembers(request);
151 case "GETGROUPROLES":
152 return HandleGetGroupRoles(request);
153 case "GETROLEMEMBERS":
154 return HandleGetRoleMembers(request);
155
156 }
157 m_log.DebugFormat("[Groups.RobustHGConnector]: unknown method request: {0}", method);
158 }
159 catch (Exception e)
160 {
161 m_log.Error(string.Format("[Groups.RobustHGConnector]: Exception {0} ", e.Message), e);
162 }
163
164 return FailureResult();
165 }
166
167 byte[] HandleAddGroupProxy(Dictionary<string, object> request)
168 {
169 Dictionary<string, object> result = new Dictionary<string, object>();
170
171 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")
172 || !request.ContainsKey("AgentID")
173 || !request.ContainsKey("AccessToken") || !request.ContainsKey("Location"))
174 NullResult(result, "Bad network data");
175
176 else
177 {
178 string RequestingAgentID = request["RequestingAgentID"].ToString();
179 string agentID = request["AgentID"].ToString();
180 UUID groupID = new UUID(request["GroupID"].ToString());
181 string accessToken = request["AccessToken"].ToString();
182 string location = request["Location"].ToString();
183 string name = string.Empty;
184 if (request.ContainsKey("Name"))
185 name = request["Name"].ToString();
186
187 string reason = string.Empty;
188 bool success = m_GroupsService.CreateGroupProxy(RequestingAgentID, agentID, accessToken, groupID, location, name, out reason);
189 result["REASON"] = reason;
190 result["RESULT"] = success.ToString();
191 }
192
193 string xmlString = ServerUtils.BuildXmlResponse(result);
194
195 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
196 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
197 }
198
199 byte[] HandleRemoveAgentFromGroup(Dictionary<string, object> request)
200 {
201 Dictionary<string, object> result = new Dictionary<string, object>();
202
203 if (!request.ContainsKey("AccessToken") || !request.ContainsKey("AgentID") ||
204 !request.ContainsKey("GroupID"))
205 NullResult(result, "Bad network data");
206 else
207 {
208 UUID groupID = new UUID(request["GroupID"].ToString());
209 string agentID = request["AgentID"].ToString();
210 string token = request["AccessToken"].ToString();
211
212 if (!m_GroupsService.RemoveAgentFromGroup(agentID, agentID, groupID, token))
213 NullResult(result, "Internal error");
214 else
215 result["RESULT"] = "true";
216 }
217
218 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
219 return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result));
220 }
221
222 byte[] HandleGetGroup(Dictionary<string, object> request)
223 {
224 Dictionary<string, object> result = new Dictionary<string, object>();
225
226 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AccessToken"))
227 NullResult(result, "Bad network data");
228 else
229 {
230 string RequestingAgentID = request["RequestingAgentID"].ToString();
231 string token = request["AccessToken"].ToString();
232
233 UUID groupID = UUID.Zero;
234 string groupName = string.Empty;
235
236 if (request.ContainsKey("GroupID"))
237 groupID = new UUID(request["GroupID"].ToString());
238 if (request.ContainsKey("Name"))
239 groupName = request["Name"].ToString();
240
241 ExtendedGroupRecord grec = m_GroupsService.GetGroupRecord(RequestingAgentID, groupID, groupName, token);
242 if (grec == null)
243 NullResult(result, "Group not found");
244 else
245 result["RESULT"] = GroupsDataUtils.GroupRecord(grec);
246 }
247
248 string xmlString = ServerUtils.BuildXmlResponse(result);
249
250 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
251 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
252 }
253
254 byte[] HandleGetGroupMembers(Dictionary<string, object> request)
255 {
256 Dictionary<string, object> result = new Dictionary<string, object>();
257
258 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AccessToken"))
259 NullResult(result, "Bad network data");
260 else
261 {
262 UUID groupID = new UUID(request["GroupID"].ToString());
263 string requestingAgentID = request["RequestingAgentID"].ToString();
264 string token = request["AccessToken"].ToString();
265
266 List<ExtendedGroupMembersData> members = m_GroupsService.GetGroupMembers(requestingAgentID, groupID, token);
267 if (members == null || (members != null && members.Count == 0))
268 {
269 NullResult(result, "No members");
270 }
271 else
272 {
273 Dictionary<string, object> dict = new Dictionary<string, object>();
274 int i = 0;
275 foreach (ExtendedGroupMembersData m in members)
276 {
277 dict["m-" + i++] = GroupsDataUtils.GroupMembersData(m);
278 }
279
280 result["RESULT"] = dict;
281 }
282 }
283
284 string xmlString = ServerUtils.BuildXmlResponse(result);
285
286 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
287 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
288 }
289
290 byte[] HandleGetGroupRoles(Dictionary<string, object> request)
291 {
292 Dictionary<string, object> result = new Dictionary<string, object>();
293
294 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AccessToken"))
295 NullResult(result, "Bad network data");
296 else
297 {
298 UUID groupID = new UUID(request["GroupID"].ToString());
299 string requestingAgentID = request["RequestingAgentID"].ToString();
300 string token = request["AccessToken"].ToString();
301
302 List<GroupRolesData> roles = m_GroupsService.GetGroupRoles(requestingAgentID, groupID, token);
303 if (roles == null || (roles != null && roles.Count == 0))
304 {
305 NullResult(result, "No members");
306 }
307 else
308 {
309 Dictionary<string, object> dict = new Dictionary<string, object>();
310 int i = 0;
311 foreach (GroupRolesData r in roles)
312 dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r);
313
314 result["RESULT"] = dict;
315 }
316 }
317
318 string xmlString = ServerUtils.BuildXmlResponse(result);
319
320 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
321 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
322 }
323
324 byte[] HandleGetRoleMembers(Dictionary<string, object> request)
325 {
326 Dictionary<string, object> result = new Dictionary<string, object>();
327
328 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AccessToken"))
329 NullResult(result, "Bad network data");
330 else
331 {
332 UUID groupID = new UUID(request["GroupID"].ToString());
333 string requestingAgentID = request["RequestingAgentID"].ToString();
334 string token = request["AccessToken"].ToString();
335
336 List<ExtendedGroupRoleMembersData> rmembers = m_GroupsService.GetGroupRoleMembers(requestingAgentID, groupID, token);
337 if (rmembers == null || (rmembers != null && rmembers.Count == 0))
338 {
339 NullResult(result, "No members");
340 }
341 else
342 {
343 Dictionary<string, object> dict = new Dictionary<string, object>();
344 int i = 0;
345 foreach (ExtendedGroupRoleMembersData rm in rmembers)
346 dict["rm-" + i++] = GroupsDataUtils.GroupRoleMembersData(rm);
347
348 result["RESULT"] = dict;
349 }
350 }
351
352 string xmlString = ServerUtils.BuildXmlResponse(result);
353
354 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
355 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
356 }
357
358 byte[] HandleAddNotice(Dictionary<string, object> request)
359 {
360 Dictionary<string, object> result = new Dictionary<string, object>();
361
362 if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("NoticeID") ||
363 !request.ContainsKey("FromName") || !request.ContainsKey("Subject") || !request.ContainsKey("Message") ||
364 !request.ContainsKey("HasAttachment"))
365 NullResult(result, "Bad network data");
366
367 else
368 {
369
370 bool hasAtt = bool.Parse(request["HasAttachment"].ToString());
371 byte attType = 0;
372 string attName = string.Empty;
373 string attOwner = string.Empty;
374 UUID attItem = UUID.Zero;
375 if (request.ContainsKey("AttachmentType"))
376 attType = byte.Parse(request["AttachmentType"].ToString());
377 if (request.ContainsKey("AttachmentName"))
378 attName = request["AttachmentType"].ToString();
379 if (request.ContainsKey("AttachmentItemID"))
380 attItem = new UUID(request["AttachmentItemID"].ToString());
381 if (request.ContainsKey("AttachmentOwnerID"))
382 attOwner = request["AttachmentOwnerID"].ToString();
383
384 bool success = m_GroupsService.AddNotice(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()),
385 new UUID(request["NoticeID"].ToString()), request["FromName"].ToString(), request["Subject"].ToString(),
386 request["Message"].ToString(), hasAtt, attType, attName, attItem, attOwner);
387
388 result["RESULT"] = success.ToString();
389 }
390
391 string xmlString = ServerUtils.BuildXmlResponse(result);
392
393 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
394 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
395 }
396
397 byte[] HandleVerifyNotice(Dictionary<string, object> request)
398 {
399 Dictionary<string, object> result = new Dictionary<string, object>();
400
401 if (!request.ContainsKey("NoticeID") || !request.ContainsKey("GroupID"))
402 NullResult(result, "Bad network data");
403
404 else
405 {
406 UUID noticeID = new UUID(request["NoticeID"].ToString());
407 UUID groupID = new UUID(request["GroupID"].ToString());
408
409 bool success = m_GroupsService.VerifyNotice(noticeID, groupID);
410 //m_log.DebugFormat("[XXX]: VerifyNotice returned {0}", success);
411 result["RESULT"] = success.ToString();
412 }
413
414 string xmlString = ServerUtils.BuildXmlResponse(result);
415
416 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
417 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
418 }
419
420 //
421 //
422 //
423 //
424 //
425
426 #region Helpers
427
428 private void NullResult(Dictionary<string, object> result, string reason)
429 {
430 result["RESULT"] = "NULL";
431 result["REASON"] = reason;
432 }
433
434 private byte[] FailureResult()
435 {
436 Dictionary<string, object> result = new Dictionary<string, object>();
437 NullResult(result, "Unknown method");
438 string xmlString = ServerUtils.BuildXmlResponse(result);
439 return Util.UTF8NoBomEncoding.GetBytes(xmlString);
440 }
441
442 #endregion
443 }
444}