1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-23 01:12:17 -05:00

added getDescription and help command

This commit is contained in:
kell 2010-03-26 19:05:37 +01:00
parent 9efeb5b8af
commit 6d01720ca6
34 changed files with 5505 additions and 5234 deletions

View File

@ -1,293 +1,293 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* The Colors class provides several static fields and methods that you may
* find useful when writing an IRC Bot.
* <p>
* This class contains constants that are useful for formatting lines
* sent to IRC servers. These constants allow you to apply various
* formatting to the lines, such as colours, boldness, underlining
* and reverse text.
* <p>
* The class contains static methods to remove colours and formatting
* from lines of IRC text.
* <p>
* Here are some examples of how to use the contants from within a
* class that extends PircBot and imports org.jibble.pircbot.*;
*
* <pre> sendMessage("#cs", Colors.BOLD + "A bold hello!");
* <b>A bold hello!</b>
* sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
* <font color="red">Red</font> text
* sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
* <b><font color="red">Bold and red</font></b></pre>
*
* Please note that some IRC channels may be configured to reject any
* messages that use colours. Also note that older IRC clients may be
* unable to correctly display lines that contain colours and other
* control characters.
* <p>
* Note that this class name has been spelt in the American style in
* order to remain consistent with the rest of the Java API.
*
*
* @since 0.9.12
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class Colors {
/**
* Removes all previously applied color and formatting attributes.
*/
public static final String NORMAL = "\u000f";
/**
* Bold text.
*/
public static final String BOLD = "\u0002";
/**
* Underlined text.
*/
public static final String UNDERLINE = "\u001f";
/**
* Reversed text (may be rendered as italic text in some clients).
*/
public static final String REVERSE = "\u0016";
/**
* White coloured text.
*/
public static final String WHITE = "\u000300";
/**
* Black coloured text.
*/
public static final String BLACK = "\u000301";
/**
* Dark blue coloured text.
*/
public static final String DARK_BLUE = "\u000302";
/**
* Dark green coloured text.
*/
public static final String DARK_GREEN = "\u000303";
/**
* Red coloured text.
*/
public static final String RED = "\u000304";
/**
* Brown coloured text.
*/
public static final String BROWN = "\u000305";
/**
* Purple coloured text.
*/
public static final String PURPLE = "\u000306";
/**
* Olive coloured text.
*/
public static final String OLIVE = "\u000307";
/**
* Yellow coloured text.
*/
public static final String YELLOW = "\u000308";
/**
* Green coloured text.
*/
public static final String GREEN = "\u000309";
/**
* Teal coloured text.
*/
public static final String TEAL = "\u000310";
/**
* Cyan coloured text.
*/
public static final String CYAN = "\u000311";
/**
* Blue coloured text.
*/
public static final String BLUE = "\u000312";
/**
* Magenta coloured text.
*/
public static final String MAGENTA = "\u000313";
/**
* Dark gray coloured text.
*/
public static final String DARK_GRAY = "\u000314";
/**
* Light gray coloured text.
*/
public static final String LIGHT_GRAY = "\u000315";
/**
* This class should not be constructed.
*/
private Colors() {
}
/**
* Removes all colours from a line of IRC text.
*
* @since PircBot 1.2.0
*
* @param line the input text.
*
* @return the same text, but with all colours removed.
*/
public static String removeColors(String line) {
int length = line.length();
StringBuffer buffer = new StringBuffer();
int i = 0;
while (i < length) {
char ch = line.charAt(i);
if (ch == '\u0003') {
i++;
// Skip "x" or "xy" (foreground color).
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
}
}
// Now skip ",x" or ",xy" (background color).
if (i < length) {
ch = line.charAt(i);
if (ch == ',') {
i++;
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
}
}
}
else {
// Keep the comma.
i--;
}
}
else {
// Keep the comma.
i--;
}
}
}
}
}
}
else if (ch == '\u000f') {
i++;
}
else {
buffer.append(ch);
i++;
}
}
return buffer.toString();
}
/**
* Remove formatting from a line of IRC text.
*
* @since PircBot 1.2.0
*
* @param line the input text.
*
* @return the same text, but without any bold, underlining, reverse, etc.
*/
public static String removeFormatting(String line) {
int length = line.length();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
char ch = line.charAt(i);
if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') {
// Don't add this character.
}
else {
buffer.append(ch);
}
}
return buffer.toString();
}
/**
* Removes all formatting and colours from a line of IRC text.
*
* @since PircBot 1.2.0
*
* @param line the input text.
*
* @return the same text, but without formatting and colour characters.
*
*/
public static String removeFormattingAndColors(String line) {
return removeFormatting(removeColors(line));
}
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* The Colors class provides several static fields and methods that you may
* find useful when writing an IRC Bot.
* <p>
* This class contains constants that are useful for formatting lines
* sent to IRC servers. These constants allow you to apply various
* formatting to the lines, such as colours, boldness, underlining
* and reverse text.
* <p>
* The class contains static methods to remove colours and formatting
* from lines of IRC text.
* <p>
* Here are some examples of how to use the contants from within a
* class that extends PircBot and imports org.jibble.pircbot.*;
*
* <pre> sendMessage("#cs", Colors.BOLD + "A bold hello!");
* <b>A bold hello!</b>
* sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
* <font color="red">Red</font> text
* sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
* <b><font color="red">Bold and red</font></b></pre>
*
* Please note that some IRC channels may be configured to reject any
* messages that use colours. Also note that older IRC clients may be
* unable to correctly display lines that contain colours and other
* control characters.
* <p>
* Note that this class name has been spelt in the American style in
* order to remain consistent with the rest of the Java API.
*
*
* @since 0.9.12
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class Colors {
/**
* Removes all previously applied color and formatting attributes.
*/
public static final String NORMAL = "\u000f";
/**
* Bold text.
*/
public static final String BOLD = "\u0002";
/**
* Underlined text.
*/
public static final String UNDERLINE = "\u001f";
/**
* Reversed text (may be rendered as italic text in some clients).
*/
public static final String REVERSE = "\u0016";
/**
* White coloured text.
*/
public static final String WHITE = "\u000300";
/**
* Black coloured text.
*/
public static final String BLACK = "\u000301";
/**
* Dark blue coloured text.
*/
public static final String DARK_BLUE = "\u000302";
/**
* Dark green coloured text.
*/
public static final String DARK_GREEN = "\u000303";
/**
* Red coloured text.
*/
public static final String RED = "\u000304";
/**
* Brown coloured text.
*/
public static final String BROWN = "\u000305";
/**
* Purple coloured text.
*/
public static final String PURPLE = "\u000306";
/**
* Olive coloured text.
*/
public static final String OLIVE = "\u000307";
/**
* Yellow coloured text.
*/
public static final String YELLOW = "\u000308";
/**
* Green coloured text.
*/
public static final String GREEN = "\u000309";
/**
* Teal coloured text.
*/
public static final String TEAL = "\u000310";
/**
* Cyan coloured text.
*/
public static final String CYAN = "\u000311";
/**
* Blue coloured text.
*/
public static final String BLUE = "\u000312";
/**
* Magenta coloured text.
*/
public static final String MAGENTA = "\u000313";
/**
* Dark gray coloured text.
*/
public static final String DARK_GRAY = "\u000314";
/**
* Light gray coloured text.
*/
public static final String LIGHT_GRAY = "\u000315";
/**
* This class should not be constructed.
*/
private Colors() {
}
/**
* Removes all colours from a line of IRC text.
*
* @since PircBot 1.2.0
*
* @param line the input text.
*
* @return the same text, but with all colours removed.
*/
public static String removeColors(String line) {
int length = line.length();
StringBuffer buffer = new StringBuffer();
int i = 0;
while (i < length) {
char ch = line.charAt(i);
if (ch == '\u0003') {
i++;
// Skip "x" or "xy" (foreground color).
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
}
}
// Now skip ",x" or ",xy" (background color).
if (i < length) {
ch = line.charAt(i);
if (ch == ',') {
i++;
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
if (i < length) {
ch = line.charAt(i);
if (Character.isDigit(ch)) {
i++;
}
}
}
else {
// Keep the comma.
i--;
}
}
else {
// Keep the comma.
i--;
}
}
}
}
}
}
else if (ch == '\u000f') {
i++;
}
else {
buffer.append(ch);
i++;
}
}
return buffer.toString();
}
/**
* Remove formatting from a line of IRC text.
*
* @since PircBot 1.2.0
*
* @param line the input text.
*
* @return the same text, but without any bold, underlining, reverse, etc.
*/
public static String removeFormatting(String line) {
int length = line.length();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
char ch = line.charAt(i);
if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') {
// Don't add this character.
}
else {
buffer.append(ch);
}
}
return buffer.toString();
}
/**
* Removes all formatting and colours from a line of IRC text.
*
* @since PircBot 1.2.0
*
* @param line the input text.
*
* @return the same text, but without formatting and colour characters.
*
*/
public static String removeFormattingAndColors(String line) {
return removeFormatting(removeColors(line));
}
}

View File

