aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2019-02-03 12:31:55 +0000
committerLoic Blot <loic.blot@unix-experience.fr>2019-02-09 19:52:56 +0100
commit7796a3118d7b4f58752fad0ca5f676dcafd7a76c (patch)
tree12348fd175d8b144bf72c977dd117fffa81b4a84
parentb7e1bca28c2c551198d284473c22b0293139163d (diff)
downloadminetest-7796a3118d7b4f58752fad0ca5f676dcafd7a76c.tar.gz
minetest-7796a3118d7b4f58752fad0ca5f676dcafd7a76c.tar.bz2
minetest-7796a3118d7b4f58752fad0ca5f676dcafd7a76c.zip
Disable confirmation dialog on localhost
-rw-r--r--src/network/address.cpp16
-rw-r--r--src/network/address.h1
-rw-r--r--src/network/clientpackethandler.cpp7
3 files changed, 21 insertions, 3 deletions
diff --git a/src/network/address.cpp b/src/network/address.cpp
index f698a2e91..0ecface37 100644
--- a/src/network/address.cpp
+++ b/src/network/address.cpp
@@ -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;
+ }
+}
diff --git a/src/network/address.h b/src/network/address.h
index fb25b3565..4329c84a8 100644
--- a/src/network/address.h
+++ b/src/network/address.h
@@ -66,6 +66,7 @@ public:
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;
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 909d336ae..2d02d0755 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -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);