Proper nickname validation #1

Merged
lesderid merged 1 commits from albino/salty-ircd:valnick into master 2017-04-08 00:01:38 +02:00
2 changed files with 20 additions and 2 deletions
Showing only changes of commit 9c8caae67d - Show all commits

View File

@ -203,6 +203,12 @@ class Connection
return;
}
if(!_server.isValidNick(newNick))
{
send(Message(_server.name, "432", [nick, newNick, "Erroneous nickname"]));
return;
}
if(nick !is null)
{
sendToPeers(Message(nick, "NICK", [newNick]));

View File

@ -76,8 +76,20 @@ class Server
static bool isValidNick(string name)
{
//TODO: Use the real rules
return !name.startsWith('#') && !name.startsWith('&') && name.length <= 9;
import std.ascii : digits, letters;
if(name.length > 9)
return false;
foreach(i, c; name)
{
auto allowed = letters ~ "[]\\`_^{|}";
if(i > 0)
allowed = allowed ~ digits ~ "-";
if (!allowed.canFind(c))
return false;
}
return true;
}
bool isNickAvailable(string nick)