aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs')
-rw-r--r--OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs105
1 files changed, 50 insertions, 55 deletions
diff --git a/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs b/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs
index 850f3e0..13d7a8a 100644
--- a/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs
+++ b/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs
@@ -49,6 +49,9 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
49 49
50 public RegionInfo[] LoadRegions() 50 public RegionInfo[] LoadRegions()
51 { 51 {
52 int tries = 3;
53 int wait = 2000;
54
52 if (m_configSource == null) 55 if (m_configSource == null)
53 { 56 {
54 m_log.Error("[WEBLOADER]: Unable to load configuration source!"); 57 m_log.Error("[WEBLOADER]: Unable to load configuration source!");
@@ -56,7 +59,7 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
56 } 59 }
57 else 60 else
58 { 61 {
59 IConfig startupConfig = (IConfig) m_configSource.Configs["Startup"]; 62 IConfig startupConfig = (IConfig)m_configSource.Configs["Startup"];
60 string url = startupConfig.GetString("regionload_webserver_url", String.Empty).Trim(); 63 string url = startupConfig.GetString("regionload_webserver_url", String.Empty).Trim();
61 bool allowRegionless = startupConfig.GetBoolean("allow_regionless", false); 64 bool allowRegionless = startupConfig.GetBoolean("allow_regionless", false);
62 65
@@ -67,82 +70,74 @@ namespace OpenSim.ApplicationPlugins.LoadRegions
67 } 70 }
68 else 71 else
69 { 72 {
70 RegionInfo[] regionInfos = new RegionInfo[] {}; 73 while (tries > 0)
71 int regionCount = 0;
72 HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url);
73 webRequest.Timeout = 30000; //30 Second Timeout
74 m_log.DebugFormat("[WEBLOADER]: Sending download request to {0}", url);
75
76 try
77 { 74 {
78 string xmlSource = String.Empty; 75 RegionInfo[] regionInfos = new RegionInfo[] { };
76 int regionCount = 0;
77 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
78 webRequest.Timeout = 30000; //30 Second Timeout
79 m_log.DebugFormat("[WEBLOADER]: Sending download request to {0}", url);
79 80
80 using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse()) 81 try
81 { 82 {
83 HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
82 m_log.Debug("[WEBLOADER]: Downloading region information..."); 84 m_log.Debug("[WEBLOADER]: Downloading region information...");
83 85 StreamReader reader = new StreamReader(webResponse.GetResponseStream());
84 using (Stream s = webResponse.GetResponseStream()) 86 string xmlSource = String.Empty;
87 string tempStr = reader.ReadLine();
88 while (tempStr != null)
85 { 89 {
86 using (StreamReader reader = new StreamReader(s)) 90 xmlSource = xmlSource + tempStr;
87 { 91 tempStr = reader.ReadLine();
88 string tempStr = reader.ReadLine();
89 while (tempStr != null)
90 {
91 xmlSource = xmlSource + tempStr;
92 tempStr = reader.ReadLine();
93 }
94 }
95 } 92 }
96 } 93 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " +
97 94 xmlSource.Length);
98 m_log.Debug("[WEBLOADER]: Done downloading region information from server. Total Bytes: " + 95 XmlDocument xmlDoc = new XmlDocument();
99 xmlSource.Length); 96 xmlDoc.LoadXml(xmlSource);
100 XmlDocument xmlDoc = new XmlDocument(); 97 if (xmlDoc.FirstChild.Name == "Nini")
101 xmlDoc.LoadXml(xmlSource);
102 if (xmlDoc.FirstChild.Name == "Nini")
103 {
104 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
105
106 if (regionCount > 0)
107 { 98 {
108 regionInfos = new RegionInfo[regionCount]; 99 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
109 int i; 100
110 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++) 101 if (regionCount > 0)
111 { 102 {
112 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml); 103 regionInfos = new RegionInfo[regionCount];
113 regionInfos[i] = 104 int i;
114 new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i],false,m_configSource); 105 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++)
106 {
107 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml);
108 regionInfos[i] =
109 new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i], false, m_configSource);
110 }
115 } 111 }
116 } 112 }
117 } 113 }
118 } 114 catch (WebException ex)
119 catch (WebException ex)
120 {
121 using (HttpWebResponse response = (HttpWebResponse)ex.Response)
122 { 115 {
123 if (response.StatusCode == HttpStatusCode.NotFound) 116 if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
124 { 117 {
125 if (!allowRegionless) 118 if (!allowRegionless)
126 throw ex; 119 throw ex;
127 } 120 }
128 else 121 else
129 {
130 throw ex; 122 throw ex;
131 }
132 } 123 }
133 }
134 124
135 if (regionCount > 0 | allowRegionless) 125 if (regionCount > 0 | allowRegionless)
136 { 126 return regionInfos;
137 return regionInfos; 127
138 } 128 m_log.Debug("[WEBLOADER]: Request yielded no regions.");
139 else 129 tries--;
140 { 130 if (tries > 0)
141 m_log.Error("[WEBLOADER]: No region configs were available."); 131 {
142 return null; 132 m_log.Debug("[WEBLOADER]: Retrying");
133 System.Threading.Thread.Sleep(wait);
134 }
143 } 135 }
136
137 m_log.Error("[WEBLOADER]: No region configs were available.");
138 return null;
144 } 139 }
145 } 140 }
146 } 141 }
147 } 142 }
148} 143} \ No newline at end of file