summaryrefslogtreecommitdiff
path: root/src/Client/ChatClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/ChatClient.java')
-rw-r--r--src/Client/ChatClient.java75
1 files changed, 16 insertions, 59 deletions
diff --git a/src/Client/ChatClient.java b/src/Client/ChatClient.java
index 6499b75..fe70742 100644
--- a/src/Client/ChatClient.java
+++ b/src/Client/ChatClient.java
@@ -2,18 +2,6 @@ package Client;
import java.io.*;
import java.net.Socket;
-
-
-
-
-
-
-
-
-
-import Server.ChatServer;
-import Server.Client;
-
public class ChatClient
{
private String nick;
@@ -23,7 +11,7 @@ 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
+ private static final String CHANNEL = "#Dor-chat";
ChatClient() {
this.soc = null;
@@ -39,7 +27,8 @@ public class ChatClient
{
return this.realname;
}
- /** changing the nick name */
+ /** changing the nick name *
+ * @param nick name the name to set*/
public void setNick (String nick)
{
this.nick = nick;
@@ -57,6 +46,7 @@ public class ChatClient
this.isConnected = true;
}
+ /** returning connection */
public boolean getConnected()
{
return this.isConnected;
@@ -71,12 +61,14 @@ public class ChatClient
writer.sendLine(line);
}
+ /** send line to server */
private void earlySendline(String line)
{
writer.sendLine(line);
}
- /** */
+ /** if the line is special command privmsg will handle it, else it will send the lien as a privmsg.
+ * @param the line.*/
public void PRIVMSG (String line)
{
String[] words = line.split("[ \t]", 2);
@@ -97,12 +89,14 @@ public class ChatClient
}
}
+ /** checking for nick Collisions and handling them. */
public void fixNickCollision()
{
- String newNick = getNick() + new Integer((int) (Math.random()*1000)).toString();
+ String newNick = getNick() + new Integer((int)(Math.random()*1000)).toString();
earlySendline("NICK " + newNick);
}
+ /** sending nick and user to the writer.*/
public void startup() {
earlySendline("NICK " + this.getNick());
earlySendline("USER " + this.getNick() + " 0 * :" + this.getRealname());
@@ -116,6 +110,7 @@ public class ChatClient
this.setConnected(); // FIXME: Not sure yet if client is connected.
}
+ /** closing the socket*/
public void shutdown()
{
if (soc != null)
@@ -128,14 +123,16 @@ public class ChatClient
}
}
+ /** opening new connection
+ * @param
+ * host name.
+ * port name. */
public boolean connect (String host, int port)
{
try
{
soc = new Socket(host, port);
- ChatClientReader reader = new ChatClientReader(this, soc);
-
- reader.setDisplay(ui);
+ ChatClientReader reader = new ChatClientReader(this, soc, ui);
this.writer = new ChatClientWriter(soc,this);
@@ -158,44 +155,4 @@ public class ChatClient
client.setRealname("Dor bivas");
client.ui = new UserInterface(client);
}
-
}
-
-
-
-/** Tasks
-
- * TODO: 5. When we get from the server a PRIVMSG, parse it and show who sent it.
- * Print other messages (Server messages) differently.
- *
- * Example:
- *
- * Instead of: :tzafrir!~tzafrir@localhost PRIVMSG #the-chan :Hello There
- * print: [#the-chan] Hello There
- *
- * TODO: 6. Join a channel at startup: For any server besides our own we need to send
- * a JOIN command (see how it is handled in the server).
- *
- * TODO: 7. Don't allow sending text until we joined a channel.
- */
-
-/** Later
- *
- * * Fix or remove all the fixme-s.
- * * Closing the program (Close, ALT-F4) does not end the process
- * * Keep channels up: PING occasionally
- * * The output buffer does not have a scroll bar.
- * * Pressing Enter in the message line does not send text.
- * * Configuration file to save the nick?
- * * History log?
- * * In the end:
- * * Close socket
- * * Send QUIT before that (QUIT :leaving)
- * * It may be handy to implement other client commands:
- * - /NICK - changes the nick
- * - /CLEAR - clears the output window
- * - /SAY - print a message directly to output window
- * - // - sends just a leading '/' (in case you want to send '/NICK whatever' to the channel
- * - /HELP - print a help message to the user
- * * Command-line client - useful for testing.
- */