com.realtime.crossfire.jxclient.scripts
Class PacketWatcher

java.lang.Object
  extended by com.realtime.crossfire.jxclient.scripts.PacketWatcher

public class PacketWatcher
extends java.lang.Object

Implements the "watch" function for client-sided scripts.


Field Summary
private  java.util.Collection<java.lang.String> commands
          The commands to watch for.
private  CrossfireServerConnection crossfireServerConnection
          The CrossfireServerConnection to watch.
private  java.util.regex.Pattern pattern
          A Pattern matching all commands.
private  ReceivedPacketListener receivedPacketListener
          The ReceivedPacketListener attached to crossfireServerConnection.
private  ScriptProcess scriptProcess
          The ScriptProcess for sending commands.
 
Constructor Summary
PacketWatcher(CrossfireServerConnection crossfireServerConnection, ScriptProcess scriptProcess)
          Creates a new instance.
 
Method Summary
 void addCommand(java.lang.String command)
          Adds a command to watch for.
 void destroy()
          Releases allocated resources.
private  boolean matchesCommand(java.lang.CharSequence command)
          Returns whether a command matches the currently watched commands.
private  void rebuildPattern()
          Rebuilds pattern from commands.
 void removeCommand(java.lang.String command)
          Removes a command to watch for.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commands

@NotNull
private final java.util.Collection<java.lang.String> commands
The commands to watch for.


crossfireServerConnection

@NotNull
private final CrossfireServerConnection crossfireServerConnection
The CrossfireServerConnection to watch.


pattern

@Nullable
private java.util.regex.Pattern pattern
A Pattern matching all commands. Set to null when not watching for commands.


receivedPacketListener

@NotNull
private final ReceivedPacketListener receivedPacketListener
The ReceivedPacketListener attached to crossfireServerConnection. It is attached if and only if pattern is non-null.


scriptProcess

@NotNull
private final ScriptProcess scriptProcess
The ScriptProcess for sending commands.

Constructor Detail

PacketWatcher

public PacketWatcher(@NotNull
                     CrossfireServerConnection crossfireServerConnection,
                     @NotNull
                     ScriptProcess scriptProcess)
Creates a new instance.

Parameters:
crossfireServerConnection - the server connection to watch
scriptProcess - the script process for sending commands
Method Detail

addCommand

public void addCommand(@NotNull
                       java.lang.String command)
Adds a command to watch for.

Parameters:
command - the command

destroy

public void destroy()
Releases allocated resources. Must be called before this instance is freed.


matchesCommand

private boolean matchesCommand(@NotNull
                               java.lang.CharSequence command)
Returns whether a command matches the currently watched commands.

Parameters:
command - the command
Returns:
whether the command matches

rebuildPattern

private void rebuildPattern()
Rebuilds pattern from commands.


removeCommand

public void removeCommand(@NotNull
                          java.lang.String command)
Removes a command to watch for.

Parameters:
command - the command