2 Commits

Author SHA1 Message Date
  Louis Farina 38ee3f108c outdoor users(14) 3 years ago
  Louis Farina 748ab397cd outdoor users(13) 3 years ago
3 changed files with 41 additions and 45 deletions
  1. BIN
      Projet.jar
  2. 35
    43
      src/chat/ReceiveThread.java
  3. 6
    2
      src/chat/User.java

BIN
Projet.jar View File


+ 35
- 43
src/chat/ReceiveThread.java View File

44
         			ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
44
         			ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
45
 			        Notification notif = (Notification) in.readObject();
45
 			        Notification notif = (Notification) in.readObject();
46
 			        
46
 			        
47
+			        if(!(notif.getAuthor().equals(user)) && !notif.isRedirected())
48
+	            	{
49
+	            		System.out.println("Redirecting message");
50
+	            		for(Socket s:outdoor_dest_sockets)
51
+				    	{
52
+				    		try
53
+				    		{
54
+				    			ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
55
+				    			notif.setRedirected(true);
56
+				    		    out.writeObject(notif);
57
+				    		}
58
+				    		catch(IOException e){}
59
+				    	}
60
+	            	}
61
+			        
47
 	            	if(isOutdoor)
62
 	            	if(isOutdoor)
48
 		            {
63
 		            {
49
 		            	for(Socket s:dest_sockets)
64
 		            	for(Socket s:dest_sockets)
59
 		            }
74
 		            }
60
 	            	else
75
 	            	else
61
 	            	{
76
 	            	{
62
-			        	if(notif instanceof Message)
63
-			        	{
64
-			        		Message m = (Message) notif;
65
-				            displayArea.append(m.getAuthor() + " : " + m.getText() + "\n");
66
-			        	}
77
+	            		if(notif instanceof Message)
78
+				        {
79
+				        	Message m = (Message) notif;
80
+					        displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
81
+				        }
67
 			        	else if (notif instanceof DisconnectNotification)
82
 			        	else if (notif instanceof DisconnectNotification)
68
 			        	{
83
 			        	{
69
 			        		DisconnectNotification dn = (DisconnectNotification) notif;
84
 			        		DisconnectNotification dn = (DisconnectNotification) notif;
70
 			        		
85
 			        		
71
 				            displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
86
 				            displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
72
-				            for(int i = 0;i < known_users.size();i ++)
73
-				            {
74
-				            	if (known_users.get(i).getName().equals(dn.getAuthor()))
75
-				            	{
76
-				            		known_users.remove(i);
77
-				            		break;
78
-				            		//System.out.println("Removing " + message.getAuthor());
79
-				            	}
80
-				            }
81
-				            for(int i = 0;i < known_outdoor_users.size();i ++)
82
-				            {
83
-				            	if (known_outdoor_users.get(i).getName().equals(dn.getAuthor()))
84
-				            	{
85
-				            		known_outdoor_users.remove(i);
86
-				            		break;
87
-				            		//System.out.println("Removing " + message.getAuthor());
88
-				            	}
89
-				            }
90
 				            
87
 				            
91
-				            if(!dn.isRedirected() && !dn.getAuthor().equals(user.getName()))
88
+				            known_users.remove(dn.getAuthor());
89
+				            known_outdoor_users.remove(dn.getAuthor());
90
+				            
91
+				            if(!dn.isRedirected() && !dn.getAuthor().equals(user))
92
 				            {
92
 				            {
93
 				            	socket.close();
93
 				            	socket.close();
94
 				            	if(!isOutdoor)
94
 				            	if(!isOutdoor)
105
 				            displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
105
 				            displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
106
 				            if(cn.isOutdoor())
106
 				            if(cn.isOutdoor())
107
 				            {
107
 				            {
108
-				            	known_outdoor_users.add(cn.getAuthor());
109
-					            Collections.sort(known_outdoor_users);
108
+				            	if(!known_outdoor_users.contains(cn.getAuthor()))
109
+				            	{
110
+				            		known_outdoor_users.add(cn.getAuthor());
111
+						            Collections.sort(known_outdoor_users);
112
+				            	}
110
 				            }
113
 				            }
111
 				            else
114
 				            else
112
 				            {
115
 				            {
113
-				            	known_users.add(cn.getAuthor());
114
-					            Collections.sort(known_users);
116
+				            	if(!known_users.contains(cn.getAuthor()))
117
+				            	{
118
+				            		known_users.add(cn.getAuthor());
119
+						            Collections.sort(known_users);
120
+				            	}
115
 				            }
121
 				            }
116
 			        	}
122
 			        	}
117
-			        		
118
-			        	knownUsersPanel.setText("");
123
+	            		knownUsersPanel.setText("");
119
 			            knownUsersPanel.append("Indoor users:\n");
124
 			            knownUsersPanel.append("Indoor users:\n");
120
 			            for(User a:known_users)
125
 			            for(User a:known_users)
121
 			            {
126
 			            {
128
 			            }
133
 			            }
129
 			            displayArea.setCaretPosition(displayArea.getDocument().getLength());
134
 			            displayArea.setCaretPosition(displayArea.getDocument().getLength());
130
 	            	}
135
 	            	}
131
-	            	if(!notif.getAuthor().equals(user.getName()) && !notif.isRedirected())
132
-	            	{
133
-	            		for(Socket s:outdoor_dest_sockets)
134
-				    	{
135
-				    		try
136
-				    		{
137
-				    			ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
138
-				    			notif.setRedirected(true);
139
-				    		    out.writeObject(notif);
140
-				    		}
141
-				    		catch(IOException e){}
142
-				    	}
143
-	            	}
144
 		      }
136
 		      }
145
     	}
137
     	}
146
 		catch(EOFException e) {}
138
 		catch(EOFException e) {}

+ 6
- 2
src/chat/User.java View File

32
 		return address;
32
 		return address;
33
 	}*/
33
 	}*/
34
 	
34
 	
35
-	boolean equals(User b)
35
+	public boolean equals(Object b)
36
 	{
36
 	{
37
-		return (b.getName() == name);
37
+		if(!(b instanceof User))
38
+			return false;
39
+		
40
+		User u = (User) b;
41
+		return u.getName().equals(name);
38
 	}
42
 	}
39
 	
43
 	
40
 	public int compareTo (User otherUser)
44
 	public int compareTo (User otherUser)

Loading…
Cancel
Save