1 package org.pileus.spades;
3 import java.io.BufferedReader;
4 import java.io.PrintWriter;
9 private String server = null;
10 private String nickname = null;
11 private String channel = null;
12 private String username = null;
13 private String hostname = null;
15 private BufferedReader input = null;
16 private PrintWriter output = null;
19 public boolean running = true;
22 public Client(String server, String nickname, String channel,
23 String username, String hostname)
26 this.nickname = nickname;
27 this.channel = channel;
28 this.username = username;
29 this.hostname = hostname;
30 Os.debug("Client: create");
33 public Client(String server, String nickname, String channel)
35 this(server, nickname, channel, "user", "localhost");
38 public void connect(BufferedReader input, PrintWriter output)
42 Os.debug("Client: connect");
43 putline("USER "+username+" "+hostname+" "+server+" :"+nickname);
44 putline("NICK "+nickname);
47 public Message send(String txt)
49 Message msg = new Message(channel, nickname, txt);
57 String line = getline();
62 Message msg = new Message(line);
66 } catch (Exception e) {
67 Os.debug("Client: error in recv", e);
74 private void process(Message msg)
76 if (msg.cmd.equals("001") && msg.msg.matches("Welcome.*")) {
77 putline("JOIN " + channel);
78 putline("TOPIC " + channel);
80 if (msg.cmd.equals("PING")) {
81 putline("PING " + msg.msg);
85 private String getline()
88 String line = input.readLine();
90 Os.debug("> " + line);
92 } catch (Exception e) {
93 Os.debug("Client: error reading line", e);
99 private void putline(String line)
102 Os.debug("< " + line);
103 output.println(line);
105 } catch (Exception e) {
106 Os.debug("Client: error writing line", e);
107 this.running = false;