Implement MOTD

This commit is contained in:
Les De Ridder 2017-04-07 08:08:24 +02:00
parent ffa830cf04
commit d78ca949af
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
3 changed files with 47 additions and 0 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ __dummy.html
__test__*__
/salty-ircd
source/ircd/packageVersion.d
motd

View File

@ -173,6 +173,10 @@ class Connection
if(!registered) sendErrNotRegistered();
else onTime(message);
break;
case "MOTD":
if(!registered) sendErrNotRegistered();
else onMotd(message);
break;
default:
writeln("unknown command '", message.command, "'");
send(Message(_server.name, "421", [nick, message.command, "Unknown command"]));
@ -597,6 +601,16 @@ class Connection
_server.sendTime(this);
}
void onMotd(Message message)
{
if(message.parameters.length > 0)
{
notImplemented("querying the motd of another server");
return;
}
_server.sendMotd(this);
}
void sendWhoReply(string channel, Connection user, uint hopCount)
{
auto flags = user.modes.canFind('a') ? "G" : "H";

View File

@ -7,6 +7,7 @@ import std.conv;
import std.socket;
import core.time;
import std.datetime;
import std.string;
import vibe.core.core;
@ -26,15 +27,28 @@ class Server
string name;
string motd;
Channel[] channels;
this()
{
name = Socket.hostName;
readMotd();
runTask(&pingLoop);
}
private void readMotd()
{
import std.file : exists, readText;
if(exists("motd"))
{
motd = readText("motd");
}
}
private void pingLoop()
{
while(true)
@ -269,6 +283,24 @@ class Server
user.send(Message(inviter.mask, "INVITE", [user.nick, channelName]));
}
void sendMotd(Connection connection)
{
if(motd !is null)
{
connection.send(Message(name, "375", [connection.nick, ":- " ~ name ~ " Message of the day - "], true));
foreach(line; motd.splitLines)
{
//TODO: Implement line wrapping
connection.send(Message(name, "372", [connection.nick, ":- " ~ line], true));
}
connection.send(Message(name, "376", [connection.nick, "End of MOTD command"], true));
}
else
{
connection.send(Message(name, "422", [connection.nick, "MOTD File is missing"], true));
}
}
void listen(ushort port = 6667)
{
listenTCP(port, &acceptConnection);