]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/tcpclient.cpp
Added a loop that makes gameserv reload if disconnected. It gives 3 attempts until...
[irc/gameservirc.git] / gameserv / tcpclient.cpp
index 3e355d61757fc68384e983cd7d767c85f7684e81..f2b7986385577b74299682f06dbae47743a9fd57 100644 (file)
@@ -56,7 +56,7 @@ void closeall(int fd);
 int main(int argc, char *argv[])
 {
   char buffer[1024], buf[1024];
-  int connected = 1;
+  int connected;
   char *cmd, *source = NULL, *conf = "gameserv.conf";
   srand(time(NULL));
 
@@ -95,6 +95,34 @@ int main(int argc, char *argv[])
         exit(2);
     }
 
+  init_masters();
+  load_gs_dbase();
+
+  if (load_monsters() == false)
+       goto end;
+
+   shuttingdown = false;
+
+  strcpy(boss.name, "Red Dragon");
+  strcpy(boss.weapon, "Breath of Unholy Fire");
+  boss.strength = 6667;
+  boss.gold = 2000000000;
+  boss.exp = 2000000000;
+  strcpy(boss.death, "You finally snuff out the deadly murderous "\
+    "dragon's dark flames. You have freed the land of its terror "\
+    "filled reign from above!");
+
+ // This loop will retry the connection 3 times
+ for (int retry = 0; retry < 3 && !shuttingdown; retry++)
+ {
+  connected = 1;
+  load_day();
+
+  long int loadtime = time(NULL);
+  long int currentTime;
+  long int oldTime = loadtime;
+  bool loaded = false;
+
   ignore_pipe();
   sock = make_connection(remoteport, SOCK_STREAM, remoteserver);
   if (sock == -1) {
@@ -151,26 +179,6 @@ int main(int argc, char *argv[])
       log("Server: %s",buffer);
   #endif
 
-  strcpy(boss.name, "Red Dragon");
-  strcpy(boss.weapon, "Breath of Unholy Fire");
-  boss.strength = 6667;
-  boss.gold = 2000000000;
-  boss.exp = 2000000000;
-  strcpy(boss.death, "You finally snuff out the deadly murderous "\
-    "dragon's dark flames. You have freed the land of its terror "\
-    "filled reign from above!");
-
-  init_masters();
-  load_gs_dbase();
-  load_day();
-  long int loadtime = time(NULL);
-  long int currentTime;
-  long int oldTime = loadtime;
-  bool loaded = false;
-
-  if (load_monsters() == false)
-       goto end;
-
   while (connected) {
       if (sock_gets(sock,buffer,sizeof(buffer)) == -1) {
         connected = 0;
@@ -198,7 +206,10 @@ int main(int argc, char *argv[])
         if (!loaded)
        {
            if (time(NULL) >= welcomedelay + loadtime)
+           {
                loaded = true;
+               retry = 0; // Start the reconnection cycle over
+           }
        }
 
        // Save the player data every updateperiod seconds
@@ -434,6 +445,8 @@ int main(int argc, char *argv[])
        }
   }
 
+ } // for loop for connection retry
+
   end:
 
   save_gs_dbase();