org.ag.sheriffbot
Class SheriffBot

java.lang.Object
  extended by org.elite.jdcbot.framework.DCIO
      extended by org.elite.jdcbot.framework.InputThreadTarget
          extended by org.elite.jdcbot.framework.jDCBot
              extended by org.ag.sheriffbot.SheriffBot

public class SheriffBot
extends jDCBot

SheriffBot is a derived class from jDCBot apstract class overriding some methods.

This bot's task is to periodically download all the users' file list. It downloads all the users' file list and packs them into a single xml file named in the format shown below.

Hub name-yyyy-MM-dd_HH.mm.ss.bz2

where yyyy-MM-dd_HH.mm.ss is the date and time of creation of the file.
This file is compressed using bzip2 algorithm. When any new user logs in for the first time in-between the file list dumping cycle then that user's file list is downloaded and saved separately and the file is named as

Hub name_User name-yyyy-MM-dd_HH.mm.ss.bz2

The reason of creating this was that my college laid down the condition that DC++ will only be allowed on college LAN network if the hub maintains a list of users' file list. So, that later if required the originator of any illegal file can be traced back.

Since:
0.7.1
Version:
1.2
Author:
AppleGrew

Nested Class Summary
private  class SheriffBot.UserListDownloadThread
           
 
Field Summary
private  java.lang.String _filelistDir
           
private  java.lang.String _hubIP
           
private  int _updateInterval
           
private  java.util.HashMap<java.lang.String,java.lang.String> authorizedUsers
           
private  java.util.Vector<java.lang.String> downloadedUsers
           
private  java.util.Vector<java.lang.String> indexedUsers
           
private  boolean isShuttingDown
           
private  boolean isUpdateInProgress
           
private  boolean listUpdatedAtleastOnce
           
private  java.util.Vector<java.lang.String> spareUsers
           
private  TimerThread tt
           
private  java.util.Vector<java.lang.String> users2Index
           
private  SheriffBot.UserListDownloadThread uth
           
 java.lang.String version
           
 
Fields inherited from class org.elite.jdcbot.framework.jDCBot
_botname, _conn_type, _description, _email, _hubname, _ip, _passive, _password, _port, _sharesize, downloadManager, log, shareManager, socket, socketServer, um, uploadManager, VERSION
 
Constructor Summary
SheriffBot(java.io.PrintStream outputLog)
           
SheriffBot(java.lang.String hubIP, int hubPort, java.lang.String botIP, int listenPort, java.lang.String sharesizeInBytes, int noOfSlots, int updateInterval, java.lang.String filelistDir, java.lang.String hubPass, boolean passive, java.io.PrintStream outputLog)
           
SheriffBot(java.lang.String hubIP, int hubPort, java.lang.String sharesizeInBytes, java.lang.String hubpass, java.lang.String botIP, int listenPort, java.lang.String filelistDir, boolean active, java.io.PrintStream outputLog)
           
 
Method Summary
private  boolean authorized(java.lang.String user)
           
protected  void clearIndexedUsersList()
           
 byte[] getFileListBytes(User user, int settings)
           
static void main(java.lang.String[] args)
           
 void onBotQuit()
          It is called when the bot quits.
 void onConnect()
          Prints on main chat that we are here and starts flood thread.
 void onDisconnect()
          Called upon disconnecting from hub.
protected  void onDownloadComplete(User user, DUEntity due, boolean sucess, BotException e)
          Called when download is complete.
Note: This method is called by DownloadHandler using jDCBot-EventDispatchThread thread.
 void onJoin(java.lang.String user)
          Called when user enter the hub.
 void onPrivateMessage(java.lang.String user, java.lang.String message)
          Sends user who wants to talk to us a feedback that we're (still) stupid.
private  void updateFilelists()
           
 
Methods inherited from class org.elite.jdcbot.framework.jDCBot
botname, connect, GetAllUsers, getBotClientProtoSupports, getBotHubProtoSupports, getDispatchThread, getMaxDownloadSlots, getMaxUploadSlots, GetRandomUser, getShareManager, getUser, getUserManager, handleCommand, hubname, initConnectToMe, isBotClientProtoSupports, isBotHubProtoSupports, isConnected, isHubSupports, isOp, isPassive, KickUser, KickUser, onActiveSearch, onChannelMessage, onConnect2Client, onPassiveSearch, onPublicMessage, onQuit, onUpdateMyInfo, onUploadComplete, onUploadStart, quit, SendActiveSearchReturn, SendAll, SendCommand, SendPassiveSearchReturn, SendPrivateMessage, SendPublicMessage, setMaxDownloadSlots, setMaxUploadSlots, setShareManager, terminate, UserExist
 
