Implement LUSERS

This commit is contained in:
Les De Ridder 2017-04-10 05:07:19 +02:00
parent 324cee253b
commit 2bfa4a75bf
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
2 changed files with 44 additions and 0 deletions

View File

@ -177,6 +177,10 @@ class Connection
if(!registered) sendErrNotRegistered();
else onMotd(message);
break;
case "LUSERS":
if(!registered) sendErrNotRegistered();
else onLusers(message);
break;
default:
writeln("unknown command '", message.command, "'");
send(Message(_server.name, "421", [nick, message.command, "Unknown command"]));
@ -622,6 +626,21 @@ class Connection
_server.sendMotd(this);
}
void onLusers(Message message)
{
if(message.parameters.length == 1)
{
notImplemented("querying the size of a part of the network");
return;
}
else if(message.parameters.length > 1)
{
notImplemented("forwarding LUSERS to another server");
return;
}
_server.sendLusers(this);
}
void sendWhoReply(string channel, Connection user, uint hopCount)
{
auto flags = user.modes.canFind('a') ? "G" : "H";

View File

@ -312,6 +312,31 @@ class Server
connection.send(Message(name, "376", [connection.nick, "End of MOTD command"], true));
}
void sendLusers(Connection connection)
{
//TODO: If RFC-strictness is off, use '1 server' instead of '1 servers' of the network (or the part of the network of the query) has only one server
//TODO: Support services and multiple servers
connection.send(Message(name, "251", [connection.nick, "There are " ~ connections.filter!(c => c.registered).count.to!string ~ " users and 0 services on 1 servers"], true));
if(connections.any!(c => c.isOperator))
{
connection.send(Message(name, "252", [connection.nick, connections.count!(c => c.isOperator).to!string, "operator(s) online"], true));
}
if(connections.any!(c => !c.registered))
{
connection.send(Message(name, "253", [connection.nick, connections.count!(c => !c.registered).to!string, "unknown connection(s)"], true));
}
if(channels.length > 0)
{
connection.send(Message(name, "254", [connection.nick, channels.length.to!string, "channels formed"], true));
}
connection.send(Message(name, "255", [connection.nick, "I have " ~ connections.length.to!string ~ " clients and 1 servers"], true));
}
void listen(ushort port = 6667)
{
listenTCP(port, &acceptConnection);