Select default TerraSync server automatically.

This commit is contained in:
James Turner 2015-04-11 23:50:33 +01:00
parent 2c6f9de020
commit 6683092bb2

View 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 ///////////////////////////////////////////////////// // SGTerraSync::SvnThread /////////////////////////////////////////////////////
@ -363,14 +400,7 @@ bool SGTerraSync::SvnThread::start()
_use_svn |= _use_built_in; _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=="")) if ((!_use_svn)&&(_rsync_server==""))
{ {
SG_LOG(SG_TERRAIN,SG_ALERT, SG_LOG(SG_TERRAIN,SG_ALERT,
@ -473,6 +503,28 @@ void SGTerraSync::SvnThread::run()
_active = true; _active = true;
initCompletedTilesPersistentCache(); 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) { if (_use_built_in) {
runInternal(); runInternal();
} else { } else {