1
0

GroupsExtendedData.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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 OpenSim.Framework;
  30. using OpenMetaverse;
  31. namespace OpenSim.Groups
  32. {
  33. public class ExtendedGroupRecord : GroupRecord
  34. {
  35. public int MemberCount;
  36. public int RoleCount;
  37. public string ServiceLocation;
  38. public string FounderUUI;
  39. }
  40. public class ExtendedGroupMembershipData : GroupMembershipData
  41. {
  42. public string AccessToken;
  43. }
  44. public class ExtendedGroupMembersData
  45. {
  46. // This is the only difference: this is a string
  47. public string AgentID;
  48. public int Contribution;
  49. public string OnlineStatus;
  50. public ulong AgentPowers;
  51. public string Title;
  52. public bool IsOwner;
  53. public bool ListInProfile;
  54. public bool AcceptNotices;
  55. public string AccessToken;
  56. }
  57. public class ExtendedGroupRoleMembersData
  58. {
  59. public UUID RoleID;
  60. // This is the only difference: this is a string
  61. public string MemberID;
  62. }
  63. public struct ExtendedGroupNoticeData
  64. {
  65. public UUID NoticeID;
  66. public uint Timestamp;
  67. public string FromName;
  68. public string Subject;
  69. public bool HasAttachment;
  70. public byte AttachmentType;
  71. public string AttachmentName;
  72. public UUID AttachmentItemID;
  73. public string AttachmentOwnerID;
  74. public GroupNoticeData ToGroupNoticeData()
  75. {
  76. GroupNoticeData n = new GroupNoticeData();
  77. n.FromName = this.FromName;
  78. n.AssetType = this.AttachmentType;
  79. n.HasAttachment = this.HasAttachment;
  80. n.NoticeID = this.NoticeID;
  81. n.Subject = this.Subject;
  82. n.Timestamp = this.Timestamp;
  83. return n;
  84. }
  85. }
  86. public class GroupsDataUtils
  87. {
  88. public static string Sanitize(string s)
  89. {
  90. return s == null ? string.Empty : s;
  91. }
  92. public static Dictionary<string, object> GroupRecord(ExtendedGroupRecord grec)
  93. {
  94. Dictionary<string, object> dict = new Dictionary<string, object>();
  95. if (grec == null)
  96. return dict;
  97. dict["AllowPublish"] = grec.AllowPublish.ToString();
  98. dict["Charter"] = Sanitize(grec.Charter);
  99. dict["FounderID"] = grec.FounderID.ToString();
  100. dict["FounderUUI"] = Sanitize(grec.FounderUUI);
  101. dict["GroupID"] = grec.GroupID.ToString();
  102. dict["GroupName"] = Sanitize(grec.GroupName);
  103. dict["InsigniaID"] = grec.GroupPicture.ToString();
  104. dict["MaturePublish"] = grec.MaturePublish.ToString();
  105. dict["MembershipFee"] = grec.MembershipFee.ToString();
  106. dict["OpenEnrollment"] = grec.OpenEnrollment.ToString();
  107. dict["OwnerRoleID"] = grec.OwnerRoleID.ToString();
  108. dict["ServiceLocation"] = Sanitize(grec.ServiceLocation);
  109. dict["ShownInList"] = grec.ShowInList.ToString();
  110. dict["MemberCount"] = grec.MemberCount.ToString();
  111. dict["RoleCount"] = grec.RoleCount.ToString();
  112. return dict;
  113. }
  114. public static ExtendedGroupRecord GroupRecord(Dictionary<string, object> dict)
  115. {
  116. if (dict == null)
  117. return null;
  118. ExtendedGroupRecord grec = new ExtendedGroupRecord();
  119. if (dict.ContainsKey("AllowPublish") && dict["AllowPublish"] != null)
  120. grec.AllowPublish = bool.Parse(dict["AllowPublish"].ToString());
  121. if (dict.ContainsKey("Charter") && dict["Charter"] != null)
  122. grec.Charter = dict["Charter"].ToString();
  123. else
  124. grec.Charter = string.Empty;
  125. if (dict.ContainsKey("FounderID") && dict["FounderID"] != null)
  126. grec.FounderID = UUID.Parse(dict["FounderID"].ToString());
  127. if (dict.ContainsKey("FounderUUI") && dict["FounderUUI"] != null)
  128. grec.FounderUUI = dict["FounderUUI"].ToString();
  129. else
  130. grec.FounderUUI = string.Empty;
  131. if (dict.ContainsKey("GroupID") && dict["GroupID"] != null)
  132. grec.GroupID = UUID.Parse(dict["GroupID"].ToString());
  133. if (dict.ContainsKey("GroupName") && dict["GroupName"] != null)
  134. grec.GroupName = dict["GroupName"].ToString();
  135. else
  136. grec.GroupName = string.Empty;
  137. if (dict.ContainsKey("InsigniaID") && dict["InsigniaID"] != null)
  138. grec.GroupPicture = UUID.Parse(dict["InsigniaID"].ToString());
  139. if (dict.ContainsKey("MaturePublish") && dict["MaturePublish"] != null)
  140. grec.MaturePublish = bool.Parse(dict["MaturePublish"].ToString());
  141. if (dict.ContainsKey("MembershipFee") && dict["MembershipFee"] != null)
  142. grec.MembershipFee = Int32.Parse(dict["MembershipFee"].ToString());
  143. if (dict.ContainsKey("OpenEnrollment") && dict["OpenEnrollment"] != null)
  144. grec.OpenEnrollment = bool.Parse(dict["OpenEnrollment"].ToString());
  145. if (dict.ContainsKey("OwnerRoleID") && dict["OwnerRoleID"] != null)
  146. grec.OwnerRoleID = UUID.Parse(dict["OwnerRoleID"].ToString());
  147. if (dict.ContainsKey("ServiceLocation") && dict["ServiceLocation"] != null)
  148. grec.ServiceLocation = dict["ServiceLocation"].ToString();
  149. else
  150. grec.GroupName = string.Empty;
  151. if (dict.ContainsKey("ShownInList") && dict["ShownInList"] != null)
  152. grec.ShowInList = bool.Parse(dict["ShownInList"].ToString());
  153. if (dict.ContainsKey("MemberCount") && dict["MemberCount"] != null)
  154. grec.MemberCount = Int32.Parse(dict["MemberCount"].ToString());
  155. if (dict.ContainsKey("RoleCount") && dict["RoleCount"] != null)
  156. grec.RoleCount = Int32.Parse(dict["RoleCount"].ToString());
  157. return grec;
  158. }
  159. public static Dictionary<string, object> GroupMembershipData(ExtendedGroupMembershipData membership)
  160. {
  161. Dictionary<string, object> dict = new Dictionary<string, object>();
  162. if (membership == null)
  163. return dict;
  164. dict["AcceptNotices"] = membership.AcceptNotices.ToString();
  165. dict["AccessToken"] = Sanitize(membership.AccessToken);
  166. dict["Active"] = membership.Active.ToString();
  167. dict["ActiveRole"] = membership.ActiveRole.ToString();
  168. dict["AllowPublish"] = membership.AllowPublish.ToString();
  169. dict["Charter"] = Sanitize(membership.Charter);
  170. dict["Contribution"] = membership.Contribution.ToString();
  171. dict["FounderID"] = membership.FounderID.ToString();
  172. dict["GroupID"] = membership.GroupID.ToString();
  173. dict["GroupName"] = Sanitize(membership.GroupName);
  174. dict["GroupPicture"] = membership.GroupPicture.ToString();
  175. dict["GroupPowers"] = membership.GroupPowers.ToString();
  176. dict["GroupTitle"] = Sanitize(membership.GroupTitle);
  177. dict["ListInProfile"] = membership.ListInProfile.ToString();
  178. dict["MaturePublish"] = membership.MaturePublish.ToString();
  179. dict["MembershipFee"] = membership.MembershipFee.ToString();
  180. dict["OpenEnrollment"] = membership.OpenEnrollment.ToString();
  181. dict["ShowInList"] = membership.ShowInList.ToString();
  182. return dict;
  183. }
  184. public static ExtendedGroupMembershipData GroupMembershipData(Dictionary<string, object> dict)
  185. {
  186. if (dict == null)
  187. return null;
  188. ExtendedGroupMembershipData membership = new ExtendedGroupMembershipData();
  189. if (dict.ContainsKey("AcceptNotices") && dict["AcceptNotices"] != null)
  190. membership.AcceptNotices = bool.Parse(dict["AcceptNotices"].ToString());
  191. if (dict.ContainsKey("AccessToken") && dict["AccessToken"] != null)
  192. membership.AccessToken = dict["AccessToken"].ToString();
  193. else
  194. membership.AccessToken = string.Empty;
  195. if (dict.ContainsKey("Active") && dict["Active"] != null)
  196. membership.Active = bool.Parse(dict["Active"].ToString());
  197. if (dict.ContainsKey("ActiveRole") && dict["ActiveRole"] != null)
  198. membership.ActiveRole = UUID.Parse(dict["ActiveRole"].ToString());
  199. if (dict.ContainsKey("AllowPublish") && dict["AllowPublish"] != null)
  200. membership.AllowPublish = bool.Parse(dict["AllowPublish"].ToString());
  201. if (dict.ContainsKey("Charter") && dict["Charter"] != null)
  202. membership.Charter = dict["Charter"].ToString();
  203. else
  204. membership.Charter = string.Empty;
  205. if (dict.ContainsKey("Contribution") && dict["Contribution"] != null)
  206. membership.Contribution = Int32.Parse(dict["Contribution"].ToString());
  207. if (dict.ContainsKey("FounderID") && dict["FounderID"] != null)
  208. membership.FounderID = UUID.Parse(dict["FounderID"].ToString());
  209. if (dict.ContainsKey("GroupID") && dict["GroupID"] != null)
  210. membership.GroupID = UUID.Parse(dict["GroupID"].ToString());
  211. if (dict.ContainsKey("GroupName") && dict["GroupName"] != null)
  212. membership.GroupName = dict["GroupName"].ToString();
  213. else
  214. membership.GroupName = string.Empty;
  215. if (dict.ContainsKey("GroupPicture") && dict["GroupPicture"] != null)
  216. membership.GroupPicture = UUID.Parse(dict["GroupPicture"].ToString());
  217. if (dict.ContainsKey("GroupPowers") && dict["GroupPowers"] != null)
  218. membership.GroupPowers = UInt64.Parse(dict["GroupPowers"].ToString());
  219. if (dict.ContainsKey("GroupTitle") && dict["GroupTitle"] != null)
  220. membership.GroupTitle = dict["GroupTitle"].ToString();
  221. else
  222. membership.GroupTitle = string.Empty;
  223. if (dict.ContainsKey("ListInProfile") && dict["ListInProfile"] != null)
  224. membership.ListInProfile = bool.Parse(dict["ListInProfile"].ToString());
  225. if (dict.ContainsKey("MaturePublish") && dict["MaturePublish"] != null)
  226. membership.MaturePublish = bool.Parse(dict["MaturePublish"].ToString());
  227. if (dict.ContainsKey("MembershipFee") && dict["MembershipFee"] != null)
  228. membership.MembershipFee = Int32.Parse(dict["MembershipFee"].ToString());
  229. if (dict.ContainsKey("OpenEnrollment") && dict["OpenEnrollment"] != null)
  230. membership.OpenEnrollment = bool.Parse(dict["OpenEnrollment"].ToString());
  231. if (dict.ContainsKey("ShowInList") && dict["ShowInList"] != null)
  232. membership.ShowInList = bool.Parse(dict["ShowInList"].ToString());
  233. return membership;
  234. }
  235. public static Dictionary<string, object> GroupMembersData(ExtendedGroupMembersData member)
  236. {
  237. Dictionary<string, object> dict = new Dictionary<string, object>();
  238. dict["AcceptNotices"] = member.AcceptNotices.ToString();
  239. dict["AccessToken"] = Sanitize(member.AccessToken);
  240. dict["AgentID"] = Sanitize(member.AgentID);
  241. dict["AgentPowers"] = member.AgentPowers.ToString();
  242. dict["Contribution"] = member.Contribution.ToString();
  243. dict["IsOwner"] = member.IsOwner.ToString();
  244. dict["ListInProfile"] = member.ListInProfile.ToString();
  245. dict["OnlineStatus"] = Sanitize(member.OnlineStatus);
  246. dict["Title"] = Sanitize(member.Title);
  247. return dict;
  248. }
  249. public static ExtendedGroupMembersData GroupMembersData(Dictionary<string, object> dict)
  250. {
  251. ExtendedGroupMembersData member = new ExtendedGroupMembersData();
  252. if (dict == null)
  253. return member;
  254. if (dict.ContainsKey("AcceptNotices") && dict["AcceptNotices"] != null)
  255. member.AcceptNotices = bool.Parse(dict["AcceptNotices"].ToString());
  256. if (dict.ContainsKey("AccessToken") && dict["AccessToken"] != null)
  257. member.AccessToken = Sanitize(dict["AccessToken"].ToString());
  258. else
  259. member.AccessToken = string.Empty;
  260. if (dict.ContainsKey("AgentID") && dict["AgentID"] != null)
  261. member.AgentID = Sanitize(dict["AgentID"].ToString());
  262. else
  263. member.AgentID = UUID.Zero.ToString();
  264. if (dict.ContainsKey("AgentPowers") && dict["AgentPowers"] != null)
  265. member.AgentPowers = UInt64.Parse(dict["AgentPowers"].ToString());
  266. if (dict.ContainsKey("Contribution") && dict["Contribution"] != null)
  267. member.Contribution = Int32.Parse(dict["Contribution"].ToString());
  268. if (dict.ContainsKey("IsOwner") && dict["IsOwner"] != null)
  269. member.IsOwner = bool.Parse(dict["IsOwner"].ToString());
  270. if (dict.ContainsKey("ListInProfile") && dict["ListInProfile"] != null)
  271. member.ListInProfile = bool.Parse(dict["ListInProfile"].ToString());
  272. if (dict.ContainsKey("OnlineStatus") && dict["OnlineStatus"] != null)
  273. member.OnlineStatus = Sanitize(dict["OnlineStatus"].ToString());
  274. else
  275. member.OnlineStatus = string.Empty;
  276. if (dict.ContainsKey("Title") && dict["Title"] != null)
  277. member.Title = Sanitize(dict["Title"].ToString());
  278. else
  279. member.Title = string.Empty;
  280. return member;
  281. }
  282. public static Dictionary<string, object> GroupRolesData(GroupRolesData role)
  283. {
  284. Dictionary<string, object> dict = new Dictionary<string, object>();
  285. dict["Description"] = Sanitize(role.Description);
  286. dict["Members"] = role.Members.ToString();
  287. dict["Name"] = Sanitize(role.Name);
  288. dict["Powers"] = role.Powers.ToString();
  289. dict["RoleID"] = role.RoleID.ToString();
  290. dict["Title"] = Sanitize(role.Title);
  291. return dict;
  292. }
  293. public static GroupRolesData GroupRolesData(Dictionary<string, object> dict)
  294. {
  295. GroupRolesData role = new GroupRolesData();
  296. if (dict == null)
  297. return role;
  298. if (dict.ContainsKey("Description") && dict["Description"] != null)
  299. role.Description = Sanitize(dict["Description"].ToString());
  300. else
  301. role.Description = string.Empty;
  302. if (dict.ContainsKey("Members") && dict["Members"] != null)
  303. role.Members = Int32.Parse(dict["Members"].ToString());
  304. if (dict.ContainsKey("Name") && dict["Name"] != null)
  305. role.Name = Sanitize(dict["Name"].ToString());
  306. else
  307. role.Name = string.Empty;
  308. if (dict.ContainsKey("Powers") && dict["Powers"] != null)
  309. role.Powers = UInt64.Parse(dict["Powers"].ToString());
  310. if (dict.ContainsKey("Title") && dict["Title"] != null)
  311. role.Title = Sanitize(dict["Title"].ToString());
  312. else
  313. role.Title = string.Empty;
  314. if (dict.ContainsKey("RoleID") && dict["RoleID"] != null)
  315. role.RoleID = UUID.Parse(dict["RoleID"].ToString());
  316. return role;
  317. }
  318. public static Dictionary<string, object> GroupRoleMembersData(ExtendedGroupRoleMembersData rmember)
  319. {
  320. Dictionary<string, object> dict = new Dictionary<string, object>();
  321. dict["RoleID"] = rmember.RoleID.ToString();
  322. dict["MemberID"] = rmember.MemberID;
  323. return dict;
  324. }
  325. public static ExtendedGroupRoleMembersData GroupRoleMembersData(Dictionary<string, object> dict)
  326. {
  327. ExtendedGroupRoleMembersData rmember = new ExtendedGroupRoleMembersData();
  328. if (dict.ContainsKey("RoleID") && dict["RoleID"] != null)
  329. rmember.RoleID = new UUID(dict["RoleID"].ToString());
  330. if (dict.ContainsKey("MemberID") && dict["MemberID"] != null)
  331. rmember.MemberID = dict["MemberID"].ToString();
  332. return rmember;
  333. }
  334. public static Dictionary<string, object> GroupInviteInfo(GroupInviteInfo invite)
  335. {
  336. Dictionary<string, object> dict = new Dictionary<string, object>();
  337. dict["InviteID"] = invite.InviteID.ToString();
  338. dict["GroupID"] = invite.GroupID.ToString();
  339. dict["RoleID"] = invite.RoleID.ToString();
  340. dict["AgentID"] = invite.AgentID;
  341. return dict;
  342. }
  343. public static GroupInviteInfo GroupInviteInfo(Dictionary<string, object> dict)
  344. {
  345. if (dict == null)
  346. return null;
  347. GroupInviteInfo invite = new GroupInviteInfo();
  348. invite.InviteID = new UUID(dict["InviteID"].ToString());
  349. invite.GroupID = new UUID(dict["GroupID"].ToString());
  350. invite.RoleID = new UUID(dict["RoleID"].ToString());
  351. invite.AgentID = Sanitize(dict["AgentID"].ToString());
  352. return invite;
  353. }
  354. public static Dictionary<string, object> GroupNoticeData(ExtendedGroupNoticeData notice)
  355. {
  356. Dictionary<string, object> dict = new Dictionary<string, object>();
  357. dict["NoticeID"] = notice.NoticeID.ToString();
  358. dict["Timestamp"] = notice.Timestamp.ToString();
  359. dict["FromName"] = Sanitize(notice.FromName);
  360. dict["Subject"] = Sanitize(notice.Subject);
  361. dict["HasAttachment"] = notice.HasAttachment.ToString();
  362. dict["AttachmentItemID"] = notice.AttachmentItemID.ToString();
  363. dict["AttachmentName"] = Sanitize(notice.AttachmentName);
  364. dict["AttachmentType"] = notice.AttachmentType.ToString();
  365. dict["AttachmentOwnerID"] = Sanitize(notice.AttachmentOwnerID);
  366. return dict;
  367. }
  368. public static ExtendedGroupNoticeData GroupNoticeData(Dictionary<string, object> dict)
  369. {
  370. ExtendedGroupNoticeData notice = new ExtendedGroupNoticeData();
  371. if (dict == null)
  372. return notice;
  373. notice.NoticeID = new UUID(dict["NoticeID"].ToString());
  374. notice.Timestamp = UInt32.Parse(dict["Timestamp"].ToString());
  375. notice.FromName = Sanitize(dict["FromName"].ToString());
  376. notice.Subject = Sanitize(dict["Subject"].ToString());
  377. notice.HasAttachment = bool.Parse(dict["HasAttachment"].ToString());
  378. notice.AttachmentItemID = new UUID(dict["AttachmentItemID"].ToString());
  379. notice.AttachmentName = dict["AttachmentName"].ToString();
  380. notice.AttachmentType = byte.Parse(dict["AttachmentType"].ToString());
  381. notice.AttachmentOwnerID = dict["AttachmentOwnerID"].ToString();
  382. return notice;
  383. }
  384. public static Dictionary<string, object> GroupNoticeInfo(GroupNoticeInfo notice)
  385. {
  386. Dictionary<string, object> dict = GroupNoticeData(notice.noticeData);
  387. dict["GroupID"] = notice.GroupID.ToString();
  388. dict["Message"] = Sanitize(notice.Message);
  389. return dict;
  390. }
  391. public static GroupNoticeInfo GroupNoticeInfo(Dictionary<string, object> dict)
  392. {
  393. GroupNoticeInfo notice = new GroupNoticeInfo();
  394. notice.noticeData = GroupNoticeData(dict);
  395. notice.GroupID = new UUID(dict["GroupID"].ToString());
  396. notice.Message = Sanitize(dict["Message"].ToString());
  397. return notice;
  398. }
  399. public static Dictionary<string, object> DirGroupsReplyData(DirGroupsReplyData g)
  400. {
  401. Dictionary<string, object> dict = new Dictionary<string, object>();
  402. dict["GroupID"] = g.groupID;
  403. dict["Name"] = g.groupName;
  404. dict["NMembers"] = g.members;
  405. dict["SearchOrder"] = g.searchOrder;
  406. return dict;
  407. }
  408. public static DirGroupsReplyData DirGroupsReplyData(Dictionary<string, object> dict)
  409. {
  410. DirGroupsReplyData g;
  411. g.groupID = new UUID(dict["GroupID"].ToString());
  412. g.groupName = dict["Name"].ToString();
  413. Int32.TryParse(dict["NMembers"].ToString(), out g.members);
  414. float.TryParse(dict["SearchOrder"].ToString(), out g.searchOrder);
  415. return g;
  416. }
  417. }
  418. }