diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | 245 | ||||
-rw-r--r-- | OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs | 370 |
2 files changed, 615 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..9f73b38 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | |||
@@ -0,0 +1,245 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Drawing; | ||
5 | using System.Net; | ||
6 | using System.Reflection; | ||
7 | |||
8 | using OpenSim.Framework; | ||
9 | using OpenSim.Services.Interfaces; | ||
10 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
11 | |||
12 | using OpenMetaverse; | ||
13 | using OpenMetaverse.Imaging; | ||
14 | using Nwc.XmlRpc; | ||
15 | using log4net; | ||
16 | |||
17 | using OpenSim.Services.Connectors.Simulation; | ||
18 | |||
19 | namespace OpenSim.Services.Connectors.Hypergrid | ||
20 | { | ||
21 | public class GatekeeperServiceConnector : SimulationServiceConnector | ||
22 | { | ||
23 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
24 | |||
25 | private static UUID m_HGMapImage = new UUID("00000000-0000-1111-9999-000000000013"); | ||
26 | |||
27 | private IAssetService m_AssetService; | ||
28 | |||
29 | public GatekeeperServiceConnector() : base() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | public GatekeeperServiceConnector(IAssetService assService) | ||
34 | { | ||
35 | m_AssetService = assService; | ||
36 | } | ||
37 | |||
38 | protected override string AgentPath() | ||
39 | { | ||
40 | return "/foreignagent/"; | ||
41 | } | ||
42 | |||
43 | protected override string ObjectPath() | ||
44 | { | ||
45 | return "/foreignobject/"; | ||
46 | } | ||
47 | |||
48 | public bool LinkRegion(GridRegion info, out UUID regionID, out ulong realHandle, out string externalName, out string imageURL, out string reason) | ||
49 | { | ||
50 | regionID = UUID.Zero; | ||
51 | imageURL = string.Empty; | ||
52 | realHandle = 0; | ||
53 | externalName = string.Empty; | ||
54 | reason = string.Empty; | ||
55 | |||
56 | Hashtable hash = new Hashtable(); | ||
57 | hash["region_name"] = info.RegionName; | ||
58 | |||
59 | IList paramList = new ArrayList(); | ||
60 | paramList.Add(hash); | ||
61 | |||
62 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
63 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
64 | //m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Linking to " + uri); | ||
65 | XmlRpcResponse response = null; | ||
66 | try | ||
67 | { | ||
68 | response = request.Send(uri, 10000); | ||
69 | } | ||
70 | catch (Exception e) | ||
71 | { | ||
72 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
73 | reason = "Error contacting remote server"; | ||
74 | return false; | ||
75 | } | ||
76 | |||
77 | if (response.IsFault) | ||
78 | { | ||
79 | reason = response.FaultString; | ||
80 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | hash = (Hashtable)response.Value; | ||
85 | //foreach (Object o in hash) | ||
86 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
87 | try | ||
88 | { | ||
89 | bool success = false; | ||
90 | Boolean.TryParse((string)hash["result"], out success); | ||
91 | if (success) | ||
92 | { | ||
93 | UUID.TryParse((string)hash["uuid"], out regionID); | ||
94 | //m_log.Debug(">> HERE, uuid: " + uuid); | ||
95 | if ((string)hash["handle"] != null) | ||
96 | { | ||
97 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
98 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
99 | } | ||
100 | if (hash["region_image"] != null) | ||
101 | imageURL = (string)hash["region_image"]; | ||
102 | if (hash["external_name"] != null) | ||
103 | externalName = (string)hash["external_name"]; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | catch (Exception e) | ||
108 | { | ||
109 | reason = "Error parsing return arguments"; | ||
110 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
111 | return false; | ||
112 | } | ||
113 | |||
114 | return true; | ||
115 | } | ||
116 | |||
117 | UUID m_MissingTexture = new UUID("5748decc-f629-461c-9a36-a35a221fe21f"); | ||
118 | |||
119 | public UUID GetMapImage(UUID regionID, string imageURL) | ||
120 | { | ||
121 | if (m_AssetService == null) | ||
122 | return m_MissingTexture; | ||
123 | |||
124 | try | ||
125 | { | ||
126 | |||
127 | WebClient c = new WebClient(); | ||
128 | //m_log.Debug("JPEG: " + imageURL); | ||
129 | string filename = regionID.ToString(); | ||
130 | c.DownloadFile(imageURL, filename + ".jpg"); | ||
131 | Bitmap m = new Bitmap(filename + ".jpg"); | ||
132 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
133 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
134 | AssetBase ass = new AssetBase(UUID.Random(), "region " + filename, (sbyte)AssetType.Texture, regionID.ToString()); | ||
135 | |||
136 | // !!! for now | ||
137 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
138 | |||
139 | ass.Temporary = true; | ||
140 | ass.Local = true; | ||
141 | ass.Data = imageData; | ||
142 | |||
143 | m_AssetService.Store(ass); | ||
144 | |||
145 | // finally | ||
146 | return ass.FullID; | ||
147 | |||
148 | } | ||
149 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
150 | { | ||
151 | m_log.Warn("[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache"); | ||
152 | } | ||
153 | return UUID.Zero; | ||
154 | } | ||
155 | |||
156 | public GridRegion GetHyperlinkRegion(GridRegion gatekeeper, UUID regionID) | ||
157 | { | ||
158 | Hashtable hash = new Hashtable(); | ||
159 | hash["region_uuid"] = regionID.ToString(); | ||
160 | |||
161 | IList paramList = new ArrayList(); | ||
162 | paramList.Add(hash); | ||
163 | |||
164 | XmlRpcRequest request = new XmlRpcRequest("get_region", paramList); | ||
165 | string uri = "http://" + gatekeeper.ExternalEndPoint.Address + ":" + gatekeeper.HttpPort + "/"; | ||
166 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: contacting " + uri); | ||
167 | XmlRpcResponse response = null; | ||
168 | try | ||
169 | { | ||
170 | response = request.Send(uri, 10000); | ||
171 | } | ||
172 | catch (Exception e) | ||
173 | { | ||
174 | m_log.Debug("[GATEKEEPER SERVICE CONNECTOR]: Exception " + e.Message); | ||
175 | return null; | ||
176 | } | ||
177 | |||
178 | if (response.IsFault) | ||
179 | { | ||
180 | m_log.ErrorFormat("[GATEKEEPER SERVICE CONNECTOR]: remote call returned an error: {0}", response.FaultString); | ||
181 | return null; | ||
182 | } | ||
183 | |||
184 | hash = (Hashtable)response.Value; | ||
185 | //foreach (Object o in hash) | ||
186 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
187 | try | ||
188 | { | ||
189 | bool success = false; | ||
190 | Boolean.TryParse((string)hash["result"], out success); | ||
191 | if (success) | ||
192 | { | ||
193 | GridRegion region = new GridRegion(); | ||
194 | |||
195 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
196 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
197 | int n = 0; | ||
198 | if (hash["x"] != null) | ||
199 | { | ||
200 | Int32.TryParse((string)hash["x"], out n); | ||
201 | region.RegionLocX = n; | ||
202 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
203 | } | ||
204 | if (hash["y"] != null) | ||
205 | { | ||
206 | Int32.TryParse((string)hash["y"], out n); | ||
207 | region.RegionLocY = n; | ||
208 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
209 | } | ||
210 | if (hash["region_name"] != null) | ||
211 | { | ||
212 | region.RegionName = (string)hash["region_name"]; | ||
213 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
214 | } | ||
215 | if (hash["hostname"] != null) | ||
216 | region.ExternalHostName = (string)hash["hostname"]; | ||
217 | if (hash["http_port"] != null) | ||
218 | { | ||
219 | uint p = 0; | ||
220 | UInt32.TryParse((string)hash["http_port"], out p); | ||
221 | region.HttpPort = p; | ||
222 | } | ||
223 | if (hash["internal_port"] != null) | ||
224 | { | ||
225 | int p = 0; | ||
226 | Int32.TryParse((string)hash["internal_port"], out p); | ||
227 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
228 | } | ||
229 | |||
230 | // Successful return | ||
231 | return region; | ||
232 | } | ||
233 | |||
234 | } | ||
235 | catch (Exception e) | ||
236 | { | ||
237 | m_log.Error("[GATEKEEPER SERVICE CONNECTOR]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
238 | return null; | ||
239 | } | ||
240 | |||
241 | return null; | ||
242 | } | ||
243 | |||
244 | } | ||
245 | } | ||
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs new file mode 100644 index 0000000..83d3449 --- /dev/null +++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs | |||
@@ -0,0 +1,370 @@ | |||
1 | using System; | ||
2 | using System.Collections; | ||
3 | using System.Collections.Generic; | ||
4 | using System.IO; | ||
5 | using System.Net; | ||
6 | using System.Reflection; | ||
7 | using System.Text; | ||
8 | |||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Services.Interfaces; | ||
11 | using OpenSim.Services.Connectors.Simulation; | ||
12 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
13 | |||
14 | using OpenMetaverse; | ||
15 | using OpenMetaverse.StructuredData; | ||
16 | using log4net; | ||
17 | using Nwc.XmlRpc; | ||
18 | using Nini.Config; | ||
19 | |||
20 | namespace OpenSim.Services.Connectors.Hypergrid | ||
21 | { | ||
22 | public class UserAgentServiceConnector : IUserAgentService | ||
23 | { | ||
24 | private static readonly ILog m_log = | ||
25 | LogManager.GetLogger( | ||
26 | MethodBase.GetCurrentMethod().DeclaringType); | ||
27 | |||
28 | string m_ServerURL; | ||
29 | public UserAgentServiceConnector(string url) | ||
30 | { | ||
31 | m_ServerURL = url; | ||
32 | } | ||
33 | |||
34 | public UserAgentServiceConnector(IConfigSource config) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | public bool LoginAgentToGrid(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination, out string reason) | ||
39 | { | ||
40 | reason = String.Empty; | ||
41 | |||
42 | if (destination == null) | ||
43 | { | ||
44 | reason = "Destination is null"; | ||
45 | m_log.Debug("[USER AGENT CONNECTOR]: Given destination is null"); | ||
46 | return false; | ||
47 | } | ||
48 | |||
49 | string uri = m_ServerURL + "/homeagent/" + aCircuit.AgentID + "/"; | ||
50 | |||
51 | Console.WriteLine(" >>> LoginAgentToGrid <<< " + uri); | ||
52 | |||
53 | HttpWebRequest AgentCreateRequest = (HttpWebRequest)WebRequest.Create(uri); | ||
54 | AgentCreateRequest.Method = "POST"; | ||
55 | AgentCreateRequest.ContentType = "application/json"; | ||
56 | AgentCreateRequest.Timeout = 10000; | ||
57 | //AgentCreateRequest.KeepAlive = false; | ||
58 | //AgentCreateRequest.Headers.Add("Authorization", authKey); | ||
59 | |||
60 | // Fill it in | ||
61 | OSDMap args = PackCreateAgentArguments(aCircuit, gatekeeper, destination); | ||
62 | |||
63 | string strBuffer = ""; | ||
64 | byte[] buffer = new byte[1]; | ||
65 | try | ||
66 | { | ||
67 | strBuffer = OSDParser.SerializeJsonString(args); | ||
68 | Encoding str = Util.UTF8; | ||
69 | buffer = str.GetBytes(strBuffer); | ||
70 | |||
71 | } | ||
72 | catch (Exception e) | ||
73 | { | ||
74 | m_log.WarnFormat("[USER AGENT CONNECTOR]: Exception thrown on serialization of ChildCreate: {0}", e.Message); | ||
75 | // ignore. buffer will be empty, caller should check. | ||
76 | } | ||
77 | |||
78 | Stream os = null; | ||
79 | try | ||
80 | { // send the Post | ||
81 | AgentCreateRequest.ContentLength = buffer.Length; //Count bytes to send | ||
82 | os = AgentCreateRequest.GetRequestStream(); | ||
83 | os.Write(buffer, 0, strBuffer.Length); //Send it | ||
84 | m_log.InfoFormat("[USER AGENT CONNECTOR]: Posted CreateAgent request to remote sim {0}, region {1}, x={2} y={3}", | ||
85 | uri, destination.RegionName, destination.RegionLocX, destination.RegionLocY); | ||
86 | } | ||
87 | //catch (WebException ex) | ||
88 | catch | ||
89 | { | ||
90 | //m_log.InfoFormat("[USER AGENT CONNECTOR]: Bad send on ChildAgentUpdate {0}", ex.Message); | ||
91 | reason = "cannot contact remote region"; | ||
92 | return false; | ||
93 | } | ||
94 | finally | ||
95 | { | ||
96 | if (os != null) | ||
97 | os.Close(); | ||
98 | } | ||
99 | |||
100 | // Let's wait for the response | ||
101 | //m_log.Info("[USER AGENT CONNECTOR]: Waiting for a reply after DoCreateChildAgentCall"); | ||
102 | |||
103 | WebResponse webResponse = null; | ||
104 | StreamReader sr = null; | ||
105 | try | ||
106 | { | ||
107 | webResponse = AgentCreateRequest.GetResponse(); | ||
108 | if (webResponse == null) | ||
109 | { | ||
110 | m_log.Info("[USER AGENT CONNECTOR]: Null reply on DoCreateChildAgentCall post"); | ||
111 | } | ||
112 | else | ||
113 | { | ||
114 | |||
115 | sr = new StreamReader(webResponse.GetResponseStream()); | ||
116 | string response = sr.ReadToEnd().Trim(); | ||
117 | m_log.InfoFormat("[USER AGENT CONNECTOR]: DoCreateChildAgentCall reply was {0} ", response); | ||
118 | |||
119 | if (!String.IsNullOrEmpty(response)) | ||
120 | { | ||
121 | try | ||
122 | { | ||
123 | // we assume we got an OSDMap back | ||
124 | OSDMap r = Util.GetOSDMap(response); | ||
125 | bool success = r["success"].AsBoolean(); | ||
126 | reason = r["reason"].AsString(); | ||
127 | return success; | ||
128 | } | ||
129 | catch (NullReferenceException e) | ||
130 | { | ||
131 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", e.Message); | ||
132 | |||
133 | // check for old style response | ||
134 | if (response.ToLower().StartsWith("true")) | ||
135 | return true; | ||
136 | |||
137 | return false; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | catch (WebException ex) | ||
143 | { | ||
144 | m_log.InfoFormat("[USER AGENT CONNECTOR]: exception on reply of DoCreateChildAgentCall {0}", ex.Message); | ||
145 | reason = "Destination did not reply"; | ||
146 | return false; | ||
147 | } | ||
148 | finally | ||
149 | { | ||
150 | if (sr != null) | ||
151 | sr.Close(); | ||
152 | } | ||
153 | |||
154 | return true; | ||
155 | |||
156 | } | ||
157 | |||
158 | protected OSDMap PackCreateAgentArguments(AgentCircuitData aCircuit, GridRegion gatekeeper, GridRegion destination) | ||
159 | { | ||
160 | OSDMap args = null; | ||
161 | try | ||
162 | { | ||
163 | args = aCircuit.PackAgentCircuitData(); | ||
164 | } | ||
165 | catch (Exception e) | ||
166 | { | ||
167 | m_log.Debug("[USER AGENT CONNECTOR]: PackAgentCircuitData failed with exception: " + e.Message); | ||
168 | } | ||
169 | // Add the input arguments | ||
170 | args["gatekeeper_host"] = OSD.FromString(gatekeeper.ExternalHostName); | ||
171 | args["gatekeeper_port"] = OSD.FromString(gatekeeper.HttpPort.ToString()); | ||
172 | args["destination_x"] = OSD.FromString(destination.RegionLocX.ToString()); | ||
173 | args["destination_y"] = OSD.FromString(destination.RegionLocY.ToString()); | ||
174 | args["destination_name"] = OSD.FromString(destination.RegionName); | ||
175 | args["destination_uuid"] = OSD.FromString(destination.RegionID.ToString()); | ||
176 | |||
177 | return args; | ||
178 | } | ||
179 | |||
180 | public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) | ||
181 | { | ||
182 | position = Vector3.UnitY; lookAt = Vector3.UnitY; | ||
183 | |||
184 | Hashtable hash = new Hashtable(); | ||
185 | hash["userID"] = userID.ToString(); | ||
186 | |||
187 | IList paramList = new ArrayList(); | ||
188 | paramList.Add(hash); | ||
189 | |||
190 | XmlRpcRequest request = new XmlRpcRequest("get_home_region", paramList); | ||
191 | XmlRpcResponse response = null; | ||
192 | try | ||
193 | { | ||
194 | response = request.Send(m_ServerURL, 10000); | ||
195 | } | ||
196 | catch (Exception e) | ||
197 | { | ||
198 | return null; | ||
199 | } | ||
200 | |||
201 | if (response.IsFault) | ||
202 | { | ||
203 | return null; | ||
204 | } | ||
205 | |||
206 | hash = (Hashtable)response.Value; | ||
207 | //foreach (Object o in hash) | ||
208 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
209 | try | ||
210 | { | ||
211 | bool success = false; | ||
212 | Boolean.TryParse((string)hash["result"], out success); | ||
213 | if (success) | ||
214 | { | ||
215 | GridRegion region = new GridRegion(); | ||
216 | |||
217 | UUID.TryParse((string)hash["uuid"], out region.RegionID); | ||
218 | //m_log.Debug(">> HERE, uuid: " + region.RegionID); | ||
219 | int n = 0; | ||
220 | if (hash["x"] != null) | ||
221 | { | ||
222 | Int32.TryParse((string)hash["x"], out n); | ||
223 | region.RegionLocX = n; | ||
224 | //m_log.Debug(">> HERE, x: " + region.RegionLocX); | ||
225 | } | ||
226 | if (hash["y"] != null) | ||
227 | { | ||
228 | Int32.TryParse((string)hash["y"], out n); | ||
229 | region.RegionLocY = n; | ||
230 | //m_log.Debug(">> HERE, y: " + region.RegionLocY); | ||
231 | } | ||
232 | if (hash["region_name"] != null) | ||
233 | { | ||
234 | region.RegionName = (string)hash["region_name"]; | ||
235 | //m_log.Debug(">> HERE, name: " + region.RegionName); | ||
236 | } | ||
237 | if (hash["hostname"] != null) | ||
238 | region.ExternalHostName = (string)hash["hostname"]; | ||
239 | if (hash["http_port"] != null) | ||
240 | { | ||
241 | uint p = 0; | ||
242 | UInt32.TryParse((string)hash["http_port"], out p); | ||
243 | region.HttpPort = p; | ||
244 | } | ||
245 | if (hash["internal_port"] != null) | ||
246 | { | ||
247 | int p = 0; | ||
248 | Int32.TryParse((string)hash["internal_port"], out p); | ||
249 | region.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), p); | ||
250 | } | ||
251 | if (hash["position"] != null) | ||
252 | Vector3.TryParse((string)hash["position"], out position); | ||
253 | if (hash["lookAt"] != null) | ||
254 | Vector3.TryParse((string)hash["lookAt"], out lookAt); | ||
255 | |||
256 | // Successful return | ||
257 | return region; | ||
258 | } | ||
259 | |||
260 | } | ||
261 | catch (Exception e) | ||
262 | { | ||
263 | return null; | ||
264 | } | ||
265 | |||
266 | return null; | ||
267 | |||
268 | } | ||
269 | |||
270 | public bool AgentIsComingHome(UUID sessionID, string thisGridExternalName) | ||
271 | { | ||
272 | Hashtable hash = new Hashtable(); | ||
273 | hash["sessionID"] = sessionID.ToString(); | ||
274 | hash["externalName"] = thisGridExternalName; | ||
275 | |||
276 | IList paramList = new ArrayList(); | ||
277 | paramList.Add(hash); | ||
278 | |||
279 | XmlRpcRequest request = new XmlRpcRequest("agent_is_coming_home", paramList); | ||
280 | string reason = string.Empty; | ||
281 | return GetBoolResponse(request, out reason); | ||
282 | } | ||
283 | |||
284 | public bool VerifyAgent(UUID sessionID, string token) | ||
285 | { | ||
286 | Hashtable hash = new Hashtable(); | ||
287 | hash["sessionID"] = sessionID.ToString(); | ||
288 | hash["token"] = token; | ||
289 | |||
290 | IList paramList = new ArrayList(); | ||
291 | paramList.Add(hash); | ||
292 | |||
293 | XmlRpcRequest request = new XmlRpcRequest("verify_agent", paramList); | ||
294 | string reason = string.Empty; | ||
295 | return GetBoolResponse(request, out reason); | ||
296 | } | ||
297 | |||
298 | public bool VerifyClient(UUID sessionID, string token) | ||
299 | { | ||
300 | Hashtable hash = new Hashtable(); | ||
301 | hash["sessionID"] = sessionID.ToString(); | ||
302 | hash["token"] = token; | ||
303 | |||
304 | IList paramList = new ArrayList(); | ||
305 | paramList.Add(hash); | ||
306 | |||
307 | XmlRpcRequest request = new XmlRpcRequest("verify_client", paramList); | ||
308 | string reason = string.Empty; | ||
309 | return GetBoolResponse(request, out reason); | ||
310 | } | ||
311 | |||
312 | public void LogoutAgent(UUID userID, UUID sessionID) | ||
313 | { | ||
314 | Hashtable hash = new Hashtable(); | ||
315 | hash["sessionID"] = sessionID.ToString(); | ||
316 | hash["userID"] = userID.ToString(); | ||
317 | |||
318 | IList paramList = new ArrayList(); | ||
319 | paramList.Add(hash); | ||
320 | |||
321 | XmlRpcRequest request = new XmlRpcRequest("logout_agent", paramList); | ||
322 | string reason = string.Empty; | ||
323 | GetBoolResponse(request, out reason); | ||
324 | } | ||
325 | |||
326 | |||
327 | private bool GetBoolResponse(XmlRpcRequest request, out string reason) | ||
328 | { | ||
329 | //m_log.Debug("[HGrid]: Linking to " + uri); | ||
330 | XmlRpcResponse response = null; | ||
331 | try | ||
332 | { | ||
333 | response = request.Send(m_ServerURL, 10000); | ||
334 | } | ||
335 | catch (Exception e) | ||
336 | { | ||
337 | m_log.Debug("[HGrid]: Exception " + e.Message); | ||
338 | reason = "Exception: " + e.Message; | ||
339 | return false; | ||
340 | } | ||
341 | |||
342 | if (response.IsFault) | ||
343 | { | ||
344 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
345 | reason = "XMLRPC Fault"; | ||
346 | return false; | ||
347 | } | ||
348 | |||
349 | Hashtable hash = (Hashtable)response.Value; | ||
350 | //foreach (Object o in hash) | ||
351 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
352 | try | ||
353 | { | ||
354 | bool success = false; | ||
355 | reason = string.Empty; | ||
356 | Boolean.TryParse((string)hash["result"], out success); | ||
357 | |||
358 | return success; | ||
359 | } | ||
360 | catch (Exception e) | ||
361 | { | ||
362 | m_log.Error("[HGrid]: Got exception while parsing GetEndPoint response " + e.StackTrace); | ||
363 | reason = "Exception: " + e.Message; | ||
364 | return false; | ||
365 | } | ||
366 | |||
367 | } | ||
368 | |||
369 | } | ||
370 | } | ||