From da24032cbe128d0fa57a652c683fe6715def4071 Mon Sep 17 00:00:00 2001 From: dor Date: Fri, 22 Nov 2013 21:21:56 +0200 Subject: Start documenting. --- src/Server/Client.java | 7 +++++++ src/Server/CommandsTable.java | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Server/Client.java b/src/Server/Client.java index 6b1bc3a..f577ba6 100644 --- a/src/Server/Client.java +++ b/src/Server/Client.java @@ -26,6 +26,11 @@ public class Client this.nick = newNick; } + public String getHostname() + { + return "me"; + } + public String getUsername() { return this.username; @@ -50,6 +55,8 @@ public class Client } + /** prints a line to the client socket + * @param line the text to print */ public void println(String line) throws IOException { output.write(line, 0, line.length()); diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java index 93949a8..ce016ed 100644 --- a/src/Server/CommandsTable.java +++ b/src/Server/CommandsTable.java @@ -12,6 +12,7 @@ public class CommandsTable this.table.put("USER", new CommandUser()); this.table.put("QUIT", new CommandQuit()); this.table.put("JOIN", new CommandJoin()); + this.table.put("PING", new CommandPing()); this.table.put("PRIVMSG", new CommandPrivmsg()); } @@ -38,7 +39,7 @@ abstract class Command public void println(Client client, String str) { try { - client.println(":me " + str); + client.println(":" + client.getHostname() +" " + str); } catch (IOException e) { System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")"); } @@ -47,7 +48,7 @@ abstract class Command public void printUser(Client client, String str) { try { - client.println(":" + client.getNick() + "!bla@me " + str); + client.println(":" + client.getNick() + "!" + client.getUsername() + "@" + client.getHostname() + str); } catch (IOException e) { System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")"); } @@ -91,7 +92,7 @@ class CommandJoin extends Command public void run(Client client, String args) { - // FIXME: parse args to channel names and save client state + // FIXME : parse args to channel names and save client state // but right now everybody is on a single channel this.printUser(client, "JOIN " + ":" + args); this.println(client, "332 " + client.getNick() + " " + args + " :Welcome to the single channel"); @@ -129,3 +130,13 @@ class CommandBad extends Command } } +class CommandPing extends Command +{ + public CommandPing() {} + + public void run(Client client, String args) + { + this.println(client , "PONG " + args + " :" + client.getHostname()); //FIXME: needed massge return + + } +} \ No newline at end of file -- cgit v1.2.3