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)
{
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);
}

View File

@ -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;
}

View File

@ -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)