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.cs106
1 files changed, 51 insertions, 55 deletions
diff --git a/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs b/OpenSim/ApplicationPlugins/LoadRegions/RegionLoaderWebServer.cs
index 850f3e0..2b91fc5 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,75 @@ 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.XmlResolver = null;
100 XmlDocument xmlDoc = new XmlDocument(); 97 xmlDoc.LoadXml(xmlSource);
101 xmlDoc.LoadXml(xmlSource); 98 if (xmlDoc.FirstChild.Name == "Nini")
102 if (xmlDoc.FirstChild.Name == "Nini")
103 {
104 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
105
106 if (regionCount > 0)
107 { 99 {
108 regionInfos = new RegionInfo[regionCount]; 100 regionCount = xmlDoc.FirstChild.ChildNodes.Count;
109 int i; 101
110 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++) 102 if (regionCount > 0)
111 { 103 {
112 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml); 104 regionInfos = new RegionInfo[regionCount];
113 regionInfos[i] = 105 int i;
114 new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i],false,m_configSource); 106 for (i = 0; i < xmlDoc.FirstChild.ChildNodes.Count; i++)
107 {
108 m_log.Debug(xmlDoc.FirstChild.ChildNodes[i].OuterXml);
109 regionInfos[i] =
110 new RegionInfo("REGION CONFIG #" + (i + 1), xmlDoc.FirstChild.ChildNodes[i], false, m_configSource);
111 }
115 } 112 }
116 } 113 }
117 } 114 }
118 } 115 catch (WebException ex)
119 catch (WebException ex)
120 {
121 using (HttpWebResponse response = (HttpWebResponse)ex.Response)
122 { 116 {
123 if (response.StatusCode == HttpStatusCode.NotFound) 117 if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
124 { 118 {
125 if (!allowRegionless) 119 if (!allowRegionless)
126 throw ex; 120 throw ex;
127 } 121 }
128 else 122 else
129 {
130 throw ex; 123 throw ex;
131 }
132 } 124 }
133 }
134 125
135 if (regionCount > 0 | allowRegionless) 126 if (regionCount > 0 | allowRegionless)
136 { 127 return regionInfos;
137 return regionInfos; 128
138 } 129 m_log.Debug("[WEBLOADER]: Request yielded no regions.");
139 else 130 tries--;
140 { 131 if (tries > 0)
141 m_log.Error("[WEBLOADER]: No region configs were available."); 132 {
142 return null; 133 m_log.Debug("[WEBLOADER]: Retrying");
134 System.Threading.Thread.Sleep(wait);
135 }
143 } 136 }
137
138 m_log.Error("[WEBLOADER]: No region configs were available.");
139 return null;
144 } 140 }
145 } 141 }
146 } 142 }
147 } 143 }
148} 144} \ No newline at end of file