Browse Source

outdoor users(19)

Louis Farina 3 years ago
parent
commit
03d3c77895
1 changed files with 100 additions and 100 deletions
  1. 100
    100
      src/chat/ReceiveThread.java

+ 100
- 100
src/chat/ReceiveThread.java View File

@@ -38,113 +38,113 @@ class ReceiveThread extends Thread {
38 38
 	public void run()
39 39
 	{
40 40
 		boolean exit = false;
41
-		try
42
-    	{
43
-			while(!exit)
41
+		while(!exit)
42
+		{
43
+			try
44 44
 			{
45
-        			ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
46
-			        Notification notif = (Notification) in.readObject();
47
-			        
48
-			        if(!(notif.getAuthor().equals(user)) && !(notif.getAuthor().isOutdoor() && !isOutdoor))
49
-	            	{
50
-	            		for(Socket s:outdoor_dest_sockets)
51
-				    	{
52
-				    		try
53
-				    		{
54
-				    			ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
55
-				    			
56
-				    		    out.writeObject(notif);
57
-				    		    
58
-				    		}
59
-				    		catch(IOException e){}
60
-				    	}
61
-	            	}
62
-			        
63
-	            	if(isOutdoor)
64
-		            {
65
-		            	for(Socket s:dest_sockets)
45
+				ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
46
+		        Notification notif = (Notification) in.readObject();
47
+		        
48
+		        if(!(notif.getAuthor().equals(user)) && !(notif.getAuthor().isOutdoor() && !isOutdoor))
49
+            	{
50
+            		for(Socket s:outdoor_dest_sockets)
51
+			    	{
52
+			    		try
66 53
 			    		{
67
-			    			try
68
-			    			{
69
-			    				ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
70
-			    				
71
-			    			    out.writeObject(notif);
72
-			    			}
73
-			    			catch(IOException e){}
54
+			    			ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
55
+			    			
56
+			    		    out.writeObject(notif);
57
+			    		    
74 58
 			    		}
59
+			    		catch(IOException e){}
60
+			    	}
61
+            	}
62
+		        
63
+            	if(isOutdoor)
64
+	            {
65
+	            	for(Socket s:dest_sockets)
66
+		    		{
67
+		    			try
68
+		    			{
69
+		    				ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
70
+		    				
71
+		    			    out.writeObject(notif);
72
+		    			}
73
+		    			catch(IOException e){}
74
+		    		}
75 75
 
76
-		            }
77
-	            	else
78
-	            	{
79
-	            		if(notif instanceof Message)
80
-				        {
81
-				        	Message m = (Message) notif;
82
-					        displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
83
-				        }
84
-			        	else if (notif instanceof DisconnectNotification)
85
-			        	{
86
-			        		DisconnectNotification dn = (DisconnectNotification) notif;
87
-			        		
88
-				            displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
89
-				            
90
-				            known_users.remove(dn.getAuthor());
91
-				            known_outdoor_users.remove(dn.getAuthor());
92
-				            
93
-				          if(!dn.getAuthor().equals(user) && !(dn.getAuthor().isOutdoor() && !isOutdoor))
94
-				            {
95
-				            	exit = true;
96
-				            	
97
-				            	socket.close();
98
-				            	if(!isOutdoor)
99
-				            	dest_sockets.remove(socket);
100
-				            	else
101
-				            	outdoor_dest_sockets.remove(socket);
102
-				            }
103
-			        	}
104
-			        	
105
-			        	else if (notif instanceof ConnectNotification)
106
-			        	{
107
-			        		ConnectNotification cn = (ConnectNotification) notif;
108
-			        		
109
-				            displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
110
-				            if(cn.getAuthor().isOutdoor())
111
-				            {
112
-				            	if(!known_outdoor_users.contains(cn.getAuthor()))
113
-				            	{
114
-				            		known_outdoor_users.add(cn.getAuthor());
115
-						            Collections.sort(known_outdoor_users);
116
-				            	}
117
-				            }
118
-				            else
119
-				            {
120
-				            	if(!known_users.contains(cn.getAuthor()))
121
-				            	{
122
-				            		known_users.add(cn.getAuthor());
123
-						            Collections.sort(known_users);
124
-				            	}
125
-				            }
126
-			        	}
127
-	            		knownUsersPanel.setText("");
128
-			            knownUsersPanel.append("Indoor users:\n");
129
-			            for(User a:known_users)
76
+	            }
77
+            	else
78
+            	{
79
+            		if(notif instanceof Message)
80
+			        {
81
+			        	Message m = (Message) notif;
82
+				        displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
83
+			        }
84
+		        	else if (notif instanceof DisconnectNotification)
85
+		        	{
86
+		        		DisconnectNotification dn = (DisconnectNotification) notif;
87
+		        		
88
+			            displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
89
+			            
90
+			            known_users.remove(dn.getAuthor());
91
+			            known_outdoor_users.remove(dn.getAuthor());
92
+			            
93
+			          if(!dn.getAuthor().equals(user) && !(dn.getAuthor().isOutdoor() && !isOutdoor))
94
+			            {
95
+			            	exit = true;
96
+			            	
97
+			            	socket.close();
98
+			            	if(!isOutdoor)
99
+			            	dest_sockets.remove(socket);
100
+			            	else
101
+			            	outdoor_dest_sockets.remove(socket);
102
+			            }
103
+		        	}
104
+		        	
105
+		        	else if (notif instanceof ConnectNotification)
106
+		        	{
107
+		        		ConnectNotification cn = (ConnectNotification) notif;
108
+		        		
109
+			            displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
110
+			            if(cn.getAuthor().isOutdoor())
130 111
 			            {
131
-			            	knownUsersPanel.append(" " + a.getName() + "  \n");
112
+			            	if(!known_outdoor_users.contains(cn.getAuthor()))
113
+			            	{
114
+			            		known_outdoor_users.add(cn.getAuthor());
115
+					            Collections.sort(known_outdoor_users);
116
+			            	}
132 117
 			            }
133
-			            knownUsersPanel.append("\nOutdoor users:\n");
134
-			            for(User a:known_outdoor_users)
118
+			            else
135 119
 			            {
136
-			            	knownUsersPanel.append(" " + a.getName() + "  \n");
120
+			            	if(!known_users.contains(cn.getAuthor()))
121
+			            	{
122
+			            		known_users.add(cn.getAuthor());
123
+					            Collections.sort(known_users);
124
+			            	}
137 125
 			            }
138
-			            displayArea.setCaretPosition(displayArea.getDocument().getLength());
139
-	            	}
140
-		      }
141
-    	}
142
-		catch(Exception e)
143
-    	{
144
-			/*e.printStackTrace();
145
-			System.out.println("Socket closed");
146
-        	dest_sockets.remove(socket);
147
-        	outdoor_dest_sockets.remove(socket);*/
148
-    	}
126
+		        	}
127
+            		knownUsersPanel.setText("");
128
+		            knownUsersPanel.append("Indoor users:\n");
129
+		            for(User a:known_users)
130
+		            {
131
+		            	knownUsersPanel.append(" " + a.getName() + "  \n");
132
+		            }
133
+		            knownUsersPanel.append("\nOutdoor users:\n");
134
+		            for(User a:known_outdoor_users)
135
+		            {
136
+		            	knownUsersPanel.append(" " + a.getName() + "  \n");
137
+		            }
138
+		            displayArea.setCaretPosition(displayArea.getDocument().getLength());
139
+            	}
140
+			}
141
+			catch(Exception e)
142
+	    	{
143
+				e.printStackTrace();
144
+				/*System.out.println("Socket closed");
145
+	        	dest_sockets.remove(socket);
146
+	        	outdoor_dest_sockets.remove(socket);*/
147
+	    	}
148
+		}
149 149
 	}
150 150
 }

Loading…
Cancel
Save