Skip to content

Commit 7796a31

Browse files
rubenwardynerzhul
authored andcommittedFeb 9, 2019
Disable confirmation dialog on localhost
1 parent b7e1bca commit 7796a31

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed
 

Diff for: ‎src/network/address.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,19 @@ void Address::print(std::ostream *s) const
271271
else
272272
*s << serializeString() << ":" << m_port;
273273
}
274+
275+
bool Address::isLocalhost() const {
276+
if (isIPv6()) {
277+
static const unsigned char localhost_bytes[] = {
278+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
279+
static const unsigned char mapped_ipv4_localhost[] = {
280+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0x7f, 0, 0, 1};
281+
282+
auto addr = m_address.ipv6.sin6_addr.s6_addr;
283+
284+
return memcmp(addr, localhost_bytes, 16) == 0 ||
285+
memcmp(addr, mapped_ipv4_localhost, 16) == 0;
286+
} else {
287+
return m_address.ipv4.sin_addr.s_addr == 0x0100007F;
288+
}
289+
}

Diff for: ‎src/network/address.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Address
6666
void setPort(unsigned short port);
6767
void print(std::ostream *s) const;
6868
std::string serializeString() const;
69+
bool isLocalhost() const;
6970

7071
private:
7172
unsigned int m_addr_family = 0;

Diff for: ‎src/network/clientpackethandler.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
9797

9898
// Authenticate using that method, or abort if there wasn't any method found
9999
if (chosen_auth_mechanism != AUTH_MECHANISM_NONE) {
100-
if (chosen_auth_mechanism == AUTH_MECHANISM_FIRST_SRP
101-
&& !m_simple_singleplayer_mode
102-
&& g_settings->getBool("enable_register_confirmation")) {
100+
if (chosen_auth_mechanism == AUTH_MECHANISM_FIRST_SRP &&
101+
!m_simple_singleplayer_mode &&
102+
!getServerAddress().isLocalhost() &&
103+
g_settings->getBool("enable_register_confirmation")) {
103104
promptConfirmRegistration(chosen_auth_mechanism);
104105
} else {
105106
startAuth(chosen_auth_mechanism);

0 commit comments

Comments
 (0)
Please sign in to comment.