1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2025-02-18 07:50:10 -05:00

Removed damned windows carriage returns (\r)

This commit is contained in:
Sebastian Kaspari 2010-04-14 21:41:55 +02:00
parent 648ffc8eda
commit 59674e25d1
4 changed files with 3432 additions and 3432 deletions

View File

@ -1,112 +1,112 @@
/* /*
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(String login) { IdentServer(String login) {
_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) {
return; return;
} }
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) {
line = line + " : USERID : UNIX : " + _login; line = line + " : USERID : UNIX : " + _login;
writer.write(line + "\r\n"); writer.write(line + "\r\n");
writer.flush(); writer.flush();
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...
} }
} }
private String _login; private String _login;
private ServerSocket _ss = null; private ServerSocket _ss = null;
} }

View File

@ -1,156 +1,156 @@
/* /*
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.*;
/** /**
* 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();
} }
} }
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) {
_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;
} }

View File

@ -1,103 +1,103 @@
/* /*
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();
} }
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