aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService/HGCommands.cs
diff options
context:
space:
mode:
authorDiva Canto2010-01-24 14:30:48 -0800
committerDiva Canto2010-01-24 14:30:48 -0800
commit48b03c2c61a422c3ac9843892a2ae93b29a9f7b8 (patch)
treece3aae8c5bb0ee0c1748e4355cd616ea84b5b344 /OpenSim/Services/HypergridService/HGCommands.cs
parentChange a member of the friendslist module to better reflect the client side (diff)
downloadopensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.zip
opensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.tar.gz
opensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.tar.bz2
opensim-SC_OLD-48b03c2c61a422c3ac9843892a2ae93b29a9f7b8.tar.xz
Integrated the hyperlinking with the GridService.
Diffstat (limited to 'OpenSim/Services/HypergridService/HGCommands.cs')
-rw-r--r--OpenSim/Services/HypergridService/HGCommands.cs318
1 files changed, 0 insertions, 318 deletions
diff --git a/OpenSim/Services/HypergridService/HGCommands.cs b/OpenSim/Services/HypergridService/HGCommands.cs
deleted file mode 100644
index 78ba46d..0000000
--- a/OpenSim/Services/HypergridService/HGCommands.cs
+++ /dev/null
@@ -1,318 +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
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.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39
40namespace OpenSim.Services.HypergridService
41{
42 public class HGCommands
43 {
44 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 private HypergridService m_HypergridService;
46
47 private static uint m_autoMappingX = 0;
48 private static uint m_autoMappingY = 0;
49 private static bool m_enableAutoMapping = false;
50
51 public HGCommands(HypergridService service)
52 {
53 m_HypergridService = service;
54 }
55
56 public void HandleShow(string module, string[] cmd)
57 {
58 if (cmd.Length != 2)
59 {
60 MainConsole.Instance.Output("Syntax: show hyperlinks");
61 return;
62 }
63 List<GridRegion> regions = new List<GridRegion>(m_HypergridService.m_HyperlinkRegions.Values);
64 if (regions == null || regions.Count < 1)
65 {
66 MainConsole.Instance.Output("No hyperlinks");
67 return;
68 }
69
70 MainConsole.Instance.Output("Region Name Region UUID");
71 MainConsole.Instance.Output("Location URI");
72 MainConsole.Instance.Output("Owner ID ");
73 MainConsole.Instance.Output("-------------------------------------------------------------------------------");
74 foreach (GridRegion r in regions)
75 {
76 MainConsole.Instance.Output(String.Format("{0,-20} {1}\n{2,-20} {3}\n{4,-39} \n\n",
77 r.RegionName, r.RegionID,
78 String.Format("{0},{1}", r.RegionLocX, r.RegionLocY), "http://" + r.ExternalHostName + ":" + r.HttpPort.ToString(),
79 r.EstateOwner.ToString()));
80 }
81 return;
82 }
83 public void RunCommand(string module, string[] cmdparams)
84 {
85 List<string> args = new List<string>(cmdparams);
86 if (args.Count < 1)
87 return;
88
89 string command = args[0];
90 args.RemoveAt(0);
91
92 cmdparams = args.ToArray();
93
94 RunHGCommand(command, cmdparams);
95
96 }
97
98 private void RunHGCommand(string command, string[] cmdparams)
99 {
100 if (command.Equals("link-mapping"))
101 {
102 if (cmdparams.Length == 2)
103 {
104 try
105 {
106 m_autoMappingX = Convert.ToUInt32(cmdparams[0]);
107 m_autoMappingY = Convert.ToUInt32(cmdparams[1]);
108 m_enableAutoMapping = true;
109 }
110 catch (Exception)
111 {
112 m_autoMappingX = 0;
113 m_autoMappingY = 0;
114 m_enableAutoMapping = false;
115 }
116 }
117 }
118 else if (command.Equals("link-region"))
119 {
120 if (cmdparams.Length < 3)
121 {
122 if ((cmdparams.Length == 1) || (cmdparams.Length == 2))
123 {
124 LoadXmlLinkFile(cmdparams);
125 }
126 else
127 {
128 LinkRegionCmdUsage();
129 }
130 return;
131 }
132
133 if (cmdparams[2].Contains(":"))
134 {
135 // New format
136 int xloc, yloc;
137 string mapName;
138 try
139 {
140 xloc = Convert.ToInt32(cmdparams[0]);
141 yloc = Convert.ToInt32(cmdparams[1]);
142 mapName = cmdparams[2];
143 if (cmdparams.Length > 3)
144 for (int i = 3; i < cmdparams.Length; i++)
145 mapName += " " + cmdparams[i];
146
147 //m_log.Info(">> MapName: " + mapName);
148 }
149 catch (Exception e)
150 {
151 MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
152 LinkRegionCmdUsage();
153 return;
154 }
155
156 // Convert cell coordinates given by the user to meters
157 xloc = xloc * (int)Constants.RegionSize;
158 yloc = yloc * (int)Constants.RegionSize;
159 string reason = string.Empty;
160 if (m_HypergridService.TryLinkRegionToCoords(mapName, xloc, yloc, out reason) == null)
161 MainConsole.Instance.Output("Failed to link region: " + reason);
162 MainConsole.Instance.Output("Hyperlink estalished");
163 }
164 else
165 {
166 // old format
167 GridRegion regInfo;
168 int xloc, yloc;
169 uint externalPort;
170 string externalHostName;
171 try
172 {
173 xloc = Convert.ToInt32(cmdparams[0]);
174 yloc = Convert.ToInt32(cmdparams[1]);
175 externalPort = Convert.ToUInt32(cmdparams[3]);
176 externalHostName = cmdparams[2];
177 //internalPort = Convert.ToUInt32(cmdparams[4]);
178 //remotingPort = Convert.ToUInt32(cmdparams[5]);
179 }
180 catch (Exception e)
181 {
182 MainConsole.Instance.Output("[HGrid] Wrong format for link-region command: " + e.Message);
183 LinkRegionCmdUsage();
184 return;
185 }
186
187 // Convert cell coordinates given by the user to meters
188 xloc = xloc * (int)Constants.RegionSize;
189 yloc = yloc * (int)Constants.RegionSize;
190 string reason = string.Empty;
191 if (m_HypergridService.TryCreateLink(xloc, yloc, "", externalPort, externalHostName, out regInfo, out reason))
192 {
193 if (cmdparams.Length >= 5)
194 {
195 regInfo.RegionName = "";
196 for (int i = 4; i < cmdparams.Length; i++)
197 regInfo.RegionName += cmdparams[i] + " ";
198 }
199 }
200 }
201 return;
202 }
203 else if (command.Equals("unlink-region"))
204 {
205 if (cmdparams.Length < 1)
206 {
207 UnlinkRegionCmdUsage();
208 return;
209 }
210 if (m_HypergridService.TryUnlinkRegion(cmdparams[0]))
211 MainConsole.Instance.Output("Successfully unlinked " + cmdparams[0]);
212 else
213 MainConsole.Instance.Output("Unable to unlink " + cmdparams[0] + ", region not found.");
214 }
215 }
216
217 private void LoadXmlLinkFile(string[] cmdparams)
218 {
219 //use http://www.hgurl.com/hypergrid.xml for test
220 try
221 {
222 XmlReader r = XmlReader.Create(cmdparams[0]);
223 XmlConfigSource cs = new XmlConfigSource(r);
224 string[] excludeSections = null;
225
226 if (cmdparams.Length == 2)
227 {
228 if (cmdparams[1].ToLower().StartsWith("excludelist:"))
229 {
230 string excludeString = cmdparams[1].ToLower();
231 excludeString = excludeString.Remove(0, 12);
232 char[] splitter = { ';' };
233
234 excludeSections = excludeString.Split(splitter);
235 }
236 }
237
238 for (int i = 0; i < cs.Configs.Count; i++)
239 {
240 bool skip = false;
241 if ((excludeSections != null) && (excludeSections.Length > 0))
242 {
243 for (int n = 0; n < excludeSections.Length; n++)
244 {
245 if (excludeSections[n] == cs.Configs[i].Name.ToLower())
246 {
247 skip = true;
248 break;
249 }
250 }
251 }
252 if (!skip)
253 {
254 ReadLinkFromConfig(cs.Configs[i]);
255 }
256 }
257 }
258 catch (Exception e)
259 {
260 m_log.Error(e.ToString());
261 }
262 }
263
264
265 private void ReadLinkFromConfig(IConfig config)
266 {
267 GridRegion regInfo;
268 int xloc, yloc;
269 uint externalPort;
270 string externalHostName;
271 uint realXLoc, realYLoc;
272
273 xloc = Convert.ToInt32(config.GetString("xloc", "0"));
274 yloc = Convert.ToInt32(config.GetString("yloc", "0"));
275 externalPort = Convert.ToUInt32(config.GetString("externalPort", "0"));
276 externalHostName = config.GetString("externalHostName", "");
277 realXLoc = Convert.ToUInt32(config.GetString("real-xloc", "0"));
278 realYLoc = Convert.ToUInt32(config.GetString("real-yloc", "0"));
279
280 if (m_enableAutoMapping)
281 {
282 xloc = (int)((xloc % 100) + m_autoMappingX);
283 yloc = (int)((yloc % 100) + m_autoMappingY);
284 }
285
286 if (((realXLoc == 0) && (realYLoc == 0)) ||
287 (((realXLoc - xloc < 3896) || (xloc - realXLoc < 3896)) &&
288 ((realYLoc - yloc < 3896) || (yloc - realYLoc < 3896))))
289 {
290 xloc = xloc * (int)Constants.RegionSize;
291 yloc = yloc * (int)Constants.RegionSize;
292 string reason = string.Empty;
293 if (m_HypergridService.TryCreateLink(xloc, yloc, "", externalPort,
294 externalHostName, out regInfo, out reason))
295 {
296 regInfo.RegionName = config.GetString("localName", "");
297 }
298 else
299 MainConsole.Instance.Output("Unable to link " + externalHostName + ": " + reason);
300 }
301 }
302
303
304 private void LinkRegionCmdUsage()
305 {
306 MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName>:<HttpPort>[:<RemoteRegionName>]");
307 MainConsole.Instance.Output("Usage: link-region <Xloc> <Yloc> <HostName> <HttpPort> [<LocalName>]");
308 MainConsole.Instance.Output("Usage: link-region <URI_of_xml> [<exclude>]");
309 }
310
311 private void UnlinkRegionCmdUsage()
312 {
313 MainConsole.Instance.Output("Usage: unlink-region <HostName>:<HttpPort>");
314 MainConsole.Instance.Output("Usage: unlink-region <LocalName>");
315 }
316
317 }
318}