rendered paste bodyimport java.io.*;
import java.net.*;
public class Jirk {
/* public static class jconfig {
//FileInputStream jirkconfig = new FileInputStream(file); //jirkconfig.read();
//vars
String server = "irc.battlenet.net";
String port = "6667";
String nick = "JIRK";
String user = "JIRK";
String channel = "#dump";
}*/
private static class IdentServer implements Runnable {
private String user = null;
public void run() {
this.user = user;
try {
ident();
}catch (IOException e) {
System.out.println("hi - " + e);
}
}
public void ident(String user) throws IOException{
//try {
ServerSocket servsock = new ServerSocket(113);
Socket asock = servsock.accept();
BufferedReader identreader = new BufferedReader(new InputStreamReader(asock.getInputStream()));
BufferedWriter identwriter = new BufferedWriter(new OutputStreamWriter(asock.getOutputStream()));
String line = identreader.readLine();
System.out.println("Ident server running.");
if(line!=null) {
System.out.println(line);
line = line + " : USERID : UNIX : " + user;
identwriter.write(line + "\r\n");
identwriter.flush();
}
identwriter.close();
servsock.close();
/*}catch (InterruptedException e) {
System.out.println("Ident server aborted!");
}*/
}
}
public static void main(String[] args) throws IOException {
//vars
String server = "irc.battlefoundry.net";
String port = "6667";
String nick = "JIRK";
String user = "JIRK";
String channel = "#dump";
//start ident
Thread ident = new Thread(new IdentServer());
ident.start();
//socket
Socket sock = new Socket(server, 6667);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
//login
writer.write("NICK" + nick + "\r\n");
writer.write("USER" + user + " 0 * :Jirkle\r\n");
//ident(user);
writer.flush();
//read from server until connect
String line = null;
while((line = reader.readLine()) != null) {
if(line.startsWith("PING")) {
//respond to PING with PONG
writer.write("PONG" + line.substring(5) + "\r\n");
System.out.println("Recieved PING.");
writer.flush();
}else if(line.indexOf("004") >= 0) {
//loged in
System.out.println("Logged in.");
break;
}else if(line.indexOf("433") >= 0) {
System.out.println("Nick is already in use.");
return;
}else{
System.out.println(line);
}
}
//join channel
writer.write("JOIN" + channel + "\r\n");
writer.flush();
//loop
while((line = reader.readLine()) != null) {
if(line.startsWith("PING")) {
//respond to PING with PONG
writer.write("PONG" + line.substring(5) + "\r\n");
System.out.println("Recieved PING.");
writer.flush();
}else{
System.out.println(line);
}
}
}
}