summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDor Bivas <dor1_b@walla.com>2014-03-29 21:52:54 +0300
committerDor Bivas <dor1_b@walla.com>2014-03-29 21:52:54 +0300
commit8bceed0243931ddf7a98fa5637889a9e87c8df8b (patch)
treea805f169afe3ba4984d31f028474b70d56353b06
parentf30a75c69f371ca8cf964181ae8e757d95419d1b (diff)
Server: fixes null Nick name in nick collision:
* response to USER was always 001 even in case of nick collision. * but in the case of nick collision NICK is resent and we only get it after USER. * Fix: send 001 only once we set both nick and user.
-rw-r--r--src/Server/CommandsTable.java28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/Server/CommandsTable.java b/src/Server/CommandsTable.java
index d9bbea8..e50da98 100644
--- a/src/Server/CommandsTable.java
+++ b/src/Server/CommandsTable.java
@@ -35,6 +35,11 @@ public class CommandsTable
/** parent class for all command handling classes.*/
abstract class Command
{
+ protected void printStartBanner (Client client)
+ {
+ this.println(client, "001 " + client.getNick() + " :Welcome to Dor's ircd");
+ }
+
abstract public void run(Client client, String args);
/** print line to the client
@@ -114,10 +119,19 @@ class CommandNick extends Command
public void run(Client client, String args)
{
String nick = args;
- if (!client.setNick(nick))
+ String oldNick = client.getNick();
+
+ if (client.setNick(nick))
+ {
+ if (oldNick == null && client.getUsername() != null)
+ {
+ this.printStartBanner(client);
+ }
+ }
+ else
{
- this.println(client, "433 * " + nick + " :Nick alredy in use.");
- }
+ this.println(client, "433 * " + nick + " :Nick alredy in use.");
+ }
}
}
@@ -142,7 +156,11 @@ class CommandUser extends Command
{
String[] argsArray = args.split("[ \t]+");
client.setUsername(argsArray[0]);
- this.println(client, "001 " + client.getNick() + " :Welcome to Dor's ircd");
+
+ if (client.getNick() != null)
+ {
+ printStartBanner(client);
+ }
}
}
@@ -154,7 +172,7 @@ class CommandQuit extends Command
public void run(Client client, String args)
{
client.disconect();
- }
+ }
}
/**Input of unknown command*/