aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2014-03-07 01:00:03 +0100
committersapier <Sapier at GMX dot net>2014-04-10 22:03:42 +0200
commit6090e95cdcea7c0600ea75941289494505295cf2 (patch)
tree83745714b25e66fe087c8abdef08d18d5bcd8576 /src/game.cpp
parentedcad09dee6daf119f3e29b0a63837500e7b8b85 (diff)
downloadminetest-6090e95cdcea7c0600ea75941289494505295cf2.tar.gz
minetest-6090e95cdcea7c0600ea75941289494505295cf2.tar.bz2
minetest-6090e95cdcea7c0600ea75941289494505295cf2.zip
Infer ipv6_server from bind_address; fix client connect to IN(6)ADDR_ANY
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 7d881fa88..f435a4d71 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1147,28 +1147,35 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
draw_load_screen(text, device, font,0,25);
delete[] text;
infostream<<"Creating server"<<std::endl;
- server = new Server(map_dir, gamespec,
- simple_singleplayer_mode);
std::string bind_str = g_settings->get("bind_address");
Address bind_addr(0,0,0,0, port);
- if (bind_str != "")
- {
- try {
- bind_addr.Resolve(bind_str.c_str());
- address = bind_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);
+ }
+ try {
+ bind_addr.Resolve(bind_str.c_str());
+ address = bind_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);
- }
- }
+ if(bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) {
+ error_message = L"Unable to listen on " +
+ narrow_to_wide(bind_addr.serializeString()) +
+ L" because IPv6 is disabled";
+ errorstream<<wide_to_narrow(error_message)<<std::endl;
+ // Break out of client scope
+ return;
}
+ server = new Server(map_dir, gamespec,
+ simple_singleplayer_mode,
+ bind_addr.isIPv6());
+
server->start(bind_addr);
}
@@ -1193,31 +1200,33 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
delete[] text;
}
Address connect_address(0,0,0,0, port);
- try{
- if(address == "")
- {
+ try {
+ connect_address.Resolve(address.c_str());
+ if (connect_address.isZero()) { // i.e. INADDR_ANY, IN6ADDR_ANY
//connect_address.Resolve("localhost");
- if(g_settings->getBool("enable_ipv6") && g_settings->getBool("ipv6_server"))
- {
+ if (connect_address.isIPv6()) {
IPv6AddressBytes addr_bytes;
addr_bytes.bytes[15] = 1;
connect_address.setAddress(&addr_bytes);
- }
- else
- {
+ } else {
connect_address.setAddress(127,0,0,1);
}
}
- else
- connect_address.Resolve(address.c_str());
}
- catch(ResolveError &e)
- {
+ catch(ResolveError &e) {
error_message = L"Couldn't resolve address: " + narrow_to_wide(e.what());
errorstream<<wide_to_narrow(error_message)<<std::endl;
// Break out of client scope
break;
}
+ if(connect_address.isIPv6() && !g_settings->getBool("enable_ipv6")) {
+ error_message = L"Unable to connect to " +
+ narrow_to_wide(connect_address.serializeString()) +
+ L" because IPv6 is disabled";
+ errorstream<<wide_to_narrow(error_message)<<std::endl;
+ // Break out of client scope
+ break;
+ }
/*
Create client