@ -1,227 +1,227 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.net.*;
import java.io.*;
/**
* This class is used to allow the bot to interact with a DCC Chat session.
*
* @since 0.9c
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class DccChat {
/**
* This constructor is used when we are accepting a DCC CHAT request
* from somebody. It attempts to connect to the client that issued the
* request.
*
* @param bot An instance of the underlying PircBot.
* @param sourceNick The nick of the sender.
* @param address The address to connect to.
* @param port The port number to connect to.
*
* @throws IOException If the connection cannot be made.
*/
DccChat(PircBot bot, String nick, String login, String hostname, long address, int port) {
_bot = bot;
_address = address;
_port = port;
_nick = nick;
_login = login;
_hostname = hostname;
_acceptable = true;
}
/**
* This constructor is used after we have issued a DCC CHAT request to
* somebody. If the client accepts the chat request, then the socket we
* obtain is passed to this constructor.
*
* @param bot An instance of the underlying PircBot.
* @param sourceNick The nick of the user we are sending the request to.
* @param socket The socket which will be used for the DCC CHAT session.
*
* @throws IOException If the socket cannot be read from.
*/
DccChat(PircBot bot, String nick, Socket socket) throws IOException {
_bot = bot;
_nick = nick;
_socket = socket;
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
_acceptable = false;
}
/**
* Accept this DccChat connection.
*
* @since 1.2.0
*
*/
public synchronized void accept() throws IOException {
if (_acceptable) {
_acceptable = false;
int[] ip = _bot.longToIp(_address);
String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
_socket = new Socket(ipStr, _port);
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
}
}
/**
* Reads the next line of text from the client at the other end of our DCC Chat
* connection. This method blocks until something can be returned.
* If the connection has closed, null is returned.
*
* @return The next line of text from the client. Returns null if the
* connection has closed normally.
*
* @throws IOException If an I/O error occurs.
*/
public String readLine() throws IOException {
if (_acceptable) {
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
}
return _reader.readLine();
}
/**
* Sends a line of text to the client at the other end of our DCC Chat
* connection.
*
* @param line The line of text to be sent. This should not include
* linefeed characters.
*
* @throws IOException If an I/O error occurs.
*/
public void sendLine(String line) throws IOException {
if (_acceptable) {
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
}
// No need for synchronization here really...
_writer.write(line + "\r\n");
_writer.flush();
}
/**
* Closes the DCC Chat connection.
*
* @throws IOException If an I/O error occurs.
*/
public void close() throws IOException {
if (_acceptable) {
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
}
_socket.close();
}
/**
* Returns the nick of the other user taking part in this file transfer.
*
* @return the nick of the other user.
*
*/
public String getNick() {
return _nick;
}
/**
* Returns the login of the DCC Chat initiator.
*
* @return the login of the DCC Chat initiator. null if we sent it.
*
*/
public String getLogin() {
return _login;
}
/**
* Returns the hostname of the DCC Chat initiator.
*
* @return the hostname of the DCC Chat initiator. null if we sent it.
*
*/
public String getHostname() {
return _hostname;
}
/**
* Returns the BufferedReader used by this DCC Chat.
*
* @return the BufferedReader used by this DCC Chat.
*/
public BufferedReader getBufferedReader() {
return _reader;
}
/**
* Returns the BufferedReader used by this DCC Chat.
*
* @return the BufferedReader used by this DCC Chat.
*/
public BufferedWriter getBufferedWriter() {
return _writer;
}
/**
* Returns the raw Socket used by this DCC Chat.
*
* @return the raw Socket used by this DCC Chat.
*/
public Socket getSocket() {
return _socket;
}
/**
* Returns the address of the sender as a long.
*
* @return the address of the sender as a long.
*/
public long getNumericalAddress() {
return _address;
}
private PircBot _bot;
private String _nick;
private String _login = null;
private String _hostname = null;
private BufferedReader _reader;
private BufferedWriter _writer;
private Socket _socket;
private boolean _acceptable;
private long _address = 0;
private int _port = 0;
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.net.*;
import java.io.*;
/**
* This class is used to allow the bot to interact with a DCC Chat session.
*
* @since 0.9c
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class DccChat {
/**
* This constructor is used when we are accepting a DCC CHAT request
* from somebody. It attempts to connect to the client that issued the
* request.
*
* @param bot An instance of the underlying PircBot.
* @param sourceNick The nick of the sender.
* @param address The address to connect to.
* @param port The port number to connect to.
*
* @throws IOException If the connection cannot be made.
*/
DccChat(PircBot bot, String nick, String login, String hostname, long address, int port) {
_bot = bot;
_address = address;
_port = port;
_nick = nick;
_login = login;
_hostname = hostname;
_acceptable = true;
}
/**
* This constructor is used after we have issued a DCC CHAT request to
* somebody. If the client accepts the chat request, then the socket we
* obtain is passed to this constructor.
*
* @param bot An instance of the underlying PircBot.
* @param sourceNick The nick of the user we are sending the request to.
* @param socket The socket which will be used for the DCC CHAT session.
*
* @throws IOException If the socket cannot be read from.
*/
DccChat(PircBot bot, String nick, Socket socket) throws IOException {
_bot = bot;
_nick = nick;
_socket = socket;
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
_acceptable = false;
}
/**
* Accept this DccChat connection.
*
* @since 1.2.0
*
*/
public synchronized void accept() throws IOException {
if (_acceptable) {
_acceptable = false;
int[] ip = _bot.longToIp(_address);
String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
_socket = new Socket(ipStr, _port);
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
}
}
/**
* Reads the next line of text from the client at the other end of our DCC Chat
* connection. This method blocks until something can be returned.
* If the connection has closed, null is returned.
*
* @return The next line of text from the client. Returns null if the
* connection has closed normally.
*
* @throws IOException If an I/O error occurs.
*/
public String readLine() throws IOException {
if (_acceptable) {
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
}
return _reader.readLine();
}
/**
* Sends a line of text to the client at the other end of our DCC Chat
* connection.
*
* @param line The line of text to be sent. This should not include
* linefeed characters.
*
* @throws IOException If an I/O error occurs.
*/
public void sendLine(String line) throws IOException {
if (_acceptable) {
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
}
// No need for synchronization here really...
_writer.write(line + "\r\n");
_writer.flush();
}
/**
* Closes the DCC Chat connection.
*
* @throws IOException If an I/O error occurs.
*/
public void close() throws IOException {
if (_acceptable) {
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
}
_socket.close();
}
/**
* Returns the nick of the other user taking part in this file transfer.
*
* @return the nick of the other user.
*
*/
public String getNick() {
return _nick;
}
/**
* Returns the login of the DCC Chat initiator.
*
* @return the login of the DCC Chat initiator. null if we sent it.
*
*/
public String getLogin() {
return _login;
}
/**
* Returns the hostname of the DCC Chat initiator.
*
* @return the hostname of the DCC Chat initiator. null if we sent it.
*
*/
public String getHostname() {
return _hostname;
}
/**
* Returns the BufferedReader used by this DCC Chat.
*
* @return the BufferedReader used by this DCC Chat.
*/
public BufferedReader getBufferedReader() {
return _reader;
}
/**
* Returns the BufferedReader used by this DCC Chat.
*
* @return the BufferedReader used by this DCC Chat.
*/
public BufferedWriter getBufferedWriter() {
return _writer;
}
/**
* Returns the raw Socket used by this DCC Chat.
*
* @return the raw Socket used by this DCC Chat.
*/
public Socket getSocket() {
return _socket;
}
/**
* Returns the address of the sender as a long.
*
* @return the address of the sender as a long.
*/
public long getNumericalAddress() {
return _address;
}
private PircBot _bot;
private String _nick;
private String _login = null;
private String _hostname = null;
private BufferedReader _reader;
private BufferedWriter _writer;
private Socket _socket;
private boolean _acceptable;
private long _address = 0;
private int _port = 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,152 +1,152 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.util.*;
/**
* This class is used to process DCC events from the server.
*
* @since 1.2.0
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class DccManager {
/**
* Constructs a DccManager to look after all DCC SEND and CHAT events.
*
* @param bot The PircBot whose DCC events this class will handle.
*/
DccManager(PircBot bot) {
_bot = bot;
}
/**
* Processes a DCC request.
*
* @return True if the type of request was handled successfully.
*/
boolean processRequest(String nick, String login, String hostname, String request) {
StringTokenizer tokenizer = new StringTokenizer(request);
tokenizer.nextToken();
String type = tokenizer.nextToken();
String filename = tokenizer.nextToken();
if (type.equals("SEND")) {
long address = Long.parseLong(tokenizer.nextToken());
int port = Integer.parseInt(tokenizer.nextToken());
long size = -1;
try {
size = Long.parseLong(tokenizer.nextToken());
}
catch (Exception e) {
// Stick with the old value.
}
DccFileTransfer transfer = new DccFileTransfer(_bot, this, nick, login, hostname, type, filename, address, port, size);
_bot.onIncomingFileTransfer(transfer);
}
else if (type.equals("RESUME")) {
int port = Integer.parseInt(tokenizer.nextToken());
long progress = Long.parseLong(tokenizer.nextToken());
DccFileTransfer transfer = null;
synchronized (_awaitingResume) {
for (int i = 0; i < _awaitingResume.size(); i++) {
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
_awaitingResume.removeElementAt(i);
break;
}
}
}
if (transfer != null) {
transfer.setProgress(progress);
_bot.sendCTCPCommand(nick, "DCC ACCEPT file.ext " + port + " " + progress);
}
}
else if (type.equals("ACCEPT")) {
int port = Integer.parseInt(tokenizer.nextToken());
// XXX: progress is not used?
//long progress = Long.parseLong(tokenizer.nextToken());
DccFileTransfer transfer = null;
synchronized (_awaitingResume) {
for (int i = 0; i < _awaitingResume.size(); i++) {
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
_awaitingResume.removeElementAt(i);
break;
}
}
}
if (transfer != null) {
transfer.doReceive(transfer.getFile(), true);
}
}
else if (type.equals("CHAT")) {
long address = Long.parseLong(tokenizer.nextToken());
int port = Integer.parseInt(tokenizer.nextToken());
final DccChat chat = new DccChat(_bot, nick, login, hostname, address, port);
new Thread() {
public void run() {
_bot.onIncomingChatRequest(chat);
}
}.start();
}
else {
return false;
}
return true;
}
/**
* Add this DccFileTransfer to the list of those awaiting possible
* resuming.
*
* @param transfer the DccFileTransfer that may be resumed.
*/
void addAwaitingResume(DccFileTransfer transfer) {
synchronized (_awaitingResume) {
_awaitingResume.addElement(transfer);
}
}
/**
* Remove this transfer from the list of those awaiting resuming.
*/
void removeAwaitingResume(DccFileTransfer transfer) {
_awaitingResume.removeElement(transfer);
}
private PircBot _bot;
private Vector<DccFileTransfer> _awaitingResume = new Vector<DccFileTransfer>();
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.util.*;
/**
* This class is used to process DCC events from the server.
*
* @since 1.2.0
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class DccManager {
/**
* Constructs a DccManager to look after all DCC SEND and CHAT events.
*
* @param bot The PircBot whose DCC events this class will handle.
*/
DccManager(PircBot bot) {
_bot = bot;
}
/**
* Processes a DCC request.
*
* @return True if the type of request was handled successfully.
*/
boolean processRequest(String nick, String login, String hostname, String request) {
StringTokenizer tokenizer = new StringTokenizer(request);
tokenizer.nextToken();
String type = tokenizer.nextToken();
String filename = tokenizer.nextToken();
if (type.equals("SEND")) {
long address = Long.parseLong(tokenizer.nextToken());
int port = Integer.parseInt(tokenizer.nextToken());
long size = -1;
try {
size = Long.parseLong(tokenizer.nextToken());
}
catch (Exception e) {
// Stick with the old value.
}
DccFileTransfer transfer = new DccFileTransfer(_bot, this, nick, login, hostname, type, filename, address, port, size);
_bot.onIncomingFileTransfer(transfer);
}
else if (type.equals("RESUME")) {
int port = Integer.parseInt(tokenizer.nextToken());
long progress = Long.parseLong(tokenizer.nextToken());
DccFileTransfer transfer = null;
synchronized (_awaitingResume) {
for (int i = 0; i < _awaitingResume.size(); i++) {
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
_awaitingResume.removeElementAt(i);
break;
}
}
}
if (transfer != null) {
transfer.setProgress(progress);
_bot.sendCTCPCommand(nick, "DCC ACCEPT file.ext " + port + " " + progress);
}
}
else if (type.equals("ACCEPT")) {
int port = Integer.parseInt(tokenizer.nextToken());
// XXX: progress is not used?
//long progress = Long.parseLong(tokenizer.nextToken());
DccFileTransfer transfer = null;
synchronized (_awaitingResume) {
for (int i = 0; i < _awaitingResume.size(); i++) {
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
_awaitingResume.removeElementAt(i);
break;
}
}
}
if (transfer != null) {
transfer.doReceive(transfer.getFile(), true);
}
}
else if (type.equals("CHAT")) {
long address = Long.parseLong(tokenizer.nextToken());
int port = Integer.parseInt(tokenizer.nextToken());
final DccChat chat = new DccChat(_bot, nick, login, hostname, address, port);
new Thread() {
public void run() {
_bot.onIncomingChatRequest(chat);
}
}.start();
}
else {
return false;
}
return true;
}
/**
* Add this DccFileTransfer to the list of those awaiting possible
* resuming.
*
* @param transfer the DccFileTransfer that may be resumed.
*/
void addAwaitingResume(DccFileTransfer transfer) {
synchronized (_awaitingResume) {
_awaitingResume.addElement(transfer);
}
}
/**
* Remove this transfer from the list of those awaiting resuming.
*/
void removeAwaitingResume(DccFileTransfer transfer) {
_awaitingResume.removeElement(transfer);
}
private PircBot _bot;
private Vector<DccFileTransfer> _awaitingResume = new Vector<DccFileTransfer>();
}

