|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.elite.jdcbot.framework.DCIO
org.elite.jdcbot.framework.InputThreadTarget
org.elite.jdcbot.framework.jDCBot
public abstract class jDCBot
jDCBot is a Java framework for writing DC (direct connect) bots easily.
It provides an event-driven architecture to handle common DC events.
Methods of the jDCBot class can be called to send events to the DC hub that it connects to. For example, calling the SendPublicMessage method will send a public message.
To perform an action when the jDCBot receives a normal message from the hub, you would override the onPubicMessage method defined in the jDCBot class. All onXYZ methods in the PircBot class are automatically called when the event XYZ happens, so you would override these if you wish to do something when it does happen.
Field Summary | |
---|---|
private java.lang.String |
_botIP
|
protected java.lang.String |
_botname
|
private java.lang.String |
_clientproto_supports
|
protected java.lang.String |
_conn_type
|
protected java.lang.String |
_description
|
protected java.lang.String |
_email
|
protected java.lang.String |
_hubname
|
private java.lang.String |
_hubproto_supports
|
private java.lang.String |
_hubSupports
|
private InputThread |
_inputThread
|
protected java.net.InetAddress |
_ip
|
private int |
_listenPort
|
private int |
_maxDownloadSlots
|
private int |
_maxUploadSlots
|
private boolean |
_op
|
protected boolean |
_passive
|
protected java.lang.String |
_password
|
protected int |
_port
|
private static java.lang.String |
_protoVersion
|
protected java.lang.String |
_sharesize
|
private BotEventDispatchThread |
dispatchThread
|
protected DownloadManager |
downloadManager
|
(package private) java.io.InputStream |
input
|
protected java.io.PrintStream |
log
|
(package private) java.io.OutputStream |
output
|
protected ShareManager |
shareManager
|
protected java.net.Socket |
socket
|
protected java.net.ServerSocket |
socketServer
|
protected UserManager |
um
|
protected UploadManager |
uploadManager
|
static java.lang.String |
VERSION
The definitive version number of this release of jDCBot. |
Constructor Summary | |
---|---|
jDCBot(java.lang.String botIP)
Constructs a jDCBot with the default settings. |
|
jDCBot(java.lang.String botname,
java.lang.String botIP,
int listenPort,
java.lang.String password,
java.lang.String description,
java.lang.String conn_type,
java.lang.String email,
java.lang.String sharesize,
int uploadSlots,
int downloadSlots,
boolean passive,
java.io.PrintStream outputLog)
Constructs a jDCBot with your settings. |
Method Summary | |
---|---|
java.lang.String |
botname()
|
void |
connect(java.lang.String hostname,
int port)
Attempt to connect to the specified DC hub. |
User[] |
GetAllUsers()
|
java.lang.String |
getBotClientProtoSupports()
|
java.lang.String |
getBotHubProtoSupports()
|
BotEventDispatchThread |
getDispatchThread()
|
int |
getMaxDownloadSlots()
|
int |
getMaxUploadSlots()
|
User |
GetRandomUser()
|
ShareManager |
getShareManager()
|
User |
getUser(java.lang.String user)
Gets all of user info |
UserManager |
getUserManager()
|
void |
handleCommand(java.lang.String rawCommand)
Handles all commands from InputThread all passes it to different methods. |
java.lang.String |
hubname()
|
java.net.Socket |
initConnectToMe(java.lang.String user,
java.lang.String direction)
|
boolean |
isBotClientProtoSupports(java.lang.String feature)
Checks if the bot's client-client protocol implementation supports that protocol feature. |
boolean |
isBotHubProtoSupports(java.lang.String feature)
Checks if the bot's client-hub protocol implementation supports that protocol feature. |
boolean |
isConnected()
Returns whether or not the jDCBot is currently connected to a hub. |
boolean |
isHubSupports(java.lang.String feature)
Checks if the hub supports that protocol feature. |
boolean |
isOp()
|
boolean |
isPassive()
|
void |
KickUser(java.lang.String user)
Kicks specified user. |
void |
KickUser(User user)
Kicks specified user. |
private java.lang.String |
lock2key(java.lang.String lock)
Generates key from lock needed to connect to hub. |
protected void |
onActiveSearch(java.lang.String IP,
int port,
boolean isSizeRestricted,
boolean isMinimumSize,
long size,
int dataType,
java.lang.String searchPattern)
Called when user in passive mode is searching for something. |
void |
onBotQuit()
It is called when the bot quits. |
protected void |
onChannelMessage(java.lang.String user,
java.lang.String channel,
java.lang.String message)
Called when channel message in channel where bot is present is received. |
protected void |
onConnect()
Called upon succesfully connecting to hub. |
protected void |
onConnect2Client()
|
protected void |
onDisconnect()
Called upon disconnecting from hub. |
protected void |
onDownloadComplete(User user,
DUEntity due,
boolean success,
BotException e)
Called when download is complete. Note: This method is called by DownloadHandler using jDCBot-EventDispatchThread thread. |
protected void |
onJoin(java.lang.String user)
Called when user enter the hub. |
protected void |
onPassiveSearch(java.lang.String user,
boolean isSizeRestricted,
boolean isMinimumSize,
long size,
int dataType,
java.lang.String searchPattern)
Called when user in passive mode is searching for something. |
protected void |
onPrivateMessage(java.lang.String user,
java.lang.String message)
Called when bot receives private message. |
protected void |
onPublicMessage(java.lang.String user,
java.lang.String message)
Called when public message is received. |
protected void |
onQuit(java.lang.String user)
Called when user quits hub. |
protected void |
onUpdateMyInfo(java.lang.String user)
Called when some new info about the user is found. |
protected void |
onUploadComplete(User user,
DUEntity due,
boolean success,
BotException e)
Called when upload is complete. Note: This method is called by DownloadHandler using jDCBot-EventDispatchThread thread. |
protected void |
onUploadStart(User user,
DUEntity due)
Called when upload is starting. Note: This method is called by DownloadHandler using jDCBot-EventDispatchThread thread. |
void |
quit()
Attemps to nicely close connection with the hub. |
private java.lang.String |
ReadCommand()
Reading command before InputThread is started (only for connecting). |
private void |
replyConnectToMe(java.lang.String user,
java.lang.String ip,
int port)
|
void |
SendActiveSearchReturn(java.lang.String IP,
int port,
boolean isDir,
java.lang.String name,
long size,
int free_slots)
Method for returning search results to active clients. |
void |
SendAll(java.lang.String message,
long timeout)
This method serves to send message to all users on the hub. |
void |
SendCommand(java.lang.String buffer)
Sends raw command to hub. |
void |
SendPassiveSearchReturn(java.lang.String user,
boolean isDir,
java.lang.String name,
long size,
int free_slots)
Method for returning search results to passive clients. |
void |
SendPrivateMessage(java.lang.String user,
java.lang.String message)
Sends private message to specified user. |
void |
SendPublicMessage(java.lang.String message)
Sends public message on main chat. |
void |
setMaxDownloadSlots(int slots)
|
void |
setMaxUploadSlots(int slots)
|
(package private) void |
setOp(boolean flag)
Sets if the bot is operator or not. |
void |
setShareManager(ShareManager sm)
|
void |
terminate()
Call this when you want to shut down framework completely. |
boolean |
UserExist(java.lang.String user)
Checks if user is present on hub |
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 |
---|
public static final java.lang.String VERSION
private static final java.lang.String _protoVersion
private InputThread _inputThread
private BotEventDispatchThread dispatchThread
protected java.net.Socket socket
protected java.net.ServerSocket socketServer
protected java.io.PrintStream log
java.io.InputStream input
java.io.OutputStream output
protected UserManager um
protected DownloadManager downloadManager
protected UploadManager uploadManager
protected ShareManager shareManager
protected java.lang.String _botname
protected java.lang.String _password
protected java.lang.String _description
protected java.lang.String _conn_type
protected java.lang.String _email
protected java.lang.String _sharesize
protected java.lang.String _hubname
protected boolean _passive
protected java.net.InetAddress _ip
protected int _port
private final java.lang.String _hubproto_supports
private final java.lang.String _clientproto_supports
private int _maxUploadSlots
private int _maxDownloadSlots
private java.lang.String _hubSupports
private boolean _op
private java.lang.String _botIP
private int _listenPort
Constructor Detail |
---|
public jDCBot(java.lang.String botname, java.lang.String botIP, int listenPort, java.lang.String password, java.lang.String description, java.lang.String conn_type, java.lang.String email, java.lang.String sharesize, int uploadSlots, int downloadSlots, boolean passive, java.io.PrintStream outputLog)
Most setting here depends on your hub. You might have to fake your share size and/or slots for hub to accept you... For details, look at DCPP wiki page of $MyINFO command
botname
- Name of the bot as it will appear in the list of users.botIP
- Your IP.listenPort
- The port on your computer where jdcbot should listen for incoming connections from clients.password
- Passsword if required, you could put anything if no password is needed.description
- Description of your bot as it will appear in the list of users. On your description is appended standard description.conn_type
- Your connection type, for details look hereemail
- Your e-mail address as it will appear in the list of users.sharesize
- Size of your share in bytes.uploadSlots
- Number of upload slots for other user to connect to you.downloadSlots
- Number of download slots. This has nothing to do with DC++ protocol. This has been given
to put an upper cap on no. of simultaneous downloads.passive
- Set this to fals if you are not behind a firewall.outputLog
- Almost all debug messages will be printed in this.public jDCBot(java.lang.String botIP)
Method Detail |
---|
public final java.lang.String botname()
public final boolean isPassive()
public final boolean isOp()
public final java.lang.String hubname()
public java.lang.String getBotHubProtoSupports()
public java.lang.String getBotClientProtoSupports()
public ShareManager getShareManager()
public BotEventDispatchThread getDispatchThread()
public UserManager getUserManager()
public boolean isConnected()
public boolean isHubSupports(java.lang.String feature)
feature
-
public boolean isBotHubProtoSupports(java.lang.String feature)
feature
-
public boolean isBotClientProtoSupports(java.lang.String feature)
feature
-
public int getMaxUploadSlots()
public int getMaxDownloadSlots()
public boolean UserExist(java.lang.String user)
user
- Nick of a user
public User getUser(java.lang.String user)
user
- Nick of the user
public User GetRandomUser()
public final User[] GetAllUsers()
public final void connect(java.lang.String hostname, int port) throws java.lang.Exception
hostname
- The hostname of the server to connect to.
java.lang.Exception
- if it was not possible to connect to the server.
BotException
- if the server would not let us join it because of bad password or if there exist user with the same name.public final java.net.Socket initConnectToMe(java.lang.String user, java.lang.String direction) throws java.lang.Exception
java.lang.Exception
private void replyConnectToMe(java.lang.String user, java.lang.String ip, int port) throws java.lang.Exception
java.lang.Exception
public void quit()
connect
again to connect to the hub.
public void terminate()
quit
,
connect
is not supposed to be called after calling this method.
void setOp(boolean flag)
flag
- public void setShareManager(ShareManager sm)
public void setMaxUploadSlots(int slots)
public void setMaxDownloadSlots(int slots)
public void handleCommand(java.lang.String rawCommand)
handleCommand
in class InputThreadTarget
rawCommand
- Raw command sent from hubprivate final java.lang.String lock2key(java.lang.String lock)
lock
- Lock sent from hub
public final void SendCommand(java.lang.String buffer) throws java.lang.Exception
buffer
- Line which needs to be send. This method won't append "|" on the end on the string if it doesn't exist, so it is up to make
sure buffer ends with "|" if you calling this method.
java.lang.Exception
private final java.lang.String ReadCommand() throws java.lang.Exception
java.lang.Exception
public final void SendPublicMessage(java.lang.String message) throws java.lang.Exception
message
- Message to be sent. It shouldn't end with "|".
java.lang.Exception
public final void SendPrivateMessage(java.lang.String user, java.lang.String message) throws java.lang.Exception
user
- User who will get message.message
- Message to be sent. It shouldn't end with "|".
java.lang.Exception
public final void KickUser(User user)
user
- User to be kickedpublic final void KickUser(java.lang.String user)
user
- User to be kickedpublic final void SendAll(java.lang.String message, long timeout)
message
- Message to be send to all userstimeout
- Timeout interval in milliseconds between sending to two consecutive userpublic final void SendActiveSearchReturn(java.lang.String IP, int port, boolean isDir, java.lang.String name, long size, int free_slots)
IP
- IP address that gave us user who was searching for returning resultsport
- Port that gave us user who was searching for returning resultsisDir
- Set true if you're returning directory, false if it is a filename
- Name of the file/dir you're returning. Note that some clients reject names that are note like the one they were searching
for. This means that if someone were searching for 'firefox', and we're returned 'opera', his client won't display our
result.size
- Size of the file in bytes we're returningfree_slots
- How many slots we have opened/unusedpublic final void SendPassiveSearchReturn(java.lang.String user, boolean isDir, java.lang.String name, long size, int free_slots)
user
- User who was searching. Since he is in passive mode, we return result to hubisDir
- Set true if you're returning directory, false if it is a filename
- Name of the file/dir you're returning. Note that some clients reject names that are note like the one they were searching
for. This means that if someone were searching for 'firefox', and we're returned 'opera', his client won't display our
result.size
- Size of the file in bytes we're returningfree_slots
- How many slots we have opened/unusedprotected void onConnect()
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
protected void onConnect2Client()
public void onBotQuit()
protected void onDisconnect()
The implementation of this method in the jDCBot abstract class resets the _inputThread to null hence when overridden super.onDisconnect() must be called first.
onDisconnect
in class InputThreadTarget
protected void onPublicMessage(java.lang.String user, java.lang.String message)
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
user
- User who sent message.message
- Contents of the message.protected void onJoin(java.lang.String user)
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
user
- Nema of the user who entered hub.protected void onQuit(java.lang.String user)
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
user
- of user quited hub.protected void onUpdateMyInfo(java.lang.String user)
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
Note: This method is called by User and UserManager using jDCBot-EventDispatchThread thread.
user
- The user from the hub.protected void onPrivateMessage(java.lang.String user, java.lang.String message)
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
user
- Name of user who sent us private message.message
- Contents of private message.protected void onChannelMessage(java.lang.String user, java.lang.String channel, java.lang.String message)
The implementation of this method in the jDCBot abstract class performs no actions and may be overridden as required.
user
- Name of the user who sent message.channel
- Channel on which message is sent.message
- Contents of the channel message.protected void onPassiveSearch(java.lang.String user, boolean isSizeRestricted, boolean isMinimumSize, long size, int dataType, java.lang.String searchPattern)
user
- User who is searchingisSizeRestricted
- true if user restricted search result for minimum/maximum file size. If false, isMinimumSize and size should not be used and
has no meaningisMinimumSize
- true if user restricted his search to file that has minimum size, false if user restricted search result to maximum size.
Used only if isSizeRestricted=truesize
- Size that user restricted his search. Is it minimum od maximum size is contained in isMimimumSizeUsed only if
isSizeRestricted=truedataType
- Type of the data user is searching for.searchPattern
- Pattern user is searching for.protected void onActiveSearch(java.lang.String IP, int port, boolean isSizeRestricted, boolean isMinimumSize, long size, int dataType, java.lang.String searchPattern)
IP
- IP address user who was searching gave to deliver search resultsport
- Port user who was searching gave to deliver search resultsisSizeRestricted
- true if user restricted search result for minimum/maximum file size. If false, isMinimumSize and size should not be used and
has no meaningisMinimumSize
- true if user restricted his search to file that has minimum size, false if user restricted search result to maximum size.
Used only if isSizeRestricted=truesize
- Size that user restricted his search. Is it minimum od maximum size is contained in isMimimumSizeUsed only if
isSizeRestricted=truedataType
- Type of the data user is searching for.searchPattern
- Pattern user is searching for.protected void onDownloadComplete(User user, DUEntity due, boolean success, BotException e)
user
- The user from whom the file was downloaded.due
- The informations about the file downloaded is in this.success
- It is true if download was successful else false.e
- The exception that occured when sucess is false else it is null.protected void onUploadComplete(User user, DUEntity due, boolean success, BotException e)
user
- The user to whom the file was uploaded.due
- The informations about the file uploaded is in this.success
- It is true if upload was successful else false.e
- The exception that occured when sucess is false else it is null.protected void onUploadStart(User user, DUEntity due)
user
- The user to whom the file is being uploaded.due
- The informations about the file downloaded is in this.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |