diff options
author | Dor Bivas <dor1_b@walla.com> | 2014-02-08 18:38:05 +0200 |
---|---|---|
committer | Dor Bivas <dor1_b@walla.com> | 2014-02-08 18:38:05 +0200 |
commit | 3abd457e7c58f8d39f27ce4868b652b5d58572ff (patch) | |
tree | 5a4953defd79efd21f9eaa697fc5b22e0f677c7f | |
parent | 22c469e64d1d71f8c87272458b7bb052c44c06b2 (diff) |
client: parse commands upon reading. respond to PING
* Parse commands with ParsedLine upon reading
* Print a PRIVMSG nicer
* Respond to PING and don't print it
-rw-r--r-- | src/Client/ChatClient.java | 2 | ||||
-rw-r--r-- | src/Client/ChatClientReader.java | 26 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/Client/ChatClient.java b/src/Client/ChatClient.java index df2c553..b29c756 100644 --- a/src/Client/ChatClient.java +++ b/src/Client/ChatClient.java @@ -94,7 +94,7 @@ public class ChatClient try { soc = new Socket(host, port); - ChatClientReader reader = new ChatClientReader(soc); + ChatClientReader reader = new ChatClientReader(this, soc); reader.setDisplay(ui); diff --git a/src/Client/ChatClientReader.java b/src/Client/ChatClientReader.java index 976bf84..46b5c46 100644 --- a/src/Client/ChatClientReader.java +++ b/src/Client/ChatClientReader.java @@ -8,13 +8,15 @@ import javax.swing.JTextArea; public class ChatClientReader extends Thread { public static Scanner reader = new Scanner(System.in); + private ChatClient client; private Socket soc; UserInterface ui; /** constructor * @param the socket */ - public ChatClientReader (Socket soc) + public ChatClientReader (ChatClient client, Socket soc) { + this.client = client; this.soc = soc; } @@ -40,16 +42,30 @@ public class ChatClientReader extends Thread { soc.close(); System.err.println("The line is empty"); + break; } - line = "[" + line + "]"; + System.out.println(""); System.out.println(line); - ui.outputWriter(line); + ParsedLine parsed = new ParsedLine(line); - } while (line != null); - + if (parsed.get("command").compareTo("PRIVMSG") == 0) + { + ui.outputWriter(parsed.get("nick") + ": " + parsed.get("message")); + } + else if (parsed.get("command").compareTo("PING") == 0) + { + this.client.runSendline("PONG :me"); + } + + else + { + ui.outputWriter("[" + line + "]"); + } + } while (line != null); + // FIXME: close socket here? } catch (IOException e) { System.err.println(e); return; |