diff options
author | Michael Cortez | 2009-08-05 11:15:53 -0700 |
---|---|---|
committer | Michael Cortez | 2009-08-05 11:15:53 -0700 |
commit | 989517725d02d8a2d216e599856eb2625b454e25 (patch) | |
tree | 74f31eac6e685361ff5d469cdc6992158964666f /OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs | |
parent | force back the Regions directory, which because it was empty in svn never made (diff) | |
download | opensim-SC_OLD-989517725d02d8a2d216e599856eb2625b454e25.zip opensim-SC_OLD-989517725d02d8a2d216e599856eb2625b454e25.tar.gz opensim-SC_OLD-989517725d02d8a2d216e599856eb2625b454e25.tar.bz2 opensim-SC_OLD-989517725d02d8a2d216e599856eb2625b454e25.tar.xz |
Begin refactoring XmlRpcGroups to a more generic Groups module that allows for replaceable Groups Service Connectors.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs | 916 |
1 files changed, 0 insertions, 916 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs deleted file mode 100644 index 1d4cde5..0000000 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupData.cs +++ /dev/null | |||
@@ -1,916 +0,0 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | //using System.Text; | ||
33 | |||
34 | using Nwc.XmlRpc; | ||
35 | |||
36 | using log4net; | ||
37 | // using Nini.Config; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | |||
42 | using OpenSim.Framework; | ||
43 | //using OpenSim.Region.Framework.Interfaces; | ||
44 | |||
45 | namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | ||
46 | { | ||
47 | public class XmlRpcGroupDataProvider : IGroupDataProvider | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private string m_serviceURL = string.Empty; | ||
53 | |||
54 | public const GroupPowers m_DefaultEveryonePowers = GroupPowers.AllowSetHome | | ||
55 | GroupPowers.Accountable | | ||
56 | GroupPowers.JoinChat | | ||
57 | GroupPowers.AllowVoiceChat | | ||
58 | GroupPowers.ReceiveNotices | | ||
59 | GroupPowers.StartProposal | | ||
60 | GroupPowers.VoteOnProposal; | ||
61 | |||
62 | private bool m_disableKeepAlive = false; | ||
63 | |||
64 | private string m_groupReadKey = string.Empty; | ||
65 | private string m_groupWriteKey = string.Empty; | ||
66 | |||
67 | public XmlRpcGroupDataProvider(string serviceURL, bool disableKeepAlive, string groupReadKey, string groupWriteKey) | ||
68 | { | ||
69 | m_serviceURL = serviceURL.Trim(); | ||
70 | m_disableKeepAlive = disableKeepAlive; | ||
71 | |||
72 | if ((serviceURL == null) || | ||
73 | (serviceURL == string.Empty)) | ||
74 | { | ||
75 | throw new Exception("Please specify a valid ServiceURL for XmlRpcGroupDataProvider in OpenSim.ini, [Groups], XmlRpcServiceURL"); | ||
76 | } | ||
77 | |||
78 | m_groupReadKey = groupReadKey; | ||
79 | m_groupWriteKey = groupWriteKey; | ||
80 | } | ||
81 | |||
82 | /// <summary> | ||
83 | /// Create a Group, including Everyone and Owners Role, place FounderID in both groups, select Owner as selected role, and newly created group as agent's active role. | ||
84 | /// </summary> | ||
85 | public UUID CreateGroup(GroupRequestID requestID, string name, string charter, bool showInList, UUID insigniaID, | ||
86 | int membershipFee, bool openEnrollment, bool allowPublish, | ||
87 | bool maturePublish, UUID founderID) | ||
88 | { | ||
89 | UUID GroupID = UUID.Random(); | ||
90 | UUID OwnerRoleID = UUID.Random(); | ||
91 | |||
92 | Hashtable param = new Hashtable(); | ||
93 | param["GroupID"] = GroupID.ToString(); | ||
94 | param["Name"] = name; | ||
95 | param["Charter"] = charter; | ||
96 | param["ShowInList"] = showInList == true ? 1 : 0; | ||
97 | param["InsigniaID"] = insigniaID.ToString(); | ||
98 | param["MembershipFee"] = 0; | ||
99 | param["OpenEnrollment"] = openEnrollment == true ? 1 : 0; | ||
100 | param["AllowPublish"] = allowPublish == true ? 1 : 0; | ||
101 | param["MaturePublish"] = maturePublish == true ? 1 : 0; | ||
102 | param["FounderID"] = founderID.ToString(); | ||
103 | param["EveryonePowers"] = ((ulong)m_DefaultEveryonePowers).ToString(); | ||
104 | param["OwnerRoleID"] = OwnerRoleID.ToString(); | ||
105 | |||
106 | // Would this be cleaner as (GroupPowers)ulong.MaxValue; | ||
107 | GroupPowers OwnerPowers = GroupPowers.Accountable | ||
108 | | GroupPowers.AllowEditLand | ||
109 | | GroupPowers.AllowFly | ||
110 | | GroupPowers.AllowLandmark | ||
111 | | GroupPowers.AllowRez | ||
112 | | GroupPowers.AllowSetHome | ||
113 | | GroupPowers.AllowVoiceChat | ||
114 | | GroupPowers.AssignMember | ||
115 | | GroupPowers.AssignMemberLimited | ||
116 | | GroupPowers.ChangeActions | ||
117 | | GroupPowers.ChangeIdentity | ||
118 | | GroupPowers.ChangeMedia | ||
119 | | GroupPowers.ChangeOptions | ||
120 | | GroupPowers.CreateRole | ||
121 | | GroupPowers.DeedObject | ||
122 | | GroupPowers.DeleteRole | ||
123 | | GroupPowers.Eject | ||
124 | | GroupPowers.FindPlaces | ||
125 | | GroupPowers.Invite | ||
126 | | GroupPowers.JoinChat | ||
127 | | GroupPowers.LandChangeIdentity | ||
128 | | GroupPowers.LandDeed | ||
129 | | GroupPowers.LandDivideJoin | ||
130 | | GroupPowers.LandEdit | ||
131 | | GroupPowers.LandEjectAndFreeze | ||
132 | | GroupPowers.LandGardening | ||
133 | | GroupPowers.LandManageAllowed | ||
134 | | GroupPowers.LandManageBanned | ||
135 | | GroupPowers.LandManagePasses | ||
136 | | GroupPowers.LandOptions | ||
137 | | GroupPowers.LandRelease | ||
138 | | GroupPowers.LandSetSale | ||
139 | | GroupPowers.ModerateChat | ||
140 | | GroupPowers.ObjectManipulate | ||
141 | | GroupPowers.ObjectSetForSale | ||
142 | | GroupPowers.ReceiveNotices | ||
143 | | GroupPowers.RemoveMember | ||
144 | | GroupPowers.ReturnGroupOwned | ||
145 | | GroupPowers.ReturnGroupSet | ||
146 | | GroupPowers.ReturnNonGroup | ||
147 | | GroupPowers.RoleProperties | ||
148 | | GroupPowers.SendNotices | ||
149 | | GroupPowers.SetLandingPoint | ||
150 | | GroupPowers.StartProposal | ||
151 | | GroupPowers.VoteOnProposal; | ||
152 | param["OwnersPowers"] = ((ulong)OwnerPowers).ToString(); | ||
153 | |||
154 | |||
155 | |||
156 | |||
157 | Hashtable respData = XmlRpcCall(requestID, "groups.createGroup", param); | ||
158 | |||
159 | if (respData.Contains("error")) | ||
160 | { | ||
161 | // UUID is not nullable | ||
162 | |||
163 | return UUID.Zero; | ||
164 | } | ||
165 | |||
166 | return UUID.Parse((string)respData["GroupID"]); | ||
167 | } | ||
168 | |||
169 | public void UpdateGroup(GroupRequestID requestID, UUID groupID, string charter, bool showInList, | ||
170 | UUID insigniaID, int membershipFee, bool openEnrollment, | ||
171 | bool allowPublish, bool maturePublish) | ||
172 | { | ||
173 | Hashtable param = new Hashtable(); | ||
174 | param["GroupID"] = groupID.ToString(); | ||
175 | param["Charter"] = charter; | ||
176 | param["ShowInList"] = showInList == true ? 1 : 0; | ||
177 | param["InsigniaID"] = insigniaID.ToString(); | ||
178 | param["MembershipFee"] = membershipFee; | ||
179 | param["OpenEnrollment"] = openEnrollment == true ? 1 : 0; | ||
180 | param["AllowPublish"] = allowPublish == true ? 1 : 0; | ||
181 | param["MaturePublish"] = maturePublish == true ? 1 : 0; | ||
182 | |||
183 | XmlRpcCall(requestID, "groups.updateGroup", param); | ||
184 | } | ||
185 | |||
186 | public void AddGroupRole(GroupRequestID requestID, UUID groupID, UUID roleID, string name, string description, | ||
187 | string title, ulong powers) | ||
188 | { | ||
189 | Hashtable param = new Hashtable(); | ||
190 | param["GroupID"] = groupID.ToString(); | ||
191 | param["RoleID"] = roleID.ToString(); | ||
192 | param["Name"] = name; | ||
193 | param["Description"] = description; | ||
194 | param["Title"] = title; | ||
195 | param["Powers"] = powers.ToString(); | ||
196 | |||
197 | XmlRpcCall(requestID, "groups.addRoleToGroup", param); | ||
198 | } | ||
199 | |||
200 | public void RemoveGroupRole(GroupRequestID requestID, UUID groupID, UUID roleID) | ||
201 | { | ||
202 | Hashtable param = new Hashtable(); | ||
203 | param["GroupID"] = groupID.ToString(); | ||
204 | param["RoleID"] = roleID.ToString(); | ||
205 | |||
206 | XmlRpcCall(requestID, "groups.removeRoleFromGroup", param); | ||
207 | } | ||
208 | |||
209 | public void UpdateGroupRole(GroupRequestID requestID, UUID groupID, UUID roleID, string name, string description, | ||
210 | string title, ulong powers) | ||
211 | { | ||
212 | Hashtable param = new Hashtable(); | ||
213 | param["GroupID"] = groupID.ToString(); | ||
214 | param["RoleID"] = roleID.ToString(); | ||
215 | if (name != null) | ||
216 | { | ||
217 | param["Name"] = name; | ||
218 | } | ||
219 | if (description != null) | ||
220 | { | ||
221 | param["Description"] = description; | ||
222 | } | ||
223 | if (title != null) | ||
224 | { | ||
225 | param["Title"] = title; | ||
226 | } | ||
227 | param["Powers"] = powers.ToString(); | ||
228 | |||
229 | XmlRpcCall(requestID, "groups.updateGroupRole", param); | ||
230 | } | ||
231 | |||
232 | public GroupRecord GetGroupRecord(GroupRequestID requestID, UUID GroupID, string GroupName) | ||
233 | { | ||
234 | Hashtable param = new Hashtable(); | ||
235 | if (GroupID != UUID.Zero) | ||
236 | { | ||
237 | param["GroupID"] = GroupID.ToString(); | ||
238 | } | ||
239 | if ((GroupName != null) && (GroupName != string.Empty)) | ||
240 | { | ||
241 | param["Name"] = GroupName.ToString(); | ||
242 | } | ||
243 | |||
244 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroup", param); | ||
245 | |||
246 | if (respData.Contains("error")) | ||
247 | { | ||
248 | return null; | ||
249 | } | ||
250 | |||
251 | return GroupProfileHashtableToGroupRecord(respData); | ||
252 | |||
253 | } | ||
254 | |||
255 | public GroupProfileData GetMemberGroupProfile(GroupRequestID requestID, UUID GroupID, UUID AgentID) | ||
256 | { | ||
257 | Hashtable param = new Hashtable(); | ||
258 | param["GroupID"] = GroupID.ToString(); | ||
259 | |||
260 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroup", param); | ||
261 | |||
262 | if (respData.Contains("error")) | ||
263 | { | ||
264 | // GroupProfileData is not nullable | ||
265 | return new GroupProfileData(); | ||
266 | } | ||
267 | |||
268 | GroupMembershipData MemberInfo = GetAgentGroupMembership(requestID, AgentID, GroupID); | ||
269 | GroupProfileData MemberGroupProfile = GroupProfileHashtableToGroupProfileData(respData); | ||
270 | |||
271 | MemberGroupProfile.MemberTitle = MemberInfo.GroupTitle; | ||
272 | MemberGroupProfile.PowersMask = MemberInfo.GroupPowers; | ||
273 | |||
274 | return MemberGroupProfile; | ||
275 | |||
276 | } | ||
277 | |||
278 | private GroupProfileData GroupProfileHashtableToGroupProfileData(Hashtable groupProfile) | ||
279 | { | ||
280 | GroupProfileData group = new GroupProfileData(); | ||
281 | group.GroupID = UUID.Parse((string)groupProfile["GroupID"]); | ||
282 | group.Name = (string)groupProfile["Name"]; | ||
283 | |||
284 | if (groupProfile["Charter"] != null) | ||
285 | { | ||
286 | group.Charter = (string)groupProfile["Charter"]; | ||
287 | } | ||
288 | |||
289 | group.ShowInList = ((string)groupProfile["ShowInList"]) == "1"; | ||
290 | group.InsigniaID = UUID.Parse((string)groupProfile["InsigniaID"]); | ||
291 | group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]); | ||
292 | group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1"; | ||
293 | group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1"; | ||
294 | group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1"; | ||
295 | group.FounderID = UUID.Parse((string)groupProfile["FounderID"]); | ||
296 | group.OwnerRole = UUID.Parse((string)groupProfile["OwnerRoleID"]); | ||
297 | |||
298 | group.GroupMembershipCount = int.Parse((string)groupProfile["GroupMembershipCount"]); | ||
299 | group.GroupRolesCount = int.Parse((string)groupProfile["GroupRolesCount"]); | ||
300 | |||
301 | return group; | ||
302 | } | ||
303 | |||
304 | private GroupRecord GroupProfileHashtableToGroupRecord(Hashtable groupProfile) | ||
305 | { | ||
306 | |||
307 | GroupRecord group = new GroupRecord(); | ||
308 | group.GroupID = UUID.Parse((string)groupProfile["GroupID"]); | ||
309 | group.GroupName = groupProfile["Name"].ToString(); | ||
310 | if (groupProfile["Charter"] != null) | ||
311 | { | ||
312 | group.Charter = (string)groupProfile["Charter"]; | ||
313 | } | ||
314 | group.ShowInList = ((string)groupProfile["ShowInList"]) == "1"; | ||
315 | group.GroupPicture = UUID.Parse((string)groupProfile["InsigniaID"]); | ||
316 | group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]); | ||
317 | group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1"; | ||
318 | group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1"; | ||
319 | group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1"; | ||
320 | group.FounderID = UUID.Parse((string)groupProfile["FounderID"]); | ||
321 | group.OwnerRoleID = UUID.Parse((string)groupProfile["OwnerRoleID"]); | ||
322 | |||
323 | return group; | ||
324 | } | ||
325 | |||
326 | public void SetAgentActiveGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID) | ||
327 | { | ||
328 | Hashtable param = new Hashtable(); | ||
329 | param["AgentID"] = AgentID.ToString(); | ||
330 | param["GroupID"] = GroupID.ToString(); | ||
331 | |||
332 | XmlRpcCall(requestID, "groups.setAgentActiveGroup", param); | ||
333 | } | ||
334 | |||
335 | public void SetAgentActiveGroupRole(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID) | ||
336 | { | ||
337 | Hashtable param = new Hashtable(); | ||
338 | param["AgentID"] = AgentID.ToString(); | ||
339 | param["GroupID"] = GroupID.ToString(); | ||
340 | param["SelectedRoleID"] = RoleID.ToString(); | ||
341 | |||
342 | XmlRpcCall(requestID, "groups.setAgentGroupInfo", param); | ||
343 | } | ||
344 | |||
345 | public void SetAgentGroupInfo(GroupRequestID requestID, UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile) | ||
346 | { | ||
347 | Hashtable param = new Hashtable(); | ||
348 | param["AgentID"] = AgentID.ToString(); | ||
349 | param["GroupID"] = GroupID.ToString(); | ||
350 | param["AcceptNotices"] = AcceptNotices ? "1" : "0"; | ||
351 | param["ListInProfile"] = ListInProfile ? "1" : "0"; | ||
352 | |||
353 | XmlRpcCall(requestID, "groups.setAgentGroupInfo", param); | ||
354 | |||
355 | } | ||
356 | |||
357 | public void AddAgentToGroupInvite(GroupRequestID requestID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID) | ||
358 | { | ||
359 | Hashtable param = new Hashtable(); | ||
360 | param["InviteID"] = inviteID.ToString(); | ||
361 | param["AgentID"] = agentID.ToString(); | ||
362 | param["RoleID"] = roleID.ToString(); | ||
363 | param["GroupID"] = groupID.ToString(); | ||
364 | |||
365 | XmlRpcCall(requestID, "groups.addAgentToGroupInvite", param); | ||
366 | |||
367 | } | ||
368 | |||
369 | public GroupInviteInfo GetAgentToGroupInvite(GroupRequestID requestID, UUID inviteID) | ||
370 | { | ||
371 | Hashtable param = new Hashtable(); | ||
372 | param["InviteID"] = inviteID.ToString(); | ||
373 | |||
374 | Hashtable respData = XmlRpcCall(requestID, "groups.getAgentToGroupInvite", param); | ||
375 | |||
376 | if (respData.Contains("error")) | ||
377 | { | ||
378 | return null; | ||
379 | } | ||
380 | |||
381 | GroupInviteInfo inviteInfo = new GroupInviteInfo(); | ||
382 | inviteInfo.InviteID = inviteID; | ||
383 | inviteInfo.GroupID = UUID.Parse((string)respData["GroupID"]); | ||
384 | inviteInfo.RoleID = UUID.Parse((string)respData["RoleID"]); | ||
385 | inviteInfo.AgentID = UUID.Parse((string)respData["AgentID"]); | ||
386 | |||
387 | return inviteInfo; | ||
388 | } | ||
389 | |||
390 | public void RemoveAgentToGroupInvite(GroupRequestID requestID, UUID inviteID) | ||
391 | { | ||
392 | Hashtable param = new Hashtable(); | ||
393 | param["InviteID"] = inviteID.ToString(); | ||
394 | |||
395 | XmlRpcCall(requestID, "groups.removeAgentToGroupInvite", param); | ||
396 | } | ||
397 | |||
398 | public void AddAgentToGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID) | ||
399 | { | ||
400 | Hashtable param = new Hashtable(); | ||
401 | param["AgentID"] = AgentID.ToString(); | ||
402 | param["GroupID"] = GroupID.ToString(); | ||
403 | param["RoleID"] = RoleID.ToString(); | ||
404 | |||
405 | XmlRpcCall(requestID, "groups.addAgentToGroup", param); | ||
406 | } | ||
407 | |||
408 | public void RemoveAgentFromGroup(GroupRequestID requestID, UUID AgentID, UUID GroupID) | ||
409 | { | ||
410 | Hashtable param = new Hashtable(); | ||
411 | param["AgentID"] = AgentID.ToString(); | ||
412 | param["GroupID"] = GroupID.ToString(); | ||
413 | |||
414 | XmlRpcCall(requestID, "groups.removeAgentFromGroup", param); | ||
415 | } | ||
416 | |||
417 | public void AddAgentToGroupRole(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID) | ||
418 | { | ||
419 | Hashtable param = new Hashtable(); | ||
420 | param["AgentID"] = AgentID.ToString(); | ||
421 | param["GroupID"] = GroupID.ToString(); | ||
422 | param["RoleID"] = RoleID.ToString(); | ||
423 | |||
424 | XmlRpcCall(requestID, "groups.addAgentToGroupRole", param); | ||
425 | } | ||
426 | |||
427 | public void RemoveAgentFromGroupRole(GroupRequestID requestID, UUID AgentID, UUID GroupID, UUID RoleID) | ||
428 | { | ||
429 | Hashtable param = new Hashtable(); | ||
430 | param["AgentID"] = AgentID.ToString(); | ||
431 | param["GroupID"] = GroupID.ToString(); | ||
432 | param["RoleID"] = RoleID.ToString(); | ||
433 | |||
434 | XmlRpcCall(requestID, "groups.removeAgentFromGroupRole", param); | ||
435 | } | ||
436 | |||
437 | |||
438 | public List<DirGroupsReplyData> FindGroups(GroupRequestID requestID, string search) | ||
439 | { | ||
440 | Hashtable param = new Hashtable(); | ||
441 | param["Search"] = search; | ||
442 | |||
443 | Hashtable respData = XmlRpcCall(requestID, "groups.findGroups", param); | ||
444 | |||
445 | List<DirGroupsReplyData> findings = new List<DirGroupsReplyData>(); | ||
446 | |||
447 | if (!respData.Contains("error")) | ||
448 | { | ||
449 | Hashtable results = (Hashtable)respData["results"]; | ||
450 | foreach (Hashtable groupFind in results.Values) | ||
451 | { | ||
452 | DirGroupsReplyData data = new DirGroupsReplyData(); | ||
453 | data.groupID = new UUID((string)groupFind["GroupID"]); ; | ||
454 | data.groupName = (string)groupFind["Name"]; | ||
455 | data.members = int.Parse((string)groupFind["Members"]); | ||
456 | // data.searchOrder = order; | ||
457 | |||
458 | findings.Add(data); | ||
459 | } | ||
460 | } | ||
461 | |||
462 | return findings; | ||
463 | } | ||
464 | |||
465 | public GroupMembershipData GetAgentGroupMembership(GroupRequestID requestID, UUID AgentID, UUID GroupID) | ||
466 | { | ||
467 | Hashtable param = new Hashtable(); | ||
468 | param["AgentID"] = AgentID.ToString(); | ||
469 | param["GroupID"] = GroupID.ToString(); | ||
470 | |||
471 | Hashtable respData = XmlRpcCall(requestID, "groups.getAgentGroupMembership", param); | ||
472 | |||
473 | if (respData.Contains("error")) | ||
474 | { | ||
475 | return null; | ||
476 | } | ||
477 | |||
478 | GroupMembershipData data = HashTableToGroupMembershipData(respData); | ||
479 | |||
480 | return data; | ||
481 | } | ||
482 | |||
483 | public GroupMembershipData GetAgentActiveMembership(GroupRequestID requestID, UUID AgentID) | ||
484 | { | ||
485 | Hashtable param = new Hashtable(); | ||
486 | param["AgentID"] = AgentID.ToString(); | ||
487 | |||
488 | Hashtable respData = XmlRpcCall(requestID, "groups.getAgentActiveMembership", param); | ||
489 | |||
490 | if (respData.Contains("error")) | ||
491 | { | ||
492 | return null; | ||
493 | } | ||
494 | |||
495 | return HashTableToGroupMembershipData(respData); | ||
496 | } | ||
497 | |||
498 | |||
499 | public List<GroupMembershipData> GetAgentGroupMemberships(GroupRequestID requestID, UUID AgentID) | ||
500 | { | ||
501 | Hashtable param = new Hashtable(); | ||
502 | param["AgentID"] = AgentID.ToString(); | ||
503 | |||
504 | Hashtable respData = XmlRpcCall(requestID, "groups.getAgentGroupMemberships", param); | ||
505 | |||
506 | List<GroupMembershipData> memberships = new List<GroupMembershipData>(); | ||
507 | |||
508 | if (!respData.Contains("error")) | ||
509 | { | ||
510 | foreach (object membership in respData.Values) | ||
511 | { | ||
512 | memberships.Add(HashTableToGroupMembershipData((Hashtable)membership)); | ||
513 | } | ||
514 | } | ||
515 | |||
516 | return memberships; | ||
517 | } | ||
518 | |||
519 | public List<GroupRolesData> GetAgentGroupRoles(GroupRequestID requestID, UUID AgentID, UUID GroupID) | ||
520 | { | ||
521 | Hashtable param = new Hashtable(); | ||
522 | param["AgentID"] = AgentID.ToString(); | ||
523 | param["GroupID"] = GroupID.ToString(); | ||
524 | |||
525 | Hashtable respData = XmlRpcCall(requestID, "groups.getAgentRoles", param); | ||
526 | |||
527 | List<GroupRolesData> Roles = new List<GroupRolesData>(); | ||
528 | |||
529 | if (respData.Contains("error")) | ||
530 | { | ||
531 | return Roles; | ||
532 | } | ||
533 | |||
534 | foreach (Hashtable role in respData.Values) | ||
535 | { | ||
536 | GroupRolesData data = new GroupRolesData(); | ||
537 | data.RoleID = new UUID((string)role["RoleID"]); | ||
538 | data.Name = (string)role["Name"]; | ||
539 | data.Description = (string)role["Description"]; | ||
540 | data.Powers = ulong.Parse((string)role["Powers"]); | ||
541 | data.Title = (string)role["Title"]; | ||
542 | |||
543 | Roles.Add(data); | ||
544 | } | ||
545 | |||
546 | return Roles; | ||
547 | |||
548 | |||
549 | } | ||
550 | |||
551 | public List<GroupRolesData> GetGroupRoles(GroupRequestID requestID, UUID GroupID) | ||
552 | { | ||
553 | Hashtable param = new Hashtable(); | ||
554 | param["GroupID"] = GroupID.ToString(); | ||
555 | |||
556 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroupRoles", param); | ||
557 | |||
558 | List<GroupRolesData> Roles = new List<GroupRolesData>(); | ||
559 | |||
560 | if (respData.Contains("error")) | ||
561 | { | ||
562 | return Roles; | ||
563 | } | ||
564 | |||
565 | foreach (Hashtable role in respData.Values) | ||
566 | { | ||
567 | GroupRolesData data = new GroupRolesData(); | ||
568 | data.Description = (string)role["Description"]; | ||
569 | data.Members = int.Parse((string)role["Members"]); | ||
570 | data.Name = (string)role["Name"]; | ||
571 | data.Powers = ulong.Parse((string)role["Powers"]); | ||
572 | data.RoleID = new UUID((string)role["RoleID"]); | ||
573 | data.Title = (string)role["Title"]; | ||
574 | |||
575 | Roles.Add(data); | ||
576 | } | ||
577 | |||
578 | return Roles; | ||
579 | |||
580 | } | ||
581 | |||
582 | private static GroupMembershipData HashTableToGroupMembershipData(Hashtable respData) | ||
583 | { | ||
584 | GroupMembershipData data = new GroupMembershipData(); | ||
585 | data.AcceptNotices = ((string)respData["AcceptNotices"] == "1"); | ||
586 | data.Contribution = int.Parse((string)respData["Contribution"]); | ||
587 | data.ListInProfile = ((string)respData["ListInProfile"] == "1"); | ||
588 | |||
589 | data.ActiveRole = new UUID((string)respData["SelectedRoleID"]); | ||
590 | data.GroupTitle = (string)respData["Title"]; | ||
591 | |||
592 | data.GroupPowers = ulong.Parse((string)respData["GroupPowers"]); | ||
593 | |||
594 | // Is this group the agent's active group | ||
595 | |||
596 | data.GroupID = new UUID((string)respData["GroupID"]); | ||
597 | |||
598 | UUID ActiveGroup = new UUID((string)respData["ActiveGroupID"]); | ||
599 | data.Active = data.GroupID.Equals(ActiveGroup); | ||
600 | |||
601 | data.AllowPublish = ((string)respData["AllowPublish"] == "1"); | ||
602 | if (respData["Charter"] != null) | ||
603 | { | ||
604 | data.Charter = (string)respData["Charter"]; | ||
605 | } | ||
606 | data.FounderID = new UUID((string)respData["FounderID"]); | ||
607 | data.GroupID = new UUID((string)respData["GroupID"]); | ||
608 | data.GroupName = (string)respData["GroupName"]; | ||
609 | data.GroupPicture = new UUID((string)respData["InsigniaID"]); | ||
610 | data.MaturePublish = ((string)respData["MaturePublish"] == "1"); | ||
611 | data.MembershipFee = int.Parse((string)respData["MembershipFee"]); | ||
612 | data.OpenEnrollment = ((string)respData["OpenEnrollment"] == "1"); | ||
613 | data.ShowInList = ((string)respData["ShowInList"] == "1"); | ||
614 | return data; | ||
615 | } | ||
616 | |||
617 | public List<GroupMembersData> GetGroupMembers(GroupRequestID requestID, UUID GroupID) | ||
618 | { | ||
619 | Hashtable param = new Hashtable(); | ||
620 | param["GroupID"] = GroupID.ToString(); | ||
621 | |||
622 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroupMembers", param); | ||
623 | |||
624 | List<GroupMembersData> members = new List<GroupMembersData>(); | ||
625 | |||
626 | if (respData.Contains("error")) | ||
627 | { | ||
628 | return members; | ||
629 | } | ||
630 | |||
631 | foreach (Hashtable membership in respData.Values) | ||
632 | { | ||
633 | GroupMembersData data = new GroupMembersData(); | ||
634 | |||
635 | data.AcceptNotices = ((string)membership["AcceptNotices"]) == "1"; | ||
636 | data.AgentID = new UUID((string)membership["AgentID"]); | ||
637 | data.Contribution = int.Parse((string)membership["Contribution"]); | ||
638 | data.IsOwner = ((string)membership["IsOwner"]) == "1"; | ||
639 | data.ListInProfile = ((string)membership["ListInProfile"]) == "1"; | ||
640 | data.AgentPowers = ulong.Parse((string)membership["AgentPowers"]); | ||
641 | data.Title = (string)membership["Title"]; | ||
642 | |||
643 | members.Add(data); | ||
644 | } | ||
645 | |||
646 | return members; | ||
647 | |||
648 | } | ||
649 | |||
650 | public List<GroupRoleMembersData> GetGroupRoleMembers(GroupRequestID requestID, UUID GroupID) | ||
651 | { | ||
652 | Hashtable param = new Hashtable(); | ||
653 | param["GroupID"] = GroupID.ToString(); | ||
654 | |||
655 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroupRoleMembers", param); | ||
656 | |||
657 | List<GroupRoleMembersData> members = new List<GroupRoleMembersData>(); | ||
658 | |||
659 | if (!respData.Contains("error")) | ||
660 | { | ||
661 | foreach (Hashtable membership in respData.Values) | ||
662 | { | ||
663 | GroupRoleMembersData data = new GroupRoleMembersData(); | ||
664 | |||
665 | data.MemberID = new UUID((string)membership["AgentID"]); | ||
666 | data.RoleID = new UUID((string)membership["RoleID"]); | ||
667 | |||
668 | members.Add(data); | ||
669 | } | ||
670 | } | ||
671 | return members; | ||
672 | } | ||
673 | |||
674 | public List<GroupNoticeData> GetGroupNotices(GroupRequestID requestID, UUID GroupID) | ||
675 | { | ||
676 | Hashtable param = new Hashtable(); | ||
677 | param["GroupID"] = GroupID.ToString(); | ||
678 | |||
679 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroupNotices", param); | ||
680 | |||
681 | List<GroupNoticeData> values = new List<GroupNoticeData>(); | ||
682 | |||
683 | if (!respData.Contains("error")) | ||
684 | { | ||
685 | foreach (Hashtable value in respData.Values) | ||
686 | { | ||
687 | GroupNoticeData data = new GroupNoticeData(); | ||
688 | data.NoticeID = UUID.Parse((string)value["NoticeID"]); | ||
689 | data.Timestamp = uint.Parse((string)value["Timestamp"]); | ||
690 | data.FromName = (string)value["FromName"]; | ||
691 | data.Subject = (string)value["Subject"]; | ||
692 | data.HasAttachment = false; | ||
693 | data.AssetType = 0; | ||
694 | |||
695 | values.Add(data); | ||
696 | } | ||
697 | } | ||
698 | return values; | ||
699 | |||
700 | } | ||
701 | public GroupNoticeInfo GetGroupNotice(GroupRequestID requestID, UUID noticeID) | ||
702 | { | ||
703 | Hashtable param = new Hashtable(); | ||
704 | param["NoticeID"] = noticeID.ToString(); | ||
705 | |||
706 | Hashtable respData = XmlRpcCall(requestID, "groups.getGroupNotice", param); | ||
707 | |||
708 | |||
709 | if (respData.Contains("error")) | ||
710 | { | ||
711 | return null; | ||
712 | } | ||
713 | |||
714 | GroupNoticeInfo data = new GroupNoticeInfo(); | ||
715 | data.GroupID = UUID.Parse((string)respData["GroupID"]); | ||
716 | data.Message = (string)respData["Message"]; | ||
717 | data.BinaryBucket = Utils.HexStringToBytes((string)respData["BinaryBucket"], true); | ||
718 | data.noticeData.NoticeID = UUID.Parse((string)respData["NoticeID"]); | ||
719 | data.noticeData.Timestamp = uint.Parse((string)respData["Timestamp"]); | ||
720 | data.noticeData.FromName = (string)respData["FromName"]; | ||
721 | data.noticeData.Subject = (string)respData["Subject"]; | ||
722 | data.noticeData.HasAttachment = false; | ||
723 | data.noticeData.AssetType = 0; | ||
724 | |||
725 | if (data.Message == null) | ||
726 | { | ||
727 | data.Message = string.Empty; | ||
728 | } | ||
729 | |||
730 | return data; | ||
731 | } | ||
732 | public void AddGroupNotice(GroupRequestID requestID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket) | ||
733 | { | ||
734 | string binBucket = OpenMetaverse.Utils.BytesToHexString(binaryBucket, ""); | ||
735 | |||
736 | Hashtable param = new Hashtable(); | ||
737 | param["GroupID"] = groupID.ToString(); | ||
738 | param["NoticeID"] = noticeID.ToString(); | ||
739 | param["FromName"] = fromName; | ||
740 | param["Subject"] = subject; | ||
741 | param["Message"] = message; | ||
742 | param["BinaryBucket"] = binBucket; | ||
743 | param["TimeStamp"] = ((uint)Util.UnixTimeSinceEpoch()).ToString(); | ||
744 | |||
745 | XmlRpcCall(requestID, "groups.addGroupNotice", param); | ||
746 | } | ||
747 | |||
748 | private Hashtable XmlRpcCall(GroupRequestID requestID, string function, Hashtable param) | ||
749 | { | ||
750 | if (requestID == null) | ||
751 | { | ||
752 | requestID = new GroupRequestID(); | ||
753 | } | ||
754 | param.Add("RequestingAgentID", requestID.AgentID.ToString()); | ||
755 | param.Add("RequestingAgentUserService", requestID.UserServiceURL); | ||
756 | param.Add("RequestingSessionID", requestID.SessionID.ToString()); | ||
757 | |||
758 | |||
759 | param.Add("ReadKey", m_groupReadKey); | ||
760 | param.Add("WriteKey", m_groupWriteKey); | ||
761 | |||
762 | |||
763 | IList parameters = new ArrayList(); | ||
764 | parameters.Add(param); | ||
765 | |||
766 | XmlRpcRequest req; | ||
767 | if (!m_disableKeepAlive) | ||
768 | { | ||
769 | req = new XmlRpcRequest(function, parameters); | ||
770 | } | ||
771 | else | ||
772 | { | ||
773 | // This seems to solve a major problem on some windows servers | ||
774 | req = new NoKeepAliveXmlRpcRequest(function, parameters); | ||
775 | } | ||
776 | |||
777 | XmlRpcResponse resp = null; | ||
778 | |||
779 | try | ||
780 | { | ||
781 | resp = req.Send(m_serviceURL, 10000); | ||
782 | } | ||
783 | catch (Exception e) | ||
784 | { | ||
785 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); | ||
786 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString()); | ||
787 | |||
788 | |||
789 | foreach (string key in param.Keys) | ||
790 | { | ||
791 | m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", key, param[key].ToString()); | ||
792 | } | ||
793 | |||
794 | Hashtable respData = new Hashtable(); | ||
795 | respData.Add("error", e.ToString()); | ||
796 | return respData; | ||
797 | } | ||
798 | |||
799 | if (resp.Value is Hashtable) | ||
800 | { | ||
801 | Hashtable respData = (Hashtable)resp.Value; | ||
802 | if (respData.Contains("error") && !respData.Contains("succeed")) | ||
803 | { | ||
804 | LogRespDataToConsoleError(respData); | ||
805 | } | ||
806 | |||
807 | return respData; | ||
808 | } | ||
809 | |||
810 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString()); | ||
811 | |||
812 | if (resp.Value is ArrayList) | ||
813 | { | ||
814 | ArrayList al = (ArrayList)resp.Value; | ||
815 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Contains {0} elements", al.Count); | ||
816 | |||
817 | foreach (object o in al) | ||
818 | { | ||
819 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} :: {1}", o.GetType().ToString(), o.ToString()); | ||
820 | } | ||
821 | } | ||
822 | else | ||
823 | { | ||
824 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Function returned: {0}", resp.Value.ToString()); | ||
825 | } | ||
826 | |||
827 | Hashtable error = new Hashtable(); | ||
828 | error.Add("error", "invalid return value"); | ||
829 | return error; | ||
830 | } | ||
831 | |||
832 | private void LogRespDataToConsoleError(Hashtable respData) | ||
833 | { | ||
834 | m_log.Error("[XMLRPCGROUPDATA]: Error:"); | ||
835 | |||
836 | foreach (string key in respData.Keys) | ||
837 | { | ||
838 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Key: {0}", key); | ||
839 | |||
840 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); | ||
841 | foreach (string line in lines) | ||
842 | { | ||
843 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0}", line); | ||
844 | } | ||
845 | |||
846 | } | ||
847 | } | ||
848 | |||
849 | } | ||
850 | |||
851 | public class GroupNoticeInfo | ||
852 | { | ||
853 | public GroupNoticeData noticeData = new GroupNoticeData(); | ||
854 | public UUID GroupID = UUID.Zero; | ||
855 | public string Message = string.Empty; | ||
856 | public byte[] BinaryBucket = new byte[0]; | ||
857 | } | ||
858 | } | ||
859 | |||
860 | namespace Nwc.XmlRpc | ||
861 | { | ||
862 | using System; | ||
863 | using System.Collections; | ||
864 | using System.IO; | ||
865 | using System.Xml; | ||
866 | using System.Net; | ||
867 | using System.Text; | ||
868 | using System.Reflection; | ||
869 | |||
870 | /// <summary>Class supporting the request side of an XML-RPC transaction.</summary> | ||
871 | public class NoKeepAliveXmlRpcRequest : XmlRpcRequest | ||
872 | { | ||
873 | private Encoding _encoding = new ASCIIEncoding(); | ||
874 | private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer(); | ||
875 | private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer(); | ||
876 | |||
877 | /// <summary>Instantiate an <c>XmlRpcRequest</c> for a specified method and parameters.</summary> | ||
878 | /// <param name="methodName"><c>String</c> designating the <i>object.method</i> on the server the request | ||
879 | /// should be directed to.</param> | ||
880 | /// <param name="parameters"><c>ArrayList</c> of XML-RPC type parameters to invoke the request with.</param> | ||
881 | public NoKeepAliveXmlRpcRequest(String methodName, IList parameters) | ||
882 | { | ||
883 | MethodName = methodName; | ||
884 | _params = parameters; | ||
885 | } | ||
886 | |||
887 | /// <summary>Send the request to the server.</summary> | ||
888 | /// <param name="url"><c>String</c> The url of the XML-RPC server.</param> | ||
889 | /// <returns><c>XmlRpcResponse</c> The response generated.</returns> | ||
890 | public XmlRpcResponse Send(String url) | ||
891 | { | ||
892 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); | ||
893 | if (request == null) | ||
894 | throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR, | ||
895 | XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url); | ||
896 | request.Method = "POST"; | ||
897 | request.ContentType = "text/xml"; | ||
898 | request.AllowWriteStreamBuffering = true; | ||
899 | request.KeepAlive = false; | ||
900 | |||
901 | Stream stream = request.GetRequestStream(); | ||
902 | XmlTextWriter xml = new XmlTextWriter(stream, _encoding); | ||
903 | _serializer.Serialize(xml, this); | ||
904 | xml.Flush(); | ||
905 | xml.Close(); | ||
906 | |||
907 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); | ||
908 | StreamReader input = new StreamReader(response.GetResponseStream()); | ||
909 | |||
910 | XmlRpcResponse resp = (XmlRpcResponse)_deserializer.Deserialize(input); | ||
911 | input.Close(); | ||
912 | response.Close(); | ||
913 | return resp; | ||
914 | } | ||
915 | } | ||
916 | } | ||