Parcourir la source

feat: ajout message en cas de déconnexion et autoreconnexion

Martin Passard il y a 7 ans
Parent
commit
a051f5a8f5
1 fichiers modifiés avec 10 ajouts et 5 suppressions
  1. 10 5
      src/main/Main.java

+ 10 - 5
src/main/Main.java

@@ -7,9 +7,13 @@ public class Main {
 	public static final String SERVER = "irc.geeknode.net";
 	public static final int PORT = 6667;
 	public static final String[] CHANNELS = { "#marmat" };
+	public static final long TIMEOUT_BEFORE_RECONNECTING = 360;
 	public static final Cache cache = Cache.getInstance();
+	public static int failures = 0;
+	
 	
 	public static void main(String[] args) throws Exception {
+		
 		try {
         // Now start our bot up.
         Bot bot = new Bot();
@@ -23,17 +27,18 @@ public class Main {
         // Get All the infomations and store in a cache
         Cache c = Cache.getInstance();
         
-        
-        
-        
         // Join the #pircbot channel.
         for(int i = 0; i< CHANNELS.length; i++) {
         bot.joinChannel(CHANNELS[i]);
         }
         
 		}catch(ConnectException ce) {
-			System.err.println("La connection a l'adresse "+SERVER+":"+PORT+" a échoué. Le Bot s'arrete.");
-			System.exit(1);
+			failures++;
+			System.err.println("Erreur numéro "+failures);
+			System.err.println("La connection a l'adresse "+SERVER+":"+PORT+" a échoué. Le Bot retentera de se connecter dans "+TIMEOUT_BEFORE_RECONNECTING+" secondes");
+			
+			Thread.sleep(TIMEOUT_BEFORE_RECONNECTING*1000);
+			main(args);
 		}
 	}