fix qq trucs et encore pb
This commit is contained in:
parent
dd907d3da6
commit
26a0c1341c
26 changed files with 73 additions and 77 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -134,7 +134,7 @@ public class Agent implements PropertyChangeListener{
|
|||
switch(msg.getTypeMessage()) {
|
||||
case 0 :
|
||||
//System.out.println("Envoi message présentation");
|
||||
MessagePseudo msgPresentation = new MessagePseudo(this.localAddress, msg.getAddressSrc(), this.user.getPort(), msg.getPortSrc(), 1, this.user.getPseudo(), this.user.getId());
|
||||
MessagePseudo msgPresentation = new MessagePseudo(this.localAddress, msg.getAddressSrc(), this.user.getPort(), msg.getPortSrc(), 1, this.user.getPseudo(), this.user.getId(), "");
|
||||
BOut.send(msgPresentation, msg.getAddressSrc(), msg.getPortSrc());
|
||||
break;
|
||||
case 1 :
|
||||
|
@ -149,11 +149,12 @@ public class Agent implements PropertyChangeListener{
|
|||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
MessagePseudo messageDeconnexion = (MessagePseudo) msg;
|
||||
boolean pseudoExiste = Request.sendPseudo(messageDeconnexion.getPseudo(), "pseudoOK");
|
||||
if(!pseudoExiste){
|
||||
Request.sendDeconnexion(Integer.toString(messageDeconnexion.getId()),messageDeconnexion.getPseudo(), "deconnexion");
|
||||
if(pseudoExiste){
|
||||
//Request.sendDeconnexion(Integer.toString(messageDeconnexion.getId()),messageDeconnexion.getPseudo(), "deconnexion");
|
||||
FenetreMenu.getCb().removeItem(messageDeconnexion.getPseudo());
|
||||
|
||||
}
|
||||
|
@ -164,25 +165,26 @@ public class Agent implements PropertyChangeListener{
|
|||
if(FenetreChat.isOuvert()&&FenetreChat.getDest().getPseudo().equals(messageDeconnexion.getPseudo())) {
|
||||
FenetreChat.fermer();
|
||||
}
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
MessagePseudo messageNewPseudo = (MessagePseudo) msg;
|
||||
//Contact contact = list.findContact(messageNewPseudo.getPseudo());
|
||||
//int id = this.db.getIdFromPseudo(contact.getPseudo());
|
||||
for(int i = 0 ; i<FenetreMenu.getCb().getItemCount() ; i++){//Combo étant ton JComboBox
|
||||
String pseudo = (String) FenetreMenu.getCb().getItemAt(i);
|
||||
if(this.db.getIdFromPseudo(pseudo)==messageNewPseudo.getId()) {
|
||||
FenetreMenu.getCb().removeItem(pseudo);
|
||||
FenetreMenu.getCb().addItem(messageNewPseudo.getPseudo());
|
||||
}
|
||||
}
|
||||
FenetreMenu.getCb().removeItem(messageNewPseudo.getPseudo());
|
||||
String pseudo = (String) FenetreMenu.getCb().getItemAt(i);
|
||||
if(pseudo.equals(messageNewPseudo.getAncienPseudo())) {
|
||||
FenetreMenu.getCb().removeItem(pseudo);
|
||||
FenetreMenu.getCb().addItem(messageNewPseudo.getPseudo());
|
||||
}
|
||||
}
|
||||
//FenetreMenu.getCb().removeItem(messageNewPseudo.getPseudo());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean connectInscription(String pseudo, String login) throws IOException, InterruptedException {
|
||||
MessagePseudo msg_connexion = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 0, "", this.user.getId());
|
||||
MessagePseudo msg_connexion = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 0, "", this.user.getId(), "");
|
||||
BOut.send(msg_connexion, this.broadcast, App.portDest);
|
||||
Thread.sleep(2000);
|
||||
ArrayList<MessagePseudo> msg_recus = BIn.getListMessage();
|
||||
|
@ -197,7 +199,7 @@ public class Agent implements PropertyChangeListener{
|
|||
Request.sendUser(pseudo, this.localAddress.toString(), Integer.toString(App.portSrc), "addUser");
|
||||
int id = db.addUser(pseudo, login);
|
||||
this.user.setId(id);
|
||||
MessagePseudo msgPresentation = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 1, this.user.getPseudo(), this.user.getId());
|
||||
MessagePseudo msgPresentation = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 1, this.user.getPseudo(), this.user.getId(), "");
|
||||
BOut.send(msgPresentation, this.broadcast, App.portDest);
|
||||
this.user.setStatut("En ligne");
|
||||
//System.out.println("Connexion réussie avec le pseudo : "+pseudo);
|
||||
|
@ -208,7 +210,7 @@ public class Agent implements PropertyChangeListener{
|
|||
}
|
||||
|
||||
public boolean connectConnexion(String pseudo, String login) throws IOException, InterruptedException {
|
||||
MessagePseudo msg_connexion = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 0, "", this.user.getId());
|
||||
MessagePseudo msg_connexion = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 0, "", this.user.getId(), "");
|
||||
BOut.send(msg_connexion, this.broadcast, App.portDest);
|
||||
Thread.sleep(2000);
|
||||
ArrayList<MessagePseudo> msg_recus = BIn.getListMessage();
|
||||
|
@ -221,7 +223,7 @@ public class Agent implements PropertyChangeListener{
|
|||
Request.sendUser(pseudo, this.localAddress.toString(), Integer.toString(App.portSrc), "addUser");
|
||||
int id = db.getIdFromLogin(login);
|
||||
this.user.setId(id);
|
||||
MessagePseudo msgPresentation = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 1, this.user.getPseudo(), this.user.getId());
|
||||
MessagePseudo msgPresentation = new MessagePseudo(this.localAddress, this.broadcast, this.user.getPort(), App.portDest, 1, this.user.getPseudo(), this.user.getId(), "");
|
||||
BOut.send(msgPresentation, this.broadcast, App.portDest);
|
||||
db.updateStatus(id, "En ligne");
|
||||
this.user.setStatut("En ligne");
|
||||
|
@ -247,8 +249,12 @@ public class Agent implements PropertyChangeListener{
|
|||
|
||||
public void deconnexion() throws IOException {
|
||||
Request.sendDeconnexion(Integer.toString(this.user.getId()),this.user.getPseudo(), "deconnexion");
|
||||
MessagePseudo msgDeconnexion = new MessagePseudo(this.localAddress, this.broadcast, App.portSrc, App.portDest, 2, this.user.getPseudo(), this.user.getId());
|
||||
MessagePseudo msgDeconnexion = new MessagePseudo(this.localAddress, this.broadcast, App.portSrc, App.portDest, 2, this.user.getPseudo(), this.user.getId(), "");
|
||||
BOut.send(msgDeconnexion, this.broadcast, App.portSrc);
|
||||
this.BIn.interrupt();
|
||||
this.BOut.getSocket().close();
|
||||
//this.server.getSocket().close();
|
||||
this.server.interrupt();
|
||||
//list.deleteContact(user);
|
||||
System.exit(1);
|
||||
}
|
||||
|
@ -261,7 +267,7 @@ public class Agent implements PropertyChangeListener{
|
|||
db.updatePseudo(this.user.getId(), pseudo);
|
||||
//list.modifierListe(ancienPseudo, pseudo);
|
||||
Request.sendPseudoChange(ancienPseudo, pseudo, "pseudoChanged");
|
||||
MessagePseudo msgNewPseudo = new MessagePseudo(this.localAddress, this.broadcast, App.portSrc, App.portDest, 3, pseudo, this.user.getId());
|
||||
MessagePseudo msgNewPseudo = new MessagePseudo(this.localAddress, this.broadcast, App.portSrc, App.portDest, 3, pseudo, this.user.getId(), ancienPseudo);
|
||||
BOut.send(msgNewPseudo, this.broadcast, App.portSrc);
|
||||
return true;
|
||||
}else {
|
||||
|
|
|
@ -4,8 +4,6 @@ import java.sql.*;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import model.MessageAffichage;
|
||||
//import model.MessageAffichage;
|
||||
import model.MessageChat;
|
||||
|
||||
public class DataBase {
|
||||
|
||||
|
@ -201,7 +199,7 @@ public class DataBase {
|
|||
"idSrc INT NOT NULL,\n" +
|
||||
"idDest INT NOT NULL,\n" +
|
||||
"message MEDIUMTEXT NOT NULL,\n" +
|
||||
"date_heure DATETIME NOT NULL\n" +
|
||||
"date_heure TIMESTAMP NOT NULL\n" +
|
||||
");";
|
||||
PreparedStatement pStat = null;
|
||||
try {
|
||||
|
@ -285,8 +283,8 @@ public class DataBase {
|
|||
return result;
|
||||
}
|
||||
|
||||
public Date getDateFromMessage(int id1, int id2, String message) {
|
||||
Date date = null;
|
||||
public Timestamp getDateFromMessage(int id1, int id2, String message) {
|
||||
Timestamp date = null;
|
||||
int idSrc = id1;
|
||||
int idDest = id2;
|
||||
if(id1>id2) {
|
||||
|
@ -301,7 +299,7 @@ public class DataBase {
|
|||
pStat.setString(1, message);
|
||||
ResultSet resPseudo = pStat.executeQuery();
|
||||
if(resPseudo.first()) {
|
||||
date = resPseudo.getDate("date_heure");
|
||||
date = resPseudo.getTimestamp("date_heure");
|
||||
}
|
||||
}catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -15,8 +15,6 @@ import javax.swing.JTextField;
|
|||
import javax.swing.SwingConstants;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.io.IOException;
|
||||
|
||||
import controller.*;
|
||||
|
@ -31,7 +29,7 @@ public class FenetreConnexion implements ActionListener {
|
|||
JLabel Text;
|
||||
JButton Connexion;
|
||||
JButton Cancel;
|
||||
|
||||
|
||||
/*
|
||||
* Constructeur d'une fenetre d'affichage pour la connexion d'un utilisateur.
|
||||
* Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo.
|
||||
|
@ -70,6 +68,7 @@ public class FenetreConnexion implements ActionListener {
|
|||
this.Cancel.addActionListener(this);
|
||||
//On associe au bouton Connexion des actions a realiser
|
||||
this.Connexion.addActionListener(this);
|
||||
this.Connexion.setSelected(false);
|
||||
// On ajouter les differents elements au panel
|
||||
panel.add(pseudofield);
|
||||
panel.add(Text);
|
||||
|
@ -86,22 +85,41 @@ public class FenetreConnexion implements ActionListener {
|
|||
String login = pseudofield.getText();
|
||||
|
||||
boolean loginExiste = false;
|
||||
try {
|
||||
boolean loginEstActif = false;
|
||||
try {
|
||||
loginExiste = Request.sendLogin(login, "loginExiste");
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Pb envoi requete au serveur");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
loginEstActif = Request.sendLogin(login, "estActif");
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if(!loginExiste) {
|
||||
JOptionPane.showMessageDialog(frame, "This login doesn't exist") ;
|
||||
if(!Connexion.isSelected()) {
|
||||
JOptionPane.showMessageDialog(frame, "This login doesn't exist", "Error", JOptionPane.WARNING_MESSAGE) ;
|
||||
Connexion.setSelected(true);
|
||||
frame.dispose();
|
||||
new FenetreConnexion();
|
||||
}
|
||||
}else if(loginEstActif){
|
||||
if(!Connexion.isSelected()) {
|
||||
JOptionPane.showMessageDialog(frame, "This login is used by an active user", "Error", JOptionPane.WARNING_MESSAGE) ;
|
||||
Connexion.setSelected(true);
|
||||
frame.dispose();
|
||||
new FenetreConnexion();
|
||||
}
|
||||
}else {
|
||||
// On crée un objet de type ChatApp
|
||||
Agent agent;
|
||||
boolean connexion;
|
||||
|
||||
try {
|
||||
|
||||
agent = new Agent(Tools.getAdress()[0], App.portSrc, App.portDest, login);
|
||||
String pseudo = agent.getDb().getPseudoFromLogin(login);
|
||||
// on tente une connexion avec ce pseudo
|
||||
|
|
|
@ -87,7 +87,7 @@ public class FenetreModifPseudo implements ActionListener {
|
|||
frame.dispose();
|
||||
new FenetreMenu(agent);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(frame, "Pseudo already, use choose another one");
|
||||
JOptionPane.showMessageDialog(frame, "Pseudo already use, choose another one");
|
||||
}
|
||||
} catch (HeadlessException e1) {
|
||||
e1.printStackTrace();
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB |
|
@ -1,26 +0,0 @@
|
|||
package model;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class MessageDeconnexion extends Message{
|
||||
private String msg;
|
||||
private String pseudo;
|
||||
|
||||
public MessageDeconnexion(InetAddress addressSrc, InetAddress addressDest, int portSrc, int portDest, int typeMessage, String pseudo) {
|
||||
super(addressSrc, addressDest, portSrc, portDest, typeMessage);
|
||||
this.pseudo = pseudo;
|
||||
this.msg = "Deconnexion";
|
||||
}
|
||||
|
||||
public String getPseudo() {
|
||||
return pseudo;
|
||||
}
|
||||
|
||||
public void setPseudo(String pseudo) {
|
||||
this.pseudo = pseudo;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
|
@ -6,11 +6,13 @@ public class MessagePseudo extends Message{
|
|||
|
||||
private String pseudo;
|
||||
private int id;
|
||||
private String ancienPseudo;
|
||||
|
||||
public MessagePseudo(InetAddress addressSrc, InetAddress addressDest, int portSrc, int portDest, int typeMessage,String pseudo, int id) {
|
||||
public MessagePseudo(InetAddress addressSrc, InetAddress addressDest, int portSrc, int portDest, int typeMessage,String pseudo, int id, String ancienPseudo) {
|
||||
super(addressSrc, addressDest, portSrc, portDest, typeMessage);
|
||||
this.pseudo = pseudo;
|
||||
this.id = id;
|
||||
this.ancienPseudo=ancienPseudo;
|
||||
}
|
||||
|
||||
public String getPseudo() {
|
||||
|
@ -28,6 +30,14 @@ public class MessagePseudo extends Message{
|
|||
public void setId(int id) {
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
public String getAncienPseudo() {
|
||||
return ancienPseudo;
|
||||
}
|
||||
|
||||
public void setAncienPseudo(String ancienPseudo) {
|
||||
this.ancienPseudo = ancienPseudo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -58,4 +58,8 @@ public class TCPServer extends Thread{
|
|||
public TCPChat getConnexionTCPChat() {
|
||||
return this.listeConnexions.remove(0);
|
||||
}
|
||||
|
||||
public ServerSocket getSocket() {
|
||||
return this.socket;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,11 @@ public class UDPOutput {
|
|||
System.out.println("Message envoyé, pseudo = "+msg.getPseudo()+" et num port destination = "+portSrc+"\n");
|
||||
}
|
||||
|
||||
public void send(MessageDeconnexion msg, InetAddress addressDest, int portSrc) throws IOException {
|
||||
public DatagramSocket getSocket() {
|
||||
return this.socket;
|
||||
}
|
||||
|
||||
/*public void send(MessageChangePseudo msg, InetAddress addressDest, int portSrc) throws IOException {
|
||||
byte[] buffer = "".getBytes();
|
||||
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
|
||||
|
@ -43,8 +47,8 @@ public class UDPOutput {
|
|||
buffer = byteOutStream.toByteArray();
|
||||
DatagramPacket packet = new DatagramPacket(buffer,buffer.length,msg.getAddressDest(),msg.getPortDest());
|
||||
this.socket.send(packet);
|
||||
System.out.println("Message envoyé, pseudo = "+msg.getMsg()+" et num port destination = "+portSrc+"\n");
|
||||
}
|
||||
System.out.println("Message envoyé, pseudo = "+msg.getPseudo()+" et num port destination = "+portSrc+"\n");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package server;
|
||||
|
||||
import network.TCPChat;
|
||||
|
||||
public class Server {
|
||||
private final String path;
|
||||
private final int port;
|
||||
private TCPChat serverConnection;
|
||||
|
||||
public Server(String path, int port) {
|
||||
this.path=path;
|
||||
this.port=port;
|
||||
}
|
||||
|
||||
public void suscribe() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue