com.realtime.crossfire.jxclient.scripts
Class DefaultScriptProcess

java.lang.Object
  extended by com.realtime.crossfire.jxclient.scripts.DefaultScriptProcess
All Implemented Interfaces:
ScriptProcess, java.lang.Comparable<ScriptProcess>, java.lang.Runnable

public class DefaultScriptProcess
extends java.lang.Object
implements java.lang.Runnable, ScriptProcess

Default implementation for ScriptProcesses.


Field Summary
private  ClientSocketListener clientSocketListener
          The ClientSocketListener attached to crossfireServerConnection to track commands sent to the server.
private  CommandQueue commandQueue
          The CommandQueue for sending commands.
private  CrossfireServerConnection crossfireServerConnection
          The connection instance.
private  java.lang.String filename
          The script command including arguments.
private  FloorView floorView
          The FloorView to use.
private  java.io.InputStream in
          The InputStream of process.
private  boolean isMonitoring
          Whether a "monitor" command is active.
private  ItemSet itemSet
          The ItemSet instance to use.
private  boolean killed
          Whether this script has been killed.
private  CfMapUpdater mapUpdater
          The CfMapUpdater instance to use.
private  java.io.OutputStreamWriter osw
          The OutputStreamWriter associated with process.
private  PacketWatcher packetWatcher
          The PacketWatcher to process "watch" commands.
private  java.lang.Process process
          The Process instance for the executed child process.
private  int scriptId
          The script ID identifying this script instance.
private  java.util.Collection<ScriptProcessListener> scriptProcessListeners
          The ScriptProcessListeners to notify.
private  SkillSet skillSet
          The SkillSet for looking up skill names.
private  java.lang.Iterable<Spell> spellsManager
          The SpellsManager instance to use.
private  Stats stats
          The Stats instance to watch.
 
Constructor Summary
DefaultScriptProcess(int scriptId, java.lang.String filename, CommandQueue commandQueue, CrossfireServerConnection crossfireServerConnection, Stats stats, FloorView floorView, ItemSet itemSet, java.lang.Iterable<Spell> spellsManager, CfMapUpdater mapUpdater, SkillSet skillSet)
          Creates a new instance.
 
Method Summary
 void addScriptProcessListener(ScriptProcessListener scriptProcessListener)
          Adds a ScriptProcessListener to be notified.
private  void cmdDraw(java.lang.String params)
          Processes a "draw" command from the script process.
private  void cmdIssue(java.lang.String params)
          Processes a regular "issue" command from the script process.
private  void cmdIssueLock(java.lang.String params)
          Processes a "issue lock" command from the script process.
private  void cmdIssueMark(java.lang.String params)
          Processes a "issue mark" command from the script process.
private  void cmdMonitor()
          Processes a "monitor" command from the script process.
private  void cmdRequest(java.lang.String params)
          Processes a "request" command from the script process.
private  void cmdUnmonitor()
          Processes an "unmonitor" command from the script process.
 void commandSent(java.lang.String cmd)
          Sends a message to the script process.
private  void commandSentItem(java.lang.String cmd, CfItem item)
          Sends an item info message to the script process.
private  void commandSentMap(CfMap map, int x, int y)
          Sends info about one map cell to the script process.
 int compareTo(ScriptProcess o)
          
 boolean equals(java.lang.Object obj)
          
 java.lang.String getFilename()
          Returns the script's filename.
 int getScriptId()
          Returns the script ID identifying this script instance.
 int hashCode()
          
 void killScript()
          Kills the script process.
private  void reportError(java.lang.String string)
          Reports an error while executing client commands.
 void run()
          
private  void runScriptCommand(java.lang.String cmdLine)
          Processes a line received from the script process.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

clientSocketListener

@NotNull
private final ClientSocketListener clientSocketListener
The ClientSocketListener attached to crossfireServerConnection to track commands sent to the server.


commandQueue

@NotNull
private final CommandQueue commandQueue
The CommandQueue for sending commands.


crossfireServerConnection

@NotNull
private final CrossfireServerConnection crossfireServerConnection
The connection instance.


filename

@NotNull
private final java.lang.String filename
The script command including arguments.


floorView

@NotNull
private final FloorView floorView
The FloorView to use.


in

@NotNull
private final java.io.InputStream in
The InputStream of process.


isMonitoring

private boolean isMonitoring
Whether a "monitor" command is active.


itemSet

@NotNull
private final ItemSet itemSet
The ItemSet instance to use.


killed

private boolean killed
Whether this script has been killed.


mapUpdater

@NotNull
private final CfMapUpdater mapUpdater
The CfMapUpdater instance to use.


osw

@NotNull
private final java.io.OutputStreamWriter osw
The OutputStreamWriter associated with process.


packetWatcher

@NotNull
private final PacketWatcher packetWatcher
The PacketWatcher to process "watch" commands.


process

