brought back "friends" and "broadcast" commands from lab2
git-svn-id: svn://anubis/gvsu@288 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
783a4e44ce
commit
029d7eb3e2
@ -217,6 +217,18 @@ public class ChatClient
|
|||||||
System.out.println(" available - set status to busy/away");
|
System.out.println(" available - set status to busy/away");
|
||||||
System.out.println(" exit - disconnect and exit program");
|
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"))
|
else if (command.equals("talk"))
|
||||||
{
|
{
|
||||||
String user = "";
|
String user = "";
|
||||||
@ -248,6 +260,22 @@ public class ChatClient
|
|||||||
System.out.println("Syntax: talk {user} {message}");
|
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"))
|
else if (command.equals("busy"))
|
||||||
{
|
{
|
||||||
if (myRegistrationInfo.getStatus())
|
if (myRegistrationInfo.getStatus())
|
||||||
@ -328,23 +356,28 @@ public class ChatClient
|
|||||||
String host = "localhost";
|
String host = "localhost";
|
||||||
int port = 42842;
|
int port = 42842;
|
||||||
|
|
||||||
for (int arg = 0; arg < args.length; arg++)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
switch (arg)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
user = args[arg].replace(' ', '_');
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
host = args[arg];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
usage();
|
usage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user = args[0];
|
||||||
|
user = user.replace(' ', '_');
|
||||||
|
|
||||||
|
if (args.length >= 2)
|
||||||
|
{
|
||||||
|
StringTokenizer st = new StringTokenizer(args[1], ":");
|
||||||
|
if (st.hasMoreTokens())
|
||||||
|
{
|
||||||
|
host = st.nextToken();
|
||||||
|
if (st.hasMoreTokens())
|
||||||
|
{
|
||||||
|
port = Integer.parseInt(st.nextToken());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
usage();
|
|
||||||
|
|
||||||
PresenceService pServ = new PresenceServiceImpl(host, port);
|
PresenceService pServ = new PresenceServiceImpl(host, port);
|
||||||
|
|
||||||
@ -354,7 +387,7 @@ public class ChatClient
|
|||||||
|
|
||||||
private static void usage()
|
private static void usage()
|
||||||
{
|
{
|
||||||
System.err.println("Usage: java ChatClient <username> {host}");
|
System.err.println("Usage: ChatClient <user> [host[:port]]");
|
||||||
System.exit(42);
|
System.exit(42);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user