outdoor users(17-2)

This commit is contained in:
Louis Farina 2021-02-15 18:14:09 +01:00
parent 3ce1752ddd
commit 1421b1efcf
3 changed files with 14 additions and 9 deletions

View file

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

View file

@ -64,7 +64,7 @@ public class NetworkClient {
int portNumber = 1237;
byte[] buffer1 = new byte[20000];
if(username == null || username.compareTo("") == 0)
if(username == null || username.compareTo("") == 0 || username.contains(";") || username.contains(" "))
return false;
try
@ -123,10 +123,12 @@ public class NetworkClient {
System.out.println(usernameList.length + " users currently connected");
for(String u:usernameList)
{
if(u.length() > 0)
known_users.add(new User (u));
}
for(String u:outdoorUsernameList)
{
if(u.length() > 0)
known_outdoor_users.add(new User (u));
}
for(String a:addressList)

View file

@ -47,31 +47,34 @@ class ReceiveThread extends Thread {
if(!(notif.getAuthor().equals(user)) && !notif.isRedirected())
{
notif.setRedirected(true);
for(Socket s:outdoor_dest_sockets)
{
try
{
try
{
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
notif.setRedirected(true);
out.writeObject(notif);
notif.setRedirected(false);
}
catch(IOException e){}
}
notif.setRedirected(false);
}
if(isOutdoor)
{
notif.setRedirected(true);
for(Socket s:dest_sockets)
{
try
{
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
notif.setRedirected(true);
out.writeObject(notif);
}
catch(IOException e){}
}
notif.setRedirected(false);
}
else
{
@ -132,7 +135,7 @@ class ReceiveThread extends Thread {
knownUsersPanel.append("\nOutdoor users:\n");
for(User a:known_outdoor_users)
{
knownUsersPanel.append(" " + a.getName() + " \n");
knownUsersPanel.append("(" + a.getName() + ") \n");
}
displayArea.setCaretPosition(displayArea.getDocument().getLength());
}