@NotNull
private final java.lang.Process process
The Process instance for the executed child process.


scriptId

private final int scriptId
The script ID identifying this script instance.


scriptProcessListeners

@NotNull
private final java.util.Collection<ScriptProcessListener> scriptProcessListeners
The ScriptProcessListeners to notify.


skillSet

@NotNull
private final SkillSet skillSet
The SkillSet for looking up skill names.


spellsManager

@NotNull
private final java.lang.Iterable<Spell> spellsManager
The SpellsManager instance to use.


stats

@NotNull
private final Stats stats
The Stats instance to watch.

Constructor Detail

DefaultScriptProcess

public DefaultScriptProcess(int scriptId,
                            @NotNull
                            java.lang.String filename,
                            @NotNull
                            CommandQueue commandQueue,
                            @NotNull
                            CrossfireServerConnection crossfireServerConnection,
                            @NotNull
                            Stats stats,
                            @NotNull
                            FloorView floorView,
                            @NotNull
                            ItemSet itemSet,
                            @NotNull
                            java.lang.Iterable<Spell> spellsManager,
                            @NotNull
                            CfMapUpdater mapUpdater,
                            @NotNull
                            SkillSet skillSet)
                     throws java.io.IOException
Creates a new instance.

Parameters:
scriptId - the script ID identifying the new script
filename - the command including arguments to execute
commandQueue - the command queue for sending commands
crossfireServerConnection - the server connection
stats - the stats instance to watch
floorView - the floor view to use
itemSet - the item set instance to use
spellsManager - the spells manager instance to use
mapUpdater - the map updater instance to use
skillSet - the skill set for looking up skill names
Throws:
java.io.IOException - if the script cannot be created
Method Detail

addScriptProcessListener

public void addScriptProcessListener(@NotNull
                                     ScriptProcessListener scriptProcessListener)
Adds a ScriptProcessListener to be notified.

Specified by:
addScriptProcessListener in interface ScriptProcess
Parameters:
scriptProcessListener - the listener to add

cmdDraw

private void cmdDraw(@NotNull
                     java.lang.String params)
Processes a "draw" command from the script process.

Parameters:
params - the command arguments

cmdIssue

private void cmdIssue(@NotNull
                      java.lang.String params)
Processes a regular "issue" command from the script process.

Parameters:
params - the command arguments

cmdIssueLock

private void cmdIssueLock(@NotNull
                          java.lang.String params)
Processes a "issue lock" command from the script process.

Parameters:
params - the command arguments

cmdIssueMark

private void cmdIssueMark(@NotNull
                          java.lang.String params)
Processes a "issue mark" command from the script process.

Parameters:
params - the command arguments

cmdMonitor

private void cmdMonitor()
Processes a "monitor" command from the script process.


cmdRequest

private void cmdRequest(@NotNull
                        java.lang.String params)
Processes a "request" command from the script process.

Parameters:
params - the command arguments

cmdUnmonitor

private void cmdUnmonitor()
Processes an "unmonitor" command from the script process.


commandSent

public void commandSent(@NotNull
                        java.lang.String cmd)
Sends a message to the script process.

Specified by:
commandSent in interface ScriptProcess
Parameters:
cmd - the message to send

commandSentItem

private void commandSentItem(@NotNull
                             java.lang.String cmd,
                             @NotNull
                             CfItem item)
Sends an item info message to the script process.

Parameters:
cmd - the message to send
item - the item to send

commandSentMap

private void commandSentMap(@NotNull
                            CfMap map,
                            int x,
                            int y)
Sends info about one map cell to the script process.

Parameters:
map - the map instance to use
x - the cell's x-coordinate relative to the view area
y - the cell's y-coordinate relative to the view area

compareTo

public int compareTo(@NotNull
                     ScriptProcess o)

Specified by:
compareTo in interface java.lang.Comparable<ScriptProcess>

equals

public boolean equals(@Nullable
                      java.lang.Object obj)

Overrides:
equals in class java.lang.Object

getFilename

@NotNull
public java.lang.String getFilename()
Returns the script's filename.

Specified by:
getFilename in interface ScriptProcess
Returns:
the script's filename

getScriptId

public int getScriptId()
Returns the script ID identifying this script instance.

Specified by:
getScriptId in interface ScriptProcess
Returns:
the script ID

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

killScript

public void killScript()
Kills the script process. Does nothing if the process is not running.

Specified by:
killScript in interface ScriptProcess

reportError

private void reportError(@NotNull
                         java.lang.String string)
Reports an error while executing client commands.

Parameters:
string - the error message

run

public void run()

Specified by:
run in interface java.lang.Runnable

runScriptCommand

private void runScriptCommand(@NotNull
                              java.lang.String cmdLine)
Processes a line received from the script process.

Parameters:
cmdLine - the line

toString

@NotNull
public java.lang.String toString()

Overrides:
toString in class java.lang.Object