com.planet_ink.coffee_mud.core.intermud.i3.net
Class Interactive

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.intermud.i3.net.Interactive
All Implemented Interfaces:
ServerObject, ServerUser
Direct Known Subclasses:
IMudUser

public abstract class Interactive
extends java.lang.Object
implements ServerUser

This class provides an implementation of the Imaginary server interactive module. It is responsible for handling the login of an individual user and processing its input as directed by the server. Created: 27 September 1996 Last modified: 27 September 1996


Constructor Summary
Interactive()
          Constructs a new interactive object and initializes its data.
 
Method Summary
 void connect()
          Implementation of the ServerUser connect method.
static java.lang.String createKeyName(java.lang.String nom)
          Given a user name, this method will build a unique key.
 void destruct()
          Stops any running I/O threads for this interactive, closes the user socket, and marks the object for destruction according to the requirements of the ServerObject interface.
static Interactive findUser(java.lang.String nom)
          Given a user name, this method will find the Interactive instance associated with that user name.
 java.lang.String getAddressName()
          Provides the address from which this user is connected.
 InteractiveBody getBody()
          Provides the body to which this user is connected.
 java.util.Date getCurrentLoginTime()
          Provides the time at which the user logged in for this session
 boolean getDestructed()
          Tells whether or not the user is marked for destruction.
 java.lang.String getDisplayName()
          Provides the user's name as they wish it to appear with mixed capitalization, spaces, hyphens, etc.
 java.lang.String getEmail()
          Provides the user's email address
 int getIdle()
          Provides the number of seconds which have elapsed since the user last entered a command.
 java.lang.String getKeyName()
          Provides the key name for this user.
 java.lang.String getLastLoginSite()
          Provides the name of the site from which the user logged in at their last login.
 java.util.Date getLastLoginTime()
          Provides the time of the user's last login.
 java.lang.String getObjectId()
          Gives the user object's object id.
protected  java.lang.String getPassword()
          Allows a subclass to get the password.
 java.lang.String getPrompt()
          Provides the user's command prompt.
 java.lang.String getRealName()
          Provides the user's real name, or null if they never entered a real name.
protected  void input(java.lang.String cmd)
          Called whenever a command is pulled off the incoming command stack.
protected  void loseLink()
          This method is triggered by the input thread when it detects that the user has lost their link.
 void processEvent()
          Does event handling for the user object.
 void processInput()
          The server triggers this method once each server cycle to see if the user has any input waiting to be processed.
 void redirectInput(Input ob)
          Redirects user input to the input object passed to it.
 void sendMessage(java.lang.String msg)
          Sends a message across to the client with a newline appended to the message.
 void sendMessage(java.lang.String msg, boolean nowrap)
          Sends a message across to the client.
 void setBody(InteractiveBody ob)
          Sets the body to which this interactive connection is connected.
 void setDisplayName(java.lang.String str)
          Sets the user's display name.
 void setEmail(java.lang.String str)
          Sets the user's email address
protected  void setKeyName(java.lang.String str)
          Sets the key name during user creation.
 void setLastLoginSite(java.lang.String site)
          Sets the last login site.
 void setLastLoginTime(java.util.Date time)
          Used by the login process to set the last login time.
 void setObjectId(java.lang.String id)
          Allows the server to set the object id.
protected  void setPassword(java.lang.String pass)
          Sets the user's password.
 void setRealName(java.lang.String nom)
          Sets the user's real name.
 void setSocket(java.net.Socket s)
          Called by the server before connect() is called to assign the socket for this Interactive to it.
 boolean validatePassword(java.lang.String other)
          Validates a user password against a random string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interactive

public Interactive()
Constructs a new interactive object and initializes its data.

Method Detail

createKeyName

public static java.lang.String createKeyName(java.lang.String nom)
                                      throws InvalidNameException
Given a user name, this method will build a unique key. This unique key has nothing to do with the unique object id. The idea behind a key name is to ensure that you do not end up with a user named Descartes and a user named Des Cartes. It removes all non-alphabetic characters and makes the string lower case.

Parameters:
nom - the visual name to create a key from
Returns:
the new key
Throws:
InvalidNameException - thrown if the name produces an unuseable key
InvalidNameException - an error telling you to pick a new name

findUser

public static Interactive findUser(java.lang.String nom)
Given a user name, this method will find the Interactive instance associated with that user name. If no such user is currently logged in, this method will return null.

Parameters:
nom - the name of the desired user
Returns:
the Interactive object for the specified name or null if no such user exists

connect

public void connect()
Implementation of the ServerUser connect method. A mudlib will want to display a welcome screen and ask for a user name by extending this method. Here, the login time is set.

Specified by:
connect in interface ServerUser

destruct

public void destruct()
Stops any running I/O threads for this interactive, closes the user socket, and marks the object for destruction according to the requirements of the ServerObject interface.

Specified by:
destruct in interface ServerObject
See Also:
ServerObject.getDestructed()

input

protected void input(java.lang.String cmd)
Called whenever a command is pulled off the incoming command stack. If there is an instance of the Input class to which input is supposed to be redirected, then the command is sent there. Otherwise it is sent to the parser. Muds wishing to implement their own parser system should

Parameters:
cmd - the command to be executed
See Also:
processInput()

loseLink

protected void loseLink()
This method is triggered by the input thread when it detects that the user has lost their link. It will tell the body object that the link is lost, then destruct itself.


processEvent

public void processEvent()
Does event handling for the user object. Each server cycle, the server triggers this method. If the user has periodic events which occur to it, the event processor will flag that the event() method should be called.

Specified by:
processEvent in interface ServerObject
See Also:
ServerObject.processEvent()

