vooga.network.chat
Class VoogaChatClient

java.lang.Object
  extended by vooga.network.VoogaClient
      extended by vooga.network.chat.VoogaChatClient
All Implemented Interfaces:
java.lang.Runnable

public class VoogaChatClient
extends VoogaClient

VoogaChatClients handle all server connection and chat communications. This can be used to send/receive messages, create/join chatrooms, etc.

Author:
Trevor Reid

Field Summary
static long ACHIEVEMENT_CHANNEL
           
static java.lang.String CONNECT
           
static java.lang.String DISCONNECT
           
static long ERROR_CHANNEL
           
static long FRIEND_UPDATE_CHANNEL
           
static java.lang.String ONLINE
           
static long PERSONAL_ECHO_CHANNEL
           
static long PERSONAL_MESSAGE_CHANNEL
           
static long SYSTEM_CHANNEL
           
 
Constructor Summary
VoogaChatClient(java.lang.String userName, IVoogaChatReceiver receiver)
           
VoogaChatClient(java.lang.String userName, IVoogaChatReceiver receiver, java.util.List<java.lang.String> friends)
          Creates a VoogaChatClient that listens to the given list of friends.
 
Method Summary
 void addFriend(java.lang.String userName)
          Adds the specified userName as a friend.
 void addFriends(java.util.List<java.lang.String> userNames)
          Adds the list of friends provided by userNames.
 void connect(java.net.InetAddress host)
          Connects to the server.
 java.util.List<java.lang.Long> getChannels()
          Used to determine the channels the client currently occupies.
 boolean inChannel(long channelID)
          Used to check if currently in a channel.
protected  void initializeConnection()
          Performs any necessary set-up for a new connection.
 void joinChannel(long channelID)
          Join the specified channel.
 void leaveChannel(long channelID)
          Leave the specified channel
 void run()
          Background thread runs this and outputs messages from server as they are received.
 void sendMessage(long channelID, java.lang.String message)
          Sends a message to the specified channel
 void sendPersonalMessage(java.lang.String userName, java.lang.String message)
          Sends a personal message to the specified user.
 
Methods inherited from class vooga.network.VoogaClient
allowConnection, blockConnection, connect, connect, disconnect, getMyInputStream, getMyName, getMyOutputStream, getMySocket, isConnected, setConnected, setMyName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERSONAL_MESSAGE_CHANNEL

public static final long PERSONAL_MESSAGE_CHANNEL
See Also:
Constant Field Values

SYSTEM_CHANNEL

public static final long SYSTEM_CHANNEL
See Also:
Constant Field Values

ACHIEVEMENT_CHANNEL

public static final long ACHIEVEMENT_CHANNEL
See Also:
Constant Field Values

ERROR_CHANNEL

public static final long ERROR_CHANNEL
See Also:
Constant Field Values

PERSONAL_ECHO_CHANNEL

public static final long PERSONAL_ECHO_CHANNEL
See Also:
Constant Field Values

FRIEND_UPDATE_CHANNEL

public static final long FRIEND_UPDATE_CHANNEL
See Also:
Constant Field Values

DISCONNECT

public static final java.lang.String DISCONNECT
See Also:
Constant Field Values

CONNECT

public static final java.lang.String CONNECT
See Also:
Constant Field Values

ONLINE

public static final java.lang.String ONLINE
See Also:
Constant Field Values
Constructor Detail

VoogaChatClient

public VoogaChatClient(java.lang.String userName,
                       IVoogaChatReceiver receiver)
Parameters:
userName - The name of the user connected through this client.
receiver - Used to send back messages from the server. If receiver is null, received chat messages just get printed to System.out. You probably do not want this.

VoogaChatClient

public VoogaChatClient(java.lang.String userName,
                       IVoogaChatReceiver receiver,
                       java.util.List<java.lang.String> friends)
Creates a VoogaChatClient that listens to the given list of friends.

Parameters:
userName -
receiver -
friends -
Method Detail

joinChannel

public void joinChannel(long channelID)
Join the specified channel.

Parameters:
channelID - the unique channel ID
Throws:
java.io.IOException

leaveChannel

public void leaveChannel(long channelID)
Leave the specified channel

Parameters:
channelID - the unique channel ID
Throws:
java.io.IOException

run

public void run()
Background thread runs this and outputs messages from server as they are received.


sendMessage

public void sendMessage(long channelID,
                        java.lang.String message)
Sends a message to the specified channel

Parameters:
channelID - the unique ID of the channel to send to
message - the message being sent
Throws:
java.io.IOException

sendPersonalMessage

public void sendPersonalMessage(java.lang.String userName,
                                java.lang.String message)
Sends a personal message to the specified user.

Parameters:
userName - the name of the user to send a message to
message -
Throws:
java.io.IOException

initializeConnection

protected void initializeConnection()
Description copied from class: VoogaClient
Performs any necessary set-up for a new connection.

Specified by:
initializeConnection in class VoogaClient

connect

public void connect(java.net.InetAddress host)
Connects to the server. You MUST call this before you call any other server methods.

Specified by:
connect in class VoogaClient
Parameters:
host - The IP of an existing VoogaChatServer.

getChannels

public java.util.List<java.lang.Long> getChannels()
Used to determine the channels the client currently occupies. This includes standard channels such as SYSTEM_CHANNEL, PERSONAL_MESSAGE_CHANNEL, etc.


inChannel

public boolean inChannel(long channelID)
Used to check if currently in a channel.

Parameters:
channelID -
Returns:
true iff the client is currently in channel specified by channelID.

addFriends

public void addFriends(java.util.List<java.lang.String> userNames)
Adds the list of friends provided by userNames. For each user in the list that is currently online, a message is sent to FRIEND_UPDATE_CHANNEL notifying.

Parameters:
userNames -

addFriend

public void addFriend(java.lang.String userName)
Adds the specified userName as a friend. If the user is online, a message to FRIEND_UPDATE_CHANNEL will be sent notifying.

Parameters:
userName -