View Javadoc

1   /*
2    *  PCUServeur for the PCU project.
3    *  Copyright (C) 2010  PLU Julien
4    *
5    *  This program is free software: you can redistribute it and/or modify
6    *  it under the terms of the GNU General Public License as published by
7    *  the Free Software Foundation, either version 3 of the License, or
8    *  (at your option) any later version.
9    *  
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17   *  
18   *  For questions: julien.plu@redaction-developpez.com
19   */
20  package pcuserveur.lib;
21  
22  import java.io.BufferedReader;
23  import java.io.File;
24  import java.io.FileInputStream;
25  import java.io.FileNotFoundException;
26  import java.io.IOException;
27  import java.io.InputStream;
28  import java.io.InputStreamReader;
29  import java.io.UnsupportedEncodingException;
30  import java.net.HttpURLConnection;
31  import java.net.InetAddress;
32  import java.net.MalformedURLException;
33  import java.net.NetworkInterface;
34  import java.net.ServerSocket;
35  import java.net.Socket;
36  import java.net.SocketException;
37  import java.net.URL;
38  import java.security.MessageDigest;
39  import java.security.NoSuchAlgorithmException;
40  import java.sql.Connection;
41  import java.sql.DriverManager;
42  import java.sql.PreparedStatement;
43  import java.sql.ResultSet;
44  import java.sql.SQLException;
45  import java.text.DateFormat;
46  import java.text.SimpleDateFormat;
47  import java.util.ArrayList;
48  import java.util.Date;
49  import java.util.Enumeration;
50  
51  /**
52   * @author PLU Julien
53   * @version 1.0 
54   * 
55   * <b>
56   *     Cette classe représente le serveur en lui même.
57   * </b>
58   * <p>
59   *     Un Serveur est caractérisé par les informations suivantes:
60   *     <ul>
61   *         <li>Un entier pour le port par défaut du serveur.</li>
62   *         <li>Un entier pour le nombre maximum de connexion.</li>
63   *         <li>Un entier pour le nombre maximum de canaux.</li>
64   *         <li>Un String pour le message du jour.</li>
65   *         <li>Un String pour le nombre maximum de connexion.</li>
66   *         <li>Un String pour bannir le client.</li>
67   *         <li>Une instance de MonLog pour les canaux.</li>
68   *         <li>Une instance de MonLog pour les connexion/déconnexion.</li>
69   *         <li>Une instance de MonLog pour le serveur.</li>
70   *         <li>La connexion à la base de donnée.</li>
71   *         <li>Un boolean pour savoir si le serveur est lancé.</li>
72   *         <li>Un ArrayList contenant les gestionnaire de connexion.</li>
73   *         <li>Un ArrayList contenant les canaux.</li>
74   *         <li>Un entier pour le nombre de canaux du serveur.</li>
75   *         <li>Un entier pour le nombre de gestionnaire de connexion.</li>
76   *         <li>La socket du serveur.</li>
77   *     </ul>
78   * </p>
79   * 
80   * @see Canal
81   * @see GestionnaireConnexion
82   * @see CanalExistantException
83   * @see CanalInexistantException
84   * @see Evenement
85   * @see MonLog
86   * @see IdentifierException
87   * @see NbCanauxMaxException
88   */
89  public class Serveur {
90  	/**
91  	 * <p>
92  	 * Nombre maximum de canaux que le serveur pourra héberger.
93  	 * </p>
94  	 * 
95  	 * @see Serveur#Serveur ()
96  	 * @see Serveur#initialiser ()
97  	 * @see Serveur#configuration (int, int)
98  	 */
99  	private static int CANAUX_MAX;
100 	/**
101 	 * <p>
102 	 * Nombre maximum de connexion possible sur le serveur.
103 	 * </p>
104 	 * 
105 	 * @see Serveur#Serveur ()
106 	 * @see Serveur#initialiser ()
107 	 * @see Serveur#configuration (int, int)
108 	 */
109 	private static int CONNEXION_MAX;
110 	/**
111 	 * <p>
112 	 * Une instance de MyLogger pour les canaux.
113 	 * </p>
114 	 */
115 	public static MonLog logCanaux;
116 	/**
117 	 * <p>
118 	 * Une instance de MyLogger pour les connexions/déconnexions.
119 	 * </p>
120 	 */
121 	public static MonLog logCoDeco;
122 	/**
123 	 * <p>
124 	 * Une instance de MyLogger pour le serveur.
125 	 * </p>
126 	 */
127 	public static MonLog logServeur;
128 	/**
129 	 * <p>
130 	 * Mot de passe de l'utilisateur de la BDD.
131 	 * </p>
132 	 * 
133 	 * @see Serveur#Connexion ()
134 	 * @see Serveur#configuration (int, int)
135 	 */
136 	private static String MDP_BDD;
137 	/**
138 	 * <p>
139 	 * Message envoyé par le serveur lors de la connexion d'un client.
140 	 * </p>
141 	 * 
142 	 * @see GestionnaireConnexion#run ()
143 	 * @see Serveur#configuration (int, int)
144 	 */
145 	public static String MOTD;
146 	/**
147 	 * <p>
148 	 * Message envoyé par le serveur lorsque la nombre maximum de client est
149 	 * atteint.
150 	 * </p>
151 	 * 
152 	 * @see Serveur#configuration (int, int)
153 	 * @see Serveur#lancer ()
154 	 */
155 	private static String MSG_CONNEXION_MAX;
156 	/**
157 	 * <p>
158 	 * Message envoyé par le serveur lorsqu'un client est banni.
159 	 * </p>
160 	 * 
161 	 * @see Serveur#configuration (int, int)
162 	 * @see Serveur#bannirUtilisateur (String)
163 	 */
164 	private static String MSG_UTL_BANNI;
165 	/**
166 	 * <p>
167 	 * Nom de la BDD.
168 	 * </p>
169 	 * 
170 	 * @see Serveur#Connexion ()
171 	 * @see Serveur#configuration (int, int)
172 	 */
173 	private static String NOM_BDD;
174 	/**
175 	 * <p>
176 	 * Port par défaut sur lequel se connectera le serveur.
177 	 * </p>
178 	 * 
179 	 * @see Serveur#Serveur ()
180 	 * @see Serveur#configuration (int, int)
181 	 */
182 	private static int PORT_DEFAUT;
183 	/**
184 	 * <p>
185 	 * Port par défaut sur lequel écoute le serveur de la BDD.
186 	 * </p>
187 	 * 
188 	 * @see Serveur#Connexion ()
189 	 * @see Serveur#configuration (int, int)
190 	 */
191 	private static int PORT_SERVEUR_BDD;
192 	/**
193 	 * <p>
194 	 * Adresse du serveur de la BDD.
195 	 * </p>
196 	 * 
197 	 * @see Serveur#Connexion ()
198 	 * @see Serveur#configuration (int, int)
199 	 */
200 	private static String SERVEUR_BDD;
201 	/**
202 	 * <p>
203 	 * Utilisateur de la BDD.
204 	 * </p>
205 	 * 
206 	 * @see Serveur#Connexion ()
207 	 * @see Serveur#configuration (int, int)
208 	 */
209 	private static String USER_BDD;
210 	/**
211 	 * <p>
212 	 * Connexion et gestion de la BDD.
213 	 * </p>
214 	 * 
215 	 * @see Serveur#connexion ()
216 	 * @see Serveur#initialiser ()
217 	 * @see Serveur#stopperServeur (String)
218 	 */
219 	private Connection conn;
220 	/**
221 	 * <p>
222 	 * Lancement ou arrêt du serveur.
223 	 * </p>
224 	 * 
225 	 * @see Serveur#initialiser ()
226 	 * @see Serveur#lancer ()
227 	 * @see Serveur#stopperServeur (String)
228 	 */
229 	private boolean lance = false;
230 	/**
231 	 * <p>
232 	 * Liste des canaux contenus sur le serveur.
233 	 * </p>
234 	 * 
235 	 * @see Serveur#Serveur ()
236 	 * @see Serveur#canalExistant (String)
237 	 * @see Serveur#changerSujetCanal (String, String)
238 	 * @see Serveur#creerCanal (String, String)
239 	 * @see Serveur#ejecterUtilisateur (String, String)
240 	 * @see Serveur#initialiser ()
241 	 * @see Serveur#listerCanaux (String)
242 	 * @see Serveur#listerMembres (String)
243 	 * @see Serveur#relancerServeur (String)
244 	 * @see Serveur#stopperServeur (String)
245 	 * @see Serveur#supprimerCanal (String)
246 	 */
247 	private ArrayList<Canal> listeCanaux = new ArrayList<Canal> ();
248 	/**
249 	 * <p>
250 	 * Liste des gestionnaire de connexion contenus sur le serveur.
251 	 * </p>
252 	 * 
253 	 * @see Serveur#Serveur ()
254 	 * @see Serveur#ajouterGC (Socket)
255 	 * @see Serveur#chercherUtilisateur (String)
256 	 * @see Serveur#deconnexion (int)
257 	 * @see Serveur#ejecterUtilisateur (String, String)
258 	 * @see Serveur#informationMembre (String)
259 	 * @see Serveur#initialiser ()
260 	 * @see Serveur#listerServeur ()
261 	 * @see Serveur#relancerServeur (String)
262 	 * @see Serveur#stopperServeur (String)
263 	 */
264 	private ArrayList<GestionnaireConnexion> listeGestionnaire = new ArrayList<GestionnaireConnexion> ();
265 	/**
266 	 * <p>
267 	 * Nombre de canaux contenus sur le serveur.
268 	 * </p>
269 	 * 
270 	 * @see Serveur#creerCanal (String, String)
271 	 * @see Serveur#initialiser ()
272 	 * @see Serveur#stopperServeur (String)
273 	 * @see Serveur#supprimerCanal (String)
274 	 */
275 	private int nbCanaux;
276 
277 	/**
278 	 * <p>
279 	 * Nombre de gestionnaire de connexion contenus sur le serveur.
280 	 * </p>
281 	 * 
282 	 * @see Serveur#ajouterGC (Socket)
283 	 * @see Serveur#deconnexion (int)
284 	 * @see Serveur#initialiser ()
285 	 * @see Serveur#listerServeur ()
286 	 * @see Serveur#stopperServeur (String)
287 	 */
288 	private int nbGC;
289 
290 	/**
291 	 * <p>
292 	 * Socket sur lesquels les gestionnaires de connexions seront connectés.
293 	 * </p>
294 	 * 
295 	 * @see Serveur#initialiser ()
296 	 * @see Serveur#lancer ()
297 	 * @see Serveur#stopperServeur (String)
298 	 */
299 	private final ServerSocket socket;
300 
301 	/**
302 	 * <p>
303 	 * Constructeur par défaut.
304 	 * </p>
305 	 * 
306 	 * @throws IOException
307 	 *             Un envoie à un client a échoué.
308 	 * @throws RuntimeException
309 	 * 				Erreur d'exécution.
310 	 */
311 	public Serveur () throws IOException, RuntimeException {
312 		Serveur.configuration (this.nbGC, this.nbCanaux);
313 		this.socket = new ServerSocket (Serveur.PORT_DEFAUT);
314 
315 		for (int i = 0;i < Serveur.CONNEXION_MAX;i++) {
316 			this.listeGestionnaire.add (new GestionnaireConnexion ());
317 		}
318 		for (int i = 0;i < Serveur.CANAUX_MAX;i++) {
319 			this.listeCanaux.add (new Canal ());
320 		}
321 	}
322 
323 	/**
324 	 * <p>
325 	 * Créer et ajouter un GestionnaireConnexion à partir d'un socket dans la
326 	 * listes des gestionnaires.
327 	 * </p>
328 	 * 
329 	 * @param socket1
330 	 *            Socket du gestionnaire de connexion à ajouter.
331 	 */
332 	public void ajouterGC (final Socket socket1) {
333 		this.nbGC++;
334 		final int i = this.premierNull (this.listeGestionnaire);
335 
336 		if (i != -1) {
337 			this.listeGestionnaire.get (i).initialisationGestionnaire (socket1, this, i);
338 			new Thread (this.listeGestionnaire.get (i)).start ();
339 		}
340 	}
341 
342 	/**
343 	 * <p>
344 	 * Bannir un client du serveur.
345 	 * </p>
346 	 * 
347 	 * @param login
348 	 *          Login du client à bannir.
349 	 *            
350 	 * @throws LoginIntrouvableException
351 	 *          Le client n'existe pas.
352 	 * @throws IOException
353 	 * 			Erreur d'entrée sortie.
354 	 * @throws NonConnecteException
355 	 * 			Utilisateur non connecté.
356 	 */
357 	public void bannirUtilisateur (final String login) throws LoginIntrouvableException, IOException, NonConnecteException {
358 		final int place = this.chercherUtilisateur (login);
359 
360 		if (place != -1) {
361 			PreparedStatement state;
362 
363 			try {
364 				state = this.conn.prepareStatement ("UPDATE utilisateurs SET active = '0' WHERE identifiant = ?"); //$NON-NLS-1$
365 
366 				state.setString (1, login);
367 				state.executeUpdate ();
368 				this.listeGestionnaire.get (place).stopper (Serveur.MSG_UTL_BANNI);
369 				this.listeCanaux.get (place).notifier (Evenement.BANNI, login, ""); //$NON-NLS-1$
370 				this.listeCanaux.get (place).enleverGC (login);
371 				Serveur.logCoDeco.logMessage ("Le client " + login + " a été banni"); //$NON-NLS-1$ //$NON-NLS-2$
372 				state.close ();
373 			}
374 			catch (final SQLException e) {
375 				Serveur.logServeur.logException ("Serveur", "bannirUtilisateur", e); //$NON-NLS-1$//$NON-NLS-2$
376 			}
377 		}
378 		else {
379 			throw new LoginIntrouvableException (login + " n'est pas connecté"); //$NON-NLS-1$
380 		}
381 	}
382 
383 	/**
384 	 * <p>
385 	 * Savoir si un canal existe sur le serveur.
386 	 * </p>
387 	 * 
388 	 * @param nom
389 	 *            Nom du canal à rechercher.
390 	 * @return La position du canal -1 sinon.
391 	 */
392 	public int canalExistant (final String nom) {
393 		for (int i = 0;i < this.listeCanaux.size ();i++) {
394 			if ((this.listeCanaux.get (i).getNom () != null) && this.listeCanaux.get (i).getNom ().equals (nom)) {
395 				return i;
396 			}
397 		}
398 
399 		return -1;
400 	}
401 
402 	/**
403 	 * <p>
404 	 * Changer le sujet d'un canal.
405 	 * </p>
406 	 * 
407 	 * @param nom
408 	 *            Nom du canal dont on veut changer le sujet.
409 	 * @param sujet
410 	 *            Nouveau sujet du canal.
411 	 * @throws CanalInexistantException
412 	 *             Le canal n'existe pas.
413 	 * @throws IOException
414 	 *             Un envoie à un client a échoué.
415 	 */
416 	public void changerSujetCanal (final String nom, final String sujet) throws CanalInexistantException, IOException {
417 		final int tmp = this.canalExistant (nom);
418 
419 		if (tmp != -1) {
420 			this.listeCanaux.get (tmp).changerSujet (sujet);
421 			Serveur.logCanaux.logMessage ("Le sujet du canal " + nom + " a été changé en " + sujet); //$NON-NLS-1$//$NON-NLS-2$
422 		}
423 		else {
424 			throw new CanalInexistantException ();
425 		}
426 	}
427 
428 	/**
429 	 * <p>
430 	 * Savoir si un utilisateur existe sur le serveur.
431 	 * </p>
432 	 * 
433 	 * @param login
434 	 *            Login de l'utilisateur a rechercher.
435 	 * @return La position de l'utilisateur -1 sinon.
436 	 */
437 	private int chercherUtilisateur (final String login) {
438 		boolean trouve = false;
439 		int i = 0;
440 
441 		while (i < this.listeGestionnaire.size ()) {
442 			if (!this.listeGestionnaire.get (i).getClient ().estVide ()) {
443 				if (this.listeGestionnaire.get (i).getClient ().getLogin ().equals (login)) {
444 					trouve = true;
445 					break;
446 				}
447 			}
448 			i++;
449 		}
450 		if (trouve) {
451 			return i;
452 		}
453 
454 		return -1;
455 	}
456 	
457 	/**
458 	 * <p>
459 	 * Configuration du serveur par la lecture du fichier de configuration.
460 	 * </p>
461 	 * 
462 	 * @param nbCo
463 	 * 			Nombre d'utilisateur connecté sur le serveur.
464 	 * @param nbC
465 	 * 			Nombre de canaux créé sur le serveur.
466 	 * 
467 	 * @throws RuntimeException
468 	 *             Erreur lors de la configuration.
469 	 */
470 	public static void configuration (int nbCo, int nbC) throws RuntimeException {
471 		Serveur.logCanaux = new MonLog ("Canaux"); //$NON-NLS-1$
472 		Serveur.logServeur = new MonLog ("Serveur"); //$NON-NLS-1$
473 		Serveur.logCoDeco = new MonLog ("CoDeco"); //$NON-NLS-1$
474 		final File file = new File ("." + File.separator + "conf" + File.separator + "serveur.conf"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
475 		try {
476 			final BufferedReader r = new BufferedReader (new InputStreamReader (new FileInputStream (file), "UTF-8")); //$NON-NLS-1$
477 			String contenu = r.readLine ();
478 			int i = 0;
479 
480 			while (contenu != null) {
481 				if (contenu.charAt (0) == '#') {
482 					continue;
483 				}
484 
485 				final String[] tab = contenu.split ("="); //$NON-NLS-1$
486 
487 				if (tab[0].equals ("PORT_ECOUTE")) { //$NON-NLS-1$
488 					Serveur.PORT_DEFAUT = Integer.parseInt (tab[1]);
489 					i++;
490 				}
491 				else if (tab[0].equals ("CONNEXION_MAX")) { //$NON-NLS-1$
492 					Serveur.CONNEXION_MAX = Integer.parseInt (tab[1]);
493 					i++;
494 				}
495 				else if (tab[0].equals ("CANAUX_MAX")) { //$NON-NLS-1$
496 					Serveur.CANAUX_MAX = Integer.parseInt (tab[1]);
497 					i++;
498 				}
499 				else if (tab[0].equals ("MOTD")) { //$NON-NLS-1$
500 					Serveur.MOTD = ""; //$NON-NLS-1$
501 					
502 					if (tab[1].contains ("\\\\")) { //$NON-NLS-1$
503 						String phrase = tab[1];
504 						
505 						while (phrase.contains ("\\\\")) { //$NON-NLS-1$
506 							if (phrase.contains ("%d")) { //$NON-NLS-1$
507 								Date aujourdui = new Date ();
508 								DateFormat dateFormat = new SimpleDateFormat ("dd/MM/yyyy"); //$NON-NLS-1$
509 								
510 								phrase = phrase.replace ("%d", dateFormat.format (aujourdui)); //$NON-NLS-1$
511 							}
512 							if (phrase.contains ("%ip")) { //$NON-NLS-1$
513 								phrase = phrase.replace ("%ip", Serveur.getIp ()); //$NON-NLS-1$
514 							}
515 							if (phrase.contains ("%nc")) { //$NON-NLS-1$
516 								phrase = phrase.replace ("%nc", Integer.toString (nbC)); //$NON-NLS-1$
517 							}
518 							if (phrase.contains ("%nu")) { //$NON-NLS-1$
519 								phrase = phrase.replace ("%nu", Integer.toString (nbCo)); //$NON-NLS-1$
520 							}
521 							Serveur.MOTD += phrase.substring (1, phrase.length () - 2);
522 							phrase = r.readLine ();
523 						}
524 						if (phrase.contains ("%d")) { //$NON-NLS-1$
525 							Date aujourdui = new Date ();
526 							DateFormat dateFormat = new SimpleDateFormat ("dd/MM/yyyy"); //$NON-NLS-1$
527 							
528 							phrase = phrase.replace ("%d", dateFormat.format (aujourdui)); //$NON-NLS-1$
529 						}
530 						if (phrase.contains ("%ip")) { //$NON-NLS-1$
531 							phrase = phrase.replace ("%ip", Serveur.getIp ()); //$NON-NLS-1$
532 						}
533 						if (phrase.contains ("%nc")) { //$NON-NLS-1$
534 							phrase = phrase.replace ("%nc", Integer.toString (nbC)); //$NON-NLS-1$
535 						}
536 						if (phrase.contains ("%nu")) { //$NON-NLS-1$
537 							phrase = phrase.replace ("%nu", Integer.toString (nbCo)); //$NON-NLS-1$
538 						}
539 						Serveur.MOTD += phrase.substring (0, phrase.length () - 1);
540 					}
541 					else {
542 						Serveur.MOTD = tab[1].substring (1, tab[1].length () - 1);
543 					}
544 					
545 					i++;
546 				}
547 				else if (tab[0].equals ("MSG_CONNEXION_MAX")) { //$NON-NLS-1$
548 					Serveur.MSG_CONNEXION_MAX = tab[1].substring (1, tab[1].length () - 1);
549 					i++;
550 				}
551 				else if (tab[0].equals ("MSG_UTL_BANNI")) { //$NON-NLS-1$
552 					Serveur.MSG_UTL_BANNI = tab[1].substring (1, tab[1].length () - 1);
553 					i++;
554 				}
555 				else if (tab[0].equals ("SERVEUR_BDD")) { //$NON-NLS-1$
556 					Serveur.SERVEUR_BDD = tab[1].substring (1, tab[1].length () - 1);
557 					i++;
558 				}
559 				else if (tab[0].equals ("PORT_SERVEUR_BDD")) { //$NON-NLS-1$
560 					Serveur.PORT_SERVEUR_BDD = Integer.parseInt (tab[1]);
561 					i++;
562 				}
563 				else if (tab[0].equals ("NOM_BDD")) { //$NON-NLS-1$
564 					Serveur.NOM_BDD = tab[1].substring (1, tab[1].length () - 1);
565 					i++;
566 				}
567 				else if (tab[0].equals ("USER_BDD")) { //$NON-NLS-1$
568 					Serveur.USER_BDD = tab[1].substring (1, tab[1].length () - 1);
569 					i++;
570 				}
571 				else if (tab[0].equals ("MDP_BDD")) { //$NON-NLS-1$
572 					Serveur.MDP_BDD = tab[1].substring (1, tab[1].length () - 1);
573 					i++;
574 				}
575 				contenu = r.readLine ();
576 			}
577 			r.close ();
578 			if (i != 11) {
579 				Serveur.logServeur.logMessage ("Une erreur est survenu avec le fichier de configuration, tout les paramètres n'ont pas été trouvés."); //$NON-NLS-1$
580 				Serveur.logServeur.logException ("Serveur", "configuration", new RuntimeException ()); //$NON-NLS-1$ //$NON-NLS-2$
581 				throw new RuntimeException ();
582 			}
583 		}
584 		catch (final UnsupportedEncodingException e) {
585 			Serveur.logServeur.logMessage ("Le fichier de configuration est introuvable."); //$NON-NLS-1$
586 			Serveur.logServeur.logException ("Serveur", "configuration", new RuntimeException ()); //$NON-NLS-1$ //$NON-NLS-2$
587 			throw new RuntimeException ();
588 		}
589 		catch (final FileNotFoundException e1) {
590 			Serveur.logServeur.logException ("Serveur", "configuration", e1); //$NON-NLS-1$ //$NON-NLS-2$
591 		}
592 		catch (final IOException e2) {
593 			Serveur.logServeur.logException ("Serveur", "configuration", e2); //$NON-NLS-1$ //$NON-NLS-2$
594 		}
595 	}
596 
597 	/**
598 	 * <p>
599 	 * Connexion à la BDD.
600 	 * </p>
601 	 * 
602 	 * @throws ClassNotFoundException
603 	 *             Le pilote JDBC est introuvable.
604 	 */
605 	public void connexion () throws ClassNotFoundException {
606 		Class.forName ("com.mysql.jdbc.Driver"); //$NON-NLS-1$
607 		final String url = "jdbc:mysql://" + Serveur.SERVEUR_BDD + ":" + Serveur.PORT_SERVEUR_BDD + "/" + Serveur.NOM_BDD; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
608 		final String utilisateur = Serveur.USER_BDD;
609 		final String mdp = Serveur.MDP_BDD;
610 
611 		try {
612 			this.conn = DriverManager.getConnection (url, utilisateur, mdp);
613 
614 			Serveur.logServeur.logMessage ("Connection bdd effective !"); //$NON-NLS-1$
615 		}
616 		catch (final SQLException e) {
617 			Serveur.logServeur.logMessage ("Connection bdd echoué"); //$NON-NLS-1$
618 			Serveur.logServeur.logException ("Serveur", "connexion", e); //$NON-NLS-1$ //$NON-NLS-2$
619 			throw new RuntimeException ();
620 		}
621 	}
622 
623 	/**
624 	 * <p>
625 	 * Demande de connexion directe avec un autre client.
626 	 * </p>
627 	 * 
628 	 * @param login
629 	 *            Login de la personne avec laquelle on veut une connexion.
630 	 * @return Le gestionnaire de connexion du client.
631 	 * @throws LoginIntrouvableException
632 	 *             Le login n'existe pas.
633 	 */
634 	public GestionnaireConnexion connexion_directe (final String login) throws LoginIntrouvableException {
635 		final int position = this.chercherUtilisateur (login);
636 
637 		if (position != -1) {
638 			return this.listeGestionnaire.get (position);
639 		}
640 		throw new LoginIntrouvableException ();
641 	}
642 
643 	/**
644 	 * <p>
645 	 * Demande de connexion directe avec un autre client.
646 	 * </p>
647 	 * 
648 	 * @param login
649 	 *            Login de la personne avec laquelle on veut une connexion.
650 	 * @return Le gestionnaire de connexion du client.
651 	 * @throws LoginIntrouvableException
652 	 *             Le login n'existe pas.
653 	 */
654 	public GestionnaireConnexion connexion_directe_accepte (final String login) throws LoginIntrouvableException {
655 		final int position = this.chercherUtilisateur (login);
656 
657 		if (position != -1) {
658 			return this.listeGestionnaire.get (position);
659 		}
660 		throw new LoginIntrouvableException ();
661 	}
662 
663 	/**
664 	 * <p>
665 	 * Refus de la connexion directe avec un autre client.
666 	 * </p>
667 	 * 
668 	 * @param login
669 	 *            Login de la personne avec laquelle on veut une connexion.
670 	 * @return Le gestionnaire de connexion du client.
671 	 * @throws LoginIntrouvableException
672 	 *             Le login n'existe pas.
673 	 */
674 	public GestionnaireConnexion connexion_directe_refuse (final String login) throws LoginIntrouvableException {
675 		final int position = this.chercherUtilisateur (login);
676 
677 		if (position != -1) {
678 			return this.listeGestionnaire.get (position);
679 		}
680 		throw new LoginIntrouvableException ();
681 	}
682 
683 	/**
684 	 * <p>
685 	 * Creer un canal sur le serveur.
686 	 * </p>
687 	 * 
688 	 * @param nom
689 	 *            Nom du canal à creer.
690 	 * @param sujet
691 	 *            Sujet du canal à creer.
692 	 * @throws CanalExistantException
693 	 *             Le canal n'existe pas.
694 	 * @throws NbCanauxMaxException
695 	 *             Trop de canaux ont été créé.
696 	 */
697 	public void creerCanal (final String nom, final String sujet) throws CanalExistantException, NbCanauxMaxException {
698 		if (this.canalExistant (nom) != -1) {
699 			throw new CanalExistantException ();
700 		}
701 		if (this.nbCanaux >= Serveur.CANAUX_MAX) {
702 			throw new NbCanauxMaxException ();
703 		}
704 		final int i = this.premierNull (this.listeCanaux);
705 		
706 		this.listeCanaux.get (i).initialiser (nom, sujet);
707 		this.nbCanaux++;
708 		Serveur.logServeur.logMessage ("Nouveau canal créé s'appellant " + nom + " et ayant pour sujet " + sujet); //$NON-NLS-1$ //$NON-NLS-2$
709 	}
710 
711 	/**
712 	 * <p>
713 	 * Déconnexion d'un gestionnaire de connexion.
714 	 * </p>
715 	 * 
716 	 * @param num_gc
717 	 *            Emplacement du gestionnaire de connexion.
718 	 */
719 	public void deconnexion (final int num_gc) {
720 		Serveur.logCoDeco.logMessage ("Déconnexion de " + this.listeGestionnaire.get (num_gc).getClient ().getLogin ()); //$NON-NLS-1$
721 		this.listeGestionnaire.get (num_gc).vider ();
722 		this.nbGC--;
723 	}
724 
725 	/**
726 	 * <p>
727 	 * Ejecte un utilisateur d'un canal.
728 	 * </p>
729 	 * 
730 	 * @param login
731 	 *            Login de l'utilisateur à éjecter.
732 	 * @param nom_canal
733 	 *            Nom du canal ou se situe l'utilisateur à éjecter.
734 	 * @throws CanalInexistantException
735 	 *             Le canal n'existe pas.
736 	 * @throws LoginIntrouvableException
737 	 *             Le login est introuvable.
738 	 * @throws NonConnecteException
739 	 *             L'utilisateur n'est pas connecté sur le canal.
740 	 * @throws IOException
741 	 *             Un envoie à un client a échoué.
742 	 */
743 	public void ejecterUtilisateur (final String login, final String nom_canal) throws CanalInexistantException, LoginIntrouvableException, NonConnecteException, IOException {
744 		final int place = this.chercherUtilisateur (login);
745 
746 		if (place != -1) {
747 			final int tmp = this.canalExistant (nom_canal);
748 
749 			if (tmp != -1) {
750 				this.listeCanaux.get (tmp).notifier (Evenement.EJECTE, login, ""); //$NON-NLS-1$
751 				this.listeCanaux.get (tmp).enleverGC (login);
752 				this.listeGestionnaire.get (place).enleverCanal (nom_canal);
753 				Serveur.logCoDeco.logMessage (login + " a été éjecté du canal " + nom_canal); //$NON-NLS-1$
754 			}
755 			else {
756 				throw new CanalInexistantException ();
757 			}
758 		}
759 		else {
760 			throw new LoginIntrouvableException (login + " n'est pas connecté"); //$NON-NLS-1$
761 		}
762 	}
763 	
764 	/**
765 	 * <p>
766 	 * Méthode qui retourne l'adresse IP internet du poste sur lequel le serveur tourne.
767 	 * </p>
768 	 * 
769 	 * @return Adresse IP du serveur sur internet si le poste est connecté à internet
770 	 * 		   L'adresse sur le réseau locale sinon.
771 	 */
772 	public static String getIp () {
773 		String s = ""; //$NON-NLS-1$
774 		
775 		if (Serveur.isConnecteInternet ()) {
776 			URL u = null;
777 			InputStream i = null;
778 			
779 			try {
780 				u = new URL ("http://mon-ip.com/"); //$NON-NLS-1$
781 				i = u.openStream();
782 				
783 				BufferedReader b = new BufferedReader (new InputStreamReader (i));
784 				
785 				s = b.readLine();
786 				while (s != null) {
787 					if (s.contains ("Votre adresse IP est")) { //$NON-NLS-1$
788 						s = s.substring (65, 77);
789 						break;
790 					}
791 					s = b.readLine();
792 				}
793 			}
794 			catch (MalformedURLException e) {
795 				Serveur.logServeur.logMessage ("URL mal formée"); //$NON-NLS-1$
796 				Serveur.logServeur.logException ("Serveur", "getIp", e); //$NON-NLS-1$ //$NON-NLS-2$
797 			}
798 			catch (IOException e) {
799 				Serveur.logServeur.logMessage ("Problème d'entrée sortie"); //$NON-NLS-1$
800 				Serveur.logServeur.logException ("Serveur", "getIp", e); //$NON-NLS-1$ //$NON-NLS-2$
801 			}
802 			
803 			return s;
804 		}
805 		
806 		Enumeration<NetworkInterface> interfaces = null;
807 		
808 		try {
809 			interfaces = NetworkInterface.getNetworkInterfaces();
810 			int i = 0;
811 			
812 			while (interfaces.hasMoreElements ()) {
813 				NetworkInterface currentInterface = interfaces.nextElement ();
814 				Enumeration<InetAddress> addresses = currentInterface.getInetAddresses ();
815 				
816 				while (addresses.hasMoreElements ()) {
817 					i++;
818 					InetAddress currentAddress = addresses.nextElement ();
819 					
820 					if (i == 3) {
821 						s = currentAddress.getHostAddress ().toString ();
822 					}
823 				}
824 			}
825 		}
826 		catch (SocketException e) {
827 			Serveur.logServeur.logMessage ("Problème d'entrée sortie"); //$NON-NLS-1$
828 			Serveur.logServeur.logException ("Serveur", "getIp", e); //$NON-NLS-1$ //$NON-NLS-2$
829 		}
830 		
831 		return s;
832 	}
833 
834 	/**
835 	 * <p>
836 	 * Renvoie la liste des canaux du serveur.
837 	 * </p>
838 	 * 
839 	 * @return La liste des canaux.
840 	 */
841 	public ArrayList<Canal> getListeCanaux () {
842 		return this.listeCanaux;
843 	}
844 
845 	/**
846 	 * <p>
847 	 * Connaître les informations concernant un utilisateur du serveur.
848 	 * </p>
849 	 * 
850 	 * @param login
851 	 *            Login de l'utilisateur dont on veut connaître les information.
852 	 * @return Les information de l'utilisateur.
853 	 * @throws LoginIntrouvableException
854 	 *             Le login est introuvable.
855 	 */
856 	public String informationMembre (final String login) throws LoginIntrouvableException {
857 		final int i = this.chercherUtilisateur (login);
858 
859 		if (i != -1) {
860 			return login + GestionnaireConnexion.CR + this.listeGestionnaire.get (i).infoCanaux ();
861 		}
862 		throw new LoginIntrouvableException (login + " n'est pas connecté"); //$NON-NLS-1$
863 	}
864 
865 	/**
866 	 * <p>
867 	 * Initialise le serveur
868 	 * </p>
869 	 * 
870 	 * @throws IOException
871 	 *             Un envoie à un client a échoué.
872 	 */
873 	public void initialiser () throws IOException {
874 		this.socket.setReuseAddress (true);
875 		this.nbGC = 0;
876 		this.nbCanaux = 0;
877 		this.listeGestionnaire = null;
878 		this.listeCanaux = null;
879 		this.listeGestionnaire = new ArrayList<GestionnaireConnexion> (Serveur.CONNEXION_MAX);
880 		this.listeCanaux = new ArrayList<Canal> (Serveur.CANAUX_MAX);
881 		this.conn = null;
882 		this.lance = false;
883 
884 		for (int i = 0;i < Serveur.CONNEXION_MAX;i++) {
885 			this.listeGestionnaire.add (new GestionnaireConnexion ());
886 		}
887 		for (int i = 0;i < Serveur.CANAUX_MAX;i++) {
888 			this.listeCanaux.add (new Canal ());
889 		}
890 	}
891 	
892 	/**
893 	 * <p>
894 	 * Renvoi un booleen pour savoir si le poste est connecté ou non à internet.
895 	 * </p>
896 	 * 
897 	 * @return Si le poste est connecté ou non à internet.
898 	 */
899 	public static boolean isConnecteInternet ()
900     {
901 		try {
902 			URL url = new URL ("http://www.google.com"); //$NON-NLS-1$
903             HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection ();
904             Object objData = urlConnect.getContent ();
905             objData.toString ();
906         }
907 		catch (MalformedURLException e) {
908 			Serveur.logServeur.logMessage ("URL mal formée"); //$NON-NLS-1$
909 			Serveur.logServeur.logException ("Serveur", "isConnecteInternet", e); //$NON-NLS-1$ //$NON-NLS-2$
910 			
911 			return false;
912 		}
913         catch (IOException e) {
914         	Serveur.logServeur.logMessage ("Non connecté à internet"); //$NON-NLS-1$
915 			Serveur.logServeur.logException ("Serveur", "isConnecteInternet", e); //$NON-NLS-1$ //$NON-NLS-2$
916 			
917             return false;
918         }
919             
920         return true;
921     }
922 
923 
924 	/**
925 	 * <p>
926 	 * Lance le serveur.
927 	 * </p>
928 	 * 
929 	 * @throws ClassNotFoundException
930 	 *             Classe introuvable.
931 	 * @throws RuntimeException
932 	 *             Erreur lors de l'exécution.
933 	 */
934 	public void lancer () throws ClassNotFoundException, RuntimeException {
935 		this.lance = true;
936 		Serveur.logServeur.logMessage ("Lancement du serveur"); //$NON-NLS-1$
937 
938 		try {
939 			this.connexion ();
940 		}
941 		catch (final ClassNotFoundException e) {
942 			this.lance = false;
943 			throw e;
944 		}
945 		while (this.lance) {
946 			Socket clientSocket = null;
947 
948 			try {
949 				clientSocket = this.socket.accept ();
950 				Serveur.configuration (this.nbGC, this.nbCanaux);
951 
952 				Serveur.logCoDeco.logMessage ("Connexion de " + clientSocket.getInetAddress ().toString ().substring (1)); //$NON-NLS-1$
953 			}
954 			catch (final IOException e) {
955 				if (this.lance) {
956 					Serveur.logServeur.logMessage ("Connexion echoue sur le port: 8888"); //$NON-NLS-1$
957 					Serveur.logServeur.logException ("Serveur", "lancer", e); //$NON-NLS-1$ //$NON-NLS-2$
958 				}
959 			}
960 			if (this.lance) {
961 				if (this.nbGC == Serveur.CONNEXION_MAX) {
962 					GestionnaireConnexion gc = new GestionnaireConnexion ();
963 					gc.initialisationGestionnaire (clientSocket, this, 0);
964 					final Thread t = new Thread (gc);
965 					if (t.isAlive ()) {
966 						Serveur.logCoDeco.logMessage ("Déconnexion de " + gc.getIp () + " à cause d'un trop grand nombre de connectés"); //$NON-NLS-1$ //$NON-NLS-2$
967 						gc.stopper (Serveur.MSG_CONNEXION_MAX);
968 						gc = null;
969 					}
970 				}
971 				else {
972 					this.ajouterGC (clientSocket);
973 				}
974 			}
975 		}
976 	}
977 
978 	/**
979 	 * <p>
980 	 * Lister les canaux du serveur afin de connaître leur sujet et leur nombre
981 	 * d'utilisateur.
982 	 * </p>
983 	 * 
984 	 * @param nomCanal
985 	 *            Nom du canal à lister (optionnel).
986 	 * @return Les informations sur le(s) canal (ou canaux).
987 	 * @throws CanalInexistantException
988 	 *             Le canal n'existe pas.
989 	 */
990 	public String listerCanaux (final String nomCanal) throws CanalInexistantException {
991 		final StringBuffer res = new StringBuffer ();
992 		boolean trouve = false;
993 		int i = 0;
994 
995 		if (!nomCanal.equals ("")) { //$NON-NLS-1$
996 			while (i < this.listeCanaux.size ()) {
997 				if (!this.listeCanaux.get (i).estVide ()) {
998 					if (this.listeCanaux.get (i).getNom ().equals (nomCanal)) {
999 						trouve = true;
1000 						break;
1001 					}
1002 				}
1003 				i++;
1004 			}
1005 			if (trouve) {
1006 				res.append (this.listeCanaux.get (i).getSignature ());
1007 			}
1008 			else {
1009 				throw new CanalInexistantException ();
1010 			}
1011 		}
1012 		else {
1013 			int k = 0;
1014 
1015 			for (int j = 0;j < this.listeCanaux.size ();j++) {
1016 				if (!this.listeCanaux.get (j).estVide ()) {
1017 					res.append (this.listeCanaux.get (j).getSignature ());
1018 					if (k != this.nbCanaux - 1) {
1019 						res.append (GestionnaireConnexion.CR);
1020 					}
1021 					k++;
1022 				}
1023 			}
1024 		}
1025 
1026 		return res.toString ();
1027 	}
1028 
1029 	/**
1030 	 * <p>
1031 	 * Lister les membres d'un canal.
1032 	 * </p>
1033 	 * 
1034 	 * @param nom_canal
1035 	 *            Nom du canal ou se situe les membres.
1036 	 * @return Les informations sur les membres du canal.
1037 	 */
1038 	public String listerMembres (final String nom_canal) {
1039 		final Canal canal = this.listeCanaux.get (this.canalExistant (nom_canal));
1040 
1041 		return canal.listerMembre ();
1042 	}
1043 
1044 	/**
1045 	 * <p>
1046 	 * Liste les utilisateurs du serveur.
1047 	 * </p>
1048 	 * 
1049 	 * @return Les utilisateurs du serveur.
1050 	 */
1051 	public String listerServeur () {
1052 		final StringBuffer res = new StringBuffer ();
1053 		int k = 0;
1054 		boolean isNull = false;
1055 
1056 		for (int i = 0;i < this.listeGestionnaire.size ();i++) {
1057 			if (!this.listeGestionnaire.get (i).estVide ()) {
1058 				if (this.listeGestionnaire.get (i).getClient ().getLogin () != null) {
1059 					isNull = true;
1060 					if ((k != this.nbGC) && isNull && (k != 0)) {
1061 						res.append (GestionnaireConnexion.CR);
1062 					}
1063 					res.append (this.listeGestionnaire.get (i).getClient ().getLogin () + " " + this.listeGestionnaire.get (i).getIp ()); //$NON-NLS-1$
1064 				}
1065 
1066 				k++;
1067 			}
1068 		}
1069 
1070 		return res.toString ();
1071 	}
1072 
1073 	/**
1074 	 * <p>
1075 	 * Encrypte une chaîne de caractère avec un cryptage MD5.
1076 	 * </p>
1077 	 * 
1078 	 * @param key
1079 	 *            La chaîne qui doit être encryptée.
1080 	 *            
1081 	 * @return La chaîne encryptée.
1082 	 * 
1083 	 * @throws NoSuchAlgorithmException
1084 	 *             L'algorithme MD5 n'a pas été trouvé.
1085 	 */
1086 	private String md5 (final String key) throws NoSuchAlgorithmException {
1087 		final byte[] uniqueKey = key.getBytes ();
1088 		byte[] hash = null;
1089 		hash = MessageDigest.getInstance ("MD5").digest (uniqueKey); //$NON-NLS-1$
1090 		final StringBuffer hashString = new StringBuffer ();
1091 
1092 		for (int i = 0;i < hash.length;++i) {
1093 			final String hex = Integer.toHexString (hash[i]);
1094 
1095 			if (hex.length () == 1) {
1096 				hashString.append ('0');
1097 				hashString.append (hex.charAt (hex.length () - 1));
1098 			}
1099 			else {
1100 				hashString.append (hex.substring (hex.length () - 2));
1101 			}
1102 		}
1103 
1104 		return hashString.toString ();
1105 	}
1106 
1107 	/**
1108 	 * <p>
1109 	 * Renvoie la première case vide d'une liste.
1110 	 * </p>
1111 	 * 
1112 	 * @param liste
1113 	 *            Liste dont ont veut connaître la première case vide.
1114 	 * @return L'emplacement de la première case vide.
1115 	 */
1116 	private int premierNull (final ArrayList<? extends Vide> liste) {
1117 		int res = -1;
1118 
1119 		for (int i = 0;i < liste.size ();i++) {
1120 			if (liste.get (i).estVide ()) {
1121 				res = i;
1122 				break;
1123 			}
1124 		}
1125 
1126 		return res;
1127 	}
1128 
1129 	/**
1130 	 * <p>
1131 	 * Relancer le serveur.
1132 	 * </p>
1133 	 * 
1134 	 * @param message
1135 	 *            Le message à envoyer à tous les client avant le reboot du
1136 	 *            serveur.
1137 	 * @throws IOException
1138 	 *             Un envoie à un client a échoué.
1139 	 * @throws RuntimeException
1140 	 *             Erreur d'exécution.
1141 	 */
1142 	public void relancerServeur (final String message) throws IOException, RuntimeException {
1143 		for (int i = 0;i < this.listeGestionnaire.size ();i++) {
1144 			if (!this.listeGestionnaire.get (i).estVide ()) {
1145 				this.listeGestionnaire.get (i).setLance (false);
1146 				this.listeGestionnaire.get (i).stopper (message);
1147 			}
1148 			this.listeGestionnaire.remove (i);
1149 		}
1150 		for (int i = 0;i < this.listeCanaux.size ();i++) {
1151 			if (!this.listeCanaux.get (i).estVide ()) {
1152 				this.listeCanaux.get (i).vider ();
1153 			}
1154 			this.listeCanaux.remove (i);
1155 		}
1156 		Serveur.logServeur.logMessage ("Relancement du serveur"); //$NON-NLS-1$
1157 		this.initialiser ();
1158 		try {
1159 			this.lancer ();
1160 		}
1161 		catch (final ClassNotFoundException e) {
1162 			Serveur.logServeur.logException ("Serveur", "relancerServeur", e); //$NON-NLS-1$ //$NON-NLS-2$
1163 			throw new RuntimeException ();
1164 		}
1165 	}
1166 	
1167 	/**
1168 	 * <p>
1169 	 * Renvoi le MOTD
1170 	 * </p>
1171 	 * 
1172 	 * @return Le MOTD
1173 	 */
1174 	public String requeteMOTD () {
1175 		Serveur.configuration (this.nbGC, this.nbCanaux);
1176 		
1177 		return Serveur.MOTD;
1178 	}
1179 
1180 	/**
1181 	 * <p>
1182 	 * Arrête le serveur.
1183 	 * </p>
1184 	 * 
1185 	 * @param message
1186 	 *            Le message à envoyer aux clients, avant l'arrêt du serveur.
1187 	 *            
1188 	 * @throws IOException
1189 	 *             Un envoie à un client a échoué.
1190 	 */
1191 	public void stopperServeur (final String message) throws IOException {
1192 		for (int i = 0;i < this.listeGestionnaire.size ();i++) {
1193 			if (!this.listeGestionnaire.get (i).estVide ()) {
1194 				this.listeGestionnaire.get (i).setLance (false);
1195 				this.listeGestionnaire.get (i).stopper (message);
1196 			}
1197 			else {
1198 				this.listeGestionnaire.remove (i);
1199 			}
1200 		}
1201 		for (int i = 0;i < this.listeCanaux.size ();i++) {
1202 			if (!this.listeCanaux.get (i).estVide ()) {
1203 				this.listeCanaux.get (i).vider ();
1204 			}
1205 			this.listeCanaux.remove (i);
1206 		}
1207 
1208 		this.nbGC = 0;
1209 		this.nbCanaux = 0;
1210 		this.listeCanaux = null;
1211 		this.listeGestionnaire = null;
1212 		this.lance = false;
1213 
1214 		try {
1215 			this.conn.close ();
1216 		}
1217 		catch (final SQLException e) {
1218 			Serveur.logServeur.logException ("Serveur", "stopperServeur", e); //$NON-NLS-1$ //$NON-NLS-2$
1219 		}
1220 		finally {
1221 			this.socket.close ();
1222 			Serveur.logServeur.logMessage ("Arrêt du serveur"); //$NON-NLS-1$
1223 			Serveur.logCanaux.fermer ();
1224 			Serveur.logCoDeco.fermer ();
1225 			Serveur.logServeur.fermer ();
1226 		}
1227 	}
1228 
1229 	/**
1230 	 * <p>
1231 	 * Supprime un canal.
1232 	 * </p>
1233 	 * 
1234 	 * @param nom
1235 	 *            Nom du canal à supprimer.
1236 	 *            
1237 	 * @throws CanalInexistantException
1238 	 *             Le canal n'existe pas.
1239 	 */
1240 	public void supprimerCanal (final String nom) throws CanalInexistantException {
1241 		final int tmp = this.canalExistant (nom);
1242 
1243 		if (tmp != -1) {
1244 			try {
1245 				this.listeCanaux.get (tmp).notifier (Evenement.SUPPRIME, null, null);
1246 			}
1247 			catch (final IOException e) {
1248 				Serveur.logServeur.logMessage ("Erreur d'entrée sortie"); //$NON-NLS-1$
1249 				Serveur.logServeur.logException ("Serveur", "supprimerCanal", e); //$NON-NLS-1$ //$NON-NLS-2$
1250 			}
1251 			this.listeCanaux.get (tmp).vider ();
1252 			this.listeCanaux.remove (tmp);
1253 			this.nbCanaux--;
1254 			Serveur.logCanaux.logMessage ("Le canal " + nom + " a été supprimé"); //$NON-NLS-1$ //$NON-NLS-2$
1255 		}
1256 		else {
1257 			throw new CanalInexistantException ();
1258 		}
1259 	}
1260 
1261 	/**
1262 	 * <p>
1263 	 * Savoir si un utilisateur existe ou non.
1264 	 * </p>
1265 	 * 
1266 	 * @param login
1267 	 *            Login de l'utilisateur.
1268 	 * @param mdp
1269 	 *            Mot de passe de l'utilisateur.
1270 	 * @param client
1271 	 *            Utilisateur qui contiendra les informations trouvées.
1272 	 *            
1273 	 * @throws SQLException
1274 	 *             Erreur de la BDD.
1275 	 * @throws IdentifierException
1276 	 *             La personne est déjà connecté.
1277 	 * @throws NoSuchAlgorithmException
1278 	 *             Algorithme du MD5 non trouvé
1279 	 */
1280 	public void verifierLoginMdp (final String login, final String mdp, final Utilisateur client) throws SQLException, IdentifierException, NoSuchAlgorithmException {
1281 		boolean bool = false;
1282 
1283 		for (int i = 0;i < this.listeGestionnaire.size ();i++) {
1284 			if (login.equals (this.listeGestionnaire.get (i).getClient ().getLogin ())) {
1285 				bool = true;
1286 			}
1287 		}
1288 		if (!bool) {
1289 			// Création d'un objet Statement
1290 			final PreparedStatement state = this.conn.prepareStatement ("SELECT * FROM utilisateurs WHERE identifiant = ? AND active = '1'"); //$NON-NLS-1$
1291 			state.setString (1, login);
1292 			// L'objet ResultSet contient le résultat de la requête SQL
1293 			final ResultSet result = state.executeQuery ();
1294 
1295 			if (!result.next () || !result.getString ("mdp").equals (this.md5 (mdp))) { //$NON-NLS-1$
1296 				result.close ();
1297 				state.close ();
1298 				throw new IdentifierException ();
1299 			}
1300 			Serveur.logCoDeco.logMessage ("Identification " + login + " reussie"); //$NON-NLS-1$ //$NON-NLS-2$
1301 			client.setLogin (login);
1302 			client.setAdministrateur (result.getInt ("droits") == 0); //$NON-NLS-1$
1303 			result.close ();
1304 			state.close ();
1305 		}
1306 		else {
1307 			throw new IdentifierException ();
1308 		}
1309 	}
1310 }