diff options
author | Dor Bivas <dor1_b@walla.com> | 2013-11-02 17:58:09 +0200 |
---|---|---|
committer | Dor Bivas <dor1_b@walla.com> | 2013-11-02 17:58:09 +0200 |
commit | bb802317abad8c55f205a2649194d3c0fc9b0da8 (patch) | |
tree | 123424065ccd5e405214ddba3bd31bd5698699b3 /src/Server/CommandsTable.java | |
parent | 46c9497652bc2852b4a9bc632358e20bcae7a139 (diff) |
support multiple connections and JOIN/PRIVMSG
* A separate thread per connection.
* Basic handling of JOIN and PRIVMSG. Now simple IRC clients can talk to
us.
Diffstat (limited to 'src/Server/CommandsTable.java')
-rw-r--r-- | src/Server/CommandsTable.java | 51 |
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");
}
|