com.planet_ink.coffee_mud.core.intermud.i3.packets
Class Intermud

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.intermud.i3.packets.Intermud
All Implemented Interfaces:
Persistent, java.io.Serializable, java.lang.Runnable

public class Intermud
extends java.lang.Object
implements java.lang.Runnable, Persistent, java.io.Serializable

The Intermud class is the central focus of incoming and outgoing Intermud 3 packets. It creates the link to the I3 router, handles reconnection, and routing of packets to the mudlib. The mudlib is responsible for providing two specific objects to interface with this object: an implementation of com.planet_ink.coffee_mud.core.intermud.i3.packets.ImudServices an implementation of com.planet_ink.coffee_mud.core.intermud.i3.persist.PersistentPeer To start up the Intermud connection, call the class method setup(). The class itself creates an instance of itself and serves as a way to interface to the rest of the mudlib. When the mudlib needs to send a packet, it sends it through a class method which then routes it to the proper instance of Intermud.

See Also:
ImudServices, PersistentPeer, Serialized Form

Field Summary
 int attempts
           
 java.util.Hashtable banned
           
 ChannelList channels
           
 NameServer currentRouter
           
 java.io.DataInputStream input
           
 MudList muds
           
 java.util.List<NameServer> name_servers
           
 int password
           
static long serialVersionUID
           
 boolean shutdown
           
 
Fields inherited from interface com.planet_ink.coffee_mud.core.intermud.i3.persist.Persistent
DELETED, MODIFIED, NEW, UNMODIFIED
 
Method Summary
 void addChannel(Channel c)
          Adds a channel to the channel list.
 void addMud(I3Mud m)
          Adds a mud to the list of known muds.
static ChannelList getAllChannelList()
           
static MudList getAllMudsList()
           
 ChannelList getChannelList()
           
static java.lang.String getLocalChannel(java.lang.String c)
          Returns a String representing the local channel name for the specified remote channel by calling the ImudServices implementation of getLocalChannel().
 MudList getMudList()
           
static NameServer getNameServer()
           
 int getPassword()
           
static java.lang.String getRemoteChannel(java.lang.String c)
          Returns a String representing the remote channel name for the specified local channel by calling the ImudServices implementation of getRemoteChannel().
static boolean isAPossibleMUDName(java.lang.String mud)
          Translates a user entered mud name into the mud's canonical name.
static boolean isConnected()
           
static boolean isUp(java.lang.String mud)
          Determines whether or not the specified mud is up.
 void logMemory()
           
static java.lang.String registerFakeChannel(java.lang.String c)
          Register a fake channel
 void removeChannel(Channel c)
          Removes a channel from the channel list.
static java.lang.String removeFakeChannel(java.lang.String c)
          Register a fake channel
 void removeMud(I3Mud m)
          Removed a mud from the list of known muds.
 void restore()
          Prescribes a method for restoration from a data store.
 void run()
           
 void save()
          Prescribes a method for saving this object's data to a data store.
 void send(Packet p)
          Sends any valid subclass of Packet to the router.
static void sendPacket(Packet p)
          Sends a packet to the router.
 void setChannelList(ChannelList list)
          Sets the channel list to a new channel list.
 void setMudList(MudList list)
          Sets the list of known muds to the specified list.
 void setPassword(int pass)
          Sets the Intermud 3 password.
static void setup(ImudServices imud, PersistentPeer peer)
          Creates the initial link to an I3 router.
static void shutdown()
           
 void stop()
          Shuts down the connection to the router without reconnecting.
static java.lang.String translateName(java.lang.String mud)
          Translates a user entered mud name into the mud's canonical name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

shutdown

public boolean shutdown

input

public java.io.DataInputStream input

attempts

public int attempts

banned

public java.util.Hashtable banned

channels

public ChannelList channels

muds

public MudList muds

name_servers

public java.util.List<NameServer> name_servers

password

public int password

currentRouter

public NameServer currentRouter
Method Detail

sendPacket

public static void sendPacket(Packet p)
Sends a packet to the router. The packet must be a valid subclass of com.planet_ink.coffee_mud.core.intermud.i3.packets.Packet. This method will then route the packet to the currently running Intermud instance.

Parameters:
p - an instance of a subclass of com.planet_ink.coffee_mud.core.intermud.i3.packets.Packet
See Also:
Packet

setup

public static void setup(ImudServices imud,
                         PersistentPeer peer)
Creates the initial link to an I3 router. It will handle subsequent reconnections as needed for as long as the mud process is running.

