Created
June 22, 2011 02:03
-
-
Save anonymous/1039375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ircbotgui; | |
import java.io.*; | |
import java.net.*; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* @author Malte Schuetze aka Boreeas | |
*/ | |
public class BaseBot extends Thread { | |
public boolean noPass = true; | |
public String server, nick, password, lastReceived; | |
public int port = 0; | |
public String[] oper, voice, channels; | |
public int opIndex = 0, vIndex = 0, chanIndex = 0; | |
public BufferedReader reader; | |
public BufferedWriter writer; | |
public Socket socket; | |
private GUI gui = Instances.getGuiInstance(); | |
public void connect(String server, int port, String nick, String pass) { | |
try { | |
socket = new Socket(server, port); | |
this.nick = nick; | |
this.password = pass; | |
this.noPass = false; | |
run(); | |
} catch (UnknownHostException ex) { | |
} catch (IOException ex) { | |
Logger.getLogger(BaseBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
public void connect(String server, int port, String nick, boolean noPass) { | |
try { | |
socket = new Socket(server, port); | |
this.nick = nick; | |
this.noPass = noPass; | |
run(); | |
} catch (UnknownHostException ex) { | |
} catch (IOException ex) { | |
Logger.getLogger(BaseBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
public void connect(String server, int port) { | |
try { | |
socket = new Socket(server, port); | |
run(); | |
} catch (UnknownHostException ex) { | |
} catch (IOException ex) { | |
Logger.getLogger(BaseBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
public void connect() { | |
try { | |
socket = new Socket(server, port); | |
run(); | |
} catch (UnknownHostException ex) { | |
} catch (IOException ex) { | |
Logger.getLogger(BaseBot.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
@Override | |
public void run() { | |
read(); | |
} | |
public void read(){ | |
try { | |
reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); | |
while (true) { | |
String line; | |
if ((line = reader.readLine()) != null) { | |
System.out.println(line); | |
gui.appendRaw(line); | |
} | |
} | |
} catch (IOException e) { | |
gui.logError(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment