Handle incorrect server password

This commit is contained in:
Les De Ridder 2020-10-14 06:33:29 +02:00
parent 3c06c1b738
commit 21368785d6
2 changed files with 36 additions and 9 deletions

View File

@ -48,9 +48,14 @@ class Connection
return nick ~ "!" ~ user ~ "@" ~ hostname;
}
@property bool registrationAttempted()
{
return nick !is null && user !is null;
}
@property bool registered()
{
return nick !is null && user !is null && _server.isPassCorrect(pass);
return registrationAttempted && (!_server.hasPass || _server.isPassCorrect(pass));
}
@property bool isOperator()
@ -61,9 +66,10 @@ class Connection
@property string servername()
{
return _server.name;
} //TODO: Support server linking
}
//TODO: Maybe replace string's opEquals (or make a new string class/struct) to compare with toIRCLower
//TODO: Support server linking
//TODO: Maybe 'replace' string's opEquals (or make a new string class/struct) to compare with toIRCLower
//TODO: Read errata
this(TCPConnection connection, Server server)
@ -118,6 +124,7 @@ class Connection
void closeConnection()
{
connected = false;
_connection.close();
}
@ -316,6 +323,10 @@ class Connection
{
sendWelcome();
}
else if (registrationAttempted)
{
onIncorrectPassword();
}
}
void onUser(Message message)
@ -346,6 +357,10 @@ class Connection
{
sendWelcome();
}
else if (registrationAttempted)
{
onIncorrectPassword();
}
}
void onPass(Message message)
@ -367,12 +382,6 @@ class Connection
}
pass = message.parameters[0];
if (!_server.isPassCorrect(pass))
{
//NOTE: The RFCs don't allow ERR_PASSWDMISMATCH as a response to PASS
//TODO: If RFC-strictness is off, do send ERR_PASSWDMISMATCH
}
}
void onQuit(Message message)
@ -1420,6 +1429,19 @@ class Connection
//TODO: If RFC-strictness is off, also send 002, 003, and 004
}
void onIncorrectPassword()
{
//NOTE: The RFCs don't allow ERR_PASSWDMISMATCH as a response to NICK/USER
version (BasicFixes)
{
send(Message(_server.name, "464", [nick, "Password incorrect"], true));
}
//NOTE: The RFCs don't actually specify what should happen here
closeConnection();
}
string getHost()
{
auto address = parseAddress(_connection.remoteAddress.toAddressString);

View File

@ -510,6 +510,11 @@ class Server
return pass == _pass;
}
bool hasPass()
{
return _pass != null;
}
void listen(ushort port = 6667)
{
listenTCP(port, &acceptConnection);