Class ChatServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--ChatServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ChatServlet
extends javax.servlet.GenericServlet

This servlet will take care of incoming users connecting through the Chatlet and open a connection to an IRC server, thereafter relaying information between them.

See Also:
Serialized Form

Constructor Summary
ChatServlet()
           
 
Method Summary
 void broadcast(java.lang.String str)
          Used to broadcast a message to all connected users.
 void closeConnection(UserConnection activeConnection)
          Used to close a connection and log out a user from IRC and from the servlet.
 UserConnection connectUser(java.lang.String input, java.io.ObjectOutputStream userStream, java.lang.String ip, java.lang.String host)
          Used in the login sequence to create a user object.
 void destroy()
          Invoked when the servlet is being shut down by the servlet engine or web server.
 UserConnection findConnection(int code, java.lang.String ip)
          Used to find a connection associated with a user.
 int getDebug()
          Used to get the current debug level mask.
 java.lang.String getServletInfo()
          Used to retrieve information from the servlet.
 java.lang.String getVersion()
          Used to retrieve version information.
 void init()
          Invoked when the servlet is created.
 boolean isHostBanned(java.lang.String host)
          Used to check whether a connecting host is banned or not.
 void service(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Takes care of incoming messages and commands from users.
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatServlet

public ChatServlet()
Method Detail

getServletInfo

public java.lang.String getServletInfo()
Used to retrieve information from the servlet.
Overrides:
getServletInfo in class javax.servlet.GenericServlet
Returns:
A String containing connection the number of currently connected users.

getVersion

public java.lang.String getVersion()
Used to retrieve version information.
Returns:
A String containing version info.

destroy

public void destroy()
Invoked when the servlet is being shut down by the servlet engine or web server.
Overrides:
destroy in class javax.servlet.GenericServlet

init

public void init()
Invoked when the servlet is created. Some parameters are read here and defaults are used if they are non-existant.
Overrides:
init in class javax.servlet.GenericServlet

service

public void service(javax.servlet.ServletRequest request,
                    javax.servlet.ServletResponse response)
             throws javax.servlet.ServletException,
                    java.io.IOException
Takes care of incoming messages and commands from users.
Overrides:
service in class javax.servlet.GenericServlet
Parameters:
request - The request object.
response - The response object.

findConnection

public UserConnection findConnection(int code,
                                     java.lang.String ip)
                              throws java.io.IOException
Used to find a connection associated with a user. The method uses only the parts of information about a user that makes him/her unique.
Parameters:
code - The unique code for this user.
host - The host the user is connecting from.

connectUser

public UserConnection connectUser(java.lang.String input,
                                  java.io.ObjectOutputStream userStream,
                                  java.lang.String ip,
                                  java.lang.String host)
                           throws java.io.IOException,
                                  java.lang.IndexOutOfBoundsException,
                                  java.lang.NumberFormatException
Used in the login sequence to create a user object.
Parameters:
input - The input containing login information.
userStream - The stream connected to this user.
ip - The ip the user is connecting from.
host - The host the user is connecting from.
Returns:
The connection object for this user.

getDebug

public int getDebug()
Used to get the current debug level mask.
Returns:
The current debug level mask, where:

0000 (0) = no debug messages
0001 (1) = incoming irc messages will be printed
0010 (2) = incoming user messages will be printed
0100 (4) = outgoing irc messages will be printed
1000 (8) = outgoing user messages will be printed


isHostBanned

public boolean isHostBanned(java.lang.String host)
Used to check whether a connecting host is banned or not.
Parameters:
host - The host to check.
Returns:
true if the host is banned.

closeConnection

public void closeConnection(UserConnection activeConnection)
Used to close a connection and log out a user from IRC and from the servlet.
Parameters:
activeConnection - The connection to close.

broadcast

public void broadcast(java.lang.String str)
Used to broadcast a message to all connected users.
Parameters:
str - The String to be broadcasted.