hi, recently I started making an irc bot in Java. I was testing it out on my friend's server and everything seemed to be working, it was reading from the server, and was responding to the
one command. I wanted to show it to my other friend so I changed the variables to match his irc server, and the bot couldn't connect. I was wondering if the problem was in my friend's server or in my code. (I'll include what the server sends when I connect at the bottom)
package ircbot;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class bot {
public static String message;
/* variables */
Socket sock;
OutputStream out;
BufferedWriter writer;
InputStream in;
BufferedReader reader;
static doaction action = new doaction();
String nick = "Gary";
String user = "account 8 * :oHai";
public static String channel = "#malvager";
String ip = "127.0.0.1"; // <-- not the actual ip...
int port = 11235;
/* end variable and object declarations */
public static void main(String[] args) {
bot superbot = new bot();
superbot.connect();
}
public void connect() {
try {
sock = new Socket(ip, port);
out = sock.getOutputStream();
writer = new BufferedWriter(new OutputStreamWriter(out));
in = sock.getInputStream();
reader = new BufferedReader(new InputStreamReader(in));
join(nick, channel, user, writer, reader);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException i) {
i.printStackTrace();
}// end try/catch
}
public static void join(String nick, String channel, String user, BufferedWriter writer, BufferedReader reader) {
try {
writer.write("NICK " + nick);
System.out.println("set nick");
writer.newLine();
writer.flush();
System.out.println(reader.readLine());
writer.write("USER " + user);
System.out.println("set user");
writer.newLine();
writer.flush();
System.out.println(reader.readLine());
writer.write("JOIN " + channel);
System.out.println("joined channel");
writer.newLine();
writer.flush();
System.out.println(reader.readLine());
read(reader, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void read(BufferedReader reader, BufferedWriter writer) {
String said;
while(1 == 1) {
try {
said = reader.readLine();
System.out.println(said);
if (check(said) == true) {
print(writer);
}
} catch (IOException f) {
f.printStackTrace();
}
}
}
public static boolean check(String input) {
message = action.setinput(input);
if (message.equals("I'm awesome")) {
return(true);
} else {
return(false);
}
}
public static void print(BufferedWriter writer) {
Scanner input = new Scanner(System.in);
try {
writer.write("PRIVMSG " + channel + " " + message);
writer.newLine();
writer.flush();
} catch(IOException r) {
r.printStackTrace();
}
}
}// end class
package ircbot;
import java.lang.String;
public class doaction {
public String setinput(String input) {
int length = input.length();
int control;
String message = input;
control = length - 5;
message = message.substring(control, length);
if (message.equals("!Gary")) {
message = "I'm awesome";
return(message);
} else {
message = input;
return("bad");
}
}
}
When I connect to my second friend's server (the one that doesn't work) I get:
set nick
:lolnepp.no-ip.biz NOTICE AUTH :*** Looking up your hostname...
set user
:lolnepp.no-ip.biz NOTICE AUTH :*** Found your hostname (cached)
joined channel
PING :51AA6A7F
:lolnepp.no-ip.biz 451 JOIN :You have not registered
When I connect to the friend's server that works I get:
set nick
:Malvager.hub NOTICE AUTH :*** Looking up your hostname...
set user
:Malvager.hub NOTICE AUTH :*** Found your hostname
joined channel
:Malvager.hub 001 Gary :Welcome to the Malvager-IRC-Network IRC Network Gary!account@bas1-toronto04-1176175999.dsl.bell.ca
:Malvager.hub 002 Gary :Your host is Malvager.hub, running version Unreal3.2.7
:Malvager.hub 003 Gary :This server was created Sun Oct 26 2008 at 00:01:26 PDT
:Malvager.hub 004 Gary Malvager.hub Unreal3.2.7 iowghraAsORTVSxNCWqBzvdHtGp
Okay yea, can anyoen tell me if the problem is in my code or the server? And if the problem is in the code could you please tell me what to change or point me in the right directin? thanks.