summaryrefslogtreecommitdiff
path: root/src/Server/CommandsTable.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Server/CommandsTable.java')
-rw-r--r--src/Server/CommandsTable.java30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java
index 65bbe03..966b67f 100644
--- a/src/Server/CommandsTable.java
+++ b/src/Server/CommandsTable.java
@@ -17,7 +17,7 @@ public class CommandsTable
this.table.put("PING", new CommandPing());
this.table.put("PRIVMSG", new CommandPrivmsg());
this.table.put("MODE", new CommandIgnored());
- }
+ }
public void runCommand (Client client , String commandName , String args)
{
@@ -32,11 +32,14 @@ public class CommandsTable
}
}
-
+/** parent class for all command handling classes.*/
abstract class Command
{
abstract public void run(Client client, String args);
+ /** print line to the client
+ * @param client destination client
+ * @param str the line */
public void println(Client client, String str)
{
try {
@@ -46,17 +49,22 @@ abstract class Command
}
}
-
+ /** send message to a client
+ * @param client
+ * @param str message */
public void printUser(Client client, String str)
{
printUser (client ,client, str);
}
-
+ /** print to client a message from sender.
+ * @param client destination client
+ * @param sender client
+ * @param str message */
public void printUser(Client client,Client sender, String str)
{
try {
- client.println(":" + sender .getNick() + "!" + client.getUsername() + "@" + client.getHostname() + " " + str);
+ client.println(":" + sender.getNick() + "!" + client.getUsername() + "@" + client.getHostname() + " " + str);
} catch (IOException e) {
System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
}
@@ -69,7 +77,8 @@ abstract class Command
}
}
-
+/** sending message from a client to all other clients.
+ * @param client, arguments */
class CommandPrivmsg extends Command
{
public CommandPrivmsg(){}
@@ -108,10 +117,7 @@ class CommandNick extends Command
if (!client.setNick(nick))
{
this.println(client, "433 * " + nick + " :Nick alredy in use.");
- }
-
-
-
+ }
}
}
@@ -163,9 +169,7 @@ class CommandBad extends Command
/** A command to ignore */
class CommandIgnored extends Command
{
- public void run(Client client, String args)
- {
- }
+ public void run(Client client, String args) {}
}
/** Pinging each few seconds to keep the connection alive*/