View File

@ -1,119 +1,119 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.net.*;
import java.io.*;
/**
* A simple IdentServer (also know as "The Identification Protocol").
* An ident server provides a means to determine the identity of a
* user of a particular TCP connection.
* <p>
* Most IRC servers attempt to contact the ident server on connecting
* hosts in order to determine the user's identity. A few IRC servers
* will not allow you to connect unless this information is provided.
* <p>
* So when a PircBot is run on a machine that does not run an ident server,
* it may be necessary to provide a "faked" response by starting up its
* own ident server and sending out apparently correct responses.
* <p>
* An instance of this class can be used to start up an ident server
* only if it is possible to do so. Reasons for not being able to do
* so are if there is already an ident server running on port 113, or
* if you are running as an unprivileged user who is unable to create
* a server socket on that port number.
*
* @since 0.9c
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class IdentServer extends Thread {
/**
* Constructs and starts an instance of an IdentServer that will
* respond to a client with the provided login. Rather than calling
* this constructor explicitly from your code, it is recommended that
* you use the startIdentServer method in the PircBot class.
* <p>
* The ident server will wait for up to 60 seconds before shutting
* down. Otherwise, it will shut down as soon as it has responded
* to an ident request.
*
* @param bot The PircBot instance that will be used to log to.
* @param login The login that the ident server will respond with.
*/
IdentServer(PircBot bot, String login) {
_bot = bot;
_login = login;
try {
_ss = new ServerSocket(113);
_ss.setSoTimeout(60000);
}
catch (Exception e) {
_bot.log("*** Could not start the ident server on port 113.");
return;
}
_bot.log("*** Ident server running on port 113 for the next 60 seconds...");
this.setName(this.getClass() + "-Thread");
this.start();
}
/**
* Waits for a client to connect to the ident server before making an
* appropriate response. Note that this method is started by the class
* constructor.
*/
public void run() {
try {
Socket socket = _ss.accept();
socket.setSoTimeout(60000);
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
String line = reader.readLine();
if (line != null) {
_bot.log("*** Ident request received: " + line);
line = line + " : USERID : UNIX : " + _login;
writer.write(line + "\r\n");
writer.flush();
_bot.log("*** Ident reply sent: " + line);
writer.close();
}
}
catch (Exception e) {
// We're not really concerned with what went wrong, are we?
}
try {
_ss.close();
}
catch (Exception e) {
// Doesn't really matter...
}
_bot.log("*** The Ident server has been shut down.");
}
private PircBot _bot;
private String _login;
private ServerSocket _ss = null;
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.net.*;
import java.io.*;
/**
* A simple IdentServer (also know as "The Identification Protocol").
* An ident server provides a means to determine the identity of a
* user of a particular TCP connection.
* <p>
* Most IRC servers attempt to contact the ident server on connecting
* hosts in order to determine the user's identity. A few IRC servers
* will not allow you to connect unless this information is provided.
* <p>
* So when a PircBot is run on a machine that does not run an ident server,
* it may be necessary to provide a "faked" response by starting up its
* own ident server and sending out apparently correct responses.
* <p>
* An instance of this class can be used to start up an ident server
* only if it is possible to do so. Reasons for not being able to do
* so are if there is already an ident server running on port 113, or
* if you are running as an unprivileged user who is unable to create
* a server socket on that port number.
*
* @since 0.9c
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class IdentServer extends Thread {
/**
* Constructs and starts an instance of an IdentServer that will
* respond to a client with the provided login. Rather than calling
* this constructor explicitly from your code, it is recommended that
* you use the startIdentServer method in the PircBot class.
* <p>
* The ident server will wait for up to 60 seconds before shutting
* down. Otherwise, it will shut down as soon as it has responded
* to an ident request.
*
* @param bot The PircBot instance that will be used to log to.
* @param login The login that the ident server will respond with.
*/
IdentServer(PircBot bot, String login) {
_bot = bot;
_login = login;
try {
_ss = new ServerSocket(113);
_ss.setSoTimeout(60000);
}
catch (Exception e) {
_bot.log("*** Could not start the ident server on port 113.");
return;
}
_bot.log("*** Ident server running on port 113 for the next 60 seconds...");
this.setName(this.getClass() + "-Thread");
this.start();
}
/**
* Waits for a client to connect to the ident server before making an
* appropriate response. Note that this method is started by the class
* constructor.
*/
public void run() {
try {
Socket socket = _ss.accept();
socket.setSoTimeout(60000);
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
String line = reader.readLine();
if (line != null) {
_bot.log("*** Ident request received: " + line);
line = line + " : USERID : UNIX : " + _login;
writer.write(line + "\r\n");
writer.flush();
_bot.log("*** Ident reply sent: " + line);
writer.close();
}
}
catch (Exception e) {
// We're not really concerned with what went wrong, are we?
}
try {
_ss.close();
}
catch (Exception e) {
// Doesn't really matter...
}
_bot.log("*** The Ident server has been shut down.");
}
private PircBot _bot;
private String _login;
private ServerSocket _ss = null;
}

