summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDor Bivas <dor1_b@walla.com>2014-03-29 15:43:49 +0300
committerDor Bivas <dor1_b@walla.com>2014-03-29 15:43:49 +0300
commit4b64e500799da46fc406c3d0217eb89afc8e07b1 (patch)
tree25d5ea04514158952d39f0441bc1fd2d55c653ba
parent36a96d792a102a9553d4d2b0603de453a0c14559 (diff)
ChatServer: dict of nicks.
* add \ remove nicks.
-rw-r--r--src/Server/ChatServer.java38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/Server/ChatServer.java b/src/Server/ChatServer.java
index 4705730..363a747 100644
--- a/src/Server/ChatServer.java
+++ b/src/Server/ChatServer.java
@@ -1,6 +1,7 @@
package Server;
import java.net.*;
import java.io.*;
+import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Iterator;
@@ -8,6 +9,7 @@ public class ChatServer
{
private ServerSocket service;
private LinkedList<Connection> connections;
+ private Hashtable <String, Boolean> nicks;
public static final int portNum = 6667;
public static ChatServer server;
@@ -25,7 +27,29 @@ public class ChatServer
ChatServer() throws IOException {
this.service = new ServerSocket(portNum);
this.connections = new LinkedList<Connection>();
+ this.nicks = new Hashtable <String, Boolean>();
}
+
+ /** check if nick already used. if not add it.
+ * @param nick */
+ public boolean addNick (String nick)
+ {
+ if (this.nicks.get(nick) != null)
+ {
+ return false;
+ }
+
+ this.nicks.put(nick, true); // this value (true) has no meaning.
+ return true;
+ }
+
+ /** remove nick which is no longer in use.
+ * @param nick */
+ public void removeNick (String nick)
+ {
+ this.nicks.remove(nick);
+ }
+
/** Listening to port and opening a socket */
public static void main(String[] args) throws IOException
{
@@ -55,17 +79,3 @@ public class ChatServer
}
}
-
-/** Tasks
- *
- * * Allow listening on a different port (from command-line?)
- * * Have a test server running on cohens.org.il
- * * Send requests to all clients (use list)
- * - When a client disconnects - remove it from connections list.
- * - temporary: When we get a PRIVMSG, iterate over connections and write message and every client
- * - When we get a PRIVMSG, iterate over connections and write the message to each client
- * * Don't allow two clients with the same nick
- * * When passing a message (PRIVMSG) - include the sender's nick.
- * * Keep channels up: PING occasionally
- * * Graphical interface for server
- */