forked from lesderid/salty-ircd
Send PING at regular intervals
This commit is contained in:
parent
ee1e8ff950
commit
dc6bc2bd23
|
@ -2,6 +2,7 @@ module ircd.app;
|
|||
|
||||
import std.stdio;
|
||||
import std.algorithm;
|
||||
import std.range;
|
||||
import core.time;
|
||||
|
||||
import vibe.d;
|
||||
|
@ -13,6 +14,18 @@ shared static this()
|
|||
{
|
||||
Connection[] connections = [];
|
||||
|
||||
runTask(delegate()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
foreach(connection; connections)
|
||||
{
|
||||
connection.send(Message(null, "PING", [connection.nick]));
|
||||
}
|
||||
sleep(10.seconds);
|
||||
}
|
||||
});
|
||||
|
||||
listenTCP(6667, delegate(TCPConnection connection)
|
||||
{
|
||||
auto c = new Connection(connection);
|
||||
|
|
|
@ -42,16 +42,13 @@ class Connection
|
|||
case "NICK":
|
||||
//TODO: Check availablity and validity etc.
|
||||
nick = message.parameters[0];
|
||||
writeln("nick: " ~ nick);
|
||||
break;
|
||||
case "USER":
|
||||
user = message.parameters[0];
|
||||
realname = message.parameters[3];
|
||||
|
||||
writeln("user: " ~ user);
|
||||
writeln("mode: " ~ message.parameters[1]);
|
||||
writeln("unused: " ~ message.parameters[2]);
|
||||
writeln("realname: " ~ realname);
|
||||
|
||||
send(Message("localhost", "001", [nick, "Welcome to the Internet Relay Network " ~ nick ~ "!" ~ user ~ "@hostname"], true));
|
||||
send(Message("localhost", "002", [nick, "Your host is ircd, running version 0.01"], true));
|
||||
|
@ -59,7 +56,10 @@ class Connection
|
|||
send(Message("localhost", "004", [nick, "ircd", "0.01", "w", "snt"]));
|
||||
break;
|
||||
case "PING":
|
||||
send(Message(null, "PONG", [message.parameters[0]]));
|
||||
send(Message(null, "PONG", [message.parameters[0]], true));
|
||||
break;
|
||||
case "PONG":
|
||||
//TODO: Handle pong
|
||||
break;
|
||||
case "QUIT":
|
||||
send(Message(null, "ERROR", ["Bye!"]));
|
||||
|
|
|
@ -64,6 +64,7 @@ struct Message
|
|||
{
|
||||
message ~= parameters[0 .. $-1].join(' ') ~ " ";
|
||||
}
|
||||
|
||||
if(parameters[$-1].canFind(' ') || prefixedParameter)
|
||||
{
|
||||
message ~= ":";
|
||||
|
|
Loading…
Reference in New Issue