1
0

GroupsModule.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 OpenSim 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 libsecondlife;
  30. using Nini.Config;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Environment.Interfaces;
  33. using OpenSim.Region.Environment.Scenes;
  34. namespace OpenSim.Region.Environment.Modules
  35. {
  36. public class GroupsModule : IRegionModule
  37. {
  38. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  39. private List<Scene> m_scene = new List<Scene>();
  40. private Dictionary<LLUUID, IClientAPI> m_iclientmap = new Dictionary<LLUUID, IClientAPI>();
  41. private Dictionary<LLUUID, GroupData> m_groupmap = new Dictionary<LLUUID, GroupData>();
  42. private Dictionary<LLUUID, GroupList> m_grouplistmap = new Dictionary<LLUUID, GroupList>();
  43. public void Initialise(Scene scene, IConfigSource config)
  44. {
  45. lock (m_scene)
  46. {
  47. m_scene.Add(scene);
  48. }
  49. scene.EventManager.OnNewClient += OnNewClient;
  50. scene.EventManager.OnClientClosed += OnClientClosed;
  51. scene.EventManager.OnGridInstantMessageToGroupsModule += OnGridInstantMessage;
  52. //scene.EventManager.
  53. }
  54. private void OnNewClient(IClientAPI client)
  55. {
  56. // All friends establishment protocol goes over instant message
  57. // There's no way to send a message from the sim
  58. // to a user to 'add a friend' without causing dialog box spam
  59. //
  60. // The base set of friends are added when the user signs on in their XMLRPC response
  61. // Generated by LoginService. The friends are retreived from the database by the UserManager
  62. // Subscribe to instant messages
  63. client.OnInstantMessage += OnInstantMessage;
  64. client.OnAgentDataUpdateRequest += OnAgentDataUpdateRequest;
  65. lock (m_iclientmap)
  66. {
  67. if (!m_iclientmap.ContainsKey(client.AgentId))
  68. {
  69. m_iclientmap.Add(client.AgentId, client);
  70. }
  71. }
  72. GroupData OpenSimulatorGroup = new GroupData();
  73. OpenSimulatorGroup.ActiveGroupTitle = "OpenSimulator Tester";
  74. OpenSimulatorGroup.GroupID = new LLUUID("00000000-68f9-1111-024e-222222111120");
  75. OpenSimulatorGroup.GroupMembers.Add(client.AgentId);
  76. OpenSimulatorGroup.groupName = "OpenSimulator Testing";
  77. OpenSimulatorGroup.ActiveGroupPowers = GroupPowers.LandAllowSetHome;
  78. OpenSimulatorGroup.GroupTitles.Add("OpenSimulator Tester");
  79. lock (m_groupmap)
  80. {
  81. if (!m_groupmap.ContainsKey(client.AgentId))
  82. {
  83. m_groupmap.Add(client.AgentId, OpenSimulatorGroup);
  84. }
  85. }
  86. GroupList testGroupList = new GroupList();
  87. testGroupList.m_GroupList.Add(new LLUUID("00000000-68f9-1111-024e-222222111120"));
  88. lock (m_grouplistmap)
  89. {
  90. if (!m_grouplistmap.ContainsKey(client.AgentId))
  91. {
  92. m_grouplistmap.Add(client.AgentId, testGroupList);
  93. }
  94. }
  95. m_log.Info("[GROUP]: Adding " + client.FirstName + " " + client.LastName + " to OpenSimulator Tester group");
  96. }
  97. private void OnAgentDataUpdateRequest(IClientAPI remoteClient, LLUUID AgentID, LLUUID SessionID)
  98. {
  99. string firstname = remoteClient.FirstName;
  100. string lastname = remoteClient.LastName;
  101. LLUUID ActiveGroupID = LLUUID.Zero;
  102. uint ActiveGroupPowers = 0;
  103. string ActiveGroupName = "";
  104. string ActiveGroupTitle = "";
  105. bool foundUser = false;
  106. lock (m_iclientmap)
  107. {
  108. if (m_iclientmap.ContainsKey(remoteClient.AgentId))
  109. {
  110. foundUser = true;
  111. }
  112. }
  113. if (foundUser)
  114. {
  115. lock (m_groupmap)
  116. {
  117. if (m_groupmap.ContainsKey(remoteClient.AgentId))
  118. {
  119. GroupData grp = m_groupmap[remoteClient.AgentId];
  120. if (grp != null)
  121. {
  122. ActiveGroupID = grp.GroupID;
  123. ActiveGroupName = grp.groupName;
  124. ActiveGroupPowers = grp.groupPowers;
  125. ActiveGroupTitle = grp.ActiveGroupTitle;
  126. }
  127. //remoteClient.SendAgentDataUpdate(AgentID, ActiveGroupID, firstname, lastname, ActiveGroupPowers, ActiveGroupName, ActiveGroupTitle);
  128. }
  129. }
  130. }
  131. }
  132. private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
  133. LLUUID fromAgentSession, LLUUID toAgentID,
  134. LLUUID imSessionID, uint timestamp, string fromAgentName,
  135. string message, byte dialog, bool fromGroup, byte offline,
  136. uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
  137. byte[] binaryBucket)
  138. {
  139. }
  140. private void OnGridInstantMessage(GridInstantMessage msg)
  141. {
  142. // Trigger the above event handler
  143. OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
  144. new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
  145. msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
  146. new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
  147. msg.binaryBucket);
  148. }
  149. private void OnClientClosed(LLUUID agentID)
  150. {
  151. lock (m_iclientmap)
  152. {
  153. if (m_iclientmap.ContainsKey(agentID))
  154. {
  155. IClientAPI cli = m_iclientmap[agentID];
  156. if (cli != null)
  157. {
  158. m_log.Info("[GROUP]: Removing all reference to groups for " + cli.FirstName + " " + cli.LastName);
  159. }
  160. else
  161. {
  162. m_log.Info("[GROUP]: Removing all reference to groups for " + agentID.ToString());
  163. }
  164. m_iclientmap.Remove(agentID);
  165. }
  166. }
  167. lock (m_groupmap)
  168. {
  169. if (m_groupmap.ContainsKey(agentID))
  170. {
  171. m_groupmap.Remove(agentID);
  172. }
  173. }
  174. lock (m_grouplistmap)
  175. {
  176. if (m_grouplistmap.ContainsKey(agentID))
  177. {
  178. m_grouplistmap.Remove(agentID);
  179. }
  180. }
  181. GC.Collect();
  182. }
  183. public void PostInitialise()
  184. {
  185. }
  186. public void Close()
  187. {
  188. m_log.Info("[GROUP]: Shutting down group module.");
  189. lock (m_iclientmap)
  190. {
  191. m_iclientmap.Clear();
  192. }
  193. lock (m_groupmap)
  194. {
  195. m_groupmap.Clear();
  196. }
  197. lock (m_grouplistmap)
  198. {
  199. m_grouplistmap.Clear();
  200. }
  201. GC.Collect();
  202. }
  203. public string Name
  204. {
  205. get { return "GroupsModule"; }
  206. }
  207. public bool IsSharedModule
  208. {
  209. get { return true; }
  210. }
  211. }
  212. public class GroupData
  213. {
  214. public LLUUID GroupID;
  215. public string groupName;
  216. public string ActiveGroupTitle;
  217. public List<string> GroupTitles;
  218. public List<LLUUID> GroupMembers;
  219. public uint groupPowers = (uint)(GroupPowers.LandAllowLandmark | GroupPowers.LandAllowSetHome);
  220. public GroupPowers ActiveGroupPowers
  221. {
  222. set
  223. {
  224. groupPowers = (uint) value;
  225. }
  226. get
  227. {
  228. return (GroupPowers)groupPowers;
  229. }
  230. }
  231. public GroupData()
  232. {
  233. GroupTitles = new List<string>();
  234. GroupMembers = new List<LLUUID>();
  235. }
  236. }
  237. public class GroupList
  238. {
  239. public List<LLUUID> m_GroupList;
  240. public GroupList()
  241. {
  242. m_GroupList = new List<LLUUID>();
  243. }
  244. }
  245. }