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.stdio;
|
||||||
import std.algorithm;
|
import std.algorithm;
|
||||||
|
import std.range;
|
||||||
import core.time;
|
import core.time;
|
||||||
|
|
||||||
import vibe.d;
|
import vibe.d;
|
||||||
|
@ -13,6 +14,18 @@ shared static this()
|
||||||
{
|
{
|
||||||
Connection[] connections = [];
|
Connection[] connections = [];
|
||||||
|
|
||||||
|
runTask(delegate()
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
foreach(connection; connections)
|
||||||
|
{
|
||||||
|
connection.send(Message(null, "PING", [connection.nick]));
|
||||||
|
}
|
||||||
|
sleep(10.seconds);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
listenTCP(6667, delegate(TCPConnection connection)
|
listenTCP(6667, delegate(TCPConnection connection)
|
||||||
{
|
{
|
||||||
auto c = new Connection(connection);
|
auto c = new Connection(connection);
|
||||||
|
|
|
@ -42,16 +42,13 @@ class Connection
|
||||||
case "NICK":
|
case "NICK":
|
||||||
//TODO: Check availablity and validity etc.
|
//TODO: Check availablity and validity etc.
|
||||||
nick = message.parameters[0];
|
nick = message.parameters[0];
|
||||||
writeln("nick: " ~ nick);
|
|
||||||
break;
|
break;
|
||||||
case "USER":
|
case "USER":
|
||||||
user = message.parameters[0];
|
user = message.parameters[0];
|
||||||
realname = message.parameters[3];
|
realname = message.parameters[3];
|
||||||
|
|
||||||
writeln("user: " ~ user);
|
|
||||||
writeln("mode: " ~ message.parameters[1]);
|
writeln("mode: " ~ message.parameters[1]);
|
||||||
writeln("unused: " ~ message.parameters[2]);
|
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", "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));
|
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"]));
|
send(Message("localhost", "004", [nick, "ircd", "0.01", "w", "snt"]));
|
||||||
break;
|
break;
|
||||||
case "PING":
|
case "PING":
|
||||||
send(Message(null, "PONG", [message.parameters[0]]));
|
send(Message(null, "PONG", [message.parameters[0]], true));
|
||||||
|
break;
|
||||||
|
case "PONG":
|
||||||
|
//TODO: Handle pong
|
||||||
break;
|
break;
|
||||||
case "QUIT":
|
case "QUIT":
|
||||||
send(Message(null, "ERROR", ["Bye!"]));
|
send(Message(null, "ERROR", ["Bye!"]));
|
||||||
|
|
|
@ -64,6 +64,7 @@ struct Message
|
||||||
{
|
{
|
||||||
message ~= parameters[0 .. $-1].join(' ') ~ " ";
|
message ~= parameters[0 .. $-1].join(' ') ~ " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parameters[$-1].canFind(' ') || prefixedParameter)
|
if(parameters[$-1].canFind(' ') || prefixedParameter)
|
||||||
{
|
{
|
||||||
message ~= ":";
|
message ~= ":";
|
||||||
|
|
Loading…
Reference in New Issue