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