From 9c8caae67d31ae8c97547f8076c2229a97f51532 Mon Sep 17 00:00:00 2001 From: Al Beano Date: Fri, 7 Apr 2017 22:58:03 +0100 Subject: [PATCH] Validate nicknames --- source/ircd/connection.d | 6 ++++++ source/ircd/server.d | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/ircd/connection.d b/source/ircd/connection.d index dd6c8a9..0598f25 100644 --- a/source/ircd/connection.d +++ b/source/ircd/connection.d @@ -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])); diff --git a/source/ircd/server.d b/source/ircd/server.d index 2469f81..3ad0167 100644 --- a/source/ircd/server.d +++ b/source/ircd/server.d @@ -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)