diff options
Diffstat (limited to 'modules/enet/networked_multiplayer_enet.cpp')
-rw-r--r-- | modules/enet/networked_multiplayer_enet.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 2dfb0b4a6a..13760b33aa 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"); @@ -146,9 +163,6 @@ void NetworkedMultiplayerENet::poll() { break; } - IP_Address ip; - ip.set_ipv4((uint8_t *)&(event.peer->address.host)); - int *new_id = memnew(int); *new_id = event.data; @@ -657,7 +671,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 +682,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; } |