/***********************************************************************

GECCO, a platform for command and control gaming

Copyright (C) 2001 Henrik Bäärnhielm, Andreas Enblom, Niklas
Hallenfur, Karl Hasselström, Henrik Hägerström, Oskar Linde, Jing Fu
Zi and Jon Åslund

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.

***********************************************************************/

package gecco.communication.server;

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

/**
 *  A class that keeps track of the 'physical' connection to a client
 *
 * @author     Niklas Hallenfur
 * @created    June 27, 2001
 */

public class ClientConnection {
    /**
     *  Description of the Field
     */
    private Socket s;
    /**
     *  Description of the Field
     */
    private BufferedOutputStream out;
    /**
     *  Description of the Field
     */
    private BufferedInputStream in;

    /**
     *  Description of the Field
     */
    private DataInputStream data_in;
    /**
     *  Description of the Field
     */
    private DataOutputStream data_out;

    /**
     *  Description of the Field
     */
    private int id;
    /**
     *  Description of the Field
     */
    private String role;


    /**
     * @param  sock             The client's socket
     * @param  r                The client's role
     * @param  n1               the client's unique id
     * @exception  IOException  Description of Exception
     */
    public ClientConnection(Socket sock, String r, int n1) throws IOException {
        s = sock;
        id = n1;
        role = r;
        try {
            in = new BufferedInputStream(s.getInputStream(), 16384);
            //in = s.getInputStream();
            out = new BufferedOutputStream(s.getOutputStream(), 16384);

            data_in = new DataInputStream(in);
            data_out = new DataOutputStream(out);

            //inString = new BufferedReader(new InputStreamReader(s.getInputStream()));
        } catch (IOException ioe) {
            throw ioe;
        }
    }


    /**
     *  Gets the Id attribute of the ClientConnection object
     *
     * @return    The Id value
     */
    public int getId() {
        return id;
    }


    /**
     *  Gets the Role attribute of the ClientConnection object
     *
     * @return    The Role value
     */
    public String getRole() {
        return role;
    }


    /**
     *  Gets the DataOutputStream attribute of the ClientConnection object
     *
     * @return    The DataOutputStream value
     */
    public DataOutputStream getDataOutputStream() {
        return data_out;
    }


    /**
     *  Gets the DataInputStream attribute of the ClientConnection object
     *
     * @return    The DataInputStream value
     */
    public DataInputStream getDataInputStream() {
        return data_in;
    }

}
