diff options
Diffstat (limited to 'OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs')
-rw-r--r-- | OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs new file mode 100644 index 0000000..6b0518c --- /dev/null +++ b/OpenSim/Services/Connectors/Grid/HypergridServiceConnector.cs | |||
@@ -0,0 +1,151 @@ | |||
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 | |||
37 | using OpenSim.Framework; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.Imaging; | ||
41 | using log4net; | ||
42 | using Nwc.XmlRpc; | ||
43 | |||
44 | namespace OpenSim.Services.Connectors.Grid | ||
45 | { | ||
46 | public class HypergridServiceConnector | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private IAssetService m_AssetService; | ||
51 | |||
52 | public HypergridServiceConnector(IAssetService assService) | ||
53 | { | ||
54 | m_AssetService = assService; | ||
55 | } | ||
56 | |||
57 | public UUID LinkRegion(SimpleRegionInfo info, out ulong realHandle) | ||
58 | { | ||
59 | UUID uuid = UUID.Zero; | ||
60 | realHandle = 0; | ||
61 | |||
62 | Hashtable hash = new Hashtable(); | ||
63 | hash["region_name"] = info.RegionName; | ||
64 | |||
65 | IList paramList = new ArrayList(); | ||
66 | paramList.Add(hash); | ||
67 | |||
68 | XmlRpcRequest request = new XmlRpcRequest("link_region", paramList); | ||
69 | string uri = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/"; | ||
70 | m_log.Debug("[HGrid]: Linking to " + uri); | ||
71 | XmlRpcResponse response = request.Send(uri, 10000); | ||
72 | if (response.IsFault) | ||
73 | { | ||
74 | m_log.ErrorFormat("[HGrid]: remote call returned an error: {0}", response.FaultString); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | hash = (Hashtable)response.Value; | ||
79 | //foreach (Object o in hash) | ||
80 | // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value); | ||
81 | try | ||
82 | { | ||
83 | UUID.TryParse((string)hash["uuid"], out uuid); | ||
84 | info.RegionID = uuid; | ||
85 | if ((string)hash["handle"] != null) | ||
86 | { | ||
87 | realHandle = Convert.ToUInt64((string)hash["handle"]); | ||
88 | m_log.Debug(">> HERE, realHandle: " + realHandle); | ||
89 | } | ||
90 | //if (hash["region_image"] != null) | ||
91 | //{ | ||
92 | // UUID img = UUID.Zero; | ||
93 | // UUID.TryParse((string)hash["region_image"], out img); | ||
94 | // info.RegionSettings.TerrainImageID = img; | ||
95 | //} | ||
96 | if (hash["region_name"] != null) | ||
97 | { | ||
98 | info.RegionName = (string)hash["region_name"]; | ||
99 | //m_log.Debug(">> " + info.RegionName); | ||
100 | } | ||
101 | if (hash["internal_port"] != null) | ||
102 | { | ||
103 | int port = Convert.ToInt32((string)hash["internal_port"]); | ||
104 | info.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), port); | ||
105 | //m_log.Debug(">> " + info.InternalEndPoint.ToString()); | ||
106 | } | ||
107 | |||
108 | } | ||
109 | catch (Exception e) | ||
110 | { | ||
111 | m_log.Error("[HGrid]: Got exception while parsing hyperlink response " + e.StackTrace); | ||
112 | } | ||
113 | } | ||
114 | return uuid; | ||
115 | } | ||
116 | |||
117 | public void GetMapImage(SimpleRegionInfo info) | ||
118 | { | ||
119 | try | ||
120 | { | ||
121 | string regionimage = "regionImage" + info.RegionID.ToString(); | ||
122 | regionimage = regionimage.Replace("-", ""); | ||
123 | |||
124 | WebClient c = new WebClient(); | ||
125 | string uri = "http://" + info.ExternalHostName + ":" + info.HttpPort + "/index.php?method=" + regionimage; | ||
126 | //m_log.Debug("JPEG: " + uri); | ||
127 | c.DownloadFile(uri, info.RegionID.ToString() + ".jpg"); | ||
128 | Bitmap m = new Bitmap(info.RegionID.ToString() + ".jpg"); | ||
129 | //m_log.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width); | ||
130 | byte[] imageData = OpenJPEG.EncodeFromImage(m, true); | ||
131 | AssetBase ass = new AssetBase(UUID.Random(), "region " + info.RegionID.ToString()); | ||
132 | |||
133 | // !!! for now | ||
134 | //info.RegionSettings.TerrainImageID = ass.FullID; | ||
135 | |||
136 | ass.Type = (int)AssetType.Texture; | ||
137 | ass.Temporary = true; | ||
138 | ass.Local = true; | ||
139 | ass.Data = imageData; | ||
140 | |||
141 | m_AssetService.Store(ass); | ||
142 | |||
143 | } | ||
144 | catch // LEGIT: Catching problems caused by OpenJPEG p/invoke | ||
145 | { | ||
146 | m_log.Warn("[HGrid]: Failed getting/storing map image, because it is probably already in the cache"); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | } | ||
151 | } | ||