outdoor users(19)
This commit is contained in:
parent
f975bc29d0
commit
03d3c77895
1 changed files with 103 additions and 103 deletions
|
@ -38,113 +38,113 @@ class ReceiveThread extends Thread {
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
boolean exit = false;
|
boolean exit = false;
|
||||||
try
|
while(!exit)
|
||||||
{
|
{
|
||||||
while(!exit)
|
try
|
||||||
{
|
{
|
||||||
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.getAuthor().isOutdoor() && !isOutdoor))
|
if(!(notif.getAuthor().equals(user)) && !(notif.getAuthor().isOutdoor() && !isOutdoor))
|
||||||
{
|
{
|
||||||
for(Socket s:outdoor_dest_sockets)
|
for(Socket s:outdoor_dest_sockets)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
|
||||||
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
|
||||||
|
|
||||||
out.writeObject(notif);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(IOException e){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isOutdoor)
|
|
||||||
{
|
|
||||||
for(Socket s:dest_sockets)
|
|
||||||
{
|
{
|
||||||
try
|
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
||||||
{
|
|
||||||
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
out.writeObject(notif);
|
||||||
|
|
||||||
out.writeObject(notif);
|
|
||||||
}
|
|
||||||
catch(IOException e){}
|
|
||||||
}
|
}
|
||||||
|
catch(IOException e){}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isOutdoor)
|
||||||
|
{
|
||||||
|
for(Socket s:dest_sockets)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
||||||
|
|
||||||
|
out.writeObject(notif);
|
||||||
|
}
|
||||||
|
catch(IOException e){}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(notif instanceof Message)
|
||||||
|
{
|
||||||
|
Message m = (Message) notif;
|
||||||
|
displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
|
||||||
|
}
|
||||||
|
else if (notif instanceof DisconnectNotification)
|
||||||
|
{
|
||||||
|
DisconnectNotification dn = (DisconnectNotification) notif;
|
||||||
|
|
||||||
|
displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
|
||||||
|
|
||||||
|
known_users.remove(dn.getAuthor());
|
||||||
|
known_outdoor_users.remove(dn.getAuthor());
|
||||||
|
|
||||||
|
if(!dn.getAuthor().equals(user) && !(dn.getAuthor().isOutdoor() && !isOutdoor))
|
||||||
|
{
|
||||||
|
exit = true;
|
||||||
|
|
||||||
|
socket.close();
|
||||||
|
if(!isOutdoor)
|
||||||
|
dest_sockets.remove(socket);
|
||||||
|
else
|
||||||
|
outdoor_dest_sockets.remove(socket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (notif instanceof ConnectNotification)
|
||||||
|
{
|
||||||
|
ConnectNotification cn = (ConnectNotification) notif;
|
||||||
|
|
||||||
|
displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
|
||||||
|
if(cn.getAuthor().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)
|
||||||
|
{
|
||||||
|
knownUsersPanel.append(" " + a.getName() + " \n");
|
||||||
}
|
}
|
||||||
else
|
knownUsersPanel.append("\nOutdoor users:\n");
|
||||||
{
|
for(User a:known_outdoor_users)
|
||||||
if(notif instanceof Message)
|
{
|
||||||
{
|
knownUsersPanel.append(" " + a.getName() + " \n");
|
||||||
Message m = (Message) notif;
|
}
|
||||||
displayArea.append(m.getAuthor().getName() + " : " + m.getText() + "\n");
|
displayArea.setCaretPosition(displayArea.getDocument().getLength());
|
||||||
}
|
}
|
||||||
else if (notif instanceof DisconnectNotification)
|
}
|
||||||
{
|
catch(Exception e)
|
||||||
DisconnectNotification dn = (DisconnectNotification) notif;
|
{
|
||||||
|
e.printStackTrace();
|
||||||
displayArea.append(dn.getAuthor().getName() + " has left the chat.\n");
|
/*System.out.println("Socket closed");
|
||||||
|
dest_sockets.remove(socket);
|
||||||
known_users.remove(dn.getAuthor());
|
outdoor_dest_sockets.remove(socket);*/
|
||||||
known_outdoor_users.remove(dn.getAuthor());
|
}
|
||||||
|
}
|
||||||
if(!dn.getAuthor().equals(user) && !(dn.getAuthor().isOutdoor() && !isOutdoor))
|
|
||||||
{
|
|
||||||
exit = true;
|
|
||||||
|
|
||||||
socket.close();
|
|
||||||
if(!isOutdoor)
|
|
||||||
dest_sockets.remove(socket);
|
|
||||||
else
|
|
||||||
outdoor_dest_sockets.remove(socket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (notif instanceof ConnectNotification)
|
|
||||||
{
|
|
||||||
ConnectNotification cn = (ConnectNotification) notif;
|
|
||||||
|
|
||||||
displayArea.append(cn.getAuthor().getName() + " has joined the chat.\n");
|
|
||||||
if(cn.getAuthor().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)
|
|
||||||
{
|
|
||||||
knownUsersPanel.append(" " + a.getName() + " \n");
|
|
||||||
}
|
|
||||||
knownUsersPanel.append("\nOutdoor users:\n");
|
|
||||||
for(User a:known_outdoor_users)
|
|
||||||
{
|
|
||||||
knownUsersPanel.append(" " + a.getName() + " \n");
|
|
||||||
}
|
|
||||||
displayArea.setCaretPosition(displayArea.getDocument().getLength());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
/*e.printStackTrace();
|
|
||||||
System.out.println("Socket closed");
|
|
||||||
dest_sockets.remove(socket);
|
|
||||||
outdoor_dest_sockets.remove(socket);*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue