1
0

GroupsServiceRemoteConnector.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.ServiceAuth;
  34. using OpenSim.Server.Base;
  35. using OpenMetaverse;
  36. using log4net;
  37. using Nini.Config;
  38. namespace OpenSim.Groups
  39. {
  40. public class GroupsServiceRemoteConnector
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. private string m_ServerURI;
  44. private IServiceAuth m_Auth;
  45. private object m_Lock = new object();
  46. public GroupsServiceRemoteConnector(IConfigSource config)
  47. {
  48. IConfig groupsConfig = config.Configs["Groups"];
  49. string url = groupsConfig.GetString("GroupsServerURI", string.Empty);
  50. if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
  51. throw new Exception(string.Format("[Groups.RemoteConnector]: Malformed groups server URL {0}. Fix it or disable the Groups feature.", url));
  52. m_ServerURI = url;
  53. if (!m_ServerURI.EndsWith("/"))
  54. m_ServerURI += "/";
  55. /// This is from BaseServiceConnector
  56. string authType = Util.GetConfigVarFromSections<string>(config, "AuthType", new string[] { "Network", "Groups" }, "None");
  57. switch (authType)
  58. {
  59. case "BasicHttpAuthentication":
  60. m_Auth = new BasicHttpAuthentication(config, "Groups");
  61. break;
  62. }
  63. ///
  64. m_log.DebugFormat("[Groups.RemoteConnector]: Groups server at {0}, authentication {1}",
  65. m_ServerURI, (m_Auth == null ? "None" : m_Auth.GetType().ToString()));
  66. }
  67. public ExtendedGroupRecord CreateGroup(string RequestingAgentID, string name, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment,
  68. bool allowPublish, bool maturePublish, UUID founderID, out string reason)
  69. {
  70. reason = string.Empty;
  71. ExtendedGroupRecord rec = new ExtendedGroupRecord();
  72. rec.AllowPublish = allowPublish;
  73. rec.Charter = charter;
  74. rec.FounderID = founderID;
  75. rec.GroupName = name;
  76. rec.GroupPicture = insigniaID;
  77. rec.MaturePublish = maturePublish;
  78. rec.MembershipFee = membershipFee;
  79. rec.OpenEnrollment = openEnrollment;
  80. rec.ShowInList = showInList;
  81. Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec);
  82. sendData["RequestingAgentID"] = RequestingAgentID;
  83. sendData["OP"] = "ADD";
  84. Dictionary<string, object> ret = MakeRequest("PUTGROUP", sendData);
  85. if (ret == null)
  86. return null;
  87. if (ret["RESULT"].ToString() == "NULL")
  88. {
  89. reason = ret["REASON"].ToString();
  90. return null;
  91. }
  92. return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
  93. }
  94. public ExtendedGroupRecord UpdateGroup(string RequestingAgentID, UUID groupID, string charter, bool showInList, UUID insigniaID, int membershipFee, bool openEnrollment, bool allowPublish, bool maturePublish)
  95. {
  96. ExtendedGroupRecord rec = new ExtendedGroupRecord();
  97. rec.AllowPublish = allowPublish;
  98. rec.Charter = charter;
  99. rec.GroupPicture = insigniaID;
  100. rec.MaturePublish = maturePublish;
  101. rec.GroupID = groupID;
  102. rec.MembershipFee = membershipFee;
  103. rec.OpenEnrollment = openEnrollment;
  104. rec.ShowInList = showInList;
  105. Dictionary<string, object> sendData = GroupsDataUtils.GroupRecord(rec);
  106. sendData["RequestingAgentID"] = RequestingAgentID;
  107. sendData["OP"] = "UPDATE";
  108. Dictionary<string, object> ret = MakeRequest("PUTGROUP", sendData);
  109. if (ret == null || (ret != null && (!ret.ContainsKey("RESULT") || ret["RESULT"].ToString() == "NULL")))
  110. return null;
  111. return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
  112. }
  113. public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName)
  114. {
  115. if (GroupID == UUID.Zero && (GroupName == null || (GroupName != null && GroupName == string.Empty)))
  116. return null;
  117. Dictionary<string, object> sendData = new Dictionary<string, object>();
  118. if (GroupID != UUID.Zero)
  119. sendData["GroupID"] = GroupID.ToString();
  120. if (!string.IsNullOrEmpty(GroupName))
  121. sendData["Name"] = GroupsDataUtils.Sanitize(GroupName);
  122. sendData["RequestingAgentID"] = RequestingAgentID;
  123. Dictionary<string, object> ret = MakeRequest("GETGROUP", sendData);
  124. if (ret == null || (ret != null && (!ret.ContainsKey("RESULT") || ret["RESULT"].ToString() == "NULL")))
  125. return null;
  126. return GroupsDataUtils.GroupRecord((Dictionary<string, object>)ret["RESULT"]);
  127. }
  128. public List<DirGroupsReplyData> FindGroups(string RequestingAgentID, string query)
  129. {
  130. List<DirGroupsReplyData> hits = new List<DirGroupsReplyData>();
  131. if (string.IsNullOrEmpty(query))
  132. return hits;
  133. Dictionary<string, object> sendData = new Dictionary<string, object>();
  134. sendData["Query"] = query;
  135. sendData["RequestingAgentID"] = RequestingAgentID;
  136. Dictionary<string, object> ret = MakeRequest("FINDGROUPS", sendData);
  137. if (ret == null)
  138. return hits;
  139. if (!ret.ContainsKey("RESULT"))
  140. return hits;
  141. if (ret["RESULT"].ToString() == "NULL")
  142. return hits;
  143. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  144. {
  145. DirGroupsReplyData m = GroupsDataUtils.DirGroupsReplyData((Dictionary<string, object>)v);
  146. hits.Add(m);
  147. }
  148. return hits;
  149. }
  150. public GroupMembershipData AddAgentToGroup(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID, string token, out string reason)
  151. {
  152. reason = string.Empty;
  153. Dictionary<string, object> sendData = new Dictionary<string,object>();
  154. sendData["AgentID"] = AgentID;
  155. sendData["GroupID"] = GroupID.ToString();
  156. sendData["RoleID"] = RoleID.ToString();
  157. sendData["RequestingAgentID"] = RequestingAgentID;
  158. sendData["AccessToken"] = token;
  159. Dictionary<string, object> ret = MakeRequest("ADDAGENTTOGROUP", sendData);
  160. if (ret == null)
  161. return null;
  162. if (!ret.ContainsKey("RESULT"))
  163. return null;
  164. if (ret["RESULT"].ToString() == "NULL")
  165. {
  166. reason = ret["REASON"].ToString();
  167. return null;
  168. }
  169. return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]);
  170. }
  171. public void RemoveAgentFromGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  172. {
  173. Dictionary<string, object> sendData = new Dictionary<string, object>();
  174. sendData["AgentID"] = AgentID;
  175. sendData["GroupID"] = GroupID.ToString();
  176. sendData["RequestingAgentID"] = RequestingAgentID;
  177. MakeRequest("REMOVEAGENTFROMGROUP", sendData);
  178. }
  179. public ExtendedGroupMembershipData GetMembership(string RequestingAgentID, string AgentID, UUID GroupID)
  180. {
  181. Dictionary<string, object> sendData = new Dictionary<string, object>();
  182. sendData["AgentID"] = AgentID;
  183. if (GroupID != UUID.Zero)
  184. sendData["GroupID"] = GroupID.ToString();
  185. sendData["RequestingAgentID"] = RequestingAgentID;
  186. Dictionary<string, object> ret = MakeRequest("GETMEMBERSHIP", sendData);
  187. if (ret == null)
  188. return null;
  189. if (!ret.ContainsKey("RESULT"))
  190. return null;
  191. if (ret["RESULT"].ToString() == "NULL")
  192. return null;
  193. return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]);
  194. }
  195. public List<GroupMembershipData> GetMemberships(string RequestingAgentID, string AgentID)
  196. {
  197. List<GroupMembershipData> memberships = new List<GroupMembershipData>();
  198. Dictionary<string, object> sendData = new Dictionary<string, object>();
  199. sendData["AgentID"] = AgentID;
  200. sendData["ALL"] = "true";
  201. sendData["RequestingAgentID"] = RequestingAgentID;
  202. Dictionary<string, object> ret = MakeRequest("GETMEMBERSHIP", sendData);
  203. if (ret == null)
  204. return memberships;
  205. if (!ret.ContainsKey("RESULT"))
  206. return memberships;
  207. if (ret["RESULT"].ToString() == "NULL")
  208. return memberships;
  209. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  210. {
  211. GroupMembershipData m = GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)v);
  212. memberships.Add(m);
  213. }
  214. return memberships;
  215. }
  216. public List<ExtendedGroupMembersData> GetGroupMembers(string RequestingAgentID, UUID GroupID)
  217. {
  218. List<ExtendedGroupMembersData> members = new List<ExtendedGroupMembersData>();
  219. Dictionary<string, object> sendData = new Dictionary<string, object>();
  220. sendData["GroupID"] = GroupID.ToString();
  221. sendData["RequestingAgentID"] = RequestingAgentID;
  222. Dictionary<string, object> ret = MakeRequest("GETGROUPMEMBERS", sendData);
  223. if (ret == null)
  224. return members;
  225. if (!ret.ContainsKey("RESULT"))
  226. return members;
  227. if (ret["RESULT"].ToString() == "NULL")
  228. return members;
  229. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  230. {
  231. ExtendedGroupMembersData m = GroupsDataUtils.GroupMembersData((Dictionary<string, object>)v);
  232. members.Add(m);
  233. }
  234. return members;
  235. }
  236. public bool AddGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers, out string reason)
  237. {
  238. reason = string.Empty;
  239. Dictionary<string, object> sendData = new Dictionary<string, object>();
  240. sendData["GroupID"] = groupID.ToString();
  241. sendData["RoleID"] = roleID.ToString();
  242. sendData["Name"] = GroupsDataUtils.Sanitize(name);
  243. sendData["Description"] = GroupsDataUtils.Sanitize(description);
  244. sendData["Title"] = GroupsDataUtils.Sanitize(title);
  245. sendData["Powers"] = powers.ToString();
  246. sendData["RequestingAgentID"] = RequestingAgentID;
  247. sendData["OP"] = "ADD";
  248. Dictionary<string, object> ret = MakeRequest("PUTROLE", sendData);
  249. if (ret == null)
  250. return false;
  251. if (!ret.ContainsKey("RESULT"))
  252. return false;
  253. if (ret["RESULT"].ToString().ToLower() != "true")
  254. {
  255. reason = ret["REASON"].ToString();
  256. return false;
  257. }
  258. return true;
  259. }
  260. public bool UpdateGroupRole(string RequestingAgentID, UUID groupID, UUID roleID, string name, string description, string title, ulong powers)
  261. {
  262. Dictionary<string, object> sendData = new Dictionary<string, object>();
  263. sendData["GroupID"] = groupID.ToString();
  264. sendData["RoleID"] = roleID.ToString();
  265. sendData["Name"] = GroupsDataUtils.Sanitize(name);
  266. sendData["Description"] = GroupsDataUtils.Sanitize(description);
  267. sendData["Title"] = GroupsDataUtils.Sanitize(title);
  268. sendData["Powers"] = powers.ToString();
  269. sendData["RequestingAgentID"] = RequestingAgentID;
  270. sendData["OP"] = "UPDATE";
  271. Dictionary<string, object> ret = MakeRequest("PUTROLE", sendData);
  272. if (ret == null)
  273. return false;
  274. if (!ret.ContainsKey("RESULT"))
  275. return false;
  276. if (ret["RESULT"].ToString().ToLower() != "true")
  277. return false;
  278. return true;
  279. }
  280. public void RemoveGroupRole(string RequestingAgentID, UUID groupID, UUID roleID)
  281. {
  282. Dictionary<string, object> sendData = new Dictionary<string, object>();
  283. sendData["GroupID"] = groupID.ToString();
  284. sendData["RoleID"] = roleID.ToString();
  285. sendData["RequestingAgentID"] = RequestingAgentID;
  286. MakeRequest("REMOVEROLE", sendData);
  287. }
  288. public List<GroupRolesData> GetGroupRoles(string RequestingAgentID, UUID GroupID)
  289. {
  290. List<GroupRolesData> roles = new List<GroupRolesData>();
  291. Dictionary<string, object> sendData = new Dictionary<string, object>();
  292. sendData["GroupID"] = GroupID.ToString();
  293. sendData["RequestingAgentID"] = RequestingAgentID;
  294. Dictionary<string, object> ret = MakeRequest("GETGROUPROLES", sendData);
  295. if (ret == null)
  296. return roles;
  297. if (!ret.ContainsKey("RESULT"))
  298. return roles;
  299. if (ret["RESULT"].ToString() == "NULL")
  300. return roles;
  301. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  302. {
  303. GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
  304. roles.Add(m);
  305. }
  306. return roles;
  307. }
  308. public List<ExtendedGroupRoleMembersData> GetGroupRoleMembers(string RequestingAgentID, UUID GroupID)
  309. {
  310. List<ExtendedGroupRoleMembersData> rmembers = new List<ExtendedGroupRoleMembersData>();
  311. Dictionary<string, object> sendData = new Dictionary<string, object>();
  312. sendData["GroupID"] = GroupID.ToString();
  313. sendData["RequestingAgentID"] = RequestingAgentID;
  314. Dictionary<string, object> ret = MakeRequest("GETROLEMEMBERS", sendData);
  315. if (ret == null)
  316. return rmembers;
  317. if (!ret.ContainsKey("RESULT"))
  318. return rmembers;
  319. if (ret["RESULT"].ToString() == "NULL")
  320. return rmembers;
  321. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  322. {
  323. ExtendedGroupRoleMembersData m = GroupsDataUtils.GroupRoleMembersData((Dictionary<string, object>)v);
  324. rmembers.Add(m);
  325. }
  326. return rmembers;
  327. }
  328. public bool AddAgentToGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  329. {
  330. Dictionary<string, object> sendData = new Dictionary<string, object>();
  331. sendData["AgentID"] = AgentID.ToString();
  332. sendData["GroupID"] = GroupID.ToString();
  333. sendData["RoleID"] = RoleID.ToString();
  334. sendData["RequestingAgentID"] = RequestingAgentID;
  335. sendData["OP"] = "ADD";
  336. Dictionary<string, object> ret = MakeRequest("AGENTROLE", sendData);
  337. if (ret == null)
  338. return false;
  339. if (!ret.ContainsKey("RESULT"))
  340. return false;
  341. if (ret["RESULT"].ToString().ToLower() != "true")
  342. return false;
  343. return true;
  344. }
  345. public bool RemoveAgentFromGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  346. {
  347. Dictionary<string, object> sendData = new Dictionary<string, object>();
  348. sendData["AgentID"] = AgentID.ToString();
  349. sendData["GroupID"] = GroupID.ToString();
  350. sendData["RoleID"] = RoleID.ToString();
  351. sendData["RequestingAgentID"] = RequestingAgentID;
  352. sendData["OP"] = "DELETE";
  353. Dictionary<string, object> ret = MakeRequest("AGENTROLE", sendData);
  354. if (ret == null)
  355. return false;
  356. if (!ret.ContainsKey("RESULT"))
  357. return false;
  358. if (ret["RESULT"].ToString().ToLower() != "true")
  359. return false;
  360. return true;
  361. }
  362. public List<GroupRolesData> GetAgentGroupRoles(string RequestingAgentID, string AgentID, UUID GroupID)
  363. {
  364. List<GroupRolesData> roles = new List<GroupRolesData>();
  365. Dictionary<string, object> sendData = new Dictionary<string, object>();
  366. sendData["AgentID"] = AgentID.ToString();
  367. sendData["GroupID"] = GroupID.ToString();
  368. sendData["RequestingAgentID"] = RequestingAgentID;
  369. Dictionary<string, object> ret = MakeRequest("GETAGENTROLES", sendData);
  370. if (ret == null)
  371. return roles;
  372. if (!ret.ContainsKey("RESULT"))
  373. return roles;
  374. if (ret["RESULT"].ToString() == "NULL")
  375. return roles;
  376. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  377. {
  378. GroupRolesData m = GroupsDataUtils.GroupRolesData((Dictionary<string, object>)v);
  379. roles.Add(m);
  380. }
  381. return roles;
  382. }
  383. public GroupMembershipData SetAgentActiveGroup(string RequestingAgentID, string AgentID, UUID GroupID)
  384. {
  385. Dictionary<string, object> sendData = new Dictionary<string, object>();
  386. sendData["AgentID"] = AgentID.ToString();
  387. sendData["GroupID"] = GroupID.ToString();
  388. sendData["RequestingAgentID"] = RequestingAgentID;
  389. sendData["OP"] = "GROUP";
  390. Dictionary<string, object> ret = MakeRequest("SETACTIVE", sendData);
  391. if (ret == null)
  392. return null;
  393. if (!ret.ContainsKey("RESULT"))
  394. return null;
  395. if (ret["RESULT"].ToString() == "NULL")
  396. return null;
  397. return GroupsDataUtils.GroupMembershipData((Dictionary<string, object>)ret["RESULT"]);
  398. }
  399. public void SetAgentActiveGroupRole(string RequestingAgentID, string AgentID, UUID GroupID, UUID RoleID)
  400. {
  401. Dictionary<string, object> sendData = new Dictionary<string, object>();
  402. sendData["AgentID"] = AgentID.ToString();
  403. sendData["GroupID"] = GroupID.ToString();
  404. sendData["RoleID"] = RoleID.ToString();
  405. sendData["RequestingAgentID"] = RequestingAgentID;
  406. sendData["OP"] = "ROLE";
  407. MakeRequest("SETACTIVE", sendData);
  408. }
  409. public void UpdateMembership(string RequestingAgentID, string AgentID, UUID GroupID, bool AcceptNotices, bool ListInProfile)
  410. {
  411. Dictionary<string, object> sendData = new Dictionary<string, object>();
  412. sendData["AgentID"] = AgentID.ToString();
  413. sendData["GroupID"] = GroupID.ToString();
  414. sendData["AcceptNotices"] = AcceptNotices.ToString();
  415. sendData["ListInProfile"] = ListInProfile.ToString();
  416. sendData["RequestingAgentID"] = RequestingAgentID;
  417. MakeRequest("UPDATEMEMBERSHIP", sendData);
  418. }
  419. public bool AddAgentToGroupInvite(string RequestingAgentID, UUID inviteID, UUID groupID, UUID roleID, string agentID)
  420. {
  421. Dictionary<string, object> sendData = new Dictionary<string, object>();
  422. sendData["InviteID"] = inviteID.ToString();
  423. sendData["GroupID"] = groupID.ToString();
  424. sendData["RoleID"] = roleID.ToString();
  425. sendData["AgentID"] = agentID.ToString();
  426. sendData["RequestingAgentID"] = RequestingAgentID;
  427. sendData["OP"] = "ADD";
  428. Dictionary<string, object> ret = MakeRequest("INVITE", sendData);
  429. if (ret == null)
  430. return false;
  431. if (!ret.ContainsKey("RESULT"))
  432. return false;
  433. if (ret["RESULT"].ToString().ToLower() != "true") // it may return "NULL"
  434. return false;
  435. return true;
  436. }
  437. public GroupInviteInfo GetAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  438. {
  439. Dictionary<string, object> sendData = new Dictionary<string, object>();
  440. sendData["InviteID"] = inviteID.ToString();
  441. sendData["RequestingAgentID"] = RequestingAgentID;
  442. sendData["OP"] = "GET";
  443. Dictionary<string, object> ret = MakeRequest("INVITE", sendData);
  444. if (ret == null)
  445. return null;
  446. if (!ret.ContainsKey("RESULT"))
  447. return null;
  448. if (ret["RESULT"].ToString() == "NULL")
  449. return null;
  450. return GroupsDataUtils.GroupInviteInfo((Dictionary<string, object>)ret["RESULT"]);
  451. }
  452. public void RemoveAgentToGroupInvite(string RequestingAgentID, UUID inviteID)
  453. {
  454. Dictionary<string, object> sendData = new Dictionary<string, object>();
  455. sendData["InviteID"] = inviteID.ToString();
  456. sendData["RequestingAgentID"] = RequestingAgentID;
  457. sendData["OP"] = "DELETE";
  458. MakeRequest("INVITE", sendData);
  459. }
  460. public bool AddGroupNotice(string RequestingAgentID, UUID groupID, UUID noticeID, string fromName, string subject, string message,
  461. bool hasAttachment, byte attType, string attName, UUID attItemID, string attOwnerID)
  462. {
  463. Dictionary<string, object> sendData = new Dictionary<string, object>();
  464. sendData["GroupID"] = groupID.ToString();
  465. sendData["NoticeID"] = noticeID.ToString();
  466. sendData["FromName"] = GroupsDataUtils.Sanitize(fromName);
  467. sendData["Subject"] = GroupsDataUtils.Sanitize(subject);
  468. sendData["Message"] = GroupsDataUtils.Sanitize(message);
  469. sendData["HasAttachment"] = hasAttachment.ToString();
  470. if (hasAttachment)
  471. {
  472. sendData["AttachmentType"] = attType.ToString();
  473. sendData["AttachmentName"] = attName.ToString();
  474. sendData["AttachmentItemID"] = attItemID.ToString();
  475. sendData["AttachmentOwnerID"] = attOwnerID;
  476. }
  477. sendData["RequestingAgentID"] = RequestingAgentID;
  478. Dictionary<string, object> ret = MakeRequest("ADDNOTICE", sendData);
  479. if (ret == null)
  480. return false;
  481. if (!ret.ContainsKey("RESULT"))
  482. return false;
  483. if (ret["RESULT"].ToString().ToLower() != "true")
  484. return false;
  485. return true;
  486. }
  487. public GroupNoticeInfo GetGroupNotice(string RequestingAgentID, UUID noticeID)
  488. {
  489. Dictionary<string, object> sendData = new Dictionary<string, object>();
  490. sendData["NoticeID"] = noticeID.ToString();
  491. sendData["RequestingAgentID"] = RequestingAgentID;
  492. Dictionary<string, object> ret = MakeRequest("GETNOTICES", sendData);
  493. if (ret == null)
  494. return null;
  495. if (!ret.ContainsKey("RESULT"))
  496. return null;
  497. if (ret["RESULT"].ToString() == "NULL")
  498. return null;
  499. return GroupsDataUtils.GroupNoticeInfo((Dictionary<string, object>)ret["RESULT"]);
  500. }
  501. public List<ExtendedGroupNoticeData> GetGroupNotices(string RequestingAgentID, UUID GroupID)
  502. {
  503. List<ExtendedGroupNoticeData> notices = new List<ExtendedGroupNoticeData>();
  504. Dictionary<string, object> sendData = new Dictionary<string, object>();
  505. sendData["GroupID"] = GroupID.ToString();
  506. sendData["RequestingAgentID"] = RequestingAgentID;
  507. Dictionary<string, object> ret = MakeRequest("GETNOTICES", sendData);
  508. if (ret == null)
  509. return notices;
  510. if (!ret.ContainsKey("RESULT"))
  511. return notices;
  512. if (ret["RESULT"].ToString() == "NULL")
  513. return notices;
  514. foreach (object v in ((Dictionary<string, object>)ret["RESULT"]).Values)
  515. {
  516. ExtendedGroupNoticeData m = GroupsDataUtils.GroupNoticeData((Dictionary<string, object>)v);
  517. notices.Add(m);
  518. }
  519. return notices;
  520. }
  521. #region Make Request
  522. private Dictionary<string, object> MakeRequest(string method, Dictionary<string, object> sendData)
  523. {
  524. sendData["METHOD"] = method;
  525. string reply = string.Empty;
  526. lock (m_Lock)
  527. reply = SynchronousRestFormsRequester.MakeRequest("POST",
  528. m_ServerURI + "groups",
  529. ServerUtils.BuildQueryString(sendData),
  530. m_Auth);
  531. if (reply == string.Empty)
  532. return null;
  533. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(
  534. reply);
  535. return replyData;
  536. }
  537. #endregion
  538. }
  539. }