Parameters:
imud - an instance of the mudlib implementation of com.planet_ink.coffee_mud.core.intermud.i3.packets.ImudServices
peer - and instance of the mudlib implementation of com.planet_ink.coffee_mud.core.intermud.i3.packets.IntermudPeer
See Also:
ImudServices, PersistentPeer

translateName

public static java.lang.String translateName(java.lang.String mud)
Translates a user entered mud name into the mud's canonical name.

Parameters:
mud - the user entered mud name
Returns:
the specified mud's canonical name

isAPossibleMUDName

public static boolean isAPossibleMUDName(java.lang.String mud)
Translates a user entered mud name into the mud's canonical name.

Parameters:
mud - the user entered mud name
Returns:
the specified mud's canonical name

registerFakeChannel

public static java.lang.String registerFakeChannel(java.lang.String c)
Register a fake channel

Parameters:
c - the remote channel name
Returns:
the local channel name for the specified new local channel name
See Also:
ImudServices.getLocalChannel(java.lang.String)

removeFakeChannel

public static java.lang.String removeFakeChannel(java.lang.String c)
Register a fake channel

Parameters:
c - the remote channel name
Returns:
the local channel name for the specified new local channel name
See Also:
ImudServices.getLocalChannel(java.lang.String)

getLocalChannel

public static java.lang.String getLocalChannel(java.lang.String c)
Returns a String representing the local channel name for the specified remote channel by calling the ImudServices implementation of getLocalChannel().

Parameters:
c - the remote channel name
Returns:
the local channel name for the specified remote channel name
See Also:
ImudServices.getLocalChannel(java.lang.String)

getRemoteChannel

public static java.lang.String getRemoteChannel(java.lang.String c)
Returns a String representing the remote channel name for the specified local channel by calling the ImudServices implementation of getRemoteChannel().

Parameters:
c - the local channel name
Returns:
the remote channel name for the specified local channel name
See Also:
ImudServices.getRemoteChannel(java.lang.String)

isUp

public static boolean isUp(java.lang.String mud)
Determines whether or not the specified mud is up. You may pass user entered mud names, as this method will take the time to convert to a canonical name.

Parameters:
mud - the name of the mud being checked
Returns:
true if the mud is currently up, false otherwise

getNameServer

public static NameServer getNameServer()

restore

public void restore()
             throws PersistenceException
Description copied from interface: Persistent
Prescribes a method for restoration from a data store. An implementation will usually call the object's PersistentPeer method to perform the actual save.

Specified by:
restore in interface Persistent
Throws:
PersistenceException - thrown when an error occurs in restoring
See Also:
PersistentPeer

isConnected

public static boolean isConnected()

logMemory

public void logMemory()

run

public void run()
Specified by:
run in interface java.lang.Runnable

save

public void save()
          throws PersistenceException
Description copied from interface: Persistent
Prescribes a method for saving this object's data to a data store. An implementation will usually check to see if the object has been modified and trigger the actual saving mechanism in its PersistentPeer implementation.

Specified by:
save in interface Persistent
Throws:
PersistenceException - thrown when an error occurs in saving
See Also:
PersistentPeer

send

public void send(Packet p)
Sends any valid subclass of Packet to the router.

Parameters:
p - the packet to send

stop

public void stop()
Shuts down the connection to the router without reconnecting.

See Also:
Runnable.run()

addChannel

public void addChannel(Channel c)
Adds a channel to the channel list. This does not subscribe the mud to that channel. In order to subscribe, the channel needs to be added to the ImudServices implementation's getChannels() method.

Parameters:
c - the channel to add to the list of known channels
See Also:
ImudServices.getChannels()

removeChannel

public void removeChannel(Channel c)
Removes a channel from the channel list.

Parameters:
c - the channel to remove

getChannelList

public ChannelList getChannelList()
Returns:
the list of currently known channels

setChannelList

public void setChannelList(ChannelList list)
Sets the channel list to a new channel list.

Parameters:
list - the new channel list

addMud

public void addMud(I3Mud m)
Adds a mud to the list of known muds.

Parameters:
m - the mud to add

removeMud

public void removeMud(I3Mud m)
Removed a mud from the list of known muds.

Parameters:
m - the mud to remove

getMudList

public MudList getMudList()
Returns:
the list of known muds

getAllMudsList

public static MudList getAllMudsList()
Returns:
the list of known muds

getAllChannelList

public static ChannelList getAllChannelList()
Returns:
the list of known muds

setMudList

public void setMudList(MudList list)
Sets the list of known muds to the specified list.

Parameters:
list - the new list of muds

getPassword

public int getPassword()
Returns:
the I3 password for this mud

setPassword

public void setPassword(int pass)
Sets the Intermud 3 password.

Parameters:
pass - the new password

shutdown

public static void shutdown()