Get hostname

This commit is contained in:
Les De Ridder 2017-03-14 16:54:21 +01:00
parent dad9ac49f9
commit 053b0fdd05
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
1 changed files with 13 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import std.string;
import std.algorithm;
import std.range;
import std.conv;
import std.socket;
import vibe.core.core;
import vibe.stream.operations;
@ -126,6 +127,7 @@ class Connection
writeln("mode: " ~ message.parameters[1]);
writeln("unused: " ~ message.parameters[2]);
realname = message.parameters[3];
hostname = getHost();
send(Message(_server.name, "001", [nick, "Welcome to the Internet Relay Network " ~ mask], true));
send(Message(_server.name, "002", [nick, "Your host is " ~ _server.name ~ ", running version " ~ _server.versionString], true));
@ -177,5 +179,16 @@ class Connection
}
}
}
string getHost()
{
auto address = parseAddress(_connection.peerAddress);
auto hostname = address.toHostNameString;
if(hostname is null)
{
hostname = address.toAddrString;
}
return hostname;
}
}