Implement KILL
This commit is contained in:
parent
16044982a1
commit
b4da3ef8fe
|
@ -72,6 +72,11 @@ class Connection
|
||||||
_connection.write(messageString ~ "\r\n");
|
_connection.write(messageString ~ "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void closeConnection()
|
||||||
|
{
|
||||||
|
_connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
//sends the message to all clients who have a channel in common with this client
|
//sends the message to all clients who have a channel in common with this client
|
||||||
void sendToPeers(Message message)
|
void sendToPeers(Message message)
|
||||||
{
|
{
|
||||||
|
@ -190,6 +195,9 @@ class Connection
|
||||||
case "WHOIS":
|
case "WHOIS":
|
||||||
onWhois(message);
|
onWhois(message);
|
||||||
break;
|
break;
|
||||||
|
case "KILL":
|
||||||
|
onKill(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"]));
|
||||||
|
@ -690,6 +698,32 @@ class Connection
|
||||||
send(Message(_server.name, "318", [nick, mask, "End of WHOIS list"], true));
|
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)
|
void sendWhoReply(string channel, Connection user, uint hopCount)
|
||||||
{
|
{
|
||||||
auto flags = user.modes.canFind('a') ? "G" : "H";
|
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));
|
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)
|
void sendErrChanopPrivsNeeded(string channel)
|
||||||
{
|
{
|
||||||
send(Message(_server.name, "482", [nick, channel, "You're not channel operator"], true));
|
send(Message(_server.name, "482", [nick, channel, "You're not channel operator"], true));
|
||||||
|
|
|
@ -383,6 +383,20 @@ class Server
|
||||||
connection.send(Message(name, "319", [connection.nick, user.nick, userChannels], true));
|
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)
|
void listen(ushort port = 6667)
|
||||||
{
|
{
|
||||||
listenTCP(port, &acceptConnection);
|
listenTCP(port, &acceptConnection);
|
||||||
|
|
Loading…
Reference in New Issue