mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-23 09:22:19 -05:00
added getDescription and help command
This commit is contained in:
parent
9efeb5b8af
commit
6d01720ca6
@ -1,293 +1,293 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Colors class provides several static fields and methods that you may
|
* The Colors class provides several static fields and methods that you may
|
||||||
* find useful when writing an IRC Bot.
|
* find useful when writing an IRC Bot.
|
||||||
* <p>
|
* <p>
|
||||||
* This class contains constants that are useful for formatting lines
|
* This class contains constants that are useful for formatting lines
|
||||||
* sent to IRC servers. These constants allow you to apply various
|
* sent to IRC servers. These constants allow you to apply various
|
||||||
* formatting to the lines, such as colours, boldness, underlining
|
* formatting to the lines, such as colours, boldness, underlining
|
||||||
* and reverse text.
|
* and reverse text.
|
||||||
* <p>
|
* <p>
|
||||||
* The class contains static methods to remove colours and formatting
|
* The class contains static methods to remove colours and formatting
|
||||||
* from lines of IRC text.
|
* from lines of IRC text.
|
||||||
* <p>
|
* <p>
|
||||||
* Here are some examples of how to use the contants from within a
|
* Here are some examples of how to use the contants from within a
|
||||||
* class that extends PircBot and imports org.jibble.pircbot.*;
|
* class that extends PircBot and imports org.jibble.pircbot.*;
|
||||||
*
|
*
|
||||||
* <pre> sendMessage("#cs", Colors.BOLD + "A bold hello!");
|
* <pre> sendMessage("#cs", Colors.BOLD + "A bold hello!");
|
||||||
* <b>A bold hello!</b>
|
* <b>A bold hello!</b>
|
||||||
* sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
|
* sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
|
||||||
* <font color="red">Red</font> text
|
* <font color="red">Red</font> text
|
||||||
* sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
|
* sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
|
||||||
* <b><font color="red">Bold and red</font></b></pre>
|
* <b><font color="red">Bold and red</font></b></pre>
|
||||||
*
|
*
|
||||||
* Please note that some IRC channels may be configured to reject any
|
* Please note that some IRC channels may be configured to reject any
|
||||||
* messages that use colours. Also note that older IRC clients may be
|
* messages that use colours. Also note that older IRC clients may be
|
||||||
* unable to correctly display lines that contain colours and other
|
* unable to correctly display lines that contain colours and other
|
||||||
* control characters.
|
* control characters.
|
||||||
* <p>
|
* <p>
|
||||||
* Note that this class name has been spelt in the American style in
|
* Note that this class name has been spelt in the American style in
|
||||||
* order to remain consistent with the rest of the Java API.
|
* order to remain consistent with the rest of the Java API.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @since 0.9.12
|
* @since 0.9.12
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class Colors {
|
public class Colors {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all previously applied color and formatting attributes.
|
* Removes all previously applied color and formatting attributes.
|
||||||
*/
|
*/
|
||||||
public static final String NORMAL = "\u000f";
|
public static final String NORMAL = "\u000f";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bold text.
|
* Bold text.
|
||||||
*/
|
*/
|
||||||
public static final String BOLD = "\u0002";
|
public static final String BOLD = "\u0002";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Underlined text.
|
* Underlined text.
|
||||||
*/
|
*/
|
||||||
public static final String UNDERLINE = "\u001f";
|
public static final String UNDERLINE = "\u001f";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reversed text (may be rendered as italic text in some clients).
|
* Reversed text (may be rendered as italic text in some clients).
|
||||||
*/
|
*/
|
||||||
public static final String REVERSE = "\u0016";
|
public static final String REVERSE = "\u0016";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* White coloured text.
|
* White coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String WHITE = "\u000300";
|
public static final String WHITE = "\u000300";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Black coloured text.
|
* Black coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String BLACK = "\u000301";
|
public static final String BLACK = "\u000301";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dark blue coloured text.
|
* Dark blue coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String DARK_BLUE = "\u000302";
|
public static final String DARK_BLUE = "\u000302";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dark green coloured text.
|
* Dark green coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String DARK_GREEN = "\u000303";
|
public static final String DARK_GREEN = "\u000303";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Red coloured text.
|
* Red coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String RED = "\u000304";
|
public static final String RED = "\u000304";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Brown coloured text.
|
* Brown coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String BROWN = "\u000305";
|
public static final String BROWN = "\u000305";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purple coloured text.
|
* Purple coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String PURPLE = "\u000306";
|
public static final String PURPLE = "\u000306";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Olive coloured text.
|
* Olive coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String OLIVE = "\u000307";
|
public static final String OLIVE = "\u000307";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Yellow coloured text.
|
* Yellow coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String YELLOW = "\u000308";
|
public static final String YELLOW = "\u000308";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Green coloured text.
|
* Green coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String GREEN = "\u000309";
|
public static final String GREEN = "\u000309";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teal coloured text.
|
* Teal coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String TEAL = "\u000310";
|
public static final String TEAL = "\u000310";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cyan coloured text.
|
* Cyan coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String CYAN = "\u000311";
|
public static final String CYAN = "\u000311";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blue coloured text.
|
* Blue coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String BLUE = "\u000312";
|
public static final String BLUE = "\u000312";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Magenta coloured text.
|
* Magenta coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String MAGENTA = "\u000313";
|
public static final String MAGENTA = "\u000313";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dark gray coloured text.
|
* Dark gray coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String DARK_GRAY = "\u000314";
|
public static final String DARK_GRAY = "\u000314";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Light gray coloured text.
|
* Light gray coloured text.
|
||||||
*/
|
*/
|
||||||
public static final String LIGHT_GRAY = "\u000315";
|
public static final String LIGHT_GRAY = "\u000315";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class should not be constructed.
|
* This class should not be constructed.
|
||||||
*/
|
*/
|
||||||
private Colors() {
|
private Colors() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all colours from a line of IRC text.
|
* Removes all colours from a line of IRC text.
|
||||||
*
|
*
|
||||||
* @since PircBot 1.2.0
|
* @since PircBot 1.2.0
|
||||||
*
|
*
|
||||||
* @param line the input text.
|
* @param line the input text.
|
||||||
*
|
*
|
||||||
* @return the same text, but with all colours removed.
|
* @return the same text, but with all colours removed.
|
||||||
*/
|
*/
|
||||||
public static String removeColors(String line) {
|
public static String removeColors(String line) {
|
||||||
int length = line.length();
|
int length = line.length();
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < length) {
|
while (i < length) {
|
||||||
char ch = line.charAt(i);
|
char ch = line.charAt(i);
|
||||||
if (ch == '\u0003') {
|
if (ch == '\u0003') {
|
||||||
i++;
|
i++;
|
||||||
// Skip "x" or "xy" (foreground color).
|
// Skip "x" or "xy" (foreground color).
|
||||||
if (i < length) {
|
if (i < length) {
|
||||||
ch = line.charAt(i);
|
ch = line.charAt(i);
|
||||||
if (Character.isDigit(ch)) {
|
if (Character.isDigit(ch)) {
|
||||||
i++;
|
i++;
|
||||||
if (i < length) {
|
if (i < length) {
|
||||||
ch = line.charAt(i);
|
ch = line.charAt(i);
|
||||||
if (Character.isDigit(ch)) {
|
if (Character.isDigit(ch)) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now skip ",x" or ",xy" (background color).
|
// Now skip ",x" or ",xy" (background color).
|
||||||
if (i < length) {
|
if (i < length) {
|
||||||
ch = line.charAt(i);
|
ch = line.charAt(i);
|
||||||
if (ch == ',') {
|
if (ch == ',') {
|
||||||
i++;
|
i++;
|
||||||
if (i < length) {
|
if (i < length) {
|
||||||
ch = line.charAt(i);
|
ch = line.charAt(i);
|
||||||
if (Character.isDigit(ch)) {
|
if (Character.isDigit(ch)) {
|
||||||
i++;
|
i++;
|
||||||
if (i < length) {
|
if (i < length) {
|
||||||
ch = line.charAt(i);
|
ch = line.charAt(i);
|
||||||
if (Character.isDigit(ch)) {
|
if (Character.isDigit(ch)) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Keep the comma.
|
// Keep the comma.
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Keep the comma.
|
// Keep the comma.
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ch == '\u000f') {
|
else if (ch == '\u000f') {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove formatting from a line of IRC text.
|
* Remove formatting from a line of IRC text.
|
||||||
*
|
*
|
||||||
* @since PircBot 1.2.0
|
* @since PircBot 1.2.0
|
||||||
*
|
*
|
||||||
* @param line the input text.
|
* @param line the input text.
|
||||||
*
|
*
|
||||||
* @return the same text, but without any bold, underlining, reverse, etc.
|
* @return the same text, but without any bold, underlining, reverse, etc.
|
||||||
*/
|
*/
|
||||||
public static String removeFormatting(String line) {
|
public static String removeFormatting(String line) {
|
||||||
int length = line.length();
|
int length = line.length();
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
char ch = line.charAt(i);
|
char ch = line.charAt(i);
|
||||||
if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') {
|
if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') {
|
||||||
// Don't add this character.
|
// Don't add this character.
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
buffer.append(ch);
|
buffer.append(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all formatting and colours from a line of IRC text.
|
* Removes all formatting and colours from a line of IRC text.
|
||||||
*
|
*
|
||||||
* @since PircBot 1.2.0
|
* @since PircBot 1.2.0
|
||||||
*
|
*
|
||||||
* @param line the input text.
|
* @param line the input text.
|
||||||
*
|
*
|
||||||
* @return the same text, but without formatting and colour characters.
|
* @return the same text, but without formatting and colour characters.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static String removeFormattingAndColors(String line) {
|
public static String removeFormattingAndColors(String line) {
|
||||||
return removeFormatting(removeColors(line));
|
return removeFormatting(removeColors(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,227 +1,227 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to allow the bot to interact with a DCC Chat session.
|
* This class is used to allow the bot to interact with a DCC Chat session.
|
||||||
*
|
*
|
||||||
* @since 0.9c
|
* @since 0.9c
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class DccChat {
|
public class DccChat {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is used when we are accepting a DCC CHAT request
|
* This constructor is used when we are accepting a DCC CHAT request
|
||||||
* from somebody. It attempts to connect to the client that issued the
|
* from somebody. It attempts to connect to the client that issued the
|
||||||
* request.
|
* request.
|
||||||
*
|
*
|
||||||
* @param bot An instance of the underlying PircBot.
|
* @param bot An instance of the underlying PircBot.
|
||||||
* @param sourceNick The nick of the sender.
|
* @param sourceNick The nick of the sender.
|
||||||
* @param address The address to connect to.
|
* @param address The address to connect to.
|
||||||
* @param port The port number to connect to.
|
* @param port The port number to connect to.
|
||||||
*
|
*
|
||||||
* @throws IOException If the connection cannot be made.
|
* @throws IOException If the connection cannot be made.
|
||||||
*/
|
*/
|
||||||
DccChat(PircBot bot, String nick, String login, String hostname, long address, int port) {
|
DccChat(PircBot bot, String nick, String login, String hostname, long address, int port) {
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_address = address;
|
_address = address;
|
||||||
_port = port;
|
_port = port;
|
||||||
_nick = nick;
|
_nick = nick;
|
||||||
_login = login;
|
_login = login;
|
||||||
_hostname = hostname;
|
_hostname = hostname;
|
||||||
_acceptable = true;
|
_acceptable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor is used after we have issued a DCC CHAT request to
|
* 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
|
* somebody. If the client accepts the chat request, then the socket we
|
||||||
* obtain is passed to this constructor.
|
* obtain is passed to this constructor.
|
||||||
*
|
*
|
||||||
* @param bot An instance of the underlying PircBot.
|
* @param bot An instance of the underlying PircBot.
|
||||||
* @param sourceNick The nick of the user we are sending the request to.
|
* @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.
|
* @param socket The socket which will be used for the DCC CHAT session.
|
||||||
*
|
*
|
||||||
* @throws IOException If the socket cannot be read from.
|
* @throws IOException If the socket cannot be read from.
|
||||||
*/
|
*/
|
||||||
DccChat(PircBot bot, String nick, Socket socket) throws IOException {
|
DccChat(PircBot bot, String nick, Socket socket) throws IOException {
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_nick = nick;
|
_nick = nick;
|
||||||
_socket = socket;
|
_socket = socket;
|
||||||
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
|
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
|
||||||
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
|
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
|
||||||
_acceptable = false;
|
_acceptable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept this DccChat connection.
|
* Accept this DccChat connection.
|
||||||
*
|
*
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public synchronized void accept() throws IOException {
|
public synchronized void accept() throws IOException {
|
||||||
if (_acceptable) {
|
if (_acceptable) {
|
||||||
_acceptable = false;
|
_acceptable = false;
|
||||||
int[] ip = _bot.longToIp(_address);
|
int[] ip = _bot.longToIp(_address);
|
||||||
String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
|
String ipStr = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
|
||||||
_socket = new Socket(ipStr, _port);
|
_socket = new Socket(ipStr, _port);
|
||||||
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
|
_reader = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
|
||||||
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
|
_writer = new BufferedWriter(new OutputStreamWriter(_socket.getOutputStream()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the next line of text from the client at the other end of our DCC Chat
|
* 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.
|
* connection. This method blocks until something can be returned.
|
||||||
* If the connection has closed, null is returned.
|
* If the connection has closed, null is returned.
|
||||||
*
|
*
|
||||||
* @return The next line of text from the client. Returns null if the
|
* @return The next line of text from the client. Returns null if the
|
||||||
* connection has closed normally.
|
* connection has closed normally.
|
||||||
*
|
*
|
||||||
* @throws IOException If an I/O error occurs.
|
* @throws IOException If an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public String readLine() throws IOException {
|
public String readLine() throws IOException {
|
||||||
if (_acceptable) {
|
if (_acceptable) {
|
||||||
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
||||||
}
|
}
|
||||||
return _reader.readLine();
|
return _reader.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a line of text to the client at the other end of our DCC Chat
|
* Sends a line of text to the client at the other end of our DCC Chat
|
||||||
* connection.
|
* connection.
|
||||||
*
|
*
|
||||||
* @param line The line of text to be sent. This should not include
|
* @param line The line of text to be sent. This should not include
|
||||||
* linefeed characters.
|
* linefeed characters.
|
||||||
*
|
*
|
||||||
* @throws IOException If an I/O error occurs.
|
* @throws IOException If an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void sendLine(String line) throws IOException {
|
public void sendLine(String line) throws IOException {
|
||||||
if (_acceptable) {
|
if (_acceptable) {
|
||||||
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
||||||
}
|
}
|
||||||
// No need for synchronization here really...
|
// No need for synchronization here really...
|
||||||
_writer.write(line + "\r\n");
|
_writer.write(line + "\r\n");
|
||||||
_writer.flush();
|
_writer.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the DCC Chat connection.
|
* Closes the DCC Chat connection.
|
||||||
*
|
*
|
||||||
* @throws IOException If an I/O error occurs.
|
* @throws IOException If an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
if (_acceptable) {
|
if (_acceptable) {
|
||||||
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
throw new IOException("You must call the accept() method of the DccChat request before you can use it.");
|
||||||
}
|
}
|
||||||
_socket.close();
|
_socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the nick of the other user taking part in this file transfer.
|
* Returns the nick of the other user taking part in this file transfer.
|
||||||
*
|
*
|
||||||
* @return the nick of the other user.
|
* @return the nick of the other user.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String getNick() {
|
public String getNick() {
|
||||||
return _nick;
|
return _nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the login of the DCC Chat initiator.
|
* Returns the login of the DCC Chat initiator.
|
||||||
*
|
*
|
||||||
* @return the login of the DCC Chat initiator. null if we sent it.
|
* @return the login of the DCC Chat initiator. null if we sent it.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String getLogin() {
|
public String getLogin() {
|
||||||
return _login;
|
return _login;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hostname of the DCC Chat initiator.
|
* Returns the hostname of the DCC Chat initiator.
|
||||||
*
|
*
|
||||||
* @return the hostname of the DCC Chat initiator. null if we sent it.
|
* @return the hostname of the DCC Chat initiator. null if we sent it.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return _hostname;
|
return _hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the BufferedReader used by this DCC Chat.
|
* Returns the BufferedReader used by this DCC Chat.
|
||||||
*
|
*
|
||||||
* @return the BufferedReader used by this DCC Chat.
|
* @return the BufferedReader used by this DCC Chat.
|
||||||
*/
|
*/
|
||||||
public BufferedReader getBufferedReader() {
|
public BufferedReader getBufferedReader() {
|
||||||
return _reader;
|
return _reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the BufferedReader used by this DCC Chat.
|
* Returns the BufferedReader used by this DCC Chat.
|
||||||
*
|
*
|
||||||
* @return the BufferedReader used by this DCC Chat.
|
* @return the BufferedReader used by this DCC Chat.
|
||||||
*/
|
*/
|
||||||
public BufferedWriter getBufferedWriter() {
|
public BufferedWriter getBufferedWriter() {
|
||||||
return _writer;
|
return _writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the raw Socket used by this DCC Chat.
|
* Returns the raw Socket used by this DCC Chat.
|
||||||
*
|
*
|
||||||
* @return the raw Socket used by this DCC Chat.
|
* @return the raw Socket used by this DCC Chat.
|
||||||
*/
|
*/
|
||||||
public Socket getSocket() {
|
public Socket getSocket() {
|
||||||
return _socket;
|
return _socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the address of the sender as a long.
|
* Returns the address of the sender as a long.
|
||||||
*
|
*
|
||||||
* @return the address of the sender as a long.
|
* @return the address of the sender as a long.
|
||||||
*/
|
*/
|
||||||
public long getNumericalAddress() {
|
public long getNumericalAddress() {
|
||||||
return _address;
|
return _address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PircBot _bot;
|
private PircBot _bot;
|
||||||
private String _nick;
|
private String _nick;
|
||||||
private String _login = null;
|
private String _login = null;
|
||||||
private String _hostname = null;
|
private String _hostname = null;
|
||||||
private BufferedReader _reader;
|
private BufferedReader _reader;
|
||||||
private BufferedWriter _writer;
|
private BufferedWriter _writer;
|
||||||
private Socket _socket;
|
private Socket _socket;
|
||||||
private boolean _acceptable;
|
private boolean _acceptable;
|
||||||
private long _address = 0;
|
private long _address = 0;
|
||||||
private int _port = 0;
|
private int _port = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,152 +1,152 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to process DCC events from the server.
|
* This class is used to process DCC events from the server.
|
||||||
*
|
*
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class DccManager {
|
public class DccManager {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DccManager to look after all DCC SEND and CHAT events.
|
* Constructs a DccManager to look after all DCC SEND and CHAT events.
|
||||||
*
|
*
|
||||||
* @param bot The PircBot whose DCC events this class will handle.
|
* @param bot The PircBot whose DCC events this class will handle.
|
||||||
*/
|
*/
|
||||||
DccManager(PircBot bot) {
|
DccManager(PircBot bot) {
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a DCC request.
|
* Processes a DCC request.
|
||||||
*
|
*
|
||||||
* @return True if the type of request was handled successfully.
|
* @return True if the type of request was handled successfully.
|
||||||
*/
|
*/
|
||||||
boolean processRequest(String nick, String login, String hostname, String request) {
|
boolean processRequest(String nick, String login, String hostname, String request) {
|
||||||
StringTokenizer tokenizer = new StringTokenizer(request);
|
StringTokenizer tokenizer = new StringTokenizer(request);
|
||||||
tokenizer.nextToken();
|
tokenizer.nextToken();
|
||||||
String type = tokenizer.nextToken();
|
String type = tokenizer.nextToken();
|
||||||
String filename = tokenizer.nextToken();
|
String filename = tokenizer.nextToken();
|
||||||
|
|
||||||
if (type.equals("SEND")) {
|
if (type.equals("SEND")) {
|
||||||
long address = Long.parseLong(tokenizer.nextToken());
|
long address = Long.parseLong(tokenizer.nextToken());
|
||||||
int port = Integer.parseInt(tokenizer.nextToken());
|
int port = Integer.parseInt(tokenizer.nextToken());
|
||||||
long size = -1;
|
long size = -1;
|
||||||
try {
|
try {
|
||||||
size = Long.parseLong(tokenizer.nextToken());
|
size = Long.parseLong(tokenizer.nextToken());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Stick with the old value.
|
// Stick with the old value.
|
||||||
}
|
}
|
||||||
|
|
||||||
DccFileTransfer transfer = new DccFileTransfer(_bot, this, nick, login, hostname, type, filename, address, port, size);
|
DccFileTransfer transfer = new DccFileTransfer(_bot, this, nick, login, hostname, type, filename, address, port, size);
|
||||||
_bot.onIncomingFileTransfer(transfer);
|
_bot.onIncomingFileTransfer(transfer);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (type.equals("RESUME")) {
|
else if (type.equals("RESUME")) {
|
||||||
int port = Integer.parseInt(tokenizer.nextToken());
|
int port = Integer.parseInt(tokenizer.nextToken());
|
||||||
long progress = Long.parseLong(tokenizer.nextToken());
|
long progress = Long.parseLong(tokenizer.nextToken());
|
||||||
|
|
||||||
DccFileTransfer transfer = null;
|
DccFileTransfer transfer = null;
|
||||||
synchronized (_awaitingResume) {
|
synchronized (_awaitingResume) {
|
||||||
for (int i = 0; i < _awaitingResume.size(); i++) {
|
for (int i = 0; i < _awaitingResume.size(); i++) {
|
||||||
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
|
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
|
||||||
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
|
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
|
||||||
_awaitingResume.removeElementAt(i);
|
_awaitingResume.removeElementAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transfer != null) {
|
if (transfer != null) {
|
||||||
transfer.setProgress(progress);
|
transfer.setProgress(progress);
|
||||||
_bot.sendCTCPCommand(nick, "DCC ACCEPT file.ext " + port + " " + progress);
|
_bot.sendCTCPCommand(nick, "DCC ACCEPT file.ext " + port + " " + progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (type.equals("ACCEPT")) {
|
else if (type.equals("ACCEPT")) {
|
||||||
int port = Integer.parseInt(tokenizer.nextToken());
|
int port = Integer.parseInt(tokenizer.nextToken());
|
||||||
// XXX: progress is not used?
|
// XXX: progress is not used?
|
||||||
//long progress = Long.parseLong(tokenizer.nextToken());
|
//long progress = Long.parseLong(tokenizer.nextToken());
|
||||||
|
|
||||||
DccFileTransfer transfer = null;
|
DccFileTransfer transfer = null;
|
||||||
synchronized (_awaitingResume) {
|
synchronized (_awaitingResume) {
|
||||||
for (int i = 0; i < _awaitingResume.size(); i++) {
|
for (int i = 0; i < _awaitingResume.size(); i++) {
|
||||||
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
|
transfer = (DccFileTransfer) _awaitingResume.elementAt(i);
|
||||||
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
|
if (transfer.getNick().equals(nick) && transfer.getPort() == port) {
|
||||||
_awaitingResume.removeElementAt(i);
|
_awaitingResume.removeElementAt(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transfer != null) {
|
if (transfer != null) {
|
||||||
transfer.doReceive(transfer.getFile(), true);
|
transfer.doReceive(transfer.getFile(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (type.equals("CHAT")) {
|
else if (type.equals("CHAT")) {
|
||||||
long address = Long.parseLong(tokenizer.nextToken());
|
long address = Long.parseLong(tokenizer.nextToken());
|
||||||
int port = Integer.parseInt(tokenizer.nextToken());
|
int port = Integer.parseInt(tokenizer.nextToken());
|
||||||
|
|
||||||
final DccChat chat = new DccChat(_bot, nick, login, hostname, address, port);
|
final DccChat chat = new DccChat(_bot, nick, login, hostname, address, port);
|
||||||
|
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
_bot.onIncomingChatRequest(chat);
|
_bot.onIncomingChatRequest(chat);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add this DccFileTransfer to the list of those awaiting possible
|
* Add this DccFileTransfer to the list of those awaiting possible
|
||||||
* resuming.
|
* resuming.
|
||||||
*
|
*
|
||||||
* @param transfer the DccFileTransfer that may be resumed.
|
* @param transfer the DccFileTransfer that may be resumed.
|
||||||
*/
|
*/
|
||||||
void addAwaitingResume(DccFileTransfer transfer) {
|
void addAwaitingResume(DccFileTransfer transfer) {
|
||||||
synchronized (_awaitingResume) {
|
synchronized (_awaitingResume) {
|
||||||
_awaitingResume.addElement(transfer);
|
_awaitingResume.addElement(transfer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove this transfer from the list of those awaiting resuming.
|
* Remove this transfer from the list of those awaiting resuming.
|
||||||
*/
|
*/
|
||||||
void removeAwaitingResume(DccFileTransfer transfer) {
|
void removeAwaitingResume(DccFileTransfer transfer) {
|
||||||
_awaitingResume.removeElement(transfer);
|
_awaitingResume.removeElement(transfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PircBot _bot;
|
private PircBot _bot;
|
||||||
private Vector<DccFileTransfer> _awaitingResume = new Vector<DccFileTransfer>();
|
private Vector<DccFileTransfer> _awaitingResume = new Vector<DccFileTransfer>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,119 +1,119 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple IdentServer (also know as "The Identification Protocol").
|
* A simple IdentServer (also know as "The Identification Protocol").
|
||||||
* An ident server provides a means to determine the identity of a
|
* An ident server provides a means to determine the identity of a
|
||||||
* user of a particular TCP connection.
|
* user of a particular TCP connection.
|
||||||
* <p>
|
* <p>
|
||||||
* Most IRC servers attempt to contact the ident server on connecting
|
* Most IRC servers attempt to contact the ident server on connecting
|
||||||
* hosts in order to determine the user's identity. A few IRC servers
|
* hosts in order to determine the user's identity. A few IRC servers
|
||||||
* will not allow you to connect unless this information is provided.
|
* will not allow you to connect unless this information is provided.
|
||||||
* <p>
|
* <p>
|
||||||
* So when a PircBot is run on a machine that does not run an ident server,
|
* 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
|
* it may be necessary to provide a "faked" response by starting up its
|
||||||
* own ident server and sending out apparently correct responses.
|
* own ident server and sending out apparently correct responses.
|
||||||
* <p>
|
* <p>
|
||||||
* An instance of this class can be used to start up an ident server
|
* 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
|
* 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
|
* 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
|
* if you are running as an unprivileged user who is unable to create
|
||||||
* a server socket on that port number.
|
* a server socket on that port number.
|
||||||
*
|
*
|
||||||
* @since 0.9c
|
* @since 0.9c
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class IdentServer extends Thread {
|
public class IdentServer extends Thread {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs and starts an instance of an IdentServer that will
|
* Constructs and starts an instance of an IdentServer that will
|
||||||
* respond to a client with the provided login. Rather than calling
|
* respond to a client with the provided login. Rather than calling
|
||||||
* this constructor explicitly from your code, it is recommended that
|
* this constructor explicitly from your code, it is recommended that
|
||||||
* you use the startIdentServer method in the PircBot class.
|
* you use the startIdentServer method in the PircBot class.
|
||||||
* <p>
|
* <p>
|
||||||
* The ident server will wait for up to 60 seconds before shutting
|
* The ident server will wait for up to 60 seconds before shutting
|
||||||
* down. Otherwise, it will shut down as soon as it has responded
|
* down. Otherwise, it will shut down as soon as it has responded
|
||||||
* to an ident request.
|
* to an ident request.
|
||||||
*
|
*
|
||||||
* @param bot The PircBot instance that will be used to log to.
|
* @param bot The PircBot instance that will be used to log to.
|
||||||
* @param login The login that the ident server will respond with.
|
* @param login The login that the ident server will respond with.
|
||||||
*/
|
*/
|
||||||
IdentServer(PircBot bot, String login) {
|
IdentServer(PircBot bot, String login) {
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_login = login;
|
_login = login;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_ss = new ServerSocket(113);
|
_ss = new ServerSocket(113);
|
||||||
_ss.setSoTimeout(60000);
|
_ss.setSoTimeout(60000);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
_bot.log("*** Could not start the ident server on port 113.");
|
_bot.log("*** Could not start the ident server on port 113.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_bot.log("*** Ident server running on port 113 for the next 60 seconds...");
|
_bot.log("*** Ident server running on port 113 for the next 60 seconds...");
|
||||||
this.setName(this.getClass() + "-Thread");
|
this.setName(this.getClass() + "-Thread");
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for a client to connect to the ident server before making an
|
* Waits for a client to connect to the ident server before making an
|
||||||
* appropriate response. Note that this method is started by the class
|
* appropriate response. Note that this method is started by the class
|
||||||
* constructor.
|
* constructor.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Socket socket = _ss.accept();
|
Socket socket = _ss.accept();
|
||||||
socket.setSoTimeout(60000);
|
socket.setSoTimeout(60000);
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||||
|
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
_bot.log("*** Ident request received: " + line);
|
_bot.log("*** Ident request received: " + line);
|
||||||
line = line + " : USERID : UNIX : " + _login;
|
line = line + " : USERID : UNIX : " + _login;
|
||||||
writer.write(line + "\r\n");
|
writer.write(line + "\r\n");
|
||||||
writer.flush();
|
writer.flush();
|
||||||
_bot.log("*** Ident reply sent: " + line);
|
_bot.log("*** Ident reply sent: " + line);
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// We're not really concerned with what went wrong, are we?
|
// We're not really concerned with what went wrong, are we?
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_ss.close();
|
_ss.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Doesn't really matter...
|
// Doesn't really matter...
|
||||||
}
|
}
|
||||||
|
|
||||||
_bot.log("*** The Ident server has been shut down.");
|
_bot.log("*** The Ident server has been shut down.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private PircBot _bot;
|
private PircBot _bot;
|
||||||
private String _login;
|
private String _login;
|
||||||
private ServerSocket _ss = null;
|
private ServerSocket _ss = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,169 +1,169 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Thread which reads lines from the IRC server. It then
|
* A Thread which reads lines from the IRC server. It then
|
||||||
* passes these lines to the PircBot without changing them.
|
* passes these lines to the PircBot without changing them.
|
||||||
* This running Thread also detects disconnection from the server
|
* This running Thread also detects disconnection from the server
|
||||||
* and is thus used by the OutputThread to send lines to the server.
|
* and is thus used by the OutputThread to send lines to the server.
|
||||||
*
|
*
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class InputThread extends Thread {
|
public class InputThread extends Thread {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The InputThread reads lines from the IRC server and allows the
|
* The InputThread reads lines from the IRC server and allows the
|
||||||
* PircBot to handle them.
|
* PircBot to handle them.
|
||||||
*
|
*
|
||||||
* @param bot An instance of the underlying PircBot.
|
* @param bot An instance of the underlying PircBot.
|
||||||
* @param breader The BufferedReader that reads lines from the server.
|
* @param breader The BufferedReader that reads lines from the server.
|
||||||
* @param bwriter The BufferedWriter that sends lines to the server.
|
* @param bwriter The BufferedWriter that sends lines to the server.
|
||||||
*/
|
*/
|
||||||
InputThread(PircBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) {
|
InputThread(PircBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) {
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_socket = socket;
|
_socket = socket;
|
||||||
_breader = breader;
|
_breader = breader;
|
||||||
_bwriter = bwriter;
|
_bwriter = bwriter;
|
||||||
this.setName(this.getClass() + "-Thread");
|
this.setName(this.getClass() + "-Thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a raw line to the IRC server as soon as possible, bypassing the
|
* Sends a raw line to the IRC server as soon as possible, bypassing the
|
||||||
* outgoing message queue.
|
* outgoing message queue.
|
||||||
*
|
*
|
||||||
* @param line The raw line to send to the IRC server.
|
* @param line The raw line to send to the IRC server.
|
||||||
*/
|
*/
|
||||||
void sendRawLine(String line) {
|
void sendRawLine(String line) {
|
||||||
OutputThread.sendRawLine(_bot, _bwriter, line);
|
OutputThread.sendRawLine(_bot, _bwriter, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this InputThread is connected to an IRC server.
|
* Returns true if this InputThread is connected to an IRC server.
|
||||||
* The result of this method should only act as a rough guide,
|
* 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.
|
* as the result may not be valid by the time you act upon it.
|
||||||
*
|
*
|
||||||
* @return True if still connected.
|
* @return True if still connected.
|
||||||
*/
|
*/
|
||||||
boolean isConnected() {
|
boolean isConnected() {
|
||||||
return _isConnected;
|
return _isConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to start this Thread reading lines from the IRC server.
|
* Called to start this Thread reading lines from the IRC server.
|
||||||
* When a line is read, this method calls the handleLine method
|
* When a line is read, this method calls the handleLine method
|
||||||
* in the PircBot, which may subsequently call an 'onXxx' method
|
* in the PircBot, which may subsequently call an 'onXxx' method
|
||||||
* in the PircBot subclass. If any subclass of Throwable (i.e.
|
* in the PircBot subclass. If any subclass of Throwable (i.e.
|
||||||
* any Exception or Error) is thrown by your method, then this
|
* any Exception or Error) is thrown by your method, then this
|
||||||
* method will print the stack trace to the standard output. It
|
* method will print the stack trace to the standard output. It
|
||||||
* is probable that the PircBot may still be functioning normally
|
* is probable that the PircBot may still be functioning normally
|
||||||
* after such a problem, but the existance of any uncaught exceptions
|
* after such a problem, but the existance of any uncaught exceptions
|
||||||
* in your code is something you should really fix.
|
* in your code is something you should really fix.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
boolean running = true;
|
boolean running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
String line = null;
|
String line = null;
|
||||||
while ((line = _breader.readLine()) != null) {
|
while ((line = _breader.readLine()) != null) {
|
||||||
try {
|
try {
|
||||||
_bot.handleLine(line);
|
_bot.handleLine(line);
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
// Stick the whole stack trace into a String so we can output it nicely.
|
// Stick the whole stack trace into a String so we can output it nicely.
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
PrintWriter pw = new PrintWriter(sw);
|
||||||
t.printStackTrace(pw);
|
t.printStackTrace(pw);
|
||||||
pw.flush();
|
pw.flush();
|
||||||
StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n");
|
StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n");
|
||||||
synchronized (_bot) {
|
synchronized (_bot) {
|
||||||
_bot.log("### Your implementation of PircBot is faulty and you have");
|
_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("### allowed an uncaught Exception or Error to propagate in your");
|
||||||
_bot.log("### code. It may be possible for PircBot to continue operating");
|
_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("### normally. Here is the stack trace that was produced: -");
|
||||||
_bot.log("### ");
|
_bot.log("### ");
|
||||||
while (tokenizer.hasMoreTokens()) {
|
while (tokenizer.hasMoreTokens()) {
|
||||||
_bot.log("### " + tokenizer.nextToken());
|
_bot.log("### " + tokenizer.nextToken());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (line == null) {
|
if (line == null) {
|
||||||
// The server must have disconnected us.
|
// The server must have disconnected us.
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedIOException iioe) {
|
catch (InterruptedIOException iioe) {
|
||||||
// This will happen if we haven't received anything from the server for a while.
|
// 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.
|
// So we shall send it a ping to check that we are still connected.
|
||||||
this.sendRawLine("PING " + (System.currentTimeMillis() / 1000));
|
this.sendRawLine("PING " + (System.currentTimeMillis() / 1000));
|
||||||
// Now we go back to listening for stuff from the server...
|
// Now we go back to listening for stuff from the server...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reach this point, then we must have disconnected.
|
// If we reach this point, then we must have disconnected.
|
||||||
try {
|
try {
|
||||||
_socket.close();
|
_socket.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Just assume the socket was already closed.
|
// Just assume the socket was already closed.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_disposed) {
|
if (!_disposed) {
|
||||||
_bot.log("*** Disconnected.");
|
_bot.log("*** Disconnected.");
|
||||||
_isConnected = false;
|
_isConnected = false;
|
||||||
_bot.onDisconnect();
|
_bot.onDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the socket without onDisconnect being called subsequently.
|
* Closes the socket without onDisconnect being called subsequently.
|
||||||
*/
|
*/
|
||||||
public void dispose () {
|
public void dispose () {
|
||||||
try {
|
try {
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
_socket.close();
|
_socket.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PircBot _bot = null;
|
private PircBot _bot = null;
|
||||||
private Socket _socket = null;
|
private Socket _socket = null;
|
||||||
private BufferedReader _breader = null;
|
private BufferedReader _breader = null;
|
||||||
private BufferedWriter _bwriter = null;
|
private BufferedWriter _bwriter = null;
|
||||||
private boolean _isConnected = true;
|
private boolean _isConnected = true;
|
||||||
private boolean _disposed = false;
|
private boolean _disposed = false;
|
||||||
|
|
||||||
public static final int MAX_LINE_LENGTH = 512;
|
public static final int MAX_LINE_LENGTH = 512;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An IrcException class.
|
* An IrcException class.
|
||||||
*
|
*
|
||||||
* @since 0.9
|
* @since 0.9
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class IrcException extends Exception {
|
public class IrcException extends Exception {
|
||||||
private static final long serialVersionUID = -3705541066912475928L;
|
private static final long serialVersionUID = -3705541066912475928L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new IrcException.
|
* Constructs a new IrcException.
|
||||||
*
|
*
|
||||||
* @param e The error message to report.
|
* @param e The error message to report.
|
||||||
*/
|
*/
|
||||||
public IrcException(String e) {
|
public IrcException(String e) {
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A NickAlreadyInUseException class. This exception is
|
* A NickAlreadyInUseException class. This exception is
|
||||||
* thrown when the PircBot attempts to join an IRC server
|
* thrown when the PircBot attempts to join an IRC server
|
||||||
* with a user name that is already in use.
|
* with a user name that is already in use.
|
||||||
*
|
*
|
||||||
* @since 0.9
|
* @since 0.9
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class NickAlreadyInUseException extends IrcException {
|
public class NickAlreadyInUseException extends IrcException {
|
||||||
private static final long serialVersionUID = -4724325464519465479L;
|
private static final long serialVersionUID = -4724325464519465479L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new IrcException.
|
* Constructs a new IrcException.
|
||||||
*
|
*
|
||||||
* @param e The error message to report.
|
* @param e The error message to report.
|
||||||
*/
|
*/
|
||||||
public NickAlreadyInUseException(String e) {
|
public NickAlreadyInUseException(String e) {
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,104 +1,104 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Thread which is responsible for sending messages to the IRC server.
|
* A Thread which is responsible for sending messages to the IRC server.
|
||||||
* Messages are obtained from the outgoing message queue and sent
|
* Messages are obtained from the outgoing message queue and sent
|
||||||
* immediately if possible. If there is a flood of messages, then to
|
* immediately if possible. If there is a flood of messages, then to
|
||||||
* avoid getting kicked from a channel, we put a small delay between
|
* avoid getting kicked from a channel, we put a small delay between
|
||||||
* each one.
|
* each one.
|
||||||
*
|
*
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class OutputThread extends Thread {
|
public class OutputThread extends Thread {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an OutputThread for the underlying PircBot. All messages
|
* Constructs an OutputThread for the underlying PircBot. All messages
|
||||||
* sent to the IRC server are sent by this OutputThread to avoid hammering
|
* sent to the IRC server are sent by this OutputThread to avoid hammering
|
||||||
* the server. Messages are sent immediately if possible. If there are
|
* the server. Messages are sent immediately if possible. If there are
|
||||||
* multiple messages queued, then there is a delay imposed.
|
* multiple messages queued, then there is a delay imposed.
|
||||||
*
|
*
|
||||||
* @param bot The underlying PircBot instance.
|
* @param bot The underlying PircBot instance.
|
||||||
* @param outQueue The Queue from which we will obtain our messages.
|
* @param outQueue The Queue from which we will obtain our messages.
|
||||||
*/
|
*/
|
||||||
OutputThread(PircBot bot, Queue outQueue) {
|
OutputThread(PircBot bot, Queue outQueue) {
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_outQueue = outQueue;
|
_outQueue = outQueue;
|
||||||
this.setName(this.getClass() + "-Thread");
|
this.setName(this.getClass() + "-Thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A static method to write a line to a BufferedOutputStream and then pass
|
* A static method to write a line to a BufferedOutputStream and then pass
|
||||||
* the line to the log method of the supplied PircBot instance.
|
* the line to the log method of the supplied PircBot instance.
|
||||||
*
|
*
|
||||||
* @param bot The underlying PircBot instance.
|
* @param bot The underlying PircBot instance.
|
||||||
* @param out The BufferedOutputStream to write to.
|
* @param out The BufferedOutputStream to write to.
|
||||||
* @param line The line to be written. "\r\n" is appended to the end.
|
* @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
|
* @param encoding The charset to use when encoing this string into a
|
||||||
* byte array.
|
* byte array.
|
||||||
*/
|
*/
|
||||||
static void sendRawLine(PircBot bot, BufferedWriter bwriter, String line) {
|
static void sendRawLine(PircBot bot, BufferedWriter bwriter, String line) {
|
||||||
if (line.length() > bot.getMaxLineLength() - 2) {
|
if (line.length() > bot.getMaxLineLength() - 2) {
|
||||||
line = line.substring(0, bot.getMaxLineLength() - 2);
|
line = line.substring(0, bot.getMaxLineLength() - 2);
|
||||||
}
|
}
|
||||||
synchronized(bwriter) {
|
synchronized(bwriter) {
|
||||||
try {
|
try {
|
||||||
bwriter.write(line + "\r\n");
|
bwriter.write(line + "\r\n");
|
||||||
bwriter.flush();
|
bwriter.flush();
|
||||||
bot.log(">>>" + line);
|
bot.log(">>>" + line);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Silent response - just lose the line.
|
// Silent response - just lose the line.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method starts the Thread consuming from the outgoing message
|
* This method starts the Thread consuming from the outgoing message
|
||||||
* Queue and sending lines to the server.
|
* Queue and sending lines to the server.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
boolean running = true;
|
boolean running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
// Small delay to prevent spamming of the channel
|
// Small delay to prevent spamming of the channel
|
||||||
Thread.sleep(_bot.getMessageDelay());
|
Thread.sleep(_bot.getMessageDelay());
|
||||||
|
|
||||||
String line = (String) _outQueue.next();
|
String line = (String) _outQueue.next();
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
_bot.sendRawLine(line);
|
_bot.sendRawLine(line);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
// Just let the method return naturally...
|
// Just let the method return naturally...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PircBot _bot = null;
|
private PircBot _bot = null;
|
||||||
private Queue _outQueue = null;
|
private Queue _outQueue = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,146 +1,146 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue is a definition of a data structure that may
|
* 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
|
* 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.
|
* queue and data can be requested from the head end of the queue.
|
||||||
* This class is thread safe for multiple producers and a single
|
* This class is thread safe for multiple producers and a single
|
||||||
* consumer. The next() method will block until there is data in
|
* consumer. The next() method will block until there is data in
|
||||||
* the queue.
|
* the queue.
|
||||||
*
|
*
|
||||||
* This has now been modified so that it is compatible with
|
* This has now been modified so that it is compatible with
|
||||||
* the earlier JDK1.1 in order to be suitable for running on
|
* the earlier JDK1.1 in order to be suitable for running on
|
||||||
* mobile appliances. This means replacing the LinkedList with
|
* mobile appliances. This means replacing the LinkedList with
|
||||||
* a Vector, which is hardly ideal, but this Queue is typically
|
* a Vector, which is hardly ideal, but this Queue is typically
|
||||||
* only polled every second before dispatching messages.
|
* only polled every second before dispatching messages.
|
||||||
*
|
*
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class Queue {
|
public class Queue {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a Queue object of unlimited size.
|
* Constructs a Queue object of unlimited size.
|
||||||
*/
|
*/
|
||||||
public Queue() {
|
public Queue() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an Object to the end of the Queue.
|
* Adds an Object to the end of the Queue.
|
||||||
*
|
*
|
||||||
* @param o The Object to be added to the Queue.
|
* @param o The Object to be added to the Queue.
|
||||||
*/
|
*/
|
||||||
public void add(Object o) {
|
public void add(Object o) {
|
||||||
synchronized(_queue) {
|
synchronized(_queue) {
|
||||||
_queue.addElement(o);
|
_queue.addElement(o);
|
||||||
_queue.notify();
|
_queue.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an Object to the front of the Queue.
|
* Adds an Object to the front of the Queue.
|
||||||
*
|
*
|
||||||
* @param o The Object to be added to the Queue.
|
* @param o The Object to be added to the Queue.
|
||||||
*/
|
*/
|
||||||
public void addFront(Object o) {
|
public void addFront(Object o) {
|
||||||
synchronized(_queue) {
|
synchronized(_queue) {
|
||||||
_queue.insertElementAt(o, 0);
|
_queue.insertElementAt(o, 0);
|
||||||
_queue.notify();
|
_queue.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Object at the front of the Queue. This
|
* Returns the Object at the front of the Queue. This
|
||||||
* Object is then removed from the Queue. If the Queue
|
* Object is then removed from the Queue. If the Queue
|
||||||
* is empty, then this method shall block until there
|
* is empty, then this method shall block until there
|
||||||
* is an Object in the Queue to return.
|
* is an Object in the Queue to return.
|
||||||
*
|
*
|
||||||
* @return The next item from the front of the queue.
|
* @return The next item from the front of the queue.
|
||||||
*/
|
*/
|
||||||
public Object next() {
|
public Object next() {
|
||||||
|
|
||||||
Object o = null;
|
Object o = null;
|
||||||
|
|
||||||
// Block if the Queue is empty.
|
// Block if the Queue is empty.
|
||||||
synchronized(_queue) {
|
synchronized(_queue) {
|
||||||
if (_queue.size() == 0) {
|
if (_queue.size() == 0) {
|
||||||
try {
|
try {
|
||||||
_queue.wait();
|
_queue.wait();
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the Object.
|
// Return the Object.
|
||||||
try {
|
try {
|
||||||
o = _queue.firstElement();
|
o = _queue.firstElement();
|
||||||
_queue.removeElementAt(0);
|
_queue.removeElementAt(0);
|
||||||
}
|
}
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
catch (ArrayIndexOutOfBoundsException e) {
|
||||||
throw new InternalError("Race hazard in Queue object.");
|
throw new InternalError("Race hazard in Queue object.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the Queue is not empty. If another
|
* Returns true if the Queue is not empty. If another
|
||||||
* Thread empties the Queue before <b>next()</b> is
|
* Thread empties the Queue before <b>next()</b> is
|
||||||
* called, then the call to <b>next()</b> shall block
|
* called, then the call to <b>next()</b> shall block
|
||||||
* until the Queue has been populated again.
|
* until the Queue has been populated again.
|
||||||
*
|
*
|
||||||
* @return True only if the Queue not empty.
|
* @return True only if the Queue not empty.
|
||||||
*/
|
*/
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return (this.size() != 0);
|
return (this.size() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the contents of the Queue.
|
* Clears the contents of the Queue.
|
||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
synchronized(_queue) {
|
synchronized(_queue) {
|
||||||
_queue.removeAllElements();
|
_queue.removeAllElements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of the Queue.
|
* Returns the size of the Queue.
|
||||||
*
|
*
|
||||||
* @return The current size of the queue.
|
* @return The current size of the queue.
|
||||||
*/
|
*/
|
||||||
public int size() {
|
public int size() {
|
||||||
return _queue.size();
|
return _queue.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Vector<Object> _queue = new Vector<Object>();
|
private Vector<Object> _queue = new Vector<Object>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,176 +1,176 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface contains the values of all numeric replies specified
|
* This interface contains the values of all numeric replies specified
|
||||||
* in section 6 of RFC 1459. Refer to RFC 1459 for further information.
|
* in section 6 of RFC 1459. Refer to RFC 1459 for further information.
|
||||||
* <p>
|
* <p>
|
||||||
* If you override the onServerResponse method in the PircBot class,
|
* If you override the onServerResponse method in the PircBot class,
|
||||||
* you may find these constants useful when comparing the numeric
|
* you may find these constants useful when comparing the numeric
|
||||||
* value of a given code.
|
* value of a given code.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public interface ReplyConstants {
|
public interface ReplyConstants {
|
||||||
|
|
||||||
|
|
||||||
// Error Replies.
|
// Error Replies.
|
||||||
public static final int ERR_NOSUCHNICK = 401;
|
public static final int ERR_NOSUCHNICK = 401;
|
||||||
public static final int ERR_NOSUCHSERVER = 402;
|
public static final int ERR_NOSUCHSERVER = 402;
|
||||||
public static final int ERR_NOSUCHCHANNEL = 403;
|
public static final int ERR_NOSUCHCHANNEL = 403;
|
||||||
public static final int ERR_CANNOTSENDTOCHAN = 404;
|
public static final int ERR_CANNOTSENDTOCHAN = 404;
|
||||||
public static final int ERR_TOOMANYCHANNELS = 405;
|
public static final int ERR_TOOMANYCHANNELS = 405;
|
||||||
public static final int ERR_WASNOSUCHNICK = 406;
|
public static final int ERR_WASNOSUCHNICK = 406;
|
||||||
public static final int ERR_TOOMANYTARGETS = 407;
|
public static final int ERR_TOOMANYTARGETS = 407;
|
||||||
public static final int ERR_NOORIGIN = 409;
|
public static final int ERR_NOORIGIN = 409;
|
||||||
public static final int ERR_NORECIPIENT = 411;
|
public static final int ERR_NORECIPIENT = 411;
|
||||||
public static final int ERR_NOTEXTTOSEND = 412;
|
public static final int ERR_NOTEXTTOSEND = 412;
|
||||||
public static final int ERR_NOTOPLEVEL = 413;
|
public static final int ERR_NOTOPLEVEL = 413;
|
||||||
public static final int ERR_WILDTOPLEVEL = 414;
|
public static final int ERR_WILDTOPLEVEL = 414;
|
||||||
public static final int ERR_UNKNOWNCOMMAND = 421;
|
public static final int ERR_UNKNOWNCOMMAND = 421;
|
||||||
public static final int ERR_NOMOTD = 422;
|
public static final int ERR_NOMOTD = 422;
|
||||||
public static final int ERR_NOADMININFO = 423;
|
public static final int ERR_NOADMININFO = 423;
|
||||||
public static final int ERR_FILEERROR = 424;
|
public static final int ERR_FILEERROR = 424;
|
||||||
public static final int ERR_NONICKNAMEGIVEN = 431;
|
public static final int ERR_NONICKNAMEGIVEN = 431;
|
||||||
public static final int ERR_ERRONEUSNICKNAME = 432;
|
public static final int ERR_ERRONEUSNICKNAME = 432;
|
||||||
public static final int ERR_NICKNAMEINUSE = 433;
|
public static final int ERR_NICKNAMEINUSE = 433;
|
||||||
public static final int ERR_NICKCOLLISION = 436;
|
public static final int ERR_NICKCOLLISION = 436;
|
||||||
public static final int ERR_USERNOTINCHANNEL = 441;
|
public static final int ERR_USERNOTINCHANNEL = 441;
|
||||||
public static final int ERR_NOTONCHANNEL = 442;
|
public static final int ERR_NOTONCHANNEL = 442;
|
||||||
public static final int ERR_USERONCHANNEL = 443;
|
public static final int ERR_USERONCHANNEL = 443;
|
||||||
public static final int ERR_NOLOGIN = 444;
|
public static final int ERR_NOLOGIN = 444;
|
||||||
public static final int ERR_SUMMONDISABLED = 445;
|
public static final int ERR_SUMMONDISABLED = 445;
|
||||||
public static final int ERR_USERSDISABLED = 446;
|
public static final int ERR_USERSDISABLED = 446;
|
||||||
public static final int ERR_NOTREGISTERED = 451;
|
public static final int ERR_NOTREGISTERED = 451;
|
||||||
public static final int ERR_NEEDMOREPARAMS = 461;
|
public static final int ERR_NEEDMOREPARAMS = 461;
|
||||||
public static final int ERR_ALREADYREGISTRED = 462;
|
public static final int ERR_ALREADYREGISTRED = 462;
|
||||||
public static final int ERR_NOPERMFORHOST = 463;
|
public static final int ERR_NOPERMFORHOST = 463;
|
||||||
public static final int ERR_PASSWDMISMATCH = 464;
|
public static final int ERR_PASSWDMISMATCH = 464;
|
||||||
public static final int ERR_YOUREBANNEDCREEP = 465;
|
public static final int ERR_YOUREBANNEDCREEP = 465;
|
||||||
public static final int ERR_KEYSET = 467;
|
public static final int ERR_KEYSET = 467;
|
||||||
public static final int ERR_CHANNELISFULL = 471;
|
public static final int ERR_CHANNELISFULL = 471;
|
||||||
public static final int ERR_UNKNOWNMODE = 472;
|
public static final int ERR_UNKNOWNMODE = 472;
|
||||||
public static final int ERR_INVITEONLYCHAN = 473;
|
public static final int ERR_INVITEONLYCHAN = 473;
|
||||||
public static final int ERR_BANNEDFROMCHAN = 474;
|
public static final int ERR_BANNEDFROMCHAN = 474;
|
||||||
public static final int ERR_BADCHANNELKEY = 475;
|
public static final int ERR_BADCHANNELKEY = 475;
|
||||||
public static final int ERR_NOPRIVILEGES = 481;
|
public static final int ERR_NOPRIVILEGES = 481;
|
||||||
public static final int ERR_CHANOPRIVSNEEDED = 482;
|
public static final int ERR_CHANOPRIVSNEEDED = 482;
|
||||||
public static final int ERR_CANTKILLSERVER = 483;
|
public static final int ERR_CANTKILLSERVER = 483;
|
||||||
public static final int ERR_NOOPERHOST = 491;
|
public static final int ERR_NOOPERHOST = 491;
|
||||||
public static final int ERR_UMODEUNKNOWNFLAG = 501;
|
public static final int ERR_UMODEUNKNOWNFLAG = 501;
|
||||||
public static final int ERR_USERSDONTMATCH = 502;
|
public static final int ERR_USERSDONTMATCH = 502;
|
||||||
|
|
||||||
|
|
||||||
// Command Responses.
|
// Command Responses.
|
||||||
public static final int RPL_TRACELINK = 200;
|
public static final int RPL_TRACELINK = 200;
|
||||||
public static final int RPL_TRACECONNECTING = 201;
|
public static final int RPL_TRACECONNECTING = 201;
|
||||||
public static final int RPL_TRACEHANDSHAKE = 202;
|
public static final int RPL_TRACEHANDSHAKE = 202;
|
||||||
public static final int RPL_TRACEUNKNOWN = 203;
|
public static final int RPL_TRACEUNKNOWN = 203;
|
||||||
public static final int RPL_TRACEOPERATOR = 204;
|
public static final int RPL_TRACEOPERATOR = 204;
|
||||||
public static final int RPL_TRACEUSER = 205;
|
public static final int RPL_TRACEUSER = 205;
|
||||||
public static final int RPL_TRACESERVER = 206;
|
public static final int RPL_TRACESERVER = 206;
|
||||||
public static final int RPL_TRACENEWTYPE = 208;
|
public static final int RPL_TRACENEWTYPE = 208;
|
||||||
public static final int RPL_STATSLINKINFO = 211;
|
public static final int RPL_STATSLINKINFO = 211;
|
||||||
public static final int RPL_STATSCOMMANDS = 212;
|
public static final int RPL_STATSCOMMANDS = 212;
|
||||||
public static final int RPL_STATSCLINE = 213;
|
public static final int RPL_STATSCLINE = 213;
|
||||||
public static final int RPL_STATSNLINE = 214;
|
public static final int RPL_STATSNLINE = 214;
|
||||||
public static final int RPL_STATSILINE = 215;
|
public static final int RPL_STATSILINE = 215;
|
||||||
public static final int RPL_STATSKLINE = 216;
|
public static final int RPL_STATSKLINE = 216;
|
||||||
public static final int RPL_STATSYLINE = 218;
|
public static final int RPL_STATSYLINE = 218;
|
||||||
public static final int RPL_ENDOFSTATS = 219;
|
public static final int RPL_ENDOFSTATS = 219;
|
||||||
public static final int RPL_UMODEIS = 221;
|
public static final int RPL_UMODEIS = 221;
|
||||||
public static final int RPL_STATSLLINE = 241;
|
public static final int RPL_STATSLLINE = 241;
|
||||||
public static final int RPL_STATSUPTIME = 242;
|
public static final int RPL_STATSUPTIME = 242;
|
||||||
public static final int RPL_STATSOLINE = 243;
|
public static final int RPL_STATSOLINE = 243;
|
||||||
public static final int RPL_STATSHLINE = 244;
|
public static final int RPL_STATSHLINE = 244;
|
||||||
public static final int RPL_LUSERCLIENT = 251;
|
public static final int RPL_LUSERCLIENT = 251;
|
||||||
public static final int RPL_LUSEROP = 252;
|
public static final int RPL_LUSEROP = 252;
|
||||||
public static final int RPL_LUSERUNKNOWN = 253;
|
public static final int RPL_LUSERUNKNOWN = 253;
|
||||||
public static final int RPL_LUSERCHANNELS = 254;
|
public static final int RPL_LUSERCHANNELS = 254;
|
||||||
public static final int RPL_LUSERME = 255;
|
public static final int RPL_LUSERME = 255;
|
||||||
public static final int RPL_ADMINME = 256;
|
public static final int RPL_ADMINME = 256;
|
||||||
public static final int RPL_ADMINLOC1 = 257;
|
public static final int RPL_ADMINLOC1 = 257;
|
||||||
public static final int RPL_ADMINLOC2 = 258;
|
public static final int RPL_ADMINLOC2 = 258;
|
||||||
public static final int RPL_ADMINEMAIL = 259;
|
public static final int RPL_ADMINEMAIL = 259;
|
||||||
public static final int RPL_TRACELOG = 261;
|
public static final int RPL_TRACELOG = 261;
|
||||||
public static final int RPL_NONE = 300;
|
public static final int RPL_NONE = 300;
|
||||||
public static final int RPL_AWAY = 301;
|
public static final int RPL_AWAY = 301;
|
||||||
public static final int RPL_USERHOST = 302;
|
public static final int RPL_USERHOST = 302;
|
||||||
public static final int RPL_ISON = 303;
|
public static final int RPL_ISON = 303;
|
||||||
public static final int RPL_UNAWAY = 305;
|
public static final int RPL_UNAWAY = 305;
|
||||||
public static final int RPL_NOWAWAY = 306;
|
public static final int RPL_NOWAWAY = 306;
|
||||||
public static final int RPL_WHOISUSER = 311;
|
public static final int RPL_WHOISUSER = 311;
|
||||||
public static final int RPL_WHOISSERVER = 312;
|
public static final int RPL_WHOISSERVER = 312;
|
||||||
public static final int RPL_WHOISOPERATOR = 313;
|
public static final int RPL_WHOISOPERATOR = 313;
|
||||||
public static final int RPL_WHOWASUSER = 314;
|
public static final int RPL_WHOWASUSER = 314;
|
||||||
public static final int RPL_ENDOFWHO = 315;
|
public static final int RPL_ENDOFWHO = 315;
|
||||||
public static final int RPL_WHOISIDLE = 317;
|
public static final int RPL_WHOISIDLE = 317;
|
||||||
public static final int RPL_ENDOFWHOIS = 318;
|
public static final int RPL_ENDOFWHOIS = 318;
|
||||||
public static final int RPL_WHOISCHANNELS = 319;
|
public static final int RPL_WHOISCHANNELS = 319;
|
||||||
public static final int RPL_LISTSTART = 321;
|
public static final int RPL_LISTSTART = 321;
|
||||||
public static final int RPL_LIST = 322;
|
public static final int RPL_LIST = 322;
|
||||||
public static final int RPL_LISTEND = 323;
|
public static final int RPL_LISTEND = 323;
|
||||||
public static final int RPL_CHANNELMODEIS = 324;
|
public static final int RPL_CHANNELMODEIS = 324;
|
||||||
public static final int RPL_NOTOPIC = 331;
|
public static final int RPL_NOTOPIC = 331;
|
||||||
public static final int RPL_TOPIC = 332;
|
public static final int RPL_TOPIC = 332;
|
||||||
public static final int RPL_TOPICINFO = 333;
|
public static final int RPL_TOPICINFO = 333;
|
||||||
public static final int RPL_INVITING = 341;
|
public static final int RPL_INVITING = 341;
|
||||||
public static final int RPL_SUMMONING = 342;
|
public static final int RPL_SUMMONING = 342;
|
||||||
public static final int RPL_VERSION = 351;
|
public static final int RPL_VERSION = 351;
|
||||||
public static final int RPL_WHOREPLY = 352;
|
public static final int RPL_WHOREPLY = 352;
|
||||||
public static final int RPL_NAMREPLY = 353;
|
public static final int RPL_NAMREPLY = 353;
|
||||||
public static final int RPL_LINKS = 364;
|
public static final int RPL_LINKS = 364;
|
||||||
public static final int RPL_ENDOFLINKS = 365;
|
public static final int RPL_ENDOFLINKS = 365;
|
||||||
public static final int RPL_ENDOFNAMES = 366;
|
public static final int RPL_ENDOFNAMES = 366;
|
||||||
public static final int RPL_BANLIST = 367;
|
public static final int RPL_BANLIST = 367;
|
||||||
public static final int RPL_ENDOFBANLIST = 368;
|
public static final int RPL_ENDOFBANLIST = 368;
|
||||||
public static final int RPL_ENDOFWHOWAS = 369;
|
public static final int RPL_ENDOFWHOWAS = 369;
|
||||||
public static final int RPL_INFO = 371;
|
public static final int RPL_INFO = 371;
|
||||||
public static final int RPL_MOTD = 372;
|
public static final int RPL_MOTD = 372;
|
||||||
public static final int RPL_ENDOFINFO = 374;
|
public static final int RPL_ENDOFINFO = 374;
|
||||||
public static final int RPL_MOTDSTART = 375;
|
public static final int RPL_MOTDSTART = 375;
|
||||||
public static final int RPL_ENDOFMOTD = 376;
|
public static final int RPL_ENDOFMOTD = 376;
|
||||||
public static final int RPL_YOUREOPER = 381;
|
public static final int RPL_YOUREOPER = 381;
|
||||||
public static final int RPL_REHASHING = 382;
|
public static final int RPL_REHASHING = 382;
|
||||||
public static final int RPL_TIME = 391;
|
public static final int RPL_TIME = 391;
|
||||||
public static final int RPL_USERSSTART = 392;
|
public static final int RPL_USERSSTART = 392;
|
||||||
public static final int RPL_USERS = 393;
|
public static final int RPL_USERS = 393;
|
||||||
public static final int RPL_ENDOFUSERS = 394;
|
public static final int RPL_ENDOFUSERS = 394;
|
||||||
public static final int RPL_NOUSERS = 395;
|
public static final int RPL_NOUSERS = 395;
|
||||||
|
|
||||||
|
|
||||||
// Reserved Numerics.
|
// Reserved Numerics.
|
||||||
public static final int RPL_TRACECLASS = 209;
|
public static final int RPL_TRACECLASS = 209;
|
||||||
public static final int RPL_STATSQLINE = 217;
|
public static final int RPL_STATSQLINE = 217;
|
||||||
public static final int RPL_SERVICEINFO = 231;
|
public static final int RPL_SERVICEINFO = 231;
|
||||||
public static final int RPL_ENDOFSERVICES = 232;
|
public static final int RPL_ENDOFSERVICES = 232;
|
||||||
public static final int RPL_SERVICE = 233;
|
public static final int RPL_SERVICE = 233;
|
||||||
public static final int RPL_SERVLIST = 234;
|
public static final int RPL_SERVLIST = 234;
|
||||||
public static final int RPL_SERVLISTEND = 235;
|
public static final int RPL_SERVLISTEND = 235;
|
||||||
public static final int RPL_WHOISCHANOP = 316;
|
public static final int RPL_WHOISCHANOP = 316;
|
||||||
public static final int RPL_KILLDONE = 361;
|
public static final int RPL_KILLDONE = 361;
|
||||||
public static final int RPL_CLOSING = 362;
|
public static final int RPL_CLOSING = 362;
|
||||||
public static final int RPL_CLOSEEND = 363;
|
public static final int RPL_CLOSEEND = 363;
|
||||||
public static final int RPL_INFOSTART = 373;
|
public static final int RPL_INFOSTART = 373;
|
||||||
public static final int RPL_MYPORTIS = 384;
|
public static final int RPL_MYPORTIS = 384;
|
||||||
public static final int ERR_YOUWILLBEBANNED = 466;
|
public static final int ERR_YOUWILLBEBANNED = 466;
|
||||||
public static final int ERR_BADCHANMASK = 476;
|
public static final int ERR_BADCHANMASK = 476;
|
||||||
public static final int ERR_NOSERVICEHOST = 492;
|
public static final int ERR_NOSERVICEHOST = 492;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,161 +1,161 @@
|
|||||||
/*
|
/*
|
||||||
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
Copyright Paul James Mutton, 2001-2007, http://www.jibble.org/
|
||||||
|
|
||||||
This file is part of PircBot.
|
This file is part of PircBot.
|
||||||
|
|
||||||
This software is dual-licensed, allowing you to choose between the GNU
|
This software is dual-licensed, allowing you to choose between the GNU
|
||||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||||
Since the GPL may be too restrictive for use in a proprietary application,
|
Since the GPL may be too restrictive for use in a proprietary application,
|
||||||
a commercial license is also provided. Full license information can be
|
a commercial license is also provided. Full license information can be
|
||||||
found at http://www.jibble.org/licenses/
|
found at http://www.jibble.org/licenses/
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jibble.pircbot;
|
package org.jibble.pircbot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to represent a user on an IRC server.
|
* This class is used to represent a user on an IRC server.
|
||||||
* Instances of this class are returned by the getUsers method
|
* Instances of this class are returned by the getUsers method
|
||||||
* in the PircBot class.
|
* in the PircBot class.
|
||||||
* <p>
|
* <p>
|
||||||
* Note that this class no longer implements the Comparable interface
|
* Note that this class no longer implements the Comparable interface
|
||||||
* for Java 1.1 compatibility reasons.
|
* for Java 1.1 compatibility reasons.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Paul James Mutton,
|
* @author Paul James Mutton,
|
||||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||||
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
* @version 1.4.6 (Build time: Wed Apr 11 19:20:59 2007)
|
||||||
*/
|
*/
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a User object with a known prefix and nick.
|
* Constructs a User object with a known prefix and nick.
|
||||||
*
|
*
|
||||||
* @param prefix The status of the user, for example, "@".
|
* @param prefix The status of the user, for example, "@".
|
||||||
* @param nick The nick of the user.
|
* @param nick The nick of the user.
|
||||||
*/
|
*/
|
||||||
User(String prefix, String nick) {
|
User(String prefix, String nick) {
|
||||||
_prefix = prefix;
|
_prefix = prefix;
|
||||||
_nick = nick;
|
_nick = nick;
|
||||||
_lowerNick = nick.toLowerCase();
|
_lowerNick = nick.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the prefix of the user. If the User object has been obtained
|
* 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
|
* from a list of users in a channel, then this will reflect the user's
|
||||||
* status in that channel.
|
* status in that channel.
|
||||||
*
|
*
|
||||||
* @return The prefix of the user. If there is no prefix, then an empty
|
* @return The prefix of the user. If there is no prefix, then an empty
|
||||||
* String is returned.
|
* String is returned.
|
||||||
*/
|
*/
|
||||||
public String getPrefix() {
|
public String getPrefix() {
|
||||||
return _prefix;
|
return _prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the user represented by this object is an
|
* 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
|
* 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
|
* in a channel, then this will reflect the user's operator status in
|
||||||
* that channel.
|
* that channel.
|
||||||
*
|
*
|
||||||
* @return true if the user is an operator in the channel.
|
* @return true if the user is an operator in the channel.
|
||||||
*/
|
*/
|
||||||
public boolean isOp() {
|
public boolean isOp() {
|
||||||
return _prefix.indexOf('@') >= 0;
|
return _prefix.indexOf('@') >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the user represented by this object has
|
* Returns whether or not the user represented by this object has
|
||||||
* voice. If the User object has been obtained from a list of users
|
* 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
|
* in a channel, then this will reflect the user's voice status in
|
||||||
* that channel.
|
* that channel.
|
||||||
*
|
*
|
||||||
* @return true if the user has voice in the channel.
|
* @return true if the user has voice in the channel.
|
||||||
*/
|
*/
|
||||||
public boolean hasVoice() {
|
public boolean hasVoice() {
|
||||||
return _prefix.indexOf('+') >= 0;
|
return _prefix.indexOf('+') >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the nick of the user.
|
* Returns the nick of the user.
|
||||||
*
|
*
|
||||||
* @return The user's nick.
|
* @return The user's nick.
|
||||||
*/
|
*/
|
||||||
public String getNick() {
|
public String getNick() {
|
||||||
return _nick;
|
return _nick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the nick of the user complete with their prefix if they
|
* Returns the nick of the user complete with their prefix if they
|
||||||
* have one, e.g. "@Dave".
|
* have one, e.g. "@Dave".
|
||||||
*
|
*
|
||||||
* @return The user's prefix and nick.
|
* @return The user's prefix and nick.
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.getPrefix() + this.getNick();
|
return this.getPrefix() + this.getNick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the nick represented by this User object is the same
|
* Returns true if the nick represented by this User object is the same
|
||||||
* as the argument. A case insensitive comparison is made.
|
* as the argument. A case insensitive comparison is made.
|
||||||
*
|
*
|
||||||
* @return true if the nicks are identical (case insensitive).
|
* @return true if the nicks are identical (case insensitive).
|
||||||
*/
|
*/
|
||||||
public boolean equals(String nick) {
|
public boolean equals(String nick) {
|
||||||
return nick.toLowerCase().equals(_lowerNick);
|
return nick.toLowerCase().equals(_lowerNick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the nick represented by this User object is the same
|
* Returns true if the nick represented by this User object is the same
|
||||||
* as the nick of the User object given as an argument.
|
* as the nick of the User object given as an argument.
|
||||||
* A case insensitive comparison is made.
|
* A case insensitive comparison is made.
|
||||||
*
|
*
|
||||||
* @return true if o is a User object with a matching lowercase nick.
|
* @return true if o is a User object with a matching lowercase nick.
|
||||||
*/
|
*/
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof User) {
|
if (o instanceof User) {
|
||||||
User other = (User) o;
|
User other = (User) o;
|
||||||
return other._lowerNick.equals(_lowerNick);
|
return other._lowerNick.equals(_lowerNick);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hash code of this User object.
|
* Returns the hash code of this User object.
|
||||||
*
|
*
|
||||||
* @return the hash code of the User object.
|
* @return the hash code of the User object.
|
||||||
*/
|
*/
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return _lowerNick.hashCode();
|
return _lowerNick.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the result of calling the compareTo method on lowercased
|
* Returns the result of calling the compareTo method on lowercased
|
||||||
* nicks. This is useful for sorting lists of User objects.
|
* nicks. This is useful for sorting lists of User objects.
|
||||||
*
|
*
|
||||||
* @return the result of calling compareTo on lowercased nicks.
|
* @return the result of calling compareTo on lowercased nicks.
|
||||||
*/
|
*/
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Object o) {
|
||||||
if (o instanceof User) {
|
if (o instanceof User) {
|
||||||
User other = (User) o;
|
User other = (User) o;
|
||||||
return other._lowerNick.compareTo(_lowerNick);
|
return other._lowerNick.compareTo(_lowerNick);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String _prefix;
|
private String _prefix;
|
||||||
private String _nick;
|
private String _nick;
|
||||||
private String _lowerNick;
|
private String _lowerNick;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public abstract class BaseHandler
|
public abstract class BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc;
|
||||||
/**
|
/**
|
||||||
* Execute the command
|
* Execute the command
|
||||||
*
|
*
|
||||||
@ -50,6 +51,13 @@ public abstract class BaseHandler
|
|||||||
*/
|
*/
|
||||||
public abstract String getUsage();
|
public abstract String getUsage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the description for this command
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String getDescription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge params to a string
|
* Merge params to a string
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,7 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package org.yaaic.command;
|
package org.yaaic.command;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import android.content.Intent;
|
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.DeopHandler;
|
||||||
import org.yaaic.command.handler.DevoiceHandler;
|
import org.yaaic.command.handler.DevoiceHandler;
|
||||||
import org.yaaic.command.handler.EchoHandler;
|
import org.yaaic.command.handler.EchoHandler;
|
||||||
|
import org.yaaic.command.handler.HelpHandler;
|
||||||
import org.yaaic.command.handler.JoinHandler;
|
import org.yaaic.command.handler.JoinHandler;
|
||||||
import org.yaaic.command.handler.KickHandler;
|
import org.yaaic.command.handler.KickHandler;
|
||||||
import org.yaaic.command.handler.MeHandler;
|
import org.yaaic.command.handler.MeHandler;
|
||||||
@ -95,6 +97,7 @@ public class CommandParser
|
|||||||
commands.put("notice", new NoticeHandler());
|
commands.put("notice", new NoticeHandler());
|
||||||
commands.put("dcc", new DCCHandler());
|
commands.put("dcc", new DCCHandler());
|
||||||
commands.put("mode", new ModeHandler());
|
commands.put("mode", new ModeHandler());
|
||||||
|
commands.put("help", new HelpHandler());
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
commands.put("j", commands.get("join"));
|
commands.put("j", commands.get("join"));
|
||||||
@ -115,6 +118,16 @@ public class CommandParser
|
|||||||
return instance;
|
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?
|
* Is the given command a valid client command?
|
||||||
*
|
*
|
||||||
|
@ -38,6 +38,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class CloseHandler extends BaseHandler
|
public class CloseHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc ="Closes the current window";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /close
|
* Execute /close
|
||||||
*/
|
*/
|
||||||
@ -73,4 +75,12 @@ public class CloseHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/close";
|
return "/close";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /close
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class DCCHandler extends BaseHandler
|
public class DCCHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "Send a file to a user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /dcc
|
* Execute /dcc
|
||||||
*/
|
*/
|
||||||
@ -76,4 +78,13 @@ public class DCCHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/dcc SEND <nickname> <file>";
|
return "/dcc SEND <nickname> <file>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /dcc
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class DeopHandler extends BaseHandler
|
public class DeopHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
/**
|
/**
|
||||||
* Execute /voice
|
* Execute /voice
|
||||||
*/
|
*/
|
||||||
@ -58,4 +59,13 @@ public class DeopHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/voice <nickname>";
|
return "/voice <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /voice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class DevoiceHandler extends BaseHandler
|
public class DevoiceHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
/**
|
/**
|
||||||
* Execute /devoice
|
* Execute /devoice
|
||||||
*/
|
*/
|
||||||
@ -58,4 +59,13 @@ public class DevoiceHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/devoice <nickname>";
|
return "/devoice <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /devoice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class EchoHandler extends BaseHandler
|
public class EchoHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
/**
|
/**
|
||||||
* Execute /echo
|
* Execute /echo
|
||||||
*/
|
*/
|
||||||
@ -66,4 +67,13 @@ public class EchoHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/echo <text>";
|
return "/echo <text>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /echo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
75
src/org/yaaic/command/handler/HelpHandler.java
Normal file
75
src/org/yaaic/command/handler/HelpHandler.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,6 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class JoinHandler extends BaseHandler
|
public class JoinHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "join a channel";
|
||||||
/**
|
/**
|
||||||
* Execute /join
|
* Execute /join
|
||||||
*/
|
*/
|
||||||
@ -56,4 +57,12 @@ public class JoinHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/join <channel> [<key>]";
|
return "/join <channel> [<key>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /join
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class KickHandler extends BaseHandler
|
public class KickHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "kicks a user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /kick
|
* Execute /kick
|
||||||
*/
|
*/
|
||||||
@ -60,4 +62,12 @@ public class KickHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/kick <nickname>";
|
return "/kick <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /kick
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class MeHandler extends BaseHandler
|
public class MeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /me
|
* Execute /me
|
||||||
*/
|
*/
|
||||||
@ -77,4 +79,9 @@ public class MeHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/me <text>";
|
return "/me <text>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class ModeHandler extends BaseHandler
|
public class ModeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /mode
|
* Execute /mode
|
||||||
*/
|
*/
|
||||||
@ -58,4 +60,9 @@ public class ModeHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/mode <channel> <mode>";
|
return "/mode <channel> <mode>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class NamesHandler extends BaseHandler
|
public class NamesHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "lists all users in channel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /names
|
* Execute /names
|
||||||
*/
|
*/
|
||||||
@ -76,4 +78,13 @@ public class NamesHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/names";
|
return "/names";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /names
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class NickHandler extends BaseHandler
|
public class NickHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "change own nickname";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /nick
|
* Execute /nick
|
||||||
*/
|
*/
|
||||||
@ -54,4 +56,13 @@ public class NickHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/nick <nickname>";
|
return "/nick <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /nick
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class NoticeHandler extends BaseHandler
|
public class NoticeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "Send a notice to an other user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /notice
|
* Execute /notice
|
||||||
*/
|
*/
|
||||||
@ -74,4 +76,13 @@ public class NoticeHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/notice <nickname> <message>";
|
return "/notice <nickname> <message>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /notice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class OpHandler extends BaseHandler
|
public class OpHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /deop
|
* Execute /deop
|
||||||
*/
|
*/
|
||||||
@ -58,4 +60,13 @@ public class OpHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/op <nickname>";
|
return "/op <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /deop
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class PartHandler extends BaseHandler
|
public class PartHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "leave the current channel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /part
|
* Execute /part
|
||||||
*/
|
*/
|
||||||
@ -62,4 +64,9 @@ public class PartHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/part [<channel>]";
|
return "/part [<channel>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class QueryHandler extends BaseHandler
|
public class QueryHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "opens a private chat with a user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /query
|
* Execute /query
|
||||||
*/
|
*/
|
||||||
@ -78,4 +80,9 @@ public class QueryHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/query <nickname>";
|
return "/query <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class QuitHandler extends BaseHandler
|
public class QuitHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "leave current channel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /quit
|
* Execute /quit
|
||||||
*/
|
*/
|
||||||
@ -54,4 +56,13 @@ public class QuitHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/quit [<reason>]";
|
return "/quit [<reason>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /quit
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class TopicHandler extends BaseHandler
|
public class TopicHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "show or change the current topic";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /topic
|
* Execute /topic
|
||||||
*/
|
*/
|
||||||
@ -65,4 +67,13 @@ public class TopicHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/topic [<topic>]";
|
return "/topic [<topic>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /topic
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class VoiceHandler extends BaseHandler
|
public class VoiceHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /voice
|
* Execute /voice
|
||||||
*/
|
*/
|
||||||
@ -58,4 +60,13 @@ public class VoiceHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/voice <nickname>";
|
return "/voice <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /voice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user