irssibot.modules
Class ChannelTools

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--irssibot.modules.AbstractModule
              |
              +--irssibot.modules.ChannelTools
All Implemented Interfaces:
java.lang.Runnable

public class ChannelTools
extends AbstractModule

This module has basic functionality for maintaining/protecting IRC channels from privmsg/join/nick flood, clone attacks, massdeops and such.

Version:
$Name: $ $Revision: 1.17 $
Author:
Matti Dahlbom

Nested Class Summary
(package private)  class ChannelTools.BanHandler
          Handles removing bans after a given period.
(package private)  class ChannelTools.ChannelJoiner
          Joins a given channel when invoked by a Timer.
 
Field Summary
private  ServerConnection caller
           
private  boolean changed
           
private  java.util.Hashtable chanvars
          This Hashtable contains a ChanVars object for each channel.
private  Host host
           
private static java.lang.String moduleInfo
           
private  java.util.Hashtable permbanList
          This Hashtable contains Vector objects containing banmasks as String.
private  java.lang.String source
           
 
Fields inherited from class irssibot.modules.AbstractModule
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ChannelTools()
          Default constructor
 
Method Summary
private  boolean checkJoinFlood(User user, Host host, Channel channel)
          Checks for join flood.
private  void commandAdd(Host host, User invoker, java.lang.String[] args, Channel channel)
          Processes add-commands for this module
private  void commandBK(Host host, User invoker, java.lang.String[] args, Channel channel)
          Bans & kicks a user from a given channel.
private  void commandDel(Host host, User invoker, java.lang.String[] args, Channel channel)
          Processes del-commands for this module
private  void commandEdit(Host host, User invoker, java.lang.String[] args, Channel channel)
          Processes edit-commands for this module
private  void commandJoin(Host host, User invoker, java.lang.String[] args, Channel channel)
          Tries to join channel in args[0] with key in args[1] if given.
private  void commandK(Host host, User invoker, java.lang.String[] args, Channel channel)
          Kicks a user from a given channel.
private  void commandLeave(Host host, User invoker, java.lang.String[] args, Channel channel)
          Leaves channel for given amount of seconds.
private  void commandList(Host host, User invoker, java.lang.String[] args, Channel channel)
          Processes list-commands for this module
private  void commandMaintain(Host host, User invoker, java.lang.String[] args, Channel channel)
          Executes Channel.doMaintain() for given channel.
private  void commandSay(Host host, User invoker, java.lang.String[] args, Channel channel)
          Makes bot say something on a channel.
private  void doJoin(JoinMessage message)
          Handles JOINs.
private  void doMode(ModeMessage message)
          Handles MODE changes.
private  void doPrivmsg(IrcMessage message)
          Handles PRIVMSGs.
private  void doSelfJoin(Channel channel)
          Handles JOINs when the bot itself joins a channel.
private  void doUnBan(Host host, Channel channel, java.lang.String target)
          Handles -b MODEs.
private  void enforceHostnameLookup(User user, Host host, Channel channel)
          Checks that joiner's IP resolves into a hostname.
 java.lang.String getModuleInfo()
          Returns a module info string
 java.util.Properties getState()
          Returns state.
private  ChanVars getVars(java.lang.String channelName)
          Returns channel vars for given channel on the current calling ServerConnection.
private  void loadInitialState(java.util.Properties state, Core core)
           
 boolean onLoad(java.util.Properties state, Core core)
          Called upon loading the module.
 void onUnload()
          Called upon unloading the module.
private  void processCmdMsg(Host host, java.lang.String cmd, Channel channel, java.lang.String[] args)
          Process command message.
protected  void processMessage(IrcMessage message, ServerConnection serverConnection)
          Processes incoming IrcMessages from a ServerConnection.
private  void write(java.lang.String message)
          Sends a PRIVMSG to source (channel/user).
 
Methods inherited from class irssibot.modules.AbstractModule
addMessage, killModule, run
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

moduleInfo

private static java.lang.String moduleInfo

permbanList

private java.util.Hashtable permbanList
This Hashtable contains Vector objects containing banmasks as String. The keys are of form "network-#channel" for each channel.


chanvars

private java.util.Hashtable chanvars
This Hashtable contains a ChanVars object for each channel. The keys are of form "network-#channel" for each channel.


changed

private boolean changed

host

private Host host

source

private java.lang.String source

caller

private ServerConnection caller
Constructor Detail

ChannelTools

public ChannelTools()
Default constructor

Method Detail

getVars

private ChanVars getVars(java.lang.String channelName)
Returns channel vars for given channel on the current calling ServerConnection.

Parameters:
channelName - name of channel to retrieve chanvars for
Returns:
chanvars for channel. if not found, return default values.

getState

