Browse Source

outdoor users(17-2)

Louis Farina 1 year ago
parent
commit
1421b1efcf
3 changed files with 14 additions and 9 deletions
  1. 2
    2
      src/chat/ClientWindow.java
  2. 3
    1
      src/chat/NetworkClient.java
  3. 9
    6
      src/chat/ReceiveThread.java

+ 2
- 2
src/chat/ClientWindow.java View File

@@ -82,8 +82,8 @@ public class ClientWindow implements ActionListener {
82 82
             	connected = network.connect(username, outdoor, destinationIP);
83 83
             	if(!connected && username != null)
84 84
             	{
85
-            		if(username.equals(""))
86
-            			JOptionPane.showMessageDialog(chatWindow, "Please enter a username", "Error", JOptionPane.ERROR_MESSAGE);
85
+            		if(username.equals("") || username.contains(" ") || username.contains(";"))
86
+            			JOptionPane.showMessageDialog(chatWindow, "Please enter a valid username", "Error", JOptionPane.ERROR_MESSAGE);
87 87
             		else
88 88
             			JOptionPane.showMessageDialog(chatWindow, "This username is already taken", "Error", JOptionPane.ERROR_MESSAGE);
89 89
             	}

+ 3
- 1
src/chat/NetworkClient.java View File

@@ -64,7 +64,7 @@ public class NetworkClient {
64 64
       int portNumber = 1237;
65 65
       byte[] buffer1 = new byte[20000];
66 66
       
67
-      if(username == null || username.compareTo("") == 0)
67
+      if(username == null || username.compareTo("") == 0 || username.contains(";") || username.contains(" "))
68 68
     	  return false;
69 69
 
70 70
       try
@@ -123,10 +123,12 @@ public class NetworkClient {
123 123
             		System.out.println(usernameList.length + " users currently connected");
124 124
             		for(String u:usernameList)
125 125
                 	{
126
+            			if(u.length() > 0)
126 127
                 		known_users.add(new User (u));
127 128
                 	}
128 129
             		for(String u:outdoorUsernameList)
129 130
                 	{
131
+            			if(u.length() > 0)
130 132
                 		known_outdoor_users.add(new User (u));
131 133
                 	}
132 134
             		for(String a:addressList)

+ 9
- 6
src/chat/ReceiveThread.java View File

@@ -47,31 +47,34 @@ class ReceiveThread extends Thread {
47 47
 			        
48 48
 			        if(!(notif.getAuthor().equals(user)) && !notif.isRedirected())
49 49
 	            	{
50
+	    				notif.setRedirected(true);
51
+
50 52
 	            		for(Socket s:outdoor_dest_sockets)
51
-				    	{
52
-				    		try
53
+				    	{				    		
54
+	            			try
53 55
 				    		{
54 56
 				    			ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
55
-				    			notif.setRedirected(true);
56 57
 				    		    out.writeObject(notif);
57
-				    		    notif.setRedirected(false);
58
+				    		    
58 59
 				    		}
59 60
 				    		catch(IOException e){}
60 61
 				    	}
62
+	    				notif.setRedirected(false);
61 63
 	            	}
62 64
 			        
63 65
 	            	if(isOutdoor)
64 66
 		            {
67
+	    				notif.setRedirected(true);
65 68
 		            	for(Socket s:dest_sockets)
66 69
 			    		{
67 70
 			    			try
68 71
 			    			{
69 72
 			    				ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
70
-			    				notif.setRedirected(true);
71 73
 			    			    out.writeObject(notif);
72 74
 			    			}
73 75
 			    			catch(IOException e){}
74 76
 			    		}
77
+	    				notif.setRedirected(false);
75 78
 		            }
76 79
 	            	else
77 80
 	            	{
@@ -132,7 +135,7 @@ class ReceiveThread extends Thread {
132 135
 			            knownUsersPanel.append("\nOutdoor users:\n");
133 136
 			            for(User a:known_outdoor_users)
134 137
 			            {
135
-			            	knownUsersPanel.append(" " + a.getName() + "  \n");
138
+			            	knownUsersPanel.append("(" + a.getName() + ")  \n");
136 139
 			            }
137 140
 			            displayArea.setCaretPosition(displayArea.getDocument().getLength());
138 141
 	            	}

Loading…
Cancel
Save