Disable confirmation dialog on localhost
authorrubenwardy <rw@rubenwardy.com>
Sun, 3 Feb 2019 12:31:55 +0000 (12:31 +0000)
committerLoic Blot <loic.blot@unix-experience.fr>
Sat, 9 Feb 2019 18:52:56 +0000 (19:52 +0100)
src/network/address.cpp
src/network/address.h
src/network/clientpackethandler.cpp

index f698a2e91b7eb24e46aa9f0e299878dfa5e9180a..0ecface37f4776e9ab01111b4c73ac49370e85f4 100644 (file)
@@ -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;
+       }
+}
index fb25b35650e2b64c5094fe72ffb562d0e26058a5..4329c84a84e8973eed4d5d433c2237e64444069f 100644 (file)
@@ -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;
index 909d336ae8cac32b08be5988278663171f16e01e..2d02d07559c248c2627849b0efa66525ca9cde3f 100644 (file)
@@ -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);