diff options
author | Melanie | 2010-03-03 02:07:03 +0000 |
---|---|---|
committer | Melanie | 2010-03-03 02:07:03 +0000 |
commit | 028a87fe37002e7a0611f66babf1deee46c83804 (patch) | |
tree | 387aec499fd60c2012bed8148e6a2ddc847c3d95 /OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | |
parent | Revert "test" (diff) | |
parent | Fixes Region.Framework tests. Although these tests don't fail, they need to b... (diff) | |
download | opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.zip opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.tar.gz opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.tar.bz2 opensim-SC-028a87fe37002e7a0611f66babf1deee46c83804.tar.xz |
Merge branch 'master' into careminster-presence-refactor
This brings careminster on the level of master. To be tested
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/Connectors/Hypergrid/GatekeeperServiceConnector.cs | 245 |
1 files changed, 245 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 | } | ||