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.java51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java
index 38d1799..93949a8 100644
--- a/src/Server/CommandsTable.java
+++ b/src/Server/CommandsTable.java
@@ -11,6 +11,8 @@ public class CommandsTable
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("PRIVMSG", new CommandPrivmsg());
}
public void runCommand (Client client , String commandName , String args)
@@ -32,7 +34,7 @@ public class CommandsTable
abstract class Command
{
abstract public void run(Client client, String args);
-
+
public void println(Client client, String str)
{
try {
@@ -41,23 +43,68 @@ abstract class Command
System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
}
}
+
+ public void printUser(Client client, String str)
+ {
+ try {
+ client.println(":" + client.getNick() + "!bla@me " + str);
+ } catch (IOException e) {
+ System.err.println("Failed to print to client socket: <" + str + "> (" + e + ")");
+ }
+ }
+
+ public static String RemoveFirst(String st)
+ {
+ return st.substring(1 , st.length());
+ }
}
+
+
+class CommandPrivmsg extends Command
+{
+ public CommandPrivmsg(){}
+
+ public void run(Client client, String args)
+ {
+ String [] starr = args.split("[ \t]+" , 2);
+ String line = RemoveFirst(starr[1]);
+ }
+}
+
+
class CommandNick extends Command
{
public CommandNick() {}
public void run(Client client, String args)
{
- client.setNick(args);
+ String nick = RemoveFirst(args);
+ client.setNick(nick);
// FIXME: print reply
}
}
+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";
+ }
+}
+
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");
}