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