forked from lesderid/salty-ircd
Implement MOTD
This commit is contained in:
parent
ffa830cf04
commit
d78ca949af
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ __dummy.html
|
|||||||
__test__*__
|
__test__*__
|
||||||
/salty-ircd
|
/salty-ircd
|
||||||
source/ircd/packageVersion.d
|
source/ircd/packageVersion.d
|
||||||
|
motd
|
||||||
|
@ -173,6 +173,10 @@ class Connection
|
|||||||
if(!registered) sendErrNotRegistered();
|
if(!registered) sendErrNotRegistered();
|
||||||
else onTime(message);
|
else onTime(message);
|
||||||
break;
|
break;
|
||||||
|
case "MOTD":
|
||||||
|
if(!registered) sendErrNotRegistered();
|
||||||
|
else onMotd(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"]));
|
||||||
@ -597,6 +601,16 @@ class Connection
|
|||||||
_server.sendTime(this);
|
_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)
|
void sendWhoReply(string channel, Connection user, uint hopCount)
|
||||||
{
|
{
|
||||||
auto flags = user.modes.canFind('a') ? "G" : "H";
|
auto flags = user.modes.canFind('a') ? "G" : "H";
|
||||||
|
@ -7,6 +7,7 @@ import std.conv;
|
|||||||
import std.socket;
|
import std.socket;
|
||||||
import core.time;
|
import core.time;
|
||||||
import std.datetime;
|
import std.datetime;
|
||||||
|
import std.string;
|
||||||
|
|
||||||
import vibe.core.core;
|
import vibe.core.core;
|
||||||
|
|
||||||
@ -26,15 +27,28 @@ class Server
|
|||||||
|
|
||||||
string name;
|
string name;
|
||||||
|
|
||||||
|
string motd;
|
||||||
|
|
||||||
Channel[] channels;
|
Channel[] channels;
|
||||||
|
|
||||||
this()
|
this()
|
||||||
{
|
{
|
||||||
name = Socket.hostName;
|
name = Socket.hostName;
|
||||||
|
|
||||||
|
readMotd();
|
||||||
|
|
||||||
runTask(&pingLoop);
|
runTask(&pingLoop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void readMotd()
|
||||||
|
{
|
||||||
|
import std.file : exists, readText;
|
||||||
|
if(exists("motd"))
|
||||||
|
{
|
||||||
|
motd = readText("motd");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void pingLoop()
|
private void pingLoop()
|
||||||
{
|
{
|
||||||
while(true)
|
while(true)
|
||||||
@ -269,6 +283,24 @@ class Server
|
|||||||
user.send(Message(inviter.mask, "INVITE", [user.nick, channelName]));
|
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)
|
void listen(ushort port = 6667)
|
||||||
{
|
{
|
||||||
listenTCP(port, &acceptConnection);
|
listenTCP(port, &acceptConnection);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user