Methods inherited from class org.elite.jdcbot.framework.DCIO
parseCmdArgs, parseCmdName, parseRawCmd, ReadCommand, ReadCommand, SendCommand, SendCommand, set_IOExceptionMsg
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public final java.lang.String version
See Also:
Constant Field Values

tt

private TimerThread tt

_updateInterval

private int _updateInterval

_hubIP

private java.lang.String _hubIP

_filelistDir

private java.lang.String _filelistDir

authorizedUsers

private java.util.HashMap<java.lang.String,java.lang.String> authorizedUsers

uth

private SheriffBot.UserListDownloadThread uth

users2Index

private java.util.Vector<java.lang.String> users2Index

spareUsers

private java.util.Vector<java.lang.String> spareUsers

indexedUsers

private java.util.Vector<java.lang.String> indexedUsers

downloadedUsers

private java.util.Vector<java.lang.String> downloadedUsers

isShuttingDown

private volatile boolean isShuttingDown

listUpdatedAtleastOnce

private volatile boolean listUpdatedAtleastOnce

isUpdateInProgress

private volatile boolean isUpdateInProgress
Constructor Detail

SheriffBot

public SheriffBot(java.io.PrintStream outputLog)

SheriffBot

public SheriffBot(java.lang.String hubIP,
                  int hubPort,
                  java.lang.String sharesizeInBytes,
                  java.lang.String hubpass,
                  java.lang.String botIP,
                  int listenPort,
                  java.lang.String filelistDir,
                  boolean active,
                  java.io.PrintStream outputLog)

SheriffBot

public SheriffBot(java.lang.String hubIP,
                  int hubPort,
                  java.lang.String botIP,
                  int listenPort,
                  java.lang.String sharesizeInBytes,
                  int noOfSlots,
                  int updateInterval,
                  java.lang.String filelistDir,
                  java.lang.String hubPass,
                  boolean passive,
                  java.io.PrintStream outputLog)
Method Detail

onConnect

public void onConnect()
Prints on main chat that we are here and starts flood thread.

Overrides:
onConnect in class jDCBot

clearIndexedUsersList

protected void clearIndexedUsersList()

onPrivateMessage

public void onPrivateMessage(java.lang.String user,
                             java.lang.String message)
Sends user who wants to talk to us a feedback that we're (still) stupid.

Overrides:
onPrivateMessage in class jDCBot
Parameters:
user - Name of user who sent us private message.
message - Contents of private message.

onBotQuit

public void onBotQuit()
Description copied from class: jDCBot
It is called when the bot quits. Just after it quits, as a side-effect of closing the socket, the onDisconnect() too is called.

Overrides:
onBotQuit in class jDCBot

onDisconnect

public void onDisconnect()
Description copied from class: jDCBot
Called upon disconnecting from hub.

The implementation of this method in the jDCBot abstract class resets the _inputThread to null hence when overridden super.onDisconnect() must be called first.

Overrides:
onDisconnect in class jDCBot

updateFilelists

private void updateFilelists()

authorized

private boolean authorized(java.lang.String user)

onJoin

public void onJoin(java.lang.String user)
Description copied from class: jDCBot
Called when user enter the hub.

The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.

Overrides:
onJoin in class jDCBot
Parameters:
user - Nema of the user who entered hub.

getFileListBytes

public byte[] getFileListBytes(User user,
                               int settings)

onDownloadComplete

protected void onDownloadComplete(User user,
                                  DUEntity due,
                                  boolean sucess,
                                  BotException e)
Description copied from class: jDCBot
Called when download is complete.
Note: This method is called by DownloadHandler using jDCBot-EventDispatchThread thread.

Overrides:
onDownloadComplete in class jDCBot
Parameters:
user - The user from whom the file was downloaded.
due - The informations about the file downloaded is in this.
sucess - It is true if download was successful else false.
e - The exception that occured when sucess is false else it is null.

main

public static void main(java.lang.String[] args)