diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Services/Connectors/Hypergrid | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Services/Connectors/Hypergrid')
4 files changed, 1382 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs new file mode 100644 index 0000000..b1663ee --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | |||
@@ -0,0 +1,332 @@ | |||
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 System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Drawing; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.Imaging; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using Nwc.XmlRpc; | ||
42 | using log4net; | ||
43 | |||
44 | using OpenSim.Services.Connectors.Simulation; | ||
45 | |||
46 | namespace OpenSim.Services.Connectors.Hypergrid | ||
47 | { | ||
48 | public class GatekeeperServiceConnector : SimulationServiceConnector | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013"); | ||
53 | |||
54 | private IAssetService m_AssetService; | ||
55 | |||
56 | public GatekeeperServiceConnector() | ||
57 | : base() | ||
58 | { | ||
59 | } | ||
60 | |||
61 | public GatekeeperServiceConnector(IAssetService assService) | ||
62 | { | ||
63 | m_AssetService = assService; | ||
64 | } | ||
65 | |||
66 | protected override string AgentPath() | ||
67 | { | ||
68 | return "foreignagent/"; | ||
69 | } | ||
70 | |||
71 | protected override string ObjectPath() | ||
72 | { | ||
73 | return "foreignobject/"; | ||
74 | } | ||
75 | |||
76 | public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string externalName, out string imageURL, out string reason) | ||
77 | { | ||
78 | regionID = UUID.Zero; | ||
79 | imageURL = string.Empty; | ||
80 | realHandle = 0; | ||
81 | externalName = string.Empty; | ||
82 | reason = string.Empty; | ||
83 | |||
84 | Hashtable hash = new Hashtable(); | ||
85 | hash["region_name"] = info.RegionName; | ||
86 | |||
87 | IList paramList = new ArrayList(); | ||
88 | paramList.Add(hash); | ||
89 | |||
90 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
91 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Linking to " + info.ServerURI); | ||
92 | XmlRpcResponse response = null; | ||
93 | try | ||
94 | { | ||
95 | response = request.Send(info.ServerURI, 10000); | ||
96 | } | ||
97 | catch (Exception e) | ||
98 | { | ||
99 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
100 | reason = "Error contacting remote server"; | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | if (response.IsFault) | ||
105 | { | ||
106 | reason = response.FaultString; | ||
107 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | hash = (Hashtable)response.Value; | ||
112 | //foreach (Object o in hash) | ||
113 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
114 | try | ||
115 | { | ||
116 | bool success = false; | ||
117 | Boolean.TryParse((string)hash["result"], out success); | ||
118 | if (success) | ||
119 | { | ||
120 | UUID.TryParse((string)hash["uuid"], out regionID); | ||
121 | //m_log.Debug(">> HERE, uuid: " + regionID); | ||
122 | if ((string)hash["handle"] != null) | ||
123 | { | ||
124 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
125 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
126 | } | ||
127 | if (hash["region_image"] != null) | ||
128 | { | ||
129 | imageURL = (string)hash["region_image"]; | ||
130 | //m_log.Debug(">> HERE, imageURL: " + imageURL); | ||
131 | } | ||
132 | if (hash["external_name"] != null) | ||
133 | { | ||
134 | externalName = (string)hash["external_name"]; | ||
135 | //m_log.Debug(">> HERE, externalName: " + externalName); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | } | ||
140 | catch (Exception e) | ||
141 | { | ||
142 | reason = "Error parsing return arguments"; | ||
143 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
144 | return false; | ||
145 | } | ||
146 | |||
147 | return true; | ||
148 | } | ||
149 | |||
150 | public UUID GetMapImage(UUID regionID, string imageURL, string storagePath) | ||
151 | { | ||
152 | if (m_AssetService == null) | ||
153 | { | ||
154 | m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: No AssetService defined. Map tile not retrieved."); | ||
155 | return m_HGMapImage; | ||
156 | } | ||
157 | |||
158 | UUID mapTile = m_HGMapImage; | ||
159 | string filename = string.Empty; | ||
160 | |||
161 | try | ||
162 | { | ||
163 | WebClient c = new WebClient(); | ||
164 | string name = regionID.ToString(); | ||
165 | filename = Path.Combine(storagePath, name + ".jpg"); | ||
166 | m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: Map image at {0}, cached at {1}", imageURL, filename); | ||
167 | if (!File.Exists(filename)) | ||
168 | { | ||
169 | m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: downloading..."); | ||
170 | c.DownloadFile(imageURL, filename); | ||
171 | } | ||
172 | else | ||
173 | { | ||
174 | m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: using cached image"); | ||
175 | } | ||
176 | |||
177 | byte[] imageData = null; | ||
178 | |||
179 | using (Bitmap bitmap = new Bitmap(filename)) | ||
180 | { | ||
181 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
182 | imageData = OpenJPEG.EncodeFromImage(bitmap, true); | ||
183 | } | ||
184 | |||
185 | AssetBase ass = new AssetBase(UUID.Random(), "region " + name, (sbyte)AssetType.Texture, regionID.ToString()); | ||
186 | |||
187 | // !!! for now | ||
188 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
189 | |||
190 | ass.Data = imageData; | ||
191 | |||
192 | mapTile = ass.FullID; | ||
193 | |||
194 | // finally | ||
195 | m_AssetService.Store(ass); | ||
196 | |||
197 | } | ||
198 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
199 | { | ||
200 | m_log.Info("[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache"); | ||
201 | } | ||
202 | return mapTile; | ||
203 | } | ||
204 | |||
205 | public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID, UUID agentID, string agentHomeURI, out string message) | ||
206 | { | ||
207 | Hashtable hash = new Hashtable(); | ||
208 | hash["region_uuid"] = regionID.ToString(); | ||
209 | if (agentID != UUID.Zero) | ||
210 | { | ||
211 | hash["agent_id"] = agentID.ToString(); | ||
212 | if (agentHomeURI != null) | ||
213 | hash["agent_home_uri"] = agentHomeURI; | ||
214 | } | ||
215 | |||
216 | IList paramList = new ArrayList(); | ||
217 | paramList.Add(hash); | ||
218 | |||
219 | XmlRpcRequest request = new XmlRpcRequest("get_region", paramList); | ||
220 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: contacting " + gatekeeper.ServerURI); | ||
221 | XmlRpcResponse response = null; | ||
222 | try | ||
223 | { | ||
224 | response = request.Send(gatekeeper.ServerURI, 10000); | ||
225 | } | ||
226 | catch (Exception e) | ||
227 | { | ||
228 | message = "Error contacting grid."; | ||
229 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
230 | return null; | ||
231 | } | ||
232 | |||
233 | if (response.IsFault) | ||
234 | { | ||
235 | message = "Error contacting grid."; | ||
236 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
237 | return null; | ||
238 | } | ||
239 | |||
240 | hash = (Hashtable)response.Value; | ||
241 | //foreach (Object o in hash) | ||
242 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
243 | try | ||
244 | { | ||
245 | bool success = false; | ||
246 | Boolean.TryParse((string)hash["result"], out success); | ||
247 | |||
248 | if (hash["message"] != null) | ||
249 | message = (string)hash["message"]; | ||
250 | else if (success) | ||
251 | message = null; | ||
252 | else | ||
253 | message = "The teleport destination could not be found."; // probably the dest grid is old and doesn't send 'message', but the most common problem is that the region is unavailable | ||
254 | |||
255 | if (success) | ||
256 | { | ||
257 | GridRegion region = new GridRegion(); | ||
258 | |||
259 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
260 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
261 | int n = 0; | ||
262 | if (hash["x"] != null) | ||
263 | { | ||
264 | Int32.TryParse((string)hash["x"], out n); | ||
265 | region.RegionLocX = n; | ||
266 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
267 | } | ||
268 | if (hash["y"] != null) | ||
269 | { | ||
270 | Int32.TryParse((string)hash["y"], out n); | ||
271 | region.RegionLocY = n; | ||
272 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
273 | } | ||
274 | if (hash["size_x"] != null) | ||
275 | { | ||
276 | Int32.TryParse((string)hash["size_x"], out n); | ||
277 | region.RegionSizeX = n; | ||
278 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
279 | } | ||
280 | if (hash["size_y"] != null) | ||
281 | { | ||
282 | Int32.TryParse((string)hash["size_y"], out n); | ||
283 | region.RegionSizeY = n; | ||
284 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
285 | } | ||
286 | if (hash["region_name"] != null) | ||
287 | { | ||
288 | region.RegionName = (string)hash["region_name"]; | ||
289 | //m_log.Debug(">> HERE, region_name: " + region.RegionName); | ||
290 | } | ||
291 | if (hash["hostname"] != null) | ||
292 | { | ||
293 | region.ExternalHostName = (string)hash["hostname"]; | ||
294 | //m_log.Debug(">> HERE, hostname: " + region.ExternalHostName); | ||
295 | } | ||
296 | if (hash["http_port"] != null) | ||
297 | { | ||
298 | uint p = 0; | ||
299 | UInt32.TryParse((string)hash["http_port"], out p); | ||
300 | region.HttpPort = p; | ||
301 | //m_log.Debug(">> HERE, http_port: " + region.HttpPort); | ||
302 | } | ||
303 | if (hash["internal_port"] != null) | ||
304 | { | ||
305 | int p = 0; | ||
306 | Int32.TryParse((string)hash["internal_port"], out p); | ||
307 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
308 | //m_log.Debug(">> HERE, internal_port: " + region.InternalEndPoint); | ||
309 | } | ||
310 | |||
311 | if (hash["server_uri"] != null) | ||
312 | { | ||
313 | region.ServerURI = (string)hash["server_uri"]; | ||
314 | //m_log.Debug(">> HERE, server_uri: " + region.ServerURI); | ||
315 | } | ||
316 | |||
317 | // Successful return | ||
318 | return region; | ||
319 | } | ||
320 | |||
321 | } | ||
322 | catch (Exception e) | ||
323 | { | ||
324 | message = "Error parsing response from grid."; | ||
325 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
326 | return null; | ||
327 | } | ||
328 | |||
329 | return null; | ||
330 | } | ||
331 | } | ||
332 | } | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs new file mode 100644 index 0000000..622d4e1 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HGFriendsServicesConnector.cs | |||
@@ -0,0 +1,312 @@ | |||
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 | using OpenSim.Services.Interfaces; | ||
36 | using OpenSim.Services.Connectors.Friends; | ||
37 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace OpenSim.Services.Connectors.Hypergrid | ||
42 | { | ||
43 | public class HGFriendsServicesConnector : FriendsSimConnector | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private string m_ServerURI = String.Empty; | ||
50 | private string m_ServiceKey = String.Empty; | ||
51 | private UUID m_SessionID; | ||
52 | |||
53 | public HGFriendsServicesConnector() | ||
54 | { | ||
55 | } | ||
56 | |||
57 | public HGFriendsServicesConnector(string serverURI) | ||
58 | { | ||
59 | m_ServerURI = serverURI.TrimEnd('/'); | ||
60 | } | ||
61 | |||
62 | public HGFriendsServicesConnector(string serverURI, UUID sessionID, string serviceKey) | ||
63 | { | ||
64 | m_ServerURI = serverURI.TrimEnd('/'); | ||
65 | m_ServiceKey = serviceKey; | ||
66 | m_SessionID = sessionID; | ||
67 | } | ||
68 | |||
69 | protected override string ServicePath() | ||
70 | { | ||
71 | return "hgfriends"; | ||
72 | } | ||
73 | |||
74 | #region IFriendsService | ||
75 | |||
76 | public uint GetFriendPerms(UUID PrincipalID, UUID friendID) | ||
77 | { | ||
78 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
79 | |||
80 | sendData["PRINCIPALID"] = PrincipalID.ToString(); | ||
81 | sendData["FRIENDID"] = friendID.ToString(); | ||
82 | sendData["METHOD"] = "getfriendperms"; | ||
83 | sendData["KEY"] = m_ServiceKey; | ||
84 | sendData["SESSIONID"] = m_SessionID.ToString(); | ||
85 | |||
86 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
87 | string uri = m_ServerURI + "/hgfriends"; | ||
88 | |||
89 | try | ||
90 | { | ||
91 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
92 | uri, | ||
93 | reqString); | ||
94 | if (reply != string.Empty) | ||
95 | { | ||
96 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
97 | |||
98 | if ((replyData != null) && replyData.ContainsKey("Value") && (replyData["Value"] != null)) | ||
99 | { | ||
100 | uint perms = 0; | ||
101 | uint.TryParse(replyData["Value"].ToString(), out perms); | ||
102 | return perms; | ||
103 | } | ||
104 | else | ||
105 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: GetFriendPerms {0} received null response", | ||
106 | PrincipalID); | ||
107 | |||
108 | } | ||
109 | } | ||
110 | catch (Exception e) | ||
111 | { | ||
112 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); | ||
113 | } | ||
114 | |||
115 | return 0; | ||
116 | |||
117 | } | ||
118 | |||
119 | public bool NewFriendship(UUID PrincipalID, string Friend) | ||
120 | { | ||
121 | FriendInfo finfo = new FriendInfo(); | ||
122 | finfo.PrincipalID = PrincipalID; | ||
123 | finfo.Friend = Friend; | ||
124 | |||
125 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
126 | |||
127 | sendData["METHOD"] = "newfriendship"; | ||
128 | sendData["KEY"] = m_ServiceKey; | ||
129 | sendData["SESSIONID"] = m_SessionID.ToString(); | ||
130 | |||
131 | string reply = string.Empty; | ||
132 | string uri = m_ServerURI + "/hgfriends"; | ||
133 | try | ||
134 | { | ||
135 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
136 | uri, | ||
137 | ServerUtils.BuildQueryString(sendData)); | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); | ||
142 | return false; | ||
143 | } | ||
144 | |||
145 | if (reply != string.Empty) | ||
146 | { | ||
147 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
148 | |||
149 | if ((replyData != null) && replyData.ContainsKey("Result") && (replyData["Result"] != null)) | ||
150 | { | ||
151 | bool success = false; | ||
152 | Boolean.TryParse(replyData["Result"].ToString(), out success); | ||
153 | return success; | ||
154 | } | ||
155 | else | ||
156 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend {0} {1} received null response", | ||
157 | PrincipalID, Friend); | ||
158 | } | ||
159 | else | ||
160 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: StoreFriend received null reply"); | ||
161 | |||
162 | return false; | ||
163 | |||
164 | } | ||
165 | |||
166 | public bool DeleteFriendship(UUID PrincipalID, UUID Friend, string secret) | ||
167 | { | ||
168 | FriendInfo finfo = new FriendInfo(); | ||
169 | finfo.PrincipalID = PrincipalID; | ||
170 | finfo.Friend = Friend.ToString(); | ||
171 | |||
172 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
173 | |||
174 | sendData["METHOD"] = "deletefriendship"; | ||
175 | sendData["SECRET"] = secret; | ||
176 | |||
177 | string reply = string.Empty; | ||
178 | string uri = m_ServerURI + "/hgfriends"; | ||
179 | try | ||
180 | { | ||
181 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
182 | uri, | ||
183 | ServerUtils.BuildQueryString(sendData)); | ||
184 | } | ||
185 | catch (Exception e) | ||
186 | { | ||
187 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); | ||
188 | return false; | ||
189 | } | ||
190 | |||
191 | if (reply != string.Empty) | ||
192 | { | ||
193 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
194 | |||
195 | if (replyData.ContainsKey("RESULT")) | ||
196 | { | ||
197 | if (replyData["RESULT"].ToString().ToLower() == "true") | ||
198 | return true; | ||
199 | else | ||
200 | return false; | ||
201 | } | ||
202 | else | ||
203 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); | ||
204 | |||
205 | } | ||
206 | else | ||
207 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); | ||
208 | |||
209 | return false; | ||
210 | |||
211 | } | ||
212 | |||
213 | public bool ValidateFriendshipOffered(UUID fromID, UUID toID) | ||
214 | { | ||
215 | FriendInfo finfo = new FriendInfo(); | ||
216 | finfo.PrincipalID = fromID; | ||
217 | finfo.Friend = toID.ToString(); | ||
218 | |||
219 | Dictionary<string, object> sendData = finfo.ToKeyValuePairs(); | ||
220 | |||
221 | sendData["METHOD"] = "validate_friendship_offered"; | ||
222 | |||
223 | string reply = string.Empty; | ||
224 | string uri = m_ServerURI + "/hgfriends"; | ||
225 | try | ||
226 | { | ||
227 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
228 | uri, | ||
229 | ServerUtils.BuildQueryString(sendData)); | ||
230 | } | ||
231 | catch (Exception e) | ||
232 | { | ||
233 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); | ||
234 | return false; | ||
235 | } | ||
236 | |||
237 | if (reply != string.Empty) | ||
238 | { | ||
239 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
240 | |||
241 | if (replyData.ContainsKey("RESULT")) | ||
242 | { | ||
243 | if (replyData["RESULT"].ToString().ToLower() == "true") | ||
244 | return true; | ||
245 | else | ||
246 | return false; | ||
247 | } | ||
248 | else | ||
249 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: reply data does not contain result field"); | ||
250 | |||
251 | } | ||
252 | else | ||
253 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: received empty reply"); | ||
254 | |||
255 | return false; | ||
256 | |||
257 | } | ||
258 | |||
259 | public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online) | ||
260 | { | ||
261 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
262 | List<UUID> friendsOnline = new List<UUID>(); | ||
263 | |||
264 | sendData["METHOD"] = "statusnotification"; | ||
265 | sendData["userID"] = userID.ToString(); | ||
266 | sendData["online"] = online.ToString(); | ||
267 | int i = 0; | ||
268 | foreach (string s in friends) | ||
269 | { | ||
270 | sendData["friend_" + i.ToString()] = s; | ||
271 | i++; | ||
272 | } | ||
273 | |||
274 | string reply = string.Empty; | ||
275 | string uri = m_ServerURI + "/hgfriends"; | ||
276 | try | ||
277 | { | ||
278 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
279 | uri, | ||
280 | ServerUtils.BuildQueryString(sendData), 15); | ||
281 | } | ||
282 | catch (Exception e) | ||
283 | { | ||
284 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Exception when contacting friends server at {0}: {1}", uri, e.Message); | ||
285 | return friendsOnline; | ||
286 | } | ||
287 | |||
288 | if (reply != string.Empty) | ||
289 | { | ||
290 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
291 | |||
292 | // Here is the actual response | ||
293 | foreach (string key in replyData.Keys) | ||
294 | { | ||
295 | if (key.StartsWith("friend_") && replyData[key] != null) | ||
296 | { | ||
297 | UUID uuid; | ||
298 | if (UUID.TryParse(replyData[key].ToString(), out uuid)) | ||
299 | friendsOnline.Add(uuid); | ||
300 | } | ||
301 | } | ||
302 | } | ||
303 | else | ||
304 | m_log.DebugFormat("[HGFRIENDS CONNECTOR]: Received empty reply from remote StatusNotify"); | ||
305 | |||
306 | return friendsOnline; | ||
307 | |||
308 | } | ||
309 | |||
310 | #endregion | ||
311 | } | ||
312 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs b/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs new file mode 100644 index 0000000..b5e6d69 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/HeloServicesConnector.cs | |||
@@ -0,0 +1,113 @@ | |||
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.Net; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | |||
34 | namespace OpenSim.Services.Connectors | ||
35 | { | ||
36 | public class HeloServicesConnector | ||
37 | { | ||
38 | private static readonly ILog m_log = | ||
39 | LogManager.GetLogger( | ||
40 | MethodBase.GetCurrentMethod().DeclaringType); | ||
41 | |||
42 | private string m_ServerURI = String.Empty; | ||
43 | |||
44 | public HeloServicesConnector() | ||
45 | { | ||
46 | } | ||
47 | |||
48 | public HeloServicesConnector(string serverURI) | ||
49 | { | ||
50 | try | ||
51 | { | ||
52 | Uri uri; | ||
53 | |||
54 | if (!serverURI.EndsWith("=")) | ||
55 | { | ||
56 | // Let's check if this is a valid URI, because it may not be | ||
57 | uri = new Uri(serverURI); | ||
58 | m_ServerURI = serverURI.TrimEnd('/') + "/helo/"; | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | // Simian sends malformed urls like this: | ||
63 | // http://valley.virtualportland.org/simtest/Grid/?id= | ||
64 | // | ||
65 | uri = new Uri(serverURI + "xxx"); | ||
66 | if (uri.Query == string.Empty) | ||
67 | m_ServerURI = serverURI.TrimEnd('/') + "/helo/"; | ||
68 | else | ||
69 | { | ||
70 | serverURI = serverURI + "xxx"; | ||
71 | m_ServerURI = serverURI.Replace(uri.Query, ""); | ||
72 | m_ServerURI = m_ServerURI.TrimEnd('/') + "/helo/"; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | } | ||
77 | catch (UriFormatException) | ||
78 | { | ||
79 | m_log.WarnFormat("[HELO SERVICE]: Malformed URL {0}", serverURI); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public virtual string Helo() | ||
84 | { | ||
85 | if (String.IsNullOrEmpty(m_ServerURI)) | ||
86 | { | ||
87 | m_log.WarnFormat("[HELO SERVICE]: Unable to invoke HELO due to empty URL"); | ||
88 | return String.Empty; | ||
89 | } | ||
90 | |||
91 | try | ||
92 | { | ||
93 | HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); | ||
94 | // Eventually we need to switch to HEAD | ||
95 | /* req.Method = "HEAD"; */ | ||
96 | |||
97 | using (WebResponse response = req.GetResponse()) | ||
98 | { | ||
99 | if (response.Headers.Get("X-Handlers-Provided") == null) // just in case this ever returns a null | ||
100 | return string.Empty; | ||
101 | return response.Headers.Get("X-Handlers-Provided"); | ||
102 | } | ||
103 | } | ||
104 | catch (Exception e) | ||
105 | { | ||
106 | m_log.DebugFormat("[HELO SERVICE]: Unable to perform HELO request to {0}: {1}", m_ServerURI, e.Message); | ||
107 | } | ||
108 | |||
109 | // fail | ||
110 | return string.Empty; | ||
111 | } | ||
112 | } | ||
113 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs new file mode 100644 index 0000000..8abd046 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs | |||
@@ -0,0 +1,625 @@ | |||
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 System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Net; | ||
33 | using System.Reflection; | ||
34 | using System.Text; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Services.Connectors.Simulation; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using log4net; | ||
42 | using Nwc.XmlRpc; | ||
43 | using Nini.Config; | ||
44 | |||
45 | namespace OpenSim.Services.Connectors.Hypergrid | ||
46 | { | ||
47 | public class UserAgentServiceConnector : SimulationServiceConnector, IUserAgentService | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger( | ||
51 | MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | private string m_ServerURLHost; | ||
54 | private string m_ServerURL; | ||
55 | private GridRegion m_Gatekeeper; | ||
56 | |||
57 | public UserAgentServiceConnector(string url) : this(url, true) | ||
58 | { | ||
59 | } | ||
60 | |||
61 | public UserAgentServiceConnector(string url, bool dnsLookup) | ||
62 | { | ||
63 | m_ServerURL = m_ServerURLHost = url; | ||
64 | |||
65 | if (dnsLookup) | ||
66 | { | ||
67 | // Doing this here, because XML-RPC or mono have some strong ideas about | ||
68 | // caching DNS translations. | ||
69 | try | ||
70 | { | ||
71 | Uri m_Uri = new Uri(m_ServerURL); | ||
72 | IPAddress ip = Util.GetHostFromDNS(m_Uri.Host); | ||
73 | m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString()); | ||
74 | if (!m_ServerURL.EndsWith("/")) | ||
75 | m_ServerURL += "/"; | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", url, e.Message); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | //m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL); | ||
84 | } | ||
85 | |||
86 | public UserAgentServiceConnector(IConfigSource config) | ||
87 | { | ||
88 | IConfig serviceConfig = config.Configs["UserAgentService"]; | ||
89 | if (serviceConfig == null) | ||
90 | { | ||
91 | m_log.Error("[USER AGENT CONNECTOR]: UserAgentService missing from ini"); | ||
92 | throw new Exception("UserAgent connector init error"); | ||
93 | } | ||
94 | |||
95 | string serviceURI = serviceConfig.GetString("UserAgentServerURI", | ||
96 | String.Empty); | ||
97 | |||
98 | if (serviceURI == String.Empty) | ||
99 | { | ||
100 | m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService"); | ||
101 | throw new Exception("UserAgent connector init error"); | ||
102 | } | ||
103 | |||
104 | m_ServerURL = m_ServerURLHost = serviceURI; | ||
105 | if (!m_ServerURL.EndsWith("/")) | ||
106 | m_ServerURL += "/"; | ||
107 | |||
108 | //m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0}", m_ServerURL); | ||
109 | } | ||
110 | |||
111 | protected override string AgentPath() | ||
112 | { | ||
113 | return "homeagent/"; | ||
114 | } | ||
115 | |||
116 | // The Login service calls this interface with fromLogin=true | ||
117 | // Sims call it with fromLogin=false | ||
118 | // Either way, this is verified by the handler | ||
119 | public bool LoginAgentToGrid(GridRegion source, AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, bool fromLogin, out string reason) | ||
120 | { | ||
121 | reason = String.Empty; | ||
122 | |||
123 | if (destination == null) | ||
124 | { | ||
125 | reason = "Destination is null"; | ||
126 | m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null"); | ||
127 | return false; | ||
128 | } | ||
129 | |||
130 | GridRegion home = new GridRegion(); | ||
131 | home.ServerURI = m_ServerURL; | ||
132 | home.RegionID = destination.RegionID; | ||
133 | home.RegionLocX = destination.RegionLocX; | ||
134 | home.RegionLocY = destination.RegionLocY; | ||
135 | |||
136 | m_Gatekeeper = gatekeeper; | ||
137 | |||
138 | Console.WriteLine(" >>> LoginAgentToGrid <<< " + home.ServerURI); | ||
139 | |||
140 | uint flags = fromLogin ? (uint)TeleportFlags.ViaLogin : (uint)TeleportFlags.ViaHome; | ||
141 | return CreateAgent(source, home, aCircuit, flags, out reason); | ||
142 | } | ||
143 | |||
144 | |||
145 | // The simulators call this interface | ||
146 | public bool LoginAgentToGrid(GridRegion source, AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason) | ||
147 | { | ||
148 | return LoginAgentToGrid(source, aCircuit, gatekeeper, destination, false, out reason); | ||
149 | } | ||
150 | |||
151 | protected override void PackData(OSDMap args, GridRegion source, AgentCircuitData aCircuit, GridRegion destination, uint flags) | ||
152 | { | ||
153 | base.PackData(args, source, aCircuit, destination, flags); | ||
154 | args["gatekeeper_serveruri"] = OSD.FromString(m_Gatekeeper.ServerURI); | ||
155 | args["gatekeeper_host"] = OSD.FromString(m_Gatekeeper.ExternalHostName); | ||
156 | args["gatekeeper_port"] = OSD.FromString(m_Gatekeeper.HttpPort.ToString()); | ||
157 | args["destination_serveruri"] = OSD.FromString(destination.ServerURI); | ||
158 | } | ||
159 | |||
160 | public void SetClientToken(UUID sessionID, string token) | ||
161 | { | ||
162 | // no-op | ||
163 | } | ||
164 | |||
165 | private Hashtable CallServer(string methodName, Hashtable hash) | ||
166 | { | ||
167 | IList paramList = new ArrayList(); | ||
168 | paramList.Add(hash); | ||
169 | |||
170 | XmlRpcRequest request = new XmlRpcRequest(methodName, paramList); | ||
171 | |||
172 | // Send and get reply | ||
173 | XmlRpcResponse response = null; | ||
174 | try | ||
175 | { | ||
176 | response = request.Send(m_ServerURL, 10000); | ||
177 | } | ||
178 | catch (Exception e) | ||
179 | { | ||
180 | m_log.DebugFormat("[USER AGENT CONNECTOR]: {0} call to {1} failed: {2}", methodName, m_ServerURLHost, e.Message); | ||
181 | throw; | ||
182 | } | ||
183 | |||
184 | if (response.IsFault) | ||
185 | { | ||
186 | throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned an error: {2}", methodName, m_ServerURLHost, response.FaultString)); | ||
187 | } | ||
188 | |||
189 | hash = (Hashtable)response.Value; | ||
190 | |||
191 | if (hash == null) | ||
192 | { | ||
193 | throw new Exception(string.Format("[USER AGENT CONNECTOR]: {0} call to {1} returned null", methodName, m_ServerURLHost)); | ||
194 | } | ||
195 | |||
196 | return hash; | ||
197 | } | ||
198 | |||
199 | public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) | ||
200 | { | ||
201 | position = Vector3.UnitY; lookAt = Vector3.UnitY; | ||
202 | |||
203 | Hashtable hash = new Hashtable(); | ||
204 | hash["userID"] = userID.ToString(); | ||
205 | |||
206 | hash = CallServer("get_home_region", hash); | ||
207 | |||
208 | bool success; | ||
209 | if (!Boolean.TryParse((string)hash["result"], out success) || !success) | ||
210 | return null; | ||
211 | |||
212 | GridRegion region = new GridRegion(); | ||
213 | |||
214 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
215 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
216 | int n = 0; | ||
217 | if (hash["x"] != null) | ||
218 | { | ||
219 | Int32.TryParse((string)hash["x"], out n); | ||
220 | region.RegionLocX = n; | ||
221 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
222 | } | ||
223 | if (hash["y"] != null) | ||
224 | { | ||
225 | Int32.TryParse((string)hash["y"], out n); | ||
226 | region.RegionLocY = n; | ||
227 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
228 | } | ||
229 | if (hash["size_x"] != null) | ||
230 | { | ||
231 | Int32.TryParse((string)hash["size_x"], out n); | ||
232 | region.RegionSizeX = n; | ||
233 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
234 | } | ||
235 | if (hash["size_y"] != null) | ||
236 | { | ||
237 | Int32.TryParse((string)hash["size_y"], out n); | ||
238 | region.RegionSizeY = n; | ||
239 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
240 | } | ||
241 | if (hash["region_name"] != null) | ||
242 | { | ||
243 | region.RegionName = (string)hash["region_name"]; | ||
244 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
245 | } | ||
246 | if (hash["hostname"] != null) | ||
247 | region.ExternalHostName = (string)hash["hostname"]; | ||
248 | if (hash["http_port"] != null) | ||
249 | { | ||
250 | uint p = 0; | ||
251 | UInt32.TryParse((string)hash["http_port"], out p); | ||
252 | region.HttpPort = p; | ||
253 | } | ||
254 | if (hash.ContainsKey("server_uri") && hash["server_uri"] != null) | ||
255 | region.ServerURI = (string)hash["server_uri"]; | ||
256 | |||
257 | if (hash["internal_port"] != null) | ||
258 | { | ||
259 | int p = 0; | ||
260 | Int32.TryParse((string)hash["internal_port"], out p); | ||
261 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
262 | } | ||
263 | if (hash["position"] != null) | ||
264 | Vector3.TryParse((string)hash["position"], out position); | ||
265 | if (hash["lookAt"] != null) | ||
266 | Vector3.TryParse((string)hash["lookAt"], out lookAt); | ||
267 | |||
268 | // Successful return | ||
269 | return region; | ||
270 | } | ||
271 | |||
272 | public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName) | ||
273 | { | ||
274 | Hashtable hash = new Hashtable(); | ||
275 | hash["sessionID"] = sessionID.ToString(); | ||
276 | hash["externalName"] = thisGridExternalName; | ||
277 | |||
278 | IList paramList = new ArrayList(); | ||
279 | paramList.Add(hash); | ||
280 | |||
281 | XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList); | ||
282 | string reason = string.Empty; | ||
283 | return GetBoolResponse(request, out reason); | ||
284 | } | ||
285 | |||
286 | public bool VerifyAgent(UUID sessionID, string token) | ||
287 | { | ||
288 | Hashtable hash = new Hashtable(); | ||
289 | hash["sessionID"] = sessionID.ToString(); | ||
290 | hash["token"] = token; | ||
291 | |||
292 | IList paramList = new ArrayList(); | ||
293 | paramList.Add(hash); | ||
294 | |||
295 | XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList); | ||
296 | string reason = string.Empty; | ||
297 | return GetBoolResponse(request, out reason); | ||
298 | } | ||
299 | |||
300 | public bool VerifyClient(UUID sessionID, string token) | ||
301 | { | ||
302 | Hashtable hash = new Hashtable(); | ||
303 | hash["sessionID"] = sessionID.ToString(); | ||
304 | hash["token"] = token; | ||
305 | |||
306 | IList paramList = new ArrayList(); | ||
307 | paramList.Add(hash); | ||
308 | |||
309 | XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList); | ||
310 | string reason = string.Empty; | ||
311 | return GetBoolResponse(request, out reason); | ||
312 | } | ||
313 | |||
314 | public void LogoutAgent(UUID userID, UUID sessionID) | ||
315 | { | ||
316 | Hashtable hash = new Hashtable(); | ||
317 | hash["sessionID"] = sessionID.ToString(); | ||
318 | hash["userID"] = userID.ToString(); | ||
319 | |||
320 | IList paramList = new ArrayList(); | ||
321 | paramList.Add(hash); | ||
322 | |||
323 | XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList); | ||
324 | string reason = string.Empty; | ||
325 | GetBoolResponse(request, out reason); | ||
326 | } | ||
327 | |||
328 | [Obsolete] | ||
329 | public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online) | ||
330 | { | ||
331 | Hashtable hash = new Hashtable(); | ||
332 | hash["userID"] = userID.ToString(); | ||
333 | hash["online"] = online.ToString(); | ||
334 | int i = 0; | ||
335 | foreach (string s in friends) | ||
336 | { | ||
337 | hash["friend_" + i.ToString()] = s; | ||
338 | i++; | ||
339 | } | ||
340 | |||
341 | IList paramList = new ArrayList(); | ||
342 | paramList.Add(hash); | ||
343 | |||
344 | XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList); | ||
345 | // string reason = string.Empty; | ||
346 | |||
347 | // Send and get reply | ||
348 | List<UUID> friendsOnline = new List<UUID>(); | ||
349 | XmlRpcResponse response = null; | ||
350 | try | ||
351 | { | ||
352 | response = request.Send(m_ServerURL, 6000); | ||
353 | } | ||
354 | catch | ||
355 | { | ||
356 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURLHost); | ||
357 | // reason = "Exception: " + e.Message; | ||
358 | return friendsOnline; | ||
359 | } | ||
360 | |||
361 | if (response.IsFault) | ||
362 | { | ||
363 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURLHost, response.FaultString); | ||
364 | // reason = "XMLRPC Fault"; | ||
365 | return friendsOnline; | ||
366 | } | ||
367 | |||
368 | hash = (Hashtable)response.Value; | ||
369 | //foreach (Object o in hash) | ||
370 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
371 | try | ||
372 | { | ||
373 | if (hash == null) | ||
374 | { | ||
375 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost); | ||
376 | // reason = "Internal error 1"; | ||
377 | return friendsOnline; | ||
378 | } | ||
379 | |||
380 | // Here is the actual response | ||
381 | foreach (object key in hash.Keys) | ||
382 | { | ||
383 | if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null) | ||
384 | { | ||
385 | UUID uuid; | ||
386 | if (UUID.TryParse(hash[key].ToString(), out uuid)) | ||
387 | friendsOnline.Add(uuid); | ||
388 | } | ||
389 | } | ||
390 | |||
391 | } | ||
392 | catch | ||
393 | { | ||
394 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); | ||
395 | // reason = "Exception: " + e.Message; | ||
396 | } | ||
397 | |||
398 | return friendsOnline; | ||
399 | } | ||
400 | |||
401 | [Obsolete] | ||
402 | public List<UUID> GetOnlineFriends(UUID userID, List<string> friends) | ||
403 | { | ||
404 | Hashtable hash = new Hashtable(); | ||
405 | hash["userID"] = userID.ToString(); | ||
406 | int i = 0; | ||
407 | foreach (string s in friends) | ||
408 | { | ||
409 | hash["friend_" + i.ToString()] = s; | ||
410 | i++; | ||
411 | } | ||
412 | |||
413 | IList paramList = new ArrayList(); | ||
414 | paramList.Add(hash); | ||
415 | |||
416 | XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList); | ||
417 | // string reason = string.Empty; | ||
418 | |||
419 | // Send and get reply | ||
420 | List<UUID> online = new List<UUID>(); | ||
421 | XmlRpcResponse response = null; | ||
422 | try | ||
423 | { | ||
424 | response = request.Send(m_ServerURL, 10000); | ||
425 | } | ||
426 | catch | ||
427 | { | ||
428 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURLHost); | ||
429 | // reason = "Exception: " + e.Message; | ||
430 | return online; | ||
431 | } | ||
432 | |||
433 | if (response.IsFault) | ||
434 | { | ||
435 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURLHost, response.FaultString); | ||
436 | // reason = "XMLRPC Fault"; | ||
437 | return online; | ||
438 | } | ||
439 | |||
440 | hash = (Hashtable)response.Value; | ||
441 | //foreach (Object o in hash) | ||
442 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
443 | try | ||
444 | { | ||
445 | if (hash == null) | ||
446 | { | ||
447 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost); | ||
448 | // reason = "Internal error 1"; | ||
449 | return online; | ||
450 | } | ||
451 | |||
452 | // Here is the actual response | ||
453 | foreach (object key in hash.Keys) | ||
454 | { | ||
455 | if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null) | ||
456 | { | ||
457 | UUID uuid; | ||
458 | if (UUID.TryParse(hash[key].ToString(), out uuid)) | ||
459 | online.Add(uuid); | ||
460 | } | ||
461 | } | ||
462 | |||
463 | } | ||
464 | catch | ||
465 | { | ||
466 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); | ||
467 | // reason = "Exception: " + e.Message; | ||
468 | } | ||
469 | |||
470 | return online; | ||
471 | } | ||
472 | |||
473 | public Dictionary<string,object> GetUserInfo (UUID userID) | ||
474 | { | ||
475 | Hashtable hash = new Hashtable(); | ||
476 | hash["userID"] = userID.ToString(); | ||
477 | |||
478 | hash = CallServer("get_user_info", hash); | ||
479 | |||
480 | Dictionary<string, object> info = new Dictionary<string, object>(); | ||
481 | |||
482 | foreach (object key in hash.Keys) | ||
483 | { | ||
484 | if (hash[key] != null) | ||
485 | { | ||
486 | info.Add(key.ToString(), hash[key]); | ||
487 | } | ||
488 | } | ||
489 | |||
490 | return info; | ||
491 | } | ||
492 | |||
493 | public Dictionary<string, object> GetServerURLs(UUID userID) | ||
494 | { | ||
495 | Hashtable hash = new Hashtable(); | ||
496 | hash["userID"] = userID.ToString(); | ||
497 | |||
498 | hash = CallServer("get_server_urls", hash); | ||
499 | |||
500 | Dictionary<string, object> serverURLs = new Dictionary<string, object>(); | ||
501 | foreach (object key in hash.Keys) | ||
502 | { | ||
503 | if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null) | ||
504 | { | ||
505 | string serverType = key.ToString().Substring(4); // remove "SRV_" | ||
506 | serverURLs.Add(serverType, hash[key].ToString()); | ||
507 | } | ||
508 | } | ||
509 | |||
510 | return serverURLs; | ||
511 | } | ||
512 | |||
513 | public string LocateUser(UUID userID) | ||
514 | { | ||
515 | Hashtable hash = new Hashtable(); | ||
516 | hash["userID"] = userID.ToString(); | ||
517 | |||
518 | hash = CallServer("locate_user", hash); | ||
519 | |||
520 | string url = string.Empty; | ||
521 | |||
522 | // Here's the actual response | ||
523 | if (hash.ContainsKey("URL")) | ||
524 | url = hash["URL"].ToString(); | ||
525 | |||
526 | return url; | ||
527 | } | ||
528 | |||
529 | public string GetUUI(UUID userID, UUID targetUserID) | ||
530 | { | ||
531 | Hashtable hash = new Hashtable(); | ||
532 | hash["userID"] = userID.ToString(); | ||
533 | hash["targetUserID"] = targetUserID.ToString(); | ||
534 | |||
535 | hash = CallServer("get_uui", hash); | ||
536 | |||
537 | string uui = string.Empty; | ||
538 | |||
539 | // Here's the actual response | ||
540 | if (hash.ContainsKey("UUI")) | ||
541 | uui = hash["UUI"].ToString(); | ||
542 | |||
543 | return uui; | ||
544 | } | ||
545 | |||
546 | public UUID GetUUID(String first, String last) | ||
547 | { | ||
548 | Hashtable hash = new Hashtable(); | ||
549 | hash["first"] = first; | ||
550 | hash["last"] = last; | ||
551 | |||
552 | hash = CallServer("get_uuid", hash); | ||
553 | |||
554 | if (!hash.ContainsKey("UUID")) | ||
555 | { | ||
556 | throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} didn't return a UUID", m_ServerURLHost)); | ||
557 | } | ||
558 | |||
559 | UUID uuid; | ||
560 | if (!UUID.TryParse(hash["UUID"].ToString(), out uuid)) | ||
561 | { | ||
562 | throw new Exception(string.Format("[USER AGENT CONNECTOR]: get_uuid call to {0} returned an invalid UUID: {1}", m_ServerURLHost, hash["UUID"].ToString())); | ||
563 | } | ||
564 | |||
565 | return uuid; | ||
566 | } | ||
567 | |||
568 | private bool GetBoolResponse(XmlRpcRequest request, out string reason) | ||
569 | { | ||
570 | //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURLHost); | ||
571 | XmlRpcResponse response = null; | ||
572 | try | ||
573 | { | ||
574 | response = request.Send(m_ServerURL, 10000); | ||
575 | } | ||
576 | catch (Exception e) | ||
577 | { | ||
578 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURLHost); | ||
579 | reason = "Exception: " + e.Message; | ||
580 | return false; | ||
581 | } | ||
582 | |||
583 | if (response.IsFault) | ||
584 | { | ||
585 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURLHost, response.FaultString); | ||
586 | reason = "XMLRPC Fault"; | ||
587 | return false; | ||
588 | } | ||
589 | |||
590 | Hashtable hash = (Hashtable)response.Value; | ||
591 | //foreach (Object o in hash) | ||
592 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
593 | try | ||
594 | { | ||
595 | if (hash == null) | ||
596 | { | ||
597 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURLHost); | ||
598 | reason = "Internal error 1"; | ||
599 | return false; | ||
600 | } | ||
601 | bool success = false; | ||
602 | reason = string.Empty; | ||
603 | if (hash.ContainsKey("result")) | ||
604 | Boolean.TryParse((string)hash["result"], out success); | ||
605 | else | ||
606 | { | ||
607 | reason = "Internal error 2"; | ||
608 | m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURLHost); | ||
609 | } | ||
610 | |||
611 | return success; | ||
612 | } | ||
613 | catch (Exception e) | ||
614 | { | ||
615 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response."); | ||
616 | if (hash.ContainsKey("result") && hash["result"] != null) | ||
617 | m_log.ErrorFormat("Reply was ", (string)hash["result"]); | ||
618 | reason = "Exception: " + e.Message; | ||
619 | return false; | ||
620 | } | ||
621 | |||
622 | } | ||
623 | |||
624 | } | ||
625 | } | ||