Skip to content

Commit

Permalink
Disable confirmation dialog on localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy authored and nerzhul committed Feb 9, 2019
1 parent b7e1bca commit 7796a31
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/network/address.cpp
Expand Up @@ -271,3 +271,19 @@ void Address::print(std::ostream *s) const
else
*s << serializeString() << ":" << m_port;
}

bool Address::isLocalhost() const {
if (isIPv6()) {
static const unsigned char localhost_bytes[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
static const unsigned char mapped_ipv4_localhost[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1};

auto addr = m_address.ipv6.sin6_addr.s6_addr;

return memcmp(addr, localhost_bytes, 16) == 0 ||
memcmp(addr, mapped_ipv4_localhost, 16) == 0;
} else {
return m_address.ipv4.sin_addr.s_addr == 0x0100007F;
}
}
1 change: 1 addition & 0 deletions src/network/address.h
Expand Up @@ -66,6 +66,7 @@ class Address
void setPort(unsigned short port);
void print(std::ostream *s) const;
std::string serializeString() const;
bool isLocalhost() const;

private:
unsigned int m_addr_family = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/network/clientpackethandler.cpp
Expand Up @@ -97,9 +97,10 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)

// Authenticate using that method, or abort if there wasn't any method found
if (chosen_auth_mechanism != AUTH_MECHANISM_NONE) {
if (chosen_auth_mechanism == AUTH_MECHANISM_FIRST_SRP
&& !m_simple_singleplayer_mode
&& g_settings->getBool("enable_register_confirmation")) {
if (chosen_auth_mechanism == AUTH_MECHANISM_FIRST_SRP &&
!m_simple_singleplayer_mode &&
!getServerAddress().isLocalhost() &&
g_settings->getBool("enable_register_confirmation")) {
promptConfirmRegistration(chosen_auth_mechanism);
} else {
startAuth(chosen_auth_mechanism);
Expand Down

0 comments on commit 7796a31

Please sign in to comment.