diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2017-01-22 06:00:59 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2017-03-24 02:30:05 +0100 |
commit | 38d457170a15fd9eb902cecc8c5dc401646cd0b8 (patch) | |
tree | e43ccf541b01664b49ed24572e289139f00fdb74 /modules/enet/networked_multiplayer_enet.cpp | |
parent | 5bdbc0f762bf3a7cc38ebda0757de234c45b5f65 (diff) | |
download | redot-engine-38d457170a15fd9eb902cecc8c5dc401646cd0b8.tar.gz |
Update ENet module to support custom ENet lib
Keep compatibility with upstream enet libraries
Diffstat (limited to 'modules/enet/networked_multiplayer_enet.cpp')
-rw-r--r-- | modules/enet/networked_multiplayer_enet.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 2dfb0b4a6a..9e6a171d7f 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -53,8 +53,21 @@ 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 = bind_ip; +#ifdef GODOT_ENET + if (bind_ip.is_wildcard()) { + address.wildcard = 1; + } else { + enet_address_set_ip(&address, bind_ip.get_ipv6(), 16); + } +#else + if (bind_ip.is_wildcard()) { + address.host = 0; + } else { + ERR_FAIL_COND_V(!bind_ip.is_ipv4(), ERR_INVALID_PARAMETER); + address.host = *(uint32_t *)bind_ip.get_ipv4(); + } +#endif address.port = p_port; host = enet_host_create(&address /* the address to bind the server host to */, @@ -76,7 +89,6 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V(active, ERR_ALREADY_IN_USE); - ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER); host = enet_host_create(NULL /* create a client host */, 1 /* only allow 1 outgoing connection */, @@ -89,7 +101,12 @@ Error NetworkedMultiplayerENet::create_client(const IP_Address &p_ip, int p_port _setup_compressor(); ENetAddress address; - address.host = *((uint32_t *)p_ip.get_ipv4()); +#ifdef GODOT_ENET + enet_address_set_ip(&address, p_ip.get_ipv6(), 16); +#else + ERR_FAIL_COND_V(!p_ip.is_ipv4(), ERR_INVALID_PARAMETER); + address.host = *(uint32_t *)p_ip.get_ipv4(); +#endif address.port = p_port; //enet_address_set_host (& address, "localhost"); @@ -147,7 +164,11 @@ void NetworkedMultiplayerENet::poll() { } IP_Address ip; +#ifdef GODOT_ENET + ip.set_ipv6((uint8_t *)&(event.peer->address.host)); +#else ip.set_ipv4((uint8_t *)&(event.peer->address.host)); +#endif int *new_id = memnew(int); *new_id = event.data; @@ -657,7 +678,7 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { enet_compressor.decompress = enet_decompress; enet_compressor.destroy = enet_compressor_destroy; - bind_ip = ENET_HOST_ANY; + bind_ip = IP_Address("*"); } NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { @@ -668,6 +689,7 @@ NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { // 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) { - ERR_FAIL_COND(!p_ip.is_ipv4()); - bind_ip = *(uint32_t *)p_ip.get_ipv4(); + ERR_FAIL_COND(!p_ip.is_valid() && !p_ip.is_wildcard()); + + bind_ip = p_ip; } |