Connexion vers locale terminée
This commit is contained in:
parent
69392477dd
commit
54999b3184
8 changed files with 161 additions and 113 deletions
|
@ -1,5 +1,6 @@
|
||||||
package communication;
|
package communication;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -39,35 +40,20 @@ public class Communication extends Thread{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
protected static synchronized void addUser(String idClient, String pseudoClient, InetAddress ipClient) throws UnknownHostException {
|
||||||
//Combiner add et change
|
Communication.users.add(new Utilisateur(idClient, pseudoClient, ipClient));
|
||||||
protected static synchronized void addUser(List<String> datas) throws UnknownHostException {
|
/*VueStandard.userList.addElement(pseudoClient);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static synchronized void changePseudoUser(String idClient, String pseudoClient, InetAddress ipClient) {
|
||||||
|
int index = Communication.getIndexFromID(idClient);
|
||||||
|
Communication.users.get(index).setPseudo(pseudoClient);
|
||||||
|
/*VueStandard.userList.set(index, pseudoClient);*/
|
||||||
|
}
|
||||||
|
|
||||||
String idClient = datas.get(0);
|
|
||||||
String pseudoClient = datas.get(1);
|
|
||||||
String clientAddress = datas.get(2);
|
|
||||||
|
|
||||||
if (!Communication.containsUserFromID(idClient)) {
|
|
||||||
Communication.users.add(new Utilisateur(idClient, pseudoClient, clientAddress));
|
|
||||||
/*VueStandard.userList.addElement(pseudoClient);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static synchronized void changePseudoUser(List<String> datas) {
|
protected static synchronized void removeUser(String idClient, String pseudoClient, InetAddress ipClient) {
|
||||||
String idClient = datas.get(0);
|
|
||||||
String pseudoClient = datas.get(1);
|
|
||||||
int index = Communication.getIndexFromID(idClient);
|
int index = Communication.getIndexFromID(idClient);
|
||||||
System.out.println(index);
|
|
||||||
if(index != -1) {
|
|
||||||
Communication.users.get(index).setPseudo(pseudoClient);
|
|
||||||
/*VueStandard.userList.set(index, pseudoClient);*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static synchronized void removeUser(List<String> datas) {
|
|
||||||
String idClient = datas.get(0);
|
|
||||||
int index = Communication.getIndexFromID(idClient);
|
|
||||||
System.out.println(index);
|
|
||||||
if( index != -1) {
|
if( index != -1) {
|
||||||
Communication.users.remove(index);
|
Communication.users.remove(index);
|
||||||
/*VueStandard.userList.remove(index);*/
|
/*VueStandard.userList.remove(index);*/
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import main.Utilisateur;
|
import main.Utilisateur;
|
||||||
|
import messages.*;
|
||||||
|
|
||||||
|
|
||||||
public class CommunicationUDP extends Communication {
|
public class CommunicationUDP extends Communication {
|
||||||
|
|
||||||
|
@ -36,64 +38,53 @@ public class CommunicationUDP extends Communication {
|
||||||
|
|
||||||
public void sendMessageConnecte() throws UnknownHostException, IOException {
|
public void sendMessageConnecte() throws UnknownHostException, IOException {
|
||||||
for(int port : this.portOthers) {
|
for(int port : this.portOthers) {
|
||||||
this.client.sendMessageUDP_local("first_connection", port, InetAddress.getLocalHost());
|
try {
|
||||||
|
this.client.sendMessageUDP_local(new MessageSysteme(Message.TypeMessage.JE_SUIS_CONNECTE), port, InetAddress.getLocalHost());
|
||||||
|
} catch (MauvaisTypeMessageException e) {/*Si ça marche pas essayer là*/}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send the message "add,id,pseudo" to localhost on all the ports in
|
// Send the message "add,id,pseudo" to localhost on all the ports in
|
||||||
// "portOthers"
|
// "portOthers"
|
||||||
// This allows the receivers' agent (portOthers) to create an entry with the
|
// This allows the receivers' agent (portOthers) to create or modify an entry with the
|
||||||
// data of this agent
|
// data of this agent
|
||||||
public void sendMessageAdd() throws UnknownHostException, IOException {
|
//Typically used to notify of a name change
|
||||||
this.sendIDPseudo_local("add");
|
public void sendMessageInfoPseudo() throws UnknownHostException, IOException {
|
||||||
|
Utilisateur self = Utilisateur.getSelf();
|
||||||
|
for(int port : this.portOthers) {
|
||||||
|
try {
|
||||||
|
String pseudoSelf =self.getPseudo();
|
||||||
|
String idSelf = self.getId();
|
||||||
|
Message msout = new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, pseudoSelf, idSelf);
|
||||||
|
this.client.sendMessageUDP_local(msout, port, InetAddress.getLocalHost());
|
||||||
|
} catch (Exception e) {e.printStackTrace();}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Same, but on only one port
|
||||||
|
//Typically used to give your current name and id to a newly arrived host
|
||||||
|
public void sendMessageInfoPseudo(int portOther) throws UnknownHostException, IOException {
|
||||||
|
Utilisateur self = Utilisateur.getSelf();
|
||||||
|
try {
|
||||||
|
this.client.sendMessageUDP_local(new MessageSysteme(Message.TypeMessage.INFO_PSEUDO, self.getPseudo(), self.getId()), portOther, InetAddress.getLocalHost());
|
||||||
|
} catch (MauvaisTypeMessageException e) {/*Si ça marche pas essayer là*/}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageAdd(ArrayList<Integer> portServers) throws UnknownHostException, IOException {
|
|
||||||
this.sendIDPseudo_local("add", portServers);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the message "modify,id,pseudo" to localhost on all the ports in
|
|
||||||
// "portOthers"
|
|
||||||
// This allows the receivers' agent (portOthers) to update the entry
|
|
||||||
// corresponding to this agent
|
|
||||||
public void sendMessageModify() throws UnknownHostException, IOException {
|
|
||||||
this.sendIDPseudo_local("modify");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the message "del,id,pseudo" to localhost on all the ports in
|
// Send the message "del,id,pseudo" to localhost on all the ports in
|
||||||
// "portOthers"
|
// "portOthers"
|
||||||
// This allows the receivers' agent (portOthers) to delete the entry
|
// This allows the receivers' agent (portOthers) to delete the entry
|
||||||
// corresponding to this agent
|
// corresponding to this agent
|
||||||
public void sendMessageDelete() throws UnknownHostException, IOException {
|
public void sendMessageDelete() throws UnknownHostException, IOException {
|
||||||
this.sendIDPseudo_local("del");
|
for(int port : this.portOthers) {
|
||||||
}
|
try {
|
||||||
|
this.client.sendMessageUDP_local(new MessageSysteme(Message.TypeMessage.JE_SUIS_DECONNECTE), port, InetAddress.getLocalHost());
|
||||||
// Private function to create the message "[prefix],id,pseudo"
|
} catch (MauvaisTypeMessageException e) {/*Si ça marche pas essayer là*/}
|
||||||
// and send it to localhost on all the ports in "portOthers"
|
|
||||||
private void sendIDPseudo_local(String prefixe, ArrayList<Integer> portServers) throws UnknownHostException, IOException {
|
|
||||||
Utilisateur self = Utilisateur.getSelf();
|
|
||||||
String idSelf = self.getId();
|
|
||||||
String pseudoSelf = self.getPseudo();
|
|
||||||
|
|
||||||
if (!pseudoSelf.equals("")) {
|
|
||||||
|
|
||||||
String message = prefixe + "," + idSelf + "," + pseudoSelf;
|
|
||||||
// A modifier pour créer un objet de type Message
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
for (int port : portServers) {
|
|
||||||
this.client.sendMessageUDP_local(message, port, InetAddress.getLocalHost());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendIDPseudo_local(String prefixe) throws UnknownHostException, IOException {
|
|
||||||
this.sendIDPseudo_local(prefixe, this.portOthers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Pas encore adapte message
|
||||||
// private void sendIDPseudo_broadcast(String prefixe) throws UnknownHostException, IOException {
|
// private void sendIDPseudo_broadcast(String prefixe) throws UnknownHostException, IOException {
|
||||||
// Utilisateur self = Utilisateur.getSelf();
|
// Utilisateur self = Utilisateur.getSelf();
|
||||||
// String idSelf = self.getId();
|
// String idSelf = self.getId();
|
||||||
|
|
|
@ -7,6 +7,8 @@ import java.net.SocketException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import messages.*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class UDPServer extends Thread {
|
public class UDPServer extends Thread {
|
||||||
|
@ -28,50 +30,38 @@ public class UDPServer extends Thread {
|
||||||
try {
|
try {
|
||||||
DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length);
|
DatagramPacket inPacket = new DatagramPacket(buffer, buffer.length);
|
||||||
this.sockUDP.receive(inPacket);
|
this.sockUDP.receive(inPacket);
|
||||||
String msg = new String(inPacket.getData(), 0, inPacket.getLength());
|
String msgString = new String(inPacket.getData(), 0, inPacket.getLength());
|
||||||
|
Message msg = Message.stringToMessage(msgString);
|
||||||
|
|
||||||
if (msg.equals("first_connection")) {
|
switch(msg.getTypeMessage()) {
|
||||||
|
case JE_SUIS_CONNECTE :
|
||||||
//System.out.println("first co");
|
//System.out.println("first co");
|
||||||
ArrayList<Integer> portClient = new ArrayList<Integer>();
|
int portServer = inPacket.getPort();
|
||||||
portClient.add(inPacket.getPort()+1);
|
int portClient = portServer+1;
|
||||||
this.commUDP.sendMessageAdd(portClient);
|
this.commUDP.sendMessageInfoPseudo(portServer);
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (msg.contains("add,")) {
|
case INFO_PSEUDO :
|
||||||
//System.out.println("add");
|
if (Communication.containsUserFromID(((MessageSysteme) msg).getId())) {
|
||||||
ArrayList<String> datas = this.getDatas(inPacket);
|
Communication.changePseudoUser(((MessageSysteme) msg).getId(), ((MessageSysteme) msg).getPseudo(), inPacket.getAddress());
|
||||||
Communication.addUser(datas);
|
}
|
||||||
|
else {
|
||||||
|
Communication.addUser(((MessageSysteme) msg).getId(), ((MessageSysteme) msg).getPseudo(), inPacket.getAddress());
|
||||||
|
System.out.println(((MessageSysteme) msg).getId()+", "+((MessageSysteme) msg).getPseudo());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
} else if (msg.contains("modify,")) {
|
case JE_SUIS_DECONNECTE :
|
||||||
ArrayList<String> datas = this.getDatas(inPacket);
|
Communication.removeUser(((MessageSysteme) msg).getId(), ((MessageSysteme) msg).getPseudo(), inPacket.getAddress());
|
||||||
Communication.changePseudoUser(datas);
|
break;
|
||||||
|
|
||||||
} else if (msg.contains("del,")) {
|
default : //Others types of messages are ignored because they are supposed to be transmitted by TCP and not UDP
|
||||||
ArrayList<String> datas = this.getDatas(inPacket);
|
|
||||||
Communication.removeUser(datas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("receive exception");
|
System.out.println("receive exception");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<String> getDatas(DatagramPacket inPacket) {
|
|
||||||
//Message
|
|
||||||
//
|
|
||||||
|
|
||||||
String msg = new String(inPacket.getData(), 0, inPacket.getLength());
|
|
||||||
String tmp[] = msg.split(",");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ArrayList<String> datas = new ArrayList<String>(Arrays.asList(tmp));
|
|
||||||
datas.remove(0);
|
|
||||||
datas.add(inPacket.getAddress().toString());
|
|
||||||
|
|
||||||
return datas;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,10 @@ package main;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import communication.*;
|
||||||
|
|
||||||
public class ControleurConnexion implements ActionListener {
|
public class ControleurConnexion implements ActionListener {
|
||||||
|
|
||||||
|
@ -9,26 +13,51 @@ public class ControleurConnexion implements ActionListener {
|
||||||
|
|
||||||
private VueConnexion vue;
|
private VueConnexion vue;
|
||||||
private Etat etat;
|
private Etat etat;
|
||||||
|
private CommunicationUDP comUDP;
|
||||||
|
private String id;
|
||||||
|
private String pseudo;
|
||||||
|
|
||||||
public ControleurConnexion(VueConnexion vue) {
|
public ControleurConnexion(VueConnexion vue) {
|
||||||
this.vue = vue;
|
this.vue = vue;
|
||||||
this.etat = Etat.DEBUT;
|
this.etat = Etat.DEBUT;
|
||||||
|
this.id="";
|
||||||
|
//Pour les tests, changer pour un truc plus général quand on change CommunicationUDP
|
||||||
|
try {
|
||||||
|
this.comUDP = new CommunicationUDP(2209, 2208, new int[] {2905});
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String input;
|
|
||||||
boolean inputOK = false;
|
boolean inputOK = false;
|
||||||
if (this.etat == Etat.DEBUT) {
|
if (this.etat == Etat.DEBUT) {
|
||||||
input=vue.getValeurTextField();
|
id=vue.getValeurTextField();
|
||||||
|
|
||||||
//Recherche dans la liste des utilisateurs enregistres, report sur inputOK
|
//Recherche dans la liste des utilisateurs enregistres, report sur inputOK
|
||||||
if (input.contentEquals("idvalide")) inputOK=true;
|
inputOK = id.contentEquals("idvalide");
|
||||||
|
|
||||||
if (inputOK) {
|
if (inputOK) {
|
||||||
this.etat=Etat.ID_OK;
|
this.etat=Etat.ID_OK;
|
||||||
|
|
||||||
//Envoi broadcast du message "JeSuisActif" et, attente du retour de la liste des utilisateurs actifs
|
//Envoi broadcast du message "JeSuisActif" et, attente du retour de la liste des utilisateurs actifs
|
||||||
|
try {
|
||||||
|
comUDP.sendMessageConnecte();
|
||||||
|
} catch (UnknownHostException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(2);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
//Mise en place de la demande du pseudo
|
//Mise en place de la demande du pseudo
|
||||||
vue.setTexteLabelInput("Veuillez entrer votre nom");
|
vue.setTexteLabelInput("Veuillez entrer votre nom");
|
||||||
|
@ -38,14 +67,32 @@ public class ControleurConnexion implements ActionListener {
|
||||||
else vue.setTexteLabelInput("Identifiant invalide, veuillez réessayer");
|
else vue.setTexteLabelInput("Identifiant invalide, veuillez réessayer");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
input=vue.getValeurTextField();
|
pseudo=vue.getValeurTextField();
|
||||||
|
|
||||||
//Recherche dans la liste locale des utilisateurs connectes, report sur inputOK
|
//Recherche dans la liste locale des utilisateurs connectes, report sur inputOK
|
||||||
if (input.contentEquals("nomvalide")) inputOK=true;
|
inputOK = !Communication.containsUserFromPseudo(pseudo);
|
||||||
|
|
||||||
if (inputOK) {
|
if (inputOK) {
|
||||||
//Creation de la vue principale
|
//Reglage de l'utilisateur
|
||||||
|
try {
|
||||||
|
Utilisateur.setSelf(id, pseudo, "localhost");
|
||||||
|
} catch (UnknownHostException e2) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Broadcast du pseudo
|
||||||
|
try {
|
||||||
|
comUDP.sendMessageInfoPseudo();
|
||||||
|
} catch (UnknownHostException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
//Creation de la vue principale
|
||||||
|
vue.setTexteLabelInput("Congrations you done it");
|
||||||
}
|
}
|
||||||
else vue.setTexteLabelInput("Ce nom est déjà utilisé, veuillez en choisir un autre");
|
else vue.setTexteLabelInput("Ce nom est déjà utilisé, veuillez en choisir un autre");
|
||||||
}
|
}
|
||||||
|
|
28
POO/src/main/Main2tests.java
Normal file
28
POO/src/main/Main2tests.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package main;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import communication.*;
|
||||||
|
|
||||||
|
public class Main2tests {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
Utilisateur.setSelf("idrandom", "RandomPersonne", "localhost");
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Communication comUDP = new CommunicationUDP(2906, 2905, new int[] {});
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,10 +15,10 @@ public class Utilisateur implements Serializable{
|
||||||
|
|
||||||
private static Utilisateur self;
|
private static Utilisateur self;
|
||||||
|
|
||||||
public Utilisateur(String id, String pseudo, String host) throws UnknownHostException {
|
public Utilisateur(String id, String pseudo, InetAddress ip) throws UnknownHostException {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.pseudo = pseudo;
|
this.pseudo = pseudo;
|
||||||
this.ip = InetAddress.getLocalHost();
|
this.ip = ip;
|
||||||
System.out.println(InetAddress.getLocalHost());
|
System.out.println(InetAddress.getLocalHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,9 +41,8 @@ public class Utilisateur implements Serializable{
|
||||||
|
|
||||||
public static void setSelf(String id, String pseudo,String host) throws UnknownHostException {
|
public static void setSelf(String id, String pseudo,String host) throws UnknownHostException {
|
||||||
if(Utilisateur.self == null) {
|
if(Utilisateur.self == null) {
|
||||||
Utilisateur.self = new Utilisateur(id, pseudo, host);
|
Utilisateur.self = new Utilisateur(id, pseudo, InetAddress.getByName(host));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Utilisateur getSelf() {
|
public static Utilisateur getSelf() {
|
||||||
|
|
|
@ -34,7 +34,7 @@ public abstract class Message implements Serializable {
|
||||||
return new MessageSysteme(TypeMessage.JE_SUIS_DECONNECTE);
|
return new MessageSysteme(TypeMessage.JE_SUIS_DECONNECTE);
|
||||||
|
|
||||||
case "INFO_PSEUDO" :
|
case "INFO_PSEUDO" :
|
||||||
return new MessageSysteme(TypeMessage.INFO_PSEUDO, parts[1]);
|
return new MessageSysteme(TypeMessage.INFO_PSEUDO, parts[1], parts[2]);
|
||||||
|
|
||||||
case "TEXTE" :
|
case "TEXTE" :
|
||||||
return new MessageTexte(TypeMessage.TEXTE, parts[1]);
|
return new MessageTexte(TypeMessage.TEXTE, parts[1]);
|
||||||
|
@ -53,7 +53,7 @@ public abstract class Message implements Serializable {
|
||||||
public static void main(String[] args) throws MauvaisTypeMessageException {
|
public static void main(String[] args) throws MauvaisTypeMessageException {
|
||||||
Message m1 = new MessageSysteme(TypeMessage.JE_SUIS_CONNECTE);
|
Message m1 = new MessageSysteme(TypeMessage.JE_SUIS_CONNECTE);
|
||||||
Message m2 = new MessageSysteme(TypeMessage.JE_SUIS_DECONNECTE);
|
Message m2 = new MessageSysteme(TypeMessage.JE_SUIS_DECONNECTE);
|
||||||
Message m3 = new MessageSysteme(TypeMessage.INFO_PSEUDO, "pseudo156434518");
|
Message m3 = new MessageSysteme(TypeMessage.INFO_PSEUDO, "pseudo156434518", "id236");
|
||||||
Message m4 = new MessageTexte(TypeMessage.TEXTE, "blablabla");
|
Message m4 = new MessageTexte(TypeMessage.TEXTE, "blablabla");
|
||||||
Message m5 = new MessageFichier(TypeMessage.FICHIER, "truc", ".pdf");
|
Message m5 = new MessageFichier(TypeMessage.FICHIER, "truc", ".pdf");
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,22 @@ public class MessageSysteme extends Message {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private String pseudo;
|
private String pseudo;
|
||||||
|
private String id;
|
||||||
|
|
||||||
public MessageSysteme(TypeMessage type) throws MauvaisTypeMessageException{
|
public MessageSysteme(TypeMessage type) throws MauvaisTypeMessageException{
|
||||||
if ((type==TypeMessage.JE_SUIS_CONNECTE)||(type==TypeMessage.JE_SUIS_DECONNECTE)||(type==TypeMessage.MESSAGE_NUL)) {
|
if ((type==TypeMessage.JE_SUIS_CONNECTE)||(type==TypeMessage.JE_SUIS_DECONNECTE)||(type==TypeMessage.MESSAGE_NUL)) {
|
||||||
this.type=type;
|
this.type=type;
|
||||||
this.pseudo="";
|
this.pseudo="";
|
||||||
|
this.id="";
|
||||||
}
|
}
|
||||||
else throw new MauvaisTypeMessageException();
|
else throw new MauvaisTypeMessageException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageSysteme(TypeMessage type, String pseudo) throws MauvaisTypeMessageException {
|
public MessageSysteme(TypeMessage type, String pseudo, String id) throws MauvaisTypeMessageException {
|
||||||
if (type==TypeMessage.INFO_PSEUDO) {
|
if (type==TypeMessage.INFO_PSEUDO) {
|
||||||
this.type=type;
|
this.type=type;
|
||||||
this.pseudo=pseudo;
|
this.pseudo=pseudo;
|
||||||
|
this.id=id;
|
||||||
}
|
}
|
||||||
else throw new MauvaisTypeMessageException();
|
else throw new MauvaisTypeMessageException();
|
||||||
}
|
}
|
||||||
|
@ -24,9 +27,13 @@ public class MessageSysteme extends Message {
|
||||||
public String getPseudo() {
|
public String getPseudo() {
|
||||||
return this.pseudo;
|
return this.pseudo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String attributsToString() {
|
protected String attributsToString() {
|
||||||
return this.pseudo;
|
return this.pseudo+"###"+this.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue