XmlRpcGroupsServicesConnectorModule.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  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", "Default") != 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("[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function);
  794. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", e.ToString());
  795. foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
  796. {
  797. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine);
  798. }
  799. foreach (string key in param.Keys)
  800. {
  801. m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString());
  802. }
  803. Hashtable respData = new Hashtable();
  804. respData.Add("error", e.ToString());
  805. return respData;
  806. }
  807. }
  808. if (resp.Value is Hashtable)
  809. {
  810. Hashtable respData = (Hashtable)resp.Value;
  811. if (respData.Contains("error") && !respData.Contains("succeed"))
  812. {
  813. LogRespDataToConsoleError(respData);
  814. }
  815. return respData;
  816. }
  817. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString());
  818. if (resp.Value is ArrayList)
  819. {
  820. ArrayList al = (ArrayList)resp.Value;
  821. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count);
  822. foreach (object o in al)
  823. {
  824. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString());
  825. }
  826. }
  827. else
  828. {
  829. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString());
  830. }
  831. Hashtable error = new Hashtable();
  832. error.Add("error", "invalid return value");
  833. return error;
  834. }
  835. private void LogRespDataToConsoleError(Hashtable respData)
  836. {
  837. m_log.Error("[XMLRPC-GROUPS-CONNECTOR]: Error:");
  838. foreach (string key in respData.Keys)
  839. {
  840. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Key: {0}", key);
  841. string[] lines = respData[key].ToString().Split(new char[] { '\n' });
  842. foreach (string line in lines)
  843. {
  844. m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}", line);
  845. }
  846. }
  847. }
  848. /// <summary>
  849. /// Group Request Tokens are an attempt to allow the groups service to authenticate
  850. /// requests.
  851. /// TODO: This broke after the big grid refactor, either find a better way, or discard this
  852. /// </summary>
  853. /// <param name="client"></param>
  854. /// <returns></returns>
  855. private void GetClientGroupRequestID(UUID AgentID, out string UserServiceURL, out UUID SessionID)
  856. {
  857. UserServiceURL = "";
  858. SessionID = UUID.Zero;
  859. // Need to rework this based on changes to User Services
  860. /*
  861. UserAccount userAccount = m_accountService.GetUserAccount(UUID.Zero,AgentID);
  862. if (userAccount == null)
  863. {
  864. // This should be impossible. If I've been passed a reference to a client
  865. // that client should be registered with the UserService. So something
  866. // is horribly wrong somewhere.
  867. m_log.WarnFormat("[GROUPS]: Could not find a UserServiceURL for {0}", AgentID);
  868. }
  869. else if (userProfile is ForeignUserProfileData)
  870. {
  871. // They aren't from around here
  872. ForeignUserProfileData fupd = (ForeignUserProfileData)userProfile;
  873. UserServiceURL = fupd.UserServerURI;
  874. SessionID = fupd.CurrentAgent.SessionID;
  875. }
  876. else
  877. {
  878. // They're a local user, use this:
  879. UserServiceURL = m_commManager.NetworkServersInfo.UserURL;
  880. SessionID = userProfile.CurrentAgent.SessionID;
  881. }
  882. */
  883. }
  884. }
  885. }
  886. namespace Nwc.XmlRpc
  887. {
  888. using System;
  889. using System.Collections;
  890. using System.IO;
  891. using System.Xml;
  892. using System.Net;
  893. using System.Text;
  894. using System.Reflection;
  895. /// <summary>Class supporting the request side of an XML-RPC transaction.</summary>
  896. public class ConfigurableKeepAliveXmlRpcRequest : XmlRpcRequest
  897. {
  898. private Encoding _encoding = new ASCIIEncoding();
  899. private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer();
  900. private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer();
  901. private bool _disableKeepAlive = true;
  902. public string RequestResponse = String.Empty;
  903. /// <summary>Instantiate an <c>XmlRpcRequest</c> for a specified method and parameters.</summary>
  904. /// <param name="methodName"><c>String</c> designating the <i>object.method</i> on the server the request
  905. /// should be directed to.</param>
  906. /// <param name="parameters"><c>ArrayList</c> of XML-RPC type parameters to invoke the request with.</param>
  907. public ConfigurableKeepAliveXmlRpcRequest(String methodName, IList parameters, bool disableKeepAlive)
  908. {
  909. MethodName = methodName;
  910. _params = parameters;
  911. _disableKeepAlive = disableKeepAlive;
  912. }
  913. /// <summary>Send the request to the server.</summary>
  914. /// <param name="url"><c>String</c> The url of the XML-RPC server.</param>
  915. /// <returns><c>XmlRpcResponse</c> The response generated.</returns>
  916. public XmlRpcResponse Send(String url)
  917. {
  918. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  919. if (request == null)
  920. throw new XmlRpcException(XmlRpcErrorCodes.TRANSPORT_ERROR,
  921. XmlRpcErrorCodes.TRANSPORT_ERROR_MSG + ": Could not create request with " + url);
  922. request.Method = "POST";
  923. request.ContentType = "text/xml";
  924. request.AllowWriteStreamBuffering = true;
  925. request.KeepAlive = !_disableKeepAlive;
  926. Stream stream = request.GetRequestStream();
  927. XmlTextWriter xml = new XmlTextWriter(stream, _encoding);
  928. _serializer.Serialize(xml, this);
  929. xml.Flush();
  930. xml.Close();
  931. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  932. StreamReader input = new StreamReader(response.GetResponseStream());
  933. string inputXml = input.ReadToEnd();
  934. XmlRpcResponse resp;
  935. try
  936. {
  937. resp = (XmlRpcResponse)_deserializer.Deserialize(inputXml);
  938. }
  939. catch (Exception e)
  940. {
  941. RequestResponse = inputXml;
  942. throw e;
  943. }
  944. input.Close();
  945. response.Close();
  946. return resp;
  947. }
  948. }
  949. }