Skip to content

Commit

Permalink
test unicité pseudo
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyesKhama committed Dec 22, 2017
1 parent f85df68 commit 1ecde72
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
31 changes: 24 additions & 7 deletions src/GraphiquePackage/FichAccueil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import SourcePackage.User;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import static java.lang.Thread.sleep;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author elyes
*/
public class FichAccueil extends javax.swing.JFrame {

/** * Creates new form FichMenu
Expand Down Expand Up @@ -96,13 +95,31 @@ private void PseudoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
}//GEN-LAST:event_PseudoActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
String a = Pseudo.getText();
Main.launchUser(a);

try {

Main.launchUser("");

String a = Pseudo.getText();
System.out.println("Checking pseudo ...");

sleep(3000);

if(Main.user.getListUser().containsKey(a)){
System.out.println("pseudo deja utilisé !! , réessayez ! ");
}

else{
Main.user.setPseudo(a);
menu = new FichMenu(this, false);
this.setVisible(false);
menu.setVisible(true);

Main.setFichMenu(menu);
Main.setFichMenu(menu);
}
} catch (InterruptedException ex) {
Logger.getLogger(FichAccueil.class.getName()).log(Level.SEVERE, null, ex);
}

}//GEN-LAST:event_jButton1ActionPerformed

Expand Down
5 changes: 4 additions & 1 deletion src/GraphiquePackage/FichCom.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FichCom extends javax.swing.JDialog {
* Creates new form FichCom
*/

private static int portDest;
private int portDest;

public FichCom(java.awt.Dialog parent, boolean modal, int port ) {
super(parent, modal);
Expand All @@ -28,6 +28,9 @@ public FichCom(java.awt.Dialog parent, boolean modal, int port ) {

}

public int getPortDest(){
return portDest;
}

public void exitSystem(){
this.addWindowListener(new java.awt.event.WindowAdapter() {
Expand Down
4 changes: 2 additions & 2 deletions src/GraphiquePackage/FichMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
Main.user.sendMessageTCP("je me co",info[0],parseInt(info[1]), true);
fichCom = new FichCom(this,false,parseInt(info[1]));
this.fichCom.setVisible(true);
Main.user.addFichCom(fichCom);
Main.user.addFichCom(parseInt(info[1]),fichCom);


}//GEN-LAST:event_jButton2ActionPerformed
Expand All @@ -181,7 +181,7 @@ public void majButton(String name){
public void openWindow(int port){
fichCom = new FichCom(this,false,port);
this.fichCom.setVisible(true);
Main.user.addFichCom(fichCom);
Main.user.addFichCom(port, fichCom);
}
/**
* @param args the command line arguments
Expand Down
9 changes: 8 additions & 1 deletion src/SourcePackage/ThreadReceive.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static void receiveMessage() throws IOException { //UDP : boucle qui re
//System.out.println("nouveau client : " + recvStr + "\n voici son adresse IP : " + addr + " et voici son port : " + port);
// System.out.println("pseudo recu : " + recvStr);



if(recvStr.contains("quita")){
String[] info = recvStr.split("-");
Main.user.removeUserList(info[1]);//mettre a jour sa liste : l'enlever
Expand All @@ -50,13 +52,18 @@ else if(recvStr.contains("quito")){

else {
if( !Main.user.belongList(recvStr)){
if(recvStr.equals("")){

}
else{

InetAddress addr = recvPacket.getAddress();
int port = recvPacket.getPort();
sendMessage(addr, port);
ajoutUserListe(recvStr,addr.toString().substring(1)+"-"+port);
}
}
}

}
}

Expand Down
3 changes: 2 additions & 1 deletion src/SourcePackage/ThreadReceiveTCPFinal.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void run() {
if(a.equals("quita")){
socket.close();
}
Main.user.getFichCom(0).setListMsg(a);

Main.user.getFichCom(socket.getPort()).setListMsg(a);
}
}
} catch (IOException e) {
Expand Down
13 changes: 9 additions & 4 deletions src/SourcePackage/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class User {
private static DatagramSocket socketEcoute;
private static boolean firstMsg = false;
private HashMap<Integer,Socket> listSocket;
private ArrayList<FichCom> listFichCom;
private HashMap<Integer , FichCom> listFichCom;
private PrintWriter writer = null;
private HashMap<String, String> listUser ;

public User(String pseudo){
listFichCom = new ArrayList<>();
listFichCom = new HashMap<>();
listUser = new HashMap<>();
listSocket = new HashMap();

Expand All @@ -52,6 +52,10 @@ public void startThread(){

}

public void startThread(int i){

}

public void sendMessageUDP(String message,int port){
String data = "" ;

Expand Down Expand Up @@ -180,10 +184,11 @@ public int getPort(){
return socketEnvoi.getLocalPort();
}

public void addFichCom(FichCom fichCom){
this.listFichCom.add(fichCom);
public void addFichCom(int port ,FichCom fichCom){
this.listFichCom.put(port, fichCom);
}


public FichCom getFichCom(int i){
return listFichCom.get(i);
}
Expand Down

0 comments on commit 1ecde72

Please sign in to comment.