From 324cee253b6903c274fbae929a7bcbd010ba7c8a Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Mon, 10 Apr 2017 02:56:31 +0200 Subject: [PATCH] Fix Connection sorting --- source/ircd/connection.d | 7 +++++- source/ircd/helpers.d | 13 +++++++---- source/ircd/server.d | 49 ++++++++++++++++++++-------------------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/source/ircd/connection.d b/source/ircd/connection.d index 0598f25..d94859a 100644 --- a/source/ircd/connection.d +++ b/source/ircd/connection.d @@ -50,7 +50,7 @@ class Connection override int opCmp(Object o) { Connection other; - if((other = cast(Connection)other) !is null) + if((other = cast(Connection)o) !is null) { return cmp(nick, other.nick); } @@ -614,6 +614,11 @@ class Connection notImplemented("querying the motd of another server"); return; } + else if(_server.motd is null) + { + send(Message(_server.name, "422", [nick, "MOTD File is missing"], true)); + return; + } _server.sendMotd(this); } diff --git a/source/ircd/helpers.d b/source/ircd/helpers.d index 56cfec2..3e5fdd1 100644 --- a/source/ircd/helpers.d +++ b/source/ircd/helpers.d @@ -8,7 +8,6 @@ import std.range; @safe pure bool wildcardMatch(string input, string pattern) { - foreach (ref pi; 0 .. pattern.length) { const pc = pattern[pi]; @@ -16,24 +15,30 @@ bool wildcardMatch(string input, string pattern) { case '*': if (pi + 1 == pattern.length) + { return true; + } for (; !input.empty; input.popFront()) { auto p = input.save; if (wildcardMatch(p, pattern[pi + 1 .. pattern.length])) + { return true; + } } return false; case '?': if (input.empty) + { return false; + } input.popFront(); break; default: - if (input.empty) - return false; - if (pc != input.front) + if (input.empty || pc != input.front) + { return false; + } input.popFront(); break; } diff --git a/source/ircd/server.d b/source/ircd/server.d index 3ad0167..d0f7f23 100644 --- a/source/ircd/server.d +++ b/source/ircd/server.d @@ -76,20 +76,26 @@ class Server static bool isValidNick(string name) { - import std.ascii : digits, letters; + 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; + if(name.length > 9) + { + return false; + } + foreach(i, c; name) + { + auto allowed = letters ~ "[]\\`_^{|}"; + if(i > 0) + { + allowed ~= digits ~ "-"; + } + + if (!allowed.canFind(c)) + { + return false; + } + } + return true; } bool isNickAvailable(string nick) @@ -297,20 +303,13 @@ class Server void sendMotd(Connection connection) { - if(motd !is null) + connection.send(Message(name, "375", [connection.nick, ":- " ~ name ~ " Message of the day - "], true)); + foreach(line; motd.splitLines) { - connection.send(Message(name, "375", [connection.nick, ":- " ~ name ~ " Message of the day - "], true)); - foreach(line; motd.splitLines) - { - //TODO: Implement line wrapping - connection.send(Message(name, "372", [connection.nick, ":- " ~ line], true)); - } - connection.send(Message(name, "376", [connection.nick, "End of MOTD command"], true)); - } - else - { - connection.send(Message(name, "422", [connection.nick, "MOTD File is missing"], true)); + //TODO: Implement line wrapping + connection.send(Message(name, "372", [connection.nick, ":- " ~ line], true)); } + connection.send(Message(name, "376", [connection.nick, "End of MOTD command"], true)); } void listen(ushort port = 6667)