summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2016-08-29 19:05:45 +0200
committerGitHub <noreply@github.com>2016-08-29 19:05:45 +0200
commitb06fd4cfda67e37d45a5114f81b8b0062e68ed51 (patch)
tree39e0e40d0986cc936ce62108ed74e1be117e8473
parent622bf389f2956d33921c9eaa8bf6fafaded61474 (diff)
parent8a4e636df673aad0e0f9a6c927270bf1d4c80a1b (diff)
Merge pull request #6303 from Marqin/enet_bind_ip_rebased
add NetworkedMultiplayerENet::set_bind_ip
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp11
-rw-r--r--modules/enet/networked_multiplayer_enet.h3
2 files changed, 12 insertions, 2 deletions
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index 5ddbb83534..18a4347edf 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -26,7 +26,7 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int
ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);
ENetAddress address;
- address.host = ENET_HOST_ANY;
+ address.host = bind_ip;
address.port = p_port;
@@ -610,12 +610,12 @@ void NetworkedMultiplayerENet::_bind_methods() {
ObjectTypeDB::bind_method(_MD("close_connection"),&NetworkedMultiplayerENet::close_connection);
ObjectTypeDB::bind_method(_MD("set_compression_mode","mode"),&NetworkedMultiplayerENet::set_compression_mode);
ObjectTypeDB::bind_method(_MD("get_compression_mode"),&NetworkedMultiplayerENet::get_compression_mode);
+ ObjectTypeDB::bind_method(_MD("set_bind_ip", "ip"),&NetworkedMultiplayerENet::set_bind_ip);
BIND_CONSTANT( COMPRESS_NONE );
BIND_CONSTANT( COMPRESS_RANGE_CODER );
BIND_CONSTANT( COMPRESS_FASTLZ );
BIND_CONSTANT( COMPRESS_ZLIB );
-
}
@@ -635,9 +635,16 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet(){
enet_compressor.decompress=enet_decompress;
enet_compressor.destroy=enet_compressor_destroy;
+ bind_ip=ENET_HOST_ANY;
}
NetworkedMultiplayerENet::~NetworkedMultiplayerENet(){
close_connection();
}
+
+// sets IP for ENet to bind when using create_server
+// if no IP is set, then ENet bind to ENET_HOST_ANY
+void NetworkedMultiplayerENet::set_bind_ip(const IP_Address& p_ip){
+ bind_ip=p_ip.host;
+}
diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h
index dc86058cbb..59863c1f78 100644
--- a/modules/enet/networked_multiplayer_enet.h
+++ b/modules/enet/networked_multiplayer_enet.h
@@ -65,6 +65,7 @@ private:
static void enet_compressor_destroy(void * context);
void _setup_compressor();
+ enet_uint32 bind_ip;
protected:
static void _bind_methods();
public:
@@ -103,6 +104,8 @@ public:
NetworkedMultiplayerENet();
~NetworkedMultiplayerENet();
+
+ void set_bind_ip(const IP_Address& p_ip);
};
VARIANT_ENUM_CAST(NetworkedMultiplayerENet::CompressionMode);