processInput

public final void processInput()
The server triggers this method once each server cycle to see if the user has any input waiting to be processed. This method checks the input queue. If there is input waiting, it updates the last command time and calls the input() method with the waiting command. Otherwise it simply returns.

Specified by:
processInput in interface ServerUser
See Also:
input(java.lang.String), ServerUser.processInput(), ServerThread.tick(com.planet_ink.coffee_mud.core.interfaces.Tickable, int)

redirectInput

public final void redirectInput(Input ob)
Redirects user input to the input object passed to it. This will create a LIFO chain of input redirection. For example, if I have my input currently redirected to a mud created editor, then I wish to get help from inside the editor, my next input will be directed to the help prompt. If I enter something at that point with no further input redirection, my next input will then go back to the editor.

Parameters:
ob - the instance of com.planet_ink.coffee_mud.core.intermud.i3.net.Input to which input will be redirected
See Also:
Input, input(java.lang.String)

sendMessage

public final void sendMessage(java.lang.String msg)
Sends a message across to the client with a newline appended to the message.

Parameters:
msg - the message to send to the client machine

sendMessage

public final void sendMessage(java.lang.String msg,
                              boolean nowrap)
Sends a message across to the client. It will append nowrap is true, no newline will be appended.

Parameters:
msg - the message to send to the client
nowrap - if true, no newline is attached

validatePassword

public final boolean validatePassword(java.lang.String other)
Validates a user password against a random string.

Parameters:
other - the password to check
Returns:
true if the two passwords match

getAddressName

public final java.lang.String getAddressName()
Provides the address from which this user is connected.

Returns:
the host name for this user's current site

getBody

public final InteractiveBody getBody()
Provides the body to which this user is connected.

Returns:
the body to which this user is connected, or null if no body exists

setBody

public void setBody(InteractiveBody ob)
Sets the body to which this interactive connection is connected. Any mudlib using this system for interactive management must implement the InteractiveBody interface for any body to be used by a user.

Parameters:
ob - the body to which this interactive is being connected
See Also:
InteractiveBody

getCurrentLoginTime

public final java.util.Date getCurrentLoginTime()
Provides the time at which the user logged in for this session

Returns:
the time of login for the current session

getDestructed

public boolean getDestructed()
Tells whether or not the user is marked for destruction.

Specified by:
getDestructed in interface ServerObject
Returns:
true if the user is marked for destruction

getDisplayName

public java.lang.String getDisplayName()
Provides the user's name as they wish it to appear with mixed capitalization, spaces, hyphens, etc.

Returns:
the user's display name

setDisplayName

public final void setDisplayName(java.lang.String str)
Sets the user's display name. Prevents the operation if the display name is not a permutation of the key name.

Parameters:
str - the new display name

getEmail

public final java.lang.String getEmail()
Provides the user's email address

Returns:
the email address for this user

setEmail

public final void setEmail(java.lang.String str)
Sets the user's email address

Parameters:
str - the new email address

getIdle

public final int getIdle()
Provides the number of seconds which have elapsed since the user last entered a command.

Returns:
the idle time in seconds

getKeyName

public final java.lang.String getKeyName()
Provides the key name for this user. The key name is a play on the user name to create a unique identifier for this user that will always work. For example, the following command should work for a user: tell descartes hi! tell deScartes hi! tell des cartes hi! The key name thus creates a common denomenator to which a name can be reduced for comparison.

Returns:
the key name
See Also:
createKeyName(java.lang.String)

setKeyName

protected void setKeyName(java.lang.String str)
Sets the key name during user creation. This prevents resetting of the key name.

Parameters:
str - the key name being set
See Also:
getKeyName()

getLastLoginSite

public final java.lang.String getLastLoginSite()
Provides the name of the site from which the user logged in at their last login.

Returns:
the last login site

setLastLoginSite

public void setLastLoginSite(java.lang.String site)
Sets the last login site. Used by a subclass during login.

Parameters:
site - the last login site

getLastLoginTime

public final java.util.Date getLastLoginTime()
Provides the time of the user's last login.

Returns:
the last login time

setLastLoginTime

public void setLastLoginTime(java.util.Date time)
Used by the login process to set the last login time.

Parameters:
time - the time the user last logged in

getObjectId

public final java.lang.String getObjectId()
Gives the user object's object id.

Specified by:
getObjectId in interface ServerObject
Returns:
the object id
See Also:
ServerObject.getObjectId()

setObjectId

public final void setObjectId(java.lang.String id)
Allows the server to set the object id.

Specified by:
setObjectId in interface ServerObject
Parameters:
id - the object id assigned to this object
See Also:
ServerObject.setObjectId(java.lang.String)

getPassword

protected java.lang.String getPassword()
Allows a subclass to get the password.

Returns:
the user's password

setPassword

protected void setPassword(java.lang.String pass)
Sets the user's password.

Parameters:
pass - the new password

getPrompt

public java.lang.String getPrompt()
Provides the user's command prompt.

Returns:
the command prompt

getRealName

public final java.lang.String getRealName()
Provides the user's real name, or null if they never entered a real name.

Returns:
the user's real name or null

setRealName

public void setRealName(java.lang.String nom)
Sets the user's real name.

Parameters:
nom - the real name for the user

setSocket

public final void setSocket(java.net.Socket s)
                     throws java.io.IOException
Called by the server before connect() is called to assign the socket for this Interactive to it.

Specified by:
setSocket in interface ServerUser
Parameters:
s - the socket for this connection
Throws:
java.io.IOException - thrown if a problem creating I/O streams occurs
See Also:
ServerUser.setSocket(java.net.Socket)