From 8bceed0243931ddf7a98fa5637889a9e87c8df8b Mon Sep 17 00:00:00 2001 From: Dor Bivas Date: Sat, 29 Mar 2014 21:52:54 +0300 Subject: 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. --- src/Server/CommandsTable.java | 28 +++++++++++++++++++++++----- 1 file 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*/ -- cgit v1.2.3