Proper nickname validation #1
|
@ -203,6 +203,12 @@ class Connection
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!_server.isValidNick(newNick))
|
||||||
|
{
|
||||||
|
send(Message(_server.name, "432", [nick, newNick, "Erroneous nickname"]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(nick !is null)
|
if(nick !is null)
|
||||||
{
|
{
|
||||||
sendToPeers(Message(nick, "NICK", [newNick]));
|
sendToPeers(Message(nick, "NICK", [newNick]));
|
||||||
|
|
|
@ -76,8 +76,20 @@ class Server
|
||||||
|
|
||||||
static bool isValidNick(string name)
|
static bool isValidNick(string name)
|
||||||
{
|
{
|
||||||
//TODO: Use the real rules
|
import std.ascii : digits, letters;
|
||||||
return !name.startsWith('#') && !name.startsWith('&') && name.length <= 9;
|
|
||||||
|
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)
|
bool isNickAvailable(string nick)
|
||||||
|
|
Loading…
Reference in New Issue