diff options
author | UbitUmarov | 2018-01-04 20:56:48 +0000 |
---|---|---|
committer | UbitUmarov | 2018-01-04 20:56:48 +0000 |
commit | 48dbba34416e31fa9d525007807b070d0eb25cf9 (patch) | |
tree | 7bf4c4e9c7804e8b232eaadab0ea66a7658c9c3d /OpenSim/Services/Connectors | |
parent | fix estates URI (diff) | |
download | opensim-SC_OLD-48dbba34416e31fa9d525007807b070d0eb25cf9.zip opensim-SC_OLD-48dbba34416e31fa9d525007807b070d0eb25cf9.tar.gz opensim-SC_OLD-48dbba34416e31fa9d525007807b070d0eb25cf9.tar.bz2 opensim-SC_OLD-48dbba34416e31fa9d525007807b070d0eb25cf9.tar.xz |
add more files for robust mutes suport. (module is still named MuteListModuleTst for testing, others in core will be removed later
Diffstat (limited to 'OpenSim/Services/Connectors')
-rw-r--r-- | OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs b/OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs new file mode 100644 index 0000000..e574c1d --- /dev/null +++ b/OpenSim/Services/Connectors/MuteList/MuteListServicesConnector.cs | |||
@@ -0,0 +1,183 @@ | |||
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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | |||
36 | using OpenSim.Framework.ServiceAuth; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenSim.Server.Base; | ||
40 | using OpenMetaverse; | ||
41 | |||
42 | namespace OpenSim.Services.Connectors | ||
43 | { | ||
44 | public class MuteListServicesConnector : BaseServiceConnector, IMuteListService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private string m_ServerURI = String.Empty; | ||
49 | |||
50 | public MuteListServicesConnector() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | public MuteListServicesConnector(string serverURI) | ||
55 | { | ||
56 | m_ServerURI = serverURI.TrimEnd('/') + "/mutelist"; | ||
57 | } | ||
58 | |||
59 | public MuteListServicesConnector(IConfigSource source) | ||
60 | { | ||
61 | Initialise(source); | ||
62 | } | ||
63 | |||
64 | public virtual void Initialise(IConfigSource source) | ||
65 | { | ||
66 | IConfig gridConfig = source.Configs["MuteListService"]; | ||
67 | if (gridConfig == null) | ||
68 | { | ||
69 | m_log.Error("[MUTELIST CONNECTOR]: MuteListService missing from configuration"); | ||
70 | throw new Exception("MuteList connector init error"); | ||
71 | } | ||
72 | |||
73 | string serviceURI = gridConfig.GetString("MuteListServerURI", | ||
74 | String.Empty); | ||
75 | |||
76 | if (serviceURI == String.Empty) | ||
77 | { | ||
78 | m_log.Error("[GRID USER CONNECTOR]: No Server URI named in section GridUserService"); | ||
79 | throw new Exception("GridUser connector init error"); | ||
80 | } | ||
81 | m_ServerURI = serviceURI + "/mutelist";; | ||
82 | base.Initialise(source, "MuteListService"); | ||
83 | } | ||
84 | |||
85 | #region IMuteListService | ||
86 | public Byte[] MuteListRequest(UUID agentID, uint crc) | ||
87 | { | ||
88 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
89 | sendData["METHOD"] = "get"; | ||
90 | sendData["agentid"] = agentID.ToString(); | ||
91 | sendData["mutecrc"] = crc.ToString(); | ||
92 | |||
93 | try | ||
94 | { | ||
95 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI, | ||
96 | ServerUtils.BuildQueryString(sendData), m_Auth); | ||
97 | if (reply != string.Empty) | ||
98 | { | ||
99 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
100 | |||
101 | if (replyData.ContainsKey("result")) | ||
102 | { | ||
103 | string datastr = replyData["result"].ToString(); | ||
104 | if(String.IsNullOrWhiteSpace(datastr)) | ||
105 | return null; | ||
106 | return Convert.FromBase64String(datastr); | ||
107 | } | ||
108 | else | ||
109 | m_log.DebugFormat("[MUTELIST CONNECTOR]: get reply data does not contain result field"); | ||
110 | } | ||
111 | else | ||
112 | m_log.DebugFormat("[MUTELIST CONNECTOR]: get received empty reply"); | ||
113 | } | ||
114 | catch (Exception e) | ||
115 | { | ||
116 | m_log.DebugFormat("[MUTELIST CONNECTOR]: Exception when contacting server at {0}: {1}", m_ServerURI, e.Message); | ||
117 | } | ||
118 | |||
119 | return null; | ||
120 | } | ||
121 | |||
122 | public bool UpdateMute(MuteData mute) | ||
123 | { | ||
124 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
125 | sendData["METHOD"] = "update"; | ||
126 | sendData["agentid"] = mute.AgentID.ToString(); | ||
127 | sendData["muteid"] = mute.MuteID.ToString(); | ||
128 | if(mute.MuteType != 0) | ||
129 | sendData["mutetype"] = mute.MuteType.ToString(); | ||
130 | if(mute.MuteFlags != 0) | ||
131 | sendData["muteflags"] = mute.MuteFlags.ToString(); | ||
132 | sendData["mutestamp"] = mute.Stamp.ToString(); | ||
133 | if(!String.IsNullOrEmpty(mute.MuteName)) | ||
134 | sendData["mutename"] = mute.MuteName; | ||
135 | |||
136 | return doSimplePost(ServerUtils.BuildQueryString(sendData), "update"); | ||
137 | } | ||
138 | |||
139 | public bool RemoveMute(UUID agentID, UUID muteID, string muteName) | ||
140 | { | ||
141 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
142 | sendData["METHOD"] = "delete"; | ||
143 | sendData["agentid"] = agentID.ToString(); | ||
144 | sendData["muteid"] = muteID.ToString(); | ||
145 | if(!String.IsNullOrEmpty(muteName)) | ||
146 | sendData["mutename"] = muteName; | ||
147 | |||
148 | return doSimplePost(ServerUtils.BuildQueryString(sendData), "remove"); | ||
149 | } | ||
150 | |||
151 | #endregion IMuteListService | ||
152 | |||
153 | private bool doSimplePost(string reqString, string meth) | ||
154 | { | ||
155 | try | ||
156 | { | ||
157 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", m_ServerURI, reqString, m_Auth); | ||
158 | if (reply != string.Empty) | ||
159 | { | ||
160 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
161 | |||
162 | if (replyData.ContainsKey("result")) | ||
163 | { | ||
164 | if (replyData["result"].ToString().ToLower() == "success") | ||
165 | return true; | ||
166 | else | ||
167 | return false; | ||
168 | } | ||
169 | else | ||
170 | m_log.DebugFormat("[MUTELIST CONNECTOR]: {0} reply data does not contain result field", meth); | ||
171 | } | ||
172 | else | ||
173 | m_log.DebugFormat("[MUTELIST CONNECTOR]: {0} received empty reply", meth); | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.DebugFormat("[MUTELIST CONNECTOR]: Exception when contacting server at {0}: {1}", m_ServerURI, e.Message); | ||
178 | } | ||
179 | |||
180 | return false; | ||
181 | } | ||
182 | } | ||
183 | } | ||