]> git.mxchange.org Git - simgear.git/commitdiff
Select default TerraSync server automatically.
authorJames Turner <zakalawe@mac.com>
Sat, 11 Apr 2015 22:50:33 +0000 (23:50 +0100)
committerJames Turner <zakalawe@mac.com>
Sat, 11 Apr 2015 22:50:33 +0000 (23:50 +0100)
simgear/scene/tsync/terrasync.cxx

index 425231532503fb750c1c8c085f87adae04356ac1..7ebb3f341f697a97d9b2670224e86c66a6a12009 100644 (file)
@@ -199,6 +199,43 @@ static unsigned int syncSlotForType(SyncItem::Type ty)
     }
 }
 
+///////////////////////////////////////////////////////////////////////////////
+// Base server query
+///////////////////////////////////////////////////////////////////////////////
+
+class ServerSelectQuery : public HTTP::Request
+{
+public:
+    ServerSelectQuery() :
+        HTTP::Request("http://scenery.flightgear.org/svn-server", "GET")
+    {
+    }
+
+    std::string svnUrl() const
+    {
+        std::string s = simgear::strutils::strip(m_url);
+        if (s.at(s.length() - 1) == '/') {
+            s = s.substr(0, s.length() - 1);
+        }
+
+        return s;
+    }
+protected:
+    virtual void gotBodyData(const char* s, int n)
+    {
+        m_url.append(std::string(s, n));
+    }
+
+    virtual void onFail()
+    {
+        SG_LOG(SG_TERRAIN, SG_ALERT, "Failed to query TerraSync SVN server");
+        HTTP::Request::onFail();
+    }
+
+private:
+    std::string m_url;
+};
+
 
 ///////////////////////////////////////////////////////////////////////////////
 // SGTerraSync::SvnThread /////////////////////////////////////////////////////
@@ -363,14 +400,7 @@ bool SGTerraSync::SvnThread::start()
 
     _use_svn |= _use_built_in;
 
-    if ((_use_svn)&&(_svn_server==""))
-    {
-        SG_LOG(SG_TERRAIN,SG_ALERT,
-               "Cannot start scenery download. Subversion scenery server is undefined.");
-        _fail_count++;
-        _stalled = true;
-        return false;
-    }
+
     if ((!_use_svn)&&(_rsync_server==""))
     {
         SG_LOG(SG_TERRAIN,SG_ALERT,
@@ -473,6 +503,28 @@ void SGTerraSync::SvnThread::run()
     _active = true;
     initCompletedTilesPersistentCache();
 
+    {
+        if (_svn_server.empty()) {
+            SG_LOG(SG_TERRAIN,SG_INFO, "Querying closest TerraSync server");
+            ServerSelectQuery* ssq = new ServerSelectQuery;
+            HTTP::Request_ptr req = ssq;
+            _http.makeRequest(req);
+            while (!req->isComplete()) {
+                _http.update(20);
+            }
+
+            _svn_server = ssq->svnUrl();
+            SG_LOG(SG_TERRAIN,SG_INFO, "Closest TerraSync server:" << _svn_server);
+        } else {
+            SG_LOG(SG_TERRAIN,SG_INFO, "Explicit: TerraSync server:" << _svn_server);
+        }
+
+        if (_svn_server.empty()) {
+            // default value
+            _svn_server = "http://foxtrot.mgras.net:8080/terrascenery/trunk/data/Scenery";
+        }
+    }
+
     if (_use_built_in) {
         runInternal();
     } else {