Implement LUSERS
This commit is contained in:
parent
324cee253b
commit
2bfa4a75bf
|
@ -177,6 +177,10 @@ class Connection
|
||||||
if(!registered) sendErrNotRegistered();
|
if(!registered) sendErrNotRegistered();
|
||||||
else onMotd(message);
|
else onMotd(message);
|
||||||
break;
|
break;
|
||||||
|
case "LUSERS":
|
||||||
|
if(!registered) sendErrNotRegistered();
|
||||||
|
else onLusers(message);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
writeln("unknown command '", message.command, "'");
|
writeln("unknown command '", message.command, "'");
|
||||||
send(Message(_server.name, "421", [nick, message.command, "Unknown command"]));
|
send(Message(_server.name, "421", [nick, message.command, "Unknown command"]));
|
||||||
|
@ -622,6 +626,21 @@ class Connection
|
||||||
_server.sendMotd(this);
|
_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)
|
void sendWhoReply(string channel, Connection user, uint hopCount)
|
||||||
{
|
{
|
||||||
auto flags = user.modes.canFind('a') ? "G" : "H";
|
auto flags = user.modes.canFind('a') ? "G" : "H";
|
||||||
|
|
|
@ -312,6 +312,31 @@ class Server
|
||||||
connection.send(Message(name, "376", [connection.nick, "End of MOTD command"], true));
|
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)
|
void listen(ushort port = 6667)
|
||||||
{
|
{
|
||||||
listenTCP(port, &acceptConnection);
|
listenTCP(port, &acceptConnection);
|
||||||
|
|
Loading…
Reference in New Issue