// Melvin K Lew <melvin@columbia.edu>
// $Source: /amd/cheers-fast/root/np/melvin/AIS/aisproj/RCS/ClientInfo.java,v $
// $Date: 1998/04/27 01:46:04 $
// $Author: melvin $
// $Revision: 1.10 $
//
// CS-E6998-03 Advanced Internet Services: Term Project
//
// The JINCS Project: Collaborative Whiteboard Client/Server Application
//
// Group:
//	Johan Andersen <johan@columbia.edu>
//	Richard Denmark <thor@columbia.edu>
//	Melvin Lew <melvin@columbia.edu
//
// A multi-threaded networked Whiteboard Server
//

import java.io.*;
import java.net.*;
import java.util.*;

/**
 * Contains information about each client connected to the Whiteboard server,
 * and maintains the current state of the client.  These objects are stored
 * in a Hashtable.
 *
 * @author	Melvin K Lew
 * @version	$Revision: 1.10 $, $Date: 1998/04/27 01:46:04 $
 *
 * @see		WBCListenThread
 * @see		WBCParser
 * @see		WBCPrintThread
 * @see		WBSListenThread
 * @see		WBServer
 */
public class ClientInfo
{
  private Socket socket = null;			// client socket
  private boolean alive = true;			// alive status
  private BufferedReader brin = null;		// input
  private Date date = null;			// date of connection
  private String hostname = null;		// hostname of client
  private String hostport = null;		// description of client
  private boolean mute = true;		        // mute status
  private int port = -1;		        // port number of client
  private PrintWriter pwout = null;	        // output
  private boolean raisehand = false;	        // raisehand status
  private String type = null;		        // type of client
  private String username = null;	        // username of client

/**
 * Class constructor, determines some fields by reading the socket,
 * creates BufferedReader and PrinterWriter objects to access the client.
 */
  public ClientInfo(Socket socket) throws IOException
  {
    this.socket = socket;
    this.date = new Date();
    this.hostname = socket.getInetAddress().getHostName();
    this.port = socket.getPort();
    this.hostport = this.hostname + "/" + this.port;
    this.username = this.hostport;
    this.brin =
      new BufferedReader(new InputStreamReader(socket.getInputStream()));
    this.pwout = new PrintWriter(socket.getOutputStream(), true);
    this.mute = true;
    this.raisehand = false;
    this.type = "student";
  }

  /**
   * Sets the value of the alive parameter.
   *
   * @param	alive	this boolean indicates whether this client is running
   */
  public void setAlive(boolean alive)		{ this.alive = alive; }

  /**
   * Sets the BufferedReader to use for reading in from the client.
   *
   * @param	brin	the BufferedReader object to use
   */
  public void setBrin(BufferedReader brin)	{ this.brin = brin; }

  /**
   * Sets the date of connection.
   *
   * @param	date	the date of connection
   */
  public void setDate(Date date)		{ this.date = date; }

  /**
   * Sets the hostname of the client.
   *
   * @param	hostname	a string containing the hostname
   */
  public void setHostname(String hostname)	{ this.hostname = hostname; }

  /**
   * Set the hostname/port description of the client.
   *
   * @param	hostport	a string description
   */
  public void setHostport(String hostport)	{ this.hostport = hostport; }

  /**
   * Set the mute status.
   *
   * @param	mute	a boolean mute status
   */
  public void setMute(boolean mute)		{ this.mute = mute; }

  /**
   * Set the port number.
   *
   * @param	port	the integer port number
   */
  public void setPort(int port)			{ this.port = port; }

  /**
   * Set the output printer object.
   *
   * @param	pwout	the PrinterWriter object to write to
   */
  public void setPwout(PrintWriter pwout)	{ this.pwout = pwout; }

  /**
   * Set the raised hand status.
   *
   * @param	raisehand	a boolean raised hand status
   */
  public void setRaisehand(boolean raisehand)	{ this.raisehand = raisehand; }

  /**
   * Set the socket for the client connection.
   *
   * @param	socket	a Socket to the client
   */
  public void setSocket(Socket socket)		{ this.socket = socket; }

  /**
   * Set the type of client.
   *
   * @param	type	a string description "teacher" or "student"
   */
  public void setType(String type)		{ this.type = type; }

  /**
   * Set the username of the client
   *
   * @param	username	a string containing the username
   */
  public void setUsername(String username)	{ this.username = username; }

  /**
   * Returns the alive value.
   *
   * @return	alive boolean
   */
  public boolean getAlive()			{ return alive; }

  /**
   * Returns the brin value.
   *
   * @return	brin BufferedReader
   */
  public BufferedReader getBrin()		{ return brin; }

  /**
   * Returns the date value.
   *
   * @return	date Date
   */
  public Date getDate()				{ return date; }

  /**
   * Returns the hostname value.
   *
   * @return	hostname String
   */
  public String getHostname()			{ return hostname; }

  /**
   * Returns the hostport value.
   *
   * @return	hostport String
   */
  public String getHostport()			{ return hostport; }

  /**
   * Returns the mute value.
   *
   * @return	mute boolean
   */
  public boolean getMute()			{ return mute; }

  /**
   * Returns the port value.
   *
   * @return	port int
   */
  public int getPort()				{ return port; }

  /**
   * Returns the pwout value.
   *
   * @return	pwout PrintWriter
   */
  public PrintWriter getPwout()			{ return pwout; }

  /**
   * Returns the raisehand value.
   *
   * @return	raisehand boolean
   */
  public boolean getRaisehand()			{ return raisehand; }

  /**
   * Returns the socket value.
   *
   * @return	socket Socket
   */
  public Socket getSocket()			{ return socket; }

  /**
   * Returns the type value.
   *
   * @return	type String
   */
  public String getType()			{ return type; }

  /**
   * Returns the username value.
   *
   * @return	username String
   */
  public String getUsername()			{ return username; }
    
}
