summaryrefslogtreecommitdiff
path: root/src/Server/CommandsTable.java
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir@cohens.org.il>2013-12-04 10:50:36 +0200
committerTzafrir Cohen <tzafrir@cohens.org.il>2013-12-04 10:50:36 +0200
commit3bbbd95c8d2d6f3185b0f3e48263f36ba4bb0e75 (patch)
treeb336db15d08ab911658a646a6b7f3e6bf011be28 /src/Server/CommandsTable.java
parentd57f9416a9d4bb92d4111f73af278f607bbe78b9 (diff)
Convert source to NL-terminated
Diffstat (limited to 'src/Server/CommandsTable.java')
-rw-r--r--src/Server/CommandsTable.java294
1 files changed, 147 insertions, 147 deletions
diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java
index 2d580fc..6edac37 100644
--- a/src/Server/CommandsTable.java
+++ b/src/Server/CommandsTable.java
@@ -1,148 +1,148 @@
-package Server;
-import java.io.IOException;
-import java.util.Hashtable;
-
-public class CommandsTable
-{
- private Hashtable<String, Command> table;
- public CommandsTable()
- {
- this.table = new Hashtable<String, Command>();
- this.table.put("NICK", new CommandNick());
- 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());
- }
-
- public void runCommand (Client client , String commandName , String args)
- {
- //FIXME: convert to upper case
- Command command = this.table.get(commandName);
-
- if (command == null)
- {
- System.err.println("Missing command <" + commandName + ">.");
- command = new CommandBad();
- }
- command.run(client, args);
- }
-
-}
-
-
-abstract class Command
-{
- abstract public void run(Client client, String args);
-
- public void println(Client client, String str)
- {
- try {
- client.println(":" + client.getHostname() +" " + str);
- } catch (IOException e) {
- System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
- }
- }
-
- public void printUser(Client client, String str)
- {
- try {
- client.println(":" + client.getNick() + "!" + client.getUsername() + "@" + client.getHostname() + str);
- } catch (IOException e) {
- System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
- }
- }
-
- /** Remove the first char from the input (this char is irelevant)*/
- public static String RemoveFirst(String st)
- {
- return st.substring(1 , st.length());
- }
-}
-
-
-//FIXME:
-class CommandPrivmsg extends Command
-{
- public CommandPrivmsg(){}
-
- public void run(Client client, String args)
- {
- String [] starr = args.split("[ \t]+" , 2);
- String line = RemoveFirst(starr[1]);
- }
-}
-
-/** Command that setting the nick name of the client*/
-class CommandNick extends Command
-{
- public CommandNick() {}
-
- public void run(Client client, String args)
- {
- String nick = args;
- client.setNick(nick);
- // FIXME: print reply
- }
-}
-
-/** Command that connecting the client to the server */
-class CommandJoin extends Command
-{
- public CommandJoin() {}
-
- public void run(Client client, String args)
- {
- // 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");
- //this.println(client, "333 " + client.getNick()) + args + "someone!somewhere";
- }
-}
-
-/** Command that recipient the client to the irc*/
-class CommandUser extends Command
-{
- public void run(Client client, String args)
- {
- String[] argsArray = args.split("[ \t]+");
- client.setUsername(argsArray[0]);
- //client.setNick(args);
- this.println(client, "001 " + client.getNick() + " :Welcome to Dor's ircd");
- }
-}
-
-/** Command that disconnect the client from the server*/
-class CommandQuit extends Command
-{
- public CommandQuit() {}
-
- public void run(Client client, String args)
- {
- client.disconect();
-
- }
-}
-
-/**Input of unknown command*/
-class CommandBad extends Command
-{
- public void run(Client client, String args)
- {
- this.println(client, "421 " + client.getNick() + " " + args + " Unknown command.");
- }
-}
-
-/** Pinging each few seconds to keep the connection alive*/
-class CommandPing extends Command
-{
- public CommandPing() {}
-
- public void run(Client client, String args)
- {
- this.println(client , "PONG " + args + " :" + client.getHostname()); //FIXME: needed massge return
-
- }
+package Server;
+import java.io.IOException;
+import java.util.Hashtable;
+
+public class CommandsTable
+{
+ private Hashtable<String, Command> table;
+ public CommandsTable()
+ {
+ this.table = new Hashtable<String, Command>();
+ this.table.put("NICK", new CommandNick());
+ 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());
+ }
+
+ public void runCommand (Client client , String commandName , String args)
+ {
+ //FIXME: convert to upper case
+ Command command = this.table.get(commandName);
+
+ if (command == null)
+ {
+ System.err.println("Missing command <" + commandName + ">.");
+ command = new CommandBad();
+ }
+ command.run(client, args);
+ }
+
+}
+
+
+abstract class Command
+{
+ abstract public void run(Client client, String args);
+
+ public void println(Client client, String str)
+ {
+ try {
+ client.println(":" + client.getHostname() +" " + str);
+ } catch (IOException e) {
+ System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
+ }
+ }
+
+ public void printUser(Client client, String str)
+ {
+ try {
+ client.println(":" + client.getNick() + "!" + client.getUsername() + "@" + client.getHostname() + str);
+ } catch (IOException e) {
+ System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
+ }
+ }
+
+ /** Remove the first char from the input (this char is irelevant)*/
+ public static String RemoveFirst(String st)
+ {
+ return st.substring(1 , st.length());
+ }
+}
+
+
+//FIXME:
+class CommandPrivmsg extends Command
+{
+ public CommandPrivmsg(){}
+
+ public void run(Client client, String args)
+ {
+ String [] starr = args.split("[ \t]+" , 2);
+ String line = RemoveFirst(starr[1]);
+ }
+}
+
+/** Command that setting the nick name of the client*/
+class CommandNick extends Command
+{
+ public CommandNick() {}
+
+ public void run(Client client, String args)
+ {
+ String nick = args;
+ client.setNick(nick);
+ // FIXME: print reply
+ }
+}
+
+/** Command that connecting the client to the server */
+class CommandJoin extends Command
+{
+ public CommandJoin() {}
+
+ public void run(Client client, String args)
+ {
+ // 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");
+ //this.println(client, "333 " + client.getNick()) + args + "someone!somewhere";
+ }
+}
+
+/** Command that recipient the client to the irc*/
+class CommandUser extends Command
+{
+ public void run(Client client, String args)
+ {
+ String[] argsArray = args.split("[ \t]+");
+ client.setUsername(argsArray[0]);
+ //client.setNick(args);
+ this.println(client, "001 " + client.getNick() + " :Welcome to Dor's ircd");
+ }
+}
+
+/** Command that disconnect the client from the server*/
+class CommandQuit extends Command
+{
+ public CommandQuit() {}
+
+ public void run(Client client, String args)
+ {
+ client.disconect();
+
+ }
+}
+
+/**Input of unknown command*/
+class CommandBad extends Command
+{
+ public void run(Client client, String args)
+ {
+ this.println(client, "421 " + client.getNick() + " " + args + " Unknown command.");
+ }
+}
+
+/** Pinging each few seconds to keep the connection alive*/
+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