| 1314 | VARP(mastertype, 0, 0, 1); // 0: TCP direct, 1: HTTP proxy |
| 1315 | |
| 1316 | void retrieveservers(vector<char> &data) |
| 1317 | { |
| 1318 | if(mastertype) |
| 1319 | { |
| 1320 | httpget h; |
| 1321 | defformatstring(progresstext)("resolving %s", mastername); |
| 1322 | h.callbackfunc = progress_callback_retrieveservers; |
| 1323 | h.callbackdata = progresstext; |
| 1324 | show_out_of_renderloop_progress(0.01f, progresstext); |
| 1325 | if(h.set_host(mastername)) |
| 1326 | { |
| 1327 | formatstring(progresstext)("retrieving servers from %s:%d... (esc to abort)", mastername, masterport); |
| 1328 | defformatstring(url)("/retrieve.do?action=list&name=%s&version=%d&build=%d", urlencode(player1->name, true), AC_VERSION, getbuildtype()|(1<<16)); |
| 1329 | h.outvec = (vector<uchar> *) &data; // ouch... |
| 1330 | show_out_of_renderloop_progress(0, progresstext); |
| 1331 | int got = h.get(url, RETRIEVELIMIT, RETRIEVELIMIT); |
| 1332 | if(got < 0 || h.response != 200) data.setsize(0); |
| 1333 | h.outvec = NULL; // must not be cleaned up by httpget |
| 1334 | if(data.length()) data.add('\0'); |
| 1335 | } |
| 1336 | else |
| 1337 | { |
| 1338 | conoutf("failed to resolve host %s", mastername); |
| 1339 | } |
| 1340 | } |
| 1341 | else |
| 1342 | { |
| 1343 | ENetSocket sock = connectmaster(); |
| 1344 | if(sock == ENET_SOCKET_NULL) |
| 1345 | { |
| 1346 | conoutf("Master server is not replying."); |
| 1347 | return; |
| 1348 | } |
| 1349 | defformatstring(text)("retrieving servers from %s:%d... (esc to abort)", mastername, masterport); |
| 1350 | show_out_of_renderloop_progress(0, text); |
| 1351 | int starttime = SDL_GetTicks(), timeout = 0; |
| 1352 | defformatstring(request)("list %s %d %d\n", player1->name, AC_VERSION, getbuildtype()); |
| 1353 | const char *req = request; |
| 1354 | int reqlen = strlen(req); |
| 1355 | ENetBuffer buf; |
| 1356 | while(reqlen > 0) |
| 1357 | { |
| 1358 | enet_uint32 events = ENET_SOCKET_WAIT_SEND; |
| 1359 | if(enet_socket_wait(sock, &events, 250) >= 0 && events) |
| 1360 | { |
| 1361 | buf.data = (void *)req; |
| 1362 | buf.dataLength = reqlen; |
| 1363 | int sent = enet_socket_send(sock, NULL, &buf, 1); |
| 1364 | if(sent < 0) break; |
| 1365 | req += sent; |
| 1366 | reqlen -= sent; |
| 1367 | if(reqlen <= 0) break; |
| 1368 | } |
| 1369 | timeout = SDL_GetTicks() - starttime; |
| 1370 | show_out_of_renderloop_progress(min(float(timeout)/RETRIEVELIMIT, 1.0f), text); |
| 1371 | if(interceptkey(SDLK_ESCAPE)) timeout = RETRIEVELIMIT + 1; |
| 1372 | if(timeout > RETRIEVELIMIT) break; |
| 1373 | } |
no test coverage detected