opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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_ServerURL; |
||
54 | private GridRegion m_Gatekeeper; |
||
55 | |||
56 | public UserAgentServiceConnector(string url) : this(url, true) |
||
57 | { |
||
58 | } |
||
59 | |||
60 | public UserAgentServiceConnector(string url, bool dnsLookup) |
||
61 | { |
||
62 | m_ServerURL = url; |
||
63 | |||
64 | if (dnsLookup) |
||
65 | { |
||
66 | // Doing this here, because XML-RPC or mono have some strong ideas about |
||
67 | // caching DNS translations. |
||
68 | try |
||
69 | { |
||
70 | Uri m_Uri = new Uri(m_ServerURL); |
||
71 | IPAddress ip = Util.GetHostFromDNS(m_Uri.Host); |
||
72 | m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString()); |
||
73 | if (!m_ServerURL.EndsWith("/")) |
||
74 | m_ServerURL += "/"; |
||
75 | } |
||
76 | catch (Exception e) |
||
77 | { |
||
78 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Malformed Uri {0}: {1}", m_ServerURL, e.Message); |
||
79 | } |
||
80 | } |
||
81 | m_log.DebugFormat("[USER AGENT CONNECTOR]: new connector to {0} ({1})", url, m_ServerURL); |
||
82 | } |
||
83 | |||
84 | public UserAgentServiceConnector(IConfigSource config) |
||
85 | { |
||
86 | IConfig serviceConfig = config.Configs["UserAgentService"]; |
||
87 | if (serviceConfig == null) |
||
88 | { |
||
89 | m_log.Error("[USER AGENT CONNECTOR]: UserAgentService missing from ini"); |
||
90 | throw new Exception("UserAgent connector init error"); |
||
91 | } |
||
92 | |||
93 | string serviceURI = serviceConfig.GetString("UserAgentServerURI", |
||
94 | String.Empty); |
||
95 | |||
96 | if (serviceURI == String.Empty) |
||
97 | { |
||
98 | m_log.Error("[USER AGENT CONNECTOR]: No Server URI named in section UserAgentService"); |
||
99 | throw new Exception("UserAgent connector init error"); |
||
100 | } |
||
101 | m_ServerURL = serviceURI; |
||
102 | if (!m_ServerURL.EndsWith("/")) |
||
103 | m_ServerURL += "/"; |
||
104 | |||
105 | m_log.DebugFormat("[USER AGENT CONNECTOR]: UserAgentServiceConnector started for {0}", m_ServerURL); |
||
106 | } |
||
107 | |||
108 | protected override string AgentPath() |
||
109 | { |
||
110 | return "homeagent/"; |
||
111 | } |
||
112 | |||
113 | // The Login service calls this interface with fromLogin=true |
||
114 | // Sims call it with fromLogin=false |
||
115 | // Either way, this is verified by the handler |
||
116 | public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, bool fromLogin, out string reason) |
||
117 | { |
||
118 | reason = String.Empty; |
||
119 | |||
120 | if (destination == null) |
||
121 | { |
||
122 | reason = "Destination is null"; |
||
123 | m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null"); |
||
124 | return false; |
||
125 | } |
||
126 | |||
127 | GridRegion home = new GridRegion(); |
||
128 | home.ServerURI = m_ServerURL; |
||
129 | home.RegionID = destination.RegionID; |
||
130 | home.RegionLocX = destination.RegionLocX; |
||
131 | home.RegionLocY = destination.RegionLocY; |
||
132 | |||
133 | m_Gatekeeper = gatekeeper; |
||
134 | |||
135 | Console.WriteLine(" >>> LoginAgentToGrid <<< " + home.ServerURI); |
||
136 | |||
137 | uint flags = fromLogin ? (uint)TeleportFlags.ViaLogin : (uint)TeleportFlags.ViaHome; |
||
138 | return CreateAgent(home, aCircuit, flags, out reason); |
||
139 | } |
||
140 | |||
141 | |||
142 | // The simulators call this interface |
||
143 | public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason) |
||
144 | { |
||
145 | return LoginAgentToGrid(aCircuit, gatekeeper, destination, false, out reason); |
||
146 | } |
||
147 | |||
148 | protected override void PackData(OSDMap args, AgentCircuitData aCircuit, GridRegion destination, uint flags) |
||
149 | { |
||
150 | base.PackData(args, aCircuit, destination, flags); |
||
151 | args["gatekeeper_serveruri"] = OSD.FromString(m_Gatekeeper.ServerURI); |
||
152 | args["gatekeeper_host"] = OSD.FromString(m_Gatekeeper.ExternalHostName); |
||
153 | args["gatekeeper_port"] = OSD.FromString(m_Gatekeeper.HttpPort.ToString()); |
||
154 | args["destination_serveruri"] = OSD.FromString(destination.ServerURI); |
||
155 | } |
||
156 | |||
157 | protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, IPEndPoint ipaddress) |
||
158 | { |
||
159 | OSDMap args = null; |
||
160 | try |
||
161 | { |
||
162 | args = aCircuit.PackAgentCircuitData(); |
||
163 | } |
||
164 | catch (Exception e) |
||
165 | { |
||
166 | m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); |
||
167 | } |
||
168 | |||
169 | // Add the input arguments |
||
170 | args["gatekeeper_serveruri"] = OSD.FromString(gatekeeper.ServerURI); |
||
171 | args["gatekeeper_host"] = OSD.FromString(gatekeeper.ExternalHostName); |
||
172 | args["gatekeeper_port"] = OSD.FromString(gatekeeper.HttpPort.ToString()); |
||
173 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); |
||
174 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); |
||
175 | args["destination_name"] = OSD.FromString(destination.RegionName); |
||
176 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); |
||
177 | args["destination_serveruri"] = OSD.FromString(destination.ServerURI); |
||
178 | |||
179 | // 10/3/2010 |
||
180 | // I added the client_ip up to the regular AgentCircuitData, so this doesn't need to be here. |
||
181 | // This need cleaning elsewhere... |
||
182 | //if (ipaddress != null) |
||
183 | // args["client_ip"] = OSD.FromString(ipaddress.Address.ToString()); |
||
184 | |||
185 | return args; |
||
186 | } |
||
187 | |||
188 | public void SetClientToken(UUID sessionID, string token) |
||
189 | { |
||
190 | // no-op |
||
191 | } |
||
192 | |||
193 | public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) |
||
194 | { |
||
195 | position = Vector3.UnitY; lookAt = Vector3.UnitY; |
||
196 | |||
197 | Hashtable hash = new Hashtable(); |
||
198 | hash["userID"] = userID.ToString(); |
||
199 | |||
200 | IList paramList = new ArrayList(); |
||
201 | paramList.Add(hash); |
||
202 | |||
203 | XmlRpcRequest request = new XmlRpcRequest("get_home_region", paramList); |
||
204 | XmlRpcResponse response = null; |
||
205 | try |
||
206 | { |
||
207 | response = request.Send(m_ServerURL, 10000); |
||
208 | } |
||
209 | catch (Exception) |
||
210 | { |
||
211 | return null; |
||
212 | } |
||
213 | |||
214 | if (response.IsFault) |
||
215 | { |
||
216 | return null; |
||
217 | } |
||
218 | |||
219 | hash = (Hashtable)response.Value; |
||
220 | //foreach (Object o in hash) |
||
221 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
222 | try |
||
223 | { |
||
224 | bool success = false; |
||
225 | Boolean.TryParse((string)hash["result"], out success); |
||
226 | if (success) |
||
227 | { |
||
228 | GridRegion region = new GridRegion(); |
||
229 | |||
230 | UUID.TryParse((string)hash["uuid"], out region.RegionID); |
||
231 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); |
||
232 | int n = 0; |
||
233 | if (hash["x"] != null) |
||
234 | { |
||
235 | Int32.TryParse((string)hash["x"], out n); |
||
236 | region.RegionLocX = n; |
||
237 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); |
||
238 | } |
||
239 | if (hash["y"] != null) |
||
240 | { |
||
241 | Int32.TryParse((string)hash["y"], out n); |
||
242 | region.RegionLocY = n; |
||
243 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); |
||
244 | } |
||
245 | if (hash["size_x"] != null) |
||
246 | { |
||
247 | Int32.TryParse((string)hash["size_x"], out n); |
||
248 | region.RegionSizeX = n; |
||
249 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); |
||
250 | } |
||
251 | if (hash["size_y"] != null) |
||
252 | { |
||
253 | Int32.TryParse((string)hash["size_y"], out n); |
||
254 | region.RegionSizeY = n; |
||
255 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); |
||
256 | } |
||
257 | if (hash["region_name"] != null) |
||
258 | { |
||
259 | region.RegionName = (string)hash["region_name"]; |
||
260 | //m_log.Debug(">> HERE, name: " + region.RegionName); |
||
261 | } |
||
262 | if (hash["hostname"] != null) |
||
263 | region.ExternalHostName = (string)hash["hostname"]; |
||
264 | if (hash["http_port"] != null) |
||
265 | { |
||
266 | uint p = 0; |
||
267 | UInt32.TryParse((string)hash["http_port"], out p); |
||
268 | region.HttpPort = p; |
||
269 | } |
||
270 | if (hash.ContainsKey("server_uri") && hash["server_uri"] != null) |
||
271 | region.ServerURI = (string)hash["server_uri"]; |
||
272 | |||
273 | if (hash["internal_port"] != null) |
||
274 | { |
||
275 | int p = 0; |
||
276 | Int32.TryParse((string)hash["internal_port"], out p); |
||
277 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); |
||
278 | } |
||
279 | if (hash["position"] != null) |
||
280 | Vector3.TryParse((string)hash["position"], out position); |
||
281 | if (hash["lookAt"] != null) |
||
282 | Vector3.TryParse((string)hash["lookAt"], out lookAt); |
||
283 | |||
284 | // Successful return |
||
285 | return region; |
||
286 | } |
||
287 | |||
288 | } |
||
289 | catch (Exception) |
||
290 | { |
||
291 | return null; |
||
292 | } |
||
293 | |||
294 | return null; |
||
295 | } |
||
296 | |||
297 | public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName) |
||
298 | { |
||
299 | Hashtable hash = new Hashtable(); |
||
300 | hash["sessionID"] = sessionID.ToString(); |
||
301 | hash["externalName"] = thisGridExternalName; |
||
302 | |||
303 | IList paramList = new ArrayList(); |
||
304 | paramList.Add(hash); |
||
305 | |||
306 | XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList); |
||
307 | string reason = string.Empty; |
||
308 | return GetBoolResponse(request, out reason); |
||
309 | } |
||
310 | |||
311 | public bool VerifyAgent(UUID sessionID, string token) |
||
312 | { |
||
313 | Hashtable hash = new Hashtable(); |
||
314 | hash["sessionID"] = sessionID.ToString(); |
||
315 | hash["token"] = token; |
||
316 | |||
317 | IList paramList = new ArrayList(); |
||
318 | paramList.Add(hash); |
||
319 | |||
320 | XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList); |
||
321 | string reason = string.Empty; |
||
322 | return GetBoolResponse(request, out reason); |
||
323 | } |
||
324 | |||
325 | public bool VerifyClient(UUID sessionID, string token) |
||
326 | { |
||
327 | Hashtable hash = new Hashtable(); |
||
328 | hash["sessionID"] = sessionID.ToString(); |
||
329 | hash["token"] = token; |
||
330 | |||
331 | IList paramList = new ArrayList(); |
||
332 | paramList.Add(hash); |
||
333 | |||
334 | XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList); |
||
335 | string reason = string.Empty; |
||
336 | return GetBoolResponse(request, out reason); |
||
337 | } |
||
338 | |||
339 | public void LogoutAgent(UUID userID, UUID sessionID) |
||
340 | { |
||
341 | Hashtable hash = new Hashtable(); |
||
342 | hash["sessionID"] = sessionID.ToString(); |
||
343 | hash["userID"] = userID.ToString(); |
||
344 | |||
345 | IList paramList = new ArrayList(); |
||
346 | paramList.Add(hash); |
||
347 | |||
348 | XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList); |
||
349 | string reason = string.Empty; |
||
350 | GetBoolResponse(request, out reason); |
||
351 | } |
||
352 | |||
353 | [Obsolete] |
||
354 | public List<UUID> StatusNotification(List<string> friends, UUID userID, bool online) |
||
355 | { |
||
356 | Hashtable hash = new Hashtable(); |
||
357 | hash["userID"] = userID.ToString(); |
||
358 | hash["online"] = online.ToString(); |
||
359 | int i = 0; |
||
360 | foreach (string s in friends) |
||
361 | { |
||
362 | hash["friend_" + i.ToString()] = s; |
||
363 | i++; |
||
364 | } |
||
365 | |||
366 | IList paramList = new ArrayList(); |
||
367 | paramList.Add(hash); |
||
368 | |||
369 | XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList); |
||
370 | // string reason = string.Empty; |
||
371 | |||
372 | // Send and get reply |
||
373 | List<UUID> friendsOnline = new List<UUID>(); |
||
374 | XmlRpcResponse response = null; |
||
375 | try |
||
376 | { |
||
377 | response = request.Send(m_ServerURL, 6000); |
||
378 | } |
||
379 | catch |
||
380 | { |
||
381 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for StatusNotification", m_ServerURL); |
||
382 | // reason = "Exception: " + e.Message; |
||
383 | return friendsOnline; |
||
384 | } |
||
385 | |||
386 | if (response.IsFault) |
||
387 | { |
||
388 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for StatusNotification returned an error: {1}", m_ServerURL, response.FaultString); |
||
389 | // reason = "XMLRPC Fault"; |
||
390 | return friendsOnline; |
||
391 | } |
||
392 | |||
393 | hash = (Hashtable)response.Value; |
||
394 | //foreach (Object o in hash) |
||
395 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
396 | try |
||
397 | { |
||
398 | if (hash == null) |
||
399 | { |
||
400 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
401 | // reason = "Internal error 1"; |
||
402 | return friendsOnline; |
||
403 | } |
||
404 | |||
405 | // Here is the actual response |
||
406 | foreach (object key in hash.Keys) |
||
407 | { |
||
408 | if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null) |
||
409 | { |
||
410 | UUID uuid; |
||
411 | if (UUID.TryParse(hash[key].ToString(), out uuid)) |
||
412 | friendsOnline.Add(uuid); |
||
413 | } |
||
414 | } |
||
415 | |||
416 | } |
||
417 | catch |
||
418 | { |
||
419 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); |
||
420 | // reason = "Exception: " + e.Message; |
||
421 | } |
||
422 | |||
423 | return friendsOnline; |
||
424 | } |
||
425 | |||
426 | [Obsolete] |
||
427 | public List<UUID> GetOnlineFriends(UUID userID, List<string> friends) |
||
428 | { |
||
429 | Hashtable hash = new Hashtable(); |
||
430 | hash["userID"] = userID.ToString(); |
||
431 | int i = 0; |
||
432 | foreach (string s in friends) |
||
433 | { |
||
434 | hash["friend_" + i.ToString()] = s; |
||
435 | i++; |
||
436 | } |
||
437 | |||
438 | IList paramList = new ArrayList(); |
||
439 | paramList.Add(hash); |
||
440 | |||
441 | XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList); |
||
442 | // string reason = string.Empty; |
||
443 | |||
444 | // Send and get reply |
||
445 | List<UUID> online = new List<UUID>(); |
||
446 | XmlRpcResponse response = null; |
||
447 | try |
||
448 | { |
||
449 | response = request.Send(m_ServerURL, 10000); |
||
450 | } |
||
451 | catch |
||
452 | { |
||
453 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetOnlineFriends", m_ServerURL); |
||
454 | // reason = "Exception: " + e.Message; |
||
455 | return online; |
||
456 | } |
||
457 | |||
458 | if (response.IsFault) |
||
459 | { |
||
460 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetOnlineFriends returned an error: {1}", m_ServerURL, response.FaultString); |
||
461 | // reason = "XMLRPC Fault"; |
||
462 | return online; |
||
463 | } |
||
464 | |||
465 | hash = (Hashtable)response.Value; |
||
466 | //foreach (Object o in hash) |
||
467 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
468 | try |
||
469 | { |
||
470 | if (hash == null) |
||
471 | { |
||
472 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetOnlineFriends Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
473 | // reason = "Internal error 1"; |
||
474 | return online; |
||
475 | } |
||
476 | |||
477 | // Here is the actual response |
||
478 | foreach (object key in hash.Keys) |
||
479 | { |
||
480 | if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null) |
||
481 | { |
||
482 | UUID uuid; |
||
483 | if (UUID.TryParse(hash[key].ToString(), out uuid)) |
||
484 | online.Add(uuid); |
||
485 | } |
||
486 | } |
||
487 | |||
488 | } |
||
489 | catch |
||
490 | { |
||
491 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); |
||
492 | // reason = "Exception: " + e.Message; |
||
493 | } |
||
494 | |||
495 | return online; |
||
496 | } |
||
497 | |||
498 | public Dictionary<string,object> GetUserInfo (UUID userID) |
||
499 | { |
||
500 | Hashtable hash = new Hashtable(); |
||
501 | hash["userID"] = userID.ToString(); |
||
502 | |||
503 | IList paramList = new ArrayList(); |
||
504 | paramList.Add(hash); |
||
505 | |||
506 | XmlRpcRequest request = new XmlRpcRequest("get_user_info", paramList); |
||
507 | |||
508 | Dictionary<string, object> info = new Dictionary<string, object>(); |
||
509 | XmlRpcResponse response = null; |
||
510 | try |
||
511 | { |
||
512 | response = request.Send(m_ServerURL, 10000); |
||
513 | } |
||
514 | catch |
||
515 | { |
||
516 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUserInfo", m_ServerURL); |
||
517 | return info; |
||
518 | } |
||
519 | |||
520 | if (response.IsFault) |
||
521 | { |
||
522 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString); |
||
523 | return info; |
||
524 | } |
||
525 | |||
526 | hash = (Hashtable)response.Value; |
||
527 | try |
||
528 | { |
||
529 | if (hash == null) |
||
530 | { |
||
531 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUserInfo Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
532 | return info; |
||
533 | } |
||
534 | |||
535 | // Here is the actual response |
||
536 | foreach (object key in hash.Keys) |
||
537 | { |
||
538 | if (hash[key] != null) |
||
539 | { |
||
540 | info.Add(key.ToString(), hash[key]); |
||
541 | } |
||
542 | } |
||
543 | } |
||
544 | catch |
||
545 | { |
||
546 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); |
||
547 | } |
||
548 | |||
549 | return info; |
||
550 | } |
||
551 | |||
552 | public Dictionary<string, object> GetServerURLs(UUID userID) |
||
553 | { |
||
554 | Hashtable hash = new Hashtable(); |
||
555 | hash["userID"] = userID.ToString(); |
||
556 | |||
557 | IList paramList = new ArrayList(); |
||
558 | paramList.Add(hash); |
||
559 | |||
560 | XmlRpcRequest request = new XmlRpcRequest("get_server_urls", paramList); |
||
561 | // string reason = string.Empty; |
||
562 | |||
563 | // Send and get reply |
||
564 | Dictionary<string, object> serverURLs = new Dictionary<string,object>(); |
||
565 | XmlRpcResponse response = null; |
||
566 | try |
||
567 | { |
||
568 | response = request.Send(m_ServerURL, 10000); |
||
569 | } |
||
570 | catch |
||
571 | { |
||
572 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetServerURLs for user {1}", m_ServerURL, userID); |
||
573 | // reason = "Exception: " + e.Message; |
||
574 | return serverURLs; |
||
575 | } |
||
576 | |||
577 | if (response.IsFault) |
||
578 | { |
||
579 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetServerURLs returned an error: {1}", m_ServerURL, response.FaultString); |
||
580 | // reason = "XMLRPC Fault"; |
||
581 | return serverURLs; |
||
582 | } |
||
583 | |||
584 | hash = (Hashtable)response.Value; |
||
585 | //foreach (Object o in hash) |
||
586 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
587 | try |
||
588 | { |
||
589 | if (hash == null) |
||
590 | { |
||
591 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetServerURLs Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
592 | // reason = "Internal error 1"; |
||
593 | return serverURLs; |
||
594 | } |
||
595 | |||
596 | // Here is the actual response |
||
597 | foreach (object key in hash.Keys) |
||
598 | { |
||
599 | if (key is string && ((string)key).StartsWith("SRV_") && hash[key] != null) |
||
600 | { |
||
601 | string serverType = key.ToString().Substring(4); // remove "SRV_" |
||
602 | serverURLs.Add(serverType, hash[key].ToString()); |
||
603 | } |
||
604 | } |
||
605 | |||
606 | } |
||
607 | catch |
||
608 | { |
||
609 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response."); |
||
610 | // reason = "Exception: " + e.Message; |
||
611 | } |
||
612 | |||
613 | return serverURLs; |
||
614 | } |
||
615 | |||
616 | public string LocateUser(UUID userID) |
||
617 | { |
||
618 | Hashtable hash = new Hashtable(); |
||
619 | hash["userID"] = userID.ToString(); |
||
620 | |||
621 | IList paramList = new ArrayList(); |
||
622 | paramList.Add(hash); |
||
623 | |||
624 | XmlRpcRequest request = new XmlRpcRequest("locate_user", paramList); |
||
625 | // string reason = string.Empty; |
||
626 | |||
627 | // Send and get reply |
||
628 | string url = string.Empty; |
||
629 | XmlRpcResponse response = null; |
||
630 | try |
||
631 | { |
||
632 | response = request.Send(m_ServerURL, 10000); |
||
633 | } |
||
634 | catch |
||
635 | { |
||
636 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for LocateUser", m_ServerURL); |
||
637 | // reason = "Exception: " + e.Message; |
||
638 | return url; |
||
639 | } |
||
640 | |||
641 | if (response.IsFault) |
||
642 | { |
||
643 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for LocateUser returned an error: {1}", m_ServerURL, response.FaultString); |
||
644 | // reason = "XMLRPC Fault"; |
||
645 | return url; |
||
646 | } |
||
647 | |||
648 | hash = (Hashtable)response.Value; |
||
649 | //foreach (Object o in hash) |
||
650 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
651 | try |
||
652 | { |
||
653 | if (hash == null) |
||
654 | { |
||
655 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: LocateUser Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
656 | // reason = "Internal error 1"; |
||
657 | return url; |
||
658 | } |
||
659 | |||
660 | // Here's the actual response |
||
661 | if (hash.ContainsKey("URL")) |
||
662 | url = hash["URL"].ToString(); |
||
663 | |||
664 | } |
||
665 | catch |
||
666 | { |
||
667 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on LocateUser response."); |
||
668 | // reason = "Exception: " + e.Message; |
||
669 | } |
||
670 | |||
671 | return url; |
||
672 | } |
||
673 | |||
674 | public string GetUUI(UUID userID, UUID targetUserID) |
||
675 | { |
||
676 | Hashtable hash = new Hashtable(); |
||
677 | hash["userID"] = userID.ToString(); |
||
678 | hash["targetUserID"] = targetUserID.ToString(); |
||
679 | |||
680 | IList paramList = new ArrayList(); |
||
681 | paramList.Add(hash); |
||
682 | |||
683 | XmlRpcRequest request = new XmlRpcRequest("get_uui", paramList); |
||
684 | // string reason = string.Empty; |
||
685 | |||
686 | // Send and get reply |
||
687 | string uui = string.Empty; |
||
688 | XmlRpcResponse response = null; |
||
689 | try |
||
690 | { |
||
691 | response = request.Send(m_ServerURL, 10000); |
||
692 | } |
||
693 | catch |
||
694 | { |
||
695 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUI", m_ServerURL); |
||
696 | // reason = "Exception: " + e.Message; |
||
697 | return uui; |
||
698 | } |
||
699 | |||
700 | if (response.IsFault) |
||
701 | { |
||
702 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUI returned an error: {1}", m_ServerURL, response.FaultString); |
||
703 | // reason = "XMLRPC Fault"; |
||
704 | return uui; |
||
705 | } |
||
706 | |||
707 | hash = (Hashtable)response.Value; |
||
708 | //foreach (Object o in hash) |
||
709 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
710 | try |
||
711 | { |
||
712 | if (hash == null) |
||
713 | { |
||
714 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUI Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
715 | // reason = "Internal error 1"; |
||
716 | return uui; |
||
717 | } |
||
718 | |||
719 | // Here's the actual response |
||
720 | if (hash.ContainsKey("UUI")) |
||
721 | uui = hash["UUI"].ToString(); |
||
722 | |||
723 | } |
||
724 | catch |
||
725 | { |
||
726 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetUUI response."); |
||
727 | // reason = "Exception: " + e.Message; |
||
728 | } |
||
729 | |||
730 | return uui; |
||
731 | } |
||
732 | |||
733 | public UUID GetUUID(String first, String last) |
||
734 | { |
||
735 | Hashtable hash = new Hashtable(); |
||
736 | hash["first"] = first; |
||
737 | hash["last"] = last; |
||
738 | |||
739 | IList paramList = new ArrayList(); |
||
740 | paramList.Add(hash); |
||
741 | |||
742 | XmlRpcRequest request = new XmlRpcRequest("get_uuid", paramList); |
||
743 | // string reason = string.Empty; |
||
744 | |||
745 | // Send and get reply |
||
746 | UUID uuid = UUID.Zero; |
||
747 | XmlRpcResponse response = null; |
||
748 | try |
||
749 | { |
||
750 | response = request.Send(m_ServerURL, 10000); |
||
751 | } |
||
752 | catch |
||
753 | { |
||
754 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetUUID", m_ServerURL); |
||
755 | // reason = "Exception: " + e.Message; |
||
756 | return uuid; |
||
757 | } |
||
758 | |||
759 | if (response.IsFault) |
||
760 | { |
||
761 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetUUID returned an error: {1}", m_ServerURL, response.FaultString); |
||
762 | // reason = "XMLRPC Fault"; |
||
763 | return uuid; |
||
764 | } |
||
765 | |||
766 | hash = (Hashtable)response.Value; |
||
767 | //foreach (Object o in hash) |
||
768 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
769 | try |
||
770 | { |
||
771 | if (hash == null) |
||
772 | { |
||
773 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: GetUUDI Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
774 | // reason = "Internal error 1"; |
||
775 | return uuid; |
||
776 | } |
||
777 | |||
778 | // Here's the actual response |
||
779 | if (hash.ContainsKey("UUID")) |
||
780 | UUID.TryParse(hash["UUID"].ToString(), out uuid); |
||
781 | |||
782 | } |
||
783 | catch |
||
784 | { |
||
785 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on UUID response."); |
||
786 | // reason = "Exception: " + e.Message; |
||
787 | } |
||
788 | |||
789 | return uuid; |
||
790 | } |
||
791 | |||
792 | private bool GetBoolResponse(XmlRpcRequest request, out string reason) |
||
793 | { |
||
794 | //m_log.Debug("[USER AGENT CONNECTOR]: GetBoolResponse from/to " + m_ServerURL); |
||
795 | XmlRpcResponse response = null; |
||
796 | try |
||
797 | { |
||
798 | response = request.Send(m_ServerURL, 10000); |
||
799 | } |
||
800 | catch (Exception e) |
||
801 | { |
||
802 | m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0} for GetBoolResponse", m_ServerURL); |
||
803 | reason = "Exception: " + e.Message; |
||
804 | return false; |
||
805 | } |
||
806 | |||
807 | if (response.IsFault) |
||
808 | { |
||
809 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} for GetBoolResponse returned an error: {1}", m_ServerURL, response.FaultString); |
||
810 | reason = "XMLRPC Fault"; |
||
811 | return false; |
||
812 | } |
||
813 | |||
814 | Hashtable hash = (Hashtable)response.Value; |
||
815 | //foreach (Object o in hash) |
||
816 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); |
||
817 | try |
||
818 | { |
||
819 | if (hash == null) |
||
820 | { |
||
821 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL); |
||
822 | reason = "Internal error 1"; |
||
823 | return false; |
||
824 | } |
||
825 | bool success = false; |
||
826 | reason = string.Empty; |
||
827 | if (hash.ContainsKey("result")) |
||
828 | Boolean.TryParse((string)hash["result"], out success); |
||
829 | else |
||
830 | { |
||
831 | reason = "Internal error 2"; |
||
832 | m_log.WarnFormat("[USER AGENT CONNECTOR]: response from {0} does not have expected key 'result'", m_ServerURL); |
||
833 | } |
||
834 | |||
835 | return success; |
||
836 | } |
||
837 | catch (Exception e) |
||
838 | { |
||
839 | m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetBoolResponse response."); |
||
840 | if (hash.ContainsKey("result") && hash["result"] != null) |
||
841 | m_log.ErrorFormat("Reply was ", (string)hash["result"]); |
||
842 | reason = "Exception: " + e.Message; |
||
843 | return false; |
||
844 | } |
||
845 | |||
846 | } |
||
847 | |||
848 | } |
||
849 | } |