From 6090e95cdcea7c0600ea75941289494505295cf2 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Fri, 7 Mar 2014 01:00:03 +0100 Subject: Infer ipv6_server from bind_address; fix client connect to IN(6)ADDR_ANY --- src/main.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index e52002772..baaf8ebde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1023,21 +1023,6 @@ int main(int argc, char *argv[]) if(port == 0) port = 30000; - // Bind address - std::string bind_str = g_settings->get("bind_address"); - Address bind_addr(0,0,0,0, port); - try { - bind_addr.Resolve(bind_str.c_str()); - } catch (ResolveError &e) { - infostream << "Resolving bind address \"" << bind_str - << "\" failed: " << e.what() - << " -- Listening on all addresses." << std::endl; - - if (g_settings->getBool("ipv6_server")) { - bind_addr.setAddress((IPv6AddressBytes*) NULL); - } - } - // World directory std::string commanded_world = ""; if(cmd_args.exists("world")) @@ -1223,8 +1208,29 @@ int main(int argc, char *argv[]) } verbosestream<<_("Using gameid")<<" ["<get("bind_address"); + Address bind_addr(0,0,0,0, port); + + if (g_settings->getBool("ipv6_server")) { + bind_addr.setAddress((IPv6AddressBytes*) NULL); + } + try { + bind_addr.Resolve(bind_str.c_str()); + } catch (ResolveError &e) { + infostream << "Resolving bind address \"" << bind_str + << "\" failed: " << e.what() + << " -- Listening on all addresses." << std::endl; + } + if(bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) { + errorstream << "Unable to listen on " + << bind_addr.serializeString() + << L" because IPv6 is disabled" << std::endl; + return 1; + } + // Create server - Server server(world_path, gamespec, false); + Server server(world_path, gamespec, false, bind_addr.isIPv6()); // Database migration if (cmd_args.exists("migrate")) { -- cgit v1.2.3