From ec570b2a1afdb481703b9114fa9673bb759b8c08 Mon Sep 17 00:00:00 2001 From: Dor Bivas Date: Sat, 22 Feb 2014 14:10:24 +0200 Subject: ChatClient : Starting with Dor-Chet Channel --- src/Client/ChatClient.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Client/ChatClient.java b/src/Client/ChatClient.java index b29c756..6d22d58 100644 --- a/src/Client/ChatClient.java +++ b/src/Client/ChatClient.java @@ -22,6 +22,8 @@ public class ChatClient private Socket soc; private boolean isConnected = false; + private static final String CHANNEL = "#Dor-chat"; //FIXME: should be public. But it's interesting if the server could be ignorant of it + ChatClient() { this.soc = null; } @@ -54,6 +56,11 @@ public class ChatClient this.isConnected = true; } + public boolean getConnected() + { + return this.isConnected; + } + /** send a line to server */ public void runSendline (String line) { @@ -73,10 +80,25 @@ public class ChatClient else { - runSendline("PRIVMSG " + "#Chat-Dor :" + line); + runSendline("PRIVMSG " + this.CHANNEL + " :" + line); } } + public void fixNickCollision() + { + String newNick = getNick() + new Integer((int) (Math.random()*1000)).toString(); + runSendline("NICK " + newNick); + } + + /** Initial setup with the server once the nick was set up*/ + public void startup() + { + // 0: mode (nothing special). *: unused in RFC 2812, server name in RFC 1459 + runSendline("USER " + this.getNick() + " 0 * :" + this.getRealname()); + runSendline("JOIN " + this.CHANNEL); + this.setConnected(); // FIXME: Not sure yet if client is connected. + } + public void shutdown() { if (soc != null) -- cgit v1.2.3