|
@@ -4,10 +4,7 @@ import app.insa.clav.Messages.Message;
|
4
|
4
|
import app.insa.clav.Messages.MessageChatTxt;
|
5
|
5
|
import app.insa.clav.Messages.MessageInit;
|
6
|
6
|
import app.insa.clav.Messages.MessagePseudo;
|
7
|
|
-import app.insa.clav.Reseau.TCPChatConnection;
|
8
|
|
-import app.insa.clav.Reseau.TCPListener;
|
9
|
|
-import app.insa.clav.Reseau.UDPInput;
|
10
|
|
-import app.insa.clav.Reseau.UDPOutput;
|
|
7
|
+import app.insa.clav.Reseau.*;
|
11
|
8
|
import javafx.application.Application;
|
12
|
9
|
import javafx.application.Platform;
|
13
|
10
|
import jdk.jshell.execution.Util;
|
|
@@ -16,11 +13,9 @@ import java.beans.PropertyChangeEvent;
|
16
|
13
|
import java.beans.PropertyChangeListener;
|
17
|
14
|
import java.beans.PropertyChangeSupport;
|
18
|
15
|
import java.io.IOException;
|
19
|
|
-import java.util.ArrayList;
|
|
16
|
+import java.nio.charset.StandardCharsets;
|
|
17
|
+import java.util.*;
|
20
|
18
|
import java.net.*;
|
21
|
|
-import java.util.Collections;
|
22
|
|
-import java.util.Timer;
|
23
|
|
-import java.util.TimerTask;
|
24
|
19
|
//Toutes les interactions avec l'utilisateur (pour tester)
|
25
|
20
|
|
26
|
21
|
/**
|
|
@@ -32,6 +27,9 @@ public class Model implements PropertyChangeListener{
|
32
|
27
|
* Liste des utilisateurs connectés.
|
33
|
28
|
*/
|
34
|
29
|
private ArrayList<Utilisateurs> userList;
|
|
30
|
+
|
|
31
|
+ private ServletConnection servCon;
|
|
32
|
+
|
35
|
33
|
/**
|
36
|
34
|
* Timer qui permet de planifier des éxécutions dans le temps
|
37
|
35
|
*/
|
|
@@ -105,7 +103,7 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
105
|
103
|
*/
|
106
|
104
|
private Model(int inputPort, int outputPort, int tcpListenerPort, Application app){
|
107
|
105
|
try {
|
108
|
|
- this.user = new Utilisateurs("NA", InetAddress.getLocalHost(), 0, inputPort);
|
|
106
|
+ this.user = new Utilisateurs("NA", InetAddress.getLocalHost(), 0, inputPort, false);
|
109
|
107
|
this.UDPOut = new UDPOutput(InetAddress.getLocalHost(), outputPort);
|
110
|
108
|
this.UDPIn = new UDPInput(user.getInetAddress(),inputPort);
|
111
|
109
|
this.tcpListener = new TCPListener(this.user.getInetAddress(),tcpListenerPort,user.getId());
|
|
@@ -120,6 +118,7 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
120
|
118
|
this.listTCPConnection = new ArrayList<TCPChatConnection>();
|
121
|
119
|
this.dbAccess = DataBaseAccess.getInstance();
|
122
|
120
|
this.app = app;
|
|
121
|
+ this.servCon = ServletConnection.getInstance();
|
123
|
122
|
}
|
124
|
123
|
|
125
|
124
|
/**
|
|
@@ -248,16 +247,47 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
248
|
247
|
* Méthode appelée par le controleur quand la vue envoie un signal d'appuis bouton changer Pseudo
|
249
|
248
|
* @param pseudo
|
250
|
249
|
* Pseudo rentré par l'utilisateur
|
251
|
|
- * @return
|
252
|
250
|
*/
|
253
|
|
- public boolean choosePseudo(String pseudo, boolean isConfirmationNeeded){
|
|
251
|
+ public void choosePseudo(String pseudo, boolean isConfirmationNeeded){
|
254
|
252
|
this.ancienPseudo = this.user.getPseudo();
|
255
|
253
|
this.user.setPseudo(pseudo);
|
256
|
|
- this.UDPIn.setFilterValue(2,true);
|
257
|
|
- this.UDPIn.setFilterValue(3,true);
|
258
|
|
- this.sendPseudoBroadcast();
|
259
|
|
- this.tim.schedule(new TimerTaskResponseWait(isConfirmationNeeded),1000);
|
260
|
|
- return true;
|
|
254
|
+ this.UDPIn.setFilterValue(2, true);
|
|
255
|
+ this.UDPIn.setFilterValue(3, true);
|
|
256
|
+ if (!this.user.isOutdoor()) {
|
|
257
|
+ this.sendPseudoBroadcast();
|
|
258
|
+ this.tim.schedule(new TimerTaskResponseWait(isConfirmationNeeded), 2000);
|
|
259
|
+ ArrayList<Utilisateurs> outdoorUsers = servCon.getRemoteActiveUsers();
|
|
260
|
+ for (Utilisateurs newUser : outdoorUsers) {
|
|
261
|
+ if (newUser.getPseudo().equals(this.user.getPseudo())) {
|
|
262
|
+ this.isPseudoOk = false;
|
|
263
|
+ this.user.setPseudo(this.ancienPseudo);
|
|
264
|
+ this.ancienPseudo = "";
|
|
265
|
+ this.support.firePropertyChange("pseudoRefused", this.user.getPseudo(), this.ancienPseudo);
|
|
266
|
+ }
|
|
267
|
+ if (!this.userList.contains(newUser)) {
|
|
268
|
+ this.userList.add(newUser);
|
|
269
|
+ Collections.sort(this.userList);
|
|
270
|
+ this.support.firePropertyChange("newUserConnected", -1, -2);
|
|
271
|
+ }
|
|
272
|
+ }
|
|
273
|
+ }
|
|
274
|
+ else{
|
|
275
|
+ this.tim.schedule(new TimerTaskResponseWait(isConfirmationNeeded), 2000);
|
|
276
|
+ ArrayList<Utilisateurs> users = servCon.getAllActiveUsers();
|
|
277
|
+ for (Utilisateurs newUser : users) {
|
|
278
|
+ if (newUser.getPseudo().equals(this.user.getPseudo())) {
|
|
279
|
+ this.isPseudoOk = false;
|
|
280
|
+ this.user.setPseudo(this.ancienPseudo);
|
|
281
|
+ this.ancienPseudo = "";
|
|
282
|
+ this.support.firePropertyChange("pseudoRefused", this.user.getPseudo(), this.ancienPseudo);
|
|
283
|
+ }
|
|
284
|
+ if (!this.userList.contains(newUser)) {
|
|
285
|
+ this.userList.add(newUser);
|
|
286
|
+ Collections.sort(this.userList);
|
|
287
|
+ this.support.firePropertyChange("newUserConnected", -1, -2);
|
|
288
|
+ }
|
|
289
|
+ }
|
|
290
|
+ }
|
261
|
291
|
}
|
262
|
292
|
|
263
|
293
|
/** Sets the id
|
|
@@ -331,7 +361,7 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
331
|
361
|
break;
|
332
|
362
|
case 2 :
|
333
|
363
|
MessagePseudo msgP2 = (MessagePseudo) msg;
|
334
|
|
- Utilisateurs newUser2 = new Utilisateurs(msgP2.pseudo,msgP2.srcIP,msgP2.id,msgP2.srcResponsePort);
|
|
364
|
+ Utilisateurs newUser2 = new Utilisateurs(msgP2.pseudo,msgP2.srcIP,msgP2.id,msgP2.srcResponsePort,false);
|
335
|
365
|
if (!this.userList.contains(newUser2)) {
|
336
|
366
|
this.userList.add(newUser2);
|
337
|
367
|
Collections.sort(this.userList);
|
|
@@ -341,7 +371,7 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
341
|
371
|
case 3 :
|
342
|
372
|
System.out.println("Received message type 3");
|
343
|
373
|
MessagePseudo msgP3 = (MessagePseudo) msg;
|
344
|
|
- Utilisateurs newUser3 = new Utilisateurs(msgP3.pseudo,msgP3.srcIP,msgP3.id,msgP3.srcResponsePort);
|
|
374
|
+ Utilisateurs newUser3 = new Utilisateurs(msgP3.pseudo,msgP3.srcIP,msgP3.id,msgP3.srcResponsePort,false);
|
345
|
375
|
if (!this.userList.contains(newUser3)) {
|
346
|
376
|
this.userList.add(newUser3);
|
347
|
377
|
Collections.sort(this.userList);
|
|
@@ -355,7 +385,7 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
355
|
385
|
break;
|
356
|
386
|
case 4:
|
357
|
387
|
MessagePseudo msgP4 = (MessagePseudo) msg;
|
358
|
|
- Utilisateurs newUser4 = new Utilisateurs(msgP4.pseudo,msgP4.srcIP,msgP4.id,msgP4.srcResponsePort);
|
|
388
|
+ Utilisateurs newUser4 = new Utilisateurs(msgP4.pseudo,msgP4.srcIP,msgP4.id,msgP4.srcResponsePort,false);
|
359
|
389
|
this.userList.remove(newUser4);
|
360
|
390
|
this.userList.add(newUser4);
|
361
|
391
|
Collections.sort(this.userList);
|
|
@@ -363,7 +393,7 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
363
|
393
|
break;
|
364
|
394
|
case 7 :
|
365
|
395
|
MessagePseudo msgP7 = (MessagePseudo) msg;
|
366
|
|
- Utilisateurs User7 = new Utilisateurs(msgP7.pseudo,msgP7.srcIP,msgP7.id,msgP7.srcResponsePort);
|
|
396
|
+ Utilisateurs User7 = new Utilisateurs(msgP7.pseudo,msgP7.srcIP,msgP7.id,msgP7.srcResponsePort,false);
|
367
|
397
|
this.userList.remove(User7);
|
368
|
398
|
this.support.firePropertyChange("newUserConnected",true,false);
|
369
|
399
|
default :
|
|
@@ -486,8 +516,6 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
486
|
516
|
}
|
487
|
517
|
this.dbAccess.deleteHistory(remoteId,user.getId());
|
488
|
518
|
}
|
489
|
|
-
|
490
|
|
-
|
491
|
519
|
/**
|
492
|
520
|
* Classe interne au model pour au bout d'une seconde d'envoi de demande pseudo type 1,
|
493
|
521
|
* on desactive les filtes et on met à jour la vue.
|
|
@@ -514,7 +542,13 @@ ID 2 -> Listening on 6002, sending on 5002, tcpServer on 7002
|
514
|
542
|
support.firePropertyChange("pseudoValide",ancienPseudo,user.getPseudo());
|
515
|
543
|
UDPIn.setFilterValue(1,true);
|
516
|
544
|
if (isConfirmationNeeded){
|
517
|
|
- sendPseudoValideBroadcast();
|
|
545
|
+ if (!user.isOutdoor()) {
|
|
546
|
+ sendPseudoValideBroadcast();
|
|
547
|
+ servCon.submitConnectionIndoor(user);
|
|
548
|
+ }
|
|
549
|
+ else{
|
|
550
|
+ servCon.submitConnectionOutdoor(user);
|
|
551
|
+ }
|
518
|
552
|
}
|
519
|
553
|
}
|
520
|
554
|
else{
|