MS now writes to servers.cfg directly and progress bar is fixed
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7638 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
@@ -1266,7 +1266,7 @@ void clearservers()
|
||||
servers.deletecontents();
|
||||
}
|
||||
|
||||
#define RETRIEVELIMIT 20000
|
||||
#define RETRIEVELIMIT 5000
|
||||
extern char *global_name;
|
||||
bool cllock = false, clfail = false;
|
||||
|
||||
@@ -1294,11 +1294,61 @@ static size_t write_callback(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
return fwrite(ptr, size, nmemb, stream);
|
||||
}
|
||||
|
||||
int mastertype = 1; //0: UDP, 1: TCP
|
||||
void retrieveservers(vector<char> &data)
|
||||
{
|
||||
if (mastertype==0) {
|
||||
conoutf("Contacting masterserver %s using UDP.", mastername);
|
||||
if(mastertype == AC_MASTER_HTTP)
|
||||
{
|
||||
string request;
|
||||
sprintf(request, "http://%s/retrieve.do?action=list&name=%s&version=%d&build=%d", mastername, global_name, AC_VERSION, getbuildtype()|(1<<16));
|
||||
|
||||
const char *tmpname = findfile(path("config/servers.cfg", true), "wb");
|
||||
FILE *outfile = fopen(tmpname, "w+");
|
||||
if(!outfile)
|
||||
{
|
||||
conoutf("\f3cannot write server list");
|
||||
return;
|
||||
}
|
||||
|
||||
resolver_data *rd = new resolver_data();
|
||||
formatstring(rd->text)("retrieving servers from %s:%d... (esc to abort)", mastername, masterport);
|
||||
show_out_of_renderloop_progress(0, rd->text);
|
||||
|
||||
rd->starttime = SDL_GetTicks();
|
||||
rd->timeout = 0;
|
||||
|
||||
CURL *curl = curl_easy_init();
|
||||
int result = 0, httpresult = 0;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, request);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, rd);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, RETRIEVELIMIT/1000);
|
||||
result = curl_easy_perform(curl);
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpresult);
|
||||
curl_easy_cleanup(curl);
|
||||
curl = NULL;
|
||||
if(outfile) fclose(outfile);
|
||||
|
||||
if(result == CURLE_OPERATION_TIMEDOUT || result == CURLE_COULDNT_RESOLVE_HOST)
|
||||
{
|
||||
clfail = true;
|
||||
}
|
||||
|
||||
if(!result && httpresult == 200)
|
||||
{
|
||||
int size = 0;
|
||||
char *content = loadfile(path("config/servers.cfg", true), &size);
|
||||
data.shrink(0);
|
||||
data.insert(0, content, size);
|
||||
if(data.length()) data.add('\0');
|
||||
}
|
||||
DELETEP(rd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ENetSocket sock = connectmaster();
|
||||
if(sock == ENET_SOCKET_NULL)
|
||||
{
|
||||
@@ -1307,10 +1357,8 @@ void retrieveservers(vector<char> &data)
|
||||
return;
|
||||
}
|
||||
clfail = false;
|
||||
|
||||
defformatstring(text)("retrieving servers from %s:%d... (esc to abort)", mastername, masterport);
|
||||
show_out_of_renderloop_progress(0, text);
|
||||
|
||||
int starttime = SDL_GetTicks(), timeout = 0;
|
||||
string request;
|
||||
sprintf(request, "list %s %d %d\n",global_name,AC_VERSION,getbuildtype());
|
||||
@@ -1335,7 +1383,6 @@ void retrieveservers(vector<char> &data)
|
||||
if(interceptkey(SDLK_ESCAPE)) timeout = RETRIEVELIMIT + 1;
|
||||
if(timeout > RETRIEVELIMIT) break;
|
||||
}
|
||||
|
||||
if(reqlen <= 0) for(;;)
|
||||
{
|
||||
enet_uint32 events = ENET_SOCKET_WAIT_RECEIVE;
|
||||
@@ -1353,59 +1400,8 @@ void retrieveservers(vector<char> &data)
|
||||
if(interceptkey(SDLK_ESCAPE)) timeout = RETRIEVELIMIT + 1;
|
||||
if(timeout > RETRIEVELIMIT) break;
|
||||
}
|
||||
|
||||
if(data.length()) data.add('\0');
|
||||
enet_socket_destroy(sock);
|
||||
}
|
||||
else if(mastertype==1) {
|
||||
conoutf("Contacting masterserver %s using HTTP.", mastername);
|
||||
string request;
|
||||
sprintf(request, "http://%s/retrieve.do?action=list&name=%s&version=%d&build=%d",mastername, global_name, AC_VERSION, getbuildtype());
|
||||
|
||||
const char *tmpname = findfile(path("config/servers_tmp.cfg", true), "wb");
|
||||
FILE *outfile = fopen(tmpname, "w+");
|
||||
if(!outfile)
|
||||
{
|
||||
conoutf("\f3cannot write server list");
|
||||
return;
|
||||
}
|
||||
|
||||
resolver_data *rd = new resolver_data();
|
||||
formatstring(rd->text)("retrieving servers from %s:%d... (esc to abort)", mastername, masterport);
|
||||
show_out_of_renderloop_progress(0, rd->text);
|
||||
|
||||
rd->starttime = SDL_GetTicks();
|
||||
rd->timeout = 0;
|
||||
|
||||
CURL *curl = curl_easy_init();
|
||||
int result = 0, httpresult = 0;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, request);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, rd);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
|
||||
result = curl_easy_perform(curl);
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpresult);
|
||||
curl_easy_cleanup(curl);
|
||||
curl = NULL;
|
||||
if(outfile) fclose(outfile);
|
||||
|
||||
if(result == CURLE_OPERATION_TIMEDOUT || result == CURLE_COULDNT_RESOLVE_HOST)
|
||||
{
|
||||
clfail = true;
|
||||
}
|
||||
|
||||
if(!result && httpresult == 200)
|
||||
{
|
||||
int size = 0;
|
||||
char *content = loadfile(path("config/servers_tmp.cfg", true), &size);
|
||||
data.shrink(0);
|
||||
data.insert(0, content, size);
|
||||
if(data.length()) data.add('\0');
|
||||
}
|
||||
DELETEP(rd);
|
||||
enet_socket_destroy(sock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user