diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs new file mode 100644 index 0000000..6857f35 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs | |||
@@ -0,0 +1,229 @@ | |||
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.Reflection; | ||
30 | using System.Text; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Servers; | ||
36 | using OpenSim.Framework.Client; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using Mono.Addins; | ||
40 | |||
41 | using OpenSim.Server.Base; | ||
42 | using OpenSim.Services.Interfaces; | ||
43 | |||
44 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | ||
45 | { | ||
46 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MuteListModuleTst")] | ||
47 | public class MuteListModuleTst : ISharedRegionModule | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | protected bool m_Enabled = false; | ||
53 | protected List<Scene> m_SceneList = new List<Scene>(); | ||
54 | protected IMuteListService m_service = null; | ||
55 | |||
56 | public void Initialise(IConfigSource config) | ||
57 | { | ||
58 | IConfig cnf = config.Configs["Messaging"]; | ||
59 | if (cnf == null) | ||
60 | return; | ||
61 | |||
62 | if (cnf.GetString("MuteListModule", "None") != "MuteListModuleTst") | ||
63 | return; | ||
64 | |||
65 | m_Enabled = true; | ||
66 | } | ||
67 | |||
68 | public void AddRegion(Scene scene) | ||
69 | { | ||
70 | } | ||
71 | |||
72 | public void RegionLoaded(Scene scene) | ||
73 | { | ||
74 | if (!m_Enabled) | ||
75 | return; | ||
76 | |||
77 | IXfer xfer = scene.RequestModuleInterface<IXfer>(); | ||
78 | if (xfer == null) | ||
79 | { | ||
80 | m_log.ErrorFormat("[MuteListModuleTst]: Xfer not availble in region {0}. Module Disabled", scene.Name); | ||
81 | m_Enabled = false; | ||
82 | return; | ||
83 | } | ||
84 | |||
85 | IMuteListService srv = scene.RequestModuleInterface<IMuteListService>(); | ||
86 | if(srv == null) | ||
87 | { | ||
88 | m_log.ErrorFormat("[MuteListModuleTst]: MuteListService not availble in region {0}. Module Disabled", scene.Name); | ||
89 | m_Enabled = false; | ||
90 | return; | ||
91 | } | ||
92 | lock (m_SceneList) | ||
93 | { | ||
94 | if(m_service == null) | ||
95 | m_service = srv; | ||
96 | m_SceneList.Add(scene); | ||
97 | scene.EventManager.OnNewClient += OnNewClient; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public void RemoveRegion(Scene scene) | ||
102 | { | ||
103 | lock (m_SceneList) | ||
104 | { | ||
105 | if(m_SceneList.Contains(scene)) | ||
106 | { | ||
107 | m_SceneList.Remove(scene); | ||
108 | scene.EventManager.OnNewClient -= OnNewClient; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public void PostInitialise() | ||
114 | { | ||
115 | if (!m_Enabled) | ||
116 | return; | ||
117 | |||
118 | m_log.Debug("[MuteListModuleTst]: enabled"); | ||
119 | } | ||
120 | |||
121 | public string Name | ||
122 | { | ||
123 | get { return "MuteListModuleTst"; } | ||
124 | } | ||
125 | |||
126 | public Type ReplaceableInterface | ||
127 | { | ||
128 | get { return null; } | ||
129 | } | ||
130 | |||
131 | public void Close() | ||
132 | { | ||
133 | } | ||
134 | |||
135 | private void OnNewClient(IClientAPI client) | ||
136 | { | ||
137 | client.OnMuteListRequest += OnMuteListRequest; | ||
138 | client.OnUpdateMuteListEntry += OnUpdateMuteListEntry; | ||
139 | client.OnRemoveMuteListEntry += OnRemoveMuteListEntry; | ||
140 | } | ||
141 | |||
142 | private void OnMuteListRequest(IClientAPI client, uint crc) | ||
143 | { | ||
144 | if (!m_Enabled) | ||
145 | { | ||
146 | if(crc == 0) | ||
147 | client.SendEmpytMuteList(); | ||
148 | else | ||
149 | client.SendUseCachedMuteList(); | ||
150 | return; | ||
151 | } | ||
152 | |||
153 | IXfer xfer = client.Scene.RequestModuleInterface<IXfer>(); | ||
154 | if (xfer == null) | ||
155 | { | ||
156 | if(crc == 0) | ||
157 | client.SendEmpytMuteList(); | ||
158 | else | ||
159 | client.SendUseCachedMuteList(); | ||
160 | return; | ||
161 | } | ||
162 | |||
163 | Byte[] data = m_service.MuteListRequest(client.AgentId, crc); | ||
164 | if (data == null) | ||
165 | { | ||
166 | if(crc == 0) | ||
167 | client.SendEmpytMuteList(); | ||
168 | else | ||
169 | client.SendUseCachedMuteList(); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | if (data.Length == 0) | ||
174 | { | ||
175 | client.SendEmpytMuteList(); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | if (data.Length == 1) | ||
180 | { | ||
181 | if(crc == 0) | ||
182 | client.SendEmpytMuteList(); | ||
183 | else | ||
184 | client.SendUseCachedMuteList(); | ||
185 | return; | ||
186 | } | ||
187 | |||
188 | string filename = "mutes" + client.AgentId.ToString(); | ||
189 | xfer.AddNewFile(filename, data); | ||
190 | client.SendMuteListUpdate(filename); | ||
191 | } | ||
192 | |||
193 | private void OnUpdateMuteListEntry(IClientAPI client, UUID muteID, string muteName, int muteType, uint muteFlags) | ||
194 | { | ||
195 | if (!m_Enabled) | ||
196 | return; | ||
197 | |||
198 | UUID agentID = client.AgentId; | ||
199 | if(muteType == 1) // agent | ||
200 | { | ||
201 | if(agentID == muteID) | ||
202 | return; | ||
203 | if(m_SceneList[0].Permissions.IsAdministrator(muteID)) | ||
204 | { | ||
205 | OnMuteListRequest(client, 0); | ||
206 | return; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | MuteData mute = new MuteData(); | ||
211 | mute.AgentID = agentID; | ||
212 | mute.MuteID = muteID; | ||
213 | mute.MuteName = muteName; | ||
214 | mute.MuteType = muteType; | ||
215 | mute.MuteFlags = (int)muteFlags; | ||
216 | mute.Stamp = Util.UnixTimeSinceEpoch(); | ||
217 | |||
218 | m_service.UpdateMute(mute); | ||
219 | } | ||
220 | |||
221 | private void OnRemoveMuteListEntry(IClientAPI client, UUID muteID, string muteName) | ||
222 | { | ||
223 | if (!m_Enabled) | ||
224 | return; | ||
225 | m_service.RemoveMute(client.AgentId, muteID, muteName); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | |||