diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Grid')
-rw-r--r-- | OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | 147 | ||||
-rw-r--r-- | OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs | 254 |
2 files changed, 147 insertions, 254 deletions
diff --git a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs index 04c7c53..a453d99 100644 --- a/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs +++ b/OpenSim/Services/Connectors/Grid/GridServiceConnector.cs | |||
@@ -460,6 +460,153 @@ namespace OpenSim.Services.Connectors | |||
460 | return rinfos; | 460 | return rinfos; |
461 | } | 461 | } |
462 | 462 | ||
463 | public List<GridRegion> GetDefaultRegions(UUID scopeID) | ||
464 | { | ||
465 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
466 | |||
467 | sendData["SCOPEID"] = scopeID.ToString(); | ||
468 | |||
469 | sendData["METHOD"] = "get_default_regions"; | ||
470 | |||
471 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
472 | string reply = string.Empty; | ||
473 | try | ||
474 | { | ||
475 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
476 | m_ServerURI + "/grid", | ||
477 | ServerUtils.BuildQueryString(sendData)); | ||
478 | |||
479 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
480 | } | ||
481 | catch (Exception e) | ||
482 | { | ||
483 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
484 | return rinfos; | ||
485 | } | ||
486 | |||
487 | if (reply != string.Empty) | ||
488 | { | ||
489 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
490 | |||
491 | if (replyData != null) | ||
492 | { | ||
493 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
494 | foreach (object r in rinfosList) | ||
495 | { | ||
496 | if (r is Dictionary<string, object>) | ||
497 | { | ||
498 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
499 | rinfos.Add(rinfo); | ||
500 | } | ||
501 | } | ||
502 | } | ||
503 | else | ||
504 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions {0} received null response", | ||
505 | scopeID); | ||
506 | } | ||
507 | else | ||
508 | m_log.DebugFormat("[GRID CONNECTOR]: GetDefaultRegions received null reply"); | ||
509 | |||
510 | return rinfos; | ||
511 | } | ||
512 | |||
513 | public List<GridRegion> GetFallbackRegions(UUID scopeID, int x, int y) | ||
514 | { | ||
515 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
516 | |||
517 | sendData["SCOPEID"] = scopeID.ToString(); | ||
518 | sendData["X"] = x.ToString(); | ||
519 | sendData["Y"] = y.ToString(); | ||
520 | |||
521 | sendData["METHOD"] = "get_fallback_regions"; | ||
522 | |||
523 | List<GridRegion> rinfos = new List<GridRegion>(); | ||
524 | string reply = string.Empty; | ||
525 | try | ||
526 | { | ||
527 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
528 | m_ServerURI + "/grid", | ||
529 | ServerUtils.BuildQueryString(sendData)); | ||
530 | |||
531 | //m_log.DebugFormat("[GRID CONNECTOR]: reply was {0}", reply); | ||
532 | } | ||
533 | catch (Exception e) | ||
534 | { | ||
535 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
536 | return rinfos; | ||
537 | } | ||
538 | |||
539 | if (reply != string.Empty) | ||
540 | { | ||
541 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
542 | |||
543 | if (replyData != null) | ||
544 | { | ||
545 | Dictionary<string, object>.ValueCollection rinfosList = replyData.Values; | ||
546 | foreach (object r in rinfosList) | ||
547 | { | ||
548 | if (r is Dictionary<string, object>) | ||
549 | { | ||
550 | GridRegion rinfo = new GridRegion((Dictionary<string, object>)r); | ||
551 | rinfos.Add(rinfo); | ||
552 | } | ||
553 | } | ||
554 | } | ||
555 | else | ||
556 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions {0}, {1}-{2} received null response", | ||
557 | scopeID, x, y); | ||
558 | } | ||
559 | else | ||
560 | m_log.DebugFormat("[GRID CONNECTOR]: GetFallbackRegions received null reply"); | ||
561 | |||
562 | return rinfos; | ||
563 | } | ||
564 | |||
565 | public virtual int GetRegionFlags(UUID scopeID, UUID regionID) | ||
566 | { | ||
567 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
568 | |||
569 | sendData["SCOPEID"] = scopeID.ToString(); | ||
570 | sendData["REGIONID"] = regionID.ToString(); | ||
571 | |||
572 | sendData["METHOD"] = "get_region_flags"; | ||
573 | |||
574 | string reply = string.Empty; | ||
575 | try | ||
576 | { | ||
577 | reply = SynchronousRestFormsRequester.MakeRequest("POST", | ||
578 | m_ServerURI + "/grid", | ||
579 | ServerUtils.BuildQueryString(sendData)); | ||
580 | } | ||
581 | catch (Exception e) | ||
582 | { | ||
583 | m_log.DebugFormat("[GRID CONNECTOR]: Exception when contacting grid server: {0}", e.Message); | ||
584 | return -1; | ||
585 | } | ||
586 | |||
587 | int flags = -1; | ||
588 | |||
589 | if (reply != string.Empty) | ||
590 | { | ||
591 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); | ||
592 | |||
593 | if ((replyData != null) && replyData.ContainsKey("result") && (replyData["result"] != null)) | ||
594 | { | ||
595 | Int32.TryParse((string)replyData["result"], out flags); | ||
596 | //else | ||
597 | // m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received wrong type {2}", | ||
598 | // scopeID, regionID, replyData["result"].GetType()); | ||
599 | } | ||
600 | else | ||
601 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags {0}, {1} received null response", | ||
602 | scopeID, regionID); | ||
603 | } | ||
604 | else | ||
605 | m_log.DebugFormat("[GRID CONNECTOR]: GetRegionFlags received null reply"); | ||
606 | |||
607 | return flags; | ||
608 | } | ||
609 | |||
463 | #endregion | 610 | #endregion |
464 | 611 | ||
465 | } | 612 | } |
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs deleted file mode 100644 index 7098b07..0000000 --- a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs +++ /dev/null | |||
@@ -1,254 +0,0 @@ | |||
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.Text; | ||
32 | using System.Drawing; | ||
33 | using System.Net; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Services.Interfaces; | ||
36 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
37 | |||
38 | using OpenSim.Framework; | ||
39 | |||
40 | using OpenMetaverse; | ||
41 | using OpenMetaverse.Imaging; | ||
42 | using log4net; | ||
43 | using Nwc.XmlRpc; | ||
44 | |||
45 | namespace OpenSim.Services.Connectors.Grid | ||
46 | { | ||
47 | public class HypergridServiceConnector | ||
48 | { | ||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IAssetService m_AssetService; | ||
52 | |||
53 | public HypergridServiceConnector(IAssetService assService) | ||
54 | { | ||
55 | m_AssetService = assService; | ||
56 | } | ||
57 | |||
58 | public UUID LinkRegion(GridRegion info, out ulong realHandle) | ||
59 | { | ||
60 | UUID uuid = UUID.Zero; | ||
61 | realHandle = 0; | ||
62 | |||
63 | Hashtable hash = new Hashtable(); | ||
64 | hash["region_name"] = info.RegionName; | ||
65 | |||
66 | IList paramList = new ArrayList(); | ||
67 | paramList.Add(hash); | ||
68 | |||
69 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
70 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
71 | m_log.Debug("[HGrid]: Linking to " + uri); | ||
72 | XmlRpcResponse response = null; | ||
73 | try | ||
74 | { | ||
75 | response = request.Send(uri, 10000); | ||
76 | } | ||
77 | catch (Exception e) | ||
78 | { | ||
79 | m_log.Debug("[HGrid]: Exception " + e.Message); | ||
80 | return uuid; | ||
81 | } | ||
82 | |||
83 | if (response.IsFault) | ||
84 | { | ||
85 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | hash = (Hashtable)response.Value; | ||
90 | //foreach (Object o in hash) | ||
91 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
92 | try | ||
93 | { | ||
94 | UUID.TryParse((string)hash["uuid"], out uuid); | ||
95 | //m_log.Debug(">> HERE, uuid: " + uuid); | ||
96 | info.RegionID = uuid; | ||
97 | if ((string)hash["handle"] != null) | ||
98 | { | ||
99 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
100 | //m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
101 | } | ||
102 | //if (hash["region_image"] != null) | ||
103 | //{ | ||
104 | // UUID img = UUID.Zero; | ||
105 | // UUID.TryParse((string)hash["region_image"], out img); | ||
106 | // info.RegionSettings.TerrainImageID = img; | ||
107 | //} | ||
108 | if (hash["region_name"] != null) | ||
109 | { | ||
110 | info.RegionName = (string)hash["region_name"]; | ||
111 | //m_log.Debug(">> " + info.RegionName); | ||
112 | } | ||
113 | if (hash["internal_port"] != null) | ||
114 | { | ||
115 | int port = Convert.ToInt32((string)hash["internal_port"]); | ||
116 | info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port); | ||
117 | //m_log.Debug(">> " + info.InternalEndPoint.ToString()); | ||
118 | } | ||
119 | |||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
124 | } | ||
125 | } | ||
126 | return uuid; | ||
127 | } | ||
128 | |||
129 | public void GetMapImage(GridRegion info) | ||
130 | { | ||
131 | try | ||
132 | { | ||
133 | string regionimage = "regionImage" + info.RegionID.ToString(); | ||
134 | regionimage = regionimage.Replace("-", ""); | ||
135 | |||
136 | WebClient c = new WebClient(); | ||
137 | string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage; | ||
138 | //m_log.Debug("JPEG: " + uri); | ||
139 | c.DownloadFile(uri, info.RegionID.ToString() + ".jpg"); | ||
140 | Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg"); | ||
141 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
142 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
143 | AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString(), (sbyte)AssetType.Texture); | ||
144 | |||
145 | // !!! for now | ||
146 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
147 | |||
148 | ass.Temporary = true; | ||
149 | ass.Local = true; | ||
150 | ass.Data = imageData; | ||
151 | |||
152 | m_AssetService.Store(ass); | ||
153 | |||
154 | // finally | ||
155 | info.TerrainImage = ass.FullID; | ||
156 | |||
157 | } | ||
158 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
159 | { | ||
160 | m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache"); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | public bool InformRegionOfUser(GridRegion regInfo, AgentCircuitData agentData, GridRegion home, string userServer, string assetServer, string inventoryServer) | ||
165 | { | ||
166 | string capsPath = agentData.CapsPath; | ||
167 | Hashtable loginParams = new Hashtable(); | ||
168 | loginParams["session_id"] = agentData.SessionID.ToString(); | ||
169 | |||
170 | loginParams["firstname"] = agentData.firstname; | ||
171 | loginParams["lastname"] = agentData.lastname; | ||
172 | |||
173 | loginParams["agent_id"] = agentData.AgentID.ToString(); | ||
174 | loginParams["circuit_code"] = agentData.circuitcode.ToString(); | ||
175 | loginParams["startpos_x"] = agentData.startpos.X.ToString(); | ||
176 | loginParams["startpos_y"] = agentData.startpos.Y.ToString(); | ||
177 | loginParams["startpos_z"] = agentData.startpos.Z.ToString(); | ||
178 | loginParams["caps_path"] = capsPath; | ||
179 | |||
180 | if (home != null) | ||
181 | { | ||
182 | loginParams["region_uuid"] = home.RegionID.ToString(); | ||
183 | loginParams["regionhandle"] = home.RegionHandle.ToString(); | ||
184 | loginParams["home_address"] = home.ExternalHostName; | ||
185 | loginParams["home_port"] = home.HttpPort.ToString(); | ||
186 | loginParams["internal_port"] = home.InternalEndPoint.Port.ToString(); | ||
187 | |||
188 | m_log.Debug(" --------- Home -------"); | ||
189 | m_log.Debug(" >> " + loginParams["home_address"] + " <<"); | ||
190 | m_log.Debug(" >> " + loginParams["region_uuid"] + " <<"); | ||
191 | m_log.Debug(" >> " + loginParams["regionhandle"] + " <<"); | ||
192 | m_log.Debug(" >> " + loginParams["home_port"] + " <<"); | ||
193 | m_log.Debug(" --------- ------------ -------"); | ||
194 | } | ||
195 | else | ||
196 | m_log.WarnFormat("[HGrid]: Home region not found for {0} {1}", agentData.firstname, agentData.lastname); | ||
197 | |||
198 | loginParams["userserver_id"] = userServer; | ||
199 | loginParams["assetserver_id"] = assetServer; | ||
200 | loginParams["inventoryserver_id"] = inventoryServer; | ||
201 | |||
202 | |||
203 | ArrayList SendParams = new ArrayList(); | ||
204 | SendParams.Add(loginParams); | ||
205 | |||
206 | // Send | ||
207 | string uri = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort + "/"; | ||
208 | //m_log.Debug("XXX uri: " + uri); | ||
209 | XmlRpcRequest request = new XmlRpcRequest("expect_hg_user", SendParams); | ||
210 | XmlRpcResponse reply; | ||
211 | try | ||
212 | { | ||
213 | reply = request.Send(uri, 6000); | ||
214 | } | ||
215 | catch (Exception e) | ||
216 | { | ||
217 | m_log.Warn("[HGrid]: Failed to notify region about user. Reason: " + e.Message); | ||
218 | return false; | ||
219 | } | ||
220 | |||
221 | if (!reply.IsFault) | ||
222 | { | ||
223 | bool responseSuccess = true; | ||
224 | if (reply.Value != null) | ||
225 | { | ||
226 | Hashtable resp = (Hashtable)reply.Value; | ||
227 | if (resp.ContainsKey("success")) | ||
228 | { | ||
229 | if ((string)resp["success"] == "FALSE") | ||
230 | { | ||
231 | responseSuccess = false; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | if (responseSuccess) | ||
236 | { | ||
237 | m_log.Info("[HGrid]: Successfully informed remote region about user " + agentData.AgentID); | ||
238 | return true; | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | m_log.ErrorFormat("[HGrid]: Region responded that it is not available to receive clients"); | ||
243 | return false; | ||
244 | } | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | m_log.ErrorFormat("[HGrid]: XmlRpc request to region failed with message {0}, code {1} ", reply.FaultString, reply.FaultCode); | ||
249 | return false; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | } | ||
254 | } | ||