1
0

XmlRpcGroupsServicesConnectorModule.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using System.Text;
  32. using Nwc.XmlRpc;
  33. using log4net;
  34. using Mono.Addins;
  35. using Nini.Config;
  36. using OpenMetaverse;
  37. using OpenMetaverse.StructuredData;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Communications;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Services.Interfaces;
  42. namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups
  43. {
  44. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  45. public class XmlRpcGroupsServicesConnectorModule : ISharedRegionModule, IGroupsServicesConnector
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. public const GroupPowers m_DefaultEveryonePowers = GroupPowers.AllowSetHome |
  49. GroupPowers.Accountable |
  50. GroupPowers.JoinChat |
  51. GroupPowers.AllowVoiceChat |
  52. GroupPowers.ReceiveNotices |
  53. GroupPowers.StartProposal |
  54. GroupPowers.VoteOnProposal;
  55. private bool m_connectorEnabled = false;
  56. private string m_groupsServerURI = string.Empty;
  57. private bool m_disableKeepAlive = false;
  58. private string m_groupReadKey = string.Empty;
  59. private string m_groupWriteKey = string.Empty;
  60. private IUserAccountService m_accountService = null;
  61. private ExpiringCache<string, XmlRpcResponse> m_memoryCache;
  62. private int m_cacheTimeout = 30;
  63. // Used to track which agents are have dropped from a group chat session
  64. // Should be reset per agent, on logon
  65. // TODO: move this to Flotsam XmlRpc Service
  66. // SessionID, List<AgentID>
  67. private Dictionary<UUID, List<UUID>> m_groupsAgentsDroppedFromChatSession = new Dictionary<UUID, List<UUID>>();
  68. private Dictionary<UUID, List<UUID>> m_groupsAgentsInvitedToChatSession = new Dictionary<UUID, List<UUID>>();
  69. #region IRegionModuleBase Members
  70. public string Name
  71. {
  72. get { return "XmlRpcGroupsServicesConnector"; }
  73. }
  74. // this module is not intended to be replaced, but there should only be 1 of them.
  75. public Type ReplaceableInterface
  76. {
  77. get { return null; }
  78. }
  79. public void Initialise(IConfigSource config)
  80. {
  81. IConfig groupsConfig = config.Configs["Groups"];
  82. if (groupsConfig == null)
  83. {
  84. // Do not run this module by default.
  85. return;
  86. }
  87. else
  88. {
  89. // if groups aren't enabled, we're not needed.
  90. // if we're not specified as the connector to use, then we're not wanted
  91. if ((groupsConfig.GetBoolean("Enabled", false) == false)
  92. || (groupsConfig.GetString("ServicesConnectorModule", "XmlRpcGroupsServicesConnector") != Name))
  93. {
  94. m_connectorEnabled = false;
  95. return;
  96. }
  97. m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name);
  98. m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty);
  99. if ((m_groupsServerURI == null) ||
  100. (m_groupsServerURI == string.Empty))
  101. {
  102. m_log.ErrorFormat("Please specify a valid URL for GroupsServerURI in OpenSim.ini, [Groups]");
  103. m_connectorEnabled = false;
  104. return;
  105. }
  106. m_disableKeepAlive = groupsConfig.GetBoolean("XmlRpcDisableKeepAlive", false);
  107. m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty);
  108. m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty);
  109. m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30);
  110. if (m_cacheTimeout == 0)
  111. {
  112. m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled.");
  113. }
  114. else
  115. {
  116. m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout);
  117. }
  118. // If we got all the config options we need, lets start'er'up
  119. m_memoryCache = new ExpiringCache<string, XmlRpcResponse>();
  120. m_connectorEnabled = true;
  121. }
  122. }
  123. public void Close()
  124. {
  125. m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Closing {0}", this.Name);
  126. }
  127. public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene)
  128. {
  129. if (m_connectorEnabled)
  130. {
  131. if (m_accountService == null)
  132. {
  133. m_accountService = scene.UserAccountService;
  134. }
  135. scene.RegisterModuleInterface<IGroupsServicesConnector>(this);
  136. }
  137. }
  138. public void RemoveRegion(OpenSim.Region.Framework.Scenes.Scene scene)
  139. {
  140. if (scene.RequestModuleInterface<IGroupsServicesConnector>() == this)
  141. {
  142. scene.UnregisterModuleInterface<IGroupsServicesConnector>(this);
  143. }
  144. }
  145. public void RegionLoaded(OpenSim.Region.Framework.Scenes.Scene scene)
  146. {
  147. // TODO: May want to consider listenning for Agent Connections so we can pre-cache group info
  148. // scene.EventManager.OnNewClient += OnNewClient;
  149. }
  150. #endregion
  151. #region ISharedRegionModule Members
  152. public void PostInitialise()
  153. {
  154. // NoOp
  155. }
  156. #endregion
  157. #region IGroupsServicesConnector Members
  158. /// <summary>
  159. /// 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.
  160. /// </summary>
  161. public UUID CreateGroup(UUID requestingAgentID, string name, string charter, bool showInList, UUID insigniaID,
  162. int membershipFee, bool openEnrollment, bool allowPublish,
  163. bool maturePublish, UUID founderID)
  164. {
  165. UUID GroupID = UUID.Random();
  166. UUID OwnerRoleID = UUID.Random();
  167. Hashtable param = new Hashtable();
  168. param["GroupID"] = GroupID.ToString();
  169. param["Name"] = name;
  170. param["Charter"] = charter;
  171. param["ShowInList"] = showInList == true ? 1 : 0;
  172. param["InsigniaID"] = insigniaID.ToString();
  173. param["MembershipFee"] = 0;
  174. param["OpenEnrollment"] = openEnrollment == true ? 1 : 0;
  175. param["AllowPublish"] = allowPublish == true ? 1 : 0;
  176. param["MaturePublish"] = maturePublish == true ? 1 : 0;
  177. param["FounderID"] = founderID.ToString();
  178. param["EveryonePowers"] = ((ulong)m_DefaultEveryonePowers).ToString();
  179. param["OwnerRoleID"] = OwnerRoleID.ToString();
  180. // Would this be cleaner as (GroupPowers)ulong.MaxValue;
  181. GroupPowers OwnerPowers = GroupPowers.Accountable
  182. | GroupPowers.AllowEditLand
  183. | GroupPowers.AllowFly
  184. | GroupPowers.AllowLandmark
  185. | GroupPowers.AllowRez
  186. | GroupPowers.AllowSetHome
  187. | GroupPowers.AllowVoiceChat
  188. | GroupPowers.AssignMember
  189. | GroupPowers.AssignMemberLimited
  190. | GroupPowers.ChangeActions
  191. | GroupPowers.ChangeIdentity
  192. | GroupPowers.ChangeMedia
  193. | GroupPowers.ChangeOptions
  194. | GroupPowers.CreateRole
  195. | GroupPowers.DeedObject
  196. | GroupPowers.DeleteRole
  197. | GroupPowers.Eject
  198. | GroupPowers.FindPlaces
  199. | GroupPowers.Invite
  200. | GroupPowers.JoinChat
  201. | GroupPowers.LandChangeIdentity
  202. | GroupPowers.LandDeed
  203. | GroupPowers.LandDivideJoin
  204. | GroupPowers.LandEdit
  205. | GroupPowers.LandEjectAndFreeze
  206. | GroupPowers.LandGardening
  207. | GroupPowers.LandManageAllowed
  208. | GroupPowers.LandManageBanned
  209. | GroupPowers.LandManagePasses
  210. | GroupPowers.LandOptions
  211. | GroupPowers.LandRelease
  212. | GroupPowers.LandSetSale
  213. | GroupPowers.ModerateChat
  214. | GroupPowers.ObjectManipulate
  215. | GroupPowers.ObjectSetForSale
  216. | GroupPowers.ReceiveNotices
  217. | GroupPowers.RemoveMember
  218. | GroupPowers.ReturnGroupOwned
  219. | GroupPowers.ReturnGroupSet
  220. | GroupPowers.ReturnNonGroup
  221. | GroupPowers.RoleProperties
  222. | GroupPowers.SendNotices
  223. | GroupPowers.SetLandingPoint
  224. | GroupPowers.StartProposal
  225. | GroupPowers.VoteOnProposal;
  226. param["OwnersPowers"] = ((ulong)OwnerPowers).ToString();
  227. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.createGroup", param);
  228. if (respData.Contains("error"))
  229. {
  230. // UUID is not nullable
  231. return UUID.Zero;
  232. }
  233. return UUID.Parse((string)respData["GroupID"]);
  234. }
  235. public void UpdateGroup(UUID requestingAgentID, UUID groupID, string charter, bool showInList,
  236. UUID insigniaID, int membershipFee, bool openEnrollment,
  237. bool allowPublish, bool maturePublish)
  238. {
  239. Hashtable param = new Hashtable();
  240. param["GroupID"] = groupID.ToString();
  241. param["Charter"] = charter;
  242. param["ShowInList"] = showInList == true ? 1 : 0;
  243. param["InsigniaID"] = insigniaID.ToString();
  244. param["MembershipFee"] = membershipFee;
  245. param["OpenEnrollment"] = openEnrollment == true ? 1 : 0;
  246. param["AllowPublish"] = allowPublish == true ? 1 : 0;
  247. param["MaturePublish"] = maturePublish == true ? 1 : 0;
  248. XmlRpcCall(requestingAgentID, "groups.updateGroup", param);
  249. }
  250. public void AddGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
  251. string title, ulong powers)
  252. {
  253. Hashtable param = new Hashtable();
  254. param["GroupID"] = groupID.ToString();
  255. param["RoleID"] = roleID.ToString();
  256. param["Name"] = name;
  257. param["Description"] = description;
  258. param["Title"] = title;
  259. param["Powers"] = powers.ToString();
  260. XmlRpcCall(requestingAgentID, "groups.addRoleToGroup", param);
  261. }
  262. public void RemoveGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID)
  263. {
  264. Hashtable param = new Hashtable();
  265. param["GroupID"] = groupID.ToString();
  266. param["RoleID"] = roleID.ToString();
  267. XmlRpcCall(requestingAgentID, "groups.removeRoleFromGroup", param);
  268. }
  269. public void UpdateGroupRole(UUID requestingAgentID, UUID groupID, UUID roleID, string name, string description,
  270. string title, ulong powers)
  271. {
  272. Hashtable param = new Hashtable();
  273. param["GroupID"] = groupID.ToString();
  274. param["RoleID"] = roleID.ToString();
  275. if (name != null)
  276. {
  277. param["Name"] = name;
  278. }
  279. if (description != null)
  280. {
  281. param["Description"] = description;
  282. }
  283. if (title != null)
  284. {
  285. param["Title"] = title;
  286. }
  287. param["Powers"] = powers.ToString();
  288. XmlRpcCall(requestingAgentID, "groups.updateGroupRole", param);
  289. }
  290. public GroupRecord GetGroupRecord(UUID requestingAgentID, UUID GroupID, string GroupName)
  291. {
  292. Hashtable param = new Hashtable();
  293. if (GroupID != UUID.Zero)
  294. {
  295. param["GroupID"] = GroupID.ToString();
  296. }
  297. if ((GroupName != null) && (GroupName != string.Empty))
  298. {
  299. param["Name"] = GroupName.ToString();
  300. }
  301. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroup", param);
  302. if (respData.Contains("error"))
  303. {
  304. return null;
  305. }
  306. return GroupProfileHashtableToGroupRecord(respData);
  307. }
  308. public GroupProfileData GetMemberGroupProfile(UUID requestingAgentID, UUID GroupID, UUID AgentID)
  309. {
  310. Hashtable param = new Hashtable();
  311. param["GroupID"] = GroupID.ToString();
  312. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroup", param);
  313. if (respData.Contains("error"))
  314. {
  315. // GroupProfileData is not nullable
  316. return new GroupProfileData();
  317. }
  318. GroupMembershipData MemberInfo = GetAgentGroupMembership(requestingAgentID, AgentID, GroupID);
  319. GroupProfileData MemberGroupProfile = GroupProfileHashtableToGroupProfileData(respData);
  320. MemberGroupProfile.MemberTitle = MemberInfo.GroupTitle;
  321. MemberGroupProfile.PowersMask = MemberInfo.GroupPowers;
  322. return MemberGroupProfile;
  323. }
  324. public void SetAgentActiveGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  325. {
  326. Hashtable param = new Hashtable();
  327. param["AgentID"] = AgentID.ToString();
  328. param["GroupID"] = GroupID.ToString();
  329. XmlRpcCall(requestingAgentID, "groups.setAgentActiveGroup", param);
  330. }
  331. public void SetAgentActiveGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  332. {
  333. Hashtable param = new Hashtable();
  334. param["AgentID"] = AgentID.ToString();
  335. param["GroupID"] = GroupID.ToString();
  336. param["SelectedRoleID"] = RoleID.ToString();
  337. XmlRpcCall(requestingAgentID, "groups.setAgentGroupInfo", param);
  338. }
  339. public void SetAgentGroupInfo(UUID requestingAgentID, UUID AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  340. {
  341. Hashtable param = new Hashtable();
  342. param["AgentID"] = AgentID.ToString();
  343. param["GroupID"] = GroupID.ToString();
  344. param["AcceptNotices"] = AcceptNotices ? "1" : "0";
  345. param["ListInProfile"] = ListInProfile ? "1" : "0";
  346. XmlRpcCall(requestingAgentID, "groups.setAgentGroupInfo", param);
  347. }
  348. public void AddAgentToGroupInvite(UUID requestingAgentID, UUID inviteID, UUID groupID, UUID roleID, UUID agentID)
  349. {
  350. Hashtable param = new Hashtable();
  351. param["InviteID"] = inviteID.ToString();
  352. param["AgentID"] = agentID.ToString();
  353. param["RoleID"] = roleID.ToString();
  354. param["GroupID"] = groupID.ToString();
  355. XmlRpcCall(requestingAgentID, "groups.addAgentToGroupInvite", param);
  356. }
  357. public GroupInviteInfo GetAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
  358. {
  359. Hashtable param = new Hashtable();
  360. param["InviteID"] = inviteID.ToString();
  361. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentToGroupInvite", param);
  362. if (respData.Contains("error"))
  363. {
  364. return null;
  365. }
  366. GroupInviteInfo inviteInfo = new GroupInviteInfo();
  367. inviteInfo.InviteID = inviteID;
  368. inviteInfo.GroupID = UUID.Parse((string)respData["GroupID"]);
  369. inviteInfo.RoleID = UUID.Parse((string)respData["RoleID"]);
  370. inviteInfo.AgentID = UUID.Parse((string)respData["AgentID"]);
  371. return inviteInfo;
  372. }
  373. public void RemoveAgentToGroupInvite(UUID requestingAgentID, UUID inviteID)
  374. {
  375. Hashtable param = new Hashtable();
  376. param["InviteID"] = inviteID.ToString();
  377. XmlRpcCall(requestingAgentID, "groups.removeAgentToGroupInvite", param);
  378. }
  379. public void AddAgentToGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  380. {
  381. Hashtable param = new Hashtable();
  382. param["AgentID"] = AgentID.ToString();
  383. param["GroupID"] = GroupID.ToString();
  384. param["RoleID"] = RoleID.ToString();
  385. XmlRpcCall(requestingAgentID, "groups.addAgentToGroup", param);
  386. }
  387. public void RemoveAgentFromGroup(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  388. {
  389. Hashtable param = new Hashtable();
  390. param["AgentID"] = AgentID.ToString();
  391. param["GroupID"] = GroupID.ToString();
  392. XmlRpcCall(requestingAgentID, "groups.removeAgentFromGroup", param);
  393. }
  394. public void AddAgentToGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  395. {
  396. Hashtable param = new Hashtable();
  397. param["AgentID"] = AgentID.ToString();
  398. param["GroupID"] = GroupID.ToString();
  399. param["RoleID"] = RoleID.ToString();
  400. XmlRpcCall(requestingAgentID, "groups.addAgentToGroupRole", param);
  401. }
  402. public void RemoveAgentFromGroupRole(UUID requestingAgentID, UUID AgentID, UUID GroupID, UUID RoleID)
  403. {
  404. Hashtable param = new Hashtable();
  405. param["AgentID"] = AgentID.ToString();
  406. param["GroupID"] = GroupID.ToString();
  407. param["RoleID"] = RoleID.ToString();
  408. XmlRpcCall(requestingAgentID, "groups.removeAgentFromGroupRole", param);
  409. }
  410. public List<DirGroupsReplyData> FindGroups(UUID requestingAgentID, string search)
  411. {
  412. Hashtable param = new Hashtable();
  413. param["Search"] = search;
  414. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.findGroups", param);
  415. List<DirGroupsReplyData> findings = new List<DirGroupsReplyData>();
  416. if (!respData.Contains("error"))
  417. {
  418. Hashtable results = (Hashtable)respData["results"];
  419. foreach (Hashtable groupFind in results.Values)
  420. {
  421. DirGroupsReplyData data = new DirGroupsReplyData();
  422. data.groupID = new UUID((string)groupFind["GroupID"]); ;
  423. data.groupName = (string)groupFind["Name"];
  424. data.members = int.Parse((string)groupFind["Members"]);
  425. // data.searchOrder = order;
  426. findings.Add(data);
  427. }
  428. }
  429. return findings;
  430. }
  431. public GroupMembershipData GetAgentGroupMembership(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  432. {
  433. Hashtable param = new Hashtable();
  434. param["AgentID"] = AgentID.ToString();
  435. param["GroupID"] = GroupID.ToString();
  436. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentGroupMembership", param);
  437. if (respData.Contains("error"))
  438. {
  439. return null;
  440. }
  441. GroupMembershipData data = HashTableToGroupMembershipData(respData);
  442. return data;
  443. }
  444. public GroupMembershipData GetAgentActiveMembership(UUID requestingAgentID, UUID AgentID)
  445. {
  446. Hashtable param = new Hashtable();
  447. param["AgentID"] = AgentID.ToString();
  448. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentActiveMembership", param);
  449. if (respData.Contains("error"))
  450. {
  451. return null;
  452. }
  453. return HashTableToGroupMembershipData(respData);
  454. }
  455. public List<GroupMembershipData> GetAgentGroupMemberships(UUID requestingAgentID, UUID AgentID)
  456. {
  457. Hashtable param = new Hashtable();
  458. param["AgentID"] = AgentID.ToString();
  459. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentGroupMemberships", param);
  460. List<GroupMembershipData> memberships = new List<GroupMembershipData>();
  461. if (!respData.Contains("error"))
  462. {
  463. foreach (object membership in respData.Values)
  464. {
  465. memberships.Add(HashTableToGroupMembershipData((Hashtable)membership));
  466. }
  467. }
  468. return memberships;
  469. }
  470. public List<GroupRolesData> GetAgentGroupRoles(UUID requestingAgentID, UUID AgentID, UUID GroupID)
  471. {
  472. Hashtable param = new Hashtable();
  473. param["AgentID"] = AgentID.ToString();
  474. param["GroupID"] = GroupID.ToString();
  475. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getAgentRoles", param);
  476. List<GroupRolesData> Roles = new List<GroupRolesData>();
  477. if (respData.Contains("error"))
  478. {
  479. return Roles;
  480. }
  481. foreach (Hashtable role in respData.Values)
  482. {
  483. GroupRolesData data = new GroupRolesData();
  484. data.RoleID = new UUID((string)role["RoleID"]);
  485. data.Name = (string)role["Name"];
  486. data.Description = (string)role["Description"];
  487. data.Powers = ulong.Parse((string)role["Powers"]);
  488. data.Title = (string)role["Title"];
  489. Roles.Add(data);
  490. }
  491. return Roles;
  492. }
  493. public List<GroupRolesData> GetGroupRoles(UUID requestingAgentID, UUID GroupID)
  494. {
  495. Hashtable param = new Hashtable();
  496. param["GroupID"] = GroupID.ToString();
  497. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupRoles", param);
  498. List<GroupRolesData> Roles = new List<GroupRolesData>();
  499. if (respData.Contains("error"))
  500. {
  501. return Roles;
  502. }
  503. foreach (Hashtable role in respData.Values)
  504. {
  505. GroupRolesData data = new GroupRolesData();
  506. data.Description = (string)role["Description"];
  507. data.Members = int.Parse((string)role["Members"]);
  508. data.Name = (string)role["Name"];
  509. data.Powers = ulong.Parse((string)role["Powers"]);
  510. data.RoleID = new UUID((string)role["RoleID"]);
  511. data.Title = (string)role["Title"];
  512. Roles.Add(data);
  513. }
  514. return Roles;
  515. }
  516. public List<GroupMembersData> GetGroupMembers(UUID requestingAgentID, UUID GroupID)
  517. {
  518. Hashtable param = new Hashtable();
  519. param["GroupID"] = GroupID.ToString();
  520. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupMembers", param);
  521. List<GroupMembersData> members = new List<GroupMembersData>();
  522. if (respData.Contains("error"))
  523. {
  524. return members;
  525. }
  526. foreach (Hashtable membership in respData.Values)
  527. {
  528. GroupMembersData data = new GroupMembersData();
  529. data.AcceptNotices = ((string)membership["AcceptNotices"]) == "1";
  530. data.AgentID = new UUID((string)membership["AgentID"]);
  531. data.Contribution = int.Parse((string)membership["Contribution"]);
  532. data.IsOwner = ((string)membership["IsOwner"]) == "1";
  533. data.ListInProfile = ((string)membership["ListInProfile"]) == "1";
  534. data.AgentPowers = ulong.Parse((string)membership["AgentPowers"]);
  535. data.Title = (string)membership["Title"];
  536. members.Add(data);
  537. }
  538. return members;
  539. }
  540. public List<GroupRoleMembersData> GetGroupRoleMembers(UUID requestingAgentID, UUID GroupID)
  541. {
  542. Hashtable param = new Hashtable();
  543. param["GroupID"] = GroupID.ToString();
  544. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupRoleMembers", param);
  545. List<GroupRoleMembersData> members = new List<GroupRoleMembersData>();
  546. if (!respData.Contains("error"))
  547. {
  548. foreach (Hashtable membership in respData.Values)
  549. {
  550. GroupRoleMembersData data = new GroupRoleMembersData();
  551. data.MemberID = new UUID((string)membership["AgentID"]);
  552. data.RoleID = new UUID((string)membership["RoleID"]);
  553. members.Add(data);
  554. }
  555. }
  556. return members;
  557. }
  558. public List<GroupNoticeData> GetGroupNotices(UUID requestingAgentID, UUID GroupID)
  559. {
  560. Hashtable param = new Hashtable();
  561. param["GroupID"] = GroupID.ToString();
  562. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupNotices", param);
  563. List<GroupNoticeData> values = new List<GroupNoticeData>();
  564. if (!respData.Contains("error"))
  565. {
  566. foreach (Hashtable value in respData.Values)
  567. {
  568. GroupNoticeData data = new GroupNoticeData();
  569. data.NoticeID = UUID.Parse((string)value["NoticeID"]);
  570. data.Timestamp = uint.Parse((string)value["Timestamp"]);
  571. data.FromName = (string)value["FromName"];
  572. data.Subject = (string)value["Subject"];
  573. data.HasAttachment = false;
  574. data.AssetType = 0;
  575. values.Add(data);
  576. }
  577. }
  578. return values;
  579. }
  580. public GroupNoticeInfo GetGroupNotice(UUID requestingAgentID, UUID noticeID)
  581. {
  582. Hashtable param = new Hashtable();
  583. param["NoticeID"] = noticeID.ToString();
  584. Hashtable respData = XmlRpcCall(requestingAgentID, "groups.getGroupNotice", param);
  585. if (respData.Contains("error"))
  586. {
  587. return null;
  588. }
  589. GroupNoticeInfo data = new GroupNoticeInfo();
  590. data.GroupID = UUID.Parse((string)respData["GroupID"]);
  591. data.Message = (string)respData["Message"];
  592. data.BinaryBucket = Utils.HexStringToBytes((string)respData["BinaryBucket"], true);
  593. data.noticeData.NoticeID = UUID.Parse((string)respData["NoticeID"]);
  594. data.noticeData.Timestamp = uint.Parse((string)respData["Timestamp"]);
  595. data.noticeData.FromName = (string)respData["FromName"];
  596. data.noticeData.Subject = (string)respData["Subject"];
  597. data.noticeData.HasAttachment = false;
  598. data.noticeData.AssetType = 0;
  599. if (data.Message == null)
  600. {
  601. data.Message = string.Empty;
  602. }
  603. return data;
  604. }
  605. public void AddGroupNotice(UUID requestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message, byte[] binaryBucket)
  606. {
  607. string binBucket = OpenMetaverse.Utils.BytesToHexString(binaryBucket, "");
  608. Hashtable param = new Hashtable();
  609. param["GroupID"] = groupID.ToString();
  610. param["NoticeID"] = noticeID.ToString();
  611. param["FromName"] = fromName;
  612. param["Subject"] = subject;
  613. param["Message"] = message;
  614. param["BinaryBucket"] = binBucket;
  615. param["TimeStamp"] = ((uint)Util.UnixTimeSinceEpoch()).ToString();
  616. XmlRpcCall(requestingAgentID, "groups.addGroupNotice", param);
  617. }
  618. #endregion
  619. #region GroupSessionTracking
  620. public void ResetAgentGroupChatSessions(UUID agentID)
  621. {
  622. foreach (List<UUID> agentList in m_groupsAgentsDroppedFromChatSession.Values)
  623. {
  624. agentList.Remove(agentID);
  625. }
  626. }
  627. public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID)
  628. {
  629. // If we're tracking this group, and we can find them in the tracking, then they've been invited
  630. return m_groupsAgentsInvitedToChatSession.ContainsKey(groupID)
  631. && m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID);
  632. }
  633. public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID)
  634. {
  635. // If we're tracking drops for this group,
  636. // and we find them, well... then they've dropped
  637. return m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID)
  638. && m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID);
  639. }
  640. public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID)
  641. {
  642. if (m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID))
  643. {
  644. // If not in dropped list, add
  645. if (!m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID))
  646. {
  647. m_groupsAgentsDroppedFromChatSession[groupID].Add(agentID);
  648. }
  649. }
  650. }
  651. public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID)
  652. {
  653. // Add Session Status if it doesn't exist for this session
  654. CreateGroupChatSessionTracking(groupID);
  655. // If nessesary, remove from dropped list
  656. if (m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID))
  657. {
  658. m_groupsAgentsDroppedFromChatSession[groupID].Remove(agentID);
  659. }
  660. }
  661. private void CreateGroupChatSessionTracking(UUID groupID)
  662. {
  663. if (!m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID))
  664. {
  665. m_groupsAgentsDroppedFromChatSession.Add(groupID, new List<UUID>());
  666. m_groupsAgentsInvitedToChatSession.Add(groupID, new List<UUID>());
  667. }
  668. }
  669. #endregion
  670. #region XmlRpcHashtableMarshalling
  671. private GroupProfileData GroupProfileHashtableToGroupProfileData(Hashtable groupProfile)
  672. {
  673. GroupProfileData group = new GroupProfileData();
  674. group.GroupID = UUID.Parse((string)groupProfile["GroupID"]);
  675. group.Name = (string)groupProfile["Name"];
  676. if (groupProfile["Charter"] != null)
  677. {
  678. group.Charter = (string)groupProfile["Charter"];
  679. }
  680. group.ShowInList = ((string)groupProfile["ShowInList"]) == "1";
  681. group.InsigniaID = UUID.Parse((string)groupProfile["InsigniaID"]);
  682. group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]);
  683. group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1";
  684. group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1";
  685. group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1";
  686. group.FounderID = UUID.Parse((string)groupProfile["FounderID"]);
  687. group.OwnerRole = UUID.Parse((string)groupProfile["OwnerRoleID"]);
  688. group.GroupMembershipCount = int.Parse((string)groupProfile["GroupMembershipCount"]);
  689. group.GroupRolesCount = int.Parse((string)groupProfile["GroupRolesCount"]);
  690. return group;
  691. }
  692. private GroupRecord GroupProfileHashtableToGroupRecord(Hashtable groupProfile)
  693. {
  694. GroupRecord group = new GroupRecord();
  695. group.GroupID = UUID.Parse((string)groupProfile["GroupID"]);
  696. group.GroupName = groupProfile["Name"].ToString();
  697. if (groupProfile["Charter"] != null)
  698. {
  699. group.Charter = (string)groupProfile["Charter"];
  700. }
  701. group.ShowInList = ((string)groupProfile["ShowInList"]) == "1";
  702. group.GroupPicture = UUID.Parse((string)groupProfile["InsigniaID"]);
  703. group.MembershipFee = int.Parse((string)groupProfile["MembershipFee"]);
  704. group.OpenEnrollment = ((string)groupProfile["OpenEnrollment"]) == "1";
  705. group.AllowPublish = ((string)groupProfile["AllowPublish"]) == "1";
  706. group.MaturePublish = ((string)groupProfile["MaturePublish"]) == "1";
  707. group.FounderID = UUID.Parse((string)groupProfile["FounderID"]);
  708. group.OwnerRoleID = UUID.Parse((string)groupProfile["OwnerRoleID"]);
  709. return group;
  710. }
  711. private static GroupMembershipData HashTableToGroupMembershipData(Hashtable respData)
  712. {
  713. GroupMembershipData data = new GroupMembershipData();
  714. data.AcceptNotices = ((string)respData["AcceptNotices"] == "1");
  715. data.Contribution = int.Parse((string)respData["Contribution"]);
  716. data.ListInProfile = ((string)respData["ListInProfile"] == "1");
  717. data.ActiveRole = new UUID((string)respData["SelectedRoleID"]);
  718. data.GroupTitle = (string)respData["Title"];
  719. data.GroupPowers = ulong.Parse((string)respData["GroupPowers"]);
  720. // Is this group the agent's active group
  721. data.GroupID = new UUID((string)respData["GroupID"]);
  722. UUID ActiveGroup = new UUID((string)respData["ActiveGroupID"]);
  723. data.Active = data.GroupID.Equals(ActiveGroup);
  724. data.AllowPublish = ((string)respData["AllowPublish"] == "1");
  725. if (respData["Charter"] != null)
  726. {
  727. data.Charter = (string)respData["Charter"];
  728. }
  729. data.FounderID = new UUID((string)respData["FounderID"]);
  730. data.GroupID = new UUID((string)respData["GroupID"]);
  731. data.GroupName = (string)respData["GroupName"];
  732. data.GroupPicture = new UUID((string)respData["InsigniaID"]);
  733. data.MaturePublish = ((string)respData["MaturePublish"] == "1");
  734. data.MembershipFee = int.Parse((string)respData["MembershipFee"]);
  735. data.OpenEnrollment = ((string)respData["OpenEnrollment"] == "1");
  736. data.ShowInList = ((string)respData["ShowInList"] == "1");
  737. return data;
  738. }
  739. #endregion
  740. /// <summary>
  741. /// Encapsulate the XmlRpc call to standardize security and error handling.
  742. /// </summary>
  743. private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param)
  744. {
  745. XmlRpcResponse resp = null;
  746. string CacheKey = null;
  747. // Only bother with the cache if it isn't disabled.
  748. if (m_cacheTimeout > 0)
  749. {
  750. if (!function.StartsWith("groups.get"))
  751. {
  752. // Any and all updates cause the cache to clear
  753. m_memoryCache.Clear();
  754. }
  755. else
  756. {
  757. StringBuilder sb = new StringBuilder(requestingAgentID + function);
  758. foreach (object key in param.Keys)
  759. {
  760. if (param[key] != null)
  761. {
  762. sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString());
  763. }
  764. }
  765. CacheKey = sb.ToString();
  766. m_memoryCache.TryGetValue(CacheKey, out resp);
  767. }
  768. }
  769. if (resp == null)
  770. {
  771. string UserService;
  772. UUID SessionID;
  773. GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID);
  774. param.Add("RequestingAgentID", requestingAgentID.ToString());
  775. param.Add("RequestingAgentUserService", UserService);
  776. param.Add("RequestingSessionID", SessionID.ToString());
  777. param.Add("ReadKey", m_groupReadKey);
  778. param.Add("WriteKey", m_groupWriteKey);
  779. IList parameters = new ArrayList();
  780. parameters.Add(param);
  781. ConfigurableKeepAliveXmlRpcRequest req;
  782. req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive);
  783. try
  784. {
  785. resp = req.Send(m_groupsServerURI, 10000);
  786. if ((m_cacheTimeout > 0) && (CacheKey != null))
  787. {
  788. m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout));
  789. }
  790. }
  791. catch (Exception e)
  792. {
  793. m_log.ErrorFormat(
  794. "[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method {0} at {1}",
  795. function, m_groupsServerURI);
  796. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}{1}", e.Message, e.StackTrace);
  797. foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
  798. {
  799. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine);
  800. }
  801. foreach (string key in param.Keys)
  802. {
  803. m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString());
  804. }
  805. Hashtable respData = new Hashtable();
  806. respData.Add("error", e.ToString());
  807. return respData;
  808. }
  809. }
  810. if (resp.Value is Hashtable)
  811. {
  812. Hashtable respData = (Hashtable)resp.Value;
  813. if (respData.Contains("error") && !respData.Contains("succeed"))
  814. {
  815. LogRespDataToConsoleError(respData);
  816. }
  817. return respData;
  818. }
  819. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString());
  820. if (resp.Value is ArrayList)
  821. {
  822. ArrayList al = (ArrayList)resp.Value;
  823. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count);
  824. foreach (object o in al)
  825. {
  826. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString());
  827. }
  828. }
  829. else
  830. {
  831. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString());
  832. }
  833. Hashtable error = new Hashtable();
  834. error.Add("error", "invalid return value");
  835. return error;
  836. }
  837. private void LogRespDataToConsoleError(Hashtable respData)
  838. {
  839. m_log.Error("[XMLRPC-GROUPS-CONNECTOR]: Error:");
  840. foreach (string key in respData.Keys)
  841. {
  842. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Key: {0}", key);
  843. string[] lines = respData[key].ToString().Split(new char[] { '\n' });
  844. foreach (string line in lines)
  845. {
  846. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}", line);
  847. }
  848. }
  849. }
  850. /// <summary>
  851. /// Group Request Tokens are an attempt to allow the groups service to authenticate
  852. /// requests.
  853. /// TODO: This broke after the big grid refactor, either find a better way, or discard this
  854. /// </summary>
  855. /// <param name="client"></param>
  856. /// <returns></returns>
  857. private void GetClientGroupRequestID(UUID AgentID, out string UserServiceURL, out UUID SessionID)
  858. {
  859. UserServiceURL = "";
  860. SessionID = UUID.Zero;
  861. // Need to rework this based on changes to User Services
  862. /*
  863. UserAccount userAccount = m_accountService.GetUserAccount(UUID.Zero,AgentID);
  864. if (userAccount == null)
  865. {
  866. // This should be impossible. If I've been passed a reference to a client
  867. // that client should be registered with the UserService. So something
  868. // is horribly wrong somewhere.
  869. m_log.WarnFormat("[GROUPS]: Could not find a UserServiceURL for {0}", AgentID);
  870. }
  871. else if (userProfile is ForeignUserProfileData)
  872. {
  873. // They aren't from around here
  874. ForeignUserProfileData fupd = (ForeignUserProfileData)userProfile;
  875. UserServiceURL = fupd.UserServerURI;
  876. SessionID = fupd.CurrentAgent.SessionID;
  877. }
  878. else
  879. {
  880. // They're a local user, use this:
  881. UserServiceURL = m_commManager.NetworkServersInfo.UserURL;
  882. SessionID = userProfile.CurrentAgent.SessionID;
  883. }
  884. */
  885. }
  886. }
  887. }
  888. namespace Nwc.XmlRpc
  889. {
  890. using System;
  891. using System.Collections;
  892. using System.IO;
  893. using System.Xml;
  894. using System.Net;
  895. using System.Text;
  896. using System.Reflection;
  897. /// <summary>Class supporting the request side of an XML-RPC transaction.</summary>
  898. public class ConfigurableKeepAliveXmlRpcRequest : XmlRpcRequest
  899. {
  900. private Encoding _encoding = new ASCIIEncoding();
  901. private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer();
  902. private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer();
  903. private bool _disableKeepAlive = true;
  904. public string RequestResponse = String.Empty;
  905. /// <summary>Instantiate an <c>XmlRpcRequest</c> for a specified method and parameters.</summary>
  906. /// <param name="methodName"><c>String</c> designating the <i>object.method</i> on the server the request
  907. /// should be directed to.</param>
  908. /// <param name="parameters"><c>ArrayList</c> of XML-RPC type parameters to invoke the request with.</param>
  909. public ConfigurableKeepAliveXmlRpcRequest(String methodName, IList parameters, bool disableKeepAlive)
  910. {
  911. MethodName = methodName;
  912. _params = parameters;
  913. _disableKeepAlive = disableKeepAlive;
  914. }
  915. /// <summary>Send the request to the server.</summary>
  916. /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
  917. /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
  918. public XmlRpcResponse Send(String url)
  919. {
  920. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  921. if (request == null)
  922. throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
  923. XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
  924. request.Method = "POST";
  925. request.ContentType = "text/xml";
  926. request.AllowWriteStreamBuffering = true;
  927. request.KeepAlive = !_disableKeepAlive;
  928. Stream stream = request.GetRequestStream();
  929. XmlTextWriter xml = new XmlTextWriter(stream, _encoding);
  930. _serializer.Serialize(xml, this);
  931. xml.Flush();
  932. xml.Close();
  933. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  934. StreamReader input = new StreamReader(response.GetResponseStream());
  935. string inputXml = input.ReadToEnd();
  936. XmlRpcResponse resp;
  937. try
  938. {
  939. resp = (XmlRpcResponse)_deserializer.Deserialize(inputXml);
  940. }
  941. catch (Exception e)
  942. {
  943. RequestResponse = inputXml;
  944. throw e;
  945. }
  946. input.Close();
  947. response.Close();
  948. return resp;
  949. }
  950. }
  951. }