diff options
Diffstat (limited to 'OpenSim/Services/Connectors/MapImage')
-rw-r--r-- | OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs index 30bfb70..c91ed84 100644 --- a/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs +++ b/OpenSim/Services/Connectors/MapImage/MapImageServicesConnector.cs | |||
@@ -35,7 +35,8 @@ using System.Reflection; | |||
35 | using Nini.Config; | 35 | using Nini.Config; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Console; | 37 | using OpenSim.Framework.Console; |
38 | using OpenSim.Framework.Communications; | 38 | |
39 | using OpenSim.Framework.ServiceAuth; | ||
39 | using OpenSim.Server.Base; | 40 | using OpenSim.Server.Base; |
40 | using OpenSim.Services.Interfaces; | 41 | using OpenSim.Services.Interfaces; |
41 | using OpenMetaverse; | 42 | using OpenMetaverse; |
@@ -43,7 +44,7 @@ using OpenMetaverse.StructuredData; | |||
43 | 44 | ||
44 | namespace OpenSim.Services.Connectors | 45 | namespace OpenSim.Services.Connectors |
45 | { | 46 | { |
46 | public class MapImageServicesConnector : IMapImageService | 47 | public class MapImageServicesConnector : BaseServiceConnector, IMapImageService |
47 | { | 48 | { |
48 | private static readonly ILog m_log = | 49 | private static readonly ILog m_log = |
49 | LogManager.GetLogger( | 50 | LogManager.GetLogger( |
@@ -84,26 +85,26 @@ namespace OpenSim.Services.Connectors | |||
84 | } | 85 | } |
85 | m_ServerURI = serviceURI; | 86 | m_ServerURI = serviceURI; |
86 | m_ServerURI = serviceURI.TrimEnd('/'); | 87 | m_ServerURI = serviceURI.TrimEnd('/'); |
88 | base.Initialise(source, "MapImageService"); | ||
87 | } | 89 | } |
88 | 90 | ||
89 | public bool AddMapTile(int x, int y, byte[] jpgData, out string reason) | 91 | public bool RemoveMapTile(int x, int y, out string reason) |
90 | { | 92 | { |
91 | reason = string.Empty; | 93 | reason = string.Empty; |
92 | int tickstart = Util.EnvironmentTickCount(); | 94 | int tickstart = Util.EnvironmentTickCount(); |
93 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | 95 | Dictionary<string, object> sendData = new Dictionary<string, object>(); |
94 | sendData["X"] = x.ToString(); | 96 | sendData["X"] = x.ToString(); |
95 | sendData["Y"] = y.ToString(); | 97 | sendData["Y"] = y.ToString(); |
96 | sendData["TYPE"] = "image/jpeg"; | ||
97 | sendData["DATA"] = Convert.ToBase64String(jpgData); | ||
98 | 98 | ||
99 | string reqString = ServerUtils.BuildQueryString(sendData); | 99 | string reqString = ServerUtils.BuildQueryString(sendData); |
100 | string uri = m_ServerURI + "/map"; | 100 | string uri = m_ServerURI + "/removemap"; |
101 | 101 | ||
102 | try | 102 | try |
103 | { | 103 | { |
104 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | 104 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", |
105 | uri, | 105 | uri, |
106 | reqString); | 106 | reqString, |
107 | m_Auth); | ||
107 | if (reply != string.Empty) | 108 | if (reply != string.Empty) |
108 | { | 109 | { |
109 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | 110 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
@@ -114,7 +115,7 @@ namespace OpenSim.Services.Connectors | |||
114 | } | 115 | } |
115 | else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure")) | 116 | else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure")) |
116 | { | 117 | { |
117 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Registration failed: {0}", replyData["Message"].ToString()); | 118 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Delete failed: {0}", replyData["Message"].ToString()); |
118 | reason = replyData["Message"].ToString(); | 119 | reason = replyData["Message"].ToString(); |
119 | return false; | 120 | return false; |
120 | } | 121 | } |
@@ -142,6 +143,72 @@ namespace OpenSim.Services.Connectors | |||
142 | { | 143 | { |
143 | // This just dumps a warning for any operation that takes more than 100 ms | 144 | // This just dumps a warning for any operation that takes more than 100 ms |
144 | int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); | 145 | int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); |
146 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile deleted in {0}ms", tickdiff); | ||
147 | } | ||
148 | |||
149 | return false; | ||
150 | } | ||
151 | |||
152 | public bool AddMapTile(int x, int y, byte[] jpgData, out string reason) | ||
153 | { | ||
154 | reason = string.Empty; | ||
155 | int tickstart = Util.EnvironmentTickCount(); | ||
156 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
157 | sendData["X"] = x.ToString(); | ||
158 | sendData["Y"] = y.ToString(); | ||
159 | sendData["TYPE"] = "image/jpeg"; | ||
160 | sendData["DATA"] = Convert.ToBase64String(jpgData); | ||
161 | |||
162 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
163 | string uri = m_ServerURI + "/map"; | ||
164 | |||
165 | try | ||
166 | { | ||
167 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
168 | uri, | ||
169 | reqString, | ||
170 | m_Auth); | ||
171 | if (reply != string.Empty) | ||
172 | { | ||
173 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
174 | |||
175 | if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success")) | ||
176 | { | ||
177 | return true; | ||
178 | } | ||
179 | else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure")) | ||
180 | { | ||
181 | reason = string.Format("Map post to {0} failed: {1}", uri, replyData["Message"].ToString()); | ||
182 | m_log.WarnFormat("[MAP IMAGE CONNECTOR]: {0}", reason); | ||
183 | |||
184 | return false; | ||
185 | } | ||
186 | else if (!replyData.ContainsKey("Result")) | ||
187 | { | ||
188 | reason = string.Format("Reply data from {0} does not contain result field", uri); | ||
189 | m_log.WarnFormat("[MAP IMAGE CONNECTOR]: {0}", reason); | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | reason = string.Format("Unexpected result {0} from {1}" + replyData["Result"].ToString(), uri); | ||
194 | m_log.WarnFormat("[MAP IMAGE CONNECTOR]: {0}", reason); | ||
195 | } | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | reason = string.Format("Map post received null reply from {0}", uri); | ||
200 | m_log.WarnFormat("[MAP IMAGE CONNECTOR]: {0}", reason); | ||
201 | } | ||
202 | } | ||
203 | catch (Exception e) | ||
204 | { | ||
205 | reason = string.Format("Exception when posting to map server at {0}: {1}", uri, e.Message); | ||
206 | m_log.WarnFormat("[MAP IMAGE CONNECTOR]: {0}", reason); | ||
207 | } | ||
208 | finally | ||
209 | { | ||
210 | // This just dumps a warning for any operation that takes more than 100 ms | ||
211 | int tickdiff = Util.EnvironmentTickCountSubtract(tickstart); | ||
145 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile uploaded in {0}ms", tickdiff); | 212 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: map tile uploaded in {0}ms", tickdiff); |
146 | } | 213 | } |
147 | 214 | ||