Some bugs fixed

This commit is contained in:
Paul Faure 2021-02-13 22:46:35 +01:00
parent e232ff6d7d
commit 29be5ad5a8
13 changed files with 100 additions and 18 deletions

Binary file not shown.

View file

@ -1,3 +1,21 @@
app/insa/clav/Messages/Message.java
app.insa.clav.Messages.Message
app/insa/clav/Messages/MessageSrvTCP.java
app.insa.clav.Messages.MessageSrvTCP
app/insa/clav/Messages/MessageChatTxt.java
app.insa.clav.Messages.MessageChatTxt
app/insa/clav/Messages/MessageRetourSrvTCP.java
app.insa.clav.Messages.MessageRetourSrvTCP
com/example/ServeurClavardage/Support/Connexion.java
com.example.ServeurClavardage.Support.Connexion
app/insa/clav/Messages/MessageInit.java
app.insa.clav.Messages.MessageInit
com/example/ServeurClavardage/Support/ListMessageTxtParCo.java
com.example.ServeurClavardage.Support.ListMessageTxtParCo
app/insa/clav/Messages/MessagePseudo.java
app.insa.clav.Messages.MessagePseudo
app/insa/clav/Messages/MessageChatFile.java
app.insa.clav.Messages.MessageChatFile
com/example/ServeurClavardage/Request/GetConnectionChat.java
com.example.ServeurClavardage.Request.GetConnectionChat
com/example/ServeurClavardage/Request/SubmitDeconnectionIndoor.java
@ -8,24 +26,12 @@ com/example/ServeurClavardage/Request/SubmitConnectionIndoor.java
com.example.ServeurClavardage.Request.SubmitConnectionIndoor
com/example/ServeurClavardage/Support/ListMessageTxtParUser.java
com.example.ServeurClavardage.Support.ListMessageTxtParUser
com/example/ServeurClavardage/Support/ListMessageTxtParCo.java
com.example.ServeurClavardage.Support.ListMessageTxtParCo
com/example/ServeurClavardage/Request/GetOutdoorUsers.java
com.example.ServeurClavardage.Request.GetOutdoorUsers
com/example/ServeurClavardage/Request/SubmitConnectionOutdoor.java
com.example.ServeurClavardage.Request.SubmitConnectionOutdoor
com/example/ServeurClavardage/Support/SharedInformation.java
com.example.ServeurClavardage.Support.SharedInformation
app/insa/clav/Messages/MessageInit.java
app.insa.clav.Messages.MessageInit
app/insa/clav/Messages/MessageSrvTCP.java
app.insa.clav.Messages.MessageSrvTCP
app/insa/clav/Messages/MessagePseudo.java
app.insa.clav.Messages.MessagePseudo
app/insa/clav/Messages/MessageChatFile.java
app.insa.clav.Messages.MessageChatFile
app/insa/clav/Messages/Message.java
app.insa.clav.Messages.Message
com/example/ServeurClavardage/Request/SubmitDeconnectionOutdoor.java
com.example.ServeurClavardage.Request.SubmitDeconnectionOutdoor
com/example/ServeurClavardage/Request/SubmitConnectionChat.java
@ -38,7 +44,3 @@ com/example/ServeurClavardage/Support/ListMessagesInitParUser.java
com.example.ServeurClavardage.Support.ListMessagesInitParUser
app/insa/clav/Core/Utilisateurs.java
app.insa.clav.Core.Utilisateurs
app/insa/clav/Messages/MessageRetourSrvTCP.java
app.insa.clav.Messages.MessageRetourSrvTCP
app/insa/clav/Messages/MessageChatTxt.java
app.insa.clav.Messages.MessageChatTxt

View file

@ -83,7 +83,7 @@ public class Utilisateurs implements Comparable{
System.out.println("Local time : " + this.lastUpdate.getTime());
System.out.println("Remote Date : " + date.toString());
System.out.println("Remote Time : " + date.getTime());
return (date.getTime() - this.lastUpdate.getTime() > 4000);
return (date.getTime() - this.lastUpdate.getTime() > 5000);
}
@Override

View file

