This commit is contained in:
LMAGallois 2020-12-15 22:14:13 +01:00
parent 27d44abacf
commit e19bc4b45c
2 changed files with 25 additions and 9 deletions

View file

@ -10,6 +10,7 @@ import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -29,7 +30,7 @@ public class Controller {
private ListeningThreadUDP udp_connect_thread; private ListeningThreadUDP udp_connect_thread;
private ListeningThreadTCPConnection tcp_connect_thread; private ListeningThreadTCPConnection tcp_connect_thread;
private ArrayList<ListeningThreadTCPChat> tcp_chats_threads = new ArrayList<ListeningThreadTCPChat>(); // listes des utilisateurs actifs private ArrayList<ListeningThreadTCPChat> tcp_chats_threads = new ArrayList<ListeningThreadTCPChat>(); // listes des utilisateurs actifs
private Historique histoire;
/** /**
* Constructor of Controller * Constructor of Controller
* @parametres * @parametres
@ -45,7 +46,8 @@ public class Controller {
* - notification aux autres utilisateurs actifs * - notification aux autres utilisateurs actifs
* </p> * </p>
*/ */
private Controller(int portUDPsend,int portUDPlistening,int portTCP) { private Controller(int portUDPsend,int portUDPlistening,int portTCP,Historique histoire) {
this.histoire=histoire;
InetAddress addIP = null; InetAddress addIP = null;
try try
{ {
@ -88,7 +90,8 @@ public class Controller {
* - notification aux autres utilisateurs actifs * - notification aux autres utilisateurs actifs
* </p> * </p>
*/ */
private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo) { private Controller(int portUDPsend,int portUDPlistening,int portTCP,String pseudo,Historique histoire) {
this.histoire=histoire;
InetAddress addIP = null; InetAddress addIP = null;
try try
{ {
@ -127,7 +130,9 @@ public class Controller {
public ArrayList<ListeningThreadTCPChat> getTcp_chats_threads() { public ArrayList<ListeningThreadTCPChat> getTcp_chats_threads() {
return tcp_chats_threads; return tcp_chats_threads;
} }
public Historique getHistory() {
return histoire;
}
/*** SETTERS ***/ /*** SETTERS ***/
public void setMyUser(LocalUser myUser) { public void setMyUser(LocalUser myUser) {
this.myUser = myUser; this.myUser = myUser;
@ -144,7 +149,9 @@ public class Controller {
public void setTcp_chats_threads(ArrayList<ListeningThreadTCPChat> tcp_chats_threads) { public void setTcp_chats_threads(ArrayList<ListeningThreadTCPChat> tcp_chats_threads) {
this.tcp_chats_threads = tcp_chats_threads; this.tcp_chats_threads = tcp_chats_threads;
} }
public void setHistory(Historique histoire) {
this.histoire=histoire;
}
/** /**
@ -347,10 +354,18 @@ public class Controller {
e.printStackTrace(); e.printStackTrace();
} }
String input; String input;
String dateString;
Date date;
Calendar date1=Calendar.getInstance();
String s2 = (this.myUser.getPseudo()+" reçoit un message"); String s2 = (this.myUser.getPseudo()+" reçoit un message");
try { try {
while (!(input=in.readLine()).equals("end")) { while (!(input=in.readLine()).equals("end")) {
System.out.print("client_recoit:"+input); System.out.print("client_recoit:"+input);
date=new Date();
date1.setTime(date);
dateString=date1.toString();
this.getHistory().saveMessage(this.getMyUser(), getMyUser().getRemoteUsersList().get(index),input ,dateString );
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -424,9 +439,10 @@ public class Controller {
/*************************************************************************************************************************/ /*************************************************************************************************************************/
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
Controller ctr2 = new Controller(12226,portUDPlistening_remoteUsr2,22222,"Mike"); Historique histoire=new Historique();
Controller ctr3 = new Controller(12224,portUDPlistening_remoteUsr3,22223,"Alice"); Controller ctr2 = new Controller(12226,portUDPlistening_remoteUsr2,22222,"Mike",histoire);
Controller ctr1 = new Controller(12225,20001,22221); // Notre utilisateur local Controller ctr3 = new Controller(12224,portUDPlistening_remoteUsr3,22223,"Alice",histoire);
Controller ctr1 = new Controller(12225,20001,22221,histoire); // Notre utilisateur local
// Création de l'interface // Création de l'interface
ctr1.hisView=Interface.createAndShowGUI(ctr1); ctr1.hisView=Interface.createAndShowGUI(ctr1);

View file

@ -62,7 +62,7 @@ public class Historique {
} }
} }
public String retrieveMessage(model.User user1, model.RemoteUser user2) throws SQLException { public String retrieveMessage(model.LocalUser user1, model.RemoteUser user2) throws SQLException {
this.setRSSent(this.bdd.getStatement().executeQuery("SELECT"+user1.getIPcode()+","+user2.getIPcode()+",? ,? FROM table")); this.setRSSent(this.bdd.getStatement().executeQuery("SELECT"+user1.getIPcode()+","+user2.getIPcode()+",? ,? FROM table"));
this.setRSReceived(this.bdd.getStatement().executeQuery("SELECT"+user2.getIPcode()+","+user1.getIPcode()+",?, ? FROM table")); this.setRSReceived(this.bdd.getStatement().executeQuery("SELECT"+user2.getIPcode()+","+user1.getIPcode()+",?, ? FROM table"));
//this.setRSMDSent(this.getRSSent().getMetaData()); //this.setRSMDSent(this.getRSSent().getMetaData());