aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs224
1 files changed, 224 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..7ade511
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModuleTst.cs
@@ -0,0 +1,224 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using System.Text;
31using log4net;
32using Nini.Config;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Framework.Servers;
36using OpenSim.Framework.Client;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using Mono.Addins;
40using OpenSim.Data;
41using OpenSim.Data.MySQL;
42using MySql.Data.MySqlClient;
43using System.Security.Cryptography;
44
45namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
46{
47 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MuteListModuleTst")]
48 public class MuteModuleTst : ISharedRegionModule
49 {
50 private static readonly ILog m_log = LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 protected bool m_Enabled = false;
54 protected List<Scene> m_SceneList = new List<Scene>();
55 protected MuteTableHandler m_MuteTable;
56 protected string m_DatabaseConnect;
57
58 public void Initialise(IConfigSource config)
59 {
60 IConfig cnf = config.Configs["Messaging"];
61 if (cnf == null)
62 return;
63
64 if (cnf.GetString("MuteListModule", "None") != "MuteListModuleTst")
65 return;
66
67 m_DatabaseConnect = cnf.GetString("MuteDatabaseConnect", String.Empty);
68 if (m_DatabaseConnect == String.Empty)
69 {
70 m_log.Debug("[MuteModuleTst]: MuteDatabaseConnect missing or empty");
71 return;
72 }
73
74 try
75 {
76 m_MuteTable = new MuteTableHandler(m_DatabaseConnect, "XMute", String.Empty);
77 }
78 catch
79 {
80 m_log.Error("[MuteListModuleTst]: Failed to open/create database table");
81 return;
82 }
83
84 m_Enabled = true;
85 }
86
87 public void AddRegion(Scene scene)
88 {
89 if (!m_Enabled)
90 return;
91
92 lock (m_SceneList)
93 {
94 m_SceneList.Add(scene);
95
96 scene.EventManager.OnNewClient += OnNewClient;
97 }
98 }
99
100 public void RegionLoaded(Scene scene)
101 {
102 if (!m_Enabled)
103 return;
104
105 IXfer xfer = scene.RequestModuleInterface<IXfer>();
106 if (xfer == null)
107 m_log.ErrorFormat("[MuteListModuleTst]: Xfer not availble in region {0}", scene.Name);
108 }
109
110 public void RemoveRegion(Scene scene)
111 {
112 if (!m_Enabled)
113 return;
114
115 lock (m_SceneList)
116 {
117 m_SceneList.Remove(scene);
118 }
119 }
120
121 public void PostInitialise()
122 {
123 if (!m_Enabled)
124 return;
125
126 m_log.Debug("[MuteListModuleTst]: Mute list enabled");
127 }
128
129 public string Name
130 {
131 get { return "MuteListModuleTst"; }
132 }
133
134 public Type ReplaceableInterface
135 {
136 get { return null; }
137 }
138
139 public void Close()
140 {
141 }
142
143 private void OnNewClient(IClientAPI client)
144 {
145 client.OnMuteListRequest += OnMuteListRequest;
146 client.OnUpdateMuteListEntry += OnUpdateMuteListEntry;
147 client.OnRemoveMuteListEntry += OnRemoveMuteListEntry;
148 }
149
150 private void OnMuteListRequest(IClientAPI client, uint crc)
151 {
152 IXfer xfer = client.Scene.RequestModuleInterface<IXfer>();
153 if (xfer == null)
154 {
155 if(crc == 0)
156 client.SendEmpytMuteList();
157 else
158 client.SendUseCachedMuteList();
159 return;
160 }
161
162 MuteData[] data = m_MuteTable.Get("AgentID", client.AgentId.ToString());
163 if (data == null || data.Length == 0)
164 {
165 if(crc == 0)
166 client.SendEmpytMuteList();
167 else
168 client.SendUseCachedMuteList();
169 return;
170 }
171
172 StringBuilder sb = new StringBuilder(16384);
173
174 foreach (MuteData d in data)
175 sb.AppendFormat("{0} {1} {2}|{3}\n",
176 d.MuteType,
177 d.MuteID.ToString(),
178 d.MuteName,
179 d.MuteFlags);
180
181 Byte[] filedata = Util.UTF8.GetBytes(sb.ToString());
182
183 uint dataCrc = Crc32.Compute(filedata);
184
185 if (dataCrc == crc)
186 {
187 if(crc == 0)
188 client.SendEmpytMuteList();
189 else
190 client.SendUseCachedMuteList();
191 return;
192 }
193
194 string filename = "mutes"+client.AgentId.ToString();
195 xfer.AddNewFile(filename, filedata);
196 client.SendMuteListUpdate(filename);
197 }
198
199 private void OnUpdateMuteListEntry(IClientAPI client, UUID muteID, string muteName, int muteType, uint muteFlags)
200 {
201 MuteData mute = new MuteData();
202
203 mute.AgentID = client.AgentId;
204 mute.MuteID = muteID;
205 mute.MuteName = muteName;
206 mute.MuteType = muteType;
207 mute.MuteFlags = (int)muteFlags;
208 mute.Stamp = Util.UnixTimeSinceEpoch();
209
210 m_MuteTable.Store(mute);
211 }
212
213 private void OnRemoveMuteListEntry(IClientAPI client, UUID muteID, string muteName)
214 {
215 m_MuteTable.Delete(new string[] { "AgentID",
216 "MuteID",
217 "MuteName" },
218 new string[] { client.AgentId.ToString(),
219 muteID.ToString(),
220 muteName });
221 }
222 }
223}
224