diff options
author | Hubert Jarosz <marqin.pl@gmail.com> | 2016-08-27 13:41:34 +0200 |
---|---|---|
committer | Hubert Jarosz <marqin.pl@gmail.com> | 2016-08-27 13:41:34 +0200 |
commit | 8a4e636df673aad0e0f9a6c927270bf1d4c80a1b (patch) | |
tree | 21d416d34b1c82e5f368da09fd8482d1276e064a /modules/enet | |
parent | d015d93b8f94f55b26f874781ac7fd0a53e68227 (diff) |
add NetworkedMultiplayerENet::set_bind_ip
which allows ENet to bind on custom IP.
Diffstat (limited to 'modules/enet')
-rw-r--r-- | modules/enet/networked_multiplayer_enet.cpp | 11 | ||||
-rw-r--r-- | modules/enet/networked_multiplayer_enet.h | 3 |
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); |