Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package irc;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.util.Random;
- public class IRC {
- public static void main(String[] args) {
- Random randomGenerator = new Random();
- String host = "seattle.uwirc.com";
- int port = 6667;
- String nick = "FinnBawt" + randomGenerator.nextInt(100);
- String channel = "#css161";
- try{
- Socket socket = new Socket(host, port);
- PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- out.println("NICK " + nick);
- out.println("USER " + nick + " " + nick + " " + host + " " + nick);
- out.println("JOIN " + channel);
- out.println("PRIVMSG thefinn93 hai");
- String line;
- while((line = in.readLine()) != null) {
- System.out.println(line);
- String[] parsedline = line.split(" ",4);
- if(parsedline[0].equals("PING")) {
- out.println("PONG");
- } else if(parsedline[1].equals("PRIVMSG")) {
- if(parsedline[2].equals(nick)) {
- String from = parsedline[0].split("!")[0].split(":")[1];
- String msg = parsedline[3].split(":",2)[1];
- out.println("PRIVMSG " + from + " " + parsedline[3]);
- if(from.equals("thefinn93") && parsedline[3].equals(":quit")) {
- System.out.println("Quitting!");
- out.println("QUIT :Good night");
- socket.close();
- }
- } else {
- out.println("PRIVMSG " + parsedline[2] + " " + parsedline[3]);
- }
- } else if(parsedline[1].equals("NOTICE")) {
- System.out.println("NOTICE: " + line.split(":")[1]);
- } else {
- System.out.println("Recevied " + parsedline[1] + ", not sure what to do about it.");
- System.out.println(line);
- }
- }
- } catch (UnknownHostException e) {
- System.out.println("Unknown host: " + host);
- System.exit(1);
- } catch (IOException e) {
- System.out.println("No I/O");
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement