Fix Connection sorting

This commit is contained in:
Les De Ridder 2017-04-10 02:56:31 +02:00
parent dd33015ec7
commit 324cee253b
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
3 changed files with 39 additions and 30 deletions

View File

@ -50,7 +50,7 @@ class Connection
override int opCmp(Object o) override int opCmp(Object o)
{ {
Connection other; Connection other;
if((other = cast(Connection)other) !is null) if((other = cast(Connection)o) !is null)
{ {
return cmp(nick, other.nick); return cmp(nick, other.nick);
} }
@ -614,6 +614,11 @@ class Connection
notImplemented("querying the motd of another server"); notImplemented("querying the motd of another server");
return; return;
} }
else if(_server.motd is null)
{
send(Message(_server.name, "422", [nick, "MOTD File is missing"], true));
return;
}
_server.sendMotd(this); _server.sendMotd(this);
} }

View File

@ -8,7 +8,6 @@ import std.range;
@safe pure @safe pure
bool wildcardMatch(string input, string pattern) bool wildcardMatch(string input, string pattern)
{ {
foreach (ref pi; 0 .. pattern.length) foreach (ref pi; 0 .. pattern.length)
{ {
const pc = pattern[pi]; const pc = pattern[pi];
@ -16,24 +15,30 @@ bool wildcardMatch(string input, string pattern)
{ {
case '*': case '*':
if (pi + 1 == pattern.length) if (pi + 1 == pattern.length)
{
return true; return true;
}
for (; !input.empty; input.popFront()) for (; !input.empty; input.popFront())
{ {
auto p = input.save; auto p = input.save;
if (wildcardMatch(p, pattern[pi + 1 .. pattern.length])) if (wildcardMatch(p, pattern[pi + 1 .. pattern.length]))
{
return true; return true;
}
} }
return false; return false;
case '?': case '?':
if (input.empty) if (input.empty)
{
return false; return false;
}
input.popFront(); input.popFront();
break; break;
default: default:
if (input.empty) if (input.empty || pc != input.front)
return false; {
if (pc != input.front)
return false; return false;
}
input.popFront(); input.popFront();
break; break;
} }

View File

@ -76,20 +76,26 @@ class Server
static bool isValidNick(string name) static bool isValidNick(string name)
{ {
import std.ascii : digits, letters; import std.ascii : digits, letters;
if(name.length > 9) if(name.length > 9)
return false; {
foreach(i, c; name) return false;
{ }
auto allowed = letters ~ "[]\\`_^{|}"; foreach(i, c; name)
if(i > 0) {
allowed = allowed ~ digits ~ "-"; auto allowed = letters ~ "[]\\`_^{|}";
if(i > 0)
if (!allowed.canFind(c)) {
return false; allowed ~= digits ~ "-";
} }
return true;
if (!allowed.canFind(c))
{
return false;
}
}
return true;
} }
bool isNickAvailable(string nick) bool isNickAvailable(string nick)
@ -297,20 +303,13 @@ class Server
void sendMotd(Connection connection) 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)); //TODO: Implement line wrapping
foreach(line; motd.splitLines) connection.send(Message(name, "372", [connection.nick, ":- " ~ line], 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));
}
else
{
connection.send(Message(name, "422", [connection.nick, "MOTD File is missing"], true));
} }
connection.send(Message(name, "376", [connection.nick, "End of MOTD command"], true));
} }
void listen(ushort port = 6667) void listen(ushort port = 6667)