aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs303
1 files changed, 303 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
new file mode 100644
index 0000000..36915ef
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/HGCommands.cs
@@ -0,0 +1,303 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Xml;
32using log4net;
33using Nini.Config;
34using OpenSim.Framework;
35//using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console;
37using OpenSim.Region.Framework;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.Framework.Scenes.Hypergrid;
40using GridRegion = OpenSim.Services.Interfaces.GridRegion;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
43{
44 public class HGCommands
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private HGGridConnector m_HGGridConnector;
48 private Scene m_scene;
49
50 private static uint m_autoMappingX = 0;
51 private static uint m_autoMappingY = 0;
52 private static bool m_enableAutoMapping = false;
53
54 public HGCommands(HGGridConnector hgConnector, Scene scene)
55 {
56 m_HGGridConnector = hgConnector;
57 m_scene = scene;
58 }
59
60 //public static Scene CreateScene(RegionInfo regionInfo, AgentCircuitManager circuitManager, CommunicationsManager m_commsManager,
61 // StorageManager storageManager, ModuleLoader m_moduleLoader, ConfigSettings m_configSettings, OpenSimConfigSource m_config, string m_version)
62 //{
63 // HGSceneCommunicationService sceneGridService = new HGSceneCommunicationService(m_commsManager, HGServices);
64
65 // return
66 // new HGScene(
67 // regionInfo, circuitManager, m_commsManager, sceneGridService, storageManager,
68 // m_moduleLoader, false, m_configSettings.PhysicalPrim,
69 // m_configSettings.See_into_region_from_neighbor, m_config.Source, m_version);
70 //}
71
72 public void RunCommand(string module, string[] cmdparams)
73 {
74 List<string> args = new List<string>(cmdparams);
75 if (args.Count < 1)
76 return;
77
78 string command = args[0];
79 args.RemoveAt(0);
80
81 cmdparams = args.ToArray();
82
83 RunHGCommand(command, cmdparams);
84
85 }
86
87 private void RunHGCommand(string command, string[] cmdparams)
88 {
89 if (command.Equals("linkk-mapping"))
90 {
91 if (cmdparams.Length == 2)
92 {
93 try
94 {
95 m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
96 m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
97 m_enableAutoMapping = true;
98 }
99 catch (Exception)
100 {
101 m_autoMappingX = 0;
102 m_autoMappingY = 0;
103 m_enableAutoMapping = false;
104 }
105 }
106 }
107 else if (command.Equals("linkk-region"))
108 {
109 if (cmdparams.Length < 3)
110 {
111 if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
112 {
113 LoadXmlLinkFile(cmdparams);
114 }
115 else
116 {
117 LinkRegionCmdUsage();
118 }
119 return;
120 }
121
122 if (cmdparams[2].Contains(":"))
123 {
124 // New format
125 int xloc, yloc;
126 string mapName;
127 try
128 {
129 xloc = Convert.ToInt32(cmdparams[0]);
130 yloc = Convert.ToInt32(cmdparams[1]);
131 mapName = cmdparams[2];
132 if (cmdparams.Length > 3)
133 for (int i = 3; i < cmdparams.Length; i++)
134 mapName += " " + cmdparams[i];
135
136 m_log.Info(">> MapName: " + mapName);
137 //internalPort = Convert.ToUInt32(cmdparams[4]);
138 //remotingPort = Convert.ToUInt32(cmdparams[5]);
139 }
140 catch (Exception e)
141 {
142 m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
143 LinkRegionCmdUsage();
144 return;
145 }
146
147 // Convert cell coordinates given by the user to meters
148 xloc = xloc * (int)Constants.RegionSize;
149 yloc = yloc * (int)Constants.RegionSize;
150 m_HGGridConnector.TryLinkRegionToCoords(m_scene, null, mapName, xloc, yloc);
151 }
152 else
153 {
154 // old format
155 GridRegion regInfo;
156 int xloc, yloc;
157 uint externalPort;
158 string externalHostName;
159 try
160 {
161 xloc = Convert.ToInt32(cmdparams[0]);
162 yloc = Convert.ToInt32(cmdparams[1]);
163 externalPort = Convert.ToUInt32(cmdparams[3]);
164 externalHostName = cmdparams[2];
165 //internalPort = Convert.ToUInt32(cmdparams[4]);
166 //remotingPort = Convert.ToUInt32(cmdparams[5]);
167 }
168 catch (Exception e)
169 {
170 m_log.Warn("[HGrid] Wrong format for link-region command: " + e.Message);
171 LinkRegionCmdUsage();
172 return;
173 }
174
175 // Convert cell coordinates given by the user to meters
176 xloc = xloc * (int)Constants.RegionSize;
177 yloc = yloc * (int)Constants.RegionSize;
178 if (m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort, externalHostName, out regInfo))
179 {
180 if (cmdparams.Length >= 5)
181 {
182 regInfo.RegionName = "";
183 for (int i = 4; i < cmdparams.Length; i++)
184 regInfo.RegionName += cmdparams[i] + " ";
185 }
186 }
187 }
188 return;
189 }
190 else if (command.Equals("unlinkk-region"))
191 {
192 if (cmdparams.Length < 1)
193 {
194 UnlinkRegionCmdUsage();
195 return;
196 }
197 if (m_HGGridConnector.TryUnlinkRegion(m_scene, cmdparams[0]))
198 m_log.InfoFormat("[HGrid]: Successfully unlinked {0}", cmdparams[0]);
199 else
200 m_log.InfoFormat("[HGrid]: Unable to unlink {0}, region not found", cmdparams[0]);
201 }
202 }
203
204 private void LoadXmlLinkFile(string[] cmdparams)
205 {
206 //use http://www.hgurl.com/hypergrid.xml for test
207 try
208 {
209 XmlReader r = XmlReader.Create(cmdparams[0]);
210 XmlConfigSource cs = new XmlConfigSource(r);
211 string[] excludeSections = null;
212
213 if (cmdparams.Length == 2)
214 {
215 if (cmdparams[1].ToLower().StartsWith("excludelist:"))
216 {
217 string excludeString = cmdparams[1].ToLower();
218 excludeString = excludeString.Remove(0, 12);
219 char[] splitter = { ';' };
220
221 excludeSections = excludeString.Split(splitter);
222 }
223 }
224
225 for (int i = 0; i < cs.Configs.Count; i++)
226 {
227 bool skip = false;
228 if ((excludeSections != null) && (excludeSections.Length > 0))
229 {
230 for (int n = 0; n < excludeSections.Length; n++)
231 {
232 if (excludeSections[n] == cs.Configs[i].Name.ToLower())
233 {
234 skip = true;
235 break;
236 }
237 }
238 }
239 if (!skip)
240 {
241 ReadLinkFromConfig(cs.Configs[i]);
242 }
243 }
244 }
245 catch (Exception e)
246 {
247 m_log.Error(e.ToString());
248 }
249 }
250
251
252 private void ReadLinkFromConfig(IConfig config)
253 {
254 GridRegion regInfo;
255 int xloc, yloc;
256 uint externalPort;
257 string externalHostName;
258 uint realXLoc, realYLoc;
259
260 xloc = Convert.ToInt32(config.GetString("xloc", "0"));
261 yloc = Convert.ToInt32(config.GetString("yloc", "0"));
262 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
263 externalHostName = config.GetString("externalHostName", "");
264 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
265 realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
266
267 if (m_enableAutoMapping)
268 {
269 xloc = (int)((xloc % 100) + m_autoMappingX);
270 yloc = (int)((yloc % 100) + m_autoMappingY);
271 }
272
273 if (((realXLoc == 0) && (realYLoc == 0)) ||
274 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
275 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
276 {
277 xloc = xloc * (int)Constants.RegionSize;
278 yloc = yloc * (int)Constants.RegionSize;
279 if (
280 m_HGGridConnector.TryCreateLink(m_scene, null, xloc, yloc, "", externalPort,
281 externalHostName, out regInfo))
282 {
283 regInfo.RegionName = config.GetString("localName", "");
284 }
285 }
286 }
287
288
289 private void LinkRegionCmdUsage()
290 {
291 m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
292 m_log.Info("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
293 m_log.Info("Usage: link-region <URI_of_xml> [<exclude>]");
294 }
295
296 private void UnlinkRegionCmdUsage()
297 {
298 m_log.Info("Usage: unlink-region <HostName>:<HttpPort>");
299 m_log.Info("Usage: unlink-region <LocalName>");
300 }
301
302 }
303}