Compare commits

..

No commits in common. "38ee3f108cfc0dffc30a2b15ecd56a800282aacb" and "972671ee8ffb1ae2e4c26bace83cc7a55f8af5bc" have entirely different histories.

3 changed files with 45 additions and 41 deletions

Binary file not shown.

View file

@ -44,21 +44,6 @@ class ReceiveThread extends Thread {
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Notification notif = (Notification) in.readObject();
if(!(notif.getAuthor().equals(user)) && !notif.isRedirected())
{
System.out.println("Redirecting message");
for(Socket s:outdoor_dest_sockets)
{
try
{
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
notif.setRedirected(true);
out.writeObject(notif);
}
catch(IOException e){}
}
}
if(isOutdoor)
{
for(Socket s:dest_sockets)
@ -77,18 +62,33 @@ class ReceiveThread extends Thread {
if(notif instanceof Message)
{
Message m = (Message) notif;
displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
displayArea.append(m.getAuthor() + " : " + m.getText() + "\n");
}
else if (notif instanceof DisconnectNotification)
{
DisconnectNotification dn = (DisconnectNotification) notif;
displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
for(int i = 0;i < known_users.size();i ++)
{
if (known_users.get(i).getName().equals(dn.getAuthor()))
{
known_users.remove(i);
break;
//System.out.println("Removing " + message.getAuthor());
}
}
for(int i = 0;i < known_outdoor_users.size();i ++)
{
if (known_outdoor_users.get(i).getName().equals(dn.getAuthor()))
{
known_outdoor_users.remove(i);
break;
//System.out.println("Removing " + message.getAuthor());
}
}
known_users.remove(dn.getAuthor());
known_outdoor_users.remove(dn.getAuthor());
if(!dn.isRedirected() && !dn.getAuthor().equals(user))
if(!dn.isRedirected() && !dn.getAuthor().equals(user.getName()))
{
socket.close();
if(!isOutdoor)
@ -104,22 +104,17 @@ class ReceiveThread extends Thread {
displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
if(cn.isOutdoor())
{
if(!known_outdoor_users.contains(cn.getAuthor()))
{
known_outdoor_users.add(cn.getAuthor());
Collections.sort(known_outdoor_users);
}
}
else
{
if(!known_users.contains(cn.getAuthor()))
{
known_users.add(cn.getAuthor());
Collections.sort(known_users);
}
}
}
knownUsersPanel.setText("");
knownUsersPanel.append("Indoor users:\n");
for(User a:known_users)
@ -133,6 +128,19 @@ class ReceiveThread extends Thread {
}
displayArea.setCaretPosition(displayArea.getDocument().getLength());
}
if(!notif.getAuthor().equals(user.getName()) && !notif.isRedirected())
{
for(Socket s:outdoor_dest_sockets)
{
try
{
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
notif.setRedirected(true);
out.writeObject(notif);
}
catch(IOException e){}
}
}
}
}
catch(EOFException e) {}

View file

@ -32,13 +32,9 @@ public class User implements Comparable<User>, Serializable{
return address;
}*/
public boolean equals(Object b)
boolean equals(User b)
{
if(!(b instanceof User))
return false;
User u = (User) b;
return u.getName().equals(name);
return (b.getName() == name);
}
public int compareTo (User otherUser)