Check nick availability
This commit is contained in:
parent
dfe9e65786
commit
10bd22734d
|
@ -133,7 +133,19 @@ class Connection
|
|||
|
||||
void onNick(Message message)
|
||||
{
|
||||
if(message.parameters.length == 0)
|
||||
{
|
||||
sendErrNoNickGiven();
|
||||
}
|
||||
|
||||
auto newNick = message.parameters[0];
|
||||
|
||||
if(!_server.isNickAvailable(newNick))
|
||||
{
|
||||
send(Message(_server.name, "433", [nick, newNick, "Nickname already in use"]));
|
||||
return;
|
||||
}
|
||||
|
||||
if(nick !is null)
|
||||
{
|
||||
sendToPeers(Message(nick, "NICK", [newNick]));
|
||||
|
@ -254,7 +266,7 @@ class Connection
|
|||
}
|
||||
else
|
||||
{
|
||||
//is this the right response?
|
||||
//is this the right reply?
|
||||
sendErrNoSuchNick(target);
|
||||
}
|
||||
}
|
||||
|
@ -269,6 +281,11 @@ class Connection
|
|||
send(Message(_server.name, "401", [nick, name, "No such nick/channel"], true));
|
||||
}
|
||||
|
||||
void sendErrNoNickGiven()
|
||||
{
|
||||
send(Message(_server.name, "431", [nick, "No nickname given"], true));
|
||||
}
|
||||
|
||||
string getHost()
|
||||
{
|
||||
auto address = parseAddress(_connection.peerAddress);
|
||||
|
|
|
@ -64,6 +64,11 @@ class Server
|
|||
return !name.startsWith('#') && !name.startsWith('&') && name.length <= 9;
|
||||
}
|
||||
|
||||
bool isNickAvailable(string nick)
|
||||
{
|
||||
return !connections.canFind!(c => c.nick == nick);
|
||||
}
|
||||
|
||||
void join(Connection connection, string channelName)
|
||||
{
|
||||
auto channelRange = channels.find!(c => c.name == channelName);
|
||||
|
|
Loading…
Reference in New Issue