1 package org.pileus.spades;
9 public String server = "irc.freenode.net";
10 public int port = 6667;
11 public String nickname = "SpadeGuest";
12 public String channel = "#rhnoise";
13 public boolean usesasl = false;
14 public String authname = "";
15 public String password = "";
16 public String username = "user";
17 public String hostname = "localhost";
20 public boolean ready = false;
23 private Socket socket;
24 private BufferedReader input;
25 private PrintWriter output;
33 Os.debug("Client: create");
36 public void setServer(String server, int port)
42 public void setAuth(boolean usesasl, String authname, String password)
44 this.usesasl = usesasl;
45 this.authname = authname;
46 this.password = password;
49 public void setUser(String nickname, String channel)
51 this.nickname = nickname;
52 this.channel = channel;
55 public boolean connect()
57 Os.debug("Client: connect");
60 this.socket = new Socket(this.server, this.port);
61 this.input = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
62 this.output = new PrintWriter(this.socket.getOutputStream());
63 } catch (Exception e) {
64 Os.debug("Client: failed to create connection: " + e);
68 Os.debug("Client: connected");
69 this.raw("USER "+this.username+" "+this.hostname+" "+this.server+" :"+this.nickname);
70 this.raw("NICK "+this.nickname);
75 public boolean abort()
77 Os.debug("Client: abort");
82 } catch (Exception e) {
83 Os.debug("Client: error closing socket", e);
88 public void raw(String line)
91 Os.debug("< " + line);
92 this.output.println(line);
94 } catch (Exception e) {
95 Os.debug("Client: error writing line", e);
99 public Message send(String txt)
101 Message msg = new Message(this.channel, this.nickname, txt);
106 public Message recv()
109 String line = input.readLine();
112 Os.debug("> " + line);
113 Message msg = new Message(line);
116 } catch (SocketException e) {
119 } catch (Exception e) {
121 Os.debug("Client: error in recv", e);
126 /* Private methods */
127 private void process(Message msg)
129 if (msg.cmd.equals("001") && msg.msg.matches("Welcome.*")) {
130 this.raw("JOIN " + this.channel);
131 this.raw("TOPIC " + this.channel);
134 if (msg.cmd.equals("433")) {
135 this.raw("NICK "+this.nickname+this.mangle);
138 if (msg.cmd.equals("PING")) {
139 this.raw("PING " + msg.msg);