Browse Source

fix conflit

Martin Passard 7 years ago
parent
commit
6a715ed4a2

+ 35 - 6
src/IRC/Server.java

@@ -1,10 +1,17 @@
 package IRC;
 package IRC;
 
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.List;
 
 
 import main.AffichableSurIRC;
 import main.AffichableSurIRC;
 
 
+/**
+ * Cette classe à pour but de stocker les serveurs/channels pour les FAI
+ * @author Marmat
+ *
+ */
+
 public class Server implements AffichableSurIRC{
 public class Server implements AffichableSurIRC{
 	private String address;
 	private String address;
 	private int port;
 	private int port;
@@ -36,6 +43,12 @@ public class Server implements AffichableSurIRC{
 		
 		
 		
 		
 	}
 	}
+	
+	/**
+	 * Extrait le port d'une URI. par exemple irc://geeknode.net:6789#marmat renveira 6789
+	 * @param s URI sur laquelle extraire le numéro de port
+	 * @return Le numéro de port
+	 */
 	private int getSrvPort(String s) {
 	private int getSrvPort(String s) {
 		int res;
 		int res;
 		if(s.contains(":")) {
 		if(s.contains(":")) {
@@ -53,6 +66,11 @@ public class Server implements AffichableSurIRC{
 		return res;
 		return res;
 	}
 	}
 
 
+	/**
+	 * Extrait l'addresse d'une URI. par exemple irc://geeknode.net:789#marmat renveira geeknode.net
+	 * @param s URI 
+	 * @return L'addresse 
+	 */
 	private String getSrvAddr(String s) {
 	private String getSrvAddr(String s) {
 		String res="";
 		String res="";
 		String serv=s.substring(7); // on enleve irc://
 		String serv=s.substring(7); // on enleve irc://
@@ -64,6 +82,11 @@ public class Server implements AffichableSurIRC{
 		return res;
 		return res;
 	}
 	}
 	
 	
+	/**
+	 * Extrait le chan d'une URI. par exemple irc://geeknode.net:789#marmat renveira #marmat
+	 * @param s URI 
+	 * @return L'addresse 
+	 */
 	private String getSrvChan(String s) {
 	private String getSrvChan(String s) {
 		int idxcar = s.indexOf('#');
 		int idxcar = s.indexOf('#');
 		return s.substring(idxcar+1);
 		return s.substring(idxcar+1);
@@ -98,15 +121,21 @@ public class Server implements AffichableSurIRC{
 		return this.t.equals(Type.IRC);
 		return this.t.equals(Type.IRC);
 	}
 	}
 
 
-	@Override
-	public List<String> toStringIRC() {
-		List<String> s = new LinkedList<>();
+	public List<String> toStringIRC(){
+		List<String> res = new ArrayList<>();
+		res.add(toString());
+		return res;
+	}
+
+	
+	public String toString() {
+		
 		if(isIRC()) {
 		if(isIRC()) {
-			s.add("IRC://"+address+" chan:"+chan+" port:"+port);
+			return "IRC://"+address+" chan:"+chan+" port:"+port;
 		}else {
 		}else {
-			s.add(address);
+			return address;
 		}
 		}
-		return s;
+		
 	}
 	}
 	
 	
 	
 	

+ 19 - 2
src/data/CoveredAreas.java

@@ -7,19 +7,28 @@ public class CoveredAreas {
 
 
 	private final List<TechnoCoverage> technos;
 	private final List<TechnoCoverage> technos;
 	private final String name;
 	private final String name;
+	private ISP isp;
 	
 	
-	public CoveredAreas(String name, List<TechnoCoverage> techno) {
+	public CoveredAreas(String name, ISP isp, List<TechnoCoverage> techno) {
 		technos=techno;
 		technos=techno;
 		this.name=name;
 		this.name=name;
+		this.isp = isp;
 		
 		
 	}
 	}
-	public CoveredAreas(String name, TechnoCoverage...techno) {
+	
+	public CoveredAreas(String name, List<TechnoCoverage> techno) {
+		this(name,null,techno);
+	}
+	
+	public CoveredAreas(String name, ISP isp, TechnoCoverage...techno) {
 		ArrayList<TechnoCoverage> l = new ArrayList<>();
 		ArrayList<TechnoCoverage> l = new ArrayList<>();
 		for(int i=0;i<techno.length;++i) {
 		for(int i=0;i<techno.length;++i) {
 			l.add(techno[i]);
 			l.add(techno[i]);
 		}
 		}
 		this.technos=l;
 		this.technos=l;
 		this.name=name;
 		this.name=name;
+		this.isp=isp;
+		
 		
 		
 	}
 	}
 	
 	
@@ -38,9 +47,17 @@ public class CoveredAreas {
 		for (TechnoCoverage tc: technos) {
 		for (TechnoCoverage tc: technos) {
 			res+=tc+" ";
 			res+=tc+" ";
 		}
 		}
+		res+="par "+isp.getBetterName();
 		
 		
 		return res;
 		return res;
 	}
 	}
+	public ISP getIsp() {
+		return isp;
+	}
+	public void setIsp(ISP isp) {
+		this.isp = isp;
+	}
+	
 	
 	
 	
 	
 
 

+ 87 - 19
src/data/ISP.java

@@ -1,13 +1,16 @@
 package data;
 package data;
 
 
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.List;
 
 
+import IRC.Server;
 import main.AffichableSurIRC;
 import main.AffichableSurIRC;
 import main.Cache;
 import main.Cache;
+import main.Main;
 
 
 public class ISP implements AffichableSurIRC {
 public class ISP implements AffichableSurIRC {
-	
+
 	private String name;
 	private String name;
 	private int id;
 	private int id;
 	private boolean isFFDNMember;
 	private boolean isFFDNMember;
@@ -15,9 +18,18 @@ public class ISP implements AffichableSurIRC {
 	private String last_update;
 	private String last_update;
 	private ISPdata data;
 	private ISPdata data;
 	private CoveredAreas [] coveredAreas;
 	private CoveredAreas [] coveredAreas;
-	
-	
-	
+
+	/**
+	 *  Constructeur principal de la classe.
+	 * @param name
+	 * @param id
+	 * @param isFFDNMember
+	 * @param date_added
+	 * @param last_update
+	 * @param data
+	 * @param ca
+	 */
+
 	public ISP(String name, int id, boolean isFFDNMember, String date_added, String last_update, ISPdata data, CoveredAreas [] ca) {
 	public ISP(String name, int id, boolean isFFDNMember, String date_added, String last_update, ISPdata data, CoveredAreas [] ca) {
 		super();
 		super();
 		this.name = name;
 		this.name = name;
@@ -27,8 +39,15 @@ public class ISP implements AffichableSurIRC {
 		this.last_update = last_update;
 		this.last_update = last_update;
 		this.data = data;
 		this.data = data;
 		this.coveredAreas = ca;
 		this.coveredAreas = ca;
+		for(int i=0; i<coveredAreas.length;++i) {
+			coveredAreas[i].setIsp(this);
+		}
 	}
 	}
-	
+
+	/**
+	 * Méthode pour récuperer le plus court des noms du FAI, c'est à dire, si il existe shortname, sinon name
+	 * @return 
+	 */
 	public String getShortestName() {
 	public String getShortestName() {
 		if(data.hasShortName()) {
 		if(data.hasShortName()) {
 			return data.getShortname();
 			return data.getShortname();
@@ -36,7 +55,7 @@ public class ISP implements AffichableSurIRC {
 			return name;
 			return name;
 		}
 		}
 	}
 	}
-	
+
 	/**
 	/**
 	 * Méthode pour récuperer le nom le plus correct pour afficher les informations.
 	 * Méthode pour récuperer le nom le plus correct pour afficher les informations.
 	 * Si il n'y a pas de Shortname alors name sera utilisé.
 	 * Si il n'y a pas de Shortname alors name sera utilisé.
@@ -56,7 +75,7 @@ public class ISP implements AffichableSurIRC {
 		}else {
 		}else {
 			return name;
 			return name;
 		}
 		}
-		
+
 	}
 	}
 	/**
 	/**
 	 * Inverse de getBetterName. Le but est dans le cadre de l'affichage de plusieurs noms
 	 * Inverse de getBetterName. Le but est dans le cadre de l'affichage de plusieurs noms
@@ -70,12 +89,12 @@ public class ISP implements AffichableSurIRC {
 			}else {
 			}else {
 				return shortname;
 				return shortname;
 			}
 			}
-			
+
 		}else {
 		}else {
 			return name;
 			return name;
 		}
 		}
 	}
 	}
-	
+
 	public void setName(String name) {
 	public void setName(String name) {
 		this.name = name;
 		this.name = name;
 	}
 	}
@@ -105,7 +124,7 @@ public class ISP implements AffichableSurIRC {
 		this.isFFDNMember = isFFDNMember;
 		this.isFFDNMember = isFFDNMember;
 	}
 	}
 
 
-	
+
 	public String getDate_added() {
 	public String getDate_added() {
 		return date_added;
 		return date_added;
 	}
 	}
@@ -133,7 +152,7 @@ public class ISP implements AffichableSurIRC {
 	public int getSubscribersCount() {
 	public int getSubscribersCount() {
 		return data.getSubscribersCount();
 		return data.getSubscribersCount();
 	}
 	}
-	
+
 	public String toString() {
 	public String toString() {
 		String res="";
 		String res="";
 		res+=name+" : ";
 		res+=name+" : ";
@@ -141,20 +160,20 @@ public class ISP implements AffichableSurIRC {
 		res+="Nombre de membres: "+getMembersCount()+" Nombre d'abonnements:"+getSubscribersCount(); 
 		res+="Nombre de membres: "+getMembersCount()+" Nombre d'abonnements:"+getSubscribersCount(); 
 		return res;
 		return res;
 	}
 	}
-	
+
 	private String booleanToOuiNon(boolean b) {
 	private String booleanToOuiNon(boolean b) {
 		if(b) {
 		if(b) {
 			return "oui";
 			return "oui";
 		}
 		}
 		return "non";
 		return "non";
-		
+
 	}
 	}
-	
+
 	/**
 	/**
 	 * Renvoie une Liste de chaine de caractères pour permettre l'affichage sur IRC ligne par ligne, bien que le \n ne soit pas interprété.
 	 * Renvoie une Liste de chaine de caractères pour permettre l'affichage sur IRC ligne par ligne, bien que le \n ne soit pas interprété.
 	 * @return Une Liste de chaine correspondant à toutes les lignes que le bot doit écrire
 	 * @return Une Liste de chaine correspondant à toutes les lignes que le bot doit écrire
 	 */
 	 */
-	
+
 	public List<String> toStringIRC () {
 	public List<String> toStringIRC () {
 		Cache c = Cache.getInstance();
 		Cache c = Cache.getInstance();
 		List<String> res = new LinkedList<>();
 		List<String> res = new LinkedList<>();
@@ -167,11 +186,11 @@ public class ISP implements AffichableSurIRC {
 			res.add(preface+"Nombre de Membres : "+getMembersCount());
 			res.add(preface+"Nombre de Membres : "+getMembersCount());
 			res.add(preface+"Nombre d'abonnements : "+getSubscribersCount());
 			res.add(preface+"Nombre d'abonnements : "+getSubscribersCount());
 		}
 		}
-		
-		
+
+
 		return res;
 		return res;
 	}
 	}
-	
+
 	private String getShortName() {
 	private String getShortName() {
 		return data.getShortname();
 		return data.getShortname();
 	}
 	}
@@ -180,5 +199,54 @@ public class ISP implements AffichableSurIRC {
 		return coveredAreas;
 		return coveredAreas;
 	}
 	}
 
 
-	
+	/**
+	 * Récupere la zone couverte correspondante au paramètre
+	 * @param name Nom de la zone
+	 * @return	la première Zone correspondante au nom.
+	 */
+	public CoveredAreas getCoveredArea(String name) {
+		for(CoveredAreas ca : coveredAreas) {
+			if(ca.getName().equalsIgnoreCase(name)) {
+				return ca;
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Récupere la zone couverte correspondante au paramètre
+	 * @param name Nom de la zone
+	 * @return	toutes les Zones correspondante au nom.
+	 */
+	public List<CoveredAreas> getCoveredAreas(String name){
+		List<CoveredAreas> lca = new ArrayList<>(4);
+		for(CoveredAreas ca : coveredAreas) {
+			if(ca.getName().equalsIgnoreCase(name)) {
+				lca.add(ca);
+			}
+		}
+		return lca;
+
+	}
+
+	public List<String> contact() {
+		List<String> s = new ArrayList<>();
+		s.add( "["+this.getBetterName()+"] est joignable par:");
+		s.add("Site web: "+getData().getWebsite());
+		s.add("Mail: "+getData().emailSyntaxer());
+		String chats="Chat : ";
+		Server[] chans = getData().getIrcChan();
+		if(chans != null) {
+			for(int i=0; i<chans.length; i++) {
+				chats+=chans[i].toString()+" ";
+			}
+			s.add(chats);
+		} else {
+			if(Main.isDebug()) {
+			s.add("Chans a Null");
+			}
+		}
+		return s;
+	}
+
 }
 }

+ 36 - 6
src/data/ISPDAO.java

@@ -26,17 +26,20 @@ import main.Main;
 public class ISPDAO {
 public class ISPDAO {
 
 
 	/**
 	/**
-	 * This class implements the Sigleton Design Patern and is the DataAcess Object. It's role is to get informations from <a href="db.ffdn.org"> db.ffdn.org </a> and transform the into data Objects.
+	 * Cette classe implémente le design patern singleton. Son role est de récuperer les données de <a href="db.ffdn.org"> db.ffdn.org </a> et de les transformer en objets utilisables ensuite.
 	 */
 	 */
 
 
 	public static volatile ISPDAO instance = null;
 	public static volatile ISPDAO instance = null;
 	private final String dbAdress = "https://db.ffdn.org/api/v1/isp/";
 	private final String dbAdress = "https://db.ffdn.org/api/v1/isp/";
 
 
-
+	// Ceci permet de rendre impossible l'instanciation de la classe, conformement au design patern singleton.
 	private ISPDAO() {
 	private ISPDAO() {
 
 
 	}
 	}
-
+	/**
+	 * Cette méthode est celle permettant de récuperer l'instance de la classe. Si cette dernière n'est pas initialisée, elle l'initialise avant.
+	 * @return L'instance de la classe a utiliser ensuite
+	 */
 	public final static ISPDAO getInstance() {
 	public final static ISPDAO getInstance() {
 		if (ISPDAO.instance == null) {
 		if (ISPDAO.instance == null) {
 			synchronized (ISPDAO.class) {
 			synchronized (ISPDAO.class) {
@@ -48,10 +51,22 @@ public class ISPDAO {
 		return ISPDAO.instance;
 		return ISPDAO.instance;
 	}
 	}
 
 
+	/**
+	 * Version simplifiée : Execute une requette de type GET en HTTPS simplement avec l'addresse et avec les paramètres par défault pour du https
+	 * @param https_url URL a récuperer en HTTPS
+	 * @return La chaine de caractères correspondant à la page demandée par l'URL.
+	 */
 	private String executeGet(String https_url) {
 	private String executeGet(String https_url) {
 		return executeGet(https_url, "", 443);
 		return executeGet(https_url, "", 443);
 	}
 	}
 	
 	
+	/**
+	 * Implementation reele de la requete HTTPS.
+	 * @param https_url URL sur laquelle récuperer la ressource
+	 * @param proxyName Le nom du proxy, si besoin
+	 * @param port le port sur lequel faire la demande
+	 * @return La chaine de caractères correspondant à la page demandée par l'URL.
+	 */
 	@SuppressWarnings("resource")
 	@SuppressWarnings("resource")
 	private String executeGet(final String https_url, final String proxyName, final int port) {
 	private String executeGet(final String https_url, final String proxyName, final int port) {
 	    String ret = "";
 	    String ret = "";
@@ -98,8 +113,8 @@ public class ISPDAO {
 
 
 
 
 	/**
 	/**
-	 * 
-	 * @return List of ISPs constructed.
+	 * Récupere tous les FAI possibles. Dans le cas ou il y a des Fails consécutifs, c'est que peut-être DB.ffdn est deffectueux, car on a pas atteint le nombre de fai annoncés par total_items, mais on n'as que des réponses indiquant que la ressource est incorrecte.
+	 * @return la liste de tous les FAIs possibles.
 	 */
 	 */
 	public List<ISP> getISPs() throws Exception{
 	public List<ISP> getISPs() throws Exception{
 		
 		
@@ -125,7 +140,12 @@ public class ISPDAO {
 		return ar;
 		return ar;
 
 
 	}
 	}
-
+	
+	/**
+	 * Récupere le FAI qui a pour id dans db.ffdn.org le paramètre number
+	 * @param number numéro correspondna tà l'id a aller chercher dans db
+	 * @return le FAI construit correspondant, ou null si l'id n'est pas ou plus occupé par un FAI
+	 */
 
 
 	public ISP getISP(int number) {
 	public ISP getISP(int number) {
 		String json = executeGet(dbAdress+number+'/');
 		String json = executeGet(dbAdress+number+'/');
@@ -220,10 +240,18 @@ public class ISPDAO {
 		return res;
 		return res;
 	}
 	}
 	
 	
+	/**
+	 * Récupere les données
+	 * @param json objet récupéré depuis db.ffdn
+	 * @return Tableau des zones couvertes
+	 */
 	private CoveredAreas [] getCoveredAreas(JSONObject json) {
 	private CoveredAreas [] getCoveredAreas(JSONObject json) {
+		json = json.getJSONObject("ispformat");
 		CoveredAreas [] res=null;
 		CoveredAreas [] res=null;
 		try {
 		try {
+			
 			JSONArray ja = json.getJSONArray("coveredAreas");
 			JSONArray ja = json.getJSONArray("coveredAreas");
+		
 			res = new CoveredAreas [ja.length()];
 			res = new CoveredAreas [ja.length()];
 			for(int i=0;i<ja.length();i++) {
 			for(int i=0;i<ja.length();i++) {
 				JSONObject jo = ja.getJSONObject(i);
 				JSONObject jo = ja.getJSONObject(i);
@@ -239,6 +267,8 @@ public class ISPDAO {
 			}
 			}
 			return res;
 			return res;
 		}catch(JSONException jo) {
 		}catch(JSONException jo) {
+			System.err.println("erreur GetCoveredAreas pour "+getName(json));
+			jo.printStackTrace(System.err);
 			return null;
 			return null;
 		}
 		}
 		
 		

+ 29 - 1
src/data/ISPdata.java

@@ -5,6 +5,7 @@ import org.json.JSONException;
 import org.json.JSONObject;
 import org.json.JSONObject;
 
 
 import IRC.Server;
 import IRC.Server;
+import main.Main;
 
 
 public class ISPdata {
 public class ISPdata {
 
 
@@ -52,8 +53,13 @@ public class ISPdata {
 
 
 			}
 			}
 		}catch(JSONException jsonE) {	// Si il n'y a pas de chatroom
 		}catch(JSONException jsonE) {	// Si il n'y a pas de chatroom
+			if(Main.isDebug()) {
+				System.err.println("Warning : Pas de chatroom pour "+this.shortname);
+				jsonE.printStackTrace(System.err);
+			}
 			chatrooms = new Server[0];
 			chatrooms = new Server[0];
 		}
 		}
+		this.ircChan = chatrooms;
 		this.progressStatus = getInt(jo,"progressStatus");
 		this.progressStatus = getInt(jo,"progressStatus");
 		this.membersCount = getInt(jo,"memberCount",0);
 		this.membersCount = getInt(jo,"memberCount",0);
 		this.subscribersCount = getInt(jo,"subscriberCount",0);
 		this.subscribersCount = getInt(jo,"subscriberCount",0);
@@ -63,6 +69,7 @@ public class ISPdata {
 			this.joinDate = "?";
 			this.joinDate = "?";
 		}
 		}
 		this.creationDate = getString(jo,"creationDate","?");
 		this.creationDate = getString(jo,"creationDate","?");
+		this.email = getString(jo,"email","?");
 
 
 	}
 	}
 	
 	
@@ -148,5 +155,26 @@ public class ISPdata {
 		return shortname;
 		return shortname;
 	}
 	}
 	
 	
-	
+	/**
+	 * Transforme l'addresse mail. Si l'adresse est a null, alors renvoie la chaine vide a la place.
+	 * @return L'adresse Email modifiée pour ne pas être en clair.
+	 */
+	public String emailSyntaxer() {
+		String email = this.getEmail();
+		String res="";
+		if(email==null) {
+			return res;
+		}
+		for(int i=0; i<email.length(); ++i) {
+			if(email.charAt(i) == '@' ) {
+				res +=" <at> ";
+			}else if( email.charAt(i) == '.' ) {
+				res +=" <dot> ";
+			}else {
+				res +=email.charAt(i);
+			}
+		}
+		return res;
+		
+	}
 }
 }

+ 4 - 0
src/data/TechnoCoverage.java

@@ -1,6 +1,10 @@
 package data;
 package data;
 
 
 public enum TechnoCoverage {
 public enum TechnoCoverage {
+	/**
+	 * Cette enum permet de de transformer toutes les techno annoncée dans les zones couvertes en une valeur.
+	 */
+	
 	VPN,FTTH,ADSL,VDSL,xDSL,WIFI,PIGEON,CABLE,AUTRE;
 	VPN,FTTH,ADSL,VDSL,xDSL,WIFI,PIGEON,CABLE,AUTRE;
 	
 	
 	public String toString() {
 	public String toString() {

+ 45 - 4
src/main/Bot.java

@@ -6,6 +6,7 @@ import java.util.List;
 
 
 import org.jibble.pircbot.PircBot;
 import org.jibble.pircbot.PircBot;
 
 
+import data.CoveredAreas;
 import data.ISP;
 import data.ISP;
 import data.ISPDAO;
 import data.ISPDAO;
 import verif_saisie.EntierPositifNonVide;
 import verif_saisie.EntierPositifNonVide;
@@ -19,6 +20,11 @@ public class Bot extends PircBot {
 	public Bot() {
 	public Bot() {
 		this.setName("UneFede2");
 		this.setName("UneFede2");
 		this.setMessageDelay(TIME_BETWEEN_MESSAGES);
 		this.setMessageDelay(TIME_BETWEEN_MESSAGES);
+		if(Main.isDebug()) {
+			this.setVerbose(true);
+		}else {
+			this.setVerbose(false);
+		}
 		idao = ISPDAO.getInstance();
 		idao = ISPDAO.getInstance();
 	}
 	}
 
 
@@ -29,16 +35,21 @@ public class Bot extends PircBot {
 			sendMessage(channel, sender + ": Nous sommes le " + time);
 			sendMessage(channel, sender + ": Nous sommes le " + time);
 		}
 		}
 
 
-		if (message.substring(0, 5).equalsIgnoreCase("+info")) {
+		if (message.length()>6 && message.substring(0, 5).equalsIgnoreCase("+info")) {
 			info(channel,sender,login,hostname,message);
 			info(channel,sender,login,hostname,message);
 		}
 		}
+		
+		if (message.length()>9 && message.substring(0, 8).equalsIgnoreCase("+contact")) {
+			contact(channel,sender,login,hostname,message);
+		}
+		
 
 
 		if (message.equalsIgnoreCase("+source") || message.equalsIgnoreCase("+code") || message.equalsIgnoreCase("+sources")) {
 		if (message.equalsIgnoreCase("+source") || message.equalsIgnoreCase("+code") || message.equalsIgnoreCase("+sources")) {
 			sendMessage(channel, sender+": mes sources sont disponibles ici: https://code.ffdn.org/marmat8951/bot-irc2");
 			sendMessage(channel, sender+": mes sources sont disponibles ici: https://code.ffdn.org/marmat8951/bot-irc2");
 		}
 		}
 
 
 
 
-		if (message.substring(0, 6).equals("+liste")) {
+		if (message.length()>= 6 && message.substring(0, 6).equals("+liste")) {
 			list(channel, sender, login, hostname, message);
 			list(channel, sender, login, hostname, message);
 		}
 		}
 
 
@@ -137,8 +148,25 @@ public class Bot extends PircBot {
 	}
 	}
 
 
 
 
+	public void contact(String channel, String sender,
+			String login, String hostname, String message) {
+		
+		String s = message.substring(message.indexOf(' ')+1);
+		if(!EntierPositifNonVide.verifie(s)) {					// +contact suivi d'un mot
+			Cache c = Cache.getInstance();
+			ISP fai = c.getISPWithName(s);
+			if(fai == null) {
+				sendMessage(channel, "Aucun FAI "+s);
+			}else {
+				sendMessage(channel, fai.contact());
+			}
+		}
+		
+		
+	}
 
 
-
+	
+	
 	public void info(String channel, String sender,
 	public void info(String channel, String sender,
 			String login, String hostname, String message) {
 			String login, String hostname, String message) {
 
 
@@ -177,7 +205,20 @@ public class Bot extends PircBot {
 				Cache c = Cache.getInstance();
 				Cache c = Cache.getInstance();
 				ISP i = c.getISPWithName(s);
 				ISP i = c.getISPWithName(s);
 				if(i == null) {
 				if(i == null) {
-					sendMessage(channel, "Le FAI "+s+" est Inconnu, désolé");
+					sendMessage(channel, "Recherche d'une zone "+s);
+					ISP j = c.getISPWithGeoZone(s);
+					if(j == null)
+					sendMessage(channel, "Le FAI "+s+" est Inconnu, désolé. Et aucun FAI n'opère sur une sone dénomée "+s+" ...");
+					else {
+						sendMessage(channel, "Un FAI opère sur la zone "+s+" : ");
+						sendMessage(channel, j.toStringIRC());
+						List<CoveredAreas> cas = j.getCoveredAreas(s);
+						String technos = "";
+						for(CoveredAreas ca: cas) {
+							technos+=ca.getTechnos()+" ";
+						}
+						sendMessage(channel, "Avec pour techno "+technos);
+					}
 				}else {
 				}else {
 					sendMessage(channel, i.toStringIRC());
 					sendMessage(channel, i.toStringIRC());
 				}
 				}

+ 43 - 30
src/main/Cache.java

@@ -5,6 +5,7 @@ import java.util.Date;
 import java.util.LinkedList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.List;
 
 
+import data.CoveredAreas;
 import data.ISP;
 import data.ISP;
 import data.ISPDAO;
 import data.ISPDAO;
 
 
@@ -13,11 +14,11 @@ public class Cache implements AffichableSurIRC {
 	 * Cette classe sert de cache pour les infos de DB
 	 * Cette classe sert de cache pour les infos de DB
 	 * Elle implemente le Design Pattern Singleton dans la mesure où cette classe doit être l'unique instance de référence peu importe le Thread l'utilisant, et que le cache est unique.
 	 * Elle implemente le Design Pattern Singleton dans la mesure où cette classe doit être l'unique instance de référence peu importe le Thread l'utilisant, et que le cache est unique.
 	 */
 	 */
-	
+
 	public static volatile Cache instance = null;
 	public static volatile Cache instance = null;
 	private Date lastCacheUpdate;
 	private Date lastCacheUpdate;
 	private List<ISP> cache;
 	private List<ISP> cache;
-	
+
 	private Cache() {
 	private Cache() {
 		ISPDAO idao = ISPDAO.getInstance();
 		ISPDAO idao = ISPDAO.getInstance();
 		try {
 		try {
@@ -28,8 +29,8 @@ public class Cache implements AffichableSurIRC {
 			e.printStackTrace();
 			e.printStackTrace();
 		}
 		}
 	}
 	}
-	
-	
+
+
 	public  Date getLastCacheUpdate() {
 	public  Date getLastCacheUpdate() {
 		return lastCacheUpdate;
 		return lastCacheUpdate;
 	}
 	}
@@ -44,14 +45,14 @@ public class Cache implements AffichableSurIRC {
 			synchronized (ISPDAO.class) {
 			synchronized (ISPDAO.class) {
 				if(Cache.instance == null) {
 				if(Cache.instance == null) {
 					Cache.instance = new Cache();
 					Cache.instance = new Cache();
-					
-					
+
+
 				}
 				}
 			}
 			}
 		}
 		}
 		return Cache.instance;
 		return Cache.instance;
 	}
 	}
-	
+
 	/**
 	/**
 	 * Cette methode vient mettre à jour le cache des FAI. Pour cela, il récupere l'instance du DAO et récupère la liste des ISP. Si tout cse passe correctement, il supprime le cache précédent et le remplace par les nouvelles valeurs. Sinon, il maaintient le cache précédent.
 	 * Cette methode vient mettre à jour le cache des FAI. Pour cela, il récupere l'instance du DAO et récupère la liste des ISP. Si tout cse passe correctement, il supprime le cache précédent et le remplace par les nouvelles valeurs. Sinon, il maaintient le cache précédent.
 	 * @return True si l'operation s'est passée correctement, False sinon et affiche la cause
 	 * @return True si l'operation s'est passée correctement, False sinon et affiche la cause
@@ -71,7 +72,7 @@ public class Cache implements AffichableSurIRC {
 		lastCacheUpdate = new Date();
 		lastCacheUpdate = new Date();
 		return true;
 		return true;
 	}
 	}
-	
+
 	public int size() {
 	public int size() {
 		return cache.size();
 		return cache.size();
 	}
 	}
@@ -79,7 +80,7 @@ public class Cache implements AffichableSurIRC {
 	public List<ISP> getListe(){
 	public List<ISP> getListe(){
 		return cache;
 		return cache;
 	}
 	}
-	
+
 	public int getMemberCountInFede() {
 	public int getMemberCountInFede() {
 		int i = 0;
 		int i = 0;
 		for(ISP isp : getListe()) {
 		for(ISP isp : getListe()) {
@@ -89,7 +90,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		}
 		return i;
 		return i;
 	}
 	}
-	
+
 	public int getSubscribersCountInFede() {
 	public int getSubscribersCountInFede() {
 		int i = 0;
 		int i = 0;
 		for(ISP isp : getListe()) {
 		for(ISP isp : getListe()) {
@@ -99,7 +100,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		}
 		return i;
 		return i;
 	}
 	}
-	
+
 	public int getMemberCountOutFede() {
 	public int getMemberCountOutFede() {
 		int i = 0;
 		int i = 0;
 		for(ISP isp : getListe()) {
 		for(ISP isp : getListe()) {
@@ -109,7 +110,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		}
 		return i;
 		return i;
 	}
 	}
-	
+
 	public int getSubscribersCountOutFede() {
 	public int getSubscribersCountOutFede() {
 		int i = 0;
 		int i = 0;
 		for(ISP isp : getListe()) {
 		for(ISP isp : getListe()) {
@@ -119,7 +120,7 @@ public class Cache implements AffichableSurIRC {
 		}
 		}
 		return i;
 		return i;
 	}
 	}
-	
+
 	public String getSubscribersPercents(int val) {
 	public String getSubscribersPercents(int val) {
 		NumberFormat nf = NumberFormat.getInstance();
 		NumberFormat nf = NumberFormat.getInstance();
 		nf.setMaximumFractionDigits(2);
 		nf.setMaximumFractionDigits(2);
@@ -128,7 +129,7 @@ public class Cache implements AffichableSurIRC {
 		Double nbSubscribers = 0.0+getSubscribersCountInFede();
 		Double nbSubscribers = 0.0+getSubscribersCountInFede();
 		return nf.format((val2/nbSubscribers)*100)+" %";
 		return nf.format((val2/nbSubscribers)*100)+" %";
 	}
 	}
-	
+
 	public String getMembersPercents(int val) {
 	public String getMembersPercents(int val) {
 		NumberFormat nf = NumberFormat.getInstance();
 		NumberFormat nf = NumberFormat.getInstance();
 		nf.setMaximumFractionDigits(2);
 		nf.setMaximumFractionDigits(2);
@@ -137,9 +138,9 @@ public class Cache implements AffichableSurIRC {
 		Double nbMembers = 0.0+getMemberCountInFede();
 		Double nbMembers = 0.0+getMemberCountInFede();
 		return nf.format((val2/nbMembers)*100)+" %";
 		return nf.format((val2/nbMembers)*100)+" %";
 	}
 	}
-	
-	
-	
+
+
+
 	/**
 	/**
 	 * Donne le nombre de FAI de la fédé en parcourant le cache.
 	 * Donne le nombre de FAI de la fédé en parcourant le cache.
 	 * @param ffdn_member Si = null alors on s'en fout, si =true, seuls les FAI de la fédé, si = false, seuls les FAI non membres
 	 * @param ffdn_member Si = null alors on s'en fout, si =true, seuls les FAI de la fédé, si = false, seuls les FAI non membres
@@ -156,24 +157,24 @@ public class Cache implements AffichableSurIRC {
 				}
 				}
 			}
 			}
 			return count;
 			return count;
-			
+
 		}
 		}
-			
+
 	}
 	}
-	
+
 	public ISP getISPWithName(String s) {
 	public ISP getISPWithName(String s) {
 		for(ISP i : cache) {
 		for(ISP i : cache) {
-			if(i.getShortestName().equalsIgnoreCase(s) || i.getName().equalsIgnoreCase(s)) {
+			if(i.getShortestName().toLowerCase().contains(s.toLowerCase()) || i.getName().toLowerCase().contains(s.toLowerCase())) {
 				return i;
 				return i;
 			}
 			}
 		}
 		}
 		return null;
 		return null;
 	}
 	}
-	
+
 	public String toString() {
 	public String toString() {
 		return "Cache de "+cache.size()+" FAI";
 		return "Cache de "+cache.size()+" FAI";
 	}
 	}
-	
+
 	public List<String> toStringIRC() {
 	public List<String> toStringIRC() {
 		List<String> liste = new LinkedList<String>();
 		List<String> liste = new LinkedList<String>();
 		liste.add("Il y a "+cache.size()+" FAI dont "+getISPCount(Boolean.TRUE)+" dans la fédé");
 		liste.add("Il y a "+cache.size()+" FAI dont "+getISPCount(Boolean.TRUE)+" dans la fédé");
@@ -181,16 +182,28 @@ public class Cache implements AffichableSurIRC {
 		liste.add("Et hors fédé : "+getSubscribersCountOutFede()+" Abonné.e.s et "+getMemberCountOutFede()+" Membres");
 		liste.add("Et hors fédé : "+getSubscribersCountOutFede()+" Abonné.e.s et "+getMemberCountOutFede()+" Membres");
 		return liste;
 		return liste;
 	}
 	}
-	
-	
+
+
 	public ISP getISPWithGeoZone(String s) {
 	public ISP getISPWithGeoZone(String s) {
+
 		for(ISP i: cache) {
 		for(ISP i: cache) {
-			
+			if(Main.isDebug()) {
+				System.out.println("Recherche sur "+i.getBetterName());
+			}
+			if(i.getCoveredAreas()!= null) for(CoveredAreas ca : i.getCoveredAreas()) {
+				if(Main.isDebug()) {
+					ca.getName();
+				}
+				if(s.equalsIgnoreCase(ca.getName())) {
+					return i;
+				}
+			}
+
 		}
 		}
-		
+
 		return null;
 		return null;
-		
+
 	}
 	}
-	
-	
+
+
 }
 }

+ 31 - 35
src/main/Main.java

@@ -3,59 +3,55 @@ package main;
 import java.net.ConnectException;
 import java.net.ConnectException;
 
 
 public class Main {
 public class Main {
-	
+
 	public static final String SERVER = "irc.geeknode.net";
 	public static final String SERVER = "irc.geeknode.net";
 	public static final int PORT = 6667;
 	public static final int PORT = 6667;
 	public static final String[] CHANNELS = { "#marmat" };
 	public static final String[] CHANNELS = { "#marmat" };
 	public static final long TIMEOUT_BEFORE_RECONNECTING = 360;
 	public static final long TIMEOUT_BEFORE_RECONNECTING = 360;
 	public static final Cache cache = Cache.getInstance();
 	public static final Cache cache = Cache.getInstance();
 	public static int failures = 0;
 	public static int failures = 0;
-	private static boolean DEBUG;
-	
+	private static boolean DEBUG=true;
+
 	public static void main(String[] args) throws Exception {
 	public static void main(String[] args) throws Exception {
-		
-		for(int i=0;i<args.length;i++) {
-			if(args[i].equals("-debug")) {
-				DEBUG = true;
-			}
-			DEBUG = false;
-		}
-		
+
 		try {
 		try {
-        // Now start our bot up.
-        Bot bot = new Bot();
-        
-        if(isDebug()) {
-        // Enable debugging output.
-        	bot.setVerbose(true);
-        }else {
-        	bot.setVerbose(false);
-        }
-        
-        // Connect to the IRC server.
-        bot.connect(SERVER,PORT);
-        
-        // 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]);
-        }
-        CacheReloader cacheReloader = new CacheReloader(3600); // Met à jour la base toute les heures.
-        cacheReloader.start();
+			setDebug(args[0].equals("-debug"));
+
+			// Now start our bot up.
+			Bot bot = new Bot();
+
+			// Connect to the IRC server.
+			bot.connect(SERVER,PORT);
+
+			// 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]);
+			}
+			CacheReloader cacheReloader = new CacheReloader(3600); // Met à jour la base toute les heures.
+			cacheReloader.start();
+			
+			System.out.println("Debug? "+DEBUG);
+			
+
 		}catch(ConnectException ce) {
 		}catch(ConnectException ce) {
 			failures++;
 			failures++;
 			System.err.println("Erreur numéro "+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");
 			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);
 			Thread.sleep(TIMEOUT_BEFORE_RECONNECTING*1000);
 			main(args);
 			main(args);
 		}
 		}
 	}
 	}
 
 
-	
+
 	public static boolean isDebug () {
 	public static boolean isDebug () {
 		return Main.DEBUG;
 		return Main.DEBUG;
 	}
 	}
+
+	private static void setDebug(boolean b) {
+		System.out.println("Mise de debug à "+b);
+		DEBUG=b;
+	}
 }
 }