public java.util.Properties getState()
Returns state.

Overrides:
getState in class AbstractModule
Returns:
state

loadInitialState

private void loadInitialState(java.util.Properties state,
                              Core core)

getModuleInfo

public java.lang.String getModuleInfo()
Returns a module info string

Specified by:
getModuleInfo in class AbstractModule
Returns:
module info string

onLoad

public boolean onLoad(java.util.Properties state,
                      Core core)
Called upon loading the module.

 @param state initial module state

Overrides:
onLoad in class AbstractModule
Parameters:
core - reference to core
state - the initial state of module as an Properties object, or null if no state was saved for module.
Returns:
true if ok, false if error. modules returning false from onLoad() will be unloaded immediately.
See Also:
Core

onUnload

public void onUnload()
Called upon unloading the module.

Overrides:
onUnload in class AbstractModule

commandK

private void commandK(Host host,
                      User invoker,
                      java.lang.String[] args,
                      Channel channel)
Kicks a user from a given channel.

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandBK

private void commandBK(Host host,
                       User invoker,
                       java.lang.String[] args,
                       Channel channel)
Bans & kicks a user from a given channel.

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandAdd

private void commandAdd(Host host,
                        User invoker,
                        java.lang.String[] args,
                        Channel channel)
Processes add-commands for this module

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandDel

private void commandDel(Host host,
                        User invoker,
                        java.lang.String[] args,
                        Channel channel)
Processes del-commands for this module

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandList

private void commandList(Host host,
                         User invoker,
                         java.lang.String[] args,
                         Channel channel)
Processes list-commands for this module

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandEdit

private void commandEdit(Host host,
                         User invoker,
                         java.lang.String[] args,
                         Channel channel)
Processes edit-commands for this module

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandJoin

private void commandJoin(Host host,
                         User invoker,
                         java.lang.String[] args,
                         Channel channel)
Tries to join channel in args[0] with key in args[1] if given. The channel must exist in bots record.

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandSay

private void commandSay(Host host,
                        User invoker,
                        java.lang.String[] args,
                        Channel channel)
Makes bot say something on a channel.

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandMaintain

private void commandMaintain(Host host,
                             User invoker,
                             java.lang.String[] args,
                             Channel channel)
Executes Channel.doMaintain() for given channel.

a

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

commandLeave

private void commandLeave(Host host,
                          User invoker,
                          java.lang.String[] args,
                          Channel channel)
Leaves channel for given amount of seconds.

Parameters:
host - Host of invoker
invoker - User object of invoker
args - command arguments
channel - Channel where command takes place

processCmdMsg

private void processCmdMsg(Host host,
                           java.lang.String cmd,
                           Channel channel,
                           java.lang.String[] args)
Process command message. assuming valid channel argument.

Parameters:
channel - valid channel name

doUnBan

private void doUnBan(Host host,
                     Channel channel,
                     java.lang.String target)
Handles -b MODEs. Re-bans any hostmasks that are defined in the permban list.

Parameters:
host - Host of the unbanner
channel - Channel on which the mode was set
target - unbanned hostmask

doMode

private void doMode(ModeMessage message)
Handles MODE changes.

Parameters:
message - the mode message

doSelfJoin

private void doSelfJoin(Channel channel)
Handles JOINs when the bot itself joins a channel.

Parameters:
channel - the Channel bot joins on

enforceHostnameLookup

private void enforceHostnameLookup(User user,
                                   Host host,
                                   Channel channel)
Checks that joiner's IP resolves into a hostname.

Parameters:
user - the joiner as user, or null if not user.
host - host of the joiner
channel - channel that was joined

checkJoinFlood

private boolean checkJoinFlood(User user,
                               Host host,
                               Channel channel)
Checks for join flood.

Parameters:
user - the joiner as user, or null if not user.
host - host of the joiner
channel - channel that was joined
Returns:
whether the join caused join flood or not

doJoin

private void doJoin(JoinMessage message)
Handles JOINs.

Parameters:
message - the join message

doPrivmsg

private void doPrivmsg(IrcMessage message)
Handles PRIVMSGs.

Parameters:
message - PRIVMSG IrcMessage to process

processMessage

protected void processMessage(IrcMessage message,
                              ServerConnection serverConnection)
Processes incoming IrcMessages from a ServerConnection. Sets instance variable caller to refer to the calling ServerConnection.

Specified by:
processMessage in class AbstractModule
Parameters:
message - IrcMessage to process
serverConnection - invoking ServerConnection

write

private void write(java.lang.String message)
Sends a PRIVMSG to source (channel/user).

Parameters:
message - message to send
Throws:
java.lang.IllegalStateException - thrown if source param was null


IrssiBot (c) 2000-2002 Matti Dahlbom