diff options
author | Dor Bivas <dor1_b@walla.com> | 2014-01-18 14:07:55 +0200 |
---|---|---|
committer | Dor Bivas <dor1_b@walla.com> | 2014-01-18 14:07:55 +0200 |
commit | 8e00afc1514660da67d45fa4e78905559747b637 (patch) | |
tree | ad000d9745516b59aa2cfc2fdbdc3c4056dd090e | |
parent | 325974ab3c08668ce9c2f2b4957e3337928a0114 (diff) |
ChServer is now global variable.
* Reverting previous addition of local references of ChatServer in some
objects.
* Get list of ports in PRIVMSG command.
* toString for portnum.
-rw-r--r-- | src/Server/ChatServer.java | 2 | ||||
-rw-r--r-- | src/Server/Client.java | 3 | ||||
-rw-r--r-- | src/Server/CommandsTable.java | 16 | ||||
-rw-r--r-- | src/Server/Connection.java | 13 |
4 files changed, 24 insertions, 10 deletions
diff --git a/src/Server/ChatServer.java b/src/Server/ChatServer.java index 9f9beb9..4705730 100644 --- a/src/Server/ChatServer.java +++ b/src/Server/ChatServer.java @@ -10,6 +10,7 @@ public class ChatServer private LinkedList<Connection> connections; public static final int portNum = 6667; + public static ChatServer server; public void connectionRemove(Connection con) { @@ -28,7 +29,6 @@ public class ChatServer /** Listening to port and opening a socket */ public static void main(String[] args) throws IOException { - ChatServer server; try { server = new ChatServer(); diff --git a/src/Server/Client.java b/src/Server/Client.java index 7538882..b76bb57 100644 --- a/src/Server/Client.java +++ b/src/Server/Client.java @@ -8,7 +8,8 @@ public class Client String nick; String username; Socket soc; - BufferedWriter output;; + BufferedWriter output; + ChatServer server; public Client(Socket soc, BufferedWriter output) { diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java index 0b71ce6..af423ea 100644 --- a/src/Server/CommandsTable.java +++ b/src/Server/CommandsTable.java @@ -6,11 +6,9 @@ import java.util.Iterator; public class CommandsTable { private Hashtable<String, Command> table; - private ChatServer server; - public CommandsTable(ChatServer server) + public CommandsTable() { - this.server = server; this.table = new Hashtable<String, Command>(); this.table.put("NICK", new CommandNick()); this.table.put("USER", new CommandUser()); @@ -66,7 +64,6 @@ abstract class Command } -//FIXME: class CommandPrivmsg extends Command { public CommandPrivmsg(){} @@ -75,6 +72,17 @@ class CommandPrivmsg extends Command { String [] starr = args.split("[ \t]+" , 2); String line = RemoveFirst(starr[1]); + String ports = "PRIVMSG port: "; + + Iterator<Connection> iter = ChatServer.server.getConnectionIterator(); + + while (iter.hasNext()) + { + Connection con = iter.next(); + ports += con.toString(); + this.println(client, "PRIVMSG #fixme-chan :" + line); + } + System.err.println("printed message to ports: " + ports); } } diff --git a/src/Server/Connection.java b/src/Server/Connection.java index 676a65a..62afa9a 100644 --- a/src/Server/Connection.java +++ b/src/Server/Connection.java @@ -8,9 +8,10 @@ import java.io.OutputStreamWriter; class ParsedLine { - String line; - String command; - String args; + private String line; + private String command; + private String args; + public ParsedLine(String line) { @@ -44,7 +45,6 @@ public class Connection extends Thread public Connection(Socket soc) { - this.soc = soc; } @@ -56,6 +56,11 @@ public class Connection extends Thread soc.close(); } catch (IOException e) {} } + + public String toString () + { + return "[" + soc.getPort() + "]"; + } @SuppressWarnings("deprecation") public void run() |