outdoor users(13)
This commit is contained in:
parent
972671ee8f
commit
748ab397cd
2 changed files with 41 additions and 45 deletions
|
@ -44,6 +44,21 @@ class ReceiveThread extends Thread {
|
||||||
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
|
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
|
||||||
Notification notif = (Notification) in.readObject();
|
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)
|
if(isOutdoor)
|
||||||
{
|
{
|
||||||
for(Socket s:dest_sockets)
|
for(Socket s:dest_sockets)
|
||||||
|
@ -62,33 +77,18 @@ class ReceiveThread extends Thread {
|
||||||
if(notif instanceof Message)
|
if(notif instanceof Message)
|
||||||
{
|
{
|
||||||
Message m = (Message) notif;
|
Message m = (Message) notif;
|
||||||
displayArea.append(m.getAuthor() + " : " + m.getText() + "\n");
|
displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
|
||||||
}
|
}
|
||||||
else if (notif instanceof DisconnectNotification)
|
else if (notif instanceof DisconnectNotification)
|
||||||
{
|
{
|
||||||
DisconnectNotification dn = (DisconnectNotification) notif;
|
DisconnectNotification dn = (DisconnectNotification) notif;
|
||||||
|
|
||||||
displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
|
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!dn.isRedirected() && !dn.getAuthor().equals(user.getName()))
|
known_users.remove(dn.getAuthor());
|
||||||
|
known_outdoor_users.remove(dn.getAuthor());
|
||||||
|
|
||||||
|
if(!dn.isRedirected() && !dn.getAuthor().equals(user))
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
if(!isOutdoor)
|
if(!isOutdoor)
|
||||||
|
@ -104,17 +104,22 @@ class ReceiveThread extends Thread {
|
||||||
|
|
||||||
displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
|
displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
|
||||||
if(cn.isOutdoor())
|
if(cn.isOutdoor())
|
||||||
|
{
|
||||||
|
if(!known_outdoor_users.contains(cn.getAuthor()))
|
||||||
{
|
{
|
||||||
known_outdoor_users.add(cn.getAuthor());
|
known_outdoor_users.add(cn.getAuthor());
|
||||||
Collections.sort(known_outdoor_users);
|
Collections.sort(known_outdoor_users);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(!known_users.contains(cn.getAuthor()))
|
||||||
{
|
{
|
||||||
known_users.add(cn.getAuthor());
|
known_users.add(cn.getAuthor());
|
||||||
Collections.sort(known_users);
|
Collections.sort(known_users);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
knownUsersPanel.setText("");
|
knownUsersPanel.setText("");
|
||||||
knownUsersPanel.append("Indoor users:\n");
|
knownUsersPanel.append("Indoor users:\n");
|
||||||
for(User a:known_users)
|
for(User a:known_users)
|
||||||
|
@ -128,19 +133,6 @@ class ReceiveThread extends Thread {
|
||||||
}
|
}
|
||||||
displayArea.setCaretPosition(displayArea.getDocument().getLength());
|
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) {}
|
catch(EOFException e) {}
|
||||||
|
|
|
@ -32,9 +32,13 @@ public class User implements Comparable<User>, Serializable{
|
||||||
return address;
|
return address;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
boolean equals(User b)
|
public boolean equals(Object b)
|
||||||
{
|
{
|
||||||
return (b.getName() == name);
|
if(!(b instanceof User))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
User u = (User) b;
|
||||||
|
return u.getName().equals(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo (User otherUser)
|
public int compareTo (User otherUser)
|
||||||
|
|
Loading…
Reference in a new issue