diff --git a/cs656/lab4/ChatClient.java b/cs656/lab4/ChatClient.java index a7a706d..a025da2 100644 --- a/cs656/lab4/ChatClient.java +++ b/cs656/lab4/ChatClient.java @@ -217,6 +217,18 @@ public class ChatClient System.out.println(" available - set status to busy/away"); System.out.println(" exit - disconnect and exit program"); } + else if (command.equals("friends")) + { + RegistrationInfo[] friends = myPServ.listRegisteredUsers(); + System.out.println("Registered Users:"); + for (RegistrationInfo ri : friends) + { + System.out.print(ri.getUserName()); + System.out.print(" ["); + System.out.print(ri.getStatus() ? "available" : "busy"); + System.out.println("]"); + } + } else if (command.equals("talk")) { String user = ""; @@ -248,6 +260,22 @@ public class ChatClient System.out.println("Syntax: talk {user} {message}"); } } + else if (command.equals("broadcast")) + { + RegistrationInfo[] ris = myPServ.listRegisteredUsers(); + for (RegistrationInfo ri : ris) + { + /* don't send a message to ourselves */ + if (!ri.getUserName().equals(myUserName)) + { + /* send message only if user available */ + if (ri.getStatus()) + { + sendUserMessage(ri.getUserName(), rest); + } + } + } + } else if (command.equals("busy")) { if (myRegistrationInfo.getStatus()) @@ -328,23 +356,28 @@ public class ChatClient String host = "localhost"; int port = 42842; - for (int arg = 0; arg < args.length; arg++) + if (args.length < 1) { - switch (arg) + usage(); + return; + } + + user = args[0]; + user = user.replace(' ', '_'); + + if (args.length >= 2) + { + StringTokenizer st = new StringTokenizer(args[1], ":"); + if (st.hasMoreTokens()) { - case 0: - user = args[arg].replace(' ', '_'); - break; - case 1: - host = args[arg]; - break; - default: - usage(); + host = st.nextToken(); + if (st.hasMoreTokens()) + { + port = Integer.parseInt(st.nextToken()); + } } } - if (user == null) - usage(); PresenceService pServ = new PresenceServiceImpl(host, port); @@ -354,7 +387,7 @@ public class ChatClient private static void usage() { - System.err.println("Usage: java ChatClient {host}"); + System.err.println("Usage: ChatClient [host[:port]]"); System.exit(42); } }