diff --git a/POO_Server/src/communication/CommunicationUDP.java b/POO_Server/src/communication/CommunicationUDP.java index aae6850..e418865 100644 --- a/POO_Server/src/communication/CommunicationUDP.java +++ b/POO_Server/src/communication/CommunicationUDP.java @@ -95,15 +95,6 @@ public class CommunicationUDP extends Thread { return null; } - private int getIndexFromIP(InetAddress ip) { - for(int i=0; i < users.size() ; i++) { - if(users.get(i).getIp().equals(ip)) { - return i; - } - } - return -1; - } - public void printActiveUsersUDP(PrintWriter out) { for (Utilisateur uIn : users) { out.println(" " + uIn.getPseudo() + ","); diff --git a/POO_Server/src/communication/UDPClient.java b/POO_Server/src/communication/UDPClient.java index e1aed10..3fd41a3 100644 --- a/POO_Server/src/communication/UDPClient.java +++ b/POO_Server/src/communication/UDPClient.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; -import java.net.NetworkInterface; +//import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; @@ -13,14 +13,14 @@ import messages.*; public class UDPClient { private DatagramSocket sockUDP; - private InetAddress broadcast; + //private InetAddress broadcast; public UDPClient(int port) throws SocketException, UnknownHostException { this.sockUDP = new DatagramSocket(port); - InetAddress localHost = InetAddress.getLocalHost(); - NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); - this.broadcast = networkInterface.getInterfaceAddresses().get(0).getBroadcast(); + //InetAddress localHost = InetAddress.getLocalHost(); + //NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); + //this.broadcast = networkInterface.getInterfaceAddresses().get(0).getBroadcast(); } diff --git a/POO_Server/src/communication/UDPServer.java b/POO_Server/src/communication/UDPServer.java index e97ff5c..4a9a60b 100644 --- a/POO_Server/src/communication/UDPServer.java +++ b/POO_Server/src/communication/UDPServer.java @@ -4,8 +4,6 @@ import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.SocketException; -import java.util.ArrayList; -import java.util.Arrays; import main.Utilisateur; import messages.*; diff --git a/POO_Server/src/main/ServletPresence.java b/POO_Server/src/main/ServletPresence.java index 0c8766e..484bbd4 100644 --- a/POO_Server/src/main/ServletPresence.java +++ b/POO_Server/src/main/ServletPresence.java @@ -6,6 +6,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; @@ -14,9 +15,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import communication.CommunicationUDP; -import database.SQLiteManager; import messages.*; -import messages.Message.TypeMessage; /** * Servlet implementation class ServletPresence @@ -30,10 +29,9 @@ public class ServletPresence extends HttpServlet implements Observer { private CommunicationUDP comUDP; private ArrayList remoteUsers; - private SQLiteManager sqlManager; - + private String[] registeredRemoteUsers = {"user1","user2","user3"}; + public ServletPresence() { - //A changer en passant aux IP try { comUDP = new CommunicationUDP(3333, 3334, new int[] {2209, 2309, 2409, 3334}); } catch (IOException e) { @@ -47,8 +45,6 @@ public class ServletPresence extends HttpServlet implements Observer { } catch (UnknownHostException e) { e.printStackTrace(); } - - sqlManager = new SQLiteManager(0); } private int getIndexByID(String id) { @@ -184,7 +180,7 @@ public class ServletPresence extends HttpServlet implements Observer { //Si l'id n'existe pas dans la BDD : génère du html pour en informer l'utilisateur try { - if (sqlManager.getIDUser(id)==-1) { + if (!Arrays.asList(registeredRemoteUsers).contains(id)) { printErrorUnkwownUser(out); } @@ -205,7 +201,7 @@ public class ServletPresence extends HttpServlet implements Observer { } printActiveUsersOnly(out); } - } catch (UnknownHostException | SQLException e) { + } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); }