rendered paste body// Imports
import java.net.Socket;
import java.net.ServerSocket;
import java.io.*;
import java.io.Reader;
import java.io.Writer;
// Thread to respond to pings
class PingPlatesFaggotNetwork extends Thread
{
private Socket listeningSocket = null;
private DataOutputStream listeningOutbound = null;
private DataInputStream listeningInbound = null;
public PingPlatesFaggotNetwork(Socket _incomingFaggotSocket)
{
try
{
while (true)
{
// Get socket handle
listeningSocket = _incomingFaggotSocket;
// Acquire the input and output streams for listening socket
listeningInbound = new DataInputStream(listeningSocket.getInputStream());
String responseLine;
while ((responseLine = listeningInbound.readLine()) != null)
{
// Display each line to the console
System.out.println(responseLine);
if (responseLine.indexOf("PING") > -1)
break;
}
sendListenerData("PONG " + responseLine.substring(responseLine.indexOf(":")));
// Clean up
listeningInbound.close();
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
// Send the listening server data
private void sendListenerData(String _message)
{
try
{
listeningOutbound.writeBytes(_message + "\n");
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
//Thread to send messages
class PlatesFaggotNetworkServerThreadToSendMessages extends Thread implements Runnable
{
private Socket listeningSocket = null;
private DataOutputStream listeningOutbound = null;
private DataInputStream listeningInbound = null;
private DataOutputStream incomingOutbound = null;
private DataInputStream incomingInbound = null;
private String channel = null;
private Socket incomingFaggotSocket = null;
public PlatesFaggotNetworkServerThreadToSendMessages(Socket _incomingFaggotSocket, String _channel)
{
try
{
channel = _channel;
incomingFaggotSocket = _incomingFaggotSocket;
// Get socket handle
listeningSocket = _incomingFaggotSocket;
// Incoming socket declaration
Socket incomingSocket = null;
// Acquire the input and output streams for listening socket
listeningOutbound = new DataOutputStream(listeningSocket.getOutputStream());
listeningInbound = new DataInputStream(listeningSocket.getInputStream());
// Server sockets
ServerSocket serverSocket = new ServerSocket(8080);
while((incomingSocket = serverSocket.accept()) != null)
{
Thread multiThread = new Thread(new PlatesFaggotNetworkServerThreadToSendMessages(_channel, incomingSocket, listeningOutbound));
multiThread.start();
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
public PlatesFaggotNetworkServerThreadToSendMessages(String _channel, Socket _incomingFaggotSocket, DataOutputStream _listeningOutbound)
{
channel = _channel;
incomingFaggotSocket = _incomingFaggotSocket;
try
{
// Acquire the input and output streams for incoming socket
incomingOutbound = new DataOutputStream(incomingFaggotSocket.getOutputStream());
incomingInbound = new DataInputStream(incomingFaggotSocket.getInputStream());
listeningOutbound = _listeningOutbound;
String responseLine;
while ((responseLine = incomingInbound.readLine()) != null)
{
// Display each line to the console
System.out.println(responseLine);
if (responseLine.indexOf("SENDMSG") > -1)
break;
}
// Send message
sendMessage(responseLine.substring(7));
// Cleanup
incomingFaggotSocket.close();
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
System.exit(1);
}
}
// Send a message to the server from a particular port
public void sendMessage(String _message)
{
try
{
sendListenerData("PRIVMSG " + channel + " " + _message);
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
// Send the listening server data
private void sendListenerData(String _message)
{
try
{
listeningOutbound.writeBytes(_message + "\n");
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
// This program will open
public class LulzBot
{
// Basic connection data
private String listeningServer = null;
private int listeningPort = 0;
private String receivingServer = null;
private int receivingPort = 0;
// Sockets
private Socket listeningSocket = null;
private Socket receivingSocket = null;
// Data streams
private BufferedWriter listeningOutbound = null;
private BufferedReader listeningInbound = null;
private BufferedWriter receivingOutbound = null;
private BufferedReader receivingInbound = null;
// Fake user data
private String fakeUserName = null;
private String fakeRealName = null;
private String fakeHostName = null;
private String fakeChatName = null;
private String fakeChannel = null;
// Real user data
private String realUserName = null;
private String realRealName = null;
private String realHostName = null;
private String realChatName = null;
private String realChannel = null;
// Default constructor
public LulzBot(String _listeningServer, int _listeningPort, String _receivingServer, int _receivingPort)
{
listeningServer = _listeningServer;
listeningPort = _listeningPort;
receivingServer = _receivingServer;
receivingPort = _receivingPort;
}
// Go function!
private void go()
{
try
{
// Make connection to IRC server
receivingSocket = new Socket(receivingServer, receivingPort);
listeningSocket = new Socket(listeningServer, listeningPort);
// Acquire the input and output streams for listening socket
listeningOutbound = new BufferedWriter(new OutputStreamWriter(listeningSocket.getOutputStream()));
listeningInbound = new BufferedReader(new InputStreamReader(listeningSocket.getInputStream()));
// Acquire the input and output streams for receiving socket
// receivingOutbound = new BufferedWriter(new OutputStreamWriter(receivingSocket.getOutputStream()));
// receivingInbound = new BufferedReader(new InputStreamReader(receivingSocket.getInputStream()));
// Read the server response
String responseLine = "";
while ((responseLine = listeningInbound.readLine()) != null)
{
System.out.println(responseLine);
// Break out if hostname is found
if (responseLine.indexOf("Found your hostname") > -1 ||
responseLine.indexOf("No ident response") > -1 ||
responseLine.indexOf("using your IP address instead") > -1)
break;
}
// Send listener user information
sendListenerData("NICK " + fakeUserName);
/*while ((responseLine = listeningInbound.readLine()) != null)
{
// Display each line to the console
System.out.println(responseLine);
if (responseLine.indexOf("PING") > -1)
break;
}
sendListenerData("PONG " + responseLine.substring(responseLine.indexOf(":")));
*/
// Run thread to monitor pings
// PingPlatesFaggotNetwork ppfnLst = new PingPlatesFaggotNetwork(listeningSocket);
// ppfnLst.run();
sendListenerData("USER " + fakeUserName + " " + fakeHostName + " " + fakeChatName + " " + fakeRealName);
sendListenerData("JOIN " + fakeChannel);
// Success
System.out.println("Connected to listening server.");
// Loop until server is finished
/* while (true)
{
if (receivingInbound.ready())
responseLine = receivingInbound.readLine();
// Break out if hostname is found
if (responseLine.indexOf("No ident response") > -1 || responseLine.indexOf("using your IP address instead") > -1)
break;
}
System.out.println("Got here");
// Send receiver user information
sendReceiverData("NICK " + realUserName);
// Run thread to monitor pings
PingPlatesFaggotNetwork ppfnRecv = new PingPlatesFaggotNetwork(receivingSocket);
ppfnRecv.run();
sendReceiverData("USER " + realUserName + " " + realHostName + " " + realChatName + " " + realRealName);
sendReceiverData("JOIN " + realChannel);
// Run thread to monitor send traffic
PlatesFaggotNetworkServerThreadToSendMessages pfnsttsm = new PlatesFaggotNetworkServerThreadToSendMessages(listeningSocket, fakeChannel);
pfnsttsm.run();
*/
// Get all messages
while ((responseLine = listeningInbound.readLine()) != null)
{
// Display each line to the console
if (responseLine.indexOf("PRIVMSG") > -1)
{
// Set nick boundaries
int nickBegin = responseLine.indexOf(":");
int nickEnd = responseLine.indexOf("!");
// Set message boundaries
int msgBegin = responseLine.indexOf(":", nickEnd);
int msgEnd = responseLine.length();
// Extract actual values
String nick = responseLine.substring(nickBegin+1, nickEnd);
String msg = responseLine.substring(msgBegin+1, msgEnd);
// Display message
String outMessage = "<" + nick + ">\t" + msg;
sendReceiverData("PRIVMSG " + realChannel + " " + outMessage);
System.out.println(outMessage);
}
}
// Clean up
listeningOutbound.close();
listeningInbound.close();
listeningSocket.close();
receivingOutbound.close();
receivingInbound.close();
receivingSocket.close();
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
// Send the listening server data
private void sendListenerData(String _message)
{
try
{
listeningOutbound.write(_message + "\n");
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
// Send the receiving server data
private void sendReceiverData(String _message)
{
try
{
receivingOutbound.write(_message + "\n");
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
}
}
// Set fake user data
private void setFakeUserInfo(String _nick, String _host, String _chat, String _realName, String _channel)
{
fakeUserName = _nick;
fakeRealName = _realName;
fakeHostName = _host;
fakeChatName = _chat;
fakeChannel = _channel;
}
// Set real user data
private void setRealUserInfo(String _nick, String _host, String _chat, String _realName, String _channel)
{
realUserName = _nick;
realRealName = _realName;
realHostName = _host;
realChatName = _chat;
realChannel = _channel;
}
// Instantiate the program
public static void main(String[] args)
{
// Fake IRC Real IRC
LulzBot lulz = new LulzBot("irc.hobolooter.com", 6667, "irc.hobolooter.com", 6667);
lulz.setFakeUserInfo("hobolooter|mobile", "hobo", "Chat", "Goober Mc. Noobster", "#chat");
lulz.setRealUserInfo("LulzBot3", "Lulz", "LulzChat", "Mr. Purdue", "#olderchat");
lulz.go();
}
}