aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/RegionLoader
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/RegionLoader/Filesystem/Properties/AssemblyInfo.cs33
-rw-r--r--OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs116
-rw-r--r--OpenSim/Framework/RegionLoader/Web/Properties/AssemblyInfo.cs33
-rw-r--r--OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs147
4 files changed, 329 insertions, 0 deletions
diff --git a/OpenSim/Framework/RegionLoader/Filesystem/Properties/AssemblyInfo.cs b/OpenSim/Framework/RegionLoader/Filesystem/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..3bcbe2f
--- /dev/null
+++ b/OpenSim/Framework/RegionLoader/Filesystem/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenSim.Framework.RegionLoader.Filesystem")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("http://opensimulator.org")]
12[assembly: AssemblyProduct("OpenSim")]
13[assembly: AssemblyCopyright("OpenSimulator developers")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("4ab5c74b-e886-40a1-b67d-a04df285e706")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32[assembly: AssemblyVersion("0.8.2.*")]
33
diff --git a/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs b/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs
new file mode 100644
index 0000000..8332c14
--- /dev/null
+++ b/OpenSim/Framework/RegionLoader/Filesystem/RegionLoaderFileSystem.cs
@@ -0,0 +1,116 @@
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 log4net;
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using Nini.Config;
34
35namespace OpenSim.Framework.RegionLoader.Filesystem
36{
37 public class RegionLoaderFileSystem : IRegionLoader
38 {
39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
41 private IConfigSource m_configSource;
42
43 public void SetIniConfigSource(IConfigSource configSource)
44 {
45 m_configSource = configSource;
46 }
47
48 public RegionInfo[] LoadRegions()
49 {
50 string regionConfigPath = Path.Combine(Util.configDir(), "Regions");
51 bool allowRegionless = false;
52
53 try
54 {
55 IConfig startupConfig = (IConfig)m_configSource.Configs["Startup"];
56 regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
57 allowRegionless = startupConfig.GetBoolean("allow_regionless", false);
58 }
59 catch (Exception)
60 {
61 // No INI setting recorded.
62 }
63
64 if (!Directory.Exists(regionConfigPath))
65 {
66 Directory.CreateDirectory(regionConfigPath);
67 }
68
69 string[] configFiles = Directory.GetFiles(regionConfigPath, "*.xml");
70 string[] iniFiles = Directory.GetFiles(regionConfigPath, "*.ini");
71
72 // Create an empty Regions.ini if there are no existing config files.
73 if (!allowRegionless && configFiles.Length == 0 && iniFiles.Length == 0)
74 {
75 new RegionInfo("DEFAULT REGION CONFIG", Path.Combine(regionConfigPath, "Regions.ini"), false, m_configSource);
76 iniFiles = Directory.GetFiles(regionConfigPath, "*.ini");
77 }
78
79 m_log.InfoFormat("[REGION LOADER FILE SYSTEM]: Loading config files from {0}", regionConfigPath);
80
81 List<RegionInfo> regionInfos = new List<RegionInfo>();
82
83 int i = 0;
84 foreach (string file in iniFiles)
85 {
86 m_log.InfoFormat("[REGION LOADER FILE SYSTEM]: Loading config file {0}", file);
87
88 IConfigSource source = new IniConfigSource(file);
89
90 foreach (IConfig config in source.Configs)
91 {
92 RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), file, false, m_configSource, config.Name);
93 regionInfos.Add(regionInfo);
94
95 m_log.InfoFormat("[REGION LOADER FILE SYSTEM]: Loaded config for region {0}", regionInfo.RegionName);
96
97 i++;
98 }
99 }
100
101 foreach (string file in configFiles)
102 {
103 m_log.InfoFormat("[REGION LOADER FILE SYSTEM]: Loading config file {0}", file);
104
105 RegionInfo regionInfo = new RegionInfo("REGION CONFIG #" + (i + 1), file, false, m_configSource);
106 regionInfos.Add(regionInfo);
107
108 m_log.InfoFormat("[REGION LOADER FILE SYSTEM]: Loaded config for region {0}", regionInfo.RegionName);
109
110 i++;
111 }
112
113 return regionInfos.ToArray();
114 }
115 }
116} \ No newline at end of file
diff --git a/OpenSim/Framework/RegionLoader/Web/Properties/AssemblyInfo.cs b/OpenSim/Framework/RegionLoader/Web/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..1b2519c
--- /dev/null
+++ b/OpenSim/Framework/RegionLoader/Web/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenSim.Framework.RegionLoader.Web")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("http://opensimulator.org")]
12[assembly: AssemblyProduct("OpenSim")]
13[assembly: AssemblyCopyright("OpenSimulator developers")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("985afff8-e7ed-4056-acce-39abf7a43d33")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32[assembly: AssemblyVersion("0.8.2.*")]
33
diff --git a/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs b/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
new file mode 100644
index 0000000..f60bb12
--- /dev/null
+++ b/OpenSim/Framework/RegionLoader/Web/RegionLoaderWebServer.cs
@@ -0,0 +1,147 @@
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.IO;
30using System.Net;
31using System.Reflection;
32using System.Xml;
33using log4net;
34using Nini.Config;
35
36namespace OpenSim.Framework.RegionLoader.Web
37{
38 public class RegionLoaderWebServer : IRegionLoader
39 {
40 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41
42 private IConfigSource m_configSource;
43
44 public void SetIniConfigSource(IConfigSource configSource)
45 {
46 m_configSource = configSource;
47 }
48
49 public RegionInfo[] LoadRegions()
50 {
51 if (m_configSource == null)
52 {
53 m_log.Error("[WEBLOADER]: Unable to load configuration source!");
54 return null;
55 }
56 else
57 {
58 IConfig startupConfig = (IConfig) m_configSource.Configs["Startup"];
59 string url = startupConfig.GetString("regionload_webserver_url", String.Empty).Trim();
60 bool allowRegionless = startupConfig.GetBoolean("allow_regionless", false);
61
62 if (url == String.Empty)
63 {
64 m_log.Error("[WEBLOADER]: Unable to load webserver URL - URL was empty.");
65 return null;
66 }
67 else
68 {
69 RegionInfo[] regionInfos = new RegionInfo[] {};
70 int regionCount = 0;
71 HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url);
72 webRequest.Timeout = 30000; //30 Second Timeout
73 m_log.DebugFormat("[WEBLOADER]: Sending download request to {0}", url);
74
75 try
76 {
77 string xmlSource = String.Empty;
78
79 using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse())
80 {
81 m_log.Debug("[WEBLOADER]: Downloading region information...");
82
83 using (Stream s = webResponse.GetResponseStream())
84 {
85 using (StreamReader reader = new StreamReader(s))
86 {
87 string tempStr = reader.ReadLine();
88 while (tempStr != null)
89 {
90 xmlSource = xmlSource + tempStr;
91 tempStr = reader.ReadLine();
92 }
93 }
94 }
95 }
96
97 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
98 xmlSource.Length);
99 XmlDocument xmlDoc = new XmlDocument();
100 xmlDoc.LoadXml(xmlSource);
101 if (xmlDoc.FirstChild.Name == "Nini")
102 {
103 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
104
105 if (regionCount > 0)
106 {
107 regionInfos = new RegionInfo[regionCount];
108 int i;
109 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++)
110 {
111 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml);
112 regionInfos[i] =
113 new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i],false,m_configSource);
114 }
115 }
116 }
117 }
118 catch (WebException ex)
119 {
120 using (HttpWebResponse response = (HttpWebResponse)ex.Response)
121 {
122 if (response.StatusCode == HttpStatusCode.NotFound)
123 {
124 if (!allowRegionless)
125 throw ex;
126 }
127 else
128 {
129 throw ex;
130 }
131 }
132 }
133
134 if (regionCount > 0 | allowRegionless)
135 {
136 return regionInfos;
137 }
138 else
139 {
140 m_log.Error("[WEBLOADER]: No region configs were available.");
141 return null;
142 }
143 }
144 }
145 }
146 }
147}