001    /**
002     * Jetrix TetriNET Server
003     * Copyright (C) 2001-2004  Emmanuel Bourg
004     *
005     * This program is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU General Public License
007     * as published by the Free Software Foundation; either version 2
008     * of the License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
018     */
019    
020    package net.jetrix;
021    
022    import java.io.*;
023    import java.net.*;
024    import java.util.*;
025    
026    /**
027     * Layer handling communication with a client. Incomming messages are turned
028     * into a server understandable format and forwarded to the apropriate
029     * destination for processing (player's channel or main server thread)
030     *
031     * @author Emmanuel Bourg
032     * @version $Revision: 857 $, $Date: 2010-05-04 19:55:19 +0200 (mar., 04 mai 2010) $
033     */
034    public interface Client extends Runnable, Destination
035    {
036        /**
037         * Return the protocol used by this client.
038         */
039        Protocol getProtocol();
040    
041        /**
042         * Return the channel this client subscribed to.
043         */
044        Channel getChannel();
045    
046        /**
047         * Set the channel.
048         */
049        void setChannel(Channel channel);
050    
051        /**
052         * Tell if the client supports multiple channels simultaneously.
053         *
054         * @since 0.2
055         */
056        boolean supportsMultipleChannels();
057    
058        /**
059         * Tell if the client can be affected automatically to a channel
060         * on connecting to the server.
061         *
062         * @since 0.2
063         */
064        boolean supportsAutoJoin();
065    
066        /**
067         * Return the user associated to this client.
068         */
069        User getUser();
070    
071        /**
072         * Returns the name of the user agent (GTetrinet, aTwin, Blocktrix...)
073         * 
074         * @since 0.3
075         */
076        String getAgent();
077    
078        /**
079         * Return the version of the user agent (1.13, 1.14, etc)
080         */
081        String getVersion();
082    
083        /**
084         * Return the Internet address of this client.
085         */
086        InetAddress getInetAddress();
087    
088        /**
089         * Return the time of the connection to the server.
090         */
091        Date getConnectionTime();
092    
093        /**
094         * Return the time in miliseconds of inactivity.
095         *
096         * @since 0.2
097         */
098        long getIdleTime();
099    
100        /**
101         * Returns the character encoding to be used for the messages sent to the client.
102         * 
103         * @since 0.3
104         */
105        String getEncoding();
106    
107        /**
108         * Send a message to the client. The raw message property must be set.
109         *
110         * @param message the message to send
111         */
112        void send(Message message);
113    
114        /**
115         * Receive a message sent by the client.
116         *
117         * @since 0.3
118         */
119        Message receive() throws IOException;
120    
121        /**
122         * Trigger the disconnection of this client.
123         */
124        void disconnect();
125    
126    }