Implement KILL

This commit is contained in:
Les De Ridder 2017-04-24 06:57:21 +02:00
parent 16044982a1
commit b4da3ef8fe
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
2 changed files with 53 additions and 0 deletions

View File

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

View File

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