From b4da3ef8feab36653ac005d14d1ee3e3cc531301 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Mon, 24 Apr 2017 06:57:21 +0200 Subject: [PATCH] Implement KILL --- source/ircd/connection.d | 39 +++++++++++++++++++++++++++++++++++++++ source/ircd/server.d | 14 ++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/source/ircd/connection.d b/source/ircd/connection.d index 29d5554..971b422 100644 --- a/source/ircd/connection.d +++ b/source/ircd/connection.d @@ -72,6 +72,11 @@ class Connection _connection.write(messageString ~ "\r\n"); } + void closeConnection() + { + _connection.close(); + } + //sends the message to all clients who have a channel in common with this client void sendToPeers(Message message) { @@ -190,6 +195,9 @@ class Connection case "WHOIS": onWhois(message); break; + case "KILL": + onKill(message); + break; default: writeln("unknown command '", message.command, "'"); send(Message(_server.name, "421", [nick, message.command, "Unknown command"])); @@ -690,6 +698,32 @@ class Connection send(Message(_server.name, "318", [nick, mask, "End of WHOIS list"], true)); } + void onKill(Message message) + { + if(!isOperator) + { + sendErrNoPrivileges(); + return; + } + + if(message.parameters.length < 2) + { + sendErrNeedMoreParams(message.command); + return; + } + + auto nick = message.parameters[0]; + if(!_server.canFindConnectionByNick(nick)) + { + sendErrNoSuchNick(nick); + return; + } + + auto comment = message.parameters[1]; + + _server.kill(this, nick, comment); + } + void sendWhoReply(string channel, Connection user, uint hopCount) { auto flags = user.modes.canFind('a') ? "G" : "H"; @@ -755,6 +789,11 @@ class Connection send(Message(_server.name, "461", [nick, command, "Not enough parameters"], true)); } + void sendErrNoPrivileges() + { + send(Message(_server.name, "481", [nick, "Permission Denied- You're not an IRC operator"], true)); + } + void sendErrChanopPrivsNeeded(string channel) { send(Message(_server.name, "482", [nick, channel, "You're not channel operator"], true)); diff --git a/source/ircd/server.d b/source/ircd/server.d index 9498d4b..db7c584 100644 --- a/source/ircd/server.d +++ b/source/ircd/server.d @@ -383,6 +383,20 @@ class Server connection.send(Message(name, "319", [connection.nick, user.nick, userChannels], true)); } + void kill(Connection killer, string nick, string comment) + { + auto user = findConnectionByNick(nick)[0]; + + user.send(Message(killer.mask, "KILL", [nick, comment], true)); + + //TODO: Find out if any RFC specifies a QUIT message + quit(user, "Killed by " ~ killer.nick ~ " (" ~ comment ~ ")"); + + //TODO: Find out if what we have to send here + user.send(Message(null, "ERROR", ["Closing Link: Killed by " ~ killer.nick ~ " (" ~ comment ~ ")"], true)); + user.closeConnection(); + } + void listen(ushort port = 6667) { listenTCP(port, &acceptConnection);