diff options
Diffstat (limited to 'OpenSim/Addons/Groups/Remote')
3 files changed, 1836 insertions, 0 deletions
diff --git a/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs new file mode 100644 index 0000000..04328c9 --- /dev/null +++ b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnector.cs | |||
@@ -0,0 +1,642 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Base; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Groups | ||
41 | { | ||
42 | public class GroupsServiceRemoteConnector | ||
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 GroupsServiceRemoteConnector(string url) | ||
50 | { | ||
51 | m_ServerURI = url; | ||
52 | if (!m_ServerURI.EndsWith("/")) | ||
53 | m_ServerURI += "/"; | ||
54 | |||
55 | m_log.DebugFormat("[Groups.RemoteConnector]: Groups server at {0}", m_ServerURI); | ||
56 | } | ||
57 | |||
58 | public ExtendedGroupRecord CreateGroup(string RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, | ||
59 | bool allowPublish, bool maturePublish, UUID founderID, out string reason) | ||
60 | { | ||
61 | reason = string.Empty; | ||
62 | |||
63 | ExtendedGroupRecord rec = new ExtendedGroupRecord(); | ||
64 | rec.AllowPublish = allowPublish; | ||
65 | rec.Charter = charter; | ||
66 | rec.FounderID = founderID; | ||
67 | rec.GroupName = name; | ||
68 | rec.GroupPicture = insigniaID; | ||
69 | rec.MaturePublish = maturePublish; | ||
70 | rec.MembershipFee = membershipFee; | ||
71 | rec.OpenEnrollment = openEnrollment; | ||
72 | rec.ShowInList = showInList; | ||
73 | |||
74 | Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec); | ||
75 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
76 | sendData["OP"] = "ADD"; | ||
77 | Dictionary<string, object> ret = MakeRequest("PUTGROUP", sendData); | ||
78 | |||
79 | if (ret == null) | ||
80 | return null; | ||
81 | |||
82 | if (ret["RESULT"].ToString() == "NULL") | ||
83 | { | ||
84 | reason = ret["REASON"].ToString(); | ||
85 | return null; | ||
86 | } | ||
87 | |||
88 | return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]); | ||
89 | |||
90 | } | ||
91 | |||
92 | public ExtendedGroupRecord UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish) | ||
93 | { | ||
94 | ExtendedGroupRecord rec = new ExtendedGroupRecord(); | ||
95 | rec.AllowPublish = allowPublish; | ||
96 | rec.Charter = charter; | ||
97 | rec.GroupPicture = insigniaID; | ||
98 | rec.MaturePublish = maturePublish; | ||
99 | rec.GroupID = groupID; | ||
100 | rec.MembershipFee = membershipFee; | ||
101 | rec.OpenEnrollment = openEnrollment; | ||
102 | rec.ShowInList = showInList; | ||
103 | |||
104 | Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec); | ||
105 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
106 | sendData["OP"] = "UPDATE"; | ||
107 | Dictionary<string, object> ret = MakeRequest("PUTGROUP", sendData); | ||
108 | |||
109 | if (ret == null || (ret != null && ret["RESULT"].ToString() == "NULL")) | ||
110 | return null; | ||
111 | |||
112 | return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]); | ||
113 | } | ||
114 | |||
115 | public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName) | ||
116 | { | ||
117 | if (GroupID == UUID.Zero && (GroupName == null || (GroupName != null && GroupName == string.Empty))) | ||
118 | return null; | ||
119 | |||
120 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
121 | if (GroupID != UUID.Zero) | ||
122 | sendData["GroupID"] = GroupID.ToString(); | ||
123 | if (GroupName != null && GroupName != string.Empty) | ||
124 | sendData["Name"] = GroupsDataUtils.Sanitize(GroupName); | ||
125 | |||
126 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
127 | |||
128 | Dictionary<string, object> ret = MakeRequest("GETGROUP", sendData); | ||
129 | |||
130 | if (ret == null || (ret != null && ret["RESULT"].ToString() == "NULL")) | ||
131 | return null; | ||
132 | |||
133 | return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]); | ||
134 | } | ||
135 | |||
136 | public GroupMembershipData AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason) | ||
137 | { | ||
138 | reason = string.Empty; | ||
139 | |||
140 | Dictionary<string, object> sendData = new Dictionary<string,object>(); | ||
141 | sendData["AgentID"] = AgentID; | ||
142 | sendData["GroupID"] = GroupID.ToString(); | ||
143 | sendData["RoleID"] = RoleID.ToString(); | ||
144 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
145 | sendData["AccessToken"] = token; | ||
146 | Dictionary<string, object> ret = MakeRequest("ADDAGENTTOGROUP", sendData); | ||
147 | |||
148 | if (ret == null) | ||
149 | return null; | ||
150 | |||
151 | if (!ret.ContainsKey("RESULT")) | ||
152 | return null; | ||
153 | |||
154 | if (ret["RESULT"].ToString() == "NULL") | ||
155 | { | ||
156 | reason = ret["REASON"].ToString(); | ||
157 | return null; | ||
158 | } | ||
159 | |||
160 | return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]); | ||
161 | |||
162 | } | ||
163 | |||
164 | public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID) | ||
165 | { | ||
166 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
167 | sendData["AgentID"] = AgentID; | ||
168 | sendData["GroupID"] = GroupID.ToString(); | ||
169 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
170 | MakeRequest("REMOVEAGENTFROMGROUP", sendData); | ||
171 | } | ||
172 | |||
173 | public ExtendedGroupMembershipData GetMembership(string RequestingAgentID, string AgentID, UUID GroupID) | ||
174 | { | ||
175 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
176 | sendData["AgentID"] = AgentID; | ||
177 | if (GroupID != UUID.Zero) | ||
178 | sendData["GroupID"] = GroupID.ToString(); | ||
179 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
180 | Dictionary<string, object> ret = MakeRequest("GETMEMBERSHIP", sendData); | ||
181 | |||
182 | if (ret == null) | ||
183 | return null; | ||
184 | |||
185 | if (!ret.ContainsKey("RESULT")) | ||
186 | return null; | ||
187 | |||
188 | if (ret["RESULT"].ToString() == "NULL") | ||
189 | return null; | ||
190 | |||
191 | return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]); | ||
192 | } | ||
193 | |||
194 | public List<GroupMembershipData> GetMemberships(string RequestingAgentID, string AgentID) | ||
195 | { | ||
196 | List<GroupMembershipData> memberships = new List<GroupMembershipData>(); | ||
197 | |||
198 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
199 | sendData["AgentID"] = AgentID; | ||
200 | sendData["ALL"] = "true"; | ||
201 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
202 | Dictionary<string, object> ret = MakeRequest("GETMEMBERSHIP", sendData); | ||
203 | |||
204 | if (ret == null) | ||
205 | return memberships; | ||
206 | |||
207 | if (!ret.ContainsKey("RESULT")) | ||
208 | return memberships; | ||
209 | |||
210 | if (ret["RESULT"].ToString() == "NULL") | ||
211 | return memberships; | ||
212 | |||
213 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
214 | { | ||
215 | GroupMembershipData m = GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)v); | ||
216 | memberships.Add(m); | ||
217 | } | ||
218 | |||
219 | return memberships; | ||
220 | } | ||
221 | |||
222 | public List<ExtendedGroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID) | ||
223 | { | ||
224 | List<ExtendedGroupMembersData> members = new List<ExtendedGroupMembersData>(); | ||
225 | |||
226 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
227 | sendData["GroupID"] = GroupID.ToString(); | ||
228 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
229 | Dictionary<string, object> ret = MakeRequest("GETGROUPMEMBERS", sendData); | ||
230 | |||
231 | if (ret == null) | ||
232 | return members; | ||
233 | |||
234 | if (!ret.ContainsKey("RESULT")) | ||
235 | return members; | ||
236 | |||
237 | if (ret["RESULT"].ToString() == "NULL") | ||
238 | return members; | ||
239 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
240 | { | ||
241 | ExtendedGroupMembersData m = GroupsDataUtils.GroupMembersData((Dictionary<string, object>)v); | ||
242 | members.Add(m); | ||
243 | } | ||
244 | |||
245 | return members; | ||
246 | } | ||
247 | |||
248 | public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason) | ||
249 | { | ||
250 | reason = string.Empty; | ||
251 | |||
252 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
253 | sendData["GroupID"] = groupID.ToString(); | ||
254 | sendData["RoleID"] = roleID.ToString(); | ||
255 | sendData["Name"] = GroupsDataUtils.Sanitize(name); | ||
256 | sendData["Description"] = GroupsDataUtils.Sanitize(description); | ||
257 | sendData["Title"] = GroupsDataUtils.Sanitize(title); | ||
258 | sendData["Powers"] = powers.ToString(); | ||
259 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
260 | sendData["OP"] = "ADD"; | ||
261 | Dictionary<string, object> ret = MakeRequest("PUTROLE", sendData); | ||
262 | |||
263 | if (ret == null) | ||
264 | return false; | ||
265 | |||
266 | if (!ret.ContainsKey("RESULT")) | ||
267 | return false; | ||
268 | |||
269 | if (ret["RESULT"].ToString().ToLower() != "true") | ||
270 | { | ||
271 | reason = ret["REASON"].ToString(); | ||
272 | return false; | ||
273 | } | ||
274 | |||
275 | return true; | ||
276 | } | ||
277 | |||
278 | public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers) | ||
279 | { | ||
280 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
281 | sendData["GroupID"] = groupID.ToString(); | ||
282 | sendData["RoleID"] = roleID.ToString(); | ||
283 | sendData["Name"] = GroupsDataUtils.Sanitize(name); | ||
284 | sendData["Description"] = GroupsDataUtils.Sanitize(description); | ||
285 | sendData["Title"] = GroupsDataUtils.Sanitize(title); | ||
286 | sendData["Powers"] = powers.ToString(); | ||
287 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
288 | sendData["OP"] = "UPDATE"; | ||
289 | Dictionary<string, object> ret = MakeRequest("PUTROLE", sendData); | ||
290 | |||
291 | if (ret == null) | ||
292 | return false; | ||
293 | |||
294 | if (!ret.ContainsKey("RESULT")) | ||
295 | return false; | ||
296 | |||
297 | if (ret["RESULT"].ToString().ToLower() != "true") | ||
298 | return false; | ||
299 | |||
300 | return true; | ||
301 | } | ||
302 | |||
303 | public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID) | ||
304 | { | ||
305 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
306 | sendData["GroupID"] = groupID.ToString(); | ||
307 | sendData["RoleID"] = roleID.ToString(); | ||
308 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
309 | MakeRequest("REMOVEROLE", sendData); | ||
310 | } | ||
311 | |||
312 | public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID) | ||
313 | { | ||
314 | List<GroupRolesData> roles = new List<GroupRolesData>(); | ||
315 | |||
316 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
317 | sendData["GroupID"] = GroupID.ToString(); | ||
318 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
319 | Dictionary<string, object> ret = MakeRequest("GETGROUPROLES", sendData); | ||
320 | |||
321 | if (ret == null) | ||
322 | return roles; | ||
323 | |||
324 | if (!ret.ContainsKey("RESULT")) | ||
325 | return roles; | ||
326 | |||
327 | if (ret["RESULT"].ToString() == "NULL") | ||
328 | return roles; | ||
329 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
330 | { | ||
331 | GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v); | ||
332 | roles.Add(m); | ||
333 | } | ||
334 | |||
335 | return roles; | ||
336 | } | ||
337 | |||
338 | public List<ExtendedGroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID) | ||
339 | { | ||
340 | List<ExtendedGroupRoleMembersData> rmembers = new List<ExtendedGroupRoleMembersData>(); | ||
341 | |||
342 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
343 | sendData["GroupID"] = GroupID.ToString(); | ||
344 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
345 | Dictionary<string, object> ret = MakeRequest("GETROLEMEMBERS", sendData); | ||
346 | |||
347 | if (ret == null) | ||
348 | return rmembers; | ||
349 | |||
350 | if (!ret.ContainsKey("RESULT")) | ||
351 | return rmembers; | ||
352 | |||
353 | if (ret["RESULT"].ToString() == "NULL") | ||
354 | return rmembers; | ||
355 | |||
356 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
357 | { | ||
358 | ExtendedGroupRoleMembersData m = GroupsDataUtils.GroupRoleMembersData((Dictionary<string, object>)v); | ||
359 | rmembers.Add(m); | ||
360 | } | ||
361 | |||
362 | return rmembers; | ||
363 | } | ||
364 | |||
365 | public bool AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) | ||
366 | { | ||
367 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
368 | sendData["AgentID"] = AgentID.ToString(); | ||
369 | sendData["GroupID"] = GroupID.ToString(); | ||
370 | sendData["RoleID"] = RoleID.ToString(); | ||
371 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
372 | sendData["OP"] = "ADD"; | ||
373 | |||
374 | Dictionary<string, object> ret = MakeRequest("AGENTROLE", sendData); | ||
375 | |||
376 | if (ret == null) | ||
377 | return false; | ||
378 | |||
379 | if (!ret.ContainsKey("RESULT")) | ||
380 | return false; | ||
381 | |||
382 | if (ret["RESULT"].ToString().ToLower() != "true") | ||
383 | return false; | ||
384 | |||
385 | return true; | ||
386 | } | ||
387 | |||
388 | public bool RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) | ||
389 | { | ||
390 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
391 | sendData["AgentID"] = AgentID.ToString(); | ||
392 | sendData["GroupID"] = GroupID.ToString(); | ||
393 | sendData["RoleID"] = RoleID.ToString(); | ||
394 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
395 | sendData["OP"] = "DELETE"; | ||
396 | |||
397 | Dictionary<string, object> ret = MakeRequest("AGENTROLE", sendData); | ||
398 | |||
399 | if (ret == null) | ||
400 | return false; | ||
401 | |||
402 | if (!ret.ContainsKey("RESULT")) | ||
403 | return false; | ||
404 | |||
405 | if (ret["RESULT"].ToString().ToLower() != "true") | ||
406 | return false; | ||
407 | |||
408 | return true; | ||
409 | } | ||
410 | |||
411 | public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID) | ||
412 | { | ||
413 | List<GroupRolesData> roles = new List<GroupRolesData>(); | ||
414 | |||
415 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
416 | sendData["AgentID"] = AgentID.ToString(); | ||
417 | sendData["GroupID"] = GroupID.ToString(); | ||
418 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
419 | Dictionary<string, object> ret = MakeRequest("GETAGENTROLES", sendData); | ||
420 | |||
421 | if (ret == null) | ||
422 | return roles; | ||
423 | |||
424 | if (!ret.ContainsKey("RESULT")) | ||
425 | return roles; | ||
426 | |||
427 | if (ret["RESULT"].ToString() == "NULL") | ||
428 | return roles; | ||
429 | |||
430 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
431 | { | ||
432 | GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v); | ||
433 | roles.Add(m); | ||
434 | } | ||
435 | |||
436 | return roles; | ||
437 | } | ||
438 | |||
439 | public GroupMembershipData SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID) | ||
440 | { | ||
441 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
442 | sendData["AgentID"] = AgentID.ToString(); | ||
443 | sendData["GroupID"] = GroupID.ToString(); | ||
444 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
445 | sendData["OP"] = "GROUP"; | ||
446 | |||
447 | Dictionary<string, object> ret = MakeRequest("SETACTIVE", sendData); | ||
448 | |||
449 | if (ret == null) | ||
450 | return null; | ||
451 | |||
452 | if (!ret.ContainsKey("RESULT")) | ||
453 | return null; | ||
454 | |||
455 | if (ret["RESULT"].ToString() == "NULL") | ||
456 | return null; | ||
457 | |||
458 | return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]); | ||
459 | } | ||
460 | |||
461 | public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) | ||
462 | { | ||
463 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
464 | sendData["AgentID"] = AgentID.ToString(); | ||
465 | sendData["GroupID"] = GroupID.ToString(); | ||
466 | sendData["RoleID"] = RoleID.ToString(); | ||
467 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
468 | sendData["OP"] = "ROLE"; | ||
469 | |||
470 | MakeRequest("SETACTIVE", sendData); | ||
471 | } | ||
472 | |||
473 | public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile) | ||
474 | { | ||
475 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
476 | sendData["AgentID"] = AgentID.ToString(); | ||
477 | sendData["GroupID"] = GroupID.ToString(); | ||
478 | sendData["AcceptNotices"] = AcceptNotices.ToString(); | ||
479 | sendData["ListInProfile"] = ListInProfile.ToString(); | ||
480 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
481 | MakeRequest("UPDATEMEMBERSHIP", sendData); | ||
482 | } | ||
483 | |||
484 | public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID) | ||
485 | { | ||
486 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
487 | sendData["InviteID"] = inviteID.ToString(); | ||
488 | sendData["GroupID"] = groupID.ToString(); | ||
489 | sendData["RoleID"] = roleID.ToString(); | ||
490 | sendData["AgentID"] = agentID.ToString(); | ||
491 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
492 | sendData["OP"] = "ADD"; | ||
493 | |||
494 | Dictionary<string, object> ret = MakeRequest("INVITE", sendData); | ||
495 | |||
496 | if (ret == null) | ||
497 | return false; | ||
498 | |||
499 | if (!ret.ContainsKey("RESULT")) | ||
500 | return false; | ||
501 | |||
502 | if (ret["RESULT"].ToString().ToLower() != "true") // it may return "NULL" | ||
503 | return false; | ||
504 | |||
505 | return true; | ||
506 | } | ||
507 | |||
508 | public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID) | ||
509 | { | ||
510 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
511 | sendData["InviteID"] = inviteID.ToString(); | ||
512 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
513 | sendData["OP"] = "GET"; | ||
514 | |||
515 | Dictionary<string, object> ret = MakeRequest("INVITE", sendData); | ||
516 | |||
517 | if (ret == null) | ||
518 | return null; | ||
519 | |||
520 | if (!ret.ContainsKey("RESULT")) | ||
521 | return null; | ||
522 | |||
523 | if (ret["RESULT"].ToString() == "NULL") | ||
524 | return null; | ||
525 | |||
526 | return GroupsDataUtils.GroupInviteInfo((Dictionary<string, object>)ret["RESULT"]); | ||
527 | } | ||
528 | |||
529 | public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID) | ||
530 | { | ||
531 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
532 | sendData["InviteID"] = inviteID.ToString(); | ||
533 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
534 | sendData["OP"] = "DELETE"; | ||
535 | |||
536 | MakeRequest("INVITE", sendData); | ||
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 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
543 | sendData["GroupID"] = groupID.ToString(); | ||
544 | sendData["NoticeID"] = noticeID.ToString(); | ||
545 | sendData["FromName"] = GroupsDataUtils.Sanitize(fromName); | ||
546 | sendData["Subject"] = GroupsDataUtils.Sanitize(subject); | ||
547 | sendData["Message"] = GroupsDataUtils.Sanitize(message); | ||
548 | sendData["HasAttachment"] = hasAttachment.ToString(); | ||
549 | if (hasAttachment) | ||
550 | { | ||
551 | sendData["AttachmentType"] = attType.ToString(); | ||
552 | sendData["AttachmentName"] = attName.ToString(); | ||
553 | sendData["AttachmentItemID"] = attItemID.ToString(); | ||
554 | sendData["AttachmentOwnerID"] = attOwnerID; | ||
555 | } | ||
556 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
557 | |||
558 | Dictionary<string, object> ret = MakeRequest("ADDNOTICE", sendData); | ||
559 | |||
560 | if (ret == null) | ||
561 | return false; | ||
562 | |||
563 | if (!ret.ContainsKey("RESULT")) | ||
564 | return false; | ||
565 | |||
566 | if (ret["RESULT"].ToString().ToLower() != "true") | ||
567 | return false; | ||
568 | |||
569 | return true; | ||
570 | } | ||
571 | |||
572 | public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID) | ||
573 | { | ||
574 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
575 | sendData["NoticeID"] = noticeID.ToString(); | ||
576 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
577 | |||
578 | Dictionary<string, object> ret = MakeRequest("GETNOTICES", sendData); | ||
579 | |||
580 | if (ret == null) | ||
581 | return null; | ||
582 | |||
583 | if (!ret.ContainsKey("RESULT")) | ||
584 | return null; | ||
585 | |||
586 | if (ret["RESULT"].ToString() == "NULL") | ||
587 | return null; | ||
588 | |||
589 | return GroupsDataUtils.GroupNoticeInfo((Dictionary<string, object>)ret["RESULT"]); | ||
590 | } | ||
591 | |||
592 | public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID) | ||
593 | { | ||
594 | List<ExtendedGroupNoticeData> notices = new List<ExtendedGroupNoticeData>(); | ||
595 | |||
596 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
597 | sendData["GroupID"] = GroupID.ToString(); | ||
598 | sendData["RequestingAgentID"] = RequestingAgentID; | ||
599 | Dictionary<string, object> ret = MakeRequest("GETNOTICES", sendData); | ||
600 | |||
601 | if (ret == null) | ||
602 | return notices; | ||
603 | |||
604 | if (!ret.ContainsKey("RESULT")) | ||
605 | return notices; | ||
606 | |||
607 | if (ret["RESULT"].ToString() == "NULL") | ||
608 | return notices; | ||
609 | |||
610 | foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values) | ||
611 | { | ||
612 | ExtendedGroupNoticeData m = GroupsDataUtils.GroupNoticeData((Dictionary<string, object>)v); | ||
613 | notices.Add(m); | ||
614 | } | ||
615 | |||
616 | return notices; | ||
617 | } | ||
618 | |||
619 | #region Make Request | ||
620 | |||
621 | private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData) | ||
622 | { | ||
623 | sendData["METHOD"] = method; | ||
624 | |||
625 | string reply = string.Empty; | ||
626 | lock (m_Lock) | ||
627 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
628 | m_ServerURI + "groups", | ||
629 | ServerUtils.BuildQueryString(sendData)); | ||
630 | |||
631 | if (reply == string.Empty) | ||
632 | return null; | ||
633 | |||
634 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse( | ||
635 | reply); | ||
636 | |||
637 | return replyData; | ||
638 | } | ||
639 | #endregion | ||
640 | |||
641 | } | ||
642 | } | ||
diff --git a/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs new file mode 100644 index 0000000..f1cf66c --- /dev/null +++ b/OpenSim/Addons/Groups/Remote/GroupsServiceRemoteConnectorModule.cs | |||
@@ -0,0 +1,434 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using System.Text; | ||
34 | |||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Server.Base; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using Mono.Addins; | ||
42 | using log4net; | ||
43 | using Nini.Config; | ||
44 | |||
45 | namespace OpenSim.Groups | ||
46 | { | ||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GroupsServiceRemoteConnectorModule")] | ||
48 | public class GroupsServiceRemoteConnectorModule : ISharedRegionModule, IGroupsServicesConnector | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private bool m_Enabled = false; | ||
53 | private GroupsServiceRemoteConnector m_GroupsService; | ||
54 | private IUserManagement m_UserManagement; | ||
55 | private List<Scene> m_Scenes; | ||
56 | |||
57 | private RemoteConnectorCacheWrapper m_CacheWrapper; | ||
58 | |||
59 | #region constructors | ||
60 | public GroupsServiceRemoteConnectorModule() | ||
61 | { | ||
62 | } | ||
63 | |||
64 | public GroupsServiceRemoteConnectorModule(IConfigSource config, IUserManagement uman) | ||
65 | { | ||
66 | Init(config); | ||
67 | m_UserManagement = uman; | ||
68 | m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement); | ||
69 | |||
70 | } | ||
71 | #endregion | ||
72 | |||
73 | private void Init(IConfigSource config) | ||
74 | { | ||
75 | IConfig groupsConfig = config.Configs["Groups"]; | ||
76 | string url = groupsConfig.GetString("GroupsServerURI", string.Empty); | ||
77 | if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) | ||
78 | throw new Exception(string.Format("[Groups.RemoteConnector]: Malformed groups server URL {0}. Fix it or disable the Groups feature.", url)); | ||
79 | |||
80 | m_GroupsService = new GroupsServiceRemoteConnector(url); | ||
81 | m_Scenes = new List<Scene>(); | ||
82 | |||
83 | } | ||
84 | |||
85 | #region ISharedRegionModule | ||
86 | |||
87 | public void Initialise(IConfigSource config) | ||
88 | { | ||
89 | IConfig groupsConfig = config.Configs["Groups"]; | ||
90 | if (groupsConfig == null) | ||
91 | return; | ||
92 | |||
93 | if ((groupsConfig.GetBoolean("Enabled", false) == false) | ||
94 | || (groupsConfig.GetString("ServicesConnectorModule", string.Empty) != Name)) | ||
95 | { | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | Init(config); | ||
100 | |||
101 | m_Enabled = true; | ||
102 | m_log.DebugFormat("[Groups.RemoteConnector]: Initializing {0}", this.Name); | ||
103 | } | ||
104 | |||
105 | public string Name | ||
106 | { | ||
107 | get { return "Groups Remote Service Connector"; } | ||
108 | } | ||
109 | |||
110 | public Type ReplaceableInterface | ||
111 | { | ||
112 | get { return null; } | ||
113 | } | ||
114 | |||
115 | public void AddRegion(Scene scene) | ||
116 | { | ||
117 | if (!m_Enabled) | ||
118 | return; | ||
119 | |||
120 | m_log.DebugFormat("[Groups.RemoteConnector]: Registering {0} with {1}", this.Name, scene.RegionInfo.RegionName); | ||
121 | scene.RegisterModuleInterface<IGroupsServicesConnector>(this); | ||
122 | m_Scenes.Add(scene); | ||
123 | } | ||
124 | |||
125 | public void RemoveRegion(Scene scene) | ||
126 | { | ||
127 | if (!m_Enabled) | ||
128 | return; | ||
129 | |||
130 | scene.UnregisterModuleInterface<IGroupsServicesConnector>(this); | ||
131 | m_Scenes.Remove(scene); | ||
132 | } | ||
133 | |||
134 | public void RegionLoaded(Scene scene) | ||
135 | { | ||
136 | if (!m_Enabled) | ||
137 | return; | ||
138 | |||
139 | if (m_UserManagement == null) | ||
140 | { | ||
141 | m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); | ||
142 | m_CacheWrapper = new RemoteConnectorCacheWrapper(m_UserManagement); | ||
143 | } | ||
144 | } | ||
145 | |||
146 | public void PostInitialise() | ||
147 | { | ||
148 | } | ||
149 | |||
150 | public void Close() | ||
151 | { | ||
152 | } | ||
153 | |||
154 | #endregion | ||
155 | |||
156 | #region IGroupsServicesConnector | ||
157 | |||
158 | public UUID CreateGroup(UUID RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, | ||
159 | bool allowPublish, bool maturePublish, UUID founderID, out string reason) | ||
160 | { | ||
161 | m_log.DebugFormat("[Groups.RemoteConnector]: Creating group {0}", name); | ||
162 | string r = string.Empty; | ||
163 | |||
164 | UUID groupID = m_CacheWrapper.CreateGroup(RequestingAgentID, delegate | ||
165 | { | ||
166 | return m_GroupsService.CreateGroup(RequestingAgentID.ToString(), name, charter, showInList, insigniaID, | ||
167 | membershipFee, openEnrollment, allowPublish, maturePublish, founderID, out r); | ||
168 | }); | ||
169 | |||
170 | reason = r; | ||
171 | return groupID; | ||
172 | } | ||
173 | |||
174 | public bool UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, | ||
175 | bool openEnrollment, bool allowPublish, bool maturePublish, out string reason) | ||
176 | { | ||
177 | string r = string.Empty; | ||
178 | |||
179 | bool success = m_CacheWrapper.UpdateGroup(groupID, delegate | ||
180 | { | ||
181 | return m_GroupsService.UpdateGroup(RequestingAgentID, groupID, charter, showInList, insigniaID, membershipFee, openEnrollment, allowPublish, maturePublish); | ||
182 | }); | ||
183 | |||
184 | reason = r; | ||
185 | return success; | ||
186 | } | ||
187 | |||
188 | public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName) | ||
189 | { | ||
190 | if (GroupID == UUID.Zero && (GroupName == null || GroupName != null && GroupName == string.Empty)) | ||
191 | return null; | ||
192 | |||
193 | return m_CacheWrapper.GetGroupRecord(RequestingAgentID,GroupID,GroupName, delegate | ||
194 | { | ||
195 | return m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID, GroupName); | ||
196 | }); | ||
197 | } | ||
198 | |||
199 | public List<DirGroupsReplyData> FindGroups(string RequestingAgentID, string search) | ||
200 | { | ||
201 | // TODO! | ||
202 | return new List<DirGroupsReplyData>(); | ||
203 | } | ||
204 | |||
205 | public bool AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason) | ||
206 | { | ||
207 | string agentFullID = AgentID; | ||
208 | m_log.DebugFormat("[Groups.RemoteConnector]: Add agent {0} to group {1}", agentFullID, GroupID); | ||
209 | string r = string.Empty; | ||
210 | |||
211 | bool success = m_CacheWrapper.AddAgentToGroup(RequestingAgentID, AgentID, GroupID, delegate | ||
212 | { | ||
213 | return m_GroupsService.AddAgentToGroup(RequestingAgentID, agentFullID, GroupID, RoleID, token, out r); | ||
214 | }); | ||
215 | |||
216 | reason = r; | ||
217 | return success; | ||
218 | } | ||
219 | |||
220 | public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID) | ||
221 | { | ||
222 | m_CacheWrapper.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID, delegate | ||
223 | { | ||
224 | m_GroupsService.RemoveAgentFromGroup(RequestingAgentID, AgentID, GroupID); | ||
225 | }); | ||
226 | |||
227 | } | ||
228 | |||
229 | public void SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID) | ||
230 | { | ||
231 | m_CacheWrapper.SetAgentActiveGroup(AgentID, delegate | ||
232 | { | ||
233 | return m_GroupsService.SetAgentActiveGroup(RequestingAgentID, AgentID, GroupID); | ||
234 | }); | ||
235 | } | ||
236 | |||
237 | public ExtendedGroupMembershipData GetAgentActiveMembership(string RequestingAgentID, string AgentID) | ||
238 | { | ||
239 | return m_CacheWrapper.GetAgentActiveMembership(AgentID, delegate | ||
240 | { | ||
241 | return m_GroupsService.GetMembership(RequestingAgentID, AgentID, UUID.Zero); | ||
242 | }); | ||
243 | } | ||
244 | |||
245 | public ExtendedGroupMembershipData GetAgentGroupMembership(string RequestingAgentID, string AgentID, UUID GroupID) | ||
246 | { | ||
247 | return m_CacheWrapper.GetAgentGroupMembership(AgentID, GroupID, delegate | ||
248 | { | ||
249 | return m_GroupsService.GetMembership(RequestingAgentID, AgentID, GroupID); | ||
250 | }); | ||
251 | } | ||
252 | |||
253 | public List<GroupMembershipData> GetAgentGroupMemberships(string RequestingAgentID, string AgentID) | ||
254 | { | ||
255 | return m_CacheWrapper.GetAgentGroupMemberships(AgentID, delegate | ||
256 | { | ||
257 | return m_GroupsService.GetMemberships(RequestingAgentID, AgentID); | ||
258 | }); | ||
259 | } | ||
260 | |||
261 | |||
262 | public List<GroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID) | ||
263 | { | ||
264 | return m_CacheWrapper.GetGroupMembers(RequestingAgentID, GroupID, delegate | ||
265 | { | ||
266 | return m_GroupsService.GetGroupMembers(RequestingAgentID, GroupID); | ||
267 | }); | ||
268 | } | ||
269 | |||
270 | public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason) | ||
271 | { | ||
272 | string r = string.Empty; | ||
273 | bool success = m_CacheWrapper.AddGroupRole(groupID, roleID, description, name, powers, title, delegate | ||
274 | { | ||
275 | return m_GroupsService.AddGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers, out r); | ||
276 | }); | ||
277 | |||
278 | reason = r; | ||
279 | return success; | ||
280 | } | ||
281 | |||
282 | public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers) | ||
283 | { | ||
284 | return m_CacheWrapper.UpdateGroupRole(groupID, roleID, name, description, title, powers, delegate | ||
285 | { | ||
286 | return m_GroupsService.UpdateGroupRole(RequestingAgentID, groupID, roleID, name, description, title, powers); | ||
287 | }); | ||
288 | } | ||
289 | |||
290 | public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID) | ||
291 | { | ||
292 | m_CacheWrapper.RemoveGroupRole(RequestingAgentID, groupID, roleID, delegate | ||
293 | { | ||
294 | m_GroupsService.RemoveGroupRole(RequestingAgentID, groupID, roleID); | ||
295 | }); | ||
296 | } | ||
297 | |||
298 | public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID) | ||
299 | { | ||
300 | return m_CacheWrapper.GetGroupRoles(RequestingAgentID, GroupID, delegate | ||
301 | { | ||
302 | return m_GroupsService.GetGroupRoles(RequestingAgentID, GroupID); | ||
303 | }); | ||
304 | } | ||
305 | |||
306 | public List<GroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID) | ||
307 | { | ||
308 | return m_CacheWrapper.GetGroupRoleMembers(RequestingAgentID, GroupID, delegate | ||
309 | { | ||
310 | return m_GroupsService.GetGroupRoleMembers(RequestingAgentID, GroupID); | ||
311 | }); | ||
312 | } | ||
313 | |||
314 | public void AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) | ||
315 | { | ||
316 | m_CacheWrapper.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID, delegate | ||
317 | { | ||
318 | return m_GroupsService.AddAgentToGroupRole(RequestingAgentID, AgentID, GroupID, RoleID); | ||
319 | }); | ||
320 | } | ||
321 | |||
322 | public void RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) | ||
323 | { | ||
324 | m_CacheWrapper.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID, delegate | ||
325 | { | ||
326 | return m_GroupsService.RemoveAgentFromGroupRole(RequestingAgentID, AgentID, GroupID, RoleID); | ||
327 | }); | ||
328 | } | ||
329 | |||
330 | public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID) | ||
331 | { | ||
332 | return m_CacheWrapper.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID, delegate | ||
333 | { | ||
334 | return m_GroupsService.GetAgentGroupRoles(RequestingAgentID, AgentID, GroupID); ; | ||
335 | }); | ||
336 | } | ||
337 | |||
338 | public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID) | ||
339 | { | ||
340 | m_CacheWrapper.SetAgentActiveGroupRole(AgentID, GroupID, delegate | ||
341 | { | ||
342 | m_GroupsService.SetAgentActiveGroupRole(RequestingAgentID, AgentID, GroupID, RoleID); | ||
343 | }); | ||
344 | } | ||
345 | |||
346 | public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile) | ||
347 | { | ||
348 | m_CacheWrapper.UpdateMembership(AgentID, GroupID, AcceptNotices, ListInProfile, delegate | ||
349 | { | ||
350 | m_GroupsService.UpdateMembership(RequestingAgentID, AgentID, GroupID, AcceptNotices, ListInProfile); | ||
351 | }); | ||
352 | } | ||
353 | |||
354 | public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID) | ||
355 | { | ||
356 | return m_GroupsService.AddAgentToGroupInvite(RequestingAgentID, inviteID, groupID, roleID, agentID); | ||
357 | } | ||
358 | |||
359 | public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID) | ||
360 | { | ||
361 | return m_GroupsService.GetAgentToGroupInvite(RequestingAgentID, inviteID); | ||
362 | } | ||
363 | |||
364 | public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID) | ||
365 | { | ||
366 | m_GroupsService.RemoveAgentToGroupInvite(RequestingAgentID, inviteID); | ||
367 | } | ||
368 | |||
369 | public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, | ||
370 | bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID) | ||
371 | { | ||
372 | GroupNoticeInfo notice = new GroupNoticeInfo(); | ||
373 | notice.GroupID = groupID; | ||
374 | notice.Message = message; | ||
375 | notice.noticeData = new ExtendedGroupNoticeData(); | ||
376 | notice.noticeData.AttachmentItemID = attItemID; | ||
377 | notice.noticeData.AttachmentName = attName; | ||
378 | notice.noticeData.AttachmentOwnerID = attOwnerID.ToString(); | ||
379 | notice.noticeData.AttachmentType = attType; | ||
380 | notice.noticeData.FromName = fromName; | ||
381 | notice.noticeData.HasAttachment = hasAttachment; | ||
382 | notice.noticeData.NoticeID = noticeID; | ||
383 | notice.noticeData.Subject = subject; | ||
384 | notice.noticeData.Timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
385 | |||
386 | return m_CacheWrapper.AddGroupNotice(groupID, noticeID, notice, delegate | ||
387 | { | ||
388 | return m_GroupsService.AddGroupNotice(RequestingAgentID, groupID, noticeID, fromName, subject, message, | ||
389 | hasAttachment, attType, attName, attItemID, attOwnerID); | ||
390 | }); | ||
391 | } | ||
392 | |||
393 | public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID) | ||
394 | { | ||
395 | return m_CacheWrapper.GetGroupNotice(noticeID, delegate | ||
396 | { | ||
397 | return m_GroupsService.GetGroupNotice(RequestingAgentID, noticeID); | ||
398 | }); | ||
399 | } | ||
400 | |||
401 | public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID) | ||
402 | { | ||
403 | return m_CacheWrapper.GetGroupNotices(GroupID, delegate | ||
404 | { | ||
405 | return m_GroupsService.GetGroupNotices(RequestingAgentID, GroupID); | ||
406 | }); | ||
407 | } | ||
408 | |||
409 | public void ResetAgentGroupChatSessions(string agentID) | ||
410 | { | ||
411 | } | ||
412 | |||
413 | public bool hasAgentBeenInvitedToGroupChatSession(string agentID, UUID groupID) | ||
414 | { | ||
415 | return false; | ||
416 | } | ||
417 | |||
418 | public bool hasAgentDroppedGroupChatSession(string agentID, UUID groupID) | ||
419 | { | ||
420 | return false; | ||
421 | } | ||
422 | |||
423 | public void AgentDroppedFromGroupChatSession(string agentID, UUID groupID) | ||
424 | { | ||
425 | } | ||
426 | |||
427 | public void AgentInvitedToGroupChatSession(string agentID, UUID groupID) | ||
428 | { | ||
429 | } | ||
430 | |||
431 | #endregion | ||
432 | } | ||
433 | |||
434 | } | ||
diff --git a/OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs b/OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs new file mode 100644 index 0000000..f991d01 --- /dev/null +++ b/OpenSim/Addons/Groups/Remote/GroupsServiceRobustConnector.cs | |||
@@ -0,0 +1,760 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using System.Xml; | ||
32 | using System.Collections.Generic; | ||
33 | using System.IO; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | using OpenSim.Server.Handlers.Base; | ||
40 | using log4net; | ||
41 | using OpenMetaverse; | ||
42 | |||
43 | namespace OpenSim.Groups | ||
44 | { | ||
45 | public class GroupsServiceRobustConnector : ServiceConnector | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private GroupsService m_GroupsService; | ||
50 | private string m_ConfigName = "Groups"; | ||
51 | |||
52 | public GroupsServiceRobustConnector(IConfigSource config, IHttpServer server, string configName) : | ||
53 | base(config, server, configName) | ||
54 | { | ||
55 | if (configName != String.Empty) | ||
56 | m_ConfigName = configName; | ||
57 | |||
58 | m_log.DebugFormat("[Groups.RobustConnector]: Starting with config name {0}", m_ConfigName); | ||
59 | |||
60 | m_GroupsService = new GroupsService(config); | ||
61 | |||
62 | server.AddStreamHandler(new GroupsServicePostHandler(m_GroupsService)); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public class GroupsServicePostHandler : BaseStreamHandler | ||
67 | { | ||
68 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
69 | |||
70 | private GroupsService m_GroupsService; | ||
71 | |||
72 | public GroupsServicePostHandler(GroupsService service) : | ||
73 | base("POST", "/groups") | ||
74 | { | ||
75 | m_GroupsService = service; | ||
76 | } | ||
77 | |||
78 | public override byte[] Handle(string path, Stream requestData, | ||
79 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
80 | { | ||
81 | StreamReader sr = new StreamReader(requestData); | ||
82 | string body = sr.ReadToEnd(); | ||
83 | sr.Close(); | ||
84 | body = body.Trim(); | ||
85 | |||
86 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
87 | |||
88 | try | ||
89 | { | ||
90 | Dictionary<string, object> request = | ||
91 | ServerUtils.ParseQueryString(body); | ||
92 | |||
93 | if (!request.ContainsKey("METHOD")) | ||
94 | return FailureResult(); | ||
95 | |||
96 | string method = request["METHOD"].ToString(); | ||
97 | request.Remove("METHOD"); | ||
98 | |||
99 | m_log.DebugFormat("[Groups.Handler]: {0}", method); | ||
100 | switch (method) | ||
101 | { | ||
102 | case "PUTGROUP": | ||
103 | return HandleAddOrUpdateGroup(request); | ||
104 | case "GETGROUP": | ||
105 | return HandleGetGroup(request); | ||
106 | case "ADDAGENTTOGROUP": | ||
107 | return HandleAddAgentToGroup(request); | ||
108 | case "REMOVEAGENTFROMGROUP": | ||
109 | return HandleRemoveAgentFromGroup(request); | ||
110 | case "GETMEMBERSHIP": | ||
111 | return HandleGetMembership(request); | ||
112 | case "GETGROUPMEMBERS": | ||
113 | return HandleGetGroupMembers(request); | ||
114 | case "PUTROLE": | ||
115 | return HandlePutRole(request); | ||
116 | case "REMOVEROLE": | ||
117 | return HandleRemoveRole(request); | ||
118 | case "GETGROUPROLES": | ||
119 | return HandleGetGroupRoles(request); | ||
120 | case "GETROLEMEMBERS": | ||
121 | return HandleGetRoleMembers(request); | ||
122 | case "AGENTROLE": | ||
123 | return HandleAgentRole(request); | ||
124 | case "GETAGENTROLES": | ||
125 | return HandleGetAgentRoles(request); | ||
126 | case "SETACTIVE": | ||
127 | return HandleSetActive(request); | ||
128 | case "UPDATEMEMBERSHIP": | ||
129 | return HandleUpdateMembership(request); | ||
130 | case "INVITE": | ||
131 | return HandleInvite(request); | ||
132 | case "ADDNOTICE": | ||
133 | return HandleAddNotice(request); | ||
134 | case "GETNOTICES": | ||
135 | return HandleGetNotices(request); | ||
136 | } | ||
137 | m_log.DebugFormat("[GROUPS HANDLER]: unknown method request: {0}", method); | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | m_log.DebugFormat("[GROUPS HANDLER]: Exception {0}", e.StackTrace); | ||
142 | } | ||
143 | |||
144 | return FailureResult(); | ||
145 | } | ||
146 | |||
147 | byte[] HandleAddOrUpdateGroup(Dictionary<string, object> request) | ||
148 | { | ||
149 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
150 | |||
151 | ExtendedGroupRecord grec = GroupsDataUtils.GroupRecord(request); | ||
152 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("OP")) | ||
153 | NullResult(result, "Bad network data"); | ||
154 | |||
155 | else | ||
156 | { | ||
157 | string RequestingAgentID = request["RequestingAgentID"].ToString(); | ||
158 | string reason = string.Empty; | ||
159 | string op = request["OP"].ToString(); | ||
160 | if (op == "ADD") | ||
161 | { | ||
162 | grec.GroupID = m_GroupsService.CreateGroup(RequestingAgentID, grec.GroupName, grec.Charter, grec.ShowInList, grec.GroupPicture, grec.MembershipFee, | ||
163 | grec.OpenEnrollment, grec.AllowPublish, grec.MaturePublish, grec.FounderID, out reason); | ||
164 | |||
165 | } | ||
166 | else if (op == "UPDATE") | ||
167 | { | ||
168 | m_GroupsService.UpdateGroup(RequestingAgentID, grec.GroupID, grec.Charter, grec.ShowInList, grec.GroupPicture, grec.MembershipFee, | ||
169 | grec.OpenEnrollment, grec.AllowPublish, grec.MaturePublish); | ||
170 | |||
171 | } | ||
172 | |||
173 | grec = m_GroupsService.GetGroupRecord(RequestingAgentID, grec.GroupID); | ||
174 | if (grec == null) | ||
175 | NullResult(result, "Internal Error"); | ||
176 | else | ||
177 | result["RESULT"] = GroupsDataUtils.GroupRecord(grec); | ||
178 | } | ||
179 | |||
180 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
181 | |||
182 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
183 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
184 | } | ||
185 | |||
186 | byte[] HandleGetGroup(Dictionary<string, object> request) | ||
187 | { | ||
188 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
189 | |||
190 | if (!request.ContainsKey("RequestingAgentID")) | ||
191 | NullResult(result, "Bad network data"); | ||
192 | else | ||
193 | { | ||
194 | string RequestingAgentID = request["RequestingAgentID"].ToString(); | ||
195 | ExtendedGroupRecord grec = null; | ||
196 | if (request.ContainsKey("GroupID")) | ||
197 | { | ||
198 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
199 | grec = m_GroupsService.GetGroupRecord(RequestingAgentID, groupID); | ||
200 | } | ||
201 | else if (request.ContainsKey("Name")) | ||
202 | { | ||
203 | string name = request["Name"].ToString(); | ||
204 | grec = m_GroupsService.GetGroupRecord(RequestingAgentID, name); | ||
205 | } | ||
206 | |||
207 | if (grec == null) | ||
208 | NullResult(result, "Group not found"); | ||
209 | else | ||
210 | result["RESULT"] = GroupsDataUtils.GroupRecord(grec); | ||
211 | } | ||
212 | |||
213 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
214 | |||
215 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
216 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
217 | } | ||
218 | |||
219 | byte[] HandleAddAgentToGroup(Dictionary<string, object> request) | ||
220 | { | ||
221 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
222 | |||
223 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || | ||
224 | !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID")) | ||
225 | NullResult(result, "Bad network data"); | ||
226 | else | ||
227 | { | ||
228 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
229 | UUID roleID = new UUID(request["RoleID"].ToString()); | ||
230 | string agentID = request["AgentID"].ToString(); | ||
231 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
232 | string token = string.Empty; | ||
233 | string reason = string.Empty; | ||
234 | |||
235 | if (request.ContainsKey("AccessToken")) | ||
236 | token = request["AccessToken"].ToString(); | ||
237 | |||
238 | if (!m_GroupsService.AddAgentToGroup(requestingAgentID, agentID, groupID, roleID, token, out reason)) | ||
239 | NullResult(result, reason); | ||
240 | else | ||
241 | { | ||
242 | GroupMembershipData membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID); | ||
243 | if (membership == null) | ||
244 | NullResult(result, "Internal error"); | ||
245 | else | ||
246 | result["RESULT"] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)membership); | ||
247 | } | ||
248 | } | ||
249 | |||
250 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
251 | |||
252 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
253 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
254 | } | ||
255 | |||
256 | byte[] HandleRemoveAgentFromGroup(Dictionary<string, object> request) | ||
257 | { | ||
258 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
259 | |||
260 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || !request.ContainsKey("GroupID")) | ||
261 | NullResult(result, "Bad network data"); | ||
262 | else | ||
263 | { | ||
264 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
265 | string agentID = request["AgentID"].ToString(); | ||
266 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
267 | string reason = string.Empty; | ||
268 | |||
269 | m_GroupsService.RemoveAgentFromGroup(requestingAgentID, agentID, groupID); | ||
270 | } | ||
271 | |||
272 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
273 | result["RESULT"] = "true"; | ||
274 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
275 | } | ||
276 | |||
277 | byte[] HandleGetMembership(Dictionary<string, object> request) | ||
278 | { | ||
279 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
280 | |||
281 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID")) | ||
282 | NullResult(result, "Bad network data"); | ||
283 | else | ||
284 | { | ||
285 | string agentID = request["AgentID"].ToString(); | ||
286 | UUID groupID = UUID.Zero; | ||
287 | if (request.ContainsKey("GroupID")) | ||
288 | groupID = new UUID(request["GroupID"].ToString()); | ||
289 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
290 | bool all = request.ContainsKey("ALL"); | ||
291 | |||
292 | if (!all) | ||
293 | { | ||
294 | ExtendedGroupMembershipData membership = null; | ||
295 | if (groupID == UUID.Zero) | ||
296 | { | ||
297 | membership = m_GroupsService.GetAgentActiveMembership(requestingAgentID, agentID); | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | membership = m_GroupsService.GetAgentGroupMembership(requestingAgentID, agentID, groupID); | ||
302 | } | ||
303 | |||
304 | if (membership == null) | ||
305 | NullResult(result, "No such membership"); | ||
306 | else | ||
307 | result["RESULT"] = GroupsDataUtils.GroupMembershipData(membership); | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | List<GroupMembershipData> memberships = m_GroupsService.GetAgentGroupMemberships(requestingAgentID, agentID); | ||
312 | if (memberships == null || (memberships != null && memberships.Count == 0)) | ||
313 | { | ||
314 | NullResult(result, "No memberships"); | ||
315 | } | ||
316 | else | ||
317 | { | ||
318 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
319 | int i = 0; | ||
320 | foreach (GroupMembershipData m in memberships) | ||
321 | dict["m-" + i++] = GroupsDataUtils.GroupMembershipData((ExtendedGroupMembershipData)m); | ||
322 | |||
323 | result["RESULT"] = dict; | ||
324 | } | ||
325 | } | ||
326 | } | ||
327 | |||
328 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
329 | |||
330 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
331 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
332 | } | ||
333 | |||
334 | byte[] HandleGetGroupMembers(Dictionary<string, object> request) | ||
335 | { | ||
336 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
337 | |||
338 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")) | ||
339 | NullResult(result, "Bad network data"); | ||
340 | else | ||
341 | { | ||
342 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
343 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
344 | |||
345 | List<ExtendedGroupMembersData> members = m_GroupsService.GetGroupMembers(requestingAgentID, groupID); | ||
346 | if (members == null || (members != null && members.Count == 0)) | ||
347 | { | ||
348 | NullResult(result, "No members"); | ||
349 | } | ||
350 | else | ||
351 | { | ||
352 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
353 | int i = 0; | ||
354 | foreach (ExtendedGroupMembersData m in members) | ||
355 | { | ||
356 | dict["m-" + i++] = GroupsDataUtils.GroupMembersData(m); | ||
357 | } | ||
358 | |||
359 | result["RESULT"] = dict; | ||
360 | } | ||
361 | } | ||
362 | |||
363 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
364 | |||
365 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
366 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
367 | } | ||
368 | |||
369 | byte[] HandlePutRole(Dictionary<string, object> request) | ||
370 | { | ||
371 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
372 | |||
373 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID") || | ||
374 | !request.ContainsKey("Name") || !request.ContainsKey("Description") || !request.ContainsKey("Title") || | ||
375 | !request.ContainsKey("Powers") || !request.ContainsKey("OP")) | ||
376 | NullResult(result, "Bad network data"); | ||
377 | |||
378 | else | ||
379 | { | ||
380 | string op = request["OP"].ToString(); | ||
381 | string reason = string.Empty; | ||
382 | |||
383 | bool success = false; | ||
384 | if (op == "ADD") | ||
385 | success = m_GroupsService.AddGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), | ||
386 | new UUID(request["RoleID"].ToString()), request["Name"].ToString(), request["Description"].ToString(), | ||
387 | request["Title"].ToString(), UInt64.Parse(request["Powers"].ToString()), out reason); | ||
388 | |||
389 | else if (op == "UPDATE") | ||
390 | success = m_GroupsService.UpdateGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), | ||
391 | new UUID(request["RoleID"].ToString()), request["Name"].ToString(), request["Description"].ToString(), | ||
392 | request["Title"].ToString(), UInt64.Parse(request["Powers"].ToString())); | ||
393 | |||
394 | result["RESULT"] = success.ToString(); | ||
395 | } | ||
396 | |||
397 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
398 | |||
399 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
400 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
401 | } | ||
402 | |||
403 | byte[] HandleRemoveRole(Dictionary<string, object> request) | ||
404 | { | ||
405 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
406 | |||
407 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID")) | ||
408 | NullResult(result, "Bad network data"); | ||
409 | |||
410 | else | ||
411 | { | ||
412 | m_GroupsService.RemoveGroupRole(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), | ||
413 | new UUID(request["RoleID"].ToString())); | ||
414 | result["RESULT"] = "true"; | ||
415 | } | ||
416 | |||
417 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
418 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
419 | } | ||
420 | |||
421 | byte[] HandleGetGroupRoles(Dictionary<string, object> request) | ||
422 | { | ||
423 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
424 | |||
425 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")) | ||
426 | NullResult(result, "Bad network data"); | ||
427 | else | ||
428 | { | ||
429 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
430 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
431 | |||
432 | List<GroupRolesData> roles = m_GroupsService.GetGroupRoles(requestingAgentID, groupID); | ||
433 | if (roles == null || (roles != null && roles.Count == 0)) | ||
434 | { | ||
435 | NullResult(result, "No members"); | ||
436 | } | ||
437 | else | ||
438 | { | ||
439 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
440 | int i = 0; | ||
441 | foreach (GroupRolesData r in roles) | ||
442 | dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r); | ||
443 | |||
444 | result["RESULT"] = dict; | ||
445 | } | ||
446 | } | ||
447 | |||
448 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
449 | |||
450 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
451 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
452 | } | ||
453 | |||
454 | byte[] HandleGetRoleMembers(Dictionary<string, object> request) | ||
455 | { | ||
456 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
457 | |||
458 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID")) | ||
459 | NullResult(result, "Bad network data"); | ||
460 | else | ||
461 | { | ||
462 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
463 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
464 | |||
465 | List<ExtendedGroupRoleMembersData> rmembers = m_GroupsService.GetGroupRoleMembers(requestingAgentID, groupID); | ||
466 | if (rmembers == null || (rmembers != null && rmembers.Count == 0)) | ||
467 | { | ||
468 | NullResult(result, "No members"); | ||
469 | } | ||
470 | else | ||
471 | { | ||
472 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
473 | int i = 0; | ||
474 | foreach (ExtendedGroupRoleMembersData rm in rmembers) | ||
475 | dict["rm-" + i++] = GroupsDataUtils.GroupRoleMembersData(rm); | ||
476 | |||
477 | result["RESULT"] = dict; | ||
478 | } | ||
479 | } | ||
480 | |||
481 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
482 | |||
483 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
484 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
485 | } | ||
486 | |||
487 | byte[] HandleAgentRole(Dictionary<string, object> request) | ||
488 | { | ||
489 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
490 | |||
491 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("RoleID") || | ||
492 | !request.ContainsKey("AgentID") || !request.ContainsKey("OP")) | ||
493 | NullResult(result, "Bad network data"); | ||
494 | |||
495 | else | ||
496 | { | ||
497 | string op = request["OP"].ToString(); | ||
498 | string reason = string.Empty; | ||
499 | |||
500 | bool success = false; | ||
501 | if (op == "ADD") | ||
502 | success = m_GroupsService.AddAgentToGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), | ||
503 | new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString())); | ||
504 | |||
505 | else if (op == "DELETE") | ||
506 | success = m_GroupsService.RemoveAgentFromGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), | ||
507 | new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString())); | ||
508 | |||
509 | result["RESULT"] = success.ToString(); | ||
510 | } | ||
511 | |||
512 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
513 | |||
514 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
515 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
516 | } | ||
517 | |||
518 | byte[] HandleGetAgentRoles(Dictionary<string, object> request) | ||
519 | { | ||
520 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
521 | |||
522 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("AgentID")) | ||
523 | NullResult(result, "Bad network data"); | ||
524 | else | ||
525 | { | ||
526 | UUID groupID = new UUID(request["GroupID"].ToString()); | ||
527 | string agentID = request["AgentID"].ToString(); | ||
528 | string requestingAgentID = request["RequestingAgentID"].ToString(); | ||
529 | |||
530 | List<GroupRolesData> roles = m_GroupsService.GetAgentGroupRoles(requestingAgentID, agentID, groupID); | ||
531 | if (roles == null || (roles != null && roles.Count == 0)) | ||
532 | { | ||
533 | NullResult(result, "No members"); | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
538 | int i = 0; | ||
539 | foreach (GroupRolesData r in roles) | ||
540 | dict["r-" + i++] = GroupsDataUtils.GroupRolesData(r); | ||
541 | |||
542 | result["RESULT"] = dict; | ||
543 | } | ||
544 | } | ||
545 | |||
546 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
547 | |||
548 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
549 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
550 | } | ||
551 | |||
552 | byte[] HandleSetActive(Dictionary<string, object> request) | ||
553 | { | ||
554 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
555 | |||
556 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || | ||
557 | !request.ContainsKey("AgentID") || !request.ContainsKey("OP")) | ||
558 | { | ||
559 | NullResult(result, "Bad network data"); | ||
560 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
561 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
562 | } | ||
563 | else | ||
564 | { | ||
565 | string op = request["OP"].ToString(); | ||
566 | string reason = string.Empty; | ||
567 | |||
568 | if (op == "GROUP") | ||
569 | { | ||
570 | ExtendedGroupMembershipData group = m_GroupsService.SetAgentActiveGroup(request["RequestingAgentID"].ToString(), | ||
571 | request["AgentID"].ToString(), new UUID(request["GroupID"].ToString())); | ||
572 | |||
573 | if (group == null) | ||
574 | NullResult(result, "Internal error"); | ||
575 | else | ||
576 | result["RESULT"] = GroupsDataUtils.GroupMembershipData(group); | ||
577 | |||
578 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
579 | |||
580 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
581 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
582 | |||
583 | } | ||
584 | else if (op == "ROLE" && request.ContainsKey("RoleID")) | ||
585 | { | ||
586 | m_GroupsService.SetAgentActiveGroupRole(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), | ||
587 | new UUID(request["GroupID"].ToString()), new UUID(request["RoleID"].ToString())); | ||
588 | result["RESULT"] = "true"; | ||
589 | } | ||
590 | |||
591 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
592 | } | ||
593 | |||
594 | } | ||
595 | |||
596 | byte[] HandleUpdateMembership(Dictionary<string, object> request) | ||
597 | { | ||
598 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
599 | |||
600 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("AgentID") || !request.ContainsKey("GroupID") || | ||
601 | !request.ContainsKey("AcceptNotices") || !request.ContainsKey("ListInProfile")) | ||
602 | NullResult(result, "Bad network data"); | ||
603 | |||
604 | else | ||
605 | { | ||
606 | m_GroupsService.UpdateMembership(request["RequestingAgentID"].ToString(), request["AgentID"].ToString(), new UUID(request["GroupID"].ToString()), | ||
607 | bool.Parse(request["AcceptNotices"].ToString()), bool.Parse(request["ListInProfile"].ToString())); | ||
608 | |||
609 | result["RESULT"] = "true"; | ||
610 | } | ||
611 | |||
612 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
613 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
614 | } | ||
615 | |||
616 | byte[] HandleInvite(Dictionary<string, object> request) | ||
617 | { | ||
618 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
619 | |||
620 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("InviteID")) | ||
621 | { | ||
622 | NullResult(result, "Bad network data"); | ||
623 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
624 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
625 | } | ||
626 | else | ||
627 | { | ||
628 | string op = request["OP"].ToString(); | ||
629 | string reason = string.Empty; | ||
630 | |||
631 | if (op == "ADD" && request.ContainsKey("GroupID") && request.ContainsKey("RoleID") && request.ContainsKey("AgentID")) | ||
632 | { | ||
633 | bool success = m_GroupsService.AddAgentToGroupInvite(request["RequestingAgentID"].ToString(), | ||
634 | new UUID(request["InviteID"].ToString()), new UUID(request["GroupID"].ToString()), | ||
635 | new UUID(request["RoleID"].ToString()), request["AgentID"].ToString()); | ||
636 | |||
637 | result["RESULT"] = success.ToString(); | ||
638 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
639 | |||
640 | } | ||
641 | else if (op == "DELETE") | ||
642 | { | ||
643 | m_GroupsService.RemoveAgentToGroupInvite(request["RequestingAgentID"].ToString(), new UUID(request["InviteID"].ToString())); | ||
644 | result["RESULT"] = "true"; | ||
645 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
646 | } | ||
647 | else if (op == "GET") | ||
648 | { | ||
649 | GroupInviteInfo invite = m_GroupsService.GetAgentToGroupInvite(request["RequestingAgentID"].ToString(), | ||
650 | new UUID(request["InviteID"].ToString())); | ||
651 | |||
652 | result["RESULT"] = GroupsDataUtils.GroupInviteInfo(invite); | ||
653 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
654 | } | ||
655 | |||
656 | NullResult(result, "Bad OP in request"); | ||
657 | return Util.UTF8NoBomEncoding.GetBytes(ServerUtils.BuildXmlResponse(result)); | ||
658 | } | ||
659 | |||
660 | } | ||
661 | |||
662 | byte[] HandleAddNotice(Dictionary<string, object> request) | ||
663 | { | ||
664 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
665 | |||
666 | if (!request.ContainsKey("RequestingAgentID") || !request.ContainsKey("GroupID") || !request.ContainsKey("NoticeID") || | ||
667 | !request.ContainsKey("FromName") || !request.ContainsKey("Subject") || !request.ContainsKey("Message") || | ||
668 | !request.ContainsKey("HasAttachment")) | ||
669 | NullResult(result, "Bad network data"); | ||
670 | |||
671 | else | ||
672 | { | ||
673 | |||
674 | bool hasAtt = bool.Parse(request["HasAttachment"].ToString()); | ||
675 | byte attType = 0; | ||
676 | string attName = string.Empty; | ||
677 | string attOwner = string.Empty; | ||
678 | UUID attItem = UUID.Zero; | ||
679 | if (request.ContainsKey("AttachmentType")) | ||
680 | attType = byte.Parse(request["AttachmentType"].ToString()); | ||
681 | if (request.ContainsKey("AttachmentName")) | ||
682 | attName = request["AttachmentName"].ToString(); | ||
683 | if (request.ContainsKey("AttachmentItemID")) | ||
684 | attItem = new UUID(request["AttachmentItemID"].ToString()); | ||
685 | if (request.ContainsKey("AttachmentOwnerID")) | ||
686 | attOwner = request["AttachmentOwnerID"].ToString(); | ||
687 | |||
688 | bool success = m_GroupsService.AddGroupNotice(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString()), | ||
689 | new UUID(request["NoticeID"].ToString()), request["FromName"].ToString(), request["Subject"].ToString(), | ||
690 | request["Message"].ToString(), hasAtt, attType, attName, attItem, attOwner); | ||
691 | |||
692 | result["RESULT"] = success.ToString(); | ||
693 | } | ||
694 | |||
695 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
696 | |||
697 | //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString); | ||
698 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
699 | } | ||
700 | |||
701 | byte[] HandleGetNotices(Dictionary<string, object> request) | ||
702 | { | ||
703 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
704 | |||
705 | if (!request.ContainsKey("RequestingAgentID")) | ||
706 | NullResult(result, "Bad network data"); | ||
707 | |||
708 | else if (request.ContainsKey("NoticeID")) // just one | ||
709 | { | ||
710 | GroupNoticeInfo notice = m_GroupsService.GetGroupNotice(request["RequestingAgentID"].ToString(), new UUID(request["NoticeID"].ToString())); | ||
711 | |||
712 | if (notice == null) | ||
713 | NullResult(result, "NO such notice"); | ||
714 | else | ||
715 | result["RESULT"] = GroupsDataUtils.GroupNoticeInfo(notice); | ||
716 | |||
717 | } | ||
718 | else if (request.ContainsKey("GroupID")) // all notices for group | ||
719 | { | ||
720 | List<ExtendedGroupNoticeData> notices = m_GroupsService.GetGroupNotices(request["RequestingAgentID"].ToString(), new UUID(request["GroupID"].ToString())); | ||
721 | |||
722 | if (notices == null || (notices != null && notices.Count == 0)) | ||
723 | NullResult(result, "No notices"); | ||
724 | else | ||
725 | { | ||
726 | Dictionary<string, object> dict = new Dictionary<string, object>(); | ||
727 | int i = 0; | ||
728 | foreach (ExtendedGroupNoticeData n in notices) | ||
729 | dict["n-" + i++] = GroupsDataUtils.GroupNoticeData(n); | ||
730 | |||
731 | result["RESULT"] = dict; | ||
732 | } | ||
733 | |||
734 | } | ||
735 | else | ||
736 | NullResult(result, "Bad OP in request"); | ||
737 | |||
738 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
739 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
740 | } | ||
741 | |||
742 | |||
743 | #region Helpers | ||
744 | |||
745 | private void NullResult(Dictionary<string, object> result, string reason) | ||
746 | { | ||
747 | result["RESULT"] = "NULL"; | ||
748 | result["REASON"] = reason; | ||
749 | } | ||
750 | |||
751 | private byte[] FailureResult() | ||
752 | { | ||
753 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
754 | NullResult(result, "Unknown method"); | ||
755 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
756 | return Util.UTF8NoBomEncoding.GetBytes(xmlString); | ||
757 | } | ||
758 | #endregion | ||
759 | } | ||
760 | } | ||