View File

@ -1,169 +1,169 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* A Thread which reads lines from the IRC server. It then
* passes these lines to the PircBot without changing them.
* This running Thread also detects disconnection from the server
* and is thus used by the OutputThread to send lines to the server.
*
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class InputThread extends Thread {
/**
* The InputThread reads lines from the IRC server and allows the
* PircBot to handle them.
*
* @param bot An instance of the underlying PircBot.
* @param breader The BufferedReader that reads lines from the server.
* @param bwriter The BufferedWriter that sends lines to the server.
*/
InputThread(PircBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) {
_bot = bot;
_socket = socket;
_breader = breader;
_bwriter = bwriter;
this.setName(this.getClass() + "-Thread");
}
/**
* Sends a raw line to the IRC server as soon as possible, bypassing the
* outgoing message queue.
*
* @param line The raw line to send to the IRC server.
*/
void sendRawLine(String line) {
OutputThread.sendRawLine(_bot, _bwriter, line);
}
/**
* Returns true if this InputThread is connected to an IRC server.
* The result of this method should only act as a rough guide,
* as the result may not be valid by the time you act upon it.
*
* @return True if still connected.
*/
boolean isConnected() {
return _isConnected;
}
/**
* Called to start this Thread reading lines from the IRC server.
* When a line is read, this method calls the handleLine method
* in the PircBot, which may subsequently call an 'onXxx' method
* in the PircBot subclass. If any subclass of Throwable (i.e.
* any Exception or Error) is thrown by your method, then this
* method will print the stack trace to the standard output. It
* is probable that the PircBot may still be functioning normally
* after such a problem, but the existance of any uncaught exceptions
* in your code is something you should really fix.
*/
public void run() {
try {
boolean running = true;
while (running) {
try {
String line = null;
while ((line = _breader.readLine()) != null) {
try {
_bot.handleLine(line);
}
catch (Throwable t) {
// Stick the whole stack trace into a String so we can output it nicely.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.flush();
StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n");
synchronized (_bot) {
_bot.log("### Your implementation of PircBot is faulty and you have");
_bot.log("### allowed an uncaught Exception or Error to propagate in your");
_bot.log("### code. It may be possible for PircBot to continue operating");
_bot.log("### normally. Here is the stack trace that was produced: -");
_bot.log("### ");
while (tokenizer.hasMoreTokens()) {
_bot.log("### " + tokenizer.nextToken());
}
}
}
}
if (line == null) {
// The server must have disconnected us.
running = false;
}
}
catch (InterruptedIOException iioe) {
// This will happen if we haven't received anything from the server for a while.
// So we shall send it a ping to check that we are still connected.
this.sendRawLine("PING " + (System.currentTimeMillis() / 1000));
// Now we go back to listening for stuff from the server...
}
}
}
catch (Exception e) {
// Do nothing.
}
// If we reach this point, then we must have disconnected.
try {
_socket.close();
}
catch (Exception e) {
// Just assume the socket was already closed.
}
if (!_disposed) {
_bot.log("*** Disconnected.");
_isConnected = false;
_bot.onDisconnect();
}
}
/**
* Closes the socket without onDisconnect being called subsequently.
*/
public void dispose () {
try {
_disposed = true;
_socket.close();
}
catch (Exception e) {
// Do nothing.
}
}
private PircBot _bot = null;
private Socket _socket = null;
private BufferedReader _breader = null;
private BufferedWriter _bwriter = null;
private boolean _isConnected = true;
private boolean _disposed = false;
public static final int MAX_LINE_LENGTH = 512;
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.io.*;
import java.net.*;
import java.util.*;
/**
* A Thread which reads lines from the IRC server. It then
* passes these lines to the PircBot without changing them.
* This running Thread also detects disconnection from the server
* and is thus used by the OutputThread to send lines to the server.
*
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class InputThread extends Thread {
/**
* The InputThread reads lines from the IRC server and allows the
* PircBot to handle them.
*
* @param bot An instance of the underlying PircBot.
* @param breader The BufferedReader that reads lines from the server.
* @param bwriter The BufferedWriter that sends lines to the server.
*/
InputThread(PircBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) {
_bot = bot;
_socket = socket;
_breader = breader;
_bwriter = bwriter;
this.setName(this.getClass() + "-Thread");
}
/**
* Sends a raw line to the IRC server as soon as possible, bypassing the
* outgoing message queue.
*
* @param line The raw line to send to the IRC server.
*/
void sendRawLine(String line) {
OutputThread.sendRawLine(_bot, _bwriter, line);
}
/**
* Returns true if this InputThread is connected to an IRC server.
* The result of this method should only act as a rough guide,
* as the result may not be valid by the time you act upon it.
*
* @return True if still connected.
*/
boolean isConnected() {
return _isConnected;
}
/**
* Called to start this Thread reading lines from the IRC server.
* When a line is read, this method calls the handleLine method
* in the PircBot, which may subsequently call an 'onXxx' method
* in the PircBot subclass. If any subclass of Throwable (i.e.
* any Exception or Error) is thrown by your method, then this
* method will print the stack trace to the standard output. It
* is probable that the PircBot may still be functioning normally
* after such a problem, but the existance of any uncaught exceptions
* in your code is something you should really fix.
*/
public void run() {
try {
boolean running = true;
while (running) {
try {
String line = null;
while ((line = _breader.readLine()) != null) {
try {
_bot.handleLine(line);
}
catch (Throwable t) {
// Stick the whole stack trace into a String so we can output it nicely.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.flush();
StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n");
synchronized (_bot) {
_bot.log("### Your implementation of PircBot is faulty and you have");
_bot.log("### allowed an uncaught Exception or Error to propagate in your");
_bot.log("### code. It may be possible for PircBot to continue operating");
_bot.log("### normally. Here is the stack trace that was produced: -");
_bot.log("### ");
while (tokenizer.hasMoreTokens()) {
_bot.log("### " + tokenizer.nextToken());
}
}
}
}
if (line == null) {
// The server must have disconnected us.
running = false;
}
}
catch (InterruptedIOException iioe) {
// This will happen if we haven't received anything from the server for a while.
// So we shall send it a ping to check that we are still connected.
this.sendRawLine("PING " + (System.currentTimeMillis() / 1000));
// Now we go back to listening for stuff from the server...
}
}
}
catch (Exception e) {
// Do nothing.
}
// If we reach this point, then we must have disconnected.
try {
_socket.close();
}
catch (Exception e) {
// Just assume the socket was already closed.
}
if (!_disposed) {
_bot.log("*** Disconnected.");
_isConnected = false;
_bot.onDisconnect();
}
}
/**
* Closes the socket without onDisconnect being called subsequently.
*/
public void dispose () {
try {
_disposed = true;
_socket.close();
}
catch (Exception e) {
// Do nothing.
}
}
private PircBot _bot = null;
private Socket _socket = null;
private BufferedReader _breader = null;
private BufferedWriter _bwriter = null;
private boolean _isConnected = true;
private boolean _disposed = false;
public static final int MAX_LINE_LENGTH = 512;
}

View File

