31 using System.Reflection;
35 using OpenSim.Framework;
37 namespace OpenSim.ApplicationPlugins.LoadRegions
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 private IConfigSource m_configSource;
47 m_configSource = configSource;
55 if (m_configSource == null)
57 m_log.Error(
"[WEBLOADER]: Unable to load configuration source!");
62 IConfig startupConfig = (IConfig)m_configSource.Configs[
"Startup"];
63 string url = startupConfig.GetString(
"regionload_webserver_url", String.Empty).Trim();
64 bool allowRegionless = startupConfig.GetBoolean(
"allow_regionless",
false);
66 if (url == String.Empty)
68 m_log.Error(
"[WEBLOADER]: Unable to load webserver URL - URL was empty.");
77 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.
Create(url);
78 webRequest.Timeout = 30000;
79 m_log.DebugFormat(
"[WEBLOADER]: Sending download request to {0}", url);
83 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
84 m_log.Debug(
"[WEBLOADER]: Downloading region information...");
85 StreamReader reader =
new StreamReader(webResponse.GetResponseStream());
86 string xmlSource = String.Empty;
87 string tempStr = reader.ReadLine();
88 while (tempStr != null)
90 xmlSource = xmlSource + tempStr;
91 tempStr = reader.ReadLine();
93 m_log.Debug(
"[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
95 XmlDocument xmlDoc =
new XmlDocument();
96 xmlDoc.LoadXml(xmlSource);
97 if (xmlDoc.FirstChild.Name ==
"Nini")
99 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
105 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++)
107 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml);
109 new RegionInfo(
"REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i],
false, m_configSource);
114 catch (WebException ex)
116 if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
118 if (!allowRegionless)
125 if (regionCount > 0 | allowRegionless)
128 m_log.Debug(
"[WEBLOADER]: Request yielded no regions.");
132 m_log.Debug(
"[WEBLOADER]: Retrying");
133 System.Threading.Thread.Sleep(wait);
137 m_log.Error(
"[WEBLOADER]: No region configs were available.");
OpenSim.Framework.RegionInfo RegionInfo
void SetIniConfigSource(IConfigSource configSource)
RegionInfo[] LoadRegions()
static RegionInfo Create(UUID regionID, string regionName, uint regX, uint regY, string externalHostName, uint httpPort, uint simPort, uint remotingPort, string serverURI)