10s timeout when connecting to server
authorSmallJoker <mk939@ymail.com>
Thu, 9 Apr 2015 17:59:32 +0000 (19:59 +0200)
committerest31 <MTest31@outlook.com>
Fri, 17 Apr 2015 08:40:48 +0000 (10:40 +0200)
src/game.cpp

index 6bddfe90542dd2cc9cb676add83ad9acd06cc14d..24ecc99d2ab5c09144d6c30c1878043b1cb1bd2e 100644 (file)
@@ -2181,7 +2181,10 @@ bool Game::connectToServer(const std::string &playername,
                input->clear();
 
                FpsControl fps_control = { 0 };
-               f32 dtime; // in seconds
+               f32 dtime;
+               f32 wait_time = 0; // in seconds
+
+               fps_control.last_time = device->getTimer()->getTime();
 
                while (device->run()) {
 
@@ -2213,6 +2216,13 @@ bool Game::connectToServer(const std::string &playername,
                                break;
                        }
 
+                       wait_time += dtime;
+                       if (wait_time > 10) {
+                               *error_message = "Connection timed out.";
+                               errorstream << *error_message << std::endl;
+                               break;
+                       }
+
                        // Update status
                        showOverlayMessage(wgettext("Connecting to server..."), dtime, 20);
                }
@@ -2232,6 +2242,8 @@ bool Game::getServerContent(bool *aborted)
        FpsControl fps_control = { 0 };
        f32 dtime; // in seconds
 
+       fps_control.last_time = device->getTimer()->getTime();
+
        while (device->run()) {
 
                limitFps(&fps_control, &dtime);
@@ -4137,7 +4149,6 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime)
        // not using getRealTime is necessary for wine
        device->getTimer()->tick(); // Maker sure device time is up-to-date
        u32 time = device->getTimer()->getTime();
-
        u32 last_time = fps_timings->last_time;
 
        if (time > last_time)  // Make sure time hasn't overflowed