@ -1,36 +1,36 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* An IrcException class.
*
* @since 0.9
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class IrcException extends Exception {
private static final long serialVersionUID = -3705541066912475928L;
/**
* Constructs a new IrcException.
*
* @param e The error message to report.
*/
public IrcException(String e) {
super(e);
}
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* An IrcException class.
*
* @since 0.9
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class IrcException extends Exception {
private static final long serialVersionUID = -3705541066912475928L;
/**
* Constructs a new IrcException.
*
* @param e The error message to report.
*/
public IrcException(String e) {
super(e);
}
}

View File

@ -1,39 +1,39 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* A NickAlreadyInUseException class. This exception is
* thrown when the PircBot attempts to join an IRC server
* with a user name that is already in use.
*
* @since 0.9
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class NickAlreadyInUseException extends IrcException {
private static final long serialVersionUID = -4724325464519465479L;
/**
* Constructs a new IrcException.
*
* @param e The error message to report.
*/
public NickAlreadyInUseException(String e) {
super(e);
}
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* A NickAlreadyInUseException class. This exception is
* thrown when the PircBot attempts to join an IRC server
* with a user name that is already in use.
*
* @since 0.9
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class NickAlreadyInUseException extends IrcException {
private static final long serialVersionUID = -4724325464519465479L;
/**
* Constructs a new IrcException.
*
* @param e The error message to report.
*/
public NickAlreadyInUseException(String e) {
super(e);
}
}

View File

@ -1,104 +1,104 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.io.*;
/**
* A Thread which is responsible for sending messages to the IRC server.
* Messages are obtained from the outgoing message queue and sent
* immediately if possible. If there is a flood of messages, then to
* avoid getting kicked from a channel, we put a small delay between
* each one.
*
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class OutputThread extends Thread {
/**
* Constructs an OutputThread for the underlying PircBot. All messages
* sent to the IRC server are sent by this OutputThread to avoid hammering
* the server. Messages are sent immediately if possible. If there are
* multiple messages queued, then there is a delay imposed.
*
* @param bot The underlying PircBot instance.
* @param outQueue The Queue from which we will obtain our messages.
*/
OutputThread(PircBot bot, Queue outQueue) {
_bot = bot;
_outQueue = outQueue;
this.setName(this.getClass() + "-Thread");
}
/**
* A static method to write a line to a BufferedOutputStream and then pass
* the line to the log method of the supplied PircBot instance.
*
* @param bot The underlying PircBot instance.
* @param out The BufferedOutputStream to write to.
* @param line The line to be written. "\r\n" is appended to the end.
* @param encoding The charset to use when encoing this string into a
* byte array.
*/
static void sendRawLine(PircBot bot, BufferedWriter bwriter, String line) {
if (line.length() > bot.getMaxLineLength() - 2) {
line = line.substring(0, bot.getMaxLineLength() - 2);
}
synchronized(bwriter) {
try {
bwriter.write(line + "\r\n");
bwriter.flush();
bot.log(">>>" + line);
}
catch (Exception e) {
// Silent response - just lose the line.
}
}
}
/**
* This method starts the Thread consuming from the outgoing message
* Queue and sending lines to the server.
*/
public void run() {
try {
boolean running = true;
while (running) {
// Small delay to prevent spamming of the channel
Thread.sleep(_bot.getMessageDelay());
String line = (String) _outQueue.next();
if (line != null) {
_bot.sendRawLine(line);
}
else {
running = false;
}
}
}
catch (InterruptedException e) {
// Just let the method return naturally...
}
}
private PircBot _bot = null;
private Queue _outQueue = null;
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.io.*;
/**
* A Thread which is responsible for sending messages to the IRC server.
* Messages are obtained from the outgoing message queue and sent
* immediately if possible. If there is a flood of messages, then to
* avoid getting kicked from a channel, we put a small delay between
* each one.
*
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class OutputThread extends Thread {
/**
* Constructs an OutputThread for the underlying PircBot. All messages
* sent to the IRC server are sent by this OutputThread to avoid hammering
* the server. Messages are sent immediately if possible. If there are
* multiple messages queued, then there is a delay imposed.
*
* @param bot The underlying PircBot instance.
* @param outQueue The Queue from which we will obtain our messages.
*/
OutputThread(PircBot bot, Queue outQueue) {
_bot = bot;
_outQueue = outQueue;
this.setName(this.getClass() + "-Thread");
}
/**
* A static method to write a line to a BufferedOutputStream and then pass
* the line to the log method of the supplied PircBot instance.
*
* @param bot The underlying PircBot instance.
* @param out The BufferedOutputStream to write to.
* @param line The line to be written. "\r\n" is appended to the end.
* @param encoding The charset to use when encoing this string into a
* byte array.
*/
static void sendRawLine(PircBot bot, BufferedWriter bwriter, String line) {
if (line.length() > bot.getMaxLineLength() - 2) {
line = line.substring(0, bot.getMaxLineLength() - 2);
}
synchronized(bwriter) {
try {
bwriter.write(line + "\r\n");
bwriter.flush();
bot.log(">>>" + line);
}
catch (Exception e) {
// Silent response - just lose the line.
}
}
}
/**
* This method starts the Thread consuming from the outgoing message
* Queue and sending lines to the server.
*/
public void run() {
try {
boolean running = true;
while (running) {
// Small delay to prevent spamming of the channel
Thread.sleep(_bot.getMessageDelay());
String line = (String) _outQueue.next();
if (line != null) {
_bot.sendRawLine(line);
}
else {
running = false;
}
}
}
catch (InterruptedException e) {
// Just let the method return naturally...
}
}
private PircBot _bot = null;
private Queue _outQueue = null;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,146 +1,146 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.util.Vector;
/**
* Queue is a definition of a data structure that may
* act as a queue - that is, data can be added to one end of the
* queue and data can be requested from the head end of the queue.
* This class is thread safe for multiple producers and a single
* consumer. The next() method will block until there is data in
* the queue.
*
* This has now been modified so that it is compatible with
* the earlier JDK1.1 in order to be suitable for running on
* mobile appliances. This means replacing the LinkedList with
* a Vector, which is hardly ideal, but this Queue is typically
* only polled every second before dispatching messages.
*
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class Queue {
/**
* Constructs a Queue object of unlimited size.
*/
public Queue() {
}
/**
* Adds an Object to the end of the Queue.
*
* @param o The Object to be added to the Queue.
*/
public void add(Object o) {
synchronized(_queue) {
_queue.addElement(o);
_queue.notify();
}
}
/**
* Adds an Object to the front of the Queue.
*
* @param o The Object to be added to the Queue.
*/
public void addFront(Object o) {
synchronized(_queue) {
_queue.insertElementAt(o, 0);
_queue.notify();
}
}
/**
* Returns the Object at the front of the Queue. This
* Object is then removed from the Queue. If the Queue
* is empty, then this method shall block until there
* is an Object in the Queue to return.
*
* @return The next item from the front of the queue.
*/
public Object next() {
Object o = null;
// Block if the Queue is empty.
synchronized(_queue) {
if (_queue.size() == 0) {
try {
_queue.wait();
}
catch (InterruptedException e) {
return null;
}
}
// Return the Object.
try {
o = _queue.firstElement();
_queue.removeElementAt(0);
}
catch (ArrayIndexOutOfBoundsException e) {
throw new InternalError("Race hazard in Queue object.");
}
}
return o;
}
/**
* Returns true if the Queue is not empty. If another
* Thread empties the Queue before <b>next()</b> is
* called, then the call to <b>next()</b> shall block
* until the Queue has been populated again.
*
* @return True only if the Queue not empty.
*/
public boolean hasNext() {
return (this.size() != 0);
}
/**
* Clears the contents of the Queue.
*/
public void clear() {
synchronized(_queue) {
_queue.removeAllElements();
}
}
/**
* Returns the size of the Queue.
*
* @return The current size of the queue.
*/
public int size() {
return _queue.size();
}
private Vector<Object> _queue = new Vector<Object>();
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
import java.util.Vector;
/**
* Queue is a definition of a data structure that may
* act as a queue - that is, data can be added to one end of the
* queue and data can be requested from the head end of the queue.
* This class is thread safe for multiple producers and a single
* consumer. The next() method will block until there is data in
* the queue.
*
* This has now been modified so that it is compatible with
* the earlier JDK1.1 in order to be suitable for running on
* mobile appliances. This means replacing the LinkedList with
* a Vector, which is hardly ideal, but this Queue is typically
* only polled every second before dispatching messages.
*
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class Queue {
/**
* Constructs a Queue object of unlimited size.
*/
public Queue() {
}
/**
* Adds an Object to the end of the Queue.
*
* @param o The Object to be added to the Queue.
*/
public void add(Object o) {
synchronized(_queue) {
_queue.addElement(o);
_queue.notify();
}
}
/**
* Adds an Object to the front of the Queue.
*
* @param o The Object to be added to the Queue.
*/
public void addFront(Object o) {
synchronized(_queue) {
_queue.insertElementAt(o, 0);
_queue.notify();
}
}
/**
* Returns the Object at the front of the Queue. This
* Object is then removed from the Queue. If the Queue
* is empty, then this method shall block until there
* is an Object in the Queue to return.
*
* @return The next item from the front of the queue.
*/
public Object next() {
Object o = null;
// Block if the Queue is empty.
synchronized(_queue) {
if (_queue.size() == 0) {
try {
_queue.wait();
}
catch (InterruptedException e) {
return null;
}
}
// Return the Object.
try {
o = _queue.firstElement();
_queue.removeElementAt(0);
}
catch (ArrayIndexOutOfBoundsException e) {
throw new InternalError("Race hazard in Queue object.");
}
}
return o;
}
/**
* Returns true if the Queue is not empty. If another
* Thread empties the Queue before <b>next()</b> is
* called, then the call to <b>next()</b> shall block
* until the Queue has been populated again.
*
* @return True only if the Queue not empty.
*/
public boolean hasNext() {
return (this.size() != 0);
}
/**
* Clears the contents of the Queue.
*/
public void clear() {
synchronized(_queue) {
_queue.removeAllElements();
}
}
/**
* Returns the size of the Queue.
*
* @return The current size of the queue.
*/
public int size() {
return _queue.size();
}
private Vector<Object> _queue = new Vector<Object>();
}

View File

@ -1,176 +1,176 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* This interface contains the values of all numeric replies specified
* in section 6 of RFC 1459. Refer to RFC 1459 for further information.
* <p>
* If you override the onServerResponse method in the PircBot class,
* you may find these constants useful when comparing the numeric
* value of a given code.
*
* @since 1.0.0
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public interface ReplyConstants {
// Error Replies.
public static final int ERR_NOSUCHNICK = 401;
public static final int ERR_NOSUCHSERVER = 402;
public static final int ERR_NOSUCHCHANNEL = 403;
public static final int ERR_CANNOTSENDTOCHAN = 404;
public static final int ERR_TOOMANYCHANNELS = 405;
public static final int ERR_WASNOSUCHNICK = 406;
public static final int ERR_TOOMANYTARGETS = 407;
public static final int ERR_NOORIGIN = 409;
public static final int ERR_NORECIPIENT = 411;
public static final int ERR_NOTEXTTOSEND = 412;
public static final int ERR_NOTOPLEVEL = 413;
public static final int ERR_WILDTOPLEVEL = 414;
public static final int ERR_UNKNOWNCOMMAND = 421;
public static final int ERR_NOMOTD = 422;
public static final int ERR_NOADMININFO = 423;
public static final int ERR_FILEERROR = 424;
public static final int ERR_NONICKNAMEGIVEN = 431;
public static final int ERR_ERRONEUSNICKNAME = 432;
public static final int ERR_NICKNAMEINUSE = 433;
public static final int ERR_NICKCOLLISION = 436;
public static final int ERR_USERNOTINCHANNEL = 441;
public static final int ERR_NOTONCHANNEL = 442;
public static final int ERR_USERONCHANNEL = 443;
public static final int ERR_NOLOGIN = 444;
public static final int ERR_SUMMONDISABLED = 445;
public static final int ERR_USERSDISABLED = 446;
public static final int ERR_NOTREGISTERED = 451;
public static final int ERR_NEEDMOREPARAMS = 461;
public static final int ERR_ALREADYREGISTRED = 462;
public static final int ERR_NOPERMFORHOST = 463;
public static final int ERR_PASSWDMISMATCH = 464;
public static final int ERR_YOUREBANNEDCREEP = 465;
public static final int ERR_KEYSET = 467;
public static final int ERR_CHANNELISFULL = 471;
public static final int ERR_UNKNOWNMODE = 472;
public static final int ERR_INVITEONLYCHAN = 473;
public static final int ERR_BANNEDFROMCHAN = 474;
public static final int ERR_BADCHANNELKEY = 475;
public static final int ERR_NOPRIVILEGES = 481;
public static final int ERR_CHANOPRIVSNEEDED = 482;
public static final int ERR_CANTKILLSERVER = 483;
public static final int ERR_NOOPERHOST = 491;
public static final int ERR_UMODEUNKNOWNFLAG = 501;
public static final int ERR_USERSDONTMATCH = 502;
// Command Responses.
public static final int RPL_TRACELINK = 200;
public static final int RPL_TRACECONNECTING = 201;
public static final int RPL_TRACEHANDSHAKE = 202;
public static final int RPL_TRACEUNKNOWN = 203;
public static final int RPL_TRACEOPERATOR = 204;
public static final int RPL_TRACEUSER = 205;
public static final int RPL_TRACESERVER = 206;
public static final int RPL_TRACENEWTYPE = 208;
public static final int RPL_STATSLINKINFO = 211;
public static final int RPL_STATSCOMMANDS = 212;
public static final int RPL_STATSCLINE = 213;
public static final int RPL_STATSNLINE = 214;
public static final int RPL_STATSILINE = 215;
public static final int RPL_STATSKLINE = 216;
public static final int RPL_STATSYLINE = 218;
public static final int RPL_ENDOFSTATS = 219;
public static final int RPL_UMODEIS = 221;
public static final int RPL_STATSLLINE = 241;
public static final int RPL_STATSUPTIME = 242;
public static final int RPL_STATSOLINE = 243;
public static final int RPL_STATSHLINE = 244;
public static final int RPL_LUSERCLIENT = 251;
public static final int RPL_LUSEROP = 252;
public static final int RPL_LUSERUNKNOWN = 253;
public static final int RPL_LUSERCHANNELS = 254;
public static final int RPL_LUSERME = 255;
public static final int RPL_ADMINME = 256;
public static final int RPL_ADMINLOC1 = 257;
public static final int RPL_ADMINLOC2 = 258;
public static final int RPL_ADMINEMAIL = 259;
public static final int RPL_TRACELOG = 261;
public static final int RPL_NONE = 300;
public static final int RPL_AWAY = 301;
public static final int RPL_USERHOST = 302;
public static final int RPL_ISON = 303;
public static final int RPL_UNAWAY = 305;
public static final int RPL_NOWAWAY = 306;
public static final int RPL_WHOISUSER = 311;
public static final int RPL_WHOISSERVER = 312;
public static final int RPL_WHOISOPERATOR = 313;
public static final int RPL_WHOWASUSER = 314;
public static final int RPL_ENDOFWHO = 315;
public static final int RPL_WHOISIDLE = 317;
public static final int RPL_ENDOFWHOIS = 318;
public static final int RPL_WHOISCHANNELS = 319;
public static final int RPL_LISTSTART = 321;
public static final int RPL_LIST = 322;
public static final int RPL_LISTEND = 323;
public static final int RPL_CHANNELMODEIS = 324;
public static final int RPL_NOTOPIC = 331;
public static final int RPL_TOPIC = 332;
public static final int RPL_TOPICINFO = 333;
public static final int RPL_INVITING = 341;
public static final int RPL_SUMMONING = 342;
public static final int RPL_VERSION = 351;
public static final int RPL_WHOREPLY = 352;
public static final int RPL_NAMREPLY = 353;
public static final int RPL_LINKS = 364;
public static final int RPL_ENDOFLINKS = 365;
public static final int RPL_ENDOFNAMES = 366;
public static final int RPL_BANLIST = 367;
public static final int RPL_ENDOFBANLIST = 368;
public static final int RPL_ENDOFWHOWAS = 369;
public static final int RPL_INFO = 371;
public static final int RPL_MOTD = 372;
public static final int RPL_ENDOFINFO = 374;
public static final int RPL_MOTDSTART = 375;
public static final int RPL_ENDOFMOTD = 376;
public static final int RPL_YOUREOPER = 381;
public static final int RPL_REHASHING = 382;
public static final int RPL_TIME = 391;
public static final int RPL_USERSSTART = 392;
public static final int RPL_USERS = 393;
public static final int RPL_ENDOFUSERS = 394;
public static final int RPL_NOUSERS = 395;
// Reserved Numerics.
public static final int RPL_TRACECLASS = 209;
public static final int RPL_STATSQLINE = 217;
public static final int RPL_SERVICEINFO = 231;
public static final int RPL_ENDOFSERVICES = 232;
public static final int RPL_SERVICE = 233;
public static final int RPL_SERVLIST = 234;
public static final int RPL_SERVLISTEND = 235;
public static final int RPL_WHOISCHANOP = 316;
public static final int RPL_KILLDONE = 361;
public static final int RPL_CLOSING = 362;
public static final int RPL_CLOSEEND = 363;
public static final int RPL_INFOSTART = 373;
public static final int RPL_MYPORTIS = 384;
public static final int ERR_YOUWILLBEBANNED = 466;
public static final int ERR_BADCHANMASK = 476;
public static final int ERR_NOSERVICEHOST = 492;
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* This interface contains the values of all numeric replies specified
* in section 6 of RFC 1459. Refer to RFC 1459 for further information.
* <p>
* If you override the onServerResponse method in the PircBot class,
* you may find these constants useful when comparing the numeric
* value of a given code.
*
* @since 1.0.0
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public interface ReplyConstants {
// Error Replies.
public static final int ERR_NOSUCHNICK = 401;
public static final int ERR_NOSUCHSERVER = 402;
public static final int ERR_NOSUCHCHANNEL = 403;
public static final int ERR_CANNOTSENDTOCHAN = 404;
public static final int ERR_TOOMANYCHANNELS = 405;
public static final int ERR_WASNOSUCHNICK = 406;
public static final int ERR_TOOMANYTARGETS = 407;
public static final int ERR_NOORIGIN = 409;
public static final int ERR_NORECIPIENT = 411;
public static final int ERR_NOTEXTTOSEND = 412;
public static final int ERR_NOTOPLEVEL = 413;
public static final int ERR_WILDTOPLEVEL = 414;
public static final int ERR_UNKNOWNCOMMAND = 421;
public static final int ERR_NOMOTD = 422;
public static final int ERR_NOADMININFO = 423;
public static final int ERR_FILEERROR = 424;
public static final int ERR_NONICKNAMEGIVEN = 431;
public static final int ERR_ERRONEUSNICKNAME = 432;
public static final int ERR_NICKNAMEINUSE = 433;
public static final int ERR_NICKCOLLISION = 436;
public static final int ERR_USERNOTINCHANNEL = 441;
public static final int ERR_NOTONCHANNEL = 442;
public static final int ERR_USERONCHANNEL = 443;
public static final int ERR_NOLOGIN = 444;
public static final int ERR_SUMMONDISABLED = 445;
public static final int ERR_USERSDISABLED = 446;
public static final int ERR_NOTREGISTERED = 451;
public static final int ERR_NEEDMOREPARAMS = 461;
public static final int ERR_ALREADYREGISTRED = 462;
public static final int ERR_NOPERMFORHOST = 463;
public static final int ERR_PASSWDMISMATCH = 464;
public static final int ERR_YOUREBANNEDCREEP = 465;
public static final int ERR_KEYSET = 467;
public static final int ERR_CHANNELISFULL = 471;
public static final int ERR_UNKNOWNMODE = 472;
public static final int ERR_INVITEONLYCHAN = 473;
public static final int ERR_BANNEDFROMCHAN = 474;
public static final int ERR_BADCHANNELKEY = 475;
public static final int ERR_NOPRIVILEGES = 481;
public static final int ERR_CHANOPRIVSNEEDED = 482;
public static final int ERR_CANTKILLSERVER = 483;
public static final int ERR_NOOPERHOST = 491;
public static final int ERR_UMODEUNKNOWNFLAG = 501;
public static final int ERR_USERSDONTMATCH = 502;
// Command Responses.
public static final int RPL_TRACELINK = 200;
public static final int RPL_TRACECONNECTING = 201;
public static final int RPL_TRACEHANDSHAKE = 202;
public static final int RPL_TRACEUNKNOWN = 203;
public static final int RPL_TRACEOPERATOR = 204;
public static final int RPL_TRACEUSER = 205;
public static final int RPL_TRACESERVER = 206;
public static final int RPL_TRACENEWTYPE = 208;
public static final int RPL_STATSLINKINFO = 211;
public static final int RPL_STATSCOMMANDS = 212;
public static final int RPL_STATSCLINE = 213;
public static final int RPL_STATSNLINE = 214;
public static final int RPL_STATSILINE = 215;
public static final int RPL_STATSKLINE = 216;
public static final int RPL_STATSYLINE = 218;
public static final int RPL_ENDOFSTATS = 219;
public static final int RPL_UMODEIS = 221;
public static final int RPL_STATSLLINE = 241;
public static final int RPL_STATSUPTIME = 242;
public static final int RPL_STATSOLINE = 243;
public static final int RPL_STATSHLINE = 244;
public static final int RPL_LUSERCLIENT = 251;
public static final int RPL_LUSEROP = 252;
public static final int RPL_LUSERUNKNOWN = 253;
public static final int RPL_LUSERCHANNELS = 254;
public static final int RPL_LUSERME = 255;
public static final int RPL_ADMINME = 256;
public static final int RPL_ADMINLOC1 = 257;
public static final int RPL_ADMINLOC2 = 258;
public static final int RPL_ADMINEMAIL = 259;
public static final int RPL_TRACELOG = 261;
public static final int RPL_NONE = 300;
public static final int RPL_AWAY = 301;
public static final int RPL_USERHOST = 302;
public static final int RPL_ISON = 303;
public static final int RPL_UNAWAY = 305;
public static final int RPL_NOWAWAY = 306;
public static final int RPL_WHOISUSER = 311;
public static final int RPL_WHOISSERVER = 312;
public static final int RPL_WHOISOPERATOR = 313;
public static final int RPL_WHOWASUSER = 314;
public static final int RPL_ENDOFWHO = 315;
public static final int RPL_WHOISIDLE = 317;
public static final int RPL_ENDOFWHOIS = 318;
public static final int RPL_WHOISCHANNELS = 319;
public static final int RPL_LISTSTART = 321;
public static final int RPL_LIST = 322;
public static final int RPL_LISTEND = 323;
public static final int RPL_CHANNELMODEIS = 324;
public static final int RPL_NOTOPIC = 331;
public static final int RPL_TOPIC = 332;
public static final int RPL_TOPICINFO = 333;
public static final int RPL_INVITING = 341;
public static final int RPL_SUMMONING = 342;
public static final int RPL_VERSION = 351;
public static final int RPL_WHOREPLY = 352;
public static final int RPL_NAMREPLY = 353;
public static final int RPL_LINKS = 364;
public static final int RPL_ENDOFLINKS = 365;
public static final int RPL_ENDOFNAMES = 366;
public static final int RPL_BANLIST = 367;
public static final int RPL_ENDOFBANLIST = 368;
public static final int RPL_ENDOFWHOWAS = 369;
public static final int RPL_INFO = 371;
public static final int RPL_MOTD = 372;
public static final int RPL_ENDOFINFO = 374;
public static final int RPL_MOTDSTART = 375;
public static final int RPL_ENDOFMOTD = 376;
public static final int RPL_YOUREOPER = 381;
public static final int RPL_REHASHING = 382;
public static final int RPL_TIME = 391;
public static final int RPL_USERSSTART = 392;
public static final int RPL_USERS = 393;
public static final int RPL_ENDOFUSERS = 394;
public static final int RPL_NOUSERS = 395;
// Reserved Numerics.
public static final int RPL_TRACECLASS = 209;
public static final int RPL_STATSQLINE = 217;
public static final int RPL_SERVICEINFO = 231;
public static final int RPL_ENDOFSERVICES = 232;
public static final int RPL_SERVICE = 233;
public static final int RPL_SERVLIST = 234;
public static final int RPL_SERVLISTEND = 235;
public static final int RPL_WHOISCHANOP = 316;
public static final int RPL_KILLDONE = 361;
public static final int RPL_CLOSING = 362;
public static final int RPL_CLOSEEND = 363;
public static final int RPL_INFOSTART = 373;
public static final int RPL_MYPORTIS = 384;
public static final int ERR_YOUWILLBEBANNED = 466;
public static final int ERR_BADCHANMASK = 476;
public static final int ERR_NOSERVICEHOST = 492;
}

View File

@ -1,161 +1,161 @@
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* This class is used to represent a user on an IRC server.
* Instances of this class are returned by the getUsers method
* in the PircBot class.
* <p>
* Note that this class no longer implements the Comparable interface
* for Java 1.1 compatibility reasons.
*
* @since 1.0.0
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class User {
/**
* Constructs a User object with a known prefix and nick.
*
* @param prefix The status of the user, for example, "@".
* @param nick The nick of the user.
*/
User(String prefix, String nick) {
_prefix = prefix;
_nick = nick;
_lowerNick = nick.toLowerCase();
}
/**
* Returns the prefix of the user. If the User object has been obtained
* from a list of users in a channel, then this will reflect the user's
* status in that channel.
*
* @return The prefix of the user. If there is no prefix, then an empty
* String is returned.
*/
public String getPrefix() {
return _prefix;
}
/**
* Returns whether or not the user represented by this object is an
* operator. If the User object has been obtained from a list of users
* in a channel, then this will reflect the user's operator status in
* that channel.
*
* @return true if the user is an operator in the channel.
*/
public boolean isOp() {
return _prefix.indexOf('@') >= 0;
}
/**
* Returns whether or not the user represented by this object has
* voice. If the User object has been obtained from a list of users
* in a channel, then this will reflect the user's voice status in
* that channel.
*
* @return true if the user has voice in the channel.
*/
public boolean hasVoice() {
return _prefix.indexOf('+') >= 0;
}
/**
* Returns the nick of the user.
*
* @return The user's nick.
*/
public String getNick() {
return _nick;
}
/**
* Returns the nick of the user complete with their prefix if they
* have one, e.g. "@Dave".
*
* @return The user's prefix and nick.
*/
public String toString() {
return this.getPrefix() + this.getNick();
}
/**
* Returns true if the nick represented by this User object is the same
* as the argument. A case insensitive comparison is made.
*
* @return true if the nicks are identical (case insensitive).
*/
public boolean equals(String nick) {
return nick.toLowerCase().equals(_lowerNick);
}
/**
* Returns true if the nick represented by this User object is the same
* as the nick of the User object given as an argument.
* A case insensitive comparison is made.
*
* @return true if o is a User object with a matching lowercase nick.
*/
public boolean equals(Object o) {
if (o instanceof User) {
User other = (User) o;
return other._lowerNick.equals(_lowerNick);
}
return false;
}
/**
* Returns the hash code of this User object.
*
* @return the hash code of the User object.
*/
public int hashCode() {
return _lowerNick.hashCode();
}
/**
* Returns the result of calling the compareTo method on lowercased
* nicks. This is useful for sorting lists of User objects.
*
* @return the result of calling compareTo on lowercased nicks.
*/
public int compareTo(Object o) {
if (o instanceof User) {
User other = (User) o;
return other._lowerNick.compareTo(_lowerNick);
}
return -1;
}
private String _prefix;
private String _nick;
private String _lowerNick;
}
/*
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
This file is part of PircBot.
This software is dual-licensed, allowing you to choose between the GNU
General Public License (GPL) and the www.jibble.org Commercial License.
Since the GPL may be too restrictive for use in a proprietary application,
a commercial license is also provided. Full license information can be
found at http://www.jibble.org/licenses/
*/
package org.jibble.pircbot;
/**
* This class is used to represent a user on an IRC server.
* Instances of this class are returned by the getUsers method
* in the PircBot class.
* <p>
* Note that this class no longer implements the Comparable interface
* for Java 1.1 compatibility reasons.
*
* @since 1.0.0
* @author Paul James Mutton,
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
*/
public class User {
/**
* Constructs a User object with a known prefix and nick.
*
* @param prefix The status of the user, for example, "@".
* @param nick The nick of the user.
*/
User(String prefix, String nick) {
_prefix = prefix;
_nick = nick;
_lowerNick = nick.toLowerCase();
}
/**
* Returns the prefix of the user. If the User object has been obtained
* from a list of users in a channel, then this will reflect the user's
* status in that channel.
*
* @return The prefix of the user. If there is no prefix, then an empty
* String is returned.
*/
public String getPrefix() {
return _prefix;
}
/**
* Returns whether or not the user represented by this object is an
* operator. If the User object has been obtained from a list of users
* in a channel, then this will reflect the user's operator status in
* that channel.
*
* @return true if the user is an operator in the channel.
*/
public boolean isOp() {
return _prefix.indexOf('@') >= 0;
}
/**
* Returns whether or not the user represented by this object has
* voice. If the User object has been obtained from a list of users
* in a channel, then this will reflect the user's voice status in
* that channel.
*
* @return true if the user has voice in the channel.
*/
public boolean hasVoice() {
return _prefix.indexOf('+') >= 0;
}
/**
* Returns the nick of the user.
*
* @return The user's nick.
*/
public String getNick() {
return _nick;
}
/**
* Returns the nick of the user complete with their prefix if they
* have one, e.g. "@Dave".
*
* @return The user's prefix and nick.
*/
public String toString() {
return this.getPrefix() + this.getNick();
}
/**
* Returns true if the nick represented by this User object is the same
* as the argument. A case insensitive comparison is made.
*
* @return true if the nicks are identical (case insensitive).
*/
public boolean equals(String nick) {
return nick.toLowerCase().equals(_lowerNick);
}
/**
* Returns true if the nick represented by this User object is the same
* as the nick of the User object given as an argument.
* A case insensitive comparison is made.
*
* @return true if o is a User object with a matching lowercase nick.
*/
public boolean equals(Object o) {
if (o instanceof User) {
User other = (User) o;
return other._lowerNick.equals(_lowerNick);
}
return false;
}
/**
* Returns the hash code of this User object.
*
* @return the hash code of the User object.
*/
public int hashCode() {
return _lowerNick.hashCode();
}
/**
* Returns the result of calling the compareTo method on lowercased
* nicks. This is useful for sorting lists of User objects.
*
* @return the result of calling compareTo on lowercased nicks.
*/
public int compareTo(Object o) {
if (o instanceof User) {
User other = (User) o;
return other._lowerNick.compareTo(_lowerNick);
}
return -1;
}
private String _prefix;
private String _nick;
private String _lowerNick;
}

View File

@ -32,6 +32,7 @@ import org.yaaic.model.Server;
*/
public abstract class BaseHandler
{
private String desc;
/**
* Execute the command
*
@ -50,6 +51,13 @@ public abstract class BaseHandler
*/
public abstract String getUsage();
/**
* Get the description for this command
*
* @return
*/
public abstract String getDescription();
/**
* Merge params to a string
*

View File

@ -21,6 +21,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
package org.yaaic.command;
import java.util.HashMap;
import java.util.Set;
import android.content.Intent;
@ -29,6 +30,7 @@ import org.yaaic.command.handler.DCCHandler;
import org.yaaic.command.handler.DeopHandler;
import org.yaaic.command.handler.DevoiceHandler;
import org.yaaic.command.handler.EchoHandler;
import org.yaaic.command.handler.HelpHandler;
import org.yaaic.command.handler.JoinHandler;
import org.yaaic.command.handler.KickHandler;
import org.yaaic.command.handler.MeHandler;
@ -95,6 +97,7 @@ public class CommandParser
commands.put("notice", new NoticeHandler());
commands.put("dcc", new DCCHandler());
commands.put("mode", new ModeHandler());
commands.put("help", new HelpHandler());
// Aliases
commands.put("j", commands.get("join"));
@ -115,6 +118,16 @@ public class CommandParser
return instance;
}
/**
* Get the commands HashMap
*
* @return HashMap - command, commandHandler
*/
public HashMap<String, BaseHandler> getCommands() {
return commands;
}
/**
* Is the given command a valid client command?
*

View File

@ -38,6 +38,8 @@ import android.content.Intent;
*/
public class CloseHandler extends BaseHandler
{
private String desc ="Closes the current window";
/**
* Execute /close
*/
@ -73,4 +75,12 @@ public class CloseHandler extends BaseHandler
{
return "/close";
}
/**
* Description of /close
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -39,6 +39,8 @@ import org.yaaic.model.Server;
*/
public class DCCHandler extends BaseHandler
{
private String desc = "Send a file to a user";
/**
* Execute /dcc
*/
@ -76,4 +78,13 @@ public class DCCHandler extends BaseHandler
{
return "/dcc SEND <nickname> <file>";
}
/**
* Description of /dcc
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,7 @@ import org.yaaic.model.Server;
*/
public class DeopHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /voice
*/
@ -58,4 +59,13 @@ public class DeopHandler extends BaseHandler
{
return "/voice <nickname>";
}
/**
* Description of /voice
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,7 @@ import org.yaaic.model.Server;
*/
public class DevoiceHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /devoice
*/
@ -58,4 +59,13 @@ public class DevoiceHandler extends BaseHandler
{
return "/devoice <nickname>";
}
/**
* Description of /devoice
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -37,6 +37,7 @@ import android.content.Intent;
*/
public class EchoHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /echo
*/
@ -66,4 +67,13 @@ public class EchoHandler extends BaseHandler
{
return "/echo <text>";
}
/**
* Description of /echo
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -0,0 +1,75 @@
package org.yaaic.command.handler;
import java.util.HashMap;
import java.util.Set;
import org.yaaic.command.BaseHandler;
import org.yaaic.command.CommandParser;
import org.yaaic.exception.CommandException;
import org.yaaic.irc.IRCService;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Conversation;
import org.yaaic.model.Message;
import org.yaaic.model.Server;
import android.content.Intent;
/**
* Command: /help
*
* @author Karol Gliniecki <karol.gliniecki@googlemail.com>
*/
public class HelpHandler extends BaseHandler {
private String desc = "lists all available commands";
/**
* Execute /help
*/
@Override
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException {
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
throw new CommandException("Only usable from within a channel");
}
CommandParser cp = CommandParser.getInstance();
StringBuffer commandList = new StringBuffer("available commands: \n");
HashMap<String, BaseHandler> commands = cp.getCommands();
Object[] commandKeys = commands.keySet().toArray();
for (Object command: commandKeys) {
commandList.append("/"+command.toString() + " - "+commands.get(command).getDescription()+"\n");
}
Message message = new Message(commandList.toString());
message.setColor(Message.COLOR_YELLOW);
conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE,
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);
}
/**
*
*Usage of /help
*/
@Override
public String getUsage() {
return "/help";
}
/**
* Description of /help
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,7 @@ import org.yaaic.model.Server;
*/
public class JoinHandler extends BaseHandler
{
private String desc = "join a channel";
/**
* Execute /join
*/
@ -56,4 +57,12 @@ public class JoinHandler extends BaseHandler
{
return "/join <channel> [<key>]";
}
/**
* Description of /join
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -35,6 +35,8 @@ import org.yaaic.model.Server;
*/
public class KickHandler extends BaseHandler
{
private String desc = "kicks a user";
/**
* Execute /kick
*/
@ -60,4 +62,12 @@ public class KickHandler extends BaseHandler
{
return "/kick <nickname>";
}
/**
* Description of /kick
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -38,6 +38,8 @@ import android.content.Intent;
*/
public class MeHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /me
*/
@ -77,4 +79,9 @@ public class MeHandler extends BaseHandler
{
return "/me <text>";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -35,6 +35,8 @@ import org.yaaic.model.Server;
*/
public class ModeHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /mode
*/
@ -58,4 +60,9 @@ public class ModeHandler extends BaseHandler
{
return "/mode <channel> <mode>";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -39,6 +39,8 @@ import android.content.Intent;
*/
public class NamesHandler extends BaseHandler
{
private String desc = "lists all users in channel";
/**
* Execute /names
*/
@ -76,4 +78,13 @@ public class NamesHandler extends BaseHandler
{
return "/names";
}
/**
* Description of /names
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class NickHandler extends BaseHandler
{
private String desc = "change own nickname";
/**
* Execute /nick
*/
@ -54,4 +56,13 @@ public class NickHandler extends BaseHandler
{
return "/nick <nickname>";
}
/**
* Description of /nick
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -40,6 +40,8 @@ import android.content.Intent;
*/
public class NoticeHandler extends BaseHandler
{
private String desc = "Send a notice to an other user";
/**
* Execute /notice
*/
@ -74,4 +76,13 @@ public class NoticeHandler extends BaseHandler
{
return "/notice <nickname> <message>";
}
/**
* Description of /notice
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class OpHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /deop
*/
@ -58,4 +60,13 @@ public class OpHandler extends BaseHandler
{
return "/op <nickname>";
}
/**
* Description of /deop
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -35,6 +35,8 @@ import org.yaaic.model.Server;
*/
public class PartHandler extends BaseHandler
{
private String desc = "leave the current channel";
/**
* Execute /part
*/
@ -62,4 +64,9 @@ public class PartHandler extends BaseHandler
{
return "/part [<channel>]";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -39,6 +39,8 @@ import android.content.Intent;
*/
public class QueryHandler extends BaseHandler
{
private String desc = "opens a private chat with a user";
/**
* Execute /query
*/
@ -78,4 +80,9 @@ public class QueryHandler extends BaseHandler
{
return "/query <nickname>";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class QuitHandler extends BaseHandler
{
private String desc = "leave current channel";
/**
* Execute /quit
*/
@ -54,4 +56,13 @@ public class QuitHandler extends BaseHandler
{
return "/quit [<reason>]";
}
/**
* Description of /quit
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -36,6 +36,8 @@ import org.yaaic.model.Server;
*/
public class TopicHandler extends BaseHandler
{
private String desc = "show or change the current topic";
/**
* Execute /topic
*/
@ -65,4 +67,13 @@ public class TopicHandler extends BaseHandler
{
return "/topic [<topic>]";
}
/**
* Description of /topic
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class VoiceHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /voice
*/
@ -58,4 +60,13 @@ public class VoiceHandler extends BaseHandler
{
return "/voice <nickname>";
}
/**
* Description of /voice
*/
@Override
public String getDescription() {
return desc;
}
}