@ -36,6 +36,7 @@ public class Message implements Serializable {
/**
* Constructeur d'un message depuis un autre
* @param msg
* création d'un message a partir d'un autre
*/
public Message(Message msg){
this.typeMessage = msg.typeMessage;

View file

@ -2,6 +2,7 @@ package com.example.ServeurClavardage.Request;
import app.insa.clav.Messages.MessageInit;
import app.insa.clav.Messages.MessageSrvTCP;
import com.example.ServeurClavardage.Support.Connexion;
import com.example.ServeurClavardage.Support.SharedInformation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -39,7 +40,11 @@ public class SubmitConnectionChat extends HttpServlet {
MessageSrvTCP msgSrv = gson.fromJson(resp.toString(), MessageSrvTCP.class);
response.setContentType("application/json");
System.out.println("Submit connection Chat avec " + msgSrv);
this.sh.addMsgInit(msgSrv.getUserId(),msgSrv.getId(), msgSrv.getMessageInit());
if (this.sh.existConnexion(new Connexion(msgSrv.getUserId(), msgSrv.getId()))) {
response.setStatus(201);
} else {
this.sh.addMsgInit(msgSrv.getUserId(), msgSrv.getId(), msgSrv.getMessageInit());
}
//System.out.println("Etat après le dépot de connexion : " + this.sh.getCoList(msgSrv.getUserId()));
}

View file

@ -0,0 +1,24 @@
package com.example.ServeurClavardage.Support;
public class Connexion {
private final int id1;
private final int id2;
public Connexion(int id1, int id2) {
this.id1 = id1;
this.id2 = id2;
}
public int getId1() {
return id1;
}
public int getId2() {
return id2;
}
public boolean equals(Connexion con) {
return (this.id1 == con.getId1() && this.id2 == con.getId2()) || (this.id1 == con.getId2() && this.id2 == con.getId1());
}
}

View file

@ -14,6 +14,7 @@ public class SharedInformation {
private ArrayList<Utilisateurs> indoorUsersList;
private ArrayList<ListMessagesInitParUser> listMsgInit;
private ArrayList<ListMessageTxtParUser> listMessageTxt;
private ArrayList<Connexion> connexions;
private static SharedInformation instance = null;
public SharedInformation(){
@ -21,6 +22,7 @@ public class SharedInformation {
this.indoorUsersList = new ArrayList<>();
this.listMsgInit = new ArrayList<>();
this.listMessageTxt = new ArrayList<>();
this.connexions = new ArrayList<>();
}
public static SharedInformation getInstance(){
@ -121,6 +123,7 @@ public class SharedInformation {
}
public synchronized void addMsgInit(int user, int remoteId, MessageInit msg){
this.addConnexion(new Connexion(user, remoteId));
for (Iterator<ListMessagesInitParUser> iter = listMsgInit.iterator(); iter.hasNext(); ) {
ListMessagesInitParUser list = iter.next();
if (user == list.getUser().getId()) {
@ -135,6 +138,9 @@ public class SharedInformation {
}
public synchronized void addMsgTxt(int user, int remoteId, MessageRetourSrvTCP msg) {
if (msg.getMessage() != null) {
this.removeConnexion(user, remoteId);
}
for (Iterator<ListMessageTxtParUser> iter1 = listMessageTxt.iterator(); iter1.hasNext(); ) {
ListMessageTxtParUser list1 = iter1.next();
if (list1.getUser().getId() == user) {
@ -167,10 +173,54 @@ public class SharedInformation {
public synchronized void removeIndoorUser(Utilisateurs user){
this.indoorUsersList.remove(user);
this.handleDeconnexion(user.getId());
}
public synchronized void removeOutdoorUser(Utilisateurs user){
this.outdoorUsersList.remove(user);
this.handleDeconnexion(user.getId());
}
private void addConnexion(Connexion con) {
this.connexions.add(con);
}
private void removeConnexion(int id1, int id2) {
Connexion c = null;
for (Iterator<Connexion> iter = this.connexions.iterator(); iter.hasNext();) {
c = iter.next();
if ((c.getId1() == id1 && c.getId2() == id2) || (c.getId1() == id2 && c.getId2() == id1)) {
break;
}
}
if (c != null) {
this.connexions.remove(c);
}
}
private void handleDeconnexion(int user) {
for (Iterator<Connexion> iter = this.connexions.iterator(); iter.hasNext();) {
Connexion c = iter.next();
if (user == c.getId1()) {
this.addMsgTxt(c.getId2(), user, new MessageRetourSrvTCP(new Message(8, null)));
this.removeConnexion(user, c.getId2());
}
if (user == c.getId2()) {
this.addMsgTxt(c.getId1(), user, new MessageRetourSrvTCP(new Message(8, null)));
this.removeConnexion(user, c.getId1());
}
}
}
public synchronized boolean existConnexion(Connexion con) {
boolean trouve = false;
for (Iterator<Connexion> iter = this.connexions.iterator(); iter.hasNext();) {
Connexion c = iter.next();
if (c.equals(con)) {
trouve = true;
break;
}
}
return trouve;
}
private void printLists() {